From 8904918d814abf3468d084b8826e4d280b0885e3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 27 Jun 2012 16:57:40 +0000 Subject: [PATCH 1/1] Renamed variables, removeVariable() does not expect indexes --- .../template/class_CompileableTemplate.php | 20 +-- .../class_XmlRewriterTemplateDecorator.php | 12 +- .../template/class_BaseTemplateEngine.php | 141 +++++++++--------- inc/config/class_FrameworkConfiguration.php | 2 +- 4 files changed, 88 insertions(+), 87 deletions(-) diff --git a/inc/classes/interfaces/template/class_CompileableTemplate.php b/inc/classes/interfaces/template/class_CompileableTemplate.php index b54d9c68..41791914 100644 --- a/inc/classes/interfaces/template/class_CompileableTemplate.php +++ b/inc/classes/interfaces/template/class_CompileableTemplate.php @@ -25,11 +25,11 @@ interface CompileableTemplate extends FrameworkInterface { /** * Assign variables for templates * - * @param $var The "variable" we want to assign - * @param $value The value we want to store in the variable + * @param $variableName The "variable" we want to assign + * @param $value The value we want to store in the variable * @return void */ - function assignVariable ($var, $value); + function assignVariable ($variableName, $value); /** * Load a specified web template into the engine @@ -68,27 +68,27 @@ interface CompileableTemplate extends FrameworkInterface { /** * Adds a variable to current group * - * @param $var Variable to set - * @param $value Value to store in variable + * @param $variableName Variable to set + * @param $value Value to store in variable * @return void */ - function addGroupVariable ($var, $value); + function addGroupVariable ($variableName, $value); /** * Removes a given variable * - * @param $var The variable we are looking for + * @param $variableName The variable we are looking for * @return void */ - function removeVariable ($var); + function removeVariable ($variableName); /** * Assign a given congfiguration variable with a value * - * @param $var The configuration variable we want to assign + * @param $variableName The configuration variable we want to assign * @return void */ - function assignConfigVariable ($var); + function assignConfigVariable ($variableName); /** * Compiles configuration place-holders in all variables. This 'walks' diff --git a/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php b/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php index ff33d1ca..e2d0f4c4 100644 --- a/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php +++ b/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php @@ -184,12 +184,12 @@ class XmlRewriterTemplateDecorator extends BaseDecorator implements CompileableT /** * Removes a given variable * - * @param $var The variable we are looking for + * @param $variableName The variable we are looking for * @return void */ - public final function removeVariable ($var) { + public final function removeVariable ($variableName) { // Call the inner class' method - $this->getTemplateInstance()->removeVariable($var); + $this->getTemplateInstance()->removeVariable($variableName); } /** @@ -217,12 +217,12 @@ class XmlRewriterTemplateDecorator extends BaseDecorator implements CompileableT /** * Assign a given congfiguration variable with a value * - * @param $var The configuration variable we want to assign + * @param $variableName The configuration variable we want to assign * @return void */ - public function assignConfigVariable ($var) { + public function assignConfigVariable ($variableName) { // Call the inner class' method - $this->getTemplateInstance()->assignConfigVariable($var); + $this->getTemplateInstance()->assignConfigVariable($variableName); } /** diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index a95838ec..334ff102 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -167,13 +167,13 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Search for a variable in the stack * - * @param $var The variable we are looking for - * @param $stack Optional variable stack to look in - * @return $index FALSE means not found, >=0 means found on a specific index + * @param $variableName The variable we are looking for + * @param $stack Optional variable stack to look in + * @return $index FALSE means not found, >=0 means found on a specific index */ - private function getVariableIndex ($var, $stack = NULL) { + private function getVariableIndex ($variableName, $stack = NULL) { // Replace all dashes to underscores to match variables with configuration entries - $var = trim($this->convertDashesToUnderscores($var)); + $variableName = trim($this->convertDashesToUnderscores($variableName)); // First everything is not found $found = false; @@ -189,9 +189,9 @@ class BaseTemplateEngine extends BaseFrameworkSystem { if ($this->isVarStackSet($stack)) { // Now search for it foreach ($this->getVarStack($stack) as $index => $currEntry) { - //* DEBUG: */ $this->debugOutput(__METHOD__.':currGroup=' . $stack . ',idx=' . $index . ',currEntry=' . $currEntry['name'] . ',var=' . $var); + //* DEBUG: */ $this->debugOutput(__METHOD__.':currGroup=' . $stack . ',idx=' . $index . ',currEntry=' . $currEntry['name'] . ',variableName=' . $variableName); // Is the entry found? - if ($currEntry['name'] == $var) { + if ($currEntry['name'] == $variableName) { // Found! //* DEBUG: */ $this->debugOutput(__METHOD__.':FOUND!'); $found = $index; @@ -242,13 +242,13 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Return a content of a variable or null if not found * - * @param $var The variable we are looking for - * @param $stack Optional variable stack to look in - * @return $content Content of the variable or null if not found + * @param $variableName The variable we are looking for + * @param $stack Optional variable stack to look in + * @return $content Content of the variable or null if not found */ - protected function readVariable ($var, $stack = NULL) { + protected function readVariable ($variableName, $stack = NULL) { // Replace all dashes to underscores to match variables with configuration entries - $var = trim($this->convertDashesToUnderscores($var)); + $variableName = trim($this->convertDashesToUnderscores($variableName)); // First everything is not found $content = NULL; @@ -261,7 +261,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { } // END - if // Get variable index - $found = $this->getVariableIndex($var, $stack); + $found = $this->getVariableIndex($variableName, $stack); // Is the variable found? if ($found !== false) { @@ -270,23 +270,23 @@ class BaseTemplateEngine extends BaseFrameworkSystem { } // END - if // Return the current position - //* DEBUG: */ $this->debugOutput(__METHOD__.': group=' . $stack . ',var=' . $var . ', content[' . gettype($content) . ']=' . $content); + //* DEBUG: */ $this->debugOutput(__METHOD__.': group=' . $stack . ',variableName=' . $variableName . ', content[' . gettype($content) . ']=' . $content); return $content; } /** * Add a variable to the stack * - * @param $var The variable we are looking for + * @param $variableName The variable we are looking for * @param $value The value we want to store in the variable * @return void */ - private function addVariable ($var, $value) { + private function addVariable ($variableName, $value) { // Set general variable group $this->setVariableGroup('general'); // Add it to the stack - $this->addGroupVariable($var, $value); + $this->addGroupVariable($variableName, $value); } /** @@ -330,22 +330,22 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Adds a variable to current group * - * @param $var Variable to set - * @param $value Value to store in variable + * @param $variableName Variable to set + * @param $value Value to store in variable * @return void */ - public function addGroupVariable ($var, $value) { + public function addGroupVariable ($variableName, $value) { // Replace all dashes to underscores to match variables with configuration entries - $var = trim($this->convertDashesToUnderscores($var)); + $variableName = trim($this->convertDashesToUnderscores($variableName)); // Debug message - //* DEBUG: */ $this->debugOutput(__METHOD__.': group=' . $this->currGroup . ', var=' . $var . ', value=' . $value); + //* DEBUG: */ $this->debugOutput(__METHOD__.': group=' . $this->currGroup . ', variableName=' . $variableName . ', value=' . $value); // Get current variables in group $currVars = $this->readCurrentGroup(); // Append our variable - $currVars[] = $this->generateVariableArray($var, $value); + $currVars[] = $this->generateVariableArray($variableName, $value); // Add it to the stack $this->setVarStack($this->currGroup, $currVars); @@ -366,22 +366,22 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Modify an entry on the stack * - * @param $var The variable we are looking for - * @param $value The value we want to store in the variable + * @param $variableName The variable we are looking for + * @param $value The value we want to store in the variable * @return void * @throws NoVariableException If the given variable is not found */ - private function modifyVariable ($var, $value) { + private function modifyVariable ($variableName, $value) { // Replace all dashes to underscores to match variables with configuration entries - $var = trim($this->convertDashesToUnderscores($var)); + $variableName = trim($this->convertDashesToUnderscores($variableName)); // Get index for variable - $index = $this->getVariableIndex($var); + $index = $this->getVariableIndex($variableName); // Is the variable set? if ($index === false) { // Unset variables cannot be modified - throw new NoVariableException(array($this, $var, $value), self::EXCEPTION_VARIABLE_IS_MISSING); + throw new NoVariableException(array($this, $variableName, $value), self::EXCEPTION_VARIABLE_IS_MISSING); } // END - if // Then modify it @@ -405,22 +405,22 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * variable is already set. If so, the variable got modified, otherwise * added. * - * @param $varGroup Variable group to use - * @param $var Variable to set - * @param $value Value to set + * @param $varGroup Variable group to use + * @param $variableName Variable to set + * @param $value Value to set * @return void */ - protected function setVariable ($varGroup, $var, $value) { + protected function setVariable ($varGroup, $variableName, $value) { // Replace all dashes to underscores to match variables with configuration entries - $var = trim($this->convertDashesToUnderscores($var)); + $variableName = trim($this->convertDashesToUnderscores($variableName)); // Get index for variable - $index = $this->getVariableIndex($var); + $index = $this->getVariableIndex($variableName); // Is the variable set? if ($index === false) { // Not found, add it - $this->varStack[$varGroup][] = $this->generateVariableArray($var, $value); + $this->varStack[$varGroup][] = $this->generateVariableArray($variableName, $value); } else { // Then modify it $this->setVariableValue($this->currGroup, $index, $value); @@ -431,17 +431,17 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * "Generates" (better returns) an array for all variables for given * variable/value pay. * - * @param $var Variable to set - * @param $value Value to set - * @return $varData Variable data array + * @param $variableName Variable to set + * @param $value Value to set + * @return $varData Variable data array */ - private function generateVariableArray ($var, $value) { + private function generateVariableArray ($variableName, $value) { // Replace all dashes to underscores to match variables with configuration entries - $var = trim($this->convertDashesToUnderscores($var)); + $variableName = trim($this->convertDashesToUnderscores($variableName)); // Generate the temporary array $varData = array( - 'name' => $var, + 'name' => $variableName, 'value' => $value ); @@ -580,45 +580,45 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Assign (add) a given variable with a value * - * @param $var The variable we are looking for - * @param $value The value we want to store in the variable + * @param $variableName 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) { + public final function assignVariable ($variableName, $value) { // Replace all dashes to underscores to match variables with configuration entries - $var = trim($this->convertDashesToUnderscores($var)); + $variableName = trim($this->convertDashesToUnderscores($variableName)); // Empty variable found? - if (empty($var)) { + if (empty($variableName)) { // Throw an exception - throw new EmptyVariableException(array($this, 'var'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + throw new EmptyVariableException(array($this, 'variableName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); } // END - if // First search for the variable if it was already added - $index = $this->getVariableIndex($var); + $index = $this->getVariableIndex($variableName); // Was it found? if ($index === false) { // Add it to the stack - //* DEBUG: */ $this->debugOutput(__METHOD__ . ':ADD: ' . $var . '[' . gettype($value) . ']=' . $value); - $this->addVariable($var, $value); + //* DEBUG: */ $this->debugOutput(__METHOD__ . ':ADD: ' . $variableName . '[' . gettype($value) . ']=' . $value); + $this->addVariable($variableName, $value); } elseif (!empty($value)) { // Modify the stack entry - //* DEBUG: */ $this->debugOutput(__METHOD__ . ':MOD: ' . $var . '[' . gettype($value) . ']=' . $value); - $this->modifyVariable($var, $value); + //* DEBUG: */ $this->debugOutput(__METHOD__ . ':MOD: ' . $variableName . '[' . gettype($value) . ']=' . $value); + $this->modifyVariable($variableName, $value); } } /** * Removes a given variable * - * @param $var The variable we are looking for + * @param $variableName The variable we are looking for * @return void */ - public final function removeVariable ($var) { + public final function removeVariable ($variableName) { // First search for the variable if it was already added - $index = $this->getVariableIndex($var); + $index = $this->getVariableIndex($variableName); // Was it found? if ($index !== false) { @@ -777,24 +777,25 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * Try to assign an extracted template variable as a "content" or 'config' * variable. * - * @param $varName The variable's name (shall be content orconfig) by - * default - * @param $var The variable we want to assign + * @param $varName The variable's name (shall be content or config) + * by default + * @param $variableName The variable we want to assign + * @return void */ private function assignTemplateVariable ($varName, $var) { // Replace all dashes to underscores to match variables with configuration entries - $var = trim($this->convertDashesToUnderscores($var)); + $variableName = trim($this->convertDashesToUnderscores($variableName)); // Debug message - //* DEBUG: */ $this->debugOutput(__METHOD__ . ': varName=' . $varName . ',var=' . $var); + //* DEBUG: */ $this->debugOutput(__METHOD__ . ': varName=' . $varName . ',variableName=' . $variableName); // Is it not a config variable? if ($varName != 'config') { // Regular template variables - $this->assignVariable($var, ''); + $this->assignVariable($variableName, ''); } else { // Configuration variables - $this->assignConfigVariable($var); + $this->assignConfigVariable($variableName); } } @@ -1019,7 +1020,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { } // END - if // Do we have some quotes left and right side? Then it is free text - if ((substr($varMatches[2][$key], 0, 1) == "\"") && (substr($varMatches[2][$key], -1, 1) == "\"")) { + if ((substr($varMatches[2][$key], 0, 1) == '"') && (substr($varMatches[2][$key], -1, 1) == '"')) { // Free string detected! Which we can assign directly $this->assignVariable($var, $varMatches[3][$key]); } elseif (!empty($varMatches[2][$key])) { @@ -1143,16 +1144,16 @@ class BaseTemplateEngine extends BaseFrameworkSystem { /** * Assign a given congfiguration variable with a value * - * @param $var The configuration variable we want to assign + * @param $variableName The configuration variable we want to assign * @return void */ - public function assignConfigVariable ($var) { + public function assignConfigVariable ($variableName) { // Replace all dashes to underscores to match variables with configuration entries - $var = trim($this->convertDashesToUnderscores($var)); + $variableName = trim($this->convertDashesToUnderscores($variableName)); // Sweet and simple... - //* DEBUG: */ $this->debugOutput(__METHOD__ . ': var=' . $var . ',getConfigEntry()=' . $this->getConfigInstance()->getConfigEntry($var)); - $this->setVariable('config', $var, $this->getConfigInstance()->getConfigEntry($var)); + //* DEBUG: */ $this->debugOutput(__METHOD__ . ': variableName=' . $variableName . ',getConfigEntry()=' . $this->getConfigInstance()->getConfigEntry($variableName)); + $this->setVariable('config', $variableName, $this->getConfigInstance()->getConfigEntry($variableName)); } /** @@ -1194,7 +1195,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { //* DEBUG: */ $this->debugOutput(__METHOD__ . ': name=' . $currVariable['name'] . ',value=' . $value); // Remove it from stack - $this->removeVariable($index, 'general'); + $this->removeVariable($currVariable['name'], 'general'); // Re-assign the variable //* DEBUG: */ $this->debugOutput(__METHOD__ . ': value='. $value . ',name=' . $currVariable['name'] . ',index=' . $index); diff --git a/inc/config/class_FrameworkConfiguration.php b/inc/config/class_FrameworkConfiguration.php index 914d13a1..20d80cd6 100644 --- a/inc/config/class_FrameworkConfiguration.php +++ b/inc/config/class_FrameworkConfiguration.php @@ -176,7 +176,7 @@ class FrameworkConfiguration implements Registerable { } // END - if // Set the configuration value - //* NOISY-DEBUG: */ print(__METHOD__ . ':configEntry=' . $configEntry . ',configValue=' . $configValue . PHP_EOL); + /* NOISY-DEBUG: */ print(__METHOD__ . ':configEntry=' . $configEntry . ',configValue=' . $configValue . PHP_EOL); $this->config[$configEntry] = $configValue; // Resort the array -- 2.30.2