Added magic methods __get/set(). Please watch these messages carefully
[core.git] / inc / classes / main / class_BaseFrameworkSystem.php
index f8dc6b851e1a48c6b81908b03ae924e5d01525e8..7d5ac4a8578bd043d1b3ccc55c79b264b1657b8d 100644 (file)
@@ -78,6 +78,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        private $rngInstance = null;
 
+       /**
+        * Instance of a crypto helper
+        */
+       private $cryptoInstance = null;
+
        /**
         * Instance of an Iterator class
         */
@@ -219,9 +224,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Set real class
                $this->setRealClass($className);
 
-               // Set configuration instance if no registry
+               // Set configuration instance if no registry ...
                if (!$this instanceof Register) {
-                       // Because registries doesn't need to be configured
+                       // ... because registries doesn't need to be configured
                        $this->setConfigInstance(FrameworkConfiguration::getInstance());
                } // END - if
        }
@@ -230,7 +235,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * Destructor reached...
         *
         * @return      void
-        * @todo        This is old code. Do we still need this old lost code?
         */
        public function __destruct() {
                // Flush any updated entries to the database
@@ -250,8 +254,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        }
 
        /**
-        * The call method where all non-implemented methods end up
+        * The __call() method where all non-implemented methods end up
         *
+        * @param       $methodName             Name of the missing method
+        * @args        $args                   Arguments passed to the method
         * @return      void
         */
        public final function __call ($methodName, $args) {
@@ -267,7 +273,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                                $argsString .= $this->replaceControlCharacters($arg) . ' (' . gettype($arg);
 
                                // Add length if type is string
-                               if (gettype($arg) == 'string') $argsString .= ', '.strlen($arg);
+                               if (is_string($arg)) {
+                                       $argsString .= ', '.strlen($arg);
+                               } // END - if
 
                                // Closing bracket
                                $argsString .= '), ';
@@ -293,6 +301,42 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return null;
        }
 
+       /**
+        * Getter for $realClass
+        *
+        * @return      $realClass The name of the real class (not BaseFrameworkSystem)
+        */
+       public function __toString () {
+               return $this->realClass;
+       }
+
+       /**
+        * Magic function to catch setting of missing but set class fields/attributes
+        *
+        * @param       $name   Name of the field/attribute
+        * @param       $value  Value to store
+        * @return      void
+        */
+       public final function __set ($name, $value) {
+               $this->debugOutput(sprintf("Tried to set a missing field. name=%s, value[%s]=%s",
+                       $name,
+                       gettype($value),
+                       $value
+               ));
+       }
+
+       /**
+        * Magic function to catch getting of missing fields/attributes
+        *
+        * @param       $name   Name of the field/attribute
+        * @return      void
+        */
+       public final function __get ($name) {
+               $this->debugOutput(sprintf("Tried to get a missing field. name=%s",
+                       $name
+               ));
+       }
+
        /**
         * Setter for database result instance
         *
@@ -554,15 +598,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $this->responseInstance;
        }
 
-       /**
-        * Getter for $realClass
-        *
-        * @return      $realClass The name of the real class (not BaseFrameworkSystem)
-        */
-       public function __toString () {
-               return $this->realClass;
-       }
-
        /**
         * Setter for the real class name
         *
@@ -699,10 +734,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @param               $applicationInstance    An application helper instance or
         *                                                                              null if we shall use the default
         * @return              $templateInstance               The template engine instance
-        * @throws              NullPointerException    If the template engine could not
-        *                                                                              be initialized
-        * @throws              UnsupportedTemplateEngineException      If $templateInstance is an
-        *                                                                              unsupported template engine
         * @throws              NullPointerException    If the discovered application
         *                                                                              instance is still null
         */
@@ -720,7 +751,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                } // END - if
 
                // Initialize the template engine
-               $templateInstance = ObjectFactory::createObjectByConfiguredName('web_template_class', array($applicationInstance));
+               $templateInstance = ObjectFactory::createObjectByConfiguredName('web_template_class');
 
                // Return the prepared instance
                return $templateInstance;
@@ -794,7 +825,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Generate the class::method string
                $methodName = 'UnknownClass->unknownMethod';
                if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
-                       $methodName = $backtrace[1]['class']."->".$backtrace[1]['function'];
+                       $methodName = $backtrace[1]['class'] . '->' . $backtrace[1]['function'];
                } // END - if
 
                // Construct the full message
@@ -814,7 +845,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                        $this->debugOutput($stubMessage);
                } else {
                        // Trigger an error
-                       trigger_error($stubMessage."<br />\n");
+                       trigger_error($stubMessage . "<br />\n");
                }
        }
 
@@ -846,7 +877,11 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                if (is_object($debugInstance)) {
                        // Use debug output handler
                        $debugInstance->output($message);
-                       if ($doPrint === false) die(); // Die here if not printed
+
+                       if ($doPrint === false) {
+                               // Die here if not printed
+                               die();
+                       } // END - if
                } else {
                        // Put directly out
                        if ($doPrint === true) {
@@ -1141,7 +1176,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                                $this->debugOutput($message);
                        } else {
                                // Trigger an error
-                               trigger_error($message."<br />\n");
+                               trigger_error($message . "<br />\n");
                        }
                } else {
                        // @TODO Finish this part!
@@ -1182,6 +1217,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $this->rngInstance;
        }
 
+       /**
+        * Setter for Cryptable instance
+        *
+        * @param       $cryptoInstance An instance of a Cryptable class
+        * @return      void
+        */
+       protected final function setCryptoInstance (Cryptable $cryptoInstance) {
+               $this->cryptoInstance = $cryptoInstance;
+       }
+
+       /**
+        * Getter for Cryptable instance
+        *
+        * @return      $cryptoInstance An instance of a Cryptable class
+        */
+       public final function getCryptoInstance () {
+               return $this->cryptoInstance;
+       }
+
        /**
         * Setter for Iterator instance
         *