* @return void
*/
private final function setTemplateType ($templateType) {
- // Cast it
- $templateType = (string) $templateType;
-
- // And set it (only 2 letters)
- $this->templateType = $templateType;
+ $this->templateType = (string) $templateType;
}
/**
* @return void
*/
private final function setLastTemplate ($template) {
- // Cast it to string
- $template = (string) $template;
- $this->lastTemplate = $template;
+ $this->lastTemplate = (string) $template;
}
/**
* @return void
*/
public final function setBasePath ($basePath) {
- // Cast it
- $basePath = (string) $basePath;
-
// And set it
- $this->basePath = $basePath;
+ $this->basePath = (string) $basePath;
}
/**
* @return void
*/
public final function setRawTemplateExtension ($templateExtension) {
- // Cast it
- $templateExtension = (string) $templateExtension;
-
// And set it
- $this->templateExtension = $templateExtension;
+ $this->templateExtension = (string) $templateExtension;
}
/**
* @return void
*/
public final function setCodeTemplateExtension ($codeExtension) {
- // Cast it
- $codeExtension = (string) $codeExtension;
-
// And set it
- $this->codeExtension = $codeExtension;
+ $this->codeExtension = (string) $codeExtension;
}
/**
* @return void
*/
public final function setCompileOutputPath ($compileOutputPath) {
- // Cast it
- $compileOutputPath = (string) $compileOutputPath;
-
// And set it
- $this->compileOutputPath = $compileOutputPath;
+ $this->compileOutputPath = (string) $compileOutputPath;
}
/**
* @return void
*/
private final function setRawTemplateData ($rawTemplateData) {
- // Cast it to string
- $rawTemplateData = (string) $rawTemplateData;
-
// And store it in this class
- $this->rawTemplateData = $rawTemplateData;
+ //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($rawTemplateData)." Bytes set.<br />\n";
+ //* DEBUG: */ echo $this->currGroup." variables: ".count($this->varStack[$this->currGroup]).", groups=".count($this->varStack)."<br />\n";
+ $this->rawTemplateData = (string) $rawTemplateData;
+ }
+
+ /**
+ * Getter for raw template data
+ *
+ * @return $rawTemplateData The raw data from the template
+ */
+ public final function getRawTemplateData () {
+ //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($this->rawTemplateData)." Bytes read.<br />\n";
+ return $this->rawTemplateData;
}
/**
* @return void
*/
private final function setCompiledData ($compiledData) {
- // Cast it to string
- $compiledData = (string) $compiledData;
-
// And store it in this class
- $this->compiledData = $compiledData;
+ //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($compiledData)." Bytes set.<br />\n";
+ $this->compiledData = (string) $compiledData;
+ }
+
+ /**
+ * Getter for compiled templates
+ */
+ public final function getCompiledData () {
+ //* DEBUG: */ echo __METHOD__.":".$this->getUniqueId().": ".strlen($this->compiledData)." Bytes read.<br />\n";
+ return $this->compiledData;
}
/**
* @return void
*/
private function loadTemplate ($template) {
- // Cast it to string
- $template = (string) $template;
-
// Get extension for the template
$ext = $this->getRawTemplateExtension();
$this->getBasePath(),
$this->getLanguageInstance()->getLanguageCode(),
$this->getTemplateType(),
- $template,
+ (string) $template,
$ext
);
private function finalizeVariableCompilation () {
// Get the content
$content = $this->getRawTemplateData();
+ //* DEBUG: */ echo __METHOD__.": content before=".strlen($content)." (".md5($content).")<br />\n";
// Walk through all variables
foreach ($this->varStack['general'] as $currEntry) {
+ //* DEBUG: */ echo __METHOD__.": name=".$currEntry['name'].", value=<pre>".htmlentities($currEntry['value'])."</pre>\n";
// Replace all [$var] or {?$var?} with the content
- //* DEBUG: */ echo "name=".$currEntry['name'].", value=<pre>".htmlentities($currEntry['value'])."</pre>\n";
+ // Old behaviour, will become obsolete!
$content = str_replace("\$content[".$currEntry['name']."]", $currEntry['value'], $content);
+
+ // Yet another old way
$content = str_replace("[".$currEntry['name']."]", $currEntry['value'], $content);
+
+ // The new behaviour
$content = str_replace("{?".$currEntry['name']."?}", $currEntry['value'], $content);
} // END - for
+ //* DEBUG: */ echo __METHOD__.": content after=".strlen($content)." (".md5($content).")<br />\n";
+
// Set the content back
$this->setRawTemplateData($content);
}
- /**
- * Getter for raw template data
- *
- * @return $rawTemplateData The raw data from the template
- */
- public final function getRawTemplateData () {
- return $this->rawTemplateData;
- }
-
- /**
- * Getter for compiled templates
- */
- public final function getCompiledData () {
- return $this->compiledData;
- }
-
/**
* Load a specified web template into the engine
*
- * @param $template The web template we shall load which is
- * located in "html" by default
+ * @param $template The web template we shall load which is located in
+ * "html" by default
* @return void
*/
public function loadWebTemplate ($template) {
/**
* Load a specified email template into the engine
*
- * @param $template The email template we shall load which is
- * located in "emails" by default
+ * @param $template The email template we shall load which is located in
+ * "emails" by default
* @return void
*/
public function loadEmailTemplate ($template) {
$eval = sprintf("%s<%%php %s %%>%s", $evalLeft, $evalMiddle, $evalRight);
} // END - while
- // Prepare PHP code for eval() command
+ // Get length for check if PHP code was found
$evalLength = strlen($eval);
+
+ // Prepare PHP code for eval() command
$eval = str_replace(
"<%php", "\";",
str_replace(
)
);
- // Did something change?
+ // Was PHP code found in template?
if (strlen($eval) != $evalLength) {
// Run the constructed command. This will "compile" all variables in
@eval($eval);
+ //* DEBUG: */ print("<pre>".htmlentities($eval)."</pre>");
} // END - if
// Goes something wrong?
$this->debugOutput(sprintf("Failed eval() code: <pre>%s</pre>", $this->markupCode($eval, true)), true);
// Output backtrace here
- $this->debugBacktrace();
+ $this->debugBackTrace();
} // END - if
// Set raw template data
$this->setRawTemplateData($result);
$cnt++;
- }
+ } // END - while
+
+ // Final variable assignment
+ $this->finalizeVariableCompilation();
// Set the new content
- $this->setCompiledData($result);
+ $this->setCompiledData($this->getRawTemplateData());
}
/**
* @throws InvalidArrayCountException If an unexpected array
* count has been found
*/
- public final function compileTemplate () {
+ public function compileTemplate () {
// We will only work with template type "code" from configuration
if ($this->getTemplateType() != $this->getConfigInstance()->readConfig('code_template_type')) {
// Abort here
}
/**
- * Output the compiled page to the outside world. In case of web templates
- * this would be vaild (X)HTML code. And in case of email templates this
- * would store a prepared email body inside the template engine.
+ * A old deprecated method
*
* @return void
+ * @deprecated
+ * @see BaseTemplateEngine::transferToResponse
*/
public function output () {
// Check which type of template we have
public final function getVariableGroups () {
return $this->varGroups;
}
+
+ /**
+ * Renames a variable in code and in stack
+ *
+ * @param $oldName Old name of variable
+ * @param $newName New name of variable
+ * @return void
+ */
+ public function renameVariable ($oldName, $newName) {
+ //* DEBUG: */ echo __METHOD__.": oldName={$oldName}, newName={$newName}<br />\n";
+ // Get raw template code
+ $rawData = $this->getRawTemplateData();
+
+ // Replace it
+ $rawData = str_replace($oldName, $newName, $rawData);
+
+ // Set the code back
+ $this->setRawTemplateData($rawData);
+ }
}
// [EOF]