Documentation

Runtime extends Encoder
in package

LightnCandy class for compiled PHP runtime.

Table of Contents

DEBUG_ERROR_EXCEPTION  = 2
DEBUG_ERROR_LOG  = 1
DEBUG_TAGS  = 4
DEBUG_TAGS_ANSI  = 12
DEBUG_TAGS_HTML  = 20
debug()  : mixed
Output debug info.
enc()  : string
For {{var}} .
encq()  : string
For {{var}} , do html encode just like handlebars.js .
err()  : mixed
Handle error by error_log or throw exception.
exch()  : string
Execute custom helper with prepared options
hbbch()  : string
For block custom helpers.
hbch()  : mixed
ifvar()  : bool
For {{#if}} .
in()  : mixed
For {{#* inlinepartial}} .
isec()  : bool
For {{^var}} .
lo()  : mixed
For {{log}} .
m()  : array<string|int, array|string|int>|string|int
Get merged context.
miss()  : mixed
Handle missing data error.
p()  : string
For {{> partial}} .
raw()  : array<string|int, array|string|int>|string|int|null
Get string value
sec()  : string
For {{#var}} or {{#each}} .
v()  : null|string
Resursive lookup variable and helpers. This is slow and will only be used for instance property or method detection or lambdas.
wi()  : string
For {{#with}} .

Constants

DEBUG_ERROR_EXCEPTION

public mixed DEBUG_ERROR_EXCEPTION = 2

DEBUG_ERROR_LOG

public mixed DEBUG_ERROR_LOG = 1

DEBUG_TAGS

public mixed DEBUG_TAGS = 4

DEBUG_TAGS_ANSI

public mixed DEBUG_TAGS_ANSI = 12

DEBUG_TAGS_HTML

public mixed DEBUG_TAGS_HTML = 20

Methods

debug()

Output debug info.

public static debug(string $v, string $f, array<string, array|string|int> $cx) : mixed
Parameters
$v : string

expression

$f : string

runtime function name

$cx : array<string, array|string|int>

render time context for lightncandy

Tags
expect

'{{123}}' when input '123', 'miss', array('flags' => array('debug' => Runtime::DEBUG_TAGS), 'runtime' => 'LightnCandy\Runtime'), ''

expect

'{{#123}}{{/123}}' when input '123', 'wi', array('flags' => array('debug' => Runtime::DEBUG_TAGS_HTML), 'runtime' => 'LightnCandy\Runtime'), false, null, false, function () {return 'A';}

Return values
mixed

enc()

For {{var}} .

public static enc(array<string, array|string|int> $cx, array<string|int, array|string|int>|string|int|null $var) : string
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$var : array<string|int, array|string|int>|string|int|null

value to be htmlencoded

Tags
expect

'a' when input array('flags' => array('mustlam' => 0, 'lambda' => 0)), 'a'

expect

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

expect

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

expect

'a&b' when input null, new \LightnCandy\SafeString('a&b')

Return values
string

The htmlencoded value of the specified variable

encq()

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

public static encq(array<string, array|string|int> $cx, array<string|int, array|string|int>|string|int|null $var) : string
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$var : array<string|int, array|string|int>|string|int|null

value to be htmlencoded

Tags
expect

'a' when input array('flags' => array('mustlam' => 0, 'lambda' => 0)), 'a'

expect

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

expect

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

expect

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

Return values
string

The htmlencoded value of the specified variable

err()

Handle error by error_log or throw exception.

public static err(array<string, array|string|int> $cx, string $err) : mixed
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$err : string

error message

Tags
throws
Exception
Return values
mixed

exch()

Execute custom helper with prepared options

public static exch(array<string, array|string|int> $cx, string $ch, array<string|int, array|string|int>|string|int|null $vars, array<string, array|string|int> &$options) : string
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$ch : string

the name of custom helper to be executed

$vars : array<string|int, array|string|int>|string|int|null

variables for the helper

$options : array<string, array|string|int>

the options object

Return values
string

The rendered string of the token

hbbch()

For block custom helpers.

public static hbbch(array<string, array|string|int> &$cx, string $ch, array<string|int, array|string|int>|string|int|null $vars, array<string, array|string|int> &$_this, bool $inverted, Closure|null $cb[, Closure|null $else = null ]) : string
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$ch : string

the name of custom helper to be executed

$vars : array<string|int, array|string|int>|string|int|null

variables for the helper

$_this : array<string, array|string|int>

current rendering context for the helper

$inverted : bool

the logic will be inverted

$cb : Closure|null

callback function to render child context

$else : Closure|null = null

callback function to render child context when {{else}}

Return values
string

The rendered string of the token

hbch()

public static hbch(mixed &$cx, mixed $ch, mixed $vars, mixed $op, mixed &$_this) : mixed
Parameters
$cx : mixed
$ch : mixed
$vars : mixed
$op : mixed
$_this : mixed
Return values
mixed

ifvar()

For {{#if}} .

public static ifvar(array<string, array|string|int> $cx, array<string|int, array|string|int>|string|int|null $v, bool $zero) : bool
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$v : array<string|int, array|string|int>|string|int|null

value to be tested

$zero : bool

include zero as true

Tags
expect

false when input array(), null, false

expect

false when input array(), 0, false

expect

true when input array(), 0, true

expect

false when input array(), false, false

expect

true when input array(), true, false

expect

true when input array(), 1, false

expect

false when input array(), '', false

expect

false when input array(), array(), false

expect

true when input array(), array(''), false

expect

true when input array(), array(0), false

Return values
bool

Return true when the value is not null nor false.

in()

For {{#* inlinepartial}} .

public static in(array<string, array|string|int> &$cx, string $p, Closure $code) : mixed
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$p : string

partial name

$code : Closure

the compiled partial code

Return values
mixed

isec()

For {{^var}} .

public static isec(array<string, array|string|int> $cx, array<string|int, array|string|int>|string|int|null $v) : bool
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$v : array<string|int, array|string|int>|string|int|null

value to be tested

Tags
expect

true when input array(), null

expect

false when input array(), 0

expect

true when input array(), false

expect

false when input array(), 'false'

expect

true when input array(), array()

expect

false when input array(), array('1')

Return values
bool

Return true when the value is not null nor false.

lo()

For {{log}} .

public static lo(array<string, array|string|int> $cx, string $v) : mixed
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$v : string

expression

Return values
mixed

m()

Get merged context.

public static m(array<string, array|string|int> $cx, array<string|int, array|string|int>|string|int|null $a, array<string|int, array|string|int>|string|int|null $b) : array<string|int, array|string|int>|string|int
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$a : array<string|int, array|string|int>|string|int|null

the context to be merged

$b : array<string|int, array|string|int>|string|int|null

the new context to overwrite

Return values
array<string|int, array|string|int>|string|int

the merged context object

miss()

Handle missing data error.

public static miss(array<string, array|string|int> $cx, string $v) : mixed
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$v : string

expression

Return values
mixed

p()

For {{> partial}} .

public static p(array<string, array|string|int> $cx, string $p, array<string|int, array|string|int>|string|int|null $v, mixed $pid[, mixed $sp = '' ]) : string
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$p : string

partial name

$v : array<string|int, array|string|int>|string|int|null

value to be the new context

$pid : mixed
$sp : mixed = ''
Return values
string

The rendered string of the partial

raw()

Get string value

public static raw(array<string, array|string|int> $cx, array<string|int, array|string|int>|string|int|null $v, int $ex) : array<string|int, array|string|int>|string|int|null
Parameters
$cx : array<string, array|string|int>

render time context

$v : array<string|int, array|string|int>|string|int|null

value to be output

$ex : int

1 to return untouched value, default is 0

Tags
expect

true when input array('flags' => array('jstrue' => 0, 'mustlam' => 0, 'lambda' => 0)), true

expect

'true' when input array('flags' => array('jstrue' => 1)), true

expect

'' when input array('flags' => array('jstrue' => 0, 'mustlam' => 0, 'lambda' => 0)), false

expect

'false' when input array('flags' => array('jstrue' => 1)), false

expect

false when input array('flags' => array('jstrue' => 1)), false, true

expect

'Array' when input array('flags' => array('jstrue' => 1, 'jsobj' => 0)), array('a', 'b')

expect

'a,b' when input array('flags' => array('jstrue' => 1, 'jsobj' => 1, 'mustlam' => 0, 'lambda' => 0)), array('a', 'b')

expect

'[object Object]' when input array('flags' => array('jstrue' => 1, 'jsobj' => 1)), array('a', 'c' => 'b')

expect

'[object Object]' when input array('flags' => array('jstrue' => 1, 'jsobj' => 1)), array('c' => 'b')

expect

'a,true' when input array('flags' => array('jstrue' => 1, 'jsobj' => 1, 'mustlam' => 0, 'lambda' => 0)), array('a', true)

expect

'a,1' when input array('flags' => array('jstrue' => 0, 'jsobj' => 1, 'mustlam' => 0, 'lambda' => 0)), array('a',true)

expect

'a,' when input array('flags' => array('jstrue' => 0, 'jsobj' => 1, 'mustlam' => 0, 'lambda' => 0)), array('a',false)

expect

'a,false' when input array('flags' => array('jstrue' => 1, 'jsobj' => 1, 'mustlam' => 0, 'lambda' => 0)), array('a',false)

Return values
array<string|int, array|string|int>|string|int|null

The raw value of the specified variable

sec()

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

public static sec(array<string, array|string|int> $cx, array<string|int, array|string|int>|string|int|null $v, array<string|int, string>|null $bp, array<string|int, array|string|int>|string|int|null $in, bool $each, Closure $cb[, Closure|null $else = null ]) : string
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$v : array<string|int, array|string|int>|string|int|null

value for the section

$bp : array<string|int, string>|null

block parameters

$in : array<string|int, array|string|int>|string|int|null

input data with current scope

$each : bool

true when rendering #each

$cb : Closure

callback function to render child context

$else : Closure|null = null

callback function to render child context when {{else}}

Tags
expect

'' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), false, null, false, false, function () {return 'A';}

expect

'' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), null, null, null, false, function () {return 'A';}

expect

'A' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), true, null, true, false, function () {return 'A';}

expect

'A' when input array('flags' => array('spvar' => 0, 'mustlam' => 0, 'mustsec' => 0, 'lambda' => 0)), 0, null, 0, false, function () {return 'A';}

expect

'-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=";}

expect

'-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=";}

expect

'' when input array('scopes' => array(), 'flags' => array('spvar' => 0, 'mustlam' => 0, 'lambda' => 0)), 'abc', null, 'abc', true, function ($c, $i) {return "-$i=";}

expect

'-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=";}

expect

'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);}

expect

'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);}

expect

'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);}

expect

'{"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);}

expect

'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';}

expect

'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';}

expect

'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';}

expect

'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';}

expect

'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';}

expect

'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';}

expect

'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';}

expect

'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';}

expect

'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';}

expect

'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';}

expect

'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;}

expect

'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'];}

Return values
string

The rendered string of the section

v()

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

public static v(array<string, array|string|int> $cx, array<string|int, mixed>|string|bool|int|float|null $in, array<string|int, array|string|int> $base, array<string|int, string|int> $path[, array<string|int, mixed>|null $args = null ]) : null|string
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$in : array<string|int, mixed>|string|bool|int|float|null

current context

$base : array<string|int, array|string|int>

current variable context

$path : array<string|int, string|int>

array of names for path

$args : array<string|int, mixed>|null = null

extra arguments for lambda

Tags
expect

null when input array('scopes' => array(), 'flags' => array('prop' => 0, 'method' => 0, 'mustlok' => 0)), null, 0, array('a', 'b')

expect

3 when input array('scopes' => array(), 'flags' => array('prop' => 0, 'method' => 0), 'mustlok' => 0), null, array('a' => array('b' => 3)), array('a', 'b')

expect

null when input array('scopes' => array(), 'flags' => array('prop' => 0, 'method' => 0, 'mustlok' => 0)), null, (Object) array('a' => array('b' => 3)), array('a', 'b')

expect

3 when input array('scopes' => array(), 'flags' => array('prop' => 1, 'method' => 0, 'mustlok' => 0)), null, (Object) array('a' => array('b' => 3)), array('a', 'b')

Return values
null|string

Return the value or null when not found

wi()

For {{#with}} .

public static wi(array<string, array|string|int> $cx, array<string|int, array|string|int>|string|int|null $v, array<string|int, string>|null $bp, array<string|int, array|string|int>|string|int|null $in, Closure $cb[, Closure|null $else = null ]) : string
Parameters
$cx : array<string, array|string|int>

render time context for lightncandy

$v : array<string|int, array|string|int>|string|int|null

value to be the new context

$bp : array<string|int, string>|null

block parameters

$in : array<string|int, array|string|int>|string|int|null

input data with current scope

$cb : Closure

callback function to render child context

$else : Closure|null = null

callback function to render child context when {{else}}

Tags
expect

'' when input array(), false, null, false, function () {return 'A';}

expect

'' when input array(), null, null, null, function () {return 'A';}

expect

'{"a":"b"}' when input array(), array('a'=>'b'), null, array('a'=>'c'), function ($c, $i) {return json_encode($i);}

expect

'-b=' when input array(), 'b', null, array('a'=>'b'), function ($c, $i) {return "-$i=";}

Return values
string

The rendered string of the token

Search results