Pluf_Template_Compiler Class Reference

List of all members.

Public Member Functions

 __construct ($template_file, $folders=array(), $load=true)
 compile ()
 getCompiledTemplate ()
 compileBlocks ()
 loadTemplateFile ($file)
 _callback ($matches)
 _parseVariable ($expr)
 _parseFunction ($name, $args)
 _parseFinal ($string, $allowed=array(), $exceptchar=array(';'), $getAsArray=false)

Public Attributes

 $_usedModifiers = array()
 $templateFolders = array()
 $templateContent = ''
 $_extendBlocks = array()
 $_extendedTemplate = ''

Protected Member Functions

 updateModifierStack ($compiler)

Protected Attributes

 $_literals
 $_vartype
 $_assignOp
 $_op
 $_allowedInVar
 $_allowedInExpr
 $_allowedAssign
 $_modifier
 $_allowedTags
 $_extraTags = array()
 $_blockStack = array()
 $_transStack = array()
 $_transPlural = false
 $_sourceFile
 $_currentTag


Detailed Description

Class to compile a template file into the corresponding PHP script to be run by the Template class.

Compiler dataflow

The important elements of the compiler are the include extends block and superblock directives. They cannot be handled in a linear way like the rest of the elements, they are more like nodes.

Copyright (C) 2006 Laurent Jouanneau.


Constructor & Destructor Documentation

Pluf_Template_Compiler::__construct ( template_file,
folders = array(),
load = true 
)

Construct the compiler.

Parameters:
string Basename of the template file.
array Base folders in which the templates files should be found. (array())
bool Load directly the template content. (true)

[signal]

Pluf_Template_Compiler::construct_template_tags_modifiers

[sender]

Pluf_Template_Compiler

[description]

This signal allows an application to dynamically modify the allowed template tags. The order of the merge with the ones configured in the configuration files and the default one is: default -> signal -> configuration file. That is, the configuration file is the highest authority.

[parameters]

array('tags' => array(), 'modifiers' => array());


Member Function Documentation

Pluf_Template_Compiler::compile (  ) 

Compile the template into a PHP code.

Returns:
string PHP code of the compiled template.

Pluf_Template_Compiler::getCompiledTemplate (  ) 

Get a cleaned compile template.

Pluf_Template_Compiler::compileBlocks (  ) 

Parse the extend blocks.

If the current template extends another, it finds the extended template and grabs the defined blocks and compile them.

Pluf_Template_Compiler::loadTemplateFile ( file  ) 

Load a template file.

The path to the file to load is relative and the file is found in one of the $templateFolders array of folders.

Parameters:
string Relative path of the file to load.

Pluf_Template_Compiler::_callback ( matches  ) 

Pluf_Template_Compiler::_parseVariable ( expr  ) 

Pluf_Template_Compiler::_parseFunction ( name,
args 
)

Pluf_Template_Compiler::_parseFinal ( string,
allowed = array(),
exceptchar = array(';'),
getAsArray = false 
)

Pluf_Template_Compiler::updateModifierStack ( compiler  )  [protected]

Update the current stack of modifiers from another compiler.


Member Data Documentation

Pluf_Template_Compiler::$_literals [protected]

Store the literal blocks.

Pluf_Template_Compiler::$_vartype [protected]

Initial value:

 array(T_CHARACTER, T_CONSTANT_ENCAPSED_STRING, 
                                T_DNUMBER, T_ENCAPSED_AND_WHITESPACE, 
                                T_LNUMBER, T_OBJECT_OPERATOR, T_STRING, 
                                T_WHITESPACE, T_ARRAY, T_CLASS, T_PRIVATE)
Variables.

Pluf_Template_Compiler::$_assignOp [protected]

Initial value:

 array(T_AND_EQUAL, T_DIV_EQUAL, T_MINUS_EQUAL, 
                                 T_MOD_EQUAL, T_MUL_EQUAL, T_OR_EQUAL, 
                                 T_PLUS_EQUAL, T_PLUS_EQUAL, T_SL_EQUAL, 
                                 T_SR_EQUAL, T_XOR_EQUAL)
Assignation operators.

Pluf_Template_Compiler::$_op [protected]

Initial value:

 array(T_BOOLEAN_AND, T_BOOLEAN_OR, T_EMPTY, T_INC, 
                            T_ISSET, T_IS_EQUAL, T_IS_GREATER_OR_EQUAL, 
                            T_IS_IDENTICAL, T_IS_NOT_EQUAL, T_IS_NOT_IDENTICAL,
                            T_IS_SMALLER_OR_EQUAL, T_LOGICAL_AND, T_LOGICAL_OR,
                            T_LOGICAL_XOR, T_SR, T_SL, T_DOUBLE_ARROW)
Operators.

Pluf_Template_Compiler::$_allowedInVar [protected]

Authorized elements in variables.

Pluf_Template_Compiler::$_allowedInExpr [protected]

Authorized elements in expression.

Pluf_Template_Compiler::$_allowedAssign [protected]

Authorized elements in assignation.

Pluf_Template_Compiler::$_modifier [protected]

Initial value:

 array('upper' => 'strtoupper', 
                                 'lower' => 'strtolower',
                                 'count' => 'count',
                                 'md5' => 'md5',
                                 'escxml' => 'htmlspecialchars', 
                                 'escape' => 'Pluf_Template_htmlspecialchars',
                                 'strip_tags' => 'strip_tags', 
                                 'escurl' => 'rawurlencode',
                                 'capitalize' => 'ucwords',
                                 // Not var_export because of recursive issues.
                                 'debug' => 'print_r', 
                                 'dump' => 'Pluf_Template_varExport', 
                                 'fulldebug' => 'var_export',
                                 'count' => 'count',
                                 'nl2br' => 'Pluf_Template_nl2br',
                                 'trim' => 'trim',
                                 'unsafe' => 'Pluf_Template_unsafe',
                                 'safe' => 'Pluf_Template_unsafe',
                                 'date' => 'Pluf_Template_dateFormat',
                                 'time' => 'Pluf_Template_timeFormat',
                                 'dateago' => 'Pluf_Template_dateAgo',
                                 'timeago' => 'Pluf_Template_timeAgo',
                                 'email' => 'Pluf_Template_safeEmail',
                                 )
Output filters.

Pluf_Template_Compiler::$_usedModifiers = array()

After the compilation is completed, this contains the list of modifiers used in the template. The GetCompiledTemplate method will add a series of Pluf::loadFunction at the top to preload these modifiers.

Pluf_Template_Compiler::$_allowedTags [protected]

Initial value:

 array(
                                    'url' => 'Pluf_Template_Tag_Url',
                                    'aurl' => 'Pluf_Template_Tag_Rurl',
                                    'media' => 'Pluf_Template_Tag_MediaUrl',
                                    'amedia' => 'Pluf_Template_Tag_RmediaUrl',
                                    'aperm' => 'Pluf_Template_Tag_APerm',
                                    'getmsgs' => 'Pluf_Template_Tag_Messages',
                                    )
Default allowed extra tags/functions.

These default tags are merged with the 'template_tags' defined in the configuration of the application.

Pluf_Template_Compiler::$_extraTags = array() [protected]

During compilation, all the tags are created once so to query their interface easily.

Pluf_Template_Compiler::$_blockStack = array() [protected]

The block stack to see if the blocks are correctly closed.

Pluf_Template_Compiler::$_transStack = array() [protected]

Special stack for the translation handling in blocktrans.

Pluf_Template_Compiler::$_transPlural = false [protected]

Pluf_Template_Compiler::$_sourceFile [protected]

Current template source file.

Pluf_Template_Compiler::$_currentTag [protected]

Current tag.

Pluf_Template_Compiler::$templateFolders = array()

Template folders.

Pluf_Template_Compiler::$templateContent = ''

Template content. It can be set directly from a string.

Pluf_Template_Compiler::$_extendBlocks = array()

The extend blocks.

Pluf_Template_Compiler::$_extendedTemplate = ''

The extended template.


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

Generated on Wed Feb 3 15:44:52 2010 for Pluf by  doxygen