Overview

Namespaces

  • LightnCandy

Classes

  • Compiler
  • Context
  • Encoder
  • Exporter
  • Expression
  • Flags
  • LightnCandy
  • Parser
  • Partial
  • Runtime
  • SafeString
  • StringObject
  • Token
  • Validator
  • Overview
  • Namespace
  • Class

Class Runtime

LightnCandy class for compiled PHP runtime.

LightnCandy\Encoder
Extended by LightnCandy\Runtime
Namespace: LightnCandy
Located at Runtime.php
Methods summary
public static
# debug( string $v, string $f, array<string,array|string|integer> $cx )

Output debug info.

Output debug info.

Parameters

$v
expression
$f
runtime function name
$cx
render time context for lightncandy

Expect

'{{123}}' when input '123', 'miss', array('flags' => array('debug' => Runtime::DEBUG_TAGS), 'runtime' => 'LightnCandy\Runtime'), ''
'{{#123}}{{/123}}' when input '123', 'wi', array('flags' => array('debug' => Runtime::DEBUG_TAGS_HTML), 'runtime' => 'LightnCandy\Runtime'), false, null, false, function () {return 'A';}
public static
# err( array<string,array|string|integer> $cx, string $err )

Handle error by error_log or throw exception.

Handle error by error_log or throw exception.

Parameters

$cx
render time context for lightncandy
$err
error message

Throws

Exception
public static
# miss( array<string,array|string|integer> $cx, string $v )

Handle missing data error.

Handle missing data error.

Parameters

$cx
render time context for lightncandy
$v
expression
public static
# lo( array<string,array|string|integer> $cx, string $v )

For {{log}} .

For {{log}} .

Parameters

$cx
render time context for lightncandy
$v
expression
public static null|string
# v( array<string,array|string|integer> $cx, array|string|boolean|integer|float|null $in, array<array|string|integer> $base, array<string|integer> $path, array|null $args = null )

Resursive lookup variable and helpers. This is slow and will only be used for instance property or method detection or lambdas.

Resursive lookup variable and helpers. This is slow and will only be used for instance property or method detection or lambdas.

Parameters

$cx
render time context for lightncandy
$in
current context
$base
current variable context
$path
array of names for path
$args
extra arguments for lambda

Returns

null|string
Return the value or null when not found

Expect

null when input array('scopes' => array(), 'flags' => array('prop' => 0, 'method' => 0, 'mustlok' => 0)), null, 0, array('a', 'b')
3 when input array('scopes' => array(), 'flags' => array('prop' => 0, 'method' => 0), 'mustlok' => 0), null, array('a' => array('b' => 3)), array('a', 'b')
null when input array('scopes' => array(), 'flags' => array('prop' => 0, 'method' => 0, 'mustlok' => 0)), null, (Object) array('a' => array('b' => 3)), array('a', 'b')
3 when input array('scopes' => array(), 'flags' => array('prop' => 1, 'method' => 0, 'mustlok' => 0)), null, (Object) array('a' => array('b' => 3)), array('a', 'b')
public static boolean
# ifvar( array<string,array|string|integer> $cx, array<array|string|integer>|string|integer|null $v, boolean $zero )

For {{#if}} .

For {{#if}} .

Parameters

$cx
render time context for lightncandy
$v
value to be tested
$zero
include zero as true

Returns

boolean
Return true when the value is not null nor false.

Expect

false when input array(), null, false
false when input array(), 0, false
true when input array(), 0, true
false when input array(), false, false
true when input array(), true, false
true when input array(), 1, false
false when input array(), '', false
false when input array(), array(), false
true when input array(), array(''), false
true when input array(), array(0), false
public static boolean
# isec( array<string,array|string|integer> $cx, array<array|string|integer>|string|integer|null $v )

For {{^var}} .

For {{^var}} .

Parameters

$cx
render time context for lightncandy
$v
value to be tested

Returns

boolean
Return true when the value is not null nor false.

Expect

true when input array(), null
false when input array(), 0
true when input array(), false
false when input array(), 'false'
true when input array(), array()
false when input array(), array('1')
public static string
# enc( array<string,array|string|integer> $cx, array<array|string|integer>|string|integer|null $var )

For {{var}} .

For {{var}} .

Parameters

$cx
render time context for lightncandy
$var
value to be htmlencoded

Returns

string
The htmlencoded value of the specified variable

Expect

'a' when input array('flags' => array('mustlam' => 0, 'lambda' => 0)), 'a'
'a&b' when input array('flags' => array('mustlam' => 0, 'lambda' => 0)), 'a&b'
'a'b' when input array('flags' => array('mustlam' => 0, 'lambda' => 0)), 'a\'b'
'a&b' when input null, new \LightnCandy\SafeString('a&b')

Overrides

LightnCandy\Encoder::enc()
public static string
# encq( array<string,array|string|integer> $cx, array<array|string|integer>|string|integer|null $var )

For {{var}} , do html encode just like handlebars.js .

For {{var}} , do html encode just like handlebars.js .

Parameters

$cx
render time context for lightncandy
$var
value to be htmlencoded

Returns

string
The htmlencoded value of the specified variable

Expect

'a' when input array('flags' => array('mustlam' => 0, 'lambda' => 0)), 'a'
'a&b' when input array('flags' => array('mustlam' => 0, 'lambda' => 0)), 'a&b'
'a'b' when input array('flags' => array('mustlam' => 0, 'lambda' => 0)), 'a\'b'
'`a'b' when input array('flags' => array('mustlam' => 0, 'lambda' => 0)), '`a\'b'

Overrides

LightnCandy\Encoder::encq()
public static string
# sec( array<string,array|string|integer> $cx, array<array|string|integer>|string|integer|null $v, array<string>|null $bp, array<array|string|integer>|string|integer|null $in, boolean $each, Closure $cb, Closure|null $else = null )

For {{#var}} or {{#each}} .

For {{#var}} or {{#each}} .

Parameters

$cx
render time context for lightncandy
$v
value for the section
$bp
block parameters
$in
input data with current scope
$each
true when rendering #each
$cb
callback function to render child context
$else
callback function to render child context when {{else}}

Returns

string
The rendered string of the section

Expect

'' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), false, null, false, false, function () {return 'A';}
'' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), null, null, null, false, function () {return 'A';}
'A' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), true, null, true, false, function () {return 'A';}
'A' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), 0, null, 0, false, function () {return 'A';}
'-a=' when input array('scopes' => array(), 'flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), array('a'), null, array('a'), false, function ($c, $i) {return "-$i=";}
'-a=-b=' when input array('scopes' => array(), 'flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), array('a','b'), null, array('a','b'), false, function ($c, $i) {return "-$i=";}
'' when input array('scopes' => array(), 'flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), 'abc', null, 'abc', true, function ($c, $i) {return "-$i=";}
'-b=' when input array('scopes' => array(), 'flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), array('a' => 'b'), null, array('a' => 'b'), true, function ($c, $i) {return "-$i=";}
'b' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), 'b', null, 'b', false, function ($c, $i) {return print_r($i, true);}
'1' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), 1, null, 1, false, function ($c, $i) {return print_r($i, true);}
'0' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), 0, null, 0, false, function ($c, $i) {return print_r($i, true);}
'{"b":"c"}' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), array('b' => 'c'), null, array('b' => 'c'), false, function ($c, $i) {return json_encode($i);}
'inv' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), array(), null, 0, true, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';}
'inv' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), array(), null, 0, false, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';}
'inv' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), false, null, 0, true, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';}
'inv' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), false, null, 0, false, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';}
'inv' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), '', null, 0, true, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';}
'cb' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), '', null, 0, false, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';}
'inv' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), 0, null, 0, true, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';}
'cb' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), 0, null, 0, false, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';}
'inv' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), new stdClass, null, 0, true, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';}
'cb' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), new stdClass, null, 0, false, function ($c, $i) {return 'cb';}, function ($c, $i) {return 'inv';}
'268' when input array('scopes' => array(), 'flags' => array('spvar' => 1, 'mustlam' => 0, 'lambda' => 0), 'sp_vars'=>array('root' => 0)), array(1,3,4), null, 0, false, function ($c, $i) {return $i * 2;}
'038' when input array('scopes' => array(), 'flags' => array('spvar' => 1, 'mustlam' => 0, 'lambda' => 0), 'sp_vars'=>array('root' => 0)), array(1,3,'a'=>4), null, 0, true, function ($c, $i) {return $i * $c['sp_vars']['index'];}
public static string
# wi( array<string,array|string|integer> $cx, array<array|string|integer>|string|integer|null $v, array<array|string|integer>|string|integer|null $bp, array<string>|null $in, Closure $cb, Closure|null $else = null )

For {{#with}} .

For {{#with}} .

Parameters

$cx
render time context for lightncandy
$v
value to be the new context
$bp
$in input data with current scope
$in
$bp block parameters
$cb
callback function to render child context
$else
callback function to render child context when {{else}}

Returns

string
The rendered string of the token

Expect

'' when input array(), false, null, false, function () {return 'A';}
'' when input array(), null, null, null, function () {return 'A';}
'{"a":"b"}' when input array(), array('a'=>'b'), null, array('a'=>'c'), function ($c, $i) {return json_encode($i);}
'-b=' when input array(), 'b', null, array('a'=>'b'), function ($c, $i) {return "-$i=";}
public static array<array|string|integer>|string|integer
# m( array<string,array|string|integer> $cx, array<array|string|integer>|string|integer|null $a, array<array|string|integer>|string|integer|null $b )

Get merged context.

Get merged context.

Parameters

$cx
render time context for lightncandy
$a
the context to be merged
$b
the new context to overwrite

Returns

array<array|string|integer>|string|integer
the merged context object
public static string
# p( array<string,array|string|integer> $cx, string $p, array<array|string|integer>|string|integer|null $v, $pid, $sp = '' )

For {{> partial}} .

For {{> partial}} .

Parameters

$cx
render time context for lightncandy
$p
partial name
$v
value to be the new context
$pid
$sp

Returns

string
The rendered string of the partial
public static
# in( array<string,array|string|integer> & $cx, string $p, Closure $code )

For {{#* inlinepartial}} .

For {{#* inlinepartial}} .

Parameters

$cx
render time context for lightncandy
$p
partial name
$code
the compiled partial code
public static
# hbch( & $cx, $ch, $vars, $op, & $_this )
public static string
# hbbch( array<string,array|string|integer> & $cx, string $ch, array<array|string|integer>|string|integer|null $vars, array<string,array|string|integer> & $_this, boolean $inverted, Closure|null $cb, Closure|null $else = null )

For block custom helpers.

For block custom helpers.

Parameters

$cx
render time context for lightncandy
$ch
the name of custom helper to be executed
$vars
variables for the helper
$_this
current rendering context for the helper
$inverted
the logic will be inverted
$cb
callback function to render child context
$else
callback function to render child context when {{else}}

Returns

string
The rendered string of the token
public static string
# exch( array<string,array|string|integer> $cx, string $ch, array<array|string|integer>|string|integer|null $vars, array<string,array|string|integer> & $options )

Execute custom helper with prepared options

Execute custom helper with prepared options

Parameters

$cx
render time context for lightncandy
$ch
the name of custom helper to be executed
$vars
variables for the helper
$options
the options object

Returns

string
The rendered string of the token
Methods inherited from LightnCandy\Encoder
raw()
Constants summary
integer DEBUG_ERROR_LOG
# 1
integer DEBUG_ERROR_EXCEPTION
# 2
integer DEBUG_TAGS
# 4
integer DEBUG_TAGS_ANSI
# 12
integer DEBUG_TAGS_HTML
# 20
API documentation generated by ApiGen