X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=inc%2Fclasses%2Fmain%2Fclass_BaseFrameworkSystem.php;h=dbf69b14f3a7f50d3657fee3f306596409f8db5a;hb=f090ddd80669edddadcf4d682384532d93ce1fff;hp=2ffe0b25eb449fb6298cfca7e344822751dd388f;hpb=d08ad4fd8098ff750f5d849f6031588b2fd99b27;p=shipsimu.git diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index 2ffe0b2..dbf69b1 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -61,7 +61,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /** * A human-readable description for this simulator part */ - private $partDescr = "Namenlose Framework-Einheit"; + private $objectDescription = "Namenlose Framework-Einheit"; /** * The unique ID string for identifying all type of classes @@ -78,6 +78,16 @@ 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; + /*********************** * Exception codes.... * ***********************/ @@ -127,6 +137,9 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { const EXCEPTION_ATTRIBUTES_ARE_MISSING = 0x02b; const EXCEPTION_ARRAY_ELEMENTS_MISSING = 0x02c; const EXCEPTION_TEMPLATE_ENGINE_UNSUPPORTED = 0x02d; + const EXCEPTION_MISSING_LANGUAGE_HANDLER = 0x02e; + const EXCEPTION_MISSING_FILE_IO_HANDLER = 0x02f; + const EXCEPTION_MISSING_ELEMENT = 0x030; /** * In the super constructor these system classes shall be ignored or else @@ -175,7 +188,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } // Destroy all informations about this class but keep some text about it alive - $this->setPartDescr(sprintf("Entferntes Objekt %s", $this->__toString())); + $this->setObjectDescription(sprintf("Entferntes Objekt %s", $this->__toString())); $this->setRealClass("DestructedObject"); $this->resetUniqueID(); } elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) { @@ -477,7 +490,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { $this->__toString(), md5(sprintf("%s:%s:%s:%s:%s:%s", $this->__toString(), - $this->getPartDescr(), + $this->getObjectDescription(), time(), getenv('REMOTE_ADDR'), getenv('SERVER_ADDR'), @@ -536,14 +549,14 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /** * Getter for simulator description * - * @return $partDescr The description of this simulation part + * @return $objectDescription The description of this simulation part */ - public final function getPartDescr () { - if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] getPartDescr erreicht.
\n", + public final function getObjectDescription () { + if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] getObjectDescription erreicht.
\n", $this->__toString() )); - if (isset($this->partDescr)) { - return $this->partDescr; + if (isset($this->objectDescription)) { + return $this->objectDescription; } else { return null; } @@ -552,14 +565,14 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /** * Setter for simulation part description * - * @param $partDescr The description as string for this simulation part + * @param $objectDescription The description as string for this simulation part * @return void */ - public final function setPartDescr ($partDescr) { - $this->partDescr = (String) $partDescr; + public final function setObjectDescription ($objectDescription) { + $this->objectDescription = (String) $objectDescription; if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Teilbeschreibung wird auf %s gesetzt.
\n", $this->__toString(), - $this->partDescr + $this->objectDescription )); } @@ -585,7 +598,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { ( $this->__toString() == $itemInstance->__toString() ) && ( - $this->getPartDescr() == $itemInstance->getPartDescr() + $this->getObjectDescription() == $itemInstance->getObjectDescription() ) ); } @@ -751,7 +764,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /** * Appends a trailing slash to a string * - * @param $str A string (maybe) without trailing slash + * @param $str A string (maybe) without trailing slash * @return $str A string with an auto-appended trailing slash */ public final function addMissingTrailingSlash ($str) { @@ -759,6 +772,112 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { if (substr($str, -1, 1) != "/") $str .= "/"; 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 + * + * @return $fileIOInstance An instance to the file I/O sub-system + */ + protected final function getFileIOInstance () { + return $this->fileIOInstance; + } + + /** + * Setter for file I/O instance + * + * @param $fileIOInstance An instance to the file I/O sub-system + * @return void + */ + public final function setFileIOInstance (FileIOHandler $fileIOInstance) { + $this->fileIOInstance = $fileIOInstance; + } + + /** + * Prepare the template engine (TemplateEngine by default) for a given + * application helper instance (ApplicationHelper by default). + * + * @param $appInstance An application helper instance + * @return $tplEngine The template engine instance + * @throws NullPointerException If the template engine could not + * be initialized + * @throws UnsupportedTemplateEngineException If $tplEngine is an + * unsupported template engine + * @throws MissingLanguageHandlerException If the language sub-system + * is not yet initialized + */ + protected function prepareTemplateEngine (BaseFrameworkSystem $appInstance) { + // Generate FQFN for all application templates + $fqfn = sprintf("%s%s/%s/%s", + PATH, + $this->getConfigInstance()->readConfig("application_path"), + strtolower($appInstance->getAppShortName()), + $this->getConfigInstance()->readConfig("tpl_base_path") + ); + + // Are both instances set? + if ($appInstance->getLanguageInstance() === null) { + // Invalid language instance + throw new MissingLanguageHandlerException($appInstance, self::EXCEPTION_MISSING_LANGUAGE_HANDLER); + } elseif ($appInstance->getFileIOInstance() === null) { + // Invalid language instance + throw new MissingFileIoHandlerException($appInstance, self::EXCEPTION_MISSING_FILE_IO_HANDLER); + } + + // 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:] Konstruierte PHP-Anweisung:
%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); + } + + // Return the prepared instance + return $tplEngine; + } } // [EOF]