Rewrite of initInstance(), more eval() rewritten to call_user_func_array()
authorRoland Häder <roland@mxchange.org>
Mon, 9 Jun 2008 20:47:13 +0000 (20:47 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 9 Jun 2008 20:47:13 +0000 (20:47 +0000)
16 files changed:
application/selector/starter.php
application/ship-simu/init.php
application/ship-simu/starter.php
inc/classes/interfaces/database/class_FrameworkDatabaseInterface.php
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/factories/objects/class_ObjectFactory.php
inc/classes/main/io/class_FrameworkDirectoryPointer.php
inc/classes/main/output/class_WebOutput.php
inc/classes/main/registry/class_Registry.php
inc/classes/middleware/compressor/class_CompressorChannel.php
inc/classes/middleware/database/class_DatabaseConnection.php
inc/classes/middleware/debug/class_DebugMiddleware.php
inc/config.php
inc/config/class_FrameworkConfiguration.php
inc/loader/class_ClassLoader.php
index.php

index ca9d294..dab9479 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Starter of the application
+ * The application launcher
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
@@ -22,8 +22,9 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
-// Get the application helper instance
-$app = ApplicationHelper::getInstance();
+// Is there an application helper instance? We need the method main() for
+// maining the application
+$app = call_user_func_array(array(FrameworkConfiguration::getInstance()->readConfig('app_helper_class'), "getInstance"), array());
 
 // Some sanity checks
 if ((empty($app)) || (is_null($app))) {
@@ -47,11 +48,8 @@ if ((empty($app)) || (is_null($app))) {
 
 // Call the entry point method
 try {
-       $eval = sprintf("%s::getInstance()->%s();",
-               FrameworkConfiguration::getInstance()->readConfig('app_helper_class'),
-               FrameworkConfiguration::getInstance()->readConfig('entry_method')
-       );
-       eval($eval);
+       // Call user function
+       call_user_func_array(array($app, FrameworkConfiguration::getInstance()->readConfig('entry_method')), array());
 } catch (FrameworkException  $e) {
        ApplicationEntryPoint::app_die(sprintf("[Main:] The application <strong>%s</strong> could not be launched for the follwing reason: <strong>%s</strong>",
                $application,
index 431e442..0f9ff1d 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
+// Initialize output system
+require(PATH . 'inc/output.php');
+
+// Initialize file i/o system
+require(PATH . 'inc/file_io.php');
+
+// Include the language sub-system
+require(PATH . 'inc/language.php');
+
+// This application needs a database connection then we have to simply include
+// the inc/database.php script
+require(PATH . 'inc/database.php');
+
 // Generate call-back function
 $callback = sprintf("%s::getInstance",
        FrameworkConfiguration::getInstance()->readConfig('app_helper_class')
@@ -46,20 +59,10 @@ $app->setAppName("Ship-Simu Schiffsimulator");
 $app->setAppVersion("0.0.0");
 $app->setAppShortName("ship-simu");
 
-// Initialize output system
-require(PATH . 'inc/output.php');
-
-// Initialize file i/o system
-require(PATH . 'inc/file_io.php');
+// Set instances
 $app->setFileIoInstance($io);
-
-// Include the language sub-system
-require(PATH . 'inc/language.php');
 $app->setLanguageInstance($lang);
-
-// This application needs a database connection then we have to simply include
-// the inc/database.php script
-require(PATH . 'inc/database.php');
+$app->setDatabaseInstance($db);
 
 // [EOF]
 ?>
index 468848d..dab9479 100644 (file)
@@ -24,7 +24,7 @@
 
 // Is there an application helper instance? We need the method main() for
 // maining the application
-$app = ApplicationHelper::getInstance();
+$app = call_user_func_array(array(FrameworkConfiguration::getInstance()->readConfig('app_helper_class'), "getInstance"), array());
 
 // Some sanity checks
 if ((empty($app)) || (is_null($app))) {
@@ -48,11 +48,8 @@ if ((empty($app)) || (is_null($app))) {
 
 // Call the entry point method
 try {
-       $eval = sprintf("%s::getInstance()->%s();",
-               FrameworkConfiguration::getInstance()->readConfig('app_helper_class'),
-               FrameworkConfiguration::getInstance()->readConfig('entry_method')
-       );
-       eval($eval);
+       // Call user function
+       call_user_func_array(array($app, FrameworkConfiguration::getInstance()->readConfig('entry_method')), array());
 } catch (FrameworkException  $e) {
        ApplicationEntryPoint::app_die(sprintf("[Main:] The application <strong>%s</strong> could not be launched for the follwing reason: <strong>%s</strong>",
                $application,
index d1a3266..c5cf54e 100644 (file)
  */
 interface FrameworkDatabaseInterface extends FrameworkInterface {
        /**
-        * Saves a whole object by serializing it entirely or some specifyable
-        * parts. Specifying parts must be done before this method is called. If
-        * it is not done this method will serialize the whole object.
-        *
-        * @param               $object An instance to the object we want to save
-        * @return      void
-        * @see         limitObject(ObjectLimits)       limitObject
-        * @deprecated
-        */
-       function saveObject (FrameworkInterface $object);
-
-       /**
         * Analyses if a unique ID has already been used or not. This method does
         * only pass the given ID through to the "real" database layer.
         *
@@ -50,22 +38,6 @@ interface FrameworkDatabaseInterface extends FrameworkInterface {
         *                                                              isUniqueIdUsed() was not found
         */
        function isUniqueIdUsed ($uniqueID, $inConstructor = false);
-
-       /**
-        * Gets cached data from the database layer and if not found fetch it from
-        * the database again. This method does not return the header stuff because
-        * The underlaying database class will return only the requested content.
-        *
-        * @param               $idNumber               The ID number which we need for looking up
-        *                                              the requested data
-        * @return      $cachedArray    The maybe cached data from the database
-        * @throws      NullPointerException    If $dbInstance is null
-        * @throws      NoObjectException               If $dbInstance is not an object
-        * @throws      MissingMethodException  If the required method
-        *                                                              isUniqueIdUsed() was not found
-        * @deprecated
-        */
-       function getObjectFromCachedData ($idNumber);
 }
 
 // [EOF]
index bc9b5bb..2a0c807 100644 (file)
  */
 class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        /**
-        * The instance to the debug output handler (should be DebugConsoleOutput or DebugWebOutput)
-        *
-        * @see         DebugConsoleOutput
-        * @see         DebugWebOutput
-        */
-       private static $debug       = null;
-
-       /**
-        * The instance to the web output handler (should be WebOutput)
-        *
-        * @see         WebOutput
-        */
-       private static $webOutput   = null;
-
-       /**
-        * The instance to the compression layer which should be CompressorChannel
-        */
-       private static $compressor  = null;
-
-       /**
-        * The configuration instance which shall be FrameworkConfiguration
-        */
-       private static $cfgInstance = null;
-
-       /**
-        * The instance to the database layer which should be DatabaseConnection
+        * Instance to an application helper class
         */
-       private $dbInstance  = null;
+       private static $applicationInstance = null;
 
        /**
-        * Instance to an application helper class
+        * The language instance for the template loader
         */
-       private $applicationInstance = null;
+       private static $langInstance = null;
 
        /**
         * The real class name
@@ -84,11 +59,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        private $decimals  = ","; // German
 
        /**
-        * The language instance for the template loader
-        */
-       private $langInstance = null;
-
-       /**
         * The file I/O instance for the template loader
         */
        private $fileIOInstance = null;
@@ -162,18 +132,22 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         */
        private $systemClasses = array(
                "DebugMiddleware",                              // Debug middleware output sub-system
+               "Registry",                                             // Object registry
+               "ObjectFactory",                                // Object factory
                "DebugWebOutput",                               // Debug web output sub-system
+               "WebOutput",                                    // Web output sub-system
+               "CompressorChannel",                    // Compressor sub-system
                "DebugConsoleOutput",                   // Debug console output sub-system
                "DebugErrorLogOutput",                  // Debug error_log() output sub-system
-               "CompressorChannel",                    // Compressor sub-system
                "FrameworkDirectoryPointer",    // Directory handler sub-system
                "NullCompressor",                               // Null compressor
                "Bzip2Compressor",                              // BZIP2 compressor
                "GzipCompressor",                               // GZIP compressor
-               "WebOutput",                                    // Web output sub-system
-               "ObjectFactory",                                // Object factory
        );
 
+       /* No longer used:
+       */
+
        /**
         * Private super constructor
         *
@@ -183,8 +157,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Set real class
                $this->setRealClass($class);
 
-               // Init this instance
-               $this->initInstance($class);
+               // Initialize the class if the registry is there
+               if ((class_exists('Registry')) && (Registry::isInitialized() === false)) {
+                       $this->initInstance();
+               }
        }
 
        /**
@@ -280,50 +256,35 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        }
 
        /**
-        * Initializes the instance
+        * Private initializer for this class
         *
         * @return      void
         */
-       public function initInstance ($class) {
-               // Get the current (singleton) configuration instance
-               $this->setConfigInstance(FrameworkConfiguration::createFrameworkConfiguration());
-
-               // Is the class weather debug nor compressor channel?
-               if (!in_array($class, $this->systemClasses)) {
-                       // 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')));
-                       } // END - if
-
-                       // Initialize web instance
-                       if (is_null($this->getWebOutputInstance())) {
-                               // Call our object factory
-                               $outputInstance = ObjectFactory::createObjectByConfiguredName('web_engine', array($this->getConfigInstance()->readConfig('web_content_type')));
-
-                               // And set the instance
-                               $this->setWebOutputInstance($outputInstance);
-                       } // END - if
-
-                       // Initialize compressor channel
-                       if (is_null($this->getCompressorChannel())) {
-                               // Set the compressor channel
-                               $this->setCompressorChannel(CompressorChannel::createCompressorChannel(sprintf("%s%s",
-                                       PATH,
-                                       $this->getConfigInstance()->readConfig('compressor_base_path')
-                               )));
-                       } // END - if
-
-                       // Initialize database middleware
-                       if (is_null($this->getDatabaseInstance())) {
-                               // Get the middleware instance
-                               $db = DatabaseConnection::getInstance();
-                               if (is_object($db)) {
-                                       // Set the database middleware
-                                       $this->setDatabaseInstance($db);
-                               } // END - if
-                       } // END - if
-               } // END - if
+       private final function initInstance () {
+               // Is this a system class?
+               if (!in_array($this->__toString(), $this->systemClasses)) {
+                       // Add application helper to our class
+                       $this->systemclasses[] = $this->getConfigInstance()->readConfig('app_helper_class');
+
+                       // Set debug instance
+                       $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig('debug_engine')));
+
+                       // Get output instance and set it
+                       $outputInstance = ObjectFactory::createObjectByConfiguredName('web_engine', array($this->getConfigInstance()->readConfig('web_content_type')));
+                       $this->setWebOutputInstance($outputInstance);
+
+                       // Set the compressor channel
+                       $this->setCompressorChannel(CompressorChannel::createCompressorChannel(sprintf("%s%s",
+                               PATH,
+                               $this->getConfigInstance()->readConfig('compressor_base_path')
+                       )));
+
+                       // Initialization done! :D
+                       Registry::isInitialized("OK");
+               } elseif ($this->__toString() == "DebugMiddleware") {
+                       // Set configuration instance
+                       $this->setConfigInstance(FrameworkConfiguration::createFrameworkConfiguration());
+               }
        }
 
        /**
@@ -334,7 +295,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      void
         */
        public final function setConfigInstance (FrameworkConfiguration $configInstance) {
-               self::$cfgInstance = $configInstance;
+               Registry::getRegistry()->addInstance('config', $configInstance);
        }
 
        /**
@@ -343,7 +304,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      $cfhInstance - Configuration instance
         */
        protected final function getConfigInstance () {
-               return self::$cfgInstance;
+               return Registry::getRegistry()->getInstance('config');
        }
 
        /**
@@ -353,7 +314,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      void
         */
        public final function setDebugInstance (DebugMiddleware $debugInstance) {
-               self::$debug = $debugInstance;
+               Registry::getRegistry()->addInstance('debug', $debugInstance);
        }
 
        /**
@@ -362,7 +323,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      $debug - Instance to class DebugConsoleOutput or DebugWebOutput
         */
        public final function getDebugInstance () {
-               return self::$debug;
+               return Registry::getRegistry()->getInstance('debug');
        }
 
        /**
@@ -372,7 +333,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      void
         */
        public final function setWebOutputInstance (OutputStreamer $webInstance) {
-               self::$webOutput = $webInstance;
+               Registry::getRegistry()->addInstance('web_output', $webInstance);
        }
 
        /**
@@ -381,18 +342,69 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      $webOutput - Instance to class WebOutput
         */
        public final function getWebOutputInstance () {
-               return self::$webOutput;
+               return Registry::getRegistry()->getInstance('web_output');
        }
 
        /**
-        * Static setter for database instance
+        * Setter for database instance
         *
         * @param               $dbInstance     The instance for the database connection
         *                                      (forced DatabaseConnection)
         * @return      void
         */
        public final function setDatabaseInstance (DatabaseConnection $dbInstance) {
-               $this->dbInstance = $dbInstance;
+               Registry::getRegistry()->addInstance('dbInstance', $dbInstance);
+       }
+
+       /**
+        * Getter for database layer
+        *
+        * @return      $dbInstance     The database layer instance
+        */
+       public final function getDatabaseInstance () {
+               if ((class_exists('Registry')) && (Registry::isInitialized() === true)) {
+                       return Registry::getRegistry()->getInstance('dbInstance');
+               } else {
+                       return null;
+               }
+       }
+
+       /**
+        * Setter for compressor channel
+        *
+        * @param               $compressorChannel      An instance of CompressorChannel
+        * @return      void
+        */
+       public final function setCompressorChannel (CompressorChannel $compressorChannel) {
+               Registry::getRegistry()->addInstance('compressor', $compressorChannel);
+       }
+
+       /**
+        * Getter for compressor channel
+        *
+        * @return      $compressor     The compressor channel
+        */
+       public final function getCompressorChannel () {
+               return Registry::getRegistry()->getInstance('compressor');
+       }
+
+       /**
+        * Protected getter for a manageable application helper class
+        *
+        * @return      $applicationInstance    An instance of a manageable application helper class
+        */
+       protected final function getApplicationInstance () {
+               return self::$applicationInstance;
+       }
+
+       /**
+        * Setter for a manageable application helper class
+        *
+        * @param       $applicationInstance    An instance of a manageable application helper class
+        * @return      void
+        */
+       public final function setApplicationInstance (ManageableApplication $applicationInstance) {
+               self::$applicationInstance = $applicationInstance;
        }
 
        /**
@@ -424,7 +436,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
         * @return      void
         */
        public final function generateUniqueId () {
-               // Existiert noch keine?
+               // Is the id set for this class?
                if (empty($this->uniqueID)) {
 
                        // Correct missing class name
@@ -434,7 +446,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                                $corrected = true;
                        }
 
-                       // Neue ID erstellen
+                       // Cache datbase instance
+                       $db = $this->getDatabaseInstance();
+
+                       // Generate new id
                        $tempID = false;
                        while (true) {
                                // Generate a unique ID number
@@ -443,8 +458,12 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
 
                                // Try to figure out if the ID number is not yet used
                                try {
-                                       if (is_object($this->getDatabaseInstance())) {
-                                               $isUsed = $this->getDatabaseInstance()->isUniqueIdUsed($tempID, true);
+                                       // Is this a registry?
+                                       if ($this->__toString() == "Registry") {
+                                               // Registry, then abort here
+                                               break;
+                                       } elseif (is_object($db)) {
+                                               $isUsed = $db->isUniqueIdUsed($tempID, true);
                                        }
                                } catch (FrameworkException $e) {
                                        // Catches all and ignores all ;-)
@@ -455,10 +474,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                                                $tempID !== false
                                        ) && (
                                                (
-                                                       $this->getDatabaseInstance() === null
+                                                       $db === null
                                                ) || (
                                                        (
-                                                               is_object($this->getDatabaseInstance())
+                                                               is_object($db)
                                                        ) && (
                                                                !$isUsed
                                                        )
@@ -662,31 +681,23 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        }
 
        /**
-        * Getter for database layer
+        * Private getter for language instance
         *
-        * @return      $dbInstance     The database layer instance
+        * @return      $langInstance   An instance to the language sub-system
         */
-       public final function getDatabaseInstance () {
-               return $this->dbInstance;
+       protected final function getLanguageInstance () {
+               return self::$langInstance;
        }
 
        /**
-        * Setter for compressor channel
+        * Setter for language instance
         *
-        * @param               $compressorChannel      An instance of CompressorChannel
+        * @param       $langInstance   An instance to the language sub-system
         * @return      void
+        * @see         LanguageSystem
         */
-       public final function setCompressorChannel (CompressorChannel $compressorChannel) {
-               self::$compressor = $compressorChannel;
-       }
-
-       /**
-        * Getter for compressor channel
-        *
-        * @return      $compressor     The compressor channel
-        */
-       public final function getCompressorChannel () {
-               return self::$compressor;
+       public final function setLanguageInstance (ManageableLanguage $langInstance) {
+               self::$langInstance = $langInstance;
        }
 
        /**
@@ -745,26 +756,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        }
 
        /**
-        * Private getter for language instance
-        *
-        * @return      $langInstance   An instance to the language sub-system
-        */
-       protected final function getLanguageInstance () {
-               return $this->langInstance;
-       }
-
-       /**
-        * Setter for language instance
-        *
-        * @param       $langInstance   An instance to the language sub-system
-        * @return      void
-        * @see         LanguageSystem
-        */
-       public final function setLanguageInstance (ManageableLanguage $langInstance) {
-               $this->langInstance = $langInstance;
-       }
-
-       /**
         * Private getter for file IO instance
         *
         * @return      $fileIOInstance An instance to the file I/O sub-system
@@ -784,25 +775,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
        }
 
        /**
-        * Protected getter for a manageable application helper class
-        *
-        * @return      $applicationInstance    An instance of a manageable application helper class
-        */
-       protected final function getApplicationInstance () {
-               return $this->applicationInstance;
-       }
-
-       /**
-        * Setter for a manageable application helper class
-        *
-        * @param       $applicationInstance    An instance of a manageable application helper class
-        * @return      void
-        */
-       public final function setApplicationInstance (ManageableApplication $applicationInstance) {
-               $this->applicationInstance = $applicationInstance;
-       }
-
-       /**
         * Prepare the template engine (TemplateEngine by default) for a given
         * application helper instance (ApplicationHelper by default).
         *
index 8fe592b..024020d 100644 (file)
  */
 class ObjectFactory extends BaseFactory {
        /**
+        * Total objects generated
+        */
+       private static $total = 0;
+
+       /**
         * Protected constructor
         *
         * @return      void
@@ -71,6 +76,9 @@ class ObjectFactory extends BaseFactory {
                // Run the user function
                $objectInstance = call_user_func_array($callback, $args);
 
+               // Count generated objects up
+               self::$total++;
+
                // Return the prepared instance
                return $objectInstance;
        }
@@ -92,6 +100,15 @@ class ObjectFactory extends BaseFactory {
                // Return the instance
                return $objectInstance;
        }
+
+       /**
+        * Static getter for total object count
+        *
+        * @return      $total  Total amount of generated objects
+        */
+       public final static function getTotal () {
+               return self::$total;
+       }
 }
 
 // [EOF]
index 79580df..6206023 100644 (file)
@@ -143,20 +143,8 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem {
         *
         * @return      string  Directory and/or file names read from the current
         *                                      directory pointer
-        * @throws      NullPointerException    If the directory pointer instance
-        *                                                              is not set by setPointer()
-        * @throws      InvalidDirectoryResourceException       If there is being set
-        *                                                                              an invalid directory resource
         */
        public function readRawDirectory () {
-               if (is_null($this->getPointer())) {
-                       // Pointer not initialized
-                       throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
-               } elseif (!is_resource($this->getPointer())) {
-                       // Pointer is not a valid resource!
-                       throw new InvalidDirectoryResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER);
-               }
-
                // Read data from the directory pointer and return it
                return readdir($this->getPointer());
        }
@@ -197,19 +185,8 @@ class FrameworkDirectoryPointer extends BaseFrameworkSystem {
         * to empty
         *
         * @return      void
-        * @throws      NullPointerException    If the directory pointer instance
-        *                                                              is not set by setPointer()
-        * @throws      InvalidDirectoryResourceException       If there is being set
         */
        public function closeDirectory () {
-               if (is_null($this->getPointer())) {
-                       // Pointer not initialized
-                       return;
-               } elseif (!is_resource($this->getPointer())) {
-                       // Pointer is not a valid resource!
-                       throw new InvalidDirectoryResourceException($this, self::EXCEPTION_INVALID_DIRECTORY_POINTER);
-               }
-
                // Close the directory pointer and reset the instance variable
                @closedir($this->getPointer());
                $this->setPointer(null);
index 799e9ed..6c86b62 100644 (file)
@@ -22,7 +22,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class WebOutput extends BaseFrameworkSystem implements OutputStreamer {
+class WebOutput extends BaseFrameworkSystem implements OutputStreamer, Registerable {
        /**
         * The instance for the singleton design pattern
         */
index a9e1a2a..a8abb50 100644 (file)
@@ -28,6 +28,11 @@ class Registry extends BaseFrameworkSystem implements Register {
        private static $selfInstance = null;
 
        /**
+        * Wether the registry is initialized
+        */
+       private static $initialized = false;
+
+       /**
         * Instance registry
         */
        private $instanceRegistry = array();
@@ -69,6 +74,22 @@ class Registry extends BaseFrameworkSystem implements Register {
        }
 
        /**
+        * Checks or sets wether the registry has been initialized. This had only be done once
+        *
+        * @param       $initialized    Wether the registry is initialized
+        * @return      $initialized    Wether the registry is initialized
+        */
+       public final static function isInitialized ($initialized = null) {
+               if (is_null($initialized)) {
+                       // Get status if initialized
+                       return self::$initialized;
+               } elseif (!is_null($initialized)) {
+                       // Registry is initialized!
+                       self::$initialized = true;
+               }
+       }
+
+       /**
         * Checks wether an instance key was found
         *
         * @param       $instanceKey    The key holding an instance in the registry
index 1a99985..b881426 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class CompressorChannel extends BaseMiddleware {
+class CompressorChannel extends BaseMiddleware implements Registerable {
        /**
         * Real compressor instance
         */
index 81b402f..0c42807 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, LimitableObject {
+class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Registerable {
        /**
         * Array for connection data
         */
@@ -96,34 +96,12 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Li
        }
 
        /**
-        * Save a whole object or parts of it to the database or local file
-        *
-        * @param       $object         The object we shall save
-        * @return      void
-        */
-       public function saveObject (FrameworkInterface $object) {
-               // Connect to the database
-               $this->dbLayer->connectToDatabase();
-
-               // For now just pipe it through to the database layer
-               $this->dbLayer->saveObject($object);
-       }
-
-       /**
-        * Set a limitation for the saving process. This shall be done before
-        * saveObject() is called else saveObject() shall save the whole object.
-        *
-        * @param       $limitInstance  An instance of ObjectLimits which contains
-        *                                                      elements we shall exclusivly include in
-        *                                                      saving process
+        * Setter for the real database layer
+        * @param       $dbLayer        An instance of the real database layer
         * @return      void
         */
-       public function limitObject (ObjectLimits $limitInstance) {
-               // Connect to the database
-               $this->dbLayer->connectToDatabase();
-
-               // For now we pipe this through to the real database instance
-               $this->dbLayer->limitObject($limitInstance);
+       public final function setDatabaseLayer (DatabaseFrontendInterface $dbLayer) {
+               $this->dbLayer = $dbLayer;
        }
 
        /**
@@ -146,32 +124,6 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Li
        }
 
        /**
-        * Gets cached data from the database layer and if not found fetch it from
-        * the database again. This method does not return the header stuff because
-        * the underlaying database class will return only the requested content.
-        *
-        * @param       $idNumber               The ID number which we need for looking up
-        *                                                      the requested data
-        * @return      $cachedArray    The maybe cached data from the database
-        */
-       public function getObjectFromCachedData ($idNumber) {
-               // Connect to the database
-               $this->dbLayer->connectToDatabase();
-
-               // Pass the returning result through
-               return $this->dbLayer->getObjectFromCachedData($idNumber);
-       }
-
-       /**
-        * Setter for the real database layer
-        * @param       $dbLayer        An instance of the real database layer
-        * @return      void
-        */
-       public final function setDatabaseLayer (DatabaseFrontendInterface $dbLayer) {
-               $this->dbLayer = $dbLayer;
-       }
-
-       /**
         * Runs a "select" statement on the database layer with given table name
         * and criteria. If this doesn't fail the result will be returned
         *
index 5c1e050..694dac6 100644 (file)
@@ -23,7 +23,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class DebugMiddleware extends BaseMiddleware {
+class DebugMiddleware extends BaseMiddleware implements Registerable {
        /**
         * The concrete output instance
         */
index 142093b..be9058a 100644 (file)
@@ -25,6 +25,8 @@
  */
 
 // Load the class from inc/config direktory
+@require_once(dirname(__FILE__) . '/classes/interfaces/class_FrameworkInterface.php');
+@require_once(dirname(__FILE__) . '/classes/interfaces/registry/class_Registerable.php');
 @require_once(dirname(__FILE__) . '/config/class_FrameworkConfiguration.php');
 
 // Get a new configuration instance
index 664107d..6bfc3a2 100644 (file)
@@ -25,7 +25,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class FrameworkConfiguration {
+class FrameworkConfiguration implements Registerable {
        /**
         * The framework's main configuration array which will be initialized with
         * hard-coded configuration data and might be overwritten/extended by
index a82f951..06d2bb2 100644 (file)
@@ -88,7 +88,7 @@ class ClassLoader {
        /**
         * Instance of this class
         */
-       private static $thisInstance = null;
+       private static $selfInstance = null;
 
        /**
         * The *public* constructor
@@ -115,16 +115,23 @@ class ClassLoader {
                $this->classes = new ArrayObject();
 
                // Set own instance
-               self::$thisInstance = $this;
+               self::$selfInstance = $this;
        }
 
        /**
         * Getter for an instance of this class
         *
-        * @return      $thisInstance           An instance of this class
+        * @return      $selfInstance           An instance of this class
         */
        public final static function getInstance () {
-               return self::$thisInstance;
+               // Is the instance there?
+               if (is_null(self::$selfInstance)) {
+                       // Get a new one
+                       self::$selfInstance = new ClassLoader(FrameworkConfiguration::getInstance());
+               } // END - if
+
+               // Return the instance
+               return self::$selfInstance;
        }
 
        /**
@@ -179,14 +186,14 @@ class ClassLoader {
 
                                // Scan the directory
                                $this->scanLocalPath($currPath);
-                       }
+                       } // END - for
 
                        // Check if we can leave
                        $cnt = 0;
                        for ($idx = $this->dirList->getIterator(); $idx->valid(); $idx->next()) {
                                if ($idx->current() == "") $cnt++;
-                       }
-               }
+                       } // END - for
+               } // END - while
        }
 
        /**
@@ -225,11 +232,7 @@ class ClassLoader {
                        } elseif (is_dir($dirClass) && !in_array($dirClass2, $this->ignoreList)) {
                                // Directory found and added to list
                                //* DEBUG: */ print "DIR={$dirClass}\n";
-                               if ($dirClass2 == "interfaces") {
-                                       $this->scanLocalPath($dirClass);
-                               } else {
-                                       $this->dirList->append($dirClass);
-                               }
+                               $this->dirList->append($dirClass);
                                $this->dirCnt++;
                        }
                        //* DEBUG: */ print "LOOP!\n";
@@ -237,6 +240,7 @@ class ClassLoader {
 
                // Close directory handler
                $dirInstance->closeDirectory();
+               unset($dirInstance);
 
                // Output counter in debug mode
                if (defined('DEBUG_MODE')) print(sprintf("[%s:] <strong>%d</strong> Klassendateien in <strong>%d</strong> Verzeichnissen gefunden und geladen.<br />\n",
@@ -257,11 +261,11 @@ class ClassLoader {
                                // Load current class
                                //* DEBUG: */ print "Class=".$idx->current()."\n";
                                require_once($idx->current());
-                       }
+                       } // END - for
 
                        // Re-initialize the classes list
                        $this->classes = new ArrayObject();
-               }
+               } // END - if
        }
 
        /**
@@ -294,8 +298,5 @@ require_once(sprintf("%sinc/classes/interfaces/class_FrameworkInterface%s", PATH
 require_once(sprintf("%sinc/classes/main/class_BaseFrameworkSystem%s", PATH, FrameworkConfiguration::getInstance()->readConfig('php_extension')));
 require_once(sprintf("%sinc/classes/main/io/class_FrameworkDirectoryPointer%s", PATH, FrameworkConfiguration::getInstance()->readConfig('php_extension')));
 
-// Initialize the class loader
-$loader = new ClassLoader(FrameworkConfiguration::getInstance());
-
 // [EOF]
 ?>
index 8dd6132..b133cc8 100644 (file)
--- a/index.php
+++ b/index.php
@@ -75,27 +75,22 @@ class ApplicationEntryPoint {
                if ((class_exists($tpl)) && (is_object($lang)) && (is_object($io))) {
                        // Use the template engine for putting out (nicer look) the message
                        try {
-                               $eval = sprintf("\$tplEngine = %s::create%s(\"%s%s\", \$lang, \$io);",
-                                       FrameworkConfiguration::getInstance()->readConfig('tpl_engine'),
-                                       FrameworkConfiguration::getInstance()->readConfig('tpl_engine'),
-                                       PATH,
-                                       FrameworkConfiguration::getInstance()->readConfig('tpl_base_path')
-                               );
-                               eval($eval);
+                               // Get the template instance from our object factory
+                               $tplEngine = ObjectFactory::createObjectByConfiguredName('tpl_engine', array(FrameworkConfiguration::getInstance()->readConfig('tpl_base_path'), $lang, $io));
                        } catch (BasePathIsEmptyException $e) {
-                               die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
+                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
                                        $e->getMessage()
                                ));
                        } catch (InvalidBasePathStringException $e) {
-                               die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
+                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
                                        $e->getMessage()
                                ));
                        } catch (BasePathIsNoDirectoryException $e) {
-                               die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
+                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
                                        $e->getMessage()
                                ));
                        } catch (BasePathReadProtectedException $e) {
-                               die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: <strong>%s</strong>",
+                               die(sprintf("[Main:] Could not initialize template engine for this reason: <strong>%s</strong>",
                                        $e->getMessage()
                                ));
                        }
@@ -113,6 +108,7 @@ class ApplicationEntryPoint {
                        // Assign variables
                        $tplEngine->assignVariable('message', $message);
                        $tplEngine->assignVariable('backtrace', $backtrace);
+                       $tplEngine->assignVariable('total_objects', ObjectFactory::getTotal());
 
                        // Load the template
                        $tplEngine->loadCodeTemplate('emergency_exit');