3 namespace Org\Mxchange\CoreFramework\Factory\Stack\File;
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Factory\BaseFactory;
7 use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
8 use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
11 use \InvalidArgumentException;
15 * A factory class for file-based stack indexes
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 FileStackIndexFactory 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 $fileInfoInstance An instance of a SplFileInfo class
51 * @return $indexInstance An instance of a IndexableStack class
52 * @throws InvalidArgumentException If a parameter is invalid
54 public static final function createFileStackIndexInstance (SplFileInfo $fileInfoInstance, string $type) {
55 // If there is no handler?
58 throw new InvalidArgumentException('Parameter "type" is empty');
59 } elseif (GenericRegistry::getRegistry()->instanceExists($type . '_index')) {
60 // Get handler from registry
61 $indexInstance = GenericRegistry::getRegistry()->getInstance($type . '_index');
63 // Get the handler instance
64 $indexInstance = ObjectFactory::createObjectByConfiguredName($type . '_file_stack_index_class', [$fileInfoInstance]);
66 // Add it to the registry
67 GenericRegistry::getRegistry()->addInstance($type . '_index', $indexInstance);
70 // Return the instance
71 return $indexInstance;