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/memory.h"
16 #include "kernel/object.h"
17 #include "kernel/fcall.h"
18 #include "kernel/operators.h"
19 #include "kernel/concat.h"
20 #include "kernel/array.h"
21 #include "kernel/string.h"
22
23
24 /**
25 * This file is part of the Phalcon.
26 *
27 * (c) Phalcon Team <team@phalcon.com>
28 *
29 * For the full copyright and license information, please view the LICENSE
30 * file that was distributed with this source code.
31 */
32 /**
33 * Class AbstractHelper
34 *
35 * @property string $delimiter
36 * @property Escaper $escaper
37 * @property string $indent
38 * @property int $indentLevel
39 */
ZEPHIR_INIT_CLASS(Phalcon_Html_Helper_AbstractHelper)40 ZEPHIR_INIT_CLASS(Phalcon_Html_Helper_AbstractHelper) {
41
42 ZEPHIR_REGISTER_CLASS(Phalcon\\Html\\Helper, AbstractHelper, phalcon, html_helper_abstracthelper, phalcon_html_helper_abstracthelper_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS);
43
44 /**
45 * @var string
46 */
47 zend_declare_property_string(phalcon_html_helper_abstracthelper_ce, SL("delimiter"), "", ZEND_ACC_PROTECTED);
48
49 /**
50 * @var EscaperInterface
51 */
52 zend_declare_property_null(phalcon_html_helper_abstracthelper_ce, SL("escaper"), ZEND_ACC_PROTECTED);
53
54 /**
55 * @var string
56 */
57 zend_declare_property_string(phalcon_html_helper_abstracthelper_ce, SL("indent"), " ", ZEND_ACC_PROTECTED);
58
59 /**
60 * @var int
61 */
62 zend_declare_property_long(phalcon_html_helper_abstracthelper_ce, SL("indentLevel"), 1, ZEND_ACC_PROTECTED);
63
64 return SUCCESS;
65
66 }
67
68 /**
69 * AbstractHelper constructor.
70 *
71 * @param Escaper $escaper
72 */
PHP_METHOD(Phalcon_Html_Helper_AbstractHelper,__construct)73 PHP_METHOD(Phalcon_Html_Helper_AbstractHelper, __construct) {
74
75 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
76 zval *escaper, escaper_sub, _0;
77 zval *this_ptr = getThis();
78
79 ZVAL_UNDEF(&escaper_sub);
80 ZVAL_UNDEF(&_0);
81
82 ZEPHIR_MM_GROW();
83 zephir_fetch_params(1, 1, 0, &escaper);
84
85
86
87 ZEPHIR_INIT_VAR(&_0);
88 ZEPHIR_GET_CONSTANT(&_0, "PHP_EOL");
89 zephir_update_property_zval(this_ptr, ZEND_STRL("delimiter"), &_0);
90 zephir_update_property_zval(this_ptr, ZEND_STRL("escaper"), escaper);
91 ZEPHIR_MM_RESTORE();
92
93 }
94
95 /**
96 * Produces a closing tag
97 *
98 * @param string $tag
99 * @param bool $raw
100 *
101 * @return string
102 */
PHP_METHOD(Phalcon_Html_Helper_AbstractHelper,close)103 PHP_METHOD(Phalcon_Html_Helper_AbstractHelper, close) {
104
105 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
106 zend_long ZEPHIR_LAST_CALL_STATUS;
107 zend_bool raw;
108 zval *tag_param = NULL, *raw_param = NULL, _0, _1;
109 zval tag;
110 zval *this_ptr = getThis();
111
112 ZVAL_UNDEF(&tag);
113 ZVAL_UNDEF(&_0);
114 ZVAL_UNDEF(&_1);
115
116 ZEPHIR_MM_GROW();
117 zephir_fetch_params(1, 1, 1, &tag_param, &raw_param);
118
119 zephir_get_strval(&tag, tag_param);
120 if (!raw_param) {
121 raw = 0;
122 } else {
123 raw = zephir_get_boolval(raw_param);
124 }
125
126
127 ZEPHIR_INIT_VAR(&_0);
128 if (raw) {
129 ZEPHIR_CPY_WRT(&_0, &tag);
130 } else {
131 zephir_read_property(&_1, this_ptr, ZEND_STRL("escaper"), PH_NOISY_CC | PH_READONLY);
132 ZEPHIR_CALL_METHOD(&_0, &_1, "html", NULL, 0, &tag);
133 zephir_check_call_status();
134 }
135 zephir_get_strval(&tag, &_0);
136 ZEPHIR_CONCAT_SVS(return_value, "</", &tag, ">");
137 RETURN_MM();
138
139 }
140
141 /**
142 * Replicates the indent x times as per indentLevel
143 *
144 * @return string
145 */
PHP_METHOD(Phalcon_Html_Helper_AbstractHelper,indent)146 PHP_METHOD(Phalcon_Html_Helper_AbstractHelper, indent) {
147
148 zval _0, _1;
149 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
150 zend_long ZEPHIR_LAST_CALL_STATUS;
151 zval *this_ptr = getThis();
152
153 ZVAL_UNDEF(&_0);
154 ZVAL_UNDEF(&_1);
155
156 ZEPHIR_MM_GROW();
157
158 zephir_read_property(&_0, this_ptr, ZEND_STRL("indent"), PH_NOISY_CC | PH_READONLY);
159 zephir_read_property(&_1, this_ptr, ZEND_STRL("indentLevel"), PH_NOISY_CC | PH_READONLY);
160 ZEPHIR_RETURN_CALL_FUNCTION("str_repeat", NULL, 1, &_0, &_1);
161 zephir_check_call_status();
162 RETURN_MM();
163
164 }
165
166 /**
167 * Keeps all the attributes sorted - same order all the tome
168 *
169 * @param array $overrides
170 * @param array $attributes
171 *
172 * @return array
173 */
PHP_METHOD(Phalcon_Html_Helper_AbstractHelper,orderAttributes)174 PHP_METHOD(Phalcon_Html_Helper_AbstractHelper, orderAttributes) {
175
176 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
177 zend_long ZEPHIR_LAST_CALL_STATUS;
178 zval *overrides_param = NULL, *attributes_param = NULL, __$null, intersect, results, _0;
179 zval overrides, attributes, order;
180 zval *this_ptr = getThis();
181
182 ZVAL_UNDEF(&overrides);
183 ZVAL_UNDEF(&attributes);
184 ZVAL_UNDEF(&order);
185 ZVAL_NULL(&__$null);
186 ZVAL_UNDEF(&intersect);
187 ZVAL_UNDEF(&results);
188 ZVAL_UNDEF(&_0);
189
190 ZEPHIR_MM_GROW();
191 zephir_fetch_params(1, 2, 0, &overrides_param, &attributes_param);
192
193 zephir_get_arrval(&overrides, overrides_param);
194 zephir_get_arrval(&attributes, attributes_param);
195
196
197 ZEPHIR_INIT_VAR(&order);
198 zephir_create_array(&order, 10, 0);
199 zephir_array_update_string(&order, SL("rel"), &__$null, PH_COPY | PH_SEPARATE);
200 zephir_array_update_string(&order, SL("type"), &__$null, PH_COPY | PH_SEPARATE);
201 zephir_array_update_string(&order, SL("for"), &__$null, PH_COPY | PH_SEPARATE);
202 zephir_array_update_string(&order, SL("src"), &__$null, PH_COPY | PH_SEPARATE);
203 zephir_array_update_string(&order, SL("href"), &__$null, PH_COPY | PH_SEPARATE);
204 zephir_array_update_string(&order, SL("action"), &__$null, PH_COPY | PH_SEPARATE);
205 zephir_array_update_string(&order, SL("id"), &__$null, PH_COPY | PH_SEPARATE);
206 zephir_array_update_string(&order, SL("name"), &__$null, PH_COPY | PH_SEPARATE);
207 zephir_array_update_string(&order, SL("value"), &__$null, PH_COPY | PH_SEPARATE);
208 zephir_array_update_string(&order, SL("class"), &__$null, PH_COPY | PH_SEPARATE);
209 ZEPHIR_CALL_FUNCTION(&intersect, "array_intersect_key", NULL, 2, &order, &attributes);
210 zephir_check_call_status();
211 ZEPHIR_INIT_VAR(&results);
212 zephir_fast_array_merge(&results, &intersect, &attributes);
213 ZEPHIR_INIT_VAR(&_0);
214 zephir_fast_array_merge(&_0, &overrides, &results);
215 ZEPHIR_CPY_WRT(&results, &_0);
216 zephir_array_unset_string(&results, SL("escape"), PH_SEPARATE);
217 RETURN_CCTOR(&results);
218
219 }
220
221 /**
222 * Traverses an array and calls the method defined in the first element
223 * with attributes as the second, returning the resulting string
224 *
225 * @param array $elements
226 * @param string $delimiter
227 *
228 * @return string
229 */
PHP_METHOD(Phalcon_Html_Helper_AbstractHelper,renderArrayElements)230 PHP_METHOD(Phalcon_Html_Helper_AbstractHelper, renderArrayElements) {
231
232 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
233 zend_long ZEPHIR_LAST_CALL_STATUS;
234 zval delimiter;
235 zval *elements_param = NULL, *delimiter_param = NULL, item, result, *_0, _1, _2$$3, _3$$3, _5$$3, _6$$3, _7$$3, _8$$4, _9$$4, _11$$4, _12$$4, _13$$4;
236 zval elements, _4$$3, _10$$4;
237 zval *this_ptr = getThis();
238
239 ZVAL_UNDEF(&elements);
240 ZVAL_UNDEF(&_4$$3);
241 ZVAL_UNDEF(&_10$$4);
242 ZVAL_UNDEF(&item);
243 ZVAL_UNDEF(&result);
244 ZVAL_UNDEF(&_1);
245 ZVAL_UNDEF(&_2$$3);
246 ZVAL_UNDEF(&_3$$3);
247 ZVAL_UNDEF(&_5$$3);
248 ZVAL_UNDEF(&_6$$3);
249 ZVAL_UNDEF(&_7$$3);
250 ZVAL_UNDEF(&_8$$4);
251 ZVAL_UNDEF(&_9$$4);
252 ZVAL_UNDEF(&_11$$4);
253 ZVAL_UNDEF(&_12$$4);
254 ZVAL_UNDEF(&_13$$4);
255 ZVAL_UNDEF(&delimiter);
256
257 ZEPHIR_MM_GROW();
258 zephir_fetch_params(1, 2, 0, &elements_param, &delimiter_param);
259
260 zephir_get_arrval(&elements, elements_param);
261 zephir_get_strval(&delimiter, delimiter_param);
262
263
264 ZEPHIR_INIT_VAR(&result);
265 ZVAL_STRING(&result, "");
266 zephir_is_iterable(&elements, 0, "phalcon/Html/Helper/AbstractHelper.zep", 142);
267 if (Z_TYPE_P(&elements) == IS_ARRAY) {
268 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&elements), _0)
269 {
270 ZEPHIR_INIT_NVAR(&item);
271 ZVAL_COPY(&item, _0);
272 zephir_array_fetch_long(&_2$$3, &item, 2, PH_NOISY | PH_READONLY, "phalcon/Html/Helper/AbstractHelper.zep", 138);
273 ZEPHIR_INIT_NVAR(&_3$$3);
274 ZEPHIR_INIT_NVAR(&_4$$3);
275 zephir_create_array(&_4$$3, 2, 0);
276 zephir_array_fast_append(&_4$$3, this_ptr);
277 ZEPHIR_OBS_NVAR(&_5$$3);
278 zephir_array_fetch_long(&_5$$3, &item, 0, PH_NOISY, "phalcon/Html/Helper/AbstractHelper.zep", 138);
279 zephir_array_fast_append(&_4$$3, &_5$$3);
280 zephir_array_fetch_long(&_6$$3, &item, 1, PH_NOISY | PH_READONLY, "phalcon/Html/Helper/AbstractHelper.zep", 138);
281 ZEPHIR_CALL_USER_FUNC_ARRAY(&_3$$3, &_4$$3, &_6$$3);
282 zephir_check_call_status();
283 ZEPHIR_INIT_NVAR(&_7$$3);
284 ZEPHIR_CONCAT_VVV(&_7$$3, &_2$$3, &_3$$3, &delimiter);
285 zephir_concat_self(&result, &_7$$3);
286 } ZEND_HASH_FOREACH_END();
287 } else {
288 ZEPHIR_CALL_METHOD(NULL, &elements, "rewind", NULL, 0);
289 zephir_check_call_status();
290 while (1) {
291 ZEPHIR_CALL_METHOD(&_1, &elements, "valid", NULL, 0);
292 zephir_check_call_status();
293 if (!zend_is_true(&_1)) {
294 break;
295 }
296 ZEPHIR_CALL_METHOD(&item, &elements, "current", NULL, 0);
297 zephir_check_call_status();
298 zephir_array_fetch_long(&_8$$4, &item, 2, PH_NOISY | PH_READONLY, "phalcon/Html/Helper/AbstractHelper.zep", 138);
299 ZEPHIR_INIT_NVAR(&_9$$4);
300 ZEPHIR_INIT_NVAR(&_10$$4);
301 zephir_create_array(&_10$$4, 2, 0);
302 zephir_array_fast_append(&_10$$4, this_ptr);
303 ZEPHIR_OBS_NVAR(&_11$$4);
304 zephir_array_fetch_long(&_11$$4, &item, 0, PH_NOISY, "phalcon/Html/Helper/AbstractHelper.zep", 138);
305 zephir_array_fast_append(&_10$$4, &_11$$4);
306 zephir_array_fetch_long(&_12$$4, &item, 1, PH_NOISY | PH_READONLY, "phalcon/Html/Helper/AbstractHelper.zep", 138);
307 ZEPHIR_CALL_USER_FUNC_ARRAY(&_9$$4, &_10$$4, &_12$$4);
308 zephir_check_call_status();
309 ZEPHIR_INIT_NVAR(&_13$$4);
310 ZEPHIR_CONCAT_VVV(&_13$$4, &_8$$4, &_9$$4, &delimiter);
311 zephir_concat_self(&result, &_13$$4);
312 ZEPHIR_CALL_METHOD(NULL, &elements, "next", NULL, 0);
313 zephir_check_call_status();
314 }
315 }
316 ZEPHIR_INIT_NVAR(&item);
317 RETURN_CCTOR(&result);
318
319 }
320
321 /**
322 * Renders all the attributes
323 *
324 * @param array $attributes
325 *
326 * @return string
327 */
PHP_METHOD(Phalcon_Html_Helper_AbstractHelper,renderAttributes)328 PHP_METHOD(Phalcon_Html_Helper_AbstractHelper, renderAttributes) {
329
330 zend_bool _4$$3, _8$$5;
331 zend_string *_3;
332 zend_ulong _2;
333 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
334 zend_long ZEPHIR_LAST_CALL_STATUS;
335 zval *attributes_param = NULL, key, result, value, *_0, _1, _5$$4, _6$$4, _7$$4, _9$$6, _10$$6, _11$$6;
336 zval attributes;
337 zval *this_ptr = getThis();
338
339 ZVAL_UNDEF(&attributes);
340 ZVAL_UNDEF(&key);
341 ZVAL_UNDEF(&result);
342 ZVAL_UNDEF(&value);
343 ZVAL_UNDEF(&_1);
344 ZVAL_UNDEF(&_5$$4);
345 ZVAL_UNDEF(&_6$$4);
346 ZVAL_UNDEF(&_7$$4);
347 ZVAL_UNDEF(&_9$$6);
348 ZVAL_UNDEF(&_10$$6);
349 ZVAL_UNDEF(&_11$$6);
350
351 ZEPHIR_MM_GROW();
352 zephir_fetch_params(1, 1, 0, &attributes_param);
353
354 zephir_get_arrval(&attributes, attributes_param);
355
356
357 ZEPHIR_INIT_VAR(&result);
358 ZVAL_STRING(&result, "");
359 zephir_is_iterable(&attributes, 0, "phalcon/Html/Helper/AbstractHelper.zep", 163);
360 if (Z_TYPE_P(&attributes) == IS_ARRAY) {
361 ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(&attributes), _2, _3, _0)
362 {
363 ZEPHIR_INIT_NVAR(&key);
364 if (_3 != NULL) {
365 ZVAL_STR_COPY(&key, _3);
366 } else {
367 ZVAL_LONG(&key, _2);
368 }
369 ZEPHIR_INIT_NVAR(&value);
370 ZVAL_COPY(&value, _0);
371 _4$$3 = Z_TYPE_P(&key) == IS_STRING;
372 if (_4$$3) {
373 _4$$3 = Z_TYPE_P(&value) != IS_NULL;
374 }
375 if (_4$$3) {
376 zephir_read_property(&_5$$4, this_ptr, ZEND_STRL("escaper"), PH_NOISY_CC | PH_READONLY);
377 ZEPHIR_CALL_METHOD(&_6$$4, &_5$$4, "attributes", NULL, 0, &value);
378 zephir_check_call_status();
379 ZEPHIR_INIT_NVAR(&_7$$4);
380 ZEPHIR_CONCAT_VSVS(&_7$$4, &key, "=\"", &_6$$4, "\" ");
381 zephir_concat_self(&result, &_7$$4);
382 }
383 } ZEND_HASH_FOREACH_END();
384 } else {
385 ZEPHIR_CALL_METHOD(NULL, &attributes, "rewind", NULL, 0);
386 zephir_check_call_status();
387 while (1) {
388 ZEPHIR_CALL_METHOD(&_1, &attributes, "valid", NULL, 0);
389 zephir_check_call_status();
390 if (!zend_is_true(&_1)) {
391 break;
392 }
393 ZEPHIR_CALL_METHOD(&key, &attributes, "key", NULL, 0);
394 zephir_check_call_status();
395 ZEPHIR_CALL_METHOD(&value, &attributes, "current", NULL, 0);
396 zephir_check_call_status();
397 _8$$5 = Z_TYPE_P(&key) == IS_STRING;
398 if (_8$$5) {
399 _8$$5 = Z_TYPE_P(&value) != IS_NULL;
400 }
401 if (_8$$5) {
402 zephir_read_property(&_9$$6, this_ptr, ZEND_STRL("escaper"), PH_NOISY_CC | PH_READONLY);
403 ZEPHIR_CALL_METHOD(&_10$$6, &_9$$6, "attributes", NULL, 0, &value);
404 zephir_check_call_status();
405 ZEPHIR_INIT_NVAR(&_11$$6);
406 ZEPHIR_CONCAT_VSVS(&_11$$6, &key, "=\"", &_10$$6, "\" ");
407 zephir_concat_self(&result, &_11$$6);
408 }
409 ZEPHIR_CALL_METHOD(NULL, &attributes, "next", NULL, 0);
410 zephir_check_call_status();
411 }
412 }
413 ZEPHIR_INIT_NVAR(&value);
414 ZEPHIR_INIT_NVAR(&key);
415 RETURN_CCTOR(&result);
416
417 }
418
419 /**
420 * Renders an element
421 *
422 * @param string $tag
423 * @param array $attributes
424 *
425 * @return string
426 * @throws Exception
427 */
PHP_METHOD(Phalcon_Html_Helper_AbstractHelper,renderElement)428 PHP_METHOD(Phalcon_Html_Helper_AbstractHelper, renderElement) {
429
430 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
431 zend_long ZEPHIR_LAST_CALL_STATUS;
432 zval attributes;
433 zval *tag_param = NULL, *attributes_param = NULL;
434 zval tag;
435 zval *this_ptr = getThis();
436
437 ZVAL_UNDEF(&tag);
438 ZVAL_UNDEF(&attributes);
439
440 ZEPHIR_MM_GROW();
441 zephir_fetch_params(1, 1, 1, &tag_param, &attributes_param);
442
443 zephir_get_strval(&tag, tag_param);
444 if (!attributes_param) {
445 ZEPHIR_INIT_VAR(&attributes);
446 array_init(&attributes);
447 } else {
448 zephir_get_arrval(&attributes, attributes_param);
449 }
450
451
452 ZEPHIR_RETURN_CALL_METHOD(this_ptr, "rendertag", NULL, 0, &tag, &attributes);
453 zephir_check_call_status();
454 RETURN_MM();
455
456 }
457
458 /**
459 * Renders an element
460 *
461 * @param string $tag
462 * @param string $text
463 * @param array $attributes
464 * @param bool $raw
465 *
466 * @return string
467 * @throws Exception
468 */
PHP_METHOD(Phalcon_Html_Helper_AbstractHelper,renderFullElement)469 PHP_METHOD(Phalcon_Html_Helper_AbstractHelper, renderFullElement) {
470
471 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
472 zend_long ZEPHIR_LAST_CALL_STATUS;
473 zend_bool raw;
474 zval attributes;
475 zval *tag_param = NULL, *text_param = NULL, *attributes_param = NULL, *raw_param = NULL, content, _0, _1, _2, _3;
476 zval tag, text;
477 zval *this_ptr = getThis();
478
479 ZVAL_UNDEF(&tag);
480 ZVAL_UNDEF(&text);
481 ZVAL_UNDEF(&content);
482 ZVAL_UNDEF(&_0);
483 ZVAL_UNDEF(&_1);
484 ZVAL_UNDEF(&_2);
485 ZVAL_UNDEF(&_3);
486 ZVAL_UNDEF(&attributes);
487
488 ZEPHIR_MM_GROW();
489 zephir_fetch_params(1, 2, 2, &tag_param, &text_param, &attributes_param, &raw_param);
490
491 zephir_get_strval(&tag, tag_param);
492 zephir_get_strval(&text, text_param);
493 if (!attributes_param) {
494 ZEPHIR_INIT_VAR(&attributes);
495 array_init(&attributes);
496 } else {
497 zephir_get_arrval(&attributes, attributes_param);
498 }
499 if (!raw_param) {
500 raw = 0;
501 } else {
502 raw = zephir_get_boolval(raw_param);
503 }
504
505
506 if (raw) {
507 ZEPHIR_CPY_WRT(&content, &text);
508 } else {
509 zephir_read_property(&_0, this_ptr, ZEND_STRL("escaper"), PH_NOISY_CC | PH_READONLY);
510 ZEPHIR_CALL_METHOD(&content, &_0, "html", NULL, 0, &text);
511 zephir_check_call_status();
512 }
513 ZEPHIR_CALL_METHOD(&_1, this_ptr, "renderelement", NULL, 0, &tag, &attributes);
514 zephir_check_call_status();
515 if (raw) {
516 ZVAL_BOOL(&_3, 1);
517 } else {
518 ZVAL_BOOL(&_3, 0);
519 }
520 ZEPHIR_CALL_METHOD(&_2, this_ptr, "close", NULL, 0, &tag, &_3);
521 zephir_check_call_status();
522 ZEPHIR_CONCAT_VVV(return_value, &_1, &content, &_2);
523 RETURN_MM();
524
525 }
526
527 /**
528 * Renders a tag
529 *
530 * @param string $tag
531 * @param array $attributes
532 * @param string $close
533 *
534 * @return string
535 */
PHP_METHOD(Phalcon_Html_Helper_AbstractHelper,renderTag)536 PHP_METHOD(Phalcon_Html_Helper_AbstractHelper, renderTag) {
537
538 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
539 zend_long ZEPHIR_LAST_CALL_STATUS;
540 zval attributes;
541 zval *tag_param = NULL, *attributes_param = NULL, close, *close_param = NULL, attrs, escapedAttrs, _3, _4, _5, _0$$3, _1$$3, _2$$3;
542 zval tag;
543 zval *this_ptr = getThis();
544
545 ZVAL_UNDEF(&tag);
546 ZVAL_UNDEF(&close);
547 ZVAL_UNDEF(&attrs);
548 ZVAL_UNDEF(&escapedAttrs);
549 ZVAL_UNDEF(&_3);
550 ZVAL_UNDEF(&_4);
551 ZVAL_UNDEF(&_5);
552 ZVAL_UNDEF(&_0$$3);
553 ZVAL_UNDEF(&_1$$3);
554 ZVAL_UNDEF(&_2$$3);
555 ZVAL_UNDEF(&attributes);
556
557 ZEPHIR_MM_GROW();
558 zephir_fetch_params(1, 1, 2, &tag_param, &attributes_param, &close_param);
559
560 zephir_get_strval(&tag, tag_param);
561 if (!attributes_param) {
562 ZEPHIR_INIT_VAR(&attributes);
563 array_init(&attributes);
564 } else {
565 zephir_get_arrval(&attributes, attributes_param);
566 }
567 if (!close_param) {
568 ZEPHIR_INIT_VAR(&close);
569 ZVAL_STRING(&close, "");
570 } else {
571 zephir_get_strval(&close, close_param);
572 }
573
574
575 ZEPHIR_INIT_VAR(&escapedAttrs);
576 ZVAL_STRING(&escapedAttrs, "");
577 if (zephir_fast_count_int(&attributes) > 0) {
578 ZEPHIR_INIT_VAR(&_0$$3);
579 array_init(&_0$$3);
580 ZEPHIR_CALL_METHOD(&attrs, this_ptr, "orderattributes", NULL, 0, &_0$$3, &attributes);
581 zephir_check_call_status();
582 ZEPHIR_INIT_VAR(&_1$$3);
583 ZEPHIR_CALL_METHOD(&_2$$3, this_ptr, "renderattributes", NULL, 0, &attrs);
584 zephir_check_call_status();
585 zephir_fast_trim(&_1$$3, &_2$$3, NULL , ZEPHIR_TRIM_RIGHT);
586 ZEPHIR_INIT_NVAR(&escapedAttrs);
587 ZEPHIR_CONCAT_SV(&escapedAttrs, " ", &_1$$3);
588 }
589 ZEPHIR_INIT_VAR(&_3);
590 ZEPHIR_INIT_VAR(&_4);
591 zephir_fast_trim(&_4, &close, NULL , ZEPHIR_TRIM_BOTH);
592 if (ZEPHIR_IS_EMPTY(&_4)) {
593 ZEPHIR_INIT_NVAR(&_3);
594 ZVAL_STRING(&_3, "");
595 } else {
596 ZEPHIR_INIT_VAR(&_5);
597 zephir_fast_trim(&_5, &close, NULL , ZEPHIR_TRIM_BOTH);
598 ZEPHIR_INIT_NVAR(&_3);
599 ZEPHIR_CONCAT_SV(&_3, " ", &_5);
600 }
601 ZEPHIR_CPY_WRT(&close, &_3);
602 ZEPHIR_CONCAT_SVVVS(return_value, "<", &tag, &escapedAttrs, &close, ">");
603 RETURN_MM();
604
605 }
606
607 /**
608 * Produces a self close tag i.e. <img />
609 *
610 * @param string $tag
611 * @param array $attributes
612 *
613 * @return string
614 */
PHP_METHOD(Phalcon_Html_Helper_AbstractHelper,selfClose)615 PHP_METHOD(Phalcon_Html_Helper_AbstractHelper, selfClose) {
616
617 zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
618 zend_long ZEPHIR_LAST_CALL_STATUS;
619 zval attributes;
620 zval *tag_param = NULL, *attributes_param = NULL, _0;
621 zval tag;
622 zval *this_ptr = getThis();
623
624 ZVAL_UNDEF(&tag);
625 ZVAL_UNDEF(&_0);
626 ZVAL_UNDEF(&attributes);
627
628 ZEPHIR_MM_GROW();
629 zephir_fetch_params(1, 1, 1, &tag_param, &attributes_param);
630
631 zephir_get_strval(&tag, tag_param);
632 if (!attributes_param) {
633 ZEPHIR_INIT_VAR(&attributes);
634 array_init(&attributes);
635 } else {
636 zephir_get_arrval(&attributes, attributes_param);
637 }
638
639
640 ZEPHIR_INIT_VAR(&_0);
641 ZVAL_STRING(&_0, "/");
642 ZEPHIR_RETURN_CALL_METHOD(this_ptr, "rendertag", NULL, 0, &tag, &attributes, &_0);
643 zephir_check_call_status();
644 RETURN_MM();
645
646 }
647
648