From 84dcf5e4e7a6bbe55c6beac203729a82e5a2c2de Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 6 Apr 2015 01:21:21 +0200 Subject: [PATCH] Cleanup + expanded CompileableTemplate with a lot public methods from BaseTemplateEngine MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../template/class_CompileableTemplate.php | 89 +++++++++++++++++++ .../class_XmlRewriterTemplateDecorator.php | 10 --- .../template/class_BaseTemplateEngine.php | 36 ++++---- 3 files changed, 104 insertions(+), 31 deletions(-) diff --git a/inc/classes/interfaces/template/class_CompileableTemplate.php b/inc/classes/interfaces/template/class_CompileableTemplate.php index 5f426564..d3f2f764 100644 --- a/inc/classes/interfaces/template/class_CompileableTemplate.php +++ b/inc/classes/interfaces/template/class_CompileableTemplate.php @@ -189,6 +189,95 @@ interface CompileableTemplate extends FrameworkInterface { * @return $compactedContent The compacted content */ function compactContent ($uncompactedContent); + + /** + * Getter for given variable group + * + * @param $variableGroup Variable group to check + * @return $varStack Found variable group + */ + function getVarStack ($variableGroup); + + /** + * Settter for variable group + * + * @param $groupName Name of variable group + * @param $add Whether add this group + * @return void + */ + function setVariableGroup ($groupName, $add = TRUE); + + /** + * Getter for template type + * + * @return $templateType The current template's type + */ + function getTemplateType (); + + /** + * Getter for base path + * + * @return $templateBasePath The relative base path for all templates + */ + function getTemplateBasePath (); + + /** + * Getter for generic base path + * + * @return $templateBasePath The relative base path for all templates + */ + function getGenericBasePath (); + + /** + * Getter for template extension + * + * @return $templateExtension The file extension for all uncompiled + * templates + */ + function getRawTemplateExtension (); + + /** + * Getter for code-template extension + * + * @return $codeExtension The file extension for all code- + * templates + */ + function getCodeTemplateExtension (); + + /** + * Getter for raw template data + * + * @return $rawTemplateData The raw data from the template + */ + function getRawTemplateData (); + + /** + * Load a specified web template into the engine + * + * @param $template The web template we shall load which is located in + * 'html' by default + * @return void + */ + function loadWebTemplate ($template); + + /** + * Assigns a lot variables into the stack of currently loaded template. + * This method should only be used in very rare circumstances, e.g. when + * you have to copy a whole set of variables into the template engine. + * Before you use this method, please make sure you have considered all + * other possiblities. + * + * @param $variables An array with variables to be assigned + * @return void + */ + function assignMultipleVariables (array $variables); + + /** + * Getter for variable group array + * + * @return $variableGroups All variable groups + */ + function getVariableGroups (); } // [EOF] diff --git a/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php b/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php index f2fcfd48..13e07abd 100644 --- a/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php +++ b/inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php @@ -193,16 +193,6 @@ class XmlRewriterTemplateDecorator extends BaseDecorator implements CompileableT $this->getTemplateInstance()->removeVariable($variableName, $variableGroup); } - /** - * Getter for compiled templates - * - * @return $compiledData Compiled template data - */ - public final function getCompiledData () { - // Call the inner class' method - return $this->getTemplateInstance()->getCompiledData(); - } - /** * Load a specified web template into the engine * diff --git a/inc/classes/main/template/class_BaseTemplateEngine.php b/inc/classes/main/template/class_BaseTemplateEngine.php index ba5208cb..e4f3130d 100644 --- a/inc/classes/main/template/class_BaseTemplateEngine.php +++ b/inc/classes/main/template/class_BaseTemplateEngine.php @@ -505,7 +505,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * @param $templateBasePath The relative base path for all templates * @return void */ - public final function setTemplateBasePath ($templateBasePath) { + protected final function setTemplateBasePath ($templateBasePath) { // And set it $this->templateBasePath = (string) $templateBasePath; } @@ -537,7 +537,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * templates * @return void */ - public final function setRawTemplateExtension ($templateExtension) { + protected final function setRawTemplateExtension ($templateExtension) { // And set it $this->templateExtension = (string) $templateExtension; } @@ -549,7 +549,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * templates * @return void */ - public final function setCodeTemplateExtension ($codeExtension) { + protected final function setCodeTemplateExtension ($codeExtension) { // And set it $this->codeExtension = (string) $codeExtension; } @@ -583,7 +583,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * templates * @return void */ - public final function setCompileOutputPath ($compileOutputPath) { + protected final function setCompileOutputPath ($compileOutputPath) { // And set it $this->compileOutputPath = (string) $compileOutputPath; } @@ -651,7 +651,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { * * @return $compiledData Compiled template data */ - public final function getCompiledData () { + protected final function getCompiledData () { //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']: ' . strlen($this->compiledData) . ' Bytes read.'); return $this->compiledData; } @@ -830,13 +830,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('BASE-TEMPLATE[' . __METHOD__ . ':' . __LINE__ . ']:template=' . $template); // Template not found, but maybe variable assigned? - if ($this->getVariableIndex($template, 'config') !== FALSE) { - // Use that content here - $this->loadedRawData[$template] = $this->readVariable($template, 'config'); - - // Recursive protection: - array_push($this->loadedTemplates, $template); - } elseif ($this->getVariableIndex($template) !== FALSE) { + if ($this->getVariableIndex($template) !== FALSE) { // Use that content here $this->loadedRawData[$template] = $this->readVariable($template); @@ -1192,20 +1186,20 @@ class BaseTemplateEngine extends BaseFrameworkSystem { } /** - * Injects an array of config variables into the stack of currently loaded - * template. This method should only be used in very rare circumstances, - * e.g. when you have to copy a whole set of variables into the template - * engine. Before you use this method, please make sure you have considered - * all other possiblities. + * Assigns a lot variables into the stack of currently loaded template. + * This method should only be used in very rare circumstances, e.g. when + * you have to copy a whole set of variables into the template engine. + * Before you use this method, please make sure you have considered all + * other possiblities. * - * @param $variables An array with variables to be injected + * @param $variables An array with variables to be assigned * @return void */ - public function injectConfigVariables (array $variables) { + public function assignMultipleVariables (array $variables) { // "Inject" all foreach ($variables as $name => $value) { // Set variable with name for 'config' group - $this->setVariable('config', $name, $value); + $this->assignVariable($name, $value); } // END - foreach } @@ -1277,7 +1271,7 @@ class BaseTemplateEngine extends BaseFrameworkSystem { $this->assignConfigVariable($value); } else { // Re-assign the value directly - $this->setVariable('config', $currVariable['name'], $value); + $this->assignVariable($currVariable['name'], $value); } } // END - foreach } -- 2.30.2