Documentation

SafeString extends Encoder
in package

LightnCandy SafeString class

Table of Contents

EXTENDED_COMMENT_SEARCH  = '/{{!--.*?--}}/s'
IS_BLOCKPARAM_SEARCH  = '/^ +\|(.+)\|$/s'
IS_SUBEXP_SEARCH  = '/^\(.+\)$/s'
$jsContext  : mixed
$string  : mixed
__construct()  : mixed
Constructor
__toString()  : mixed
enc()  : string
Get html encoded string
encq()  : string
LightnCandy runtime method for {{var}} , and deal with single quote to same as handlebars.js .
escapeTemplate()  : string
Escape template
raw()  : array<string|int, array|string|int>|string|int|null
Get string value
stripExtendedComments()  : string
Strip extended comments {{!-- .... --}}

Constants

public mixed EXTENDED_COMMENT_SEARCH = '/{{!--.*?--}}/s'
public mixed IS_BLOCKPARAM_SEARCH = '/^ +\|(.+)\|$/s'
public mixed IS_SUBEXP_SEARCH = '/^\(.+\)$/s'

Properties

$jsContext

public static mixed $jsContext = array('flags' => array('jstrue' => 1, 'jsobj' => 1))

Methods

__construct()

Constructor

public __construct(string $str[, bool|string $escape = false ]) : mixed
Parameters
$str : string

input string

$escape : bool|string = false

false to not escape, true to escape, 'encq' to escape as handlebars.js

Return values
mixed

__toString()

public __toString() : mixed
Return values
mixed

enc()

Get html encoded string

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

$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'

Return values
string

The htmlencoded value of the specified variable

encq()

LightnCandy runtime method for {{var}} , and deal with single quote to same as 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

$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

escapeTemplate()

Escape template

public static escapeTemplate(string $template) : string
Parameters
$template : string

handlebars template string

Tags
expect

'abc' when input 'abc'

expect

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

expect

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

Return values
string

Escaped template

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

stripExtendedComments()

Strip extended comments {{!-- .... --}}

public static stripExtendedComments(string $template) : string
Parameters
$template : string

handlebars template string

Tags
expect

'abc' when input 'abc'

expect

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

expect

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

Return values
string

Stripped template

Search results