Code templates needs to be configured separately for HTML and console.
[core.git] / inc / classes / main / template / class_BaseTemplateEngine.php
index 68be4dcb037bcc35e979ad63e98999bbb810cca2..543bd88f6d182e44dd549f6e6174f2a7259f33a4 100644 (file)
@@ -178,7 +178,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        private function getVariableIndex ($variableName, $variableGroup = NULL) {
                // Replace all dashes to underscores to match variables with configuration entries
-               $variableName = trim($this->convertDashesToUnderscores($variableName));
+               $variableName = trim(self::convertDashesToUnderscores($variableName));
 
                // First everything is not found
                $found = FALSE;
@@ -253,7 +253,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        protected function readVariable ($variableName, $variableGroup = NULL) {
                // Replace all dashes to underscores to match variables with configuration entries
-               $variableName = trim($this->convertDashesToUnderscores($variableName));
+               $variableName = trim(self::convertDashesToUnderscores($variableName));
 
                // First everything is not found
                $content = NULL;
@@ -341,7 +341,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        public function addGroupVariable ($variableName, $value) {
                // Replace all dashes to underscores to match variables with configuration entries
-               $variableName = trim($this->convertDashesToUnderscores($variableName));
+               $variableName = trim(self::convertDashesToUnderscores($variableName));
 
                // Debug message
                //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': group=' . $this->currGroup . ', variableName=' . $variableName . ', value=' . $value);
@@ -378,7 +378,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        private function modifyVariable ($variableName, $value) {
                // Replace all dashes to underscores to match variables with configuration entries
-               $variableName = trim($this->convertDashesToUnderscores($variableName));
+               $variableName = trim(self::convertDashesToUnderscores($variableName));
 
                // Get index for variable
                $index = $this->getVariableIndex($variableName);
@@ -417,7 +417,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        protected function setVariable ($variableGroup, $variableName, $value) {
                // Replace all dashes to underscores to match variables with configuration entries
-               $variableName = trim($this->convertDashesToUnderscores($variableName));
+               $variableName = trim(self::convertDashesToUnderscores($variableName));
 
                // Get index for variable
                $index = $this->getVariableIndex($variableName);
@@ -448,7 +448,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        private function generateVariableArray ($variableName, $value) {
                // Replace all dashes to underscores to match variables with configuration entries
-               $variableName = trim($this->convertDashesToUnderscores($variableName));
+               $variableName = trim(self::convertDashesToUnderscores($variableName));
 
                // Generate the temporary array
                $varData = array(
@@ -647,11 +647,11 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
        }
 
        /**
-        * Getter for compiled templates
+        * Getter for compiled templates, must be public for e.g. Mailer classes.
         *
         * @return      $compiledData   Compiled template data
         */
-       protected final function getCompiledData () {
+       public final function getCompiledData () {
                //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: ' . strlen($this->compiledData) . ' Bytes read.');
                return $this->compiledData;
        }
@@ -662,7 +662,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $template       The template we shall load
         * @param       $extOther       An other extension to use
         * @return      void
-        * @throws      FileIoException If the template was not found
+        * @throws      FileNotFoundException   If the template was not found
         */
        protected function loadTemplate ($template, $extOther = '') {
                // Get extension for the template if empty
@@ -702,7 +702,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                try {
                        // Load the raw template data
                        $this->loadRawTemplateData($fqfn);
-               } catch (FileIoException $e) {
+               } catch (FileNotFoundException $e) {
                        // If we shall load a code-template we need to switch the file extension
                        if (($this->getTemplateType() != $this->getConfigInstance()->getConfigEntry('html_template_type')) && (empty($extOther))) {
                                // Switch over to the code-template extension and try it again
@@ -712,7 +712,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                                $this->loadTemplate($template, $ext);
                        } else {
                                // Throw it again
-                               throw new FileIoException($fqfn, self::EXCEPTION_FILE_NOT_FOUND);
+                               throw new FileNotFoundException($fqfn, self::EXCEPTION_FILE_NOT_FOUND);
                        }
                }
 
@@ -749,7 +749,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        private function assignTemplateVariable ($variableName, $var) {
                // Replace all dashes to underscores to match variables with configuration entries
-               $variableName = trim($this->convertDashesToUnderscores($variableName));
+               $variableName = trim(self::convertDashesToUnderscores($variableName));
 
                // Debug message
                //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: variableName=' . $variableName . ',variableName=' . $variableName);
@@ -846,7 +846,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                                                // Remember this template for recursion detection
                                                // RECURSIVE PROTECTION!
                                                array_push($this->loadedTemplates, $template);
-                                       } catch (FileIoException $e) {
+                                       } catch (FileNotFoundException $e) {
                                                // Even this is not done... :/
                                                array_push($this->rawTemplates, $template);
                                        }
@@ -945,7 +945,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                                        // Remember this template for recursion detection
                                        // RECURSIVE PROTECTION!
                                        array_push($this->loadedTemplates, $template);
-                               } catch (FileIoException $e) {
+                               } catch (FileNotFoundException $e) {
                                        // This template was never found. We silently ignore it
                                        unset($this->rawTemplates[$key]);
                                }
@@ -967,7 +967,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                // Search for all variables
                foreach ($varMatches[1] as $key => $var) {
                        // Replace all dashes to underscores to match variables with configuration entries
-                       $var = trim($this->convertDashesToUnderscores($var));
+                       $var = trim(self::convertDashesToUnderscores($var));
 
                        // Debug message
                        self::createDebugInstance(__CLASS__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:key=' . $key . ',var=' . $var);
@@ -1110,7 +1110,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        public final function assignVariable ($variableName, $value) {
                // Replace all dashes to underscores to match variables with configuration entries
-               $variableName = trim($this->convertDashesToUnderscores($variableName));
+               $variableName = trim(self::convertDashesToUnderscores($variableName));
 
                // Empty variable found?
                if (empty($variableName)) {
@@ -1178,7 +1178,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        public function assignConfigVariable ($variableName) {
                // Replace all dashes to underscores to match variables with configuration entries
-               $variableName = trim($this->convertDashesToUnderscores($variableName));
+               $variableName = trim(self::convertDashesToUnderscores($variableName));
 
                // Sweet and simple...
                //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: variableName=' . $variableName . ',getConfigEntry()=' . $this->getConfigInstance()->getConfigEntry($variableName));
@@ -1232,7 +1232,22 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        public function loadCodeTemplate ($template) {
                // Set template type
-               $this->setTemplateType($this->getConfigInstance()->getConfigEntry('code_template_type'));
+               $this->setTemplateType($this->getConfigInstance()->getConfigEntry('code_' . self::getResponseTypeFromSystem() . '_template_type'));
+
+               // Load the special template
+               $this->loadTemplate($template);
+       }
+
+       /**
+        * Load a specified email template into the engine
+        *
+        * @param       $template       The email template we shall load which is
+        *                                              located in 'emails' by default
+        * @return      void
+        */
+       public function loadEmailTemplate ($template) {
+               // Set template type
+               $this->setTemplateType($this->getConfigInstance()->getConfigEntry('email_template_type'));
 
                // Load the special template
                $this->loadTemplate($template);
@@ -1376,12 +1391,12 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         */
        public function compileTemplate () {
                // Get code type to make things shorter
-               $codeType = $this->getConfigInstance()->getConfigEntry('code_template_type');
+               $codeType = $this->getConfigInstance()->getConfigEntry('code_' . self::getResponseTypeFromSystem() . '_template_type');
 
                // We will only work with template type "code" from configuration
                if (substr($this->getTemplateType(), 0, strlen($codeType)) != $codeType) {
                        // Abort here
-                       throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->getConfigEntry('code_template_type')), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED);
+                       throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->getConfigEntry('code_' . self::getResponseTypeFromSystem() . '_template_type')), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED);
                } // END - if
 
                // Get the raw data.
@@ -1433,7 +1448,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                // Is this view helper loaded?
                if (!isset($this->helpers[$helperName])) {
                        // Create a class name
-                       $className = $this->convertToClassName($helperName) . 'ViewHelper';
+                       $className = self::convertToClassName($helperName) . 'ViewHelper';
 
                        // Generate new instance
                        $this->helpers[$helperName] = ObjectFactory::createObjectByName($className);