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\Registry\GenericRegistry;
12 use \InvalidArgumentException;
16 * A factory class for file-based stacks
18 * @author Roland Haeder <webmaster@ship-simu.org>
20 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2021 Core Developer Team
21 * @license GNU GPL 3.0 or any newer version
22 * @link http://www.ship-simu.org
24 * This program is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
34 * You should have received a copy of the GNU General Public License
35 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 class FileStackFactory extends BaseFactory {
39 * Protected constructor
43 private function __construct () {
44 // Call parent constructor
45 parent::__construct(__CLASS__);
49 * Returns a singleton (registry-based) StackableFile instance
51 * @param $prefix Class prefix
52 * @param $stackName Name of the stack
53 * @return $stackInstance An instance of a StackableFile class
55 public static final function createFileStackInstance (string $prefix, string $stackName) {
57 //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-FACTORY: prefix=%s,stackName=%s - CALLED!', $prefix, $stackName));
60 throw new InvalidArgumentException('Parameter "prefix" is empty');
61 } elseif (empty($stackName)) {
63 throw new InvalidArgumentException('Paramter "stackName" is empty');
66 // Construct file stack name
67 $fileInfoInstance = new SplFileInfo(sprintf('%s%s/%s.%s',
68 FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('root_base_path'),
69 FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('base_file_stacks_path'),
71 FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('file_stacks_extension')
74 // If there is no handler?
75 if (GenericRegistry::getRegistry()->instanceExists($stackName . '_stack')) {
76 // Get handler from registry
77 $stackInstance = GenericRegistry::getRegistry()->getInstance($stackName . '_stack');
79 // Get the handler instance
80 $stackInstance = ObjectFactory::createObjectByConfiguredName($prefix . '_' . $stackName . '_stack_class', array($fileInfoInstance, $prefix . '_' . $stackName));
82 // Add it to the registry
83 GenericRegistry::getRegistry()->addInstance($stackName . '_stack', $stackInstance);
86 // Return the instance
87 //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-FACTORY: stackInstance=%s - EXIT!', $stackInstance->__toString()));
88 return $stackInstance;