returns a default instance of this compiler, used by default by all Dwoo templates that do not have a specific compiler assigned and when you do not override the default compiler factory function
recursively implodes an array in a similar manner as var_export() does but with some tweaks to handle pre-compiled values and the fact that we do not need to enclose everything with "array" and do not require top-level keys to be displayed
static string
implode_r
( $params, [bool $recursiveCall = false])
-
array
$params: the array to implode
-
bool
$recursiveCall: if set to true, the function outputs key names for the top level
adds a block to the top of the block stack
string
addBlock
(string $type, $params, int $paramtype)
-
string
$type: block type (name)
-
array
$params: the parameters array
-
int
$paramtype: the parameters type (see mapParams), 0, 1 or 2
adds a custom block to the top of the block stack
string
addCustomBlock
(string $type, $params, int $paramtype)
-
string
$type: block type (name)
-
array
$params: the parameters array
-
int
$paramtype: the parameters type (see mapParams), 0, 1 or 2
adds a postprocessor to the compiler, it will be called before the template is compiled
void
addPostProcessor
(mixed $callback, [bool $autoload = false])
-
mixed
$callback: either a valid callback to the postprocessor or a simple name if the autoload is set to true
-
bool
$autoload: if set to true, the postprocessor is auto-loaded from one of the plugin directories, else you must provide a valid callback
adds a preprocessor to the compiler, it will be called before the template is compiled
void
addPreProcessor
(mixed $callback, [bool $autoload = false])
-
mixed
$callback: either a valid callback to the preprocessor or a simple name if the autoload is set to true
-
bool
$autoload: if set to true, the preprocessor is auto-loaded from one of the plugin directories, else you must provide a valid callback
compiles the provided string down to php code
Implementation of:
- Dwoo_ICompiler::compile()
- compiles the provided string down to php code
returns a reference to the first block of the given type encountered and optionally closes all blocks until it finds it
this is mainly used by {else} plugins to close everything that was opened between their parent and themselves
&array
&findBlock
(string $type, [bool $closeAlong = false])
-
string
$type: the block type (name)
-
bool
$closeAlong: whether to close all blocks encountered while going down the block stack or not
flattens a variable tree, this helps in parsing very complex variables such as $var.foo[$foo.bar->baz].baz, it computes the contents of the brackets first and works out from there
string
flattenVarTree
( $tree, [bool $recursed = false])
-
array
$tree: the variable tree parsed by he parseVar() method that must be flattened
-
bool
$recursed: leave that to false by default, it is only for internal use
forces an absolute scope
array
forceScope
(mixed $scope)
-
mixed
$scope: a scope as a string or array
returns the auto escape setting
default setting is disabled/false
bool
getAutoEscape
()
returns the compiled parameters (for example a variable's compiled parameter will be "$this->scope['key']") out of the given parameter array
array
getCompiledParams
( $params)
-
array
$params: parameter array
returns a reference to the current block array
&array
&getCurrentBlock
()
returns the left and right template delimiters
array
getDelimiters
()
returns the dwoo object that initiated this template compilation, only available during compilation of a template
returns the current line number, only available during compilation of a template
int
getLine
()
returns the tag openings handling strictness setting
bool
getLooseOpeningHandling
()
returns the parameter map of the given callback, it filters out entries typed as Dwoo and Dwoo_Compiler and turns the rest parameter into a "*"
array
getParamMap
(callback $callback)
-
callback
$callback: the function/method to reflect on
returns the plugin type of a plugin and adds it to the used plugins array if required
int
getPluginType
(string $name)
-
string
$name: plugin name, as found in the template
returns the current pointer position, only available during compilation of a template
int
getPointer
()
returns the real parameters (for example a variable's real parameter will be its key, etc) out of the given parameter array
array
getRealParams
( $params)
-
array
$params: parameter array
returns the current security policy object or null by default
returns the template that is being compiled
string
getTemplateSource
([bool $fromPointer = false])
-
bool
$fromPointer: if set to true, only the source from the current pointer position is returned
injects a block at the top of the plugin stack without calling its preProcessing method
used by {else} blocks to re-add themselves after having closed everything up to their parent
void
injectBlock
(string $type, $params)
-
string
$type: block type (name)
-
array
$params: parameters array
internal function to autoload processors at runtime if required
void
loadProcessor
(string $class, string $name)
-
string
$class: the class/function name
-
string
$name: the plugin name (without Dwoo_Plugin_ prefix)
maps the parameters received from the template onto the parameters required by the given callback
array
mapParams
( $params, callback $callback, [int $callType = 2])
-
array
$params: the array of parameters
-
callback
$callback: the function or method to reflect on to find out the required parameters
-
int
$callType: the type of call in the template, 0 = no params, 1 = php-style call, 2 = named parameters call
entry point of the parser, it redirects calls to other parse* functions
string
parse
(string $in, int $from, int $to, [mixed $parsingParams = false], [string $curBlock = ''], [ &$pointer = null], mixed $pointer)
-
string
$in: the string within which we must parse something
-
int
$from: the starting offset of the parsed area
-
int
$to: the ending offset of the parsed area
-
mixed
$parsingParams: must be an array if we are parsing a function or modifier's parameters, or false by default
-
string
$curBlock: the current parser-block being processed
-
mixed
$pointer: a reference to a pointer that will be increased by the amount of characters parsed, or null by default
-
&$pointer
parses a constant
string
parseConst
(string $in, int $from, int $to, [mixed $parsingParams = false], [string $curBlock = ''], [ &$pointer = null], mixed $pointer)
-
string
$in: the string within which we must parse something
-
int
$from: the starting offset of the parsed area
-
int
$to: the ending offset of the parsed area
-
mixed
$parsingParams: must be an array if we are parsing a function or modifier's parameters, or false by default
-
string
$curBlock: the current parser-block being processed
-
mixed
$pointer: a reference to a pointer that will be increased by the amount of characters parsed, or null by default
-
&$pointer
parses a constant
string
parseConstKey
(string $key, string $curBlock)
-
string
$key: the constant to parse
-
string
$curBlock: the current parser-block being processed
parses a function call
string
parseFunction
(string $in, int $from, int $to, [mixed $parsingParams = false], [string $curBlock = ''], [ &$pointer = null], mixed $pointer)
-
string
$in: the string within which we must parse something
-
int
$from: the starting offset of the parsed area
-
int
$to: the ending offset of the parsed area
-
mixed
$parsingParams: must be an array if we are parsing a function or modifier's parameters, or false by default
-
string
$curBlock: the current parser-block being processed
-
mixed
$pointer: a reference to a pointer that will be increased by the amount of characters parsed, or null by default
-
&$pointer
parses any number of chained method calls/property reads
string
parseMethodCall
(string $output, string $methodCall, string $curBlock, &$pointer, int $pointer)
-
string
$output: the variable or whatever upon which the method are called
-
string
$methodCall: method call source, starting at "->"
-
string
$curBlock: the current parser-block being processed
-
int
$pointer: a reference to a pointer that will be increased by the amount of characters parsed
-
&$pointer
parses various constants, operators or non-quoted strings
string
parseOthers
(string $in, int $from, int $to, [mixed $parsingParams = false], [string $curBlock = ''], [ &$pointer = null], mixed $pointer)
-
string
$in: the string within which we must parse something
-
int
$from: the starting offset of the parsed area
-
int
$to: the ending offset of the parsed area
-
mixed
$parsingParams: must be an array if we are parsing a function or modifier's parameters, or false by default
-
string
$curBlock: the current parser-block being processed
-
mixed
$pointer: a reference to a pointer that will be increased by the amount of characters parsed, or null by default
-
&$pointer
parses a string
string
parseString
(string $in, int $from, int $to, [mixed $parsingParams = false], [string $curBlock = ''], [ &$pointer = null], mixed $pointer)
-
string
$in: the string within which we must parse something
-
int
$from: the starting offset of the parsed area
-
int
$to: the ending offset of the parsed area
-
mixed
$parsingParams: must be an array if we are parsing a function or modifier's parameters, or false by default
-
string
$curBlock: the current parser-block being processed
-
mixed
$pointer: a reference to a pointer that will be increased by the amount of characters parsed, or null by default
-
&$pointer
parses a variable
string
parseVar
(string $in, int $from, int $to, [mixed $parsingParams = false], [string $curBlock = ''], [ &$pointer = null], mixed $pointer)
-
string
$in: the string within which we must parse something
-
int
$from: the starting offset of the parsed area
-
int
$to: the ending offset of the parsed area
-
mixed
$parsingParams: must be an array if we are parsing a function or modifier's parameters, or false by default
-
string
$curBlock: the current parser-block being processed
-
mixed
$pointer: a reference to a pointer that will be increased by the amount of characters parsed, or null by default
-
&$pointer
parses a constant variable (a variable that doesn't contain another variable) and preprocesses it to save runtime processing time
string
parseVarKey
(string $key, string $curBlock)
-
string
$key: the variable to parse
-
string
$curBlock: the current parser-block being processed
runs htmlentities over the matched <?php ?> blocks when the security policy enforces that
string
phpTagEncodingHelper
(array $match)
-
array
$match: matched php block
adds compiled content to the current block
void
push
(string $content, [int $lineCount = null])
-
string
$content: the content to push
-
int
$lineCount: newlines count in content, optional
removes the closest-to-top block of the given type and all other blocks encountered while going down the block stack
string
removeBlock
(string $type)
-
string
$type: block type (name)
removes a postprocessor from the compiler
void
removePostProcessor
(mixed $callback)
-
mixed
$callback: either a valid callback to the postprocessor or a simple name if it was autoloaded
removes a preprocessor from the compiler
void
removePreProcessor
(mixed $callback)
-
mixed
$callback: either a valid callback to the preprocessor or a simple name if it was autoloaded
removes the block at the top of the stack and calls its postProcessing() method
string
removeTopBlock
()
replaces the modifiers applied to a string or a variable
string
replaceModifiers
( $m, [string $curBlock = null], [ &$pointer = null])
-
array
$m: the regex matches that must be array(1=>"double or single quotes enclosing a string, when applicable", 2=>"the string or var", 3=>"the modifiers matched")
-
string
$curBlock: the current parser-block being processed
-
&$pointer
replaces variables within a parsed string
string
replaceStringVars
(string $string, string $first, [string $curBlock = ''])
-
string
$string: the parsed string
-
string
$first: the first character parsed in the string, which is the string delimiter (' or ")
-
string
$curBlock: the current parser-block being processed
helper function that parses a variable
string
replaceVarKeyHelper
(array $match)
-
array
$match: the matched variable, array(1=>"string match")
changes the auto escape setting
if enabled, the compiler will automatically html-escape variables, unless they are passed through the safe function such as {$var|safe} or {safe $var}
default setting is disabled/false
void
setAutoEscape
(bool $enabled)
-
bool
$enabled: set to true to enable, false to disable
adds the custom plugins loaded into Dwoo to the compiler so it can load them
void
setCustomPlugins
( $customPlugins)
-
array
$customPlugins: an array of custom plugins
Implementation of:
- Dwoo_ICompiler::setCustomPlugins()
- adds the custom plugins loaded into Dwoo to the compiler so it can load them
sets the delimiters to use in the templates
delimiters can be multi-character strings but should not be one of those as they will make it very hard to work with templates or might even break the compiler entirely : "\", "$", "|", ":" and finally "#" only if you intend to use config-vars with the #var# syntax.
void
setDelimiters
(string $left, string $right)
-
string
$left: left delimiter
-
string
$right: right delimiter
sets the line number
void
setLine
(int $number, [bool $isOffset = false])
-
int
$number: the new line number
-
bool
$isOffset: if set to true, the position acts as an offset and not an absolute position
sets the tag openings handling strictness, if set to true, template tags can contain spaces before the first function/string/variable such as { $foo} is valid.
if set to false (default setting), { $foo} is invalid but that is however a good thing as it allows css (i.e. #foo { color:red; }) to be parsed silently without triggering an error, same goes for javascript.
void
setLooseOpeningHandling
([bool $allow = false])
-
bool
$allow: true to allow loose handling, false to restore default setting
sets the pointer position
void
setPointer
(int $position, [bool $isOffset = false])
-
int
$position: the new pointer position
-
bool
$isOffset: if set to true, the position acts as an offset and not an absolute position
sets the scope
set to null if the scope becomes "unstable" (i.e. too variable or unknown) so that variables are compiled in a more evaluative way than just $this->scope['key']
array
setScope
(mixed $scope, [bool $absolute = false])
-
mixed
$scope: a string i.e. "level1.level2" or an array i.e. array("level1", "level2")
-
bool
$absolute: if true, the scope is set from the top level scope and not from the current scope
sets the security policy object to enforce some php security settings
use this if untrusted persons can modify templates, set it on the Dwoo object as it will be passed onto the compiler automatically
Implementation of:
- Dwoo_ICompiler::setSecurityPolicy()
- sets the security policy object to enforce some php security settings
overwrites the template that is being compiled
string
setTemplateSource
(string $newSource, [bool $fromPointer = false])
-
string
$newSource: the template source that must replace the current one
-
bool
$fromPointer: if set to true, only the source from the current pointer position is replaced