PHP Class LightnCandy\Compiler

Inheritance: extends Validator
显示文件 Open project: zordius/lightncandy Class Usage Examples

Public Properties

Property Type Description
$lastParsed

Public Methods

Method Description
compileSubExpression ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : array Get string presentation of a sub expression
compileTemplate ( array\arraystring | integer> &$context, string $template ) : string | null Compile template into PHP code
composePHPRender ( array\arraystring | integer> $context, string $code ) : string Compose LightnCandy render codes for include()
inline ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string handle inline partial
partial ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string handle partial

Protected Methods

Method Description
addUsageCount ( array\arraystring | integer> &$context, string $category, string $name, integer $count = 1 ) Add usage count to context
blockBegin ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string Return compiled PHP code for a handlebars block begin token
blockCustomHelper ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars, boolean $inverted = false ) : string Return compiled PHP code for a handlebars block custom helper begin token
blockEnd ( array\arraystring | integer> &$context, arrayinteger | string | array> &$vars, string | null $matchop = NULL ) : string Return compiled PHP code for a handlebars block end token
compileLog ( array\arraystring | integer> &$context, arrayinteger | string | array> &$vars, boolean $raw ) : string Return compiled PHP code for a handlebars log token
compileLookup ( array\arraystring | integer> &$context, arrayinteger | string | array> &$vars, boolean $raw, boolean $nosep = false ) : string Return compiled PHP code for a handlebars lookup token
compileOutput ( array\arraystring | integer> &$context, string $variable, string $expression, boolean $raw, boolean $nosep ) : string Return compiled PHP code for template output
compileToken ( array\arraystring | integer> &$context, array\array $info ) : string Return compiled PHP code for a handlebars token
compileVariable ( array\arraystring | integer> &$context, arrayinteger | string | array> &$vars, boolean $raw, boolean $nosep ) : string Return compiled PHP code for a handlebars variable token
customHelper ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars, boolean $raw, boolean $nosep, boolean $subExp = false ) : string | null Return compiled PHP code for a handlebars custom helper token
doElse ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string Return compiled PHP code for a handlebars else token
getFuncName ( array\arraystring | integer> &$context, string $name, string $tag ) : string Get function name for standalone or none standalone template.
getVariableName ( arraystring | integer> &$context, arraystring | integer> $var, array | null $lookup = null, $args = null ) : array Get string presentation of a variable
getVariableNameOrSubExpression ( arraystring | integer> &$context, arraystring | integer> $var ) : array Get string presentation of a subexpression or a variable
getVariableNames ( array\arraystring | integer> &$context, array $vn, array | null $blockParams = null ) : array Get string presentation of variables
invertedSection ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string Return compiled PHP code for a handlebars inverted section begin token
section ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars, boolean $isEach = false ) : string | null compile {{#foo}} token
with ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string | null compile {{with}} token

Method Details

addUsageCount() protected static method

Add usage count to context
protected static addUsageCount ( array\arraystring | integer> &$context, string $category, string $name, integer $count = 1 )
$context array\arraystring | integer>
$category string category name, can be one of: 'var', 'helpers', 'runtime'
$name string used name
$count integer increment

blockBegin() protected static method

Return compiled PHP code for a handlebars block begin token
protected static blockBegin ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string
$context array\arraystring | integer>
$vars arrayinteger | string | array>
return string Return compiled code segment for the token

blockCustomHelper() protected static method

Return compiled PHP code for a handlebars block custom helper begin token
protected static blockCustomHelper ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars, boolean $inverted = false ) : string
$context array\arraystring | integer>
$vars arrayinteger | string | array>
$inverted boolean the logic will be inverted
return string Return compiled code segment for the token

blockEnd() protected static method

Return compiled PHP code for a handlebars block end token
protected static blockEnd ( array\arraystring | integer> &$context, arrayinteger | string | array> &$vars, string | null $matchop = NULL ) : string
$context array\arraystring | integer>
$vars arrayinteger | string | array>
$matchop string | null should also match to this operator
return string Return compiled code segment for the token

compileLog() protected static method

Return compiled PHP code for a handlebars log token
protected static compileLog ( array\arraystring | integer> &$context, arrayinteger | string | array> &$vars, boolean $raw ) : string
$context array\arraystring | integer>
$vars arrayinteger | string | array>
$raw boolean is this {{{ token or not
return string Return compiled code segment for the token

compileLookup() protected static method

Return compiled PHP code for a handlebars lookup token
protected static compileLookup ( array\arraystring | integer> &$context, arrayinteger | string | array> &$vars, boolean $raw, boolean $nosep = false ) : string
$context array\arraystring | integer>
$vars arrayinteger | string | array>
$raw boolean is this {{{ token or not
$nosep boolean true to compile without seperator
return string Return compiled code segment for the token

compileOutput() protected static method

Return compiled PHP code for template output
protected static compileOutput ( array\arraystring | integer> &$context, string $variable, string $expression, boolean $raw, boolean $nosep ) : string
$context array\arraystring | integer>
$variable string PHP code for the variable
$expression string normalized handlebars expression
$raw boolean is this {{{ token or not
$nosep boolean true to compile without seperator
return string Return compiled code segment for the token

compileSubExpression() public static method

Get string presentation of a sub expression
public static compileSubExpression ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : array
$context array\arraystring | integer>
$vars arrayinteger | string | array>
return array

compileTemplate() public static method

Compile template into PHP code
public static compileTemplate ( array\arraystring | integer> &$context, string $template ) : string | null
$context array\arraystring | integer>
$template string handlebars template
return string | null generated PHP code

compileToken() protected static method

Return compiled PHP code for a handlebars token
protected static compileToken ( array\arraystring | integer> &$context, array\array $info ) : string
$context array\arraystring | integer>
$info array\array
return string Return compiled code segment for the token

compileVariable() protected static method

Return compiled PHP code for a handlebars variable token
protected static compileVariable ( array\arraystring | integer> &$context, arrayinteger | string | array> &$vars, boolean $raw, boolean $nosep ) : string
$context array\arraystring | integer>
$vars arrayinteger | string | array>
$raw boolean is this {{{ token or not
$nosep boolean true to compile without seperator
return string Return compiled code segment for the token

composePHPRender() public static method

Compose LightnCandy render codes for include()
public static composePHPRender ( array\arraystring | integer> $context, string $code ) : string
$context array\arraystring | integer>
$code string generated PHP code
return string Composed PHP code

customHelper() protected static method

Return compiled PHP code for a handlebars custom helper token
protected static customHelper ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars, boolean $raw, boolean $nosep, boolean $subExp = false ) : string | null
$context array\arraystring | integer>
$vars arrayinteger | string | array>
$raw boolean is this {{{ token or not
$nosep boolean true to compile without seperator
$subExp boolean true when compile for subexpression
return string | null Return compiled code segment for the token when the token is custom helper

doElse() protected static method

Return compiled PHP code for a handlebars else token
protected static doElse ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string
$context array\arraystring | integer>
$vars arrayinteger | string | array>
return string Return compiled code segment for the token when the token is else

getFuncName() protected static method

Get function name for standalone or none standalone template.
protected static getFuncName ( array\arraystring | integer> &$context, string $name, string $tag ) : string
$context array\arraystring | integer>
$name string base function name
$tag string original handlabars tag for debug
return string compiled Function name

getVariableName() protected static method

Get string presentation of a variable
protected static getVariableName ( arraystring | integer> &$context, arraystring | integer> $var, array | null $lookup = null, $args = null ) : array
$context arraystring | integer>
$var arraystring | integer>
$lookup array | null
return array

getVariableNameOrSubExpression() protected static method

Get string presentation of a subexpression or a variable
protected static getVariableNameOrSubExpression ( arraystring | integer> &$context, arraystring | integer> $var ) : array
$context arraystring | integer>
$var arraystring | integer>
return array

getVariableNames() protected static method

Get string presentation of variables
protected static getVariableNames ( array\arraystring | integer> &$context, array $vn, array | null $blockParams = null ) : array
$context array\arraystring | integer>
$vn array
$blockParams array | null
return array

inline() public static method

handle inline partial
public static inline ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string
$context array\arraystring | integer>
$vars arrayinteger | string | array>
return string Return compiled code segment for the partial

invertedSection() protected static method

Return compiled PHP code for a handlebars inverted section begin token
protected static invertedSection ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string
$context array\arraystring | integer>
$vars arrayinteger | string | array>
return string Return compiled code segment for the token

partial() public static method

handle partial
public static partial ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string
$context array\arraystring | integer>
$vars arrayinteger | string | array>
return string Return compiled code segment for the partial

section() protected static method

compile {{#foo}} token
protected static section ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars, boolean $isEach = false ) : string | null
$context array\arraystring | integer>
$vars arrayinteger | string | array>
$isEach boolean the section is #each
return string | null Return compiled code segment for the token

with() protected static method

compile {{with}} token
protected static with ( array\arraystring | integer> &$context, arrayinteger | string | array> $vars ) : string | null
$context array\arraystring | integer>
$vars arrayinteger | string | array>
return string | null Return compiled code segment for the token

Property Details

$lastParsed public_oe static_oe property

public static $lastParsed