Added translateBooleanToYesNo().
[core.git] / inc / classes / main / class_BaseFrameworkSystem.php
index 502ee84a7ec6eab5fb964c6eaa0b7d599978c11e..78cdde3f367828f3e4f7cf12e015b9b3e5e3e561 100644 (file)
@@ -3,11 +3,11 @@
  * The simulator system class is the super class of all other classes. This
  * class handles saving of games etc.
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.org
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -249,6 +249,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        const EXCEPTION_ARRAY_ELEMENTS_MISSING       = 0x02c;
        const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED  = 0x02d;
        const EXCEPTION_UNSPPORTED_OPERATION         = 0x02e;
+       const EXCEPTION_FACTORY_REQUIRE_PARAMETER    = 0x02f;
        const EXCEPTION_MISSING_ELEMENT              = 0x030;
        const EXCEPTION_HEADERS_ALREADY_SENT         = 0x031;
        const EXCEPTION_DEFAULT_CONTROLLER_GONE      = 0x032;
@@ -259,7 +260,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        const EXCEPTION_ASSERTION_FAILED             = 0x037;
        const EXCEPTION_FILE_CANNOT_BE_READ          = 0x038;
        const EXCEPTION_DATABASE_UPDATED_NOT_ALLOWED = 0x039;
-       const EXCEPTION_FILTER_CHAIN_INTERCEPTED     = 0x040;
+       const EXCEPTION_FILTER_CHAIN_INTERCEPTED     = 0x03a;
 
        /**
         * Hexadecimal->Decimal translation array
@@ -355,6 +356,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                } else {
                        // Do not call this twice
                        trigger_error(__METHOD__ . ': Called twice.');
+                       exit;
                }
        }
 
@@ -1410,6 +1412,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                } else {
                        // Trigger an error
                        trigger_error($stubMessage);
+                       exit;
                }
        }
 
@@ -1444,20 +1447,29 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      $debugInstance  An instance of a debugger class
         */
        public final static function createDebugInstance ($className) {
-               // Init debug instance
-               $debugInstance = NULL;
+               // Is the instance set?
+               if (!Registry::getRegistry()->instanceExists('debug')) {
+                       // Init debug instance
+                       $debugInstance = NULL;
+
+                       // Try it
+                       try {
+                               // Get a debugger instance
+                               $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_class'));
+                       } catch (NullPointerException $e) {
+                               // Didn't work, no instance there
+                               exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage());
+                       }
 
-               // Try it
-               try {
-                       // Get a debugger instance
-                       $debugInstance = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getSelfInstance()->getConfigEntry('debug_class'));
-               } catch (NullPointerException $e) {
-                       // Didn't work, no instance there
-                       exit('Cannot create debugInstance! Exception=' . $e->__toString() . ', message=' . $e->getMessage());
-               }
+                       // Empty string should be ignored and used for testing the middleware
+                       DebugMiddleware::getSelfInstance()->output('');
 
-               // Empty string should be ignored and used for testing the middleware
-               DebugMiddleware::getSelfInstance()->output('');
+                       // Set it in its own class. This will set it in the registry
+                       $debugInstance->setDebugInstance($debugInstance);
+               } else {
+                       // Get instance from registry
+                       $debugInstance = Registry::getRegistry()->getDebugInstance();
+               }
 
                // Return it
                return $debugInstance;
@@ -1775,6 +1787,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                        } else {
                                // Trigger an error
                                trigger_error($message . "<br />\n");
+                               exit;
                        }
                } else {
                        // @TODO Finish this part!
@@ -2017,7 +2030,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = array()) {
                // Generate it
-               $cacheKey = sprintf("%s@%s",
+               $cacheKey = sprintf('%s@%s',
                        $this->__toString(),
                        $criteriaInstance->getCacheKey($onlyKeys)
                );
@@ -2198,6 +2211,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
                        // No, then abort here
                        trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
+                       exit;
                } // END - if
 
                // Debug message
@@ -2304,6 +2318,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (($forceInit === FALSE) && ($this->isGenericArrayGroupSet($keyGroup, $subGroup))) {
                        // Already initialized
                        trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' already initialized.');
+                       exit;
                } // END - if
 
                // Initialize it
@@ -2327,6 +2342,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (($forceInit === FALSE) && ($this->isGenericArrayKeySet($keyGroup, $subGroup, $key))) {
                        // Already initialized
                        trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' already initialized.');
+                       exit;
                } // END - if
 
                // Initialize it
@@ -2351,6 +2367,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (($forceInit === FALSE) && ($this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element))) {
                        // Already initialized
                        trigger_error(__METHOD__ . ':keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' already initialized.');
+                       exit;
                } // END - if
 
                // Initialize it
@@ -2430,6 +2447,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
                        // Not found
                        trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
+                       exit;
                } // END - if
 
                // Then "pop" it
@@ -2457,6 +2475,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
                        // Not found
                        trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' not found.');
+                       exit;
                } // END - if
 
                // Then "shift" it
@@ -2482,6 +2501,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (!isset($this->genericArray[$keyGroup])) {
                        // Abort here
                        trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' not found.');
+                       exit;
                } // END - if
 
                // Then count it
@@ -2509,6 +2529,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (!$this->isGenericArrayGroupSet($keyGroup, $subGroup)) {
                        // Abort here
                        trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
+                       exit;
                } // END - if
 
                // Then count it
@@ -2537,9 +2558,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
                        // Abort here
                        trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' not found.');
+                       exit;
                } elseif (!$this->isValidGenericArrayGroup($keyGroup, $subGroup)) {
                        // Not valid
                        trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ' is not an array.');
+                       exit;
                }
 
                // Then count it
@@ -2566,6 +2589,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (!isset($this->genericArray[$keyGroup])) {
                        // Then abort here
                        trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ' does not exist.');
+                       exit;
                } // END - if
 
                // Return it
@@ -2605,6 +2629,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (!$this->isGenericArrayKeySet($keyGroup, $subGroup, $key)) {
                        // Then abort here
                        trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ' does not exist.');
+                       exit;
                } // END - if
 
                // Return it
@@ -2646,6 +2671,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (!$this->isGenericArrayElementSet($keyGroup, $subGroup, $key, $element)) {
                        // Then abort here
                        trigger_error(__METHOD__ . ': keyGroup=' . $keyGroup . ',subGroup=' . $subGroup . ',key=' . $key . ',element=' . $element . ' does not exist.');
+                       exit;
                } // END - if
 
                // Return it
@@ -2688,6 +2714,23 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Return it
                return $isValid;
        }
+
+       /**
+        * Translates boolean TRUE to 'Y' and FALSE to 'N'
+        *
+        * @param       $boolean                Boolean value
+        * @return      $translated             Translated boolean value
+        */
+       public static final function translateBooleanToYesNo ($boolean) {
+               // Make sure it is really boolean
+               assert(is_bool($boolean));
+
+               // "Translate" it
+               $translated = ($boolean === TRUE) ? 'Y' : 'N';
+
+               // ... and return it
+               return $translated;
+       }
 }
 
 // [EOF]