X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=inline;f=inc%2Fclasses%2Fmain%2Ftemplate%2Fclass_TemplateEngine.php;h=4c1500625a55fdf0b5d297927517d569997b9308;hb=0a4c7d2793ad13bfe4798f947ef39529f32b6567;hp=16fbd3c8f567b500551e81c7cfaba0e9ffc84352;hpb=30d74f6c90bb37a58e10c8a789cd2b185f26a1fb;p=shipsimu.git diff --git a/inc/classes/main/template/class_TemplateEngine.php b/inc/classes/main/template/class_TemplateEngine.php index 16fbd3c..4c15006 100644 --- a/inc/classes/main/template/class_TemplateEngine.php +++ b/inc/classes/main/template/class_TemplateEngine.php @@ -167,7 +167,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate } // Get configuration instance - $cfgInstance = $tplInstance->getConfigInstance(); + $cfgInstance = FrameworkConfiguration::getInstance(); // Set the base path $tplInstance->setBasePath($basePath); @@ -547,13 +547,6 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate * required method */ private function loadRawTemplateData ($fqfn) { - // Debug message - if ((defined('DEBUG_TEMPLATE')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Template %s vom Typ %s wird geladen.
\n", - $this->__toString(), - $template, - $this->getTemplateType() - )); - // Get a input/output instance from the middleware $ioInstance = $this->getFileIOInstance(); @@ -572,12 +565,6 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // Load the raw template $rawTemplateData = $ioInstance->loadFileContents($fqfn); - // Debug message - if ((defined('DEBUG_TEMPLATE')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] %s Byte Rohdaten geladen.
\n", - $this->__toString(), - strlen($rawTemplateData) - )); - // Store the template's contents into this class $this->setRawTemplateData($rawTemplateData); @@ -877,6 +864,31 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate } } + /** + * Finalizes the compilation of all template variables + * + * @return void + */ + private function finalizeVariableCompilation () { + // Get the content + $content = $this->getRawTemplateData(); + + // Walk through all variables + for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) { + // Get current entry + $currEntry = $idx->current(); + + // Replace all [$var] or {?$var?} with the content + //* DEBUG: */ echo "name=".$currEntry['name'].", value=
".htmlentities($currEntry['value'])."
\n"; + $content = str_replace("\$content[".$currEntry['name']."]", $currEntry['value'], $content); + $content = str_replace("[".$currEntry['name']."]", $currEntry['value'], $content); + $content = str_replace("{?".$currEntry['name']."?}", $currEntry['value'], $content); + } // END - for + + // Set the content back + $this->setRawTemplateData($content); + } + /** * Getter for raw template data * @@ -950,12 +962,17 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // Iterate through all variables for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) { + // Get current variable from the stack $currVariable = $idx->current(); // Transfer it's name/value combination to the $content array + //* DEBUG: */ echo $currVariable['name']."=
".htmlentities($currVariable['value'])."
\n"; $dummy[$currVariable['name']] = $currVariable['value']; - } + + }// END - if + + // Set the new variable (don't remove the second dollar !) $$validVar = $dummy; // Prepare all configuration variables @@ -965,19 +982,25 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate unset($idx); unset($currVariable); + // Finalize the compilation of template variables + $this->finalizeVariableCompilation(); + // Prepare the eval() command for comiling the template - $eval = sprintf("\$this->setCompiledData(\"%s\");", + $eval = sprintf("\$result = \"%s\";", addslashes($this->getRawTemplateData()) ); // Debug message - if (((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Konstruierte PHP-Anweisung:
%s

\n", + if ((defined('DEBUG_EVAL')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Constructed PHP command:
%s

\n", $this->__toString(), htmlentities($eval) )); // Run the constructed command. This will "compile" all variables in eval($eval); + + // Set the new content + $this->setCompiledData($result); } /** @@ -994,7 +1017,7 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate if ($this->getTemplateType() != $this->getConfigInstance()->readConfig("code_template_type")) { // Abort here throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->readConfig("code_template_type")), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED); - } + } // END - if // Get the raw data. $rawData = $this->getRawTemplateData(); @@ -1014,7 +1037,6 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // // The main analysis $this->analyzeTemplate($templateMatches); - $this->debugInstance(); // Compile raw template data $this->compileRawTemplateData($templateMatches); @@ -1024,9 +1046,14 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate // Are some raw templates found and loaded? if (count($this->rawTemplates) > 0) { + // Insert all raw templates $this->insertRawTemplates(); - } + + // Remove the raw template content as well + $this->setRawTemplateData(""); + + } // END - if } // END - if($templateMatches ... }