1 | <?php |
||
25 | class Expression |
||
26 | { |
||
27 | /** |
||
28 | * return 'true' or 'false' string. |
||
29 | * |
||
30 | * @param integer $v value |
||
31 | * |
||
32 | * @return string 'true' when the value larger then 0 |
||
33 | * |
||
34 | * @expect 'true' when input 1 |
||
35 | * @expect 'true' when input 999 |
||
36 | * @expect 'false' when input 0 |
||
37 | * @expect 'false' when input -1 |
||
38 | */ |
||
39 | 718 | public static function boolString($v) |
|
43 | |||
44 | /** |
||
45 | * Get string presentation for a string list |
||
46 | * |
||
47 | * @param array<string> $list an array of strings. |
||
48 | * |
||
49 | * @return string PHP list string |
||
50 | * |
||
51 | * @expect '' when input array() |
||
52 | * @expect "'a'" when input array('a') |
||
53 | * @expect "'a','b','c'" when input array('a', 'b', 'c') |
||
54 | */ |
||
55 | 392 | public static function listString($list) |
|
61 | |||
62 | /** |
||
63 | * Get string presentation for an array |
||
64 | * |
||
65 | * @param array<string> $list an array of variable names. |
||
66 | * |
||
67 | * @return string PHP array names string |
||
68 | * |
||
69 | * @expect '' when input array() |
||
70 | * @expect "['a']" when input array('a') |
||
71 | * @expect "['a']['b']['c']" when input array('a', 'b', 'c') |
||
72 | */ |
||
73 | 139 | public static function arrayString($list) |
|
79 | |||
80 | /** |
||
81 | * Analyze an expression |
||
82 | * |
||
83 | * @param array<string,array|string|integer> $context Current context |
||
84 | * @param array<array|string|integer> $var variable parsed path |
||
85 | * |
||
86 | * @return array<integer|boolean|array> analyzed result |
||
87 | * |
||
88 | * @expect array(0, false, array('foo')) when input array('flags' => array('spvar' => 0)), array(0, 'foo') |
||
89 | * @expect array(1, false, array('foo')) when input array('flags' => array('spvar' => 0)), array(1, 'foo') |
||
90 | */ |
||
91 | 645 | public static function analyze($context, $var) |
|
115 | |||
116 | /** |
||
117 | * get normalized handlebars expression for a variable |
||
118 | * |
||
119 | * @param integer $levels trace N levels top parent scope |
||
120 | * @param boolean $spvar is the path start with @ or not |
||
121 | * @param array<string|integer> $var variable parsed path |
||
122 | * |
||
123 | * @return string normalized expression for debug display |
||
124 | * |
||
125 | * @expect '[a].[b]' when input 0, false, array('a', 'b') |
||
126 | * @expect '@[root]' when input 0, true, array('root') |
||
127 | * @expect 'this' when input 0, false, null |
||
128 | * @expect 'this.[id]' when input 0, false, array(null, 'id') |
||
129 | * @expect '@[root].[a].[b]' when input 0, true, array('root', 'a', 'b') |
||
130 | * @expect '../../[a].[b]' when input 2, false, array('a', 'b') |
||
131 | * @expect '../[a\'b]' when input 1, false, array('a\'b') |
||
132 | */ |
||
133 | 645 | public static function toString($levels, $spvar, $var) |
|
139 | } |
||
140 |