1
2 #ifdef HAVE_CONFIG_H
3 #include "../../../../../ext_config.h"
4 #endif
5
6 #include <php.h>
7 #include "../../../../../php_ext.h"
8 #include "../../../../../ext.h"
9
10 #include <Zend/zend_operators.h>
11 #include <Zend/zend_exceptions.h>
12 #include <Zend/zend_interfaces.h>
13
14 #include "kernel/main.h"
15 #include "kernel/object.h"
16 #include "kernel/memory.h"
17 #include "ext/spl/spl_exceptions.h"
18 #include "kernel/exception.h"
19 #include "kernel/operators.h"
20 #include "kernel/array.h"
21 #include "kernel/fcall.h"
22 #include "kernel/file.h"
23 #include "Zend/zend_closures.h"
24 #include "kernel/concat.h"
25 #include "kernel/string.h"
26 #include "phalcon/mvc/view/engine/volt/scanner.h"
27 #include "phalcon/mvc/view/engine/volt/volt.h"
28
29
30 /**
31 * Phalcon\Mvc\View\Engine\Volt\Compiler
32 *
33 * This class reads and compiles Volt templates into PHP plain code
34 *
35 *<code>
36 * $compiler = new \Phalcon\Mvc\View\Engine\Volt\Compiler();
37 *
38 * $compiler->compile("views/partials/header.volt");
39 *
40 * require $compiler->getCompiledTemplatePath();
41 *</code>
42 */
ZEPHIR_INIT_CLASS(Phalcon_Mvc_View_Engine_Volt_Compiler)43 ZEPHIR_INIT_CLASS(Phalcon_Mvc_View_Engine_Volt_Compiler) {
44
45 ZEPHIR_REGISTER_CLASS(Phalcon\\Mvc\\View\\Engine\\Volt, Compiler, phalcon, mvc_view_engine_volt_compiler, phalcon_mvc_view_engine_volt_compiler_method_entry, 0);
46
47 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC);
48
49 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_view"), ZEND_ACC_PROTECTED TSRMLS_CC);
50
51 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC);
52
53 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_arrayHelpers"), ZEND_ACC_PROTECTED TSRMLS_CC);
54
55 zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_level"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
56
57 zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_foreachLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
58
59 zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_blockLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
60
61 zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_exprLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
62
63 zend_declare_property_bool(phalcon_mvc_view_engine_volt_compiler_ce, SL("_extended"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
64
65 zend_declare_property_bool(phalcon_mvc_view_engine_volt_compiler_ce, SL("_autoescape"), 0, ZEND_ACC_PROTECTED TSRMLS_CC);
66
67 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_extendedBlocks"), ZEND_ACC_PROTECTED TSRMLS_CC);
68
69 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_currentBlock"), ZEND_ACC_PROTECTED TSRMLS_CC);
70
71 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_blocks"), ZEND_ACC_PROTECTED TSRMLS_CC);
72
73 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_forElsePointers"), ZEND_ACC_PROTECTED TSRMLS_CC);
74
75 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_loopPointers"), ZEND_ACC_PROTECTED TSRMLS_CC);
76
77 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_extensions"), ZEND_ACC_PROTECTED TSRMLS_CC);
78
79 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_functions"), ZEND_ACC_PROTECTED TSRMLS_CC);
80
81 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC);
82
83 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_macros"), ZEND_ACC_PROTECTED TSRMLS_CC);
84
85 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_prefix"), ZEND_ACC_PROTECTED TSRMLS_CC);
86
87 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_currentPath"), ZEND_ACC_PROTECTED TSRMLS_CC);
88
89 zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_compiledTemplatePath"), ZEND_ACC_PROTECTED TSRMLS_CC);
90
91 zend_class_implements(phalcon_mvc_view_engine_volt_compiler_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce);
92 return SUCCESS;
93
94 }
95
96 /**
97 * Phalcon\Mvc\View\Engine\Volt\Compiler
98 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,__construct)99 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, __construct) {
100
101 zval *view = NULL;
102
103 zephir_fetch_params(0, 0, 1, &view);
104
105 if (!view) {
106 view = ZEPHIR_GLOBAL(global_null);
107 }
108
109
110 if (Z_TYPE_P(view) == IS_OBJECT) {
111 zephir_update_property_this(getThis(), SL("_view"), view TSRMLS_CC);
112 }
113
114 }
115
116 /**
117 * Sets the dependency injector
118 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,setDI)119 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setDI) {
120
121 zval *dependencyInjector;
122
123 zephir_fetch_params(0, 1, 0, &dependencyInjector);
124
125
126
127 zephir_update_property_this(getThis(), SL("_dependencyInjector"), dependencyInjector TSRMLS_CC);
128
129 }
130
131 /**
132 * Returns the internal dependency injector
133 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,getDI)134 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getDI) {
135
136
137
138 RETURN_MEMBER(getThis(), "_dependencyInjector");
139
140 }
141
142 /**
143 * Sets the compiler options
144 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,setOptions)145 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setOptions) {
146
147 zval *options_param = NULL;
148 zval *options = NULL;
149
150 zephir_fetch_params(0, 1, 0, &options_param);
151
152 options = options_param;
153
154
155 zephir_update_property_this(getThis(), SL("_options"), options TSRMLS_CC);
156
157 }
158
159 /**
160 * Sets a single compiler option
161 *
162 * @param string option
163 * @param mixed value
164 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,setOption)165 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setOption) {
166
167 zval *option_param = NULL, *value;
168 zval *option = NULL;
169
170 ZEPHIR_MM_GROW();
171 zephir_fetch_params(1, 2, 0, &option_param, &value);
172
173 if (UNEXPECTED(Z_TYPE_P(option_param) != IS_STRING && Z_TYPE_P(option_param) != IS_NULL)) {
174 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'option' must be a string") TSRMLS_CC);
175 RETURN_MM_NULL();
176 }
177 if (EXPECTED(Z_TYPE_P(option_param) == IS_STRING)) {
178 zephir_get_strval(option, option_param);
179 } else {
180 ZEPHIR_INIT_VAR(option);
181 ZVAL_EMPTY_STRING(option);
182 }
183
184
185 zephir_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC);
186 ZEPHIR_MM_RESTORE();
187
188 }
189
190 /**
191 * Returns a compiler's option
192 *
193 * @param string option
194 * @return string
195 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,getOption)196 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getOption) {
197
198 zval *option_param = NULL, *value = NULL, *_0;
199 zval *option = NULL;
200
201 ZEPHIR_MM_GROW();
202 zephir_fetch_params(1, 1, 0, &option_param);
203
204 if (UNEXPECTED(Z_TYPE_P(option_param) != IS_STRING && Z_TYPE_P(option_param) != IS_NULL)) {
205 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'option' must be a string") TSRMLS_CC);
206 RETURN_MM_NULL();
207 }
208 if (EXPECTED(Z_TYPE_P(option_param) == IS_STRING)) {
209 zephir_get_strval(option, option_param);
210 } else {
211 ZEPHIR_INIT_VAR(option);
212 ZVAL_EMPTY_STRING(option);
213 }
214
215
216 _0 = zephir_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY_CC);
217 if (zephir_array_isset_fetch(&value, _0, option, 1 TSRMLS_CC)) {
218 RETURN_CTOR(value);
219 }
220 RETURN_MM_NULL();
221
222 }
223
224 /**
225 * Returns the compiler options
226 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,getOptions)227 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getOptions) {
228
229
230
231 RETURN_MEMBER(getThis(), "_options");
232
233 }
234
235 /**
236 * Fires an event to registered extensions
237 *
238 * @param string name
239 * @param array arguments
240 * @return mixed
241 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,fireExtensionEvent)242 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, fireExtensionEvent) {
243
244 zval *_3$$6 = NULL, *_4$$7 = NULL;
245 HashTable *_1$$3;
246 HashPosition _0$$3;
247 zend_long ZEPHIR_LAST_CALL_STATUS;
248 zval *name_param = NULL, *arguments = NULL, *extensions = NULL, *extension = NULL, *status = NULL, **_2$$3;
249 zval *name = NULL;
250
251 ZEPHIR_MM_GROW();
252 zephir_fetch_params(1, 1, 1, &name_param, &arguments);
253
254 if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
255 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be a string") TSRMLS_CC);
256 RETURN_MM_NULL();
257 }
258 if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
259 zephir_get_strval(name, name_param);
260 } else {
261 ZEPHIR_INIT_VAR(name);
262 ZVAL_EMPTY_STRING(name);
263 }
264 if (!arguments) {
265 arguments = ZEPHIR_GLOBAL(global_null);
266 }
267
268
269 ZEPHIR_OBS_VAR(extensions);
270 zephir_read_property_this(&extensions, this_ptr, SL("_extensions"), PH_NOISY_CC);
271 if (Z_TYPE_P(extensions) == IS_ARRAY) {
272 zephir_is_iterable(extensions, &_1$$3, &_0$$3, 0, 0, "phalcon/mvc/view/engine/volt/compiler.zep", 189);
273 for (
274 ; zend_hash_get_current_data_ex(_1$$3, (void**) &_2$$3, &_0$$3) == SUCCESS
275 ; zend_hash_move_forward_ex(_1$$3, &_0$$3)
276 ) {
277 ZEPHIR_GET_HVALUE(extension, _2$$3);
278 if ((zephir_method_exists(extension, name TSRMLS_CC) == SUCCESS)) {
279 if (Z_TYPE_P(arguments) == IS_ARRAY) {
280 ZEPHIR_INIT_NVAR(_3$$6);
281 zephir_create_array(_3$$6, 2, 0 TSRMLS_CC);
282 zephir_array_fast_append(_3$$6, extension);
283 zephir_array_fast_append(_3$$6, name);
284 ZEPHIR_INIT_NVAR(status);
285 ZEPHIR_CALL_USER_FUNC_ARRAY(status, _3$$6, arguments);
286 zephir_check_call_status();
287 } else {
288 ZEPHIR_INIT_NVAR(_4$$7);
289 zephir_create_array(_4$$7, 2, 0 TSRMLS_CC);
290 zephir_array_fast_append(_4$$7, extension);
291 zephir_array_fast_append(_4$$7, name);
292 ZEPHIR_INIT_NVAR(status);
293 ZEPHIR_CALL_USER_FUNC(status, _4$$7);
294 zephir_check_call_status();
295 }
296 if (Z_TYPE_P(status) == IS_STRING) {
297 RETURN_CCTOR(status);
298 }
299 }
300 }
301 }
302 ZEPHIR_MM_RESTORE();
303
304 }
305
306 /**
307 * Registers a Volt's extension
308 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,addExtension)309 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addExtension) {
310
311 zend_long ZEPHIR_LAST_CALL_STATUS;
312 zval *extension;
313
314 ZEPHIR_MM_GROW();
315 zephir_fetch_params(1, 1, 0, &extension);
316
317
318
319 if (Z_TYPE_P(extension) != IS_OBJECT) {
320 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "The extension is not valid", "phalcon/mvc/view/engine/volt/compiler.zep", 198);
321 return;
322 }
323 if ((zephir_method_exists_ex(extension, SS("initialize") TSRMLS_CC) == SUCCESS)) {
324 ZEPHIR_CALL_METHOD(NULL, extension, "initialize", NULL, 0, this_ptr);
325 zephir_check_call_status();
326 }
327 zephir_update_property_array_append(this_ptr, SL("_extensions"), extension TSRMLS_CC);
328 RETURN_THIS();
329
330 }
331
332 /**
333 * Returns the list of extensions registered in Volt
334 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,getExtensions)335 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getExtensions) {
336
337
338
339 RETURN_MEMBER(getThis(), "_extensions");
340
341 }
342
343 /**
344 * Register a new function in the compiler
345 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,addFunction)346 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addFunction) {
347
348 zval *name_param = NULL, *definition;
349 zval *name = NULL;
350
351 ZEPHIR_MM_GROW();
352 zephir_fetch_params(1, 2, 0, &name_param, &definition);
353
354 if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
355 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be a string") TSRMLS_CC);
356 RETURN_MM_NULL();
357 }
358 if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
359 zephir_get_strval(name, name_param);
360 } else {
361 ZEPHIR_INIT_VAR(name);
362 ZVAL_EMPTY_STRING(name);
363 }
364
365
366 zephir_update_property_array(this_ptr, SL("_functions"), name, definition TSRMLS_CC);
367 RETURN_THIS();
368
369 }
370
371 /**
372 * Register the user registered functions
373 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,getFunctions)374 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getFunctions) {
375
376
377
378 RETURN_MEMBER(getThis(), "_functions");
379
380 }
381
382 /**
383 * Register a new filter in the compiler
384 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,addFilter)385 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addFilter) {
386
387 zval *name_param = NULL, *definition;
388 zval *name = NULL;
389
390 ZEPHIR_MM_GROW();
391 zephir_fetch_params(1, 2, 0, &name_param, &definition);
392
393 if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
394 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be a string") TSRMLS_CC);
395 RETURN_MM_NULL();
396 }
397 if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
398 zephir_get_strval(name, name_param);
399 } else {
400 ZEPHIR_INIT_VAR(name);
401 ZVAL_EMPTY_STRING(name);
402 }
403
404
405 zephir_update_property_array(this_ptr, SL("_filters"), name, definition TSRMLS_CC);
406 RETURN_THIS();
407
408 }
409
410 /**
411 * Register the user registered filters
412 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,getFilters)413 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getFilters) {
414
415
416
417 RETURN_MEMBER(getThis(), "_filters");
418
419 }
420
421 /**
422 * Set a unique prefix to be used as prefix for compiled variables
423 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,setUniquePrefix)424 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setUniquePrefix) {
425
426 zval *prefix_param = NULL;
427 zval *prefix = NULL;
428
429 ZEPHIR_MM_GROW();
430 zephir_fetch_params(1, 1, 0, &prefix_param);
431
432 if (UNEXPECTED(Z_TYPE_P(prefix_param) != IS_STRING && Z_TYPE_P(prefix_param) != IS_NULL)) {
433 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'prefix' must be a string") TSRMLS_CC);
434 RETURN_MM_NULL();
435 }
436 if (EXPECTED(Z_TYPE_P(prefix_param) == IS_STRING)) {
437 zephir_get_strval(prefix, prefix_param);
438 } else {
439 ZEPHIR_INIT_VAR(prefix);
440 ZVAL_EMPTY_STRING(prefix);
441 }
442
443
444 zephir_update_property_this(getThis(), SL("_prefix"), prefix TSRMLS_CC);
445 RETURN_THIS();
446
447 }
448
449 /**
450 * Return a unique prefix to be used as prefix for compiled variables and contexts
451 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,getUniquePrefix)452 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getUniquePrefix) {
453
454 zval *_7$$5;
455 zval *_0, *_3, *_8, *_1$$3, *_2$$3, *_4$$4, *_5$$5, *_6$$5;
456 zend_long ZEPHIR_LAST_CALL_STATUS;
457
458 ZEPHIR_MM_GROW();
459
460 _0 = zephir_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY_CC);
461 if (!(zephir_is_true(_0))) {
462 ZEPHIR_INIT_VAR(_1$$3);
463 _2$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_currentPath"), PH_NOISY_CC);
464 zephir_unique_path_key(_1$$3, _2$$3 TSRMLS_CC);
465 zephir_update_property_this(getThis(), SL("_prefix"), _1$$3 TSRMLS_CC);
466 }
467 ZEPHIR_OBS_VAR(_3);
468 zephir_read_property_this(&_3, this_ptr, SL("_prefix"), PH_NOISY_CC);
469 if (Z_TYPE_P(_3) == IS_OBJECT) {
470 ZEPHIR_OBS_VAR(_4$$4);
471 zephir_read_property_this(&_4$$4, this_ptr, SL("_prefix"), PH_NOISY_CC);
472 if (zephir_instance_of_ev(_4$$4, zend_ce_closure TSRMLS_CC)) {
473 ZEPHIR_INIT_VAR(_5$$5);
474 _6$$5 = zephir_fetch_nproperty_this(this_ptr, SL("_prefix"), PH_NOISY_CC);
475 ZEPHIR_INIT_VAR(_7$$5);
476 zephir_create_array(_7$$5, 1, 0 TSRMLS_CC);
477 zephir_array_fast_append(_7$$5, this_ptr);
478 ZEPHIR_CALL_USER_FUNC_ARRAY(_5$$5, _6$$5, _7$$5);
479 zephir_check_call_status();
480 zephir_update_property_this(getThis(), SL("_prefix"), _5$$5 TSRMLS_CC);
481 }
482 }
483 ZEPHIR_OBS_VAR(_8);
484 zephir_read_property_this(&_8, this_ptr, SL("_prefix"), PH_NOISY_CC);
485 if (Z_TYPE_P(_8) != IS_STRING) {
486 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "The unique compilation prefix is invalid", "phalcon/mvc/view/engine/volt/compiler.zep", 285);
487 return;
488 }
489 RETURN_MM_MEMBER(getThis(), "_prefix");
490
491 }
492
493 /**
494 * Resolves attribute reading
495 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,attributeReader)496 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, attributeReader) {
497
498 zend_bool _3$$5, _7$$8;
499 zend_long ZEPHIR_LAST_CALL_STATUS;
500 zval *expr_param = NULL, *exprCode = NULL, *left = NULL, *leftType = NULL, *variable = NULL, *level = NULL, *dependencyInjector = NULL, *leftCode = NULL, *right = NULL, *_0, *_8, *_1$$4 = NULL, *_2$$4, *_4$$5 = NULL, *_5$$6, *_6$$7, *_9$$11, *_10$$12 = NULL;
501 zval *expr = NULL;
502
503 ZEPHIR_MM_GROW();
504 zephir_fetch_params(1, 1, 0, &expr_param);
505
506 expr = expr_param;
507
508
509 ZEPHIR_INIT_VAR(exprCode);
510 ZVAL_NULL(exprCode);
511 ZEPHIR_OBS_VAR(left);
512 zephir_array_fetch_string(&left, expr, SL("left"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 301 TSRMLS_CC);
513 zephir_array_fetch_string(&_0, left, SL("type"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 303 TSRMLS_CC);
514 if (ZEPHIR_IS_LONG(_0, 265)) {
515 ZEPHIR_OBS_VAR(variable);
516 zephir_array_fetch_string(&variable, left, SL("value"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 305 TSRMLS_CC);
517 if (ZEPHIR_IS_STRING(variable, "loop")) {
518 ZEPHIR_OBS_VAR(level);
519 zephir_read_property_this(&level, this_ptr, SL("_foreachLevel"), PH_NOISY_CC);
520 ZEPHIR_CALL_METHOD(&_1$$4, this_ptr, "getuniqueprefix", NULL, 0);
521 zephir_check_call_status();
522 ZEPHIR_INIT_VAR(_2$$4);
523 ZEPHIR_CONCAT_SVVS(_2$$4, "$", _1$$4, level, "loop");
524 zephir_concat_self(&exprCode, _2$$4 TSRMLS_CC);
525 zephir_update_property_array(this_ptr, SL("_loopPointers"), level, level TSRMLS_CC);
526 } else {
527 ZEPHIR_OBS_VAR(dependencyInjector);
528 zephir_read_property_this(&dependencyInjector, this_ptr, SL("_dependencyInjector"), PH_NOISY_CC);
529 _3$$5 = Z_TYPE_P(dependencyInjector) == IS_OBJECT;
530 if (_3$$5) {
531 ZEPHIR_CALL_METHOD(&_4$$5, dependencyInjector, "has", NULL, 0, variable);
532 zephir_check_call_status();
533 _3$$5 = zephir_is_true(_4$$5);
534 }
535 if (_3$$5) {
536 ZEPHIR_INIT_VAR(_5$$6);
537 ZEPHIR_CONCAT_SV(_5$$6, "$this->", variable);
538 zephir_concat_self(&exprCode, _5$$6 TSRMLS_CC);
539 } else {
540 ZEPHIR_INIT_VAR(_6$$7);
541 ZEPHIR_CONCAT_SV(_6$$7, "$", variable);
542 zephir_concat_self(&exprCode, _6$$7 TSRMLS_CC);
543 }
544 }
545 } else {
546 ZEPHIR_CALL_METHOD(&leftCode, this_ptr, "expression", NULL, 413, left);
547 zephir_check_call_status();
548 ZEPHIR_OBS_VAR(leftType);
549 zephir_array_fetch_string(&leftType, left, SL("type"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 328 TSRMLS_CC);
550 _7$$8 = !ZEPHIR_IS_LONG(leftType, '.');
551 if (_7$$8) {
552 _7$$8 = !ZEPHIR_IS_LONG(leftType, 350);
553 }
554 if (_7$$8) {
555 zephir_concat_self(&exprCode, leftCode TSRMLS_CC);
556 } else {
557 zephir_concat_self(&exprCode, leftCode TSRMLS_CC);
558 }
559 }
560 zephir_concat_self_str(&exprCode, SL("->") TSRMLS_CC);
561 ZEPHIR_OBS_VAR(right);
562 zephir_array_fetch_string(&right, expr, SL("right"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 338 TSRMLS_CC);
563 zephir_array_fetch_string(&_8, right, SL("type"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 340 TSRMLS_CC);
564 if (ZEPHIR_IS_LONG(_8, 265)) {
565 zephir_array_fetch_string(&_9$$11, right, SL("value"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 341 TSRMLS_CC);
566 zephir_concat_self(&exprCode, _9$$11 TSRMLS_CC);
567 } else {
568 ZEPHIR_CALL_METHOD(&_10$$12, this_ptr, "expression", NULL, 413, right);
569 zephir_check_call_status();
570 zephir_concat_self(&exprCode, _10$$12 TSRMLS_CC);
571 }
572 RETURN_CCTOR(exprCode);
573
574 }
575
576 /**
577 * Resolves function intermediate code into PHP function calls
578 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,functionCall)579 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall) {
580
581 zend_bool _7$$5;
582 zend_long ZEPHIR_LAST_CALL_STATUS;
583 zval *expr_param = NULL, *code = NULL, *funcArguments = NULL, *arguments = NULL, *nameExpr = NULL, *nameType = NULL, *name = NULL, *extensions = NULL, *functions = NULL, *definition = NULL, *extendedBlocks = NULL, *block = NULL, *currentBlock = NULL, *exprLevel = NULL, *escapedCode = NULL, *method = NULL, *arrayHelpers = NULL, *className = NULL, *_9 = NULL, *_1$$6, *_3$$9, *_4$$9, *_5$$9, *_6$$9, *_8$$5;
584 zval *expr = NULL, *_0$$6, *_2$$12;
585
586 ZEPHIR_MM_GROW();
587 zephir_fetch_params(1, 1, 0, &expr_param);
588
589 expr = expr_param;
590
591
592 ZEPHIR_INIT_VAR(code);
593 ZVAL_NULL(code);
594 ZEPHIR_INIT_VAR(funcArguments);
595 ZVAL_NULL(funcArguments);
596 ZEPHIR_OBS_NVAR(funcArguments);
597 if (zephir_array_isset_string_fetch(&funcArguments, expr, SS("arguments"), 0 TSRMLS_CC)) {
598 ZEPHIR_CALL_METHOD(&arguments, this_ptr, "expression", NULL, 413, funcArguments);
599 zephir_check_call_status();
600 } else {
601 ZEPHIR_INIT_NVAR(arguments);
602 ZVAL_STRING(arguments, "", 1);
603 }
604 ZEPHIR_OBS_VAR(nameExpr);
605 zephir_array_fetch_string(&nameExpr, expr, SL("name"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 368 TSRMLS_CC);
606 ZEPHIR_OBS_VAR(nameType);
607 zephir_array_fetch_string(&nameType, nameExpr, SL("type"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 368 TSRMLS_CC);
608 if (ZEPHIR_IS_LONG(nameType, 265)) {
609 ZEPHIR_OBS_VAR(name);
610 zephir_array_fetch_string(&name, nameExpr, SL("value"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 375 TSRMLS_CC);
611 ZEPHIR_OBS_VAR(extensions);
612 zephir_read_property_this(&extensions, this_ptr, SL("_extensions"), PH_NOISY_CC);
613 if (Z_TYPE_P(extensions) == IS_ARRAY) {
614 ZEPHIR_INIT_VAR(_0$$6);
615 zephir_create_array(_0$$6, 3, 0 TSRMLS_CC);
616 zephir_array_fast_append(_0$$6, name);
617 zephir_array_fast_append(_0$$6, arguments);
618 zephir_array_fast_append(_0$$6, funcArguments);
619 ZEPHIR_INIT_VAR(_1$$6);
620 ZVAL_STRING(_1$$6, "compileFunction", ZEPHIR_TEMP_PARAM_COPY);
621 ZEPHIR_CALL_METHOD(&code, this_ptr, "fireextensionevent", NULL, 414, _1$$6, _0$$6);
622 zephir_check_temp_parameter(_1$$6);
623 zephir_check_call_status();
624 if (Z_TYPE_P(code) == IS_STRING) {
625 RETURN_CCTOR(code);
626 }
627 }
628 ZEPHIR_OBS_VAR(functions);
629 zephir_read_property_this(&functions, this_ptr, SL("_functions"), PH_NOISY_CC);
630 if (Z_TYPE_P(functions) == IS_ARRAY) {
631 ZEPHIR_OBS_VAR(definition);
632 if (zephir_array_isset_fetch(&definition, functions, name, 0 TSRMLS_CC)) {
633 if (Z_TYPE_P(definition) == IS_STRING) {
634 ZEPHIR_CONCAT_VSVS(return_value, definition, "(", arguments, ")");
635 RETURN_MM();
636 }
637 if (Z_TYPE_P(definition) == IS_OBJECT) {
638 if (zephir_instance_of_ev(definition, zend_ce_closure TSRMLS_CC)) {
639 ZEPHIR_INIT_VAR(_2$$12);
640 zephir_create_array(_2$$12, 2, 0 TSRMLS_CC);
641 zephir_array_fast_append(_2$$12, arguments);
642 zephir_array_fast_append(_2$$12, funcArguments);
643 ZEPHIR_CALL_USER_FUNC_ARRAY(return_value, definition, _2$$12);
644 zephir_check_call_status();
645 RETURN_MM();
646 }
647 }
648 ZEPHIR_INIT_VAR(_3$$9);
649 object_init_ex(_3$$9, phalcon_mvc_view_engine_volt_exception_ce);
650 zephir_array_fetch_string(&_4$$9, expr, SL("file"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 417 TSRMLS_CC);
651 zephir_array_fetch_string(&_5$$9, expr, SL("line"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 418 TSRMLS_CC);
652 ZEPHIR_INIT_VAR(_6$$9);
653 ZEPHIR_CONCAT_SVSVSV(_6$$9, "Invalid definition for user function '", name, "' in ", _4$$9, " on line ", _5$$9);
654 ZEPHIR_CALL_METHOD(NULL, _3$$9, "__construct", NULL, 415, _6$$9);
655 zephir_check_call_status();
656 zephir_throw_exception_debug(_3$$9, "phalcon/mvc/view/engine/volt/compiler.zep", 418 TSRMLS_CC);
657 ZEPHIR_MM_RESTORE();
658 return;
659 }
660 }
661 _7$$5 = ZEPHIR_IS_STRING(name, "get_content");
662 if (!(_7$$5)) {
663 _7$$5 = ZEPHIR_IS_STRING(name, "content");
664 }
665 if (_7$$5) {
666 RETURN_MM_STRING("$this->getContent()", 1);
667 }
668 if (ZEPHIR_IS_STRING(name, "partial")) {
669 ZEPHIR_CONCAT_SVS(return_value, "$this->partial(", arguments, ")");
670 RETURN_MM();
671 }
672 if (ZEPHIR_IS_STRING(name, "super")) {
673 ZEPHIR_OBS_VAR(extendedBlocks);
674 zephir_read_property_this(&extendedBlocks, this_ptr, SL("_extendedBlocks"), PH_NOISY_CC);
675 if (Z_TYPE_P(extendedBlocks) == IS_ARRAY) {
676 ZEPHIR_OBS_VAR(currentBlock);
677 zephir_read_property_this(¤tBlock, this_ptr, SL("_currentBlock"), PH_NOISY_CC);
678 ZEPHIR_OBS_VAR(block);
679 if (zephir_array_isset_fetch(&block, extendedBlocks, currentBlock, 0 TSRMLS_CC)) {
680 ZEPHIR_OBS_VAR(exprLevel);
681 zephir_read_property_this(&exprLevel, this_ptr, SL("_exprLevel"), PH_NOISY_CC);
682 if (Z_TYPE_P(block) == IS_ARRAY) {
683 ZEPHIR_CALL_METHOD(&code, this_ptr, "_statementlistorextends", NULL, 416, block);
684 zephir_check_call_status();
685 if (ZEPHIR_IS_LONG(exprLevel, 1)) {
686 ZEPHIR_CPY_WRT(escapedCode, code);
687 } else {
688 ZEPHIR_INIT_NVAR(escapedCode);
689 zephir_addslashes(escapedCode, code TSRMLS_CC);
690 }
691 } else {
692 if (ZEPHIR_IS_LONG(exprLevel, 1)) {
693 ZEPHIR_CPY_WRT(escapedCode, block);
694 } else {
695 ZEPHIR_INIT_NVAR(escapedCode);
696 zephir_addslashes(escapedCode, block TSRMLS_CC);
697 }
698 }
699 if (ZEPHIR_IS_LONG(exprLevel, 1)) {
700 RETURN_CCTOR(escapedCode);
701 }
702 ZEPHIR_CONCAT_SVS(return_value, "'", escapedCode, "'");
703 RETURN_MM();
704 }
705 }
706 RETURN_MM_STRING("''", 1);
707 }
708 ZEPHIR_INIT_VAR(_8$$5);
709 zephir_camelize(_8$$5, name, NULL );
710 ZEPHIR_CALL_FUNCTION(&method, "lcfirst", NULL, 71, _8$$5);
711 zephir_check_call_status();
712 ZEPHIR_INIT_VAR(className);
713 ZVAL_STRING(className, "Phalcon\\Tag", 1);
714 if ((zephir_method_exists(className, method TSRMLS_CC) == SUCCESS)) {
715 ZEPHIR_OBS_VAR(arrayHelpers);
716 zephir_read_property_this(&arrayHelpers, this_ptr, SL("_arrayHelpers"), PH_NOISY_CC);
717 if (Z_TYPE_P(arrayHelpers) != IS_ARRAY) {
718 ZEPHIR_INIT_NVAR(arrayHelpers);
719 zephir_create_array(arrayHelpers, 27, 0 TSRMLS_CC);
720 zephir_array_update_string(&arrayHelpers, SL("check_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
721 zephir_array_update_string(&arrayHelpers, SL("color_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
722 zephir_array_update_string(&arrayHelpers, SL("date_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
723 zephir_array_update_string(&arrayHelpers, SL("date_time_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
724 zephir_array_update_string(&arrayHelpers, SL("date_time_local_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
725 zephir_array_update_string(&arrayHelpers, SL("email_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
726 zephir_array_update_string(&arrayHelpers, SL("file_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
727 zephir_array_update_string(&arrayHelpers, SL("form"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
728 zephir_array_update_string(&arrayHelpers, SL("hidden_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
729 zephir_array_update_string(&arrayHelpers, SL("image"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
730 zephir_array_update_string(&arrayHelpers, SL("image_input"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
731 zephir_array_update_string(&arrayHelpers, SL("link_to"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
732 zephir_array_update_string(&arrayHelpers, SL("month_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
733 zephir_array_update_string(&arrayHelpers, SL("numeric_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
734 zephir_array_update_string(&arrayHelpers, SL("password_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
735 zephir_array_update_string(&arrayHelpers, SL("radio_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
736 zephir_array_update_string(&arrayHelpers, SL("range_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
737 zephir_array_update_string(&arrayHelpers, SL("search_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
738 zephir_array_update_string(&arrayHelpers, SL("select"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
739 zephir_array_update_string(&arrayHelpers, SL("select_static"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
740 zephir_array_update_string(&arrayHelpers, SL("submit_button"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
741 zephir_array_update_string(&arrayHelpers, SL("tel_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
742 zephir_array_update_string(&arrayHelpers, SL("text_area"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
743 zephir_array_update_string(&arrayHelpers, SL("text_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
744 zephir_array_update_string(&arrayHelpers, SL("time_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
745 zephir_array_update_string(&arrayHelpers, SL("url_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
746 zephir_array_update_string(&arrayHelpers, SL("week_field"), &ZEPHIR_GLOBAL(global_true), PH_COPY | PH_SEPARATE);
747 zephir_update_property_this(getThis(), SL("_arrayHelpers"), arrayHelpers TSRMLS_CC);
748 }
749 if (zephir_array_isset(arrayHelpers, name)) {
750 ZEPHIR_CONCAT_SVSVS(return_value, "$this->tag->", method, "([", arguments, "])");
751 RETURN_MM();
752 }
753 ZEPHIR_CONCAT_SVSVS(return_value, "$this->tag->", method, "(", arguments, ")");
754 RETURN_MM();
755 }
756 if (ZEPHIR_IS_STRING(name, "url")) {
757 ZEPHIR_CONCAT_SVS(return_value, "$this->url->get(", arguments, ")");
758 RETURN_MM();
759 }
760 if (ZEPHIR_IS_STRING(name, "static_url")) {
761 ZEPHIR_CONCAT_SVS(return_value, "$this->url->getStatic(", arguments, ")");
762 RETURN_MM();
763 }
764 if (ZEPHIR_IS_STRING(name, "date")) {
765 ZEPHIR_CONCAT_SVS(return_value, "date(", arguments, ")");
766 RETURN_MM();
767 }
768 if (ZEPHIR_IS_STRING(name, "time")) {
769 RETURN_MM_STRING("time()", 1);
770 }
771 if (ZEPHIR_IS_STRING(name, "dump")) {
772 ZEPHIR_CONCAT_SVS(return_value, "var_dump(", arguments, ")");
773 RETURN_MM();
774 }
775 if (ZEPHIR_IS_STRING(name, "version")) {
776 RETURN_MM_STRING("Phalcon\\Version::get()", 1);
777 }
778 if (ZEPHIR_IS_STRING(name, "version_id")) {
779 RETURN_MM_STRING("Phalcon\\Version::getId()", 1);
780 }
781 if (ZEPHIR_IS_STRING(name, "constant")) {
782 ZEPHIR_CONCAT_SVS(return_value, "constant(", arguments, ")");
783 RETURN_MM();
784 }
785 ZEPHIR_CONCAT_SVSVS(return_value, "$this->callMacro('", name, "', [", arguments, "])");
786 RETURN_MM();
787 }
788 ZEPHIR_CALL_METHOD(&_9, this_ptr, "expression", NULL, 413, nameExpr);
789 zephir_check_call_status();
790 ZEPHIR_CONCAT_VSVS(return_value, _9, "(", arguments, ")");
791 RETURN_MM();
792
793 }
794
795 /**
796 * Resolves filter intermediate code into a valid PHP expression
797 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,resolveTest)798 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, resolveTest) {
799
800 zend_long ZEPHIR_LAST_CALL_STATUS;
801 zval *left = NULL;
802 zval *test_param = NULL, *left_param = NULL, *type = NULL, *name = NULL, *testName = NULL, *_6 = NULL, *_0$$12 = NULL, *_1$$12, *_2$$13 = NULL, *_3$$13, *_4$$14 = NULL, *_5$$14;
803 zval *test = NULL;
804
805 ZEPHIR_MM_GROW();
806 zephir_fetch_params(1, 2, 0, &test_param, &left_param);
807
808 test = test_param;
809 zephir_get_strval(left, left_param);
810
811
812 ZEPHIR_OBS_VAR(type);
813 zephir_array_fetch_string(&type, test, SL("type"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 579 TSRMLS_CC);
814 if (ZEPHIR_IS_LONG(type, 265)) {
815 ZEPHIR_OBS_VAR(name);
816 zephir_array_fetch_string(&name, test, SL("value"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 586 TSRMLS_CC);
817 if (ZEPHIR_IS_STRING(name, "empty")) {
818 ZEPHIR_CONCAT_SVS(return_value, "empty(", left, ")");
819 RETURN_MM();
820 }
821 if (ZEPHIR_IS_STRING(name, "even")) {
822 ZEPHIR_CONCAT_SVS(return_value, "(((", left, ") % 2) == 0)");
823 RETURN_MM();
824 }
825 if (ZEPHIR_IS_STRING(name, "odd")) {
826 ZEPHIR_CONCAT_SVS(return_value, "(((", left, ") % 2) != 0)");
827 RETURN_MM();
828 }
829 if (ZEPHIR_IS_STRING(name, "numeric")) {
830 ZEPHIR_CONCAT_SVS(return_value, "is_numeric(", left, ")");
831 RETURN_MM();
832 }
833 if (ZEPHIR_IS_STRING(name, "scalar")) {
834 ZEPHIR_CONCAT_SVS(return_value, "is_scalar(", left, ")");
835 RETURN_MM();
836 }
837 if (ZEPHIR_IS_STRING(name, "iterable")) {
838 ZEPHIR_CONCAT_SVSVS(return_value, "(is_array(", left, ") || (", left, ") instanceof Traversable)");
839 RETURN_MM();
840 }
841 }
842 if (ZEPHIR_IS_LONG(type, 350)) {
843 ZEPHIR_OBS_VAR(testName);
844 zephir_array_fetch_string(&testName, test, SL("name"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 637 TSRMLS_CC);
845 ZEPHIR_OBS_NVAR(name);
846 if (zephir_array_isset_string_fetch(&name, testName, SS("value"), 0 TSRMLS_CC)) {
847 if (ZEPHIR_IS_STRING(name, "divisibleby")) {
848 zephir_array_fetch_string(&_1$$12, test, SL("arguments"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 641 TSRMLS_CC);
849 ZEPHIR_CALL_METHOD(&_0$$12, this_ptr, "expression", NULL, 413, _1$$12);
850 zephir_check_call_status();
851 ZEPHIR_CONCAT_SVSVS(return_value, "(((", left, ") % (", _0$$12, ")) == 0)");
852 RETURN_MM();
853 }
854 if (ZEPHIR_IS_STRING(name, "sameas")) {
855 zephir_array_fetch_string(&_3$$13, test, SL("arguments"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 648 TSRMLS_CC);
856 ZEPHIR_CALL_METHOD(&_2$$13, this_ptr, "expression", NULL, 413, _3$$13);
857 zephir_check_call_status();
858 ZEPHIR_CONCAT_SVSVS(return_value, "(", left, ") === (", _2$$13, ")");
859 RETURN_MM();
860 }
861 if (ZEPHIR_IS_STRING(name, "type")) {
862 zephir_array_fetch_string(&_5$$14, test, SL("arguments"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 655 TSRMLS_CC);
863 ZEPHIR_CALL_METHOD(&_4$$14, this_ptr, "expression", NULL, 413, _5$$14);
864 zephir_check_call_status();
865 ZEPHIR_CONCAT_SVSVS(return_value, "gettype(", left, ") === (", _4$$14, ")");
866 RETURN_MM();
867 }
868 }
869 }
870 ZEPHIR_CALL_METHOD(&_6, this_ptr, "expression", NULL, 413, test);
871 zephir_check_call_status();
872 ZEPHIR_CONCAT_VSV(return_value, left, " == ", _6);
873 RETURN_MM();
874
875 }
876
877 /**
878 * Resolves filter intermediate code into PHP function calls
879 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,resolveFilter)880 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, resolveFilter) {
881
882 zend_bool _13, _14, _15;
883 zend_long ZEPHIR_LAST_CALL_STATUS;
884 zval *left = NULL;
885 zval *filter_param = NULL, *left_param = NULL, *code = NULL, *type = NULL, *functionName = NULL, *name = NULL, *file = NULL, *line = NULL, *extensions = NULL, *filters = NULL, *funcArguments = NULL, *arguments = NULL, *definition = NULL, *_16, *_17, *_18, *_19, *_0$$5, *_1$$5, *_2$$5, *_3$$5, *_7$$9, *_9$$12, *_10$$12, *_11$$12, *_12$$12;
886 zval *filter = NULL, *_4$$7, *_5$$7, *_6$$9, *_8$$15;
887
888 ZEPHIR_MM_GROW();
889 zephir_fetch_params(1, 2, 0, &filter_param, &left_param);
890
891 filter = filter_param;
892 zephir_get_strval(left, left_param);
893
894
895 ZEPHIR_INIT_VAR(code);
896 ZVAL_NULL(code);
897 ZEPHIR_OBS_VAR(type);
898 zephir_array_fetch_string(&type, filter, SL("type"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 674 TSRMLS_CC);
899 if (ZEPHIR_IS_LONG(type, 265)) {
900 ZEPHIR_OBS_VAR(name);
901 zephir_array_fetch_string(&name, filter, SL("value"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 680 TSRMLS_CC);
902 } else {
903 if (!ZEPHIR_IS_LONG(type, 350)) {
904 ZEPHIR_INIT_VAR(_0$$5);
905 object_init_ex(_0$$5, phalcon_mvc_view_engine_volt_exception_ce);
906 zephir_array_fetch_string(&_1$$5, filter, SL("file"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 688 TSRMLS_CC);
907 zephir_array_fetch_string(&_2$$5, filter, SL("line"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 688 TSRMLS_CC);
908 ZEPHIR_INIT_VAR(_3$$5);
909 ZEPHIR_CONCAT_SVSV(_3$$5, "Unknown filter type in ", _1$$5, " on line ", _2$$5);
910 ZEPHIR_CALL_METHOD(NULL, _0$$5, "__construct", NULL, 415, _3$$5);
911 zephir_check_call_status();
912 zephir_throw_exception_debug(_0$$5, "phalcon/mvc/view/engine/volt/compiler.zep", 688 TSRMLS_CC);
913 ZEPHIR_MM_RESTORE();
914 return;
915 }
916 ZEPHIR_OBS_VAR(functionName);
917 zephir_array_fetch_string(&functionName, filter, SL("name"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 691 TSRMLS_CC);
918 ZEPHIR_OBS_NVAR(name);
919 zephir_array_fetch_string(&name, functionName, SL("value"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 692 TSRMLS_CC);
920 }
921 ZEPHIR_INIT_VAR(funcArguments);
922 ZVAL_NULL(funcArguments);
923 ZEPHIR_INIT_VAR(arguments);
924 ZVAL_NULL(arguments);
925 ZEPHIR_OBS_NVAR(funcArguments);
926 if (zephir_array_isset_string_fetch(&funcArguments, filter, SS("arguments"), 0 TSRMLS_CC)) {
927 if (!ZEPHIR_IS_STRING(name, "default")) {
928 ZEPHIR_OBS_VAR(file);
929 zephir_array_fetch_string(&file, filter, SL("file"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 707 TSRMLS_CC);
930 ZEPHIR_OBS_VAR(line);
931 zephir_array_fetch_string(&line, filter, SL("line"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 707 TSRMLS_CC);
932 ZEPHIR_INIT_VAR(_4$$7);
933 zephir_create_array(_4$$7, 3, 0 TSRMLS_CC);
934 ZEPHIR_INIT_VAR(_5$$7);
935 zephir_create_array(_5$$7, 4, 0 TSRMLS_CC);
936 add_assoc_long_ex(_5$$7, SS("type"), 364);
937 zephir_array_update_string(&_5$$7, SL("value"), &left, PH_COPY | PH_SEPARATE);
938 zephir_array_update_string(&_5$$7, SL("file"), &file, PH_COPY | PH_SEPARATE);
939 zephir_array_update_string(&_5$$7, SL("line"), &line, PH_COPY | PH_SEPARATE);
940 zephir_array_update_string(&_4$$7, SL("expr"), &_5$$7, PH_COPY | PH_SEPARATE);
941 zephir_array_update_string(&_4$$7, SL("file"), &file, PH_COPY | PH_SEPARATE);
942 zephir_array_update_string(&_4$$7, SL("line"), &line, PH_COPY | PH_SEPARATE);
943 ZEPHIR_MAKE_REF(funcArguments);
944 ZEPHIR_CALL_FUNCTION(NULL, "array_unshift", NULL, 417, funcArguments, _4$$7);
945 ZEPHIR_UNREF(funcArguments);
946 zephir_check_call_status();
947 }
948 ZEPHIR_CALL_METHOD(&arguments, this_ptr, "expression", NULL, 413, funcArguments);
949 zephir_check_call_status();
950 } else {
951 ZEPHIR_CPY_WRT(arguments, left);
952 }
953 ZEPHIR_OBS_VAR(extensions);
954 zephir_read_property_this(&extensions, this_ptr, SL("_extensions"), PH_NOISY_CC);
955 if (Z_TYPE_P(extensions) == IS_ARRAY) {
956 ZEPHIR_INIT_VAR(_6$$9);
957 zephir_create_array(_6$$9, 3, 0 TSRMLS_CC);
958 zephir_array_fast_append(_6$$9, name);
959 zephir_array_fast_append(_6$$9, arguments);
960 zephir_array_fast_append(_6$$9, funcArguments);
961 ZEPHIR_INIT_VAR(_7$$9);
962 ZVAL_STRING(_7$$9, "compileFilter", ZEPHIR_TEMP_PARAM_COPY);
963 ZEPHIR_CALL_METHOD(&code, this_ptr, "fireextensionevent", NULL, 414, _7$$9, _6$$9);
964 zephir_check_temp_parameter(_7$$9);
965 zephir_check_call_status();
966 if (Z_TYPE_P(code) == IS_STRING) {
967 RETURN_CCTOR(code);
968 }
969 }
970 ZEPHIR_OBS_VAR(filters);
971 zephir_read_property_this(&filters, this_ptr, SL("_filters"), PH_NOISY_CC);
972 if (Z_TYPE_P(filters) == IS_ARRAY) {
973 ZEPHIR_OBS_VAR(definition);
974 if (zephir_array_isset_fetch(&definition, filters, name, 0 TSRMLS_CC)) {
975 if (Z_TYPE_P(definition) == IS_STRING) {
976 ZEPHIR_CONCAT_VSVS(return_value, definition, "(", arguments, ")");
977 RETURN_MM();
978 }
979 if (Z_TYPE_P(definition) == IS_OBJECT) {
980 if (zephir_instance_of_ev(definition, zend_ce_closure TSRMLS_CC)) {
981 ZEPHIR_INIT_VAR(_8$$15);
982 zephir_create_array(_8$$15, 2, 0 TSRMLS_CC);
983 zephir_array_fast_append(_8$$15, arguments);
984 zephir_array_fast_append(_8$$15, funcArguments);
985 ZEPHIR_CALL_USER_FUNC_ARRAY(return_value, definition, _8$$15);
986 zephir_check_call_status();
987 RETURN_MM();
988 }
989 }
990 ZEPHIR_INIT_VAR(_9$$12);
991 object_init_ex(_9$$12, phalcon_mvc_view_engine_volt_exception_ce);
992 zephir_array_fetch_string(&_10$$12, filter, SL("file"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 771 TSRMLS_CC);
993 zephir_array_fetch_string(&_11$$12, filter, SL("line"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 772 TSRMLS_CC);
994 ZEPHIR_INIT_VAR(_12$$12);
995 ZEPHIR_CONCAT_SVSVSV(_12$$12, "Invalid definition for user filter '", name, "' in ", _10$$12, " on line ", _11$$12);
996 ZEPHIR_CALL_METHOD(NULL, _9$$12, "__construct", NULL, 415, _12$$12);
997 zephir_check_call_status();
998 zephir_throw_exception_debug(_9$$12, "phalcon/mvc/view/engine/volt/compiler.zep", 772 TSRMLS_CC);
999 ZEPHIR_MM_RESTORE();
1000 return;
1001 }
1002 }
1003 if (ZEPHIR_IS_STRING(name, "length")) {
1004 ZEPHIR_CONCAT_SVS(return_value, "$this->length(", arguments, ")");
1005 RETURN_MM();
1006 }
1007 _13 = ZEPHIR_IS_STRING(name, "e");
1008 if (!(_13)) {
1009 _13 = ZEPHIR_IS_STRING(name, "escape");
1010 }
1011 if (_13) {
1012 ZEPHIR_CONCAT_SVS(return_value, "$this->escaper->escapeHtml(", arguments, ")");
1013 RETURN_MM();
1014 }
1015 if (ZEPHIR_IS_STRING(name, "escape_css")) {
1016 ZEPHIR_CONCAT_SVS(return_value, "$this->escaper->escapeCss(", arguments, ")");
1017 RETURN_MM();
1018 }
1019 if (ZEPHIR_IS_STRING(name, "escape_js")) {
1020 ZEPHIR_CONCAT_SVS(return_value, "$this->escaper->escapeJs(", arguments, ")");
1021 RETURN_MM();
1022 }
1023 if (ZEPHIR_IS_STRING(name, "escape_attr")) {
1024 ZEPHIR_CONCAT_SVS(return_value, "$this->escaper->escapeHtmlAttr(", arguments, ")");
1025 RETURN_MM();
1026 }
1027 if (ZEPHIR_IS_STRING(name, "trim")) {
1028 ZEPHIR_CONCAT_SVS(return_value, "trim(", arguments, ")");
1029 RETURN_MM();
1030 }
1031 if (ZEPHIR_IS_STRING(name, "left_trim")) {
1032 ZEPHIR_CONCAT_SVS(return_value, "ltrim(", arguments, ")");
1033 RETURN_MM();
1034 }
1035 if (ZEPHIR_IS_STRING(name, "right_trim")) {
1036 ZEPHIR_CONCAT_SVS(return_value, "rtrim(", arguments, ")");
1037 RETURN_MM();
1038 }
1039 if (ZEPHIR_IS_STRING(name, "striptags")) {
1040 ZEPHIR_CONCAT_SVS(return_value, "strip_tags(", arguments, ")");
1041 RETURN_MM();
1042 }
1043 if (ZEPHIR_IS_STRING(name, "url_encode")) {
1044 ZEPHIR_CONCAT_SVS(return_value, "urlencode(", arguments, ")");
1045 RETURN_MM();
1046 }
1047 if (ZEPHIR_IS_STRING(name, "slashes")) {
1048 ZEPHIR_CONCAT_SVS(return_value, "addslashes(", arguments, ")");
1049 RETURN_MM();
1050 }
1051 if (ZEPHIR_IS_STRING(name, "stripslashes")) {
1052 ZEPHIR_CONCAT_SVS(return_value, "stripslashes(", arguments, ")");
1053 RETURN_MM();
1054 }
1055 if (ZEPHIR_IS_STRING(name, "nl2br")) {
1056 ZEPHIR_CONCAT_SVS(return_value, "nl2br(", arguments, ")");
1057 RETURN_MM();
1058 }
1059 if (ZEPHIR_IS_STRING(name, "keys")) {
1060 ZEPHIR_CONCAT_SVS(return_value, "array_keys(", arguments, ")");
1061 RETURN_MM();
1062 }
1063 if (ZEPHIR_IS_STRING(name, "join")) {
1064 ZEPHIR_CONCAT_SVS(return_value, "join(", arguments, ")");
1065 RETURN_MM();
1066 }
1067 _14 = ZEPHIR_IS_STRING(name, "lower");
1068 if (!(_14)) {
1069 _14 = ZEPHIR_IS_STRING(name, "lowercase");
1070 }
1071 if (_14) {
1072 ZEPHIR_CONCAT_SVS(return_value, "Phalcon\\Text::lower(", arguments, ")");
1073 RETURN_MM();
1074 }
1075 _15 = ZEPHIR_IS_STRING(name, "upper");
1076 if (!(_15)) {
1077 _15 = ZEPHIR_IS_STRING(name, "uppercase");
1078 }
1079 if (_15) {
1080 ZEPHIR_CONCAT_SVS(return_value, "Phalcon\\Text::upper(", arguments, ")");
1081 RETURN_MM();
1082 }
1083 if (ZEPHIR_IS_STRING(name, "capitalize")) {
1084 ZEPHIR_CONCAT_SVS(return_value, "ucwords(", arguments, ")");
1085 RETURN_MM();
1086 }
1087 if (ZEPHIR_IS_STRING(name, "sort")) {
1088 ZEPHIR_CONCAT_SVS(return_value, "$this->sort(", arguments, ")");
1089 RETURN_MM();
1090 }
1091 if (ZEPHIR_IS_STRING(name, "json_encode")) {
1092 ZEPHIR_CONCAT_SVS(return_value, "json_encode(", arguments, ")");
1093 RETURN_MM();
1094 }
1095 if (ZEPHIR_IS_STRING(name, "json_decode")) {
1096 ZEPHIR_CONCAT_SVS(return_value, "json_decode(", arguments, ")");
1097 RETURN_MM();
1098 }
1099 if (ZEPHIR_IS_STRING(name, "format")) {
1100 ZEPHIR_CONCAT_SVS(return_value, "sprintf(", arguments, ")");
1101 RETURN_MM();
1102 }
1103 if (ZEPHIR_IS_STRING(name, "abs")) {
1104 ZEPHIR_CONCAT_SVS(return_value, "abs(", arguments, ")");
1105 RETURN_MM();
1106 }
1107 if (ZEPHIR_IS_STRING(name, "slice")) {
1108 ZEPHIR_CONCAT_SVS(return_value, "$this->slice(", arguments, ")");
1109 RETURN_MM();
1110 }
1111 if (ZEPHIR_IS_STRING(name, "default")) {
1112 ZEPHIR_CONCAT_SVSVSVS(return_value, "(empty(", left, ") ? (", arguments, ") : (", left, "))");
1113 RETURN_MM();
1114 }
1115 if (ZEPHIR_IS_STRING(name, "convert_encoding")) {
1116 ZEPHIR_CONCAT_SVS(return_value, "$this->convertEncoding(", arguments, ")");
1117 RETURN_MM();
1118 }
1119 ZEPHIR_INIT_VAR(_16);
1120 object_init_ex(_16, phalcon_mvc_view_engine_volt_exception_ce);
1121 zephir_array_fetch_string(&_17, filter, SL("file"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 961 TSRMLS_CC);
1122 zephir_array_fetch_string(&_18, filter, SL("line"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 961 TSRMLS_CC);
1123 ZEPHIR_INIT_VAR(_19);
1124 ZEPHIR_CONCAT_SVSVSV(_19, "Unknown filter \"", name, "\" in ", _17, " on line ", _18);
1125 ZEPHIR_CALL_METHOD(NULL, _16, "__construct", NULL, 415, _19);
1126 zephir_check_call_status();
1127 zephir_throw_exception_debug(_16, "phalcon/mvc/view/engine/volt/compiler.zep", 961 TSRMLS_CC);
1128 ZEPHIR_MM_RESTORE();
1129 return;
1130
1131 }
1132
1133 /**
1134 * Resolves an expression node in an AST volt tree
1135 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,expression)1136 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, expression) {
1137
1138 HashTable *_4$$6;
1139 HashPosition _3$$6;
1140 zephir_fcall_cache_entry *_2 = NULL, *_7 = NULL, *_9 = NULL, *_11 = NULL, *_13 = NULL, *_19 = NULL, *_26 = NULL;
1141 zend_long ZEPHIR_LAST_CALL_STATUS;
1142 zval *expr_param = NULL, *exprCode = NULL, *extensions = NULL, *items = NULL, *singleExpr = NULL, *singleExprCode = NULL, *name = NULL, *left = NULL, *leftCode = NULL, *right = NULL, *rightCode = NULL, *type = NULL, *startCode = NULL, *endCode = NULL, *start = NULL, *end = NULL, *_1$$4 = NULL, **_5$$6, *_6$$7, *_8$$8 = NULL, *_10$$12, *_12$$13, *_14$$31 = NULL, *_15$$31, _16$$31 = zval_used_for_init, _17$$31 = zval_used_for_init, *_18$$35, *_20$$69 = NULL, *_21$$69, *_22$$73 = NULL, *_23$$73, *_24$$73, *_25$$73 = NULL;
1143 zval *expr = NULL, *_0$$4 = NULL;
1144
1145 ZEPHIR_MM_GROW();
1146 zephir_fetch_params(1, 1, 0, &expr_param);
1147
1148 expr = expr_param;
1149
1150
1151 ZEPHIR_INIT_VAR(exprCode);
1152 ZVAL_NULL(exprCode);
1153 RETURN_ON_FAILURE(zephir_property_incr(this_ptr, SL("_exprLevel") TSRMLS_CC));
1154 ZEPHIR_OBS_VAR(extensions);
1155 zephir_read_property_this(&extensions, this_ptr, SL("_extensions"), PH_NOISY_CC);
1156 while (1) {
1157 if (Z_TYPE_P(extensions) == IS_ARRAY) {
1158 ZEPHIR_INIT_NVAR(_0$$4);
1159 zephir_create_array(_0$$4, 1, 0 TSRMLS_CC);
1160 zephir_array_fast_append(_0$$4, expr);
1161 ZEPHIR_INIT_NVAR(_1$$4);
1162 ZVAL_STRING(_1$$4, "resolveExpression", ZEPHIR_TEMP_PARAM_COPY);
1163 ZEPHIR_CALL_METHOD(&exprCode, this_ptr, "fireextensionevent", &_2, 414, _1$$4, _0$$4);
1164 zephir_check_temp_parameter(_1$$4);
1165 zephir_check_call_status();
1166 if (Z_TYPE_P(exprCode) == IS_STRING) {
1167 break;
1168 }
1169 }
1170 ZEPHIR_OBS_NVAR(type);
1171 if (!(zephir_array_isset_string_fetch(&type, expr, SS("type"), 0 TSRMLS_CC))) {
1172 ZEPHIR_INIT_NVAR(items);
1173 array_init(items);
1174 zephir_is_iterable(expr, &_4$$6, &_3$$6, 0, 0, "phalcon/mvc/view/engine/volt/compiler.zep", 1002);
1175 for (
1176 ; zend_hash_get_current_data_ex(_4$$6, (void**) &_5$$6, &_3$$6) == SUCCESS
1177 ; zend_hash_move_forward_ex(_4$$6, &_3$$6)
1178 ) {
1179 ZEPHIR_GET_HVALUE(singleExpr, _5$$6);
1180 zephir_array_fetch_string(&_6$$7, singleExpr, SL("expr"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 995 TSRMLS_CC);
1181 ZEPHIR_CALL_METHOD(&singleExprCode, this_ptr, "expression", &_7, 413, _6$$7);
1182 zephir_check_call_status();
1183 ZEPHIR_OBS_NVAR(name);
1184 if (zephir_array_isset_string_fetch(&name, singleExpr, SS("name"), 0 TSRMLS_CC)) {
1185 ZEPHIR_INIT_LNVAR(_8$$8);
1186 ZEPHIR_CONCAT_SVSV(_8$$8, "'", name, "' => ", singleExprCode);
1187 zephir_array_append(&items, _8$$8, PH_SEPARATE, "phalcon/mvc/view/engine/volt/compiler.zep", 997);
1188 } else {
1189 zephir_array_append(&items, singleExprCode, PH_SEPARATE, "phalcon/mvc/view/engine/volt/compiler.zep", 999);
1190 }
1191 }
1192 ZEPHIR_INIT_NVAR(exprCode);
1193 zephir_fast_join_str(exprCode, SL(", "), items TSRMLS_CC);
1194 break;
1195 }
1196 if (ZEPHIR_IS_LONG(type, '.')) {
1197 ZEPHIR_CALL_METHOD(&exprCode, this_ptr, "attributereader", &_9, 0, expr);
1198 zephir_check_call_status();
1199 break;
1200 }
1201 ZEPHIR_OBS_NVAR(left);
1202 if (zephir_array_isset_string_fetch(&left, expr, SS("left"), 0 TSRMLS_CC)) {
1203 ZEPHIR_CALL_METHOD(&leftCode, this_ptr, "expression", &_7, 413, left);
1204 zephir_check_call_status();
1205 }
1206 if (ZEPHIR_IS_LONG(type, 311)) {
1207 zephir_array_fetch_string(&_10$$12, expr, SL("right"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1025 TSRMLS_CC);
1208 ZEPHIR_CALL_METHOD(&exprCode, this_ptr, "resolvetest", &_11, 0, _10$$12, leftCode);
1209 zephir_check_call_status();
1210 break;
1211 }
1212 if (ZEPHIR_IS_LONG(type, 124)) {
1213 zephir_array_fetch_string(&_12$$13, expr, SL("right"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1033 TSRMLS_CC);
1214 ZEPHIR_CALL_METHOD(&exprCode, this_ptr, "resolvefilter", &_13, 418, _12$$13, leftCode);
1215 zephir_check_call_status();
1216 break;
1217 }
1218 ZEPHIR_OBS_NVAR(right);
1219 if (zephir_array_isset_string_fetch(&right, expr, SS("right"), 0 TSRMLS_CC)) {
1220 ZEPHIR_CALL_METHOD(&rightCode, this_ptr, "expression", &_7, 413, right);
1221 zephir_check_call_status();
1222 }
1223 ZEPHIR_INIT_NVAR(exprCode);
1224 ZVAL_NULL(exprCode);
1225 do {
1226 if (ZEPHIR_IS_LONG(type, '!')) {
1227 ZEPHIR_INIT_NVAR(exprCode);
1228 ZEPHIR_CONCAT_SV(exprCode, "!", rightCode);
1229 break;
1230 }
1231 if (ZEPHIR_IS_LONG(type, '*')) {
1232 ZEPHIR_INIT_NVAR(exprCode);
1233 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " * ", rightCode);
1234 break;
1235 }
1236 if (ZEPHIR_IS_LONG(type, '+')) {
1237 ZEPHIR_INIT_NVAR(exprCode);
1238 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " + ", rightCode);
1239 break;
1240 }
1241 if (ZEPHIR_IS_LONG(type, '-')) {
1242 ZEPHIR_INIT_NVAR(exprCode);
1243 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " - ", rightCode);
1244 break;
1245 }
1246 if (ZEPHIR_IS_LONG(type, '/')) {
1247 ZEPHIR_INIT_NVAR(exprCode);
1248 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " / ", rightCode);
1249 break;
1250 }
1251 if (ZEPHIR_IS_LONG(type, 37)) {
1252 ZEPHIR_INIT_NVAR(exprCode);
1253 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " % ", rightCode);
1254 break;
1255 }
1256 if (ZEPHIR_IS_LONG(type, '<')) {
1257 ZEPHIR_INIT_NVAR(exprCode);
1258 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " < ", rightCode);
1259 break;
1260 }
1261 if (ZEPHIR_IS_LONG(type, 61)) {
1262 ZEPHIR_INIT_NVAR(exprCode);
1263 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " > ", rightCode);
1264 break;
1265 }
1266 if (ZEPHIR_IS_LONG(type, 62)) {
1267 ZEPHIR_INIT_NVAR(exprCode);
1268 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " > ", rightCode);
1269 break;
1270 }
1271 if (ZEPHIR_IS_LONG(type, 126)) {
1272 ZEPHIR_INIT_NVAR(exprCode);
1273 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " . ", rightCode);
1274 break;
1275 }
1276 if (ZEPHIR_IS_LONG(type, 278)) {
1277 ZEPHIR_INIT_NVAR(exprCode);
1278 ZEPHIR_CONCAT_SVSVS(exprCode, "pow(", leftCode, ", ", rightCode, ")");
1279 break;
1280 }
1281 if (ZEPHIR_IS_LONG(type, 360)) {
1282 ZEPHIR_INIT_NVAR(exprCode);
1283 if (zephir_array_isset_string(expr, SS("left"))) {
1284 ZEPHIR_CONCAT_SVS(exprCode, "[", leftCode, "]");
1285 } else {
1286 ZVAL_STRING(exprCode, "[]", 1);
1287 }
1288 break;
1289 }
1290 if (ZEPHIR_IS_LONG(type, 258)) {
1291 ZEPHIR_OBS_NVAR(exprCode);
1292 zephir_array_fetch_string(&exprCode, expr, SL("value"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 1100 TSRMLS_CC);
1293 break;
1294 }
1295 if (ZEPHIR_IS_LONG(type, 259)) {
1296 ZEPHIR_OBS_NVAR(exprCode);
1297 zephir_array_fetch_string(&exprCode, expr, SL("value"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 1104 TSRMLS_CC);
1298 break;
1299 }
1300 if (ZEPHIR_IS_LONG(type, 260)) {
1301 ZEPHIR_INIT_NVAR(_14$$31);
1302 zephir_array_fetch_string(&_15$$31, expr, SL("value"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1108 TSRMLS_CC);
1303 ZEPHIR_SINIT_NVAR(_16$$31);
1304 ZVAL_STRING(&_16$$31, "'", 0);
1305 ZEPHIR_SINIT_NVAR(_17$$31);
1306 ZVAL_STRING(&_17$$31, "\\'", 0);
1307 zephir_fast_str_replace(&_14$$31, &_16$$31, &_17$$31, _15$$31 TSRMLS_CC);
1308 ZEPHIR_INIT_NVAR(exprCode);
1309 ZEPHIR_CONCAT_SVS(exprCode, "'", _14$$31, "'");
1310 break;
1311 }
1312 if (ZEPHIR_IS_LONG(type, 261)) {
1313 ZEPHIR_INIT_NVAR(exprCode);
1314 ZVAL_STRING(exprCode, "null", 1);
1315 break;
1316 }
1317 if (ZEPHIR_IS_LONG(type, 262)) {
1318 ZEPHIR_INIT_NVAR(exprCode);
1319 ZVAL_STRING(exprCode, "false", 1);
1320 break;
1321 }
1322 if (ZEPHIR_IS_LONG(type, 263)) {
1323 ZEPHIR_INIT_NVAR(exprCode);
1324 ZVAL_STRING(exprCode, "true", 1);
1325 break;
1326 }
1327 if (ZEPHIR_IS_LONG(type, 265)) {
1328 zephir_array_fetch_string(&_18$$35, expr, SL("value"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1124 TSRMLS_CC);
1329 ZEPHIR_INIT_NVAR(exprCode);
1330 ZEPHIR_CONCAT_SV(exprCode, "$", _18$$35);
1331 break;
1332 }
1333 if (ZEPHIR_IS_LONG(type, 266)) {
1334 ZEPHIR_INIT_NVAR(exprCode);
1335 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " && ", rightCode);
1336 break;
1337 }
1338 if (ZEPHIR_IS_LONG(type, 267)) {
1339 ZEPHIR_INIT_NVAR(exprCode);
1340 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " || ", rightCode);
1341 break;
1342 }
1343 if (ZEPHIR_IS_LONG(type, 270)) {
1344 ZEPHIR_INIT_NVAR(exprCode);
1345 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " <= ", rightCode);
1346 break;
1347 }
1348 if (ZEPHIR_IS_LONG(type, 271)) {
1349 ZEPHIR_INIT_NVAR(exprCode);
1350 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " >= ", rightCode);
1351 break;
1352 }
1353 if (ZEPHIR_IS_LONG(type, 272)) {
1354 ZEPHIR_INIT_NVAR(exprCode);
1355 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " == ", rightCode);
1356 break;
1357 }
1358 if (ZEPHIR_IS_LONG(type, 273)) {
1359 ZEPHIR_INIT_NVAR(exprCode);
1360 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " != ", rightCode);
1361 break;
1362 }
1363 if (ZEPHIR_IS_LONG(type, 274)) {
1364 ZEPHIR_INIT_NVAR(exprCode);
1365 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " === ", rightCode);
1366 break;
1367 }
1368 if (ZEPHIR_IS_LONG(type, 275)) {
1369 ZEPHIR_INIT_NVAR(exprCode);
1370 ZEPHIR_CONCAT_VSV(exprCode, leftCode, " !== ", rightCode);
1371 break;
1372 }
1373 if (ZEPHIR_IS_LONG(type, 276)) {
1374 ZEPHIR_INIT_NVAR(exprCode);
1375 ZEPHIR_CONCAT_SVSVS(exprCode, "range(", leftCode, ", ", rightCode, ")");
1376 break;
1377 }
1378 if (ZEPHIR_IS_LONG(type, 350)) {
1379 ZEPHIR_CALL_METHOD(&exprCode, this_ptr, "functioncall", &_19, 0, expr);
1380 zephir_check_call_status();
1381 break;
1382 }
1383 if (ZEPHIR_IS_LONG(type, 356)) {
1384 ZEPHIR_INIT_NVAR(exprCode);
1385 ZEPHIR_CONCAT_SVS(exprCode, "(", leftCode, ")");
1386 break;
1387 }
1388 if (ZEPHIR_IS_LONG(type, 361)) {
1389 ZEPHIR_INIT_NVAR(exprCode);
1390 ZEPHIR_CONCAT_VSVS(exprCode, leftCode, "[", rightCode, "]");
1391 break;
1392 }
1393 if (ZEPHIR_IS_LONG(type, 365)) {
1394 ZEPHIR_OBS_NVAR(start);
1395 if (zephir_array_isset_string_fetch(&start, expr, SS("start"), 0 TSRMLS_CC)) {
1396 ZEPHIR_CALL_METHOD(&startCode, this_ptr, "expression", &_7, 413, start);
1397 zephir_check_call_status();
1398 } else {
1399 ZEPHIR_INIT_NVAR(startCode);
1400 ZVAL_STRING(startCode, "null", 1);
1401 }
1402 ZEPHIR_OBS_NVAR(end);
1403 if (zephir_array_isset_string_fetch(&end, expr, SS("end"), 0 TSRMLS_CC)) {
1404 ZEPHIR_CALL_METHOD(&endCode, this_ptr, "expression", &_7, 413, end);
1405 zephir_check_call_status();
1406 } else {
1407 ZEPHIR_INIT_NVAR(endCode);
1408 ZVAL_STRING(endCode, "null", 1);
1409 }
1410 ZEPHIR_INIT_NVAR(exprCode);
1411 ZEPHIR_CONCAT_SVSVSVS(exprCode, "$this->slice(", leftCode, ", ", startCode, ", ", endCode, ")");
1412 break;
1413 }
1414 if (ZEPHIR_IS_LONG(type, 362)) {
1415 ZEPHIR_INIT_NVAR(exprCode);
1416 ZEPHIR_CONCAT_SVS(exprCode, "!isset(", leftCode, ")");
1417 break;
1418 }
1419 if (ZEPHIR_IS_LONG(type, 363)) {
1420 ZEPHIR_INIT_NVAR(exprCode);
1421 ZEPHIR_CONCAT_SVS(exprCode, "isset(", leftCode, ")");
1422 break;
1423 }
1424 if (ZEPHIR_IS_LONG(type, 392)) {
1425 ZEPHIR_INIT_NVAR(exprCode);
1426 ZEPHIR_CONCAT_SVS(exprCode, "!empty(", leftCode, ")");
1427 break;
1428 }
1429 if (ZEPHIR_IS_LONG(type, 386)) {
1430 ZEPHIR_INIT_NVAR(exprCode);
1431 ZEPHIR_CONCAT_SVS(exprCode, "empty(", leftCode, ")");
1432 break;
1433 }
1434 if (ZEPHIR_IS_LONG(type, 393)) {
1435 ZEPHIR_INIT_NVAR(exprCode);
1436 ZEPHIR_CONCAT_SVS(exprCode, "!(((", leftCode, ") % 2) == 0)");
1437 break;
1438 }
1439 if (ZEPHIR_IS_LONG(type, 387)) {
1440 ZEPHIR_INIT_NVAR(exprCode);
1441 ZEPHIR_CONCAT_SVS(exprCode, "(((", leftCode, ") % 2) == 0)");
1442 break;
1443 }
1444 if (ZEPHIR_IS_LONG(type, 394)) {
1445 ZEPHIR_INIT_NVAR(exprCode);
1446 ZEPHIR_CONCAT_SVS(exprCode, "!(((", leftCode, ") % 2) != 0)");
1447 break;
1448 }
1449 if (ZEPHIR_IS_LONG(type, 388)) {
1450 ZEPHIR_INIT_NVAR(exprCode);
1451 ZEPHIR_CONCAT_SVS(exprCode, "(((", leftCode, ") % 2) != 0)");
1452 break;
1453 }
1454 if (ZEPHIR_IS_LONG(type, 395)) {
1455 ZEPHIR_INIT_NVAR(exprCode);
1456 ZEPHIR_CONCAT_SVS(exprCode, "!is_numeric(", leftCode, ")");
1457 break;
1458 }
1459 if (ZEPHIR_IS_LONG(type, 389)) {
1460 ZEPHIR_INIT_NVAR(exprCode);
1461 ZEPHIR_CONCAT_SVS(exprCode, "is_numeric(", leftCode, ")");
1462 break;
1463 }
1464 if (ZEPHIR_IS_LONG(type, 396)) {
1465 ZEPHIR_INIT_NVAR(exprCode);
1466 ZEPHIR_CONCAT_SVS(exprCode, "!is_scalar(", leftCode, ")");
1467 break;
1468 }
1469 if (ZEPHIR_IS_LONG(type, 390)) {
1470 ZEPHIR_INIT_NVAR(exprCode);
1471 ZEPHIR_CONCAT_SVS(exprCode, "is_scalar(", leftCode, ")");
1472 break;
1473 }
1474 if (ZEPHIR_IS_LONG(type, 397)) {
1475 ZEPHIR_INIT_NVAR(exprCode);
1476 ZEPHIR_CONCAT_SVSVS(exprCode, "!(is_array(", leftCode, ") || (", leftCode, ") instanceof Traversable)");
1477 break;
1478 }
1479 if (ZEPHIR_IS_LONG(type, 391)) {
1480 ZEPHIR_INIT_NVAR(exprCode);
1481 ZEPHIR_CONCAT_SVSVS(exprCode, "(is_array(", leftCode, ") || (", leftCode, ") instanceof Traversable)");
1482 break;
1483 }
1484 if (ZEPHIR_IS_LONG(type, 309)) {
1485 ZEPHIR_INIT_NVAR(exprCode);
1486 ZEPHIR_CONCAT_SVSVS(exprCode, "$this->isIncluded(", leftCode, ", ", rightCode, ")");
1487 break;
1488 }
1489 if (ZEPHIR_IS_LONG(type, 367)) {
1490 ZEPHIR_INIT_NVAR(exprCode);
1491 ZEPHIR_CONCAT_SVSVS(exprCode, "!$this->isIncluded(", leftCode, ", ", rightCode, ")");
1492 break;
1493 }
1494 if (ZEPHIR_IS_LONG(type, 366)) {
1495 zephir_array_fetch_string(&_21$$69, expr, SL("ternary"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1263 TSRMLS_CC);
1496 ZEPHIR_CALL_METHOD(&_20$$69, this_ptr, "expression", &_7, 413, _21$$69);
1497 zephir_check_call_status();
1498 ZEPHIR_INIT_NVAR(exprCode);
1499 ZEPHIR_CONCAT_SVSVSVS(exprCode, "(", _20$$69, " ? ", leftCode, " : ", rightCode, ")");
1500 break;
1501 }
1502 if (ZEPHIR_IS_LONG(type, 368)) {
1503 ZEPHIR_INIT_NVAR(exprCode);
1504 ZEPHIR_CONCAT_SV(exprCode, "-", rightCode);
1505 break;
1506 }
1507 if (ZEPHIR_IS_LONG(type, 369)) {
1508 ZEPHIR_INIT_NVAR(exprCode);
1509 ZEPHIR_CONCAT_SV(exprCode, "+", rightCode);
1510 break;
1511 }
1512 if (ZEPHIR_IS_LONG(type, 364)) {
1513 ZEPHIR_OBS_NVAR(exprCode);
1514 zephir_array_fetch_string(&exprCode, expr, SL("value"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 1275 TSRMLS_CC);
1515 break;
1516 }
1517 ZEPHIR_INIT_NVAR(_22$$73);
1518 object_init_ex(_22$$73, phalcon_mvc_view_engine_volt_exception_ce);
1519 zephir_array_fetch_string(&_23$$73, expr, SL("file"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1279 TSRMLS_CC);
1520 zephir_array_fetch_string(&_24$$73, expr, SL("line"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1279 TSRMLS_CC);
1521 ZEPHIR_INIT_LNVAR(_25$$73);
1522 ZEPHIR_CONCAT_SVSVSV(_25$$73, "Unknown expression ", type, " in ", _23$$73, " on line ", _24$$73);
1523 ZEPHIR_CALL_METHOD(NULL, _22$$73, "__construct", &_26, 415, _25$$73);
1524 zephir_check_call_status();
1525 zephir_throw_exception_debug(_22$$73, "phalcon/mvc/view/engine/volt/compiler.zep", 1279 TSRMLS_CC);
1526 ZEPHIR_MM_RESTORE();
1527 return;
1528 } while(0);
1529
1530 break;
1531 }
1532 RETURN_ON_FAILURE(zephir_property_decr(this_ptr, SL("_exprLevel") TSRMLS_CC));
1533 RETURN_CCTOR(exprCode);
1534
1535 }
1536
1537 /**
1538 * Compiles a block of statements
1539 *
1540 * @param array statements
1541 * @return string|array
1542 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,_statementListOrExtends)1543 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _statementListOrExtends) {
1544
1545 HashTable *_1$$4;
1546 HashPosition _0$$4;
1547 zend_bool isStatementList = 0;
1548 zend_long ZEPHIR_LAST_CALL_STATUS;
1549 zval *statements, *statement = NULL, **_2$$4;
1550
1551 ZEPHIR_MM_GROW();
1552 zephir_fetch_params(1, 1, 0, &statements);
1553
1554
1555
1556 if (Z_TYPE_P(statements) != IS_ARRAY) {
1557 RETVAL_ZVAL(statements, 1, 0);
1558 RETURN_MM();
1559 }
1560 isStatementList = 1;
1561 if (!(zephir_array_isset_string(statements, SS("type")))) {
1562 zephir_is_iterable(statements, &_1$$4, &_0$$4, 0, 0, "phalcon/mvc/view/engine/volt/compiler.zep", 1319);
1563 for (
1564 ; zend_hash_get_current_data_ex(_1$$4, (void**) &_2$$4, &_0$$4) == SUCCESS
1565 ; zend_hash_move_forward_ex(_1$$4, &_0$$4)
1566 ) {
1567 ZEPHIR_GET_HVALUE(statement, _2$$4);
1568 if (Z_TYPE_P(statement) != IS_ARRAY) {
1569 isStatementList = 0;
1570 break;
1571 }
1572 }
1573 }
1574 if (isStatementList == 1) {
1575 ZEPHIR_RETURN_CALL_METHOD(this_ptr, "_statementlist", NULL, 419, statements);
1576 zephir_check_call_status();
1577 RETURN_MM();
1578 }
1579 RETVAL_ZVAL(statements, 1, 0);
1580 RETURN_MM();
1581
1582 }
1583
1584 /**
1585 * Compiles a "foreach" intermediate code representation into plain PHP code
1586 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileForeach)1587 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileForeach) {
1588
1589 HashTable *_1$$4;
1590 HashPosition _0$$4;
1591 zend_long ZEPHIR_LAST_CALL_STATUS;
1592 zend_bool extendsMode;
1593 zval *statement_param = NULL, *extendsMode_param = NULL, *compilation = NULL, *prefix = NULL, *level = NULL, *prefixLevel = NULL, *expr = NULL, *exprCode = NULL, *bstatement = NULL, *type = NULL, *blockStatements = NULL, *forElse = NULL, *code = NULL, *loopContext = NULL, *iterator = NULL, *key = NULL, *ifExpr = NULL, *variable = NULL, *_4, **_2$$4, *_3$$8 = NULL, *_5$$9, *_6$$9, *_7$$9, *_8$$9, *_9$$9, *_10$$9, *_11$$9, *_12$$9, *_13$$9, *_14$$11, *_15$$12, *_16$$13 = NULL, *_17$$13, *_18$$15, *_19$$15, *_20$$15, *_21$$15, *_22$$15, *_23$$15, *_24$$16, *_25$$20;
1594 zval *statement = NULL;
1595
1596 ZEPHIR_MM_GROW();
1597 zephir_fetch_params(1, 1, 1, &statement_param, &extendsMode_param);
1598
1599 statement = statement_param;
1600 if (!extendsMode_param) {
1601 extendsMode = 0;
1602 } else {
1603 extendsMode = zephir_get_boolval(extendsMode_param);
1604 }
1605
1606
1607 if (!(zephir_array_isset_string(statement, SS("expr")))) {
1608 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "Corrupted statement", "phalcon/mvc/view/engine/volt/compiler.zep", 1347);
1609 return;
1610 }
1611 ZEPHIR_INIT_VAR(compilation);
1612 ZVAL_STRING(compilation, "", 1);
1613 ZEPHIR_INIT_VAR(forElse);
1614 ZVAL_NULL(forElse);
1615 RETURN_ON_FAILURE(zephir_property_incr(this_ptr, SL("_foreachLevel") TSRMLS_CC));
1616 ZEPHIR_CALL_METHOD(&prefix, this_ptr, "getuniqueprefix", NULL, 0);
1617 zephir_check_call_status();
1618 ZEPHIR_OBS_VAR(level);
1619 zephir_read_property_this(&level, this_ptr, SL("_foreachLevel"), PH_NOISY_CC);
1620 ZEPHIR_INIT_VAR(prefixLevel);
1621 ZEPHIR_CONCAT_VV(prefixLevel, prefix, level);
1622 ZEPHIR_OBS_VAR(expr);
1623 zephir_array_fetch_string(&expr, statement, SL("expr"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 1365 TSRMLS_CC);
1624 ZEPHIR_CALL_METHOD(&exprCode, this_ptr, "expression", NULL, 413, expr);
1625 zephir_check_call_status();
1626 ZEPHIR_OBS_VAR(blockStatements);
1627 zephir_array_fetch_string(&blockStatements, statement, SL("block_statements"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 1371 TSRMLS_CC);
1628 ZEPHIR_INIT_NVAR(forElse);
1629 ZVAL_BOOL(forElse, 0);
1630 if (Z_TYPE_P(blockStatements) == IS_ARRAY) {
1631 zephir_is_iterable(blockStatements, &_1$$4, &_0$$4, 0, 0, "phalcon/mvc/view/engine/volt/compiler.zep", 1397);
1632 for (
1633 ; zend_hash_get_current_data_ex(_1$$4, (void**) &_2$$4, &_0$$4) == SUCCESS
1634 ; zend_hash_move_forward_ex(_1$$4, &_0$$4)
1635 ) {
1636 ZEPHIR_GET_HVALUE(bstatement, _2$$4);
1637 if (Z_TYPE_P(bstatement) != IS_ARRAY) {
1638 break;
1639 }
1640 ZEPHIR_OBS_NVAR(type);
1641 if (!(zephir_array_isset_string_fetch(&type, bstatement, SS("type"), 0 TSRMLS_CC))) {
1642 break;
1643 }
1644 if (ZEPHIR_IS_LONG(type, 321)) {
1645 ZEPHIR_INIT_LNVAR(_3$$8);
1646 ZEPHIR_CONCAT_SVS(_3$$8, "<?php $", prefixLevel, "iterated = false; ?>");
1647 zephir_concat_self(&compilation, _3$$8 TSRMLS_CC);
1648 ZEPHIR_CPY_WRT(forElse, prefixLevel);
1649 zephir_update_property_array(this_ptr, SL("_forElsePointers"), level, forElse TSRMLS_CC);
1650 break;
1651 }
1652 }
1653 }
1654 ZEPHIR_INIT_VAR(_4);
1655 if (extendsMode) {
1656 ZVAL_BOOL(_4, 1);
1657 } else {
1658 ZVAL_BOOL(_4, 0);
1659 }
1660 ZEPHIR_CALL_METHOD(&code, this_ptr, "_statementlist", NULL, 419, blockStatements, _4);
1661 zephir_check_call_status();
1662 ZEPHIR_OBS_VAR(loopContext);
1663 zephir_read_property_this(&loopContext, this_ptr, SL("_loopPointers"), PH_NOISY_CC);
1664 if (zephir_array_isset(loopContext, level)) {
1665 ZEPHIR_INIT_VAR(_5$$9);
1666 ZEPHIR_CONCAT_SVSVS(_5$$9, "<?php $", prefixLevel, "iterator = ", exprCode, "; ");
1667 zephir_concat_self(&compilation, _5$$9 TSRMLS_CC);
1668 ZEPHIR_INIT_VAR(_6$$9);
1669 ZEPHIR_CONCAT_SVS(_6$$9, "$", prefixLevel, "incr = 0; ");
1670 zephir_concat_self(&compilation, _6$$9 TSRMLS_CC);
1671 ZEPHIR_INIT_VAR(_7$$9);
1672 ZEPHIR_CONCAT_SVS(_7$$9, "$", prefixLevel, "loop = new stdClass(); ");
1673 zephir_concat_self(&compilation, _7$$9 TSRMLS_CC);
1674 ZEPHIR_INIT_VAR(_8$$9);
1675 ZEPHIR_CONCAT_SVSVS(_8$$9, "$", prefixLevel, "loop->self = &$", prefixLevel, "loop; ");
1676 zephir_concat_self(&compilation, _8$$9 TSRMLS_CC);
1677 ZEPHIR_INIT_VAR(_9$$9);
1678 ZEPHIR_CONCAT_SVSVS(_9$$9, "$", prefixLevel, "loop->length = count($", prefixLevel, "iterator); ");
1679 zephir_concat_self(&compilation, _9$$9 TSRMLS_CC);
1680 ZEPHIR_INIT_VAR(_10$$9);
1681 ZEPHIR_CONCAT_SVS(_10$$9, "$", prefixLevel, "loop->index = 1; ");
1682 zephir_concat_self(&compilation, _10$$9 TSRMLS_CC);
1683 ZEPHIR_INIT_VAR(_11$$9);
1684 ZEPHIR_CONCAT_SVS(_11$$9, "$", prefixLevel, "loop->index0 = 1; ");
1685 zephir_concat_self(&compilation, _11$$9 TSRMLS_CC);
1686 ZEPHIR_INIT_VAR(_12$$9);
1687 ZEPHIR_CONCAT_SVSVS(_12$$9, "$", prefixLevel, "loop->revindex = $", prefixLevel, "loop->length; ");
1688 zephir_concat_self(&compilation, _12$$9 TSRMLS_CC);
1689 ZEPHIR_INIT_VAR(_13$$9);
1690 ZEPHIR_CONCAT_SVSVS(_13$$9, "$", prefixLevel, "loop->revindex0 = $", prefixLevel, "loop->length - 1; ?>");
1691 zephir_concat_self(&compilation, _13$$9 TSRMLS_CC);
1692 ZEPHIR_INIT_VAR(iterator);
1693 ZEPHIR_CONCAT_SVS(iterator, "$", prefixLevel, "iterator");
1694 } else {
1695 ZEPHIR_CPY_WRT(iterator, exprCode);
1696 }
1697 ZEPHIR_OBS_VAR(variable);
1698 zephir_array_fetch_string(&variable, statement, SL("variable"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 1427 TSRMLS_CC);
1699 ZEPHIR_OBS_VAR(key);
1700 if (zephir_array_isset_string_fetch(&key, statement, SS("key"), 0 TSRMLS_CC)) {
1701 ZEPHIR_INIT_VAR(_14$$11);
1702 ZEPHIR_CONCAT_SVSVSVS(_14$$11, "<?php foreach (", iterator, " as $", key, " => $", variable, ") { ");
1703 zephir_concat_self(&compilation, _14$$11 TSRMLS_CC);
1704 } else {
1705 ZEPHIR_INIT_VAR(_15$$12);
1706 ZEPHIR_CONCAT_SVSVS(_15$$12, "<?php foreach (", iterator, " as $", variable, ") { ");
1707 zephir_concat_self(&compilation, _15$$12 TSRMLS_CC);
1708 }
1709 ZEPHIR_OBS_VAR(ifExpr);
1710 if (zephir_array_isset_string_fetch(&ifExpr, statement, SS("if_expr"), 0 TSRMLS_CC)) {
1711 ZEPHIR_CALL_METHOD(&_16$$13, this_ptr, "expression", NULL, 413, ifExpr);
1712 zephir_check_call_status();
1713 ZEPHIR_INIT_VAR(_17$$13);
1714 ZEPHIR_CONCAT_SVS(_17$$13, "if (", _16$$13, ") { ?>");
1715 zephir_concat_self(&compilation, _17$$13 TSRMLS_CC);
1716 } else {
1717 zephir_concat_self_str(&compilation, SL("?>") TSRMLS_CC);
1718 }
1719 if (zephir_array_isset(loopContext, level)) {
1720 ZEPHIR_INIT_VAR(_18$$15);
1721 ZEPHIR_CONCAT_SVSVS(_18$$15, "<?php $", prefixLevel, "loop->first = ($", prefixLevel, "incr == 0); ");
1722 zephir_concat_self(&compilation, _18$$15 TSRMLS_CC);
1723 ZEPHIR_INIT_VAR(_19$$15);
1724 ZEPHIR_CONCAT_SVSVS(_19$$15, "$", prefixLevel, "loop->index = $", prefixLevel, "incr + 1; ");
1725 zephir_concat_self(&compilation, _19$$15 TSRMLS_CC);
1726 ZEPHIR_INIT_VAR(_20$$15);
1727 ZEPHIR_CONCAT_SVSVS(_20$$15, "$", prefixLevel, "loop->index0 = $", prefixLevel, "incr; ");
1728 zephir_concat_self(&compilation, _20$$15 TSRMLS_CC);
1729 ZEPHIR_INIT_VAR(_21$$15);
1730 ZEPHIR_CONCAT_SVSVSVS(_21$$15, "$", prefixLevel, "loop->revindex = $", prefixLevel, "loop->length - $", prefixLevel, "incr; ");
1731 zephir_concat_self(&compilation, _21$$15 TSRMLS_CC);
1732 ZEPHIR_INIT_VAR(_22$$15);
1733 ZEPHIR_CONCAT_SVSVSVS(_22$$15, "$", prefixLevel, "loop->revindex0 = $", prefixLevel, "loop->length - ($", prefixLevel, "incr + 1); ");
1734 zephir_concat_self(&compilation, _22$$15 TSRMLS_CC);
1735 ZEPHIR_INIT_VAR(_23$$15);
1736 ZEPHIR_CONCAT_SVSVSVS(_23$$15, "$", prefixLevel, "loop->last = ($", prefixLevel, "incr == ($", prefixLevel, "loop->length - 1)); ?>");
1737 zephir_concat_self(&compilation, _23$$15 TSRMLS_CC);
1738 }
1739 if (Z_TYPE_P(forElse) == IS_STRING) {
1740 ZEPHIR_INIT_VAR(_24$$16);
1741 ZEPHIR_CONCAT_SVS(_24$$16, "<?php $", forElse, "iterated = true; ?>");
1742 zephir_concat_self(&compilation, _24$$16 TSRMLS_CC);
1743 }
1744 zephir_concat_self(&compilation, code TSRMLS_CC);
1745 if (zephir_array_isset_string(statement, SS("if_expr"))) {
1746 zephir_concat_self_str(&compilation, SL("<?php } ?>") TSRMLS_CC);
1747 }
1748 if (Z_TYPE_P(forElse) == IS_STRING) {
1749 zephir_concat_self_str(&compilation, SL("<?php } ?>") TSRMLS_CC);
1750 } else {
1751 if (zephir_array_isset(loopContext, level)) {
1752 ZEPHIR_INIT_VAR(_25$$20);
1753 ZEPHIR_CONCAT_SVS(_25$$20, "<?php $", prefixLevel, "incr++; } ?>");
1754 zephir_concat_self(&compilation, _25$$20 TSRMLS_CC);
1755 } else {
1756 zephir_concat_self_str(&compilation, SL("<?php } ?>") TSRMLS_CC);
1757 }
1758 }
1759 RETURN_ON_FAILURE(zephir_property_decr(this_ptr, SL("_foreachLevel") TSRMLS_CC));
1760 RETURN_CCTOR(compilation);
1761
1762 }
1763
1764 /**
1765 * Generates a 'forelse' PHP code
1766 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileForElse)1767 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileForElse) {
1768
1769 zval *level = NULL, *prefix = NULL, *_0, *_1$$3;
1770
1771
1772 level = zephir_fetch_nproperty_this(this_ptr, SL("_foreachLevel"), PH_NOISY_CC);
1773 _0 = zephir_fetch_nproperty_this(this_ptr, SL("_forElsePointers"), PH_NOISY_CC);
1774 if (zephir_array_isset_fetch(&prefix, _0, level, 1 TSRMLS_CC)) {
1775 _1$$3 = zephir_fetch_nproperty_this(this_ptr, SL("_loopPointers"), PH_NOISY_CC);
1776 if (zephir_array_isset(_1$$3, level)) {
1777 ZEPHIR_CONCAT_SVSVS(return_value, "<?php $", prefix, "incr++; } if (!$", prefix, "iterated) { ?>");
1778 return;
1779 }
1780 ZEPHIR_CONCAT_SVS(return_value, "<?php } if (!$", prefix, "iterated) { ?>");
1781 return;
1782 }
1783 RETURN_STRING("", 1);
1784
1785 }
1786
1787 /**
1788 * Compiles a 'if' statement returning PHP code
1789 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileIf)1790 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileIf) {
1791
1792 zend_long ZEPHIR_LAST_CALL_STATUS;
1793 zend_bool extendsMode;
1794 zval *statement_param = NULL, *extendsMode_param = NULL, *compilation = NULL, *blockStatements = NULL, *expr = NULL, *_2 = NULL, *_3 = NULL, *_4, *_5, *_0$$3, *_1$$3, *_6$$4 = NULL, *_7$$4, *_8$$4;
1795 zval *statement = NULL;
1796
1797 ZEPHIR_MM_GROW();
1798 zephir_fetch_params(1, 1, 1, &statement_param, &extendsMode_param);
1799
1800 statement = statement_param;
1801 if (!extendsMode_param) {
1802 extendsMode = 0;
1803 } else {
1804 extendsMode = zephir_get_boolval(extendsMode_param);
1805 }
1806
1807
1808 ZEPHIR_OBS_VAR(expr);
1809 if (!(zephir_array_isset_string_fetch(&expr, statement, SS("expr"), 0 TSRMLS_CC))) {
1810 ZEPHIR_INIT_VAR(_0$$3);
1811 object_init_ex(_0$$3, phalcon_mvc_view_engine_volt_exception_ce);
1812 ZEPHIR_INIT_VAR(_1$$3);
1813 ZVAL_STRING(_1$$3, "Corrupt statement", ZEPHIR_TEMP_PARAM_COPY);
1814 ZEPHIR_CALL_METHOD(NULL, _0$$3, "__construct", NULL, 415, _1$$3, statement);
1815 zephir_check_temp_parameter(_1$$3);
1816 zephir_check_call_status();
1817 zephir_throw_exception_debug(_0$$3, "phalcon/mvc/view/engine/volt/compiler.zep", 1518 TSRMLS_CC);
1818 ZEPHIR_MM_RESTORE();
1819 return;
1820 }
1821 ZEPHIR_CALL_METHOD(&_2, this_ptr, "expression", NULL, 413, expr);
1822 zephir_check_call_status();
1823 zephir_array_fetch_string(&_4, statement, SL("true_statements"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1524 TSRMLS_CC);
1824 ZEPHIR_INIT_VAR(_5);
1825 if (extendsMode) {
1826 ZVAL_BOOL(_5, 1);
1827 } else {
1828 ZVAL_BOOL(_5, 0);
1829 }
1830 ZEPHIR_CALL_METHOD(&_3, this_ptr, "_statementlist", NULL, 419, _4, _5);
1831 zephir_check_call_status();
1832 ZEPHIR_INIT_VAR(compilation);
1833 ZEPHIR_CONCAT_SVSV(compilation, "<?php if (", _2, ") { ?>", _3);
1834 ZEPHIR_OBS_VAR(blockStatements);
1835 if (zephir_array_isset_string_fetch(&blockStatements, statement, SS("false_statements"), 0 TSRMLS_CC)) {
1836 ZEPHIR_INIT_VAR(_7$$4);
1837 if (extendsMode) {
1838 ZVAL_BOOL(_7$$4, 1);
1839 } else {
1840 ZVAL_BOOL(_7$$4, 0);
1841 }
1842 ZEPHIR_CALL_METHOD(&_6$$4, this_ptr, "_statementlist", NULL, 419, blockStatements, _7$$4);
1843 zephir_check_call_status();
1844 ZEPHIR_INIT_VAR(_8$$4);
1845 ZEPHIR_CONCAT_SV(_8$$4, "<?php } else { ?>", _6$$4);
1846 zephir_concat_self(&compilation, _8$$4 TSRMLS_CC);
1847 }
1848 zephir_concat_self_str(&compilation, SL("<?php } ?>") TSRMLS_CC);
1849 RETURN_CCTOR(compilation);
1850
1851 }
1852
1853 /**
1854 * Compiles a 'switch' statement returning PHP code
1855 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileSwitch)1856 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileSwitch) {
1857
1858 zend_long ZEPHIR_LAST_CALL_STATUS;
1859 zend_bool extendsMode;
1860 zval *statement_param = NULL, *extendsMode_param = NULL, *compilation = NULL, *caseClauses = NULL, *expr = NULL, *lines = NULL, *_2 = NULL, *_0$$3, *_1$$3, *_3$$4, *_4$$5, *_5$$5, *_6$$5 = NULL;
1861 zval *statement = NULL;
1862
1863 ZEPHIR_MM_GROW();
1864 zephir_fetch_params(1, 1, 1, &statement_param, &extendsMode_param);
1865
1866 statement = statement_param;
1867 if (!extendsMode_param) {
1868 extendsMode = 0;
1869 } else {
1870 extendsMode = zephir_get_boolval(extendsMode_param);
1871 }
1872
1873
1874 ZEPHIR_OBS_VAR(expr);
1875 if (!(zephir_array_isset_string_fetch(&expr, statement, SS("expr"), 0 TSRMLS_CC))) {
1876 ZEPHIR_INIT_VAR(_0$$3);
1877 object_init_ex(_0$$3, phalcon_mvc_view_engine_volt_exception_ce);
1878 ZEPHIR_INIT_VAR(_1$$3);
1879 ZVAL_STRING(_1$$3, "Corrupt statement", ZEPHIR_TEMP_PARAM_COPY);
1880 ZEPHIR_CALL_METHOD(NULL, _0$$3, "__construct", NULL, 415, _1$$3, statement);
1881 zephir_check_temp_parameter(_1$$3);
1882 zephir_check_call_status();
1883 zephir_throw_exception_debug(_0$$3, "phalcon/mvc/view/engine/volt/compiler.zep", 1553 TSRMLS_CC);
1884 ZEPHIR_MM_RESTORE();
1885 return;
1886 }
1887 ZEPHIR_CALL_METHOD(&_2, this_ptr, "expression", NULL, 413, expr);
1888 zephir_check_call_status();
1889 ZEPHIR_INIT_VAR(compilation);
1890 ZEPHIR_CONCAT_SVS(compilation, "<?php switch (", _2, "): ?>");
1891 ZEPHIR_OBS_VAR(caseClauses);
1892 if (zephir_array_isset_string_fetch(&caseClauses, statement, SS("case_clauses"), 0 TSRMLS_CC)) {
1893 ZEPHIR_INIT_VAR(_3$$4);
1894 if (extendsMode) {
1895 ZVAL_BOOL(_3$$4, 1);
1896 } else {
1897 ZVAL_BOOL(_3$$4, 0);
1898 }
1899 ZEPHIR_CALL_METHOD(&lines, this_ptr, "_statementlist", NULL, 419, caseClauses, _3$$4);
1900 zephir_check_call_status();
1901 if (zephir_fast_strlen_ev(lines) != 0) {
1902 ZEPHIR_INIT_VAR(_4$$5);
1903 ZVAL_STRING(_4$$5, "/(*ANYCRLF)^\\h+|\\h+$|(\\h){2,}/mu", ZEPHIR_TEMP_PARAM_COPY);
1904 ZEPHIR_INIT_VAR(_5$$5);
1905 ZVAL_STRING(_5$$5, "", ZEPHIR_TEMP_PARAM_COPY);
1906 ZEPHIR_CALL_FUNCTION(&_6$$5, "preg_replace", NULL, 42, _4$$5, _5$$5, lines);
1907 zephir_check_temp_parameter(_4$$5);
1908 zephir_check_temp_parameter(_5$$5);
1909 zephir_check_call_status();
1910 ZEPHIR_CPY_WRT(lines, _6$$5);
1911 }
1912 zephir_concat_self(&compilation, lines TSRMLS_CC);
1913 }
1914 zephir_concat_self_str(&compilation, SL("<?php endswitch ?>") TSRMLS_CC);
1915 RETURN_CCTOR(compilation);
1916
1917 }
1918
1919 /**
1920 * Compiles a "case"/"default" clause returning PHP code
1921 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileCase)1922 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileCase) {
1923
1924 zend_long ZEPHIR_LAST_CALL_STATUS;
1925 zend_bool caseClause;
1926 zval *statement_param = NULL, *caseClause_param = NULL, *expr = NULL, *_2 = NULL, *_0$$4, *_1$$4;
1927 zval *statement = NULL;
1928
1929 ZEPHIR_MM_GROW();
1930 zephir_fetch_params(1, 1, 1, &statement_param, &caseClause_param);
1931
1932 statement = statement_param;
1933 if (!caseClause_param) {
1934 caseClause = 1;
1935 } else {
1936 caseClause = zephir_get_boolval(caseClause_param);
1937 }
1938
1939
1940 if (UNEXPECTED(caseClause == 0)) {
1941 RETURN_MM_STRING("<?php default: ?>", 1);
1942 }
1943 ZEPHIR_OBS_VAR(expr);
1944 if (!(zephir_array_isset_string_fetch(&expr, statement, SS("expr"), 0 TSRMLS_CC))) {
1945 ZEPHIR_INIT_VAR(_0$$4);
1946 object_init_ex(_0$$4, phalcon_mvc_view_engine_volt_exception_ce);
1947 ZEPHIR_INIT_VAR(_1$$4);
1948 ZVAL_STRING(_1$$4, "Corrupt statement", ZEPHIR_TEMP_PARAM_COPY);
1949 ZEPHIR_CALL_METHOD(NULL, _0$$4, "__construct", NULL, 415, _1$$4, statement);
1950 zephir_check_temp_parameter(_1$$4);
1951 zephir_check_call_status();
1952 zephir_throw_exception_debug(_0$$4, "phalcon/mvc/view/engine/volt/compiler.zep", 1613 TSRMLS_CC);
1953 ZEPHIR_MM_RESTORE();
1954 return;
1955 }
1956 ZEPHIR_CALL_METHOD(&_2, this_ptr, "expression", NULL, 413, expr);
1957 zephir_check_call_status();
1958 ZEPHIR_CONCAT_SVS(return_value, "<?php case ", _2, ": ?>");
1959 RETURN_MM();
1960
1961 }
1962
1963 /**
1964 * Compiles a "elseif" statement returning PHP code
1965 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileElseIf)1966 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileElseIf) {
1967
1968 zend_long ZEPHIR_LAST_CALL_STATUS;
1969 zval *statement_param = NULL, *expr = NULL, *_2 = NULL, *_0$$3, *_1$$3;
1970 zval *statement = NULL;
1971
1972 ZEPHIR_MM_GROW();
1973 zephir_fetch_params(1, 1, 0, &statement_param);
1974
1975 statement = statement_param;
1976
1977
1978 ZEPHIR_OBS_VAR(expr);
1979 if (!(zephir_array_isset_string_fetch(&expr, statement, SS("expr"), 0 TSRMLS_CC))) {
1980 ZEPHIR_INIT_VAR(_0$$3);
1981 object_init_ex(_0$$3, phalcon_mvc_view_engine_volt_exception_ce);
1982 ZEPHIR_INIT_VAR(_1$$3);
1983 ZVAL_STRING(_1$$3, "Corrupt statement", ZEPHIR_TEMP_PARAM_COPY);
1984 ZEPHIR_CALL_METHOD(NULL, _0$$3, "__construct", NULL, 415, _1$$3, statement);
1985 zephir_check_temp_parameter(_1$$3);
1986 zephir_check_call_status();
1987 zephir_throw_exception_debug(_0$$3, "phalcon/mvc/view/engine/volt/compiler.zep", 1633 TSRMLS_CC);
1988 ZEPHIR_MM_RESTORE();
1989 return;
1990 }
1991 ZEPHIR_CALL_METHOD(&_2, this_ptr, "expression", NULL, 413, expr);
1992 zephir_check_call_status();
1993 ZEPHIR_CONCAT_SVS(return_value, "<?php } elseif (", _2, ") { ?>");
1994 RETURN_MM();
1995
1996 }
1997
1998 /**
1999 * Compiles a "cache" statement returning PHP code
2000 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileCache)2001 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileCache) {
2002
2003 zend_long ZEPHIR_LAST_CALL_STATUS;
2004 zend_bool extendsMode;
2005 zval *statement_param = NULL, *extendsMode_param = NULL, *compilation = NULL, *expr = NULL, *exprCode = NULL, *lifetime = NULL, *_2 = NULL, *_10, *_11 = NULL, *_12, *_13, *_0$$3, *_1$$3, *_3$$4, *_4$$4, *_5$$5, *_6$$5, *_7$$6, *_8$$6, *_9$$7, *_14$$8, *_19$$8, *_15$$9, *_16$$9, *_17$$10, *_18$$10, *_20$$11;
2006 zval *statement = NULL;
2007
2008 ZEPHIR_MM_GROW();
2009 zephir_fetch_params(1, 1, 1, &statement_param, &extendsMode_param);
2010
2011 statement = statement_param;
2012 if (!extendsMode_param) {
2013 extendsMode = 0;
2014 } else {
2015 extendsMode = zephir_get_boolval(extendsMode_param);
2016 }
2017
2018
2019 ZEPHIR_OBS_VAR(expr);
2020 if (!(zephir_array_isset_string_fetch(&expr, statement, SS("expr"), 0 TSRMLS_CC))) {
2021 ZEPHIR_INIT_VAR(_0$$3);
2022 object_init_ex(_0$$3, phalcon_mvc_view_engine_volt_exception_ce);
2023 ZEPHIR_INIT_VAR(_1$$3);
2024 ZVAL_STRING(_1$$3, "Corrupt statement", ZEPHIR_TEMP_PARAM_COPY);
2025 ZEPHIR_CALL_METHOD(NULL, _0$$3, "__construct", NULL, 415, _1$$3, statement);
2026 zephir_check_temp_parameter(_1$$3);
2027 zephir_check_call_status();
2028 zephir_throw_exception_debug(_0$$3, "phalcon/mvc/view/engine/volt/compiler.zep", 1653 TSRMLS_CC);
2029 ZEPHIR_MM_RESTORE();
2030 return;
2031 }
2032 ZEPHIR_CALL_METHOD(&exprCode, this_ptr, "expression", NULL, 413, expr);
2033 zephir_check_call_status();
2034 ZEPHIR_CALL_METHOD(&_2, this_ptr, "expression", NULL, 413, expr);
2035 zephir_check_call_status();
2036 ZEPHIR_INIT_VAR(compilation);
2037 ZEPHIR_CONCAT_SVS(compilation, "<?php $_cache[", _2, "] = $this->di->get('viewCache'); ");
2038 ZEPHIR_OBS_VAR(lifetime);
2039 if (zephir_array_isset_string_fetch(&lifetime, statement, SS("lifetime"), 0 TSRMLS_CC)) {
2040 ZEPHIR_INIT_VAR(_3$$4);
2041 ZEPHIR_CONCAT_SVS(_3$$4, "$_cacheKey[", exprCode, "]");
2042 zephir_concat_self(&compilation, _3$$4 TSRMLS_CC);
2043 zephir_array_fetch_string(&_4$$4, lifetime, SL("type"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1663 TSRMLS_CC);
2044 if (ZEPHIR_IS_LONG(_4$$4, 265)) {
2045 zephir_array_fetch_string(&_5$$5, lifetime, SL("value"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1664 TSRMLS_CC);
2046 ZEPHIR_INIT_VAR(_6$$5);
2047 ZEPHIR_CONCAT_SVSVSVS(_6$$5, " = $_cache[", exprCode, "]->start(", exprCode, ", $", _5$$5, "); ");
2048 zephir_concat_self(&compilation, _6$$5 TSRMLS_CC);
2049 } else {
2050 zephir_array_fetch_string(&_7$$6, lifetime, SL("value"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1666 TSRMLS_CC);
2051 ZEPHIR_INIT_VAR(_8$$6);
2052 ZEPHIR_CONCAT_SVSVSVS(_8$$6, " = $_cache[", exprCode, "]->start(", exprCode, ", ", _7$$6, "); ");
2053 zephir_concat_self(&compilation, _8$$6 TSRMLS_CC);
2054 }
2055 } else {
2056 ZEPHIR_INIT_VAR(_9$$7);
2057 ZEPHIR_CONCAT_SVSVSVS(_9$$7, "$_cacheKey[", exprCode, "] = $_cache[", exprCode, "]->start(", exprCode, "); ");
2058 zephir_concat_self(&compilation, _9$$7 TSRMLS_CC);
2059 }
2060 ZEPHIR_INIT_VAR(_10);
2061 ZEPHIR_CONCAT_SVS(_10, "if ($_cacheKey[", exprCode, "] === null) { ?>");
2062 zephir_concat_self(&compilation, _10 TSRMLS_CC);
2063 zephir_array_fetch_string(&_12, statement, SL("block_statements"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1676 TSRMLS_CC);
2064 ZEPHIR_INIT_VAR(_13);
2065 if (extendsMode) {
2066 ZVAL_BOOL(_13, 1);
2067 } else {
2068 ZVAL_BOOL(_13, 0);
2069 }
2070 ZEPHIR_CALL_METHOD(&_11, this_ptr, "_statementlist", NULL, 419, _12, _13);
2071 zephir_check_call_status();
2072 zephir_concat_self(&compilation, _11 TSRMLS_CC);
2073 ZEPHIR_OBS_NVAR(lifetime);
2074 if (zephir_array_isset_string_fetch(&lifetime, statement, SS("lifetime"), 0 TSRMLS_CC)) {
2075 zephir_array_fetch_string(&_14$$8, lifetime, SL("type"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1682 TSRMLS_CC);
2076 if (ZEPHIR_IS_LONG(_14$$8, 265)) {
2077 zephir_array_fetch_string(&_15$$9, lifetime, SL("value"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1683 TSRMLS_CC);
2078 ZEPHIR_INIT_VAR(_16$$9);
2079 ZEPHIR_CONCAT_SVSVSVS(_16$$9, "<?php $_cache[", exprCode, "]->save(", exprCode, ", null, $", _15$$9, "); ");
2080 zephir_concat_self(&compilation, _16$$9 TSRMLS_CC);
2081 } else {
2082 zephir_array_fetch_string(&_17$$10, lifetime, SL("value"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1685 TSRMLS_CC);
2083 ZEPHIR_INIT_VAR(_18$$10);
2084 ZEPHIR_CONCAT_SVSVSVS(_18$$10, "<?php $_cache[", exprCode, "]->save(", exprCode, ", null, ", _17$$10, "); ");
2085 zephir_concat_self(&compilation, _18$$10 TSRMLS_CC);
2086 }
2087 ZEPHIR_INIT_VAR(_19$$8);
2088 ZEPHIR_CONCAT_SVS(_19$$8, "} else { echo $_cacheKey[", exprCode, "]; } ?>");
2089 zephir_concat_self(&compilation, _19$$8 TSRMLS_CC);
2090 } else {
2091 ZEPHIR_INIT_VAR(_20$$11);
2092 ZEPHIR_CONCAT_SVSVSVS(_20$$11, "<?php $_cache[", exprCode, "]->save(", exprCode, "); } else { echo $_cacheKey[", exprCode, "]; } ?>");
2093 zephir_concat_self(&compilation, _20$$11 TSRMLS_CC);
2094 }
2095 RETURN_CCTOR(compilation);
2096
2097 }
2098
2099 /**
2100 * Compiles a "set" statement returning PHP code
2101 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileSet)2102 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileSet) {
2103
2104 HashTable *_1;
2105 HashPosition _0;
2106 zephir_fcall_cache_entry *_4 = NULL;
2107 zend_long ZEPHIR_LAST_CALL_STATUS;
2108 zval *statement_param = NULL, *assignments = NULL, *assignment = NULL, *exprCode = NULL, *target = NULL, *compilation = NULL, **_2, *_3$$4, *_5$$4, *_6$$4, *_7$$5 = NULL, *_8$$6 = NULL, *_9$$7 = NULL, *_10$$8 = NULL, *_11$$9 = NULL;
2109 zval *statement = NULL;
2110
2111 ZEPHIR_MM_GROW();
2112 zephir_fetch_params(1, 1, 0, &statement_param);
2113
2114 statement = statement_param;
2115
2116
2117 ZEPHIR_OBS_VAR(assignments);
2118 if (!(zephir_array_isset_string_fetch(&assignments, statement, SS("assignments"), 0 TSRMLS_CC))) {
2119 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "Corrupted statement", "phalcon/mvc/view/engine/volt/compiler.zep", 1706);
2120 return;
2121 }
2122 ZEPHIR_INIT_VAR(compilation);
2123 ZVAL_STRING(compilation, "<?php", 1);
2124 zephir_is_iterable(assignments, &_1, &_0, 0, 0, "phalcon/mvc/view/engine/volt/compiler.zep", 1752);
2125 for (
2126 ; zend_hash_get_current_data_ex(_1, (void**) &_2, &_0) == SUCCESS
2127 ; zend_hash_move_forward_ex(_1, &_0)
2128 ) {
2129 ZEPHIR_GET_HVALUE(assignment, _2);
2130 zephir_array_fetch_string(&_3$$4, assignment, SL("expr"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1716 TSRMLS_CC);
2131 ZEPHIR_CALL_METHOD(&exprCode, this_ptr, "expression", &_4, 413, _3$$4);
2132 zephir_check_call_status();
2133 zephir_array_fetch_string(&_5$$4, assignment, SL("variable"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1721 TSRMLS_CC);
2134 ZEPHIR_CALL_METHOD(&target, this_ptr, "expression", &_4, 413, _5$$4);
2135 zephir_check_call_status();
2136 zephir_array_fetch_string(&_6$$4, assignment, SL("op"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1727 TSRMLS_CC);
2137 do {
2138 if (ZEPHIR_IS_LONG(_6$$4, 281)) {
2139 ZEPHIR_INIT_LNVAR(_7$$5);
2140 ZEPHIR_CONCAT_SVSVS(_7$$5, " ", target, " += ", exprCode, ";");
2141 zephir_concat_self(&compilation, _7$$5 TSRMLS_CC);
2142 break;
2143 }
2144 if (ZEPHIR_IS_LONG(_6$$4, 282)) {
2145 ZEPHIR_INIT_LNVAR(_8$$6);
2146 ZEPHIR_CONCAT_SVSVS(_8$$6, " ", target, " -= ", exprCode, ";");
2147 zephir_concat_self(&compilation, _8$$6 TSRMLS_CC);
2148 break;
2149 }
2150 if (ZEPHIR_IS_LONG(_6$$4, 283)) {
2151 ZEPHIR_INIT_LNVAR(_9$$7);
2152 ZEPHIR_CONCAT_SVSVS(_9$$7, " ", target, " *= ", exprCode, ";");
2153 zephir_concat_self(&compilation, _9$$7 TSRMLS_CC);
2154 break;
2155 }
2156 if (ZEPHIR_IS_LONG(_6$$4, 284)) {
2157 ZEPHIR_INIT_LNVAR(_10$$8);
2158 ZEPHIR_CONCAT_SVSVS(_10$$8, " ", target, " /= ", exprCode, ";");
2159 zephir_concat_self(&compilation, _10$$8 TSRMLS_CC);
2160 break;
2161 }
2162 ZEPHIR_INIT_LNVAR(_11$$9);
2163 ZEPHIR_CONCAT_SVSVS(_11$$9, " ", target, " = ", exprCode, ";");
2164 zephir_concat_self(&compilation, _11$$9 TSRMLS_CC);
2165 break;
2166 } while(0);
2167
2168 }
2169 zephir_concat_self_str(&compilation, SL(" ?>") TSRMLS_CC);
2170 RETURN_CCTOR(compilation);
2171
2172 }
2173
2174 /**
2175 * Compiles a "do" statement returning PHP code
2176 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileDo)2177 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileDo) {
2178
2179 zend_long ZEPHIR_LAST_CALL_STATUS;
2180 zval *statement_param = NULL, *expr = NULL, *_0 = NULL;
2181 zval *statement = NULL;
2182
2183 ZEPHIR_MM_GROW();
2184 zephir_fetch_params(1, 1, 0, &statement_param);
2185
2186 statement = statement_param;
2187
2188
2189 ZEPHIR_OBS_VAR(expr);
2190 if (!(zephir_array_isset_string_fetch(&expr, statement, SS("expr"), 0 TSRMLS_CC))) {
2191 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "Corrupted statement", "phalcon/mvc/view/engine/volt/compiler.zep", 1767);
2192 return;
2193 }
2194 ZEPHIR_CALL_METHOD(&_0, this_ptr, "expression", NULL, 413, expr);
2195 zephir_check_call_status();
2196 ZEPHIR_CONCAT_SVS(return_value, "<?php ", _0, "; ?>");
2197 RETURN_MM();
2198
2199 }
2200
2201 /**
2202 * Compiles a "return" statement returning PHP code
2203 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileReturn)2204 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileReturn) {
2205
2206 zend_long ZEPHIR_LAST_CALL_STATUS;
2207 zval *statement_param = NULL, *expr = NULL, *_0 = NULL;
2208 zval *statement = NULL;
2209
2210 ZEPHIR_MM_GROW();
2211 zephir_fetch_params(1, 1, 0, &statement_param);
2212
2213 statement = statement_param;
2214
2215
2216 ZEPHIR_OBS_VAR(expr);
2217 if (!(zephir_array_isset_string_fetch(&expr, statement, SS("expr"), 0 TSRMLS_CC))) {
2218 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "Corrupted statement", "phalcon/mvc/view/engine/volt/compiler.zep", 1787);
2219 return;
2220 }
2221 ZEPHIR_CALL_METHOD(&_0, this_ptr, "expression", NULL, 413, expr);
2222 zephir_check_call_status();
2223 ZEPHIR_CONCAT_SVS(return_value, "<?php return ", _0, "; ?>");
2224 RETURN_MM();
2225
2226 }
2227
2228 /**
2229 * Compiles a "autoescape" statement returning PHP code
2230 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileAutoEscape)2231 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileAutoEscape) {
2232
2233 zend_long ZEPHIR_LAST_CALL_STATUS;
2234 zend_bool extendsMode;
2235 zval *statement_param = NULL, *extendsMode_param = NULL, *autoescape = NULL, *oldAutoescape = NULL, *compilation = NULL, *_0, *_1;
2236 zval *statement = NULL;
2237
2238 ZEPHIR_MM_GROW();
2239 zephir_fetch_params(1, 2, 0, &statement_param, &extendsMode_param);
2240
2241 statement = statement_param;
2242 extendsMode = zephir_get_boolval(extendsMode_param);
2243
2244
2245 ZEPHIR_OBS_VAR(autoescape);
2246 if (!(zephir_array_isset_string_fetch(&autoescape, statement, SS("enable"), 0 TSRMLS_CC))) {
2247 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "Corrupted statement", "phalcon/mvc/view/engine/volt/compiler.zep", 1807);
2248 return;
2249 }
2250 ZEPHIR_OBS_VAR(oldAutoescape);
2251 zephir_read_property_this(&oldAutoescape, this_ptr, SL("_autoescape"), PH_NOISY_CC);
2252 zephir_update_property_this(getThis(), SL("_autoescape"), autoescape TSRMLS_CC);
2253 zephir_array_fetch_string(&_0, statement, SL("block_statements"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1816 TSRMLS_CC);
2254 ZEPHIR_INIT_VAR(_1);
2255 if (extendsMode) {
2256 ZVAL_BOOL(_1, 1);
2257 } else {
2258 ZVAL_BOOL(_1, 0);
2259 }
2260 ZEPHIR_CALL_METHOD(&compilation, this_ptr, "_statementlist", NULL, 419, _0, _1);
2261 zephir_check_call_status();
2262 zephir_update_property_this(getThis(), SL("_autoescape"), oldAutoescape TSRMLS_CC);
2263 RETURN_CCTOR(compilation);
2264
2265 }
2266
2267 /**
2268 * Compiles a '{{' '}}' statement returning PHP code
2269 *
2270 * @param array statement
2271 * @param boolean extendsMode
2272 * @return string
2273 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileEcho)2274 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileEcho) {
2275
2276 zend_long ZEPHIR_LAST_CALL_STATUS;
2277 zval *statement_param = NULL, *expr = NULL, *exprCode = NULL, *name = NULL, *_2, *_5, *_0$$3, *_1$$3, *_3$$4, *_4$$5;
2278 zval *statement = NULL;
2279
2280 ZEPHIR_MM_GROW();
2281 zephir_fetch_params(1, 1, 0, &statement_param);
2282
2283 statement = statement_param;
2284
2285
2286 ZEPHIR_OBS_VAR(expr);
2287 if (!(zephir_array_isset_string_fetch(&expr, statement, SS("expr"), 0 TSRMLS_CC))) {
2288 ZEPHIR_INIT_VAR(_0$$3);
2289 object_init_ex(_0$$3, phalcon_mvc_view_engine_volt_exception_ce);
2290 ZEPHIR_INIT_VAR(_1$$3);
2291 ZVAL_STRING(_1$$3, "Corrupt statement", ZEPHIR_TEMP_PARAM_COPY);
2292 ZEPHIR_CALL_METHOD(NULL, _0$$3, "__construct", NULL, 415, _1$$3, statement);
2293 zephir_check_temp_parameter(_1$$3);
2294 zephir_check_call_status();
2295 zephir_throw_exception_debug(_0$$3, "phalcon/mvc/view/engine/volt/compiler.zep", 1837 TSRMLS_CC);
2296 ZEPHIR_MM_RESTORE();
2297 return;
2298 }
2299 ZEPHIR_CALL_METHOD(&exprCode, this_ptr, "expression", NULL, 413, expr);
2300 zephir_check_call_status();
2301 zephir_array_fetch_string(&_2, expr, SL("type"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1845 TSRMLS_CC);
2302 if (ZEPHIR_IS_LONG(_2, 350)) {
2303 zephir_array_fetch_string(&name, expr, SL("name"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1847 TSRMLS_CC);
2304 zephir_array_fetch_string(&_3$$4, name, SL("type"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1849 TSRMLS_CC);
2305 if (ZEPHIR_IS_LONG(_3$$4, 265)) {
2306 zephir_array_fetch_string(&_4$$5, name, SL("value"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1854 TSRMLS_CC);
2307 if (ZEPHIR_IS_STRING(_4$$5, "super")) {
2308 RETURN_CCTOR(exprCode);
2309 }
2310 }
2311 }
2312 _5 = zephir_fetch_nproperty_this(this_ptr, SL("_autoescape"), PH_NOISY_CC);
2313 if (zephir_is_true(_5)) {
2314 ZEPHIR_CONCAT_SVS(return_value, "<?= $this->escaper->escapeHtml(", exprCode, ") ?>");
2315 RETURN_MM();
2316 }
2317 ZEPHIR_CONCAT_SVS(return_value, "<?= ", exprCode, " ?>");
2318 RETURN_MM();
2319
2320 }
2321
2322 /**
2323 * Compiles a 'include' statement returning PHP code
2324 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileInclude)2325 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileInclude) {
2326
2327 zend_long ZEPHIR_LAST_CALL_STATUS;
2328 zval *statement_param = NULL, *pathExpr = NULL, *path = NULL, *subCompiler = NULL, *finalPath = NULL, *compilation = NULL, *params = NULL, *_0, *_3 = NULL, *_1$$5, *_2$$6 = NULL;
2329 zval *statement = NULL;
2330
2331 ZEPHIR_MM_GROW();
2332 zephir_fetch_params(1, 1, 0, &statement_param);
2333
2334 statement = statement_param;
2335
2336
2337 ZEPHIR_OBS_VAR(pathExpr);
2338 if (!(zephir_array_isset_string_fetch(&pathExpr, statement, SS("path"), 0 TSRMLS_CC))) {
2339 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "Corrupted statement", "phalcon/mvc/view/engine/volt/compiler.zep", 1882);
2340 return;
2341 }
2342 zephir_array_fetch_string(&_0, pathExpr, SL("type"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 1889 TSRMLS_CC);
2343 if (ZEPHIR_IS_LONG(_0, 260)) {
2344 if (!(zephir_array_isset_string(statement, SS("params")))) {
2345 ZEPHIR_OBS_VAR(path);
2346 zephir_array_fetch_string(&path, pathExpr, SL("value"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 1899 TSRMLS_CC);
2347 ZEPHIR_CALL_METHOD(&finalPath, this_ptr, "getfinalpath", NULL, 0, path);
2348 zephir_check_call_status();
2349 ZEPHIR_INIT_VAR(subCompiler);
2350 if (zephir_clone(subCompiler, this_ptr TSRMLS_CC) == FAILURE) {
2351 RETURN_MM();
2352 }
2353 ZEPHIR_INIT_VAR(_1$$5);
2354 ZVAL_BOOL(_1$$5, 0);
2355 ZEPHIR_CALL_METHOD(&compilation, subCompiler, "compile", NULL, 0, finalPath, _1$$5);
2356 zephir_check_call_status();
2357 if (Z_TYPE_P(compilation) == IS_NULL) {
2358 ZEPHIR_CALL_METHOD(&_2$$6, subCompiler, "getcompiledtemplatepath", NULL, 0);
2359 zephir_check_call_status();
2360 ZEPHIR_INIT_NVAR(compilation);
2361 zephir_file_get_contents(compilation, _2$$6 TSRMLS_CC);
2362 }
2363 RETURN_CCTOR(compilation);
2364 }
2365 }
2366 ZEPHIR_CALL_METHOD(&path, this_ptr, "expression", NULL, 413, pathExpr);
2367 zephir_check_call_status();
2368 ZEPHIR_OBS_VAR(params);
2369 if (!(zephir_array_isset_string_fetch(¶ms, statement, SS("params"), 0 TSRMLS_CC))) {
2370 ZEPHIR_CONCAT_SVS(return_value, "<?php $this->partial(", path, "); ?>");
2371 RETURN_MM();
2372 }
2373 ZEPHIR_CALL_METHOD(&_3, this_ptr, "expression", NULL, 413, params);
2374 zephir_check_call_status();
2375 ZEPHIR_CONCAT_SVSVS(return_value, "<?php $this->partial(", path, ", ", _3, "); ?>");
2376 RETURN_MM();
2377
2378 }
2379
2380 /**
2381 * Compiles macros
2382 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileMacro)2383 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileMacro) {
2384
2385 HashTable *_6$$6;
2386 HashPosition _5$$6;
2387 zephir_fcall_cache_entry *_13 = NULL;
2388 zend_long ZEPHIR_LAST_CALL_STATUS;
2389 zend_bool extendsMode;
2390 zval *statement_param = NULL, *extendsMode_param = NULL, *code = NULL, *name = NULL, *defaultValue = NULL, *macroName = NULL, *parameters = NULL, *position = NULL, *parameter = NULL, *variableName = NULL, *blockStatements = NULL, *_0, *_19, *_1$$4, *_2$$4, *_3$$5, *_4$$6, **_7$$6, *_8$$7 = NULL, *_9$$7 = NULL, *_10$$7 = NULL, *_11$$7 = NULL, *_12$$8 = NULL, *_14$$8 = NULL, *_15$$9 = NULL, *_16$$10 = NULL, *_17$$10, *_18$$10;
2391 zval *statement = NULL;
2392
2393 ZEPHIR_MM_GROW();
2394 zephir_fetch_params(1, 2, 0, &statement_param, &extendsMode_param);
2395
2396 statement = statement_param;
2397 extendsMode = zephir_get_boolval(extendsMode_param);
2398
2399
2400 ZEPHIR_OBS_VAR(name);
2401 if (!(zephir_array_isset_string_fetch(&name, statement, SS("name"), 0 TSRMLS_CC))) {
2402 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "Corrupted statement", "phalcon/mvc/view/engine/volt/compiler.zep", 1949);
2403 return;
2404 }
2405 _0 = zephir_fetch_nproperty_this(this_ptr, SL("_macros"), PH_NOISY_CC);
2406 if (zephir_array_isset(_0, name)) {
2407 ZEPHIR_INIT_VAR(_1$$4);
2408 object_init_ex(_1$$4, phalcon_mvc_view_engine_volt_exception_ce);
2409 ZEPHIR_INIT_VAR(_2$$4);
2410 ZEPHIR_CONCAT_SVS(_2$$4, "Macro '", name, "' is already defined");
2411 ZEPHIR_CALL_METHOD(NULL, _1$$4, "__construct", NULL, 415, _2$$4);
2412 zephir_check_call_status();
2413 zephir_throw_exception_debug(_1$$4, "phalcon/mvc/view/engine/volt/compiler.zep", 1956 TSRMLS_CC);
2414 ZEPHIR_MM_RESTORE();
2415 return;
2416 }
2417 zephir_update_property_array(this_ptr, SL("_macros"), name, name TSRMLS_CC);
2418 ZEPHIR_INIT_VAR(macroName);
2419 ZEPHIR_CONCAT_SVS(macroName, "$this->_macros['", name, "']");
2420 ZEPHIR_INIT_VAR(code);
2421 ZVAL_STRING(code, "<?php ", 1);
2422 ZEPHIR_OBS_VAR(parameters);
2423 if (!(zephir_array_isset_string_fetch(¶meters, statement, SS("parameters"), 0 TSRMLS_CC))) {
2424 ZEPHIR_INIT_VAR(_3$$5);
2425 ZEPHIR_CONCAT_VS(_3$$5, macroName, " = function() { ?>");
2426 zephir_concat_self(&code, _3$$5 TSRMLS_CC);
2427 } else {
2428 ZEPHIR_INIT_VAR(_4$$6);
2429 ZEPHIR_CONCAT_VS(_4$$6, macroName, " = function($__p = null) { ");
2430 zephir_concat_self(&code, _4$$6 TSRMLS_CC);
2431 zephir_is_iterable(parameters, &_6$$6, &_5$$6, 0, 0, "phalcon/mvc/view/engine/volt/compiler.zep", 1994);
2432 for (
2433 ; zend_hash_get_current_data_ex(_6$$6, (void**) &_7$$6, &_5$$6) == SUCCESS
2434 ; zend_hash_move_forward_ex(_6$$6, &_5$$6)
2435 ) {
2436 ZEPHIR_GET_HMKEY(position, _6$$6, _5$$6);
2437 ZEPHIR_GET_HVALUE(parameter, _7$$6);
2438 ZEPHIR_OBS_NVAR(variableName);
2439 zephir_array_fetch_string(&variableName, parameter, SL("variable"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 1978 TSRMLS_CC);
2440 ZEPHIR_INIT_LNVAR(_8$$7);
2441 ZEPHIR_CONCAT_SVS(_8$$7, "if (isset($__p[", position, "])) { ");
2442 zephir_concat_self(&code, _8$$7 TSRMLS_CC);
2443 ZEPHIR_INIT_LNVAR(_9$$7);
2444 ZEPHIR_CONCAT_SVSVS(_9$$7, "$", variableName, " = $__p[", position, "];");
2445 zephir_concat_self(&code, _9$$7 TSRMLS_CC);
2446 zephir_concat_self_str(&code, SL(" } else { ") TSRMLS_CC);
2447 ZEPHIR_INIT_LNVAR(_10$$7);
2448 ZEPHIR_CONCAT_SVS(_10$$7, "if (isset($__p[\"", variableName, "\"])) { ");
2449 zephir_concat_self(&code, _10$$7 TSRMLS_CC);
2450 ZEPHIR_INIT_LNVAR(_11$$7);
2451 ZEPHIR_CONCAT_SVSVS(_11$$7, "$", variableName, " = $__p[\"", variableName, "\"];");
2452 zephir_concat_self(&code, _11$$7 TSRMLS_CC);
2453 zephir_concat_self_str(&code, SL(" } else { ") TSRMLS_CC);
2454 ZEPHIR_OBS_NVAR(defaultValue);
2455 if (zephir_array_isset_string_fetch(&defaultValue, parameter, SS("default"), 0 TSRMLS_CC)) {
2456 ZEPHIR_CALL_METHOD(&_12$$8, this_ptr, "expression", &_13, 413, defaultValue);
2457 zephir_check_call_status();
2458 ZEPHIR_INIT_LNVAR(_14$$8);
2459 ZEPHIR_CONCAT_SVSVS(_14$$8, "$", variableName, " = ", _12$$8, ";");
2460 zephir_concat_self(&code, _14$$8 TSRMLS_CC);
2461 } else {
2462 ZEPHIR_INIT_LNVAR(_15$$9);
2463 ZEPHIR_CONCAT_SVSVS(_15$$9, " throw new \\Phalcon\\Mvc\\View\\Exception(\"Macro '", name, "' was called without parameter: ", variableName, "\"); ");
2464 zephir_concat_self(&code, _15$$9 TSRMLS_CC);
2465 }
2466 zephir_concat_self_str(&code, SL(" } } ") TSRMLS_CC);
2467 }
2468 zephir_concat_self_str(&code, SL(" ?>") TSRMLS_CC);
2469 }
2470 ZEPHIR_OBS_VAR(blockStatements);
2471 if (zephir_array_isset_string_fetch(&blockStatements, statement, SS("block_statements"), 0 TSRMLS_CC)) {
2472 ZEPHIR_INIT_VAR(_17$$10);
2473 if (extendsMode) {
2474 ZVAL_BOOL(_17$$10, 1);
2475 } else {
2476 ZVAL_BOOL(_17$$10, 0);
2477 }
2478 ZEPHIR_CALL_METHOD(&_16$$10, this_ptr, "_statementlist", NULL, 419, blockStatements, _17$$10);
2479 zephir_check_call_status();
2480 ZEPHIR_INIT_VAR(_18$$10);
2481 ZEPHIR_CONCAT_VS(_18$$10, _16$$10, "<?php }; ");
2482 zephir_concat_self(&code, _18$$10 TSRMLS_CC);
2483 } else {
2484 zephir_concat_self_str(&code, SL("<?php }; ") TSRMLS_CC);
2485 }
2486 ZEPHIR_INIT_VAR(_19);
2487 ZEPHIR_CONCAT_VSVS(_19, macroName, " = \\Closure::bind(", macroName, ", $this); ?>");
2488 zephir_concat_self(&code, _19 TSRMLS_CC);
2489 RETURN_CCTOR(code);
2490
2491 }
2492
2493 /**
2494 * Compiles calls to macros
2495 *
2496 * @param array statement
2497 * @param boolean extendsMode
2498 * @return string
2499 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileCall)2500 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileCall) {
2501
2502 zend_bool extendsMode;
2503 zval *statement_param = NULL, *extendsMode_param = NULL;
2504 zval *statement = NULL;
2505
2506 zephir_fetch_params(0, 2, 0, &statement_param, &extendsMode_param);
2507
2508 statement = statement_param;
2509 extendsMode = zephir_get_boolval(extendsMode_param);
2510
2511
2512
2513 }
2514
2515 /**
2516 * Traverses a statement list compiling each of its nodes
2517 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,_statementList)2518 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _statementList) {
2519
2520 HashTable *_2;
2521 HashPosition _1;
2522 zephir_fcall_cache_entry *_8 = NULL, *_11 = NULL, *_15 = NULL, *_17 = NULL, *_20 = NULL, *_22 = NULL, *_27 = NULL, *_29 = NULL, *_31 = NULL, *_34 = NULL, *_36 = NULL, *_39 = NULL, *_42 = NULL, *_44 = NULL, *_46 = NULL, *_49 = NULL, *_51 = NULL, *_54 = NULL, *_57 = NULL;
2523 zend_long ZEPHIR_LAST_CALL_STATUS;
2524 zend_bool extendsMode, _0;
2525 zval *statements_param = NULL, *extendsMode_param = NULL, *extended = NULL, *blockMode = NULL, *compilation = NULL, *extensions = NULL, *statement = NULL, *tempCompilation = NULL, *type = NULL, *blockName = NULL, *blockStatements = NULL, *blocks = NULL, *path = NULL, *finalPath = NULL, *subCompiler = NULL, *level = NULL, **_3, *_4$$7 = NULL, *_5$$7, *_6$$7, *_7$$7 = NULL, *_10$$8 = NULL, *_12$$10, *_13$$11 = NULL, *_14$$11 = NULL, *_16$$12 = NULL, *_18$$13 = NULL, *_19$$13 = NULL, *_21$$14 = NULL, *_23$$15 = NULL, *_24$$15 = NULL, *_25$$16 = NULL, *_26$$16 = NULL, *_28$$17 = NULL, *_30$$18 = NULL, *_32$$24 = NULL, *_33$$24 = NULL, *_35$$25, *_37$$26 = NULL, *_38$$27 = NULL, *_40$$28 = NULL, *_41$$28 = NULL, *_43$$29 = NULL, *_45$$30 = NULL, *_47$$31 = NULL, *_48$$31 = NULL, *_50$$34 = NULL, *_52$$35 = NULL, *_53$$35 = NULL, *_55$$36 = NULL, *_56$$36 = NULL, *_58$$38 = NULL, *_59$$38, *_60$$38, *_61$$38 = NULL;
2526 zval *statements = NULL, *_9$$8 = NULL;
2527
2528 ZEPHIR_MM_GROW();
2529 zephir_fetch_params(1, 1, 1, &statements_param, &extendsMode_param);
2530
2531 statements = statements_param;
2532 if (!extendsMode_param) {
2533 extendsMode = 0;
2534 } else {
2535 extendsMode = zephir_get_boolval(extendsMode_param);
2536 }
2537
2538
2539 if (!(zephir_fast_count_int(statements TSRMLS_CC))) {
2540 RETURN_MM_STRING("", 1);
2541 }
2542 ZEPHIR_OBS_VAR(extended);
2543 zephir_read_property_this(&extended, this_ptr, SL("_extended"), PH_NOISY_CC);
2544 _0 = zephir_is_true(extended);
2545 if (!(_0)) {
2546 _0 = extendsMode;
2547 }
2548 ZEPHIR_INIT_VAR(blockMode);
2549 ZVAL_BOOL(blockMode, _0);
2550 if (ZEPHIR_IS_TRUE_IDENTICAL(blockMode)) {
2551 RETURN_ON_FAILURE(zephir_property_incr(this_ptr, SL("_blockLevel") TSRMLS_CC));
2552 }
2553 RETURN_ON_FAILURE(zephir_property_incr(this_ptr, SL("_level") TSRMLS_CC));
2554 ZEPHIR_INIT_VAR(compilation);
2555 ZVAL_NULL(compilation);
2556 ZEPHIR_OBS_VAR(extensions);
2557 zephir_read_property_this(&extensions, this_ptr, SL("_extensions"), PH_NOISY_CC);
2558 zephir_is_iterable(statements, &_2, &_1, 0, 0, "phalcon/mvc/view/engine/volt/compiler.zep", 2273);
2559 for (
2560 ; zend_hash_get_current_data_ex(_2, (void**) &_3, &_1) == SUCCESS
2561 ; zend_hash_move_forward_ex(_2, &_1)
2562 ) {
2563 ZEPHIR_GET_HVALUE(statement, _3);
2564 if (Z_TYPE_P(statement) != IS_ARRAY) {
2565 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "Corrupted statement", "phalcon/mvc/view/engine/volt/compiler.zep", 2066);
2566 return;
2567 }
2568 if (!(zephir_array_isset_string(statement, SS("type")))) {
2569 ZEPHIR_INIT_NVAR(_4$$7);
2570 object_init_ex(_4$$7, phalcon_mvc_view_engine_volt_exception_ce);
2571 zephir_array_fetch_string(&_5$$7, statement, SL("file"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 2073 TSRMLS_CC);
2572 zephir_array_fetch_string(&_6$$7, statement, SL("line"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 2073 TSRMLS_CC);
2573 ZEPHIR_INIT_LNVAR(_7$$7);
2574 ZEPHIR_CONCAT_SVSV(_7$$7, "Invalid statement in ", _5$$7, " on line ", _6$$7);
2575 ZEPHIR_CALL_METHOD(NULL, _4$$7, "__construct", &_8, 415, _7$$7, statement);
2576 zephir_check_call_status();
2577 zephir_throw_exception_debug(_4$$7, "phalcon/mvc/view/engine/volt/compiler.zep", 2073 TSRMLS_CC);
2578 ZEPHIR_MM_RESTORE();
2579 return;
2580 }
2581 if (Z_TYPE_P(extensions) == IS_ARRAY) {
2582 ZEPHIR_INIT_NVAR(_9$$8);
2583 zephir_create_array(_9$$8, 1, 0 TSRMLS_CC);
2584 zephir_array_fast_append(_9$$8, statement);
2585 ZEPHIR_INIT_NVAR(_10$$8);
2586 ZVAL_STRING(_10$$8, "compileStatement", ZEPHIR_TEMP_PARAM_COPY);
2587 ZEPHIR_CALL_METHOD(&tempCompilation, this_ptr, "fireextensionevent", &_11, 414, _10$$8, _9$$8);
2588 zephir_check_temp_parameter(_10$$8);
2589 zephir_check_call_status();
2590 if (Z_TYPE_P(tempCompilation) == IS_STRING) {
2591 zephir_concat_self(&compilation, tempCompilation TSRMLS_CC);
2592 continue;
2593 }
2594 }
2595 ZEPHIR_OBS_NVAR(type);
2596 zephir_array_fetch_string(&type, statement, SL("type"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 2094 TSRMLS_CC);
2597 do {
2598 if (ZEPHIR_IS_LONG(type, 357)) {
2599 zephir_array_fetch_string(&_12$$10, statement, SL("value"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 2102 TSRMLS_CC);
2600 zephir_concat_self(&compilation, _12$$10 TSRMLS_CC);
2601 break;
2602 }
2603 if (ZEPHIR_IS_LONG(type, 300)) {
2604 ZEPHIR_INIT_NVAR(_14$$11);
2605 if (extendsMode) {
2606 ZVAL_BOOL(_14$$11, 1);
2607 } else {
2608 ZVAL_BOOL(_14$$11, 0);
2609 }
2610 ZEPHIR_CALL_METHOD(&_13$$11, this_ptr, "compileif", &_15, 0, statement, _14$$11);
2611 zephir_check_call_status();
2612 zephir_concat_self(&compilation, _13$$11 TSRMLS_CC);
2613 break;
2614 }
2615 if (ZEPHIR_IS_LONG(type, 302)) {
2616 ZEPHIR_CALL_METHOD(&_16$$12, this_ptr, "compileelseif", &_17, 0, statement);
2617 zephir_check_call_status();
2618 zephir_concat_self(&compilation, _16$$12 TSRMLS_CC);
2619 break;
2620 }
2621 if (ZEPHIR_IS_LONG(type, 411)) {
2622 ZEPHIR_INIT_NVAR(_19$$13);
2623 if (extendsMode) {
2624 ZVAL_BOOL(_19$$13, 1);
2625 } else {
2626 ZVAL_BOOL(_19$$13, 0);
2627 }
2628 ZEPHIR_CALL_METHOD(&_18$$13, this_ptr, "compileswitch", &_20, 0, statement, _19$$13);
2629 zephir_check_call_status();
2630 zephir_concat_self(&compilation, _18$$13 TSRMLS_CC);
2631 break;
2632 }
2633 if (ZEPHIR_IS_LONG(type, 412)) {
2634 ZEPHIR_CALL_METHOD(&_21$$14, this_ptr, "compilecase", &_22, 0, statement);
2635 zephir_check_call_status();
2636 zephir_concat_self(&compilation, _21$$14 TSRMLS_CC);
2637 break;
2638 }
2639 if (ZEPHIR_IS_LONG(type, 413)) {
2640 ZEPHIR_INIT_NVAR(_24$$15);
2641 ZVAL_BOOL(_24$$15, 0);
2642 ZEPHIR_CALL_METHOD(&_23$$15, this_ptr, "compilecase", &_22, 0, statement, _24$$15);
2643 zephir_check_call_status();
2644 zephir_concat_self(&compilation, _23$$15 TSRMLS_CC);
2645 break;
2646 }
2647 if (ZEPHIR_IS_LONG(type, 304)) {
2648 ZEPHIR_INIT_NVAR(_26$$16);
2649 if (extendsMode) {
2650 ZVAL_BOOL(_26$$16, 1);
2651 } else {
2652 ZVAL_BOOL(_26$$16, 0);
2653 }
2654 ZEPHIR_CALL_METHOD(&_25$$16, this_ptr, "compileforeach", &_27, 0, statement, _26$$16);
2655 zephir_check_call_status();
2656 zephir_concat_self(&compilation, _25$$16 TSRMLS_CC);
2657 break;
2658 }
2659 if (ZEPHIR_IS_LONG(type, 306)) {
2660 ZEPHIR_CALL_METHOD(&_28$$17, this_ptr, "compileset", &_29, 0, statement);
2661 zephir_check_call_status();
2662 zephir_concat_self(&compilation, _28$$17 TSRMLS_CC);
2663 break;
2664 }
2665 if (ZEPHIR_IS_LONG(type, 359)) {
2666 ZEPHIR_CALL_METHOD(&_30$$18, this_ptr, "compileecho", &_31, 0, statement);
2667 zephir_check_call_status();
2668 zephir_concat_self(&compilation, _30$$18 TSRMLS_CC);
2669 break;
2670 }
2671 if (ZEPHIR_IS_LONG(type, 307)) {
2672 ZEPHIR_OBS_NVAR(blockName);
2673 zephir_array_fetch_string(&blockName, statement, SL("name"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 2142 TSRMLS_CC);
2674 ZEPHIR_OBS_NVAR(blockStatements);
2675 zephir_array_isset_string_fetch(&blockStatements, statement, SS("block_statements"), 0 TSRMLS_CC);
2676 ZEPHIR_OBS_NVAR(blocks);
2677 zephir_read_property_this(&blocks, this_ptr, SL("_blocks"), PH_NOISY_CC);
2678 if (zephir_is_true(blockMode)) {
2679 if (Z_TYPE_P(blocks) != IS_ARRAY) {
2680 ZEPHIR_INIT_NVAR(blocks);
2681 array_init(blocks);
2682 }
2683 if (Z_TYPE_P(compilation) != IS_NULL) {
2684 zephir_array_append(&blocks, compilation, PH_SEPARATE, "phalcon/mvc/view/engine/volt/compiler.zep", 2157);
2685 ZEPHIR_INIT_NVAR(compilation);
2686 ZVAL_NULL(compilation);
2687 }
2688 zephir_array_update_zval(&blocks, blockName, &blockStatements, PH_COPY | PH_SEPARATE);
2689 zephir_update_property_this(getThis(), SL("_blocks"), blocks TSRMLS_CC);
2690 } else {
2691 if (Z_TYPE_P(blockStatements) == IS_ARRAY) {
2692 ZEPHIR_INIT_NVAR(_33$$24);
2693 if (extendsMode) {
2694 ZVAL_BOOL(_33$$24, 1);
2695 } else {
2696 ZVAL_BOOL(_33$$24, 0);
2697 }
2698 ZEPHIR_CALL_METHOD(&_32$$24, this_ptr, "_statementlist", &_34, 419, blockStatements, _33$$24);
2699 zephir_check_call_status();
2700 zephir_concat_self(&compilation, _32$$24 TSRMLS_CC);
2701 }
2702 }
2703 break;
2704 }
2705 if (ZEPHIR_IS_LONG(type, 310)) {
2706 ZEPHIR_OBS_NVAR(path);
2707 zephir_array_fetch_string(&path, statement, SL("path"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 2179 TSRMLS_CC);
2708 zephir_array_fetch_string(&_35$$25, path, SL("value"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 2181 TSRMLS_CC);
2709 ZEPHIR_CALL_METHOD(&finalPath, this_ptr, "getfinalpath", &_36, 0, _35$$25);
2710 zephir_check_call_status();
2711 ZEPHIR_INIT_NVAR(extended);
2712 ZVAL_BOOL(extended, 1);
2713 ZEPHIR_INIT_NVAR(subCompiler);
2714 if (zephir_clone(subCompiler, this_ptr TSRMLS_CC) == FAILURE) {
2715 RETURN_MM();
2716 }
2717 ZEPHIR_CALL_METHOD(&tempCompilation, subCompiler, "compile", NULL, 0, finalPath, extended);
2718 zephir_check_call_status();
2719 if (Z_TYPE_P(tempCompilation) == IS_NULL) {
2720 ZEPHIR_CALL_METHOD(&_37$$26, subCompiler, "getcompiledtemplatepath", NULL, 0);
2721 zephir_check_call_status();
2722 ZEPHIR_INIT_NVAR(tempCompilation);
2723 zephir_file_get_contents(tempCompilation, _37$$26 TSRMLS_CC);
2724 }
2725 if (1) {
2726 zephir_update_property_this(getThis(), SL("_extended"), ZEPHIR_GLOBAL(global_true) TSRMLS_CC);
2727 } else {
2728 zephir_update_property_this(getThis(), SL("_extended"), ZEPHIR_GLOBAL(global_false) TSRMLS_CC);
2729 }
2730 zephir_update_property_this(getThis(), SL("_extendedBlocks"), tempCompilation TSRMLS_CC);
2731 ZEPHIR_CPY_WRT(blockMode, extended);
2732 break;
2733 }
2734 if (ZEPHIR_IS_LONG(type, 313)) {
2735 ZEPHIR_CALL_METHOD(&_38$$27, this_ptr, "compileinclude", &_39, 0, statement);
2736 zephir_check_call_status();
2737 zephir_concat_self(&compilation, _38$$27 TSRMLS_CC);
2738 break;
2739 }
2740 if (ZEPHIR_IS_LONG(type, 314)) {
2741 ZEPHIR_INIT_NVAR(_41$$28);
2742 if (extendsMode) {
2743 ZVAL_BOOL(_41$$28, 1);
2744 } else {
2745 ZVAL_BOOL(_41$$28, 0);
2746 }
2747 ZEPHIR_CALL_METHOD(&_40$$28, this_ptr, "compilecache", &_42, 0, statement, _41$$28);
2748 zephir_check_call_status();
2749 zephir_concat_self(&compilation, _40$$28 TSRMLS_CC);
2750 break;
2751 }
2752 if (ZEPHIR_IS_LONG(type, 316)) {
2753 ZEPHIR_CALL_METHOD(&_43$$29, this_ptr, "compiledo", &_44, 0, statement);
2754 zephir_check_call_status();
2755 zephir_concat_self(&compilation, _43$$29 TSRMLS_CC);
2756 break;
2757 }
2758 if (ZEPHIR_IS_LONG(type, 327)) {
2759 ZEPHIR_CALL_METHOD(&_45$$30, this_ptr, "compilereturn", &_46, 0, statement);
2760 zephir_check_call_status();
2761 zephir_concat_self(&compilation, _45$$30 TSRMLS_CC);
2762 break;
2763 }
2764 if (ZEPHIR_IS_LONG(type, 317)) {
2765 ZEPHIR_INIT_NVAR(_48$$31);
2766 if (extendsMode) {
2767 ZVAL_BOOL(_48$$31, 1);
2768 } else {
2769 ZVAL_BOOL(_48$$31, 0);
2770 }
2771 ZEPHIR_CALL_METHOD(&_47$$31, this_ptr, "compileautoescape", &_49, 0, statement, _48$$31);
2772 zephir_check_call_status();
2773 zephir_concat_self(&compilation, _47$$31 TSRMLS_CC);
2774 break;
2775 }
2776 if (ZEPHIR_IS_LONG(type, 319)) {
2777 zephir_concat_self_str(&compilation, SL("<?php continue; ?>") TSRMLS_CC);
2778 break;
2779 }
2780 if (ZEPHIR_IS_LONG(type, 320)) {
2781 zephir_concat_self_str(&compilation, SL("<?php break; ?>") TSRMLS_CC);
2782 break;
2783 }
2784 if (ZEPHIR_IS_LONG(type, 321)) {
2785 ZEPHIR_CALL_METHOD(&_50$$34, this_ptr, "compileforelse", &_51, 0);
2786 zephir_check_call_status();
2787 zephir_concat_self(&compilation, _50$$34 TSRMLS_CC);
2788 break;
2789 }
2790 if (ZEPHIR_IS_LONG(type, 322)) {
2791 ZEPHIR_INIT_NVAR(_53$$35);
2792 if (extendsMode) {
2793 ZVAL_BOOL(_53$$35, 1);
2794 } else {
2795 ZVAL_BOOL(_53$$35, 0);
2796 }
2797 ZEPHIR_CALL_METHOD(&_52$$35, this_ptr, "compilemacro", &_54, 0, statement, _53$$35);
2798 zephir_check_call_status();
2799 zephir_concat_self(&compilation, _52$$35 TSRMLS_CC);
2800 break;
2801 }
2802 if (ZEPHIR_IS_LONG(type, 325)) {
2803 ZEPHIR_INIT_NVAR(_56$$36);
2804 if (extendsMode) {
2805 ZVAL_BOOL(_56$$36, 1);
2806 } else {
2807 ZVAL_BOOL(_56$$36, 0);
2808 }
2809 ZEPHIR_CALL_METHOD(&_55$$36, this_ptr, "compilecall", &_57, 0, statement, _56$$36);
2810 zephir_check_call_status();
2811 zephir_concat_self(&compilation, _55$$36 TSRMLS_CC);
2812 break;
2813 }
2814 if (ZEPHIR_IS_LONG(type, 358)) {
2815 break;
2816 }
2817 ZEPHIR_INIT_NVAR(_58$$38);
2818 object_init_ex(_58$$38, phalcon_mvc_view_engine_volt_exception_ce);
2819 zephir_array_fetch_string(&_59$$38, statement, SL("file"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 2265 TSRMLS_CC);
2820 zephir_array_fetch_string(&_60$$38, statement, SL("line"), PH_NOISY | PH_READONLY, "phalcon/mvc/view/engine/volt/compiler.zep", 2265 TSRMLS_CC);
2821 ZEPHIR_INIT_LNVAR(_61$$38);
2822 ZEPHIR_CONCAT_SVSVSV(_61$$38, "Unknown statement ", type, " in ", _59$$38, " on line ", _60$$38);
2823 ZEPHIR_CALL_METHOD(NULL, _58$$38, "__construct", &_8, 415, _61$$38);
2824 zephir_check_call_status();
2825 zephir_throw_exception_debug(_58$$38, "phalcon/mvc/view/engine/volt/compiler.zep", 2265 TSRMLS_CC);
2826 ZEPHIR_MM_RESTORE();
2827 return;
2828 } while(0);
2829
2830 }
2831 if (ZEPHIR_IS_TRUE_IDENTICAL(blockMode)) {
2832 level = zephir_fetch_nproperty_this(this_ptr, SL("_blockLevel"), PH_NOISY_CC);
2833 if (ZEPHIR_IS_LONG(level, 1)) {
2834 if (Z_TYPE_P(compilation) != IS_NULL) {
2835 zephir_update_property_array_append(this_ptr, SL("_blocks"), compilation TSRMLS_CC);
2836 }
2837 }
2838 RETURN_ON_FAILURE(zephir_property_decr(this_ptr, SL("_blockLevel") TSRMLS_CC));
2839 }
2840 RETURN_ON_FAILURE(zephir_property_decr(this_ptr, SL("_level") TSRMLS_CC));
2841 RETURN_CCTOR(compilation);
2842
2843 }
2844
2845 /**
2846 * Compiles a Volt source code returning a PHP plain version
2847 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,_compileSource)2848 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _compileSource) {
2849
2850 HashTable *_2$$7;
2851 HashPosition _1$$7;
2852 zend_long ZEPHIR_LAST_CALL_STATUS;
2853 zend_bool extendsMode;
2854 zval *viewCode_param = NULL, *extendsMode_param = NULL, *currentPath = NULL, *intermediate = NULL, *extended = NULL, *finalCompilation = NULL, *blocks = NULL, *extendedBlocks = NULL, *name = NULL, *block = NULL, *blockCompilation = NULL, *localBlock = NULL, *compilation = NULL, *options = NULL, *autoescape = NULL, *_0, **_3$$7;
2855 zval *viewCode = NULL;
2856
2857 ZEPHIR_MM_GROW();
2858 zephir_fetch_params(1, 1, 1, &viewCode_param, &extendsMode_param);
2859
2860 if (UNEXPECTED(Z_TYPE_P(viewCode_param) != IS_STRING && Z_TYPE_P(viewCode_param) != IS_NULL)) {
2861 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'viewCode' must be a string") TSRMLS_CC);
2862 RETURN_MM_NULL();
2863 }
2864 if (EXPECTED(Z_TYPE_P(viewCode_param) == IS_STRING)) {
2865 zephir_get_strval(viewCode, viewCode_param);
2866 } else {
2867 ZEPHIR_INIT_VAR(viewCode);
2868 ZVAL_EMPTY_STRING(viewCode);
2869 }
2870 if (!extendsMode_param) {
2871 extendsMode = 0;
2872 } else {
2873 extendsMode = zephir_get_boolval(extendsMode_param);
2874 }
2875
2876
2877 ZEPHIR_OBS_VAR(currentPath);
2878 zephir_read_property_this(¤tPath, this_ptr, SL("_currentPath"), PH_NOISY_CC);
2879 ZEPHIR_OBS_VAR(options);
2880 zephir_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC);
2881 if (Z_TYPE_P(options) == IS_ARRAY) {
2882 ZEPHIR_OBS_VAR(autoescape);
2883 if (zephir_array_isset_string_fetch(&autoescape, options, SS("autoescape"), 0 TSRMLS_CC)) {
2884 if (Z_TYPE_P(autoescape) != IS_BOOL) {
2885 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "'autoescape' must be boolean", "phalcon/mvc/view/engine/volt/compiler.zep", 2310);
2886 return;
2887 }
2888 zephir_update_property_this(getThis(), SL("_autoescape"), autoescape TSRMLS_CC);
2889 }
2890 }
2891 ZEPHIR_INIT_VAR(intermediate);
2892 ZEPHIR_LAST_CALL_STATUS = phvolt_parse_view(intermediate, viewCode, currentPath TSRMLS_CC);
2893 zephir_check_call_status();
2894 if (Z_TYPE_P(intermediate) != IS_ARRAY) {
2895 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "Invalid intermediate representation", "phalcon/mvc/view/engine/volt/compiler.zep", 2322);
2896 return;
2897 }
2898 ZEPHIR_INIT_VAR(_0);
2899 if (extendsMode) {
2900 ZVAL_BOOL(_0, 1);
2901 } else {
2902 ZVAL_BOOL(_0, 0);
2903 }
2904 ZEPHIR_CALL_METHOD(&compilation, this_ptr, "_statementlist", NULL, 419, intermediate, _0);
2905 zephir_check_call_status();
2906 ZEPHIR_OBS_VAR(extended);
2907 zephir_read_property_this(&extended, this_ptr, SL("_extended"), PH_NOISY_CC);
2908 if (ZEPHIR_IS_TRUE_IDENTICAL(extended)) {
2909 ZEPHIR_INIT_VAR(finalCompilation);
2910 if (extendsMode == 1) {
2911 array_init(finalCompilation);
2912 } else {
2913 ZVAL_NULL(finalCompilation);
2914 }
2915 ZEPHIR_OBS_VAR(blocks);
2916 zephir_read_property_this(&blocks, this_ptr, SL("_blocks"), PH_NOISY_CC);
2917 ZEPHIR_OBS_VAR(extendedBlocks);
2918 zephir_read_property_this(&extendedBlocks, this_ptr, SL("_extendedBlocks"), PH_NOISY_CC);
2919 zephir_is_iterable(extendedBlocks, &_2$$7, &_1$$7, 0, 0, "phalcon/mvc/view/engine/volt/compiler.zep", 2388);
2920 for (
2921 ; zend_hash_get_current_data_ex(_2$$7, (void**) &_3$$7, &_1$$7) == SUCCESS
2922 ; zend_hash_move_forward_ex(_2$$7, &_1$$7)
2923 ) {
2924 ZEPHIR_GET_HMKEY(name, _2$$7, _1$$7);
2925 ZEPHIR_GET_HVALUE(block, _3$$7);
2926 if (Z_TYPE_P(name) == IS_STRING) {
2927 if (zephir_array_isset(blocks, name)) {
2928 ZEPHIR_OBS_NVAR(localBlock);
2929 zephir_array_fetch(&localBlock, blocks, name, PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 2356 TSRMLS_CC);
2930 zephir_update_property_this(getThis(), SL("_currentBlock"), name TSRMLS_CC);
2931 ZEPHIR_CALL_METHOD(&blockCompilation, this_ptr, "_statementlist", NULL, 419, localBlock);
2932 zephir_check_call_status();
2933 } else {
2934 if (Z_TYPE_P(block) == IS_ARRAY) {
2935 ZEPHIR_CALL_METHOD(&blockCompilation, this_ptr, "_statementlist", NULL, 419, block);
2936 zephir_check_call_status();
2937 } else {
2938 ZEPHIR_CPY_WRT(blockCompilation, block);
2939 }
2940 }
2941 if (extendsMode == 1) {
2942 zephir_array_update_zval(&finalCompilation, name, &blockCompilation, PH_COPY | PH_SEPARATE);
2943 } else {
2944 zephir_concat_self(&finalCompilation, blockCompilation TSRMLS_CC);
2945 }
2946 } else {
2947 if (extendsMode == 1) {
2948 zephir_array_append(&finalCompilation, block, PH_SEPARATE, "phalcon/mvc/view/engine/volt/compiler.zep", 2381);
2949 } else {
2950 zephir_concat_self(&finalCompilation, block TSRMLS_CC);
2951 }
2952 }
2953 }
2954 RETURN_CCTOR(finalCompilation);
2955 }
2956 if (extendsMode == 1) {
2957 RETURN_MM_MEMBER(getThis(), "_blocks");
2958 }
2959 RETURN_CCTOR(compilation);
2960
2961 }
2962
2963 /**
2964 * Compiles a template into a string
2965 *
2966 *<code>
2967 * echo $compiler->compileString('{{ "hello world" }}');
2968 *</code>
2969 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileString)2970 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileString) {
2971
2972 zend_long ZEPHIR_LAST_CALL_STATUS;
2973 zend_bool extendsMode;
2974 zval *viewCode_param = NULL, *extendsMode_param = NULL, *_0, *_1;
2975 zval *viewCode = NULL;
2976
2977 ZEPHIR_MM_GROW();
2978 zephir_fetch_params(1, 1, 1, &viewCode_param, &extendsMode_param);
2979
2980 if (UNEXPECTED(Z_TYPE_P(viewCode_param) != IS_STRING && Z_TYPE_P(viewCode_param) != IS_NULL)) {
2981 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'viewCode' must be a string") TSRMLS_CC);
2982 RETURN_MM_NULL();
2983 }
2984 if (EXPECTED(Z_TYPE_P(viewCode_param) == IS_STRING)) {
2985 zephir_get_strval(viewCode, viewCode_param);
2986 } else {
2987 ZEPHIR_INIT_VAR(viewCode);
2988 ZVAL_EMPTY_STRING(viewCode);
2989 }
2990 if (!extendsMode_param) {
2991 extendsMode = 0;
2992 } else {
2993 extendsMode = zephir_get_boolval(extendsMode_param);
2994 }
2995
2996
2997 ZEPHIR_INIT_ZVAL_NREF(_0);
2998 ZVAL_STRING(_0, "eval code", 1);
2999 zephir_update_property_this(getThis(), SL("_currentPath"), _0 TSRMLS_CC);
3000 ZEPHIR_INIT_VAR(_1);
3001 if (extendsMode) {
3002 ZVAL_BOOL(_1, 1);
3003 } else {
3004 ZVAL_BOOL(_1, 0);
3005 }
3006 ZEPHIR_RETURN_CALL_METHOD(this_ptr, "_compilesource", NULL, 0, viewCode, _1);
3007 zephir_check_call_status();
3008 RETURN_MM();
3009
3010 }
3011
3012 /**
3013 * Compiles a template into a file forcing the destination path
3014 *
3015 *<code>
3016 * $compiler->compileFile("views/layouts/main.volt", "views/layouts/main.volt.php");
3017 *</code>
3018 *
3019 * @param string path
3020 * @param string compiledPath
3021 * @param boolean extendsMode
3022 * @return string|array
3023 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compileFile)3024 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileFile) {
3025
3026 zend_long ZEPHIR_LAST_CALL_STATUS;
3027 zend_bool extendsMode;
3028 zval *path_param = NULL, *compiledPath_param = NULL, *extendsMode_param = NULL, *viewCode = NULL, *compilation = NULL, *finalCompilation = NULL, *_4, *_5, *_0$$4, *_2$$5;
3029 zval *path = NULL, *compiledPath = NULL, *_1$$4, *_3$$5;
3030
3031 ZEPHIR_MM_GROW();
3032 zephir_fetch_params(1, 2, 1, &path_param, &compiledPath_param, &extendsMode_param);
3033
3034 if (UNEXPECTED(Z_TYPE_P(path_param) != IS_STRING && Z_TYPE_P(path_param) != IS_NULL)) {
3035 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'path' must be a string") TSRMLS_CC);
3036 RETURN_MM_NULL();
3037 }
3038 if (EXPECTED(Z_TYPE_P(path_param) == IS_STRING)) {
3039 zephir_get_strval(path, path_param);
3040 } else {
3041 ZEPHIR_INIT_VAR(path);
3042 ZVAL_EMPTY_STRING(path);
3043 }
3044 if (UNEXPECTED(Z_TYPE_P(compiledPath_param) != IS_STRING && Z_TYPE_P(compiledPath_param) != IS_NULL)) {
3045 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'compiledPath' must be a string") TSRMLS_CC);
3046 RETURN_MM_NULL();
3047 }
3048 if (EXPECTED(Z_TYPE_P(compiledPath_param) == IS_STRING)) {
3049 zephir_get_strval(compiledPath, compiledPath_param);
3050 } else {
3051 ZEPHIR_INIT_VAR(compiledPath);
3052 ZVAL_EMPTY_STRING(compiledPath);
3053 }
3054 if (!extendsMode_param) {
3055 extendsMode = 0;
3056 } else {
3057 extendsMode = zephir_get_boolval(extendsMode_param);
3058 }
3059
3060
3061 if (ZEPHIR_IS_EQUAL(path, compiledPath)) {
3062 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "Template path and compilation template path cannot be the same", "phalcon/mvc/view/engine/volt/compiler.zep", 2430);
3063 return;
3064 }
3065 if (!((zephir_file_exists(path TSRMLS_CC) == SUCCESS))) {
3066 ZEPHIR_INIT_VAR(_0$$4);
3067 object_init_ex(_0$$4, phalcon_mvc_view_engine_volt_exception_ce);
3068 ZEPHIR_INIT_VAR(_1$$4);
3069 ZEPHIR_CONCAT_SVS(_1$$4, "Template file ", path, " does not exist");
3070 ZEPHIR_CALL_METHOD(NULL, _0$$4, "__construct", NULL, 415, _1$$4);
3071 zephir_check_call_status();
3072 zephir_throw_exception_debug(_0$$4, "phalcon/mvc/view/engine/volt/compiler.zep", 2437 TSRMLS_CC);
3073 ZEPHIR_MM_RESTORE();
3074 return;
3075 }
3076 ZEPHIR_INIT_VAR(viewCode);
3077 zephir_file_get_contents(viewCode, path TSRMLS_CC);
3078 if (ZEPHIR_IS_FALSE_IDENTICAL(viewCode)) {
3079 ZEPHIR_INIT_VAR(_2$$5);
3080 object_init_ex(_2$$5, phalcon_mvc_view_engine_volt_exception_ce);
3081 ZEPHIR_INIT_VAR(_3$$5);
3082 ZEPHIR_CONCAT_SVS(_3$$5, "Template file ", path, " could not be opened");
3083 ZEPHIR_CALL_METHOD(NULL, _2$$5, "__construct", NULL, 415, _3$$5);
3084 zephir_check_call_status();
3085 zephir_throw_exception_debug(_2$$5, "phalcon/mvc/view/engine/volt/compiler.zep", 2445 TSRMLS_CC);
3086 ZEPHIR_MM_RESTORE();
3087 return;
3088 }
3089 zephir_update_property_this(getThis(), SL("_currentPath"), path TSRMLS_CC);
3090 ZEPHIR_INIT_VAR(_4);
3091 if (extendsMode) {
3092 ZVAL_BOOL(_4, 1);
3093 } else {
3094 ZVAL_BOOL(_4, 0);
3095 }
3096 ZEPHIR_CALL_METHOD(&compilation, this_ptr, "_compilesource", NULL, 0, viewCode, _4);
3097 zephir_check_call_status();
3098 if (Z_TYPE_P(compilation) == IS_ARRAY) {
3099 ZEPHIR_CALL_FUNCTION(&finalCompilation, "serialize", NULL, 68, compilation);
3100 zephir_check_call_status();
3101 } else {
3102 ZEPHIR_CPY_WRT(finalCompilation, compilation);
3103 }
3104 ZEPHIR_INIT_VAR(_5);
3105 zephir_file_put_contents(_5, compiledPath, finalCompilation TSRMLS_CC);
3106 if (ZEPHIR_IS_FALSE_IDENTICAL(_5)) {
3107 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "Volt directory can't be written", "phalcon/mvc/view/engine/volt/compiler.zep", 2465);
3108 return;
3109 }
3110 RETURN_CCTOR(compilation);
3111
3112 }
3113
3114 /**
3115 * Compiles a template into a file applying the compiler options
3116 * This method does not return the compiled path if the template was not compiled
3117 *
3118 *<code>
3119 * $compiler->compile("views/layouts/main.volt");
3120 *
3121 * require $compiler->getCompiledTemplatePath();
3122 *</code>
3123 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,compile)3124 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compile) {
3125
3126 zval *_2$$23;
3127 zend_long ZEPHIR_LAST_CALL_STATUS;
3128 zend_bool extendsMode;
3129 zval *templatePath_param = NULL, *extendsMode_param = NULL, *stat = NULL, *compileAlways = NULL, *prefix = NULL, *compiledPath = NULL, *compiledSeparator = NULL, *blocksCode = NULL, *compiledExtension = NULL, *compilation = NULL, *options = NULL, *realCompiledPath = NULL, *compiledTemplatePath = NULL, *templateSepPath = NULL, *_0, *_1$$17 = NULL, *_3$$23, *_4$$26, *_5$$29, *_6$$30, *_7$$33, *_8$$33, *_9$$36, *_10$$38;
3130 zval *templatePath = NULL;
3131
3132 ZEPHIR_MM_GROW();
3133 zephir_fetch_params(1, 1, 1, &templatePath_param, &extendsMode_param);
3134
3135 if (UNEXPECTED(Z_TYPE_P(templatePath_param) != IS_STRING && Z_TYPE_P(templatePath_param) != IS_NULL)) {
3136 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'templatePath' must be a string") TSRMLS_CC);
3137 RETURN_MM_NULL();
3138 }
3139 if (EXPECTED(Z_TYPE_P(templatePath_param) == IS_STRING)) {
3140 zephir_get_strval(templatePath, templatePath_param);
3141 } else {
3142 ZEPHIR_INIT_VAR(templatePath);
3143 ZVAL_EMPTY_STRING(templatePath);
3144 }
3145 if (!extendsMode_param) {
3146 extendsMode = 0;
3147 } else {
3148 extendsMode = zephir_get_boolval(extendsMode_param);
3149 }
3150
3151
3152 if (0) {
3153 zephir_update_property_this(getThis(), SL("_extended"), ZEPHIR_GLOBAL(global_true) TSRMLS_CC);
3154 } else {
3155 zephir_update_property_this(getThis(), SL("_extended"), ZEPHIR_GLOBAL(global_false) TSRMLS_CC);
3156 }
3157 if (0) {
3158 zephir_update_property_this(getThis(), SL("_extendedBlocks"), ZEPHIR_GLOBAL(global_true) TSRMLS_CC);
3159 } else {
3160 zephir_update_property_this(getThis(), SL("_extendedBlocks"), ZEPHIR_GLOBAL(global_false) TSRMLS_CC);
3161 }
3162 zephir_update_property_this(getThis(), SL("_blocks"), ZEPHIR_GLOBAL(global_null) TSRMLS_CC);
3163 ZEPHIR_INIT_ZVAL_NREF(_0);
3164 ZVAL_LONG(_0, 0);
3165 zephir_update_property_this(getThis(), SL("_level"), _0 TSRMLS_CC);
3166 ZEPHIR_INIT_ZVAL_NREF(_0);
3167 ZVAL_LONG(_0, 0);
3168 zephir_update_property_this(getThis(), SL("_foreachLevel"), _0 TSRMLS_CC);
3169 ZEPHIR_INIT_ZVAL_NREF(_0);
3170 ZVAL_LONG(_0, 0);
3171 zephir_update_property_this(getThis(), SL("_blockLevel"), _0 TSRMLS_CC);
3172 ZEPHIR_INIT_ZVAL_NREF(_0);
3173 ZVAL_LONG(_0, 0);
3174 zephir_update_property_this(getThis(), SL("_exprLevel"), _0 TSRMLS_CC);
3175 ZEPHIR_INIT_VAR(stat);
3176 ZVAL_BOOL(stat, 1);
3177 ZEPHIR_INIT_VAR(compileAlways);
3178 ZVAL_BOOL(compileAlways, 0);
3179 ZEPHIR_INIT_VAR(compiledPath);
3180 ZVAL_STRING(compiledPath, "", 1);
3181 ZEPHIR_INIT_VAR(prefix);
3182 ZVAL_NULL(prefix);
3183 ZEPHIR_INIT_VAR(compiledSeparator);
3184 ZVAL_STRING(compiledSeparator, "%%", 1);
3185 ZEPHIR_INIT_VAR(compiledExtension);
3186 ZVAL_STRING(compiledExtension, ".php", 1);
3187 ZEPHIR_INIT_VAR(compilation);
3188 ZVAL_NULL(compilation);
3189 ZEPHIR_OBS_VAR(options);
3190 zephir_read_property_this(&options, this_ptr, SL("_options"), PH_NOISY_CC);
3191 if (Z_TYPE_P(options) == IS_ARRAY) {
3192 if (zephir_array_isset_string(options, SS("compileAlways"))) {
3193 ZEPHIR_OBS_NVAR(compileAlways);
3194 zephir_array_fetch_string(&compileAlways, options, SL("compileAlways"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 2513 TSRMLS_CC);
3195 if (Z_TYPE_P(compileAlways) != IS_BOOL) {
3196 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "'compileAlways' must be a bool value", "phalcon/mvc/view/engine/volt/compiler.zep", 2515);
3197 return;
3198 }
3199 }
3200 if (zephir_array_isset_string(options, SS("prefix"))) {
3201 ZEPHIR_OBS_NVAR(prefix);
3202 zephir_array_fetch_string(&prefix, options, SL("prefix"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 2523 TSRMLS_CC);
3203 if (Z_TYPE_P(prefix) != IS_STRING) {
3204 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "'prefix' must be a string", "phalcon/mvc/view/engine/volt/compiler.zep", 2525);
3205 return;
3206 }
3207 }
3208 if (zephir_array_isset_string(options, SS("compiledPath"))) {
3209 ZEPHIR_OBS_NVAR(compiledPath);
3210 zephir_array_fetch_string(&compiledPath, options, SL("compiledPath"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 2533 TSRMLS_CC);
3211 if (Z_TYPE_P(compiledPath) != IS_STRING) {
3212 if (Z_TYPE_P(compiledPath) != IS_OBJECT) {
3213 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "'compiledPath' must be a string or a closure", "phalcon/mvc/view/engine/volt/compiler.zep", 2536);
3214 return;
3215 }
3216 }
3217 }
3218 if (zephir_array_isset_string(options, SS("compiledSeparator"))) {
3219 ZEPHIR_OBS_NVAR(compiledSeparator);
3220 zephir_array_fetch_string(&compiledSeparator, options, SL("compiledSeparator"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 2545 TSRMLS_CC);
3221 if (Z_TYPE_P(compiledSeparator) != IS_STRING) {
3222 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "'compiledSeparator' must be a string", "phalcon/mvc/view/engine/volt/compiler.zep", 2547);
3223 return;
3224 }
3225 }
3226 if (zephir_array_isset_string(options, SS("compiledExtension"))) {
3227 ZEPHIR_OBS_NVAR(compiledExtension);
3228 zephir_array_fetch_string(&compiledExtension, options, SL("compiledExtension"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 2555 TSRMLS_CC);
3229 if (Z_TYPE_P(compiledExtension) != IS_STRING) {
3230 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "'compiledExtension' must be a string", "phalcon/mvc/view/engine/volt/compiler.zep", 2557);
3231 return;
3232 }
3233 }
3234 if (zephir_array_isset_string(options, SS("stat"))) {
3235 ZEPHIR_OBS_NVAR(stat);
3236 zephir_array_fetch_string(&stat, options, SL("stat"), PH_NOISY, "phalcon/mvc/view/engine/volt/compiler.zep", 2565 TSRMLS_CC);
3237 }
3238 }
3239 if (Z_TYPE_P(compiledPath) == IS_STRING) {
3240 if (!(ZEPHIR_IS_EMPTY(compiledPath))) {
3241 ZEPHIR_CALL_FUNCTION(&_1$$17, "realpath", NULL, 67, templatePath);
3242 zephir_check_call_status();
3243 ZEPHIR_INIT_VAR(templateSepPath);
3244 zephir_prepare_virtual_path(templateSepPath, _1$$17, compiledSeparator TSRMLS_CC);
3245 } else {
3246 ZEPHIR_CPY_WRT(templateSepPath, templatePath);
3247 }
3248 ZEPHIR_INIT_VAR(compiledTemplatePath);
3249 if (extendsMode == 1) {
3250 ZEPHIR_CONCAT_VVVVSVV(compiledTemplatePath, compiledPath, prefix, templateSepPath, compiledSeparator, "e", compiledSeparator, compiledExtension);
3251 } else {
3252 ZEPHIR_CONCAT_VVVV(compiledTemplatePath, compiledPath, prefix, templateSepPath, compiledExtension);
3253 }
3254 } else {
3255 if (Z_TYPE_P(compiledPath) == IS_OBJECT) {
3256 if (zephir_instance_of_ev(compiledPath, zend_ce_closure TSRMLS_CC)) {
3257 ZEPHIR_INIT_VAR(_2$$23);
3258 zephir_create_array(_2$$23, 3, 0 TSRMLS_CC);
3259 zephir_array_fast_append(_2$$23, templatePath);
3260 zephir_array_fast_append(_2$$23, options);
3261 ZEPHIR_INIT_VAR(_3$$23);
3262 ZVAL_BOOL(_3$$23, extendsMode);
3263 zephir_array_fast_append(_2$$23, _3$$23);
3264 ZEPHIR_INIT_NVAR(compiledTemplatePath);
3265 ZEPHIR_CALL_USER_FUNC_ARRAY(compiledTemplatePath, compiledPath, _2$$23);
3266 zephir_check_call_status();
3267 if (Z_TYPE_P(compiledTemplatePath) != IS_STRING) {
3268 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "compiledPath closure didn't return a valid string", "phalcon/mvc/view/engine/volt/compiler.zep", 2610);
3269 return;
3270 }
3271 } else {
3272 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_engine_volt_exception_ce, "compiledPath must be a string or a closure", "phalcon/mvc/view/engine/volt/compiler.zep", 2613);
3273 return;
3274 }
3275 }
3276 }
3277 ZEPHIR_CPY_WRT(realCompiledPath, compiledTemplatePath);
3278 if (zephir_is_true(compileAlways)) {
3279 ZEPHIR_INIT_VAR(_4$$26);
3280 if (extendsMode) {
3281 ZVAL_BOOL(_4$$26, 1);
3282 } else {
3283 ZVAL_BOOL(_4$$26, 0);
3284 }
3285 ZEPHIR_CALL_METHOD(&compilation, this_ptr, "compilefile", NULL, 0, templatePath, realCompiledPath, _4$$26);
3286 zephir_check_call_status();
3287 } else {
3288 if (ZEPHIR_IS_TRUE_IDENTICAL(stat)) {
3289 if ((zephir_file_exists(compiledTemplatePath TSRMLS_CC) == SUCCESS)) {
3290 ZEPHIR_INIT_VAR(_5$$29);
3291 if (zephir_compare_mtime(templatePath, realCompiledPath TSRMLS_CC)) {
3292 ZEPHIR_INIT_VAR(_6$$30);
3293 if (extendsMode) {
3294 ZVAL_BOOL(_6$$30, 1);
3295 } else {
3296 ZVAL_BOOL(_6$$30, 0);
3297 }
3298 ZEPHIR_CALL_METHOD(&compilation, this_ptr, "compilefile", NULL, 0, templatePath, realCompiledPath, _6$$30);
3299 zephir_check_call_status();
3300 } else {
3301 if (extendsMode == 1) {
3302 ZEPHIR_INIT_VAR(blocksCode);
3303 zephir_file_get_contents(blocksCode, realCompiledPath TSRMLS_CC);
3304 if (ZEPHIR_IS_FALSE_IDENTICAL(blocksCode)) {
3305 ZEPHIR_INIT_VAR(_7$$33);
3306 object_init_ex(_7$$33, phalcon_mvc_view_engine_volt_exception_ce);
3307 ZEPHIR_INIT_VAR(_8$$33);
3308 ZEPHIR_CONCAT_SVS(_8$$33, "Extends compilation file ", realCompiledPath, " could not be opened");
3309 ZEPHIR_CALL_METHOD(NULL, _7$$33, "__construct", NULL, 415, _8$$33);
3310 zephir_check_call_status();
3311 zephir_throw_exception_debug(_7$$33, "phalcon/mvc/view/engine/volt/compiler.zep", 2647 TSRMLS_CC);
3312 ZEPHIR_MM_RESTORE();
3313 return;
3314 }
3315 if (zephir_is_true(blocksCode)) {
3316 ZEPHIR_CALL_FUNCTION(&compilation, "unserialize", NULL, 69, blocksCode);
3317 zephir_check_call_status();
3318 } else {
3319 ZEPHIR_INIT_NVAR(compilation);
3320 array_init(compilation);
3321 }
3322 }
3323 }
3324 } else {
3325 ZEPHIR_INIT_VAR(_9$$36);
3326 if (extendsMode) {
3327 ZVAL_BOOL(_9$$36, 1);
3328 } else {
3329 ZVAL_BOOL(_9$$36, 0);
3330 }
3331 ZEPHIR_CALL_METHOD(&compilation, this_ptr, "compilefile", NULL, 0, templatePath, realCompiledPath, _9$$36);
3332 zephir_check_call_status();
3333 }
3334 } else {
3335 if (!((zephir_file_exists(realCompiledPath TSRMLS_CC) == SUCCESS))) {
3336 ZEPHIR_INIT_VAR(_10$$38);
3337 if (extendsMode) {
3338 ZVAL_BOOL(_10$$38, 1);
3339 } else {
3340 ZVAL_BOOL(_10$$38, 0);
3341 }
3342 ZEPHIR_CALL_METHOD(&compilation, this_ptr, "compilefile", NULL, 0, templatePath, realCompiledPath, _10$$38);
3343 zephir_check_call_status();
3344 }
3345 }
3346 }
3347 zephir_update_property_this(getThis(), SL("_compiledTemplatePath"), realCompiledPath TSRMLS_CC);
3348 RETURN_CCTOR(compilation);
3349
3350 }
3351
3352 /**
3353 * Returns the path that is currently being compiled
3354 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,getTemplatePath)3355 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getTemplatePath) {
3356
3357
3358
3359 RETURN_MEMBER(getThis(), "_currentPath");
3360
3361 }
3362
3363 /**
3364 * Returns the path to the last compiled template
3365 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,getCompiledTemplatePath)3366 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getCompiledTemplatePath) {
3367
3368
3369
3370 RETURN_MEMBER(getThis(), "_compiledTemplatePath");
3371
3372 }
3373
3374 /**
3375 * Parses a Volt template returning its intermediate representation
3376 *
3377 *<code>
3378 * print_r(
3379 * $compiler->parse("{{ 3 + 2 }}")
3380 * );
3381 *</code>
3382 *
3383 * @param string viewCode
3384 * @return array
3385 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,parse)3386 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, parse) {
3387
3388 zend_long ZEPHIR_LAST_CALL_STATUS;
3389 zval *viewCode_param = NULL, *currentPath = NULL;
3390 zval *viewCode = NULL;
3391
3392 ZEPHIR_MM_GROW();
3393 zephir_fetch_params(1, 1, 0, &viewCode_param);
3394
3395 if (UNEXPECTED(Z_TYPE_P(viewCode_param) != IS_STRING && Z_TYPE_P(viewCode_param) != IS_NULL)) {
3396 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'viewCode' must be a string") TSRMLS_CC);
3397 RETURN_MM_NULL();
3398 }
3399 if (EXPECTED(Z_TYPE_P(viewCode_param) == IS_STRING)) {
3400 zephir_get_strval(viewCode, viewCode_param);
3401 } else {
3402 ZEPHIR_INIT_VAR(viewCode);
3403 ZVAL_EMPTY_STRING(viewCode);
3404 }
3405
3406
3407 ZEPHIR_INIT_VAR(currentPath);
3408 ZVAL_STRING(currentPath, "eval code", 1);
3409 ZEPHIR_LAST_CALL_STATUS = phvolt_parse_view(return_value, viewCode, currentPath TSRMLS_CC);
3410 zephir_check_call_status();
3411 RETURN_MM();
3412
3413 }
3414
3415 /**
3416 * Gets the final path with VIEW
3417 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler,getFinalPath)3418 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getFinalPath) {
3419
3420 HashTable *_1$$4;
3421 HashPosition _0$$4;
3422 zend_long ZEPHIR_LAST_CALL_STATUS;
3423 zval *path_param = NULL, *view = NULL, *viewsDirs = NULL, *viewsDir = NULL, **_2$$4, *_3$$5 = NULL;
3424 zval *path = NULL;
3425
3426 ZEPHIR_MM_GROW();
3427 zephir_fetch_params(1, 1, 0, &path_param);
3428
3429 zephir_get_strval(path, path_param);
3430
3431
3432 ZEPHIR_OBS_VAR(view);
3433 zephir_read_property_this(&view, this_ptr, SL("_view"), PH_NOISY_CC);
3434 if (Z_TYPE_P(view) == IS_OBJECT) {
3435 ZEPHIR_CALL_METHOD(&viewsDirs, view, "getviewsdir", NULL, 0);
3436 zephir_check_call_status();
3437 if (Z_TYPE_P(viewsDirs) == IS_ARRAY) {
3438 zephir_is_iterable(viewsDirs, &_1$$4, &_0$$4, 0, 0, "phalcon/mvc/view/engine/volt/compiler.zep", 2740);
3439 for (
3440 ; zend_hash_get_current_data_ex(_1$$4, (void**) &_2$$4, &_0$$4) == SUCCESS
3441 ; zend_hash_move_forward_ex(_1$$4, &_0$$4)
3442 ) {
3443 ZEPHIR_GET_HVALUE(viewsDir, _2$$4);
3444 ZEPHIR_INIT_LNVAR(_3$$5);
3445 ZEPHIR_CONCAT_VV(_3$$5, viewsDir, path);
3446 if ((zephir_file_exists(_3$$5 TSRMLS_CC) == SUCCESS)) {
3447 ZEPHIR_CONCAT_VV(return_value, viewsDir, path);
3448 RETURN_MM();
3449 }
3450 }
3451 ZEPHIR_CONCAT_VV(return_value, viewsDir, path);
3452 RETURN_MM();
3453 } else {
3454 ZEPHIR_CONCAT_VV(return_value, viewsDirs, path);
3455 RETURN_MM();
3456 }
3457 }
3458 RETURN_CTOR(path);
3459
3460 }
3461
3462