+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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).
+ *
+ * @param $appInstance An application helper instance or
+ * null if we shall use the default
+ * @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
+ * @throws NullPointerException If the discovered application
+ * instance is still null
+ */
+ protected function prepareTemplateEngine (BaseFrameworkSystem $appInstance=null) {
+ // Is the application instance set?
+ if (is_null($appInstance)) {
+ // Get the current instance
+ $appInstance = $this->getApplicationInstance();
+
+ // Still null?
+ if (is_null($appInstance)) {
+ // Thrown an exception
+ throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
+ }
+ }
+
+ // 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:] Constructed PHP command: <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;
+ }
+
+ /**
+ * Debugs this instance by putting out it's full content
+ *
+ * @return void
+ */
+ public final function debugInstance () {
+ // Generate the output
+ $content = sprintf("<pre>%s</pre>",
+ trim(print_r($this, true))
+ );
+
+ // Output it
+ ApplicationEntryPoint::app_die(sprintf("<strong>%s debug output:</strong>%s", $this->__toString(), $content));
+ }
+
+ /**
+ * Output a partial stub message for the caller method
+ *
+ * @param $message An optional message to display
+ * @return void
+ */
+ protected function partialStub ($message = "") {
+ // Get the backtrace
+ $backtrace = debug_backtrace();
+
+ // Generate the class::method string
+ $methodName = "UnknownClass::unknownMethod";
+ if ((isset($backtrace[1]['class'])) && (isset($backtrace[1]['function']))) {
+ $methodName = $backtrace[1]['class']."::".$backtrace[1]['function'];
+ }
+
+ // Construct the full message
+ $stubMessage = sprintf("[%s:] Partial stub!",
+ $methodName
+ );
+
+ // Is the extra message given?
+ if (!empty($message)) {
+ // Then add it as well
+ $stubMessage .= sprintf(" Message: <u>%s</u>", $message);
+ }
+
+ // Debug instance is there?
+ if (!is_null($this->getDebugInstance())) {
+ // Output stub message
+ $this->getDebugInstance()->output($stubMessage);
+ } else {
+ // Trigger an error
+ trigger_error($stubMessage."<br />\n");
+ }
+ }
+
+ /**
+ * Converts e.g. a command from URL to a valid class by keeping out bad characters
+ *
+ * @param $str The string, what ever it is needs to be converted
+ * @return $className Generated class name
+ */
+ public function convertToClassName ($str) {
+ $className = "";
+ foreach (explode("_", $str) as $strPart) {
+ $className .= ucfirst(strtolower($strPart));
+ }
+ return $className;
+ }
+
+ /**
+ * Outputs a debug backtrace and stops further script execution
+ *
+ * @return void
+ */
+ public function debugBacktrace () {
+ // Sorry, there is no other way getting this nice backtrace
+ print "<pre>\n";
+ debug_print_backtrace();
+ print "</pre>";
+ exit;
+ }