Continued:
[core.git] / framework / main / classes / class_BaseFrameworkSystem.php
index ab26925d0d90fed6ed32147f1feb656d94e6f3f6..357f228a8f703cf6d6168591d695bbecbf784e09 100644 (file)
@@ -64,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
  *
@@ -87,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
         */
@@ -382,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
@@ -491,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)) {
@@ -551,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
 
@@ -560,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
                ));
@@ -1654,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;