3 namespace Org\Mxchange\CoreFramework\Factory\Stack;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
7 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
8 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
9 use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
10 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
13 use \InvalidArgumentException;
17 * A factory class for file-based stacks
19 * @author Roland Haeder <webmaster@ship-simu.org>
21 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
22 * @license GNU GPL 3.0 or any newer version
23 * @link http://www.ship-simu.org
25 * This program is free software: you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation, either version 3 of the License, or
28 * (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program. If not, see <http://www.gnu.org/licenses/>.
38 class FileStackFactory extends BaseFactory {
40 * Protected constructor
44 private function __construct () {
45 // Call parent constructor
46 parent::__construct(__CLASS__);
50 * Returns a singleton (registry-based) StackableFile instance
52 * @param $prefix Class prefix
53 * @param $stackName Name of the stack
54 * @return $stackInstance An instance of a StackableFile class
56 public static final function createFileStackInstance (string $prefix, string $stackName) {
58 //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-FACTORY: prefix=%s,stackName=%s - CALLED!', $prefix, $stackName));
61 throw new InvalidArgumentException('Parameter "prefix" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
62 } elseif (empty($stackName)) {
64 throw new InvalidArgumentException('Paramter "stackName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
67 // Construct file stack name
68 $fileInfoInstance = new SplFileInfo(sprintf('%s%s/%s.%s',
69 FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('root_base_path'),
70 FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('base_file_stacks_path'),
72 FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('file_stacks_extension')
75 // If there is no handler?
76 if (GenericRegistry::getRegistry()->instanceExists($stackName . '_stack')) {
77 // Get handler from registry
78 $stackInstance = GenericRegistry::getRegistry()->getInstance($stackName . '_stack');
80 // Get the handler instance
81 $stackInstance = ObjectFactory::createObjectByConfiguredName($prefix . '_' . $stackName . '_stack_class', array($fileInfoInstance, $prefix . '_' . $stackName));
83 // Add it to the registry
84 GenericRegistry::getRegistry()->addInstance($stackName . '_stack', $stackInstance);
87 // Return the instance
88 //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-FACTORY: stackInstance=%s - EXIT!', $stackInstance->__toString()));
89 return $stackInstance;