Template compiler for administrative templates.
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.
| inherited_from | \XenForo_Template_Compiler::__construct() |
|---|
stringText to compile
addFunctionHandler(string $function, \XenForo_Template_Compiler_Function_Interface $handler) : \XenForo_Template_Compiler
| inherited_from | \XenForo_Template_Compiler::addFunctionHandler() |
|---|
stringName of function to handle
\XenForo_Template_CompilerFluent interface ($this)addFunctionHandlers(array $functions) : \XenForo_Template_Compiler
| inherited_from | \XenForo_Template_Compiler::addFunctionHandlers() |
|---|
arrayFunction handlers; key: function name, value: object
\XenForo_Template_CompilerFluent interface ($this)addTagHandler(string $tag, \XenForo_Template_Compiler_Tag_Interface $handler) : \XenForo_Template_Compiler
| inherited_from | \XenForo_Template_Compiler::addTagHandler() |
|---|
stringName of tag to handle
\XenForo_Template_CompilerFluent interface ($this)addTagHandlers(array $tags) : \XenForo_Template_Compiler
| inherited_from | \XenForo_Template_Compiler::addTagHandlers() |
|---|
arrayTag handlers; key: tag name, value: object
\XenForo_Template_CompilerFluent interface ($this)buildNamedParamCode(array $compiled) : string
| inherited_from | \XenForo_Template_Compiler::buildNamedParamCode() |
|---|
arrayAlready compiled named params. See {@link compileNamedParams}.
stringcompile(string $title, integer $styleId, integer $languageId) : string
Returns any number of statements.
| inherited_from | \XenForo_Template_Compiler::compile() |
|---|
stringTitle of this template (required to prevent circular references)
integerStyle ID this template belongs to (for template includes)
integerLanguage ID this compilation is for (used for phrases)
stringcompileAndCombineSegments(string | array $segments, array $options) : string
This is simply a helper function that compiles and then combines them for you.
| inherited_from | \XenForo_Template_Compiler::compileAndCombineSegments() |
|---|
stringarraySegment(s)
arraynullOverride options. If specified, this represents all options.
stringValid PHP codecompileFunction(string $function, array $arguments, array $options)
| inherited_from | \XenForo_Template_Compiler::compileFunction() |
|---|
stringName of function found
arrayArguments (really should have at least 1 value). Each argument may be any number of segments
arrayOptions
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).
| inherited_from | \XenForo_Template_Compiler::compileIntoVariable() |
|---|
stringarraySegmenets
stringName of the variable to compile into. If generateVar is true, this will be written to (by ref).
arrayCompiler options
booleanWhether to generate the var in argument 2 or use the provided input
stringFull compiled statementscompileNamedParams(array $params, array $options, array $compileAsCondition) : array
The key is a single quoted string.
| inherited_from | \XenForo_Template_Compiler::compileNamedParams() |
|---|
arraySee {@link parseNamedArguments()}. Key is the name, value is segments for that param.
arrayCompiler options
arrayA list of named params should be compiled as conditions instead of plain output
arraycompileParsed(string | array $segments, string $title, integer $styleId, integer $languageId) : string
| inherited_from | \XenForo_Template_Compiler::compileParsed() |
|---|
stringarray
stringTitle of this template (required to prevent circular references)
integerStyle ID this template belongs to (for template includes)
integerLanguage ID this compilation is for (used for phrases)
stringcompileParsedPlainText(string | array $segments, string $title, integer $styleId, integer $languageId) : string
The template is considered to be plain text (the default variable escaping is disabled).
| inherited_from | \XenForo_Template_Compiler::compileParsedPlainText() |
|---|
stringarray
stringTitle of this template (required to prevent circular references)
integerStyle ID this template belongs to (for template includes)
integerLanguage ID this compilation is for (used for phrases)
stringcompilePlainText(string $text, array $options)
| inherited_from | \XenForo_Template_Compiler::compilePlainText() |
|---|
stringText to compile
arrayOptions
compileSegment(string | array $segment, array $options) : string
| inherited_from | \XenForo_Template_Compiler::compileSegment() |
|---|
stringarraySegment
arrayOverride options, must be specified
stringcompileSegments(string | array $segments, array $options) : \XenForo_Template_Compiler_Statement_Collection
| inherited_from | \XenForo_Template_Compiler::compileSegments() |
|---|
stringarraySegment(s)
arraynullOverride options. If specified, this represents all options.
\XenForo_Template_Compiler_Statement_CollectionCollection of parts of a statement or sub statementscompileTag(string $tag, array $attributes, array $children, array $options)
Mostly handled by the specified tag handler.
| inherited_from | \XenForo_Template_Compiler::compileTag() |
|---|
stringTag found
arrayAttributes (key: name, value: value)
arrayAny nodes (text, var, tag) that are within this tag
arrayOptions
compileVar(string $name, array $keys, array $options)
| inherited_from | \XenForo_Template_Compiler::compileVar() |
|---|
stringName of variable found, not including keys
arrayKeys, may be empty
arrayOptions
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
| inherited_from | \XenForo_Template_Compiler::compileVarRef() |
|---|
stringarrayVariable reference segment(s)
arrayOptions
stringPHP code to access named variabledisableDynamicPhraseLoad()
Generally only desired for tests.
| inherited_from | \XenForo_Template_Compiler::disableDynamicPhraseLoad() |
|---|
escapeSingleQuotedString(string $string) : string
| inherited_from | \XenForo_Template_Compiler::escapeSingleQuotedString() |
|---|
string
stringgetArgumentLiteralValue(string | array $argument) : string | false
If a literal value cannot be obtained, false is returned.
| inherited_from | \XenForo_Template_Compiler::getArgumentLiteralValue() |
|---|
stringarray
stringfalseLiteral value or falsegetCompilerType() : string
This method generally needs to be overridden in child classes because of the lack of LSB.
stringgetDefaultOptions() : array
| inherited_from | \XenForo_Template_Compiler::getDefaultOptions() |
|---|
arraygetIncludedPhrases() : array
| inherited_from | \XenForo_Template_Compiler::getIncludedPhrases() |
|---|
arrayList of phrase titlesgetIncludedTemplates() : array
| inherited_from | \XenForo_Template_Compiler::getIncludedTemplates() |
|---|
arraygetLineNumber() : integer
| inherited_from | \XenForo_Template_Compiler::getLineNumber() |
|---|
integergetNamedAttributes(array $attributes, array $wantedAttributes) : array
| inherited_from | \XenForo_Template_Compiler::getNamedAttributes() |
|---|
arrayAttributes for the tag
arrayAttributes to fetch
arrayAny attributes that existedgetNamedParamsAsPhpCode(array $params, array $options, array $compileAsCondition) : string
| inherited_from | \XenForo_Template_Compiler::getNamedParamsAsPhpCode() |
|---|
arraySee {@link parseNamedArguments()}. Key is the name, value is segments for that param.
arrayCompiler options
arrayA list of named params should be compiled as conditions instead of plain output
stringPHP code for an arraygetNewCompilerArgumentException(mixed $segment) : \XenForo_Template_Compiler_Exception
| inherited_from | \XenForo_Template_Compiler::getNewCompilerArgumentException() |
|---|
mixedThe segment that caused this. If specified and has a line number, that line is reported.
getNewCompilerException(string $message, mixed $segment) : \XenForo_Template_Compiler_Exception
| inherited_from | \XenForo_Template_Compiler::getNewCompilerException() |
|---|
stringOptional message
mixedThe segment that caused this. If specified and has a line number, that line is reported.
getNewRawStatement(string $statement) : \XenForo_Template_Compiler_Statement_Raw
| inherited_from | \XenForo_Template_Compiler::getNewRawStatement() |
|---|
stringQuickly set a statement
getNewStatementCollection() : \XenForo_Template_Compiler_Statement_Collection
| inherited_from | \XenForo_Template_Compiler::getNewStatementCollection() |
|---|
getOutputVar() : string
| inherited_from | \XenForo_Template_Compiler::getOutputVar() |
|---|
stringgetOutputVarInitializer() : string
| inherited_from | \XenForo_Template_Compiler::getOutputVarInitializer() |
|---|
stringgetPhraseValue(string $title) : string | false
| inherited_from | \XenForo_Template_Compiler::getPhraseValue() |
|---|
string
stringfalse
getUniqueVar() : string
| inherited_from | \XenForo_Template_Compiler::getUniqueVar() |
|---|
stringgetVariableMap() : array
| inherited_from | \XenForo_Template_Compiler::getVariableMap() |
|---|
arrayidentifyPhrasesInParsedTemplate(string | array $segments) : array
This list can be populated even if the template is invalid.
| inherited_from | \XenForo_Template_Compiler::identifyPhrasesInParsedTemplate() |
|---|
stringarrayList of parsed segments
arrayUnique list of phrases used in this templateincludeParsedTemplate(string $title) : string | array
| inherited_from | \XenForo_Template_Compiler::includeParsedTemplate() |
|---|
stringName of the template to include
stringarraySegmentsisSegmentNamedTag(string | array $segment, string $tagName) : boolean
| inherited_from | \XenForo_Template_Compiler::isSegmentNamedTag() |
|---|
stringarraySegment
stringTag name
booleanlexAndParse() : array
| inherited_from | \XenForo_Template_Compiler::lexAndParse() |
|---|
arrayParsed segmentsmergePhraseCache(array $phraseData)
Phrases are expected for all languages.
| inherited_from | \XenForo_Template_Compiler::mergePhraseCache() |
|---|
arrayFormat: [language id][title] => value
parseConditionExpression(string | array $origCondition, array $options) : string
| inherited_from | \XenForo_Template_Compiler::parseConditionExpression() |
|---|
stringarrayThe original unparsed condition. This will consist of plaintext or curly var/function segments.
arrayCompiler options
stringValid 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.
| inherited_from | \XenForo_Template_Compiler::parseNamedArguments() |
|---|
arrayArguments to treat as named
arrayKey is the argument name, value is segment(s) to be compiledprepareSegmentsForIteration(string | array $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.
| inherited_from | \XenForo_Template_Compiler::prepareSegmentsForIteration() |
|---|
stringarray
arrayremoveTemplateFromCache(string $title)
string
resetPhraseCache()
This should be done when a phrase value changes, before compiling templates.
| inherited_from | \XenForo_Template_Compiler::resetPhraseCache() |
|---|
resetTemplateCache(integer | true $styleId)
integertrueStyle ID to reset the cache for; true for all
resolveMappedVariable(string $name, array $options) : string
| inherited_from | \XenForo_Template_Compiler::resolveMappedVariable() |
|---|
string
arrayCompiler options
stringsetDefaultOptions(array $options) : \XenForo_Template_Compiler
Note that this merges into the options, maintaining any that are not specified in the parameter.
| inherited_from | \XenForo_Template_Compiler::setDefaultOptions() |
|---|
array
\XenForo_Template_CompilerFluent interface ($this)setFollowExternal(boolean $value)
This can be set to false when doing a test compile.
| inherited_from | \XenForo_Template_Compiler::setFollowExternal() |
|---|
boolean
setLastVistedSegment(mixed $segment)
| inherited_from | \XenForo_Template_Compiler::setLastVistedSegment() |
|---|
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.
| inherited_from | \XenForo_Template_Compiler::setLineNumber() |
|---|
integer
setOutputVar(string $_outputVar)
| inherited_from | \XenForo_Template_Compiler::setOutputVar() |
|---|
string
setTemplateCache(array $templates, integer $styleId)
arrayKeys are template names, values are parsed vesions of templates
integerID of the style that the templates are from
setText(string $text)
| inherited_from | \XenForo_Template_Compiler::setText() |
|---|
string
setVariableMap(array $map, boolean $merge)
| inherited_from | \XenForo_Template_Compiler::setVariableMap() |
|---|
array
booleanIf true, merges; otherwise, overwrites
_findAndLoadPhrasesFromSegments(array | string $segments)
| inherited_from | \XenForo_Template_Compiler::_findAndLoadPhrasesFromSegments() |
|---|
arraystring
_getParsedTemplateFromModel(string $title, $styleId) : false | array
stringTitle of template
falsearray
_identifyPhrasesInSegments(string | array $segments) : array
| inherited_from | \XenForo_Template_Compiler::_identifyPhrasesInSegments() |
|---|
stringarray
arrayList 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.
| inherited_from | \XenForo_Template_Compiler::_parseConditionExpression() |
|---|
stringExpression with placeholders replaced with "\x1A"
arrayPlaceholders for variables/functions
booleanWhether to return when we match a right parenthesis
stringParsed condition_removeTemplateFromCache(string $title, string $compilerType)
| inherited_from | \XenForo_Template_Compiler::_removeTemplateFromCache() |
|---|
string
string
_resetTemplateCache(integer | boolean $styleId, string $compilerType)
| inherited_from | \XenForo_Template_Compiler::_resetTemplateCache() |
|---|
integerboolean
string
_setTemplateCache(array $templates, integer $styleId, string $compilerType)
| inherited_from | \XenForo_Template_Compiler::_setTemplateCache() |
|---|
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
| inherited_from | \XenForo_Template_Compiler::$$_enableDynamicPhraseLoad |
|---|
$_followExternal : boolean
This can be set to false for test compiles.
| inherited_from | \XenForo_Template_Compiler::$$_followExternal |
|---|
$_functionHandlers : array
Key is the function name (lower case) and value is the object.
| inherited_from | \XenForo_Template_Compiler::$$_functionHandlers |
|---|
$_includedPhrases
| inherited_from | \XenForo_Template_Compiler::$$_includedPhrases |
|---|
$_includedTemplates
| inherited_from | \XenForo_Template_Compiler::$$_includedTemplates |
|---|
$_languageId
| inherited_from | \XenForo_Template_Compiler::$$_languageId |
|---|
$_lineNumber : integer
| inherited_from | \XenForo_Template_Compiler::$$_lineNumber |
|---|
$_outputVar : string
| inherited_from | \XenForo_Template_Compiler::$$_outputVar |
|---|
$_phraseCache
| inherited_from | \XenForo_Template_Compiler::$$_phraseCache |
|---|
$_styleId
| inherited_from | \XenForo_Template_Compiler::$$_styleId |
|---|
$_tagHandlers : array
Key is tag name (lower case) and value is the object.
| inherited_from | \XenForo_Template_Compiler::$$_tagHandlers |
|---|
$_templateCache : array
Used for includes
| inherited_from | \XenForo_Template_Compiler::$$_templateCache |
|---|
$_text : string
| inherited_from | \XenForo_Template_Compiler::$$_text |
|---|
$_title
| inherited_from | \XenForo_Template_Compiler::$$_title |
|---|
$_uniqueVarCount : integer
| inherited_from | \XenForo_Template_Compiler::$$_uniqueVarCount |
|---|
$_uniqueVarPrefix : string
| inherited_from | \XenForo_Template_Compiler::$$_uniqueVarPrefix |
|---|
$_variableMap : array
This is primarily used for includes. Key is the from, value is the to.
| inherited_from | \XenForo_Template_Compiler::$$_variableMap |
|---|