]> git.mxchange.org Git - core.git/commitdiff
Fixed variable group handling by unsetting right index
authorRoland Häder <roland@mxchange.org>
Mon, 18 Feb 2013 04:50:06 +0000 (04:50 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 18 Feb 2013 04:50:06 +0000 (04:50 +0000)
inc/classes/interfaces/template/class_CompileableTemplate.php
inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php
inc/classes/main/template/class_BaseTemplateEngine.php

index 41791914ee5581de90d9de32d04206018624081f..cf982f62b97e86ddff4fff6fd8b3e2f4ba8afde5 100644 (file)
@@ -78,9 +78,10 @@ interface CompileableTemplate extends FrameworkInterface {
         * Removes a given variable
         *
         * @param       $variableName   The variable we are looking for
+        * @param       $variableGroup  Name of variable group (default: 'general')
         * @return      void
         */
-       function removeVariable ($variableName);
+       function removeVariable ($variableName, $variableGroup = 'general');
 
        /**
         * Assign a given congfiguration variable with a value
index e2d0f4c4717b0e8bfcc6cc69ae8838ac64a6baec..f8210271481ca3d7d51f05cddb31efcb00b26f98 100644 (file)
@@ -185,11 +185,12 @@ class XmlRewriterTemplateDecorator extends BaseDecorator implements CompileableT
         * Removes a given variable
         *
         * @param       $variableName   The variable we are looking for
+        * @param       $variableGroup  Name of variable group (default: 'general')
         * @return      void
         */
-       public final function removeVariable ($variableName) {
+       public final function removeVariable ($variableName, $variableGroup = 'general') {
                // Call the inner class' method
-               $this->getTemplateInstance()->removeVariable($variableName);
+               $this->getTemplateInstance()->removeVariable($variableName, $variableGroup);
        }
 
        /**
index b143aebed5c3ba38e5d86954d904bf207727188b..ed974689a5001031e481f95e56d764037914cdc0 100644 (file)
@@ -168,10 +168,10 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * Search for a variable in the stack
         *
         * @param       $variableName   The variable we are looking for
-        * @param       $stack                  Optional variable stack to look in
+        * @param       $variableGroup  Optional variable group to look in
         * @return      $index                  FALSE means not found, >=0 means found on a specific index
         */
-       private function getVariableIndex ($variableName, $stack = NULL) {
+       private function getVariableIndex ($variableName, $variableGroup = NULL) {
                // Replace all dashes to underscores to match variables with configuration entries
                $variableName = trim($this->convertDashesToUnderscores($variableName));
 
@@ -179,17 +179,17 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                $found = false;
 
                // If the stack is null, use the current group
-               if (is_null($stack)) {
+               if (is_null($variableGroup)) {
                        // Use current group
                        //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.' currGroup=' . $this->currGroup . ' set as stack!');
-                       $stack = $this->currGroup;
+                       $variableGroup = $this->currGroup;
                } // END - if
 
                // Is the group there?
-               if ($this->isVarStackSet($stack)) {
+               if ($this->isVarStackSet($variableGroup)) {
                        // Now search for it
-                       foreach ($this->getVarStack($stack) as $index => $currEntry) {
-                               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.':currGroup=' . $stack . ',idx=' . $index . ',currEntry=' . $currEntry['name'] . ',variableName=' . $variableName);
+                       foreach ($this->getVarStack($variableGroup) as $index => $currEntry) {
+                               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.':currGroup=' . $variableGroup . ',idx=' . $index . ',currEntry=' . $currEntry['name'] . ',variableName=' . $variableName);
                                // Is the entry found?
                                if ($currEntry['name'] == $variableName) {
                                        // Found!
@@ -205,48 +205,48 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
        }
 
        /**
-        * Checks whether the given variable stack is set
+        * Checks whether the given variable group is set
         *
-        * @param       $stack  Variable stack to check
-        * @return      $isSet  Whether the given variable stack is set
+        * @param       $variableGroup  Variable group to check
+        * @return      $isSet                  Whether the given variable group is set
         */
-       protected final function isVarStackSet ($stack) {
+       protected final function isVarStackSet ($variableGroup) {
                // Check it
-               $isSet = isset($this->varStack[$stack]);
+               $isSet = isset($this->varStack[$variableGroup]);
 
                // Return result
                return $isSet;
        }
 
        /**
-        * Getter for given variable stack
+        * Getter for given variable group
         *
-        * @param       $stack          Variable stack to check
-        * @return      $varStack       Found variable stack
+        * @param       $variableGroup  Variable group to check
+        * @return      $varStack               Found variable group
         */
-       public final function getVarStack ($stack) {
-               return $this->varStack[$stack];
+       public final function getVarStack ($variableGroup) {
+               return $this->varStack[$variableGroup];
        }
 
        /**
-        * Setter for given variable stack
+        * Setter for given variable group
         *
-        * @param       $stack          Variable stack to check
-        * @param       $varStack       Variable stack to check
+        * @param       $variableGroup  Variable group to check
+        * @param       $varStack               Variable stack to check
         * @return      void
         */
-       protected final function setVarStack ($stack, array $varStack) {
-               $this->varStack[$stack]  = $varStack;
+       protected final function setVarStack ($variableGroup, array $varStack) {
+               $this->varStack[$variableGroup]  = $varStack;
        }
 
        /**
         * Return a content of a variable or null if not found
         *
         * @param       $variableName   The variable we are looking for
-        * @param       $stack                  Optional variable stack to look in
+        * @param       $variableGroup  Optional variable group to look in
         * @return      $content                Content of the variable or null if not found
         */
-       protected function readVariable ($variableName, $stack = NULL) {
+       protected function readVariable ($variableName, $variableGroup = NULL) {
                // Replace all dashes to underscores to match variables with configuration entries
                $variableName = trim($this->convertDashesToUnderscores($variableName));
 
@@ -254,31 +254,31 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
                $content = NULL;
 
                // If the stack is null, use the current group
-               if (is_null($stack)) {
+               if (is_null($variableGroup)) {
                        // Use current group
                        //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.' currGroup=' . $this->currGroup . ' set as stack!');
-                       $stack = $this->currGroup;
+                       $variableGroup = $this->currGroup;
                } // END - if
 
                // Get variable index
-               $found = $this->getVariableIndex($variableName, $stack);
+               $found = $this->getVariableIndex($variableName, $variableGroup);
 
                // Is the variable found?
                if ($found !== false) {
                        // Read it
-                       $content = $this->getVariableValue($stack, $found);
+                       $content = $this->getVariableValue($variableGroup, $found);
                } // END - if
 
                // Return the current position
-               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': group=' . $stack . ',variableName=' . $variableName . ', content[' . gettype($content) . ']=' . $content);
+               //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(__METHOD__.': variableGroup=' . $variableGroup . ',variableName=' . $variableName . ', content[' . gettype($content) . ']=' . $content);
                return $content;
        }
 
        /**
         * Add a variable to the stack
         *
-        * @param       $variableName   The variable we are looking for
-        * @param       $value  The value we want to store in the variable
+        * @param       $variableName   Name of variable to add
+        * @param       $value                  Value we want to store in the variable
         * @return      void
         */
        private function addVariable ($variableName, $value) {
@@ -614,34 +614,42 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
         * Removes a given variable
         *
         * @param       $variableName   The variable we are looking for
+        * @param       $variableGroup  Name of variable group (default: 'general')
         * @return      void
         */
-       public final function removeVariable ($variableName) {
+       public final function removeVariable ($variableName, $variableGroup = 'general') {
                // First search for the variable if it was already added
-               $index = $this->getVariableIndex($variableName);
+               $index = $this->getVariableIndex($variableName, $variableGroup);
 
                // Was it found?
                if ($index !== false) {
                        // Remove this variable
-                       $this->unsetVariableStackOffset($index);
+                       $this->unsetVariableStackOffset($index, $variableGroup);
                } // END - if
        }
 
        /**
-        * Unsets the given offset in the variable stack
+        * Unsets the given offset in the variable group
         *
-        * @param       $index  Index to unset
+        * @param       $index                  Index to unset
+        * @param       $variableGroup  Variable group (default: currGroup)
         * @return      void
         */
-       protected final function unsetVariableStackOffset ($index) {
+       protected final function unsetVariableStackOffset ($index, $variableGroup = NULL) {
+               // Is the variable group not set?
+               if (is_null($variableGroup)) {
+                       // Then set it to current
+                       $variableGroup = $this->currGroup;
+               } // END - if
+
                // Is the entry there?
-               if (!isset($this->varStack[$this->currGroup][$index])) {
+               if (!isset($this->varStack[$variableGroup][$index])) {
                        // Abort here, we need fixing!
                        $this->debugInstance();
                } // END - if
 
                // Remove it
-               unset($this->varStack[$this->currGroup][$index]);
+               unset($this->varStack[$variableGroup][$index]);
        }
 
        /**
@@ -1173,7 +1181,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem {
 
        /**
         * Compiles configuration place-holders in all variables. This 'walks'
-        * through the variable stack 'general'. It interprets all values from that
+        * through the variable group 'general'. It interprets all values from that
         * variables as configuration entries after compiling them.
         *
         * @return      void