]> git.mxchange.org Git - shipsimu.git/commitdiff
Template engine does now insert all variables (work-around)
authorRoland Häder <roland@mxchange.org>
Mon, 21 Apr 2008 11:28:16 +0000 (11:28 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 21 Apr 2008 11:28:16 +0000 (11:28 +0000)
inc/classes/exceptions/template/class_UnexpectedTemplateTypeException.php
inc/classes/main/template/class_TemplateEngine.php

index 568fa916f1d8900efdd50b9213bbaa36b039e364..bfb096e9714fdc7197fd57b85cb201b4cce1998c 100644 (file)
@@ -25,17 +25,17 @@ class UnexpectedTemplateTypeException extends FrameworkException {
        /**
         * The constructor
         *
-        * @param               $class          An array holding our informations
+        * @param               $msgArray       An array holding our informations
         * @param               $code           Code number for the exception
         * @return      void
         */
-       public function __construct (BaseFrameworkSystem $class, $code) {
+       public function __construct (array $msgArray, $code) {
                // Add a message around the missing class
                $message = sprintf("[%s:%d] Der Template-Typ <u>%s</u> entspricht nicht dem erwartetem Template-Typ <u>%s</u>.",
-                       $class[0]->__toString(),
+                       $msgArray[0]->__toString(),
                        $this->getLine(),
-                       $class[1],
-                       $class[2]
+                       $msgArray[1],
+                       $msgArray[2]
                );
 
                // Call parent constructor
index 16fbd3c8f567b500551e81c7cfaba0e9ffc84352..6e09d8943f7ed32ee4e0b9259f9c37352a9a46fd 100644 (file)
@@ -877,6 +877,32 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate
                }
        }
 
+       /**
+        * Finalizes the compilation of all template variables
+        *
+        * @return      void
+        */
+       private function finalizeVariableCompilation () {
+               // Get the content
+               $content = $this->getRawTemplateData();
+
+               // Walk through all variables
+               for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) {
+
+                       // Get current entry
+                       $currEntry = $idx->current();
+
+                       // Replace all [$var] or {?$var?} with the content
+                       $content = str_replace("\$content[".$currEntry['name']."]", $currEntry['value'], $content);
+                       $content = str_replace("[".$currEntry['name']."]", $currEntry['value'], $content);
+                       $content = str_replace("{?".$currEntry['name']."?}", $currEntry['value'], $content);
+
+               } // END - for
+
+               // Set the content back
+               $this->setRawTemplateData($content);
+       }
+
        /**
         * Getter for raw template data
         *
@@ -950,12 +976,16 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate
 
                // Iterate through all variables
                for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) {
+
                        // Get current variable from the stack
                        $currVariable = $idx->current();
 
                        // Transfer it's name/value combination to the $content array
                        $dummy[$currVariable['name']] = $currVariable['value'];
-               }
+
+               }// END - if
+
+               // Set the new variable (don't remove the second dollar !)
                $$validVar = $dummy;
 
                // Prepare all configuration variables
@@ -965,6 +995,9 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate
                unset($idx);
                unset($currVariable);
 
+               // Finalize the compilation of template variables
+               $this->finalizeVariableCompilation();
+
                // Prepare the eval() command for comiling the template
                $eval = sprintf("\$this->setCompiledData(\"%s\");",
                        addslashes($this->getRawTemplateData())
@@ -994,7 +1027,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate
                if ($this->getTemplateType() != $this->getConfigInstance()->readConfig("code_template_type")) {
                        // Abort here
                        throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->readConfig("code_template_type")), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED);
-               }
+               } // END - if
 
                // Get the raw data.
                $rawData = $this->getRawTemplateData();
@@ -1014,7 +1047,6 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate
                        //
                        // The main analysis
                        $this->analyzeTemplate($templateMatches);
-                       $this->debugInstance();
 
                        // Compile raw template data
                        $this->compileRawTemplateData($templateMatches);
@@ -1024,9 +1056,14 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate
 
                        // Are some raw templates found and loaded?
                        if (count($this->rawTemplates) > 0) {
+
                                // Insert all raw templates
                                $this->insertRawTemplates();
-                       }
+
+                               // Remove the raw template content as well
+                               $this->setRawTemplateData("");
+
+                       } // END - if
 
                } // END - if($templateMatches ...
        }