Updated documentation of template classes
authorMatthias Schmidt <gravatronics@live.com>
Wed, 10 Aug 2011 16:42:06 +0000 (18:42 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 10 Aug 2011 16:42:06 +0000 (18:42 +0200)
SetupTemplate has been replaced by SetupTemplateEngine and isn't needed
anymore.

wcfsetup/install/files/lib/system/template/SetupTemplate.class.php [deleted file]
wcfsetup/install/files/lib/system/template/TemplateEngine.class.php
wcfsetup/install/files/lib/system/template/TemplateScriptingCompiler.class.php

diff --git a/wcfsetup/install/files/lib/system/template/SetupTemplate.class.php b/wcfsetup/install/files/lib/system/template/SetupTemplate.class.php
deleted file mode 100644 (file)
index 5dab590..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-namespace wcf\system\template;
-
-/**
- * SetupTemplate loads and displays template in the setup process.
- * 
- * @author     Marcel Werk
- * @copyright  2001-2009 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package    com.woltlab.wcf
- * @subpackage system.template
- * @category   Community Framework
- */
-class SetupTemplate extends Template {
-       protected $templatePath = '';
-       
-       /**
-        * @see wcf\system\template\Template::setTemplatePaths()
-        */
-       public function setTemplatePaths($templatePaths) {
-               if (is_array($templatePaths)) $this->templatePath = array_shift($templatePaths);
-               else $this->templatePath = $templatePaths;
-       }
-       
-       /**
-        * @see wcf\system\template\Template::loadTemplateStructure()
-        */
-       protected function loadTemplateStructure() {}
-       
-       /**
-        * @see wcf\system\template\Template::getSourceFilename()
-        */
-       public function getSourceFilename($templateName, $packageID = 0) {
-               return $this->templatePath.TMP_FILE_PREFIX.$templateName.'.tpl';
-       }
-       
-       /**
-        * @see wcf\system\template\Template::getCompiledFilename()
-        */
-       public function getCompiledFilename($templateName, $packageID = 0) {
-               return $this->compileDir.TMP_FILE_PREFIX.$this->languageID.'_'.$templateName.'.php';
-       }
-       
-       /**
-        * @see wcf\system\template\Template::getPluginFilename()
-        */
-       public function getPluginFilename($type, $tag) {
-               return $this->pluginDir.TMP_FILE_PREFIX.'TemplatePlugin'.StringUtil::firstCharToUpperCase(StringUtil::toLowerCase($type)).StringUtil::firstCharToUpperCase(StringUtil::toLowerCase($tag)).'.class.php';
-       }
-       
-       /**
-        * @see wcf\system\template\Template::getCompiler()
-        */
-       protected function getCompiler() {
-               return new TemplateCompiler($this);
-       }
-}
index bf5ed4c674ba3b1243f4701aaad010b5ec7d907e..3f55efde4eaab7d9fd74af9cfb3be28de5a4976a 100644 (file)
@@ -20,92 +20,79 @@ use wcf\util\DirectoryUtil;
  */
 class TemplateEngine extends SingletonFactory {
        /**
-        * Directory used to cache previously compiled templates
-        * 
+        * directory used to cache previously compiled templates
         * @var string
         */
        public $compileDir = '';
        
        /**
-        * Active language id used to identify specific language versions of compiled templates
-        * 
+        * active language id used to identify specific language versions of compiled templates
         * @var integer
         */
        public $languageID = 0;
        
        /**
-        * Directories used as template source
-        * 
-        * @var array
+        * directories used as template source
+        * @var array<string>
         */
        public $templatePaths = array();
        
        /**
-        * Namespace containing template modifiers and plugins
-        * 
+        * namespace containing template modifiers and plugins
         * @var string
         */
        public $pluginNamespace = '';
        
        /**
-        * Active template compiler.
-        * 
-        * @var TemplateCompiler
+        * active template compiler
+        * @var wcf\system\template\TemplateCompiler
         */
        protected $compilerObj = null;
        
        /**
         * forces the template engine to recompile all included templates
-        * 
         * @var boolean
         */
        protected $forceCompile = false;
        
        /**
         * list of registered prefilters
-        * 
-        * @var array
+        * @var array<string>
         */
        protected $prefilters = array();
        
        /**
-        * Cached list of known template groups.
-        * 
+        * cached list of known template groups
         * @var array
         */
        protected $templateGroupCache = array();
        
        /**
-        * Active template group id.
-        * 
+        * active template group id
         * @var integer
         */
        protected $templateGroupID = 0;
        
        /**
-        * Contains all available template variables and those assigned during runtime.
-        * 
+        * all available template variables and those assigned during runtime
         * @var array<array>
         */
        protected $v = array();
        
        /**
-        * Contains all cached vars for usage after execution in sandbox.
-        * 
+        * all cached variables for usage after execution in sandbox
         * @var array
         */
        protected $sandboxVars = null;
        
        /**
-        * Contains all templates with assigned template listeners.
-        * 
+        * contains all templates with assigned template listeners.
         * @var array<array>
         */
        protected $templateListeners = array();
        
        /**
-        * Current environment
-        * 
+        * current environment
         * @var string
         */
        protected $environment = 'user';
@@ -169,8 +156,8 @@ class TemplateEngine extends SingletonFactory {
        /**
         * Assigns a template variable.
         *
-        * @param       mixed   $variable
-        * @param       mixed   $value
+        * @param       mixed           $variable
+        * @param       mixed           $value
         */
        public function assign($variable, $value = '') {
                if (is_array($variable)) {
@@ -465,7 +452,7 @@ class TemplateEngine extends SingletonFactory {
        /**
         * Returns a new template compiler object.
         * 
-        * @return      TemplateCompiler
+        * @return      wcf\system\template\TemplateCompiler
         */
        protected function getCompiler() {
                return new TemplateCompiler($this);
@@ -605,7 +592,7 @@ class TemplateEngine extends SingletonFactory {
        /**
         * Returns an array with all prefilters.
         *
-        * @return      array
+        * @return      array<string>
         */
        public function getPrefilters() {
                return $this->prefilters;
@@ -644,7 +631,7 @@ class TemplateEngine extends SingletonFactory {
        /**
         * Registers prefilters.
         *
-        * @param       array           $prefilters
+        * @param       array<string>           $prefilters
         */
        public function registerPrefilter(array $prefilters) {
                foreach ($prefilters as $name) {
index fa6b4949b8c8108f6ce562ecd138e00fd34e6e62..402ac610f555350ab0939d4f1b1abe16a1d0f984 100644 (file)
@@ -16,46 +16,160 @@ use wcf\util\StringUtil;
  */
 class TemplateScriptingCompiler {
        /**
-        * template object
-        * 
-        * @var         TemplateEngine
+        * template engine object
+        * @var wcf\system\templateTemplateEngine
         */
-       protected       $template;
+       protected $template;
        
        /**
-        * PHP functions that can be used in the modifier syntax and are unknown to the function_exists PHP method.
-        * 
+        * PHP functions that can be used in the modifier syntax and are unknown
+        * to the function_exists PHP method
+        * @var array<string>
+        */
+       protected $unknownPHPFunctions = array('isset', 'unset', 'empty');
+       
+       /**
+        * PHP functions that can not be used in the modifier syntax
+        * @var array<string>
+        */
+       protected $disabledPHPFunctions = array(
+               'system', 'exec', 'passthru', 'shell_exec', // command line execution
+               'include', 'require', 'include_once', 'require_once', // includes
+               'eval', 'virtual', 'call_user_func_array', 'call_user_func', 'assert' // code execution
+       );
+       
+       /**
+        * pattern to match variable operators like -> or .
+        * @var string
+        */
+       protected $variableOperatorPattern;
+       
+       /**
+        * pattern to match condition operators like == or <
+        * @var string
+        */
+       protected $conditionOperatorPattern;
+       
+       /**
+        * negative lookbehind for a backslash
+        * @var string
+        */
+       protected $escapedPattern;
+       
+       /**
+        * pattern to match valid variable names
+        * @var string
+        */
+       protected $validVarnamePattern;
+       
+       /**
+        * pattern to match constants like CONSTANT or __CONSTANT
+        * @var string
+        */
+       protected $constantPattern;
+       
+       /**
+        * pattern to match double quoted strings like "blah" or "quote: \"blah\""
+        * @var string
+        */
+       protected $doubleQuotePattern;
+       
+       /**
+        * pattern to match single quoted strings like 'blah' or 'don\'t'
+        * @var string
+        */
+       protected $singleQuotePattern;
+       
+       /**
+        * pattern to match single or double quoted strings
+        * @var string
+        */
+       protected $quotePattern;
+       
+       /**
+        * pattern to match numbers, true, false and null
+        * @var string
+        */
+       protected $numericPattern;
+       
+       /**
+        * pattern to match simple variables like $foo
+        * @var string
+        */
+       protected $simpleVarPattern;
+       
+       /**
+        * pattern to match outputs like @$foo or #CONST
+        * @var string
+        */
+       protected $outputPattern;
+       
+       /**
+        * identifier of currently compiled template
+        * @var string
+        */
+       protected $currentIdentifier;
+       
+       /**
+        * current line number during template compilation
+        * @var string
+        */
+       protected $currentLineNo;
+       
+       protected $modifiers = array();
+       
+       /**
+        * list of automatically loaded tenplate plugins
+        * @var array<string>
+        */
+       protected $autoloadPlugins = array();
+       
+       /**
+        * stack with template tags data
         * @var array
         */
-       protected       $unknownPHPFunctions = array('isset', 'unset', 'empty');
+       protected $tagStack = array();
        
        /**
-        * PHP functions that can not be used in the modifier syntax.
-        * 
+        * list of loaded compiler plugin objects
+        * @var array<wcf\system\template\ITemplatePluginCompiler>
+        */
+       protected $compilerPlugins = array();
+       
+       /**
+        * stack used to compile the capture tag
         * @var array
         */
-       protected       $disabledPHPFunctions = array(
-                               'system', 'exec', 'passthru', 'shell_exec', // command line execution
-                               'include', 'require', 'include_once', 'require_once', // includes
-                               'eval', 'virtual', 'call_user_func_array', 'call_user_func', 'assert' // code execution
-                       );
+       protected $captureStack = array();
        
-       protected       $variableOperatorPattern, $conditionOperatorPattern, $escapedPattern, $validVarnamePattern,
-                       $constantPattern, $doubleQuotePattern, $singleQuotePattern, $quotePattern, $numericPattern,
-                       $simpleVarPattern, $outputPattern;
+       /**
+        * left delimiter of template syntax
+        * @var string
+        */
+       protected $leftDelimiter = '{';
        
-       protected       $currentIdentifier, $currentLineNo;
+       /**
+        * right delimiter of template syntax
+        * @var string
+        */
+       protected $rightDelimiter = '}';
        
-       protected       $modifiers = array(), $autoloadPlugins = array(), $tagStack = array(),
-                       $compilerPlugins = array(), $captureStack = array();
+       /**
+        * left delimiter of template syntax used in regular expressions
+        * @var string
+        */
+       protected $ldq;
        
-       protected       $leftDelimiter = '{', $rightDelimiter = '}';
-       protected       $ldq, $rdq;
+       /**
+        * right delimiter of template syntax used in regular expressions
+        * @var string
+        */
+       protected $rdq;
        
        /**
-        * Creates a new TemplateScriptingCompiler.
+        * Creates a new TemplateScriptingCompiler object.
         * 
-        * @param       TemplateEngine          $template
+        * @param       wcf\system\templateTemplateEngine       $template
         */
        public function __construct(TemplateEngine $template) {
                $this->template = $template;
@@ -1173,57 +1287,25 @@ class TemplateScriptingCompiler {
         * Generates the regexp pattern.
         */
        protected function buildPattern() {
-               // operator pattern
                $this->variableOperatorPattern = '\-\>|\.|\(|\)|\[|\]|\||\:|\+|\-|\*|\/|\%|\^|\,';
                $this->conditionOperatorPattern = '===|!==|==|!=|<=|<|>=|(?<!-)>|\|\||&&|!|=';
-
-               // negative lookbehind for a backslash
                $this->escapedPattern = '(?<!\\\\)';
-               
-               // valid variable name pattern
                $this->validVarnamePattern = '(?:[a-zA-Z_][a-zA-Z_0-9]*)';
-               
-               // matches constants
-               // CONSTANT
-               // __CONSTANT2
                $this->constantPattern = '(?:[A-Z_][A-Z_0-9]*)';
-               
-               // matches double quoted strings
-               // "blah"
-               // "quote: \"blah\""
                //$this->doubleQuotePattern = '"[^"\\\\]*(?:\\\\.[^"\\\\]*)*"';
                $this->doubleQuotePattern = '"(?:[^"\\\\]+|\\\\.)*"';
-               
-               // matches single quoted strings
-               // 'blah'
-               // 'don\'t'
                //$this->singleQuotePattern = '\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'';
                $this->singleQuotePattern = '\'(?:[^\'\\\\]+|\\\\.)*\'';
-               
-               // matches single or double quoted strings
                $this->quotePattern = '(?:' . $this->doubleQuotePattern . '|' . $this->singleQuotePattern . ')';
-               
-               // matches numericals and boolean constants
-               // 234
-               // -12
-               // 23.92
-               // true
-               // false
                $this->numericPattern = '(?i)(?:(?:\-?\d+(?:\.\d+)?)|true|false|null)';
-               
-               // matches simple variables
-               // $foo
                $this->simpleVarPattern = '(?:\$('.$this->validVarnamePattern.'))';
-               
-               // matches variable outputs
-               // @$oo
                $this->outputPattern = '(?:(?:@|#)?(?:'.$this->constantPattern.'|'.$this->quotePattern.'|'.$this->numericPattern.'|'.$this->simpleVarPattern.'|\())';
        }
        
        /**
         * Returns the instance of the template engine class.
         * 
-        * @return       TemplateEngine
+        * @return      wcf\system\templateTemplateEngine
         */
        public function getTemplate() {
                return $this->template;
@@ -1232,7 +1314,7 @@ class TemplateScriptingCompiler {
        /**
         * Returns the left delimiter for template tags.
         * 
-        * @return      string
+        * @return      string
         */
        public function getLeftDelimiter() {
                return $this->leftDelimiter;
@@ -1250,7 +1332,7 @@ class TemplateScriptingCompiler {
        /**
         * Returns the name of the current template.
         * 
-        * @return      string
+        * @return      string
         */
        public function getCurrentIdentifier() {
                return $this->currentIdentifier;
@@ -1259,7 +1341,7 @@ class TemplateScriptingCompiler {
        /**
         * Returns the current line number.
         * 
-        * @return      integer
+        * @return      integer
         */
        public function getCurrentLineNo() {
                return $this->currentLineNo;