X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Fclasses%2Fmain%2Fclass_BaseFrameworkSystem.php;h=2a0c80768b2b2c7fd2928af4a88e30716f82d640;hp=28627720d238a7c104d3e13e4fdcb717faecc7c2;hb=42bc0e1fc5ae4653fe04c9d41474c874a0050b69;hpb=1b7df549b9e8eb283d201606489c0e388c7917a2 diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 28627720d2..2a0c80768b 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,17 +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 ); + /* No longer used: + */ + /** * Private super constructor * @@ -182,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(); + } } /** @@ -249,6 +226,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } elseif (is_string($arg)) { // String $argsString .= "\"".$arg."\"(string)"; + } elseif (is_null($arg)) { + // Null + $argsString .= "(null)"; } else { // Unknown type (please report!) $argsString .= $arg."(unknown!)"; @@ -276,71 +256,46 @@ 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'))); - } - - // Initialize web instance - if (is_null($this->getWebOutputInstance())) { - // Generate the eval() command - $eval = sprintf("\$this->setWebOutputInstance(%s::create%s(\"%s\"));", - $this->getConfigInstance()->readConfig('web_engine'), - $this->getConfigInstance()->readConfig('web_engine'), - $this->getConfigInstance()->readConfig('web_content_type') - ); - - // Debug message - if (defined('DEBUG_EVAL')) $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command:
%s

\n", - $this->__toString(), - htmlentities($eval) - )); - - // Run the command - eval($eval); - } - - // 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') - ))); - } - - // 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); - } - } + 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()); } } /** * Setter for language instance * - * @param $configInstance The configuration instance which shall - * be FrameworkConfiguration + * @param $configInstance The configuration instance which shall + * be FrameworkConfiguration * @return void */ public final function setConfigInstance (FrameworkConfiguration $configInstance) { - self::$cfgInstance = $configInstance; + Registry::getRegistry()->addInstance('config', $configInstance); } /** @@ -349,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'); } /** @@ -359,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); } /** @@ -368,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'); } /** @@ -378,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); } /** @@ -387,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; } /** @@ -429,8 +435,8 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * * @return void */ - public final function createUniqueID () { - // Existiert noch keine? + public final function generateUniqueId () { + // Is the id set for this class? if (empty($this->uniqueID)) { // Correct missing class name @@ -440,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 @@ -449,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 ;-) @@ -461,10 +474,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { $tempID !== false ) && ( ( - $this->getDatabaseInstance() === null + $db === null ) || ( ( - is_object($this->getDatabaseInstance()) + is_object($db) ) && ( !$isUsed ) @@ -629,10 +642,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * Formats computer generated price values into human-understandable formats * with thousand and decimal seperators. * - * @param $value The in computer format value for a price - * @param $currency The currency symbol (use HTML-valid characters!) - * @param $decNum Number of decimals after commata - * @return $price The for the current language formated price string + * @param $value The in computer format value for a price + * @param $currency The currency symbol (use HTML-valid characters!) + * @param $decNum Number of decimals after commata + * @return $price The for the current language formated price string * @throws MissingDecimalsThousandsSeperatorException If decimals or * thousands seperator * is missing @@ -668,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; } /** @@ -750,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 * @@ -789,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). @@ -855,36 +821,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } // Initialize the template engine - $tplEngine = null; - $eval = sprintf("\$tplEngine = %s::create%s( - \"%s\", - \$appInstance->getLanguageInstance(), - \$appInstance->getFileIoInstance() -);", - $this->getConfigInstance()->readConfig('tpl_engine'), - $this->getConfigInstance()->readConfig('tpl_engine'), - $fqfn - ); - - // Debug message - if ((!is_null($this->getDebugInstance())) && (defined('DEBUG_EVAL'))) { - $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command:
%s

\n", - $this->__toString(), - htmlentities($eval) - )); - } - - // Run the command - eval($eval); - - // Is it a valid instance? - if (is_null($tplEngine)) { - // No class returned - throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (!$tplEngine instanceof CompileableTemplate) { - // Not an object! ;-( - throw new UnsupportedTemplateEngineException($tplEngine, self::EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED); - } + $tplEngine = ObjectFactory::createObjectByConfiguredName('tpl_engine', array($fqfn, $appInstance->getLanguageInstance(), $appInstance->getFileIoInstance())); // Return the prepared instance return $tplEngine;