__construct()
addFunctionHandler()
addFunctionHandlers()
addTagHandler()
addTagHandlers()
buildNamedParamCode()
compile()
compileAndCombineSegments()
compileFunction()
compileIntoVariable()
compileNamedParams()
compileParsed()
compileParsedPlainText()
compilePlainText()
compileSegment()
compileSegments()
compileTag()
compileVar()
compileVarRef()
disableDynamicPhraseLoad()
escapeSingleQuotedString()
getArgumentLiteralValue()
getCompilerType()
getDefaultOptions()
getIncludedPhrases()
getIncludedTemplates()
getLineNumber()
getNamedAttributes()
getNamedParamsAsPhpCode()
getNewCompilerArgumentException()
getNewCompilerException()
getNewRawStatement()
getNewStatementCollection()
getOutputVar()
getOutputVarInitializer()
getPhraseValue()
getUniqueVar()
getVariableMap()
identifyPhrasesInParsedTemplate()
includeParsedTemplate()
isSegmentNamedTag()
lexAndParse()
mergePhraseCache()
parseConditionExpression()
parseNamedArguments()
prepareSegmentsForIteration()
removeTemplateFromCache()
resetPhraseCache()
resetTemplateCache()
resolveMappedVariable()
setDefaultOptions()
setFollowExternal()
setLastVistedSegment()
setLineNumber()
setOutputVar()
setTemplateCache()
setText()
setVariableMap()
_findAndLoadPhrasesFromSegments()
_getParsedTemplateFromModel()
_identifyPhrasesInSegments()
_parseConditionExpression()
_removeTemplateFromCache()
_resetTemplateCache()
_setTemplateCache()
_setupDefaults()
$_compilerType
$_enableDynamicPhraseLoad
$_followExternal
$_functionHandlers
$_includedPhrases
$_includedTemplates
$_languageId
$_lineNumber
$_options
$_outputVar
$_phraseCache
$_styleId
$_tagHandlers
$_templateCache
$_text
$_title
$_uniqueVarCount
$_uniqueVarPrefix
$_variableMap
General template compiling class.
This takes a string (template) and converts it into PHP code. This code represents the full statements.
Most methods are public so as to be usable by the tag/function handlers. Externally, compile() is the primary method to use for basic compilation.
package | XenForo_Template |
---|
__construct(string $text)
Sets up text.
string
Text to compile
addFunctionHandler(string $function, \XenForo_Template_Compiler_Function_Interface $handler) : \XenForo_Template_Compiler
string
Name of function to handle
\XenForo_Template_Compiler
Fluent interface ($this)addFunctionHandlers(array $functions) : \XenForo_Template_Compiler
array
Function handlers; key: function name, value: object
\XenForo_Template_Compiler
Fluent interface ($this)addTagHandler(string $tag, \XenForo_Template_Compiler_Tag_Interface $handler) : \XenForo_Template_Compiler
string
Name of tag to handle
\XenForo_Template_Compiler
Fluent interface ($this)addTagHandlers(array $tags) : \XenForo_Template_Compiler
array
Tag handlers; key: tag name, value: object
\XenForo_Template_Compiler
Fluent interface ($this)buildNamedParamCode(array $compiled) : string
array
Already compiled named params. See {@link compileNamedParams}.
string
compile(string $title, integer $styleId, integer $languageId) : string
Returns any number of statements.
string
Title of this template (required to prevent circular references)
integer
Style ID this template belongs to (for template includes)
integer
Language ID this compilation is for (used for phrases)
string
compileAndCombineSegments(string | array $segments, array $options) : string
This is simply a helper function that compiles and then combines them for you.
string
array
Segment(s)
array
null
Override options. If specified, this represents all options.
string
Valid PHP codecompileFunction(string $function, array $arguments, array $options)
string
Name of function found
array
Arguments (really should have at least 1 value). Each argument may be any number of segments
array
Options
compileIntoVariable(string | array $segments, string $var, array $options, boolean $generateVar) : string
This is commonly used to simplify compilation of data that needs to be passed into a function (eg, the children of a form tag).
string
array
Segmenets
string
Name of the variable to compile into. If generateVar is true, this will be written to (by ref).
array
Compiler options
boolean
Whether to generate the var in argument 2 or use the provided input
string
Full compiled statementscompileNamedParams(array $params, array $options, array $compileAsCondition) : array
The key is a single quoted string.
array
See {@link parseNamedArguments()}. Key is the name, value is segments for that param.
array
Compiler options
array
A list of named params should be compiled as conditions instead of plain output
array
compileParsed(string | array $segments, string $title, integer $styleId, integer $languageId) : string
string
array
string
Title of this template (required to prevent circular references)
integer
Style ID this template belongs to (for template includes)
integer
Language ID this compilation is for (used for phrases)
string
compileParsedPlainText(string | array $segments, string $title, integer $styleId, integer $languageId) : string
The template is considered to be plain text (the default variable escaping is disabled).
string
array
string
Title of this template (required to prevent circular references)
integer
Style ID this template belongs to (for template includes)
integer
Language ID this compilation is for (used for phrases)
string
compilePlainText(string $text, array $options)
string
Text to compile
array
Options
compileSegment(string | array $segment, array $options) : string
string
array
Segment
array
Override options, must be specified
string
compileSegments(string | array $segments, array $options) : \XenForo_Template_Compiler_Statement_Collection
string
array
Segment(s)
array
null
Override options. If specified, this represents all options.
\XenForo_Template_Compiler_Statement_Collection
Collection of parts of a statement or sub statementscompileTag(string $tag, array $attributes, array $children, array $options)
Mostly handled by the specified tag handler.
string
Tag found
array
Attributes (key: name, value: value)
array
Any nodes (text, var, tag) that are within this tag
array
Options
compileVar(string $name, array $keys, array $options)
string
Name of variable found, not including keys
array
Keys, may be empty
array
Options
compileVarRef(string | array $varRef, array $options) : string
A var ref is a string that looks somewhat like a variable. It is used in some arguments to simplify variable access and only allow variables.
Data received is any number of segments containing strings or variable segments.
Examples: $var, $var.key, $var.{$key}.2, {$key}, {$key}.blah, {$key.blah}.x
string
array
Variable reference segment(s)
array
Options
string
PHP code to access named variabledisableDynamicPhraseLoad()
Generally only desired for tests.
escapeSingleQuotedString($string) : string
string
string
getArgumentLiteralValue(string | array $argument) : string | false
If a literal value cannot be obtained, false is returned.
string
array
string
false
Literal value or falsegetCompilerType() : string
This method generally needs to be overridden in child classes because of the lack of LSB.
string
getDefaultOptions() : array
array
getIncludedPhrases() : array
array
List of phrase titlesgetIncludedTemplates() : array
array
getLineNumber() : integer
integer
getNamedAttributes(array $attributes, array $wantedAttributes) : array
array
Attributes for the tag
array
Attributes to fetch
array
Any attributes that existedgetNamedParamsAsPhpCode(array $params, array $options, array $compileAsCondition) : string
array
See {@link parseNamedArguments()}. Key is the name, value is segments for that param.
array
Compiler options
array
A list of named params should be compiled as conditions instead of plain output
string
PHP code for an arraygetNewCompilerArgumentException(mixed $segment) : \XenForo_Template_Compiler_Exception
mixed
The segment that caused this. If specified and has a line number, that line is reported.
getNewCompilerException(string $message, mixed $segment) : \XenForo_Template_Compiler_Exception
string
Optional message
mixed
The segment that caused this. If specified and has a line number, that line is reported.
getNewRawStatement(string $statement) : \XenForo_Template_Compiler_Statement_Raw
string
Quickly set a statement
getNewStatementCollection() : \XenForo_Template_Compiler_Statement_Collection
getOutputVar() : string
string
getOutputVarInitializer() : string
string
getPhraseValue(string $title) : string | false
string
string
false
getUniqueVar() : string
string
getVariableMap() : array
array
identifyPhrasesInParsedTemplate(string | array $segments) : array
This list can be populated even if the template is invalid.
string
array
List of parsed segments
array
Unique list of phrases used in this templateincludeParsedTemplate(string $title) : string | array
string
Name of the template to include
string
array
SegmentsisSegmentNamedTag(string | array $segment, string $tagName) : boolean
string
array
Segment
string
Tag name
boolean
lexAndParse() : array
array
Parsed segmentsmergePhraseCache(array $phraseData)
Phrases are expected for all languages.
array
Format: [language id][title] => value
parseConditionExpression(string | array $origCondition, array $options) : string
string
array
The original unparsed condition. This will consist of plaintext or curly var/function segments.
array
Compiler options
string
Valid PHP code for the conditionparseNamedArguments(array $arguments) : array
Each argument should be in the form of "key=value". The key must be literal, but the value can be anything.
array
Arguments to treat as named
array
Key is the argument name, value is segment(s) to be compiledprepareSegmentsForIteration($segments) : array
This sanitizes the segments so that each step will give you the next segment, which itself may be a string or an array.
string|array
array
removeTemplateFromCache(string $title)
string
resetPhraseCache()
This should be done when a phrase value changes, before compiling templates.
resetTemplateCache(integer | true $styleId)
integer
true
Style ID to reset the cache for; true for all styles
resolveMappedVariable(string $name, array $options) : string
string
array
Compiler options
string
setDefaultOptions(array $options) : \XenForo_Template_Compiler
Note that this merges into the options, maintaining any that are not specified in the parameter.
array
\XenForo_Template_Compiler
Fluent interface ($this)setFollowExternal(boolean $value)
This can be set to false when doing a test compile.
boolean
setLastVistedSegment(mixed $segment)
mixed
setLineNumber(integer $lineNumber)
This may be needed to report a more accurate line number when tags manually handle child tags (eg, if).
If this function is not used, the line number from the last tag handled by compileSegment() will be used.
integer
setOutputVar($_outputVar)
string
setTemplateCache(array $templates, integer $styleId)
array
Keys are template names, values are parsed vesions of templates
integer
ID of the style that the templates are from
setText($text)
string
setVariableMap(array $map, boolean $merge)
array
boolean
If true, merges; otherwise, overwrites
_findAndLoadPhrasesFromSegments(array | string $segments)
array
string
_getParsedTemplateFromModel(string $title, integer $styleId) : false | array
string
Title of template
integer
ID of the style the template should apply to
false
array
Array should have keys of id and data (data should be parsed version of template)_identifyPhrasesInSegments(string | array $segments) : array
string
array
array
List of phrases used in these segments; phrases may be repeated_parseConditionExpression(string $expression, array $placeholders, boolean $internalExpression, $isFunction) : string
Note that the variables passed into this will be modified by reference.
string
Expression with placeholders replaced with "\x1A"
array
Placeholders for variables/functions
boolean
Whether to return when we match a right parenthesis
string
Parsed condition_removeTemplateFromCache(string $title, string $compilerType)
string
string
_resetTemplateCache(integer | boolean $styleId, string $compilerType)
integer
boolean
string
_setTemplateCache(array $templates, integer $styleId, string $compilerType)
array
integer
string
_setupDefaults()
Primarily sets up the handlers for various functions/tags.
$_compilerType : string
This should be unique per class, based on the source for things like included templates, etc.
$_enableDynamicPhraseLoad
$_followExternal : boolean
This can be set to false for test compiles.
$_functionHandlers : array
Key is the function name (lower case) and value is the object.
$_includedPhrases
$_includedTemplates
$_languageId
$_lineNumber : integer
$_outputVar : string
$_phraseCache
$_styleId
$_tagHandlers : array
Key is tag name (lower case) and value is the object.
$_templateCache : array
Used for includes
$_text : string
$_title
$_uniqueVarCount : integer
$_uniqueVarPrefix : string
$_variableMap : array
This is primarily used for includes. Key is the from, value is the to.