Class TemplateParser

Description

Template parser class

This class parses template files into PHP code. This code is returned to the template engine to be executed. Besides, parsing task can be skipped by enabling cache. It's strongly recommended to use template cache to improve performance.

Located in /core/template/TemplateParser.class.php (line 147)

PHP2Go
   |
   --TemplateParser
Variable Summary
Method Summary
TemplateParser TemplateParser (string $src, int $type)
void parse (Template &$Template)
strign _compileAssign (string $expression)
string _compileBlockStart (string $blockName, string $parentBlock)
string _compileCaptureEnd ()
string _compileCaptureStart (string $captureProperties, string $controlBlock)
void _compileConfig ( $configProperties)
string _compileFunctionCall (string $funcProperties, [bool $isBlockFunction = FALSE], [string $controlBlock = NULL])
string _compileFunctionEnd (array $funcData)
string _compileIf (string $expression, [bool $elseif = FALSE])
string _compileInclude (string $includeName,  $controlBlock)
string _compileIncludeScript (Include $includeName)
string _compileInternalVariable (string &$variableName)
array _compileIs (string $expr, array $nextTokens)
string _compileLoopStart (string $loopProperties)
string _compilePHPBlock (string $block)
string _compileTemplate (string $src, array &$controlBlock)
string _compileVariable (string $varName, [string $varModifiers = NULL], [bool $print = FALSE])
string _compileVariableName (string $name)
string _compileWidgetAttributeStart (string $attrProperties)
string _compileWidgetEnd ()
string _compileWidgetInclude (string $widgetProperties, array &$widgets)
string _compileWidgetListenerStart (string $listenerProperties)
string _compileWidgetStart (string $widgetProperties, array &$widgets, string $controlBlock)
string _i18nPreFilter (string $match)
array _parseProperties (string $properties, [bool $compileToString = TRUE])
void _parseTemplate (string $src, int $type, string &$output, array &$widgets, string &$controlBlock)
array _parseWidgetProperties (string $widgetProperties)
mixed _validateTag (string $tag, string $tagArguments, bool $needsArguments, [array $matchTags = array()], string $controlBlock)
Variables
array $blockStack = array() (line 211)

Stack of dynamic blocks

  • access: private
array $controlFlags = array() (line 219)

Hashmap of control flags

  • access: private
array $controlStack = array() (line 227)

Stack used to control tags and widgets

  • access: private
int $includeDepth = 0 (line 243)

Template inclusion depth

  • access: private
int $loopNestingLevel = 0 (line 235)

Current nesting level for loops

  • access: private
string $parserVersion = '$Revision$' (line 251)

Parser version

  • access: private
bool $prepared = FALSE (line 203)

Indicates if the template was already compiled

  • access: private
int $tagDelimiters = array('<!--', '-->') (line 195)

Tags delimiters

  • access: private
array $tplBase = array() (line 155)

Holds information about the raw template source

  • access: private
array $tplDef = array() (line 163)

Holds information about the defined blocks and variables

  • access: private
array $tplIncludes = array() (line 171)

Holds name based include blocks

  • access: private
array $tplModifiers = array() (line 179)

Aggregates bundled and custom variable modifiers

  • access: private
array $tplWidgets = array() (line 187)

Holds declared template widgets

  • access: private
CacheManager $_Cache = NULL (line 259)

Cache manager

  • access: private
Template $_Template = NULL (line 266)

Owner template

Methods
Constructor TemplateParser (line 275)

Class constructor

TemplateParser TemplateParser (string $src, int $type)
  • string $src: Source (variable or file)
  • int $type: Source type (T_BYFILE or T_BYVAR)
parse (line 299)

Triggers the parsing of the template

void parse (Template &$Template)
_compileAssign (line 967)

Compiles an "assign" tag

Examples:

  1.  <!-- assign var=$variable -->
  2.  <!-- assign var=-->
  3.  <!-- assign var=true -->
  4.  <!-- assign var="string" -->
  5.  <!-- assign var=$obj->method(-->

  • return: Compiled code
  • access: private
strign _compileAssign (string $expression)
  • string $expression: Assignment expression
_compileBlockStart (line 1072)

Compiles a "start block" tag

Example:

  1.  <!-- start block block_name -->

  • return: Compiled code
  • access: private
string _compileBlockStart (string $blockName, string $parentBlock)
  • string $blockName: Block name
  • string $parentBlock: Parent block name
_compileCaptureEnd (line 1552)

Compiles an "end capture" tag

  • return: Compiled code
  • access: private
string _compileCaptureEnd ()
_compileCaptureStart (line 1534)

Compiles a "capture" tag

Examples:

  1.  <!-- capture -->
  2.  <!-- capture name="my_capture" -->
  3.  <!-- capture name="banner_capture" assign="banners" -->

  • return: Compiled code
  • access: private
string _compileCaptureStart (string $captureProperties, string $controlBlock)
  • string $captureProperties: Raw capture properties
  • string $controlBlock: Active dynamic block
_compileConfig (line 1565)
void _compileConfig ( $configProperties)
  • $configProperties
_compileFunctionCall (line 1000)

Compiles a function call ("call" and "function") tags

The "name" attribute is mandatory and should contain a function name, a class::method pair or an object->method expression, where the object must be a template variable.

Examples:

  1.  <!-- function name="obj->doThis" p1="string" p2=true --> ... <!-- end function -->
  2.  <!-- call function="obj->doThat" p1=$var p2=p3=yes -->
  3.  <!-- call function="procFunc" p1=$anotherVar -->
  4.  <!-- call function="Class::staticMethod" -->

  • return: Compiled code
  • access: private
string _compileFunctionCall (string $funcProperties, [bool $isBlockFunction = FALSE], [string $controlBlock = NULL])
  • string $funcProperties: Raw function arguments
  • bool $isBlockFunction: Whether is a block function call (FUNCTION, END FUNCTION)
  • string $controlBlock: Active dynamic block
_compileFunctionEnd (line 1055)

Compiles an "end function" tag

  • return: Compiled code
  • access: private
string _compileFunctionEnd (array $funcData)
  • array $funcData: Function arguments
_compileIf (line 1159)

Compiles "if" and "else if" tags

Examples:

  1.  <!-- if $var eq -->
  2.  <!-- if ( ($a $blt 20 -->
  3.  <!-- if $row is odd -->
  4.  <!-- if $data is not empty -->
  5.  <!-- else if $data !== null -->
  6.  <!-- else if ( ( $var eq or $var eq ) ) -->

  • return: Compiled code
  • access: private
string _compileIf (string $expression, [bool $elseif = FALSE])
  • string $expression: Raw expression
  • bool $elseif: Is this an "else if"?
_compileInclude (line 1094)

Compiles an "include block" tag

Examples:

  1.  <!-- include block templates/includes/include.tpl -->
  2.  <!-- include block include_block -->

  • return: Compiled code
  • access: private
string _compileInclude (string $includeName,  $controlBlock)
  • string $includeName: Include name or file path
  • $controlBlock
_compileIncludeScript (line 1126)

Compiles an "includescript block" tag

Examples:

  1.  <!-- includescript block templates/php/run_scripts.php -->
  2.  <!-- includescript block include_block_name -->

  • return: Compiled code
  • access: private
string _compileIncludeScript (Include $includeName)
  • Include $includeName: name or file path $includeName
_compileInternalVariable (line 905)

Compiles an internal variable name

  • return: Compiled variable name
  • access: private
string _compileInternalVariable (string &$variableName)
  • string &$variableName: Variable name
_compileIs (line 1284)

Compiles an "is (not) XXX" expression, which can be used inside condition tags (if and else if)

  • return: Modified tokens
  • access: private
array _compileIs (string $expr, array $nextTokens)
  • string $expr: Raw expression
  • array $nextTokens: Tokens that preceed the is expression
_compileLoopStart (line 1339)

Compiles a "loop" tag

The var and item attributes are mandatory. "var" must point to the variable that will be used to iterate (arrays, data sets or db record sets). "item" must be the variable to be used to assign each loop record.

Examples:

  1.  <!-- loop var=$loop item="row" -->
  2.  <!-- loop var=$data item="line" key="key" -->
  3.  <!-- loop name="people" var=$people item="person" -->

  • return: Compiled code
  • access: private
string _compileLoopStart (string $loopProperties)
  • string $loopProperties: Raw loop properties
_compilePHPBlock (line 1711)

Compiles a block of PHP code

  • access: private
string _compilePHPBlock (string $block)
  • string $block: Code block
_compileTemplate (line 469)

Compiles a template source into PHP code

  • return: Compiled PHP code
  • access: private
string _compileTemplate (string $src, array &$controlBlock)
  • string $src: Template source
  • array &$controlBlock: Active dynamic block
_compileVariable (line 783)

Compiles a variable reference

The $print argument indicates if we're printing a variable (direct access) or using it as an argument of a tag (IF, LOOP, ASSIGN).

  • access: private
string _compileVariable (string $varName, [string $varModifiers = NULL], [bool $print = FALSE])
  • string $varName: Variable name
  • string $varModifiers: Variable modifiers
  • bool $print: Is direct access?
_compileVariableName (line 848)

Compiles a variable name

Resolves variables names containing access to array keys, object properties, method calls and dynamic variables resolution.

Matches variable names such as: {$var}, {$array.key}, {$obj->property}, {$array.inner.innerMost}, {$obj->arrayProperty.key}, {$obj->$dynamic}, {$array.$dynamic}, {$p2g.get.request_access}, {$p2g.conf.conf_key}, {$p2g.const.my_constant}, ...

  • return: Compiled variable name
  • access: private
string _compileVariableName (string $name)
  • string $name: Raw variable name
_compileWidgetAttributeEnd (line 1480)

Compiles a "end attribute" tag

  • return: Compiled code
  • access: private
string _compileWidgetAttributeEnd ()
_compileWidgetAttributeStart (line 1466)

Compiles a "attribute" tag

  • return: Compiled code
  • access: private
string _compileWidgetAttributeStart (string $attrProperties)
  • string $attrProperties: Raw attribute properties
_compileWidgetEnd (line 1448)

Compiles an "end widget" tag

  • return: Compiled code
  • access: private
string _compileWidgetEnd ()
_compileWidgetInclude (line 1392)

Compiles an "include widget" tag

  • return: Compiled code
  • access: private
string _compileWidgetInclude (string $widgetProperties, array &$widgets)
  • string $widgetProperties: Raw widget properties
  • array &$widgets: Widgets registry
_compileWidgetListenerEnd (line 1510)

Compiles an "end listener" tag

  • return: Compiled code
  • access: private
string _compileWidgetListenerEnd ()
_compileWidgetListenerStart (line 1496)

Compiles a "listener" tag

  • return: Compiled code
  • access: private
string _compileWidgetListenerStart (string $listenerProperties)
  • string $listenerProperties: Raw listener properties
_compileWidgetStart (line 1420)

Compiles a "widget" tag

  • return: Compiled code
  • access: private
string _compileWidgetStart (string $widgetProperties, array &$widgets, string $controlBlock)
  • string $widgetProperties: Raw widget properties
  • array &$widgets: Widgets registry
  • string $controlBlock: Active dynamic block
_i18nPreFilter (line 1722)

Resolve an I18n query during template compilation

  • return: Entry value
  • access: private
string _i18nPreFilter (string $match)
  • string $match: Language entry
_parseProperties (line 1589)

Parses tag properties written in the syntax "prop=val prop2=val2 ..."

  • return: Compiled properties
  • access: private
array _parseProperties (string $properties, [bool $compileToString = TRUE])
  • string $properties: Raw properties string
  • bool $compileToString: Whether to compile property values to string
_parseTemplate (line 337)

Parses a template file (main file or include block)

void _parseTemplate (string $src, int $type, string &$output, array &$widgets, string &$controlBlock)
  • string $src: Template source (string contents or file path)
  • int $type: Source type (T_BYFILE or T_BYVAR)
  • string &$output: Used to return compiled contents
  • array &$widgets: Widgets registry
  • string &$controlBlock: Active dynamic block
_parseWidgetProperties (line 1650)

Parses the attributes of a widget, written in the syntax "prop=var prop2=var2 ..."

  • return: Compiled properties
  • access: private
array _parseWidgetProperties (string $widgetProperties)
  • string $widgetProperties: Raw properties
_validateTag (line 1680)

Validates a tag declared in the template source

  • return: Last tag data, or FALSE in case of errors
  • access: private
mixed _validateTag (string $tag, string $tagArguments, bool $needsArguments, [array $matchTags = array()], string $controlBlock)
  • string $tag: Tag name
  • string $tagArguments: Tag arguments
  • bool $needsArguments: If this tag requires (TRUE), denies (FALSE) or ignore (NULL) arguments
  • array $matchTags: Matching tags, must be read from the top of the tag stack
  • string $controlBlock: Active dynamic block

Inherited Methods

Inherited From PHP2Go

PHP2Go::PHP2Go()
PHP2Go::equals()
PHP2Go::generateUniqueId()
PHP2Go::getClassName()
PHP2Go::getConfigVal()
PHP2Go::getLangVal()
PHP2Go::getObjectName()
PHP2Go::getParentName()
PHP2Go::hasDestructor()
PHP2Go::hashCode()
PHP2Go::isA()
PHP2Go::isSubclassOf()
PHP2Go::logError()
PHP2Go::raiseError()
PHP2Go::registerDestructor()
PHP2Go::registerShutdownFunc()
PHP2Go::retrieve()
PHP2Go::store()
PHP2Go::__toString()

Documentation generated on Sun, 07 Oct 2007 19:30:24 -0300 by phpDocumentor 1.3.2