1 | <?php |
||
30 | class Partial |
||
31 | { |
||
32 | public static $TMP_JS_FUNCTION_STR = "!!\aFuNcTiOn\a!!"; |
||
33 | |||
34 | /** |
||
35 | * Include all partials when using dynamic partials |
||
36 | */ |
||
37 | 650 | public static function handleDynamic(&$context) { |
|
46 | |||
47 | /** |
||
48 | * Read partial file content as string and store in context |
||
49 | * |
||
50 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
51 | * @param string $name partial name |
||
52 | * |
||
53 | * @return string|null $code compiled PHP code when success |
||
54 | */ |
||
55 | 89 | public static function read(&$context, $name) { |
|
73 | |||
74 | /** |
||
75 | * preprocess partial template before it be stored into context |
||
76 | * |
||
77 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
78 | * @param string $tmpl partial template |
||
79 | * @param string $name partial name |
||
80 | * |
||
81 | * @return string|null $content processed partial template |
||
82 | * |
||
83 | * @expect 'hey' when input Array('prepartial' => false), 'hey', 'haha' |
||
84 | * @expect 'haha-hoho' when input Array('prepartial' => function ($cx, $tmpl, $name) {return "$name-$tmpl";}), 'hoho', 'haha' |
||
85 | */ |
||
86 | 78 | protected static function prePartial(&$context, $tmpl, &$name) { |
|
89 | |||
90 | /** |
||
91 | * resolve partial, return the partial content |
||
92 | * |
||
93 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
94 | * @param string $name partial name |
||
95 | * |
||
96 | * @return string|null $content partial content |
||
97 | */ |
||
98 | 87 | public static function resolve(&$context, &$name) { |
|
105 | |||
106 | /** |
||
107 | * use partialresolver to resolve partial, return the partial content |
||
108 | * |
||
109 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
110 | * @param string $name partial name |
||
111 | * |
||
112 | * @return string|null $content partial content |
||
113 | */ |
||
114 | 12 | public static function resolver(&$context, &$name) { |
|
120 | |||
121 | /** |
||
122 | * compile a partial to static embed PHP code |
||
123 | * |
||
124 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
125 | * @param string $name partial name |
||
126 | * |
||
127 | * @return string|null $code PHP code string |
||
128 | */ |
||
129 | 9 | public static function compileStatic(&$context, $name) { |
|
147 | |||
148 | /** |
||
149 | * compile partial as closure, stored in context |
||
150 | * |
||
151 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
152 | * @param string $name partial name |
||
153 | * |
||
154 | * @return string|null $code compiled PHP code when success |
||
155 | */ |
||
156 | 89 | public static function compileDynamic(&$context, $name) { |
|
169 | |||
170 | /** |
||
171 | * compile a template into a closure function |
||
172 | * |
||
173 | * @param array<string,array|string|integer> $context Current context of compiler progress. |
||
174 | * @param string $template template string |
||
175 | * |
||
176 | * @return string $code compiled PHP code |
||
177 | */ |
||
178 | 78 | public static function compile(&$context, $template) { |
|
195 | } |
||
196 | |||
197 |