]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/template/class_BaseTemplateEngine.php
Fixes for template engine
[shipsimu.git] / inc / classes / main / template / class_BaseTemplateEngine.php
index 00691efa515ccc45bcfee424e748deda9738a4ef..8a53c46859771174e3df40bd82c16e922b868da2 100644 (file)
@@ -429,17 +429,29 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * @param       $var    The variable we are looking for
         * @param       $value  The value we want to store in the variable
         * @return      void
+        * @throws      EmptyVariableException  If the variable name is left empty
         */
        public final function assignVariable ($var, $value) {
+               // Trim spaces of variable name
+               $var = trim($var);
+
+               // Empty variable found?
+               if (empty($var)) {
+                       // Throw an exception
+                       throw new EmptyVariableException(array($this, 'var'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+               } // END - if
+
                // First search for the variable if it was already added
                $idx = $this->isVariableAlreadySet($var);
 
                // Was it found?
                if ($idx === false) {
                        // Add it to the stack
+                       //* DEBUG: */ echo "ADD: ".$var."<br />\n";
                        $this->addVariable($var, $value);
                } elseif (!empty($value)) {
                        // Modify the stack entry
+                       //* DEBUG: */ echo "MOD: ".$var."<br />\n";
                        $this->modifyVariable($var, $value);
                }
        }
@@ -595,8 +607,14 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) {
                        // Initialize all missing variables
                        foreach ($variableMatches[3] as $key=>$var) {
-                               // Try to assign it, empty strings are being ignored
-                               $this->assignTemplateVariable($variableMatches[1][$key], $var);
+                               // Variable name
+                               $varName = $variableMatches[1][$key];
+
+                               // Workarround: Do not assign empty variables
+                               if (!empty($var)) {
+                                       // Try to assign it, empty strings are being ignored
+                                       $this->assignTemplateVariable($varName, $var);
+                               } // END - if
                        } // END - foreach
                } // END - if
        }
@@ -1015,7 +1033,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                        );
 
                        // Did something change?
-                       if (strlen($eval) != $eval) {
+                       if (strlen($eval) != $evalLength) {
                                // Run the constructed command. This will "compile" all variables in
                                @eval($eval);
                        } // END - if