/**
* 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
*/
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.... *
***********************/
const EXCEPTION_VARIABLE_NOT_SET = 0x02a;
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
}
// Destroy all informations about this class but keep some text about it alive
- $this->setPartDescr(sprintf("Entferntes Objekt <em>%s</em>", $this->__toString()));
+ $this->setObjectDescription(sprintf("Entferntes Objekt <em>%s</em>", $this->__toString()));
$this->setRealClass("DestructedObject");
$this->resetUniqueID();
} elseif ((defined('DEBUG_DESTRUCTOR')) && (is_object($this->getDebugInstance()))) {
$this->__toString(),
md5(sprintf("%s:%s:%s:%s:%s:%s",
$this->__toString(),
- $this->getPartDescr(),
+ $this->getObjectDescription(),
time(),
getenv('REMOTE_ADDR'),
getenv('SERVER_ADDR'),
/**
* 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.<br />\n",
+ public final function getObjectDescription () {
+ if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] getObjectDescription erreicht.<br />\n",
$this->__toString()
));
- if (isset($this->partDescr)) {
- return $this->partDescr;
+ if (isset($this->objectDescription)) {
+ return $this->objectDescription;
} else {
return null;
}
/**
* 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 <strong>%s</strong> gesetzt.<br />\n",
$this->__toString(),
- $this->partDescr
+ $this->objectDescription
));
}
* @return boolean The result of comparing both's unique ID
*/
public final function equals ($object) {
- if ((defined('DEBUG_SYSTEM')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Ist <strong>%s</strong>=<strong>%s</strong>?<br />\n",
- $this->__toString(),
- $this->__toString(),
- $object->__toString()
- ));
return ($this->getUniqueID() == $object->getUniqueID());
}
*/
public function itemMatches ($itemInstance) {
return (
- ($this->__toString() == $itemInstance->__toString())
- && ($this->getPartDescr() == $itemInstance->getPartDescr())
+ (
+ $this->__toString() == $itemInstance->__toString()
+ ) && (
+ $this->getObjectDescription() == $itemInstance->getObjectDescription()
+ )
);
}
* @throws InvalidArrayCountException If the array contains less or
* more than two elements
*/
- public function getPathFileNameFromObject () {
+ public final function getPathFileNameFromObject () {
// Get the main object's unique ID. We use this as a path/filename combination
$pathFile = $this->getUniqueID();
/**
* 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) {
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: <pre><em>%s</em></pre><br />\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]