1 | <?php |
||
24 | class Partial |
||
25 | { |
||
26 | public static $TMP_JS_FUNCTION_STR = "!!\aFuNcTiOn\a!!"; |
||
27 | |||
28 | /** |
||
29 | * Include all partials when using dynamic partials |
||
30 | */ |
||
31 | 718 | public static function handleDynamic(&$context) |
|
41 | |||
42 | /** |
||
43 | * Read partial file content as string and store in context |
||
44 | * |
||
45 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
46 | * @param string $name partial name |
||
47 | * |
||
48 | * @return string|null $code compiled PHP code when success |
||
49 | */ |
||
50 | 108 | public static function read(&$context, $name) |
|
70 | |||
71 | /** |
||
72 | * preprocess partial template before it be stored into context |
||
73 | * |
||
74 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
75 | * @param string $tmpl partial template |
||
76 | * @param string $name partial name |
||
77 | * |
||
78 | * @return string|null $content processed partial template |
||
79 | * |
||
80 | * @expect 'hey' when input array('prepartial' => false), 'hey', 'haha' |
||
81 | * @expect 'haha-hoho' when input array('prepartial' => function ($cx, $tmpl, $name) {return "$name-$tmpl";}), 'hoho', 'haha' |
||
82 | */ |
||
83 | 92 | protected static function prePartial(&$context, $tmpl, &$name) |
|
87 | |||
88 | /** |
||
89 | * resolve partial, return the partial content |
||
90 | * |
||
91 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
92 | * @param string $name partial name |
||
93 | * |
||
94 | * @return string|null $content partial content |
||
95 | */ |
||
96 | 110 | public static function resolve(&$context, &$name) |
|
107 | |||
108 | /** |
||
109 | * use partialresolver to resolve partial, return the partial content |
||
110 | * |
||
111 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
112 | * @param string $name partial name |
||
113 | * |
||
114 | * @return string|null $content partial content |
||
115 | */ |
||
116 | 25 | public static function resolver(&$context, &$name) |
|
123 | |||
124 | /** |
||
125 | * compile a partial to static embed PHP code |
||
126 | * |
||
127 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
128 | * @param string $name partial name |
||
129 | * |
||
130 | * @return string|null $code PHP code string |
||
131 | */ |
||
132 | 9 | public static function compileStatic(&$context, $name) |
|
151 | |||
152 | /** |
||
153 | * compile partial as closure, stored in context |
||
154 | * |
||
155 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
156 | * @param string $name partial name |
||
157 | * |
||
158 | * @return string|null $code compiled PHP code when success |
||
159 | */ |
||
160 | 109 | public static function compileDynamic(&$context, $name) |
|
174 | |||
175 | /** |
||
176 | * compile a template into a closure function |
||
177 | * |
||
178 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
179 | * @param string $template template string |
||
180 | * @param string|integer $name partial name or 0 |
||
|
|||
181 | * |
||
182 | * @return string $code compiled PHP code |
||
183 | */ |
||
184 | 98 | public static function compile(&$context, $template, $name = 0) |
|
212 | } |
||
213 |