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 "ext/spl/spl_iterators.h"
16 #include "kernel/object.h"
17 #include "kernel/memory.h"
18 #include "kernel/operators.h"
19 #include "kernel/exception.h"
20 #include "kernel/fcall.h"
21 #include "kernel/array.h"
22 #include "kernel/concat.h"
23 #include "kernel/string.h"
24 #include "ext/spl/spl_exceptions.h"
25 #include "kernel/iterator.h"
26 
27 
28 /**
29  * This file is part of the Phalcon Framework.
30  *
31  * (c) Phalcon Team <team@phalcon.io>
32  *
33  * For the full copyright and license information, please view the LICENSE.txt
34  * file that was distributed with this source code.
35  */
36 /**
37  * This component allows to build forms using an object-oriented interface
38  */
ZEPHIR_INIT_CLASS(Phalcon_Forms_Form)39 ZEPHIR_INIT_CLASS(Phalcon_Forms_Form) {
40 
41 	ZEPHIR_REGISTER_CLASS_EX(Phalcon\\Forms, Form, phalcon, forms_form, phalcon_di_injectable_ce, phalcon_forms_form_method_entry, 0);
42 
43 	/**
44 	 * @var Attributes | null
45 	 */
46 	zend_declare_property_null(phalcon_forms_form_ce, SL("attributes"), ZEND_ACC_PROTECTED);
47 
48 	zend_declare_property_null(phalcon_forms_form_ce, SL("data"), ZEND_ACC_PROTECTED);
49 
50 	zend_declare_property_null(phalcon_forms_form_ce, SL("elements"), ZEND_ACC_PROTECTED);
51 
52 	zend_declare_property_null(phalcon_forms_form_ce, SL("elementsIndexed"), ZEND_ACC_PROTECTED);
53 
54 	zend_declare_property_null(phalcon_forms_form_ce, SL("entity"), ZEND_ACC_PROTECTED);
55 
56 	zend_declare_property_null(phalcon_forms_form_ce, SL("messages"), ZEND_ACC_PROTECTED);
57 
58 	zend_declare_property_null(phalcon_forms_form_ce, SL("position"), ZEND_ACC_PROTECTED);
59 
60 	zend_declare_property_null(phalcon_forms_form_ce, SL("options"), ZEND_ACC_PROTECTED);
61 
62 	zend_declare_property_null(phalcon_forms_form_ce, SL("validation"), ZEND_ACC_PROTECTED);
63 
64 	phalcon_forms_form_ce->create_object = zephir_init_properties_Phalcon_Forms_Form;
65 
66 	zend_class_implements(phalcon_forms_form_ce, 1, spl_ce_Countable);
67 	zend_class_implements(phalcon_forms_form_ce, 1, zend_ce_iterator);
68 	zend_class_implements(phalcon_forms_form_ce, 1, phalcon_html_attributes_attributesinterface_ce);
69 	return SUCCESS;
70 
71 }
72 
PHP_METHOD(Phalcon_Forms_Form,setValidation)73 PHP_METHOD(Phalcon_Forms_Form, setValidation) {
74 
75 	zval *validation, validation_sub;
76 	zval *this_ptr = getThis();
77 
78 	ZVAL_UNDEF(&validation_sub);
79 
80 	zephir_fetch_params_without_memory_grow(1, 0, &validation);
81 
82 
83 
84 	zephir_update_property_zval(this_ptr, ZEND_STRL("validation"), validation);
85 	RETURN_THISW();
86 
87 }
88 
PHP_METHOD(Phalcon_Forms_Form,getValidation)89 PHP_METHOD(Phalcon_Forms_Form, getValidation) {
90 
91 	zval *this_ptr = getThis();
92 
93 
94 	RETURN_MEMBER(getThis(), "validation");
95 
96 }
97 
98 /**
99  * Phalcon\Forms\Form constructor
100  */
PHP_METHOD(Phalcon_Forms_Form,__construct)101 PHP_METHOD(Phalcon_Forms_Form, __construct) {
102 
103 	zend_bool _0;
104 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
105 	zend_long ZEPHIR_LAST_CALL_STATUS;
106 	zval userOptions;
107 	zval *entity = NULL, entity_sub, *userOptions_param = NULL, __$null, _1;
108 	zval *this_ptr = getThis();
109 
110 	ZVAL_UNDEF(&entity_sub);
111 	ZVAL_NULL(&__$null);
112 	ZVAL_UNDEF(&_1);
113 	ZVAL_UNDEF(&userOptions);
114 
115 	ZEPHIR_MM_GROW();
116 	zephir_fetch_params(1, 0, 2, &entity, &userOptions_param);
117 
118 	if (!entity) {
119 		entity = &entity_sub;
120 		entity = &__$null;
121 	}
122 	if (!userOptions_param) {
123 		ZEPHIR_INIT_VAR(&userOptions);
124 		array_init(&userOptions);
125 	} else {
126 		zephir_get_arrval(&userOptions, userOptions_param);
127 	}
128 
129 
130 	_0 = Z_TYPE_P(entity) != IS_NULL;
131 	if (_0) {
132 		_0 = Z_TYPE_P(entity) != IS_OBJECT;
133 	}
134 	if (UNEXPECTED(_0)) {
135 		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_forms_exception_ce, "The base entity is not valid", "phalcon/Forms/Form.zep", 58);
136 		return;
137 	}
138 	zephir_update_property_zval(this_ptr, ZEND_STRL("entity"), entity);
139 	zephir_update_property_zval(this_ptr, ZEND_STRL("options"), &userOptions);
140 	ZEPHIR_INIT_VAR(&_1);
141 	object_init_ex(&_1, phalcon_html_attributes_ce);
142 	ZEPHIR_CALL_METHOD(NULL, &_1, "__construct", NULL, 22);
143 	zephir_check_call_status();
144 	zephir_update_property_zval(this_ptr, ZEND_STRL("attributes"), &_1);
145 	if ((zephir_method_exists_ex(this_ptr, ZEND_STRL("initialize")) == SUCCESS)) {
146 		ZEPHIR_CALL_METHOD(NULL, this_ptr, "initialize", NULL, 0, entity, &userOptions);
147 		zephir_check_call_status();
148 	}
149 	ZEPHIR_MM_RESTORE();
150 
151 }
152 
153 /**
154  * Adds an element to the form
155  */
PHP_METHOD(Phalcon_Forms_Form,add)156 PHP_METHOD(Phalcon_Forms_Form, add) {
157 
158 	zend_string *_6$$4;
159 	zend_ulong _5$$4;
160 	zval elements;
161 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
162 	zend_long ZEPHIR_LAST_CALL_STATUS;
163 	zend_bool type, _0;
164 	zval position;
165 	zval *element, element_sub, *position_param = NULL, *type_param = NULL, name, key, value, _1, _2$$4, *_3$$4, _4$$4;
166 	zval *this_ptr = getThis();
167 
168 	ZVAL_UNDEF(&element_sub);
169 	ZVAL_UNDEF(&name);
170 	ZVAL_UNDEF(&key);
171 	ZVAL_UNDEF(&value);
172 	ZVAL_UNDEF(&_1);
173 	ZVAL_UNDEF(&_2$$4);
174 	ZVAL_UNDEF(&_4$$4);
175 	ZVAL_UNDEF(&position);
176 	ZVAL_UNDEF(&elements);
177 
178 	ZEPHIR_MM_GROW();
179 	zephir_fetch_params(1, 1, 2, &element, &position_param, &type_param);
180 
181 	if (!position_param) {
182 		ZEPHIR_INIT_VAR(&position);
183 		ZVAL_STRING(&position, "");
184 	} else {
185 		zephir_get_strval(&position, position_param);
186 	}
187 	if (!type_param) {
188 		type = 0;
189 	} else {
190 		type = zephir_get_boolval(type_param);
191 	}
192 
193 
194 	ZEPHIR_CALL_METHOD(&name, element, "getname", NULL, 0);
195 	zephir_check_call_status();
196 	ZEPHIR_CALL_METHOD(NULL, element, "setform", NULL, 0, this_ptr);
197 	zephir_check_call_status();
198 	_0 = ZEPHIR_IS_STRING(&position, "");
199 	if (!(_0)) {
200 		zephir_read_property(&_1, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
201 		_0 = ZEPHIR_IS_EMPTY(&_1);
202 	}
203 	if (_0) {
204 		zephir_update_property_array(this_ptr, SL("elements"), &name, element);
205 	} else {
206 		ZEPHIR_INIT_VAR(&elements);
207 		array_init(&elements);
208 		zephir_read_property(&_2$$4, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
209 		zephir_is_iterable(&_2$$4, 0, "phalcon/Forms/Form.zep", 133);
210 		if (Z_TYPE_P(&_2$$4) == IS_ARRAY) {
211 			ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(&_2$$4), _5$$4, _6$$4, _3$$4)
212 			{
213 				ZEPHIR_INIT_NVAR(&key);
214 				if (_6$$4 != NULL) {
215 					ZVAL_STR_COPY(&key, _6$$4);
216 				} else {
217 					ZVAL_LONG(&key, _5$$4);
218 				}
219 				ZEPHIR_INIT_NVAR(&value);
220 				ZVAL_COPY(&value, _3$$4);
221 				if (ZEPHIR_IS_EQUAL(&key, &position)) {
222 					if (type) {
223 						zephir_array_update_zval(&elements, &name, element, PH_COPY | PH_SEPARATE);
224 						zephir_array_update_zval(&elements, &key, &value, PH_COPY | PH_SEPARATE);
225 					} else {
226 						zephir_array_update_zval(&elements, &key, &value, PH_COPY | PH_SEPARATE);
227 						zephir_array_update_zval(&elements, &name, element, PH_COPY | PH_SEPARATE);
228 					}
229 				} else {
230 					zephir_array_update_zval(&elements, &key, &value, PH_COPY | PH_SEPARATE);
231 				}
232 			} ZEND_HASH_FOREACH_END();
233 		} else {
234 			ZEPHIR_CALL_METHOD(NULL, &_2$$4, "rewind", NULL, 0);
235 			zephir_check_call_status();
236 			while (1) {
237 				ZEPHIR_CALL_METHOD(&_4$$4, &_2$$4, "valid", NULL, 0);
238 				zephir_check_call_status();
239 				if (!zend_is_true(&_4$$4)) {
240 					break;
241 				}
242 				ZEPHIR_CALL_METHOD(&key, &_2$$4, "key", NULL, 0);
243 				zephir_check_call_status();
244 				ZEPHIR_CALL_METHOD(&value, &_2$$4, "current", NULL, 0);
245 				zephir_check_call_status();
246 					if (ZEPHIR_IS_EQUAL(&key, &position)) {
247 						if (type) {
248 							zephir_array_update_zval(&elements, &name, element, PH_COPY | PH_SEPARATE);
249 							zephir_array_update_zval(&elements, &key, &value, PH_COPY | PH_SEPARATE);
250 						} else {
251 							zephir_array_update_zval(&elements, &key, &value, PH_COPY | PH_SEPARATE);
252 							zephir_array_update_zval(&elements, &name, element, PH_COPY | PH_SEPARATE);
253 						}
254 					} else {
255 						zephir_array_update_zval(&elements, &key, &value, PH_COPY | PH_SEPARATE);
256 					}
257 				ZEPHIR_CALL_METHOD(NULL, &_2$$4, "next", NULL, 0);
258 				zephir_check_call_status();
259 			}
260 		}
261 		ZEPHIR_INIT_NVAR(&value);
262 		ZEPHIR_INIT_NVAR(&key);
263 		zephir_update_property_zval(this_ptr, ZEND_STRL("elements"), &elements);
264 	}
265 	RETURN_THIS();
266 
267 }
268 
269 /**
270  * Binds data to the entity
271  *
272  * @param object entity
273  * @param array whitelist
274  */
PHP_METHOD(Phalcon_Forms_Form,bind)275 PHP_METHOD(Phalcon_Forms_Form, bind) {
276 
277 	zend_bool _6$$4, _13$$11;
278 	zend_string *_4;
279 	zend_ulong _3;
280 	zval method;
281 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
282 	zephir_fcall_cache_entry *_7 = NULL;
283 	zend_long ZEPHIR_LAST_CALL_STATUS;
284 	zval *data_param = NULL, *entity, entity_sub, *whitelist = NULL, whitelist_sub, __$null, filter, key, value, element, filters, container, filteredValue, _0, *_1, _2, _5$$4, _10$$4, _11$$4, _8$$8, _9$$8, _12$$11, _16$$11, _17$$11, _14$$15, _15$$15;
285 	zval data;
286 	zval *this_ptr = getThis();
287 
288 	ZVAL_UNDEF(&data);
289 	ZVAL_UNDEF(&entity_sub);
290 	ZVAL_UNDEF(&whitelist_sub);
291 	ZVAL_NULL(&__$null);
292 	ZVAL_UNDEF(&filter);
293 	ZVAL_UNDEF(&key);
294 	ZVAL_UNDEF(&value);
295 	ZVAL_UNDEF(&element);
296 	ZVAL_UNDEF(&filters);
297 	ZVAL_UNDEF(&container);
298 	ZVAL_UNDEF(&filteredValue);
299 	ZVAL_UNDEF(&_0);
300 	ZVAL_UNDEF(&_2);
301 	ZVAL_UNDEF(&_5$$4);
302 	ZVAL_UNDEF(&_10$$4);
303 	ZVAL_UNDEF(&_11$$4);
304 	ZVAL_UNDEF(&_8$$8);
305 	ZVAL_UNDEF(&_9$$8);
306 	ZVAL_UNDEF(&_12$$11);
307 	ZVAL_UNDEF(&_16$$11);
308 	ZVAL_UNDEF(&_17$$11);
309 	ZVAL_UNDEF(&_14$$15);
310 	ZVAL_UNDEF(&_15$$15);
311 	ZVAL_UNDEF(&method);
312 
313 	ZEPHIR_MM_GROW();
314 	zephir_fetch_params(1, 2, 1, &data_param, &entity, &whitelist);
315 
316 	ZEPHIR_OBS_COPY_OR_DUP(&data, data_param);
317 	ZEPHIR_SEPARATE_PARAM(entity);
318 	if (!whitelist) {
319 		whitelist = &whitelist_sub;
320 		whitelist = &__$null;
321 	}
322 
323 
324 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
325 	if (UNEXPECTED(ZEPHIR_IS_EMPTY(&_0))) {
326 		ZEPHIR_THROW_EXCEPTION_DEBUG_STR(phalcon_forms_exception_ce, "There are no elements in the form", "phalcon/Forms/Form.zep", 151);
327 		return;
328 	}
329 	ZEPHIR_INIT_VAR(&filter);
330 	ZVAL_NULL(&filter);
331 	zephir_is_iterable(&data, 0, "phalcon/Forms/Form.zep", 206);
332 	if (Z_TYPE_P(&data) == IS_ARRAY) {
333 		ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(&data), _3, _4, _1)
334 		{
335 			ZEPHIR_INIT_NVAR(&key);
336 			if (_4 != NULL) {
337 				ZVAL_STR_COPY(&key, _4);
338 			} else {
339 				ZVAL_LONG(&key, _3);
340 			}
341 			ZEPHIR_INIT_NVAR(&value);
342 			ZVAL_COPY(&value, _1);
343 			ZEPHIR_OBS_NVAR(&element);
344 			zephir_read_property(&_5$$4, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
345 			if (!(zephir_array_isset_fetch(&element, &_5$$4, &key, 0))) {
346 				continue;
347 			}
348 			_6$$4 = Z_TYPE_P(whitelist) == IS_ARRAY;
349 			if (_6$$4) {
350 				_6$$4 = !(zephir_fast_in_array(&key, whitelist));
351 			}
352 			if (_6$$4) {
353 				continue;
354 			}
355 			ZEPHIR_CALL_METHOD(&filters, &element, "getfilters", NULL, 0);
356 			zephir_check_call_status();
357 			if (zephir_is_true(&filters)) {
358 				if (Z_TYPE_P(&filter) != IS_OBJECT) {
359 					ZEPHIR_CALL_METHOD(&container, this_ptr, "getdi", &_7, 0);
360 					zephir_check_call_status();
361 					ZEPHIR_INIT_NVAR(&_9$$8);
362 					ZVAL_STRING(&_9$$8, "filter");
363 					ZEPHIR_CALL_METHOD(&_8$$8, &container, "getshared", NULL, 0, &_9$$8);
364 					zephir_check_call_status();
365 					ZEPHIR_CPY_WRT(&filter, &_8$$8);
366 				}
367 				ZEPHIR_CALL_METHOD(&filteredValue, &filter, "sanitize", NULL, 0, &value, &filters);
368 				zephir_check_call_status();
369 			} else {
370 				ZEPHIR_CPY_WRT(&filteredValue, &value);
371 			}
372 			ZEPHIR_INIT_NVAR(&_10$$4);
373 			zephir_camelize(&_10$$4, &key, NULL  );
374 			ZEPHIR_INIT_NVAR(&_11$$4);
375 			ZEPHIR_CONCAT_SV(&_11$$4, "set", &_10$$4);
376 			zephir_get_strval(&method, &_11$$4);
377 			if ((zephir_method_exists(entity, &method)  == SUCCESS)) {
378 				ZEPHIR_CALL_METHOD_ZVAL(NULL, entity, &method, NULL, 0, &filteredValue);
379 				zephir_check_call_status();
380 				continue;
381 			}
382 			zephir_update_property_zval_zval(entity, &key, &filteredValue);
383 		} ZEND_HASH_FOREACH_END();
384 	} else {
385 		ZEPHIR_CALL_METHOD(NULL, &data, "rewind", NULL, 0);
386 		zephir_check_call_status();
387 		while (1) {
388 			ZEPHIR_CALL_METHOD(&_2, &data, "valid", NULL, 0);
389 			zephir_check_call_status();
390 			if (!zend_is_true(&_2)) {
391 				break;
392 			}
393 			ZEPHIR_CALL_METHOD(&key, &data, "key", NULL, 0);
394 			zephir_check_call_status();
395 			ZEPHIR_CALL_METHOD(&value, &data, "current", NULL, 0);
396 			zephir_check_call_status();
397 				ZEPHIR_OBS_NVAR(&element);
398 				zephir_read_property(&_12$$11, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
399 				if (!(zephir_array_isset_fetch(&element, &_12$$11, &key, 0))) {
400 					continue;
401 				}
402 				_13$$11 = Z_TYPE_P(whitelist) == IS_ARRAY;
403 				if (_13$$11) {
404 					_13$$11 = !(zephir_fast_in_array(&key, whitelist));
405 				}
406 				if (_13$$11) {
407 					continue;
408 				}
409 				ZEPHIR_CALL_METHOD(&filters, &element, "getfilters", NULL, 0);
410 				zephir_check_call_status();
411 				if (zephir_is_true(&filters)) {
412 					if (Z_TYPE_P(&filter) != IS_OBJECT) {
413 						ZEPHIR_CALL_METHOD(&container, this_ptr, "getdi", &_7, 0);
414 						zephir_check_call_status();
415 						ZEPHIR_INIT_NVAR(&_15$$15);
416 						ZVAL_STRING(&_15$$15, "filter");
417 						ZEPHIR_CALL_METHOD(&_14$$15, &container, "getshared", NULL, 0, &_15$$15);
418 						zephir_check_call_status();
419 						ZEPHIR_CPY_WRT(&filter, &_14$$15);
420 					}
421 					ZEPHIR_CALL_METHOD(&filteredValue, &filter, "sanitize", NULL, 0, &value, &filters);
422 					zephir_check_call_status();
423 				} else {
424 					ZEPHIR_CPY_WRT(&filteredValue, &value);
425 				}
426 				ZEPHIR_INIT_NVAR(&_16$$11);
427 				zephir_camelize(&_16$$11, &key, NULL  );
428 				ZEPHIR_INIT_NVAR(&_17$$11);
429 				ZEPHIR_CONCAT_SV(&_17$$11, "set", &_16$$11);
430 				zephir_get_strval(&method, &_17$$11);
431 				if ((zephir_method_exists(entity, &method)  == SUCCESS)) {
432 					ZEPHIR_CALL_METHOD_ZVAL(NULL, entity, &method, NULL, 0, &filteredValue);
433 					zephir_check_call_status();
434 					continue;
435 				}
436 				zephir_update_property_zval_zval(entity, &key, &filteredValue);
437 			ZEPHIR_CALL_METHOD(NULL, &data, "next", NULL, 0);
438 			zephir_check_call_status();
439 		}
440 	}
441 	ZEPHIR_INIT_NVAR(&value);
442 	ZEPHIR_INIT_NVAR(&key);
443 	zephir_update_property_zval(this_ptr, ZEND_STRL("data"), &data);
444 	RETURN_THIS();
445 
446 }
447 
448 /**
449  * Clears every element in the form to its default value
450  *
451  * @param array|string|null fields
452  */
PHP_METHOD(Phalcon_Forms_Form,clear)453 PHP_METHOD(Phalcon_Forms_Form, clear) {
454 
455 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
456 	zephir_fcall_cache_entry *_3 = NULL;
457 	zend_long ZEPHIR_LAST_CALL_STATUS;
458 	zval *fields = NULL, fields_sub, __$null, elements, element, data, field, _0, *_1$$3, _2$$3, _4$$4, _5$$4, _6$$5, _7$$5, _8$$7, *_9$$6, _10$$6, _11$$10, _12$$10, _13$$13, _14$$13;
459 	zval *this_ptr = getThis();
460 
461 	ZVAL_UNDEF(&fields_sub);
462 	ZVAL_NULL(&__$null);
463 	ZVAL_UNDEF(&elements);
464 	ZVAL_UNDEF(&element);
465 	ZVAL_UNDEF(&data);
466 	ZVAL_UNDEF(&field);
467 	ZVAL_UNDEF(&_0);
468 	ZVAL_UNDEF(&_2$$3);
469 	ZVAL_UNDEF(&_4$$4);
470 	ZVAL_UNDEF(&_5$$4);
471 	ZVAL_UNDEF(&_6$$5);
472 	ZVAL_UNDEF(&_7$$5);
473 	ZVAL_UNDEF(&_8$$7);
474 	ZVAL_UNDEF(&_10$$6);
475 	ZVAL_UNDEF(&_11$$10);
476 	ZVAL_UNDEF(&_12$$10);
477 	ZVAL_UNDEF(&_13$$13);
478 	ZVAL_UNDEF(&_14$$13);
479 
480 	ZEPHIR_MM_GROW();
481 	zephir_fetch_params(1, 0, 1, &fields);
482 
483 	if (!fields) {
484 		fields = &fields_sub;
485 		ZEPHIR_CPY_WRT(fields, &__$null);
486 	} else {
487 		ZEPHIR_SEPARATE_PARAM(fields);
488 	}
489 
490 
491 	zephir_read_property(&_0, this_ptr, ZEND_STRL("data"), PH_NOISY_CC | PH_READONLY);
492 	ZEPHIR_CPY_WRT(&data, &_0);
493 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
494 	ZEPHIR_CPY_WRT(&elements, &_0);
495 	if (Z_TYPE_P(fields) == IS_NULL) {
496 		ZEPHIR_INIT_NVAR(&data);
497 		array_init(&data);
498 		zephir_is_iterable(&elements, 0, "phalcon/Forms/Form.zep", 237);
499 		if (Z_TYPE_P(&elements) == IS_ARRAY) {
500 			ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&elements), _1$$3)
501 			{
502 				ZEPHIR_INIT_NVAR(&element);
503 				ZVAL_COPY(&element, _1$$3);
504 				ZEPHIR_CALL_METHOD(&_4$$4, &element, "getname", NULL, 0);
505 				zephir_check_call_status();
506 				ZEPHIR_CALL_METHOD(&_5$$4, &element, "getdefault", NULL, 0);
507 				zephir_check_call_status();
508 				ZEPHIR_CALL_CE_STATIC(NULL, phalcon_tag_ce, "setdefault", &_3, 0, &_4$$4, &_5$$4);
509 				zephir_check_call_status();
510 			} ZEND_HASH_FOREACH_END();
511 		} else {
512 			ZEPHIR_CALL_METHOD(NULL, &elements, "rewind", NULL, 0);
513 			zephir_check_call_status();
514 			while (1) {
515 				ZEPHIR_CALL_METHOD(&_2$$3, &elements, "valid", NULL, 0);
516 				zephir_check_call_status();
517 				if (!zend_is_true(&_2$$3)) {
518 					break;
519 				}
520 				ZEPHIR_CALL_METHOD(&element, &elements, "current", NULL, 0);
521 				zephir_check_call_status();
522 					ZEPHIR_CALL_METHOD(&_6$$5, &element, "getname", NULL, 0);
523 					zephir_check_call_status();
524 					ZEPHIR_CALL_METHOD(&_7$$5, &element, "getdefault", NULL, 0);
525 					zephir_check_call_status();
526 					ZEPHIR_CALL_CE_STATIC(NULL, phalcon_tag_ce, "setdefault", &_3, 0, &_6$$5, &_7$$5);
527 					zephir_check_call_status();
528 				ZEPHIR_CALL_METHOD(NULL, &elements, "next", NULL, 0);
529 				zephir_check_call_status();
530 			}
531 		}
532 		ZEPHIR_INIT_NVAR(&element);
533 	} else {
534 		if (Z_TYPE_P(fields) != IS_ARRAY) {
535 			ZEPHIR_INIT_VAR(&_8$$7);
536 			zephir_create_array(&_8$$7, 1, 0);
537 			zephir_array_fast_append(&_8$$7, fields);
538 			ZEPHIR_CPY_WRT(fields, &_8$$7);
539 		}
540 		zephir_is_iterable(fields, 0, "phalcon/Forms/Form.zep", 254);
541 		if (Z_TYPE_P(fields) == IS_ARRAY) {
542 			ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(fields), _9$$6)
543 			{
544 				ZEPHIR_INIT_NVAR(&field);
545 				ZVAL_COPY(&field, _9$$6);
546 				if (zephir_array_isset(&data, &field)) {
547 					zephir_array_unset(&data, &field, PH_SEPARATE);
548 				}
549 				ZEPHIR_OBS_NVAR(&element);
550 				if (zephir_array_isset_fetch(&element, &elements, &field, 0)) {
551 					ZEPHIR_CALL_METHOD(&_11$$10, &element, "getname", NULL, 0);
552 					zephir_check_call_status();
553 					ZEPHIR_CALL_METHOD(&_12$$10, &element, "getdefault", NULL, 0);
554 					zephir_check_call_status();
555 					ZEPHIR_CALL_CE_STATIC(NULL, phalcon_tag_ce, "setdefault", &_3, 0, &_11$$10, &_12$$10);
556 					zephir_check_call_status();
557 				}
558 			} ZEND_HASH_FOREACH_END();
559 		} else {
560 			ZEPHIR_CALL_METHOD(NULL, fields, "rewind", NULL, 0);
561 			zephir_check_call_status();
562 			while (1) {
563 				ZEPHIR_CALL_METHOD(&_10$$6, fields, "valid", NULL, 0);
564 				zephir_check_call_status();
565 				if (!zend_is_true(&_10$$6)) {
566 					break;
567 				}
568 				ZEPHIR_CALL_METHOD(&field, fields, "current", NULL, 0);
569 				zephir_check_call_status();
570 					if (zephir_array_isset(&data, &field)) {
571 						zephir_array_unset(&data, &field, PH_SEPARATE);
572 					}
573 					ZEPHIR_OBS_NVAR(&element);
574 					if (zephir_array_isset_fetch(&element, &elements, &field, 0)) {
575 						ZEPHIR_CALL_METHOD(&_13$$13, &element, "getname", NULL, 0);
576 						zephir_check_call_status();
577 						ZEPHIR_CALL_METHOD(&_14$$13, &element, "getdefault", NULL, 0);
578 						zephir_check_call_status();
579 						ZEPHIR_CALL_CE_STATIC(NULL, phalcon_tag_ce, "setdefault", &_3, 0, &_13$$13, &_14$$13);
580 						zephir_check_call_status();
581 					}
582 				ZEPHIR_CALL_METHOD(NULL, fields, "next", NULL, 0);
583 				zephir_check_call_status();
584 			}
585 		}
586 		ZEPHIR_INIT_NVAR(&field);
587 	}
588 	zephir_update_property_zval(this_ptr, ZEND_STRL("data"), &data);
589 	RETURN_THIS();
590 
591 }
592 
593 /**
594  * Returns the number of elements in the form
595  */
PHP_METHOD(Phalcon_Forms_Form,count)596 PHP_METHOD(Phalcon_Forms_Form, count) {
597 
598 	zval _0;
599 	zval *this_ptr = getThis();
600 
601 	ZVAL_UNDEF(&_0);
602 
603 
604 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
605 	RETURN_LONG(zephir_fast_count_int(&_0));
606 
607 }
608 
609 /**
610  * Returns the current element in the iterator
611  */
PHP_METHOD(Phalcon_Forms_Form,current)612 PHP_METHOD(Phalcon_Forms_Form, current) {
613 
614 	zval element, _0, _1;
615 	zval *this_ptr = getThis();
616 
617 	ZVAL_UNDEF(&element);
618 	ZVAL_UNDEF(&_0);
619 	ZVAL_UNDEF(&_1);
620 
621 
622 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elementsIndexed"), PH_NOISY_CC | PH_READONLY);
623 	zephir_read_property(&_1, this_ptr, ZEND_STRL("position"), PH_NOISY_CC | PH_READONLY);
624 	if (!(zephir_array_isset_fetch(&element, &_0, &_1, 1))) {
625 		RETURN_BOOL(0);
626 	}
627 	RETURN_CTORW(&element);
628 
629 }
630 
631 /**
632  * Returns an element added to the form by its name
633  */
PHP_METHOD(Phalcon_Forms_Form,get)634 PHP_METHOD(Phalcon_Forms_Form, get) {
635 
636 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
637 	zend_long ZEPHIR_LAST_CALL_STATUS;
638 	zval *name_param = NULL, element, _0, _1$$3;
639 	zval name, _2$$3;
640 	zval *this_ptr = getThis();
641 
642 	ZVAL_UNDEF(&name);
643 	ZVAL_UNDEF(&_2$$3);
644 	ZVAL_UNDEF(&element);
645 	ZVAL_UNDEF(&_0);
646 	ZVAL_UNDEF(&_1$$3);
647 
648 	ZEPHIR_MM_GROW();
649 	zephir_fetch_params(1, 1, 0, &name_param);
650 
651 	if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
652 		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
653 		RETURN_MM_NULL();
654 	}
655 	if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
656 		zephir_get_strval(&name, name_param);
657 	} else {
658 		ZEPHIR_INIT_VAR(&name);
659 		ZVAL_EMPTY_STRING(&name);
660 	}
661 
662 
663 	ZEPHIR_OBS_VAR(&element);
664 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
665 	if (UNEXPECTED(!(zephir_array_isset_fetch(&element, &_0, &name, 0)))) {
666 		ZEPHIR_INIT_VAR(&_1$$3);
667 		object_init_ex(&_1$$3, phalcon_forms_exception_ce);
668 		ZEPHIR_INIT_VAR(&_2$$3);
669 		ZEPHIR_CONCAT_SVS(&_2$$3, "Element with ID=", &name, " is not part of the form");
670 		ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 8, &_2$$3);
671 		zephir_check_call_status();
672 		zephir_throw_exception_debug(&_1$$3, "phalcon/Forms/Form.zep", 293);
673 		ZEPHIR_MM_RESTORE();
674 		return;
675 	}
676 	RETURN_CCTOR(&element);
677 
678 }
679 
680 /**
681  * Returns the form's action
682  */
PHP_METHOD(Phalcon_Forms_Form,getAction)683 PHP_METHOD(Phalcon_Forms_Form, getAction) {
684 
685 	zval _3;
686 	zval _0, _1, _2;
687 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
688 	zend_long ZEPHIR_LAST_CALL_STATUS;
689 	zval *this_ptr = getThis();
690 
691 	ZVAL_UNDEF(&_0);
692 	ZVAL_UNDEF(&_1);
693 	ZVAL_UNDEF(&_2);
694 	ZVAL_UNDEF(&_3);
695 
696 	ZEPHIR_MM_GROW();
697 
698 	ZEPHIR_CALL_METHOD(&_0, this_ptr, "getattributes", NULL, 0);
699 	zephir_check_call_status();
700 	ZEPHIR_INIT_VAR(&_2);
701 	ZVAL_STRING(&_2, "action");
702 	ZEPHIR_CALL_METHOD(&_1, &_0, "get", NULL, 0, &_2);
703 	zephir_check_call_status();
704 	zephir_get_strval(&_3, &_1);
705 	RETURN_CTOR(&_3);
706 
707 }
708 
709 /**
710  * Get Form attributes collection
711  */
PHP_METHOD(Phalcon_Forms_Form,getAttributes)712 PHP_METHOD(Phalcon_Forms_Form, getAttributes) {
713 
714 	zval _0, _1$$3;
715 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
716 	zend_long ZEPHIR_LAST_CALL_STATUS;
717 	zval *this_ptr = getThis();
718 
719 	ZVAL_UNDEF(&_0);
720 	ZVAL_UNDEF(&_1$$3);
721 
722 	ZEPHIR_MM_GROW();
723 
724 	zephir_read_property(&_0, this_ptr, ZEND_STRL("attributes"), PH_NOISY_CC | PH_READONLY);
725 	if (UNEXPECTED(Z_TYPE_P(&_0) == IS_NULL)) {
726 		ZEPHIR_INIT_VAR(&_1$$3);
727 		object_init_ex(&_1$$3, phalcon_html_attributes_ce);
728 		ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 22);
729 		zephir_check_call_status();
730 		zephir_update_property_zval(this_ptr, ZEND_STRL("attributes"), &_1$$3);
731 	}
732 	RETURN_MM_MEMBER(getThis(), "attributes");
733 
734 }
735 
736 /**
737  * Returns the form elements added to the form
738  */
PHP_METHOD(Phalcon_Forms_Form,getElements)739 PHP_METHOD(Phalcon_Forms_Form, getElements) {
740 
741 	zval *this_ptr = getThis();
742 
743 
744 	RETURN_MEMBER(getThis(), "elements");
745 
746 }
747 
748 /**
749  * Returns the entity related to the model
750  *
751  * @return object
752  */
PHP_METHOD(Phalcon_Forms_Form,getEntity)753 PHP_METHOD(Phalcon_Forms_Form, getEntity) {
754 
755 	zval *this_ptr = getThis();
756 
757 
758 	RETURN_MEMBER(getThis(), "entity");
759 
760 }
761 
762 /**
763  * Returns a label for an element
764  */
PHP_METHOD(Phalcon_Forms_Form,getLabel)765 PHP_METHOD(Phalcon_Forms_Form, getLabel) {
766 
767 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
768 	zend_long ZEPHIR_LAST_CALL_STATUS;
769 	zval *name_param = NULL, element, label, _0, _1$$3;
770 	zval name, _2$$3;
771 	zval *this_ptr = getThis();
772 
773 	ZVAL_UNDEF(&name);
774 	ZVAL_UNDEF(&_2$$3);
775 	ZVAL_UNDEF(&element);
776 	ZVAL_UNDEF(&label);
777 	ZVAL_UNDEF(&_0);
778 	ZVAL_UNDEF(&_1$$3);
779 
780 	ZEPHIR_MM_GROW();
781 	zephir_fetch_params(1, 1, 0, &name_param);
782 
783 	if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
784 		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
785 		RETURN_MM_NULL();
786 	}
787 	if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
788 		zephir_get_strval(&name, name_param);
789 	} else {
790 		ZEPHIR_INIT_VAR(&name);
791 		ZVAL_EMPTY_STRING(&name);
792 	}
793 
794 
795 	ZEPHIR_OBS_VAR(&element);
796 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
797 	if (UNEXPECTED(!(zephir_array_isset_fetch(&element, &_0, &name, 0)))) {
798 		ZEPHIR_INIT_VAR(&_1$$3);
799 		object_init_ex(&_1$$3, phalcon_forms_exception_ce);
800 		ZEPHIR_INIT_VAR(&_2$$3);
801 		ZEPHIR_CONCAT_SVS(&_2$$3, "Element with ID=", &name, " is not part of the form");
802 		ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 8, &_2$$3);
803 		zephir_check_call_status();
804 		zephir_throw_exception_debug(&_1$$3, "phalcon/Forms/Form.zep", 347);
805 		ZEPHIR_MM_RESTORE();
806 		return;
807 	}
808 	ZEPHIR_CALL_METHOD(&label, &element, "getlabel", NULL, 0);
809 	zephir_check_call_status();
810 	if (!(zephir_is_true(&label))) {
811 		RETURN_CTOR(&name);
812 	}
813 	RETURN_CCTOR(&label);
814 
815 }
816 
817 /**
818  * Returns the messages generated in the validation.
819  *
820  * ```php
821  * if ($form->isValid($_POST) == false) {
822  *     $messages = $form->getMessages();
823  *
824  *     foreach ($messages as $message) {
825  *         echo $message, "<br>";
826  *     }
827  * }
828  * ```
829  */
PHP_METHOD(Phalcon_Forms_Form,getMessages)830 PHP_METHOD(Phalcon_Forms_Form, getMessages) {
831 
832 	zend_bool _1;
833 	zval messages, _0;
834 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
835 	zend_long ZEPHIR_LAST_CALL_STATUS;
836 	zval *this_ptr = getThis();
837 
838 	ZVAL_UNDEF(&messages);
839 	ZVAL_UNDEF(&_0);
840 
841 	ZEPHIR_MM_GROW();
842 
843 	zephir_read_property(&_0, this_ptr, ZEND_STRL("messages"), PH_NOISY_CC | PH_READONLY);
844 	ZEPHIR_CPY_WRT(&messages, &_0);
845 	_1 = Z_TYPE_P(&messages) == IS_OBJECT;
846 	if (_1) {
847 		_1 = zephir_instance_of_ev(&messages, phalcon_messages_messages_ce);
848 	}
849 	if (!(_1)) {
850 		object_init_ex(return_value, phalcon_messages_messages_ce);
851 		ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 9);
852 		zephir_check_call_status();
853 		RETURN_MM();
854 	}
855 	RETURN_CCTOR(&messages);
856 
857 }
858 
859 /**
860  * Returns the messages generated for a specific element
861  */
PHP_METHOD(Phalcon_Forms_Form,getMessagesFor)862 PHP_METHOD(Phalcon_Forms_Form, getMessagesFor) {
863 
864 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
865 	zend_long ZEPHIR_LAST_CALL_STATUS;
866 	zval *name_param = NULL, _0, _1;
867 	zval name;
868 	zval *this_ptr = getThis();
869 
870 	ZVAL_UNDEF(&name);
871 	ZVAL_UNDEF(&_0);
872 	ZVAL_UNDEF(&_1);
873 
874 	ZEPHIR_MM_GROW();
875 	zephir_fetch_params(1, 1, 0, &name_param);
876 
877 	if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
878 		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
879 		RETURN_MM_NULL();
880 	}
881 	if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
882 		zephir_get_strval(&name, name_param);
883 	} else {
884 		ZEPHIR_INIT_VAR(&name);
885 		ZVAL_EMPTY_STRING(&name);
886 	}
887 
888 
889 	ZEPHIR_CALL_METHOD(&_0, this_ptr, "has", NULL, 0, &name);
890 	zephir_check_call_status();
891 	if (!(zephir_is_true(&_0))) {
892 		object_init_ex(return_value, phalcon_messages_messages_ce);
893 		ZEPHIR_CALL_METHOD(NULL, return_value, "__construct", NULL, 9);
894 		zephir_check_call_status();
895 		RETURN_MM();
896 	}
897 	ZEPHIR_CALL_METHOD(&_1, this_ptr, "get", NULL, 0, &name);
898 	zephir_check_call_status();
899 	ZEPHIR_RETURN_CALL_METHOD(&_1, "getmessages", NULL, 0);
900 	zephir_check_call_status();
901 	RETURN_MM();
902 
903 }
904 
905 /**
906  * Returns the value of an option if present
907  */
PHP_METHOD(Phalcon_Forms_Form,getUserOption)908 PHP_METHOD(Phalcon_Forms_Form, getUserOption) {
909 
910 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
911 	zval *option_param = NULL, *defaultValue = NULL, defaultValue_sub, __$null, value, _0;
912 	zval option;
913 	zval *this_ptr = getThis();
914 
915 	ZVAL_UNDEF(&option);
916 	ZVAL_UNDEF(&defaultValue_sub);
917 	ZVAL_NULL(&__$null);
918 	ZVAL_UNDEF(&value);
919 	ZVAL_UNDEF(&_0);
920 
921 	ZEPHIR_MM_GROW();
922 	zephir_fetch_params(1, 1, 1, &option_param, &defaultValue);
923 
924 	zephir_get_strval(&option, option_param);
925 	if (!defaultValue) {
926 		defaultValue = &defaultValue_sub;
927 		defaultValue = &__$null;
928 	}
929 
930 
931 	zephir_read_property(&_0, this_ptr, ZEND_STRL("options"), PH_NOISY_CC | PH_READONLY);
932 	if (!(zephir_array_isset_fetch(&value, &_0, &option, 1))) {
933 		RETVAL_ZVAL(defaultValue, 1, 0);
934 		RETURN_MM();
935 	}
936 	RETURN_CTOR(&value);
937 
938 }
939 
940 /**
941  * Returns the options for the element
942  */
PHP_METHOD(Phalcon_Forms_Form,getUserOptions)943 PHP_METHOD(Phalcon_Forms_Form, getUserOptions) {
944 
945 	zval *this_ptr = getThis();
946 
947 
948 	RETURN_MEMBER(getThis(), "options");
949 
950 }
951 
952 /**
953  * Gets a value from the internal related entity or from the default value
954  */
PHP_METHOD(Phalcon_Forms_Form,getValue)955 PHP_METHOD(Phalcon_Forms_Form, getValue) {
956 
957 	zval forbidden;
958 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
959 	zephir_fcall_cache_entry *_6 = NULL, *_7 = NULL;
960 	zend_long ZEPHIR_LAST_CALL_STATUS;
961 	zval *name_param = NULL, __$true, entity, value, data, internalEntity, element, _0, _3, _4, _5, _1$$4, _2$$4;
962 	zval name, method;
963 	zval *this_ptr = getThis();
964 
965 	ZVAL_UNDEF(&name);
966 	ZVAL_UNDEF(&method);
967 	ZVAL_BOOL(&__$true, 1);
968 	ZVAL_UNDEF(&entity);
969 	ZVAL_UNDEF(&value);
970 	ZVAL_UNDEF(&data);
971 	ZVAL_UNDEF(&internalEntity);
972 	ZVAL_UNDEF(&element);
973 	ZVAL_UNDEF(&_0);
974 	ZVAL_UNDEF(&_3);
975 	ZVAL_UNDEF(&_4);
976 	ZVAL_UNDEF(&_5);
977 	ZVAL_UNDEF(&_1$$4);
978 	ZVAL_UNDEF(&_2$$4);
979 	ZVAL_UNDEF(&forbidden);
980 
981 	ZEPHIR_MM_GROW();
982 	zephir_fetch_params(1, 1, 0, &name_param);
983 
984 	if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
985 		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
986 		RETURN_MM_NULL();
987 	}
988 	if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
989 		zephir_get_strval(&name, name_param);
990 	} else {
991 		ZEPHIR_INIT_VAR(&name);
992 		ZVAL_EMPTY_STRING(&name);
993 	}
994 
995 
996 	zephir_read_property(&_0, this_ptr, ZEND_STRL("entity"), PH_NOISY_CC | PH_READONLY);
997 	ZEPHIR_CPY_WRT(&entity, &_0);
998 	zephir_read_property(&_0, this_ptr, ZEND_STRL("data"), PH_NOISY_CC | PH_READONLY);
999 	ZEPHIR_CPY_WRT(&data, &_0);
1000 	if ((zephir_method_exists_ex(this_ptr, ZEND_STRL("getcustomvalue")) == SUCCESS)) {
1001 		ZEPHIR_RETURN_CALL_METHOD(this_ptr, "getcustomvalue", NULL, 0, &name, &entity, &data);
1002 		zephir_check_call_status();
1003 		RETURN_MM();
1004 	}
1005 	if (Z_TYPE_P(&entity) == IS_OBJECT) {
1006 		ZEPHIR_INIT_VAR(&_1$$4);
1007 		zephir_camelize(&_1$$4, &name, NULL  );
1008 		ZEPHIR_INIT_VAR(&_2$$4);
1009 		ZEPHIR_CONCAT_SV(&_2$$4, "get", &_1$$4);
1010 		zephir_get_strval(&method, &_2$$4);
1011 		if ((zephir_method_exists(&entity, &method)  == SUCCESS)) {
1012 			ZEPHIR_RETURN_CALL_METHOD_ZVAL(&entity, &method, NULL, 0);
1013 			zephir_check_call_status();
1014 			RETURN_MM();
1015 		}
1016 		ZEPHIR_OBS_VAR(&value);
1017 		if (zephir_fetch_property_zval(&value, &entity, &name, PH_SILENT_CC)) {
1018 			RETURN_CCTOR(&value);
1019 		}
1020 	}
1021 	if (Z_TYPE_P(&data) == IS_ARRAY) {
1022 		ZEPHIR_OBS_NVAR(&value);
1023 		if (zephir_array_isset_fetch(&value, &data, &name, 0)) {
1024 			RETURN_CCTOR(&value);
1025 		}
1026 	}
1027 	ZEPHIR_INIT_VAR(&forbidden);
1028 	zephir_create_array(&forbidden, 13, 0);
1029 	zephir_array_update_string(&forbidden, SL("attributes"), &__$true, PH_COPY | PH_SEPARATE);
1030 	zephir_array_update_string(&forbidden, SL("validation"), &__$true, PH_COPY | PH_SEPARATE);
1031 	zephir_array_update_string(&forbidden, SL("action"), &__$true, PH_COPY | PH_SEPARATE);
1032 	zephir_array_update_string(&forbidden, SL("useroption"), &__$true, PH_COPY | PH_SEPARATE);
1033 	zephir_array_update_string(&forbidden, SL("useroptions"), &__$true, PH_COPY | PH_SEPARATE);
1034 	zephir_array_update_string(&forbidden, SL("entity"), &__$true, PH_COPY | PH_SEPARATE);
1035 	zephir_array_update_string(&forbidden, SL("elements"), &__$true, PH_COPY | PH_SEPARATE);
1036 	zephir_array_update_string(&forbidden, SL("messages"), &__$true, PH_COPY | PH_SEPARATE);
1037 	zephir_array_update_string(&forbidden, SL("messagesfor"), &__$true, PH_COPY | PH_SEPARATE);
1038 	zephir_array_update_string(&forbidden, SL("label"), &__$true, PH_COPY | PH_SEPARATE);
1039 	zephir_array_update_string(&forbidden, SL("value"), &__$true, PH_COPY | PH_SEPARATE);
1040 	zephir_array_update_string(&forbidden, SL("di"), &__$true, PH_COPY | PH_SEPARATE);
1041 	zephir_array_update_string(&forbidden, SL("eventsmanager"), &__$true, PH_COPY | PH_SEPARATE);
1042 	ZEPHIR_INIT_VAR(&internalEntity);
1043 	zephir_fast_strtolower(&internalEntity, &name);
1044 	if (zephir_array_isset(&forbidden, &internalEntity)) {
1045 		RETURN_MM_NULL();
1046 	}
1047 	ZEPHIR_INIT_VAR(&_3);
1048 	zephir_camelize(&_3, &name, NULL  );
1049 	ZEPHIR_INIT_VAR(&_4);
1050 	ZEPHIR_CONCAT_SV(&_4, "get", &_3);
1051 	zephir_get_strval(&method, &_4);
1052 	if ((zephir_method_exists(this_ptr, &method)  == SUCCESS)) {
1053 		ZEPHIR_RETURN_CALL_METHOD_ZVAL(this_ptr, &method, NULL, 0);
1054 		zephir_check_call_status();
1055 		RETURN_MM();
1056 	}
1057 	ZEPHIR_CALL_CE_STATIC(&_5, phalcon_tag_ce, "hasvalue", &_6, 0, &name);
1058 	zephir_check_call_status();
1059 	if (zephir_is_true(&_5)) {
1060 		ZEPHIR_RETURN_CALL_CE_STATIC(phalcon_tag_ce, "getvalue", &_7, 0, &name);
1061 		zephir_check_call_status();
1062 		RETURN_MM();
1063 	}
1064 	ZEPHIR_OBS_VAR(&element);
1065 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
1066 	if (zephir_array_isset_fetch(&element, &_0, &name, 0)) {
1067 		ZEPHIR_RETURN_CALL_METHOD(&element, "getdefault", NULL, 0);
1068 		zephir_check_call_status();
1069 		RETURN_MM();
1070 	}
1071 	RETURN_MM_NULL();
1072 
1073 }
1074 
1075 /**
1076  * Check if the form contains an element
1077  */
PHP_METHOD(Phalcon_Forms_Form,has)1078 PHP_METHOD(Phalcon_Forms_Form, has) {
1079 
1080 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
1081 	zval *name_param = NULL, _0;
1082 	zval name;
1083 	zval *this_ptr = getThis();
1084 
1085 	ZVAL_UNDEF(&name);
1086 	ZVAL_UNDEF(&_0);
1087 
1088 	ZEPHIR_MM_GROW();
1089 	zephir_fetch_params(1, 1, 0, &name_param);
1090 
1091 	if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
1092 		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
1093 		RETURN_MM_NULL();
1094 	}
1095 	if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
1096 		zephir_get_strval(&name, name_param);
1097 	} else {
1098 		ZEPHIR_INIT_VAR(&name);
1099 		ZVAL_EMPTY_STRING(&name);
1100 	}
1101 
1102 
1103 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
1104 	RETURN_MM_BOOL(zephir_array_isset(&_0, &name));
1105 
1106 }
1107 
1108 /**
1109  * Check if messages were generated for a specific element
1110  */
PHP_METHOD(Phalcon_Forms_Form,hasMessagesFor)1111 PHP_METHOD(Phalcon_Forms_Form, hasMessagesFor) {
1112 
1113 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
1114 	zend_long ZEPHIR_LAST_CALL_STATUS;
1115 	zval *name_param = NULL, _0, _1;
1116 	zval name;
1117 	zval *this_ptr = getThis();
1118 
1119 	ZVAL_UNDEF(&name);
1120 	ZVAL_UNDEF(&_0);
1121 	ZVAL_UNDEF(&_1);
1122 
1123 	ZEPHIR_MM_GROW();
1124 	zephir_fetch_params(1, 1, 0, &name_param);
1125 
1126 	if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
1127 		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
1128 		RETURN_MM_NULL();
1129 	}
1130 	if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
1131 		zephir_get_strval(&name, name_param);
1132 	} else {
1133 		ZEPHIR_INIT_VAR(&name);
1134 		ZVAL_EMPTY_STRING(&name);
1135 	}
1136 
1137 
1138 	ZEPHIR_CALL_METHOD(&_0, this_ptr, "getmessagesfor", NULL, 0, &name);
1139 	zephir_check_call_status();
1140 	ZEPHIR_CALL_METHOD(&_1, &_0, "count", NULL, 0);
1141 	zephir_check_call_status();
1142 	RETURN_MM_BOOL(ZEPHIR_GT_LONG(&_1, 0));
1143 
1144 }
1145 
1146 /**
1147  * Validates the form
1148  *
1149  * @param array data
1150  * @param object entity
1151  */
PHP_METHOD(Phalcon_Forms_Form,isValid)1152 PHP_METHOD(Phalcon_Forms_Form, isValid) {
1153 
1154 	zend_object_iterator *_16$$21;
1155 	zend_bool validationStatus = 0, _5;
1156 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
1157 	zephir_fcall_cache_entry *_11 = NULL, *_12 = NULL, *_19 = NULL;
1158 	zend_long ZEPHIR_LAST_CALL_STATUS;
1159 	zval *data = NULL, data_sub, *entity = NULL, entity_sub, __$null, messages, element, validators, name, filters, validator, validation, elementMessage, _0, _6, *_7, _8, _15, _1$$4, _2$$6, _3$$7, _4$$8, *_9$$11, _10$$11, *_13$$16, _14$$16, _17$$22, _18$$22;
1160 	zval *this_ptr = getThis();
1161 
1162 	ZVAL_UNDEF(&data_sub);
1163 	ZVAL_UNDEF(&entity_sub);
1164 	ZVAL_NULL(&__$null);
1165 	ZVAL_UNDEF(&messages);
1166 	ZVAL_UNDEF(&element);
1167 	ZVAL_UNDEF(&validators);
1168 	ZVAL_UNDEF(&name);
1169 	ZVAL_UNDEF(&filters);
1170 	ZVAL_UNDEF(&validator);
1171 	ZVAL_UNDEF(&validation);
1172 	ZVAL_UNDEF(&elementMessage);
1173 	ZVAL_UNDEF(&_0);
1174 	ZVAL_UNDEF(&_6);
1175 	ZVAL_UNDEF(&_8);
1176 	ZVAL_UNDEF(&_15);
1177 	ZVAL_UNDEF(&_1$$4);
1178 	ZVAL_UNDEF(&_2$$6);
1179 	ZVAL_UNDEF(&_3$$7);
1180 	ZVAL_UNDEF(&_4$$8);
1181 	ZVAL_UNDEF(&_10$$11);
1182 	ZVAL_UNDEF(&_14$$16);
1183 	ZVAL_UNDEF(&_17$$22);
1184 	ZVAL_UNDEF(&_18$$22);
1185 
1186 	ZEPHIR_MM_GROW();
1187 	zephir_fetch_params(1, 0, 2, &data, &entity);
1188 
1189 	if (!data) {
1190 		data = &data_sub;
1191 		ZEPHIR_CPY_WRT(data, &__$null);
1192 	} else {
1193 		ZEPHIR_SEPARATE_PARAM(data);
1194 	}
1195 	if (!entity) {
1196 		entity = &entity_sub;
1197 		entity = &__$null;
1198 	}
1199 
1200 
1201 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
1202 	if (ZEPHIR_IS_EMPTY(&_0)) {
1203 		RETURN_MM_BOOL(1);
1204 	}
1205 	if (Z_TYPE_P(data) != IS_ARRAY) {
1206 		zephir_read_property(&_1$$4, this_ptr, ZEND_STRL("data"), PH_NOISY_CC | PH_READONLY);
1207 		ZEPHIR_CPY_WRT(data, &_1$$4);
1208 	}
1209 	if (Z_TYPE_P(entity) == IS_OBJECT) {
1210 		ZEPHIR_CALL_METHOD(NULL, this_ptr, "bind", NULL, 0, data, entity);
1211 		zephir_check_call_status();
1212 	} else {
1213 		ZEPHIR_OBS_VAR(&_2$$6);
1214 		zephir_read_property(&_2$$6, this_ptr, ZEND_STRL("entity"), PH_NOISY_CC);
1215 		if (Z_TYPE_P(&_2$$6) == IS_OBJECT) {
1216 			zephir_read_property(&_3$$7, this_ptr, ZEND_STRL("entity"), PH_NOISY_CC | PH_READONLY);
1217 			ZEPHIR_CALL_METHOD(NULL, this_ptr, "bind", NULL, 0, data, &_3$$7);
1218 			zephir_check_call_status();
1219 		}
1220 	}
1221 	if ((zephir_method_exists_ex(this_ptr, ZEND_STRL("beforevalidation")) == SUCCESS)) {
1222 		ZEPHIR_CALL_METHOD(&_4$$8, this_ptr, "beforevalidation", NULL, 0, data, entity);
1223 		zephir_check_call_status();
1224 		if (ZEPHIR_IS_FALSE_IDENTICAL(&_4$$8)) {
1225 			RETURN_MM_BOOL(0);
1226 		}
1227 	}
1228 	validationStatus = 1;
1229 	ZEPHIR_CALL_METHOD(&validation, this_ptr, "getvalidation", NULL, 0);
1230 	zephir_check_call_status();
1231 	_5 = Z_TYPE_P(&validation) != IS_OBJECT;
1232 	if (!(_5)) {
1233 		_5 = !((zephir_instance_of_ev(&validation, phalcon_validation_validationinterface_ce)));
1234 	}
1235 	if (_5) {
1236 		ZEPHIR_INIT_NVAR(&validation);
1237 		object_init_ex(&validation, phalcon_validation_ce);
1238 		ZEPHIR_CALL_METHOD(NULL, &validation, "__construct", NULL, 263);
1239 		zephir_check_call_status();
1240 	}
1241 	zephir_read_property(&_6, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
1242 	zephir_is_iterable(&_6, 0, "phalcon/Forms/Form.zep", 622);
1243 	if (Z_TYPE_P(&_6) == IS_ARRAY) {
1244 		ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&_6), _7)
1245 		{
1246 			ZEPHIR_INIT_NVAR(&element);
1247 			ZVAL_COPY(&element, _7);
1248 			ZEPHIR_CALL_METHOD(&validators, &element, "getvalidators", NULL, 0);
1249 			zephir_check_call_status();
1250 			if (zephir_fast_count_int(&validators) == 0) {
1251 				continue;
1252 			}
1253 			ZEPHIR_CALL_METHOD(&name, &element, "getname", NULL, 0);
1254 			zephir_check_call_status();
1255 			zephir_is_iterable(&validators, 0, "phalcon/Forms/Form.zep", 609);
1256 			if (Z_TYPE_P(&validators) == IS_ARRAY) {
1257 				ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&validators), _9$$11)
1258 				{
1259 					ZEPHIR_INIT_NVAR(&validator);
1260 					ZVAL_COPY(&validator, _9$$11);
1261 					ZEPHIR_CALL_METHOD(NULL, &validation, "add", &_11, 264, &name, &validator);
1262 					zephir_check_call_status();
1263 				} ZEND_HASH_FOREACH_END();
1264 			} else {
1265 				ZEPHIR_CALL_METHOD(NULL, &validators, "rewind", NULL, 0);
1266 				zephir_check_call_status();
1267 				while (1) {
1268 					ZEPHIR_CALL_METHOD(&_10$$11, &validators, "valid", NULL, 0);
1269 					zephir_check_call_status();
1270 					if (!zend_is_true(&_10$$11)) {
1271 						break;
1272 					}
1273 					ZEPHIR_CALL_METHOD(&validator, &validators, "current", NULL, 0);
1274 					zephir_check_call_status();
1275 						ZEPHIR_CALL_METHOD(NULL, &validation, "add", &_11, 264, &name, &validator);
1276 						zephir_check_call_status();
1277 					ZEPHIR_CALL_METHOD(NULL, &validators, "next", NULL, 0);
1278 					zephir_check_call_status();
1279 				}
1280 			}
1281 			ZEPHIR_INIT_NVAR(&validator);
1282 			ZEPHIR_CALL_METHOD(&filters, &element, "getfilters", NULL, 0);
1283 			zephir_check_call_status();
1284 			if (Z_TYPE_P(&filters) == IS_ARRAY) {
1285 				ZEPHIR_CALL_METHOD(NULL, &validation, "setfilters", &_12, 265, &name, &filters);
1286 				zephir_check_call_status();
1287 			}
1288 		} ZEND_HASH_FOREACH_END();
1289 	} else {
1290 		ZEPHIR_CALL_METHOD(NULL, &_6, "rewind", NULL, 0);
1291 		zephir_check_call_status();
1292 		while (1) {
1293 			ZEPHIR_CALL_METHOD(&_8, &_6, "valid", NULL, 0);
1294 			zephir_check_call_status();
1295 			if (!zend_is_true(&_8)) {
1296 				break;
1297 			}
1298 			ZEPHIR_CALL_METHOD(&element, &_6, "current", NULL, 0);
1299 			zephir_check_call_status();
1300 				ZEPHIR_CALL_METHOD(&validators, &element, "getvalidators", NULL, 0);
1301 				zephir_check_call_status();
1302 				if (zephir_fast_count_int(&validators) == 0) {
1303 					continue;
1304 				}
1305 				ZEPHIR_CALL_METHOD(&name, &element, "getname", NULL, 0);
1306 				zephir_check_call_status();
1307 				zephir_is_iterable(&validators, 0, "phalcon/Forms/Form.zep", 609);
1308 				if (Z_TYPE_P(&validators) == IS_ARRAY) {
1309 					ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(&validators), _13$$16)
1310 					{
1311 						ZEPHIR_INIT_NVAR(&validator);
1312 						ZVAL_COPY(&validator, _13$$16);
1313 						ZEPHIR_CALL_METHOD(NULL, &validation, "add", &_11, 264, &name, &validator);
1314 						zephir_check_call_status();
1315 					} ZEND_HASH_FOREACH_END();
1316 				} else {
1317 					ZEPHIR_CALL_METHOD(NULL, &validators, "rewind", NULL, 0);
1318 					zephir_check_call_status();
1319 					while (1) {
1320 						ZEPHIR_CALL_METHOD(&_14$$16, &validators, "valid", NULL, 0);
1321 						zephir_check_call_status();
1322 						if (!zend_is_true(&_14$$16)) {
1323 							break;
1324 						}
1325 						ZEPHIR_CALL_METHOD(&validator, &validators, "current", NULL, 0);
1326 						zephir_check_call_status();
1327 							ZEPHIR_CALL_METHOD(NULL, &validation, "add", &_11, 264, &name, &validator);
1328 							zephir_check_call_status();
1329 						ZEPHIR_CALL_METHOD(NULL, &validators, "next", NULL, 0);
1330 						zephir_check_call_status();
1331 					}
1332 				}
1333 				ZEPHIR_INIT_NVAR(&validator);
1334 				ZEPHIR_CALL_METHOD(&filters, &element, "getfilters", NULL, 0);
1335 				zephir_check_call_status();
1336 				if (Z_TYPE_P(&filters) == IS_ARRAY) {
1337 					ZEPHIR_CALL_METHOD(NULL, &validation, "setfilters", &_12, 265, &name, &filters);
1338 					zephir_check_call_status();
1339 				}
1340 			ZEPHIR_CALL_METHOD(NULL, &_6, "next", NULL, 0);
1341 			zephir_check_call_status();
1342 		}
1343 	}
1344 	ZEPHIR_INIT_NVAR(&element);
1345 	ZEPHIR_CALL_METHOD(&messages, &validation, "validate", NULL, 266, data, entity);
1346 	zephir_check_call_status();
1347 	ZEPHIR_CALL_METHOD(&_15, &messages, "count", NULL, 0);
1348 	zephir_check_call_status();
1349 	if (zephir_is_true(&_15)) {
1350 		_16$$21 = zephir_get_iterator(&messages);
1351 		_16$$21->funcs->rewind(_16$$21);
1352 		for (;_16$$21->funcs->valid(_16$$21) == SUCCESS && !EG(exception); _16$$21->funcs->move_forward(_16$$21)) {
1353 			{
1354 				ZEPHIR_ITERATOR_COPY(&elementMessage, _16$$21);
1355 			}
1356 			ZEPHIR_CALL_METHOD(&_18$$22, &elementMessage, "getfield", NULL, 0);
1357 			zephir_check_call_status();
1358 			ZEPHIR_CALL_METHOD(&_17$$22, this_ptr, "get", &_19, 0, &_18$$22);
1359 			zephir_check_call_status();
1360 			ZEPHIR_CALL_METHOD(NULL, &_17$$22, "appendmessage", NULL, 0, &elementMessage);
1361 			zephir_check_call_status();
1362 		}
1363 		zend_iterator_dtor(_16$$21);
1364 		ZEPHIR_CALL_METHOD(NULL, &messages, "rewind", NULL, 0);
1365 		zephir_check_call_status();
1366 		validationStatus = 0;
1367 	}
1368 	if (!(validationStatus)) {
1369 		zephir_update_property_zval(this_ptr, ZEND_STRL("messages"), &messages);
1370 	}
1371 	if ((zephir_method_exists_ex(this_ptr, ZEND_STRL("aftervalidation")) == SUCCESS)) {
1372 		ZEPHIR_CALL_METHOD(NULL, this_ptr, "aftervalidation", NULL, 0, &messages);
1373 		zephir_check_call_status();
1374 	}
1375 	RETURN_MM_BOOL(validationStatus);
1376 
1377 }
1378 
1379 /**
1380  * Returns the current position/key in the iterator
1381  */
PHP_METHOD(Phalcon_Forms_Form,key)1382 PHP_METHOD(Phalcon_Forms_Form, key) {
1383 
1384 	zval *this_ptr = getThis();
1385 
1386 
1387 	RETURN_MEMBER(getThis(), "position");
1388 
1389 }
1390 
1391 /**
1392  * Generate the label of an element added to the form including HTML
1393  */
PHP_METHOD(Phalcon_Forms_Form,label)1394 PHP_METHOD(Phalcon_Forms_Form, label) {
1395 
1396 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
1397 	zend_long ZEPHIR_LAST_CALL_STATUS;
1398 	zval attributes;
1399 	zval *name_param = NULL, *attributes_param = NULL, element, _0, _1$$3;
1400 	zval name, _2$$3;
1401 	zval *this_ptr = getThis();
1402 
1403 	ZVAL_UNDEF(&name);
1404 	ZVAL_UNDEF(&_2$$3);
1405 	ZVAL_UNDEF(&element);
1406 	ZVAL_UNDEF(&_0);
1407 	ZVAL_UNDEF(&_1$$3);
1408 	ZVAL_UNDEF(&attributes);
1409 
1410 	ZEPHIR_MM_GROW();
1411 	zephir_fetch_params(1, 1, 1, &name_param, &attributes_param);
1412 
1413 	if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
1414 		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
1415 		RETURN_MM_NULL();
1416 	}
1417 	if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
1418 		zephir_get_strval(&name, name_param);
1419 	} else {
1420 		ZEPHIR_INIT_VAR(&name);
1421 		ZVAL_EMPTY_STRING(&name);
1422 	}
1423 	if (!attributes_param) {
1424 		ZEPHIR_INIT_VAR(&attributes);
1425 		array_init(&attributes);
1426 	} else {
1427 		zephir_get_arrval(&attributes, attributes_param);
1428 	}
1429 
1430 
1431 	ZEPHIR_OBS_VAR(&element);
1432 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
1433 	if (UNEXPECTED(!(zephir_array_isset_fetch(&element, &_0, &name, 0)))) {
1434 		ZEPHIR_INIT_VAR(&_1$$3);
1435 		object_init_ex(&_1$$3, phalcon_forms_exception_ce);
1436 		ZEPHIR_INIT_VAR(&_2$$3);
1437 		ZEPHIR_CONCAT_SVS(&_2$$3, "Element with ID=", &name, " is not part of the form");
1438 		ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 8, &_2$$3);
1439 		zephir_check_call_status();
1440 		zephir_throw_exception_debug(&_1$$3, "phalcon/Forms/Form.zep", 672);
1441 		ZEPHIR_MM_RESTORE();
1442 		return;
1443 	}
1444 	ZEPHIR_RETURN_CALL_METHOD(&element, "label", NULL, 0, &attributes);
1445 	zephir_check_call_status();
1446 	RETURN_MM();
1447 
1448 }
1449 
1450 /**
1451  * Moves the internal iteration pointer to the next position
1452  */
PHP_METHOD(Phalcon_Forms_Form,next)1453 PHP_METHOD(Phalcon_Forms_Form, next) {
1454 
1455 	zval *this_ptr = getThis();
1456 
1457 
1458 	RETURN_ON_FAILURE(zephir_property_incr(this_ptr, SL("position")));
1459 
1460 }
1461 
1462 /**
1463  * Renders a specific item in the form
1464  */
PHP_METHOD(Phalcon_Forms_Form,render)1465 PHP_METHOD(Phalcon_Forms_Form, render) {
1466 
1467 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
1468 	zend_long ZEPHIR_LAST_CALL_STATUS;
1469 	zval attributes;
1470 	zval *name_param = NULL, *attributes_param = NULL, element, _0, _1$$3;
1471 	zval name, _2$$3;
1472 	zval *this_ptr = getThis();
1473 
1474 	ZVAL_UNDEF(&name);
1475 	ZVAL_UNDEF(&_2$$3);
1476 	ZVAL_UNDEF(&element);
1477 	ZVAL_UNDEF(&_0);
1478 	ZVAL_UNDEF(&_1$$3);
1479 	ZVAL_UNDEF(&attributes);
1480 
1481 	ZEPHIR_MM_GROW();
1482 	zephir_fetch_params(1, 1, 1, &name_param, &attributes_param);
1483 
1484 	if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
1485 		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
1486 		RETURN_MM_NULL();
1487 	}
1488 	if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
1489 		zephir_get_strval(&name, name_param);
1490 	} else {
1491 		ZEPHIR_INIT_VAR(&name);
1492 		ZVAL_EMPTY_STRING(&name);
1493 	}
1494 	if (!attributes_param) {
1495 		ZEPHIR_INIT_VAR(&attributes);
1496 		array_init(&attributes);
1497 	} else {
1498 		zephir_get_arrval(&attributes, attributes_param);
1499 	}
1500 
1501 
1502 	ZEPHIR_OBS_VAR(&element);
1503 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
1504 	if (UNEXPECTED(!(zephir_array_isset_fetch(&element, &_0, &name, 0)))) {
1505 		ZEPHIR_INIT_VAR(&_1$$3);
1506 		object_init_ex(&_1$$3, phalcon_forms_exception_ce);
1507 		ZEPHIR_INIT_VAR(&_2$$3);
1508 		ZEPHIR_CONCAT_SVS(&_2$$3, "Element with ID=", &name, " is not part of the form");
1509 		ZEPHIR_CALL_METHOD(NULL, &_1$$3, "__construct", NULL, 8, &_2$$3);
1510 		zephir_check_call_status();
1511 		zephir_throw_exception_debug(&_1$$3, "phalcon/Forms/Form.zep", 696);
1512 		ZEPHIR_MM_RESTORE();
1513 		return;
1514 	}
1515 	ZEPHIR_RETURN_CALL_METHOD(&element, "render", NULL, 0, &attributes);
1516 	zephir_check_call_status();
1517 	RETURN_MM();
1518 
1519 }
1520 
1521 /**
1522  * Removes an element from the form
1523  */
PHP_METHOD(Phalcon_Forms_Form,remove)1524 PHP_METHOD(Phalcon_Forms_Form, remove) {
1525 
1526 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
1527 	zval *name_param = NULL, __$null, _0, _1$$3;
1528 	zval name;
1529 	zval *this_ptr = getThis();
1530 
1531 	ZVAL_UNDEF(&name);
1532 	ZVAL_NULL(&__$null);
1533 	ZVAL_UNDEF(&_0);
1534 	ZVAL_UNDEF(&_1$$3);
1535 
1536 	ZEPHIR_MM_GROW();
1537 	zephir_fetch_params(1, 1, 0, &name_param);
1538 
1539 	if (UNEXPECTED(Z_TYPE_P(name_param) != IS_STRING && Z_TYPE_P(name_param) != IS_NULL)) {
1540 		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'name' must be of the type string"));
1541 		RETURN_MM_NULL();
1542 	}
1543 	if (EXPECTED(Z_TYPE_P(name_param) == IS_STRING)) {
1544 		zephir_get_strval(&name, name_param);
1545 	} else {
1546 		ZEPHIR_INIT_VAR(&name);
1547 		ZVAL_EMPTY_STRING(&name);
1548 	}
1549 
1550 
1551 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
1552 	if (zephir_array_isset(&_0, &name)) {
1553 		zephir_read_property(&_1$$3, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
1554 		zephir_array_unset(&_1$$3, &name, PH_SEPARATE);
1555 		RETURN_MM_BOOL(1);
1556 	}
1557 	zephir_update_property_zval(this_ptr, ZEND_STRL("elementsIndexed"), &__$null);
1558 	RETURN_MM_BOOL(0);
1559 
1560 }
1561 
1562 /**
1563  * Rewinds the internal iterator
1564  */
PHP_METHOD(Phalcon_Forms_Form,rewind)1565 PHP_METHOD(Phalcon_Forms_Form, rewind) {
1566 
1567 	zval _0, _1;
1568 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
1569 	zend_long ZEPHIR_LAST_CALL_STATUS;
1570 	zval *this_ptr = getThis();
1571 
1572 	ZVAL_UNDEF(&_0);
1573 	ZVAL_UNDEF(&_1);
1574 
1575 	ZEPHIR_MM_GROW();
1576 
1577 	ZEPHIR_INIT_ZVAL_NREF(_0);
1578 	ZVAL_LONG(&_0, 0);
1579 	zephir_update_property_zval(this_ptr, ZEND_STRL("position"), &_0);
1580 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
1581 	ZEPHIR_CALL_FUNCTION(&_1, "array_values", NULL, 12, &_0);
1582 	zephir_check_call_status();
1583 	zephir_update_property_zval(this_ptr, ZEND_STRL("elementsIndexed"), &_1);
1584 	ZEPHIR_MM_RESTORE();
1585 
1586 }
1587 
1588 /**
1589  * Sets the form's action
1590  *
1591  * @return Form
1592  */
PHP_METHOD(Phalcon_Forms_Form,setAction)1593 PHP_METHOD(Phalcon_Forms_Form, setAction) {
1594 
1595 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
1596 	zend_long ZEPHIR_LAST_CALL_STATUS;
1597 	zval *action_param = NULL, _0, _1;
1598 	zval action;
1599 	zval *this_ptr = getThis();
1600 
1601 	ZVAL_UNDEF(&action);
1602 	ZVAL_UNDEF(&_0);
1603 	ZVAL_UNDEF(&_1);
1604 
1605 	ZEPHIR_MM_GROW();
1606 	zephir_fetch_params(1, 1, 0, &action_param);
1607 
1608 	if (UNEXPECTED(Z_TYPE_P(action_param) != IS_STRING && Z_TYPE_P(action_param) != IS_NULL)) {
1609 		zephir_throw_exception_string(spl_ce_InvalidArgumentException, SL("Parameter 'action' must be of the type string"));
1610 		RETURN_MM_NULL();
1611 	}
1612 	if (EXPECTED(Z_TYPE_P(action_param) == IS_STRING)) {
1613 		zephir_get_strval(&action, action_param);
1614 	} else {
1615 		ZEPHIR_INIT_VAR(&action);
1616 		ZVAL_EMPTY_STRING(&action);
1617 	}
1618 
1619 
1620 	ZEPHIR_CALL_METHOD(&_0, this_ptr, "getattributes", NULL, 0);
1621 	zephir_check_call_status();
1622 	ZEPHIR_INIT_VAR(&_1);
1623 	ZVAL_STRING(&_1, "action");
1624 	ZEPHIR_CALL_METHOD(NULL, &_0, "set", NULL, 0, &_1, &action);
1625 	zephir_check_call_status();
1626 	RETURN_THIS();
1627 
1628 }
1629 
1630 /**
1631  * Sets the entity related to the model
1632  *
1633  * @param object entity
1634  */
PHP_METHOD(Phalcon_Forms_Form,setEntity)1635 PHP_METHOD(Phalcon_Forms_Form, setEntity) {
1636 
1637 	zval *entity, entity_sub;
1638 	zval *this_ptr = getThis();
1639 
1640 	ZVAL_UNDEF(&entity_sub);
1641 
1642 	zephir_fetch_params_without_memory_grow(1, 0, &entity);
1643 
1644 
1645 
1646 	zephir_update_property_zval(this_ptr, ZEND_STRL("entity"), entity);
1647 	RETURN_THISW();
1648 
1649 }
1650 
1651 /**
1652  * Set form attributes collection
1653  */
PHP_METHOD(Phalcon_Forms_Form,setAttributes)1654 PHP_METHOD(Phalcon_Forms_Form, setAttributes) {
1655 
1656 	zval *attributes, attributes_sub;
1657 	zval *this_ptr = getThis();
1658 
1659 	ZVAL_UNDEF(&attributes_sub);
1660 
1661 	zephir_fetch_params_without_memory_grow(1, 0, &attributes);
1662 
1663 
1664 
1665 	zephir_update_property_zval(this_ptr, ZEND_STRL("attributes"), attributes);
1666 	RETURN_THISW();
1667 
1668 }
1669 
1670 /**
1671  * Sets an option for the form
1672  */
PHP_METHOD(Phalcon_Forms_Form,setUserOption)1673 PHP_METHOD(Phalcon_Forms_Form, setUserOption) {
1674 
1675 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
1676 	zval *option_param = NULL, *value, value_sub;
1677 	zval option;
1678 	zval *this_ptr = getThis();
1679 
1680 	ZVAL_UNDEF(&option);
1681 	ZVAL_UNDEF(&value_sub);
1682 
1683 	ZEPHIR_MM_GROW();
1684 	zephir_fetch_params(1, 2, 0, &option_param, &value);
1685 
1686 	zephir_get_strval(&option, option_param);
1687 
1688 
1689 	zephir_update_property_array(this_ptr, SL("options"), &option, value);
1690 	RETURN_THIS();
1691 
1692 }
1693 
1694 /**
1695  * Sets options for the element
1696  */
PHP_METHOD(Phalcon_Forms_Form,setUserOptions)1697 PHP_METHOD(Phalcon_Forms_Form, setUserOptions) {
1698 
1699 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
1700 	zval *options_param = NULL;
1701 	zval options;
1702 	zval *this_ptr = getThis();
1703 
1704 	ZVAL_UNDEF(&options);
1705 
1706 	ZEPHIR_MM_GROW();
1707 	zephir_fetch_params(1, 1, 0, &options_param);
1708 
1709 	ZEPHIR_OBS_COPY_OR_DUP(&options, options_param);
1710 
1711 
1712 	zephir_update_property_zval(this_ptr, ZEND_STRL("options"), &options);
1713 	RETURN_THIS();
1714 
1715 }
1716 
1717 /**
1718  * Check if the current element in the iterator is valid
1719  */
PHP_METHOD(Phalcon_Forms_Form,valid)1720 PHP_METHOD(Phalcon_Forms_Form, valid) {
1721 
1722 	zval _0, _1;
1723 	zval *this_ptr = getThis();
1724 
1725 	ZVAL_UNDEF(&_0);
1726 	ZVAL_UNDEF(&_1);
1727 
1728 
1729 	zephir_read_property(&_0, this_ptr, ZEND_STRL("elementsIndexed"), PH_NOISY_CC | PH_READONLY);
1730 	zephir_read_property(&_1, this_ptr, ZEND_STRL("position"), PH_NOISY_CC | PH_READONLY);
1731 	RETURN_BOOL(zephir_array_isset(&_0, &_1));
1732 
1733 }
1734 
zephir_init_properties_Phalcon_Forms_Form(zend_class_entry * class_type TSRMLS_DC)1735 zend_object *zephir_init_properties_Phalcon_Forms_Form(zend_class_entry *class_type TSRMLS_DC) {
1736 
1737 		zval _0, _1$$3;
1738 	zephir_method_globals *ZEPHIR_METHOD_GLOBALS_PTR = NULL;
1739 		ZVAL_UNDEF(&_0);
1740 	ZVAL_UNDEF(&_1$$3);
1741 
1742 		ZEPHIR_MM_GROW();
1743 
1744 	{
1745 		zval local_this_ptr, *this_ptr = &local_this_ptr;
1746 		ZEPHIR_CREATE_OBJECT(this_ptr, class_type);
1747 		zephir_read_property_ex(&_0, this_ptr, ZEND_STRL("elements"), PH_NOISY_CC | PH_READONLY);
1748 		if (Z_TYPE_P(&_0) == IS_NULL) {
1749 			ZEPHIR_INIT_VAR(&_1$$3);
1750 			array_init(&_1$$3);
1751 			zephir_update_property_zval_ex(this_ptr, ZEND_STRL("elements"), &_1$$3);
1752 		}
1753 		ZEPHIR_MM_RESTORE();
1754 		return Z_OBJ_P(this_ptr);
1755 	}
1756 
1757 }
1758 
1759