Validator
in package
LightnCandy Validator
Table of Contents
- helper() : bool
- Return true when the name is listed in helper table
- log() : bool|null
- Return true when this is {{log ...}}
- lookup() : bool|null
- Return true when this is {{lookup ...}}
- resolveHelper() : bool
- use helperresolver to resolve helper, return true when helper founded
- verify() : mixed
- Verify template
- blockBegin() : bool
- validate block begin token
- blockCustomHelper() : int|null
- validate block custom helper token
- blockEnd() : bool|int
- Return compiled PHP code for a handlebars block end token
- builtin() : mixed
- validate builtin helpers
- comment() : bool|null
- handle comment
- delimiter() : bool|null
- Verify delimiters and operators
- doElse() : int
- Return 1 or larger number when else token detected
- doElseChain() : mixed
- handle else chain
- doIf() : bool
- validate if token
- inline() : bool
- validate inline partial
- inlinePartial() : bool|null
- validate inline partial begin token
- invertedSection() : int
- validate inverted section
- isBlockHelper() : bool|null
- detect for block custom helper
- isDelimiter() : bool|null
- handle delimiter change
- operator() : bool|int|null
- Verify operators
- partial() : int|bool
- validate partial
- 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() : bool
- validate section 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() : bool
- validate with token
Methods
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
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
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 —blockBegin()
validate block begin token
protected
static blockBegin(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
blockCustomHelper()
validate block custom helper token
protected
static blockCustomHelper(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars[, bool $inverted = false ]) : int|null
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
int|null —Return number of used custom helpers
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 $match = null ]) : bool|int
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
- $match : string|null = null
-
should also match to this operator
Return values
bool|int —Return true when required block ended, or Token::POS_BACKFILL when backfill happened.
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
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 1 or larger number when else token detected
protected
static doElse(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : int
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
int —Return 1 or larger number when else token detected
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
inline()
validate inline partial
protected
static inline(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
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()
validate inverted section
protected
static invertedSection(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : int
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
int —Return number of inverted sections
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
partial()
validate partial
protected
static partial(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars) : int|bool
Parameters
- $context : array<string, array|string|int>
-
current compile context
- $vars : array<string|int, bool|int|string|array>
-
parsed arguments list
Return values
int|bool —Return 1 or larger number for runtime partial, return true for other case
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()
validate section token
protected
static section(array<string, array|string|int> &$context, array<string|int, bool|int|string|array> $vars[, bool $isEach = false ]) : bool
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
bool —Return true always
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()
validate with token
protected
static with(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