]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/class_BaseFrameworkSystem.php
Continued:
[core.git] / framework / main / classes / class_BaseFrameworkSystem.php
index be1c07d883b880dc05a19036d3b454af3c5bfc78..357f228a8f703cf6d6168591d695bbecbf784e09 100644 (file)
@@ -30,7 +30,9 @@ use Org\Mxchange\CoreFramework\Helper\Helper;
 use Org\Mxchange\CoreFramework\Index\Indexable;
 use Org\Mxchange\CoreFramework\Lists\Listable;
 use Org\Mxchange\CoreFramework\Loader\ClassLoader;
+use Org\Mxchange\CoreFramework\Localization\ManageableLanguage;
 use Org\Mxchange\CoreFramework\Manager\ManageableApplication;
+use Org\Mxchange\CoreFramework\Menu\RenderableMenu;
 use Org\Mxchange\CoreFramework\Middleware\Compressor\CompressorChannel;
 use Org\Mxchange\CoreFramework\Middleware\Debug\DebugMiddleware;
 use Org\Mxchange\CoreFramework\Parser\Parseable;
@@ -44,6 +46,7 @@ use Org\Mxchange\CoreFramework\State\Stateable;
 use Org\Mxchange\CoreFramework\Stream\Input\InputStream;
 use Org\Mxchange\CoreFramework\Stream\Output\OutputStreamer;
 use Org\Mxchange\CoreFramework\Stream\Output\OutputStream;
+use Org\Mxchange\CoreFramework\String\Utils\StringUtils;
 use Org\Mxchange\CoreFramework\Template\CompileableTemplate;
 use Org\Mxchange\CoreFramework\User\ManageableAccount;
 use Org\Mxchange\CoreFramework\Visitor\Visitor;
@@ -61,7 +64,7 @@ use \SplFileInfo;
  *
  * @author             Roland Haeder <webmaster@shipsimu.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 - 2019 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -84,6 +87,11 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
         */
        private static $hashLength = NULL;
 
+       /**
+        * Self-referencing instance
+        */
+       private static $instance = NULL;
+
        /**
         * The real class name
         */
@@ -269,16 +277,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
         */
        private $socketResource = false;
 
-       /**
-        * Regular expression to use for validation
-        */
-       private $regularExpression = '';
-
-       /**
-        * Package data
-        */
-       private $packageData = array();
-
        /**
         * Generic array
         */
@@ -389,6 +387,7 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
        const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x03c;
        const EXCEPTION_FILTER_CHAIN_INTERCEPTED     = 0x03d;
        const EXCEPTION_INVALID_SOCKET               = 0x03e;
+       const EXCEPTION_SELF_INSTANCE                = 0x03f;
 
        /**
         * Hexadecimal->Decimal translation array
@@ -498,22 +497,40 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
         * @return      void
         */
        public final function __call ($methodName, $args) {
-               return self::__callStatic($methodName, $args);
+               // Set self-instance
+               self::$instance = $this;
+
+               // Call static method
+               self::__callStatic($methodName, $args);
+
+               // Clear self-instance
+               self::$instance = NULL;
        }
 
        /**
         * The __callStatic() method where all non-implemented static methods end up
         *
         * @param       $methodName             Name of the missing method
-        * @args        $args                   Arguments passed to the method
+        * @param       $args                   Arguments passed to the method
         * @return      void
+        * @throws      InvalidArgumentException If self::$instance is not a framework's own object
         */
        public static final function __callStatic ($methodName, $args) {
                // Trace message
                //* PRINT-DEBUG: */ printf('[%s:%d]: methodName=%s,args[]=%s - CALLED!' . PHP_EOL, __METHOD__, __LINE__, $methodName, gettype($args));
 
-               // Init argument string
+               // Init argument string and class name
                $argsString = '';
+               $className = 'unknown';
+
+               // Is self-instance set?
+               if (self::$instance instanceof FrameworkInterface) {
+                       // Framework's own instance
+                       $className = self::$instance->__toString();
+               } elseif (!is_null(self::$instance)) {
+                       // Invalid argument!
+                       throw new InvalidArgumentException(sprintf('self::instance[%s] is not expected.', gettype(self::$instance)), self::EXCEPTION_SELF_INSTANCE);
+               }
 
                // Is it NULL, empty or an array?
                if (is_null($args)) {
@@ -558,8 +575,9 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
                                $argsString .= ', ';
                        } // END - foreach
 
-                       // Remove last comma
+                       // Last comma found?
                        if (substr($argsString, -2, 1) == ',') {
+                               // Remove last comma
                                $argsString = substr($argsString, 0, -2);
                        } // END - if
 
@@ -567,12 +585,13 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
                        $argsString .= ')';
                } else {
                        // Invalid arguments!
-                       $argsString = '!INVALID:' . gettype($args) . '!';
+                       $argsString = sprintf('!INVALID:%s!', gettype($args));
                }
 
                // Output stub message
                // @TODO __CLASS__ does always return BaseFrameworkSystem but not the extending (=child) class
-               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[unknown::%s]: Stub! Args: %s',
+               self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s::%s]: Stub! Args: %s',
+                       $className,
                        $methodName,
                        $argsString
                ));
@@ -873,26 +892,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
                return $compressorInstance;
        }
 
-       /**
-        * Protected getter for a manageable application helper class
-        *
-        * @return      $applicationInstance    An instance of a manageable application helper class
-        */
-       protected final function getApplicationInstance () {
-               $applicationInstance = GenericRegistry::getRegistry()->getInstance('application');
-               return $applicationInstance;
-       }
-
-       /**
-        * Setter for a manageable application helper class
-        *
-        * @param       $applicationInstance    An instance of a manageable application helper class
-        * @return      void
-        */
-       public final function setApplicationInstance (ManageableApplication $applicationInstance) {
-               GenericRegistry::getRegistry()->addInstance('application', $applicationInstance);
-       }
-
        /**
         * Private getter for language instance
         *
@@ -1163,27 +1162,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
                return $this->socketResource;
        }
 
-       /**
-        * Setter for regular expression
-        *
-        * @param       $regularExpression      A valid regular expression
-        * @return      void
-        */
-       public final function setRegularExpression ($regularExpression) {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression=' . $regularExpression . ',previous[' . gettype($this->regularExpression) . ']=' . $this->regularExpression);
-               $this->regularExpression = $regularExpression;
-       }
-
-       /**
-        * Getter for regular expression
-        *
-        * @return      $regularExpression      A valid regular expression
-        */
-       public final function getRegularExpression () {
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($this->__toString() . '::' . __FUNCTION__ . ': regularExpression[' . gettype($this->regularExpression) . ']=' . $this->regularExpression);
-               return $this->regularExpression;
-       }
-
        /**
         * Setter for helper instance
         *
@@ -1279,26 +1257,6 @@ abstract class BaseFrameworkSystem extends stdClass implements FrameworkInterfac
                return $this->visitorInstance;
        }
 
-       /**
-        * Setter for raw package Data
-        *
-        * @param       $packageData    Raw package Data
-        * @return      void
-        */
-       public final function setPackageData (array $packageData) {
-               $this->packageData = $packageData;
-       }
-
-       /**
-        * Getter for raw package Data
-        *
-        * @return      $packageData    Raw package Data
-        */
-       public function getPackageData () {
-               return $this->packageData;
-       }
-
-
        /**
         * Setter for Iterator instance
         *
@@ -1722,9 +1680,9 @@ Loaded includes:
         */
        protected function partialStub ($message = '') {
                // Init variable
-               $stubMessage = 'Partial Stub!';
+               $stubMessage = 'Partial stub!';
 
-               // Is the extra message given?
+               // Is an extra message given?
                if (!empty($message)) {
                        // Then add it as well
                        $stubMessage .= ' Message: ' . $message;
@@ -1895,7 +1853,7 @@ Loaded includes:
                $className = '';
 
                // Convert all dashes in underscores
-               $str = self::convertDashesToUnderscores($str);
+               $str = StringUtils::convertDashesToUnderscores($str);
 
                // Now use that underscores to get classname parts for hungarian style
                foreach (explode('_', $str) as $strPart) {
@@ -1907,34 +1865,6 @@ Loaded includes:
                return $className;
        }
 
-       /**
-        * Converts dashes to underscores, e.g. useable for configuration entries
-        *
-        * @param       $str    The string with maybe dashes inside
-        * @return      $str    The converted string with no dashed, but underscores
-        * @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);
-
-               // Return converted string
-               return $str;
-       }
-
        /**
         * Marks up the code by adding e.g. line numbers
         *
@@ -2097,7 +2027,7 @@ Loaded includes:
                //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput($fieldName.':<pre>'.print_r($fieldArray, true).'</pre>');
 
                // Convert dashes to underscore
-               $fieldName2 = self::convertDashesToUnderscores($fieldName);
+               $fieldName2 = StringUtils::convertDashesToUnderscores($fieldName);
 
                // Does the field exist?
                if ($this->isFieldSet($fieldName)) {
@@ -2137,7 +2067,7 @@ Loaded includes:
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('[' . $this->__toString() . ':' . __LINE__ . '] fieldName=' . $fieldName . ',fieldArray=<pre>'.print_r($fieldArray, true).'</pre>');
 
                // Convert dashes to underscore
-               $fieldName = self::convertDashesToUnderscores($fieldName);
+               $fieldName = StringUtils::convertDashesToUnderscores($fieldName);
 
                // Determine it
                $isSet = isset($fieldArray[$fieldName]);