Continued:
[core.git] / framework / main / classes / factories / index / class_FileStackIndexFactory.php
index e483fc83a27a84689f11b45dc85c70af29e5c7f9..aa774a1d794ee46395c7af98998e0208d4e3d7e3 100644 (file)
@@ -1,13 +1,15 @@
 <?php
 // Own namespace
-namespace Org\Mxchange\CoreFramework\Factory\Filesystem\Stack;
+namespace Org\Mxchange\CoreFramework\Factory\Stack\File;
 
 // Import framework stuff
-use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
-use Org\Mxchange\CoreFramework\Registry\GenericRegistry;
-use Org\Mxchange\CoreFramework\Stacker\Index\IndexableStack;
+use Org\Mxchange\CoreFramework\Factory\BaseFactory;
+use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
+use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
+use Org\Mxchange\CoreFramework\Registry\Object\ObjectRegistry;
 
 // Import SPL stuff
+use \InvalidArgumentException;
 use \SplFileInfo;
 
 /**
@@ -15,7 +17,7 @@ use \SplFileInfo;
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -32,13 +34,13 @@ use \SplFileInfo;
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class FileStackIndexFactory extends ObjectFactory {
+class FileStackIndexFactory extends BaseFactory {
        /**
         * Protected constructor
         *
         * @return      void
         */
-       protected function __construct () {
+       private function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
        }
@@ -46,23 +48,24 @@ class FileStackIndexFactory extends ObjectFactory {
        /**
         * Returns a singleton (registry-based) StackableFile instance
         *
-        * @param       $infoInstance   An instance of a SplFileInfo class
+        * @param       $fileInfoInstance       An instance of a SplFileInfo class
         * @return      $indexInstance  An instance of a IndexableStack class
+        * @throws      InvalidArgumentException        If a parameter is invalid
         */
-       public static final function createFileStackIndexInstance (SplFileInfo $infoInstance, $type) {
+       public static final function createFileStackIndexInstance (SplFileInfo $fileInfoInstance, string $type) {
                // If there is no handler?
-               if (GenericRegistry::getRegistry()->instanceExists($type . '_index')) {
+               if (empty($type)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "type" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (ObjectRegistry::getRegistry('factory')->instanceExists($type . '_index')) {
                        // Get handler from registry
-                       $indexInstance = GenericRegistry::getRegistry()->getInstance($type . '_index');
+                       $indexInstance = ObjectRegistry::getRegistry('factory')->getInstance($type . '_index');
                } else {
                        // Get the handler instance
-                       $indexInstance = self::createObjectByConfiguredName($type . '_file_stack_index_class', array($infoInstance));
-
-                       // Add check for interface
-                       assert($indexInstance instanceof IndexableStack);
+                       $indexInstance = ObjectFactory::createObjectByConfiguredName($type . '_file_stack_index_class', [$fileInfoInstance]);
 
                        // Add it to the registry
-                       GenericRegistry::getRegistry()->addInstance($type . '_index', $indexInstance);
+                       ObjectRegistry::getRegistry('factory')->addInstance($type . '_index', $indexInstance);
                }
 
                // Return the instance