Rewrites:
[core.git] / framework / main / classes / class_BaseFrameworkSystem.php
index 1ab419f52db8b55e17d1bbabfb091016cf6c2f18..721e4ec52556f44fd7924358be9a83ba200167ee 100644 (file)
@@ -50,8 +50,10 @@ use CoreFramework\Visitor\Visitor;
 
 // Import SPL stuff
 use \stdClass;
+use \InvalidArgumentException;
 use \Iterator;
 use \ReflectionClass;
+use \SplFileInfo;
 
 /**
  * The simulator system class is the super class of all other classes. This
@@ -257,6 +259,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        private $stateInstance = NULL;
 
+       /**
+        * Registry instance (implementing Register)
+        */
+       private $registryInstance = NULL;
+
+       /**
+        * Call-back instance
+        */
+       private $callbackInstance = NULL;
+
        /**
         * Thousands separator
         */
@@ -455,7 +467,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Set configuration instance if no registry ...
                if (!$this instanceof Register) {
                        // ... because registries doesn't need to be configured
-                       $this->setConfigInstance(FrameworkConfiguration::getSelfInstance());
+                       $this->setConfigInstance(FrameworkBootstrap::getConfigurationInstance());
                } // END - if
 
                // Is the startup time set? (0 cannot be true anymore)
@@ -1527,6 +1539,44 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $this->outputInstance;
        }
 
+       /**
+        * Setter for registry instance
+        *
+        * @param       $registryInstance               An instance of a Register class
+        * @return      void
+        */
+       protected final function setRegistryInstance (Register $registryInstance) {
+               $this->registryInstance = $registryInstance;
+       }
+
+       /**
+        * Getter for registry instance
+        *
+        * @return      $registryInstance       The debug registry instance
+        */
+       public final function getRegistryInstance () {
+               return $this->registryInstance;
+       }
+
+       /**
+        * Setter for call-back instance
+        *
+        * @param       $callbackInstance       An instance of a FrameworkInterface class
+        * @return      void
+        */
+       public final function setCallbackInstance (FrameworkInterface $callbackInstance) {
+               $this->callbackInstance = $callbackInstance;
+       }
+
+       /**
+        * Getter for call-back instance
+        *
+        * @return      $callbackInstance       An instance of a FrameworkInterface class
+        */
+       protected final function getCallbackInstance () {
+               return $this->callbackInstance;
+       }
+
        /**
         * Setter for command name
         *
@@ -1701,7 +1751,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                );
 
                // Output it
-               ApplicationEntryPoint::app_exit(sprintf('<div class="debug_header">
+               ApplicationEntryPoint::exitApplication(sprintf('<div class="debug_header">
        %s debug output:
 </div>
 <div class="debug_content">
@@ -1804,7 +1854,7 @@ Loaded includes:
                        // Try it
                        try {
                                // Get a debugger instance
-                               $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
+                               $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('debug_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_class'), $className);
                        } catch (NullPointerException $e) {
                                // Didn't work, no instance there
                                exit(sprintf('Cannot create debugInstance! Exception=%s,message=%s,className=%s,lineNumber=%d' . PHP_EOL, $e->__toString(), $e->getMessage(), $className, $lineNumber));
@@ -1934,8 +1984,22 @@ Loaded includes:
         *
         * @param       $str    The string with maybe dashes inside
         * @return      $str    The converted string with no dashed, but underscores
-        */
-       public static final function convertDashesToUnderscores ($str) {
+        * @throws      NullPointerException    If $str is null
+        * @throws      InvalidArgumentException        If $str is empty
+        */
+       public static function convertDashesToUnderscores ($str) {
+               // Is it null?
+               if (is_null($str)) {
+                       // Throw NPE
+                       throw new NullPointerException($this, BaseFrameworkSystem::EXCEPTION_IS_NULL_POINTER);
+               } elseif (!is_string($str)) {
+                       // Entry is empty
+                       throw new InvalidArgumentException(sprintf('str[]=%s is not a string', gettype($str)), self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+               } elseif ((is_string($str)) && (empty($str))) {
+                       // Entry is empty
+                       throw new InvalidArgumentException('str is empty', self::EXCEPTION_CONFIG_KEY_IS_EMPTY);
+               }
+
                // Convert them all
                $str = str_replace('-', '_', $str);
 
@@ -3229,32 +3293,32 @@ Loaded includes:
         * Creates a full-qualified file name (FQFN) for given file name by adding
         * a configured temporary file path to it.
         *
-        * @param       $fileName       Name for temporary file
-        * @return      $fqfn   Full-qualified file name
+        * @param       $infoInstance   An instance of a SplFileInfo class
+        * @return      $tempInstance   An instance of a SplFileInfo class (temporary file)
         * @throw       PathWriteProtectedException If the path in 'temp_file_path' is write-protected
         * @throws      FileIoException If the file cannot be written
         */
-        protected static function createTempPathForFile ($fileName) {
+        protected static function createTempPathForFile (SplFileInfo $infoInstance) {
                // Get config entry
-               $basePath = FrameworkConfiguration::getSelfInstance()->getConfigEntry('temp_file_path');
+               $basePath = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('temp_file_path');
 
                // Is the path writeable?
                if (!is_writable($basePath)) {
                        // Path is write-protected
-                       throw new PathWriteProtectedException($fileName, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
+                       throw new PathWriteProtectedException($infoInstance, self::EXCEPTION_PATH_CANNOT_BE_WRITTEN);
                } // END - if
 
                // Add it
-               $fqfn = $basePath . DIRECTORY_SEPARATOR . $fileName;
+               $tempInstance = new SplFileInfo($basePath . DIRECTORY_SEPARATOR . $infoInstance->getBasename());
 
                // Is it reachable?
-               if (!FrameworkBootstrap::isReachableFilePath($fqfn)) {
+               if (!FrameworkBootstrap::isReachableFilePath($tempInstance)) {
                        // Not reachable
-                       throw new FileIoException($fqfn, self::EXCEPTION_FILE_NOT_REACHABLE);
+                       throw new FileIoException($tempInstance, self::EXCEPTION_FILE_NOT_REACHABLE);
                } // END - if
 
                // Return it
-               return $fqfn;
+               return $tempInstance;
         }
 
        /**