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/array.h"
16 #include "kernel/memory.h"
17 #include "kernel/object.h"
18 #include "kernel/exception.h"
19 #include "kernel/fcall.h"
20 #include "kernel/concat.h"
21 #include "ext/spl/spl_exceptions.h"
22 #include "kernel/operators.h"
23 #include "kernel/string.h"
24 #include "kernel/require.h"
25
26
27 /**
28 * This file is part of the Phalcon Framework.
29 *
30 * (c) Phalcon Team <team@phalcon.io>
31 *
32 * For the full copyright and license information, please view the LICENSE.txt
33 * file that was distributed with this source code.
34 */
35 /**
36 * Designer friendly and fast template engine for PHP written in Zephir/C
37 */
ZEPHIR_INIT_CLASS(Phalcon_Mvc_View_Engine_Volt)38 ZEPHIR_INIT_CLASS(Phalcon_Mvc_View_Engine_Volt) {
39
40 ZEPHIR_REGISTER_CLASS_EX(Phalcon\\Mvc\\View\\Engine, Volt, phalcon, mvc_view_engine_volt, phalcon_mvc_view_engine_abstractengine_ce, phalcon_mvc_view_engine_volt_method_entry, 0);
41
42 zend_declare_property_null(phalcon_mvc_view_engine_volt_ce, SL("compiler"), ZEND_ACC_PROTECTED);
43
44 zend_declare_property_null(phalcon_mvc_view_engine_volt_ce, SL("eventsManager"), ZEND_ACC_PROTECTED);
45
46 zend_declare_property_null(phalcon_mvc_view_engine_volt_ce, SL("macros"), ZEND_ACC_PROTECTED);
47
48 zend_declare_property_null(phalcon_mvc_view_engine_volt_ce, SL("options"), ZEND_ACC_PROTECTED);
49
50 zend_class_implements(phalcon_mvc_view_engine_volt_ce, 1, phalcon_events_eventsawareinterface_ce);
51 return SUCCESS;
52
53 }
54
55 /**
56 * Checks if a macro is defined and calls it
57 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,callMacro)58 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, callMacro) {
59
60 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
61 zend_long ZEPHIR_LAST_CALL_STATUS;
62 zval arguments;
63 zval *name_param = NULL, *arguments_param = NULL, macro, _0, _1$$3;
64 zval name, _2$$3;
65 zval *this_ptr = getThis();
66
67 ZVAL_UNDEF(&name);
68 ZVAL_UNDEF(&_2$$3);
69 ZVAL_UNDEF(¯o);
70 ZVAL_UNDEF(&_0);
71 ZVAL_UNDEF(&_1$$3);
72 ZVAL_UNDEF(&arguments);
73
74 ZEPHIR_MM_GROW();
75 zephir_fetch_params(1, 1, 1, &name_param, &arguments_param);
76
77 if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
78 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
79 RETURN_MM_NULL();
80 }
81 if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
82 zephir_get_strval(&name, name_param);
83 } else {
84 ZEPHIR_INIT_VAR(&name);
85 ZVAL_EMPTY_STRING(&name);
86 }
87 if (!arguments_param) {
88 ZEPHIR_INIT_VAR(&arguments);
89 array_init(&arguments);
90 } else {
91 zephir_get_arrval(&arguments, arguments_param);
92 }
93
94
95 ZEPHIR_OBS_VAR(¯o);
96 zephir_read_property(&_0, this_ptr, ZEND_STRL("macros"), PH_NOISY_CC | PH_READONLY);
97 if (UNEXPECTED(!(zephir_array_isset_fetch(¯o, &_0, &name, 0)))) {
98 ZEPHIR_INIT_VAR(&_1$$3);
99 object_init_ex(&_1$$3, phalcon_mvc_view_exception_ce);
100 ZEPHIR_INIT_VAR(&_2$$3);
101 ZEPHIR_CONCAT_SVS(&_2$$3, "Macro '", &name, "' does not exist");
102 ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 8, &_2$$3);
103 zephir_check_call_status();
104 zephir_throw_exception_debug(&_1$$3, "phalcon/Mvc/View/Engine/Volt.zep", 37);
105 ZEPHIR_MM_RESTORE();
106 return;
107 }
108 ZEPHIR_RETURN_CALL_FUNCTION("call_user_func", NULL, 275, ¯o, &arguments);
109 zephir_check_call_status();
110 RETURN_MM();
111
112 }
113
114 /**
115 * Performs a string conversion
116 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,convertEncoding)117 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, convertEncoding) {
118
119 zend_bool _0, _1;
120 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
121 zend_long ZEPHIR_LAST_CALL_STATUS;
122 zval *text_param = NULL, *from_param = NULL, *to_param = NULL;
123 zval text, from, to;
124 zval *this_ptr = getThis();
125
126 ZVAL_UNDEF(&text);
127 ZVAL_UNDEF(&from);
128 ZVAL_UNDEF(&to);
129
130 ZEPHIR_MM_GROW();
131 zephir_fetch_params(1, 3, 0, &text_param, &from_param, &to_param);
132
133 zephir_get_strval(&text, text_param);
134 if (UNEXPECTED(Z_TYPE_P(from_param) != IS_STRING && Z_TYPE_P(from_param) != IS_NULL)) {
135 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'from' must be of the type string"));
136 RETURN_MM_NULL();
137 }
138 if (EXPECTED(Z_TYPE_P(from_param) == IS_STRING)) {
139 zephir_get_strval(&from, from_param);
140 } else {
141 ZEPHIR_INIT_VAR(&from);
142 ZVAL_EMPTY_STRING(&from);
143 }
144 if (UNEXPECTED(Z_TYPE_P(to_param) != IS_STRING && Z_TYPE_P(to_param) != IS_NULL)) {
145 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'to' must be of the type string"));
146 RETURN_MM_NULL();
147 }
148 if (EXPECTED(Z_TYPE_P(to_param) == IS_STRING)) {
149 zephir_get_strval(&to, to_param);
150 } else {
151 ZEPHIR_INIT_VAR(&to);
152 ZVAL_EMPTY_STRING(&to);
153 }
154
155
156 _0 = ZEPHIR_IS_STRING(&from, "latin1");
157 if (!(_0)) {
158 _0 = ZEPHIR_IS_STRING(&to, "utf8");
159 }
160 if (_0) {
161 ZEPHIR_RETURN_CALL_FUNCTION("utf8_encode", NULL, 0, &text);
162 zephir_check_call_status();
163 RETURN_MM();
164 }
165 _1 = ZEPHIR_IS_STRING(&to, "latin1");
166 if (!(_1)) {
167 _1 = ZEPHIR_IS_STRING(&from, "utf8");
168 }
169 if (_1) {
170 ZEPHIR_RETURN_CALL_FUNCTION("utf8_decode", NULL, 260, &text);
171 zephir_check_call_status();
172 RETURN_MM();
173 }
174 if ((zephir_function_exists_ex(ZEND_STRL("mb_convert_encoding")) == SUCCESS)) {
175 ZEPHIR_RETURN_CALL_FUNCTION("mb_convert_encoding", NULL, 248, &text, &from, &to);
176 zephir_check_call_status();
177 RETURN_MM();
178 }
179 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_exception_ce, "'mbstring' is required to perform the charset conversion", "phalcon/Mvc/View/Engine/Volt.zep", 74);
180 return;
181
182 }
183
184 /**
185 * Returns the Volt's compiler
186 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,getCompiler)187 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, getCompiler) {
188
189 zval compiler, container, options, _0, _1$$3, _2$$3;
190 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
191 zend_long ZEPHIR_LAST_CALL_STATUS;
192 zval *this_ptr = getThis();
193
194 ZVAL_UNDEF(&compiler);
195 ZVAL_UNDEF(&container);
196 ZVAL_UNDEF(&options);
197 ZVAL_UNDEF(&_0);
198 ZVAL_UNDEF(&_1$$3);
199 ZVAL_UNDEF(&_2$$3);
200
201 ZEPHIR_MM_GROW();
202
203 zephir_read_property(&_0, this_ptr, ZEND_STRL("compiler"), PH_NOISY_CC | PH_READONLY);
204 ZEPHIR_CPY_WRT(&compiler, &_0);
205 if (Z_TYPE_P(&compiler) != IS_OBJECT) {
206 ZEPHIR_INIT_NVAR(&compiler);
207 object_init_ex(&compiler, phalcon_mvc_view_engine_volt_compiler_ce);
208 zephir_read_property(&_1$$3, this_ptr, ZEND_STRL("view"), PH_NOISY_CC | PH_READONLY);
209 ZEPHIR_CALL_METHOD(NULL, &compiler, "__construct", NULL, 0, &_1$$3);
210 zephir_check_call_status();
211 zephir_read_property(&_2$$3, this_ptr, ZEND_STRL("container"), PH_NOISY_CC | PH_READONLY);
212 ZEPHIR_CPY_WRT(&container, &_2$$3);
213 if (Z_TYPE_P(&container) == IS_OBJECT) {
214 ZEPHIR_CALL_METHOD(NULL, &compiler, "setdi", NULL, 0, &container);
215 zephir_check_call_status();
216 }
217 zephir_read_property(&_2$$3, this_ptr, ZEND_STRL("options"), PH_NOISY_CC | PH_READONLY);
218 ZEPHIR_CPY_WRT(&options, &_2$$3);
219 if (Z_TYPE_P(&options) == IS_ARRAY) {
220 ZEPHIR_CALL_METHOD(NULL, &compiler, "setoptions", NULL, 0, &options);
221 zephir_check_call_status();
222 }
223 zephir_update_property_zval(this_ptr, ZEND_STRL("compiler"), &compiler);
224 }
225 RETURN_CCTOR(&compiler);
226
227 }
228
229 /**
230 * Returns the internal event manager
231 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,getEventsManager)232 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, getEventsManager) {
233
234 zval *this_ptr = getThis();
235
236
237 RETURN_MEMBER(getThis(), "eventsManager");
238
239 }
240
241 /**
242 * Return Volt's options
243 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,getOptions)244 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, getOptions) {
245
246 zval *this_ptr = getThis();
247
248
249 RETURN_MEMBER(getThis(), "options");
250
251 }
252
253 /**
254 * Checks if the needle is included in the haystack
255 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,isIncluded)256 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, isIncluded) {
257
258 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
259 zend_long ZEPHIR_LAST_CALL_STATUS;
260 zval *needle, needle_sub, *haystack, haystack_sub, _0$$5, _1$$4;
261 zval *this_ptr = getThis();
262
263 ZVAL_UNDEF(&needle_sub);
264 ZVAL_UNDEF(&haystack_sub);
265 ZVAL_UNDEF(&_0$$5);
266 ZVAL_UNDEF(&_1$$4);
267
268 ZEPHIR_MM_GROW();
269 zephir_fetch_params(1, 2, 0, &needle, &haystack);
270
271
272
273 if (Z_TYPE_P(haystack) == IS_ARRAY) {
274 RETURN_MM_BOOL(zephir_fast_in_array(needle, haystack));
275 }
276 if (Z_TYPE_P(haystack) == IS_STRING) {
277 if ((zephir_function_exists_ex(ZEND_STRL("mb_strpos")) == SUCCESS)) {
278 ZEPHIR_CALL_FUNCTION(&_0$$5, "mb_strpos", NULL, 293, haystack, needle);
279 zephir_check_call_status();
280 RETURN_MM_BOOL(!ZEPHIR_IS_FALSE_IDENTICAL(&_0$$5));
281 }
282 ZEPHIR_INIT_VAR(&_1$$4);
283 zephir_fast_strpos(&_1$$4, haystack, needle, 0 );
284 RETURN_MM_BOOL(!ZEPHIR_IS_FALSE_IDENTICAL(&_1$$4));
285 }
286 ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_mvc_view_exception_ce, "Invalid haystack", "phalcon/Mvc/View/Engine/Volt.zep", 146);
287 return;
288
289 }
290
291 /**
292 * Length filter. If an array/object is passed a count is performed otherwise a strlen/mb_strlen
293 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,length)294 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, length) {
295
296 zend_bool _0;
297 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
298 zend_long ZEPHIR_LAST_CALL_STATUS;
299 zval *item, item_sub;
300 zval *this_ptr = getThis();
301
302 ZVAL_UNDEF(&item_sub);
303
304 ZEPHIR_MM_GROW();
305 zephir_fetch_params(1, 1, 0, &item);
306
307
308
309 _0 = Z_TYPE_P(item) == IS_OBJECT;
310 if (!(_0)) {
311 _0 = Z_TYPE_P(item) == IS_ARRAY;
312 }
313 if (_0) {
314 RETURN_MM_LONG(zephir_fast_count_int(item));
315 }
316 if ((zephir_function_exists_ex(ZEND_STRL("mb_strlen")) == SUCCESS)) {
317 ZEPHIR_RETURN_CALL_FUNCTION("mb_strlen", NULL, 301, item);
318 zephir_check_call_status();
319 RETURN_MM();
320 }
321 RETURN_MM_LONG(zephir_fast_strlen_ev(item));
322
323 }
324
325 /**
326 * Renders a view using the template engine
327 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,render)328 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, render) {
329
330 zend_string *_8$$8;
331 zend_ulong _7$$8;
332 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
333 zend_long ZEPHIR_LAST_CALL_STATUS;
334 zend_bool mustClean;
335 zval *templatePath_param = NULL, *params, params_sub, *mustClean_param = NULL, compiler, compiledTemplatePath, eventsManager, key, value, _0, _1$$4, _2$$4, _3$$6, _4$$6, *_5$$8, _6$$8, _9$$9, _10$$10, _11$$11, _12$$11;
336 zval templatePath;
337 zval *this_ptr = getThis();
338
339 ZVAL_UNDEF(&templatePath);
340 ZVAL_UNDEF(¶ms_sub);
341 ZVAL_UNDEF(&compiler);
342 ZVAL_UNDEF(&compiledTemplatePath);
343 ZVAL_UNDEF(&eventsManager);
344 ZVAL_UNDEF(&key);
345 ZVAL_UNDEF(&value);
346 ZVAL_UNDEF(&_0);
347 ZVAL_UNDEF(&_1$$4);
348 ZVAL_UNDEF(&_2$$4);
349 ZVAL_UNDEF(&_3$$6);
350 ZVAL_UNDEF(&_4$$6);
351 ZVAL_UNDEF(&_6$$8);
352 ZVAL_UNDEF(&_9$$9);
353 ZVAL_UNDEF(&_10$$10);
354 ZVAL_UNDEF(&_11$$11);
355 ZVAL_UNDEF(&_12$$11);
356
357 ZEPHIR_MM_GROW();
358 zephir_fetch_params(1, 2, 1, &templatePath_param, ¶ms, &mustClean_param);
359
360 if (UNEXPECTED(Z_TYPE_P(templatePath_param) != IS_STRING && Z_TYPE_P(templatePath_param) != IS_NULL)) {
361 zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'templatePath' must be of the type string"));
362 RETURN_MM_NULL();
363 }
364 if (EXPECTED(Z_TYPE_P(templatePath_param) == IS_STRING)) {
365 zephir_get_strval(&templatePath, templatePath_param);
366 } else {
367 ZEPHIR_INIT_VAR(&templatePath);
368 ZVAL_EMPTY_STRING(&templatePath);
369 }
370 if (!mustClean_param) {
371 mustClean = 0;
372 } else {
373 mustClean = zephir_get_boolval(mustClean_param);
374 }
375
376
377 if (mustClean) {
378 ZEPHIR_CALL_FUNCTION(NULL, "ob_clean", NULL, 0);
379 zephir_check_call_status();
380 }
381 ZEPHIR_CALL_METHOD(&compiler, this_ptr, "getcompiler", NULL, 0);
382 zephir_check_call_status();
383 zephir_read_property(&_0, this_ptr, ZEND_STRL("eventsManager"), PH_NOISY_CC | PH_READONLY);
384 ZEPHIR_CPY_WRT(&eventsManager, &_0);
385 if (Z_TYPE_P(&eventsManager) == IS_OBJECT) {
386 ZEPHIR_INIT_VAR(&_2$$4);
387 ZVAL_STRING(&_2$$4, "view:beforeCompile");
388 ZEPHIR_CALL_METHOD(&_1$$4, &eventsManager, "fire", NULL, 0, &_2$$4, this_ptr);
389 zephir_check_call_status();
390 if (ZEPHIR_IS_FALSE_IDENTICAL(&_1$$4)) {
391 RETURN_MM_NULL();
392 }
393 }
394 ZEPHIR_CALL_METHOD(NULL, &compiler, "compile", NULL, 0, &templatePath);
395 zephir_check_call_status();
396 if (Z_TYPE_P(&eventsManager) == IS_OBJECT) {
397 ZEPHIR_INIT_VAR(&_4$$6);
398 ZVAL_STRING(&_4$$6, "view:afterCompile");
399 ZEPHIR_CALL_METHOD(&_3$$6, &eventsManager, "fire", NULL, 0, &_4$$6, this_ptr);
400 zephir_check_call_status();
401 if (ZEPHIR_IS_FALSE_IDENTICAL(&_3$$6)) {
402 RETURN_MM_NULL();
403 }
404 }
405 ZEPHIR_CALL_METHOD(&compiledTemplatePath, &compiler, "getcompiledtemplatepath", NULL, 0);
406 zephir_check_call_status();
407 if (Z_TYPE_P(params) == IS_ARRAY) {
408 zephir_is_iterable(params, 0, "phalcon/Mvc/View/Engine/Volt.zep", 205);
409 if (Z_TYPE_P(params) == IS_ARRAY) {
410 ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(params), _7$$8, _8$$8, _5$$8)
411 {
412 ZEPHIR_INIT_NVAR(&key);
413 if (_8$$8 != NULL) {
414 ZVAL_STR_COPY(&key, _8$$8);
415 } else {
416 ZVAL_LONG(&key, _7$$8);
417 }
418 ZEPHIR_INIT_NVAR(&value);
419 ZVAL_COPY(&value, _5$$8);
420 ZEPHIR_CPY_WRT(&_9$$9, &value);
421 if (zephir_set_symbol(&key, &_9$$9) == FAILURE) {
422 return;
423 }
424 } ZEND_HASH_FOREACH_END();
425 } else {
426 ZEPHIR_CALL_METHOD(NULL, params, "rewind", NULL, 0);
427 zephir_check_call_status();
428 while (1) {
429 ZEPHIR_CALL_METHOD(&_6$$8, params, "valid", NULL, 0);
430 zephir_check_call_status();
431 if (!zend_is_true(&_6$$8)) {
432 break;
433 }
434 ZEPHIR_CALL_METHOD(&key, params, "key", NULL, 0);
435 zephir_check_call_status();
436 ZEPHIR_CALL_METHOD(&value, params, "current", NULL, 0);
437 zephir_check_call_status();
438 ZEPHIR_CPY_WRT(&_10$$10, &value);
439 if (zephir_set_symbol(&key, &_10$$10) == FAILURE) {
440 return;
441 }
442 ZEPHIR_CALL_METHOD(NULL, params, "next", NULL, 0);
443 zephir_check_call_status();
444 }
445 }
446 ZEPHIR_INIT_NVAR(&value);
447 ZEPHIR_INIT_NVAR(&key);
448 }
449 if (zephir_require_zval(&compiledTemplatePath) == FAILURE) {
450 RETURN_MM_NULL();
451 }
452 if (mustClean) {
453 zephir_read_property(&_11$$11, this_ptr, ZEND_STRL("view"), PH_NOISY_CC | PH_READONLY);
454 ZEPHIR_CALL_FUNCTION(&_12$$11, "ob_get_contents", NULL, 0);
455 zephir_check_call_status();
456 ZEPHIR_CALL_METHOD(NULL, &_11$$11, "setcontent", NULL, 0, &_12$$11);
457 zephir_check_call_status();
458 }
459 ZEPHIR_MM_RESTORE();
460
461 }
462
463 /**
464 * Sets the events manager
465 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,setEventsManager)466 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, setEventsManager) {
467
468 zval *eventsManager, eventsManager_sub;
469 zval *this_ptr = getThis();
470
471 ZVAL_UNDEF(&eventsManager_sub);
472
473 zephir_fetch_params_without_memory_grow(1, 0, &eventsManager);
474
475
476
477 zephir_update_property_zval(this_ptr, ZEND_STRL("eventsManager"), eventsManager);
478
479 }
480
481 /**
482 * Set Volt's options
483 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,setOptions)484 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, setOptions) {
485
486 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
487 zval *options_param = NULL;
488 zval options;
489 zval *this_ptr = getThis();
490
491 ZVAL_UNDEF(&options);
492
493 ZEPHIR_MM_GROW();
494 zephir_fetch_params(1, 1, 0, &options_param);
495
496 ZEPHIR_OBS_COPY_OR_DUP(&options, options_param);
497
498
499 zephir_update_property_zval(this_ptr, ZEND_STRL("options"), &options);
500 ZEPHIR_MM_RESTORE();
501
502 }
503
504 /**
505 * Extracts a slice from a string/array/traversable object value
506 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,slice)507 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, slice) {
508
509 zend_bool _1$$5;
510 zval slice;
511 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
512 zephir_fcall_cache_entry *_3 = NULL, *_4 = NULL;
513 zend_long start, ZEPHIR_LAST_CALL_STATUS, position = 0;
514 zval *value, value_sub, *start_param = NULL, *end = NULL, end_sub, __$null, length, _9, _0$$3, _2$$6, _5$$9, _6$$11, _7$$10, _8$$12;
515 zval *this_ptr = getThis();
516
517 ZVAL_UNDEF(&value_sub);
518 ZVAL_UNDEF(&end_sub);
519 ZVAL_NULL(&__$null);
520 ZVAL_UNDEF(&length);
521 ZVAL_UNDEF(&_9);
522 ZVAL_UNDEF(&_0$$3);
523 ZVAL_UNDEF(&_2$$6);
524 ZVAL_UNDEF(&_5$$9);
525 ZVAL_UNDEF(&_6$$11);
526 ZVAL_UNDEF(&_7$$10);
527 ZVAL_UNDEF(&_8$$12);
528 ZVAL_UNDEF(&slice);
529
530 ZEPHIR_MM_GROW();
531 zephir_fetch_params(1, 1, 2, &value, &start_param, &end);
532
533 if (!start_param) {
534 start = 0;
535 } else {
536 start = zephir_get_intval(start_param);
537 }
538 if (!end) {
539 end = &end_sub;
540 ZEPHIR_CPY_WRT(end, &__$null);
541 } else {
542 ZEPHIR_SEPARATE_PARAM(end);
543 }
544
545
546 if (Z_TYPE_P(value) == IS_OBJECT) {
547 if (Z_TYPE_P(end) == IS_NULL) {
548 ZEPHIR_INIT_NVAR(end);
549 ZVAL_LONG(end, (zephir_fast_count_int(value) - 1));
550 }
551 position = 0;
552 ZEPHIR_INIT_VAR(&slice);
553 array_init(&slice);
554 ZEPHIR_CALL_METHOD(NULL, value, "rewind", NULL, 0);
555 zephir_check_call_status();
556 while (1) {
557 ZEPHIR_CALL_METHOD(&_0$$3, value, "valid", NULL, 0);
558 zephir_check_call_status();
559 if (!(zephir_is_true(&_0$$3))) {
560 break;
561 }
562 _1$$5 = position >= start;
563 if (_1$$5) {
564 _1$$5 = ZEPHIR_GE_LONG(end, position);
565 }
566 if (_1$$5) {
567 ZEPHIR_CALL_METHOD(&_2$$6, value, "current", &_3, 0);
568 zephir_check_call_status();
569 zephir_array_append(&slice, &_2$$6, PH_SEPARATE, "phalcon/Mvc/View/Engine/Volt.zep", 254);
570 }
571 ZEPHIR_CALL_METHOD(NULL, value, "next", &_4, 0);
572 zephir_check_call_status();
573 position++;
574 }
575 RETURN_CTOR(&slice);
576 }
577 ZEPHIR_INIT_VAR(&length);
578 if (Z_TYPE_P(end) != IS_NULL) {
579 ZVAL_LONG(&length, (((zephir_get_numberval(end) - start)) + 1));
580 } else {
581 ZVAL_NULL(&length);
582 }
583 if (Z_TYPE_P(value) == IS_ARRAY) {
584 ZVAL_LONG(&_5$$9, start);
585 ZEPHIR_RETURN_CALL_FUNCTION("array_slice", NULL, 280, value, &_5$$9, &length);
586 zephir_check_call_status();
587 RETURN_MM();
588 }
589 if ((zephir_function_exists_ex(ZEND_STRL("mb_substr")) == SUCCESS)) {
590 if (Z_TYPE_P(&length) != IS_NULL) {
591 ZVAL_LONG(&_6$$11, start);
592 ZEPHIR_RETURN_CALL_FUNCTION("mb_substr", NULL, 183, value, &_6$$11, &length);
593 zephir_check_call_status();
594 RETURN_MM();
595 }
596 ZVAL_LONG(&_7$$10, start);
597 ZEPHIR_RETURN_CALL_FUNCTION("mb_substr", NULL, 183, value, &_7$$10);
598 zephir_check_call_status();
599 RETURN_MM();
600 }
601 if (Z_TYPE_P(&length) != IS_NULL) {
602 ZVAL_LONG(&_8$$12, start);
603 zephir_substr(return_value, value, zephir_get_intval(&_8$$12), zephir_get_intval(&length), 0);
604 RETURN_MM();
605 }
606 ZVAL_LONG(&_9, start);
607 zephir_substr(return_value, value, zephir_get_intval(&_9), 0, ZEPHIR_SUBSTR_NO_LENGTH);
608 RETURN_MM();
609
610 }
611
612 /**
613 * Sorts an array
614 */
PHP_METHOD(Phalcon_Mvc_View_Engine_Volt,sort)615 PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, sort) {
616
617 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
618 zend_long ZEPHIR_LAST_CALL_STATUS;
619 zval *value_param = NULL;
620 zval value;
621 zval *this_ptr = getThis();
622
623 ZVAL_UNDEF(&value);
624
625 ZEPHIR_MM_GROW();
626 zephir_fetch_params(1, 1, 0, &value_param);
627
628 zephir_get_arrval(&value, value_param);
629
630
631 ZEPHIR_MAKE_REF(&value);
632 ZEPHIR_CALL_FUNCTION(NULL, "asort", NULL, 0, &value);
633 ZEPHIR_UNREF(&value);
634 zephir_check_call_status();
635 RETURN_CTOR(&value);
636
637 }
638
639