Introduced new setter/getter and generic interface:
[core.git] / inc / classes / main / class_BaseFrameworkSystem.php
index 70ab046529da504a28c0a40d9e4d74e996bf4021..0eaddce17e5e361d872b15c72af8c3551ee0ee73 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
         */
@@ -123,6 +128,16 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        private $databaseInstance = null;
 
+       /**
+        * A helper instance for the form
+        */
+       private $helperInstance = null;
+
+       /**
+        * An instance of a source
+        */
+       private $sourceInstance = null;
+
        /**
         * The real class name
         */
@@ -219,9 +234,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 +245,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 +264,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 +283,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 +311,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 +608,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 +744,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
         */
@@ -794,7 +835,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 +855,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 +887,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 +1186,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 +1227,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
         *
@@ -1412,6 +1476,44 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                return $this->socketResource;
        }
 
+       /**
+        * Setter for helper instance
+        *
+        * @param       $helperInstance         An instance of a helper class
+        * @return      void
+        */
+       protected final function setHelperInstance (Helper $helperInstance) {
+               $this->helperInstance = $helperInstance;
+       }
+
+       /**
+        * Getter for helper instance
+        *
+        * @return      $helperInstance         An instance of a helper class
+        */
+       public final function getHelperInstance () {
+               return $this->helperInstance;
+       }
+
+       /**
+        * Setter for a Sourceable instance
+        *
+        * @param       $sourceInstance The Sourceable instance
+        * @return      void
+        */
+       protected final function setSourceInstance (Sourceable $sourceInstance) {
+               $this->sourceInstance = $sourceInstance;
+       }
+
+       /**
+        * Getter for a Sourceable instance
+        *
+        * @param       $sourceInstance The Sourceable instance
+        */
+       protected final function getSourceInstance () {
+               return $this->sourceInstance;
+       }
+
        /**
         * Setter for raw package Data
         *