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;
15 * A factory class for file-based stacks
17 * @author Roland Haeder <webmaster@ship-simu.org>
19 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2020 Core Developer Team
20 * @license GNU GPL 3.0 or any newer version
21 * @link http://www.ship-simu.org
23 * This program is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program. If not, see <http://www.gnu.org/licenses/>.
36 class FileStackFactory extends BaseFactory {
38 * Protected constructor
42 protected function __construct () {
43 // Call parent constructor
44 parent::__construct(__CLASS__);
48 * Returns a singleton (registry-based) StackableFile instance
50 * @param $prefix Class prefix
51 * @param $stackName Name of the stack
52 * @return $stackInstance An instance of a StackableFile class
54 public static final function createFileStackInstance (string $prefix, string $stackName) {
55 // Construct file stack name
56 $fileInfoInstance = new SplFileInfo(sprintf('%s%s/%s.%s',
57 FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('root_base_path'),
58 FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('base_file_stacks_path'),
60 FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('file_stacks_extension')
63 // If there is no handler?
64 if (GenericRegistry::getRegistry()->instanceExists($stackName . '_stack')) {
65 // Get handler from registry
66 $stackInstance = GenericRegistry::getRegistry()->getInstance($stackName . '_stack');
68 // Get the handler instance
69 $stackInstance = ObjectFactory::createObjectByConfiguredName($prefix . '_' . $stackName . '_stack_class', array($fileInfoInstance, $prefix . '_' . $stackName));
71 // Add it to the registry
72 GenericRegistry::getRegistry()->addInstance($stackName . '_stack', $stackInstance);
75 // Return the instance
76 return $stackInstance;