From: Roland Häder Date: Mon, 18 Feb 2013 04:50:06 +0000 (+0000) Subject: Fixed variable group handling by unsetting right index X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=980c7be55e69deb95920b903cbe803423b49e341;ds=sidebyside Fixed variable group handling by unsetting right index --- diff --git a/inc/classes/interfaces/template/class_CompileableTemplate.php b/inc/classes/interfaces/template/class_CompileableTemplate.php index 41791914..cf982f62 100644 --- a/inc/classes/interfaces/template/class_CompileableTemplate.php +++ b/inc/classes/interfaces/template/class_CompileableTemplate.php @@ -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 diff --git a/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php b/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php index e2d0f4c4..f8210271 100644 --- a/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php +++ b/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php @@ -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); } /** diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index b143aebe..ed974689 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -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