]> git.mxchange.org Git - core.git/blob - framework/main/classes/factories/stacks/class_FileStackFactory.php
Continued:
[core.git] / framework / main / classes / factories / stacks / class_FileStackFactory.php
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Factory\Stack;
4
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;
10
11 // Import SPL stuff
12 use \SplFileInfo;
13
14 /**
15  * A factory class for file-based stacks
16  *
17  * @author              Roland Haeder <webmaster@ship-simu.org>
18  * @version             0.0.0
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
22  *
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.
27  *
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.
32  *
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/>.
35  */
36 class FileStackFactory extends BaseFactory {
37         /**
38          * Protected constructor
39          *
40          * @return      void
41          */
42         protected function __construct () {
43                 // Call parent constructor
44                 parent::__construct(__CLASS__);
45         }
46
47         /**
48          * Returns a singleton (registry-based) StackableFile instance
49          *
50          * @param       $prefix                         Class prefix
51          * @param       $stackName                      Name of the stack
52          * @return      $stackInstance          An instance of a StackableFile class
53          */
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'),
59                         $stackName,
60                         FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('file_stacks_extension')
61                 ));
62
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');
67                 } else {
68                         // Get the handler instance
69                         $stackInstance = ObjectFactory::createObjectByConfiguredName($prefix . '_' . $stackName . '_stack_class', array($fileInfoInstance, $prefix . '_' . $stackName));
70
71                         // Add it to the registry
72                         GenericRegistry::getRegistry()->addInstance($stackName . '_stack', $stackInstance);
73                 }
74
75                 // Return the instance
76                 return $stackInstance;
77         }
78
79 }