]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/class_BaseFrameworkSystem.php
createUniqueID -> generateUniqueId renamed, dataset criteria added, registration...
[shipsimu.git] / inc / classes / main / class_BaseFrameworkSystem.php
index 9db30498b2b1fb6dd8ded9e163ca2b124fb06069..f61deb85c47df5f02c5e04f8bc78c8f8004994bc 100644 (file)
@@ -148,6 +148,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        const EXCEPTION_INVALID_COMMAND              = 0x031;
        const EXCEPTION_INVALID_CONTROLLER           = 0x032;
        const EXCEPTION_HEADERS_ALREADY_SENT         = 0x033;
+       const EXCEPTION_DEFAUL_CONTROLLER_GONE       = 0x034;
+       const EXCEPTION_CLASS_NOT_FOUND              = 0x035;
+       const EXCEPTION_REQUIRED_INTERFACE_MISSING   = 0x036;
 
        /**
         * In the super constructor these system classes shall be ignored or else
@@ -217,8 +220,53 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        public final function __call ($methodName, $args) {
                // Implode all given arguments
-               $argsString = implode("|", $args);
-               if (empty($argsString)) $argsString = "NULL";
+               $argsString = "";
+               if (empty($args)) {
+                       // No arguments
+                       $argsString = "NULL";
+               } elseif (is_array($args)) {
+                       // Some arguments are there
+                       foreach ($args as $arg) {
+                               // Check the type
+                               if (is_bool($arg)) {
+                                       // Boolean!
+                                       if ($arg) $argsString .= "true(bool)"; else $argsString .= "false(bool)";
+                               } elseif (is_int($arg)) {
+                                       // Integer
+                                       $argsString .= $arg."(int)";
+                               } elseif (is_float($arg)) {
+                                       // Floating point
+                                       $argsString .= $arg."(float)";
+                               } elseif ($arg instanceof BaseFrameworkSystem) {
+                                       // Own object instance
+                                       $argsString .= $arg->__toString()."(Object)";
+                               } elseif (is_object($arg)) {
+                                       // External object
+                                       $argsString .= "unknown object(!)";
+                               } elseif (is_array($arg)) {
+                                       // Array
+                                       $argsString .= "Array(array)";
+                               } elseif (is_string($arg)) {
+                                       // String
+                                       $argsString .= "\"".$arg."\"(string)";
+                               } elseif (is_null($arg)) {
+                                       // Null
+                                       $argsString .= "(null)";
+                               } else {
+                                       // Unknown type (please report!)
+                                       $argsString .= $arg."(unknown!)";
+                               }
+
+                               // Add comma
+                               $argsString .= ", ";
+                       }
+
+                       // Remove last comma
+                       if (substr($argsString, -2, 1) === ",") $argsString = substr($argsString, 0, -2);
+               } else {
+                       // Invalid arguments!
+                       $argsString = sprintf("!INVALID:%s!", $args);
+               }
 
                $this->getDebugInstance()->output(sprintf("[%s::%s] Stub! Args: %s",
                        $this->__toString(),
@@ -244,16 +292,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                        // Initialize debug instance
                        if (is_null($this->getDebugInstance())) {
                                // Set the debug output system if it is not debug class ;)
-                               $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig("debug_engine")));
+                               $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig('debug_engine')));
                        }
 
                        // Initialize web instance
                        if (is_null($this->getWebOutputInstance())) {
                                // Generate the eval() command
                                $eval = sprintf("\$this->setWebOutputInstance(%s::create%s(\"%s\"));",
-                                       $this->getConfigInstance()->readConfig("web_engine"),
-                                       $this->getConfigInstance()->readConfig("web_engine"),
-                                       $this->getConfigInstance()->readConfig("web_content_type")
+                                       $this->getConfigInstance()->readConfig('web_engine'),
+                                       $this->getConfigInstance()->readConfig('web_engine'),
+                                       $this->getConfigInstance()->readConfig('web_content_type')
                                );
 
                                // Debug message
@@ -271,7 +319,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                                // Set the compressor channel
                                $this->setCompressorChannel(CompressorChannel::createCompressorChannel(sprintf("%s%s",
                                        PATH,
-                                       $this->getConfigInstance()->readConfig("compressor_base_path")
+                                       $this->getConfigInstance()->readConfig('compressor_base_path')
                                )));
                        }
 
@@ -303,7 +351,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         *
         * @return      $cfhInstance - Configuration instance
         */
-       public final function getConfigInstance () {
+       protected final function getConfigInstance () {
                return self::$cfgInstance;
        }
 
@@ -384,7 +432,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         *
         * @return      void
         */
-       public final function createUniqueID () {
+       public final function generateUniqueId () {
                // Existiert noch keine?
                if (empty($this->uniqueID)) {
 
@@ -584,10 +632,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * Formats computer generated price values into human-understandable formats
         * with thousand and decimal seperators.
         *
-        * @param               $value  The in computer format value for a price
-        * @param               $currency       The currency symbol (use HTML-valid characters!)
-        * @param               $decNum Number of decimals after commata
-        * @return      $price  The for the current language formated price string
+        * @param       $value          The in computer format value for a price
+        * @param       $currency       The currency symbol (use HTML-valid characters!)
+        * @param       $decNum         Number of decimals after commata
+        * @return      $price          The for the current language formated price string
         * @throws      MissingDecimalsThousandsSeperatorException      If decimals or
         *                                                                                              thousands seperator
         *                                                                                              is missing
@@ -730,7 +778,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         *
         * @return      $fileIOInstance An instance to the file I/O sub-system
         */
-       protected final function getFileIOInstance () {
+       protected final function getFileIoInstance () {
                return $this->fileIOInstance;
        }
 
@@ -740,7 +788,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @param       $fileIOInstance An instance to the file I/O sub-system
         * @return      void
         */
-       public final function setFileIOInstance (FileIOHandler $fileIOInstance) {
+       public final function setFileIoInstance (FileIoHandler $fileIOInstance) {
                $this->fileIOInstance = $fileIOInstance;
        }
 
@@ -795,16 +843,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Generate FQFN for all application templates
                $fqfn = sprintf("%s%s/%s/%s",
                        PATH,
-                       $this->getConfigInstance()->readConfig("application_path"),
+                       $this->getConfigInstance()->readConfig('application_path'),
                        strtolower($appInstance->getAppShortName()),
-                       $this->getConfigInstance()->readConfig("tpl_base_path")
+                       $this->getConfigInstance()->readConfig('tpl_base_path')
                );
 
                // Are both instances set?
                if ($appInstance->getLanguageInstance() === null) {
                        // Invalid language instance
                        throw new MissingLanguageHandlerException($appInstance, self::EXCEPTION_MISSING_LANGUAGE_HANDLER);
-               } elseif ($appInstance->getFileIOInstance() === null) {
+               } elseif ($appInstance->getFileIoInstance() === null) {
                        // Invalid language instance
                        throw new MissingFileIoHandlerException($appInstance, self::EXCEPTION_MISSING_FILE_IO_HANDLER);
                }
@@ -814,10 +862,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                $eval = sprintf("\$tplEngine = %s::create%s(
        \"%s\",
        \$appInstance->getLanguageInstance(),
-       \$appInstance->getFileIOInstance()
+       \$appInstance->getFileIoInstance()
 );",
-                       $this->getConfigInstance()->readConfig("tpl_engine"),
-                       $this->getConfigInstance()->readConfig("tpl_engine"),
+                       $this->getConfigInstance()->readConfig('tpl_engine'),
+                       $this->getConfigInstance()->readConfig('tpl_engine'),
                        $fqfn
                );
 
@@ -852,10 +900,76 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        public final function debugInstance () {
                // Generate the output
-               $content = "<pre>".trim(print_r($this, true))."</pre>";
+               $content = sprintf("<pre>%s</pre>",
+                       trim(print_r($this, true))
+               );
 
                // Output it
-               ApplicationEntryPoint::app_die("<strong>Debug output:</strong>".$content);
+               ApplicationEntryPoint::app_die(sprintf("<strong>%s debug output:</strong>%s", $this->__toString(), $content));
+       }
+
+       /**
+        * Output a partial stub message for the caller method
+        *
+        * @param       $message        An optional message to display
+        * @return      void
+        */
+       protected function partialStub ($message = "") {
+               // Get the backtrace
+               $backtrace = debug_backtrace();
+
+               // Generate the class::method string
+               $methodName = "UnknownClass::unknownMethod";
+               if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
+                       $methodName = $backtrace[1]['class']."::".$backtrace[1]['function'];
+               }
+
+               // Construct the full message
+               $stubMessage = sprintf("[%s:] Partial stub!",
+                       $methodName
+               );
+
+               // Is the extra message given?
+               if (!empty($message)) {
+                       // Then add it as well
+                       $stubMessage .= sprintf(" Message: <u>%s</u>", $message);
+               }
+
+               // Debug instance is there?
+               if (!is_null($this->getDebugInstance())) {
+                       // Output stub message
+                       $this->getDebugInstance()->output($stubMessage);
+               } else {
+                       // Trigger an error
+                       trigger_error($stubMessage."<br />\n");
+               }
+       }
+
+       /**
+        * Converts e.g. a command from URL to a valid class by keeping out bad characters
+        *
+        * @param       $str            The string, what ever it is needs to be converted
+        * @return      $className      Generated class name
+        */
+       public function convertToClassName ($str) {
+               $className = "";
+               foreach (explode("_", $str) as $strPart) {
+                       $className .= ucfirst(strtolower($strPart));
+               }
+               return $className;
+       }
+
+       /**
+        * Outputs a debug backtrace and stops further script execution
+        *
+        * @return      void
+        */
+       public function debugBacktrace () {
+               // Sorry, there is no other way getting this nice backtrace
+               print "<pre>\n";
+               debug_print_backtrace();
+               print "</pre>";
+               exit;
        }
 }