Continued:
[core.git] / framework / main / classes / factories / stacks / class_FileStackFactory.php
index 957810fbfe35bad3b4fe4bf15bf6d08868545b1b..32d6326f159d3c9743628c1f10f2b41af82f5f2e 100644 (file)
@@ -1,18 +1,24 @@
 <?php
 // Own namespace
-namespace CoreFramework\Factory\Stack;
+namespace Org\Mxchange\CoreFramework\Factory\Stack;
 
 // Import framework stuff
-use CoreFramework\Configuration\FrameworkConfiguration;
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Registry\Registry;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+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;
 
 /**
  * A factory class for file-based stacks
  *
  * @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
  *
@@ -29,13 +35,13 @@ use CoreFramework\Registry\Registry;
  * 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 FileStackFactory extends ObjectFactory {
+class FileStackFactory extends BaseFactory {
        /**
         * Protected constructor
         *
         * @return      void
         */
-       protected function __construct () {
+       private function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
        }
@@ -47,28 +53,39 @@ class FileStackFactory extends ObjectFactory {
         * @param       $stackName                      Name of the stack
         * @return      $stackInstance          An instance of a StackableFile class
         */
-       public static final function createFileStackInstance ($prefix, $stackName) {
+       public static final function createFileStackInstance (string $prefix, string $stackName) {
+               // Validate parameter
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-FACTORY: prefix=%s,stackName=%s - CALLED!', $prefix, $stackName));
+               if (empty($prefix)) {
+                       // Throw IAE
+                       throw new InvalidArgumentException('Parameter "prefix" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               } elseif (empty($stackName)) {
+                       // Throw it again
+                       throw new InvalidArgumentException('Paramter "stackName" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+               }
+
                // Construct file stack name
-               $stackFileName = sprintf('%s%s/%s.%s',
-                       FrameworkConfiguration::getSelfInstance()->getConfigEntry('framework_base_path'),
-                       FrameworkConfiguration::getSelfInstance()->getConfigEntry('base_file_stacks_path'),
+               $fileInfoInstance = new SplFileInfo(sprintf('%s%s/%s.%s',
+                       FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('root_base_path'),
+                       FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('base_file_stacks_path'),
                        $stackName,
-                       FrameworkConfiguration::getSelfInstance()->getConfigEntry('file_stacks_extension')
-               );
+                       FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('file_stacks_extension')
+               ));
 
                // If there is no handler?
-               if (Registry::getRegistry()->instanceExists($stackName . '_stack')) {
+               if (ObjectRegistry::getRegistry('factory')->instanceExists($stackName . '_stack')) {
                        // Get handler from registry
-                       $stackInstance = Registry::getRegistry()->getInstance($stackName . '_stack');
+                       $stackInstance = ObjectRegistry::getRegistry('factory')->getInstance($stackName . '_stack');
                } else {
                        // Get the handler instance
-                       $stackInstance = self::createObjectByConfiguredName($prefix . '_' . $stackName . '_stack_class', array($stackFileName, $prefix . '_' . $stackName));
+                       $stackInstance = ObjectFactory::createObjectByConfiguredName($prefix . '_' . $stackName . '_stack_class', array($fileInfoInstance, $prefix . '_' . $stackName));
 
                        // Add it to the registry
-                       Registry::getRegistry()->addInstance($stackName . '_stack', $stackInstance);
+                       ObjectRegistry::getRegistry('factory')->addInstance($stackName . '_stack', $stackInstance);
                }
 
                // Return the instance
+               //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('FILE-STACK-FACTORY: stackInstance=%s - EXIT!', $stackInstance->__toString()));
                return $stackInstance;
        }