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 * Loaded templates for recursive protection and detection
77 private $loadedTemplates = array();
80 * Compiled templates for recursive protection and detection
82 private $compiledTemplates = array();
85 * Loaded raw template data
87 private $loadedRawData = null;
90 * Raw templates which are linked in code templates
92 private $rawTemplates = null;
95 * A regular expression for variable=value pairs
97 private $regExpVarValue = '/([\w_]+)(="([^"]*)"|=([\w_]+))?/';
100 * A regular expression for filtering out code tags
102 * E.g.: {?template:variable=value;var2=value2;[...]?}
104 private $regExpCodeTags = '/\{\?([a-z_]+)(:("[^"]+"|[^?}]+)+)?\?\}/';
109 private $helpers = array();
111 // Exception codes for the template engine
112 const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED = 0xa00;
113 const EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR = 0xa01;
114 const EXCEPTION_INVALID_VIEW_HELPER = 0xa02;
117 * Private constructor
121 private final function __construct () {
122 // Call parent constructor
123 parent::constructor(__CLASS__);
125 // Set part description
126 $this->setPartDescr("Template-Engine");
128 // Create unique ID number
129 $this->createUniqueID();
132 $this->removeNumberFormaters();
133 $this->removeSystemArray();
137 * Creates an instance of the class TemplateEngine and prepares it for usage
139 * @param $basePath The local base path for all templates
140 * @param $langInstance An instance of LanguageSystem (default)
141 * @param $ioInstance An instance of FileIOHandler (default, middleware!)
142 * @return $tplInstance An instance of TemplateEngine
143 * @throws BasePathIsEmptyException If the provided $basePath is empty
144 * @throws InvalidBasePathStringException If $basePath is no string
145 * @throws BasePathIsNoDirectoryException If $basePath is no
146 * directory or not found
147 * @throws BasePathReadProtectedException If $basePath is
150 public final static function createTemplateEngine ($basePath, ManageableLanguage $langInstance, FileIOHandler $ioInstance) {
151 // Get a new instance
152 $tplInstance = new TemplateEngine();
154 // Is the base path valid?
155 if (empty($basePath)) {
156 // Base path is empty
157 throw new BasePathIsEmptyException($tplInstance, self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
158 } elseif (!is_string($basePath)) {
160 throw new InvalidBasePathStringException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_STRING);
161 } elseif (!is_dir($basePath)) {
163 throw new BasePathIsNoDirectoryException(array($tplInstance, $basePath), self::EXCEPTION_INVALID_PATH_NAME);
164 } elseif (!is_readable($basePath)) {
166 throw new BasePathReadProtectedException(array($tplInstance, $basePath), self::EXCEPTION_READ_PROTECED_PATH);
169 // Get configuration instance
170 $cfgInstance = $tplInstance->getConfigInstance();
173 $tplInstance->setBasePath($basePath);
175 // Initialize the variable stack
176 $tplInstance->initVariableStack();
178 // Set the language and IO instances
179 $tplInstance->setLanguageInstance($langInstance);
180 $tplInstance->setFileIOInstance($ioInstance);
182 // Set template extensions
183 $tplInstance->setRawTemplateExtension($cfgInstance->readConfig("raw_template_extension"));
184 $tplInstance->setCodeTemplateExtension($cfgInstance->readConfig("code_template_extension"));
186 // Absolute output path for compiled templates
187 $tplInstance->setCompileOutputPath(PATH . $cfgInstance->readConfig("compile_output_path"));
189 // Return the prepared instance
194 * Search for a variable in the stack
196 * @param $var The variable we are looking for
197 * @return $idx FALSE means not found, > 0 means found on a specific index
199 private function isVariableAlreadySet ($var) {
200 // First everything is not found
204 for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) {
206 $currEntry = $idx->current();
208 // Is the entry found?
209 if ($currEntry['name'] == $var) {
211 $found = $idx->key();
216 // Return the current position
221 * Add a variable to the stack
223 * @param $var The variable we are looking for
224 * @param $value The value we want to store in the variable
227 private function addVariable ($var, $value) {
228 // Add it to the stack
229 $this->varStack->append(array(
236 * Modify an entry on the stack
238 * @param $var The variable we are looking for
239 * @param $value The value we want to store in the variable
242 private function modifyVariable ($var, $value) {
243 // It should be there so let's look again...
244 for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) {
246 $currEntry = $idx->current();
248 // Is this the requested variable?
249 if ($currEntry['name'] == $var) {
250 // Change it to the other value
251 $this->varStack->offsetSet($idx->key(), array(
260 * Initialize the variable stack. This holds all variables for later
265 public final function initVariableStack () {
266 $this->varStack = new FrameworkArrayObject();
270 * Setter for base path
272 * @param $basePath The local base path for all templates
275 public final function setBasePath ($basePath) {
277 $basePath = (string) $basePath;
280 $this->basePath = $basePath;
284 * Getter for base path
286 * @return $basePath The local base path for all templates
288 public final function getBasePath () {
290 return $this->basePath;
294 * Setter for template extension
296 * @param $templateExtension The file extension for all uncompiled
300 public final function setRawTemplateExtension ($templateExtension) {
302 $templateExtension = (string) $templateExtension;
305 $this->templateExtension = $templateExtension;
309 * Setter for code template extension
311 * @param $codeExtension The file extension for all uncompiled
315 public final function setCodeTemplateExtension ($codeExtension) {
317 $codeExtension = (string) $codeExtension;
320 $this->codeExtension = $codeExtension;
324 * Getter for template extension
326 * @return $templateExtension The file extension for all uncompiled
329 public final function getRawTemplateExtension () {
331 return $this->templateExtension;
335 * Getter for code-template extension
337 * @return $codeExtension The file extension for all code-
340 public final function getCodeTemplateExtension () {
342 return $this->codeExtension;
346 * Setter for path of compiled templates
348 * @param $compileOutputPath The local base path for all
352 public final function setCompileOutputPath ($compileOutputPath) {
354 $compileOutputPath = (string) $compileOutputPath;
357 $this->compileOutputPath = $compileOutputPath;
361 * Setter for template type. Only "html", "emails" and "compiled" should
364 * @param $templateType The current template's type
367 private final function setTemplateType ($templateType) {
369 $templateType = (string) $templateType;
371 // And set it (only 2 letters)
372 $this->templateType = $templateType;
376 * Getter for template type
378 * @return $templateType The current template's type
380 public final function getTemplateType () {
381 return $this->templateType;
385 * Setter for the last loaded template's FQFN
387 * @param $template The last loaded template
390 private final function setLastTemplate ($template) {
392 $template = (string) $template;
393 $this->lastTemplate = $template;
397 * Getter for the last loaded template's FQFN
399 * @return $template The last loaded template
401 private final function getLastTemplate () {
402 return $this->lastTemplate;
406 * Assign (add) a given variable with a value
408 * @param $var The variable we are looking for
409 * @param $value The value we want to store in the variable
412 public final function assignVariable ($var, $value) {
413 // First search for the variable if it was already added
414 $idx = $this->isVariableAlreadySet($var);
417 if ($idx === false) {
418 // Add it to the stack
419 $this->addVariable($var, $value);
420 } elseif (!empty($value)) {
421 // Modify the stack entry
422 $this->modifyVariable($var, $value);
427 * Assign a given congfiguration variable with a value
429 * @param $var The configuration variable we are looking for
430 * @param $value The value we want to store in the variable
433 public final function assignConfigVariable ($var, $value) {
434 // Sweet and simple...
435 $this->configVariables[$var] = $value;
439 * Removes a given variable
441 * @param $var The variable we are looking for
444 public final function removeVariable ($var) {
445 // First search for the variable if it was already added
446 $idx = $this->isVariableAlreadySet($var);
449 if ($idx !== false) {
450 // Remove this variable
451 $this->varStack->offsetUnset($idx);
456 * Private setter for raw template data
458 * @param $rawTemplateData The raw data from the template
461 private final function setRawTemplateData ($rawTemplateData) {
463 $rawTemplateData = (string) $rawTemplateData;
465 // And store it in this class
466 $this->rawTemplateData = $rawTemplateData;
470 * Private setter for compiled templates
472 private final function setCompiledData ($compiledData) {
474 $compiledData = (string) $compiledData;
476 // And store it in this class
477 $this->compiledData = $compiledData;
481 * Private loader for all template types
483 * @param $template The template we shall load
486 private final function loadTemplate ($template) {
488 $template = (string) $template;
490 // Get extension for the template
491 $ext = $this->getRawTemplateExtension();
493 // If we shall load a code-template we need to switch the file extension
494 if ($this->getTemplateType() == $this->getConfigInstance()->readConfig("code_template_type")) {
495 // Switch over to the code-template extension
496 $ext = $this->getCodeTemplateExtension();
499 // Construct the FQFN for the template by honoring the current language
500 $fqfn = sprintf("%s%s/%s/%s%s",
501 $this->getBasePath(),
502 $this->getLanguageInstance()->getLanguageCode(),
503 $this->getTemplateType(),
508 // Load the raw template data
509 $this->loadRawTemplateData($fqfn);
513 * A private loader for raw template names
515 * @param $fqfn The full-qualified file name for a template
517 * @throws NullPointerException If $inputInstance is null
518 * @throws NoObjectException If $inputInstance is not an object
519 * @throws MissingMethodException If $inputInstance is missing a
522 private function loadRawTemplateData ($fqfn) {
524 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",
527 $this->getTemplateType()
530 // Get a input/output instance from the middleware
531 $ioInstance = $this->getFileIOInstance();
533 // Validate the instance
534 if (is_null($ioInstance)) {
536 throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER);
537 } elseif (!is_object($ioInstance)) {
538 // Throw another exception
539 throw new NoObjectException($ioInstance, self::EXCEPTION_IS_NO_OBJECT);
540 } elseif (!method_exists($ioInstance, 'loadFileContents')) {
541 // Throw yet another exception
542 throw new MissingMethodException(array($ioInstance, 'loadFileContents'), self::EXCEPTION_MISSING_METHOD);
545 // Load the raw template
546 $rawTemplateData = $ioInstance->loadFileContents($fqfn);
549 if ((defined('DEBUG_TEMPLATE')) && (is_object($this->getDebugInstance()))) $this->getDebugInstance()->output(sprintf("[%s:] <strong>%s</strong> Byte Rohdaten geladen.<br />\n",
551 strlen($rawTemplateData)
554 // Store the template's contents into this class
555 $this->setRawTemplateData($rawTemplateData);
557 // Remember the template's FQFN
558 $this->setLastTemplate($fqfn);
562 * Try to assign an extracted template variable as a "content" or "config"
565 * @param $varName The variable's name (shall be content or
567 * @param $var The variable we want to assign
569 private function assignTemplateVariable ($varName, $var) {
570 // Is it not a config variable?
571 if ($varName != "config") {
572 // Regular template variables
573 $this->assignVariable($var, "");
575 // Configuration variables
576 $this->assignConfigVariable($var, $this->getConfigInstance()->readConfig($var));
581 * Extract variables from a given raw data stream
583 * @param $rawData The raw template data we shall analyze
585 * @throws InvalidTemplateVariableNameException If a variable name
589 private function extractVariablesFromRawData ($rawData) {
591 $rawData = (string) $rawData;
593 // Search for variables
594 @preg_match_all('/\$(\w+)(\[(\w+)\])?/', $rawData, $variableMatches);
596 // Did we find some variables?
597 if ((is_array($variableMatches)) && (count($variableMatches) == 4) && (count($variableMatches[0]) > 0)) {
598 // Initialize all missing variables
599 foreach ($variableMatches[3] as $key=>$var) {
600 // Is the variable name valid?
601 if (($variableMatches[1][$key] != $this->getConfigInstance()->readConfig("tpl_valid_var")) && ($variableMatches[1][$key] != "config")) {
602 // Invalid variable name
603 throw new InvalidTemplateVariableNameException(array($this, $this->getLastTemplate(), $variableMatches[1][$key], $this->getConfigInstance()), self::EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR);
606 // Try to assign it, empty strings are being ignored
607 $this->assignTemplateVariable($variableMatches[1][$key], $var);
613 * Main analysis of the loaded template
615 * @param $templateMatches Found template place-holders, see below
618 *---------------------------------
619 * Structure of $templateMatches:
620 *---------------------------------
621 * [0] => Array - An array with all full matches
622 * [1] => Array - An array with left part (before the ":") of a match
623 * [2] => Array - An array with right part of a match including ":"
624 * [3] => Array - An array with right part of a match excluding ":"
626 private function analyzeTemplate ($templateMatches) {
627 // Backup raw template data
628 $backup = $this->getRawTemplateData();
630 // Initialize some arrays
631 if (is_null($this->loadedRawData)) { $this->loadedRawData = array(); $this->rawTemplates = array(); }
633 // Load all requested templates
634 foreach ($templateMatches[1] as $template) {
636 // Load and compile only templates which we have not yet loaded
637 // RECURSIVE PROTECTION! BE CAREFUL HERE!
638 if ((!isset($this->loadedRawData[$template])) && (!in_array($template, $this->loadedTemplates))) {
640 // Then try to search for code-templates first
642 // Load the code template and remember it's contents
643 $this->loadCodeTemplate($template);
644 $this->loadedRawData[$template] = $this->getRawTemplateData();
646 // Remember this template for recursion detection
647 // RECURSIVE PROTECTION!
648 $this->loadedTemplates[] = $template;
649 } catch (FilePointerNotOpenedException $e) {
650 // Template not found!
651 $this->rawTemplates[] = $template;
654 } // if ((!isset( ...
656 } // for ($templateMatches ...
658 // Restore the raw template data
659 $this->setRawTemplateData($backup);
663 * Compile a given raw template code and remember it for later usage
665 * @param $code The raw template code
666 * @param $template The template's name
669 private function compileCode ($code, $template) {
670 // Is this template already compiled?
671 if (in_array($template, $this->compiledTemplates)) {
676 // Remember this template being compiled
677 $this->compiledTemplates[] = $template;
679 // Compile the loaded code in five steps:
681 // 1. Backup current template data
682 $backup = $this->getRawTemplateData();
684 // 2. Set the current template's raw data as the new content
685 $this->setRawTemplateData($code);
687 // 3. Compile the template data
688 $this->compileTemplate();
690 // 4. Remember it's contents
691 $this->loadedRawData[$template] = $this->getRawTemplateData();
693 // 5. Restore the previous raw content from backup variable
694 $this->setRawTemplateData($backup);
698 * Insert all given and loaded templates by running through all loaded
699 * codes and searching for their place-holder in the main template
701 * @param $templateMatches See method analyzeTemplate()
704 private function insertAllTemplates ($templateMatches) {
705 // Run through all loaded codes
706 foreach ($this->loadedRawData as $template => $code) {
708 // Search for the template
709 $foundIndex = array_search($template, $templateMatches[1]);
711 // Lookup the matching template replacement
712 if (isset($templateMatches[0][$foundIndex])) {
714 // Get the current raw template
715 $rawData = $this->getRawTemplateData();
717 // Replace the space holder with the template code
718 $rawData = str_replace($templateMatches[0][$foundIndex], $code, $rawData);
720 // Set the new raw data
721 $this->setRawTemplateData($rawData);
727 * Load all extra raw templates
731 private function loadExtraRawTemplates () {
732 // Are there some raw templates we need to load?
733 if (count($this->rawTemplates) > 0) {
734 // Try to load all raw templates
735 foreach ($this->rawTemplates as $key => $template) {
738 $this->loadWebTemplate($template);
740 // Remember it's contents
741 $this->rawTemplates[$template] = $this->getRawTemplateData();
743 // Remove it from the loader list
744 unset($this->rawTemplates[$key]);
746 // Remember this template for recursion detection
747 // RECURSIVE PROTECTION!
748 $this->loadedTemplates[] = $template;
749 } catch (FilePointerNotOpenedException $e) {
750 // This template was never found. We silently ignore it
751 unset($this->rawTemplates[$key]);
758 * Assign all found template variables
760 * @param $varMatches An array full of variable/value pairs.
763 private function assignAllVariables ($varMatches) {
764 // Search for all variables
765 foreach ($varMatches[1] as $key=>$var) {
767 // Detect leading equals
768 if (substr($varMatches[2][$key], 0, 1) == "=") {
769 // Remove and cast it
770 $varMatches[2][$key] = (string) substr($varMatches[2][$key], 1);
773 // Do we have some quotes left and right side? Then it is free text
774 if ((substr($varMatches[2][$key], 0, 1) == "\"") && (substr($varMatches[2][$key], -1, 1) == "\"")) {
775 // Free string detected! Which we can assign directly
776 $this->assignVariable($var, $varMatches[3][$key]);
778 // Non-string found so we need some deeper analysis...
779 die("Deeper analysis not yet implemented!");
782 } // for ($varMatches ...
785 * Compiles all loaded raw templates
787 * @param $templateMatches See method analyzeTemplate() for details
790 private function compileRawTemplateData ($templateMatches) {
791 // Are some code-templates found which we need to compile?
792 if (count($this->loadedRawData) > 0) {
795 foreach ($this->loadedRawData as $template => $code) {
797 // Search for the template
798 $foundIndex = array_search($template, $templateMatches[1]);
800 // Lookup the matching variable data
801 if (isset($templateMatches[3][$foundIndex])) {
803 // Split it up with another reg. exp. into variable=value pairs
804 @preg_match_all($this->regExpVarValue, $templateMatches[3][$foundIndex], $varMatches);
806 // Assign all variables
807 $this->assignAllVariables($varMatches);
809 } // END - if (isset($templateMatches ...
811 // Compile the loaded template
812 $this->compileCode($code, $template);
814 } // END - foreach ($this->loadedRawData ...
816 // Insert all templates
817 $this->insertAllTemplates($templateMatches);
819 } // END - if (count($this->loadedRawData) ...
823 * Getter for raw template data
825 * @return $rawTemplateData The raw data from the template
827 public final function getRawTemplateData () {
828 return $this->rawTemplateData;
832 * Getter for compiled templates
834 public final function getCompiledData () {
835 return $this->compiledData;
839 * Load a specified web template into the engine
841 * @param $template The web template we shall load which is
842 * located in "html" by default
845 public final function loadWebTemplate ($template) {
847 $this->setTemplateType($this->getConfigInstance()->readConfig("web_template_type"));
849 // Load the special template
850 $this->loadTemplate($template);
854 * Load a specified email template into the engine
856 * @param $template The email template we shall load which is
857 * located in "emails" by default
860 public final function loadEmailTemplate ($template) {
862 $this->setTemplateType($this->getConfigInstance()->readConfig("email_template_type"));
864 // Load the special template
865 $this->loadTemplate($template);
869 * Load a specified code template into the engine
871 * @param $template The code template we shall load which is
872 * located in "code" by default
875 public final function loadCodeTemplate ($template) {
877 $this->setTemplateType($this->getConfigInstance()->readConfig("code_template_type"));
879 // Load the special template
880 $this->loadTemplate($template);
884 * Compile all variables by inserting their respective values
888 public final function compileVariables () {
889 // Initialize the $content array
890 $validVar = $this->getConfigInstance()->readConfig("tpl_valid_var");
893 // Iterate through all variables
894 for ($idx = $this->varStack->getIterator(); $idx->valid(); $idx->next()) {
895 // Get current variable from the stack
896 $currVariable = $idx->current();
898 // Transfer it's name/value combination to the $content array
899 $dummy[$currVariable['name']] = $currVariable['value'];
903 // Prepare all configuration variables
904 $config = $this->configVariables;
906 // Remove some variables
908 unset($currVariable);
910 // Prepare the eval() command for comiling the template
911 $eval = sprintf("\$this->setCompiledData(\"%s\");",
912 addslashes($this->getRawTemplateData())
916 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",
921 // Run the constructed command. This will "compile" all variables in
926 * Compile all required templates into the current loaded one
929 * @throws UnexpectedTemplateTypeException If the template type is
931 * @throws InvalidArrayCountException If an unexpected array
932 * count has been found
934 public final function compileTemplate () {
935 // We will only work with template type "code" from configuration
936 if ($this->getTemplateType() != $this->getConfigInstance()->readConfig("code_template_type")) {
938 throw new UnexpectedTemplateTypeException(array($this, $this->getTemplateType(), $this->getConfigInstance()->readConfig("code_template_type")), self::EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED);
941 // Get the raw data. Thanks to Flobee(R) for given me a hint using the
942 // modifier "m" in regular expressions. I had implemented a regex here
943 // like this: (\n|\r)
944 $rawData = $this->getRawTemplateData();
946 // Remove double spaces and trim leading/trailing spaces
947 $rawData = trim(str_replace(" ", " ", $rawData));
949 // Search for raw variables
950 $this->extractVariablesFromRawData($rawData);
952 // Search for code-tags which are {? ?}
953 @preg_match_all($this->regExpCodeTags, $rawData, $templateMatches);
955 // Analyze the matches array
956 if ((is_array($templateMatches)) && (count($templateMatches) == 4) && (count($templateMatches[0]) > 0)) {
957 // Entries are found:
960 $this->analyzeTemplate($templateMatches);
962 // Compile raw template data
963 $this->compileRawTemplateData($templateMatches);
965 // Are there some raw templates left for loading?
966 $this->loadExtraRawTemplates();
968 // Are some raw templates found and loaded?
969 if (count($this->rawTemplates) > 0) {
970 die("NOT YET IMPLEMENTED");
972 } // END - if($templateMatches ...
976 * Output the compiled page to the outside world. In case of web templates
977 * this would be vaild (X)HTML code. And in case of email templates this
978 * would store a prepared email body inside the template engine.
982 public final function output () {
983 // Check which type of template we have
984 switch ($this->getTemplateType()) {
985 case "html": // Raw HTML templates can be send to the output buffer
987 $this->getWebOutputInstance()->output($this->getCompiledData());
990 default: // Unknown type found
991 if ((is_object($this->getDebugInstance())) && (method_exists($this->getDebugInstance(), 'output'))) {
992 // Use debug output handler
993 $this->getDebugInstance()->output(sprintf("[%s:] Unbekannter Template-Typ <strong>%s</strong> erkannt.",
995 $this->getTemplateType()
1000 // DO NOT REWRITE THIS TO app_die() !!!
1001 die(sprintf("[%s:] Unbekannter Template-Typ <strong>%s</strong> erkannt.",
1002 $this->__toString(),
1003 $this->getTemplateType()
1011 * Loads a given view helper (by name)
1013 * @param $helperName The helper's name
1015 * @throws ViewHelperNotFoundException If the given view helper was not found
1017 protected function loadViewHelper ($helperName) {
1018 // Make first character upper case, rest low
1019 $helperName = ucfirst($helperName);
1021 // Is this view helper loaded?
1022 if (!isset($this->helpers[$helperName])) {
1023 // Create a class name
1024 $className = "{$helperName}ViewHelper";
1026 // Does this class exists?
1027 if (!class_exists($className)) {
1029 throw new ViewHelperNotFoundException(array($this, $helperName), self::EXCEPTION_INVALID_VIEW_HELPER);
1032 // Generate new instance
1033 $eval = sprintf("\$this->helpers[%s] = %s::create%s();",
1043 // Return the requested instance
1044 return $this->helpers[$helperName];