3 * The own template engine for loading caching and sending out the web pages
6 * @author Roland Haeder <webmaster@mxchange.org>
8 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
9 * @license GNU GPL 3.0 or any newer version
10 * @link http://www.mxchange.org
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate {
27 * The local path name where all templates and sub folders for special
28 * templates are stored. We will internally determine the language plus
29 * "html" for web templates or "emails" for email templates
31 private $basePath = "";
34 * The extension for web and email templates (not compiled templates)
36 private $templateExtension = ".tpl";
39 * The extension for code templates (not compiled templates)
41 private $codeExtension = ".ctp";
44 * Path relative to $basePath and language code for compiled code-templates
46 private $compileOutputPath = "templates/_compiled";
49 * The raw (maybe uncompiled) template
51 private $rawTemplateData = "";
54 * Template data with compiled-in variables
56 private $compiledData = "";
59 * The last loaded template's FQFN for debugging the engine
61 private $lastTemplate = "";
64 * The variable stack for the templates. This must be initialized and
65 * shall become an instance of FrameworkArrayObject.
67 private $varStack = null;
70 * Configuration variables in a simple array
72 private $configVariables = array();
75 * The language instance which should link to an object of LanguageSystem
77 private $langInstance = null;
80 * Loaded templates for recursive protection and detection
82 private $loadedTemplates = array();
85 * Compiled templates for recursive protection and detection
87 private $compiledTemplates = array();
90 * Loaded raw template data
92 private $loadedRawData = null;
95 * Raw templates which are linked in code templates
97 private $rawTemplates = null;
100 * A regular expression for variable=value pairs
102 private $regExpVarValue = '/([\w_]+)(="([^"]*)"|=([\w_]+))?/';
105 * A regular expression for filtering out code tags
107 * E.g.: {?template:variable=value;var2=value2;[...]?}
109 private $regExpCodeTags = '/\{\?([a-z_]+)(:("[^"]+"|[^?}]+)+)?\?\}/';
111 // Exception codes for the template engine
112 const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED = 0xa00;
113 const TEMPLATE_CONTAINS_INVALID_VAR_EXCEPTION = 0xa01;
116 * Private constructor
120 private final function __construct () {
121 // Call parent constructor
122 parent::constructor(__CLASS__);
124 // Set part description
125 $this->setPartDescr("Template-Engine");
127 // Create unique ID number
128 $this->createUniqueID();
131 $this->removeNumberFormaters();
132 $this->removeSystemArray();
136 * Creates an instance of the class TemplateEngine and prepares it for usage
138 * @param $basePath The local base path for all templates
139 * @param $langInstance An instance of LanguageSystem (default)
140 * @param $ioInstance An instance of FileIOHandler (default, middleware!)
141 * @return $tplInstance An instance of TemplateEngine
142 * @throws BasePathIsEmptyException If the provided $basePath is empty
143 * @throws InvalidBasePathStringException If $basePath is no string
144 * @throws BasePathIsNoDirectoryException If $basePath is no
145 * directory or not found
146 * @throws BasePathReadProtectedException If $basePath is
149 public final static function createTemplateEngine ($basePath, $langInstance, $ioInstance) {
150 // Get a new instance
151 $tplInstance = new TemplateEngine();
153 // Is the base path valid?
154 if (empty($basePath)) {
155 // Base path is empty
156 throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
157 } elseif (!is_string($basePath)) {
159 throw new InvalidBasePathStringException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_STRING);
160 } elseif (!is_dir($basePath)) {
162 throw new BasePathIsNoDirectoryException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
163 } elseif (!is_readable($basePath)) {
165 throw new BasePathReadProtectedException(array($tplInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
168 // Get configuration instance
169 $cfgInstance = $tplInstance->getConfigInstance();
172 $tplInstance->setBasePath($basePath);
174 // Initialize the variable stack
175 $tplInstance->initVariableStack();
177 // Set the language and IO instances
178 $tplInstance->setLanguageInstance($langInstance);
179 $tplInstance->setIOInstance($ioInstance);
181 // Set template extensions
182 $tplInstance->setRawTemplateExtension($cfgInstance->readConfig("raw_template_extension"));
183 $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig("code_template_extension"));
185 // Absolute output path for compiled templates
186 $tplInstance->setCompileOutputPath(PATH . $cfgInstance->readConfig("compile_output_path"));
188 // Return the prepared instance
193 * Search for a variable in the stack
195 * @param $var The variable we are looking for
196 * @return $idx FALSE means not found, > 0 means found on a specific index
198 private function isVariableAlreadySet ($var) {
199 // First everything is not found
203 for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) {
205 $currEntry = $idx->current();
207 // Is the entry found?
208 if ($currEntry['name'] == $var) {
210 $found = $idx->key();
215 // Return the current position
220 * Add a variable to the stack
222 * @param $var The variable we are looking for
223 * @param $value The value we want to store in the variable
226 private function addVariable ($var, $value) {
227 // Add it to the stack
228 $this->varStack->append(array(
235 * Modify an entry on the stack
237 * @param $var The variable we are looking for
238 * @param $value The value we want to store in the variable
241 private function modifyVariable ($var, $value) {
242 // It should be there so let's look again...
243 for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) {
245 $currEntry = $idx->current();
247 // Is this the requested variable?
248 if ($currEntry['name'] == $var) {
249 // Change it to the other value
250 $this->varStack->offsetSet($idx->key(), array(
259 * Initialize the variable stack. This holds all variables for later
264 public final function initVariableStack () {
265 $this->varStack = new FrameworkArrayObject();
269 * Setter for language instance which should be LanguageSystem
271 * @param $langInstance The language instance
274 public final function setLanguageInstance (ManageableLanguage $langInstance) {
275 $this->langInstance = $langInstance;
279 * Setter for file I/O instance which should be FileIOHandler
281 * @param $ioInstance The file I/O instance
284 public final function setIOInstance (FileIOHandler $ioInstance) {
285 $this->ioInstance = $ioInstance;
289 * Getter for file I/O instance which should be FileIOHandler
291 * @return $ioInstance The file I/O instance
293 public final function getIOInstance () {
294 return $this->ioInstance;
298 * Setter for base path
300 * @param $basePath The local base path for all templates
303 public final function setBasePath ($basePath) {
305 $basePath = (string) $basePath;
308 $this->basePath = $basePath;
312 * Getter for base path
314 * @return $basePath The local base path for all templates
316 public final function getBasePath () {
318 return $this->basePath;
322 * Setter for template extension
324 * @param $templateExtension The file extension for all uncompiled
328 public final function setRawTemplateExtension ($templateExtension) {
330 $templateExtension = (string) $templateExtension;
333 $this->templateExtension = $templateExtension;
337 * Setter for code template extension
339 * @param $codeExtension The file extension for all uncompiled
343 public final function setCodeTemplateExtension ($codeExtension) {
345 $codeExtension = (string) $codeExtension;
348 $this->codeExtension = $codeExtension;
352 * Getter for template extension
354 * @return $templateExtension The file extension for all uncompiled
357 public final function getRawTemplateExtension () {
359 return $this->templateExtension;
363 * Getter for code-template extension
365 * @return $codeExtension The file extension for all code-
368 public final function getCodeTemplateExtension () {
370 return $this->codeExtension;
374 * Setter for path of compiled templates
376 * @param $compileOutputPath The local base path for all
380 public final function setCompileOutputPath ($compileOutputPath) {
382 $compileOutputPath = (string) $compileOutputPath;
385 $this->compileOutputPath = $compileOutputPath;
389 * Setter for template type. Only "html", "emails" and "compiled" should
392 * @param $templateType The current template's type
395 private final function setTemplateType ($templateType) {
397 $templateType = (string) $templateType;
399 // And set it (only 2 letters)
400 $this->templateType = $templateType;
404 * Getter for template type
406 * @return $templateType The current template's type
408 public final function getTemplateType () {
409 return $this->templateType;
413 * Setter for the last loaded template's FQFN
415 * @param $template The last loaded template
418 private final function setLastTemplate ($template) {
420 $template = (string) $template;
421 $this->lastTemplate = $template;
425 * Getter for the last loaded template's FQFN
427 * @return $template The last loaded template
429 private final function getLastTemplate () {
430 return $this->lastTemplate;
434 * Assign (add) a given variable with a value
436 * @param $var The variable we are looking for
437 * @param $value The value we want to store in the variable
440 public final function assignVariable ($var, $value) {
441 // First search for the variable if it was already added
442 $idx = $this->isVariableAlreadySet($var);
445 if ($idx === false) {
446 // Add it to the stack
447 $this->addVariable($var, $value);
448 } elseif (!empty($value)) {
449 // Modify the stack entry
450 $this->modifyVariable($var, $value);
455 * Assign a given congfiguration variable with a value
457 * @param $var The configuration variable we are looking for
458 * @param $value The value we want to store in the variable
461 public final function assignConfigVariable ($var, $value) {
462 // Sweet and simple...
463 $this->configVariables[$var] = $value;
467 * Removes a given variable
469 * @param $var The variable we are looking for
472 public final function removeVariable ($var) {
473 // First search for the variable if it was already added
474 $idx = $this->isVariableAlreadySet($var);
477 if ($idx !== false) {
478 // Remove this variable
479 $this->varStack->offsetUnset($idx);
484 * Private setter for raw template data
486 * @param $rawTemplateData The raw data from the template
489 private final function setRawTemplateData ($rawTemplateData) {
491 $rawTemplateData = (string) $rawTemplateData;
493 // And store it in this class
494 $this->rawTemplateData = $rawTemplateData;
498 * Private setter for compiled templates
500 private final function setCompiledData ($compiledData) {
502 $compiledData = (string) $compiledData;
504 // And store it in this class
505 $this->compiledData = $compiledData;
509 * Private loader for all template types
511 * @param $template The template we shall load
514 private final function loadTemplate ($template) {
516 $template = (string) $template;
518 // Get extension for the template
519 $ext = $this->getRawTemplateExtension();
521 // If we shall load a code-template we need to switch the file extension
522 if ($this->getTemplateType() == $this->getConfigInstance()->readConfig("code_template_type")) {
523 // Switch over to the code-template extension
524 $ext = $this->getCodeTemplateExtension();
527 // Construct the FQFN for the template by honoring the current language
528 $fqfn = sprintf("%s%s/%s/%s%s",
529 $this->getBasePath(),
530 $this->langInstance->getLanguageCode(),
531 $this->getTemplateType(),
536 // Load the raw template data
537 $this->loadRawTemplateData($fqfn);
541 * A private loader for raw template names
543 * @param $fqfn The full-qualified file name for a template
545 * @throws NullPointerException If $inputInstance is null
546 * @throws NoObjectException If $inputInstance is not an object
547 * @throws MissingMethodException If $inputInstance is missing a
550 private function loadRawTemplateData ($fqfn) {
552 if ((defined('DEBUG_TEMPLATE')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Template <strong>%s</strong> vom Typ <strong>%s</strong> wird geladen.<br />\n",
555 $this->getTemplateType()
558 // Get a input/output instance from the middleware
559 $ioInstance = $this->getIOInstance();
561 // Validate the instance
562 if (is_null($ioInstance)) {
564 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
565 } elseif (!is_object($ioInstance)) {
566 // Throw another exception
567 throw new NoObjectException($ioInstance, self::EXCEPTION_IS_NO_OBJECT);
568 } elseif (!method_exists($ioInstance, 'loadFileContents')) {
569 // Throw yet another exception
570 throw new MissingMethodException(array($ioInstance, 'loadFileContents'), self::EXCEPTION_MISSING_METHOD);
573 // Load the raw template
574 $rawTemplateData = $ioInstance->loadFileContents($fqfn);
577 if ((defined('DEBUG_TEMPLATE')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] <strong>%s</strong> Byte Rohdaten geladen.<br />\n",
579 strlen($rawTemplateData)
582 // Store the template's contents into this class
583 $this->setRawTemplateData($rawTemplateData);
585 // Remember the template's FQFN
586 $this->setLastTemplate($fqfn);
590 * Try to assign an extracted template variable as a "content" or "config"
593 * @param $varName The variable's name (shall be content or
595 * @param $var The variable we want to assign
597 private function assignTemplateVariable ($varName, $var) {
598 // Is it not a config variable?
599 if ($varName != "config") {
600 // Regular template variables
601 $this->assignVariable($var, "");
603 // Configuration variables
604 $this->assignConfigVariable($var, $this->getConfigInstance()->readConfig($var));
609 * Extract variables from a given raw data stream
611 * @param $rawData The raw template data we shall analyze
613 * @throws InvalidTemplateVariableNameException If a variable name
617 private function extractVariablesFromRawData ($rawData) {
619 $rawData = (string) $rawData;
621 // Search for variables
622 @preg_match_all('/\$(\w+)(\[(\w+)\])?/', $rawData, $variableMatches);
624 // Did we find some variables?
625 if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) {
626 // Initialize all missing variables
627 foreach ($variableMatches[3] as $key=>$var) {
628 // Is the variable name valid?
629 if (($variableMatches[1][$key] != $this->getConfigInstance()->readConfig("tpl_valid_var")) && ($variableMatches[1][$key] != "config")) {
630 // Invalid variable name
631 throw new InvalidTemplateVariableNameException(array($this, $this->getLastTemplate(), $variableMatches[1][$key], $this->getConfigInstance()), self::TEMPLATE_CONTAINS_INVALID_VAR_EXCEPTION);
634 // Try to assign it, empty strings are being ignored
635 $this->assignTemplateVariable($variableMatches[1][$key], $var);
641 * Main analysis of the loaded template
643 * @param $templateMatches Found template place-holders, see below
646 *---------------------------------
647 * Structure of $templateMatches:
648 *---------------------------------
649 * [0] => Array - An array with all full matches
650 * [1] => Array - An array with left part (before the ":") of a match
651 * [2] => Array - An array with right part of a match including ":"
652 * [3] => Array - An array with right part of a match excluding ":"
654 private function analyzeTemplate ($templateMatches) {
655 // Backup raw template data
656 $backup = $this->getRawTemplateData();
658 // Initialize some arrays
659 if (is_null($this->loadedRawData)) { $this->loadedRawData = array(); $this->rawTemplates = array(); }
661 // Load all requested templates
662 foreach ($templateMatches[1] as $template) {
664 // Load and compile only templates which we have not yet loaded
665 // RECURSIVE PROTECTION! BE CAREFUL HERE!
666 if ((!isset($this->loadedRawData[$template])) && (!in_array($template, $this->loadedTemplates))) {
668 // Then try to search for code-templates first
670 // Load the code template and remember it's contents
671 $this->loadCodeTemplate($template);
672 $this->loadedRawData[$template] = $this->getRawTemplateData();
674 // Remember this template for recursion detection
675 // RECURSIVE PROTECTION!
676 $this->loadedTemplates[] = $template;
677 } catch (FilePointerNotOpenedException $e) {
678 // Template not found!
679 $this->rawTemplates[] = $template;
682 } // if ((!isset( ...
684 } // for ($templateMatches ...
686 // Restore the raw template data
687 $this->setRawTemplateData($backup);
691 * Compile a given raw template code and remember it for later usage
693 * @param $code The raw template code
694 * @param $template The template's name
697 private function compileCode ($code, $template) {
698 // Is this template already compiled?
699 if (in_array($template, $this->compiledTemplates)) {
704 // Remember this template being compiled
705 $this->compiledTemplates[] = $template;
707 // Compile the loaded code in five steps:
709 // 1. Backup current template data
710 $backup = $this->getRawTemplateData();
712 // 2. Set the current template's raw data as the new content
713 $this->setRawTemplateData($code);
715 // 3. Compile the template data
716 $this->compileTemplate();
718 // 4. Remember it's contents
719 $this->loadedRawData[$template] = $this->getRawTemplateData();
721 // 5. Restore the previous raw content from backup variable
722 $this->setRawTemplateData($backup);
726 * Insert all given and loaded templates by running through all loaded
727 * codes and searching for their place-holder in the main template
729 * @param $templateMatches See method analyzeTemplate()
732 private function insertAllTemplates ($templateMatches) {
733 // Run through all loaded codes
734 foreach ($this->loadedRawData as $template => $code) {
736 // Search for the template
737 $foundIndex = array_search($template, $templateMatches[1]);
739 // Lookup the matching template replacement
740 if (isset($templateMatches[0][$foundIndex])) {
742 // Get the current raw template
743 $rawData = $this->getRawTemplateData();
745 // Replace the space holder with the template code
746 $rawData = str_replace($templateMatches[0][$foundIndex], $code, $rawData);
748 // Set the new raw data
749 $this->setRawTemplateData($rawData);
755 * Load all extra raw templates
759 private function loadExtraRawTemplates () {
760 // Are there some raw templates we need to load?
761 if (count($this->rawTemplates) > 0) {
762 // Try to load all raw templates
763 foreach ($this->rawTemplates as $key => $template) {
766 $this->loadWebTemplate($template);
768 // Remember it's contents
769 $this->rawTemplates[$template] = $this->getRawTemplateData();
771 // Remove it from the loader list
772 unset($this->rawTemplates[$key]);
774 // Remember this template for recursion detection
775 // RECURSIVE PROTECTION!
776 $this->loadedTemplates[] = $template;
777 } catch (FilePointerNotOpenedException $e) {
778 // This template was never found. We silently ignore it
779 unset($this->rawTemplates[$key]);
786 * Assign all found template variables
788 * @param $varMatches An array full of variable/value pairs.
791 private function assignAllVariables ($varMatches) {
792 // Search for all variables
793 foreach ($varMatches[1] as $key=>$var) {
795 // Detect leading equals
796 if (substr($varMatches[2][$key], 0, 1) == "=") {
797 // Remove and cast it
798 $varMatches[2][$key] = (string) substr($varMatches[2][$key], 1);
801 // Do we have some quotes left and right side? Then it is free text
802 if ((substr($varMatches[2][$key], 0, 1) == "\"") && (substr($varMatches[2][$key], -1, 1) == "\"")) {
803 // Free string detected! Which we can assign directly
804 $this->assignVariable($var, $varMatches[3][$key]);
806 // Non-string found so we need some deeper analysis...
807 die("Deeper analysis not yet implemented!");
810 } // for ($varMatches ...
813 * Compiles all loaded raw templates
815 * @param $templateMatches See method analyzeTemplate() for details
818 private function compileRawTemplateData ($templateMatches) {
819 // Are some code-templates found which we need to compile?
820 if (count($this->loadedRawData) > 0) {
823 foreach ($this->loadedRawData as $template => $code) {
825 // Search for the template
826 $foundIndex = array_search($template, $templateMatches[1]);
828 // Lookup the matching variable data
829 if (isset($templateMatches[3][$foundIndex])) {
831 // Split it up with another reg. exp. into variable=value pairs
832 @preg_match_all($this->regExpVarValue, $templateMatches[3][$foundIndex], $varMatches);
834 // Assign all variables
835 $this->assignAllVariables($varMatches);
837 } // END - if (isset($templateMatches ...
839 // Compile the loaded template
840 $this->compileCode($code, $template);
842 } // END - foreach ($this->loadedRawData ...
844 // Insert all templates
845 $this->insertAllTemplates($templateMatches);
847 } // END - if (count($this->loadedRawData) ...
851 * Getter for raw template data
853 * @return $rawTemplateData The raw data from the template
855 public final function getRawTemplateData () {
856 return $this->rawTemplateData;
860 * Getter for compiled templates
862 public final function getCompiledData () {
863 return $this->compiledData;
867 * Load a specified web template into the engine
869 * @param $template The web template we shall load which is
870 * located in "html" by default
873 public final function loadWebTemplate ($template) {
875 $this->setTemplateType($this->getConfigInstance()->readConfig("web_template_type"));
877 // Load the special template
878 $this->loadTemplate($template);
882 * Load a specified email template into the engine
884 * @param $template The email template we shall load which is
885 * located in "emails" by default
888 public final function loadEmailTemplate ($template) {
890 $this->setTemplateType($this->getConfigInstance()->readConfig("email_template_type"));
892 // Load the special template
893 $this->loadTemplate($template);
897 * Load a specified code template into the engine
899 * @param $template The code template we shall load which is
900 * located in "code" by default
903 public final function loadCodeTemplate ($template) {
905 $this->setTemplateType($this->getConfigInstance()->readConfig("code_template_type"));
907 // Load the special template
908 $this->loadTemplate($template);
912 * Compile all variables by inserting their respective values
916 public final function compileVariables () {
917 // Initialize the $content array
918 $validVar = $this->getConfigInstance()->readConfig("tpl_valid_var");
921 // Iterate through all variables
922 for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) {
923 // Get current variable from the stack
924 $currVariable = $idx->current();
926 // Transfer it's name/value combination to the $content array
927 $dummy[$currVariable['name']] = $currVariable['value'];
931 // Prepare all configuration variables
932 $config = $this->configVariables;
934 // Remove some variables
936 unset($currVariable);
938 // Prepare the eval() command for comiling the template
939 $eval = sprintf("\$this->setCompiledData(\"%s\");",
940 addslashes($this->getRawTemplateData())
944 if (((defined('DEBUG_EVAL')) || (defined('DEBUG_ALL'))) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] Konstruierte PHP-Anweisung: <pre><em>%s</em></pre><br />\n",
949 // Run the constructed command. This will "compile" all variables in
954 * Compile all required templates into the current loaded one
957 * @throws UnexpectedTemplateTypeException If the template type is
959 * @throws InvalidArrayCountException If an unexpected array
960 * count has been found
962 public final function compileTemplate () {
963 // We will only work with template type "code" from configuration
964 if ($this->getTemplateType() != $this->getConfigInstance()->readConfig("code_template_type")) {
966 throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->readConfig("code_template_type")), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED);
969 // Get the raw data. Thanks to Flobee(R) for given me a hint using the
970 // modifier "m" in regular expressions. I had implemented a regex here
971 // like this: (\n|\r)
972 $rawData = $this->getRawTemplateData();
974 // Remove double spaces and trim leading/trailing spaces
975 $rawData = trim(str_replace(" ", " ", $rawData));
977 // Search for raw variables
978 $this->extractVariablesFromRawData($rawData);
980 // Search for code-tags which are {? ?}
981 @preg_match_all($this->regExpCodeTags, $rawData, $templateMatches);
983 // Analyze the matches array
984 if ((is_array($templateMatches)) && (count($templateMatches) == 4) && (count($templateMatches[0]) > 0)) {
985 // Entries are found:
988 $this->analyzeTemplate($templateMatches);
990 // Compile raw template data
991 $this->compileRawTemplateData($templateMatches);
993 // Are there some raw templates left for loading?
994 $this->loadExtraRawTemplates();
996 // Are some raw templates found and loaded?
997 if (count($this->rawTemplates) > 0) {
998 die("NOT YET IMPLEMENTED");
1000 } // END - if($templateMatches ...
1004 * Output the compiled page to the outside world. In case of web templates
1005 * this would be vaild (X)HTML code. And in case of email templates this
1006 * would store a prepared email body inside the template engine.
1010 public final function output () {
1011 // Check which type of template we have
1012 switch ($this->getTemplateType()) {
1013 case "html": // Raw HTML templates can be send to the output buffer
1015 $this->getWebOutputInstance()->output($this->getCompiledData());
1018 default: // Unknown type found
1019 if ((is_object($this->getDebugInstance())) && (method_exists($this->getDebugInstance(), 'output'))) {
1020 // Use debug output handler
1021 $this->getDebugInstance()->output(sprintf("[%s:] Unbekannter Template-Typ <strong>%s</strong> erkannt.",
1022 $this->__toString(),
1023 $this->getTemplateType()
1028 // DO NOT REWRITE THIS TO app_die() !!!
1029 die(sprintf("[%s:] Unbekannter Template-Typ <strong>%s</strong> erkannt.",
1030 $this->__toString(),
1031 $this->getTemplateType()