Compiler
extends Validator
in package
LightnCandy Compiler
Table of Contents
- $lastParsed : mixed
- compileSubExpression() : array<string|int, string>
- Get string presentation of a sub expression
- compileTemplate() : string|null
- Compile template into PHP code
- composePHPRender() : string
- Compose LightnCandy render codes for include()
- helper() : bool
- Return true when the name is listed in helper table
- inline() : string
- handle inline partial
- log() : bool|null
- Return true when this is {{log ...}}
- lookup() : bool|null
- Return true when this is {{lookup ...}}
- partial() : string
- handle partial
- resolveHelper() : bool
- use helperresolver to resolve helper, return true when helper founded
- verify() : mixed
- Verify template
- addUsageCount() : mixed
- Add usage count to context
- blockBegin() : string
- Return compiled PHP code for a handlebars block begin token
- blockCustomHelper() : string
- Return compiled PHP code for a handlebars block custom helper begin token
- blockEnd() : string
- Return compiled PHP code for a handlebars block end token
- builtin() : mixed
- validate builtin helpers
- comment() : bool|null
- handle comment
- compileLog() : string
- Return compiled PHP code for a handlebars log token
- compileLookup() : string
- Return compiled PHP code for a handlebars lookup token
- compileOutput() : string
- Return compiled PHP code for template output
- compileToken() : string
- Return compiled PHP code for a handlebars token
- compileVariable() : string
- Return compiled PHP code for a handlebars variable token
- customHelper() : string|null
- Return compiled PHP code for a handlebars custom helper token
- delimiter() : bool|null
- Verify delimiters and operators
- doElse() : string
- Return compiled PHP code for a handlebars else token
- doElseChain() : mixed
- handle else chain
- doIf() : bool
- validate if token
- getFuncName() : string
- Get function name for standalone or none standalone template.
- getVariableName() : array<string|int, string>
- Get string presentation of a variable
- getVariableNameOrSubExpression() : array<string|int, string>
- Get string presentation of a subexpression or a variable
- getVariableNames() : array<string|int, string|array>
- Get string presentation of variables
- inlinePartial() : bool|null
- validate inline partial begin token
- invertedSection() : string
- Return compiled PHP code for a handlebars inverted section begin token
- isBlockHelper() : bool|null
- detect for block custom helper
- isDelimiter() : bool|null
- handle delimiter change
- operator() : bool|int|null
- Verify operators
- partialBlock() : bool|null
- validate partial block token
- pushLeft() : mixed
- push left string of current token and clear it
- pushPartial() : mixed
- push a string into the partial stacks
- pushStack() : mixed
- push current token into the section stack
- pushToken() : mixed
- push a token into the stack when it is not empty string
- rawblock() : bool|null
- handle raw block
- section() : string|null
- compile {{#foo}} token
- spacing() : string|null
- Modify $token when spacing rules matched.
- token() : string|array<string, array|string|int>|null
- Collect handlebars usage information, detect template error.
- unless() : bool
- validate unless token
- with() : string|null
- compile {{with}} token
Properties
$lastParsed
public
static mixed
$lastParsed
Methods
compileSubExpression()
Get string presentation of a sub expression
public
static compileSubExpression(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : array<string|int, string>
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
array<string|int, string> —code representing passed expression
compileTemplate()
Compile template into PHP code
public
static compileTemplate(array<string, array|string|int> &$context, string $template) : string|null
Parameters
- $context : array<string, array|string|int>
-
Current context
- $template : string
-
handlebars template
Return values
string|null —generated PHP code
composePHPRender()
Compose LightnCandy render codes for include()
public
static composePHPRender(array<string, array|string|int> $context, string $code) : string
Parameters
- $context : array<string, array|string|int>
-
Current context
- $code : string
-
generated PHP code
Return values
string —Composed PHP code
helper()
Return true when the name is listed in helper table
public
static helper(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars[, bool $checkSubexp = false ]) : bool
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
- $checkSubexp : bool = false
-
true when check for subexpression
Return values
bool —Return true when it is custom helper
inline()
handle inline partial
public
static inline(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
string —Return compiled code segment for the partial
log()
Return true when this is {{log ...}}
public
static log(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : bool|null
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
bool|null —Return true when it is custom helper
lookup()
Return true when this is {{lookup ...}}
public
static lookup(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : bool|null
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
bool|null —Return true when it is custom helper
partial()
handle partial
public
static partial(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
string —Return compiled code segment for the partial
resolveHelper()
use helperresolver to resolve helper, return true when helper founded
public
static resolveHelper(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> &$vars) : bool
Parameters
- $context : array<string, array|string|int>
-
Current context of compiler progress.
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
bool —$found helper exists or not
verify()
Verify template
public
static verify(array<string, array|string|int> &$context, string $template) : mixed
Parameters
- $context : array<string, array|string|int>
-
Current context
- $template : string
-
handlebars template
Return values
mixed —addUsageCount()
Add usage count to context
protected
static addUsageCount(array<string, array|string|int> &$context, string $category, string $name[, int $count = 1 ]) : mixed
Parameters
- $context : array<string, array|string|int>
-
current context
- $category : string
-
category name, can be one of: 'var', 'helpers', 'runtime'
- $name : string
-
used name
- $count : int = 1
-
increment
Tags
Return values
mixed —blockBegin()
Return compiled PHP code for a handlebars block begin token
protected
static blockBegin(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
string —Return compiled code segment for the token
blockCustomHelper()
Return compiled PHP code for a handlebars block custom helper begin token
protected
static blockCustomHelper(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars[, bool $inverted = false ]) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
- $inverted : bool = false
-
the logic will be inverted
Return values
string —Return compiled code segment for the token
blockEnd()
Return compiled PHP code for a handlebars block end token
protected
static blockEnd(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> &$vars[, string|null $matchop = null ]) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
- $matchop : string|null = null
-
should also match to this operator
Return values
string —Return compiled code segment for the token
builtin()
validate builtin helpers
protected
static builtin(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : mixed
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
mixed —comment()
handle comment
protected
static comment(array<string|int, string> &$token, array<string, array|string|int> &$context) : bool|null
Parameters
- $token : array<string|int, string>
-
detected handlebars {{ }} token
- $context : array<string, array|string|int>
-
current compile context
Return values
bool|null —Return true when is comment
compileLog()
Return compiled PHP code for a handlebars log token
protected
static compileLog(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> &$vars, bool $raw) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
- $raw : bool
-
is this {{{ token or not
Return values
string —Return compiled code segment for the token
compileLookup()
Return compiled PHP code for a handlebars lookup token
protected
static compileLookup(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> &$vars, bool $raw[, bool $nosep = false ]) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
- $raw : bool
-
is this {{{ token or not
- $nosep : bool = false
-
true to compile without seperator
Return values
string —Return compiled code segment for the token
compileOutput()
Return compiled PHP code for template output
protected
static compileOutput(array<string, array|string|int> &$context, string $variable, string $expression, bool $raw, bool $nosep) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $variable : string
-
PHP code for the variable
- $expression : string
-
normalized handlebars expression
- $raw : bool
-
is this {{{ token or not
- $nosep : bool
-
true to compile without seperator
Return values
string —Return compiled code segment for the token
compileToken()
Return compiled PHP code for a handlebars token
protected
static compileToken(array<string, array|string|int> &$context, array<string, array|bool> $info) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $info : array<string, array|bool>
-
parsed information
Return values
string —Return compiled code segment for the token
compileVariable()
Return compiled PHP code for a handlebars variable token
protected
static compileVariable(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> &$vars, bool $raw, bool $nosep) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
- $raw : bool
-
is this {{{ token or not
- $nosep : bool
-
true to compile without seperator
Return values
string —Return compiled code segment for the token
customHelper()
Return compiled PHP code for a handlebars custom helper token
protected
static customHelper(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars, bool $raw, bool $nosep[, bool $subExp = false ]) : string|null
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
- $raw : bool
-
is this {{{ token or not
- $nosep : bool
-
true to compile without seperator
- $subExp : bool = false
-
true when compile for subexpression
Return values
string|null —Return compiled code segment for the token when the token is custom helper
delimiter()
Verify delimiters and operators
protected
static delimiter(array<string|int, string> $token, array<string, array|string|int> &$context) : bool|null
Parameters
- $token : array<string|int, string>
-
detected handlebars {{ }} token
- $context : array<string, array|string|int>
-
current compile context
Tags
Return values
bool|null —Return true when invalid
doElse()
Return compiled PHP code for a handlebars else token
protected
static doElse(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
string —Return compiled code segment for the token when the token is else
doElseChain()
handle else chain
protected
static doElseChain(array<string, array|string|int> &$context) : mixed
Parameters
- $context : array<string, array|string|int>
-
current compile context
Return values
mixed —doIf()
validate if token
protected
static doIf(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : bool
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
bool —Return true always
getFuncName()
Get function name for standalone or none standalone template.
protected
static getFuncName(array<string, array|string|int> &$context, string $name, string $tag) : string
Parameters
- $context : array<string, array|string|int>
-
Current context of compiler progress.
- $name : string
-
base function name
- $tag : string
-
original handlabars tag for debug
Tags
Return values
string —compiled Function name
getVariableName()
Get string presentation of a variable
protected
static getVariableName(array<string|int, array|string|int> &$context, array<string|int, array|string|int> $var[, array<string|int, string>|null $lookup = null ][, mixed $args = null ]) : array<string|int, string>
Parameters
- $context : array<string|int, array|string|int>
-
current compile context
- $var : array<string|int, array|string|int>
-
variable parsed path
- $lookup : array<string|int, string>|null = null
-
extra lookup string as valid PHP variable name
- $args : mixed = null
Tags
Return values
array<string|int, string> —variable names
getVariableNameOrSubExpression()
Get string presentation of a subexpression or a variable
protected
static getVariableNameOrSubExpression(array<string|int, array|string|int> &$context, array<string|int, array|string|int> $var) : array<string|int, string>
Parameters
- $context : array<string|int, array|string|int>
-
current compile context
- $var : array<string|int, array|string|int>
-
variable parsed path
Return values
array<string|int, string> —variable names
getVariableNames()
Get string presentation of variables
protected
static getVariableNames(array<string, array|string|int> &$context, array<string|int, array<string|int, mixed>> $vn[, array<string|int, string>|null $blockParams = null ]) : array<string|int, string|array>
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vn : array<string|int, array<string|int, mixed>>
-
variable name array.
- $blockParams : array<string|int, string>|null = null
-
block param list
Tags
Return values
array<string|int, string|array> —variable names
inlinePartial()
validate inline partial begin token
protected
static inlinePartial(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : bool|null
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
bool|null —Return true when inline partial ends
invertedSection()
Return compiled PHP code for a handlebars inverted section begin token
protected
static invertedSection(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : string
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
string —Return compiled code segment for the token
isBlockHelper()
detect for block custom helper
protected
static isBlockHelper(array<string, array|string|int> $context, array<string|int, bool|int|string|array> $vars) : bool|null
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
bool|null —Return true when this token is block custom helper
isDelimiter()
handle delimiter change
protected
static isDelimiter(array<string, array|string|int> &$context) : bool|null
Parameters
- $context : array<string, array|string|int>
-
current compile context
Return values
bool|null —Return true when delimiter changed
operator()
Verify operators
protected
static operator(string $operator, array<string, array|string|int> &$context, array<string|int, bool|int|string|array> &$vars) : bool|int|null
Parameters
- $operator : string
-
the operator string
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Tags
Return values
bool|int|null —Return true when invalid or detected
partialBlock()
validate partial block token
protected
static partialBlock(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : bool|null
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
bool|null —Return true when partial block ends
pushLeft()
push left string of current token and clear it
protected
static pushLeft(array<string, array|string|int> &$context) : mixed
Parameters
- $context : array<string, array|string|int>
-
Current context
Return values
mixed —pushPartial()
push a string into the partial stacks
protected
static pushPartial(array<string, array|string|int> &$context, string $append) : mixed
Parameters
- $context : array<string, array|string|int>
-
Current context
- $append : string
-
a string to be appended int partial stacks
Return values
mixed —pushStack()
push current token into the section stack
protected
static pushStack(array<string, array|string|int> &$context, string $operation, array<string|int, bool|int|string|array> $vars) : mixed
Parameters
- $context : array<string, array|string|int>
-
Current context
- $operation : string
-
operation string
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
mixed —pushToken()
push a token into the stack when it is not empty string
protected
static pushToken(array<string, array|string|int> &$context, string|array<string|int, mixed> $token) : mixed
Parameters
- $context : array<string, array|string|int>
-
Current context
- $token : string|array<string|int, mixed>
-
a parsed token or a string
Return values
mixed —rawblock()
handle raw block
protected
static rawblock(array<string|int, string> &$token, array<string, array|string|int> &$context) : bool|null
Parameters
- $token : array<string|int, string>
-
detected handlebars {{ }} token
- $context : array<string, array|string|int>
-
current compile context
Return values
bool|null —Return true when in rawblock mode
section()
compile {{#foo}} token
protected
static section(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars[, bool $isEach = false ]) : string|null
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
- $isEach : bool = false
-
the section is #each
Return values
string|null —Return compiled code segment for the token
spacing()
Modify $token when spacing rules matched.
protected
static spacing(array<string|int, string> &$token, array<string, array|string|int> &$context[, bool $nost = false ]) : string|null
Parameters
- $token : array<string|int, string>
-
detected handlebars {{ }} token
- $context : array<string, array|string|int>
-
current compile context
- $nost : bool = false
-
do not do stand alone logic
Return values
string|null —Return compiled code segment for the token
token()
Collect handlebars usage information, detect template error.
protected
static token(array<string|int, string> &$token, array<string, array|string|int> &$context) : string|array<string, array|string|int>|null
Parameters
- $token : array<string|int, string>
-
detected handlebars {{ }} token
- $context : array<string, array|string|int>
-
current compile context
Return values
string|array<string, array|string|int>|null —$token string when rawblock; array when valid token require to be compiled, null when skip the token.
unless()
validate unless token
protected
static unless(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : bool
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
bool —Return true always
with()
compile {{with}} token
protected
static with(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : string|null
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
string|null —Return compiled code segment for the token