BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
LightnCandy Class Reference

Static Public Member Functions

static compile ($template, $options=array('flags'=> self::FLAG_BESTPERFORMANCE))
 
static getContext ()
 
static prepare ($php, $tmpDir=null, $delete=true)
 
static noNamedArguments ($token, &$context, $named, $suggest= '!')
 
static handleMustacheSpacing (&$token, $vars, &$context)
 
static compileToken (&$token, &$context)
 

Public Attributes

const FLAG_ERROR_LOG = 1
 
const FLAG_ERROR_EXCEPTION = 2
 
const FLAG_ERROR_SKIPPARTIAL = 4194304
 
const FLAG_STANDALONE = 4
 
const FLAG_BARE = 33554432
 
const FLAG_NOESCAPE = 67108864
 
const FLAG_JSTRUE = 8
 
const FLAG_JSOBJECT = 16
 
const FLAG_THIS = 32
 
const FLAG_WITH = 64
 
const FLAG_PARENT = 128
 
const FLAG_JSQUOTE = 256
 
const FLAG_ADVARNAME = 512
 
const FLAG_SPACECTL = 1024
 
const FLAG_NAMEDARG = 2048
 
const FLAG_SPVARS = 4096
 
const FLAG_SLASH = 8388608
 
const FLAG_ELSE = 16777216
 
const FLAG_RAWBLOCK = 134217728
 
const FLAG_EXTHELPER = 8192
 
const FLAG_ECHO = 16384
 
const FLAG_PROPERTY = 32768
 
const FLAG_METHOD = 65536
 
const FLAG_RUNTIMEPARTIAL = 1048576
 
const FLAG_MUSTACHESP = 131072
 
const FLAG_MUSTACHELOOKUP = 262144
 
const FLAG_MUSTACHEPAIN = 2097152
 
const FLAG_RENDER_DEBUG = 524288
 
const FLAG_BESTPERFORMANCE = 16384
 
const FLAG_JS = 24
 
const FLAG_MUSTACHE = 6684672
 
const FLAG_HANDLEBARS = 161619936
 
const FLAG_HANDLEBARSJS = 161619960
 
const FLAG_INSTANCE = 98304
 
const VARNAME_SEARCH = '/(\\[[^\\]]+\\]|[^\\[\\]\\.]+)/'
 
const EXTENDED_COMMENT_SEARCH = '/{{!--.*?--}}/s'
 
const IS_SUBEXP_SEARCH = '/^\(.+\)$/s'
 
const POS_LOTHER = 1
 
const POS_LSPACE = 2
 
const POS_BEGINTAG = 3
 
const POS_LSPACECTL = 4
 
const POS_OP = 5
 
const POS_INNERTAG = 6
 
const POS_RSPACECTL = 7
 
const POS_ENDTAG = 8
 
const POS_RSPACE = 9
 
const POS_ROTHER = 10
 

Static Public Attributes

static $TMP_JS_FUNCTION_STR = "!!\aFuNcTiOn\a!!"
 

Static Protected Member Functions

static stripExtendedComments ($template)
 
static handleDynamicPartial (&$context)
 
static escapeTemplate ($template)
 
static setupToken (&$context, $left= '{{', $right= '}}')
 
static verifyTemplate (&$context, $template)
 
static compileTemplate (&$context, $template, $partial= '')
 
static composePHPRender ($context, $code)
 
static buildContext ($options)
 
static buildHelperTable ($context, $options, $tname= 'helpers')
 
static readPartial ($name, &$context)
 
static prePartial ($tmpl, &$name, &$context)
 
static resolvePartial (&$name, &$context)
 
static compilePartial (&$name, &$context, $content)
 
static buildCXFileext ($options)
 
static buildCXBasedir ($options)
 
static getPHPCode ($closure)
 
static exportHelper ($context, $tname= 'helpers')
 
static exportLCRun ($context)
 
static exportLCRunConstant ($context)
 
static scanLCRunDependency ($context, $code)
 
static handleError (&$context)
 
static getBoolStr ($v)
 
static getFuncName (&$context, $name, $tag)
 
static getArrayStr ($scopes)
 
static getArrayCode ($list)
 
static getVariableNames ($vn, &$context)
 
static compileSubExpression ($subExpression, &$context, $keepCount=false)
 
static getVariableNameOrSubExpression ($var, &$context)
 
static getVariableName ($var, &$context)
 
static getExpression ($levels, $spvar, $var)
 
static fixVariable ($v, &$context)
 
static parseTokenArgs (&$token, &$context)
 
static tokenString ($token, $remove=2)
 
static validateStartEnd ($token, &$context)
 
static validateOperations ($token, &$context, $vars)
 
static scanFeatures ($token, &$context)
 
static compileSection (&$token, &$context, &$vars, $named)
 
static compileBlockCustomHelper (&$context, $vars, $inverted=false)
 
static compileBlockEnd (&$token, &$context, $vars)
 
static compileBlockBegin (&$context, $vars)
 
static compileCustomHelper (&$context, $vars, $raw, $err=false)
 
static compileElse (&$context, &$vars)
 
static compileVariable (&$context, &$vars, $raw)
 
static addUsageCount (&$context, $category, $name, $count=1)
 

Static Protected Attributes

static $lastContext
 

Detailed Description

LightnCandy static core class.

Member Function Documentation

static LightnCandy::addUsageCount ( $context,
  $category,
  $name,
  $count = 1 
)
staticprotected

Internal method used by compile(). Add usage count to context

Parameters
array<string,array|string|integer>$context current context
string$categoryctegory name, can be one of: 'var', 'helpers', 'blockhelpers'
string$nameused name
integer$countincrement

1 when input array('usedCount' => array('test' => array())), 'test', 'testname' 3 when input array('usedCount' => array('test' => array('testname' => 2))), 'test', 'testname' 5 when input array('usedCount' => array('test' => array('testname' => 2))), 'test', 'testname', 3

static LightnCandy::buildContext (   $options)
staticprotected

Build context from options

Parameters
array<string,array|string|integer>$options input options
Returns
array<string,array|string|integer> Context from options
static LightnCandy::buildCXBasedir (   $options)
staticprotected

Internal method used by compile(). Check options and handle basedir.

Parameters
array<string,array|string|integer>$options current compile option
Returns
array<string> base directories

array() when input array() array() when input array('basedir' => array()) array('src') when input array('basedir' => array('src')) array('src') when input array('basedir' => array('src', 'dir_not_found')) array('src', 'tests') when input array('basedir' => array('src', 'tests'))

static LightnCandy::buildCXFileext (   $options)
staticprotected

Internal method used by compile(). Check options and handle fileext.

Parameters
array<string,array|string|integer>$options current compile option
Returns
array<string> file extensions

array('.tmpl') when input array() array('test') when input array('fileext' => 'test') array('test1') when input array('fileext' => array('test1')) array('test2', 'test3') when input array('fileext' => array('test2', 'test3'))

static LightnCandy::buildHelperTable (   $context,
  $options,
  $tname = 'helpers' 
)
staticprotected

Build custom helper table

Parameters
array<string,array|string|integer>$context prepared context
array<string,array|string|integer>$options input options
string$tnamehelper table name
Returns
array<string,array|string|integer> context with generated helper table

array() when input array(), array() array('flags' => array('exhlp' => 1)) when input array('flags' => array('exhlp' => 1)), array('helpers' => array('abc')) array('error' => array('Can not find custom helper function defination abc() !'), 'flags' => array('exhlp' => 0)) when input array('error' => array(), 'flags' => array('exhlp' => 0)), array('helpers' => array('abc')) array('flags' => array('exhlp' => 1), 'helpers' => array('LCRun3::raw' => 'LCRun3::raw')) when input array('flags' => array('exhlp' => 1), 'helpers' => array()), array('helpers' => array('LCRun3::raw')) array('flags' => array('exhlp' => 1), 'helpers' => array('test' => 'LCRun3::raw')) when input array('flags' => array('exhlp' => 1), 'helpers' => array()), array('helpers' => array('test' => 'LCRun3::raw'))

static LightnCandy::compile (   $template,
  $options = array('flags' => self::FLAG_BESTPERFORMANCE) 
)
static

Compile handlebars template into PHP code.

Parameters
string$templatehandlebars template string
array<string,array|string|integer>$options LightnCandy compile time and run time options, default is array('flags' => LightnCandy::FLAG_BESTPERFORMANCE)
Returns
string|false Compiled PHP code when successed. If error happened and compile failed, return false.
static LightnCandy::compileBlockBegin ( $context,
  $vars 
)
staticprotected

Internal method used by compile(). Return compiled PHP code partial for a handlebars block begin token.

Parameters
array<string,array|string|integer>$context current compile context
array<array|string|integer>$vars parsed arguments list
Returns
string Return compiled code segment for the token
static LightnCandy::compileBlockCustomHelper ( $context,
  $vars,
  $inverted = false 
)
staticprotected

Internal method used by compile(). Return compiled PHP code partial for a handlebars block custom helper begin token.

Parameters
array<string,array|string|integer>$context current compile context
array<array|string|integer>$vars parsed arguments list
boolean$invertedthe logic will be inverted
Returns
string|null Return compiled code segment for the token
static LightnCandy::compileBlockEnd ( $token,
$context,
  $vars 
)
staticprotected

Internal method used by compile(). Return compiled PHP code partial for a handlebars block end token.

Parameters
array<string>$token detected handlebars {{ }} token
array<string,array|string|integer>$context current compile context
array<array|string|integer>$vars parsed arguments list
Returns
string Return compiled code segment for the token
static LightnCandy::compileCustomHelper ( $context,
  $vars,
  $raw,
  $err = false 
)
staticprotected

Internal method used by compile(). Return compiled PHP code partial for a handlebars custom helper token.

Parameters
array<string,array|string|integer>$context current compile context
array<array|string|integer>$vars parsed arguments list
boolean$rawis this {{{ token or not
boolean$errshould cause error when missing helper or not
Returns
string|null Return compiled code segment for the token when the token is custom helper
static LightnCandy::compileElse ( $context,
$vars 
)
staticprotected

Internal method used by compile(). Return compiled PHP code partial for a handlebars else token.

Parameters
array<string,array|string|integer>$context current compile context
array<array|string|integer>$vars parsed arguments list
Returns
string|null Return compiled code segment for the token when the token is else
static LightnCandy::compilePartial ( $name,
$context,
  $content 
)
staticprotected

compile partial file, stored in context

Parameters
string$namepartial name
array<string,array|string|integer>$context Current context of compiler progress.
string$contentpartial content
static LightnCandy::compileSection ( $token,
$context,
$vars,
  $named 
)
staticprotected

Internal method used by compile(). Return compiled PHP code partial for a handlebars section token.

Parameters
array<string>$token detected handlebars {{ }} token
array<string,array|string|integer>$context current compile context
array<array|string|integer>$vars parsed arguments list
boolean$namedis named arguments or not
Returns
string|null Return compiled code segment for the token when the token is section
static LightnCandy::compileSubExpression (   $subExpression,
$context,
  $keepCount = false 
)
staticprotected

Internal method used by compile().

Parameters
string$subExpressionsubExpression to compile
array<string,array|string|integer>$context current compile context
boolean$keepCountkeep original usage count
Returns
array<string> code representing passed expression
static LightnCandy::compileTemplate ( $context,
  $template,
  $partial = '' 
)
staticprotected

Compile template into PHP code (internal method)

Parameters
array<string,array|string|integer>$context Current context
string$templatehandlebars template
string$partialpartial name when $template is come from the template
Returns
string generated PHP code
static LightnCandy::compileToken ( $token,
$context 
)
static

Internal method used by compile(). Return compiled PHP code partial for a handlebars token.

Parameters
array<string>$token detected handlebars {{ }} token
array<string,array|string|integer>$context current compile context
Returns
string Return compiled code segment for the token
static LightnCandy::compileVariable ( $context,
$vars,
  $raw 
)
staticprotected

Internal method used by compile(). Return compiled PHP code partial for a handlebars variable token.

Parameters
array<string,array|string|integer>$context current compile context
array<array|string|integer>$vars parsed arguments list
boolean$rawis this {{{ token or not
Returns
string Return compiled code segment for the token
static LightnCandy::composePHPRender (   $context,
  $code 
)
staticprotected

Compose LightnCandy render codes for include()

Parameters
array<string,array|string|integer>$context Current context
string$codegenerated PHP code
Returns
string Composed PHP code
static LightnCandy::escapeTemplate (   $template)
staticprotected

Escape template

Parameters
string$templatehandlebars template string
Returns
string Escaped template

'abc' when input 'abc' 'a\\bc' when input 'a' 'a\\'bc' when input 'a\'bc'

static LightnCandy::exportHelper (   $context,
  $tname = 'helpers' 
)
staticprotected

Internal method used by compile(). Export required custom helper functions.

Parameters
string$tnamehelper table name
array<string,array|string|integer>$context current compile context
Returns
string
static LightnCandy::exportLCRun (   $context)
staticprotected

Internal method used by compile(). Export required standalone functions.

Parameters
array<string,array|string|integer>$context current compile context
Returns
string
static LightnCandy::exportLCRunConstant (   $context)
staticprotected

Internal method used by compile(). Export standalone constants.

Parameters
array<string,array|string|integer>$context current compile context
Returns
string
static LightnCandy::fixVariable (   $v,
$context 
)
staticprotected

Internal method used by compile(). Return array presentation for a variable name

Parameters
string$vvariable name to be fixed.
array<string,array|string|integer>$context Current compile content.
Returns
array<integer,string> Return variable name array

array('this') when input 'this', array('flags' => array('advar' => 0, 'this' => 0)) array() when input 'this', array('flags' => array('advar' => 0, 'this' => 1)) array(1) when input '../', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) array(1) when input '../.', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) array(1) when input '../this', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) array(1, 'a') when input '../a', array('flags' => array('advar' => 0, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) array(2, 'a', 'b') when input '../../a.b', array('flags' => array('advar' => 0, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) array(2, '[a]', 'b') when input '../../[a].b', array('flags' => array('advar' => 0, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) array(2, 'a', 'b') when input '../../[a].b', array('flags' => array('advar' => 1, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0), 'scan' => true) array('id') when input 'this.id', array('flags' => array('advar' => 1, 'this' => 1, 'parent' => 1), 'usedFeature' => array('parent' => 0)) array(0, '\'a.b\'') when input '"a.b"', array('flags' => array('advar' => 1, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0)) array(0, '123') when input '123', array('flags' => array('advar' => 1, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0)) array(0, 'null') when input 'null', array('flags' => array('advar' => 1, 'this' => 0, 'parent' => 1), 'usedFeature' => array('parent' => 0))

static LightnCandy::getArrayCode (   $list)
staticprotected

Internal method used by getVariableName(). Get variable names translated string.

Parameters
array<string>$list an array of variable names.
Returns
string PHP array names string

'' when input array() "['a']" when input array('a') "['a']['b']['c']" when input array('a', 'b', 'c')

static LightnCandy::getArrayStr (   $scopes)
staticprotected

Internal method used by getArrayCode(). Get variable names translated string.

Parameters
array<string>$scopes an array of variable names with single quote
Returns
string PHP array names string

'' when input array() '[a]' when input array('a') '[a][b][c]' when input array('a', 'b', 'c')

static LightnCandy::getBoolStr (   $v)
staticprotected

Internal method used by compile(). Return 'true' or 'false' string.

Parameters
integer$vvalue
Returns
string 'true' when the value larger then 0

'true' when input 1 'true' when input 999 'false' when input 0 'false' when input -1

static LightnCandy::getContext ( )
static

Get last compiler context.

Returns
array<string,array|string|integer> Context data
static LightnCandy::getExpression (   $levels,
  $spvar,
  $var 
)
staticprotected

Internal method used by compile().

Parameters
integer$levelstrace N levels top parent scope
boolean$spvaris the path start with @ or not
array<string|integer>$var variable parsed path
Returns
string normalized expression for debug display

'[a].[b]' when input 0, false, array('a', 'b') '@[root]' when input 0, true, array('root') 'this' when input 0, false, null 'this.[id]' when input 0, false, array(null, 'id') '@[root].[a].[b]' when input 0, true, array('root', 'a', 'b') '../../[a].[b]' when input 2, false, array('a', 'b') '../[a\'b]' when input 1, false, array('a\'b')

static LightnCandy::getFuncName ( $context,
  $name,
  $tag 
)
staticprotected

Internal method used by compile(). Get function name for standalone or none standalone template.

Parameters
array<string,array|string|integer>$context Current context of compiler progress.
string$namebase function name
string$tagoriginal handlabars tag for debug
Returns
string compiled Function name

'LCRun3::test(' when input array('flags' => array('standalone' => 0, 'debug' => 0), 'lcrun' => 'LCRun3'), 'test', '' 'LCRun3::test2(' when input array('flags' => array('standalone' => 0, 'debug' => 0), 'lcrun' => 'LCRun3'), 'test2', '' "\$cx['funcs']['test3'](" when input array('flags' => array('standalone' => 1, 'debug' => 0), 'lcrun' => 'LCRun3'), 'test3', '' 'LCRun3::debug(\'abc\', \'test\', ' when input array('flags' => array('standalone' => 0, 'debug' => 1), 'lcrun' => 'LCRun3'), 'test', 'abc'

static LightnCandy::getPHPCode (   $closure)
staticprotected

Internal method used by compile(). Get PHP code from a closure of function as string.

Parameters
object$closureClosure object
Returns
string

'function($a) {return;}' when input function ($a) {return;} 'function($a) {return;}' when input function ($a) {return;}

static LightnCandy::getVariableName (   $var,
$context 
)
staticprotected

Internal method used by compile().

Parameters
array<array|string|integer>$var variable parsed path
array<array|string|integer>$context current compile context
Returns
array<string> variable names

array('$in', 'this') when input array(null), array('flags'=>array('spvar'=>true,'debug'=>0)) array('((isset($in[\'true\']) && is_array($in)) ? $in[\'true\'] : null)', '[true]') when input array('true'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array('((isset($in[\'false\']) && is_array($in)) ? $in[\'false\'] : null)', '[false]') when input array('false'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array('true', 'true') when input array(0, 'true'), array('flags'=>array('spvar'=>true,'debug'=>0)) array('false', 'false') when input array(0, 'false'), array('flags'=>array('spvar'=>true,'debug'=>0)) array('((isset($in[\'2\']) && is_array($in)) ? $in[\'2\'] : null)', '[2]') when input array('2'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array('2', '2') when input array(0, '2'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0)) array('((isset($in[\'\']) && is_array($in)) ? $in[\'\'] : null)', '[]') when input array(''), array('flags'=>array('spvar'=>false,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array("((isset(\$cx['sp_vars']['index']) && is_array(\$cx['sp_vars'])) ? \$cx['sp_vars']['index'] : null)", '@[index]') when input array(''), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array("((isset(\$cx['sp_vars']['key']) && is_array(\$cx['sp_vars'])) ? \$cx['sp_vars']['key'] : null)", '@[key]') when input array(''), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array("((isset(\$cx['sp_vars']['first']) && is_array(\$cx['sp_vars'])) ? \$cx['sp_vars']['first'] : null)", '@[first]') when input array(''), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array("((isset(\$cx['sp_vars']['last']) && is_array(\$cx['sp_vars'])) ? \$cx['sp_vars']['last'] : null)", '@[last]') when input array(''), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array('((isset($in[\'"a"\']) && is_array($in)) ? $in[\'"a"\'] : null)', '["a"]') when input array('"a"'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array('"a"', '"a"') when input array(0, '"a"'), array('flags'=>array('spvar'=>true,'debug'=>0)) array('((isset($in[\'a\']) && is_array($in)) ? $in[\'a\'] : null)', '[a]') when input array('a'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array('((isset($cx[\'scopes\'][count($cx[\'scopes\'])-1][\'a\']) && is_array($cx[\'scopes\'][count($cx[\'scopes\'])-1])) ? $cx[\'scopes\'][count($cx[\'scopes\'])-1][\'a\'] : null)', '../[a]') when input array(1,'a'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array('((isset($cx[\'scopes\'][count($cx[\'scopes\'])-3][\'a\']) && is_array($cx[\'scopes\'][count($cx[\'scopes\'])-3])) ? $cx[\'scopes\'][count($cx[\'scopes\'])-3][\'a\'] : null)', '../../../[a]') when input array(3,'a'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array('((isset($in[\'id\']) && is_array($in)) ? $in[\'id\'] : null)', 'this.[id]') when input array(null, 'id'), array('flags'=>array('spvar'=>true,'debug'=>0,'prop'=>0,'method'=>0,'mustlok'=>0)) array('LCRun3::v($cx, $in, array(\'id\'))', 'this.[id]') when input array(null, 'id'), array('flags'=>array('prop'=>true,'spvar'=>true,'debug'=>0,'method'=>0,'mustlok'=>0,'standalone'=>0), 'lcrun' => 'LCRun3')

static LightnCandy::getVariableNameOrSubExpression (   $var,
$context 
)
staticprotected

Internal method used by compile().

Parameters
array<array|string|integer>$var variable parsed path
array<array|string|integer>$context current compile context
Returns
array<string> variable names
static LightnCandy::getVariableNames (   $vn,
$context 
)
staticprotected

Internal method used by compile().

Parameters
array<array>$vn variable name array.
array<string,array|string|integer>$context current compile context
Returns
array<string|array> variable names

array('array(array($in),array())', array('this')) when input array(null), array('flags'=>array('spvar'=>true)) array('array(array($in,$in),array())', array('this', 'this')) when input array(null, null), array('flags'=>array('spvar'=>true)) array('array(array(),array(\'a\'=>$in))', array('this')) when input array('a' => null), array('flags'=>array('spvar'=>true))

static LightnCandy::handleDynamicPartial ( $context)
staticprotected

Include all partials when using dynamic partials

static LightnCandy::handleError ( $context)
staticprotected

Internal method used by compile(). Handle exists error and return error status.

Parameters
array<string,array|string|integer>$context Current context of compiler progress.
Exceptions
Exception
Returns
boolean True when error detected

true when input array('level' => 1, 'stack' => array('X'), 'flags' => array('errorlog' => 0, 'exception' => 0), 'error' => array(), 'rawblock' => 0) false when input array('level' => 0, 'error' => array()) true when input array('level' => 0, 'error' => array('some error'), 'flags' => array('errorlog' => 0, 'exception' => 0))

static LightnCandy::handleMustacheSpacing ( $token,
  $vars,
$context 
)
static

Internal method used by compileToken(). Modify $token when spacing rules matched.

Parameters
array<string>$token detected handlebars {{ }} token
array<array|string|integer>$vars parsed arguments list
array<string,array|string|integer>$context current compile context
Returns
string|null Return compiled code segment for the token
static LightnCandy::noNamedArguments (   $token,
$context,
  $named,
  $suggest = '!' 
)
static

Internal method used by compile(). Show error message when named arguments appear without custom helper.

Parameters
array<string>$token detected handlebars {{ }} token
array<string,array|string|integer>$context current compile context
boolean$namedis named arguments
string$suggestextended hint for this no named argument error
static LightnCandy::parseTokenArgs ( $token,
$context 
)
staticprotected

Internal method used by scanFeatures() and compile(). Parse the token and return parsed result.

Parameters
array<string>$token preg_match results
array<string,array|string|integer>$context current compile context
Returns
array<boolean|integer|array> Return parsed result

array(false, array(array())) when input array(0,0,0,0,0,0,''), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(true, array(array())) when input array(0,0,0,'{{{',0,0,''), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(true, array(array())) when input array(0,0,0,0,0,0,''), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 1), 'scan' => false, 'rawblock' => false) array(false, array(array('a'))) when input array(0,0,0,0,0,0,'a'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), array('b'))) when input array(0,0,0,0,0,0,'a b'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), array('"b'), array('c"'))) when input array(0,0,0,0,0,0,'a "b c"'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), array(0, '\'b c\''))) when input array(0,0,0,0,0,0,'a "b c"'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), array('[b'), array('c]'))) when input array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), array('[b'), array('c]'))) when input array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), array('b c'))) when input array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), array('b c'))) when input array(0,0,0,0,0,0,'a [b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), 'q' => array('b c'))) when input array(0,0,0,0,0,0,'a q=[b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), array('q=[b c'))) when input array(0,0,0,0,0,0,'a [q=[b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), 'q' => array('[b'), array('c]'))) when input array(0,0,0,0,0,0,'a q=[b c]'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), 'q' => array('b'), array('c'))) when input array(0,0,0,0,0,0,'a [q]=b c'), array('flags' => array('advar' => 0, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), 'q' => array(0, '\'b c\''))) when input array(0,0,0,0,0,0,'a q="b c"'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('(foo bar)'))) when input array(0,0,0,0,0,0,'(foo bar)'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0, 'exhlp' => 1), 'ops' => array('seperator' => ''), 'usedFeature' => array('subexp' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('foo'), array("'=='"), array('bar'))) when input array(0,0,0,0,0,0,"foo '==' bar"), array('flags' => array('advar' => 1, 'namev' => 1, 'noesc' => 0, 'this' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('( foo bar)'))) when input array(0,0,0,0,0,0,'( foo bar)'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0, 'exhlp' => 1), 'ops' => array('seperator' => ''), 'usedFeature' => array('subexp' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), array(0, '\' b c\''))) when input array(0,0,0,0,0,0,'a " b c"'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 0, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), 'q' => array(0, '\' b c\''))) when input array(0,0,0,0,0,0,'a q=" b c"'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('foo'), array(0, "' =='"), array('bar'))) when input array(0,0,0,0,0,0,"foo \' ==\' bar"), array('flags' => array('advar' => 1, 'namev' => 1, 'noesc' => 0, 'this' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), array(' b c'))) when input array(0,0,0,0,0,0,'a [ b c]'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array(array('a'), 'q' => array(0, "' d e'"))) when input array(0,0,0,0,0,0,"a q=\' d e\'"), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0), 'scan' => false, 'rawblock' => false) array(false, array('q' => array('( foo bar)'))) when input array(0,0,0,0,0,0,'q=( foo bar)'), array('flags' => array('advar' => 1, 'this' => 1, 'namev' => 1, 'noesc' => 0, 'exhlp' => 0), 'scan' => false, 'usedFeature' => array(), 'ops' => array('seperator' => 0), 'rawblock' => false)

static LightnCandy::prepare (   $php,
  $tmpDir = null,
  $delete = true 
)
static

Get a working render function by a string of PHP code. This method may requires php setting allow_url_include=1 and allow_url_fopen=1 , or access right to tmp file system.

Parameters
string$phpPHP code
string | null$tmpDirOptional, change temp directory for php include file saved by prepare() when cannot include PHP code with data:// format.
boolean$deleteOptional, delete temp php file when set to tru. Default is true, set it to false for debug propose
Returns
Closure|false result of include()
Deprecated:
static LightnCandy::prePartial (   $tmpl,
$name,
$context 
)
staticprotected

preprocess partial template before it be stored into context

Parameters
string$tmplpartial template
string$namepartial name
array<string,array|string|integer>$context Current context of compiler progress.
Returns
string|null $content processed partial template

'hey' when input 'hey', 'haha', Array('prepartial' => false) 'haha-hoho' when input 'hoho', 'haha', Array('prepartial' => function ($tmpl, $name) {return "$name-$tmpl";})

static LightnCandy::readPartial (   $name,
$context 
)
staticprotected

Read partial file content as string and store in context

Parameters
string$namepartial name
array<string,array|string|integer>$context Current context of compiler progress.
static LightnCandy::resolvePartial ( $name,
$context 
)
staticprotected

locate partial file, return the file name

Parameters
string$namepartial name
array<string,array|string|integer>$context Current context of compiler progress.
Returns
string|null $content partial content
static LightnCandy::scanFeatures (   $token,
$context 
)
staticprotected

Internal method used by compile(). Collect handlebars usage information, detect template error.

Parameters
string[]$token detected handlebars {{ }} token
array<string,array|string|integer>$context current compile context
static LightnCandy::scanLCRunDependency (   $context,
  $code 
)
staticprotected

Internal method used by compile(). Export required standalone functions.

Parameters
array<string,array|string|integer>$context current compile context
string$codePHP code string of the method
Returns
array<string|array> list of converted code and children array
static LightnCandy::setupToken ( $context,
  $left = '{{', $right = '}}' 
)
staticprotected

Setup token delimiter by default or provided string

Parameters
array<string,array|string|integer>$context Current context
string$leftleft string of a token
string$rightright string of a token
static LightnCandy::stripExtendedComments (   $template)
staticprotected

Strip extended comments {{!– .... –}}

Parameters
string$templatehandlebars template string
Returns
string Stripped template

'abc' when input 'abc' 'abc{{!}}cde' when input 'abc{{!}}cde' 'abc{{! }}cde' when input 'abc{{!-—}}cde'

static LightnCandy::tokenString (   $token,
  $remove = 2 
)
staticprotected

Internal method used by scanFeatures(). return token string

Parameters
string[]$token detected handlebars {{ }} token
integer$removeremove how many heading and ending token
Returns
string Return whole token

'b' when input array(0, 'a', 'b', 'c'), 1 'c' when input array(0, 'a', 'b', 'c', 'd', 'e')

static LightnCandy::validateOperations (   $token,
$context,
  $vars 
)
staticprotected

Internal method used by compile(). Collect handlebars usage information, detect template error.

Parameters
string[]$token detected handlebars {{ }} token
array<string,array|string|integer>$context current compile context
array<array>$vars parsed arguments list
Returns
boolean|integer|null Return true when invalid or detected

null when input array(0, 0, 0, 0, 0, ''), array(), array() 2 when input array(0, 0, 0, 0, 0, '^', '...'), array('usedFeature' => array('isec' => 1), 'level' => 0), array(array('foo')) 3 when input array(0, 0, 0, 0, 0, '!', '...'), array('usedFeature' => array('comment' => 2)), array() true when input array(0, 0, 0, 0, 0, '/'), array('stack' => array(1), 'level' => 1), array() 4 when input array(0, 0, 0, 0, 0, '#', '...'), array('usedFeature' => array('sec' => 3), 'level' => 0), array(array('x')) 5 when input array(0, 0, 0, 0, 0, '#', '...'), array('usedFeature' => array('if' => 4), 'level' => 0), array(array('if')) 6 when input array(0, 0, 0, 0, 0, '#', '...'), array('usedFeature' => array('with' => 5), 'level' => 0, 'flags' => array('with' => 1)), array(array('with')) 7 when input array(0, 0, 0, 0, 0, '#', '...'), array('usedFeature' => array('each' => 6), 'level' => 0), array(array('each')) 8 when input array(0, 0, 0, 0, 0, '#', '...'), array('usedFeature' => array('unless' => 7), 'level' => 0), array(array('unless')) 9 when input array(0, 0, 0, 0, 0, '#', '...'), array('blockhelpers' => array('abc' => ''), 'usedFeature' => array('bhelper' => 8), 'level' => 0), array(array('abc')) 10 when input array(0, 0, 0, 0, 0, ' ', '...'), array('usedFeature' => array('delimiter' => 9), 'level' => 0), array() 11 when input array(0, 0, 0, 0, 0, '#', '...'), array('hbhelpers' => array('abc' => ''), 'usedFeature' => array('hbhelper' => 10), 'level' => 0), array(array('abc')) true when input array(0, 0, 0, 0, 0, '>', '...'), array('basedir' => array('.'), 'fileext' => array('.tmpl'), 'usedFeature' => array('unless' => 7, 'partial' => 7), 'level' => 0, 'flags' => array('skippartial' => 0)), array('test')

static LightnCandy::validateStartEnd (   $token,
$context 
)
staticprotected

Internal method used by scanFeatures(). Validate start and and.

Parameters
string[]$token detected handlebars {{ }} token
array<string,array|string|integer>$context current compile context
Returns
boolean|null Return true when invalid

null when input array_fill(0, 9, ''), array() null when input array_fill(0, 9, '}}'), array() true when input array_fill(0, 9, '{{{'), array()

static LightnCandy::verifyTemplate ( $context,
  $template 
)
staticprotected

Verify template and scan for used features

Parameters
array<string,array|string|integer>$context Current context
string$templatehandlebars template

The documentation for this class was generated from the following file: