eZPublish  3.9
eZTemplateCompiler Class Reference

Creates compiled PHP code from templates to speed up template usage. More...

Public Member Functions

 boundVariableName ($variableID, $parameters)
 
 calculateVariableNodeStatistics (&$tpl, $variableData, $variablePlacement, &$resourceData, $namespace, &$stats)
 
 calculateVariableStatistics (&$tpl, &$node, &$resourceData, &$stats)
 
 calculateVariableStatisticsChildren (&$tpl, &$nodeChildren, &$resourceData, $namespace, &$stats)
 
 combineStaticNodes (&$tpl, &$resourceData, &$lastNode, &$newNode)
 
 compilationFilename ($key, $resourceData)
 
 createCommonCompileTemplate ()
 
 createStaticVariableData (&$tpl, $staticData, $variableItemPlacement)
 
 currentTextName ($parameters)
 
 decreaseCurrentTextName (&$parameters)
 
 executeCompilation (&$tpl, &$textElements, $key, &$resourceData, $rootNamespace, $currentNamespace)
 
 executeCompilationHelper ($phpScript, &$text, &$tpl, $key, &$resourceData, $rootNamespace, $currentNamespace)
 
 eZTemplateCompiler ()
 
 fetchTemplatePiece ($placementData)
 
 generateMergeNamespaceCode (&$php, &$tpl, $namespace, $namespaceScope, $parameters=array(), $skipSimpleAssignment=false)
 
 generatePHPCode ($useComments, &$php, &$tpl, &$node, &$resourceData)
 
 generatePHPCodeChildren ($useComments, &$php, &$tpl, &$nodeChildren, &$resourceData, &$parameters, $currentParameters)
 
 generateVariableCode (&$php, &$tpl, $node, &$knownTypes, $dataInspection, $parameters, &$resourceData)
 
 generateVariableDataCode (&$php, &$tpl, $variableData, &$knownTypes, $dataInspection, &$persistence, $parameters, &$resourceData)
 
 increaseCurrentTextName (&$parameters)
 
 inspectVariableData (&$tpl, $variableData, $variablePlacement, &$resourceData)
 
 operatorHint (&$tpl, $operatorName)
 
 operatorStaticData (&$tpl, $operatorName)
 
 prepareVariableStatistics (&$tpl, &$resourceData, &$stats)
 
 processElementTransformationChild ($useComments, &$php, &$tpl, &$node, &$elementTree, &$elementList, &$resourceData)
 
 processElementTransformationList (&$tpl, &$node, &$elements, &$privateData)
 
 processNodeCombining ($useComments, &$php, &$tpl, &$node, &$resourceData, &$newNode)
 
 processNodeCombiningChildren ($useComments, &$php, &$tpl, &$nodeChildren, &$resourceData, &$parentNode)
 
 processNodeTransformation ($useComments, &$php, &$tpl, &$node, &$resourceData, &$newNode)
 
 processNodeTransformationChild ($useComments, &$php, &$tpl, &$node, &$resourceData)
 
 processNodeTransformationChildren ($useComments, &$php, &$tpl, &$node, &$children, &$resourceData)
 
 processNodeTransformationNodes (&$tpl, &$node, &$nodes, &$privateData)
 
 processNodeTransformationRoot ($useComments, &$php, &$tpl, &$node, &$resourceData)
 
 processRemoveNodePlacement (&$node)
 
 processStaticOptimizations ($useComments, &$php, &$tpl, &$node, &$resourceData, &$newNode)
 
 setVariableStatistics (&$stats, $namespace, $variableName, $changes)
 
 staticNodeData ($node)
 

Static Public Member Functions

 alwaysGenerate ()
 
 compilationDirectory ()
 
 compileTemplate (&$tpl, $key, &$resourceData)
 
 hasCompiledTemplate ($key, $timestamp, &$resourceData)
 
 isAccumulatorsEnabled ()
 
 isCommentsEnabled ()
 
 isCompilationEnabled ()
 
 isDevelopmentModeEnabled ()
 
 isExecutionEnabled ()
 
 isFallbackResourceCodeEnabled ()
 
 isNodePlacementEnabled ()
 
 isTimingPointsEnabled ()
 
 isTreeEnabled ($treeName)
 
 setSettings ($settingsMap)
 
 TemplatePrefix ()
 

Detailed Description

Creates compiled PHP code from templates to speed up template usage.

Various optimizations that can be done are:

Data:

  • Is constant, generate static data
  • Is variable, generate direct variable extraction
  • Has operators
  • Has attributes

Attributes:

  • Is constant, generate static data

Operators:

  • Supports input
  • Supports output
  • Supports parameters
  • Generates static data (true, false)
  • Custom PHP code
  • Modifies template variables, if possible name which ones. Allows for caching of variables in the script.

Functions:

  • Supports parameters
  • Supports children (set? no, section? yes)
  • Generates static data (ldelim,rdelim)
  • Children usage, no result(set-block) | copy(let,default) | dynamic(conditional, repeated etc.)
  • Children tree, requires original tree | allows custom processing
  • Custom PHP code
  • Deflate/transform tree, create new non-nested tree (let, default)
  • Modifies template variables, if possible name which ones. Allows for caching of variables in the script.

Member Function Documentation

eZTemplateCompiler::alwaysGenerate ( )
static
Returns
true if template compilation should always be run even if a sufficient compilation already exists.

Referenced by hasCompiledTemplate().

eZTemplateCompiler::boundVariableName (   $variableID,
  $parameters 
)
eZTemplateCompiler::calculateVariableNodeStatistics ( $tpl,
  $variableData,
  $variablePlacement,
$resourceData,
  $namespace,
$stats 
)
eZTemplateCompiler::calculateVariableStatistics ( $tpl,
$node,
$resourceData,
$stats 
)
eZTemplateCompiler::calculateVariableStatisticsChildren ( $tpl,
$nodeChildren,
$resourceData,
  $namespace,
$stats 
)
eZTemplateCompiler::combineStaticNodes ( $tpl,
$resourceData,
$lastNode,
$newNode 
)

Tries to combine the node $lastNode and the node $newNode into one new text node. If possible the new node is created in $newNode and $lastNode will be set to false. Combining nodes only works for text nodes and variable nodes without variable lookup, attributes and operators.

Referenced by processNodeCombiningChildren().

eZTemplateCompiler::compilationDirectory ( )
static
eZTemplateCompiler::compilationFilename (   $key,
  $resourceData 
)

Creates the name for the compiled template and returns it. The name conists of original filename with the md5 of the key and charset appended.

Referenced by compileTemplate(), executeCompilation(), generatePHPCodeChildren(), and hasCompiledTemplate().

eZTemplateCompiler::compileTemplate ( $tpl,
  $key,
$resourceData 
)
static

Generates the cache which will be used for handling optimized processing using the key $key.

Note
Each call to this will set the PHP time limit to 30
Returns
false if the cache does not exist.

Referenced by eZTemplateFileResource\compileTemplate(), and eZTemplate\compileTemplateFile().

eZTemplateCompiler::createCommonCompileTemplate ( )

Creates the common.php file which has common functions for compiled templates. If the file already exists if will not create it.

Referenced by compileTemplate().

eZTemplateCompiler::createStaticVariableData ( $tpl,
  $staticData,
  $variableItemPlacement 
)

Creates a variable data element for the data $staticData and returns it. The type of element depends on the type of the data, strings and booleans are returned as EZ_TEMPLATE_TYPE_TEXT and EZ_TEMPLATE_TYPE_NUMERIC while other types are turned into text and returned as EZ_TEMPLATE_TYPE_TEXT.

Referenced by inspectVariableData().

eZTemplateCompiler::currentTextName (   $parameters)

Figures out the current text name to use in compiled template code and return it. The names will be text, text1, text2 etc.

Referenced by compileTemplate(), and generatePHPCodeChildren().

eZTemplateCompiler::decreaseCurrentTextName ( $parameters)

Decreases a previosuly increased counter for the current text name.

eZTemplateCompiler::executeCompilation ( $tpl,
$textElements,
  $key,
$resourceData,
  $rootNamespace,
  $currentNamespace 
)

Tries to execute the compiled template and returns true if succsesful. Returns false if caching is disabled or the compiled template could not be executed.

Referenced by eZTemplateFileResource\executeCompiledTemplate().

eZTemplateCompiler::executeCompilationHelper (   $phpScript,
$text,
$tpl,
  $key,
$resourceData,
  $rootNamespace,
  $currentNamespace 
)

Helper function for executeCompilation. Will execute the script $phpScript and set the result text in $text. The parameters $tpl, $resourceData, $rootNamespace and $currentNamespace are passed to the executed template compilation script.

Returns
true if a text result was created.

Referenced by executeCompilation().

eZTemplateCompiler::eZTemplateCompiler ( )

Constructor

eZTemplateCompiler::fetchTemplatePiece (   $placementData)

Opens the template files specified in $placementData and fetches the text portion defined by the start and end position. The text is returned or null if the text could not be fetched.

Referenced by generatePHPCodeChildren().

eZTemplateCompiler::generateMergeNamespaceCode ( $php,
$tpl,
  $namespace,
  $namespaceScope,
  $parameters = array(),
  $skipSimpleAssignment = false 
)

Generates PHP code which will do namespace merging. The namespace to merge with is specified in $namespace and the scope of the merging is defined by $namespaceScope.

Referenced by generatePHPCodeChildren(), and generateVariableDataCode().

eZTemplateCompiler::generatePHPCode (   $useComments,
$php,
$tpl,
$node,
$resourceData 
)

Generates the PHP code defined in the template node tree $node. The code is generated using the php creator specified in $php.

Referenced by compileTemplate().

eZTemplateCompiler::generatePHPCodeChildren (   $useComments,
$php,
$tpl,
$nodeChildren,
$resourceData,
$parameters,
  $currentParameters 
)

Generates the PHP code for all node children specified in $nodeChildren.

See Also
generatePHPCode

Referenced by generatePHPCode().

eZTemplateCompiler::generateVariableCode ( $php,
$tpl,
  $node,
$knownTypes,
  $dataInspection,
  $parameters,
$resourceData 
)

Generates PHP code for the variable node $node. Use generateVariableDataCode if you want to create code for arbitrary variable data structures.

eZTemplateCompiler::generateVariableDataCode ( $php,
$tpl,
  $variableData,
$knownTypes,
  $dataInspection,
$persistence,
  $parameters,
$resourceData 
)

Generates PHP code for the variable tree structure in $variableData. The code will contain string, numeric and identifier assignment, variable lookup, attribute lookup and operator execution. Use generateVariableCode if you want to create code for a variable tree node.

eZTemplateCompiler::hasCompiledTemplate (   $key,
  $timestamp,
$resourceData 
)
static
Returns
true if the compiled template with the key $key exists. A compiled template is found usable when it exists and has a timestamp higher or equal to $timestamp.

Referenced by eZTemplateFileResource\hasCompiledTemplate().

eZTemplateCompiler::increaseCurrentTextName ( $parameters)

Increases the counter for the current text name, this ensure a uniqe name for it.

eZTemplateCompiler::inspectVariableData ( $tpl,
  $variableData,
  $variablePlacement,
$resourceData 
)

Looks over the variable data $variableData and returns an array with information on the structure. The following entries are generated.

  • is-constant - true if the variable data contains constant data like text and numerics
  • is-variable - true if the variable data is a variable lookup
  • has-operators - true if operators are present
  • has-attributes - true if attributes are used

Referenced by combineStaticNodes(), eZTemplateSetFunction\functionTemplateStatistics(), eZTemplateSectionFunction\functionTemplateStatistics(), processNodeCombiningChildren(), and processStaticOptimizations().

eZTemplateCompiler::isAccumulatorsEnabled ( )
static
Returns
true if template compilation should include debug accumulators.

Referenced by compileTemplate().

eZTemplateCompiler::isCompilationEnabled ( )
static
Returns
true if template compiling is enabled.
Note
To change this setting edit settings/site.ini and locate the group TemplateSettings and the entry TemplateCompile.

Referenced by eZTemplateFileResource\canCompileTemplate(), compileTemplate(), executeCompilation(), and hasCompiledTemplate().

eZTemplateCompiler::isDevelopmentModeEnabled ( )
static
Returns
true if template compilation should run in development mode.

When in development mode the system will perform additional checks, e.g. for modification time of compiled file vs original source file. This mode is quite useful for development since it requires less clear-cache calls but has additional file checks and should be turned off for live sites.

Referenced by generatePHPCodeChildren().

eZTemplateCompiler::isExecutionEnabled ( )
static
Returns
true if the compiled template execution is enabled.

Referenced by executeCompilation().

eZTemplateCompiler::isFallbackResourceCodeEnabled ( )
static
Returns
true if resource fallback code should be included.
eZTemplateCompiler::isNodePlacementEnabled ( )
static
Returns
true if template compilation should include comments.

Referenced by compileTemplate().

eZTemplateCompiler::isTimingPointsEnabled ( )
static
Returns
true if template compilation should include debug timing points.

Referenced by compileTemplate().

eZTemplateCompiler::isTreeEnabled (   $treeName)
static
Returns
true if template node tree named $treeName should be included the compiled template.

Referenced by compileTemplate().

eZTemplateCompiler::operatorHint ( $tpl,
  $operatorName 
)
Returns
the operator hint for the operator $operatorName, or false if the operator does not exist or has no hints.

Referenced by generateVariableDataCode(), and inspectVariableData().

eZTemplateCompiler::operatorStaticData ( $tpl,
  $operatorName 
)
Returns
static data from operators which support returning static data, or null if no static data could be extracted. The operator is specified in $operatorName.

Referenced by inspectVariableData().

eZTemplateCompiler::prepareVariableStatistics ( $tpl,
$resourceData,
$stats 
)
eZTemplateCompiler::processElementTransformationChild (   $useComments,
$php,
$tpl,
$node,
$elementTree,
$elementList,
$resourceData 
)

Iterates over the children of the function node $node and transforms the tree. If the node is not a function it will return false.

See Also
processNodeTransformationRoot, processNodeTransformationChild

Referenced by processElementTransformationList(), and processNodeTransformationChild().

eZTemplateCompiler::processElementTransformationList ( $tpl,
$node,
$elements,
$privateData 
)
eZTemplateCompiler::processNodeCombining (   $useComments,
$php,
$tpl,
$node,
$resourceData,
$newNode 
)

Iterates over the template node tree and tries to combine multiple static siblings into one element. The original tree is specified in $node and the new combined tree will be present in $newNode.

See Also
processNodeCombiningChildren

Referenced by compileTemplate().

eZTemplateCompiler::processNodeCombiningChildren (   $useComments,
$php,
$tpl,
$nodeChildren,
$resourceData,
$parentNode 
)

Does node combining on the children $nodeChildren.

See Also
processNodeCombining

Referenced by processNodeCombining().

eZTemplateCompiler::processNodeTransformation (   $useComments,
$php,
$tpl,
$node,
$resourceData,
$newNode 
)

Iterates over the template node tree $node and returns a new transformed tree in $newNode.

See Also
processNodeTransformationRoot, processNodeTransformationChild

Referenced by compileTemplate().

eZTemplateCompiler::processNodeTransformationChild (   $useComments,
$php,
$tpl,
$node,
$resourceData 
)

Iterates over the children of the function node $node and transforms the tree. If the node is not a function it will return false.

See Also
processNodeTransformationRoot, processNodeTransformationChild

Referenced by processNodeTransformationChildren(), and processNodeTransformationRoot().

eZTemplateCompiler::processNodeTransformationChildren (   $useComments,
$php,
$tpl,
$node,
$children,
$resourceData 
)

Iterates over the children $children and does transformation on them.

See Also
processNodeTransformation, processNodeTransformationChild

Referenced by processNodeTransformationNodes().

eZTemplateCompiler::processNodeTransformationNodes ( $tpl,
$node,
$nodes,
$privateData 
)

Iterates over the nodes $nodes and does transformation on them.

See Also
processNodeTransformationChildren
Note
This method can be called from operator and functions as long as they have the $privateData parameter.

Referenced by eZTemplateCompiledLoop\processChildren(), eZTemplateSwitchFunction\templateNodeCaseTransformation(), and eZTemplateSectionFunction\templateNodeTransformation().

eZTemplateCompiler::processNodeTransformationRoot (   $useComments,
$php,
$tpl,
$node,
$resourceData 
)

Iterates over the children of the root node $node and does transformation on them.

See Also
processNodeTransformation, processNodeTransformationChild

Referenced by processNodeTransformation(), and processNodeTransformationChild().

eZTemplateCompiler::processRemoveNodePlacement ( $node)

Iterates over the node tree and removes all placement information.

Referenced by compileTemplate().

eZTemplateCompiler::processStaticOptimizations (   $useComments,
$php,
$tpl,
$node,
$resourceData,
$newNode 
)

Iterates over the items in the tree $node and tries to extract static data from operators which supports it.

Referenced by compileTemplate().

eZTemplateCompiler::setSettings (   $settingsMap)
static

Sets/unsets various compiler settings. To set a setting add a key in the $settingsMap with the wanted value, to unset it use null as the value.

The following values can be set.

  • compile - boolean, whether to compile templates or not
  • comments - boolean, whether to include comments in templates
  • accumulators - boolean, whether to include debug accumulators in templates
  • timingpoints - boolean, whether to include debug timingpoints in templates
  • fallbackresource - boolean, whether to include the fallback resource code
  • nodeplacement - boolean, whether to include information on placement of all nodes
  • execution - boolean, whether to execute the compiled templates or not
  • generate - boolean, whether to always generate the compiled files, or only when template is changed
  • compilation-directory - string, where to place compiled files, the path will be relative from the eZ publish directory and not the var/cache directory.
eZTemplateCompiler::setVariableStatistics ( $stats,
  $namespace,
  $variableName,
  $changes 
)
eZTemplateCompiler::staticNodeData (   $node)
Returns
the static data for the node $node or false if no data could be fetched. Will only return data from text nodes and variables nodes without variable lookup, attribute lookup or operators.

Referenced by combineStaticNodes().

eZTemplateCompiler::TemplatePrefix ( )
static

The documentation for this class was generated from the following file: