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\Generic\FrameworkInterface;
9 use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
12 use \InvalidArgumentException;
16 * A factory class for file-based stack indexes
18 * @author Roland Haeder <webmaster@ship-simu.org>
20 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 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 FileStackIndexFactory 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 $fileInfoInstance An instance of a SplFileInfo class
52 * @return $indexInstance An instance of a IndexableStack class
53 * @throws InvalidArgumentException If a parameter is invalid
55 public static final function createFileStackIndexInstance (SplFileInfo $fileInfoInstance, string $type) {
56 // If there is no handler?
59 throw new InvalidArgumentException('Parameter "type" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
60 } elseif (ObjectRegistry::getRegistry('factory')->instanceExists($type . '_index')) {
61 // Get handler from registry
62 $indexInstance = ObjectRegistry::getRegistry('factory')->getInstance($type . '_index');
64 // Get the handler instance
65 $indexInstance = ObjectFactory::createObjectByConfiguredName($type . '_file_stack_index_class', [$fileInfoInstance]);
67 // Add it to the registry
68 ObjectRegistry::getRegistry('factory')->addInstance($type . '_index', $indexInstance);
71 // Return the instance
72 return $indexInstance;