From 2e472bcbab0c23f070d39cfc66bef639706f0868 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 9 Jun 2008 20:47:13 +0000 Subject: [PATCH] Rewrite of initInstance(), more eval() rewritten to call_user_func_array() --- application/selector/starter.php | 14 +- application/ship-simu/init.php | 27 +- application/ship-simu/starter.php | 9 +- .../class_FrameworkDatabaseInterface.php | 28 -- .../main/class_BaseFrameworkSystem.php | 272 ++++++++---------- .../factories/objects/class_ObjectFactory.php | 17 ++ .../io/class_FrameworkDirectoryPointer.php | 23 -- inc/classes/main/output/class_WebOutput.php | 2 +- inc/classes/main/registry/class_Registry.php | 21 ++ .../compressor/class_CompressorChannel.php | 2 +- .../database/class_DatabaseConnection.php | 58 +--- .../debug/class_DebugMiddleware.php | 2 +- inc/config.php | 2 + inc/config/class_FrameworkConfiguration.php | 2 +- inc/loader/class_ClassLoader.php | 35 +-- index.php | 18 +- 16 files changed, 220 insertions(+), 312 deletions(-) diff --git a/application/selector/starter.php b/application/selector/starter.php index ca9d294..dab9479 100644 --- a/application/selector/starter.php +++ b/application/selector/starter.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -22,8 +22,9 @@ * along with this program. If not, see . */ -// 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 %s could not be launched for the follwing reason: %s", $application, diff --git a/application/ship-simu/init.php b/application/ship-simu/init.php index 431e442..0f9ff1d 100644 --- a/application/ship-simu/init.php +++ b/application/ship-simu/init.php @@ -33,6 +33,19 @@ * along with this program. If not, see . */ +// 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] ?> diff --git a/application/ship-simu/starter.php b/application/ship-simu/starter.php index 468848d..dab9479 100644 --- a/application/ship-simu/starter.php +++ b/application/ship-simu/starter.php @@ -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 %s could not be launched for the follwing reason: %s", $application, diff --git a/inc/classes/interfaces/database/class_FrameworkDatabaseInterface.php b/inc/classes/interfaces/database/class_FrameworkDatabaseInterface.php index d1a3266..c5cf54e 100644 --- a/inc/classes/interfaces/database/class_FrameworkDatabaseInterface.php +++ b/inc/classes/interfaces/database/class_FrameworkDatabaseInterface.php @@ -22,18 +22,6 @@ * along with this program. If not, see . */ 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] diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index bc9b5bb..2a0c807 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -24,39 +24,14 @@ */ 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 @@ -83,11 +58,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 */ @@ -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; } /** @@ -744,26 +755,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { return $str; } - /** - * 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 * @@ -783,25 +774,6 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { $this->fileIOInstance = $fileIOInstance; } - /** - * 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). diff --git a/inc/classes/main/factories/objects/class_ObjectFactory.php b/inc/classes/main/factories/objects/class_ObjectFactory.php index 8fe592b..024020d 100644 --- a/inc/classes/main/factories/objects/class_ObjectFactory.php +++ b/inc/classes/main/factories/objects/class_ObjectFactory.php @@ -22,6 +22,11 @@ * along with this program. If not, see . */ class ObjectFactory extends BaseFactory { + /** + * Total objects generated + */ + private static $total = 0; + /** * Protected constructor * @@ -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] diff --git a/inc/classes/main/io/class_FrameworkDirectoryPointer.php b/inc/classes/main/io/class_FrameworkDirectoryPointer.php index 79580df..6206023 100644 --- a/inc/classes/main/io/class_FrameworkDirectoryPointer.php +++ b/inc/classes/main/io/class_FrameworkDirectoryPointer.php @@ -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); diff --git a/inc/classes/main/output/class_WebOutput.php b/inc/classes/main/output/class_WebOutput.php index 799e9ed..6c86b62 100644 --- a/inc/classes/main/output/class_WebOutput.php +++ b/inc/classes/main/output/class_WebOutput.php @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class WebOutput extends BaseFrameworkSystem implements OutputStreamer { +class WebOutput extends BaseFrameworkSystem implements OutputStreamer, Registerable { /** * The instance for the singleton design pattern */ diff --git a/inc/classes/main/registry/class_Registry.php b/inc/classes/main/registry/class_Registry.php index a9e1a2a..a8abb50 100644 --- a/inc/classes/main/registry/class_Registry.php +++ b/inc/classes/main/registry/class_Registry.php @@ -27,6 +27,11 @@ class Registry extends BaseFrameworkSystem implements Register { */ private static $selfInstance = null; + /** + * Wether the registry is initialized + */ + private static $initialized = false; + /** * Instance registry */ @@ -68,6 +73,22 @@ class Registry extends BaseFrameworkSystem implements Register { return self::$selfInstance; } + /** + * 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 * diff --git a/inc/classes/middleware/compressor/class_CompressorChannel.php b/inc/classes/middleware/compressor/class_CompressorChannel.php index 1a99985..b881426 100644 --- a/inc/classes/middleware/compressor/class_CompressorChannel.php +++ b/inc/classes/middleware/compressor/class_CompressorChannel.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class CompressorChannel extends BaseMiddleware { +class CompressorChannel extends BaseMiddleware implements Registerable { /** * Real compressor instance */ diff --git a/inc/classes/middleware/database/class_DatabaseConnection.php b/inc/classes/middleware/database/class_DatabaseConnection.php index 81b402f..0c42807 100644 --- a/inc/classes/middleware/database/class_DatabaseConnection.php +++ b/inc/classes/middleware/database/class_DatabaseConnection.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -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; } /** @@ -145,32 +123,6 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Li return $this->dbLayer->isUniqueIdUsed($uniqueID, $inConstructor); } - /** - * 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 diff --git a/inc/classes/middleware/debug/class_DebugMiddleware.php b/inc/classes/middleware/debug/class_DebugMiddleware.php index 5c1e050..694dac6 100644 --- a/inc/classes/middleware/debug/class_DebugMiddleware.php +++ b/inc/classes/middleware/debug/class_DebugMiddleware.php @@ -23,7 +23,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class DebugMiddleware extends BaseMiddleware { +class DebugMiddleware extends BaseMiddleware implements Registerable { /** * The concrete output instance */ diff --git a/inc/config.php b/inc/config.php index 142093b..be9058a 100644 --- a/inc/config.php +++ b/inc/config.php @@ -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 diff --git a/inc/config/class_FrameworkConfiguration.php b/inc/config/class_FrameworkConfiguration.php index 664107d..6bfc3a2 100644 --- a/inc/config/class_FrameworkConfiguration.php +++ b/inc/config/class_FrameworkConfiguration.php @@ -25,7 +25,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -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 diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index a82f951..06d2bb2 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -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:] %d Klassendateien in %d Verzeichnissen gefunden und geladen.
\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] ?> diff --git a/index.php b/index.php index 8dd6132..b133cc8 100644 --- 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: %s", + die(sprintf("[Main:] Could not initialize template engine for this reason: %s", $e->getMessage() )); } catch (InvalidBasePathStringException $e) { - die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: %s", + die(sprintf("[Main:] Could not initialize template engine for this reason: %s", $e->getMessage() )); } catch (BasePathIsNoDirectoryException $e) { - die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: %s", + die(sprintf("[Main:] Could not initialize template engine for this reason: %s", $e->getMessage() )); } catch (BasePathReadProtectedException $e) { - die(sprintf("[Main:] Die Template-Engine konnte nicht initialisieren. Grund: %s", + die(sprintf("[Main:] Could not initialize template engine for this reason: %s", $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'); -- 2.39.5