diff --git a/CHANGELOG b/CHANGELOG index d6e1b9d2d8a..c965f47d5d7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +1.3.4 + - Fix improper access to \Phalcon\Debug::$_charset (#2840) + - Fix segfault in Phalcon\Mvc\Collection when an invalid parameter is passed as conditions + - Fix segfault when MongoClient does not return a valid collection in Phalcon\Mvc\Collection + - Fix possible memory corruption when phalcon_concat_self does not properly separate values + 1.3.3 - Fix segmentation fault in zim_Phalcon_Http_Request_getBasicAuth (#2819) - Fix memory corruption on unclean shutdown (#2829) @@ -70,7 +76,6 @@ - #2018 add method \Phalcon\Db\Result\Pdo::nextRowset - Use phalcon_camelize for namesapce - #1932 Phalcon\Http\Request\File extend SplFileInfo ->>>>>>> master 1.3.1 - Fixed segfault in Phalcon\Di\Service::resolve when string class does not exist (#2205) diff --git a/build/32bits/phalcon.c b/build/32bits/phalcon.c index 71523cbeb19..e78477fe4a4 100644 --- a/build/32bits/phalcon.c +++ b/build/32bits/phalcon.c @@ -1210,17 +1210,25 @@ static int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt } #define PHALCON_VERIFY_INTERFACE_EX(instance, interface_ce, exception_ce, restore_stack) \ - if (Z_TYPE_P(instance) != IS_OBJECT || !instanceof_function_ex(Z_OBJCE_P(instance), interface_ce, 1 TSRMLS_CC)) { \ - if (Z_TYPE_P(instance) != IS_OBJECT) { \ - zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ - } \ - else { \ - zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, object of type %s given", interface_ce->name, Z_OBJCE_P(instance)->name); \ - } \ + if (Z_TYPE_P(instance) != IS_OBJECT) { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ if (restore_stack) { \ PHALCON_MM_RESTORE(); \ } \ return; \ + } else { \ + if (!instanceof_function_ex(Z_OBJCE_P(instance), interface_ce, 1 TSRMLS_CC)) { \ + if (Z_TYPE_P(instance) != IS_OBJECT) { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ + } \ + else { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, object of type %s given", interface_ce->name, Z_OBJCE_P(instance)->name); \ + } \ + if (restore_stack) { \ + PHALCON_MM_RESTORE(); \ + } \ + return; \ + } \ } #define PHALCON_VERIFY_INTERFACE_OR_NULL_EX(pzv, interface_ce, exception_ce, restore_stack) \ @@ -9736,6 +9744,8 @@ static void phalcon_concat_self(zval **left, zval *right TSRMLS_DC){ } } + SEPARATE_ZVAL_IF_NOT_REF(left); + length = Z_STRLEN_PP(left) + Z_STRLEN_P(right); Z_STRVAL_PP(left) = str_erealloc(Z_STRVAL_PP(left), length + 1); @@ -9777,6 +9787,8 @@ static void phalcon_concat_self_str(zval **left, const char *right, int right_le } } + SEPARATE_ZVAL_IF_NOT_REF(left); + length = Z_STRLEN_PP(left) + right_length; Z_STRVAL_PP(left) = str_erealloc(Z_STRVAL_PP(left), length + 1); @@ -15230,7 +15242,7 @@ static const zend_function_entry phalcon_debug_method_entry[] = { PHP_ME(Phalcon_Debug, getJsSources, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, showTraceItem, NULL, ZEND_ACC_PROTECTED) PHP_ME(Phalcon_Debug, onUncaughtException, arginfo_phalcon_debug_onuncaughtexception, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Debug, getCharset, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Debug, getCharset, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_ME(Phalcon_Debug, setCharset, arginfo_phalcon_debug_setcharset, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, getLinesBeforeContext, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, setLinesBeforeContext, arginfo_phalcon_debug_setlines, ZEND_ACC_PUBLIC) @@ -15388,7 +15400,7 @@ static PHP_METHOD(Phalcon_Debug, _escapeString){ zval line_break; zval escaped_line_break; - charset = phalcon_fetch_nproperty_this(getThis(), SL("_charset"), PH_NOISY TSRMLS_CC); + charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); INIT_ZVAL(line_break); ZVAL_STRING(&line_break, "\n", 0); @@ -15847,7 +15859,7 @@ static PHP_METHOD(Phalcon_Debug, showTraceItem){ PHALCON_INIT_VAR(comment_pattern); ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1); - charset = phalcon_fetch_nproperty_this(getThis(), SL("_charset"), PH_NOISY TSRMLS_CC); + charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); PHALCON_INIT_VAR(tab); ZVAL_STRING(tab, "\t", 1); @@ -16120,7 +16132,8 @@ static PHP_METHOD(Phalcon_Debug, onUncaughtException){ } static PHP_METHOD(Phalcon_Debug, getCharset) { - RETURN_MEMBER(getThis(), "_charset"); + zval *charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); + RETURN_ZVAL(charset, 1, 0); } static PHP_METHOD(Phalcon_Debug, setCharset) { @@ -16130,7 +16143,7 @@ static PHP_METHOD(Phalcon_Debug, setCharset) { phalcon_fetch_params_ex(1, 0, &charset); PHALCON_ENSURE_IS_STRING(charset); - phalcon_update_property_this(getThis(), SL("_charset"), *charset TSRMLS_CC); + phalcon_update_static_property_ce(phalcon_debug_ce, SL("_charset"), *charset TSRMLS_CC); RETURN_THISW(); } @@ -21755,15 +21768,36 @@ static PHP_METHOD(Phalcon_Tag, setDefault){ static PHP_METHOD(Phalcon_Tag, setDefaults){ - zval *values; + zval *values, *merge = NULL, *display_values, *merged_values = NULL;; + + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &values); + phalcon_fetch_params(1, 1, 1, &values, &merge); + + if (!merge) { + merge = PHALCON_GLOBAL(z_false); + } if (Z_TYPE_P(values) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_tag_exception_ce, "An array is required as default values"); return; } - phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + + if (zend_is_true(merge)) { + + display_values = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_displayValues") TSRMLS_CC); + if (Z_TYPE_P(display_values) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_values); + phalcon_fast_array_merge(merged_values, &display_values, &values TSRMLS_CC); + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), merged_values TSRMLS_CC); + } else { + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + } + } else { + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); } @@ -23637,7 +23671,7 @@ static PHP_METHOD(Phalcon_Version, _getVersion){ array_init_size(return_value, 5); add_next_index_long(return_value, 1); add_next_index_long(return_value, 3); - add_next_index_long(return_value, 3); + add_next_index_long(return_value, 4); add_next_index_long(return_value, PHALCON_VERSION_STABLE); add_next_index_long(return_value, 1); } @@ -29407,52 +29441,50 @@ static PHP_METHOD(Phalcon_Assets_Manager, output){ PHALCON_CALL_METHOD(&local, resource, "getlocal"); if (Z_TYPE_P(filters) == IS_ARRAY) { - if (zend_is_true(join)) { - if (zend_is_true(local)) { - - PHALCON_CALL_METHOD(&source_path, resource, "getrealsourcepath", complete_source_path); - - if (!zend_is_true(source_path)) { - PHALCON_CALL_METHOD(&source_path, resource, "getpath"); - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid source path"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } - } else { + if (zend_is_true(local)) { + + PHALCON_CALL_METHOD(&source_path, resource, "getrealsourcepath", complete_source_path); + + if (!zend_is_true(source_path)) { PHALCON_CALL_METHOD(&source_path, resource, "getpath"); - - PHALCON_INIT_NVAR(filter_needed); - ZVAL_TRUE(filter_needed); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid source path"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; } - - PHALCON_CALL_METHOD(&target_path, resource, "getrealtargetpath", complete_target_path); - - if (PHALCON_IS_EMPTY(target_path)) { + } else { + PHALCON_CALL_METHOD(&source_path, resource, "getpath"); + + PHALCON_INIT_NVAR(filter_needed); + ZVAL_TRUE(filter_needed); + } + + PHALCON_CALL_METHOD(&target_path, resource, "getrealtargetpath", complete_target_path); + + if (PHALCON_IS_EMPTY(target_path)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; + } + + if (zend_is_true(local)) { + + if (PHALCON_IS_EQUAL(target_path, source_path)) { PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path"); + PHALCON_CONCAT_SVS(exception_message, "Resource '", target_path, "' have the same source and target paths"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); return; } - - if (zend_is_true(local)) { - - if (PHALCON_IS_EQUAL(target_path, source_path)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", target_path, "' have the same source and target paths"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } - if (phalcon_file_exists(target_path TSRMLS_CC) == SUCCESS) { - if (phalcon_compare_mtime(target_path, source_path TSRMLS_CC)) { - PHALCON_INIT_NVAR(filter_needed); - ZVAL_TRUE(filter_needed); - } - } else { + if (phalcon_file_exists(target_path TSRMLS_CC) == SUCCESS) { + if (phalcon_compare_mtime(target_path, source_path TSRMLS_CC)) { PHALCON_INIT_NVAR(filter_needed); ZVAL_TRUE(filter_needed); } + } else { + PHALCON_INIT_NVAR(filter_needed); + ZVAL_TRUE(filter_needed); } } } @@ -48808,15 +48840,15 @@ static PHP_METHOD(Phalcon_Forms_Form, __construct){ Z_OBJ_HT_P(getThis()) = &phalcon_forms_form_object_handlers; phalcon_fetch_params(0, 0, 2, &entity, &user_options); - + if (!entity) { entity = PHALCON_GLOBAL(z_null); } - + if (!user_options) { user_options = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(entity) != IS_NULL) { if (Z_TYPE_P(entity) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The base entity is not valid"); @@ -48825,11 +48857,11 @@ static PHP_METHOD(Phalcon_Forms_Form, __construct){ phalcon_update_property_this_quick(this_ptr, SL("_entity"), entity, 2413912609UL TSRMLS_CC); } - - if (Z_TYPE_P(user_options) == IS_ARRAY) { + + if (Z_TYPE_P(user_options) == IS_ARRAY) { phalcon_update_property_this_quick(this_ptr, SL("_options"), user_options, 1620153008UL TSRMLS_CC); } - + if (phalcon_method_quick_exists_ex(this_ptr, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { PHALCON_MM_GROW(); PHALCON_CALL_METHOD(NULL, this_ptr, "initialize", entity, user_options); @@ -48842,7 +48874,7 @@ static PHP_METHOD(Phalcon_Forms_Form, setAction){ zval *action; phalcon_fetch_params(0, 1, 0, &action); - + phalcon_update_property_this_quick(this_ptr, SL("_action"), action, 1112512898UL TSRMLS_CC); RETURN_THISW(); } @@ -48858,7 +48890,7 @@ static PHP_METHOD(Phalcon_Forms_Form, setUserOption){ zval *option, *value; phalcon_fetch_params(0, 2, 0, &option, &value); - + phalcon_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC); RETURN_THISW(); } @@ -48868,16 +48900,16 @@ static PHP_METHOD(Phalcon_Forms_Form, getUserOption){ zval *option, *default_value = NULL, *options, *value; phalcon_fetch_params(0, 1, 1, &option, &default_value); - + if (!default_value) { default_value = PHALCON_GLOBAL(z_null); } - + options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_fetch(&value, options, option)) { RETURN_ZVAL(value, 1, 0); } - + RETURN_ZVAL(default_value, 1, 0); } @@ -48886,13 +48918,13 @@ static PHP_METHOD(Phalcon_Forms_Form, setUserOptions){ zval *options; phalcon_fetch_params(0, 1, 0, &options); - - if (Z_TYPE_P(options) != IS_ARRAY) { + + if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "Parameter 'options' must be an array"); return; } phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - + RETURN_THISW(); } @@ -48907,7 +48939,7 @@ static PHP_METHOD(Phalcon_Forms_Form, setEntity){ zval *entity; phalcon_fetch_params(0, 1, 0, &entity); - + if (Z_TYPE_P(entity) != IS_NULL && Z_TYPE_P(entity) != IS_OBJECT) { zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "'%s' must be an object or NULL", "entity"); return; @@ -48942,80 +48974,84 @@ static PHP_METHOD(Phalcon_Forms_Form, bind){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &data, &entity, &whitelist); - + if (!whitelist) { whitelist = PHALCON_GLOBAL(z_null); } - - if (Z_TYPE_P(data) != IS_ARRAY) { + + if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The data must be an array"); return; } - + PHALCON_OBS_VAR(elements); phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) != IS_ARRAY) { + if (Z_TYPE_P(elements) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "There are no elements in the form"); return; } - + PHALCON_INIT_VAR(filter); - + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + if (!phalcon_array_isset(elements, key)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } - - if (Z_TYPE_P(whitelist) == IS_ARRAY) { + + if (Z_TYPE_P(whitelist) == IS_ARRAY) { if (!phalcon_fast_in_array(key, whitelist TSRMLS_CC)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } } - + PHALCON_OBS_NVAR(element); phalcon_array_fetch(&element, elements, key, PH_NOISY); - + PHALCON_CALL_METHOD(&filters, element, "getfilters"); if (zend_is_true(filters)) { + if (Z_TYPE_P(filter) != IS_OBJECT) { + PHALCON_INIT_NVAR(service_name); PHALCON_ZVAL_MAYBE_INTERNED_STRING(service_name, phalcon_interned_filter); - + PHALCON_CALL_METHOD(&dependency_injector, this_ptr, "getdi"); + PHALCON_VERIFY_INTERFACE(dependency_injector, phalcon_diinterface_ce); + PHALCON_CALL_METHOD(&filter, dependency_injector, "getshared", service_name); PHALCON_VERIFY_INTERFACE(filter, phalcon_filterinterface_ce); } - + PHALCON_CALL_METHOD(&filtered_value, filter, "sanitize", value, filters); } else { PHALCON_CPY_WRT(filtered_value, value); } - + PHALCON_INIT_NVAR(method); PHALCON_CONCAT_SV(method, "set", key); zend_str_tolower(Z_STRVAL_P(method), Z_STRLEN_P(method)); - + if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, entity, Z_STRVAL_P(method), filtered_value); zend_hash_move_forward_ex(ah0, &hp0); continue; } - + phalcon_update_property_zval_zval(entity, key, filtered_value TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC); - + PHALCON_MM_RESTORE(); } @@ -49032,103 +49068,103 @@ static PHP_METHOD(Phalcon_Forms_Form, isValid){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &data, &entity); - + if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!entity) { entity = PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) != IS_ARRAY) { + if (Z_TYPE_P(elements) != IS_ARRAY) { RETURN_MM_TRUE; } - + if (Z_TYPE_P(entity) == IS_OBJECT) { PHALCON_CALL_METHOD(NULL, this_ptr, "bind", data, entity); } - - if (Z_TYPE_P(data) != IS_ARRAY) { + + if (Z_TYPE_P(data) != IS_ARRAY) { data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY TSRMLS_CC); } - + if (phalcon_method_quick_exists_ex(this_ptr, SS("beforevalidation"), 4025473891UL TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(&status, this_ptr, "beforevalidation", data, entity); if (PHALCON_IS_FALSE(status)) { RETURN_CTOR(status); } } - + not_failed = PHALCON_GLOBAL(z_true); - + PHALCON_INIT_VAR(messages); array_init(messages); - + phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(element); - + PHALCON_CALL_METHOD(&validators, element, "getvalidators"); - if (Z_TYPE_P(validators) == IS_ARRAY) { + if (Z_TYPE_P(validators) == IS_ARRAY) { if (phalcon_fast_count_ev(validators TSRMLS_CC)) { - + PHALCON_CALL_METHOD(&name, element, "getname"); - + PHALCON_INIT_NVAR(prepared_validators); array_init(prepared_validators); - + phalcon_is_iterable(validators, &ah1, &hp1, 0, 0); - + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - + PHALCON_GET_HVALUE(validator); - + PHALCON_INIT_NVAR(scope); array_init_size(scope, 2); phalcon_array_append(&scope, name, 0); phalcon_array_append(&scope, validator, 0); phalcon_array_append(&prepared_validators, scope, PH_SEPARATE); - + zend_hash_move_forward_ex(ah1, &hp1); } - + PHALCON_INIT_NVAR(validation); object_init_ex(validation, phalcon_validation_ce); PHALCON_CALL_METHOD(NULL, validation, "__construct", prepared_validators); - + PHALCON_CALL_METHOD(&filters, element, "getfilters"); - - if (Z_TYPE_P(filters) == IS_ARRAY) { + + if (Z_TYPE_P(filters) == IS_ARRAY) { PHALCON_CALL_METHOD(&name, element, "getname"); PHALCON_CALL_METHOD(NULL, validation, "setfilters", name, filters); } - + PHALCON_CALL_METHOD(&element_messages, validation, "validate", data, entity); if (phalcon_fast_count_ev(element_messages TSRMLS_CC)) { PHALCON_CALL_METHOD(&name, element, "getname"); phalcon_array_update_zval(&messages, name, element_messages, PH_COPY | PH_SEPARATE); - + not_failed = PHALCON_GLOBAL(z_false); } } } - + zend_hash_move_forward_ex(ah0, &hp0); } - + if (!zend_is_true(not_failed)) { phalcon_update_property_this_quick(this_ptr, SL("_messages"), messages, 743366684UL TSRMLS_CC); } - + if (phalcon_method_quick_exists_ex(this_ptr, SS("aftervalidation"), 1795965282UL TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, "aftervalidation", messages); } - - + + RETURN_NCTOR(not_failed); } @@ -49137,10 +49173,10 @@ static PHP_METHOD(Phalcon_Forms_Form, getMessages){ zval **by_item_name = NULL, *messages; phalcon_fetch_params_ex(0, 1, &by_item_name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); if (by_item_name && zend_is_true(*by_item_name)) { - if (Z_TYPE_P(messages) != IS_ARRAY) { + if (Z_TYPE_P(messages) != IS_ARRAY) { object_init_ex(return_value, phalcon_validation_message_group_ce); phalcon_validation_group_construct_helper(return_value, NULL TSRMLS_CC); } @@ -49172,12 +49208,12 @@ static PHP_METHOD(Phalcon_Forms_Form, getMessagesFor){ zval **name, *messages, *element_messages; phalcon_fetch_params_ex(1, 0, &name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_fetch(&element_messages, messages, *name)) { RETURN_ZVAL(element_messages, 1, 0); } - + object_init_ex(return_value, phalcon_validation_message_group_ce); phalcon_validation_group_construct_helper(return_value, NULL TSRMLS_CC); } @@ -49187,7 +49223,7 @@ static PHP_METHOD(Phalcon_Forms_Form, hasMessagesFor){ zval **name, *messages; phalcon_fetch_params_ex(1, 0, &name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); RETURN_BOOL(phalcon_array_isset(messages, *name)); } @@ -49201,11 +49237,11 @@ static PHP_METHOD(Phalcon_Forms_Form, add){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &element, &pos, &type); - + PHALCON_VERIFY_INTERFACE_EX(element, phalcon_forms_elementinterface_ce, phalcon_forms_exception_ce, 1); - + PHALCON_CALL_METHOD(&name, element, "getname"); - + PHALCON_CALL_METHOD(NULL, element, "setform", this_ptr); if (!pos || Z_TYPE_P(pos) == IS_NULL) { @@ -49267,7 +49303,7 @@ static PHP_METHOD(Phalcon_Forms_Form, add){ phalcon_update_property_this_quick(this_ptr, SL("_elements"), elements, 3134610529UL TSRMLS_CC); } - + RETURN_THIS(); } @@ -49276,12 +49312,12 @@ static PHP_METHOD(Phalcon_Forms_Form, render){ zval **name, **attributes = NULL, *elements, *element; phalcon_fetch_params_ex(1, 1, &name, &attributes); - + PHALCON_ENSURE_IS_STRING(name); if (!attributes) { attributes = &PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); @@ -49296,14 +49332,14 @@ static PHP_METHOD(Phalcon_Forms_Form, get){ zval **name, *elements, *element; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { PHALCON_ENSURE_IS_STRING(name); zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + RETURN_ZVAL(element, 1, 0); } @@ -49323,7 +49359,7 @@ static PHP_METHOD(Phalcon_Forms_Form, label){ zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + PHALCON_RETURN_CALL_METHODW(element, "label", *attributes); } @@ -49332,22 +49368,22 @@ static PHP_METHOD(Phalcon_Forms_Form, getLabel){ zval **name, *elements, *element, *label = NULL; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { PHALCON_ENSURE_IS_STRING(name); zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + PHALCON_MM_GROW(); PHALCON_CALL_METHOD(&label, element, "getlabel"); - + /* Use the element's name as label if the label is not available */ if (!zend_is_true(label)) { RETURN_CTOR(*name); } - + RETURN_CTOR(label); } @@ -49358,7 +49394,7 @@ static PHP_METHOD(Phalcon_Forms_Form, getValue){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &name); - + entity = phalcon_fetch_nproperty_this(this_ptr, SL("_entity"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(entity) == IS_OBJECT) { PHALCON_INIT_VAR(method); @@ -49368,22 +49404,22 @@ static PHP_METHOD(Phalcon_Forms_Form, getValue){ PHALCON_RETURN_CALL_METHOD(entity, Z_STRVAL_P(method)); RETURN_MM(); } - + if (phalcon_isset_property_zval(entity, name TSRMLS_CC)) { PHALCON_OBS_VAR(value); phalcon_read_property_zval(&value, entity, name, PH_NOISY TSRMLS_CC); RETURN_CTOR(value); } } - + data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(data) == IS_ARRAY) { - + if (Z_TYPE_P(data) == IS_ARRAY) { + if (phalcon_array_isset_fetch(&value, data, name)) { RETURN_CTOR(value); } } - + RETURN_MM_NULL(); } @@ -49392,7 +49428,7 @@ static PHP_METHOD(Phalcon_Forms_Form, has){ zval **name, *elements; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); RETURN_BOOL(phalcon_array_isset(elements, *name)); } @@ -49402,9 +49438,9 @@ static PHP_METHOD(Phalcon_Forms_Form, remove){ zval *name, *elements; phalcon_fetch_params(0, 1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - + if (phalcon_array_isset(elements, name)) { phalcon_unset_property_array(this_ptr, SL("_elements"), name TSRMLS_CC); @@ -49427,21 +49463,21 @@ static PHP_METHOD(Phalcon_Forms_Form, clear){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &fields); - + if (!fields) { fields = PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) == IS_ARRAY) { - + if (Z_TYPE_P(elements) == IS_ARRAY) { + phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(element); - - if (Z_TYPE_P(fields) != IS_ARRAY) { + + if (Z_TYPE_P(fields) != IS_ARRAY) { PHALCON_CALL_METHOD(NULL, element, "clear"); } else { PHALCON_CALL_METHOD(&name, element, "getname"); @@ -49449,12 +49485,12 @@ static PHP_METHOD(Phalcon_Forms_Form, clear){ PHALCON_CALL_METHOD(NULL, element, "clear"); } } - + zend_hash_move_forward_ex(ah0, &hp0); } - + } - + RETURN_THIS(); } @@ -53648,7 +53684,7 @@ static PHP_METHOD(Phalcon_Http_Request_File, __set_state) { static PHP_METHOD(Phalcon_Http_Request_File, getExtension){ - RETURN_MEMBER(this_ptr, "_extension "); + RETURN_MEMBER_QUICK(this_ptr, "_extension", 282305761UL); } @@ -60564,7 +60600,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, __construct){ zval *service_name; phalcon_fetch_params_ex(0, 2, &dependency_injector, &collection_manager); - + PHALCON_MM_GROW(); if (!dependency_injector || Z_TYPE_PP(dependency_injector) != IS_OBJECT) { @@ -60575,13 +60611,13 @@ static PHP_METHOD(Phalcon_Mvc_Collection, __construct){ } PHALCON_VERIFY_INTERFACE_EX(di, phalcon_diinterface_ce, phalcon_mvc_collection_exception_ce, 1); - + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), di, 765199457UL TSRMLS_CC); - + if (!collection_manager || Z_TYPE_PP(collection_manager) != IS_OBJECT) { PHALCON_ALLOC_GHOST_ZVAL(service_name); ZVAL_STRING(service_name, "collectionManager", 1); - + PHALCON_CALL_METHOD(&mm, di, "getshared", service_name); if (Z_TYPE_P(mm) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The injected service 'collectionManager' is not valid"); @@ -60591,17 +60627,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, __construct){ else { mm = *collection_manager; } - + PHALCON_VERIFY_INTERFACE_EX(mm, phalcon_mvc_collection_managerinterface_ce, phalcon_mvc_collection_exception_ce, 1); phalcon_update_property_this_quick(this_ptr, SL("_collectionManager"), mm, 2683361163UL TSRMLS_CC); - + PHALCON_CALL_METHOD(NULL, mm, "initialize", this_ptr); - + if (phalcon_method_quick_exists_ex(this_ptr, SS("onconstruct"), 564344039UL TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, "onconstruct"); } - + PHALCON_MM_RESTORE(); } @@ -60614,10 +60650,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setId){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &id); - + if (Z_TYPE_P(id) != IS_OBJECT) { collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); if (zend_is_true(use_implicit_ids)) { ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -60665,10 +60701,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setEventsManager){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &events_manager); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "setcustomeventsmanager", this_ptr, events_manager); - + PHALCON_MM_RESTORE(); } @@ -60693,7 +60729,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, getReservedAttributes){ reserved = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_reserved") TSRMLS_CC); if (Z_TYPE_P(reserved) == IS_NULL) { zval *dummy = PHALCON_GLOBAL(z_true); - + array_init_size(return_value, 5); Z_ADDREF_P(dummy); add_assoc_zval_ex(return_value, SS("_connection"), dummy); Z_ADDREF_P(dummy); add_assoc_zval_ex(return_value, SS("_dependencyInjector"), dummy); @@ -60715,10 +60751,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, useImplicitObjectIds){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &use_implicit_object_ids); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "useimplicitobjectids", this_ptr, use_implicit_object_ids); - + PHALCON_MM_RESTORE(); } @@ -60727,7 +60763,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setSource){ zval *source; phalcon_fetch_params(0, 1, 0, &source); - + phalcon_update_property_this_quick(this_ptr, SL("_source"), source, 3355220565UL TSRMLS_CC); RETURN_THISW(); } @@ -60743,12 +60779,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, getSource){ if (!zend_is_true(source)) { PHALCON_INIT_VAR(class_name); phalcon_get_class_ns(class_name, this_ptr, 0 TSRMLS_CC); - + PHALCON_INIT_NVAR(source); phalcon_uncamelize(source, class_name); phalcon_update_property_this_quick(this_ptr, SL("_source"), source, 3355220565UL TSRMLS_CC); } - + RETURN_CTOR(source); } @@ -60759,7 +60795,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setConnectionService){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &connection_service); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "setconnectionservice", this_ptr, connection_service); RETURN_THIS(); @@ -60783,11 +60819,11 @@ static PHP_METHOD(Phalcon_Mvc_Collection, getConnection){ phalcon_read_property_this(&connection, this_ptr, SL("_connection"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(connection) != IS_OBJECT) { collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&connection, collection_manager, "getconnection", this_ptr); phalcon_update_property_this_quick(this_ptr, SL("_connection"), connection, 3057302292UL TSRMLS_CC); } - + RETURN_CTOR(connection); } @@ -60798,7 +60834,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, readAttribute){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &attribute); - + if (phalcon_isset_property_zval(this_ptr, attribute TSRMLS_CC)) { PHALCON_OBS_VAR(attribute_value); phalcon_read_property_zval(&attribute_value, this_ptr, attribute, PH_NOISY TSRMLS_CC); @@ -60812,9 +60848,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, writeAttribute){ zval *attribute, *value; phalcon_fetch_params(0, 2, 0, &attribute, &value); - + phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - + } static PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ @@ -60828,33 +60864,33 @@ static PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &collection, &document); - + if (Z_TYPE_P(collection) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid collection"); return; } - if (Z_TYPE_P(document) != IS_ARRAY) { + if (Z_TYPE_P(document) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid document"); return; } - + PHALCON_INIT_VAR(cloned_collection); if (phalcon_clone(cloned_collection, collection TSRMLS_CC) == FAILURE) { RETURN_MM(); } - + phalcon_is_iterable(document, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + PHALCON_CALL_METHOD(NULL, cloned_collection, "writeattribute", key, value); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(cloned_collection); } @@ -60872,15 +60908,19 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 4, 0, ¶ms, &collection, &connection, &unique); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&mongo_collection, connection, "selectcollection", source); - + if (Z_TYPE_P(mongo_collection) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Couldn't select mongo collection"); + return; + } + if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(conditions); phalcon_array_fetch_long(&conditions, params, 0, PH_NOISY); @@ -60893,71 +60933,76 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ array_init(conditions); } } - + + if (Z_TYPE_P(conditions) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Find parameters must be an array"); + return; + } + PHALCON_INIT_VAR(documents_cursor); if (phalcon_array_isset_quick_string(params, SS("fields"), 2881624156UL)) { PHALCON_OBS_VAR(fields); phalcon_array_fetch_quick_string(&fields, params, SS("fields"), 2881624156UL, PH_NOISY); - + PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions, fields); } else { PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions); } - + if (phalcon_array_isset_quick_string(params, SS("limit"), 192268420UL)) { PHALCON_OBS_VAR(limit); phalcon_array_fetch_quick_string(&limit, params, SS("limit"), 192268420UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "limit", limit); } - + if (phalcon_array_isset_quick_string(params, SS("sort"), 274650125UL)) { PHALCON_OBS_VAR(sort); phalcon_array_fetch_quick_string(&sort, params, SS("sort"), 274650125UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "sort", sort); } - + if (phalcon_array_isset_quick_string(params, SS("skip"), 274496444UL)) { PHALCON_OBS_NVAR(sort); phalcon_array_fetch_quick_string(&sort, params, SS("skip"), 274496444UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "skip", sort); } - + if (phalcon_array_isset_quick_string(params, SS("fields"), 2881624156UL)) { PHALCON_INIT_VAR(base); object_init_ex(base, phalcon_mvc_collection_document_ce); } else { PHALCON_CPY_WRT(base, collection); } - + if (PHALCON_IS_TRUE(unique)) { - + PHALCON_CALL_METHOD(NULL, documents_cursor, "rewind"); PHALCON_CALL_METHOD(&document, documents_cursor, "current"); - if (Z_TYPE_P(document) == IS_ARRAY) { + if (Z_TYPE_P(document) == IS_ARRAY) { PHALCON_RETURN_CALL_SELF("cloneresult", base, document); RETURN_MM(); } - + RETURN_MM_FALSE; } - + PHALCON_INIT_VAR(collections); array_init(collections); - + PHALCON_CALL_FUNCTION(&documents_array, "iterator_to_array", documents_cursor); - + phalcon_is_iterable(documents_array, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(document); - + PHALCON_CALL_SELF(&collection_cloned, "cloneresult", base, document); phalcon_array_append(&collections, collection_cloned, PH_SEPARATE); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(collections); } @@ -60970,15 +61015,15 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, ¶ms, &collection, &connection); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&mongo_collection, connection, "selectcollection", source); - + if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(conditions); phalcon_array_fetch_long(&conditions, params, 0, PH_NOISY); @@ -60991,7 +61036,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ array_init(conditions); } } - + PHALCON_INIT_VAR(simple); ZVAL_BOOL(simple, 1); if (phalcon_array_isset_quick_string(params, SS("limit"), 192268420UL)) { @@ -61007,33 +61052,33 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ } } } - + if (PHALCON_IS_FALSE(simple)) { - + PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions); - + if (phalcon_array_isset_quick_string(params, SS("limit"), 192268420UL)) { PHALCON_OBS_VAR(limit); phalcon_array_fetch_quick_string(&limit, params, SS("limit"), 192268420UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "limit", limit); } - + if (phalcon_array_isset_quick_string(params, SS("sort"), 274650125UL)) { PHALCON_OBS_VAR(sort); phalcon_array_fetch_quick_string(&sort, params, SS("sort"), 274650125UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "sort", sort); } - + if (phalcon_array_isset_quick_string(params, SS("skip"), 274496444UL)) { PHALCON_OBS_NVAR(sort); phalcon_array_fetch_quick_string(&sort, params, SS("skip"), 274496444UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "skip", sort); } - + phalcon_fast_count(return_value, documents_cursor TSRMLS_CC); RETURN_MM(); } - + PHALCON_RETURN_CALL_METHOD(mongo_collection, "count", conditions); RETURN_MM(); } @@ -61046,17 +61091,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &dependency_injector, &disable_events, &exists); - + if (!zend_is_true(disable_events)) { - + PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "beforeValidation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + if (!zend_is_true(exists)) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeValidationOnCreate", 1); @@ -61064,16 +61109,16 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeValidationOnUpdate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "validation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { if (!zend_is_true(disable_events)) { @@ -61083,9 +61128,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ } RETURN_MM_FALSE; } - + if (!zend_is_true(disable_events)) { - + if (!zend_is_true(exists)) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterValidationOnCreate", 1); @@ -61093,28 +61138,28 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterValidationOnUpdate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterValidation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeSave", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + if (zend_is_true(exists)) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeUpdate", 1); @@ -61122,13 +61167,13 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeCreate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - + RETURN_MM_TRUE; } @@ -61139,7 +61184,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &disable_events, &success, &exists); - + if (PHALCON_IS_TRUE(success)) { if (!zend_is_true(disable_events)) { if (PHALCON_IS_TRUE(exists)) { @@ -61150,12 +61195,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ ZVAL_STRING(event_name, "afterCreate", 1); } PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterSave", 1); PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } - + RETURN_CTOR(success); } if (!zend_is_true(disable_events)) { @@ -61163,7 +61208,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ ZVAL_STRING(event_name, "notSave", 1); PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } - + PHALCON_CALL_METHOD(NULL, this_ptr, "_canceloperation", disable_events); RETURN_MM_FALSE; } @@ -61178,29 +61223,29 @@ static PHP_METHOD(Phalcon_Mvc_Collection, validate){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &validator); - + if (Z_TYPE_P(validator) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Validator must be an Object"); return; } - + PHALCON_CALL_METHOD(&status, validator, "validate", this_ptr); if (PHALCON_IS_FALSE(status)) { PHALCON_CALL_METHOD(&messages, validator, "getmessages"); - + phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(message); - + phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + } - + PHALCON_MM_RESTORE(); } @@ -61212,12 +61257,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, validationHasFailed){ PHALCON_OBS_VAR(error_messages); phalcon_read_property_this(&error_messages, this_ptr, SL("_errorMessages"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(error_messages) == IS_ARRAY) { + if (Z_TYPE_P(error_messages) == IS_ARRAY) { if (phalcon_fast_count_ev(error_messages TSRMLS_CC)) { RETURN_MM_TRUE; } } - + RETURN_MM_FALSE; } @@ -61240,7 +61285,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, fireEvent){ if (phalcon_method_exists_ex(this_ptr, Z_STRVAL_P(lower), Z_STRLEN_P(lower)+1 TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, Z_STRVAL_P(lower)); } - + PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_RETURN_CALL_METHOD(collection_manager, "notifyevent", *event_name, this_ptr); @@ -61271,12 +61316,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, fireEventCancel){ PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&status, collection_manager, "notifyevent", *event_name, this_ptr); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + RETURN_MM_TRUE; } @@ -61287,9 +61332,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &disable_events); - + if (!zend_is_true(disable_events)) { - + PHALCON_OBS_VAR(operation_made); phalcon_read_property_this(&operation_made, this_ptr, SL("_operationMade"), PH_NOISY TSRMLS_CC); if (PHALCON_IS_LONG(operation_made, 3)) { @@ -61299,7 +61344,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "notSaved", 1); } - + PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } RETURN_MM_FALSE; @@ -61315,9 +61360,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &collection); - + if (phalcon_isset_property(this_ptr, SS("_id") TSRMLS_CC)) { - + PHALCON_OBS_VAR(id); phalcon_read_property_this(&id, this_ptr, SL("_id"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(id) == IS_OBJECT) { @@ -61325,7 +61370,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ } else { PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); if (zend_is_true(use_implicit_ids)) { ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -61339,16 +61384,16 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ PHALCON_CPY_WRT(mongo_id, id); } } - + PHALCON_INIT_VAR(parameters); array_init_size(parameters, 1); phalcon_array_update_string(¶meters, SL("_id"), mongo_id, PH_COPY); - + PHALCON_CALL_METHOD(&document_count, collection, "count", parameters); - + z_zero = PHALCON_GLOBAL(z_zero); is_smaller_function(return_value, z_zero, document_count TSRMLS_CC); - + RETURN_MM(); } RETURN_MM_FALSE; @@ -61367,17 +61412,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, appendMessage){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &message); - + if (Z_TYPE_P(message) != IS_OBJECT) { PHALCON_CALL_FUNCTION(&type, "gettype", message); - + PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Invalid message format '", type, "'"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_collection_exception_ce, exception_message); return; } phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - + PHALCON_MM_RESTORE(); } @@ -61407,11 +61452,11 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ if (!arr) { arr = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } - + if (!mode) { mode = PHALCON_GLOBAL(z_null); } @@ -61421,17 +61466,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - + if (Z_TYPE_P(mode) == IS_NULL) { PHALCON_SEPARATE_PARAM(mode); PHALCON_CALL_METHOD(&exists, this_ptr, "_exists", collection); PHALCON_INIT_NVAR(mode); - + ZVAL_BOOL(mode, (PHALCON_IS_FALSE(exists) ? 1 : 0)); phalcon_update_property_long(this_ptr, SL("_operationMade"), (PHALCON_IS_FALSE(exists) ? 1 : 2) TSRMLS_CC); } else { @@ -61440,19 +61485,19 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ phalcon_update_property_long(this_ptr, SL("_operationMade"), (PHALCON_IS_FALSE(exists) ? 1 : 2) TSRMLS_CC); } - + PHALCON_INIT_VAR(empty_array); array_init(empty_array); - + phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), empty_array, 1019066246UL TSRMLS_CC); - + disable_events = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_disableEvents") TSRMLS_CC); - + PHALCON_CALL_METHOD(&status, this_ptr, "_presave", dependency_injector, disable_events, exists); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + PHALCON_CALL_METHOD(&reserved, this_ptr, "getreservedattributes"); PHALCON_CALL_FUNCTION(&properties, "get_object_vars", this_ptr); @@ -61472,7 +61517,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ if (Z_TYPE_P(white_list) != IS_ARRAY || phalcon_fast_in_array(&key, white_list TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch(&value, arr, &key, PH_NOISY); - + Z_ADDREF_P(value); if (likely(Z_TYPE(key) == IS_STRING)) { add_assoc_zval_ex(data, Z_STRVAL(key), Z_STRLEN(key)+1, value); @@ -61497,7 +61542,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ else { array_init(data); } - + PHALCON_INIT_NVAR(status); if (PHALCON_IS_FALSE(mode)){ @@ -61534,7 +61579,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ } zval_ptr_dtor(&data); - + PHALCON_RETURN_CALL_METHOD(this_ptr, "_postsave", disable_events, success, exists); RETURN_MM(); } @@ -61549,21 +61594,21 @@ static PHP_METHOD(Phalcon_Mvc_Collection, findById){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &id); - + if (Z_TYPE_P(id) != IS_OBJECT) { - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&collection_manager, collection, "getcollectionmanager"); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", collection); if (zend_is_true(use_implicit_ids)) { ce1 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -61578,11 +61623,11 @@ static PHP_METHOD(Phalcon_Mvc_Collection, findById){ } else { PHALCON_CPY_WRT(mongo_id, id); } - + PHALCON_INIT_VAR(conditions); array_init_size(conditions, 1); phalcon_array_update_string(&conditions, SL("_id"), mongo_id, PH_COPY); - + PHALCON_INIT_VAR(parameters); array_init_size(parameters, 1); phalcon_array_append(¶meters, conditions, 0); @@ -61599,28 +61644,28 @@ static PHP_METHOD(Phalcon_Mvc_Collection, findFirst){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for findFirst"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); unique = PHALCON_GLOBAL(z_true); @@ -61637,30 +61682,30 @@ static PHP_METHOD(Phalcon_Mvc_Collection, find){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for find"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + unique = PHALCON_GLOBAL(z_false); PHALCON_RETURN_CALL_SELF("_getresultset", parameters, collection, connection, unique); RETURN_MM(); @@ -61674,28 +61719,28 @@ static PHP_METHOD(Phalcon_Mvc_Collection, count){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for count"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); PHALCON_RETURN_CALL_SELF("_getgroupresultset", parameters, collection, connection); RETURN_MM(); @@ -61710,32 +61755,32 @@ static PHP_METHOD(Phalcon_Mvc_Collection, aggregate){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, ¶meters); - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for aggregate"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); PHALCON_RETURN_CALL_METHOD(collection, "aggregate", parameters); RETURN_MM(); @@ -61752,60 +61797,60 @@ static PHP_METHOD(Phalcon_Mvc_Collection, summatory){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &field, &conditions, &finalize); - + if (!conditions) { conditions = PHALCON_GLOBAL(z_null); } - + if (!finalize) { finalize = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(field) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid field name for group"); return; } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - + PHALCON_INIT_VAR(keys); array_init(keys); - + PHALCON_INIT_VAR(empty_array); array_init(empty_array); - + PHALCON_INIT_VAR(initial); array_init_size(initial, 1); phalcon_array_update_string(&initial, SL("summatory"), empty_array, PH_COPY); - + PHALCON_INIT_VAR(reduce); PHALCON_CONCAT_SVSVSVS(reduce, "function (curr, result) { if (typeof result.summatory[curr.", field, "] === \"undefined\") { result.summatory[curr.", field, "] = 1; } else { result.summatory[curr.", field, "]++; } }"); PHALCON_CALL_METHOD(&group, collection, "group", keys, initial, reduce); if (phalcon_array_isset_quick_string(group, SS("retval"), 1060973715UL)) { - + PHALCON_OBS_VAR(retval); phalcon_array_fetch_quick_string(&retval, group, SS("retval"), 1060973715UL, PH_NOISY); if (phalcon_array_isset_long(retval, 0)) { - + PHALCON_OBS_VAR(first_retval); phalcon_array_fetch_long(&first_retval, retval, 0, PH_NOISY); if (phalcon_array_isset_quick_string(first_retval, SS("summatory"), 2358676118UL)) { @@ -61813,13 +61858,13 @@ static PHP_METHOD(Phalcon_Mvc_Collection, summatory){ phalcon_array_fetch_quick_string(&summatory, first_retval, SS("summatory"), 2358676118UL, PH_NOISY); RETURN_CTOR(summatory); } - + RETURN_CTOR(first_retval); } - + RETURN_CTOR(retval); } - + PHALCON_MM_RESTORE(); } @@ -61834,7 +61879,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, create){ if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } @@ -61856,7 +61901,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, update){ if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } @@ -61866,24 +61911,24 @@ static PHP_METHOD(Phalcon_Mvc_Collection, update){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - + PHALCON_CALL_METHOD(&exists, this_ptr, "_exists", collection); - if (!zend_is_true(exists)) { + if (!zend_is_true(exists)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "InvalidUpdateAttempt", 1); - + PHALCON_INIT_VAR(message); ZVAL_STRING(message, "Document cannot be updated because it does not exist", 1); - + PHALCON_INIT_VAR(collection_message); object_init_ex(collection_message, phalcon_mvc_collection_message_ce); PHALCON_CALL_METHOD(NULL, collection_message, "__construct", message, PHALCON_GLOBAL(z_null), type); - + PHALCON_INIT_VAR(messages); array_init_size(messages, 1); phalcon_array_append(&messages, collection_message, PH_SEPARATE); @@ -61909,37 +61954,37 @@ static PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The document cannot be deleted because it doesn't exist"); return; } - + disable_events = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_disableEvents") TSRMLS_CC); if (!zend_is_true(disable_events)) { - + PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "beforeDelete", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - + PHALCON_OBS_VAR(id); phalcon_read_property_this(&id, this_ptr, SL("_id"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - + PHALCON_CALL_METHOD(&source, this_ptr, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); if (Z_TYPE_P(id) == IS_OBJECT || Z_TYPE_P(id) == IS_NULL) { PHALCON_CPY_WRT(mongo_id, id); } else { PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); if (zend_is_true(use_implicit_ids)) { ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -61952,29 +61997,29 @@ static PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_CPY_WRT(mongo_id, id); } } - + PHALCON_INIT_VAR(id_condition); array_init_size(id_condition, 1); phalcon_array_update_string(&id_condition, SL("_id"), mongo_id, PH_COPY); - + PHALCON_INIT_VAR(success); ZVAL_BOOL(success, 0); - + PHALCON_INIT_VAR(options); array_init_size(options, 1); add_assoc_long_ex(options, SS("w"), 1); - + PHALCON_CALL_METHOD(&status, collection, "remove", id_condition, options); - if (Z_TYPE_P(status) != IS_ARRAY) { + if (Z_TYPE_P(status) != IS_ARRAY) { RETURN_MM_FALSE; } - + if (phalcon_array_isset_quick_string(status, SS("ok"), 193501407UL)) { - + PHALCON_OBS_VAR(ok); phalcon_array_fetch_quick_string(&ok, status, SS("ok"), 193501407UL, PH_NOISY); if (zend_is_true(ok)) { - + ZVAL_BOOL(success, 1); if (!zend_is_true(disable_events)) { PHALCON_INIT_NVAR(event_name); @@ -61986,7 +62031,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_INIT_NVAR(success); ZVAL_BOOL(success, 0); } - + RETURN_NCTOR(success); } @@ -62001,20 +62046,20 @@ static PHP_METHOD(Phalcon_Mvc_Collection, toArray){ PHALCON_INIT_VAR(data); array_init(data); - + PHALCON_CALL_METHOD(&reserved, this_ptr, "getreservedattributes"); - + PHALCON_CALL_FUNCTION(&properties, "get_object_vars", this_ptr); - + phalcon_is_iterable(properties, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + if (PHALCON_IS_STRING(key, "_id")) { - + if (Z_TYPE_P(value) != IS_NULL) { phalcon_array_update_zval(&data, key, value, PH_COPY); } @@ -62023,10 +62068,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, toArray){ phalcon_array_update_zval(&data, key, value, PH_COPY); } } - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(data); } @@ -62037,7 +62082,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, serialize){ PHALCON_MM_GROW(); PHALCON_CALL_METHOD(&data, this_ptr, "toarray"); - + phalcon_serialize(return_value, &data TSRMLS_CC); RETURN_MM(); } @@ -62053,25 +62098,25 @@ static PHP_METHOD(Phalcon_Mvc_Collection, unserialize){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &data); - + if (Z_TYPE_P(data) == IS_STRING) { - + PHALCON_INIT_VAR(attributes); phalcon_unserialize(attributes, data TSRMLS_CC); - if (Z_TYPE_P(attributes) == IS_ARRAY) { - + if (Z_TYPE_P(attributes) == IS_ARRAY) { + PHALCON_CALL_CE_STATIC(&dependency_injector, phalcon_di_ce, "getdefault"); - + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A dependency injector container is required to obtain the services related to the ODM"); return; } - + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - + PHALCON_INIT_VAR(service); ZVAL_STRING(service, "collectionManager", 1); - + PHALCON_CALL_METHOD(&manager, dependency_injector, "getshared", service); if (Z_TYPE_P(manager) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The injected service 'collectionManager' is not valid"); @@ -62079,21 +62124,21 @@ static PHP_METHOD(Phalcon_Mvc_Collection, unserialize){ } PHALCON_VERIFY_INTERFACE(manager, phalcon_mvc_collection_managerinterface_ce); - + phalcon_update_property_this_quick(this_ptr, SL("_collectionManager"), manager, 2683361163UL TSRMLS_CC); - + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_MM_NULL(); } } @@ -62109,22 +62154,22 @@ static PHP_METHOD(Phalcon_Mvc_Collection, execute){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &code, &args); - - if (args && Z_TYPE_P(args) != IS_ARRAY) { + + if (args && Z_TYPE_P(args) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid args for execute"); return; } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); if (args) { @@ -68178,13 +68223,6 @@ static PHP_METHOD(Phalcon_Mvc_Model, toArray){ PHALCON_GET_HVALUE(attribute); - if (columns && Z_TYPE_P(columns) == IS_ARRAY) { - if (!phalcon_fast_in_array(attribute, columns TSRMLS_CC)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - if (Z_TYPE_P(column_map) == IS_ARRAY) { if (!phalcon_array_isset(column_map, attribute)) { PHALCON_INIT_NVAR(exception_message); @@ -68198,6 +68236,14 @@ static PHP_METHOD(Phalcon_Mvc_Model, toArray){ } else { PHALCON_CPY_WRT(attribute_field, attribute); } + + if (columns && Z_TYPE_P(columns) == IS_ARRAY) { + if (!phalcon_fast_in_array(attribute_field, columns TSRMLS_CC) && !phalcon_fast_in_array(attribute, columns TSRMLS_CC)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } + if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY TSRMLS_CC); @@ -97085,7 +97131,7 @@ static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall){ phalcon_read_property_this(&array_helpers, this_ptr, SL("_arrayHelpers"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(array_helpers) != IS_ARRAY) { PHALCON_INIT_NVAR(array_helpers); - array_init_size(array_helpers, 16); + array_init_size(array_helpers, 17); add_assoc_bool_ex(array_helpers, SS("link_to"), 1); add_assoc_bool_ex(array_helpers, SS("image"), 1); add_assoc_bool_ex(array_helpers, SS("form"), 1); @@ -97102,6 +97148,7 @@ static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall){ add_assoc_bool_ex(array_helpers, SS("date_field"), 1); add_assoc_bool_ex(array_helpers, SS("numeric_field"), 1); add_assoc_bool_ex(array_helpers, SS("email_field"), 1); + add_assoc_bool_ex(array_helpers, SS("image_input"), 1); phalcon_update_property_this_quick(this_ptr, SL("_arrayHelpers"), array_helpers, 3087512406UL TSRMLS_CC); } @@ -105661,8 +105708,8 @@ static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate){ PHALCON_CALL_METHOD(&models, builder, "getfrom"); if (Z_TYPE_P(models) == IS_ARRAY) { - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); + PHALCON_INIT_VAR(model_name); + phalcon_array_get_current(model_name, models); } else { PHALCON_CPY_WRT(model_name, models); } diff --git a/build/32bits/php_phalcon.h b/build/32bits/php_phalcon.h index ee2dcbe1d55..0deb4ad5733 100644 --- a/build/32bits/php_phalcon.h +++ b/build/32bits/php_phalcon.h @@ -29,7 +29,7 @@ #include #endif -#define PHP_PHALCON_VERSION "1.3.3" +#define PHP_PHALCON_VERSION "1.3.4" #define PHP_PHALCON_EXTNAME "phalcon" #define PHALCON_NUM_PREALLOCATED_FRAMES 25 diff --git a/build/64bits/phalcon.c b/build/64bits/phalcon.c index 4ce25a04a80..c6a8f47fb06 100644 --- a/build/64bits/phalcon.c +++ b/build/64bits/phalcon.c @@ -1210,17 +1210,25 @@ static int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt } #define PHALCON_VERIFY_INTERFACE_EX(instance, interface_ce, exception_ce, restore_stack) \ - if (Z_TYPE_P(instance) != IS_OBJECT || !instanceof_function_ex(Z_OBJCE_P(instance), interface_ce, 1 TSRMLS_CC)) { \ - if (Z_TYPE_P(instance) != IS_OBJECT) { \ - zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ - } \ - else { \ - zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, object of type %s given", interface_ce->name, Z_OBJCE_P(instance)->name); \ - } \ + if (Z_TYPE_P(instance) != IS_OBJECT) { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ if (restore_stack) { \ PHALCON_MM_RESTORE(); \ } \ return; \ + } else { \ + if (!instanceof_function_ex(Z_OBJCE_P(instance), interface_ce, 1 TSRMLS_CC)) { \ + if (Z_TYPE_P(instance) != IS_OBJECT) { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ + } \ + else { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, object of type %s given", interface_ce->name, Z_OBJCE_P(instance)->name); \ + } \ + if (restore_stack) { \ + PHALCON_MM_RESTORE(); \ + } \ + return; \ + } \ } #define PHALCON_VERIFY_INTERFACE_OR_NULL_EX(pzv, interface_ce, exception_ce, restore_stack) \ @@ -9736,6 +9744,8 @@ static void phalcon_concat_self(zval **left, zval *right TSRMLS_DC){ } } + SEPARATE_ZVAL_IF_NOT_REF(left); + length = Z_STRLEN_PP(left) + Z_STRLEN_P(right); Z_STRVAL_PP(left) = str_erealloc(Z_STRVAL_PP(left), length + 1); @@ -9777,6 +9787,8 @@ static void phalcon_concat_self_str(zval **left, const char *right, int right_le } } + SEPARATE_ZVAL_IF_NOT_REF(left); + length = Z_STRLEN_PP(left) + right_length; Z_STRVAL_PP(left) = str_erealloc(Z_STRVAL_PP(left), length + 1); @@ -15230,7 +15242,7 @@ static const zend_function_entry phalcon_debug_method_entry[] = { PHP_ME(Phalcon_Debug, getJsSources, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, showTraceItem, NULL, ZEND_ACC_PROTECTED) PHP_ME(Phalcon_Debug, onUncaughtException, arginfo_phalcon_debug_onuncaughtexception, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Debug, getCharset, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Debug, getCharset, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_ME(Phalcon_Debug, setCharset, arginfo_phalcon_debug_setcharset, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, getLinesBeforeContext, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, setLinesBeforeContext, arginfo_phalcon_debug_setlines, ZEND_ACC_PUBLIC) @@ -15388,7 +15400,7 @@ static PHP_METHOD(Phalcon_Debug, _escapeString){ zval line_break; zval escaped_line_break; - charset = phalcon_fetch_nproperty_this(getThis(), SL("_charset"), PH_NOISY TSRMLS_CC); + charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); INIT_ZVAL(line_break); ZVAL_STRING(&line_break, "\n", 0); @@ -15847,7 +15859,7 @@ static PHP_METHOD(Phalcon_Debug, showTraceItem){ PHALCON_INIT_VAR(comment_pattern); ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1); - charset = phalcon_fetch_nproperty_this(getThis(), SL("_charset"), PH_NOISY TSRMLS_CC); + charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); PHALCON_INIT_VAR(tab); ZVAL_STRING(tab, "\t", 1); @@ -16120,7 +16132,8 @@ static PHP_METHOD(Phalcon_Debug, onUncaughtException){ } static PHP_METHOD(Phalcon_Debug, getCharset) { - RETURN_MEMBER(getThis(), "_charset"); + zval *charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); + RETURN_ZVAL(charset, 1, 0); } static PHP_METHOD(Phalcon_Debug, setCharset) { @@ -16130,7 +16143,7 @@ static PHP_METHOD(Phalcon_Debug, setCharset) { phalcon_fetch_params_ex(1, 0, &charset); PHALCON_ENSURE_IS_STRING(charset); - phalcon_update_property_this(getThis(), SL("_charset"), *charset TSRMLS_CC); + phalcon_update_static_property_ce(phalcon_debug_ce, SL("_charset"), *charset TSRMLS_CC); RETURN_THISW(); } @@ -21755,15 +21768,36 @@ static PHP_METHOD(Phalcon_Tag, setDefault){ static PHP_METHOD(Phalcon_Tag, setDefaults){ - zval *values; + zval *values, *merge = NULL, *display_values, *merged_values = NULL;; + + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &values); + phalcon_fetch_params(1, 1, 1, &values, &merge); + + if (!merge) { + merge = PHALCON_GLOBAL(z_false); + } if (Z_TYPE_P(values) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_tag_exception_ce, "An array is required as default values"); return; } - phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + + if (zend_is_true(merge)) { + + display_values = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_displayValues") TSRMLS_CC); + if (Z_TYPE_P(display_values) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_values); + phalcon_fast_array_merge(merged_values, &display_values, &values TSRMLS_CC); + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), merged_values TSRMLS_CC); + } else { + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + } + } else { + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); } @@ -23637,7 +23671,7 @@ static PHP_METHOD(Phalcon_Version, _getVersion){ array_init_size(return_value, 5); add_next_index_long(return_value, 1); add_next_index_long(return_value, 3); - add_next_index_long(return_value, 3); + add_next_index_long(return_value, 4); add_next_index_long(return_value, PHALCON_VERSION_STABLE); add_next_index_long(return_value, 1); } @@ -29407,52 +29441,50 @@ static PHP_METHOD(Phalcon_Assets_Manager, output){ PHALCON_CALL_METHOD(&local, resource, "getlocal"); if (Z_TYPE_P(filters) == IS_ARRAY) { - if (zend_is_true(join)) { - if (zend_is_true(local)) { - - PHALCON_CALL_METHOD(&source_path, resource, "getrealsourcepath", complete_source_path); - - if (!zend_is_true(source_path)) { - PHALCON_CALL_METHOD(&source_path, resource, "getpath"); - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid source path"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } - } else { + if (zend_is_true(local)) { + + PHALCON_CALL_METHOD(&source_path, resource, "getrealsourcepath", complete_source_path); + + if (!zend_is_true(source_path)) { PHALCON_CALL_METHOD(&source_path, resource, "getpath"); - - PHALCON_INIT_NVAR(filter_needed); - ZVAL_TRUE(filter_needed); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid source path"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; } - - PHALCON_CALL_METHOD(&target_path, resource, "getrealtargetpath", complete_target_path); - - if (PHALCON_IS_EMPTY(target_path)) { + } else { + PHALCON_CALL_METHOD(&source_path, resource, "getpath"); + + PHALCON_INIT_NVAR(filter_needed); + ZVAL_TRUE(filter_needed); + } + + PHALCON_CALL_METHOD(&target_path, resource, "getrealtargetpath", complete_target_path); + + if (PHALCON_IS_EMPTY(target_path)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; + } + + if (zend_is_true(local)) { + + if (PHALCON_IS_EQUAL(target_path, source_path)) { PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path"); + PHALCON_CONCAT_SVS(exception_message, "Resource '", target_path, "' have the same source and target paths"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); return; } - - if (zend_is_true(local)) { - - if (PHALCON_IS_EQUAL(target_path, source_path)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", target_path, "' have the same source and target paths"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } - if (phalcon_file_exists(target_path TSRMLS_CC) == SUCCESS) { - if (phalcon_compare_mtime(target_path, source_path TSRMLS_CC)) { - PHALCON_INIT_NVAR(filter_needed); - ZVAL_TRUE(filter_needed); - } - } else { + if (phalcon_file_exists(target_path TSRMLS_CC) == SUCCESS) { + if (phalcon_compare_mtime(target_path, source_path TSRMLS_CC)) { PHALCON_INIT_NVAR(filter_needed); ZVAL_TRUE(filter_needed); } + } else { + PHALCON_INIT_NVAR(filter_needed); + ZVAL_TRUE(filter_needed); } } } @@ -48808,15 +48840,15 @@ static PHP_METHOD(Phalcon_Forms_Form, __construct){ Z_OBJ_HT_P(getThis()) = &phalcon_forms_form_object_handlers; phalcon_fetch_params(0, 0, 2, &entity, &user_options); - + if (!entity) { entity = PHALCON_GLOBAL(z_null); } - + if (!user_options) { user_options = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(entity) != IS_NULL) { if (Z_TYPE_P(entity) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The base entity is not valid"); @@ -48825,11 +48857,11 @@ static PHP_METHOD(Phalcon_Forms_Form, __construct){ phalcon_update_property_this_quick(this_ptr, SL("_entity"), entity, 7572068411466273UL TSRMLS_CC); } - - if (Z_TYPE_P(user_options) == IS_ARRAY) { + + if (Z_TYPE_P(user_options) == IS_ARRAY) { phalcon_update_property_this_quick(this_ptr, SL("_options"), user_options, 249878686345564848UL TSRMLS_CC); } - + if (phalcon_method_quick_exists_ex(this_ptr, SS("initialize"), 13878731931343821175UL TSRMLS_CC) == SUCCESS) { PHALCON_MM_GROW(); PHALCON_CALL_METHOD(NULL, this_ptr, "initialize", entity, user_options); @@ -48842,7 +48874,7 @@ static PHP_METHOD(Phalcon_Forms_Form, setAction){ zval *action; phalcon_fetch_params(0, 1, 0, &action); - + phalcon_update_property_this_quick(this_ptr, SL("_action"), action, 7572062815099266UL TSRMLS_CC); RETURN_THISW(); } @@ -48858,7 +48890,7 @@ static PHP_METHOD(Phalcon_Forms_Form, setUserOption){ zval *option, *value; phalcon_fetch_params(0, 2, 0, &option, &value); - + phalcon_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC); RETURN_THISW(); } @@ -48868,16 +48900,16 @@ static PHP_METHOD(Phalcon_Forms_Form, getUserOption){ zval *option, *default_value = NULL, *options, *value; phalcon_fetch_params(0, 1, 1, &option, &default_value); - + if (!default_value) { default_value = PHALCON_GLOBAL(z_null); } - + options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_fetch(&value, options, option)) { RETURN_ZVAL(value, 1, 0); } - + RETURN_ZVAL(default_value, 1, 0); } @@ -48886,13 +48918,13 @@ static PHP_METHOD(Phalcon_Forms_Form, setUserOptions){ zval *options; phalcon_fetch_params(0, 1, 0, &options); - - if (Z_TYPE_P(options) != IS_ARRAY) { + + if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "Parameter 'options' must be an array"); return; } phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 249878686345564848UL TSRMLS_CC); - + RETURN_THISW(); } @@ -48907,7 +48939,7 @@ static PHP_METHOD(Phalcon_Forms_Form, setEntity){ zval *entity; phalcon_fetch_params(0, 1, 0, &entity); - + if (Z_TYPE_P(entity) != IS_NULL && Z_TYPE_P(entity) != IS_OBJECT) { zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "'%s' must be an object or NULL", "entity"); return; @@ -48942,80 +48974,84 @@ static PHP_METHOD(Phalcon_Forms_Form, bind){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &data, &entity, &whitelist); - + if (!whitelist) { whitelist = PHALCON_GLOBAL(z_null); } - - if (Z_TYPE_P(data) != IS_ARRAY) { + + if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The data must be an array"); return; } - + PHALCON_OBS_VAR(elements); phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) != IS_ARRAY) { + if (Z_TYPE_P(elements) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "There are no elements in the form"); return; } - + PHALCON_INIT_VAR(filter); - + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + if (!phalcon_array_isset(elements, key)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } - - if (Z_TYPE_P(whitelist) == IS_ARRAY) { + + if (Z_TYPE_P(whitelist) == IS_ARRAY) { if (!phalcon_fast_in_array(key, whitelist TSRMLS_CC)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } } - + PHALCON_OBS_NVAR(element); phalcon_array_fetch(&element, elements, key, PH_NOISY); - + PHALCON_CALL_METHOD(&filters, element, "getfilters"); if (zend_is_true(filters)) { + if (Z_TYPE_P(filter) != IS_OBJECT) { + PHALCON_INIT_NVAR(service_name); PHALCON_ZVAL_MAYBE_INTERNED_STRING(service_name, phalcon_interned_filter); - + PHALCON_CALL_METHOD(&dependency_injector, this_ptr, "getdi"); + PHALCON_VERIFY_INTERFACE(dependency_injector, phalcon_diinterface_ce); + PHALCON_CALL_METHOD(&filter, dependency_injector, "getshared", service_name); PHALCON_VERIFY_INTERFACE(filter, phalcon_filterinterface_ce); } - + PHALCON_CALL_METHOD(&filtered_value, filter, "sanitize", value, filters); } else { PHALCON_CPY_WRT(filtered_value, value); } - + PHALCON_INIT_NVAR(method); PHALCON_CONCAT_SV(method, "set", key); zend_str_tolower(Z_STRVAL_P(method), Z_STRLEN_P(method)); - + if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, entity, Z_STRVAL_P(method), filtered_value); zend_hash_move_forward_ex(ah0, &hp0); continue; } - + phalcon_update_property_zval_zval(entity, key, filtered_value TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 6953229211038UL TSRMLS_CC); - + PHALCON_MM_RESTORE(); } @@ -49032,103 +49068,103 @@ static PHP_METHOD(Phalcon_Forms_Form, isValid){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &data, &entity); - + if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!entity) { entity = PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) != IS_ARRAY) { + if (Z_TYPE_P(elements) != IS_ARRAY) { RETURN_MM_TRUE; } - + if (Z_TYPE_P(entity) == IS_OBJECT) { PHALCON_CALL_METHOD(NULL, this_ptr, "bind", data, entity); } - - if (Z_TYPE_P(data) != IS_ARRAY) { + + if (Z_TYPE_P(data) != IS_ARRAY) { data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY TSRMLS_CC); } - + if (phalcon_method_quick_exists_ex(this_ptr, SS("beforevalidation"), 2568167555410680675UL TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(&status, this_ptr, "beforevalidation", data, entity); if (PHALCON_IS_FALSE(status)) { RETURN_CTOR(status); } } - + not_failed = PHALCON_GLOBAL(z_true); - + PHALCON_INIT_VAR(messages); array_init(messages); - + phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(element); - + PHALCON_CALL_METHOD(&validators, element, "getvalidators"); - if (Z_TYPE_P(validators) == IS_ARRAY) { + if (Z_TYPE_P(validators) == IS_ARRAY) { if (phalcon_fast_count_ev(validators TSRMLS_CC)) { - + PHALCON_CALL_METHOD(&name, element, "getname"); - + PHALCON_INIT_NVAR(prepared_validators); array_init(prepared_validators); - + phalcon_is_iterable(validators, &ah1, &hp1, 0, 0); - + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - + PHALCON_GET_HVALUE(validator); - + PHALCON_INIT_NVAR(scope); array_init_size(scope, 2); phalcon_array_append(&scope, name, 0); phalcon_array_append(&scope, validator, 0); phalcon_array_append(&prepared_validators, scope, PH_SEPARATE); - + zend_hash_move_forward_ex(ah1, &hp1); } - + PHALCON_INIT_NVAR(validation); object_init_ex(validation, phalcon_validation_ce); PHALCON_CALL_METHOD(NULL, validation, "__construct", prepared_validators); - + PHALCON_CALL_METHOD(&filters, element, "getfilters"); - - if (Z_TYPE_P(filters) == IS_ARRAY) { + + if (Z_TYPE_P(filters) == IS_ARRAY) { PHALCON_CALL_METHOD(&name, element, "getname"); PHALCON_CALL_METHOD(NULL, validation, "setfilters", name, filters); } - + PHALCON_CALL_METHOD(&element_messages, validation, "validate", data, entity); if (phalcon_fast_count_ev(element_messages TSRMLS_CC)) { PHALCON_CALL_METHOD(&name, element, "getname"); phalcon_array_update_zval(&messages, name, element_messages, PH_COPY | PH_SEPARATE); - + not_failed = PHALCON_GLOBAL(z_false); } } } - + zend_hash_move_forward_ex(ah0, &hp0); } - + if (!zend_is_true(not_failed)) { phalcon_update_property_this_quick(this_ptr, SL("_messages"), messages, 8245993366866550812UL TSRMLS_CC); } - + if (phalcon_method_quick_exists_ex(this_ptr, SS("aftervalidation"), 14165027582542365026UL TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, "aftervalidation", messages); } - - + + RETURN_NCTOR(not_failed); } @@ -49137,10 +49173,10 @@ static PHP_METHOD(Phalcon_Forms_Form, getMessages){ zval **by_item_name = NULL, *messages; phalcon_fetch_params_ex(0, 1, &by_item_name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); if (by_item_name && zend_is_true(*by_item_name)) { - if (Z_TYPE_P(messages) != IS_ARRAY) { + if (Z_TYPE_P(messages) != IS_ARRAY) { object_init_ex(return_value, phalcon_validation_message_group_ce); phalcon_validation_group_construct_helper(return_value, NULL TSRMLS_CC); } @@ -49172,12 +49208,12 @@ static PHP_METHOD(Phalcon_Forms_Form, getMessagesFor){ zval **name, *messages, *element_messages; phalcon_fetch_params_ex(1, 0, &name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_fetch(&element_messages, messages, *name)) { RETURN_ZVAL(element_messages, 1, 0); } - + object_init_ex(return_value, phalcon_validation_message_group_ce); phalcon_validation_group_construct_helper(return_value, NULL TSRMLS_CC); } @@ -49187,7 +49223,7 @@ static PHP_METHOD(Phalcon_Forms_Form, hasMessagesFor){ zval **name, *messages; phalcon_fetch_params_ex(1, 0, &name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); RETURN_BOOL(phalcon_array_isset(messages, *name)); } @@ -49201,11 +49237,11 @@ static PHP_METHOD(Phalcon_Forms_Form, add){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &element, &pos, &type); - + PHALCON_VERIFY_INTERFACE_EX(element, phalcon_forms_elementinterface_ce, phalcon_forms_exception_ce, 1); - + PHALCON_CALL_METHOD(&name, element, "getname"); - + PHALCON_CALL_METHOD(NULL, element, "setform", this_ptr); if (!pos || Z_TYPE_P(pos) == IS_NULL) { @@ -49267,7 +49303,7 @@ static PHP_METHOD(Phalcon_Forms_Form, add){ phalcon_update_property_this_quick(this_ptr, SL("_elements"), elements, 8245982395616353377UL TSRMLS_CC); } - + RETURN_THIS(); } @@ -49276,12 +49312,12 @@ static PHP_METHOD(Phalcon_Forms_Form, render){ zval **name, **attributes = NULL, *elements, *element; phalcon_fetch_params_ex(1, 1, &name, &attributes); - + PHALCON_ENSURE_IS_STRING(name); if (!attributes) { attributes = &PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); @@ -49296,14 +49332,14 @@ static PHP_METHOD(Phalcon_Forms_Form, get){ zval **name, *elements, *element; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { PHALCON_ENSURE_IS_STRING(name); zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + RETURN_ZVAL(element, 1, 0); } @@ -49323,7 +49359,7 @@ static PHP_METHOD(Phalcon_Forms_Form, label){ zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + PHALCON_RETURN_CALL_METHODW(element, "label", *attributes); } @@ -49332,22 +49368,22 @@ static PHP_METHOD(Phalcon_Forms_Form, getLabel){ zval **name, *elements, *element, *label = NULL; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { PHALCON_ENSURE_IS_STRING(name); zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + PHALCON_MM_GROW(); PHALCON_CALL_METHOD(&label, element, "getlabel"); - + /* Use the element's name as label if the label is not available */ if (!zend_is_true(label)) { RETURN_CTOR(*name); } - + RETURN_CTOR(label); } @@ -49358,7 +49394,7 @@ static PHP_METHOD(Phalcon_Forms_Form, getValue){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &name); - + entity = phalcon_fetch_nproperty_this(this_ptr, SL("_entity"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(entity) == IS_OBJECT) { PHALCON_INIT_VAR(method); @@ -49368,22 +49404,22 @@ static PHP_METHOD(Phalcon_Forms_Form, getValue){ PHALCON_RETURN_CALL_METHOD(entity, Z_STRVAL_P(method)); RETURN_MM(); } - + if (phalcon_isset_property_zval(entity, name TSRMLS_CC)) { PHALCON_OBS_VAR(value); phalcon_read_property_zval(&value, entity, name, PH_NOISY TSRMLS_CC); RETURN_CTOR(value); } } - + data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(data) == IS_ARRAY) { - + if (Z_TYPE_P(data) == IS_ARRAY) { + if (phalcon_array_isset_fetch(&value, data, name)) { RETURN_CTOR(value); } } - + RETURN_MM_NULL(); } @@ -49392,7 +49428,7 @@ static PHP_METHOD(Phalcon_Forms_Form, has){ zval **name, *elements; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); RETURN_BOOL(phalcon_array_isset(elements, *name)); } @@ -49402,9 +49438,9 @@ static PHP_METHOD(Phalcon_Forms_Form, remove){ zval *name, *elements; phalcon_fetch_params(0, 1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - + if (phalcon_array_isset(elements, name)) { phalcon_unset_property_array(this_ptr, SL("_elements"), name TSRMLS_CC); @@ -49427,21 +49463,21 @@ static PHP_METHOD(Phalcon_Forms_Form, clear){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &fields); - + if (!fields) { fields = PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) == IS_ARRAY) { - + if (Z_TYPE_P(elements) == IS_ARRAY) { + phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(element); - - if (Z_TYPE_P(fields) != IS_ARRAY) { + + if (Z_TYPE_P(fields) != IS_ARRAY) { PHALCON_CALL_METHOD(NULL, element, "clear"); } else { PHALCON_CALL_METHOD(&name, element, "getname"); @@ -49449,12 +49485,12 @@ static PHP_METHOD(Phalcon_Forms_Form, clear){ PHALCON_CALL_METHOD(NULL, element, "clear"); } } - + zend_hash_move_forward_ex(ah0, &hp0); } - + } - + RETURN_THIS(); } @@ -53648,7 +53684,7 @@ static PHP_METHOD(Phalcon_Http_Request_File, __set_state) { static PHP_METHOD(Phalcon_Http_Request_File, getExtension){ - RETURN_MEMBER(this_ptr, "_extension "); + RETURN_MEMBER_QUICK(this_ptr, "_extension", 13863019529612010721UL); } @@ -60564,7 +60600,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, __construct){ zval *service_name; phalcon_fetch_params_ex(0, 2, &dependency_injector, &collection_manager); - + PHALCON_MM_GROW(); if (!dependency_injector || Z_TYPE_PP(dependency_injector) != IS_OBJECT) { @@ -60575,13 +60611,13 @@ static PHP_METHOD(Phalcon_Mvc_Collection, __construct){ } PHALCON_VERIFY_INTERFACE_EX(di, phalcon_diinterface_ce, phalcon_mvc_collection_exception_ce, 1); - + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), di, 9934233281666745441UL TSRMLS_CC); - + if (!collection_manager || Z_TYPE_PP(collection_manager) != IS_OBJECT) { PHALCON_ALLOC_GHOST_ZVAL(service_name); ZVAL_STRING(service_name, "collectionManager", 1); - + PHALCON_CALL_METHOD(&mm, di, "getshared", service_name); if (Z_TYPE_P(mm) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The injected service 'collectionManager' is not valid"); @@ -60591,17 +60627,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, __construct){ else { mm = *collection_manager; } - + PHALCON_VERIFY_INTERFACE_EX(mm, phalcon_mvc_collection_managerinterface_ce, phalcon_mvc_collection_exception_ce, 1); phalcon_update_property_this_quick(this_ptr, SL("_collectionManager"), mm, 10636589431528675211UL TSRMLS_CC); - + PHALCON_CALL_METHOD(NULL, mm, "initialize", this_ptr); - + if (phalcon_method_quick_exists_ex(this_ptr, SS("onconstruct"), 15579263340111934695UL TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, "onconstruct"); } - + PHALCON_MM_RESTORE(); } @@ -60614,10 +60650,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setId){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &id); - + if (Z_TYPE_P(id) != IS_OBJECT) { collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); if (zend_is_true(use_implicit_ids)) { ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -60665,10 +60701,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setEventsManager){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &events_manager); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "setcustomeventsmanager", this_ptr, events_manager); - + PHALCON_MM_RESTORE(); } @@ -60693,7 +60729,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, getReservedAttributes){ reserved = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_reserved") TSRMLS_CC); if (Z_TYPE_P(reserved) == IS_NULL) { zval *dummy = PHALCON_GLOBAL(z_true); - + array_init_size(return_value, 5); Z_ADDREF_P(dummy); add_assoc_zval_ex(return_value, SS("_connection"), dummy); Z_ADDREF_P(dummy); add_assoc_zval_ex(return_value, SS("_dependencyInjector"), dummy); @@ -60715,10 +60751,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, useImplicitObjectIds){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &use_implicit_object_ids); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "useimplicitobjectids", this_ptr, use_implicit_object_ids); - + PHALCON_MM_RESTORE(); } @@ -60727,7 +60763,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setSource){ zval *source; phalcon_fetch_params(0, 1, 0, &source); - + phalcon_update_property_this_quick(this_ptr, SL("_source"), source, 7572086532643413UL TSRMLS_CC); RETURN_THISW(); } @@ -60743,12 +60779,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, getSource){ if (!zend_is_true(source)) { PHALCON_INIT_VAR(class_name); phalcon_get_class_ns(class_name, this_ptr, 0 TSRMLS_CC); - + PHALCON_INIT_NVAR(source); phalcon_uncamelize(source, class_name); phalcon_update_property_this_quick(this_ptr, SL("_source"), source, 7572086532643413UL TSRMLS_CC); } - + RETURN_CTOR(source); } @@ -60759,7 +60795,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setConnectionService){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &connection_service); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "setconnectionservice", this_ptr, connection_service); RETURN_THIS(); @@ -60783,11 +60819,11 @@ static PHP_METHOD(Phalcon_Mvc_Collection, getConnection){ phalcon_read_property_this(&connection, this_ptr, SL("_connection"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(connection) != IS_OBJECT) { collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&connection, collection_manager, "getconnection", this_ptr); phalcon_update_property_this_quick(this_ptr, SL("_connection"), connection, 14754297779714702100UL TSRMLS_CC); } - + RETURN_CTOR(connection); } @@ -60798,7 +60834,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, readAttribute){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &attribute); - + if (phalcon_isset_property_zval(this_ptr, attribute TSRMLS_CC)) { PHALCON_OBS_VAR(attribute_value); phalcon_read_property_zval(&attribute_value, this_ptr, attribute, PH_NOISY TSRMLS_CC); @@ -60812,9 +60848,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, writeAttribute){ zval *attribute, *value; phalcon_fetch_params(0, 2, 0, &attribute, &value); - + phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - + } static PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ @@ -60828,33 +60864,33 @@ static PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &collection, &document); - + if (Z_TYPE_P(collection) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid collection"); return; } - if (Z_TYPE_P(document) != IS_ARRAY) { + if (Z_TYPE_P(document) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid document"); return; } - + PHALCON_INIT_VAR(cloned_collection); if (phalcon_clone(cloned_collection, collection TSRMLS_CC) == FAILURE) { RETURN_MM(); } - + phalcon_is_iterable(document, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + PHALCON_CALL_METHOD(NULL, cloned_collection, "writeattribute", key, value); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(cloned_collection); } @@ -60872,15 +60908,19 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 4, 0, ¶ms, &collection, &connection, &unique); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&mongo_collection, connection, "selectcollection", source); - + if (Z_TYPE_P(mongo_collection) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Couldn't select mongo collection"); + return; + } + if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(conditions); phalcon_array_fetch_long(&conditions, params, 0, PH_NOISY); @@ -60893,71 +60933,76 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ array_init(conditions); } } - + + if (Z_TYPE_P(conditions) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Find parameters must be an array"); + return; + } + PHALCON_INIT_VAR(documents_cursor); if (phalcon_array_isset_quick_string(params, SS("fields"), 229465804380252UL)) { PHALCON_OBS_VAR(fields); phalcon_array_fetch_quick_string(&fields, params, SS("fields"), 229465804380252UL, PH_NOISY); - + PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions, fields); } else { PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions); } - + if (phalcon_array_isset_quick_string(params, SS("limit"), 6953744320644UL)) { PHALCON_OBS_VAR(limit); phalcon_array_fetch_quick_string(&limit, params, SS("limit"), 6953744320644UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "limit", limit); } - + if (phalcon_array_isset_quick_string(params, SS("sort"), 210728047629UL)) { PHALCON_OBS_VAR(sort); phalcon_array_fetch_quick_string(&sort, params, SS("sort"), 210728047629UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "sort", sort); } - + if (phalcon_array_isset_quick_string(params, SS("skip"), 210727893948UL)) { PHALCON_OBS_NVAR(sort); phalcon_array_fetch_quick_string(&sort, params, SS("skip"), 210727893948UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "skip", sort); } - + if (phalcon_array_isset_quick_string(params, SS("fields"), 229465804380252UL)) { PHALCON_INIT_VAR(base); object_init_ex(base, phalcon_mvc_collection_document_ce); } else { PHALCON_CPY_WRT(base, collection); } - + if (PHALCON_IS_TRUE(unique)) { - + PHALCON_CALL_METHOD(NULL, documents_cursor, "rewind"); PHALCON_CALL_METHOD(&document, documents_cursor, "current"); - if (Z_TYPE_P(document) == IS_ARRAY) { + if (Z_TYPE_P(document) == IS_ARRAY) { PHALCON_RETURN_CALL_SELF("cloneresult", base, document); RETURN_MM(); } - + RETURN_MM_FALSE; } - + PHALCON_INIT_VAR(collections); array_init(collections); - + PHALCON_CALL_FUNCTION(&documents_array, "iterator_to_array", documents_cursor); - + phalcon_is_iterable(documents_array, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(document); - + PHALCON_CALL_SELF(&collection_cloned, "cloneresult", base, document); phalcon_array_append(&collections, collection_cloned, PH_SEPARATE); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(collections); } @@ -60970,15 +61015,15 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, ¶ms, &collection, &connection); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&mongo_collection, connection, "selectcollection", source); - + if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(conditions); phalcon_array_fetch_long(&conditions, params, 0, PH_NOISY); @@ -60991,7 +61036,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ array_init(conditions); } } - + PHALCON_INIT_VAR(simple); ZVAL_BOOL(simple, 1); if (phalcon_array_isset_quick_string(params, SS("limit"), 6953744320644UL)) { @@ -61007,33 +61052,33 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ } } } - + if (PHALCON_IS_FALSE(simple)) { - + PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions); - + if (phalcon_array_isset_quick_string(params, SS("limit"), 6953744320644UL)) { PHALCON_OBS_VAR(limit); phalcon_array_fetch_quick_string(&limit, params, SS("limit"), 6953744320644UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "limit", limit); } - + if (phalcon_array_isset_quick_string(params, SS("sort"), 210728047629UL)) { PHALCON_OBS_VAR(sort); phalcon_array_fetch_quick_string(&sort, params, SS("sort"), 210728047629UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "sort", sort); } - + if (phalcon_array_isset_quick_string(params, SS("skip"), 210727893948UL)) { PHALCON_OBS_NVAR(sort); phalcon_array_fetch_quick_string(&sort, params, SS("skip"), 210727893948UL, PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "skip", sort); } - + phalcon_fast_count(return_value, documents_cursor TSRMLS_CC); RETURN_MM(); } - + PHALCON_RETURN_CALL_METHOD(mongo_collection, "count", conditions); RETURN_MM(); } @@ -61046,17 +61091,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &dependency_injector, &disable_events, &exists); - + if (!zend_is_true(disable_events)) { - + PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "beforeValidation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + if (!zend_is_true(exists)) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeValidationOnCreate", 1); @@ -61064,16 +61109,16 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeValidationOnUpdate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "validation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { if (!zend_is_true(disable_events)) { @@ -61083,9 +61128,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ } RETURN_MM_FALSE; } - + if (!zend_is_true(disable_events)) { - + if (!zend_is_true(exists)) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterValidationOnCreate", 1); @@ -61093,28 +61138,28 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterValidationOnUpdate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterValidation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeSave", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + if (zend_is_true(exists)) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeUpdate", 1); @@ -61122,13 +61167,13 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeCreate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - + RETURN_MM_TRUE; } @@ -61139,7 +61184,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &disable_events, &success, &exists); - + if (PHALCON_IS_TRUE(success)) { if (!zend_is_true(disable_events)) { if (PHALCON_IS_TRUE(exists)) { @@ -61150,12 +61195,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ ZVAL_STRING(event_name, "afterCreate", 1); } PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterSave", 1); PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } - + RETURN_CTOR(success); } if (!zend_is_true(disable_events)) { @@ -61163,7 +61208,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ ZVAL_STRING(event_name, "notSave", 1); PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } - + PHALCON_CALL_METHOD(NULL, this_ptr, "_canceloperation", disable_events); RETURN_MM_FALSE; } @@ -61178,29 +61223,29 @@ static PHP_METHOD(Phalcon_Mvc_Collection, validate){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &validator); - + if (Z_TYPE_P(validator) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Validator must be an Object"); return; } - + PHALCON_CALL_METHOD(&status, validator, "validate", this_ptr); if (PHALCON_IS_FALSE(status)) { PHALCON_CALL_METHOD(&messages, validator, "getmessages"); - + phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(message); - + phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + } - + PHALCON_MM_RESTORE(); } @@ -61212,12 +61257,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, validationHasFailed){ PHALCON_OBS_VAR(error_messages); phalcon_read_property_this(&error_messages, this_ptr, SL("_errorMessages"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(error_messages) == IS_ARRAY) { + if (Z_TYPE_P(error_messages) == IS_ARRAY) { if (phalcon_fast_count_ev(error_messages TSRMLS_CC)) { RETURN_MM_TRUE; } } - + RETURN_MM_FALSE; } @@ -61240,7 +61285,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, fireEvent){ if (phalcon_method_exists_ex(this_ptr, Z_STRVAL_P(lower), Z_STRLEN_P(lower)+1 TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, Z_STRVAL_P(lower)); } - + PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_RETURN_CALL_METHOD(collection_manager, "notifyevent", *event_name, this_ptr); @@ -61271,12 +61316,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, fireEventCancel){ PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&status, collection_manager, "notifyevent", *event_name, this_ptr); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + RETURN_MM_TRUE; } @@ -61287,9 +61332,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &disable_events); - + if (!zend_is_true(disable_events)) { - + PHALCON_OBS_VAR(operation_made); phalcon_read_property_this(&operation_made, this_ptr, SL("_operationMade"), PH_NOISY TSRMLS_CC); if (PHALCON_IS_LONG(operation_made, 3)) { @@ -61299,7 +61344,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "notSaved", 1); } - + PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } RETURN_MM_FALSE; @@ -61315,9 +61360,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &collection); - + if (phalcon_isset_property(this_ptr, SS("_id") TSRMLS_CC)) { - + PHALCON_OBS_VAR(id); phalcon_read_property_this(&id, this_ptr, SL("_id"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(id) == IS_OBJECT) { @@ -61325,7 +61370,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ } else { PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); if (zend_is_true(use_implicit_ids)) { ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -61339,16 +61384,16 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ PHALCON_CPY_WRT(mongo_id, id); } } - + PHALCON_INIT_VAR(parameters); array_init_size(parameters, 1); phalcon_array_update_string(¶meters, SL("_id"), mongo_id, PH_COPY); - + PHALCON_CALL_METHOD(&document_count, collection, "count", parameters); - + z_zero = PHALCON_GLOBAL(z_zero); is_smaller_function(return_value, z_zero, document_count TSRMLS_CC); - + RETURN_MM(); } RETURN_MM_FALSE; @@ -61367,17 +61412,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, appendMessage){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &message); - + if (Z_TYPE_P(message) != IS_OBJECT) { PHALCON_CALL_FUNCTION(&type, "gettype", message); - + PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Invalid message format '", type, "'"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_collection_exception_ce, exception_message); return; } phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - + PHALCON_MM_RESTORE(); } @@ -61407,11 +61452,11 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ if (!arr) { arr = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } - + if (!mode) { mode = PHALCON_GLOBAL(z_null); } @@ -61421,17 +61466,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - + if (Z_TYPE_P(mode) == IS_NULL) { PHALCON_SEPARATE_PARAM(mode); PHALCON_CALL_METHOD(&exists, this_ptr, "_exists", collection); PHALCON_INIT_NVAR(mode); - + ZVAL_BOOL(mode, (PHALCON_IS_FALSE(exists) ? 1 : 0)); phalcon_update_property_long(this_ptr, SL("_operationMade"), (PHALCON_IS_FALSE(exists) ? 1 : 2) TSRMLS_CC); } else { @@ -61440,19 +61485,19 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ phalcon_update_property_long(this_ptr, SL("_operationMade"), (PHALCON_IS_FALSE(exists) ? 1 : 2) TSRMLS_CC); } - + PHALCON_INIT_VAR(empty_array); array_init(empty_array); - + phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), empty_array, 15042582850236692358UL TSRMLS_CC); - + disable_events = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_disableEvents") TSRMLS_CC); - + PHALCON_CALL_METHOD(&status, this_ptr, "_presave", dependency_injector, disable_events, exists); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + PHALCON_CALL_METHOD(&reserved, this_ptr, "getreservedattributes"); PHALCON_CALL_FUNCTION(&properties, "get_object_vars", this_ptr); @@ -61472,7 +61517,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ if (Z_TYPE_P(white_list) != IS_ARRAY || phalcon_fast_in_array(&key, white_list TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch(&value, arr, &key, PH_NOISY); - + Z_ADDREF_P(value); if (likely(Z_TYPE(key) == IS_STRING)) { add_assoc_zval_ex(data, Z_STRVAL(key), Z_STRLEN(key)+1, value); @@ -61497,7 +61542,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ else { array_init(data); } - + PHALCON_INIT_NVAR(status); if (PHALCON_IS_FALSE(mode)){ @@ -61534,7 +61579,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ } zval_ptr_dtor(&data); - + PHALCON_RETURN_CALL_METHOD(this_ptr, "_postsave", disable_events, success, exists); RETURN_MM(); } @@ -61549,21 +61594,21 @@ static PHP_METHOD(Phalcon_Mvc_Collection, findById){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &id); - + if (Z_TYPE_P(id) != IS_OBJECT) { - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&collection_manager, collection, "getcollectionmanager"); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", collection); if (zend_is_true(use_implicit_ids)) { ce1 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -61578,11 +61623,11 @@ static PHP_METHOD(Phalcon_Mvc_Collection, findById){ } else { PHALCON_CPY_WRT(mongo_id, id); } - + PHALCON_INIT_VAR(conditions); array_init_size(conditions, 1); phalcon_array_update_string(&conditions, SL("_id"), mongo_id, PH_COPY); - + PHALCON_INIT_VAR(parameters); array_init_size(parameters, 1); phalcon_array_append(¶meters, conditions, 0); @@ -61599,28 +61644,28 @@ static PHP_METHOD(Phalcon_Mvc_Collection, findFirst){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for findFirst"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); unique = PHALCON_GLOBAL(z_true); @@ -61637,30 +61682,30 @@ static PHP_METHOD(Phalcon_Mvc_Collection, find){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for find"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + unique = PHALCON_GLOBAL(z_false); PHALCON_RETURN_CALL_SELF("_getresultset", parameters, collection, connection, unique); RETURN_MM(); @@ -61674,28 +61719,28 @@ static PHP_METHOD(Phalcon_Mvc_Collection, count){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for count"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); PHALCON_RETURN_CALL_SELF("_getgroupresultset", parameters, collection, connection); RETURN_MM(); @@ -61710,32 +61755,32 @@ static PHP_METHOD(Phalcon_Mvc_Collection, aggregate){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, ¶meters); - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for aggregate"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); PHALCON_RETURN_CALL_METHOD(collection, "aggregate", parameters); RETURN_MM(); @@ -61752,60 +61797,60 @@ static PHP_METHOD(Phalcon_Mvc_Collection, summatory){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &field, &conditions, &finalize); - + if (!conditions) { conditions = PHALCON_GLOBAL(z_null); } - + if (!finalize) { finalize = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(field) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid field name for group"); return; } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - + PHALCON_INIT_VAR(keys); array_init(keys); - + PHALCON_INIT_VAR(empty_array); array_init(empty_array); - + PHALCON_INIT_VAR(initial); array_init_size(initial, 1); phalcon_array_update_string(&initial, SL("summatory"), empty_array, PH_COPY); - + PHALCON_INIT_VAR(reduce); PHALCON_CONCAT_SVSVSVS(reduce, "function (curr, result) { if (typeof result.summatory[curr.", field, "] === \"undefined\") { result.summatory[curr.", field, "] = 1; } else { result.summatory[curr.", field, "]++; } }"); PHALCON_CALL_METHOD(&group, collection, "group", keys, initial, reduce); if (phalcon_array_isset_quick_string(group, SS("retval"), 229481163598995UL)) { - + PHALCON_OBS_VAR(retval); phalcon_array_fetch_quick_string(&retval, group, SS("retval"), 229481163598995UL, PH_NOISY); if (phalcon_array_isset_long(retval, 0)) { - + PHALCON_OBS_VAR(first_retval); phalcon_array_fetch_long(&first_retval, retval, 0, PH_NOISY); if (phalcon_array_isset_quick_string(first_retval, SS("summatory"), 8246933180340669078UL)) { @@ -61813,13 +61858,13 @@ static PHP_METHOD(Phalcon_Mvc_Collection, summatory){ phalcon_array_fetch_quick_string(&summatory, first_retval, SS("summatory"), 8246933180340669078UL, PH_NOISY); RETURN_CTOR(summatory); } - + RETURN_CTOR(first_retval); } - + RETURN_CTOR(retval); } - + PHALCON_MM_RESTORE(); } @@ -61834,7 +61879,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, create){ if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } @@ -61856,7 +61901,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, update){ if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } @@ -61866,24 +61911,24 @@ static PHP_METHOD(Phalcon_Mvc_Collection, update){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - + PHALCON_CALL_METHOD(&exists, this_ptr, "_exists", collection); - if (!zend_is_true(exists)) { + if (!zend_is_true(exists)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "InvalidUpdateAttempt", 1); - + PHALCON_INIT_VAR(message); ZVAL_STRING(message, "Document cannot be updated because it does not exist", 1); - + PHALCON_INIT_VAR(collection_message); object_init_ex(collection_message, phalcon_mvc_collection_message_ce); PHALCON_CALL_METHOD(NULL, collection_message, "__construct", message, PHALCON_GLOBAL(z_null), type); - + PHALCON_INIT_VAR(messages); array_init_size(messages, 1); phalcon_array_append(&messages, collection_message, PH_SEPARATE); @@ -61909,37 +61954,37 @@ static PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The document cannot be deleted because it doesn't exist"); return; } - + disable_events = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_disableEvents") TSRMLS_CC); if (!zend_is_true(disable_events)) { - + PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "beforeDelete", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - + PHALCON_OBS_VAR(id); phalcon_read_property_this(&id, this_ptr, SL("_id"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - + PHALCON_CALL_METHOD(&source, this_ptr, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); if (Z_TYPE_P(id) == IS_OBJECT || Z_TYPE_P(id) == IS_NULL) { PHALCON_CPY_WRT(mongo_id, id); } else { PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); if (zend_is_true(use_implicit_ids)) { ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -61952,29 +61997,29 @@ static PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_CPY_WRT(mongo_id, id); } } - + PHALCON_INIT_VAR(id_condition); array_init_size(id_condition, 1); phalcon_array_update_string(&id_condition, SL("_id"), mongo_id, PH_COPY); - + PHALCON_INIT_VAR(success); ZVAL_BOOL(success, 0); - + PHALCON_INIT_VAR(options); array_init_size(options, 1); add_assoc_long_ex(options, SS("w"), 1); - + PHALCON_CALL_METHOD(&status, collection, "remove", id_condition, options); - if (Z_TYPE_P(status) != IS_ARRAY) { + if (Z_TYPE_P(status) != IS_ARRAY) { RETURN_MM_FALSE; } - + if (phalcon_array_isset_quick_string(status, SS("ok"), 193501407UL)) { - + PHALCON_OBS_VAR(ok); phalcon_array_fetch_quick_string(&ok, status, SS("ok"), 193501407UL, PH_NOISY); if (zend_is_true(ok)) { - + ZVAL_BOOL(success, 1); if (!zend_is_true(disable_events)) { PHALCON_INIT_NVAR(event_name); @@ -61986,7 +62031,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_INIT_NVAR(success); ZVAL_BOOL(success, 0); } - + RETURN_NCTOR(success); } @@ -62001,20 +62046,20 @@ static PHP_METHOD(Phalcon_Mvc_Collection, toArray){ PHALCON_INIT_VAR(data); array_init(data); - + PHALCON_CALL_METHOD(&reserved, this_ptr, "getreservedattributes"); - + PHALCON_CALL_FUNCTION(&properties, "get_object_vars", this_ptr); - + phalcon_is_iterable(properties, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + if (PHALCON_IS_STRING(key, "_id")) { - + if (Z_TYPE_P(value) != IS_NULL) { phalcon_array_update_zval(&data, key, value, PH_COPY); } @@ -62023,10 +62068,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, toArray){ phalcon_array_update_zval(&data, key, value, PH_COPY); } } - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(data); } @@ -62037,7 +62082,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, serialize){ PHALCON_MM_GROW(); PHALCON_CALL_METHOD(&data, this_ptr, "toarray"); - + phalcon_serialize(return_value, &data TSRMLS_CC); RETURN_MM(); } @@ -62053,25 +62098,25 @@ static PHP_METHOD(Phalcon_Mvc_Collection, unserialize){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &data); - + if (Z_TYPE_P(data) == IS_STRING) { - + PHALCON_INIT_VAR(attributes); phalcon_unserialize(attributes, data TSRMLS_CC); - if (Z_TYPE_P(attributes) == IS_ARRAY) { - + if (Z_TYPE_P(attributes) == IS_ARRAY) { + PHALCON_CALL_CE_STATIC(&dependency_injector, phalcon_di_ce, "getdefault"); - + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A dependency injector container is required to obtain the services related to the ODM"); return; } - + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 9934233281666745441UL TSRMLS_CC); - + PHALCON_INIT_VAR(service); ZVAL_STRING(service, "collectionManager", 1); - + PHALCON_CALL_METHOD(&manager, dependency_injector, "getshared", service); if (Z_TYPE_P(manager) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The injected service 'collectionManager' is not valid"); @@ -62079,21 +62124,21 @@ static PHP_METHOD(Phalcon_Mvc_Collection, unserialize){ } PHALCON_VERIFY_INTERFACE(manager, phalcon_mvc_collection_managerinterface_ce); - + phalcon_update_property_this_quick(this_ptr, SL("_collectionManager"), manager, 10636589431528675211UL TSRMLS_CC); - + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_MM_NULL(); } } @@ -62109,22 +62154,22 @@ static PHP_METHOD(Phalcon_Mvc_Collection, execute){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &code, &args); - - if (args && Z_TYPE_P(args) != IS_ARRAY) { + + if (args && Z_TYPE_P(args) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid args for execute"); return; } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); if (args) { @@ -68178,13 +68223,6 @@ static PHP_METHOD(Phalcon_Mvc_Model, toArray){ PHALCON_GET_HVALUE(attribute); - if (columns && Z_TYPE_P(columns) == IS_ARRAY) { - if (!phalcon_fast_in_array(attribute, columns TSRMLS_CC)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - if (Z_TYPE_P(column_map) == IS_ARRAY) { if (!phalcon_array_isset(column_map, attribute)) { PHALCON_INIT_NVAR(exception_message); @@ -68198,6 +68236,14 @@ static PHP_METHOD(Phalcon_Mvc_Model, toArray){ } else { PHALCON_CPY_WRT(attribute_field, attribute); } + + if (columns && Z_TYPE_P(columns) == IS_ARRAY) { + if (!phalcon_fast_in_array(attribute_field, columns TSRMLS_CC) && !phalcon_fast_in_array(attribute, columns TSRMLS_CC)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } + if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY TSRMLS_CC); @@ -97085,7 +97131,7 @@ static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall){ phalcon_read_property_this(&array_helpers, this_ptr, SL("_arrayHelpers"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(array_helpers) != IS_ARRAY) { PHALCON_INIT_NVAR(array_helpers); - array_init_size(array_helpers, 16); + array_init_size(array_helpers, 17); add_assoc_bool_ex(array_helpers, SS("link_to"), 1); add_assoc_bool_ex(array_helpers, SS("image"), 1); add_assoc_bool_ex(array_helpers, SS("form"), 1); @@ -97102,6 +97148,7 @@ static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall){ add_assoc_bool_ex(array_helpers, SS("date_field"), 1); add_assoc_bool_ex(array_helpers, SS("numeric_field"), 1); add_assoc_bool_ex(array_helpers, SS("email_field"), 1); + add_assoc_bool_ex(array_helpers, SS("image_input"), 1); phalcon_update_property_this_quick(this_ptr, SL("_arrayHelpers"), array_helpers, 15584335196500505430UL TSRMLS_CC); } @@ -105661,8 +105708,8 @@ static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate){ PHALCON_CALL_METHOD(&models, builder, "getfrom"); if (Z_TYPE_P(models) == IS_ARRAY) { - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); + PHALCON_INIT_VAR(model_name); + phalcon_array_get_current(model_name, models); } else { PHALCON_CPY_WRT(model_name, models); } diff --git a/build/64bits/php_phalcon.h b/build/64bits/php_phalcon.h index ee2dcbe1d55..0deb4ad5733 100644 --- a/build/64bits/php_phalcon.h +++ b/build/64bits/php_phalcon.h @@ -29,7 +29,7 @@ #include #endif -#define PHP_PHALCON_VERSION "1.3.3" +#define PHP_PHALCON_VERSION "1.3.4" #define PHP_PHALCON_EXTNAME "phalcon" #define PHALCON_NUM_PREALLOCATED_FRAMES 25 diff --git a/build/safe/phalcon.c b/build/safe/phalcon.c index 6dc88860322..19afdba1994 100644 --- a/build/safe/phalcon.c +++ b/build/safe/phalcon.c @@ -1210,17 +1210,25 @@ static int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt } #define PHALCON_VERIFY_INTERFACE_EX(instance, interface_ce, exception_ce, restore_stack) \ - if (Z_TYPE_P(instance) != IS_OBJECT || !instanceof_function_ex(Z_OBJCE_P(instance), interface_ce, 1 TSRMLS_CC)) { \ - if (Z_TYPE_P(instance) != IS_OBJECT) { \ - zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ - } \ - else { \ - zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, object of type %s given", interface_ce->name, Z_OBJCE_P(instance)->name); \ - } \ + if (Z_TYPE_P(instance) != IS_OBJECT) { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ if (restore_stack) { \ PHALCON_MM_RESTORE(); \ } \ return; \ + } else { \ + if (!instanceof_function_ex(Z_OBJCE_P(instance), interface_ce, 1 TSRMLS_CC)) { \ + if (Z_TYPE_P(instance) != IS_OBJECT) { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ + } \ + else { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, object of type %s given", interface_ce->name, Z_OBJCE_P(instance)->name); \ + } \ + if (restore_stack) { \ + PHALCON_MM_RESTORE(); \ + } \ + return; \ + } \ } #define PHALCON_VERIFY_INTERFACE_OR_NULL_EX(pzv, interface_ce, exception_ce, restore_stack) \ @@ -9736,6 +9744,8 @@ static void phalcon_concat_self(zval **left, zval *right TSRMLS_DC){ } } + SEPARATE_ZVAL_IF_NOT_REF(left); + length = Z_STRLEN_PP(left) + Z_STRLEN_P(right); Z_STRVAL_PP(left) = str_erealloc(Z_STRVAL_PP(left), length + 1); @@ -9777,6 +9787,8 @@ static void phalcon_concat_self_str(zval **left, const char *right, int right_le } } + SEPARATE_ZVAL_IF_NOT_REF(left); + length = Z_STRLEN_PP(left) + right_length; Z_STRVAL_PP(left) = str_erealloc(Z_STRVAL_PP(left), length + 1); @@ -15230,7 +15242,7 @@ static const zend_function_entry phalcon_debug_method_entry[] = { PHP_ME(Phalcon_Debug, getJsSources, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, showTraceItem, NULL, ZEND_ACC_PROTECTED) PHP_ME(Phalcon_Debug, onUncaughtException, arginfo_phalcon_debug_onuncaughtexception, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Debug, getCharset, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Debug, getCharset, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_ME(Phalcon_Debug, setCharset, arginfo_phalcon_debug_setcharset, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, getLinesBeforeContext, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, setLinesBeforeContext, arginfo_phalcon_debug_setlines, ZEND_ACC_PUBLIC) @@ -15388,7 +15400,7 @@ static PHP_METHOD(Phalcon_Debug, _escapeString){ zval line_break; zval escaped_line_break; - charset = phalcon_fetch_nproperty_this(getThis(), SL("_charset"), PH_NOISY TSRMLS_CC); + charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); INIT_ZVAL(line_break); ZVAL_STRING(&line_break, "\n", 0); @@ -15847,7 +15859,7 @@ static PHP_METHOD(Phalcon_Debug, showTraceItem){ PHALCON_INIT_VAR(comment_pattern); ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1); - charset = phalcon_fetch_nproperty_this(getThis(), SL("_charset"), PH_NOISY TSRMLS_CC); + charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); PHALCON_INIT_VAR(tab); ZVAL_STRING(tab, "\t", 1); @@ -16120,7 +16132,8 @@ static PHP_METHOD(Phalcon_Debug, onUncaughtException){ } static PHP_METHOD(Phalcon_Debug, getCharset) { - RETURN_MEMBER(getThis(), "_charset"); + zval *charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); + RETURN_ZVAL(charset, 1, 0); } static PHP_METHOD(Phalcon_Debug, setCharset) { @@ -16130,7 +16143,7 @@ static PHP_METHOD(Phalcon_Debug, setCharset) { phalcon_fetch_params_ex(1, 0, &charset); PHALCON_ENSURE_IS_STRING(charset); - phalcon_update_property_this(getThis(), SL("_charset"), *charset TSRMLS_CC); + phalcon_update_static_property_ce(phalcon_debug_ce, SL("_charset"), *charset TSRMLS_CC); RETURN_THISW(); } @@ -21755,15 +21768,36 @@ static PHP_METHOD(Phalcon_Tag, setDefault){ static PHP_METHOD(Phalcon_Tag, setDefaults){ - zval *values; + zval *values, *merge = NULL, *display_values, *merged_values = NULL;; + + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &values); + phalcon_fetch_params(1, 1, 1, &values, &merge); + + if (!merge) { + merge = PHALCON_GLOBAL(z_false); + } if (Z_TYPE_P(values) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_tag_exception_ce, "An array is required as default values"); return; } - phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + + if (zend_is_true(merge)) { + + display_values = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_displayValues") TSRMLS_CC); + if (Z_TYPE_P(display_values) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_values); + phalcon_fast_array_merge(merged_values, &display_values, &values TSRMLS_CC); + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), merged_values TSRMLS_CC); + } else { + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + } + } else { + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); } @@ -23637,7 +23671,7 @@ static PHP_METHOD(Phalcon_Version, _getVersion){ array_init_size(return_value, 5); add_next_index_long(return_value, 1); add_next_index_long(return_value, 3); - add_next_index_long(return_value, 3); + add_next_index_long(return_value, 4); add_next_index_long(return_value, PHALCON_VERSION_STABLE); add_next_index_long(return_value, 1); } @@ -29407,52 +29441,50 @@ static PHP_METHOD(Phalcon_Assets_Manager, output){ PHALCON_CALL_METHOD(&local, resource, "getlocal"); if (Z_TYPE_P(filters) == IS_ARRAY) { - if (zend_is_true(join)) { - if (zend_is_true(local)) { - - PHALCON_CALL_METHOD(&source_path, resource, "getrealsourcepath", complete_source_path); - - if (!zend_is_true(source_path)) { - PHALCON_CALL_METHOD(&source_path, resource, "getpath"); - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid source path"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } - } else { + if (zend_is_true(local)) { + + PHALCON_CALL_METHOD(&source_path, resource, "getrealsourcepath", complete_source_path); + + if (!zend_is_true(source_path)) { PHALCON_CALL_METHOD(&source_path, resource, "getpath"); - - PHALCON_INIT_NVAR(filter_needed); - ZVAL_TRUE(filter_needed); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid source path"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; } - - PHALCON_CALL_METHOD(&target_path, resource, "getrealtargetpath", complete_target_path); - - if (PHALCON_IS_EMPTY(target_path)) { + } else { + PHALCON_CALL_METHOD(&source_path, resource, "getpath"); + + PHALCON_INIT_NVAR(filter_needed); + ZVAL_TRUE(filter_needed); + } + + PHALCON_CALL_METHOD(&target_path, resource, "getrealtargetpath", complete_target_path); + + if (PHALCON_IS_EMPTY(target_path)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; + } + + if (zend_is_true(local)) { + + if (PHALCON_IS_EQUAL(target_path, source_path)) { PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path"); + PHALCON_CONCAT_SVS(exception_message, "Resource '", target_path, "' have the same source and target paths"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); return; } - - if (zend_is_true(local)) { - - if (PHALCON_IS_EQUAL(target_path, source_path)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", target_path, "' have the same source and target paths"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } - if (phalcon_file_exists(target_path TSRMLS_CC) == SUCCESS) { - if (phalcon_compare_mtime(target_path, source_path TSRMLS_CC)) { - PHALCON_INIT_NVAR(filter_needed); - ZVAL_TRUE(filter_needed); - } - } else { + if (phalcon_file_exists(target_path TSRMLS_CC) == SUCCESS) { + if (phalcon_compare_mtime(target_path, source_path TSRMLS_CC)) { PHALCON_INIT_NVAR(filter_needed); ZVAL_TRUE(filter_needed); } + } else { + PHALCON_INIT_NVAR(filter_needed); + ZVAL_TRUE(filter_needed); } } } @@ -48808,15 +48840,15 @@ static PHP_METHOD(Phalcon_Forms_Form, __construct){ Z_OBJ_HT_P(getThis()) = &phalcon_forms_form_object_handlers; phalcon_fetch_params(0, 0, 2, &entity, &user_options); - + if (!entity) { entity = PHALCON_GLOBAL(z_null); } - + if (!user_options) { user_options = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(entity) != IS_NULL) { if (Z_TYPE_P(entity) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The base entity is not valid"); @@ -48825,11 +48857,11 @@ static PHP_METHOD(Phalcon_Forms_Form, __construct){ phalcon_update_property_this(this_ptr, SL("_entity"), entity TSRMLS_CC); } - - if (Z_TYPE_P(user_options) == IS_ARRAY) { + + if (Z_TYPE_P(user_options) == IS_ARRAY) { phalcon_update_property_this(this_ptr, SL("_options"), user_options TSRMLS_CC); } - + if (phalcon_method_exists_ex(this_ptr, SS("initialize") TSRMLS_CC) == SUCCESS) { PHALCON_MM_GROW(); PHALCON_CALL_METHOD(NULL, this_ptr, "initialize", entity, user_options); @@ -48842,7 +48874,7 @@ static PHP_METHOD(Phalcon_Forms_Form, setAction){ zval *action; phalcon_fetch_params(0, 1, 0, &action); - + phalcon_update_property_this(this_ptr, SL("_action"), action TSRMLS_CC); RETURN_THISW(); } @@ -48858,7 +48890,7 @@ static PHP_METHOD(Phalcon_Forms_Form, setUserOption){ zval *option, *value; phalcon_fetch_params(0, 2, 0, &option, &value); - + phalcon_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC); RETURN_THISW(); } @@ -48868,16 +48900,16 @@ static PHP_METHOD(Phalcon_Forms_Form, getUserOption){ zval *option, *default_value = NULL, *options, *value; phalcon_fetch_params(0, 1, 1, &option, &default_value); - + if (!default_value) { default_value = PHALCON_GLOBAL(z_null); } - + options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_fetch(&value, options, option)) { RETURN_ZVAL(value, 1, 0); } - + RETURN_ZVAL(default_value, 1, 0); } @@ -48886,13 +48918,13 @@ static PHP_METHOD(Phalcon_Forms_Form, setUserOptions){ zval *options; phalcon_fetch_params(0, 1, 0, &options); - - if (Z_TYPE_P(options) != IS_ARRAY) { + + if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "Parameter 'options' must be an array"); return; } phalcon_update_property_this(this_ptr, SL("_options"), options TSRMLS_CC); - + RETURN_THISW(); } @@ -48907,7 +48939,7 @@ static PHP_METHOD(Phalcon_Forms_Form, setEntity){ zval *entity; phalcon_fetch_params(0, 1, 0, &entity); - + if (Z_TYPE_P(entity) != IS_NULL && Z_TYPE_P(entity) != IS_OBJECT) { zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "'%s' must be an object or NULL", "entity"); return; @@ -48942,80 +48974,84 @@ static PHP_METHOD(Phalcon_Forms_Form, bind){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &data, &entity, &whitelist); - + if (!whitelist) { whitelist = PHALCON_GLOBAL(z_null); } - - if (Z_TYPE_P(data) != IS_ARRAY) { + + if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The data must be an array"); return; } - + PHALCON_OBS_VAR(elements); phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) != IS_ARRAY) { + if (Z_TYPE_P(elements) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "There are no elements in the form"); return; } - + PHALCON_INIT_VAR(filter); - + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + if (!phalcon_array_isset(elements, key)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } - - if (Z_TYPE_P(whitelist) == IS_ARRAY) { + + if (Z_TYPE_P(whitelist) == IS_ARRAY) { if (!phalcon_fast_in_array(key, whitelist TSRMLS_CC)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } } - + PHALCON_OBS_NVAR(element); phalcon_array_fetch(&element, elements, key, PH_NOISY); - + PHALCON_CALL_METHOD(&filters, element, "getfilters"); if (zend_is_true(filters)) { + if (Z_TYPE_P(filter) != IS_OBJECT) { + PHALCON_INIT_NVAR(service_name); PHALCON_ZVAL_MAYBE_INTERNED_STRING(service_name, phalcon_interned_filter); - + PHALCON_CALL_METHOD(&dependency_injector, this_ptr, "getdi"); + PHALCON_VERIFY_INTERFACE(dependency_injector, phalcon_diinterface_ce); + PHALCON_CALL_METHOD(&filter, dependency_injector, "getshared", service_name); PHALCON_VERIFY_INTERFACE(filter, phalcon_filterinterface_ce); } - + PHALCON_CALL_METHOD(&filtered_value, filter, "sanitize", value, filters); } else { PHALCON_CPY_WRT(filtered_value, value); } - + PHALCON_INIT_NVAR(method); PHALCON_CONCAT_SV(method, "set", key); zend_str_tolower(Z_STRVAL_P(method), Z_STRLEN_P(method)); - + if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, entity, Z_STRVAL_P(method), filtered_value); zend_hash_move_forward_ex(ah0, &hp0); continue; } - + phalcon_update_property_zval_zval(entity, key, filtered_value TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + phalcon_update_property_this(this_ptr, SL("_data"), data TSRMLS_CC); - + PHALCON_MM_RESTORE(); } @@ -49032,103 +49068,103 @@ static PHP_METHOD(Phalcon_Forms_Form, isValid){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &data, &entity); - + if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!entity) { entity = PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) != IS_ARRAY) { + if (Z_TYPE_P(elements) != IS_ARRAY) { RETURN_MM_TRUE; } - + if (Z_TYPE_P(entity) == IS_OBJECT) { PHALCON_CALL_METHOD(NULL, this_ptr, "bind", data, entity); } - - if (Z_TYPE_P(data) != IS_ARRAY) { + + if (Z_TYPE_P(data) != IS_ARRAY) { data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY TSRMLS_CC); } - + if (phalcon_method_exists_ex(this_ptr, SS("beforevalidation") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(&status, this_ptr, "beforevalidation", data, entity); if (PHALCON_IS_FALSE(status)) { RETURN_CTOR(status); } } - + not_failed = PHALCON_GLOBAL(z_true); - + PHALCON_INIT_VAR(messages); array_init(messages); - + phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(element); - + PHALCON_CALL_METHOD(&validators, element, "getvalidators"); - if (Z_TYPE_P(validators) == IS_ARRAY) { + if (Z_TYPE_P(validators) == IS_ARRAY) { if (phalcon_fast_count_ev(validators TSRMLS_CC)) { - + PHALCON_CALL_METHOD(&name, element, "getname"); - + PHALCON_INIT_NVAR(prepared_validators); array_init(prepared_validators); - + phalcon_is_iterable(validators, &ah1, &hp1, 0, 0); - + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - + PHALCON_GET_HVALUE(validator); - + PHALCON_INIT_NVAR(scope); array_init_size(scope, 2); phalcon_array_append(&scope, name, 0); phalcon_array_append(&scope, validator, 0); phalcon_array_append(&prepared_validators, scope, PH_SEPARATE); - + zend_hash_move_forward_ex(ah1, &hp1); } - + PHALCON_INIT_NVAR(validation); object_init_ex(validation, phalcon_validation_ce); PHALCON_CALL_METHOD(NULL, validation, "__construct", prepared_validators); - + PHALCON_CALL_METHOD(&filters, element, "getfilters"); - - if (Z_TYPE_P(filters) == IS_ARRAY) { + + if (Z_TYPE_P(filters) == IS_ARRAY) { PHALCON_CALL_METHOD(&name, element, "getname"); PHALCON_CALL_METHOD(NULL, validation, "setfilters", name, filters); } - + PHALCON_CALL_METHOD(&element_messages, validation, "validate", data, entity); if (phalcon_fast_count_ev(element_messages TSRMLS_CC)) { PHALCON_CALL_METHOD(&name, element, "getname"); phalcon_array_update_zval(&messages, name, element_messages, PH_COPY | PH_SEPARATE); - + not_failed = PHALCON_GLOBAL(z_false); } } } - + zend_hash_move_forward_ex(ah0, &hp0); } - + if (!zend_is_true(not_failed)) { phalcon_update_property_this(this_ptr, SL("_messages"), messages TSRMLS_CC); } - + if (phalcon_method_exists_ex(this_ptr, SS("aftervalidation") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, "aftervalidation", messages); } - - + + RETURN_NCTOR(not_failed); } @@ -49137,10 +49173,10 @@ static PHP_METHOD(Phalcon_Forms_Form, getMessages){ zval **by_item_name = NULL, *messages; phalcon_fetch_params_ex(0, 1, &by_item_name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); if (by_item_name && zend_is_true(*by_item_name)) { - if (Z_TYPE_P(messages) != IS_ARRAY) { + if (Z_TYPE_P(messages) != IS_ARRAY) { object_init_ex(return_value, phalcon_validation_message_group_ce); phalcon_validation_group_construct_helper(return_value, NULL TSRMLS_CC); } @@ -49172,12 +49208,12 @@ static PHP_METHOD(Phalcon_Forms_Form, getMessagesFor){ zval **name, *messages, *element_messages; phalcon_fetch_params_ex(1, 0, &name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_fetch(&element_messages, messages, *name)) { RETURN_ZVAL(element_messages, 1, 0); } - + object_init_ex(return_value, phalcon_validation_message_group_ce); phalcon_validation_group_construct_helper(return_value, NULL TSRMLS_CC); } @@ -49187,7 +49223,7 @@ static PHP_METHOD(Phalcon_Forms_Form, hasMessagesFor){ zval **name, *messages; phalcon_fetch_params_ex(1, 0, &name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); RETURN_BOOL(phalcon_array_isset(messages, *name)); } @@ -49201,11 +49237,11 @@ static PHP_METHOD(Phalcon_Forms_Form, add){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &element, &pos, &type); - + PHALCON_VERIFY_INTERFACE_EX(element, phalcon_forms_elementinterface_ce, phalcon_forms_exception_ce, 1); - + PHALCON_CALL_METHOD(&name, element, "getname"); - + PHALCON_CALL_METHOD(NULL, element, "setform", this_ptr); if (!pos || Z_TYPE_P(pos) == IS_NULL) { @@ -49267,7 +49303,7 @@ static PHP_METHOD(Phalcon_Forms_Form, add){ phalcon_update_property_this(this_ptr, SL("_elements"), elements TSRMLS_CC); } - + RETURN_THIS(); } @@ -49276,12 +49312,12 @@ static PHP_METHOD(Phalcon_Forms_Form, render){ zval **name, **attributes = NULL, *elements, *element; phalcon_fetch_params_ex(1, 1, &name, &attributes); - + PHALCON_ENSURE_IS_STRING(name); if (!attributes) { attributes = &PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); @@ -49296,14 +49332,14 @@ static PHP_METHOD(Phalcon_Forms_Form, get){ zval **name, *elements, *element; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { PHALCON_ENSURE_IS_STRING(name); zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + RETURN_ZVAL(element, 1, 0); } @@ -49323,7 +49359,7 @@ static PHP_METHOD(Phalcon_Forms_Form, label){ zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + PHALCON_RETURN_CALL_METHODW(element, "label", *attributes); } @@ -49332,22 +49368,22 @@ static PHP_METHOD(Phalcon_Forms_Form, getLabel){ zval **name, *elements, *element, *label = NULL; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { PHALCON_ENSURE_IS_STRING(name); zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + PHALCON_MM_GROW(); PHALCON_CALL_METHOD(&label, element, "getlabel"); - + /* Use the element's name as label if the label is not available */ if (!zend_is_true(label)) { RETURN_CTOR(*name); } - + RETURN_CTOR(label); } @@ -49358,7 +49394,7 @@ static PHP_METHOD(Phalcon_Forms_Form, getValue){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &name); - + entity = phalcon_fetch_nproperty_this(this_ptr, SL("_entity"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(entity) == IS_OBJECT) { PHALCON_INIT_VAR(method); @@ -49368,22 +49404,22 @@ static PHP_METHOD(Phalcon_Forms_Form, getValue){ PHALCON_RETURN_CALL_METHOD(entity, Z_STRVAL_P(method)); RETURN_MM(); } - + if (phalcon_isset_property_zval(entity, name TSRMLS_CC)) { PHALCON_OBS_VAR(value); phalcon_read_property_zval(&value, entity, name, PH_NOISY TSRMLS_CC); RETURN_CTOR(value); } } - + data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(data) == IS_ARRAY) { - + if (Z_TYPE_P(data) == IS_ARRAY) { + if (phalcon_array_isset_fetch(&value, data, name)) { RETURN_CTOR(value); } } - + RETURN_MM_NULL(); } @@ -49392,7 +49428,7 @@ static PHP_METHOD(Phalcon_Forms_Form, has){ zval **name, *elements; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); RETURN_BOOL(phalcon_array_isset(elements, *name)); } @@ -49402,9 +49438,9 @@ static PHP_METHOD(Phalcon_Forms_Form, remove){ zval *name, *elements; phalcon_fetch_params(0, 1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - + if (phalcon_array_isset(elements, name)) { phalcon_unset_property_array(this_ptr, SL("_elements"), name TSRMLS_CC); @@ -49427,21 +49463,21 @@ static PHP_METHOD(Phalcon_Forms_Form, clear){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &fields); - + if (!fields) { fields = PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) == IS_ARRAY) { - + if (Z_TYPE_P(elements) == IS_ARRAY) { + phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(element); - - if (Z_TYPE_P(fields) != IS_ARRAY) { + + if (Z_TYPE_P(fields) != IS_ARRAY) { PHALCON_CALL_METHOD(NULL, element, "clear"); } else { PHALCON_CALL_METHOD(&name, element, "getname"); @@ -49449,12 +49485,12 @@ static PHP_METHOD(Phalcon_Forms_Form, clear){ PHALCON_CALL_METHOD(NULL, element, "clear"); } } - + zend_hash_move_forward_ex(ah0, &hp0); } - + } - + RETURN_THIS(); } @@ -53648,7 +53684,7 @@ static PHP_METHOD(Phalcon_Http_Request_File, __set_state) { static PHP_METHOD(Phalcon_Http_Request_File, getExtension){ - RETURN_MEMBER(this_ptr, "_extension "); + RETURN_MEMBER(this_ptr, "_extension"); } @@ -60564,7 +60600,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, __construct){ zval *service_name; phalcon_fetch_params_ex(0, 2, &dependency_injector, &collection_manager); - + PHALCON_MM_GROW(); if (!dependency_injector || Z_TYPE_PP(dependency_injector) != IS_OBJECT) { @@ -60575,13 +60611,13 @@ static PHP_METHOD(Phalcon_Mvc_Collection, __construct){ } PHALCON_VERIFY_INTERFACE_EX(di, phalcon_diinterface_ce, phalcon_mvc_collection_exception_ce, 1); - + phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), di TSRMLS_CC); - + if (!collection_manager || Z_TYPE_PP(collection_manager) != IS_OBJECT) { PHALCON_ALLOC_GHOST_ZVAL(service_name); ZVAL_STRING(service_name, "collectionManager", 1); - + PHALCON_CALL_METHOD(&mm, di, "getshared", service_name); if (Z_TYPE_P(mm) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The injected service 'collectionManager' is not valid"); @@ -60591,17 +60627,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, __construct){ else { mm = *collection_manager; } - + PHALCON_VERIFY_INTERFACE_EX(mm, phalcon_mvc_collection_managerinterface_ce, phalcon_mvc_collection_exception_ce, 1); phalcon_update_property_this(this_ptr, SL("_collectionManager"), mm TSRMLS_CC); - + PHALCON_CALL_METHOD(NULL, mm, "initialize", this_ptr); - + if (phalcon_method_exists_ex(this_ptr, SS("onconstruct") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, "onconstruct"); } - + PHALCON_MM_RESTORE(); } @@ -60614,10 +60650,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setId){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &id); - + if (Z_TYPE_P(id) != IS_OBJECT) { collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); if (zend_is_true(use_implicit_ids)) { ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -60665,10 +60701,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setEventsManager){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &events_manager); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "setcustomeventsmanager", this_ptr, events_manager); - + PHALCON_MM_RESTORE(); } @@ -60693,7 +60729,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, getReservedAttributes){ reserved = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_reserved") TSRMLS_CC); if (Z_TYPE_P(reserved) == IS_NULL) { zval *dummy = PHALCON_GLOBAL(z_true); - + array_init_size(return_value, 5); Z_ADDREF_P(dummy); add_assoc_zval_ex(return_value, SS("_connection"), dummy); Z_ADDREF_P(dummy); add_assoc_zval_ex(return_value, SS("_dependencyInjector"), dummy); @@ -60715,10 +60751,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, useImplicitObjectIds){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &use_implicit_object_ids); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "useimplicitobjectids", this_ptr, use_implicit_object_ids); - + PHALCON_MM_RESTORE(); } @@ -60727,7 +60763,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setSource){ zval *source; phalcon_fetch_params(0, 1, 0, &source); - + phalcon_update_property_this(this_ptr, SL("_source"), source TSRMLS_CC); RETURN_THISW(); } @@ -60743,12 +60779,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, getSource){ if (!zend_is_true(source)) { PHALCON_INIT_VAR(class_name); phalcon_get_class_ns(class_name, this_ptr, 0 TSRMLS_CC); - + PHALCON_INIT_NVAR(source); phalcon_uncamelize(source, class_name); phalcon_update_property_this(this_ptr, SL("_source"), source TSRMLS_CC); } - + RETURN_CTOR(source); } @@ -60759,7 +60795,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, setConnectionService){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &connection_service); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "setconnectionservice", this_ptr, connection_service); RETURN_THIS(); @@ -60783,11 +60819,11 @@ static PHP_METHOD(Phalcon_Mvc_Collection, getConnection){ phalcon_read_property_this(&connection, this_ptr, SL("_connection"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(connection) != IS_OBJECT) { collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&connection, collection_manager, "getconnection", this_ptr); phalcon_update_property_this(this_ptr, SL("_connection"), connection TSRMLS_CC); } - + RETURN_CTOR(connection); } @@ -60798,7 +60834,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, readAttribute){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &attribute); - + if (phalcon_isset_property_zval(this_ptr, attribute TSRMLS_CC)) { PHALCON_OBS_VAR(attribute_value); phalcon_read_property_zval(&attribute_value, this_ptr, attribute, PH_NOISY TSRMLS_CC); @@ -60812,9 +60848,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, writeAttribute){ zval *attribute, *value; phalcon_fetch_params(0, 2, 0, &attribute, &value); - + phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - + } static PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ @@ -60828,33 +60864,33 @@ static PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &collection, &document); - + if (Z_TYPE_P(collection) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid collection"); return; } - if (Z_TYPE_P(document) != IS_ARRAY) { + if (Z_TYPE_P(document) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid document"); return; } - + PHALCON_INIT_VAR(cloned_collection); if (phalcon_clone(cloned_collection, collection TSRMLS_CC) == FAILURE) { RETURN_MM(); } - + phalcon_is_iterable(document, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + PHALCON_CALL_METHOD(NULL, cloned_collection, "writeattribute", key, value); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(cloned_collection); } @@ -60872,15 +60908,19 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 4, 0, ¶ms, &collection, &connection, &unique); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&mongo_collection, connection, "selectcollection", source); - + if (Z_TYPE_P(mongo_collection) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Couldn't select mongo collection"); + return; + } + if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(conditions); phalcon_array_fetch_long(&conditions, params, 0, PH_NOISY); @@ -60893,71 +60933,76 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ array_init(conditions); } } - + + if (Z_TYPE_P(conditions) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Find parameters must be an array"); + return; + } + PHALCON_INIT_VAR(documents_cursor); if (phalcon_array_isset_string(params, SS("fields"))) { PHALCON_OBS_VAR(fields); phalcon_array_fetch_string(&fields, params, SL("fields"), PH_NOISY); - + PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions, fields); } else { PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions); } - + if (phalcon_array_isset_string(params, SS("limit"))) { PHALCON_OBS_VAR(limit); phalcon_array_fetch_string(&limit, params, SL("limit"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "limit", limit); } - + if (phalcon_array_isset_string(params, SS("sort"))) { PHALCON_OBS_VAR(sort); phalcon_array_fetch_string(&sort, params, SL("sort"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "sort", sort); } - + if (phalcon_array_isset_string(params, SS("skip"))) { PHALCON_OBS_NVAR(sort); phalcon_array_fetch_string(&sort, params, SL("skip"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "skip", sort); } - + if (phalcon_array_isset_string(params, SS("fields"))) { PHALCON_INIT_VAR(base); object_init_ex(base, phalcon_mvc_collection_document_ce); } else { PHALCON_CPY_WRT(base, collection); } - + if (PHALCON_IS_TRUE(unique)) { - + PHALCON_CALL_METHOD(NULL, documents_cursor, "rewind"); PHALCON_CALL_METHOD(&document, documents_cursor, "current"); - if (Z_TYPE_P(document) == IS_ARRAY) { + if (Z_TYPE_P(document) == IS_ARRAY) { PHALCON_RETURN_CALL_SELF("cloneresult", base, document); RETURN_MM(); } - + RETURN_MM_FALSE; } - + PHALCON_INIT_VAR(collections); array_init(collections); - + PHALCON_CALL_FUNCTION(&documents_array, "iterator_to_array", documents_cursor); - + phalcon_is_iterable(documents_array, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(document); - + PHALCON_CALL_SELF(&collection_cloned, "cloneresult", base, document); phalcon_array_append(&collections, collection_cloned, PH_SEPARATE); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(collections); } @@ -60970,15 +61015,15 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, ¶ms, &collection, &connection); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&mongo_collection, connection, "selectcollection", source); - + if (phalcon_array_isset_long(params, 0)) { PHALCON_OBS_VAR(conditions); phalcon_array_fetch_long(&conditions, params, 0, PH_NOISY); @@ -60991,7 +61036,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ array_init(conditions); } } - + PHALCON_INIT_VAR(simple); ZVAL_BOOL(simple, 1); if (phalcon_array_isset_string(params, SS("limit"))) { @@ -61007,33 +61052,33 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ } } } - + if (PHALCON_IS_FALSE(simple)) { - + PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions); - + if (phalcon_array_isset_string(params, SS("limit"))) { PHALCON_OBS_VAR(limit); phalcon_array_fetch_string(&limit, params, SL("limit"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "limit", limit); } - + if (phalcon_array_isset_string(params, SS("sort"))) { PHALCON_OBS_VAR(sort); phalcon_array_fetch_string(&sort, params, SL("sort"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "sort", sort); } - + if (phalcon_array_isset_string(params, SS("skip"))) { PHALCON_OBS_NVAR(sort); phalcon_array_fetch_string(&sort, params, SL("skip"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "skip", sort); } - + phalcon_fast_count(return_value, documents_cursor TSRMLS_CC); RETURN_MM(); } - + PHALCON_RETURN_CALL_METHOD(mongo_collection, "count", conditions); RETURN_MM(); } @@ -61046,17 +61091,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &dependency_injector, &disable_events, &exists); - + if (!zend_is_true(disable_events)) { - + PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "beforeValidation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + if (!zend_is_true(exists)) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeValidationOnCreate", 1); @@ -61064,16 +61109,16 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeValidationOnUpdate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "validation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { if (!zend_is_true(disable_events)) { @@ -61083,9 +61128,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ } RETURN_MM_FALSE; } - + if (!zend_is_true(disable_events)) { - + if (!zend_is_true(exists)) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterValidationOnCreate", 1); @@ -61093,28 +61138,28 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterValidationOnUpdate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterValidation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeSave", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + if (zend_is_true(exists)) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeUpdate", 1); @@ -61122,13 +61167,13 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeCreate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - + RETURN_MM_TRUE; } @@ -61139,7 +61184,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &disable_events, &success, &exists); - + if (PHALCON_IS_TRUE(success)) { if (!zend_is_true(disable_events)) { if (PHALCON_IS_TRUE(exists)) { @@ -61150,12 +61195,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ ZVAL_STRING(event_name, "afterCreate", 1); } PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterSave", 1); PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } - + RETURN_CTOR(success); } if (!zend_is_true(disable_events)) { @@ -61163,7 +61208,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ ZVAL_STRING(event_name, "notSave", 1); PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } - + PHALCON_CALL_METHOD(NULL, this_ptr, "_canceloperation", disable_events); RETURN_MM_FALSE; } @@ -61178,29 +61223,29 @@ static PHP_METHOD(Phalcon_Mvc_Collection, validate){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &validator); - + if (Z_TYPE_P(validator) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Validator must be an Object"); return; } - + PHALCON_CALL_METHOD(&status, validator, "validate", this_ptr); if (PHALCON_IS_FALSE(status)) { PHALCON_CALL_METHOD(&messages, validator, "getmessages"); - + phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(message); - + phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + } - + PHALCON_MM_RESTORE(); } @@ -61212,12 +61257,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, validationHasFailed){ PHALCON_OBS_VAR(error_messages); phalcon_read_property_this(&error_messages, this_ptr, SL("_errorMessages"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(error_messages) == IS_ARRAY) { + if (Z_TYPE_P(error_messages) == IS_ARRAY) { if (phalcon_fast_count_ev(error_messages TSRMLS_CC)) { RETURN_MM_TRUE; } } - + RETURN_MM_FALSE; } @@ -61240,7 +61285,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, fireEvent){ if (phalcon_method_exists_ex(this_ptr, Z_STRVAL_P(lower), Z_STRLEN_P(lower)+1 TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, Z_STRVAL_P(lower)); } - + PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_RETURN_CALL_METHOD(collection_manager, "notifyevent", *event_name, this_ptr); @@ -61271,12 +61316,12 @@ static PHP_METHOD(Phalcon_Mvc_Collection, fireEventCancel){ PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&status, collection_manager, "notifyevent", *event_name, this_ptr); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + RETURN_MM_TRUE; } @@ -61287,9 +61332,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &disable_events); - + if (!zend_is_true(disable_events)) { - + PHALCON_OBS_VAR(operation_made); phalcon_read_property_this(&operation_made, this_ptr, SL("_operationMade"), PH_NOISY TSRMLS_CC); if (PHALCON_IS_LONG(operation_made, 3)) { @@ -61299,7 +61344,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "notSaved", 1); } - + PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } RETURN_MM_FALSE; @@ -61315,9 +61360,9 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &collection); - + if (phalcon_isset_property(this_ptr, SS("_id") TSRMLS_CC)) { - + PHALCON_OBS_VAR(id); phalcon_read_property_this(&id, this_ptr, SL("_id"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(id) == IS_OBJECT) { @@ -61325,7 +61370,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ } else { PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); if (zend_is_true(use_implicit_ids)) { ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -61339,16 +61384,16 @@ static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ PHALCON_CPY_WRT(mongo_id, id); } } - + PHALCON_INIT_VAR(parameters); array_init_size(parameters, 1); phalcon_array_update_string(¶meters, SL("_id"), mongo_id, PH_COPY); - + PHALCON_CALL_METHOD(&document_count, collection, "count", parameters); - + z_zero = PHALCON_GLOBAL(z_zero); is_smaller_function(return_value, z_zero, document_count TSRMLS_CC); - + RETURN_MM(); } RETURN_MM_FALSE; @@ -61367,17 +61412,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, appendMessage){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &message); - + if (Z_TYPE_P(message) != IS_OBJECT) { PHALCON_CALL_FUNCTION(&type, "gettype", message); - + PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Invalid message format '", type, "'"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_collection_exception_ce, exception_message); return; } phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - + PHALCON_MM_RESTORE(); } @@ -61407,11 +61452,11 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ if (!arr) { arr = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } - + if (!mode) { mode = PHALCON_GLOBAL(z_null); } @@ -61421,17 +61466,17 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - + if (Z_TYPE_P(mode) == IS_NULL) { PHALCON_SEPARATE_PARAM(mode); PHALCON_CALL_METHOD(&exists, this_ptr, "_exists", collection); PHALCON_INIT_NVAR(mode); - + ZVAL_BOOL(mode, (PHALCON_IS_FALSE(exists) ? 1 : 0)); phalcon_update_property_long(this_ptr, SL("_operationMade"), (PHALCON_IS_FALSE(exists) ? 1 : 2) TSRMLS_CC); } else { @@ -61440,19 +61485,19 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ phalcon_update_property_long(this_ptr, SL("_operationMade"), (PHALCON_IS_FALSE(exists) ? 1 : 2) TSRMLS_CC); } - + PHALCON_INIT_VAR(empty_array); array_init(empty_array); - + phalcon_update_property_this(this_ptr, SL("_errorMessages"), empty_array TSRMLS_CC); - + disable_events = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_disableEvents") TSRMLS_CC); - + PHALCON_CALL_METHOD(&status, this_ptr, "_presave", dependency_injector, disable_events, exists); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + PHALCON_CALL_METHOD(&reserved, this_ptr, "getreservedattributes"); PHALCON_CALL_FUNCTION(&properties, "get_object_vars", this_ptr); @@ -61472,7 +61517,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ if (Z_TYPE_P(white_list) != IS_ARRAY || phalcon_fast_in_array(&key, white_list TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch(&value, arr, &key, PH_NOISY); - + Z_ADDREF_P(value); if (likely(Z_TYPE(key) == IS_STRING)) { add_assoc_zval_ex(data, Z_STRVAL(key), Z_STRLEN(key)+1, value); @@ -61497,7 +61542,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ else { array_init(data); } - + PHALCON_INIT_NVAR(status); if (PHALCON_IS_FALSE(mode)){ @@ -61534,7 +61579,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, save){ } zval_ptr_dtor(&data); - + PHALCON_RETURN_CALL_METHOD(this_ptr, "_postsave", disable_events, success, exists); RETURN_MM(); } @@ -61549,21 +61594,21 @@ static PHP_METHOD(Phalcon_Mvc_Collection, findById){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &id); - + if (Z_TYPE_P(id) != IS_OBJECT) { - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&collection_manager, collection, "getcollectionmanager"); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", collection); if (zend_is_true(use_implicit_ids)) { ce1 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -61578,11 +61623,11 @@ static PHP_METHOD(Phalcon_Mvc_Collection, findById){ } else { PHALCON_CPY_WRT(mongo_id, id); } - + PHALCON_INIT_VAR(conditions); array_init_size(conditions, 1); phalcon_array_update_string(&conditions, SL("_id"), mongo_id, PH_COPY); - + PHALCON_INIT_VAR(parameters); array_init_size(parameters, 1); phalcon_array_append(¶meters, conditions, 0); @@ -61599,28 +61644,28 @@ static PHP_METHOD(Phalcon_Mvc_Collection, findFirst){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for findFirst"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); unique = PHALCON_GLOBAL(z_true); @@ -61637,30 +61682,30 @@ static PHP_METHOD(Phalcon_Mvc_Collection, find){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for find"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + unique = PHALCON_GLOBAL(z_false); PHALCON_RETURN_CALL_SELF("_getresultset", parameters, collection, connection, unique); RETURN_MM(); @@ -61674,28 +61719,28 @@ static PHP_METHOD(Phalcon_Mvc_Collection, count){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for count"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); PHALCON_RETURN_CALL_SELF("_getgroupresultset", parameters, collection, connection); RETURN_MM(); @@ -61710,32 +61755,32 @@ static PHP_METHOD(Phalcon_Mvc_Collection, aggregate){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, ¶meters); - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for aggregate"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); PHALCON_RETURN_CALL_METHOD(collection, "aggregate", parameters); RETURN_MM(); @@ -61752,60 +61797,60 @@ static PHP_METHOD(Phalcon_Mvc_Collection, summatory){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &field, &conditions, &finalize); - + if (!conditions) { conditions = PHALCON_GLOBAL(z_null); } - + if (!finalize) { finalize = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(field) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid field name for group"); return; } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - + PHALCON_INIT_VAR(keys); array_init(keys); - + PHALCON_INIT_VAR(empty_array); array_init(empty_array); - + PHALCON_INIT_VAR(initial); array_init_size(initial, 1); phalcon_array_update_string(&initial, SL("summatory"), empty_array, PH_COPY); - + PHALCON_INIT_VAR(reduce); PHALCON_CONCAT_SVSVSVS(reduce, "function (curr, result) { if (typeof result.summatory[curr.", field, "] === \"undefined\") { result.summatory[curr.", field, "] = 1; } else { result.summatory[curr.", field, "]++; } }"); PHALCON_CALL_METHOD(&group, collection, "group", keys, initial, reduce); if (phalcon_array_isset_string(group, SS("retval"))) { - + PHALCON_OBS_VAR(retval); phalcon_array_fetch_string(&retval, group, SL("retval"), PH_NOISY); if (phalcon_array_isset_long(retval, 0)) { - + PHALCON_OBS_VAR(first_retval); phalcon_array_fetch_long(&first_retval, retval, 0, PH_NOISY); if (phalcon_array_isset_string(first_retval, SS("summatory"))) { @@ -61813,13 +61858,13 @@ static PHP_METHOD(Phalcon_Mvc_Collection, summatory){ phalcon_array_fetch_string(&summatory, first_retval, SL("summatory"), PH_NOISY); RETURN_CTOR(summatory); } - + RETURN_CTOR(first_retval); } - + RETURN_CTOR(retval); } - + PHALCON_MM_RESTORE(); } @@ -61834,7 +61879,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, create){ if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } @@ -61856,7 +61901,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, update){ if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } @@ -61866,24 +61911,24 @@ static PHP_METHOD(Phalcon_Mvc_Collection, update){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - + PHALCON_CALL_METHOD(&exists, this_ptr, "_exists", collection); - if (!zend_is_true(exists)) { + if (!zend_is_true(exists)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "InvalidUpdateAttempt", 1); - + PHALCON_INIT_VAR(message); ZVAL_STRING(message, "Document cannot be updated because it does not exist", 1); - + PHALCON_INIT_VAR(collection_message); object_init_ex(collection_message, phalcon_mvc_collection_message_ce); PHALCON_CALL_METHOD(NULL, collection_message, "__construct", message, PHALCON_GLOBAL(z_null), type); - + PHALCON_INIT_VAR(messages); array_init_size(messages, 1); phalcon_array_append(&messages, collection_message, PH_SEPARATE); @@ -61909,37 +61954,37 @@ static PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The document cannot be deleted because it doesn't exist"); return; } - + disable_events = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_disableEvents") TSRMLS_CC); if (!zend_is_true(disable_events)) { - + PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "beforeDelete", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - + PHALCON_OBS_VAR(id); phalcon_read_property_this(&id, this_ptr, SL("_id"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - + PHALCON_CALL_METHOD(&source, this_ptr, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); if (Z_TYPE_P(id) == IS_OBJECT || Z_TYPE_P(id) == IS_NULL) { PHALCON_CPY_WRT(mongo_id, id); } else { PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); if (zend_is_true(use_implicit_ids)) { ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); @@ -61952,29 +61997,29 @@ static PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_CPY_WRT(mongo_id, id); } } - + PHALCON_INIT_VAR(id_condition); array_init_size(id_condition, 1); phalcon_array_update_string(&id_condition, SL("_id"), mongo_id, PH_COPY); - + PHALCON_INIT_VAR(success); ZVAL_BOOL(success, 0); - + PHALCON_INIT_VAR(options); array_init_size(options, 1); add_assoc_long_ex(options, SS("w"), 1); - + PHALCON_CALL_METHOD(&status, collection, "remove", id_condition, options); - if (Z_TYPE_P(status) != IS_ARRAY) { + if (Z_TYPE_P(status) != IS_ARRAY) { RETURN_MM_FALSE; } - + if (phalcon_array_isset_string(status, SS("ok"))) { - + PHALCON_OBS_VAR(ok); phalcon_array_fetch_string(&ok, status, SL("ok"), PH_NOISY); if (zend_is_true(ok)) { - + ZVAL_BOOL(success, 1); if (!zend_is_true(disable_events)) { PHALCON_INIT_NVAR(event_name); @@ -61986,7 +62031,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_INIT_NVAR(success); ZVAL_BOOL(success, 0); } - + RETURN_NCTOR(success); } @@ -62001,20 +62046,20 @@ static PHP_METHOD(Phalcon_Mvc_Collection, toArray){ PHALCON_INIT_VAR(data); array_init(data); - + PHALCON_CALL_METHOD(&reserved, this_ptr, "getreservedattributes"); - + PHALCON_CALL_FUNCTION(&properties, "get_object_vars", this_ptr); - + phalcon_is_iterable(properties, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + if (PHALCON_IS_STRING(key, "_id")) { - + if (Z_TYPE_P(value) != IS_NULL) { phalcon_array_update_zval(&data, key, value, PH_COPY); } @@ -62023,10 +62068,10 @@ static PHP_METHOD(Phalcon_Mvc_Collection, toArray){ phalcon_array_update_zval(&data, key, value, PH_COPY); } } - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(data); } @@ -62037,7 +62082,7 @@ static PHP_METHOD(Phalcon_Mvc_Collection, serialize){ PHALCON_MM_GROW(); PHALCON_CALL_METHOD(&data, this_ptr, "toarray"); - + phalcon_serialize(return_value, &data TSRMLS_CC); RETURN_MM(); } @@ -62053,25 +62098,25 @@ static PHP_METHOD(Phalcon_Mvc_Collection, unserialize){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &data); - + if (Z_TYPE_P(data) == IS_STRING) { - + PHALCON_INIT_VAR(attributes); phalcon_unserialize(attributes, data TSRMLS_CC); - if (Z_TYPE_P(attributes) == IS_ARRAY) { - + if (Z_TYPE_P(attributes) == IS_ARRAY) { + PHALCON_CALL_CE_STATIC(&dependency_injector, phalcon_di_ce, "getdefault"); - + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A dependency injector container is required to obtain the services related to the ODM"); return; } - + phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - + PHALCON_INIT_VAR(service); ZVAL_STRING(service, "collectionManager", 1); - + PHALCON_CALL_METHOD(&manager, dependency_injector, "getshared", service); if (Z_TYPE_P(manager) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The injected service 'collectionManager' is not valid"); @@ -62079,21 +62124,21 @@ static PHP_METHOD(Phalcon_Mvc_Collection, unserialize){ } PHALCON_VERIFY_INTERFACE(manager, phalcon_mvc_collection_managerinterface_ce); - + phalcon_update_property_this(this_ptr, SL("_collectionManager"), manager TSRMLS_CC); - + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_MM_NULL(); } } @@ -62109,22 +62154,22 @@ static PHP_METHOD(Phalcon_Mvc_Collection, execute){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &code, &args); - - if (args && Z_TYPE_P(args) != IS_ARRAY) { + + if (args && Z_TYPE_P(args) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid args for execute"); return; } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); if (args) { @@ -68178,13 +68223,6 @@ static PHP_METHOD(Phalcon_Mvc_Model, toArray){ PHALCON_GET_HVALUE(attribute); - if (columns && Z_TYPE_P(columns) == IS_ARRAY) { - if (!phalcon_fast_in_array(attribute, columns TSRMLS_CC)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - if (Z_TYPE_P(column_map) == IS_ARRAY) { if (!phalcon_array_isset(column_map, attribute)) { PHALCON_INIT_NVAR(exception_message); @@ -68198,6 +68236,14 @@ static PHP_METHOD(Phalcon_Mvc_Model, toArray){ } else { PHALCON_CPY_WRT(attribute_field, attribute); } + + if (columns && Z_TYPE_P(columns) == IS_ARRAY) { + if (!phalcon_fast_in_array(attribute_field, columns TSRMLS_CC) && !phalcon_fast_in_array(attribute, columns TSRMLS_CC)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } + if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY TSRMLS_CC); @@ -97085,7 +97131,7 @@ static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall){ phalcon_read_property_this(&array_helpers, this_ptr, SL("_arrayHelpers"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(array_helpers) != IS_ARRAY) { PHALCON_INIT_NVAR(array_helpers); - array_init_size(array_helpers, 16); + array_init_size(array_helpers, 17); add_assoc_bool_ex(array_helpers, SS("link_to"), 1); add_assoc_bool_ex(array_helpers, SS("image"), 1); add_assoc_bool_ex(array_helpers, SS("form"), 1); @@ -97102,6 +97148,7 @@ static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall){ add_assoc_bool_ex(array_helpers, SS("date_field"), 1); add_assoc_bool_ex(array_helpers, SS("numeric_field"), 1); add_assoc_bool_ex(array_helpers, SS("email_field"), 1); + add_assoc_bool_ex(array_helpers, SS("image_input"), 1); phalcon_update_property_this(this_ptr, SL("_arrayHelpers"), array_helpers TSRMLS_CC); } @@ -105661,8 +105708,8 @@ static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate){ PHALCON_CALL_METHOD(&models, builder, "getfrom"); if (Z_TYPE_P(models) == IS_ARRAY) { - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); + PHALCON_INIT_VAR(model_name); + phalcon_array_get_current(model_name, models); } else { PHALCON_CPY_WRT(model_name, models); } diff --git a/build/safe/php_phalcon.h b/build/safe/php_phalcon.h index ee2dcbe1d55..0deb4ad5733 100644 --- a/build/safe/php_phalcon.h +++ b/build/safe/php_phalcon.h @@ -29,7 +29,7 @@ #include #endif -#define PHP_PHALCON_VERSION "1.3.3" +#define PHP_PHALCON_VERSION "1.3.4" #define PHP_PHALCON_EXTNAME "phalcon" #define PHALCON_NUM_PREALLOCATED_FRAMES 25 diff --git a/ext/acl/adapter/memory.c b/ext/acl/adapter/memory.c index bcab66118dd..498d794bee2 100644 --- a/ext/acl/adapter/memory.c +++ b/ext/acl/adapter/memory.c @@ -178,7 +178,7 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, __construct){ * $acl->addRole('administrator', 'consultant'); * * - * @param Phalcon\Acl\RoleInterface $role + * @param Phalcon\Acl\RoleInterface|string $role * @param array|string $accessInherits * @return boolean */ @@ -352,7 +352,7 @@ PHP_METHOD(Phalcon_Acl_Adapter_Memory, isResource){ * $acl->addResource('customers', array('create', 'search')); * * - * @param Phalcon\Acl\Resource $resource + * @param Phalcon\Acl\Resource|string $resource * @param array $accessList * @return boolean */ diff --git a/ext/assets/manager.c b/ext/assets/manager.c index 2105bb23c4b..67a9e6117fc 100644 --- a/ext/assets/manager.c +++ b/ext/assets/manager.c @@ -678,73 +678,71 @@ PHP_METHOD(Phalcon_Assets_Manager, output){ * If the collection must not be joined we must print a HTML for each one */ if (Z_TYPE_P(filters) == IS_ARRAY) { - if (zend_is_true(join)) { - if (zend_is_true(local)) { - - /** - * Get the complete path - */ - PHALCON_CALL_METHOD(&source_path, resource, "getrealsourcepath", complete_source_path); - - /** - * We need a valid source path - */ - if (!zend_is_true(source_path)) { - PHALCON_CALL_METHOD(&source_path, resource, "getpath"); - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid source path"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } - } else { - /** - * Get the complete source path - */ + if (zend_is_true(local)) { + + /** + * Get the complete path + */ + PHALCON_CALL_METHOD(&source_path, resource, "getrealsourcepath", complete_source_path); + + /** + * We need a valid source path + */ + if (!zend_is_true(source_path)) { PHALCON_CALL_METHOD(&source_path, resource, "getpath"); - - /** - * resources paths are always filtered - */ - PHALCON_INIT_NVAR(filter_needed); - ZVAL_TRUE(filter_needed); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid source path"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; } - + } else { /** - * Get the target path, we need to write the filtered content to a file + * Get the complete source path */ - PHALCON_CALL_METHOD(&target_path, resource, "getrealtargetpath", complete_target_path); - + PHALCON_CALL_METHOD(&source_path, resource, "getpath"); + /** - * We need a valid final target path + * resources paths are always filtered */ - if (PHALCON_IS_EMPTY(target_path)) { + PHALCON_INIT_NVAR(filter_needed); + ZVAL_TRUE(filter_needed); + } + + /** + * Get the target path, we need to write the filtered content to a file + */ + PHALCON_CALL_METHOD(&target_path, resource, "getrealtargetpath", complete_target_path); + + /** + * We need a valid final target path + */ + if (PHALCON_IS_EMPTY(target_path)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; + } + + if (zend_is_true(local)) { + + /** + * Make sure the target path is not the same source path + */ + if (PHALCON_IS_EQUAL(target_path, source_path)) { PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path"); + PHALCON_CONCAT_SVS(exception_message, "Resource '", target_path, "' have the same source and target paths"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); return; } - - if (zend_is_true(local)) { - - /** - * Make sure the target path is not the same source path - */ - if (PHALCON_IS_EQUAL(target_path, source_path)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", target_path, "' have the same source and target paths"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } - if (phalcon_file_exists(target_path TSRMLS_CC) == SUCCESS) { - if (phalcon_compare_mtime(target_path, source_path TSRMLS_CC)) { - PHALCON_INIT_NVAR(filter_needed); - ZVAL_TRUE(filter_needed); - } - } else { + if (phalcon_file_exists(target_path TSRMLS_CC) == SUCCESS) { + if (phalcon_compare_mtime(target_path, source_path TSRMLS_CC)) { PHALCON_INIT_NVAR(filter_needed); ZVAL_TRUE(filter_needed); } + } else { + PHALCON_INIT_NVAR(filter_needed); + ZVAL_TRUE(filter_needed); } } } diff --git a/ext/debug.c b/ext/debug.c index 1838f33c77d..b2e3368ebe9 100644 --- a/ext/debug.c +++ b/ext/debug.c @@ -132,7 +132,7 @@ static const zend_function_entry phalcon_debug_method_entry[] = { PHP_ME(Phalcon_Debug, getJsSources, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, showTraceItem, NULL, ZEND_ACC_PROTECTED) PHP_ME(Phalcon_Debug, onUncaughtException, arginfo_phalcon_debug_onuncaughtexception, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Debug, getCharset, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Debug, getCharset, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_ME(Phalcon_Debug, setCharset, arginfo_phalcon_debug_setcharset, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, getLinesBeforeContext, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Debug, setLinesBeforeContext, arginfo_phalcon_debug_setlines, ZEND_ACC_PUBLIC) @@ -364,7 +364,7 @@ PHP_METHOD(Phalcon_Debug, _escapeString){ zval line_break; zval escaped_line_break; - charset = phalcon_fetch_nproperty_this(getThis(), SL("_charset"), PH_NOISY TSRMLS_CC); + charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); INIT_ZVAL(line_break); ZVAL_STRING(&line_break, "\n", 0); @@ -948,7 +948,7 @@ PHP_METHOD(Phalcon_Debug, showTraceItem){ PHALCON_INIT_VAR(comment_pattern); ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1); - charset = phalcon_fetch_nproperty_this(getThis(), SL("_charset"), PH_NOISY TSRMLS_CC); + charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); PHALCON_INIT_VAR(tab); ZVAL_STRING(tab, "\t", 1); @@ -1306,7 +1306,8 @@ PHP_METHOD(Phalcon_Debug, onUncaughtException){ * @return string */ PHP_METHOD(Phalcon_Debug, getCharset) { - RETURN_MEMBER(getThis(), "_charset"); + zval *charset = phalcon_fetch_static_property_ce(phalcon_debug_ce, SL("_charset") TSRMLS_CC); + RETURN_ZVAL(charset, 1, 0); } /** @@ -1323,7 +1324,7 @@ PHP_METHOD(Phalcon_Debug, setCharset) { phalcon_fetch_params_ex(1, 0, &charset); PHALCON_ENSURE_IS_STRING(charset); - phalcon_update_property_this(getThis(), SL("_charset"), *charset TSRMLS_CC); + phalcon_update_static_property_ce(phalcon_debug_ce, SL("_charset"), *charset TSRMLS_CC); RETURN_THISW(); } diff --git a/ext/forms/form.c b/ext/forms/form.c index 55becd1a689..d044d235a7f 100644 --- a/ext/forms/form.c +++ b/ext/forms/form.c @@ -21,6 +21,7 @@ #include "forms/elementinterface.h" #include "forms/exception.h" #include "di/injectable.h" +#include "diinterface.h" #include "filterinterface.h" #include "validation.h" #include "validation/exception.h" @@ -358,15 +359,15 @@ PHP_METHOD(Phalcon_Forms_Form, __construct){ Z_OBJ_HT_P(getThis()) = &phalcon_forms_form_object_handlers; phalcon_fetch_params(0, 0, 2, &entity, &user_options); - + if (!entity) { entity = PHALCON_GLOBAL(z_null); } - + if (!user_options) { user_options = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(entity) != IS_NULL) { if (Z_TYPE_P(entity) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The base entity is not valid"); @@ -375,15 +376,15 @@ PHP_METHOD(Phalcon_Forms_Form, __construct){ phalcon_update_property_this(this_ptr, SL("_entity"), entity TSRMLS_CC); } - - /** + + /** * Update the user options */ - if (Z_TYPE_P(user_options) == IS_ARRAY) { + if (Z_TYPE_P(user_options) == IS_ARRAY) { phalcon_update_property_this(this_ptr, SL("_options"), user_options TSRMLS_CC); } - - /** + + /** * Check for an 'initialize' method and call it */ if (phalcon_method_exists_ex(this_ptr, SS("initialize") TSRMLS_CC) == SUCCESS) { @@ -404,7 +405,7 @@ PHP_METHOD(Phalcon_Forms_Form, setAction){ zval *action; phalcon_fetch_params(0, 1, 0, &action); - + phalcon_update_property_this(this_ptr, SL("_action"), action TSRMLS_CC); RETURN_THISW(); } @@ -432,7 +433,7 @@ PHP_METHOD(Phalcon_Forms_Form, setUserOption){ zval *option, *value; phalcon_fetch_params(0, 2, 0, &option, &value); - + phalcon_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC); RETURN_THISW(); } @@ -449,16 +450,16 @@ PHP_METHOD(Phalcon_Forms_Form, getUserOption){ zval *option, *default_value = NULL, *options, *value; phalcon_fetch_params(0, 1, 1, &option, &default_value); - + if (!default_value) { default_value = PHALCON_GLOBAL(z_null); } - + options = phalcon_fetch_nproperty_this(this_ptr, SL("_options"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_fetch(&value, options, option)) { RETURN_ZVAL(value, 1, 0); } - + RETURN_ZVAL(default_value, 1, 0); } @@ -473,13 +474,13 @@ PHP_METHOD(Phalcon_Forms_Form, setUserOptions){ zval *options; phalcon_fetch_params(0, 1, 0, &options); - - if (Z_TYPE_P(options) != IS_ARRAY) { + + if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "Parameter 'options' must be an array"); return; } phalcon_update_property_this(this_ptr, SL("_options"), options TSRMLS_CC); - + RETURN_THISW(); } @@ -505,7 +506,7 @@ PHP_METHOD(Phalcon_Forms_Form, setEntity){ zval *entity; phalcon_fetch_params(0, 1, 0, &entity); - + if (Z_TYPE_P(entity) != IS_NULL && Z_TYPE_P(entity) != IS_OBJECT) { zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "'%s' must be an object or NULL", "entity"); return; @@ -558,83 +559,87 @@ PHP_METHOD(Phalcon_Forms_Form, bind){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 1, &data, &entity, &whitelist); - + if (!whitelist) { whitelist = PHALCON_GLOBAL(z_null); } - - /** + + /** * The data must be an array */ - if (Z_TYPE_P(data) != IS_ARRAY) { + if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The data must be an array"); return; } - + PHALCON_OBS_VAR(elements); phalcon_read_property_this(&elements, this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) != IS_ARRAY) { + if (Z_TYPE_P(elements) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "There are no elements in the form"); return; } - + PHALCON_INIT_VAR(filter); - + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + if (!phalcon_array_isset(elements, key)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } - - /** + + /** * Check if the item is in the whitelist */ - if (Z_TYPE_P(whitelist) == IS_ARRAY) { + if (Z_TYPE_P(whitelist) == IS_ARRAY) { if (!phalcon_fast_in_array(key, whitelist TSRMLS_CC)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } } - - /** + + /** * Get the element */ PHALCON_OBS_NVAR(element); phalcon_array_fetch(&element, elements, key, PH_NOISY); - - /** + + /** * Check if the method has filters */ PHALCON_CALL_METHOD(&filters, element, "getfilters"); if (zend_is_true(filters)) { + if (Z_TYPE_P(filter) != IS_OBJECT) { + PHALCON_INIT_NVAR(service_name); PHALCON_ZVAL_MAYBE_INTERNED_STRING(service_name, phalcon_interned_filter); - + PHALCON_CALL_METHOD(&dependency_injector, this_ptr, "getdi"); + PHALCON_VERIFY_INTERFACE(dependency_injector, phalcon_diinterface_ce); + PHALCON_CALL_METHOD(&filter, dependency_injector, "getshared", service_name); PHALCON_VERIFY_INTERFACE(filter, phalcon_filterinterface_ce); } - - /** + + /** * Sanitize the filters */ PHALCON_CALL_METHOD(&filtered_value, filter, "sanitize", value, filters); } else { PHALCON_CPY_WRT(filtered_value, value); } - + PHALCON_INIT_NVAR(method); PHALCON_CONCAT_SV(method, "set", key); zend_str_tolower(Z_STRVAL_P(method), Z_STRLEN_P(method)); - - /** + + /** * Use the setter if any available */ if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { @@ -642,17 +647,17 @@ PHP_METHOD(Phalcon_Forms_Form, bind){ zend_hash_move_forward_ex(ah0, &hp0); continue; } - - /** + + /** * Use the public property if it doesn't have a setter */ phalcon_update_property_zval_zval(entity, key, filtered_value TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + phalcon_update_property_this(this_ptr, SL("_data"), data TSRMLS_CC); - + PHALCON_MM_RESTORE(); } @@ -676,35 +681,35 @@ PHP_METHOD(Phalcon_Forms_Form, isValid){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 2, &data, &entity); - + if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!entity) { entity = PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) != IS_ARRAY) { + if (Z_TYPE_P(elements) != IS_ARRAY) { RETURN_MM_TRUE; } - - /** + + /** * If the user doesn't pass an entity we use the one in this_ptr->_entity */ if (Z_TYPE_P(entity) == IS_OBJECT) { PHALCON_CALL_METHOD(NULL, this_ptr, "bind", data, entity); } - - /** + + /** * If the data is not an array use the one passed previously */ - if (Z_TYPE_P(data) != IS_ARRAY) { + if (Z_TYPE_P(data) != IS_ARRAY) { data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY TSRMLS_CC); } - - /** + + /** * Check if there is a method 'beforeValidation' */ if (phalcon_method_exists_ex(this_ptr, SS("beforevalidation") TSRMLS_CC) == SUCCESS) { @@ -713,102 +718,102 @@ PHP_METHOD(Phalcon_Forms_Form, isValid){ RETURN_CTOR(status); } } - + not_failed = PHALCON_GLOBAL(z_true); - + PHALCON_INIT_VAR(messages); array_init(messages); - + phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(element); - + PHALCON_CALL_METHOD(&validators, element, "getvalidators"); - if (Z_TYPE_P(validators) == IS_ARRAY) { + if (Z_TYPE_P(validators) == IS_ARRAY) { if (phalcon_fast_count_ev(validators TSRMLS_CC)) { - - /** + + /** * Element's name */ PHALCON_CALL_METHOD(&name, element, "getname"); - - /** + + /** * Prepare the validators */ PHALCON_INIT_NVAR(prepared_validators); array_init(prepared_validators); - + phalcon_is_iterable(validators, &ah1, &hp1, 0, 0); - + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - + PHALCON_GET_HVALUE(validator); - + PHALCON_INIT_NVAR(scope); array_init_size(scope, 2); phalcon_array_append(&scope, name, 0); phalcon_array_append(&scope, validator, 0); phalcon_array_append(&prepared_validators, scope, PH_SEPARATE); - + zend_hash_move_forward_ex(ah1, &hp1); } - - /** + + /** * Create an implicit validation */ PHALCON_INIT_NVAR(validation); object_init_ex(validation, phalcon_validation_ce); PHALCON_CALL_METHOD(NULL, validation, "__construct", prepared_validators); - - /** + + /** * Get filters in the element */ PHALCON_CALL_METHOD(&filters, element, "getfilters"); - - /** + + /** * Assign the filters to the validation */ - if (Z_TYPE_P(filters) == IS_ARRAY) { + if (Z_TYPE_P(filters) == IS_ARRAY) { PHALCON_CALL_METHOD(&name, element, "getname"); PHALCON_CALL_METHOD(NULL, validation, "setfilters", name, filters); } - - /** + + /** * Perform the validation */ PHALCON_CALL_METHOD(&element_messages, validation, "validate", data, entity); if (phalcon_fast_count_ev(element_messages TSRMLS_CC)) { PHALCON_CALL_METHOD(&name, element, "getname"); phalcon_array_update_zval(&messages, name, element_messages, PH_COPY | PH_SEPARATE); - + not_failed = PHALCON_GLOBAL(z_false); } } } - + zend_hash_move_forward_ex(ah0, &hp0); } - - /** + + /** * If the validation fails update the messages */ if (!zend_is_true(not_failed)) { phalcon_update_property_this(this_ptr, SL("_messages"), messages TSRMLS_CC); } - - /** + + /** * Check if there is a method 'afterValidation' */ if (phalcon_method_exists_ex(this_ptr, SS("aftervalidation") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, "aftervalidation", messages); } - - /** + + /** * Return the validation status */ - + RETURN_NCTOR(not_failed); } @@ -823,10 +828,10 @@ PHP_METHOD(Phalcon_Forms_Form, getMessages){ zval **by_item_name = NULL, *messages; phalcon_fetch_params_ex(0, 1, &by_item_name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); if (by_item_name && zend_is_true(*by_item_name)) { - if (Z_TYPE_P(messages) != IS_ARRAY) { + if (Z_TYPE_P(messages) != IS_ARRAY) { object_init_ex(return_value, phalcon_validation_message_group_ce); phalcon_validation_group_construct_helper(return_value, NULL TSRMLS_CC); } @@ -863,12 +868,12 @@ PHP_METHOD(Phalcon_Forms_Form, getMessagesFor){ zval **name, *messages, *element_messages; phalcon_fetch_params_ex(1, 0, &name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); if (phalcon_array_isset_fetch(&element_messages, messages, *name)) { RETURN_ZVAL(element_messages, 1, 0); } - + object_init_ex(return_value, phalcon_validation_message_group_ce); phalcon_validation_group_construct_helper(return_value, NULL TSRMLS_CC); } @@ -883,7 +888,7 @@ PHP_METHOD(Phalcon_Forms_Form, hasMessagesFor){ zval **name, *messages; phalcon_fetch_params_ex(1, 0, &name); - + messages = phalcon_fetch_nproperty_this(this_ptr, SL("_messages"), PH_NOISY TSRMLS_CC); RETURN_BOOL(phalcon_array_isset(messages, *name)); } @@ -905,15 +910,15 @@ PHP_METHOD(Phalcon_Forms_Form, add){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &element, &pos, &type); - + PHALCON_VERIFY_INTERFACE_EX(element, phalcon_forms_elementinterface_ce, phalcon_forms_exception_ce, 1); - - /** + + /** * Gets the element's name */ PHALCON_CALL_METHOD(&name, element, "getname"); - - /** + + /** * Link the element to the form */ PHALCON_CALL_METHOD(NULL, element, "setform", this_ptr); @@ -977,7 +982,7 @@ PHP_METHOD(Phalcon_Forms_Form, add){ phalcon_update_property_this(this_ptr, SL("_elements"), elements TSRMLS_CC); } - + RETURN_THIS(); } @@ -993,12 +998,12 @@ PHP_METHOD(Phalcon_Forms_Form, render){ zval **name, **attributes = NULL, *elements, *element; phalcon_fetch_params_ex(1, 1, &name, &attributes); - + PHALCON_ENSURE_IS_STRING(name); if (!attributes) { attributes = &PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); @@ -1019,14 +1024,14 @@ PHP_METHOD(Phalcon_Forms_Form, get){ zval **name, *elements, *element; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { PHALCON_ENSURE_IS_STRING(name); zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + RETURN_ZVAL(element, 1, 0); } @@ -1052,7 +1057,7 @@ PHP_METHOD(Phalcon_Forms_Form, label){ zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + PHALCON_RETURN_CALL_METHODW(element, "label", *attributes); } @@ -1067,22 +1072,22 @@ PHP_METHOD(Phalcon_Forms_Form, getLabel){ zval **name, *elements, *element, *label = NULL; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); if (!phalcon_array_isset_fetch(&element, elements, *name)) { PHALCON_ENSURE_IS_STRING(name); zend_throw_exception_ex(phalcon_forms_exception_ce, 0 TSRMLS_CC, "Element with ID=%s is not a part of the form", Z_STRVAL_P(*name)); return; } - + PHALCON_MM_GROW(); PHALCON_CALL_METHOD(&label, element, "getlabel"); - + /* Use the element's name as label if the label is not available */ if (!zend_is_true(label)) { RETURN_CTOR(*name); } - + RETURN_CTOR(label); } @@ -1099,10 +1104,10 @@ PHP_METHOD(Phalcon_Forms_Form, getValue){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &name); - + entity = phalcon_fetch_nproperty_this(this_ptr, SL("_entity"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(entity) == IS_OBJECT) { - /** + /** * Check if the entity has a getter */ PHALCON_INIT_VAR(method); @@ -1112,8 +1117,8 @@ PHP_METHOD(Phalcon_Forms_Form, getValue){ PHALCON_RETURN_CALL_METHOD(entity, Z_STRVAL_P(method)); RETURN_MM(); } - - /** + + /** * Check if the entity has a public property */ if (phalcon_isset_property_zval(entity, name TSRMLS_CC)) { @@ -1122,18 +1127,18 @@ PHP_METHOD(Phalcon_Forms_Form, getValue){ RETURN_CTOR(value); } } - + data = phalcon_fetch_nproperty_this(this_ptr, SL("_data"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(data) == IS_ARRAY) { - - /** + if (Z_TYPE_P(data) == IS_ARRAY) { + + /** * Check if the data is in the data array */ if (phalcon_array_isset_fetch(&value, data, name)) { RETURN_CTOR(value); } } - + RETURN_MM_NULL(); } @@ -1148,7 +1153,7 @@ PHP_METHOD(Phalcon_Forms_Form, has){ zval **name, *elements; phalcon_fetch_params_ex(1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); RETURN_BOOL(phalcon_array_isset(elements, *name)); } @@ -1164,9 +1169,9 @@ PHP_METHOD(Phalcon_Forms_Form, remove){ zval *name, *elements; phalcon_fetch_params(0, 1, 0, &name); - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - + if (phalcon_array_isset(elements, name)) { phalcon_unset_property_array(this_ptr, SL("_elements"), name TSRMLS_CC); @@ -1195,21 +1200,21 @@ PHP_METHOD(Phalcon_Forms_Form, clear){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &fields); - + if (!fields) { fields = PHALCON_GLOBAL(z_null); } - + elements = phalcon_fetch_nproperty_this(this_ptr, SL("_elements"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(elements) == IS_ARRAY) { - + if (Z_TYPE_P(elements) == IS_ARRAY) { + phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(element); - - if (Z_TYPE_P(fields) != IS_ARRAY) { + + if (Z_TYPE_P(fields) != IS_ARRAY) { PHALCON_CALL_METHOD(NULL, element, "clear"); } else { PHALCON_CALL_METHOD(&name, element, "getname"); @@ -1217,12 +1222,12 @@ PHP_METHOD(Phalcon_Forms_Form, clear){ PHALCON_CALL_METHOD(NULL, element, "clear"); } } - + zend_hash_move_forward_ex(ah0, &hp0); } - + } - + RETURN_THIS(); } @@ -1255,7 +1260,7 @@ PHP_METHOD(Phalcon_Forms_Form, rewind){ /** * Returns the current element in the iterator * - * @return Phalcon\Validation\Message + * @return Phalcon\Forms\ElementInterface */ PHP_METHOD(Phalcon_Forms_Form, current){ diff --git a/ext/http/request/file.c b/ext/http/request/file.c index 3a121c994a8..f8db85f3994 100644 --- a/ext/http/request/file.c +++ b/ext/http/request/file.c @@ -344,5 +344,5 @@ PHP_METHOD(Phalcon_Http_Request_File, __set_state) { PHP_METHOD(Phalcon_Http_Request_File, getExtension){ - RETURN_MEMBER(this_ptr, "_extension "); + RETURN_MEMBER(this_ptr, "_extension"); } diff --git a/ext/install b/ext/install index 25661add27e..7eaa3833b48 100755 --- a/ext/install +++ b/ext/install @@ -21,4 +21,4 @@ if [ -f Makefile ]; then fi phpize -CC="gcc" CFLAGS="-g3 -O0 -Wall" ./configure --enable-phalcon && make && make install && echo "Notice: Phalcon was compiled in debug mode.\nThanks for compiling Phalcon!\nBuild succeed: Please restart your web server to complete the installation" +CC="gcc" CFLAGS="-g3 -O0 -Wall" ./configure --enable-phalcon && make -j2 && make install && echo "Notice: Phalcon was compiled in debug mode.\nThanks for compiling Phalcon!\nBuild succeed: Please restart your web server to complete the installation" diff --git a/ext/kernel/main.h b/ext/kernel/main.h index 9fbf2a354ac..2beace98c1a 100644 --- a/ext/kernel/main.h +++ b/ext/kernel/main.h @@ -357,17 +357,25 @@ int phalcon_fetch_parameters_ex(int dummy TSRMLS_DC, int n_req, int n_opt, ...); } #define PHALCON_VERIFY_INTERFACE_EX(instance, interface_ce, exception_ce, restore_stack) \ - if (Z_TYPE_P(instance) != IS_OBJECT || !instanceof_function_ex(Z_OBJCE_P(instance), interface_ce, 1 TSRMLS_CC)) { \ - if (Z_TYPE_P(instance) != IS_OBJECT) { \ - zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ - } \ - else { \ - zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, object of type %s given", interface_ce->name, Z_OBJCE_P(instance)->name); \ - } \ + if (Z_TYPE_P(instance) != IS_OBJECT) { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ if (restore_stack) { \ PHALCON_MM_RESTORE(); \ } \ return; \ + } else { \ + if (!instanceof_function_ex(Z_OBJCE_P(instance), interface_ce, 1 TSRMLS_CC)) { \ + if (Z_TYPE_P(instance) != IS_OBJECT) { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, %s given", interface_ce->name, zend_zval_type_name(instance)); \ + } \ + else { \ + zend_throw_exception_ex(exception_ce, 0 TSRMLS_CC, "Unexpected value type: expected object implementing %s, object of type %s given", interface_ce->name, Z_OBJCE_P(instance)->name); \ + } \ + if (restore_stack) { \ + PHALCON_MM_RESTORE(); \ + } \ + return; \ + } \ } #define PHALCON_VERIFY_INTERFACE_OR_NULL_EX(pzv, interface_ce, exception_ce, restore_stack) \ diff --git a/ext/kernel/operators.c b/ext/kernel/operators.c index 0b46284c8ab..82ac1f25021 100644 --- a/ext/kernel/operators.c +++ b/ext/kernel/operators.c @@ -81,6 +81,8 @@ void phalcon_concat_self(zval **left, zval *right TSRMLS_DC){ } } + SEPARATE_ZVAL_IF_NOT_REF(left); + length = Z_STRLEN_PP(left) + Z_STRLEN_P(right); Z_STRVAL_PP(left) = str_erealloc(Z_STRVAL_PP(left), length + 1); @@ -125,6 +127,8 @@ void phalcon_concat_self_str(zval **left, const char *right, int right_length TS } } + SEPARATE_ZVAL_IF_NOT_REF(left); + length = Z_STRLEN_PP(left) + right_length; Z_STRVAL_PP(left) = str_erealloc(Z_STRVAL_PP(left), length + 1); diff --git a/ext/mvc/collection.c b/ext/mvc/collection.c index 9e6615826a0..c5d708a2fe3 100644 --- a/ext/mvc/collection.c +++ b/ext/mvc/collection.c @@ -204,10 +204,10 @@ PHP_METHOD(Phalcon_Mvc_Collection, __construct){ zval *service_name; phalcon_fetch_params_ex(0, 2, &dependency_injector, &collection_manager); - + PHALCON_MM_GROW(); - /** + /** * We use a default DI if the user doesn't define one */ if (!dependency_injector || Z_TYPE_PP(dependency_injector) != IS_OBJECT) { @@ -218,16 +218,16 @@ PHP_METHOD(Phalcon_Mvc_Collection, __construct){ } PHALCON_VERIFY_INTERFACE_EX(di, phalcon_diinterface_ce, phalcon_mvc_collection_exception_ce, 1); - + phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), di TSRMLS_CC); - - /** + + /** * Inject the manager service from the DI */ if (!collection_manager || Z_TYPE_PP(collection_manager) != IS_OBJECT) { PHALCON_ALLOC_GHOST_ZVAL(service_name); ZVAL_STRING(service_name, "collectionManager", 1); - + PHALCON_CALL_METHOD(&mm, di, "getshared", service_name); if (Z_TYPE_P(mm) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The injected service 'collectionManager' is not valid"); @@ -237,27 +237,27 @@ PHP_METHOD(Phalcon_Mvc_Collection, __construct){ else { mm = *collection_manager; } - + PHALCON_VERIFY_INTERFACE_EX(mm, phalcon_mvc_collection_managerinterface_ce, phalcon_mvc_collection_exception_ce, 1); - /** + /** * Update the collection-manager */ phalcon_update_property_this(this_ptr, SL("_collectionManager"), mm TSRMLS_CC); - - /** + + /** * The manager always initializes the object */ PHALCON_CALL_METHOD(NULL, mm, "initialize", this_ptr); - - /** + + /** * This allows the developer to execute initialization stuff every time an instance * is created */ if (phalcon_method_exists_ex(this_ptr, SS("onconstruct") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, "onconstruct"); } - + PHALCON_MM_RESTORE(); } @@ -275,11 +275,11 @@ PHP_METHOD(Phalcon_Mvc_Collection, setId){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &id); - + if (Z_TYPE_P(id) != IS_OBJECT) { collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - - /** + + /** * Check if the collection use implicit ids */ PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); @@ -349,10 +349,10 @@ PHP_METHOD(Phalcon_Mvc_Collection, setEventsManager){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &events_manager); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "setcustomeventsmanager", this_ptr, events_manager); - + PHALCON_MM_RESTORE(); } @@ -392,7 +392,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, getReservedAttributes){ reserved = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_reserved") TSRMLS_CC); if (Z_TYPE_P(reserved) == IS_NULL) { zval *dummy = PHALCON_GLOBAL(z_true); - + array_init_size(return_value, 5); Z_ADDREF_P(dummy); add_assoc_zval_ex(return_value, SS("_connection"), dummy); Z_ADDREF_P(dummy); add_assoc_zval_ex(return_value, SS("_dependencyInjector"), dummy); @@ -419,10 +419,10 @@ PHP_METHOD(Phalcon_Mvc_Collection, useImplicitObjectIds){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &use_implicit_object_ids); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "useimplicitobjectids", this_ptr, use_implicit_object_ids); - + PHALCON_MM_RESTORE(); } @@ -437,7 +437,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, setSource){ zval *source; phalcon_fetch_params(0, 1, 0, &source); - + phalcon_update_property_this(this_ptr, SL("_source"), source TSRMLS_CC); RETURN_THISW(); } @@ -458,12 +458,12 @@ PHP_METHOD(Phalcon_Mvc_Collection, getSource){ if (!zend_is_true(source)) { PHALCON_INIT_VAR(class_name); phalcon_get_class_ns(class_name, this_ptr, 0 TSRMLS_CC); - + PHALCON_INIT_NVAR(source); phalcon_uncamelize(source, class_name); phalcon_update_property_this(this_ptr, SL("_source"), source TSRMLS_CC); } - + RETURN_CTOR(source); } @@ -480,7 +480,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, setConnectionService){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &connection_service); - + collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); PHALCON_CALL_METHOD(NULL, collection_manager, "setconnectionservice", this_ptr, connection_service); RETURN_THIS(); @@ -514,11 +514,11 @@ PHP_METHOD(Phalcon_Mvc_Collection, getConnection){ phalcon_read_property_this(&connection, this_ptr, SL("_connection"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(connection) != IS_OBJECT) { collection_manager = phalcon_fetch_nproperty_this(this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&connection, collection_manager, "getconnection", this_ptr); phalcon_update_property_this(this_ptr, SL("_connection"), connection TSRMLS_CC); } - + RETURN_CTOR(connection); } @@ -539,7 +539,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, readAttribute){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &attribute); - + if (phalcon_isset_property_zval(this_ptr, attribute TSRMLS_CC)) { PHALCON_OBS_VAR(attribute_value); phalcon_read_property_zval(&attribute_value, this_ptr, attribute, PH_NOISY TSRMLS_CC); @@ -563,9 +563,9 @@ PHP_METHOD(Phalcon_Mvc_Collection, writeAttribute){ zval *attribute, *value; phalcon_fetch_params(0, 2, 0, &attribute, &value); - + phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - + } /** @@ -586,33 +586,33 @@ PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &collection, &document); - + if (Z_TYPE_P(collection) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid collection"); return; } - if (Z_TYPE_P(document) != IS_ARRAY) { + if (Z_TYPE_P(document) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid document"); return; } - + PHALCON_INIT_VAR(cloned_collection); if (phalcon_clone(cloned_collection, collection TSRMLS_CC) == FAILURE) { RETURN_MM(); } - + phalcon_is_iterable(document, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + PHALCON_CALL_METHOD(NULL, cloned_collection, "writeattribute", key, value); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(cloned_collection); } @@ -639,16 +639,20 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 4, 0, ¶ms, &collection, &connection, &unique); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&mongo_collection, connection, "selectcollection", source); - - /** + if (Z_TYPE_P(mongo_collection) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Couldn't select mongo collection"); + return; + } + + /** * Convert the string to an array */ if (phalcon_array_isset_long(params, 0)) { @@ -663,21 +667,26 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ array_init(conditions); } } - - /** + + if (Z_TYPE_P(conditions) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Find parameters must be an array"); + return; + } + + /** * Perform the find */ PHALCON_INIT_VAR(documents_cursor); if (phalcon_array_isset_string(params, SS("fields"))) { PHALCON_OBS_VAR(fields); phalcon_array_fetch_string(&fields, params, SL("fields"), PH_NOISY); - + PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions, fields); } else { PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions); } - - /** + + /** * Check if a 'limit' clause was defined */ if (phalcon_array_isset_string(params, SS("limit"))) { @@ -685,8 +694,8 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ phalcon_array_fetch_string(&limit, params, SL("limit"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "limit", limit); } - - /** + + /** * Check if a 'sort' clause was defined */ if (phalcon_array_isset_string(params, SS("sort"))) { @@ -694,8 +703,8 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ phalcon_array_fetch_string(&sort, params, SL("sort"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "sort", sort); } - - /** + + /** * Check if a 'skip' clause was defined */ if (phalcon_array_isset_string(params, SS("skip"))) { @@ -703,8 +712,8 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ phalcon_array_fetch_string(&sort, params, SL("skip"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "skip", sort); } - - /** + + /** * If a group of specific fields are requested we use a * Phalcon\Mvc\Collection\Document instead */ @@ -714,48 +723,48 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ } else { PHALCON_CPY_WRT(base, collection); } - + if (PHALCON_IS_TRUE(unique)) { - - /** + + /** * Requesting a single result */ PHALCON_CALL_METHOD(NULL, documents_cursor, "rewind"); PHALCON_CALL_METHOD(&document, documents_cursor, "current"); - if (Z_TYPE_P(document) == IS_ARRAY) { - /** + if (Z_TYPE_P(document) == IS_ARRAY) { + /** * Assign the values to the base object */ PHALCON_RETURN_CALL_SELF("cloneresult", base, document); RETURN_MM(); } - + RETURN_MM_FALSE; } - - /** + + /** * Requesting a complete resultset */ PHALCON_INIT_VAR(collections); array_init(collections); - + PHALCON_CALL_FUNCTION(&documents_array, "iterator_to_array", documents_cursor); - + phalcon_is_iterable(documents_array, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(document); - - /** + + /** * Assign the values to the base object */ PHALCON_CALL_SELF(&collection_cloned, "cloneresult", base, document); phalcon_array_append(&collections, collection_cloned, PH_SEPARATE); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(collections); } @@ -776,16 +785,16 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, ¶ms, &collection, &connection); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&mongo_collection, connection, "selectcollection", source); - - /** + + /** * Convert the string to an array */ if (phalcon_array_isset_long(params, 0)) { @@ -800,7 +809,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ array_init(conditions); } } - + PHALCON_INIT_VAR(simple); ZVAL_BOOL(simple, 1); if (phalcon_array_isset_string(params, SS("limit"))) { @@ -816,15 +825,15 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ } } } - + if (PHALCON_IS_FALSE(simple)) { - - /** + + /** * Perform the find */ PHALCON_CALL_METHOD(&documents_cursor, mongo_collection, "find", conditions); - - /** + + /** * Check if a 'limit' clause was defined */ if (phalcon_array_isset_string(params, SS("limit"))) { @@ -832,8 +841,8 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ phalcon_array_fetch_string(&limit, params, SL("limit"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "limit", limit); } - - /** + + /** * Check if a 'sort' clause was defined */ if (phalcon_array_isset_string(params, SS("sort"))) { @@ -841,8 +850,8 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ phalcon_array_fetch_string(&sort, params, SL("sort"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "sort", sort); } - - /** + + /** * Check if a 'skip' clause was defined */ if (phalcon_array_isset_string(params, SS("skip"))) { @@ -850,14 +859,14 @@ PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ phalcon_array_fetch_string(&sort, params, SL("skip"), PH_NOISY); PHALCON_CALL_METHOD(NULL, documents_cursor, "skip", sort); } - - /** + + /** * Only 'count' is supported */ phalcon_fast_count(return_value, documents_cursor TSRMLS_CC); RETURN_MM(); } - + PHALCON_RETURN_CALL_METHOD(mongo_collection, "count", conditions); RETURN_MM(); } @@ -878,20 +887,20 @@ PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &dependency_injector, &disable_events, &exists); - - /** + + /** * Run Validation Callbacks Before */ if (!zend_is_true(disable_events)) { - + PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "beforeValidation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + if (!zend_is_true(exists)) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeValidationOnCreate", 1); @@ -899,19 +908,19 @@ PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeValidationOnUpdate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - - /** + + /** * Run validation */ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "validation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { if (!zend_is_true(disable_events)) { @@ -921,10 +930,10 @@ PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ } RETURN_MM_FALSE; } - + if (!zend_is_true(disable_events)) { - - /** + + /** * Run Validation Callbacks After */ if (!zend_is_true(exists)) { @@ -934,31 +943,31 @@ PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterValidationOnUpdate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterValidation", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - - /** + + /** * Run Before Callbacks */ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeSave", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + if (zend_is_true(exists)) { PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeUpdate", 1); @@ -966,13 +975,13 @@ PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "beforeCreate", 1); } - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - + RETURN_MM_TRUE; } @@ -991,7 +1000,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 3, 0, &disable_events, &success, &exists); - + if (PHALCON_IS_TRUE(success)) { if (!zend_is_true(disable_events)) { if (PHALCON_IS_TRUE(exists)) { @@ -1002,12 +1011,12 @@ PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ ZVAL_STRING(event_name, "afterCreate", 1); } PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); - + PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "afterSave", 1); PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } - + RETURN_CTOR(success); } if (!zend_is_true(disable_events)) { @@ -1015,7 +1024,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ ZVAL_STRING(event_name, "notSave", 1); PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } - + PHALCON_CALL_METHOD(NULL, this_ptr, "_canceloperation", disable_events); RETURN_MM_FALSE; } @@ -1055,29 +1064,29 @@ PHP_METHOD(Phalcon_Mvc_Collection, validate){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &validator); - + if (Z_TYPE_P(validator) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Validator must be an Object"); return; } - + PHALCON_CALL_METHOD(&status, validator, "validate", this_ptr); if (PHALCON_IS_FALSE(status)) { PHALCON_CALL_METHOD(&messages, validator, "getmessages"); - + phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HVALUE(message); - + phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + } - + PHALCON_MM_RESTORE(); } @@ -1114,12 +1123,12 @@ PHP_METHOD(Phalcon_Mvc_Collection, validationHasFailed){ PHALCON_OBS_VAR(error_messages); phalcon_read_property_this(&error_messages, this_ptr, SL("_errorMessages"), PH_NOISY TSRMLS_CC); - if (Z_TYPE_P(error_messages) == IS_ARRAY) { + if (Z_TYPE_P(error_messages) == IS_ARRAY) { if (phalcon_fast_count_ev(error_messages TSRMLS_CC)) { RETURN_MM_TRUE; } } - + RETURN_MM_FALSE; } @@ -1145,14 +1154,14 @@ PHP_METHOD(Phalcon_Mvc_Collection, fireEvent){ tmp = zend_str_tolower_dup(Z_STRVAL_PP(event_name), Z_STRLEN_PP(event_name)); ZVAL_STRINGL(lower, tmp, Z_STRLEN_PP(event_name), 0); - /** + /** * Check if there is a method with the same name of the event */ if (phalcon_method_exists_ex(this_ptr, Z_STRVAL_P(lower), Z_STRLEN_P(lower)+1 TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD(NULL, this_ptr, Z_STRVAL_P(lower)); } - - /** + + /** * Send a notification to the events manager */ PHALCON_OBS_VAR(collection_manager); @@ -1192,17 +1201,17 @@ PHP_METHOD(Phalcon_Mvc_Collection, fireEventCancel){ } } - /** + /** * Send a notification to the events manager */ PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&status, collection_manager, "notifyevent", *event_name, this_ptr); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + RETURN_MM_TRUE; } @@ -1218,9 +1227,9 @@ PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &disable_events); - + if (!zend_is_true(disable_events)) { - + PHALCON_OBS_VAR(operation_made); phalcon_read_property_this(&operation_made, this_ptr, SL("_operationMade"), PH_NOISY TSRMLS_CC); if (PHALCON_IS_LONG(operation_made, 3)) { @@ -1230,7 +1239,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ PHALCON_INIT_NVAR(event_name); ZVAL_STRING(event_name, "notSaved", 1); } - + PHALCON_CALL_METHOD(NULL, this_ptr, "fireevent", event_name); } RETURN_MM_FALSE; @@ -1251,9 +1260,9 @@ PHP_METHOD(Phalcon_Mvc_Collection, _exists){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &collection); - + if (phalcon_isset_property(this_ptr, SS("_id") TSRMLS_CC)) { - + PHALCON_OBS_VAR(id); phalcon_read_property_this(&id, this_ptr, SL("_id"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(id) == IS_OBJECT) { @@ -1261,8 +1270,8 @@ PHP_METHOD(Phalcon_Mvc_Collection, _exists){ } else { PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - - /** + + /** * Check if the collection use implicit ids */ PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); @@ -1278,19 +1287,19 @@ PHP_METHOD(Phalcon_Mvc_Collection, _exists){ PHALCON_CPY_WRT(mongo_id, id); } } - + PHALCON_INIT_VAR(parameters); array_init_size(parameters, 1); phalcon_array_update_string(¶meters, SL("_id"), mongo_id, PH_COPY); - - /** + + /** * Perform the count using the function provided by the driver */ PHALCON_CALL_METHOD(&document_count, collection, "count", parameters); - + z_zero = PHALCON_GLOBAL(z_zero); is_smaller_function(return_value, z_zero, document_count TSRMLS_CC); - + RETURN_MM(); } RETURN_MM_FALSE; @@ -1350,17 +1359,17 @@ PHP_METHOD(Phalcon_Mvc_Collection, appendMessage){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &message); - + if (Z_TYPE_P(message) != IS_OBJECT) { PHALCON_CALL_FUNCTION(&type, "gettype", message); - + PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SVS(exception_message, "Invalid message format '", type, "'"); PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_collection_exception_ce, exception_message); return; } phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - + PHALCON_MM_RESTORE(); } @@ -1398,11 +1407,11 @@ PHP_METHOD(Phalcon_Mvc_Collection, save){ if (!arr) { arr = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } - + if (!mode) { mode = PHALCON_GLOBAL(z_null); } @@ -1412,15 +1421,15 @@ PHP_METHOD(Phalcon_Mvc_Collection, save){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - - /** + + /** * Choose a collection according to the collection name */ PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - - /** + + /** * Check the dirty state of the current operation to update the current operation */ if (Z_TYPE_P(mode) == IS_NULL) { @@ -1428,7 +1437,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, save){ PHALCON_CALL_METHOD(&exists, this_ptr, "_exists", collection); PHALCON_INIT_NVAR(mode); - + ZVAL_BOOL(mode, (PHALCON_IS_FALSE(exists) ? 1 : 0)); phalcon_update_property_long(this_ptr, SL("_operationMade"), (PHALCON_IS_FALSE(exists) ? 1 : 2) TSRMLS_CC); } else { @@ -1437,25 +1446,25 @@ PHP_METHOD(Phalcon_Mvc_Collection, save){ phalcon_update_property_long(this_ptr, SL("_operationMade"), (PHALCON_IS_FALSE(exists) ? 1 : 2) TSRMLS_CC); } - + PHALCON_INIT_VAR(empty_array); array_init(empty_array); - - /** + + /** * The messages added to the validator are reset here */ phalcon_update_property_this(this_ptr, SL("_errorMessages"), empty_array TSRMLS_CC); - + disable_events = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_disableEvents") TSRMLS_CC); - - /** + + /** * Execute the preSave hook */ PHALCON_CALL_METHOD(&status, this_ptr, "_presave", dependency_injector, disable_events, exists); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } - + PHALCON_CALL_METHOD(&reserved, this_ptr, "getreservedattributes"); PHALCON_CALL_FUNCTION(&properties, "get_object_vars", this_ptr); @@ -1478,7 +1487,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, save){ if (Z_TYPE_P(white_list) != IS_ARRAY || phalcon_fast_in_array(&key, white_list TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch(&value, arr, &key, PH_NOISY); - + Z_ADDREF_P(value); if (likely(Z_TYPE(key) == IS_STRING)) { add_assoc_zval_ex(data, Z_STRVAL(key), Z_STRLEN(key)+1, value); @@ -1503,7 +1512,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, save){ else { array_init(data); } - + PHALCON_INIT_NVAR(status); if (PHALCON_IS_FALSE(mode)){ @@ -1546,8 +1555,8 @@ PHP_METHOD(Phalcon_Mvc_Collection, save){ } zval_ptr_dtor(&data); - - /** + + /** * Call the postSave hooks */ PHALCON_RETURN_CALL_METHOD(this_ptr, "_postsave", disable_events, success, exists); @@ -1570,22 +1579,22 @@ PHP_METHOD(Phalcon_Mvc_Collection, findById){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &id); - + if (Z_TYPE_P(id) != IS_OBJECT) { - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&collection_manager, collection, "getcollectionmanager"); - - /** + + /** * Check if the collection use implicit ids */ PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", collection); @@ -1602,11 +1611,11 @@ PHP_METHOD(Phalcon_Mvc_Collection, findById){ } else { PHALCON_CPY_WRT(mongo_id, id); } - + PHALCON_INIT_VAR(conditions); array_init_size(conditions, 1); phalcon_array_update_string(&conditions, SL("_id"), mongo_id, PH_COPY); - + PHALCON_INIT_VAR(parameters); array_init_size(parameters, 1); phalcon_array_append(¶meters, conditions, 0); @@ -1650,28 +1659,28 @@ PHP_METHOD(Phalcon_Mvc_Collection, findFirst){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for findFirst"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); unique = PHALCON_GLOBAL(z_true); @@ -1726,30 +1735,30 @@ PHP_METHOD(Phalcon_Mvc_Collection, find){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for find"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + unique = PHALCON_GLOBAL(z_false); PHALCON_RETURN_CALL_SELF("_getresultset", parameters, collection, connection, unique); RETURN_MM(); @@ -1773,28 +1782,28 @@ PHP_METHOD(Phalcon_Mvc_Collection, count){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, ¶meters); - + if (!parameters) { parameters = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for count"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); PHALCON_RETURN_CALL_SELF("_getgroupresultset", parameters, collection, connection); RETURN_MM(); @@ -1815,32 +1824,32 @@ PHP_METHOD(Phalcon_Mvc_Collection, aggregate){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, ¶meters); - + if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for aggregate"); return; } } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); PHALCON_RETURN_CALL_METHOD(collection, "aggregate", parameters); RETURN_MM(); @@ -1865,54 +1874,54 @@ PHP_METHOD(Phalcon_Mvc_Collection, summatory){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 2, &field, &conditions, &finalize); - + if (!conditions) { conditions = PHALCON_GLOBAL(z_null); } - + if (!finalize) { finalize = PHALCON_GLOBAL(z_null); } - + if (Z_TYPE_P(field) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid field name for group"); return; } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); - + PHALCON_CALL_METHOD(&source, collection, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - + PHALCON_INIT_VAR(keys); array_init(keys); - + PHALCON_INIT_VAR(empty_array); array_init(empty_array); - - /** + + /** * Uses a javascript hash to group the results */ PHALCON_INIT_VAR(initial); array_init_size(initial, 1); phalcon_array_update_string(&initial, SL("summatory"), empty_array, PH_COPY); - - /** + + /** * Uses a javascript hash to group the results, however this is slow with larger * datasets */ @@ -1921,11 +1930,11 @@ PHP_METHOD(Phalcon_Mvc_Collection, summatory){ PHALCON_CALL_METHOD(&group, collection, "group", keys, initial, reduce); if (phalcon_array_isset_string(group, SS("retval"))) { - + PHALCON_OBS_VAR(retval); phalcon_array_fetch_string(&retval, group, SL("retval"), PH_NOISY); if (phalcon_array_isset_long(retval, 0)) { - + PHALCON_OBS_VAR(first_retval); phalcon_array_fetch_long(&first_retval, retval, 0, PH_NOISY); if (phalcon_array_isset_string(first_retval, SS("summatory"))) { @@ -1933,13 +1942,13 @@ PHP_METHOD(Phalcon_Mvc_Collection, summatory){ phalcon_array_fetch_string(&summatory, first_retval, SL("summatory"), PH_NOISY); RETURN_CTOR(summatory); } - + RETURN_CTOR(first_retval); } - + RETURN_CTOR(retval); } - + PHALCON_MM_RESTORE(); } @@ -1959,7 +1968,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, create){ if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } @@ -1986,7 +1995,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, update){ if (!data) { data = PHALCON_GLOBAL(z_null); } - + if (!white_list) { white_list = PHALCON_GLOBAL(z_null); } @@ -1996,33 +2005,33 @@ PHP_METHOD(Phalcon_Mvc_Collection, update){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - - /** + + /** * Choose a collection according to the collection name */ PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); - - /** + + /** * Check the dirty state of the current operation to update the current operation */ PHALCON_CALL_METHOD(&exists, this_ptr, "_exists", collection); - /** + /** * If the record already exists we must throw an exception */ - if (!zend_is_true(exists)) { + if (!zend_is_true(exists)) { PHALCON_INIT_VAR(type); ZVAL_STRING(type, "InvalidUpdateAttempt", 1); - + PHALCON_INIT_VAR(message); ZVAL_STRING(message, "Document cannot be updated because it does not exist", 1); - + PHALCON_INIT_VAR(collection_message); object_init_ex(collection_message, phalcon_mvc_collection_message_ce); PHALCON_CALL_METHOD(NULL, collection_message, "__construct", message, PHALCON_GLOBAL(z_null), type); - + PHALCON_INIT_VAR(messages); array_init_size(messages, 1); phalcon_array_append(&messages, collection_message, PH_SEPARATE); @@ -2063,31 +2072,31 @@ PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The document cannot be deleted because it doesn't exist"); return; } - + disable_events = phalcon_fetch_static_property_ce(phalcon_mvc_collection_ce, SL("_disableEvents") TSRMLS_CC); if (!zend_is_true(disable_events)) { - + PHALCON_INIT_VAR(event_name); ZVAL_STRING(event_name, "beforeDelete", 1); - + PHALCON_CALL_METHOD(&status, this_ptr, "fireeventcancel", event_name); if (PHALCON_IS_FALSE(status)) { RETURN_MM_FALSE; } } - + PHALCON_OBS_VAR(id); phalcon_read_property_this(&id, this_ptr, SL("_id"), PH_NOISY TSRMLS_CC); - + PHALCON_CALL_METHOD(&connection, this_ptr, "getconnection"); - + PHALCON_CALL_METHOD(&source, this_ptr, "getsource"); if (PHALCON_IS_EMPTY(source)) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } - - /** + + /** * Get the \MongoCollection */ PHALCON_CALL_METHOD(&collection, connection, "selectcollection", source); @@ -2096,8 +2105,8 @@ PHP_METHOD(Phalcon_Mvc_Collection, delete){ } else { PHALCON_OBS_VAR(collection_manager); phalcon_read_property_this(&collection_manager, this_ptr, SL("_collectionManager"), PH_NOISY TSRMLS_CC); - - /** + + /** * Is the collection using implicit object Ids? */ PHALCON_CALL_METHOD(&use_implicit_ids, collection_manager, "isusingimplicitobjectids", this_ptr); @@ -2112,35 +2121,35 @@ PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_CPY_WRT(mongo_id, id); } } - + PHALCON_INIT_VAR(id_condition); array_init_size(id_condition, 1); phalcon_array_update_string(&id_condition, SL("_id"), mongo_id, PH_COPY); - + PHALCON_INIT_VAR(success); ZVAL_BOOL(success, 0); - + PHALCON_INIT_VAR(options); array_init_size(options, 1); add_assoc_long_ex(options, SS("w"), 1); - - /** + + /** * Remove the instance */ PHALCON_CALL_METHOD(&status, collection, "remove", id_condition, options); - if (Z_TYPE_P(status) != IS_ARRAY) { + if (Z_TYPE_P(status) != IS_ARRAY) { RETURN_MM_FALSE; } - - /** + + /** * Check the operation status */ if (phalcon_array_isset_string(status, SS("ok"))) { - + PHALCON_OBS_VAR(ok); phalcon_array_fetch_string(&ok, status, SL("ok"), PH_NOISY); if (zend_is_true(ok)) { - + ZVAL_BOOL(success, 1); if (!zend_is_true(disable_events)) { PHALCON_INIT_NVAR(event_name); @@ -2152,7 +2161,7 @@ PHP_METHOD(Phalcon_Mvc_Collection, delete){ PHALCON_INIT_NVAR(success); ZVAL_BOOL(success, 0); } - + RETURN_NCTOR(success); } @@ -2176,26 +2185,26 @@ PHP_METHOD(Phalcon_Mvc_Collection, toArray){ PHALCON_INIT_VAR(data); array_init(data); - + PHALCON_CALL_METHOD(&reserved, this_ptr, "getreservedattributes"); - - /** + + /** * Get an array with the values of the object */ PHALCON_CALL_FUNCTION(&properties, "get_object_vars", this_ptr); - - /** + + /** * We only assign values to the public properties */ phalcon_is_iterable(properties, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + if (PHALCON_IS_STRING(key, "_id")) { - + if (Z_TYPE_P(value) != IS_NULL) { phalcon_array_update_zval(&data, key, value, PH_COPY); } @@ -2204,10 +2213,10 @@ PHP_METHOD(Phalcon_Mvc_Collection, toArray){ phalcon_array_update_zval(&data, key, value, PH_COPY); } } - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_CTOR(data); } @@ -2223,8 +2232,8 @@ PHP_METHOD(Phalcon_Mvc_Collection, serialize){ PHALCON_MM_GROW(); PHALCON_CALL_METHOD(&data, this_ptr, "toarray"); - - /** + + /** * Use the standard serialize function to serialize the array data */ phalcon_serialize(return_value, &data TSRMLS_CC); @@ -2247,34 +2256,34 @@ PHP_METHOD(Phalcon_Mvc_Collection, unserialize){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &data); - + if (Z_TYPE_P(data) == IS_STRING) { - + PHALCON_INIT_VAR(attributes); phalcon_unserialize(attributes, data TSRMLS_CC); - if (Z_TYPE_P(attributes) == IS_ARRAY) { - - /** + if (Z_TYPE_P(attributes) == IS_ARRAY) { + + /** * Obtain the default DI */ PHALCON_CALL_CE_STATIC(&dependency_injector, phalcon_di_ce, "getdefault"); - + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A dependency injector container is required to obtain the services related to the ODM"); return; } - - /** + + /** * Update the dependency injector */ phalcon_update_property_this(this_ptr, SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - - /** + + /** * Gets the default collectionManager service */ PHALCON_INIT_VAR(service); ZVAL_STRING(service, "collectionManager", 1); - + PHALCON_CALL_METHOD(&manager, dependency_injector, "getshared", service); if (Z_TYPE_P(manager) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The injected service 'collectionManager' is not valid"); @@ -2282,27 +2291,27 @@ PHP_METHOD(Phalcon_Mvc_Collection, unserialize){ } PHALCON_VERIFY_INTERFACE(manager, phalcon_mvc_collection_managerinterface_ce); - - /** + + /** * Update the collection manager */ phalcon_update_property_this(this_ptr, SL("_collectionManager"), manager TSRMLS_CC); - - /** + + /** * Update the objects attributes */ phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - + PHALCON_GET_HKEY(key, ah0, hp0); PHALCON_GET_HVALUE(value); - + phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); - + zend_hash_move_forward_ex(ah0, &hp0); } - + RETURN_MM_NULL(); } } @@ -2332,22 +2341,22 @@ PHP_METHOD(Phalcon_Mvc_Collection, execute){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &code, &args); - - if (args && Z_TYPE_P(args) != IS_ARRAY) { + + if (args && Z_TYPE_P(args) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid args for execute"); return; } - + PHALCON_INIT_VAR(class_name); phalcon_get_called_class(class_name TSRMLS_CC); ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - + PHALCON_INIT_VAR(collection); object_init_ex(collection, ce0); if (phalcon_has_constructor(collection TSRMLS_CC)) { PHALCON_CALL_METHOD(NULL, collection, "__construct"); } - + PHALCON_CALL_METHOD(&connection, collection, "getconnection"); if (args) { diff --git a/ext/mvc/model.c b/ext/mvc/model.c index cf3217c3bcf..b9c79d24f75 100644 --- a/ext/mvc/model.c +++ b/ext/mvc/model.c @@ -6796,13 +6796,6 @@ PHP_METHOD(Phalcon_Mvc_Model, toArray){ PHALCON_GET_HVALUE(attribute); - if (columns && Z_TYPE_P(columns) == IS_ARRAY) { - if (!phalcon_fast_in_array(attribute, columns TSRMLS_CC)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - /** * Check if the columns must be renamed */ @@ -6819,6 +6812,14 @@ PHP_METHOD(Phalcon_Mvc_Model, toArray){ } else { PHALCON_CPY_WRT(attribute_field, attribute); } + + if (columns && Z_TYPE_P(columns) == IS_ARRAY) { + if (!phalcon_fast_in_array(attribute_field, columns TSRMLS_CC) && !phalcon_fast_in_array(attribute, columns TSRMLS_CC)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } + if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY TSRMLS_CC); diff --git a/ext/mvc/model/criteria.c b/ext/mvc/model/criteria.c index 61bf553e5ef..52c15c9bd91 100644 --- a/ext/mvc/model/criteria.c +++ b/ext/mvc/model/criteria.c @@ -1109,7 +1109,7 @@ PHP_METHOD(Phalcon_Mvc_Model_Criteria, notInWhere){ * Adds the conditions parameter to the criteria * * @param string $conditions - * @return Phalcon\Mvc\Model\CriteriaIntreface + * @return Phalcon\Mvc\Model\CriteriaInterface */ PHP_METHOD(Phalcon_Mvc_Model_Criteria, conditions){ diff --git a/ext/mvc/view/engine/volt/compiler.c b/ext/mvc/view/engine/volt/compiler.c index 49b36e38a4c..84916a66e30 100644 --- a/ext/mvc/view/engine/volt/compiler.c +++ b/ext/mvc/view/engine/volt/compiler.c @@ -936,7 +936,7 @@ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall){ phalcon_read_property_this(&array_helpers, this_ptr, SL("_arrayHelpers"), PH_NOISY TSRMLS_CC); if (Z_TYPE_P(array_helpers) != IS_ARRAY) { PHALCON_INIT_NVAR(array_helpers); - array_init_size(array_helpers, 16); + array_init_size(array_helpers, 17); add_assoc_bool_ex(array_helpers, SS("link_to"), 1); add_assoc_bool_ex(array_helpers, SS("image"), 1); add_assoc_bool_ex(array_helpers, SS("form"), 1); @@ -953,6 +953,7 @@ PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall){ add_assoc_bool_ex(array_helpers, SS("date_field"), 1); add_assoc_bool_ex(array_helpers, SS("numeric_field"), 1); add_assoc_bool_ex(array_helpers, SS("email_field"), 1); + add_assoc_bool_ex(array_helpers, SS("image_input"), 1); phalcon_update_property_this(this_ptr, SL("_arrayHelpers"), array_helpers TSRMLS_CC); } diff --git a/ext/paginator/adapter/querybuilder.c b/ext/paginator/adapter/querybuilder.c index 9698e4679b4..69e91c75c44 100644 --- a/ext/paginator/adapter/querybuilder.c +++ b/ext/paginator/adapter/querybuilder.c @@ -324,8 +324,8 @@ PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate){ PHALCON_CALL_METHOD(&models, builder, "getfrom"); if (Z_TYPE_P(models) == IS_ARRAY) { - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); + PHALCON_INIT_VAR(model_name); + phalcon_array_get_current(model_name, models); } else { PHALCON_CPY_WRT(model_name, models); } diff --git a/ext/php_phalcon.h b/ext/php_phalcon.h index ee2dcbe1d55..0deb4ad5733 100644 --- a/ext/php_phalcon.h +++ b/ext/php_phalcon.h @@ -29,7 +29,7 @@ #include #endif -#define PHP_PHALCON_VERSION "1.3.3" +#define PHP_PHALCON_VERSION "1.3.4" #define PHP_PHALCON_EXTNAME "phalcon" #define PHALCON_NUM_PREALLOCATED_FRAMES 25 diff --git a/ext/tag.c b/ext/tag.c index b437dbb2320..58135446112 100644 --- a/ext/tag.c +++ b/ext/tag.c @@ -582,18 +582,40 @@ PHP_METHOD(Phalcon_Tag, setDefault){ * * * @param array $values + * @param boolean $merge */ PHP_METHOD(Phalcon_Tag, setDefaults){ - zval *values; + zval *values, *merge = NULL, *display_values, *merged_values = NULL;; - phalcon_fetch_params(0, 1, 0, &values); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &values, &merge); + + if (!merge) { + merge = PHALCON_GLOBAL(z_false); + } if (Z_TYPE_P(values) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_tag_exception_ce, "An array is required as default values"); return; } - phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + + if (zend_is_true(merge)) { + + display_values = phalcon_fetch_static_property_ce(phalcon_tag_ce, SL("_displayValues") TSRMLS_CC); + if (Z_TYPE_P(display_values) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_values); + phalcon_fast_array_merge(merged_values, &display_values, &values TSRMLS_CC); + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), merged_values TSRMLS_CC); + } else { + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + } + } else { + phalcon_update_static_property_ce(phalcon_tag_ce, SL("_displayValues"), values TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); } diff --git a/ext/version.c b/ext/version.c index 567ecef1daa..ad80ccfa627 100644 --- a/ext/version.c +++ b/ext/version.c @@ -70,7 +70,7 @@ PHP_METHOD(Phalcon_Version, _getVersion){ array_init_size(return_value, 5); add_next_index_long(return_value, 1); add_next_index_long(return_value, 3); - add_next_index_long(return_value, 3); + add_next_index_long(return_value, 4); add_next_index_long(return_value, PHALCON_VERSION_STABLE); add_next_index_long(return_value, 1); }