diff --git a/.travis.yml b/.travis.yml index 688611b657a..6d1234fb6f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,4 +35,4 @@ notifications: email: - andres@phalconphp.com - eduar@phalconphp.com - - nikos@phalconphp.com + - nikos@phalconphp.com \ No newline at end of file diff --git a/build/32bits/phalcon.c b/build/32bits/phalcon.c index a281448a0dc..820e912cc92 100644 --- a/build/32bits/phalcon.c +++ b/build/32bits/phalcon.c @@ -2554,7 +2554,7 @@ static int PHALCON_FASTCALL phalcon_memory_restore_stack(TSRMLS_D) { } } - for (i=0; ihash_pointer; ++i) { + for (i = 0; i < active_memory->hash_pointer; ++i) { if (Z_REFCOUNT_PP(active_memory->hash_addresses[i]) <= 1) { ZVAL_NULL(*active_memory->hash_addresses[i]); } else { @@ -2562,7 +2562,7 @@ static int PHALCON_FASTCALL phalcon_memory_restore_stack(TSRMLS_D) { } } - for (i=0; ipointer; ++i) { + for (i = 0; i < active_memory->pointer; ++i) { if (likely(active_memory->addresses[i] != NULL)) { if (Z_REFCOUNT_PP(active_memory->addresses[i]) == 1) { zval_ptr_dtor(active_memory->addresses[i]); @@ -2598,9 +2598,13 @@ static int PHALCON_FASTCALL phalcon_memory_restore_stack(TSRMLS_D) { return SUCCESS; } -static int PHALCON_FASTCALL phalcon_clean_shutdown_stack(TSRMLS_D) { - +static int PHALCON_FASTCALL phalcon_clean_shutdown_stack(TSRMLS_D) +{ + #if !ZEND_DEBUG && PHP_VERSION_ID <= 50400 return phalcon_clean_restore_stack(TSRMLS_C); + #else + return SUCCESS; + #endif } static void phalcon_reallocate_memory(phalcon_memory_entry *frame) @@ -11981,1331 +11985,919 @@ static void phalcon_raw_url_encode(zval *return_value, zval *url) { +PHALCON_INIT_CLASS(Phalcon_Acl_Adapter_Memory){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Acl\\Adapter, Memory, acl_adapter_memory, "phalcon\\acl\\adapter", phalcon_acl_adapter_memory_method_entry, 0); -PHALCON_INIT_CLASS(Phalcon_Http_Request){ - - PHALCON_REGISTER_CLASS(Phalcon\\Http, Request, http_request, phalcon_http_request_method_entry, 0); - - zend_declare_property_null(phalcon_http_request_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_request_ce, SL("_filter"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_rolesNames"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_roles"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_resourcesNames"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_resources"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_access"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_roleInherits"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_accessList"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_http_request_ce TSRMLS_CC, 2, phalcon_http_requestinterface_ce, phalcon_di_injectionawareinterface_ce); + zend_class_implements(phalcon_acl_adapter_memory_ce TSRMLS_CC, 1, phalcon_acl_adapterinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Http_Request, setDI){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, __construct){ - zval *dependency_injector; + zval *ztrue, *resources_names, *access_list; - phalcon_fetch_params(0, 1, 0, &dependency_injector); + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(ztrue); + ZVAL_BOOL(ztrue, 1); - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + PHALCON_INIT_VAR(resources_names); + array_init_size(resources_names, 1); + phalcon_array_update_string(&resources_names, SL("*"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_resourcesNames"), resources_names, 2424408563UL TSRMLS_CC); + PHALCON_INIT_VAR(access_list); + array_init_size(access_list, 1); + phalcon_array_update_string(&access_list, SL("*!*"), &ztrue, PH_COPY | PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_accessList"), access_list, 2206680658UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Http_Request, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -static PHP_METHOD(Phalcon_Http_Request, get){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addRole){ - zval *name = NULL, *filters = NULL, *default_value = NULL, *request = NULL; - zval *_REQUEST, *value, *filter = NULL, *dependency_injector; - zval *service; + zval *role, *access_inherits = NULL, *role_name = NULL, *object = NULL; + zval *roles_names, *exists, *default_access; + zval *key; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 3, &name, &filters, &default_value); - - if (!name) { - PHALCON_INIT_VAR(name); - } - - if (!filters) { - PHALCON_INIT_VAR(filters); - } + phalcon_fetch_params(1, 1, 1, &role, &access_inherits); - if (!default_value) { - PHALCON_INIT_VAR(default_value); + if (!access_inherits) { + PHALCON_INIT_VAR(access_inherits); } - phalcon_get_global(&_REQUEST, SS("_REQUEST") TSRMLS_CC); - PHALCON_CPY_WRT(request, _REQUEST); - if (Z_TYPE_P(name) != IS_NULL) { - if (phalcon_array_isset(request, name)) { - - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, request, name, PH_NOISY); - if (Z_TYPE_P(filters) != IS_NULL) { + if (Z_TYPE_P(role) == IS_OBJECT) { + PHALCON_INIT_VAR(role_name); + phalcon_call_method_key(role_name, role, "getname", 4286441094UL); + PHALCON_CPY_WRT(object, role); + } else { + PHALCON_CPY_WRT(role_name, role); - PHALCON_OBS_VAR(filter); - phalcon_read_property_this_quick(&filter, this_ptr, SL("_filter"), 3500594986UL, PH_NOISY_CC); - if (Z_TYPE_P(filter) != IS_OBJECT) { + PHALCON_INIT_NVAR(object); + object_init_ex(object, phalcon_acl_role_ce); + phalcon_call_method_p1_key(NULL, object, "__construct", role, 1107214344UL); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service"); - return; - } + } - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "filter", 1); + PHALCON_OBS_VAR(roles_names); + phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC); + if (phalcon_array_isset(roles_names, role_name)) { + RETURN_MM_FALSE; + } - PHALCON_INIT_NVAR(filter); - phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); - } + PHALCON_INIT_VAR(exists); + ZVAL_BOOL(exists, 1); + phalcon_update_property_array_append(this_ptr, SL("_roles"), object TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_rolesNames"), role_name, exists TSRMLS_CC); - phalcon_call_method_p2_key(return_value, filter, "sanitize", value, filters, 3688332940UL); - RETURN_MM(); - } else { - RETURN_CCTOR(value); - } - } + PHALCON_OBS_VAR(default_access); + phalcon_read_property_this_quick(&default_access, this_ptr, SL("_defaultAccess"), 875397115UL, PH_NOISY_CC); - RETURN_CCTOR(default_value); + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_VS(key, role_name, "!*!*"); + phalcon_update_property_array(this_ptr, SL("_access"), key, default_access TSRMLS_CC); + if (Z_TYPE_P(access_inherits) != IS_NULL) { + phalcon_call_method_p2_key(return_value, this_ptr, "addinherit", role_name, access_inherits, 2093626145UL); + RETURN_MM(); } - RETURN_CCTOR(request); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Http_Request, getPost){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addInherit){ - zval *name = NULL, *filters = NULL, *default_value = NULL, *post = NULL, *_POST; - zval *value, *filter = NULL, *dependency_injector, *service; + zval *role_name, *role_to_inherit, *roles_names; + zval *exception_message = NULL, *role_inherit_name = NULL; + zval *roles_inherits, *empty_arr, *_roleInherits; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 3, &name, &filters, &default_value); + phalcon_fetch_params(1, 2, 0, &role_name, &role_to_inherit); - if (!name) { - PHALCON_INIT_VAR(name); + PHALCON_OBS_VAR(roles_names); + phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC); + if (!phalcon_array_isset(roles_names, role_name)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Role '", role_name, "' does not exist in the role list"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); + return; } - if (!filters) { - PHALCON_INIT_VAR(filters); + if (Z_TYPE_P(role_to_inherit) == IS_OBJECT) { + PHALCON_INIT_VAR(role_inherit_name); + phalcon_call_method_key(role_inherit_name, role_to_inherit, "getname", 4286441094UL); + } else { + PHALCON_CPY_WRT(role_inherit_name, role_to_inherit); } - if (!default_value) { - PHALCON_INIT_VAR(default_value); + if (!phalcon_array_isset(roles_names, role_inherit_name)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Role '", role_inherit_name, "' (to inherit) does not exist in the role list"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); + return; } - phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); - PHALCON_CPY_WRT(post, _POST); - if (Z_TYPE_P(name) != IS_NULL) { - if (phalcon_array_isset(post, name)) { - - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, post, name, PH_NOISY); - if (Z_TYPE_P(filters) != IS_NULL) { - - PHALCON_OBS_VAR(filter); - phalcon_read_property_this_quick(&filter, this_ptr, SL("_filter"), 3500594986UL, PH_NOISY_CC); - if (Z_TYPE_P(filter) != IS_OBJECT) { - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service"); - return; - } - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "filter", 1); - - PHALCON_INIT_NVAR(filter); - phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); - } - - phalcon_call_method_p2_key(return_value, filter, "sanitize", value, filters, 3688332940UL); - RETURN_MM(); - } else { - RETURN_CCTOR(value); - } - } + if (PHALCON_IS_EQUAL(role_inherit_name, role_name)) { + RETURN_MM_FALSE; + } - RETURN_CCTOR(default_value); + PHALCON_OBS_VAR(roles_inherits); + phalcon_read_property_this_quick(&roles_inherits, this_ptr, SL("_roleInherits"), 1806479324UL, PH_NOISY_CC); + if (!phalcon_array_isset(roles_inherits, role_name)) { + PHALCON_INIT_VAR(empty_arr); + array_init(empty_arr); + phalcon_update_property_array(this_ptr, SL("_roleInherits"), role_name, empty_arr TSRMLS_CC); } - RETURN_CCTOR(post); + PHALCON_OBS_VAR(_roleInherits); + phalcon_read_property_this_quick(&_roleInherits, this_ptr, SL("_roleInherits"), 1806479324UL, PH_NOISY_CC); + phalcon_array_update_append_multi_2(&_roleInherits, role_name, role_inherit_name, 0); + phalcon_update_property_this_quick(this_ptr, SL("_roleInherits"), _roleInherits, 1806479324UL TSRMLS_CC); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Http_Request, getQuery){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isRole){ - zval *name = NULL, *filters = NULL, *default_value = NULL, *get = NULL, *_GET; - zval *value, *filter = NULL, *dependency_injector, *service; + zval *role_name, *roles_names; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 3, &name, &filters, &default_value); - - if (!name) { - PHALCON_INIT_VAR(name); - } - - if (!filters) { - PHALCON_INIT_VAR(filters); - } - - if (!default_value) { - PHALCON_INIT_VAR(default_value); - } - - phalcon_get_global(&_GET, SS("_GET") TSRMLS_CC); - PHALCON_CPY_WRT(get, _GET); - if (Z_TYPE_P(name) != IS_NULL) { - if (phalcon_array_isset(get, name)) { - - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, get, name, PH_NOISY); - if (Z_TYPE_P(filters) != IS_NULL) { - - PHALCON_OBS_VAR(filter); - phalcon_read_property_this_quick(&filter, this_ptr, SL("_filter"), 3500594986UL, PH_NOISY_CC); - if (Z_TYPE_P(filter) != IS_OBJECT) { - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service"); - return; - } - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "filter", 1); - - PHALCON_INIT_NVAR(filter); - phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); - } - - phalcon_call_method_p2_key(return_value, filter, "sanitize", value, filters, 3688332940UL); - RETURN_MM(); - } else { - RETURN_CCTOR(value); - } - } + phalcon_fetch_params(1, 1, 0, &role_name); - RETURN_CCTOR(default_value); + PHALCON_OBS_VAR(roles_names); + phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC); + if (phalcon_array_isset(roles_names, role_name)) { + RETURN_MM_TRUE; } - RETURN_CCTOR(get); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Http_Request, getServer){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isResource){ - zval *name, *_SERVER, *server_value; + zval *resource_name, *resources_names; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); + phalcon_fetch_params(1, 1, 0, &resource_name); - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - if (phalcon_array_isset(_SERVER, name)) { - PHALCON_OBS_VAR(server_value); - phalcon_array_fetch(&server_value, _SERVER, name, PH_NOISY); - RETURN_CCTOR(server_value); + PHALCON_OBS_VAR(resources_names); + phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC); + if (phalcon_array_isset(resources_names, resource_name)) { + RETURN_MM_TRUE; } - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Http_Request, has){ - - zval *name, *_REQUEST; - - phalcon_fetch_params(0, 1, 0, &name); - phalcon_get_global(&_REQUEST, SS("_REQUEST") TSRMLS_CC); - if (phalcon_array_isset(_REQUEST, name)) { - RETURN_TRUE; - } - RETURN_FALSE; + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Http_Request, hasPost){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResource){ - zval *name, *_POST; + zval *resource, *access_list = NULL, *resource_name = NULL; + zval *object = NULL, *resources_names, *exists; - phalcon_fetch_params(0, 1, 0, &name); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &resource, &access_list); - phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); - if (phalcon_array_isset(_POST, name)) { - RETURN_TRUE; + if (!access_list) { + PHALCON_INIT_VAR(access_list); } - RETURN_FALSE; -} - -static PHP_METHOD(Phalcon_Http_Request, hasQuery){ - - zval *name, *_GET; - - phalcon_fetch_params(0, 1, 0, &name); - phalcon_get_global(&_GET, SS("_GET") TSRMLS_CC); - if (phalcon_array_isset(_GET, name)) { - RETURN_TRUE; + if (Z_TYPE_P(resource) == IS_OBJECT) { + PHALCON_INIT_VAR(resource_name); + phalcon_call_method_key(resource_name, resource, "getname", 4286441094UL); + PHALCON_CPY_WRT(object, resource); + } else { + PHALCON_CPY_WRT(resource_name, resource); + + PHALCON_INIT_NVAR(object); + object_init_ex(object, phalcon_acl_resource_ce); + phalcon_call_method_p1_key(NULL, object, "__construct", resource_name, 1107214344UL); + } - RETURN_FALSE; -} - -static PHP_METHOD(Phalcon_Http_Request, hasServer){ - - zval *name, *_SERVER; - - phalcon_fetch_params(0, 1, 0, &name); - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - if (phalcon_array_isset(_SERVER, name)) { - RETURN_TRUE; + PHALCON_OBS_VAR(resources_names); + phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC); + if (!phalcon_array_isset(resources_names, resource_name)) { + PHALCON_INIT_VAR(exists); + ZVAL_BOOL(exists, 1); + phalcon_update_property_array_append(this_ptr, SL("_resources"), object TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_resourcesNames"), resource_name, exists TSRMLS_CC); } - RETURN_FALSE; + + phalcon_call_method_p2_key(return_value, this_ptr, "addresourceaccess", resource_name, access_list, 3379195048UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Http_Request, getHeader){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResourceAccess){ - zval *header, *_SERVER, *server_value = NULL, *key; + zval *resource_name, *access_list, *resources_names; + zval *exception_message, *exists, *internal_access_list; + zval *access_name = NULL, *access_key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &header); + phalcon_fetch_params(1, 2, 0, &resource_name, &access_list); - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - if (phalcon_array_isset(_SERVER, header)) { - PHALCON_OBS_VAR(server_value); - phalcon_array_fetch(&server_value, _SERVER, header, PH_NOISY); - RETURN_CCTOR(server_value); - } else { - PHALCON_INIT_VAR(key); - PHALCON_CONCAT_SV(key, "HTTP_", header); - if (phalcon_array_isset(_SERVER, key)) { - PHALCON_OBS_NVAR(server_value); - phalcon_array_fetch(&server_value, _SERVER, key, PH_NOISY); - RETURN_CCTOR(server_value); - } + PHALCON_OBS_VAR(resources_names); + phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC); + if (!phalcon_array_isset(resources_names, resource_name)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource '", resource_name, "' does not exist in ACL"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); + return; } - RETURN_MM_EMPTY_STRING(); -} - -static PHP_METHOD(Phalcon_Http_Request, getScheme){ - - zval *https_header, *https, *scheme = NULL; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(https_header); - ZVAL_STRING(https_header, "HTTPS", 1); - PHALCON_INIT_VAR(https); - phalcon_call_method_p1_key(https, this_ptr, "getserver", https_header, 1630469020UL); - if (zend_is_true(https)) { - if (PHALCON_IS_STRING(https, "off")) { - PHALCON_INIT_VAR(scheme); - ZVAL_STRING(scheme, "http", 1); - } else { - PHALCON_INIT_NVAR(scheme); - ZVAL_STRING(scheme, "https", 1); + PHALCON_INIT_VAR(exists); + ZVAL_BOOL(exists, 1); + + PHALCON_OBS_VAR(internal_access_list); + phalcon_read_property_this_quick(&internal_access_list, this_ptr, SL("_accessList"), 2206680658UL, PH_NOISY_CC); + if (Z_TYPE_P(access_list) == IS_ARRAY) { + + phalcon_is_iterable(access_list, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(access_name); + + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name); + if (!phalcon_array_isset(internal_access_list, access_key)) { + phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, exists TSRMLS_CC); + } + + zend_hash_move_forward_ex(ah0, &hp0); } + } else { - PHALCON_INIT_NVAR(scheme); - ZVAL_STRING(scheme, "http", 1); + if (Z_TYPE_P(access_list) == IS_STRING) { + + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_list); + if (!phalcon_array_isset(internal_access_list, access_key)) { + phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, exists TSRMLS_CC); + } + } } - RETURN_CTOR(scheme); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Http_Request, isAjax){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, dropResourceAccess){ - zval *requested_header, *xml_http_request; - zval *requested_with; + zval *resource_name, *access_list, *access_name = NULL; + zval *access_key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(requested_header); - ZVAL_STRING(requested_header, "HTTP_X_REQUESTED_WITH", 1); + phalcon_fetch_params(1, 2, 0, &resource_name, &access_list); - PHALCON_INIT_VAR(xml_http_request); - ZVAL_STRING(xml_http_request, "XMLHttpRequest", 1); + if (Z_TYPE_P(access_list) == IS_ARRAY) { - PHALCON_INIT_VAR(requested_with); - phalcon_call_method_p1_key(requested_with, this_ptr, "getheader", requested_header, 288415726UL); - is_equal_function(return_value, requested_with, xml_http_request TSRMLS_CC); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Http_Request, isSoapRequested){ - - zval *server = NULL, *_SERVER, *content_type; - - PHALCON_MM_GROW(); - - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - PHALCON_CPY_WRT(server, _SERVER); - if (phalcon_array_isset_quick_string(server, SS("HTTP_SOAPACTION"), 1001189845UL)) { - RETURN_MM_TRUE; - } else { - if (phalcon_array_isset_quick_string(server, SS("CONTENT_TYPE"), 3407676833UL)) { + phalcon_is_iterable(access_list, &ah0, &hp0, 0, 0); - PHALCON_OBS_VAR(content_type); - phalcon_array_fetch_quick_string(&content_type, server, SS("CONTENT_TYPE"), 3407676833UL, PH_NOISY); - if (phalcon_memnstr_str(content_type, SL("application/soap+xml"))) { - RETURN_MM_TRUE; - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(access_name); + + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name); + phalcon_unset_property_array(this_ptr, SL("_accessList"), access_key TSRMLS_CC); + + zend_hash_move_forward_ex(ah0, &hp0); } + + } else { + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name); + phalcon_unset_property_array(this_ptr, SL("_accessList"), access_key TSRMLS_CC); } - RETURN_MM_FALSE; + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Http_Request, isSecureRequest){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, _allowOrDeny){ - zval *scheme, *https; + zval *role_name, *resource_name, *access, *action; + zval *roles_names, *exception_message = NULL, *resources_names; + zval *default_access, *access_list, *internal_access; + zval *access_name = NULL, *access_key = NULL, *access_key_all = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(scheme); - phalcon_call_method_key(scheme, this_ptr, "getscheme", 1539736378UL); + phalcon_fetch_params(1, 4, 0, &role_name, &resource_name, &access, &action); - PHALCON_INIT_VAR(https); - ZVAL_STRING(https, "https", 1); - is_identical_function(return_value, https, scheme TSRMLS_CC); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Http_Request, getRawBody){ - - if (SG(request_info).raw_post_data) { - RETURN_STRINGL(SG(request_info).raw_post_data, SG(request_info).raw_post_data_length, 1); + PHALCON_OBS_VAR(roles_names); + phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC); + if (!phalcon_array_isset(roles_names, role_name)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Role \"", role_name, "\" does not exist in ACL"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); + return; } - - if (sapi_module.read_post) { - int read_bytes; - char *buf = emalloc(8192); - smart_str raw_data = { NULL, 0, 0 }; - - while ((read_bytes = sapi_module.read_post(buf, 8192 TSRMLS_CC)) > 0) { - smart_str_appendl(&raw_data, buf, read_bytes); - SG(read_post_bytes) += read_bytes; + + PHALCON_OBS_VAR(resources_names); + phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC); + if (!phalcon_array_isset(resources_names, resource_name)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource \"", resource_name, "\" does not exist in ACL"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); + return; + } + + PHALCON_OBS_VAR(default_access); + phalcon_read_property_this_quick(&default_access, this_ptr, SL("_defaultAccess"), 875397115UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(access_list); + phalcon_read_property_this_quick(&access_list, this_ptr, SL("_accessList"), 2206680658UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(internal_access); + phalcon_read_property_this_quick(&internal_access, this_ptr, SL("_access"), 1092213014UL, PH_NOISY_CC); + if (Z_TYPE_P(access) == IS_ARRAY) { + + phalcon_is_iterable(access, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(access_name); + + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name); + if (!phalcon_array_isset(access_list, access_key)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVS(exception_message, "Acccess '", access_name, "' does not exist in resource '", resource_name, "'"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); + return; + } + + zend_hash_move_forward_ex(ah0, &hp0); } - - efree(buf); - if (raw_data.c) { - RETURN_STRINGL(raw_data.c, raw_data.len, 0); + + phalcon_is_iterable(access, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(access_name); + + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSVSV(access_key, role_name, "!", resource_name, "!", access_name); + phalcon_update_property_array(this_ptr, SL("_access"), access_key, action TSRMLS_CC); + if (!PHALCON_IS_STRING(access_name, "*")) { + + PHALCON_INIT_NVAR(access_key_all); + PHALCON_CONCAT_VSVS(access_key_all, role_name, "!", resource_name, "!*"); + if (!phalcon_array_isset(internal_access, access_key_all)) { + phalcon_update_property_array(this_ptr, SL("_access"), access_key_all, default_access TSRMLS_CC); + } + } + + zend_hash_move_forward_ex(ah1, &hp1); + } + + } else { + if (!PHALCON_IS_STRING(access, "*")) { + + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSV(access_key, resource_name, "!", access); + if (!phalcon_array_isset(access_list, access_key)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVS(exception_message, "Acccess '", access, "' does not exist in resource '", resource_name, "'"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); + return; + } + } + + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSVSV(access_key, role_name, "!", resource_name, "!", access); + + phalcon_update_property_array(this_ptr, SL("_access"), access_key, action TSRMLS_CC); + if (!PHALCON_IS_STRING(access, "*")) { + + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSVS(access_key, role_name, "!", resource_name, "!*"); + + if (!phalcon_array_isset(internal_access, access_key)) { + phalcon_update_property_array(this_ptr, SL("_access"), access_key, default_access TSRMLS_CC); + } } - } - - RETURN_EMPTY_STRING(); -} - -static PHP_METHOD(Phalcon_Http_Request, getJsonRawBody){ - - zval *raw_body; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(raw_body); - phalcon_call_method_key(raw_body, this_ptr, "getrawbody", 1898502173UL); - if (Z_TYPE_P(raw_body) == IS_STRING) { - phalcon_json_decode(return_value, raw_body, 0 TSRMLS_CC); - RETURN_MM(); } PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Http_Request, getServerAddress){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, allow){ - zval *server = NULL, *_SERVER, *server_addr, *localhost; + zval *role_name, *resource_name, *access, *action; PHALCON_MM_GROW(); - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - PHALCON_CPY_WRT(server, _SERVER); - if (phalcon_array_isset_quick_string(server, SS("SERVER_ADDR"), 3472224502UL)) { - PHALCON_OBS_VAR(server_addr); - phalcon_array_fetch_quick_string(&server_addr, server, SS("SERVER_ADDR"), 3472224502UL, PH_NOISY); - RETURN_CCTOR(server_addr); - } + phalcon_fetch_params(1, 3, 0, &role_name, &resource_name, &access); - PHALCON_INIT_VAR(localhost); - ZVAL_STRING(localhost, "localhost", 1); - phalcon_call_func_p1(return_value, "gethostbyname", localhost); + PHALCON_INIT_VAR(action); + ZVAL_LONG(action, 1); + phalcon_call_method_p4_key(return_value, this_ptr, "_allowordeny", role_name, resource_name, access, action, 726543028UL); RETURN_MM(); } -static PHP_METHOD(Phalcon_Http_Request, getServerName){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, deny){ - zval *server = NULL, *_SERVER, *server_name = NULL; + zval *role_name, *resource_name, *access, *action; PHALCON_MM_GROW(); - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - PHALCON_CPY_WRT(server, _SERVER); - if (phalcon_array_isset_quick_string(server, SS("SERVER_NAME"), 3487543036UL)) { - PHALCON_OBS_VAR(server_name); - phalcon_array_fetch_quick_string(&server_name, server, SS("SERVER_NAME"), 3487543036UL, PH_NOISY); - RETURN_CCTOR(server_name); - } - - PHALCON_INIT_NVAR(server_name); - ZVAL_STRING(server_name, "localhost", 1); + phalcon_fetch_params(1, 3, 0, &role_name, &resource_name, &access); - RETURN_CCTOR(server_name); + PHALCON_INIT_VAR(action); + ZVAL_LONG(action, 0); + phalcon_call_method_p4_key(return_value, this_ptr, "_allowordeny", role_name, resource_name, access, action, 726543028UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Http_Request, getHttpHost){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isAllowed){ - zval *host, *http_host, *scheme, *server_name, *name; - zval *server_port, *port, *http, *standard_port; - zval *is_std_name, *is_std_port, *is_std_http; - zval *https, *secure_port, *is_secure_scheme; - zval *is_secure_port, *is_secure_http; + zval *role, *resource, *access, *events_manager; + zval *event_name = NULL, *status, *default_access, *roles_names; + zval *have_access = NULL, *access_list, *access_key = NULL; + zval *role_inherits, *inherited_roles = NULL, *inherited_role = NULL; + HashTable *ah0, *ah1, *ah2; + HashPosition hp0, hp1, hp2; + zval **hd; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(host); - ZVAL_STRING(host, "HTTP_HOST", 1); + phalcon_fetch_params(1, 3, 0, &role, &resource, &access); - PHALCON_INIT_VAR(http_host); - phalcon_call_method_p1_key(http_host, this_ptr, "getserver", host, 1630469020UL); - if (zend_is_true(http_host)) { - RETURN_CCTOR(http_host); + phalcon_update_property_this_quick(this_ptr, SL("_activeRole"), role, 3079165426UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_activeResource"), resource, 1323587080UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_activeAccess"), access, 2176370066UL TSRMLS_CC); + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "acl:beforeCheckAccess", 1); + + PHALCON_INIT_VAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_CCTOR(status); + } } - PHALCON_INIT_VAR(scheme); - phalcon_call_method_key(scheme, this_ptr, "getscheme", 1539736378UL); + PHALCON_OBS_VAR(default_access); + phalcon_read_property_this_quick(&default_access, this_ptr, SL("_defaultAccess"), 875397115UL, PH_NOISY_CC); - PHALCON_INIT_VAR(server_name); - ZVAL_STRING(server_name, "SERVER_NAME", 1); + PHALCON_OBS_VAR(roles_names); + phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC); + if (!phalcon_array_isset(roles_names, role)) { + RETURN_CCTOR(default_access); + } - PHALCON_INIT_VAR(name); - phalcon_call_method_p1_key(name, this_ptr, "getserver", server_name, 1630469020UL); + PHALCON_INIT_VAR(have_access); - PHALCON_INIT_VAR(server_port); - ZVAL_STRING(server_port, "SERVER_PORT", 1); + PHALCON_OBS_VAR(access_list); + phalcon_read_property_this_quick(&access_list, this_ptr, SL("_access"), 1092213014UL, PH_NOISY_CC); - PHALCON_INIT_VAR(port); - phalcon_call_method_p1_key(port, this_ptr, "getserver", server_port, 1630469020UL); + PHALCON_INIT_VAR(access_key); + PHALCON_CONCAT_VSVSV(access_key, role, "!", resource, "!", access); - PHALCON_INIT_VAR(http); - ZVAL_STRING(http, "http", 1); + if (phalcon_array_isset(access_list, access_key)) { + PHALCON_OBS_NVAR(have_access); + phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); + } - PHALCON_INIT_VAR(standard_port); - ZVAL_LONG(standard_port, 80); + if (Z_TYPE_P(have_access) == IS_NULL) { - PHALCON_INIT_VAR(is_std_name); - is_equal_function(is_std_name, scheme, http TSRMLS_CC); + PHALCON_OBS_VAR(role_inherits); + phalcon_read_property_this_quick(&role_inherits, this_ptr, SL("_roleInherits"), 1806479324UL, PH_NOISY_CC); + if (phalcon_array_isset(role_inherits, role)) { + PHALCON_OBS_VAR(inherited_roles); + phalcon_array_fetch(&inherited_roles, role_inherits, role, PH_NOISY); + } else { + PHALCON_INIT_NVAR(inherited_roles); + } - PHALCON_INIT_VAR(is_std_port); - is_equal_function(is_std_port, port, standard_port TSRMLS_CC); + if (Z_TYPE_P(inherited_roles) == IS_ARRAY) { - PHALCON_INIT_VAR(is_std_http); - phalcon_and_function(is_std_http, is_std_name, is_std_port); + phalcon_is_iterable(inherited_roles, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(https); - ZVAL_STRING(https, "https", 1); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(secure_port); - ZVAL_LONG(secure_port, 443); + PHALCON_GET_HVALUE(inherited_role); - PHALCON_INIT_VAR(is_secure_scheme); - is_equal_function(is_secure_scheme, scheme, https TSRMLS_CC); + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSVSV(access_key, inherited_role, "!", resource, "!", access); - PHALCON_INIT_VAR(is_secure_port); - is_equal_function(is_secure_port, port, secure_port TSRMLS_CC); + if (phalcon_array_isset(access_list, access_key)) { + PHALCON_OBS_NVAR(have_access); + phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); + break; + } - PHALCON_INIT_VAR(is_secure_http); - phalcon_and_function(is_secure_http, is_secure_scheme, is_secure_port); + zend_hash_move_forward_ex(ah0, &hp0); + } - if (PHALCON_IS_TRUE(is_std_http)) { - RETURN_CCTOR(name); + } } - if (PHALCON_IS_TRUE(is_secure_http)) { - RETURN_CCTOR(name); - } + if (Z_TYPE_P(have_access) == IS_NULL) { - PHALCON_CONCAT_VSV(return_value, name, ":", port); + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSVS(access_key, role, "!", resource, "!*"); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Http_Request, getClientAddress){ - - zval *trust_forwarded_header = NULL, *address = NULL, *_SERVER; - zval *addresses, *first; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &trust_forwarded_header); + if (phalcon_array_isset(access_list, access_key)) { + PHALCON_OBS_NVAR(have_access); + phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); + } else { + if (Z_TYPE_P(inherited_roles) == IS_ARRAY) { - if (!trust_forwarded_header) { - PHALCON_INIT_VAR(trust_forwarded_header); - ZVAL_BOOL(trust_forwarded_header, 0); - } + phalcon_is_iterable(inherited_roles, &ah1, &hp1, 0, 0); - PHALCON_INIT_VAR(address); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - if (phalcon_array_isset_quick_string(_SERVER, SS("HTTP_X_FORWARDED_FOR"), 243594879UL)) { - if (zend_is_true(trust_forwarded_header)) { - PHALCON_OBS_NVAR(address); - phalcon_array_fetch_quick_string(&address, _SERVER, SS("HTTP_X_FORWARDED_FOR"), 243594879UL, PH_NOISY); - } - } + PHALCON_GET_HVALUE(inherited_role); - if (Z_TYPE_P(address) == IS_NULL) { - if (phalcon_array_isset_quick_string(_SERVER, SS("REMOTE_ADDR"), 1233979979UL)) { - PHALCON_OBS_NVAR(address); - phalcon_array_fetch_quick_string(&address, _SERVER, SS("REMOTE_ADDR"), 1233979979UL, PH_NOISY); + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VSVS(access_key, inherited_role, "!", resource, "!*"); + + if (phalcon_array_isset(access_list, access_key)) { + PHALCON_OBS_NVAR(have_access); + phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); + break; + } + + zend_hash_move_forward_ex(ah1, &hp1); + } + + } } } - if (Z_TYPE_P(address) == IS_STRING) { - if (phalcon_memnstr_str(address, SL(","))) { - PHALCON_INIT_VAR(addresses); - phalcon_fast_explode_str(addresses, SL(","), address); + if (Z_TYPE_P(have_access) == IS_NULL) { - PHALCON_OBS_VAR(first); - phalcon_array_fetch_long(&first, addresses, 0, PH_NOISY); - RETURN_CCTOR(first); + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VS(access_key, role, "!*!*"); + + if (phalcon_array_isset(access_list, access_key)) { + PHALCON_OBS_NVAR(have_access); + phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); + } else { + if (Z_TYPE_P(inherited_roles) == IS_ARRAY) { + + phalcon_is_iterable(inherited_roles, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HVALUE(inherited_role); + + PHALCON_INIT_NVAR(access_key); + PHALCON_CONCAT_VS(access_key, inherited_role, "!*!*"); + if (phalcon_array_isset(access_list, access_key)) { + PHALCON_OBS_NVAR(have_access); + phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); + break; + } + + zend_hash_move_forward_ex(ah2, &hp2); + } + + } } + } - RETURN_CCTOR(address); + phalcon_update_property_this_quick(this_ptr, SL("_accessGranted"), have_access, 3188809627UL TSRMLS_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "acl:afterCheckAccess", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, have_access, 259017035UL); } - RETURN_MM_FALSE; + if (Z_TYPE_P(have_access) == IS_NULL) { + PHALCON_MM_RESTORE(); + RETURN_LONG(0); + } + + RETURN_CCTOR(have_access); } -static const char* phalcon_http_request_getmethod_helper(TSRMLS_D) -{ - zval **value; - const char *method = SG(request_info).request_method; - if (unlikely(!method)) { - zval *_SERVER, key; - - INIT_ZVAL(key); - ZVAL_STRING(&key, "REQUEST_METHOD", 0); - - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - value = phalcon_hash_get(Z_ARRVAL_P(_SERVER), &key, BP_VAR_NA); - if (value && Z_TYPE_PP(value) == IS_STRING) { - return Z_STRVAL_PP(value); - } +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, getRoles){ - return ""; - } - return method; + RETURN_MEMBER_QUICK(this_ptr, "_roles", 2795361801UL); } -static PHP_METHOD(Phalcon_Http_Request, getMethod){ +static PHP_METHOD(Phalcon_Acl_Adapter_Memory, getResources){ - const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); - if (method) { - RETURN_STRING(method, 1); - } - RETURN_EMPTY_STRING(); + RETURN_MEMBER_QUICK(this_ptr, "_resources", 3320036063UL); } -static PHP_METHOD(Phalcon_Http_Request, getUserAgent){ - zval *server = NULL, *_SERVER, *user_agent = NULL; - PHALCON_MM_GROW(); - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - PHALCON_CPY_WRT(server, _SERVER); - if (phalcon_array_isset_quick_string(server, SS("HTTP_USER_AGENT"), 12675185UL)) { - PHALCON_OBS_VAR(user_agent); - phalcon_array_fetch_quick_string(&user_agent, server, SS("HTTP_USER_AGENT"), 12675185UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(user_agent); - ZVAL_STRING(user_agent, "", 1); - } - - RETURN_CCTOR(user_agent); -} -static PHP_METHOD(Phalcon_Http_Request, isMethod){ +#ifdef HAVE_CONFIG_H +#endif - zval *methods, *http_method, *is_equals, *method = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &methods); - - PHALCON_INIT_VAR(http_method); - phalcon_call_method_key(http_method, this_ptr, "getmethod", 2473474950UL); - if (Z_TYPE_P(methods) == IS_STRING) { - PHALCON_INIT_VAR(is_equals); - is_equal_function(is_equals, methods, http_method TSRMLS_CC); - RETURN_NCTOR(is_equals); - } else { - - phalcon_is_iterable(methods, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(method); - - if (PHALCON_IS_EQUAL(method, http_method)) { - RETURN_MM_TRUE; - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - RETURN_MM_FALSE; -} -static PHP_METHOD(Phalcon_Http_Request, isPost){ - zval *post, *method; - if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { - const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); - RETURN_BOOL(!strcmp(method, "POST")); - } +PHALCON_INIT_CLASS(Phalcon_Acl_Adapter){ - PHALCON_MM_GROW(); + PHALCON_REGISTER_CLASS(Phalcon\\Acl, Adapter, acl_adapter, phalcon_acl_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - PHALCON_INIT_VAR(post); - ZVAL_STRING(post, "POST", 1); + zend_declare_property_null(phalcon_acl_adapter_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_acl_adapter_ce, SL("_defaultAccess"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_acl_adapter_ce, SL("_accessGranted"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_adapter_ce, SL("_activeRole"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_adapter_ce, SL("_activeResource"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_adapter_ce, SL("_activeAccess"), ZEND_ACC_PROTECTED TSRMLS_CC); - PHALCON_INIT_VAR(method); - phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); - is_equal_function(return_value, method, post TSRMLS_CC); + zend_class_implements(phalcon_acl_adapter_ce TSRMLS_CC, 1, phalcon_events_eventsawareinterface_ce); - RETURN_MM(); + return SUCCESS; } -static PHP_METHOD(Phalcon_Http_Request, isGet){ - - zval *get, *method; +static PHP_METHOD(Phalcon_Acl_Adapter, setEventsManager){ - if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { - const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); - RETURN_BOOL(!strcmp(method, "GET")); - } + zval *events_manager; - PHALCON_MM_GROW(); + phalcon_fetch_params(0, 1, 0, &events_manager); + + phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); + +} - PHALCON_INIT_VAR(get); - ZVAL_STRING(get, "GET", 1); +static PHP_METHOD(Phalcon_Acl_Adapter, getEventsManager){ - PHALCON_INIT_VAR(method); - phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); - is_equal_function(return_value, method, get TSRMLS_CC); - RETURN_MM(); + RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); } -static PHP_METHOD(Phalcon_Http_Request, isPut){ - - zval *put, *method; +static PHP_METHOD(Phalcon_Acl_Adapter, setDefaultAction){ - if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { - const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); - RETURN_BOOL(!strcmp(method, "PUT")); - } + zval *default_access; - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(put); - ZVAL_STRING(put, "PUT", 1); - - PHALCON_INIT_VAR(method); - phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); - is_equal_function(return_value, method, put TSRMLS_CC); + phalcon_fetch_params(0, 1, 0, &default_access); + + phalcon_update_property_this_quick(this_ptr, SL("_defaultAccess"), default_access, 875397115UL TSRMLS_CC); - RETURN_MM(); } -static PHP_METHOD(Phalcon_Http_Request, isPatch){ +static PHP_METHOD(Phalcon_Acl_Adapter, getDefaultAction){ - zval *patch, *method; - if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { - const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); - RETURN_BOOL(!strcmp(method, "PATCH")); - } + RETURN_MEMBER_QUICK(this_ptr, "_defaultAccess", 875397115UL); +} - PHALCON_MM_GROW(); +static PHP_METHOD(Phalcon_Acl_Adapter, getActiveRole){ - PHALCON_INIT_VAR(patch); - ZVAL_STRING(patch, "PATCH", 1); - PHALCON_INIT_VAR(method); - phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); - is_equal_function(return_value, method, patch TSRMLS_CC); - - RETURN_MM(); + RETURN_MEMBER_QUICK(this_ptr, "_activeRole", 3079165426UL); } -static PHP_METHOD(Phalcon_Http_Request, isHead){ +static PHP_METHOD(Phalcon_Acl_Adapter, getActiveResource){ - zval *head, *method; - if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { - const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); - RETURN_BOOL(!strcmp(method, "HEAD")); - } + RETURN_MEMBER_QUICK(this_ptr, "_activeResource", 1323587080UL); +} - PHALCON_MM_GROW(); +static PHP_METHOD(Phalcon_Acl_Adapter, getActiveAccess){ - PHALCON_INIT_VAR(head); - ZVAL_STRING(head, "HEAD", 1); - PHALCON_INIT_VAR(method); - phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); - is_equal_function(return_value, method, head TSRMLS_CC); - - RETURN_MM(); + RETURN_MEMBER_QUICK(this_ptr, "_activeAccess", 2176370066UL); } -static PHP_METHOD(Phalcon_Http_Request, isDelete){ - zval *delete, *method; - if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { - const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); - RETURN_BOOL(!strcmp(method, "DELETE")); - } - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(delete); - ZVAL_STRING(delete, "DELETE", 1); +#ifdef HAVE_CONFIG_H +#endif - PHALCON_INIT_VAR(method); - phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); - is_equal_function(return_value, method, delete TSRMLS_CC); - - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Http_Request, isOptions){ - zval *options, *method; +PHALCON_INIT_CLASS(Phalcon_Acl_AdapterInterface){ - if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { - const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); - RETURN_BOOL(!strcmp(method, "OPTIONS")); - } + PHALCON_REGISTER_INTERFACE(Phalcon\\Acl, AdapterInterface, acl_adapterinterface, phalcon_acl_adapterinterface_method_entry); - PHALCON_MM_GROW(); + return SUCCESS; +} - PHALCON_INIT_VAR(options); - ZVAL_STRING(options, "OPTIONS", 1); - PHALCON_INIT_VAR(method); - phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); - is_equal_function(return_value, method, options TSRMLS_CC); - - RETURN_MM(); -} -static int phalcon_http_request_hasfiles_helper(zval *arr, int only_successful) -{ - HashTable *ah0; - HashPosition hp0; - zval **hd; - int nfiles = 0; - assert(Z_TYPE_P(arr) == IS_ARRAY); - phalcon_is_iterable_ex(arr, &ah0, &hp0, 0, 0); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (Z_TYPE_PP(hd) < IS_ARRAY) { - if (!zend_is_true(*hd) || !only_successful) { - ++nfiles; - } - } - else if (Z_TYPE_PP(hd) == IS_ARRAY) { - nfiles += phalcon_http_request_hasfiles_helper(*hd, only_successful); - } - zend_hash_move_forward_ex(ah0, &hp0); - } - return nfiles; -} -static PHP_METHOD(Phalcon_Http_Request, hasFiles){ - zval *not_errored = NULL, *_FILES, *error = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - int nfiles = 0; - int only_successful; - phalcon_fetch_params(0, 0, 1, ¬_errored); - - only_successful = not_errored ? phalcon_get_intval(not_errored) : 1; - - phalcon_get_global(&_FILES, SS("_FILES") TSRMLS_CC); - if (unlikely(Z_TYPE_P(_FILES) != IS_ARRAY)) { - RETURN_LONG(0); - } - phalcon_is_iterable(_FILES, &ah0, &hp0, 0, 0); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (phalcon_array_isset_string(*hd, SS("error"))) { - phalcon_array_fetch_string(&error, *hd, SL("error"), PH_NOISY); - assert(Z_REFCOUNT_P(error) > 1); - Z_DELREF_P(error); - if (Z_TYPE_P(error) < IS_ARRAY) { - if (!zend_is_true(error) || !only_successful) { - ++nfiles; - } - } - else if (Z_TYPE_P(error) == IS_ARRAY) { - nfiles += phalcon_http_request_hasfiles_helper(error, only_successful); - } - } - zend_hash_move_forward_ex(ah0, &hp0); - } - RETURN_LONG(nfiles); -} -static void phalcon_http_request_getuploadedfiles_helper(zval **return_value, zval *name, zval *type, zval *tmp_name, zval *error, zval *size, int only_successful, smart_str *prefix TSRMLS_DC) -{ - if ( - Z_TYPE_P(name) == IS_ARRAY && Z_TYPE_P(type) == IS_ARRAY - && Z_TYPE_P(tmp_name) == IS_ARRAY && Z_TYPE_P(error) == IS_ARRAY - && Z_TYPE_P(size) == IS_ARRAY - ) { - HashPosition pos_name, pos_type, pos_tmp, pos_error, pos_size; - zval **dname, **dtype, **dtmp, **derror, **dsize; - zval *arr, *file, *key; - size_t prefix_len = prefix->len; - zval *params[2]; - int res; - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(name), &pos_name); - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(type), &pos_type); - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(tmp_name), &pos_tmp); - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(error), &pos_error); - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(size), &pos_size); - while ( - zend_hash_get_current_data_ex(Z_ARRVAL_P(name), (void**)&dname, &pos_name) == SUCCESS - && zend_hash_get_current_data_ex(Z_ARRVAL_P(type), (void**)&dtype, &pos_type) == SUCCESS - && zend_hash_get_current_data_ex(Z_ARRVAL_P(tmp_name), (void**)&dtmp, &pos_tmp) == SUCCESS - && zend_hash_get_current_data_ex(Z_ARRVAL_P(error), (void**)&derror, &pos_error) == SUCCESS - && zend_hash_get_current_data_ex(Z_ARRVAL_P(size), (void**)&dsize, &pos_size) == SUCCESS - && !EG(exception) - ) { - zval index = phalcon_get_current_key_w(Z_ARRVAL_P(name), &pos_name); - if (Z_TYPE(index) == IS_STRING) { - smart_str_appendl(prefix, Z_STRVAL(index), Z_STRLEN(index)); - } - else { - smart_str_append_long(prefix, Z_LVAL(index)); - } - if (Z_TYPE_PP(derror) < IS_ARRAY) { - if (!zend_is_true(*derror) || !only_successful) { - Z_ADDREF_PP(dname); - Z_ADDREF_PP(dtype); - Z_ADDREF_PP(dtmp); - Z_ADDREF_PP(derror); - Z_ADDREF_PP(dsize); - ALLOC_INIT_ZVAL(arr); - array_init_size(arr, 5); - add_assoc_zval_ex(arr, SS("name"), *dname); - add_assoc_zval_ex(arr, SS("type"), *dtype); - add_assoc_zval_ex(arr, SS("tmp_name"), *dtmp); - add_assoc_zval_ex(arr, SS("error"), *derror); - add_assoc_zval_ex(arr, SS("size"), *dsize); +#ifdef HAVE_CONFIG_H +#endif - ALLOC_INIT_ZVAL(key); - ZVAL_STRINGL(key, prefix->c, prefix->len, 1); - prefix->len = prefix_len; - ALLOC_INIT_ZVAL(file); - object_init_ex(file, phalcon_http_request_file_ce); - params[0] = arr; - params[1] = key; - res = phalcon_call_method_params_w(NULL, file, SL("__construct"), 2, params, 0, 0 TSRMLS_CC); - zval_ptr_dtor(&arr); - zval_ptr_dtor(&key); - if (res != FAILURE) { - add_next_index_zval(*return_value, file); - } - else { - break; - } - } - } - else if (Z_TYPE_PP(derror) == IS_ARRAY) { - smart_str_appendc(prefix, '.'); - phalcon_http_request_getuploadedfiles_helper(return_value, *dname, *dtype, *dtmp, *derror, *dsize, only_successful, prefix TSRMLS_CC); - prefix->len = prefix_len; - } - zend_hash_move_forward_ex(Z_ARRVAL_P(name), &pos_name); - zend_hash_move_forward_ex(Z_ARRVAL_P(type), &pos_type); - zend_hash_move_forward_ex(Z_ARRVAL_P(tmp_name), &pos_tmp); - zend_hash_move_forward_ex(Z_ARRVAL_P(error), &pos_error); - zend_hash_move_forward_ex(Z_ARRVAL_P(size), &pos_size); - } - } -} +PHALCON_INIT_CLASS(Phalcon_Acl_Exception){ -static PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Acl, Exception, acl_exception, "phalcon\\exception", NULL, 0); - zval *name = NULL, *type = NULL, *tmp_name = NULL, *error = NULL, *size = NULL; - zval *not_errored = NULL, *_FILES, *request_file = NULL, *key = NULL; - zval index; - HashTable *ah0; - HashPosition hp0; - zval **hd; - int only_successful; - smart_str prefix = { NULL, 0, 0 }; + return SUCCESS; +} - phalcon_fetch_params(0, 0, 1, ¬_errored); - - only_successful = not_errored ? phalcon_get_intval(not_errored) : 1; - array_init(return_value); - phalcon_get_global(&_FILES, SS("_FILES") TSRMLS_CC); - if (Z_TYPE_P(_FILES) != IS_ARRAY || !zend_hash_num_elements(Z_ARRVAL_P(_FILES))) { - return; - } - PHALCON_MM_GROW(); - phalcon_is_iterable(_FILES, &ah0, &hp0, 0, 0); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS && !EG(exception)) { +#ifdef HAVE_CONFIG_H +#endif - if (phalcon_array_isset_string(*hd, SS("error"))) { - PHALCON_OBS_NVAR(error); - phalcon_array_fetch_string(&error, *hd, SL("error"), PH_NOISY); - index = phalcon_get_current_key_w(ah0, &hp0); - if (Z_TYPE_P(error) < IS_ARRAY) { - if (!zend_is_true(error) || !only_successful) { - PHALCON_INIT_NVAR(request_file); - object_init_ex(request_file, phalcon_http_request_file_ce); - PHALCON_INIT_NVAR(key); - ZVAL_STRINGL(key, Z_STRVAL(index), Z_STRLEN(index), 1); - Z_ADDREF_PP(hd); - phalcon_call_method_p2_noret(request_file, "__construct", *hd, key); - phalcon_array_append(&return_value, request_file, 0); - } - } - else if (Z_TYPE_P(error) == IS_ARRAY) { - PHALCON_OBS_NVAR(name); - PHALCON_OBS_NVAR(type); - PHALCON_OBS_NVAR(tmp_name); - PHALCON_OBS_NVAR(size); - phalcon_array_fetch_string(&name, *hd, SL("name"), PH_NOISY); - phalcon_array_fetch_string(&type, *hd, SL("type"), PH_NOISY); - phalcon_array_fetch_string(&tmp_name, *hd, SL("tmp_name"), PH_NOISY); - phalcon_array_fetch_string(&size, *hd, SL("size"), PH_NOISY); - if (prefix.len) { - prefix.len = 0; - } - if (likely(Z_TYPE(index) == IS_STRING)) { - smart_str_appendl(&prefix, Z_STRVAL(index), Z_STRLEN(index)); - } - else { - smart_str_append_long(&prefix, Z_LVAL(index)); - } +PHALCON_INIT_CLASS(Phalcon_Acl_Resource){ - smart_str_appendc(&prefix, '.'); - phalcon_http_request_getuploadedfiles_helper(&return_value, name, type, tmp_name, error, size, only_successful, &prefix TSRMLS_CC); - } - } + PHALCON_REGISTER_CLASS(Phalcon\\Acl, Resource, acl_resource, phalcon_acl_resource_method_entry, 0); - zend_hash_move_forward_ex(ah0, &hp0); - } - - if (prefix.c) { - smart_str_free(&prefix); - } + zend_declare_property_null(phalcon_acl_resource_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_resource_ce, SL("_description"), ZEND_ACC_PROTECTED TSRMLS_CC); - RETURN_MM(); -} + zend_class_implements(phalcon_acl_resource_ce TSRMLS_CC, 1, phalcon_acl_resourceinterface_ce); -static PHP_METHOD(Phalcon_Http_Request, getHeaders){ + return SUCCESS; +} - zval *_SERVER, *key = NULL, *header = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; +static PHP_METHOD(Phalcon_Acl_Resource, __construct){ - array_init(return_value); - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - if (unlikely(Z_TYPE_P(_SERVER) != IS_ARRAY)) { - return; - } + zval *name, *description = NULL; PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &name, &description); - phalcon_is_iterable(_SERVER, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(key, ah0, hp0); - - if (phalcon_start_with_str(key, SL("HTTP_"))) { - PHALCON_INIT_NVAR(header); - phalcon_substr(header, key, 5, 0); - phalcon_array_update_zval(&return_value, header, hd, PH_COPY); - } + if (!description) { + PHALCON_INIT_VAR(description); + } - zend_hash_move_forward_ex(ah0, &hp0); + if (PHALCON_IS_STRING(name, "*")) { + PHALCON_THROW_EXCEPTION_STR(phalcon_acl_exception_ce, "Resource name cannot be \"*\""); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); + if (Z_TYPE_P(description) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_description"), description, 1348915240UL TSRMLS_CC); } PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Http_Request, getHTTPReferer){ - - zval *_SERVER, *http_referer; +static PHP_METHOD(Phalcon_Acl_Resource, getName){ - PHALCON_MM_GROW(); - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - if (phalcon_array_isset_quick_string(_SERVER, SS("HTTP_REFERER"), 609736271UL)) { - PHALCON_OBS_VAR(http_referer); - phalcon_array_fetch_quick_string(&http_referer, _SERVER, SS("HTTP_REFERER"), 609736271UL, PH_NOISY); - RETURN_CCTOR(http_referer); - } - RETURN_MM_EMPTY_STRING(); + RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); } -static PHP_METHOD(Phalcon_Http_Request, _getQualityHeader){ +static PHP_METHOD(Phalcon_Acl_Resource, getDescription){ - zval *server_index, *name, *quality_one; - zval *http_server, *pattern, *parts, *part = NULL, *header_parts = NULL; - zval *quality_part = NULL, *quality = NULL, *header_name = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_description", 1348915240UL); +} - phalcon_fetch_params(1, 2, 0, &server_index, &name); - - PHALCON_INIT_VAR(quality_one); - ZVAL_DOUBLE(quality_one, 1); - - array_init(return_value); - - PHALCON_INIT_VAR(http_server); - phalcon_call_method_p1_key(http_server, this_ptr, "getserver", server_index, 1630469020UL); - - PHALCON_INIT_VAR(pattern); - ZVAL_STRING(pattern, "/,\\s*/", 1); - PHALCON_INIT_VAR(parts); - phalcon_call_func_p2(parts, "preg_split", pattern, http_server); - - phalcon_is_iterable(parts, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(part); - - PHALCON_INIT_NVAR(header_parts); - phalcon_fast_explode_str(header_parts, SL(";"), part); - if (phalcon_array_isset_long(header_parts, 1)) { - PHALCON_OBS_NVAR(quality_part); - phalcon_array_fetch_long(&quality_part, header_parts, 1, PH_NOISY); - - PHALCON_INIT_NVAR(quality); - phalcon_substr(quality, quality_part, 2, 0); - } else { - PHALCON_CPY_WRT(quality, quality_one); - } - - PHALCON_OBS_NVAR(header_name); - phalcon_array_fetch_long(&header_name, header_parts, 0, PH_NOISY); - - PHALCON_INIT_NVAR(quality_part); - array_init_size(quality_part, 2); - phalcon_array_update_zval(&quality_part, name, &header_name, PH_COPY); - phalcon_array_update_quick_string(&quality_part, SS("quality"), 3712111054UL, &quality, PH_COPY); - phalcon_array_append(&return_value, quality_part, 0); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_MM_RESTORE(); +static PHP_METHOD(Phalcon_Acl_Resource, __toString){ + + + RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); } -static PHP_METHOD(Phalcon_Http_Request, _getBestQuality){ - zval *quality_parts, *name, *quality = NULL, *selected_name = NULL; - zval *accept = NULL, *accept_quality = NULL, *best_quality = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - long int i = 0; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &quality_parts, &name); - - PHALCON_INIT_VAR(quality); - ZVAL_LONG(quality, 0); - - PHALCON_INIT_VAR(selected_name); - ZVAL_EMPTY_STRING(selected_name); - - phalcon_is_iterable(quality_parts, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(accept); - - if (i == 0) { - PHALCON_OBS_NVAR(quality); - phalcon_array_fetch_quick_string(&quality, accept, SS("quality"), 3712111054UL, PH_NOISY); - - PHALCON_OBS_NVAR(selected_name); - phalcon_array_fetch(&selected_name, accept, name, PH_NOISY); - } else { - PHALCON_OBS_NVAR(accept_quality); - phalcon_array_fetch_quick_string(&accept_quality, accept, SS("quality"), 3712111054UL, PH_NOISY); - - PHALCON_INIT_NVAR(best_quality); - is_smaller_function(best_quality, quality, accept_quality TSRMLS_CC); - if (PHALCON_IS_TRUE(best_quality)) { - PHALCON_CPY_WRT(quality, accept_quality); - - PHALCON_OBS_NVAR(selected_name); - phalcon_array_fetch(&selected_name, accept, name, PH_NOISY); - } - } - ++i; - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CCTOR(selected_name); -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Http_Request, getAcceptableContent){ - zval *accept_header, *quality_index; - PHALCON_MM_GROW(); +PHALCON_INIT_CLASS(Phalcon_Acl_ResourceInterface){ - PHALCON_INIT_VAR(accept_header); - ZVAL_STRING(accept_header, "HTTP_ACCEPT", 1); - - PHALCON_INIT_VAR(quality_index); - ZVAL_STRING(quality_index, "accept", 1); - phalcon_call_method_p2_key(return_value, this_ptr, "_getqualityheader", accept_header, quality_index, 757409206UL); - RETURN_MM(); + PHALCON_REGISTER_INTERFACE(Phalcon\\Acl, ResourceInterface, acl_resourceinterface, phalcon_acl_resourceinterface_method_entry); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Http_Request, getBestAccept){ - zval *quality_index, *acceptable_content; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(quality_index); - ZVAL_STRING(quality_index, "accept", 1); - - PHALCON_INIT_VAR(acceptable_content); - phalcon_call_method_key(acceptable_content, this_ptr, "getacceptablecontent", 3152475684UL); - phalcon_call_method_p2_key(return_value, this_ptr, "_getbestquality", acceptable_content, quality_index, 2752999675UL); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Http_Request, getClientCharsets){ - zval *charset_header, *quality_index; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(charset_header); - ZVAL_STRING(charset_header, "HTTP_ACCEPT_CHARSET", 1); - - PHALCON_INIT_VAR(quality_index); - ZVAL_STRING(quality_index, "charset", 1); - phalcon_call_method_p2_key(return_value, this_ptr, "_getqualityheader", charset_header, quality_index, 757409206UL); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Http_Request, getBestCharset){ +#ifdef HAVE_CONFIG_H +#endif - zval *quality_index, *client_charsets; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(quality_index); - ZVAL_STRING(quality_index, "charset", 1); - - PHALCON_INIT_VAR(client_charsets); - phalcon_call_method_key(client_charsets, this_ptr, "getclientcharsets", 166081441UL); - phalcon_call_method_p2_key(return_value, this_ptr, "_getbestquality", client_charsets, quality_index, 2752999675UL); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Http_Request, getLanguages){ - zval *language_header, *quality_index; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(language_header); - ZVAL_STRING(language_header, "HTTP_ACCEPT_LANGUAGE", 1); - - PHALCON_INIT_VAR(quality_index); - ZVAL_STRING(quality_index, "language", 1); - phalcon_call_method_p2_key(return_value, this_ptr, "_getqualityheader", language_header, quality_index, 757409206UL); - RETURN_MM(); +PHALCON_INIT_CLASS(Phalcon_Acl_Role){ + + PHALCON_REGISTER_CLASS(Phalcon\\Acl, Role, acl_role, phalcon_acl_role_method_entry, 0); + + zend_declare_property_null(phalcon_acl_role_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_acl_role_ce, SL("_description"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_acl_role_ce TSRMLS_CC, 1, phalcon_acl_roleinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Http_Request, getBestLanguage){ +static PHP_METHOD(Phalcon_Acl_Role, __construct){ - zval *languages, *quality_index; + zval *name, *description = NULL; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(languages); - phalcon_call_method_key(languages, this_ptr, "getlanguages", 2261985372UL); + phalcon_fetch_params(1, 1, 1, &name, &description); - PHALCON_INIT_VAR(quality_index); - ZVAL_STRING(quality_index, "language", 1); - phalcon_call_method_p2_key(return_value, this_ptr, "_getbestquality", languages, quality_index, 2752999675UL); - RETURN_MM(); + if (!description) { + PHALCON_INIT_VAR(description); + } + + if (PHALCON_IS_STRING(name, "*")) { + PHALCON_THROW_EXCEPTION_STR(phalcon_acl_exception_ce, "Role name cannot be \"*\""); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); + if (Z_TYPE_P(description) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_description"), description, 1348915240UL TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Acl_Role, getName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); +} + +static PHP_METHOD(Phalcon_Acl_Role, getDescription){ + + + RETURN_MEMBER_QUICK(this_ptr, "_description", 1348915240UL); +} + +static PHP_METHOD(Phalcon_Acl_Role, __toString){ + + + RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); } @@ -13317,675 +12909,583 @@ static PHP_METHOD(Phalcon_Http_Request, getBestLanguage){ +PHALCON_INIT_CLASS(Phalcon_Acl_RoleInterface){ + PHALCON_REGISTER_INTERFACE(Phalcon\\Acl, RoleInterface, acl_roleinterface, phalcon_acl_roleinterface_method_entry); + return SUCCESS; +} -PHALCON_INIT_CLASS(Phalcon_Http_Cookie){ - PHALCON_REGISTER_CLASS(Phalcon\\Http, Cookie, http_cookie, phalcon_http_cookie_method_entry, 0); - zend_declare_property_bool(phalcon_http_cookie_ce, SL("_readed"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_http_cookie_ce, SL("_restored"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_http_cookie_ce, SL("_useEncryption"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_cookie_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_cookie_ce, SL("_filter"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_cookie_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_cookie_ce, SL("_value"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_cookie_ce, SL("_expire"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_http_cookie_ce, SL("_path"), "/", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_cookie_ce, SL("_domain"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_cookie_ce, SL("_secure"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_http_cookie_ce, SL("_httpOnly"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_http_cookie_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Acl){ + + PHALCON_REGISTER_CLASS(Phalcon, Acl, acl, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_class_constant_long(phalcon_acl_ce, SL("ALLOW"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_acl_ce, SL("DENY"), 0 TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_Http_Cookie, __construct){ - zval *name, *value = NULL, *expire = NULL, *path = NULL, *secure = NULL, *domain = NULL; - zval *http_only = NULL; + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Apc){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Apc, annotations_adapter_apc, "phalcon\\annotations\\adapter", phalcon_annotations_adapter_apc_method_entry, 0); + + zend_class_implements(phalcon_annotations_adapter_apc_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Annotations_Adapter_Apc, read){ + + zval *key, *prefixed_key, *prefixed_lower, *data; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 6, &name, &value, &expire, &path, &secure, &domain, &http_only); - - if (!value) { - PHALCON_INIT_VAR(value); - } - - if (!expire) { - PHALCON_INIT_VAR(expire); - ZVAL_LONG(expire, 0); - } + phalcon_fetch_params(1, 1, 0, &key); - if (!path) { - PHALCON_INIT_VAR(path); - ZVAL_STRING(path, "/", 1); - } + PHALCON_INIT_VAR(prefixed_key); + PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key); - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_http_cookie_exception_ce, "The cookie name must be string"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); - if (Z_TYPE_P(value) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_value"), value, 2935317441UL TSRMLS_CC); - } + PHALCON_INIT_VAR(prefixed_lower); + phalcon_fast_strtolower(prefixed_lower, prefixed_key); - phalcon_update_property_this_quick(this_ptr, SL("_expire"), expire, 2800520017UL TSRMLS_CC); - if (Z_TYPE_P(path) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_path"), path, 3986357393UL TSRMLS_CC); + PHALCON_INIT_VAR(data); + phalcon_call_func_p1(data, "apc_fetch", prefixed_lower); + if (Z_TYPE_P(data) == IS_OBJECT) { + RETURN_CCTOR(data); } - if (secure && Z_TYPE_P(secure) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_secure"), secure, 2942644203UL TSRMLS_CC); - } + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Annotations_Adapter_Apc, write){ + + zval *key, *data, *prefixed_key, *prefixed_lower; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &key, &data); - if (domain && Z_TYPE_P(domain) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_domain"), domain, 1152978748UL TSRMLS_CC); - } + PHALCON_INIT_VAR(prefixed_key); + PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key); - if (http_only && Z_TYPE_P(http_only) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_httpOnly"), http_only, 41231174UL TSRMLS_CC); - } + PHALCON_INIT_VAR(prefixed_lower); + phalcon_fast_strtolower(prefixed_lower, prefixed_key); + phalcon_call_func_p2_noret("apc_store", prefixed_lower, data); PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Http_Cookie, setDI){ - zval *dependency_injector; - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - -} -static PHP_METHOD(Phalcon_Http_Cookie, getDI){ +#ifdef HAVE_CONFIG_H +#endif - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} -static PHP_METHOD(Phalcon_Http_Cookie, setValue){ - zval *value; - phalcon_fetch_params(0, 1, 0, &value); - - phalcon_update_property_this_quick(this_ptr, SL("_value"), value, 2935317441UL TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_readed"), 1 TSRMLS_CC); - RETURN_THISW(); + + + +PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Files){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Files, annotations_adapter_files, "phalcon\\annotations\\adapter", phalcon_annotations_adapter_files_method_entry, 0); + + zend_declare_property_string(phalcon_annotations_adapter_files_ce, SL("_annotationsDir"), "./", ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_annotations_adapter_files_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Http_Cookie, getValue){ +static PHP_METHOD(Phalcon_Annotations_Adapter_Files, __construct){ - zval *filters = NULL, *default_value = NULL, *restored, *dependency_injector = NULL; - zval *readed, *name, *_COOKIE, *value = NULL, *encryption; - zval *service = NULL, *crypt, *decrypted_value = NULL, *filter = NULL; - zval *sanitized_value; + zval *options = NULL, *annotations_dir; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &filters, &default_value); - - if (!filters) { - PHALCON_INIT_VAR(filters); - } + phalcon_fetch_params(1, 0, 1, &options); - if (!default_value) { - PHALCON_INIT_VAR(default_value); + if (!options) { + PHALCON_INIT_VAR(options); } - PHALCON_OBS_VAR(restored); - phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); - if (!zend_is_true(restored)) { - phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); + if (Z_TYPE_P(options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(options, SS("annotationsDir"), 1341171666UL)) { + PHALCON_OBS_VAR(annotations_dir); + phalcon_array_fetch_quick_string(&annotations_dir, options, SS("annotationsDir"), 1341171666UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_annotationsDir"), annotations_dir, 4233102065UL TSRMLS_CC); + } } - PHALCON_INIT_VAR(dependency_injector); - - PHALCON_OBS_VAR(readed); - phalcon_read_property_this_quick(&readed, this_ptr, SL("_readed"), 1648179273UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(readed)) { - - PHALCON_OBS_VAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - phalcon_get_global(&_COOKIE, SS("_COOKIE") TSRMLS_CC); - if (phalcon_array_isset(_COOKIE, name)) { - - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, _COOKIE, name, PH_NOISY); - - PHALCON_OBS_VAR(encryption); - phalcon_read_property_this_quick(&encryption, this_ptr, SL("_useEncryption"), 2628069468UL, PH_NOISY_CC); - if (zend_is_true(encryption)) { - - PHALCON_OBS_NVAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "A dependency injection object is required to access the 'filter' service"); - return; - } - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "crypt", 1); - - PHALCON_INIT_VAR(crypt); - phalcon_call_method_p1_key(crypt, dependency_injector, "getshared", service, 1727570332UL); - - PHALCON_INIT_VAR(decrypted_value); - phalcon_call_method_p1_key(decrypted_value, crypt, "decryptbase64", value, 588154501UL); - } else { - PHALCON_CPY_WRT(decrypted_value, value); - } - - phalcon_update_property_this_quick(this_ptr, SL("_value"), decrypted_value, 2935317441UL TSRMLS_CC); - if (Z_TYPE_P(filters) != IS_NULL) { - - PHALCON_OBS_VAR(filter); - phalcon_read_property_this_quick(&filter, this_ptr, SL("_filter"), 3500594986UL, PH_NOISY_CC); - if (Z_TYPE_P(filter) != IS_OBJECT) { - if (Z_TYPE_P(dependency_injector) == IS_NULL) { - - PHALCON_OBS_NVAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "A dependency injection object is required to access the 'filter' service"); - return; - } - } - - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "filter", 1); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Annotations_Adapter_Files, read){ + + zval *key, *annotations_dir, *separator, *virtual_key; + zval *path, *data; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &key); - PHALCON_INIT_NVAR(filter); - phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); - } + PHALCON_OBS_VAR(annotations_dir); + phalcon_read_property_this_quick(&annotations_dir, this_ptr, SL("_annotationsDir"), 4233102065UL, PH_NOISY_CC); - PHALCON_INIT_VAR(sanitized_value); - phalcon_call_method_p2_key(sanitized_value, filter, "sanitize", decrypted_value, filters, 3688332940UL); + PHALCON_INIT_VAR(separator); + ZVAL_STRING(separator, "_", 1); - RETURN_CCTOR(sanitized_value); - } + PHALCON_INIT_VAR(virtual_key); + phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); + PHALCON_INIT_VAR(path); + PHALCON_CONCAT_VVS(path, annotations_dir, virtual_key, ".php"); - RETURN_CCTOR(decrypted_value); + if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_VAR(data); + if (phalcon_require_ret(data, path TSRMLS_CC) == FAILURE) { + return; } - - RETURN_CCTOR(default_value); + RETURN_CCTOR(data); } - PHALCON_OBS_NVAR(value); - phalcon_read_property_this_quick(&value, this_ptr, SL("_value"), 2935317441UL, PH_NOISY_CC); - - RETURN_CCTOR(value); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Http_Cookie, send){ +static PHP_METHOD(Phalcon_Annotations_Adapter_Files, write){ - zval *name, *value, *expire, *domain, *path, *secure; - zval *http_only, *dependency_injector, *definition; - zval *service = NULL, *session, *key, *encryption, *crypt; - zval *encrypt_value = NULL, *has_session; + zval *key, *data, *annotations_dir, *separator; + zval *virtual_key, *path, *to_string, *export, *php_export; + zval *status; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); + phalcon_fetch_params(1, 2, 0, &key, &data); - PHALCON_OBS_VAR(value); - phalcon_read_property_this_quick(&value, this_ptr, SL("_value"), 2935317441UL, PH_NOISY_CC); + PHALCON_OBS_VAR(annotations_dir); + phalcon_read_property_this_quick(&annotations_dir, this_ptr, SL("_annotationsDir"), 4233102065UL, PH_NOISY_CC); - PHALCON_OBS_VAR(expire); - phalcon_read_property_this_quick(&expire, this_ptr, SL("_expire"), 2800520017UL, PH_NOISY_CC); + PHALCON_INIT_VAR(separator); + ZVAL_STRING(separator, "_", 1); - PHALCON_OBS_VAR(domain); - phalcon_read_property_this_quick(&domain, this_ptr, SL("_domain"), 1152978748UL, PH_NOISY_CC); + PHALCON_INIT_VAR(virtual_key); + phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); - PHALCON_OBS_VAR(path); - phalcon_read_property_this_quick(&path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); + PHALCON_INIT_VAR(path); + PHALCON_CONCAT_VVS(path, annotations_dir, virtual_key, ".php"); - PHALCON_OBS_VAR(secure); - phalcon_read_property_this_quick(&secure, this_ptr, SL("_secure"), 2942644203UL, PH_NOISY_CC); + PHALCON_INIT_VAR(to_string); + ZVAL_BOOL(to_string, 1); - PHALCON_OBS_VAR(http_only); - phalcon_read_property_this_quick(&http_only, this_ptr, SL("_httpOnly"), 41231174UL, PH_NOISY_CC); + PHALCON_INIT_VAR(export); + phalcon_call_func_p2(export, "var_export", data, to_string); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { - PHALCON_INIT_VAR(service); - PHALCON_INIT_VAR(has_session); - ZVAL_STRING(service, "session", 1); + PHALCON_INIT_VAR(php_export); + PHALCON_CONCAT_SVS(php_export, " +// 28 "parser.lemon" -static PHP_METHOD(Phalcon_Http_Response, setRawHeader){ - zval *header, *headers; +#ifdef HAVE_CONFIG_H +#endif - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &header); - - PHALCON_INIT_VAR(headers); - phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); - phalcon_call_method_p1_key(NULL, headers, "setraw", header, 2352298299UL); - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Http_Response, resetHeaders){ - zval *headers; +static zval *phannot_ret_literal_zval(int type, phannot_parser_token *T) +{ + zval *ret; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", type); + if (T) { + add_assoc_stringl(ret, "value", T->token, T->token_len, 0); + efree(T); + } - PHALCON_INIT_VAR(headers); - phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); - phalcon_call_method_key(NULL, headers, "reset", 422548360UL); - RETURN_THIS(); + return ret; } -static PHP_METHOD(Phalcon_Http_Response, setExpires){ - - zval *datetime, *headers, *date, *utc_zone, *timezone; - zval *format, *utc_format, *utc_date, *expires_header; - zend_class_entry *ce0; +static zval *phannot_ret_array(zval *items) +{ + zval *ret; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHANNOT_T_ARRAY); - phalcon_fetch_params(1, 1, 0, &datetime); - - if (Z_TYPE_P(datetime) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "datetime parameter must be an instance of DateTime"); - return; - } - - PHALCON_INIT_VAR(headers); - phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); - - PHALCON_INIT_VAR(date); - if (phalcon_clone(date, datetime TSRMLS_CC) == FAILURE) { - return; - } - - PHALCON_INIT_VAR(utc_zone); - ZVAL_STRING(utc_zone, "UTC", 1); - ce0 = zend_fetch_class(SL("DateTimeZone"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - - PHALCON_INIT_VAR(timezone); - object_init_ex(timezone, ce0); - if (phalcon_has_constructor(timezone TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, timezone, "__construct", utc_zone, 1107214344UL); + if (items) { + add_assoc_zval(ret, "items", items); } - - phalcon_call_method_p1_key(NULL, date, "settimezone", timezone, 851039132UL); - - PHALCON_INIT_VAR(format); - ZVAL_STRING(format, "D, d M Y H:i:s", 1); - - PHALCON_INIT_VAR(utc_format); - phalcon_call_method_p1_key(utc_format, date, "format", format, 3131886190UL); - - PHALCON_INIT_VAR(utc_date); - PHALCON_CONCAT_VS(utc_date, utc_format, " GMT"); - - PHALCON_INIT_VAR(expires_header); - ZVAL_STRING(expires_header, "Expires", 1); - phalcon_call_method_p2_key(NULL, this_ptr, "setheader", expires_header, utc_date, 1102032250UL); - - RETURN_THIS(); + + return ret; } -static PHP_METHOD(Phalcon_Http_Response, setNotModified){ +static zval *phannot_ret_zval_list(zval *list_left, zval *right_list) +{ - zval *code, *status; + zval *ret; + HashPosition pos; + HashTable *list; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init(ret); - PHALCON_INIT_VAR(code); - ZVAL_LONG(code, 304); - - PHALCON_INIT_VAR(status); - ZVAL_STRING(status, "Not modified", 1); - phalcon_call_method_p2_key(NULL, this_ptr, "setstatuscode", code, status, 1498183248UL); - RETURN_THIS(); -} + if (list_left) { -static PHP_METHOD(Phalcon_Http_Response, setContentType){ + list = Z_ARRVAL_P(list_left); + if (zend_hash_index_exists(list, 0)) { + zend_hash_internal_pointer_reset_ex(list, &pos); + for (;; zend_hash_move_forward_ex(list, &pos)) { - zval *content_type, *charset = NULL, *headers, *name, *header_value; + zval ** item; - PHALCON_MM_GROW(); + if (zend_hash_get_current_data_ex(list, (void**) &item, &pos) == FAILURE) { + break; + } - phalcon_fetch_params(1, 1, 1, &content_type, &charset); - - if (!charset) { - PHALCON_INIT_VAR(charset); - } - - PHALCON_INIT_VAR(headers); - phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "Content-Type", 1); - if (Z_TYPE_P(charset) == IS_NULL) { - phalcon_call_method_p2_key(NULL, headers, "set", name, content_type, 2090720177UL); - } else { - PHALCON_INIT_VAR(header_value); - PHALCON_CONCAT_VSV(header_value, content_type, "; charset=", charset); - phalcon_call_method_p2_key(NULL, headers, "set", name, header_value, 2090720177UL); + Z_ADDREF_PP(item); + add_next_index_zval(ret, *item); + + } + zval_ptr_dtor(&list_left); + } else { + add_next_index_zval(ret, list_left); + } } - - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Http_Response, setEtag){ + add_next_index_zval(ret, right_list); - zval *etag, *name, *headers; + return ret; +} - PHALCON_MM_GROW(); +static zval *phannot_ret_named_item(phannot_parser_token *name, zval *expr) +{ + zval *ret; - phalcon_fetch_params(1, 1, 0, &etag); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "Etag", 1); - - PHALCON_INIT_VAR(headers); - phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); - phalcon_call_method_p2_key(NULL, headers, "set", name, etag, 2090720177UL); - RETURN_THIS(); + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_zval(ret, "expr", expr); + if (name != NULL) { + add_assoc_stringl(ret, "name", name->token, name->token_len, 0); + efree(name); + } + + return ret; } -static PHP_METHOD(Phalcon_Http_Response, redirect){ +static zval *phannot_ret_annotation(phannot_parser_token *name, zval *arguments, phannot_scanner_state *state) +{ - zval *location = NULL, *external_redirect = NULL, *status_code = NULL; - zval *header = NULL, *dependency_injector, *service; - zval *url, *status_text, *header_name; + zval *ret; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init(ret); - phalcon_fetch_params(1, 0, 3, &location, &external_redirect, &status_code); - - if (!location) { - PHALCON_INIT_VAR(location); - } - - if (!external_redirect) { - PHALCON_INIT_VAR(external_redirect); - ZVAL_BOOL(external_redirect, 0); - } - - if (!status_code) { - PHALCON_INIT_VAR(status_code); - ZVAL_LONG(status_code, 302); - } - - if (zend_is_true(external_redirect)) { - PHALCON_CPY_WRT(header, location); - } else { - PHALCON_INIT_VAR(dependency_injector); - phalcon_call_method_key(dependency_injector, this_ptr, "getdi", 4287060818UL); - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "url", 1); - - PHALCON_INIT_VAR(url); - phalcon_call_method_p1_key(url, dependency_injector, "getshared", service, 1727570332UL); - - PHALCON_INIT_NVAR(header); - phalcon_call_method_p1_key(header, url, "get", location, 2090288933UL); + add_assoc_long(ret, "type", PHANNOT_T_ANNOTATION); + + if (name) { + add_assoc_stringl(ret, "name", name->token, name->token_len, 0); + efree(name); } - - PHALCON_INIT_VAR(status_text); - ZVAL_STRING(status_text, "Redirect", 1); - phalcon_call_method_p2_key(NULL, this_ptr, "setstatuscode", status_code, status_text, 1498183248UL); - - PHALCON_INIT_VAR(header_name); - ZVAL_STRING(header_name, "Location", 1); - phalcon_call_method_p2_key(NULL, this_ptr, "setheader", header_name, header, 1102032250UL); - - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Http_Response, setContent){ + if (arguments) { + add_assoc_zval(ret, "arguments", arguments); + } - zval *content; + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); - phalcon_fetch_params(0, 1, 0, &content); - - phalcon_update_property_this_quick(this_ptr, SL("_content"), content, 4081318271UL TSRMLS_CC); - RETURN_THISW(); + return ret; } -static PHP_METHOD(Phalcon_Http_Response, setJsonContent){ - - zval *content, *json_options = NULL, *json_content; - int options = 0; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &content, &json_options); - - if (json_options) { - options = phalcon_get_intval(json_options); - } - - PHALCON_INIT_VAR(json_content); - phalcon_json_encode(json_content, content, options TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_content"), json_content, 4081318271UL TSRMLS_CC); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Http_Response, appendContent){ - - zval *content, *_content; - zval *r0 = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &content); - - PHALCON_OBS_VAR(_content); - phalcon_read_property_this_quick(&_content, this_ptr, SL("_content"), 4081318271UL, PH_NOISY_CC); - PHALCON_ALLOC_ZVAL_MM(r0); - concat_function(r0, _content, content TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_content"), r0, 4081318271UL TSRMLS_CC); - RETURN_THIS(); -} +// 139 "parser.c" +/* Next is all token values, in a form suitable for use by makeheaders. +** This section will be null unless lemon is run with the -m switch. +*/ +/* Make sure the INTERFACE macro is defined. +*/ +#ifndef INTERFACE +# define INTERFACE 1 +#endif +/* The next thing included is series of defines which control +** various aspects of the generated parser. +** JJCODETYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 terminals +** and nonterminals. "int" is used otherwise. +** JJNOCODE is a number of type JJCODETYPE which corresponds +** to no legal terminal or nonterminal number. This +** number is used to fill in empty slots of the hash +** table. +** JJFALLBACK If defined, this indicates that one or more tokens +** have fall-back values which should be used if the +** original value of the token will not parse. +** JJACTIONTYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 rules and +** states combined. "int" is used otherwise. +** phannot_JTOKENTYPE is the data type used for minor tokens given +** directly to the parser from the tokenizer. +** JJMINORTYPE is the data type used for all minor tokens. +** This is typically a union of many types, one of +** which is phannot_JTOKENTYPE. The entry in the union +** for base tokens is called "jj0". +** JJSTACKDEPTH is the maximum depth of the parser's stack. +** phannot_ARG_SDECL A static variable declaration for the %extra_argument +** phannot_ARG_PDECL A parameter declaration for the %extra_argument +** phannot_ARG_STORE Code to store %extra_argument into jjpParser +** phannot_ARG_FETCH Code to extract %extra_argument from jjpParser +** JJNSTATE the combined number of states. +** JJNRULE the number of rules in the grammar +** JJERRORSYMBOL is the code number of the error symbol. If not +** defined, then do no error processing. +*/ +#define JJCODETYPE unsigned char +#define JJNOCODE 28 +#define JJACTIONTYPE unsigned char +#define phannot_JTOKENTYPE phannot_parser_token* +typedef union { + phannot_JTOKENTYPE jj0; + zval* jj36; + int jj55; +} JJMINORTYPE; +#define JJSTACKDEPTH 100 +#define phannot_ARG_SDECL phannot_parser_status *status; +#define phannot_ARG_PDECL ,phannot_parser_status *status +#define phannot_ARG_FETCH phannot_parser_status *status = jjpParser->status +#define phannot_ARG_STORE jjpParser->status = status +#define JJNSTATE 40 +#define JJNRULE 25 +#define JJERRORSYMBOL 18 +#define JJERRSYMDT jj55 +#define JJ_NO_ACTION (JJNSTATE+JJNRULE+2) +#define JJ_ACCEPT_ACTION (JJNSTATE+JJNRULE+1) +#define JJ_ERROR_ACTION (JJNSTATE+JJNRULE) -static PHP_METHOD(Phalcon_Http_Response, getContent){ +/* Next are that tables used to determine what action to take based on the +** current state and lookahead token. These tables are used to implement +** functions that take a state number and lookahead value and return an +** action integer. +** +** Suppose the action integer is N. Then the action is determined as +** follows +** +** 0 <= N < JJNSTATE Shift N. That is, push the lookahead +** token onto the stack and goto state N. +** +** JJNSTATE <= N < JJNSTATE+JJNRULE Reduce by rule N-JJNSTATE. +** +** N == JJNSTATE+JJNRULE A syntax error has occurred. +** +** N == JJNSTATE+JJNRULE+1 The parser accepts its input. +** +** N == JJNSTATE+JJNRULE+2 No such action. Denotes unused +** slots in the jj_action[] table. +** +** The action table is constructed as a single large table named jj_action[]. +** Given state S and lookahead X, the action is computed as +** +** jj_action[ jj_shift_ofst[S] + X ] +** +** If the index value jj_shift_ofst[S]+X is out of range or if the value +** jj_lookahead[jj_shift_ofst[S]+X] is not equal to X or if jj_shift_ofst[S] +** is equal to JJ_SHIFT_USE_DFLT, it means that the action is not in the table +** and that jj_default[S] should be used instead. +** +** The formula above is for computing the action when the lookahead is +** a terminal symbol. If the lookahead is a non-terminal (as occurs after +** a reduce action) then the jj_reduce_ofst[] array is used in place of +** the jj_shift_ofst[] array and JJ_REDUCE_USE_DFLT is used in place of +** JJ_SHIFT_USE_DFLT. +** +** The following are the tables generated in this section: +** +** jj_action[] A single table containing all actions. +** jj_lookahead[] A table containing the lookahead for each entry in +** jj_action. Used to detect hash collisions. +** jj_shift_ofst[] For each state, the offset into jj_action for +** shifting terminals. +** jj_reduce_ofst[] For each state, the offset into jj_action for +** shifting non-terminals after a reduce. +** jj_default[] Default action for each state. +*/ +static JJACTIONTYPE jj_action[] = { + /* 0 */ 4, 28, 15, 38, 12, 14, 16, 18, 20, 21, + /* 10 */ 22, 23, 24, 4, 31, 4, 28, 15, 40, 12, + /* 20 */ 30, 16, 18, 20, 21, 22, 23, 24, 3, 31, + /* 30 */ 4, 17, 15, 6, 19, 35, 16, 18, 20, 21, + /* 40 */ 22, 23, 24, 5, 31, 15, 7, 27, 11, 16, + /* 50 */ 54, 54, 15, 25, 27, 11, 16, 15, 32, 27, + /* 60 */ 11, 16, 66, 1, 2, 39, 41, 15, 4, 10, + /* 70 */ 11, 16, 15, 9, 9, 37, 16, 8, 13, 36, + /* 80 */ 9, 29, 34, 54, 54, 54, 54, 54, 26, 54, + /* 90 */ 54, 54, 54, 54, 54, 54, 33, +}; +static JJCODETYPE jj_lookahead[] = { + /* 0 */ 2, 3, 22, 5, 6, 25, 26, 9, 10, 11, + /* 10 */ 12, 13, 14, 2, 16, 2, 3, 22, 0, 6, + /* 20 */ 25, 26, 9, 10, 11, 12, 13, 14, 22, 16, + /* 30 */ 2, 3, 22, 4, 6, 25, 26, 9, 10, 11, + /* 40 */ 12, 13, 14, 3, 16, 22, 23, 24, 25, 26, + /* 50 */ 27, 27, 22, 23, 24, 25, 26, 22, 23, 24, + /* 60 */ 25, 26, 19, 20, 21, 22, 0, 22, 2, 24, + /* 70 */ 25, 26, 22, 1, 1, 25, 26, 5, 7, 8, + /* 80 */ 1, 7, 8, 27, 27, 27, 27, 27, 15, 27, + /* 90 */ 27, 27, 27, 27, 27, 27, 17, +}; +#define JJ_SHIFT_USE_DFLT (-3) +static signed char jj_shift_ofst[] = { + /* 0 */ 11, 18, 66, -3, 40, 29, -2, 72, -3, 13, + /* 10 */ -3, -3, 71, 28, -3, -3, -3, -3, -3, -3, + /* 20 */ -3, -3, -3, -3, 13, 73, -3, -3, 74, 28, + /* 30 */ -3, 13, 79, -3, 28, -3, 28, -3, -3, -3, +}; +#define JJ_REDUCE_USE_DFLT (-21) +static signed char jj_reduce_ofst[] = { + /* 0 */ 43, -21, 6, -21, -21, -21, 23, -21, -21, 45, + /* 10 */ -21, -21, -21, -20, -21, -21, -21, -21, -21, -21, + /* 20 */ -21, -21, -21, -21, 30, -21, -21, -21, -21, -5, + /* 30 */ -21, 35, -21, -21, 10, -21, 50, -21, -21, -21, +}; +static JJACTIONTYPE jj_default[] = { + /* 0 */ 65, 65, 65, 42, 65, 46, 65, 65, 44, 65, + /* 10 */ 47, 49, 58, 65, 50, 54, 55, 56, 57, 58, + /* 20 */ 59, 60, 61, 62, 65, 65, 63, 48, 56, 65, + /* 30 */ 52, 65, 65, 64, 65, 53, 65, 51, 45, 43, +}; +#define JJ_SZ_ACTTAB (sizeof(jj_action)/sizeof(jj_action[0])) +/* The next table maps tokens into fallback tokens. If a construct +** like the following: +** +** %fallback ID X Y Z. +** +** appears in the grammer, then ID becomes a fallback token for X, Y, +** and Z. Whenever one of the tokens X, Y, or Z is input to the parser +** but it does not parse, the type of the token is changed to ID and +** the parse is retried before an error is thrown. +*/ +#ifdef JJFALLBACK +static const JJCODETYPE jjFallback[] = { +}; +#endif /* JJFALLBACK */ - RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); -} +/* The following structure represents a single element of the +** parser's stack. Information stored includes: +** +** + The state number for the parser at this level of the stack. +** +** + The value of the token stored at this level of the stack. +** (In other words, the "major" token.) +** +** + The semantic value stored at this level of the stack. This is +** the information used by the action routines in the grammar. +** It is sometimes called the "minor" token. +*/ +struct jjStackEntry { + int stateno; /* The state-number */ + int major; /* The major token value. This is the code + ** number for the token at this stack level */ + JJMINORTYPE minor; /* The user-supplied minor token value. This + ** is the value of the token */ +}; +typedef struct jjStackEntry jjStackEntry; -static PHP_METHOD(Phalcon_Http_Response, isSent){ +/* The state of the parser is completely contained in an instance of +** the following structure */ +struct jjParser { + int jjidx; /* Index of top element in stack */ + int jjerrcnt; /* Shifts left before out of the error */ + phannot_ARG_SDECL /* A place to hold %extra_argument */ + jjStackEntry jjstack[JJSTACKDEPTH]; /* The parser's stack */ +}; +typedef struct jjParser jjParser; +#ifndef NDEBUG +#include +static FILE *jjTraceFILE = 0; +static char *jjTracePrompt = 0; +#endif /* NDEBUG */ - RETURN_MEMBER_QUICK(this_ptr, "_sent", 3990052766UL); +#ifndef NDEBUG +static void phannot_Trace(FILE *TraceFILE, char *zTracePrompt){ + jjTraceFILE = TraceFILE; + jjTracePrompt = zTracePrompt; + if( jjTraceFILE==0 ) jjTracePrompt = 0; + else if( jjTracePrompt==0 ) jjTraceFILE = 0; } +#endif /* NDEBUG */ -static PHP_METHOD(Phalcon_Http_Response, sendHeaders){ - - zval *headers; +#ifndef NDEBUG +/* For tracing shifts, the names of all terminals and nonterminals +** are required. The following table supplies these names */ +static const char *jjTokenName[] = { + "$", "COMMA", "AT", "IDENTIFIER", + "PARENTHESES_OPEN", "PARENTHESES_CLOSE", "STRING", "EQUALS", + "COLON", "INTEGER", "DOUBLE", "NULL", + "FALSE", "TRUE", "BRACKET_OPEN", "BRACKET_CLOSE", + "SBRACKET_OPEN", "SBRACKET_CLOSE", "error", "program", + "annotation_language", "annotation_list", "annotation", "argument_list", + "argument_item", "expr", "array", +}; +#endif /* NDEBUG */ - PHALCON_MM_GROW(); +#ifndef NDEBUG +/* For tracing reduce actions, the names of all rules are required. +*/ +static const char *jjRuleName[] = { + /* 0 */ "program ::= annotation_language", + /* 1 */ "annotation_language ::= annotation_list", + /* 2 */ "annotation_list ::= annotation_list annotation", + /* 3 */ "annotation_list ::= annotation", + /* 4 */ "annotation ::= AT IDENTIFIER PARENTHESES_OPEN argument_list PARENTHESES_CLOSE", + /* 5 */ "annotation ::= AT IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE", + /* 6 */ "annotation ::= AT IDENTIFIER", + /* 7 */ "argument_list ::= argument_list COMMA argument_item", + /* 8 */ "argument_list ::= argument_item", + /* 9 */ "argument_item ::= expr", + /* 10 */ "argument_item ::= STRING EQUALS expr", + /* 11 */ "argument_item ::= STRING COLON expr", + /* 12 */ "argument_item ::= IDENTIFIER EQUALS expr", + /* 13 */ "argument_item ::= IDENTIFIER COLON expr", + /* 14 */ "expr ::= annotation", + /* 15 */ "expr ::= array", + /* 16 */ "expr ::= IDENTIFIER", + /* 17 */ "expr ::= INTEGER", + /* 18 */ "expr ::= STRING", + /* 19 */ "expr ::= DOUBLE", + /* 20 */ "expr ::= NULL", + /* 21 */ "expr ::= FALSE", + /* 22 */ "expr ::= TRUE", + /* 23 */ "array ::= BRACKET_OPEN argument_list BRACKET_CLOSE", + /* 24 */ "array ::= SBRACKET_OPEN argument_list SBRACKET_CLOSE", +}; +#endif /* NDEBUG */ - PHALCON_OBS_VAR(headers); - phalcon_read_property_this_quick(&headers, this_ptr, SL("_headers"), 1867660032UL, PH_NOISY_CC); - if (Z_TYPE_P(headers) == IS_OBJECT) { - phalcon_call_method_key(NULL, headers, "send", 274285871UL); - } - - RETURN_THIS(); +const char *phannot_TokenName(int tokenType){ +#ifndef NDEBUG + if( tokenType>0 && tokenType<(sizeof(jjTokenName)/sizeof(jjTokenName[0])) ){ + return jjTokenName[tokenType]; + }else{ + return "Unknown"; + } +#else + return ""; +#endif } -static PHP_METHOD(Phalcon_Http_Response, sendCookies){ - - zval *cookies; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(cookies); - phalcon_read_property_this_quick(&cookies, this_ptr, SL("_cookies"), 4109914289UL, PH_NOISY_CC); - if (Z_TYPE_P(cookies) == IS_OBJECT) { - phalcon_call_method_key(NULL, cookies, "send", 274285871UL); - } - - RETURN_THIS(); +void *phannot_Alloc(void *(*mallocProc)(size_t)){ + jjParser *pParser; + pParser = (jjParser*)(*mallocProc)( (size_t)sizeof(jjParser) ); + if( pParser ){ + pParser->jjidx = -1; + } + return pParser; } -static PHP_METHOD(Phalcon_Http_Response, send){ - - zval *sent, *headers, *cookies, *content, *file; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(sent); - phalcon_read_property_this_quick(&sent, this_ptr, SL("_sent"), 3990052766UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(sent)) { - - PHALCON_OBS_VAR(headers); - phalcon_read_property_this_quick(&headers, this_ptr, SL("_headers"), 1867660032UL, PH_NOISY_CC); - if (Z_TYPE_P(headers) == IS_OBJECT) { - phalcon_call_method_key(NULL, headers, "send", 274285871UL); - } - - PHALCON_OBS_VAR(cookies); - phalcon_read_property_this_quick(&cookies, this_ptr, SL("_cookies"), 4109914289UL, PH_NOISY_CC); - if (Z_TYPE_P(cookies) == IS_OBJECT) { - phalcon_call_method_key(NULL, cookies, "send", 274285871UL); - } - - PHALCON_OBS_VAR(content); - phalcon_read_property_this_quick(&content, this_ptr, SL("_content"), 4081318271UL, PH_NOISY_CC); - if (Z_STRLEN_P(content)) { - zend_print_zval(content, 0); - } - else { - PHALCON_OBS_VAR(file); - phalcon_read_property_this_quick(&file, this_ptr, SL("_file"), 3974776868UL, PH_NOISY_CC); - - if (Z_STRLEN_P(file)) { - php_stream *stream; - - stream = php_stream_open_wrapper(Z_STRVAL_P(file), "rb", REPORT_ERRORS, NULL); - if (stream != NULL) { - php_stream_passthru(stream); - php_stream_close(stream); - } - } +/* The following function deletes the value associated with a +** symbol. The symbol can be either a terminal or nonterminal. +** "jjmajor" is the symbol code, and "jjpminor" is a pointer to +** the value. +*/ +static void jj_destructor(JJCODETYPE jjmajor, JJMINORTYPE *jjpminor){ + switch( jjmajor ){ + /* Here is inserted the actions which take place when a + ** terminal or non-terminal is destroyed. This can happen + ** when the symbol is popped from the stack during a + ** reduce or during error processing or when a parser is + ** being destroyed before it is finished parsing. + ** + ** Note: during a reduce, the only symbols destroyed are those + ** which appear on the RHS of the rule, but which are not used + ** inside the C code. + */ + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: +// 222 "parser.lemon" +{ + if ((jjpminor->jj0)) { + if ((jjpminor->jj0)->free_flag) { + efree((jjpminor->jj0)->token); } - - phalcon_update_property_bool(this_ptr, SL("_sent"), 1 TSRMLS_CC); - - RETURN_THIS(); + efree((jjpminor->jj0)); } - - PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "Response was already sent"); - return; } - -static PHP_METHOD(Phalcon_Http_Response, setFileToSend){ - - zval *file_path, *attachment_name = NULL, *attachment = NULL, *base_path = NULL; - zval *headers, *content_description, *content_disposition; - zval *content_transfer; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &file_path, &attachment_name, &attachment); - - if (!attachment_name) { - PHALCON_INIT_VAR(attachment_name); - } - - if (!attachment) { - PHALCON_INIT_VAR(attachment); - ZVAL_BOOL(attachment, 1); - } - - if (Z_TYPE_P(attachment_name) != IS_STRING) { - PHALCON_INIT_VAR(base_path); - phalcon_call_func_p1(base_path, "basename", file_path); - } else { - PHALCON_CPY_WRT(base_path, attachment_name); - } - - if (zend_is_true(attachment)) { - PHALCON_INIT_VAR(headers); - phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); - - PHALCON_INIT_VAR(content_description); - ZVAL_STRING(content_description, "Content-Description: File Transfer", 1); - phalcon_call_method_p1_key(NULL, headers, "setraw", content_description, 2352298299UL); - - PHALCON_INIT_VAR(content_disposition); - PHALCON_CONCAT_SV(content_disposition, "Content-Disposition: attachment; filename=", base_path); - phalcon_call_method_p1_key(NULL, headers, "setraw", content_disposition, 2352298299UL); - - PHALCON_INIT_VAR(content_transfer); - ZVAL_STRING(content_transfer, "Content-Transfer-Encoding: binary", 1); - phalcon_call_method_p1_key(NULL, headers, "setraw", content_transfer, 2352298299UL); - } - phalcon_update_property_this_quick(this_ptr, SL("_file"), file_path, 3974776868UL TSRMLS_CC); - - RETURN_THIS(); +// 507 "parser.c" + break; + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: +// 235 "parser.lemon" +{ zval_ptr_dtor(&(jjpminor->jj36)); } +// 517 "parser.c" + break; + default: break; /* If no destructor action specified: do nothing */ + } } +static int jj_pop_parser_stack(jjParser *pParser){ + JJCODETYPE jjmajor; + jjStackEntry *jjtos = &pParser->jjstack[pParser->jjidx]; - - - -#ifdef HAVE_CONFIG_H + if( pParser->jjidx<0 ) return 0; +#ifndef NDEBUG + if( jjTraceFILE && pParser->jjidx>=0 ){ + fprintf(jjTraceFILE,"%sPopping %s\n", + jjTracePrompt, + jjTokenName[jjtos->major]); + } #endif - - - -PHALCON_INIT_CLASS(Phalcon_Http_ResponseInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Http, ResponseInterface, http_responseinterface, phalcon_http_responseinterface_method_entry); - - return SUCCESS; + jjmajor = jjtos->major; + jj_destructor( jjmajor, &jjtos->minor); + pParser->jjidx--; + return jjmajor; } +static void phannot_Free( + void *p, /* The parser to be deleted */ + void (*freeProc)(void*) /* Function used to reclaim memory */ +){ + jjParser *pParser = (jjParser*)p; + if( pParser==0 ) return; + while( pParser->jjidx>=0 ) jj_pop_parser_stack(pParser); + (*freeProc)((void*)pParser); +} - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H +static int jj_find_shift_action( + jjParser *pParser, /* The parser */ + int iLookAhead /* The look-ahead token */ +){ + int i; + int stateno = pParser->jjstack[pParser->jjidx].stateno; + + /* if( pParser->jjidx<0 ) return JJ_NO_ACTION; */ + i = jj_shift_ofst[stateno]; + if( i==JJ_SHIFT_USE_DFLT ){ + return jj_default[stateno]; + } + if( iLookAhead==JJNOCODE ){ + return JJ_NO_ACTION; + } + i += iLookAhead; + if( i<0 || i>=JJ_SZ_ACTTAB || jj_lookahead[i]!=iLookAhead ){ +#ifdef JJFALLBACK + int iFallback; /* Fallback token */ + if( iLookAhead %s\n", + jjTracePrompt, jjTokenName[iLookAhead], jjTokenName[iFallback]); + } #endif - - - -PHALCON_INIT_CLASS(Phalcon_Http_Request_FileInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Http\\Request, FileInterface, http_request_fileinterface, phalcon_http_request_fileinterface_method_entry); - - return SUCCESS; + return jj_find_shift_action(pParser, iFallback); + } +#endif + return jj_default[stateno]; + }else{ + return jj_action[i]; + } } +static int jj_find_reduce_action( + jjParser *pParser, /* The parser */ + int iLookAhead /* The look-ahead token */ +){ + int i; + int stateno = pParser->jjstack[pParser->jjidx].stateno; + + i = jj_reduce_ofst[stateno]; + if( i==JJ_REDUCE_USE_DFLT ){ + return jj_default[stateno]; + } + if( iLookAhead==JJNOCODE ){ + return JJ_NO_ACTION; + } + i += iLookAhead; + if( i<0 || i>=JJ_SZ_ACTTAB || jj_lookahead[i]!=iLookAhead ){ + return jj_default[stateno]; + }else{ + return jj_action[i]; + } +} +static void jj_shift( + jjParser *jjpParser, /* The parser to be shifted */ + int jjNewState, /* The new state to shift in */ + int jjMajor, /* The major token to shift in */ + JJMINORTYPE *jjpMinor /* Pointer ot the minor token to shift in */ +){ + jjStackEntry *jjtos; + jjpParser->jjidx++; + if( jjpParser->jjidx>=JJSTACKDEPTH ){ + phannot_ARG_FETCH; + jjpParser->jjidx--; +#ifndef NDEBUG + if( jjTraceFILE ){ + fprintf(jjTraceFILE,"%sStack Overflow!\n",jjTracePrompt); + } +#endif + while( jjpParser->jjidx>=0 ) jj_pop_parser_stack(jjpParser); + /* Here code is inserted which will execute if the parser + ** stack every overflows */ + phannot_ARG_STORE; /* Suppress warning about unused %extra_argument var */ + return; + } + jjtos = &jjpParser->jjstack[jjpParser->jjidx]; + jjtos->stateno = jjNewState; + jjtos->major = jjMajor; + jjtos->minor = *jjpMinor; +#ifndef NDEBUG + if( jjTraceFILE && jjpParser->jjidx>0 ){ + int i; + fprintf(jjTraceFILE,"%sShift %d\n",jjTracePrompt,jjNewState); + fprintf(jjTraceFILE,"%sStack:",jjTracePrompt); + for(i=1; i<=jjpParser->jjidx; i++) + fprintf(jjTraceFILE," %s",jjTokenName[jjpParser->jjstack[i].major]); + fprintf(jjTraceFILE,"\n"); + } +#endif +} +/* The following table contains information about every rule that +** is used during the reduce. +*/ +static struct { + JJCODETYPE lhs; /* Symbol on the left-hand side of the rule */ + unsigned char nrhs; /* Number of right-hand side symbols in the rule */ +} jjRuleInfo[] = { + { 19, 1 }, + { 20, 1 }, + { 21, 2 }, + { 21, 1 }, + { 22, 5 }, + { 22, 4 }, + { 22, 2 }, + { 23, 3 }, + { 23, 1 }, + { 24, 1 }, + { 24, 3 }, + { 24, 3 }, + { 24, 3 }, + { 24, 3 }, + { 25, 1 }, + { 25, 1 }, + { 25, 1 }, + { 25, 1 }, + { 25, 1 }, + { 25, 1 }, + { 25, 1 }, + { 25, 1 }, + { 25, 1 }, + { 26, 3 }, + { 26, 3 }, +}; +static void jj_accept(jjParser*); /* Forward Declaration */ +static void jj_reduce( + jjParser *jjpParser, /* The parser */ + int jjruleno /* Number of the rule by which to reduce */ +){ + int jjgoto; /* The next state */ + int jjact; /* The next action */ + JJMINORTYPE jjgotominor; /* The LHS of the rule reduced */ + jjStackEntry *jjmsp; /* The top of the parser's stack */ + int jjsize; /* Amount to pop the stack */ + phannot_ARG_FETCH; + jjmsp = &jjpParser->jjstack[jjpParser->jjidx]; +#ifndef NDEBUG + if( jjTraceFILE && jjruleno>=0 + && jjruleno + ** { ... } // User supplied code + ** // + ** break; + */ + case 0: +// 231 "parser.lemon" +{ + status->ret = jjmsp[0].minor.jj36; +} +// 759 "parser.c" + break; + case 1: + case 14: + case 15: +// 237 "parser.lemon" +{ + jjgotominor.jj36 = jjmsp[0].minor.jj36; +} +// 768 "parser.c" + break; + case 2: +// 243 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_zval_list(jjmsp[-1].minor.jj36, jjmsp[0].minor.jj36); +} +// 775 "parser.c" + break; + case 3: + case 8: +// 247 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_zval_list(NULL, jjmsp[0].minor.jj36); +} +// 783 "parser.c" + break; + case 4: +// 254 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_annotation(jjmsp[-3].minor.jj0, jjmsp[-1].minor.jj36, status->scanner_state); + jj_destructor(2,&jjmsp[-4].minor); + jj_destructor(4,&jjmsp[-2].minor); + jj_destructor(5,&jjmsp[0].minor); +} +// 793 "parser.c" + break; + case 5: +// 258 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_annotation(jjmsp[-2].minor.jj0, NULL, status->scanner_state); + jj_destructor(2,&jjmsp[-3].minor); + jj_destructor(4,&jjmsp[-1].minor); + jj_destructor(5,&jjmsp[0].minor); +} +// 803 "parser.c" + break; + case 6: +// 262 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_annotation(jjmsp[0].minor.jj0, NULL, status->scanner_state); + jj_destructor(2,&jjmsp[-1].minor); +} +// 811 "parser.c" + break; + case 7: +// 268 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_zval_list(jjmsp[-2].minor.jj36, jjmsp[0].minor.jj36); + jj_destructor(1,&jjmsp[-1].minor); +} +// 819 "parser.c" + break; + case 9: +// 278 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_named_item(NULL, jjmsp[0].minor.jj36); +} +// 826 "parser.c" + break; + case 10: + case 12: +// 282 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_named_item(jjmsp[-2].minor.jj0, jjmsp[0].minor.jj36); + jj_destructor(7,&jjmsp[-1].minor); +} +// 835 "parser.c" + break; + case 11: + case 13: +// 286 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_named_item(jjmsp[-2].minor.jj0, jjmsp[0].minor.jj36); + jj_destructor(8,&jjmsp[-1].minor); +} +// 844 "parser.c" + break; + case 16: +// 308 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_IDENTIFIER, jjmsp[0].minor.jj0); +} +// 851 "parser.c" + break; + case 17: +// 312 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_INTEGER, jjmsp[0].minor.jj0); +} +// 858 "parser.c" + break; + case 18: +// 316 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_STRING, jjmsp[0].minor.jj0); +} +// 865 "parser.c" + break; + case 19: +// 320 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_DOUBLE, jjmsp[0].minor.jj0); +} +// 872 "parser.c" + break; + case 20: +// 324 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_NULL, NULL); + jj_destructor(11,&jjmsp[0].minor); +} +// 880 "parser.c" + break; + case 21: +// 328 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_FALSE, NULL); + jj_destructor(12,&jjmsp[0].minor); +} +// 888 "parser.c" + break; + case 22: +// 332 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_TRUE, NULL); + jj_destructor(13,&jjmsp[0].minor); +} +// 896 "parser.c" + break; + case 23: +// 336 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_array(jjmsp[-1].minor.jj36); + jj_destructor(14,&jjmsp[-2].minor); + jj_destructor(15,&jjmsp[0].minor); +} +// 905 "parser.c" + break; + case 24: +// 340 "parser.lemon" +{ + jjgotominor.jj36 = phannot_ret_array(jjmsp[-1].minor.jj36); + jj_destructor(16,&jjmsp[-2].minor); + jj_destructor(17,&jjmsp[0].minor); +} +// 914 "parser.c" + break; + }; + jjgoto = jjRuleInfo[jjruleno].lhs; + jjsize = jjRuleInfo[jjruleno].nrhs; + jjpParser->jjidx -= jjsize; + jjact = jj_find_reduce_action(jjpParser,jjgoto); + if( jjact < JJNSTATE ){ + jj_shift(jjpParser,jjact,jjgoto,&jjgotominor); + }else if( jjact == JJNSTATE + JJNRULE + 1 ){ + jj_accept(jjpParser); + } +} - - - - - -#ifdef HAVE_CONFIG_H +static void jj_parse_failed( + jjParser *jjpParser /* The parser */ +){ + phannot_ARG_FETCH; +#ifndef NDEBUG + if( jjTraceFILE ){ + fprintf(jjTraceFILE,"%sFail!\n",jjTracePrompt); + } #endif + while( jjpParser->jjidx>=0 ) jj_pop_parser_stack(jjpParser); + /* Here code is inserted which will be executed whenever the + ** parser fails */ + phannot_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} +static void jj_syntax_error( + jjParser *jjpParser, /* The parser */ + int jjmajor, /* The major type of the error token */ + JJMINORTYPE jjminor /* The minor type of the error token */ +){ + phannot_ARG_FETCH; +#define JTOKEN (jjminor.jj0) +// 159 "parser.lemon" + if (status->scanner_state->start_length) { + { + char *token_name = NULL; + const phannot_token_names *tokens = phannot_tokens; + int token_found = 0; + int active_token = status->scanner_state->active_token; + int near_length = status->scanner_state->start_length; + if (active_token) { + do { + if (tokens->code == active_token) { + token_found = 1; + token_name = tokens->name; + break; + } + ++tokens; + } while (tokens[0].code != 0); + } + if (!token_name) { + token_found = 0; + token_name = estrndup("UNKNOWN", strlen("UNKNOWN")); + } + status->syntax_error_len = 128 + strlen(token_name) + Z_STRLEN_P(status->scanner_state->active_file); + status->syntax_error = emalloc(sizeof(char) * status->syntax_error_len); + if (near_length > 0) { + if (status->token->value) { + snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), near to '%s' in %s on line %d", token_name, status->token->value, status->scanner_state->start, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line); + } else { + snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, near to '%s' in %s on line %d", token_name, status->scanner_state->start, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line); + } + } else { + if (active_token != PHANNOT_T_IGNORE) { + if (status->token->value) { + snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), at the end of docblock in %s on line %d", token_name, status->token->value, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line); + } else { + snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, at the end of docblock in %s on line %d", token_name, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line); + } + } else { + snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected EOF, at the end of docblock in %s on line %d", Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line); + } + status->syntax_error[status->syntax_error_len-1] = '\0'; + } -PHALCON_INIT_CLASS(Phalcon_Http_Request_File){ - - PHALCON_REGISTER_CLASS(Phalcon\\Http\\Request, File, http_request_file, phalcon_http_request_file_method_entry, 0); + if (!token_found) { + if (token_name) { + efree(token_name); + } + } + } + } else { + status->syntax_error_len = 48 + Z_STRLEN_P(status->scanner_state->active_file); + status->syntax_error = emalloc(sizeof(char) * status->syntax_error_len); + sprintf(status->syntax_error, "Syntax error, unexpected EOF in %s", Z_STRVAL_P(status->scanner_state->active_file)); + } - zend_declare_property_null(phalcon_http_request_file_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_request_file_ce, SL("_tmp"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_request_file_ce, SL("_size"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_request_file_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_request_file_ce, SL("_error"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_http_request_file_ce, SL("_key"), ZEND_ACC_PROTECTED TSRMLS_CC); + status->status = PHANNOT_PARSING_FAILED; - zend_class_implements(phalcon_http_request_file_ce TSRMLS_CC, 1, phalcon_http_request_fileinterface_ce); +// 1019 "parser.c" + phannot_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} - return SUCCESS; +static void jj_accept( + jjParser *jjpParser /* The parser */ +){ + phannot_ARG_FETCH; +#ifndef NDEBUG + if( jjTraceFILE ){ + fprintf(jjTraceFILE,"%sAccept!\n",jjTracePrompt); + } +#endif + while( jjpParser->jjidx>=0 ) jj_pop_parser_stack(jjpParser); + /* Here code is inserted which will be executed whenever the + ** parser accepts */ + phannot_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ } -static PHP_METHOD(Phalcon_Http_Request_File, __construct){ +/* The main parser program. +** The first argument is a pointer to a structure obtained from +** "phannot_Alloc" which describes the current state of the parser. +** The second argument is the major token number. The third is +** the minor token. The fourth optional argument is whatever the +** user wants (and specified in the grammar) and is available for +** use by the action routines. +** +** Inputs: +**
    +**
  • A pointer to the parser (an opaque structure.) +**
  • The major token number. +**
  • The minor token number. +**
  • An option argument of a grammar-specified type. +**
+** +** Outputs: +** None. +*/ +static void phannot_( + void *jjp, /* The parser */ + int jjmajor, /* The major token code number */ + phannot_JTOKENTYPE jjminor /* The value for the token */ + phannot_ARG_PDECL /* Optional %extra_argument parameter */ +){ + JJMINORTYPE jjminorunion; + int jjact; /* The parser action. */ + int jjendofinput; /* True if we are at the end of input */ + int jjerrorhit = 0; /* True if jjmajor has invoked an error */ + jjParser *jjpParser; /* The parser */ - zval *file, *name, *temp_name, *size, *type, *error, *key = NULL; + /* (re)initialize the parser, if necessary */ + jjpParser = (jjParser*)jjp; + if( jjpParser->jjidx<0 ){ + if( jjmajor==0 ) return; + jjpParser->jjidx = 0; + jjpParser->jjerrcnt = -1; + jjpParser->jjstack[0].stateno = 0; + jjpParser->jjstack[0].major = 0; + } + jjminorunion.jj0 = jjminor; + jjendofinput = (jjmajor==0); + phannot_ARG_STORE; - PHALCON_MM_GROW(); +#ifndef NDEBUG + if( jjTraceFILE ){ + fprintf(jjTraceFILE,"%sInput %s\n",jjTracePrompt,jjTokenName[jjmajor]); + } +#endif - phalcon_fetch_params(1, 1, 1, &file, &key); - - if (Z_TYPE_P(file) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "Phalcon\\Http\\Request\\File requires a valid uploaded file"); - return; - } - if (phalcon_array_isset_quick_string(file, SS("name"), 268211462UL)) { - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, file, SS("name"), 268211462UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(file, SS("tmp_name"), 3852050422UL)) { - PHALCON_OBS_VAR(temp_name); - phalcon_array_fetch_quick_string(&temp_name, file, SS("tmp_name"), 3852050422UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_tmp"), temp_name, 251105813UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(file, SS("size"), 274442720UL)) { - PHALCON_OBS_VAR(size); - phalcon_array_fetch_quick_string(&size, file, SS("size"), 274442720UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_size"), size, 3990209087UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(file, SS("type"), 276192743UL)) { - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, file, SS("type"), 276192743UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(file, SS("error"), 4224147407UL)) { - PHALCON_OBS_VAR(error); - phalcon_array_fetch_quick_string(&error, file, SS("error"), 4224147407UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_error"), error, 2290385934UL TSRMLS_CC); - } - - if (key) { - phalcon_update_property_this_quick(this_ptr, SL("_key"), key, 250773965UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); + do{ + jjact = jj_find_shift_action(jjpParser,jjmajor); + if( jjactjjerrcnt--; + if( jjendofinput && jjpParser->jjidx>=0 ){ + jjmajor = 0; + }else{ + jjmajor = JJNOCODE; + } + }else if( jjact < JJNSTATE + JJNRULE ){ + jj_reduce(jjpParser,jjact-JJNSTATE); + }else if( jjact == JJ_ERROR_ACTION ){ + int jjmx; +#ifndef NDEBUG + if( jjTraceFILE ){ + fprintf(jjTraceFILE,"%sSyntax Error!\n",jjTracePrompt); + } +#endif +#ifdef JJERRORSYMBOL + /* A syntax error has occurred. + ** The response to an error depends upon whether or not the + ** grammar defines an error token "ERROR". + ** + ** This is what we do if the grammar does define ERROR: + ** + ** * Call the %syntax_error function. + ** + ** * Begin popping the stack until we enter a state where + ** it is legal to shift the error symbol, then shift + ** the error symbol. + ** + ** * Set the error count to three. + ** + ** * Begin accepting and shifting new tokens. No new error + ** processing will occur until three tokens have been + ** shifted successfully. + ** + */ + if( jjpParser->jjerrcnt<0 ){ + jj_syntax_error(jjpParser,jjmajor,jjminorunion); + } + jjmx = jjpParser->jjstack[jjpParser->jjidx].major; + if( jjmx==JJERRORSYMBOL || jjerrorhit ){ +#ifndef NDEBUG + if( jjTraceFILE ){ + fprintf(jjTraceFILE,"%sDiscard input token %s\n", + jjTracePrompt,jjTokenName[jjmajor]); + } +#endif + jj_destructor(jjmajor,&jjminorunion); + jjmajor = JJNOCODE; + }else{ + while( + jjpParser->jjidx >= 0 && + jjmx != JJERRORSYMBOL && + (jjact = jj_find_shift_action(jjpParser,JJERRORSYMBOL)) >= JJNSTATE + ){ + jj_pop_parser_stack(jjpParser); + } + if( jjpParser->jjidx < 0 || jjmajor==0 ){ + jj_destructor(jjmajor,&jjminorunion); + jj_parse_failed(jjpParser); + jjmajor = JJNOCODE; + }else if( jjmx!=JJERRORSYMBOL ){ + JJMINORTYPE u2; + u2.JJERRSYMDT = 0; + jj_shift(jjpParser,jjact,JJERRORSYMBOL,&u2); + } + } + jjpParser->jjerrcnt = 3; + jjerrorhit = 1; +#else /* JJERRORSYMBOL is not defined */ + /* This is what we do if the grammar does not define ERROR: + ** + ** * Report an error message, and throw away the input token. + ** + ** * If the input token is $, then fail the parse. + ** + ** As before, subsequent error messages are suppressed until + ** three input tokens have been successfully shifted. + */ + if( jjpParser->jjerrcnt<=0 ){ + jj_syntax_error(jjpParser,jjmajor,jjminorunion); + } + jjpParser->jjerrcnt = 3; + jj_destructor(jjmajor,&jjminorunion); + if( jjendofinput ){ + jj_parse_failed(jjpParser); + } + jjmajor = JJNOCODE; +#endif + }else{ + jj_accept(jjpParser); + jjmajor = JJNOCODE; + } + }while( jjmajor!=JJNOCODE && jjpParser->jjidx>=0 ); + return; } -static PHP_METHOD(Phalcon_Http_Request_File, getSize){ +const phannot_token_names phannot_tokens[] = +{ + { "INTEGER", PHANNOT_T_INTEGER }, + { "DOUBLE", PHANNOT_T_DOUBLE }, + { "STRING", PHANNOT_T_STRING }, + { "IDENTIFIER", PHANNOT_T_IDENTIFIER }, + { "@", PHANNOT_T_AT }, + { ",", PHANNOT_T_COMMA }, + { "=", PHANNOT_T_EQUALS }, + { ":", PHANNOT_T_COLON }, + { "(", PHANNOT_T_PARENTHESES_OPEN }, + { ")", PHANNOT_T_PARENTHESES_CLOSE }, + { "{", PHANNOT_T_BRACKET_OPEN }, + { "}", PHANNOT_T_BRACKET_CLOSE }, + { "[", PHANNOT_T_SBRACKET_OPEN }, + { "]", PHANNOT_T_SBRACKET_CLOSE }, + { "ARBITRARY TEXT", PHANNOT_T_ARBITRARY_TEXT }, + { NULL, 0 } +}; - RETURN_MEMBER_QUICK(this_ptr, "_size", 3990209087UL); +static void *phannot_wrapper_alloc(size_t bytes){ + return emalloc(bytes); } -static PHP_METHOD(Phalcon_Http_Request_File, getName){ +static void phannot_wrapper_free(void *pointer){ + efree(pointer); +} +static void phannot_parse_with_token(void* phannot_parser, int opcode, int parsercode, phannot_scanner_token *token, phannot_parser_status *parser_status){ - RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); -} + phannot_parser_token *pToken; -static PHP_METHOD(Phalcon_Http_Request_File, getTempName){ + pToken = emalloc(sizeof(phannot_parser_token)); + pToken->opcode = opcode; + pToken->token = token->value; + pToken->token_len = token->len; + pToken->free_flag = 1; + phannot_(phannot_parser, parsercode, pToken, parser_status); - RETURN_MEMBER_QUICK(this_ptr, "_tmp", 251105813UL); + token->value = NULL; + token->len = 0; } -static PHP_METHOD(Phalcon_Http_Request_File, getType){ +static void phannot_scanner_error_msg(phannot_parser_status *parser_status, zval **error_msg TSRMLS_DC){ + int error_length; + char *error, *error_part; + phannot_scanner_state *state = parser_status->scanner_state; - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); + PHALCON_INIT_VAR(*error_msg); + if (state->start) { + error_length = 128 + state->start_length + Z_STRLEN_P(state->active_file); + error = emalloc(sizeof(char) * error_length); + if (state->start_length > 16) { + error_part = estrndup(state->start, 16); + snprintf(error, 64 + state->start_length, "Scanning error before '%s...' in %s on line %d", error_part, Z_STRVAL_P(state->active_file), state->active_line); + efree(error_part); + } else { + snprintf(error, error_length - 1, "Scanning error before '%s' in %s on line %d", state->start, Z_STRVAL_P(state->active_file), state->active_line); + } + error[error_length - 1] = '\0'; + ZVAL_STRING(*error_msg, error, 1); + } else { + error_length = sizeof(char) * (64 + Z_STRLEN_P(state->active_file)); + error = emalloc(error_length); + snprintf(error, error_length - 1, "Scanning error near to EOF in %s", Z_STRVAL_P(state->active_file)); + ZVAL_STRING(*error_msg, error, 1); + error[error_length - 1] = '\0'; + } + efree(error); } -static PHP_METHOD(Phalcon_Http_Request_File, getRealType){ +static int phannot_parse_annotations(zval *result, zval *comment, zval *file_path, zval *line TSRMLS_DC){ + zval *error_msg = NULL; - -} + ZVAL_NULL(result); -static PHP_METHOD(Phalcon_Http_Request_File, getError){ + if (Z_TYPE_P(comment) != IS_STRING) { + phalcon_throw_exception_string(phalcon_annotations_exception_ce, SL("Comment must be a string"), 1 TSRMLS_CC); + return FAILURE; + } + if(phannot_internal_parse_annotations(&result, comment, file_path, line, &error_msg TSRMLS_CC) == FAILURE){ + phalcon_throw_exception_string(phalcon_annotations_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC); + return FAILURE; + } - RETURN_MEMBER_QUICK(this_ptr, "_error", 2290385934UL); + return SUCCESS; } -static PHP_METHOD(Phalcon_Http_Request_File, getKey){ +static void phannot_remove_comment_separators(zval *return_value, char *comment, int length, int *start_lines) { - RETURN_MEMBER_QUICK(this_ptr, "_key", 250773965UL); -} + int start_mode = 1, j, i, open_parentheses; + smart_str processed_str = {0}; + char ch; -static PHP_METHOD(Phalcon_Http_Request_File, isUploadedFile) { + (*start_lines) = 0; - zval *tmp_name; + for (i = 0; i < length; i++) { - if (!SG(rfc1867_uploaded_files)) { - RETURN_FALSE; - } + ch = comment[i]; - PHALCON_ALLOC_ZVAL(tmp_name); - if (phalcon_call_method_params_w(tmp_name, getThis(), SL("gettempname"), 0, NULL, 0, 0 TSRMLS_CC) == SUCCESS) { - if (Z_TYPE_P(tmp_name) == IS_STRING && zend_hash_exists(SG(rfc1867_uploaded_files), Z_STRVAL_P(tmp_name), Z_STRLEN_P(tmp_name) + 1)) { - RETVAL_TRUE; - } - else { - RETVAL_FALSE; + if (start_mode) { + if (ch == ' ' || ch == '*' || ch == '/' || ch == '\t' || ch == 11) { + continue; + } + start_mode = 0; } - } - zval_ptr_dtor(&tmp_name); -} + if (ch == '@') { -static PHP_METHOD(Phalcon_Http_Request_File, moveTo){ + smart_str_appendc(&processed_str, ch); + i++; - zval *destination, *temp_file; + open_parentheses = 0; + for (j = i; j < length; j++) { - PHALCON_MM_GROW(); + ch = comment[j]; - phalcon_fetch_params(1, 1, 0, &destination); - - PHALCON_OBS_VAR(temp_file); - phalcon_read_property_this_quick(&temp_file, this_ptr, SL("_tmp"), 251105813UL, PH_NOISY_CC); - phalcon_call_func_p2(return_value, "move_uploaded_file", temp_file, destination); - RETURN_MM(); -} + if (start_mode) { + if (ch == ' ' || ch == '*' || ch == '/' || ch == '\t' || ch == 11) { + continue; + } + start_mode = 0; + } -static PHP_METHOD(Phalcon_Http_Request_File, __set_state) { + if (open_parentheses == 0) { - zval *data; + if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { + smart_str_appendc(&processed_str, ch); + continue; + } - phalcon_fetch_params(0, 1, 0, &data); + if (ch == '(') { + smart_str_appendc(&processed_str, ch); + open_parentheses++; + continue; + } - object_init_ex(return_value, phalcon_http_request_file_ce); + } else { - PHALCON_MM_GROW(); - phalcon_call_method_p1_key(NULL, return_value, "__construct", data, 1107214344UL); - PHALCON_MM_RESTORE(); -} + smart_str_appendc(&processed_str, ch); + if (ch == '(') { + open_parentheses++; + } else { + if (ch == ')') { + open_parentheses--; + } else { + if (ch == '\n') { + (*start_lines)++; + start_mode = 1; + } + } + } + if (open_parentheses > 0) { + continue; + } + } + i = j; + smart_str_appendc(&processed_str, ' '); + break; + } + } -#ifdef HAVE_CONFIG_H -#endif + if (ch == '\n') { + (*start_lines)++; + start_mode = 1; + } + } + smart_str_0(&processed_str); + if (processed_str.len) { + RETURN_STRINGL(processed_str.c, processed_str.len, 0); + } else { + RETURN_EMPTY_STRING(); + } +} +static int phannot_internal_parse_annotations(zval **result, zval *comment, zval *file_path, zval *line, zval **error_msg TSRMLS_DC) { + char *error; + phannot_scanner_state *state; + phannot_scanner_token token; + int scanner_status, status = SUCCESS, start_lines, error_length; + phannot_parser_status *parser_status = NULL; + void* phannot_parser; + zval processed_comment; + if (!Z_STRVAL_P(comment)) { + ZVAL_BOOL(*result, 0); + return FAILURE; + } -PHALCON_INIT_CLASS(Phalcon_Http_Request_Exception){ + if (Z_STRLEN_P(comment) < 2) { + ZVAL_BOOL(*result, 0); + return SUCCESS; + } - PHALCON_REGISTER_CLASS_EX(Phalcon\\Http\\Request, Exception, http_request_exception, "phalcon\\exception", NULL, 0); + phannot_remove_comment_separators(&processed_comment, Z_STRVAL_P(comment), Z_STRLEN_P(comment), &start_lines); - return SUCCESS; -} + if (Z_STRLEN(processed_comment) < 2) { + ZVAL_BOOL(*result, 0); + efree(Z_STRVAL(processed_comment)); + return SUCCESS; + } + phannot_parser = phannot_Alloc(phannot_wrapper_alloc); + parser_status = emalloc(sizeof(phannot_parser_status)); + state = emalloc(sizeof(phannot_scanner_state)); + parser_status->status = PHANNOT_PARSING_OK; + parser_status->scanner_state = state; + parser_status->ret = NULL; + parser_status->token = &token; + parser_status->syntax_error = NULL; + state->active_token = 0; + state->start = Z_STRVAL(processed_comment); + state->start_length = 0; + state->mode = PHANNOT_MODE_RAW; + state->active_file = file_path; -#ifdef HAVE_CONFIG_H -#endif + token.value = NULL; + token.len = 0; + if (Z_TYPE_P(line) == IS_LONG) { + state->active_line = Z_LVAL_P(line) - start_lines; + } else { + state->active_line = 1; + } + state->end = state->start; + while(0 <= (scanner_status = phannot_get_token(state, &token))) { + state->active_token = token.opcode; + state->start_length = (Z_STRVAL(processed_comment) + Z_STRLEN(processed_comment) - state->start); -PHALCON_INIT_CLASS(Phalcon_Http_Cookie_Exception){ + switch (token.opcode) { - PHALCON_REGISTER_CLASS_EX(Phalcon\\Http\\Cookie, Exception, http_cookie_exception, "phalcon\\exception", NULL, 0); + case PHANNOT_T_IGNORE: + break; - return SUCCESS; -} + case PHANNOT_T_AT: + phannot_(phannot_parser, PHANNOT_AT, NULL, parser_status); + break; + case PHANNOT_T_COMMA: + phannot_(phannot_parser, PHANNOT_COMMA, NULL, parser_status); + break; + case PHANNOT_T_EQUALS: + phannot_(phannot_parser, PHANNOT_EQUALS, NULL, parser_status); + break; + case PHANNOT_T_COLON: + phannot_(phannot_parser, PHANNOT_COLON, NULL, parser_status); + break; + case PHANNOT_T_PARENTHESES_OPEN: + phannot_(phannot_parser, PHANNOT_PARENTHESES_OPEN, NULL, parser_status); + break; + case PHANNOT_T_PARENTHESES_CLOSE: + phannot_(phannot_parser, PHANNOT_PARENTHESES_CLOSE, NULL, parser_status); + break; + case PHANNOT_T_BRACKET_OPEN: + phannot_(phannot_parser, PHANNOT_BRACKET_OPEN, NULL, parser_status); + break; + case PHANNOT_T_BRACKET_CLOSE: + phannot_(phannot_parser, PHANNOT_BRACKET_CLOSE, NULL, parser_status); + break; + case PHANNOT_T_SBRACKET_OPEN: + phannot_(phannot_parser, PHANNOT_SBRACKET_OPEN, NULL, parser_status); + break; + case PHANNOT_T_SBRACKET_CLOSE: + phannot_(phannot_parser, PHANNOT_SBRACKET_CLOSE, NULL, parser_status); + break; + case PHANNOT_T_NULL: + phannot_(phannot_parser, PHANNOT_NULL, NULL, parser_status); + break; + case PHANNOT_T_TRUE: + phannot_(phannot_parser, PHANNOT_TRUE, NULL, parser_status); + break; + case PHANNOT_T_FALSE: + phannot_(phannot_parser, PHANNOT_FALSE, NULL, parser_status); + break; -#ifdef HAVE_CONFIG_H -#endif + case PHANNOT_T_INTEGER: + phannot_parse_with_token(phannot_parser, PHANNOT_T_INTEGER, PHANNOT_INTEGER, &token, parser_status); + break; + case PHANNOT_T_DOUBLE: + phannot_parse_with_token(phannot_parser, PHANNOT_T_DOUBLE, PHANNOT_DOUBLE, &token, parser_status); + break; + case PHANNOT_T_STRING: + phannot_parse_with_token(phannot_parser, PHANNOT_T_STRING, PHANNOT_STRING, &token, parser_status); + break; + case PHANNOT_T_IDENTIFIER: + phannot_parse_with_token(phannot_parser, PHANNOT_T_IDENTIFIER, PHANNOT_IDENTIFIER, &token, parser_status); + break; + /*case PHANNOT_T_ARBITRARY_TEXT: + phannot_parse_with_token(phannot_parser, PHANNOT_T_ARBITRARY_TEXT, PHANNOT_ARBITRARY_TEXT, &token, parser_status); + break;*/ + default: + parser_status->status = PHANNOT_PARSING_FAILED; + if (!*error_msg) { + error_length = sizeof(char) * (48 + Z_STRLEN_P(state->active_file)); + error = emalloc(error_length); + snprintf(error, error_length - 1, "Scanner: unknown opcode %d on in %s line %d", token.opcode, Z_STRVAL_P(state->active_file), state->active_line); + error[error_length - 1] = '\0'; + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, error, 1); + efree(error); + } + break; + } + if (parser_status->status != PHANNOT_PARSING_OK) { + status = FAILURE; + break; + } -PHALCON_INIT_CLASS(Phalcon_DispatcherInterface){ + state->end = state->start; + } - PHALCON_REGISTER_INTERFACE(Phalcon, DispatcherInterface, dispatcherinterface, phalcon_dispatcherinterface_method_entry); + if (status != FAILURE) { + switch (scanner_status) { + case PHANNOT_SCANNER_RETCODE_ERR: + case PHANNOT_SCANNER_RETCODE_IMPOSSIBLE: + if (!*error_msg) { + phannot_scanner_error_msg(parser_status, error_msg TSRMLS_CC); + } + status = FAILURE; + break; + default: + phannot_(phannot_parser, 0, NULL, parser_status); + } + } - return SUCCESS; -} + state->active_token = 0; + state->start = NULL; + if (parser_status->status != PHANNOT_PARSING_OK) { + status = FAILURE; + if (parser_status->syntax_error) { + if (!*error_msg) { + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, parser_status->syntax_error, 1); + } + efree(parser_status->syntax_error); + } + } + phannot_Free(phannot_parser, phannot_wrapper_free); + if (status != FAILURE) { + if (parser_status->status == PHANNOT_PARSING_OK) { + if (parser_status->ret) { + ZVAL_ZVAL(*result, parser_status->ret, 0, 0); + ZVAL_NULL(parser_status->ret); + zval_ptr_dtor(&parser_status->ret); + } else { + array_init(*result); + } + } + } + efree(Z_STRVAL(processed_comment)); + efree(parser_status); + efree(state); + return status; +} +#ifdef HAVE_CONFIG_H +#endif @@ -15422,83 +15580,195 @@ PHALCON_INIT_CLASS(Phalcon_DispatcherInterface){ +PHALCON_INIT_CLASS(Phalcon_Annotations_Reader){ -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db){ - - PHALCON_REGISTER_CLASS(Phalcon, Db, db, phalcon_db_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Reader, annotations_reader, phalcon_annotations_reader_method_entry, 0); - zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_ASSOC"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_BOTH"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_NUM"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_OBJ"), 4 TSRMLS_CC); + zend_class_implements(phalcon_annotations_reader_ce TSRMLS_CC, 1, phalcon_annotations_readerinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Db, setup){ +static PHP_METHOD(Phalcon_Annotations_Reader, parse){ - zval *options, *escape_identifiers; + zval *class_name, *annotations, *reflection; + zval *comment = NULL, *file = NULL, *line = NULL, *class_annotations; + zval *properties, *annotations_properties; + zval *property = NULL, *property_annotations = NULL, *name = NULL; + zval *methods, *annotations_methods, *method = NULL; + zval *method_annotations = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; + zend_class_entry *ce0; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &options); + phalcon_fetch_params(1, 1, 0, &class_name); - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Options must be an array"); + if (unlikely(Z_TYPE_P(class_name) != IS_STRING)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "The class name must be an object"); return; } - if (phalcon_array_isset_quick_string(options, SS("escapeSqlIdentifiers"), 2537413436UL)) { - PHALCON_OBS_VAR(escape_identifiers); - phalcon_array_fetch_quick_string(&escape_identifiers, options, SS("escapeSqlIdentifiers"), 2537413436UL, PH_NOISY); - PHALCON_GLOBAL(db).escape_identifiers = zend_is_true(escape_identifiers); + PHALCON_INIT_VAR(annotations); + array_init(annotations); + + ce0 = zend_fetch_class(SL("ReflectionClass"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + + PHALCON_INIT_VAR(reflection); + object_init_ex(reflection, ce0); + if (phalcon_has_constructor(reflection TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, reflection, "__construct", class_name, 1107214344UL); } - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(comment); + phalcon_call_method_key(comment, reflection, "getdoccomment", 185815758UL); + if (Z_TYPE_P(comment) == IS_STRING) { + + PHALCON_INIT_VAR(file); + phalcon_call_method_key(file, reflection, "getfilename", 984101030UL); + + PHALCON_INIT_VAR(line); + phalcon_call_method_key(line, reflection, "getstartline", 2520085083UL); + + PHALCON_INIT_VAR(class_annotations); + if (phannot_parse_annotations(class_annotations, comment, file, line TSRMLS_CC) == FAILURE) { + return; + } + + if (Z_TYPE_P(class_annotations) == IS_ARRAY) { + phalcon_array_update_quick_string(&annotations, SS("class"), 4138154555UL, &class_annotations, PH_COPY | PH_SEPARATE); + } + } + + PHALCON_INIT_VAR(properties); + phalcon_call_method_key(properties, reflection, "getproperties", 3608986354UL); + if (phalcon_fast_count_ev(properties TSRMLS_CC)) { + + PHALCON_INIT_NVAR(line); + ZVAL_LONG(line, 1); + + PHALCON_INIT_VAR(annotations_properties); + array_init(annotations_properties); + + phalcon_is_iterable(properties, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(property); + + PHALCON_INIT_NVAR(comment); + phalcon_call_method_key(comment, property, "getdoccomment", 185815758UL); + if (Z_TYPE_P(comment) == IS_STRING) { + + PHALCON_INIT_NVAR(file); + phalcon_call_method_key(file, reflection, "getfilename", 984101030UL); + + PHALCON_INIT_NVAR(property_annotations); + if (phannot_parse_annotations(property_annotations, comment, file, line TSRMLS_CC) == FAILURE) { + return; + } + if (Z_TYPE_P(property_annotations) == IS_ARRAY) { + PHALCON_OBS_NVAR(name); + phalcon_read_property(&name, property, SL("name"), PH_NOISY_CC); + phalcon_array_update_zval(&annotations_properties, name, &property_annotations, PH_COPY | PH_SEPARATE); + } + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + if (phalcon_fast_count_ev(annotations_properties TSRMLS_CC)) { + phalcon_array_update_quick_string(&annotations, SS("properties"), 1619284338UL, &annotations_properties, PH_COPY | PH_SEPARATE); + } + } + + PHALCON_INIT_VAR(methods); + phalcon_call_method_key(methods, reflection, "getmethods", 20298521UL); + if (phalcon_fast_count_ev(methods TSRMLS_CC)) { + + PHALCON_INIT_VAR(annotations_methods); + array_init(annotations_methods); + + phalcon_is_iterable(methods, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(method); + + PHALCON_INIT_NVAR(comment); + phalcon_call_method_key(comment, method, "getdoccomment", 185815758UL); + if (Z_TYPE_P(comment) == IS_STRING) { + + PHALCON_INIT_NVAR(file); + phalcon_call_method_key(file, method, "getfilename", 984101030UL); + + PHALCON_INIT_NVAR(line); + phalcon_call_method_key(line, method, "getstartline", 2520085083UL); + + PHALCON_INIT_NVAR(method_annotations); + if (phannot_parse_annotations(method_annotations, comment, file, line TSRMLS_CC) == FAILURE) { + return; + } + if (Z_TYPE_P(method_annotations) == IS_ARRAY) { + PHALCON_OBS_NVAR(name); + phalcon_read_property(&name, method, SL("name"), PH_NOISY_CC); + phalcon_array_update_zval(&annotations_methods, name, &method_annotations, PH_COPY | PH_SEPARATE); + } + } + + zend_hash_move_forward_ex(ah1, &hp1); + } + + if (phalcon_fast_count_ev(annotations_methods TSRMLS_CC)) { + phalcon_array_update_quick_string(&annotations, SS("methods"), 2292439449UL, &annotations_methods, PH_COPY | PH_SEPARATE); + } + } + + RETURN_CTOR(annotations); } +static PHP_METHOD(Phalcon_Annotations_Reader, parseDocBlock){ + zval *doc_block, *file = NULL, *line = NULL; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_FlashInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon, FlashInterface, flashinterface, phalcon_flashinterface_method_entry); - - return SUCCESS; + phalcon_fetch_params(1, 1, 2, &doc_block, &file, &line); + + if (!file) { + PHALCON_INIT_VAR(file); + } else { + PHALCON_SEPARATE_PARAM(file); + } + + if (!line) { + PHALCON_INIT_VAR(line); + } + + if (Z_TYPE_P(file) != IS_STRING) { + PHALCON_INIT_NVAR(file); + ZVAL_STRING(file, "eval code", 1); + } + if (phannot_parse_annotations(return_value, doc_block, file, line TSRMLS_CC) == FAILURE) { + return; + } + RETURN_MM(); } - - - - - #ifdef HAVE_CONFIG_H #endif -PHALCON_INIT_CLASS(Phalcon_Db_DialectInterface){ +PHALCON_INIT_CLASS(Phalcon_Annotations_ReaderInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, DialectInterface, db_dialectinterface, phalcon_db_dialectinterface_method_entry); + PHALCON_REGISTER_INTERFACE(Phalcon\\Annotations, ReaderInterface, annotations_readerinterface, phalcon_annotations_readerinterface_method_entry); return SUCCESS; } @@ -15509,32 +15779,6 @@ PHALCON_INIT_CLASS(Phalcon_Db_DialectInterface){ - - - - - - - - - - - - - - - - - - - - - - - - - - #ifdef HAVE_CONFIG_H #endif @@ -15544,1656 +15788,1411 @@ PHALCON_INIT_CLASS(Phalcon_Db_DialectInterface){ -PHALCON_INIT_CLASS(Phalcon_Db_Profiler){ +PHALCON_INIT_CLASS(Phalcon_Annotations_Reflection){ - PHALCON_REGISTER_CLASS(Phalcon\\Db, Profiler, db_profiler, phalcon_db_profiler_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Reflection, annotations_reflection, phalcon_annotations_reflection_method_entry, 0); - zend_declare_property_null(phalcon_db_profiler_ce, SL("_allProfiles"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_profiler_ce, SL("_activeProfile"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_db_profiler_ce, SL("_totalSeconds"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_reflectionData"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_classAnnotations"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_methodAnnotations"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_propertyAnnotations"), ZEND_ACC_PROTECTED TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Profiler, startProfile){ +static PHP_METHOD(Phalcon_Annotations_Reflection, __construct){ - zval *sql_statement, *active_profile, *micro; - zval *time; + zval *reflection_data = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &sql_statement); - - PHALCON_INIT_VAR(active_profile); - object_init_ex(active_profile, phalcon_db_profiler_item_ce); - phalcon_call_method_p1_key(NULL, active_profile, "setsqlstatement", sql_statement, 4146869238UL); - - PHALCON_INIT_VAR(micro); - ZVAL_BOOL(micro, 1); + phalcon_fetch_params(1, 0, 1, &reflection_data); - PHALCON_INIT_VAR(time); - phalcon_call_func_p1(time, "microtime", micro); - phalcon_call_method_p1_key(NULL, active_profile, "setinitialtime", time, 841971978UL); - if (phalcon_method_quick_exists_ex(this_ptr, SS("beforestartprofile"), 1538499511UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_p1_key(NULL, this_ptr, "beforestartprofile", active_profile, 1538499511UL); + if (!reflection_data) { + PHALCON_INIT_VAR(reflection_data); } - phalcon_update_property_this_quick(this_ptr, SL("_activeProfile"), active_profile, 794883025UL TSRMLS_CC); + if (Z_TYPE_P(reflection_data) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_reflectionData"), reflection_data, 3848141129UL TSRMLS_CC); + } - RETURN_THIS(); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Profiler, stopProfile){ +static PHP_METHOD(Phalcon_Annotations_Reflection, getClassAnnotations){ - zval *micro, *final_time, *active_profile, *initial_time; - zval *diference, *total_seconds, *new_total_seconds; + zval *annotations, *reflection_data, *reflection_class; + zval *collection; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(micro); - ZVAL_BOOL(micro, 1); - - PHALCON_INIT_VAR(final_time); - phalcon_call_func_p1(final_time, "microtime", micro); - - PHALCON_OBS_VAR(active_profile); - phalcon_read_property_this_quick(&active_profile, this_ptr, SL("_activeProfile"), 794883025UL, PH_NOISY_CC); - phalcon_call_method_p1_key(NULL, active_profile, "setfinaltime", final_time, 3915967498UL); + PHALCON_OBS_VAR(annotations); + phalcon_read_property_this_quick(&annotations, this_ptr, SL("_classAnnotations"), 372163368UL, PH_NOISY_CC); + if (Z_TYPE_P(annotations) != IS_OBJECT) { - PHALCON_INIT_VAR(initial_time); - phalcon_call_method_key(initial_time, active_profile, "getinitialtime", 2329302014UL); + PHALCON_OBS_VAR(reflection_data); + phalcon_read_property_this_quick(&reflection_data, this_ptr, SL("_reflectionData"), 3848141129UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(reflection_data, SS("class"), 4138154555UL)) { + PHALCON_OBS_VAR(reflection_class); + phalcon_array_fetch_quick_string(&reflection_class, reflection_data, SS("class"), 4138154555UL, PH_NOISY); - PHALCON_INIT_VAR(diference); - sub_function(diference, final_time, initial_time TSRMLS_CC); + PHALCON_INIT_VAR(collection); + object_init_ex(collection, phalcon_annotations_collection_ce); + phalcon_call_method_p1_key(NULL, collection, "__construct", reflection_class, 1107214344UL); - PHALCON_OBS_VAR(total_seconds); - phalcon_read_property_this_quick(&total_seconds, this_ptr, SL("_totalSeconds"), 996888727UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_classAnnotations"), collection, 372163368UL TSRMLS_CC); + RETURN_CTOR(collection); + } - PHALCON_INIT_VAR(new_total_seconds); - phalcon_add_function(new_total_seconds, total_seconds, diference TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_totalSeconds"), new_total_seconds, 996888727UL TSRMLS_CC); - phalcon_update_property_array_append(this_ptr, SL("_allProfiles"), active_profile TSRMLS_CC); - if (phalcon_method_quick_exists_ex(this_ptr, SS("afterendprofile"), 3954247487UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_p1_key(NULL, this_ptr, "afterendprofile", active_profile, 3954247487UL); + phalcon_update_property_bool(this_ptr, SL("_classAnnotations"), 0 TSRMLS_CC); + RETURN_MM_FALSE; } - RETURN_THIS(); + RETURN_CCTOR(annotations); } -static PHP_METHOD(Phalcon_Db_Profiler, getNumberTotalStatements){ +static PHP_METHOD(Phalcon_Annotations_Reflection, getMethodsAnnotations){ - zval *all_profiles; + zval *annotations, *reflection_data, *reflection_methods; + zval *collections, *reflection_method = NULL, *method_name = NULL; + zval *collection = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(all_profiles); - phalcon_read_property_this_quick(&all_profiles, this_ptr, SL("_allProfiles"), 1465095617UL, PH_NOISY_CC); - phalcon_fast_count(return_value, all_profiles TSRMLS_CC); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Profiler, getTotalElapsedSeconds){ - - - RETURN_MEMBER_QUICK(this_ptr, "_totalSeconds", 996888727UL); -} - -static PHP_METHOD(Phalcon_Db_Profiler, getProfiles){ - - - RETURN_MEMBER_QUICK(this_ptr, "_allProfiles", 1465095617UL); + PHALCON_OBS_VAR(annotations); + phalcon_read_property_this_quick(&annotations, this_ptr, SL("_methodAnnotations"), 4229536243UL, PH_NOISY_CC); + if (Z_TYPE_P(annotations) != IS_OBJECT) { + + PHALCON_OBS_VAR(reflection_data); + phalcon_read_property_this_quick(&reflection_data, this_ptr, SL("_reflectionData"), 3848141129UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(reflection_data, SS("methods"), 2292439449UL)) { + + PHALCON_OBS_VAR(reflection_methods); + phalcon_array_fetch_quick_string(&reflection_methods, reflection_data, SS("methods"), 2292439449UL, PH_NOISY); + if (phalcon_fast_count_ev(reflection_methods TSRMLS_CC)) { + + PHALCON_INIT_VAR(collections); + array_init(collections); + + phalcon_is_iterable(reflection_methods, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(method_name, ah0, hp0); + PHALCON_GET_HVALUE(reflection_method); + + PHALCON_INIT_NVAR(collection); + object_init_ex(collection, phalcon_annotations_collection_ce); + phalcon_call_method_p1_key(NULL, collection, "__construct", reflection_method, 1107214344UL); + + phalcon_array_update_zval(&collections, method_name, &collection, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_update_property_this_quick(this_ptr, SL("_methodAnnotations"), collections, 4229536243UL TSRMLS_CC); + + RETURN_CTOR(collections); + } + } + + phalcon_update_property_bool(this_ptr, SL("_methodAnnotations"), 0 TSRMLS_CC); + RETURN_MM_FALSE; + } + + RETURN_CCTOR(annotations); } -static PHP_METHOD(Phalcon_Db_Profiler, reset){ +static PHP_METHOD(Phalcon_Annotations_Reflection, getPropertiesAnnotations){ - zval *empty_arr; + zval *annotations, *reflection_data, *reflection_properties; + zval *collections, *reflection_property = NULL, *property = NULL; + zval *collection = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(empty_arr); - array_init(empty_arr); - phalcon_update_property_this_quick(this_ptr, SL("_allProfiles"), empty_arr, 1465095617UL TSRMLS_CC); - RETURN_THIS(); + PHALCON_OBS_VAR(annotations); + phalcon_read_property_this_quick(&annotations, this_ptr, SL("_propertyAnnotations"), 762458551UL, PH_NOISY_CC); + if (Z_TYPE_P(annotations) != IS_OBJECT) { + + PHALCON_OBS_VAR(reflection_data); + phalcon_read_property_this_quick(&reflection_data, this_ptr, SL("_reflectionData"), 3848141129UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(reflection_data, SS("properties"), 1619284338UL)) { + + PHALCON_OBS_VAR(reflection_properties); + phalcon_array_fetch_quick_string(&reflection_properties, reflection_data, SS("properties"), 1619284338UL, PH_NOISY); + if (phalcon_fast_count_ev(reflection_properties TSRMLS_CC)) { + + PHALCON_INIT_VAR(collections); + array_init(collections); + + phalcon_is_iterable(reflection_properties, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(property, ah0, hp0); + PHALCON_GET_HVALUE(reflection_property); + + PHALCON_INIT_NVAR(collection); + object_init_ex(collection, phalcon_annotations_collection_ce); + phalcon_call_method_p1_key(NULL, collection, "__construct", reflection_property, 1107214344UL); + + phalcon_array_update_zval(&collections, property, &collection, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_update_property_this_quick(this_ptr, SL("_propertyAnnotations"), collections, 762458551UL TSRMLS_CC); + + RETURN_CTOR(collections); + } + } + + phalcon_update_property_bool(this_ptr, SL("_propertyAnnotations"), 0 TSRMLS_CC); + RETURN_MM_FALSE; + } + + RETURN_CCTOR(annotations); } -static PHP_METHOD(Phalcon_Db_Profiler, getLastProfile){ +static PHP_METHOD(Phalcon_Annotations_Reflection, getReflectionData){ - RETURN_MEMBER_QUICK(this_ptr, "_activeProfile", 794883025UL); + RETURN_MEMBER_QUICK(this_ptr, "_reflectionData", 3848141129UL); } +static PHP_METHOD(Phalcon_Annotations_Reflection, __set_state){ + zval *data, *reflection_data; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_RawValue){ - - PHALCON_REGISTER_CLASS(Phalcon\\Db, RawValue, db_rawvalue, phalcon_db_rawvalue_method_entry, 0); - - zend_declare_property_null(phalcon_db_rawvalue_ce, SL("_value"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Db_RawValue, __construct){ - - zval *value; - - phalcon_fetch_params(0, 1, 0, &value); + phalcon_fetch_params(1, 1, 0, &data); - phalcon_update_property_this_quick(this_ptr, SL("_value"), value, 2935317441UL TSRMLS_CC); + if (Z_TYPE_P(data) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(data, SS("_reflectionData"), 3848141129UL)) { + PHALCON_OBS_VAR(reflection_data); + phalcon_array_fetch_quick_string(&reflection_data, data, SS("_reflectionData"), 3848141129UL, PH_NOISY); + object_init_ex(return_value, phalcon_annotations_reflection_ce); + phalcon_call_method_p1_key(NULL, return_value, "__construct", reflection_data, 1107214344UL); + + RETURN_MM(); + } + } + object_init_ex(return_value, phalcon_annotations_reflection_ce); + phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL); + + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_RawValue, getValue){ - RETURN_MEMBER_QUICK(this_ptr, "_value", 2935317441UL); -} +/* Generated by re2c 0.13.5 on Fri Jun 28 19:00:52 2013 */ +// 1 "scanner.re" -static PHP_METHOD(Phalcon_Db_RawValue, __toString){ +#ifdef HAVE_CONFIG_H +#endif - RETURN_MEMBER_QUICK(this_ptr, "_value", 2935317441UL); -} +#define JJCTYPE unsigned char +#define JJCURSOR (s->start) +#define JJLIMIT (s->end) +#define JJMARKER q +static int phannot_get_token(phannot_scanner_state *s, phannot_scanner_token *token) { + char next, *q = JJCURSOR, *start = JJCURSOR; + int status = PHANNOT_SCANNER_RETCODE_IMPOSSIBLE; -#ifdef HAVE_CONFIG_H -#endif + while (PHANNOT_SCANNER_RETCODE_IMPOSSIBLE == status) { + if (s->mode == PHANNOT_MODE_RAW) { + if (*JJCURSOR == '\n') { + s->active_line++; + } + next = *(JJCURSOR+1); + if (*JJCURSOR == '\0' || *JJCURSOR == '@') { + if ((next >= 'A' && next <= 'Z') || (next >= 'a' && next <= 'z')) { + s->mode = PHANNOT_MODE_ANNOTATION; + continue; + } + } + ++JJCURSOR; + token->opcode = PHANNOT_T_IGNORE; + return 0; + } else { -PHALCON_INIT_CLASS(Phalcon_Db_Profiler_Item){ - - PHALCON_REGISTER_CLASS(Phalcon\\Db\\Profiler, Item, db_profiler_item, phalcon_db_profiler_item_method_entry, 0); - - zend_declare_property_null(phalcon_db_profiler_item_ce, SL("_sqlStatement"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_profiler_item_ce, SL("_initialTime"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_profiler_item_ce, SL("_finalTime"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Db_Profiler_Item, setSQLStatement){ - - zval *sql_statement; - - phalcon_fetch_params(0, 1, 0, &sql_statement); - - phalcon_update_property_this_quick(this_ptr, SL("_sqlStatement"), sql_statement, 18972457UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Db_Profiler_Item, getSQLStatement){ - - - RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); -} - -static PHP_METHOD(Phalcon_Db_Profiler_Item, setInitialTime){ - - zval *initial_time; - - phalcon_fetch_params(0, 1, 0, &initial_time); - - phalcon_update_property_this_quick(this_ptr, SL("_initialTime"), initial_time, 3347691997UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Db_Profiler_Item, setFinalTime){ - - zval *final_time; - - phalcon_fetch_params(0, 1, 0, &final_time); - - phalcon_update_property_this_quick(this_ptr, SL("_finalTime"), final_time, 2101629981UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Db_Profiler_Item, getInitialTime){ - - - RETURN_MEMBER_QUICK(this_ptr, "_initialTime", 3347691997UL); -} - -static PHP_METHOD(Phalcon_Db_Profiler_Item, getFinalTime){ - - - RETURN_MEMBER_QUICK(this_ptr, "_finalTime", 2101629981UL); -} - -static PHP_METHOD(Phalcon_Db_Profiler_Item, getTotalElapsedSeconds){ - - zval *final_time, *initial_time; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(final_time); - phalcon_read_property_this_quick(&final_time, this_ptr, SL("_finalTime"), 2101629981UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(initial_time); - phalcon_read_property_this_quick(&initial_time, this_ptr, SL("_initialTime"), 3347691997UL, PH_NOISY_CC); - sub_function(return_value, final_time, initial_time TSRMLS_CC); - RETURN_MM(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Reference){ - - PHALCON_REGISTER_CLASS(Phalcon\\Db, Reference, db_reference, phalcon_db_reference_method_entry, 0); - - zend_declare_property_null(phalcon_db_reference_ce, SL("_schemaName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_reference_ce, SL("_referencedSchema"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_reference_ce, SL("_referenceName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_reference_ce, SL("_referencedTable"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_reference_ce, SL("_columns"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_reference_ce, SL("_referencedColumns"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_db_reference_ce TSRMLS_CC, 1, phalcon_db_referenceinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Db_Reference, __construct){ - - zval *reference_name, *definition, *referenced_table; - zval *columns, *referenced_columns, *schema; - zval *referenced_schema, *number_columns; - zval *number_referenced_columns; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &reference_name, &definition); - - phalcon_update_property_this_quick(this_ptr, SL("_referenceName"), reference_name, 4269393812UL TSRMLS_CC); - if (phalcon_array_isset_quick_string(definition, SS("referencedTable"), 3390337856UL)) { - PHALCON_OBS_VAR(referenced_table); - phalcon_array_fetch_quick_string(&referenced_table, definition, SS("referencedTable"), 3390337856UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_referencedTable"), referenced_table, 39793215UL TSRMLS_CC); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Referenced table is required"); - return; - } - - if (phalcon_array_isset_quick_string(definition, SS("columns"), 1041822630UL)) { - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_columns"), columns, 4004520869UL TSRMLS_CC); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Foreign key columns are required"); - return; - } - - if (phalcon_array_isset_quick_string(definition, SS("referencedColumns"), 1045113721UL)) { - PHALCON_OBS_VAR(referenced_columns); - phalcon_array_fetch_quick_string(&referenced_columns, definition, SS("referencedColumns"), 1045113721UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_referencedColumns"), referenced_columns, 3024201272UL TSRMLS_CC); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Referenced columns of the foreign key are required"); - return; - } - - if (phalcon_array_isset_quick_string(definition, SS("schema"), 2259341622UL)) { - PHALCON_OBS_VAR(schema); - phalcon_array_fetch_quick_string(&schema, definition, SS("schema"), 2259341622UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_schemaName"), schema, 851420310UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(definition, SS("referencedSchema"), 3300645545UL)) { - PHALCON_OBS_VAR(referenced_schema); - phalcon_array_fetch_quick_string(&referenced_schema, definition, SS("referencedSchema"), 3300645545UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_referencedSchema"), referenced_schema, 106854792UL TSRMLS_CC); - } - - PHALCON_INIT_VAR(number_columns); - phalcon_fast_count(number_columns, columns TSRMLS_CC); - - PHALCON_INIT_VAR(number_referenced_columns); - phalcon_fast_count(number_referenced_columns, referenced_columns TSRMLS_CC); - if (!PHALCON_IS_EQUAL(number_columns, number_referenced_columns)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Number of columns is not equals than the number of columns referenced"); - return; - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Db_Reference, getName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_referenceName", 4269393812UL); -} - -static PHP_METHOD(Phalcon_Db_Reference, getSchemaName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_schemaName", 851420310UL); -} - -static PHP_METHOD(Phalcon_Db_Reference, getReferencedSchema){ - - - RETURN_MEMBER_QUICK(this_ptr, "_referencedSchema", 106854792UL); -} - -static PHP_METHOD(Phalcon_Db_Reference, getColumns){ - - - RETURN_MEMBER_QUICK(this_ptr, "_columns", 4004520869UL); -} - -static PHP_METHOD(Phalcon_Db_Reference, getReferencedTable){ - - - RETURN_MEMBER_QUICK(this_ptr, "_referencedTable", 39793215UL); -} - -static PHP_METHOD(Phalcon_Db_Reference, getReferencedColumns){ - - - RETURN_MEMBER_QUICK(this_ptr, "_referencedColumns", 3024201272UL); -} - -static PHP_METHOD(Phalcon_Db_Reference, __set_state){ - - zval *data, *constraint_name, *referenced_schema = NULL; - zval *referenced_table = NULL, *columns = NULL, *referenced_columns = NULL; - zval *definition; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &data); - - if (!phalcon_array_isset_quick_string(data, SS("_referenceName"), 4269393812UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "_referenceName parameter is required"); - return; - } else { - PHALCON_OBS_VAR(constraint_name); - phalcon_array_fetch_quick_string(&constraint_name, data, SS("_referenceName"), 4269393812UL, PH_NOISY); - } - if (phalcon_array_isset_quick_string(data, SS("_referencedSchema"), 106854792UL)) { - PHALCON_OBS_VAR(referenced_schema); - phalcon_array_fetch_quick_string(&referenced_schema, data, SS("_referencedSchema"), 106854792UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(referenced_schema); - } - - if (phalcon_array_isset_quick_string(data, SS("_referencedTable"), 39793215UL)) { - PHALCON_OBS_VAR(referenced_table); - phalcon_array_fetch_quick_string(&referenced_table, data, SS("_referencedTable"), 39793215UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(referenced_table); - } - - if (phalcon_array_isset_quick_string(data, SS("_columns"), 4004520869UL)) { - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, data, SS("_columns"), 4004520869UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(columns); - } - - if (phalcon_array_isset_quick_string(data, SS("_referencedColumns"), 3024201272UL)) { - PHALCON_OBS_VAR(referenced_columns); - phalcon_array_fetch_quick_string(&referenced_columns, data, SS("_referencedColumns"), 3024201272UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(referenced_columns); - } - - PHALCON_INIT_VAR(definition); - array_init_size(definition, 4); - phalcon_array_update_quick_string(&definition, SS("referencedSchema"), 3300645545UL, &referenced_schema, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("referencedTable"), 3390337856UL, &referenced_table, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("columns"), 1041822630UL, &columns, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("referencedColumns"), 1045113721UL, &referenced_columns, PH_COPY | PH_SEPARATE); - object_init_ex(return_value, phalcon_db_reference_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", constraint_name, definition, 1107214344UL); - - RETURN_MM(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Db_AdapterInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, AdapterInterface, db_adapterinterface, phalcon_db_adapterinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Dialect){ - - PHALCON_REGISTER_CLASS(Phalcon\\Db, Dialect, db_dialect, phalcon_db_dialect_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - zend_declare_property_null(phalcon_db_dialect_ce, SL("_escapeChar"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Db_Dialect, limit){ - - zval *sql_query, *number, *limit; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &sql_query, &number); - - if (phalcon_is_numeric(number)) { - PHALCON_INIT_VAR(limit); - ZVAL_LONG(limit, phalcon_get_intval(number)); - PHALCON_CONCAT_VSV(return_value, sql_query, " LIMIT ", limit); - RETURN_MM(); - } - - RETURN_CCTOR(sql_query); -} - -static PHP_METHOD(Phalcon_Db_Dialect, forUpdate){ - - zval *sql_query; - - phalcon_fetch_params(0, 1, 0, &sql_query); - - PHALCON_CONCAT_VS(return_value, sql_query, " FOR UPDATE"); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect, sharedLock){ - - zval *sql_query; - - phalcon_fetch_params(0, 1, 0, &sql_query); - - PHALCON_CONCAT_VS(return_value, sql_query, " LOCK IN SHARE MODE"); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect, getColumnList){ - - zval *column_list, *str_list, *escape_char, *column = NULL; - zval *column_quoted = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &column_list); - - PHALCON_INIT_VAR(str_list); - array_init(str_list); - - PHALCON_OBS_VAR(escape_char); - phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); - - phalcon_is_iterable(column_list, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(column); - - PHALCON_INIT_NVAR(column_quoted); - PHALCON_CONCAT_VVV(column_quoted, escape_char, column, escape_char); - phalcon_array_append(&str_list, column_quoted, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - phalcon_fast_join_str(return_value, SL(", "), str_list TSRMLS_CC); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Dialect, getSqlExpression){ - - zval *expression, *escape_char = NULL, *type, *name = NULL, *escaped_name = NULL; - zval *domain, *escaped_domain = NULL, *value = NULL, *operator = NULL; - zval *left = NULL, *expression_left = NULL, *right = NULL, *expression_right = NULL; - zval *expression_group, *sql_arguments, *arguments; - zval *argument = NULL, *argument_expression = NULL, *arguments_joined; - zval *sql_items, *items, *item = NULL, *item_expression = NULL; - zval *list_expression, *exception_message; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; - - PHALCON_MM_GROW(); + +// 66 "scanner.c" + { + JJCTYPE jjch; + unsigned int jjaccept = 0; - phalcon_fetch_params(1, 1, 1, &expression, &escape_char); - - if (!escape_char) { - PHALCON_INIT_VAR(escape_char); - } else { - PHALCON_SEPARATE_PARAM(escape_char); - } - - if (PHALCON_GLOBAL(db).escape_identifiers) { - if (Z_TYPE_P(escape_char) == IS_NULL) { - PHALCON_OBS_NVAR(escape_char); - phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); - } - } - if (Z_TYPE_P(expression) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid SQL expression"); - return; - } - - if (!phalcon_array_isset_quick_string(expression, SS("type"), 276192743UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid SQL expression"); - return; - } - - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, expression, SS("type"), 276192743UL, PH_NOISY); - - if (PHALCON_IS_STRING(type, "qualified")) { - - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, expression, SS("name"), 268211462UL, PH_NOISY); - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(escaped_name); - PHALCON_CONCAT_VVV(escaped_name, escape_char, name, escape_char); - } else { - PHALCON_CPY_WRT(escaped_name, name); - } - - if (phalcon_array_isset_quick_string(expression, SS("domain"), 542597917UL)) { - - PHALCON_OBS_VAR(domain); - phalcon_array_fetch_quick_string(&domain, expression, SS("domain"), 542597917UL, PH_NOISY); - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(escaped_domain); - PHALCON_CONCAT_VVVSV(escaped_domain, escape_char, domain, escape_char, ".", escaped_name); - } else { - PHALCON_INIT_NVAR(escaped_domain); - PHALCON_CONCAT_VSV(escaped_domain, domain, ".", escaped_name); - } - - RETURN_CTOR(escaped_domain); - } - - RETURN_CCTOR(escaped_name); - } - - if (PHALCON_IS_STRING(type, "literal")) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch_quick_string(&value, expression, SS("value"), 574111618UL, PH_NOISY); - RETURN_CCTOR(value); - } - - if (PHALCON_IS_STRING(type, "binary-op")) { - PHALCON_OBS_VAR(operator); - phalcon_array_fetch_quick_string(&operator, expression, SS("op"), 193501572UL, PH_NOISY); - - PHALCON_OBS_VAR(left); - phalcon_array_fetch_quick_string(&left, expression, SS("left"), 265976240UL, PH_NOISY); - - PHALCON_INIT_VAR(expression_left); - phalcon_call_method_p2_key(expression_left, this_ptr, "getsqlexpression", left, escape_char, 3377787077UL); - - PHALCON_OBS_VAR(right); - phalcon_array_fetch_quick_string(&right, expression, SS("right"), 426864067UL, PH_NOISY); - - PHALCON_INIT_VAR(expression_right); - phalcon_call_method_p2_key(expression_right, this_ptr, "getsqlexpression", right, escape_char, 3377787077UL); - PHALCON_CONCAT_VSVSV(return_value, expression_left, " ", operator, " ", expression_right); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(type, "unary-op")) { - - PHALCON_OBS_NVAR(operator); - phalcon_array_fetch_quick_string(&operator, expression, SS("op"), 193501572UL, PH_NOISY); - - if (phalcon_array_isset_quick_string(expression, SS("left"), 265976240UL)) { - PHALCON_OBS_NVAR(left); - phalcon_array_fetch_quick_string(&left, expression, SS("left"), 265976240UL, PH_NOISY); - - PHALCON_INIT_NVAR(expression_left); - phalcon_call_method_p2_key(expression_left, this_ptr, "getsqlexpression", left, escape_char, 3377787077UL); - PHALCON_CONCAT_VV(return_value, expression_left, operator); - RETURN_MM(); + jjch = *JJCURSOR; + switch (jjch) { + case 0x00: goto jj38; + case '\t': + case '\r': + case ' ': goto jj34; + case '\n': goto jj36; + case '"': goto jj10; + case '\'': goto jj11; + case '(': goto jj14; + case ')': goto jj16; + case ',': goto jj32; + case '-': goto jj2; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto jj4; + case ':': goto jj30; + case '=': goto jj28; + case '@': goto jj26; + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto jj13; + case 'F': + case 'f': goto jj8; + case 'N': + case 'n': goto jj6; + case 'T': + case 't': goto jj9; + case '[': goto jj22; + case '\\': goto jj12; + case ']': goto jj24; + case '{': goto jj18; + case '}': goto jj20; + default: goto jj40; + } +jj2: + ++JJCURSOR; + switch ((jjch = *JJCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto jj68; + default: goto jj3; + } +jj3: +// 183 "scanner.re" + { + status = PHANNOT_SCANNER_RETCODE_ERR; + break; } - - if (phalcon_array_isset_quick_string(expression, SS("right"), 426864067UL)) { - PHALCON_OBS_NVAR(right); - phalcon_array_fetch_quick_string(&right, expression, SS("right"), 426864067UL, PH_NOISY); - - PHALCON_INIT_NVAR(expression_right); - phalcon_call_method_p2_key(expression_right, this_ptr, "getsqlexpression", right, escape_char, 3377787077UL); - PHALCON_CONCAT_VV(return_value, operator, expression_right); - RETURN_MM(); +// 178 "scanner.c" +jj4: + jjaccept = 0; + jjch = *(JJMARKER = ++JJCURSOR); + goto jj69; +jj5: +// 67 "scanner.re" + { + token->opcode = PHANNOT_T_INTEGER; + token->value = estrndup(start, JJCURSOR - start); + token->len = JJCURSOR - start; + q = JJCURSOR; + return 0; } - } - - if (PHALCON_IS_STRING(type, "placeholder")) { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expression, SS("value"), 574111618UL, PH_NOISY); - RETURN_CCTOR(value); - } - - if (PHALCON_IS_STRING(type, "parentheses")) { - PHALCON_OBS_NVAR(left); - phalcon_array_fetch_quick_string(&left, expression, SS("left"), 265976240UL, PH_NOISY); - - PHALCON_INIT_NVAR(expression_left); - phalcon_call_method_p2_key(expression_left, this_ptr, "getsqlexpression", left, escape_char, 3377787077UL); - - PHALCON_INIT_VAR(expression_group); - PHALCON_CONCAT_SVS(expression_group, "(", expression_left, ")"); - RETURN_CTOR(expression_group); - } - - if (PHALCON_IS_STRING(type, "functionCall")) { - - PHALCON_OBS_NVAR(name); - phalcon_array_fetch_quick_string(&name, expression, SS("name"), 268211462UL, PH_NOISY); - - PHALCON_INIT_VAR(sql_arguments); - array_init(sql_arguments); - if (phalcon_array_isset_quick_string(expression, SS("arguments"), 3751272283UL)) { - - PHALCON_OBS_VAR(arguments); - phalcon_array_fetch_quick_string(&arguments, expression, SS("arguments"), 3751272283UL, PH_NOISY); - - phalcon_is_iterable(arguments, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(argument); - - PHALCON_INIT_NVAR(argument_expression); - phalcon_call_method_p2_key(argument_expression, this_ptr, "getsqlexpression", argument, escape_char, 3377787077UL); - phalcon_array_append(&sql_arguments, argument_expression, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); +// 192 "scanner.c" +jj6: + ++JJCURSOR; + switch ((jjch = *JJCURSOR)) { + case 'U': + case 'u': goto jj63; + default: goto jj44; } - - PHALCON_INIT_VAR(arguments_joined); - phalcon_fast_join_str(arguments_joined, SL(", "), sql_arguments TSRMLS_CC); - PHALCON_CONCAT_VSVS(return_value, name, "(", arguments_joined, ")"); - - RETURN_MM(); - } else { - PHALCON_CONCAT_VS(return_value, name, "()"); - RETURN_MM(); +jj7: +// 109 "scanner.re" + { + token->opcode = PHANNOT_T_IDENTIFIER; + token->value = estrndup(start, JJCURSOR - start); + token->len = JJCURSOR - start; + q = JJCURSOR; + return 0; } - } - - if (PHALCON_IS_STRING(type, "list")) { - - PHALCON_INIT_VAR(sql_items); - array_init(sql_items); - - PHALCON_OBS_VAR(items); - phalcon_array_fetch_long(&items, expression, 0, PH_NOISY); - - phalcon_is_iterable(items, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(item); - - PHALCON_INIT_NVAR(item_expression); - phalcon_call_method_p2_key(item_expression, this_ptr, "getsqlexpression", item, escape_char, 3377787077UL); - phalcon_array_append(&sql_items, item_expression, PH_SEPARATE); - - zend_hash_move_forward_ex(ah1, &hp1); +// 209 "scanner.c" +jj8: + jjch = *++JJCURSOR; + switch (jjch) { + case 'A': + case 'a': goto jj58; + default: goto jj44; + } +jj9: + jjch = *++JJCURSOR; + switch (jjch) { + case 'R': + case 'r': goto jj54; + default: goto jj44; + } +jj10: + jjaccept = 1; + jjch = *(JJMARKER = ++JJCURSOR); + if (jjch <= 0x00) goto jj3; + goto jj52; +jj11: + jjaccept = 1; + jjch = *(JJMARKER = ++JJCURSOR); + if (jjch <= 0x00) goto jj3; + goto jj46; +jj12: + jjch = *++JJCURSOR; + goto jj44; +jj13: + jjch = *++JJCURSOR; + goto jj44; +jj14: + ++JJCURSOR; +// 117 "scanner.re" + { + token->opcode = PHANNOT_T_PARENTHESES_OPEN; + return 0; } - - PHALCON_INIT_VAR(list_expression); - phalcon_fast_join_str(list_expression, SL(", "), sql_items TSRMLS_CC); - PHALCON_CONCAT_SVS(return_value, "(", list_expression, ")"); - - RETURN_MM(); - } - - if (PHALCON_IS_STRING(type, "all")) { - RETURN_MM_STRING("*", 1); - } - - if (PHALCON_IS_STRING(type, "cast")) { - PHALCON_OBS_NVAR(left); - phalcon_array_fetch_quick_string(&left, expression, SS("left"), 265976240UL, PH_NOISY); - - PHALCON_INIT_NVAR(expression_left); - phalcon_call_method_p2_key(expression_left, this_ptr, "getsqlexpression", left, escape_char, 3377787077UL); - - PHALCON_OBS_NVAR(right); - phalcon_array_fetch_quick_string(&right, expression, SS("right"), 426864067UL, PH_NOISY); - - PHALCON_INIT_NVAR(expression_right); - phalcon_call_method_p2_key(expression_right, this_ptr, "getsqlexpression", right, escape_char, 3377787077UL); - PHALCON_CONCAT_SVSVS(return_value, "CAST(", expression_left, " AS ", expression_right, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(type, "convert")) { - PHALCON_OBS_NVAR(left); - phalcon_array_fetch_quick_string(&left, expression, SS("left"), 265976240UL, PH_NOISY); - - PHALCON_INIT_NVAR(expression_left); - phalcon_call_method_p2_key(expression_left, this_ptr, "getsqlexpression", left, escape_char, 3377787077UL); - - PHALCON_OBS_NVAR(right); - phalcon_array_fetch_quick_string(&right, expression, SS("right"), 426864067UL, PH_NOISY); - - PHALCON_INIT_NVAR(expression_right); - phalcon_call_method_p2_key(expression_right, this_ptr, "getsqlexpression", right, escape_char, 3377787077UL); - PHALCON_CONCAT_SVSVS(return_value, "CONVERT(", expression_left, " USING ", expression_right, ")"); - RETURN_MM(); - } - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Invalid SQL expression type '", type, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_db_exception_ce, exception_message); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect, getSqlTable){ - - zval *table, *escape_char = NULL, *table_name, *sql_table = NULL; - zval *schema_name, *sql_schema = NULL, *alias_name; - zval *sql_table_alias = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &escape_char); - - if (!escape_char) { - PHALCON_INIT_VAR(escape_char); - } else { - PHALCON_SEPARATE_PARAM(escape_char); - } - - if (Z_TYPE_P(escape_char) == IS_NULL) { - PHALCON_OBS_NVAR(escape_char); - phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); - } - if (Z_TYPE_P(table) == IS_ARRAY) { - - PHALCON_OBS_VAR(table_name); - phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY); - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(sql_table); - PHALCON_CONCAT_VVV(sql_table, escape_char, table_name, escape_char); - } else { - PHALCON_CPY_WRT(sql_table, table_name); +// 247 "scanner.c" +jj16: + ++JJCURSOR; +// 122 "scanner.re" + { + token->opcode = PHANNOT_T_PARENTHESES_CLOSE; + return 0; } - - PHALCON_OBS_VAR(schema_name); - phalcon_array_fetch_long(&schema_name, table, 1, PH_NOISY); - if (Z_TYPE_P(schema_name) != IS_NULL) { - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(sql_schema); - PHALCON_CONCAT_VVVSV(sql_schema, escape_char, schema_name, escape_char, ".", sql_table); - } else { - PHALCON_INIT_NVAR(sql_schema); - PHALCON_CONCAT_VSV(sql_schema, schema_name, ".", sql_table); - } - } else { - PHALCON_CPY_WRT(sql_schema, sql_table); +// 255 "scanner.c" +jj18: + ++JJCURSOR; +// 127 "scanner.re" + { + token->opcode = PHANNOT_T_BRACKET_OPEN; + return 0; } - - if (phalcon_array_isset_long(table, 2)) { - - PHALCON_OBS_VAR(alias_name); - phalcon_array_fetch_long(&alias_name, table, 2, PH_NOISY); - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(sql_table_alias); - PHALCON_CONCAT_VSVVV(sql_table_alias, sql_schema, " AS ", escape_char, alias_name, escape_char); - } else { - PHALCON_INIT_NVAR(sql_table_alias); - PHALCON_CONCAT_VSV(sql_table_alias, sql_schema, " AS ", alias_name); - } - } else { - PHALCON_CPY_WRT(sql_table_alias, sql_schema); +// 263 "scanner.c" +jj20: + ++JJCURSOR; +// 132 "scanner.re" + { + token->opcode = PHANNOT_T_BRACKET_CLOSE; + return 0; } - - RETURN_CCTOR(sql_table_alias); - } - - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_CONCAT_VVV(return_value, escape_char, table, escape_char); - RETURN_MM(); - } - - RETURN_CCTOR(table); -} - -static PHP_METHOD(Phalcon_Db_Dialect, select){ - - zval *definition, *escape_char = NULL, *columns, *selected_columns; - zval *column = NULL, *column_item = NULL, *column_sql = NULL, *column_domain = NULL; - zval *column_domain_sql = NULL, *column_alias = NULL, *column_alias_sql = NULL; - zval *columns_sql = NULL, *tables, *selected_tables; - zval *table = NULL, *sql_table = NULL, *tables_sql = NULL, *sql, *joins; - zval *join = NULL, *type = NULL, *sql_join = NULL, *join_conditions_array = NULL; - zval *join_expressions = NULL, *join_condition = NULL, *join_expression = NULL; - zval *join_conditions = NULL, *where_conditions; - zval *where_expression, *group_items, *group_fields; - zval *group_field = NULL, *group_expression = NULL, *group_sql; - zval *group_clause, *having_conditions, *having_expression; - zval *order_fields, *order_items, *order_item = NULL; - zval *order_expression = NULL, *order_sql_item = NULL, *sql_order_type = NULL; - zval *order_sql_item_type = NULL, *order_sql, *limit_value; - zval *number, *offset; - HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5; - HashPosition hp0, hp1, hp2, hp3, hp4, hp5; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &definition); - - if (Z_TYPE_P(definition) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid SELECT definition"); - return; - } - if (!phalcon_array_isset_quick_string(definition, SS("tables"), 3465666720UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'tables' is required in the definition array"); - return; - } - - if (!phalcon_array_isset_quick_string(definition, SS("columns"), 1041822630UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'columns' is required in the definition array"); - return; - } - - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_OBS_VAR(escape_char); - phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); - } else { - PHALCON_INIT_NVAR(escape_char); - } - - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); - if (Z_TYPE_P(columns) == IS_ARRAY) { - - PHALCON_INIT_VAR(selected_columns); - array_init(selected_columns); - - phalcon_is_iterable(columns, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(column); - - PHALCON_OBS_NVAR(column_item); - phalcon_array_fetch_long(&column_item, column, 0, PH_NOISY); - if (Z_TYPE_P(column_item) == IS_ARRAY) { - PHALCON_INIT_NVAR(column_sql); - phalcon_call_method_p2_key(column_sql, this_ptr, "getsqlexpression", column_item, escape_char, 3377787077UL); - } else { - if (PHALCON_IS_STRING(column_item, "*")) { - PHALCON_CPY_WRT(column_sql, column_item); - } else { - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_VVV(column_sql, escape_char, column_item, escape_char); - } else { - PHALCON_CPY_WRT(column_sql, column_item); - } - } - } - - if (phalcon_array_isset_long(column, 1)) { - - PHALCON_OBS_NVAR(column_domain); - phalcon_array_fetch_long(&column_domain, column, 1, PH_NOISY); - if (zend_is_true(column_domain)) { - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_NVAR(column_domain_sql); - PHALCON_CONCAT_VVVSV(column_domain_sql, escape_char, column_domain, escape_char, ".", column_sql); - } else { - PHALCON_INIT_NVAR(column_domain_sql); - PHALCON_CONCAT_VSV(column_domain_sql, column_domain, ".", column_sql); - } - } else { - PHALCON_CPY_WRT(column_domain_sql, column_sql); - } - } else { - PHALCON_CPY_WRT(column_domain_sql, column_sql); - } - - if (phalcon_array_isset_long(column, 2)) { - - PHALCON_OBS_NVAR(column_alias); - phalcon_array_fetch_long(&column_alias, column, 2, PH_NOISY); - if (zend_is_true(column_alias)) { - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_NVAR(column_alias_sql); - PHALCON_CONCAT_VSVVV(column_alias_sql, column_domain_sql, " AS ", escape_char, column_alias, escape_char); - } else { - PHALCON_INIT_NVAR(column_alias_sql); - PHALCON_CONCAT_VSV(column_alias_sql, column_domain_sql, " AS ", column_alias); - } - } else { - PHALCON_CPY_WRT(column_alias_sql, column_domain_sql); - } - } else { - PHALCON_CPY_WRT(column_alias_sql, column_domain_sql); - } - - phalcon_array_append(&selected_columns, column_alias_sql, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(columns_sql); - phalcon_fast_join_str(columns_sql, SL(", "), selected_columns TSRMLS_CC); - } else { - PHALCON_CPY_WRT(columns_sql, columns); - } - - PHALCON_OBS_VAR(tables); - phalcon_array_fetch_quick_string(&tables, definition, SS("tables"), 3465666720UL, PH_NOISY); - if (Z_TYPE_P(tables) == IS_ARRAY) { - - PHALCON_INIT_VAR(selected_tables); - array_init(selected_tables); - - phalcon_is_iterable(tables, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(table); - - PHALCON_INIT_NVAR(sql_table); - phalcon_call_method_p2_key(sql_table, this_ptr, "getsqltable", table, escape_char, 2837135293UL); - phalcon_array_append(&selected_tables, sql_table, PH_SEPARATE); - - zend_hash_move_forward_ex(ah1, &hp1); +// 271 "scanner.c" +jj22: + ++JJCURSOR; +// 137 "scanner.re" + { + token->opcode = PHANNOT_T_SBRACKET_OPEN; + return 0; } - - PHALCON_INIT_VAR(tables_sql); - phalcon_fast_join_str(tables_sql, SL(", "), selected_tables TSRMLS_CC); - } else { - PHALCON_CPY_WRT(tables_sql, tables); - } - - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "SELECT ", columns_sql, " FROM ", tables_sql); - - if (phalcon_array_isset_quick_string(definition, SS("joins"), 120974824UL)) { - - PHALCON_OBS_VAR(joins); - phalcon_array_fetch_quick_string(&joins, definition, SS("joins"), 120974824UL, PH_NOISY); - - phalcon_is_iterable(joins, &ah2, &hp2, 0, 0); - - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - - PHALCON_GET_HVALUE(join); - - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, join, SS("type"), 276192743UL, PH_NOISY); - - PHALCON_OBS_NVAR(table); - phalcon_array_fetch_quick_string(&table, join, SS("source"), 2744839734UL, PH_NOISY); - - PHALCON_INIT_NVAR(sql_table); - phalcon_call_method_p2_key(sql_table, this_ptr, "getsqltable", table, escape_char, 2837135293UL); - phalcon_array_append(&selected_tables, sql_table, PH_SEPARATE); - - PHALCON_INIT_NVAR(sql_join); - PHALCON_CONCAT_SVSV(sql_join, " ", type, " JOIN ", sql_table); - - if (phalcon_array_isset_quick_string(join, SS("conditions"), 1055696255UL)) { - - PHALCON_OBS_NVAR(join_conditions_array); - phalcon_array_fetch_quick_string(&join_conditions_array, join, SS("conditions"), 1055696255UL, PH_NOISY); - if (phalcon_fast_count_ev(join_conditions_array TSRMLS_CC)) { - - PHALCON_INIT_NVAR(join_expressions); - array_init(join_expressions); - - phalcon_is_iterable(join_conditions_array, &ah3, &hp3, 0, 0); - - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - - PHALCON_GET_HVALUE(join_condition); - - PHALCON_INIT_NVAR(join_expression); - phalcon_call_method_p2_key(join_expression, this_ptr, "getsqlexpression", join_condition, escape_char, 3377787077UL); - phalcon_array_append(&join_expressions, join_expression, PH_SEPARATE); - - zend_hash_move_forward_ex(ah3, &hp3); - } - - PHALCON_INIT_NVAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), join_expressions TSRMLS_CC); - PHALCON_SCONCAT_SVS(sql_join, " ON ", join_conditions, " "); - } - } - - phalcon_concat_self(&sql, sql_join TSRMLS_CC); - - zend_hash_move_forward_ex(ah2, &hp2); +// 279 "scanner.c" +jj24: + ++JJCURSOR; +// 142 "scanner.re" + { + token->opcode = PHANNOT_T_SBRACKET_CLOSE; + return 0; } - - } - - if (phalcon_array_isset_quick_string(definition, SS("where"), 621293632UL)) { - - PHALCON_OBS_VAR(where_conditions); - phalcon_array_fetch_quick_string(&where_conditions, definition, SS("where"), 621293632UL, PH_NOISY); - if (Z_TYPE_P(where_conditions) == IS_ARRAY) { - PHALCON_INIT_VAR(where_expression); - phalcon_call_method_p2_key(where_expression, this_ptr, "getsqlexpression", where_conditions, escape_char, 3377787077UL); - PHALCON_SCONCAT_SV(sql, " WHERE ", where_expression); - } else { - PHALCON_SCONCAT_SV(sql, " WHERE ", where_conditions); +// 287 "scanner.c" +jj26: + ++JJCURSOR; +// 147 "scanner.re" + { + token->opcode = PHANNOT_T_AT; + return 0; } - } - - if (phalcon_array_isset_quick_string(definition, SS("group"), 7349554UL)) { - - PHALCON_INIT_VAR(group_items); - array_init(group_items); - - PHALCON_OBS_VAR(group_fields); - phalcon_array_fetch_quick_string(&group_fields, definition, SS("group"), 7349554UL, PH_NOISY); - - phalcon_is_iterable(group_fields, &ah4, &hp4, 0, 0); - - while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { - - PHALCON_GET_HVALUE(group_field); - - PHALCON_INIT_NVAR(group_expression); - phalcon_call_method_p2_key(group_expression, this_ptr, "getsqlexpression", group_field, escape_char, 3377787077UL); - phalcon_array_append(&group_items, group_expression, PH_SEPARATE); - - zend_hash_move_forward_ex(ah4, &hp4); +// 295 "scanner.c" +jj28: + ++JJCURSOR; +// 152 "scanner.re" + { + token->opcode = PHANNOT_T_EQUALS; + return 0; } - - PHALCON_INIT_VAR(group_sql); - phalcon_fast_join_str(group_sql, SL(", "), group_items TSRMLS_CC); - - PHALCON_INIT_VAR(group_clause); - PHALCON_CONCAT_SV(group_clause, " GROUP BY ", group_sql); - phalcon_concat_self(&sql, group_clause TSRMLS_CC); - - if (phalcon_array_isset_quick_string(definition, SS("having"), 876572994UL)) { - PHALCON_OBS_VAR(having_conditions); - phalcon_array_fetch_quick_string(&having_conditions, definition, SS("having"), 876572994UL, PH_NOISY); - - PHALCON_INIT_VAR(having_expression); - phalcon_call_method_p2_key(having_expression, this_ptr, "getsqlexpression", having_conditions, escape_char, 3377787077UL); - PHALCON_SCONCAT_SV(sql, " HAVING ", having_expression); +// 303 "scanner.c" +jj30: + ++JJCURSOR; +// 157 "scanner.re" + { + token->opcode = PHANNOT_T_COLON; + return 0; } - } - - if (phalcon_array_isset_quick_string(definition, SS("order"), 320020033UL)) { - - PHALCON_OBS_VAR(order_fields); - phalcon_array_fetch_quick_string(&order_fields, definition, SS("order"), 320020033UL, PH_NOISY); - - PHALCON_INIT_VAR(order_items); - array_init(order_items); - - phalcon_is_iterable(order_fields, &ah5, &hp5, 0, 0); - - while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { - - PHALCON_GET_HVALUE(order_item); - - PHALCON_OBS_NVAR(order_expression); - phalcon_array_fetch_long(&order_expression, order_item, 0, PH_NOISY); - - PHALCON_INIT_NVAR(order_sql_item); - phalcon_call_method_p2_key(order_sql_item, this_ptr, "getsqlexpression", order_expression, escape_char, 3377787077UL); - - if (phalcon_array_isset_long(order_item, 1)) { - PHALCON_OBS_NVAR(sql_order_type); - phalcon_array_fetch_long(&sql_order_type, order_item, 1, PH_NOISY); - - PHALCON_INIT_NVAR(order_sql_item_type); - PHALCON_CONCAT_VSV(order_sql_item_type, order_sql_item, " ", sql_order_type); - } else { - PHALCON_CPY_WRT(order_sql_item_type, order_sql_item); - } - - phalcon_array_append(&order_items, order_sql_item_type, PH_SEPARATE); - - zend_hash_move_forward_ex(ah5, &hp5); +// 311 "scanner.c" +jj32: + ++JJCURSOR; +// 162 "scanner.re" + { + token->opcode = PHANNOT_T_COMMA; + return 0; } - - PHALCON_INIT_VAR(order_sql); - phalcon_fast_join_str(order_sql, SL(", "), order_items TSRMLS_CC); - PHALCON_SCONCAT_SV(sql, " ORDER BY ", order_sql); - } - - if (phalcon_array_isset_quick_string(definition, SS("limit"), 192268420UL)) { - - PHALCON_OBS_VAR(limit_value); - phalcon_array_fetch_quick_string(&limit_value, definition, SS("limit"), 192268420UL, PH_NOISY); - if (Z_TYPE_P(limit_value) == IS_ARRAY) { - - PHALCON_OBS_VAR(number); - phalcon_array_fetch_quick_string(&number, limit_value, SS("number"), 807219790UL, PH_NOISY); - - if (phalcon_array_isset_quick_string(limit_value, SS("offset"), 1503966412UL)) { - PHALCON_OBS_VAR(offset); - phalcon_array_fetch_quick_string(&offset, limit_value, SS("offset"), 1503966412UL, PH_NOISY); - PHALCON_SCONCAT_SVSV(sql, " LIMIT ", number, " OFFSET ", offset); - } else { - PHALCON_SCONCAT_SV(sql, " LIMIT ", number); - } - } else { - PHALCON_SCONCAT_SV(sql, " LIMIT ", limit_value); +// 319 "scanner.c" +jj34: + ++JJCURSOR; + jjch = *JJCURSOR; + goto jj42; +jj35: +// 167 "scanner.re" + { + token->opcode = PHANNOT_T_IGNORE; + return 0; } - } - - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect, supportsSavepoints){ - - - RETURN_TRUE; -} - -static PHP_METHOD(Phalcon_Db_Dialect, supportsReleaseSavepoints){ - - - PHALCON_MM_GROW(); - - phalcon_call_method_key(return_value, this_ptr, "supportssavepoints", 1063347073UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Dialect, createSavepoint){ - - zval *name; - - phalcon_fetch_params(0, 1, 0, &name); - - PHALCON_CONCAT_SV(return_value, "SAVEPOINT ", name); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect, releaseSavepoint){ - - zval *name; - - phalcon_fetch_params(0, 1, 0, &name); - - PHALCON_CONCAT_SV(return_value, "RELEASE SAVEPOINT ", name); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect, rollbackSavepoint){ - - zval *name; - - phalcon_fetch_params(0, 1, 0, &name); - - PHALCON_CONCAT_SV(return_value, "ROLLBACK TO SAVEPOINT ", name); - return; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Db_ColumnInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ColumnInterface, db_columninterface, phalcon_db_columninterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Column){ - - PHALCON_REGISTER_CLASS(Phalcon\\Db, Column, db_column, phalcon_db_column_method_entry, 0); - - zend_declare_property_null(phalcon_db_column_ce, SL("_columnName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_column_ce, SL("_schemaName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_column_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_db_column_ce, SL("_isNumeric"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_db_column_ce, SL("_size"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_db_column_ce, SL("_scale"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_db_column_ce, SL("_unsigned"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_db_column_ce, SL("_notNull"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_db_column_ce, SL("_primary"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_db_column_ce, SL("_autoIncrement"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_db_column_ce, SL("_first"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_column_ce, SL("_after"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_db_column_ce, SL("_bindType"), 2, ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_INTEGER"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_DATE"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_VARCHAR"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_DECIMAL"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_DATETIME"), 4 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_CHAR"), 5 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_TEXT"), 6 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_FLOAT"), 7 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_BOOLEAN"), 8 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_PARAM_NULL"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_PARAM_INT"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_PARAM_STR"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_PARAM_BOOL"), 5 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_PARAM_DECIMAL"), 32 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_SKIP"), 1024 TSRMLS_CC); - - zend_class_implements(phalcon_db_column_ce TSRMLS_CC, 1, phalcon_db_columninterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Db_Column, __construct){ - - zval *column_name, *definition, *type, *not_null; - zval *primary, *size, *is_numeric = NULL, *scale, *dunsigned; - zval *auto_increment, *first, *after, *bind_type; - zval *t0 = NULL, *t1 = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &column_name, &definition); - - phalcon_update_property_this_quick(this_ptr, SL("_columnName"), column_name, 3251978323UL TSRMLS_CC); - - if (phalcon_array_isset_quick_string(definition, SS("type"), 276192743UL)) { - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, definition, SS("type"), 276192743UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column type is required"); - return; - } - - if (phalcon_array_isset_quick_string(definition, SS("notNull"), 1960377425UL)) { - PHALCON_OBS_VAR(not_null); - phalcon_array_fetch_quick_string(¬_null, definition, SS("notNull"), 1960377425UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_notNull"), not_null, 628108368UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(definition, SS("primary"), 482916521UL)) { - PHALCON_OBS_VAR(primary); - phalcon_array_fetch_quick_string(&primary, definition, SS("primary"), 482916521UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_primary"), primary, 3445614760UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(definition, SS("size"), 274442720UL)) { - PHALCON_OBS_VAR(size); - phalcon_array_fetch_quick_string(&size, definition, SS("size"), 274442720UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_size"), size, 3990209087UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(definition, SS("scale"), 458672173UL)) { - - PHALCON_INIT_VAR(t0); - ZVAL_LONG(t0, 3); - PHALCON_INIT_VAR(is_numeric); - is_equal_function(is_numeric, type, t0 TSRMLS_CC); - if (PHALCON_IS_NOT_TRUE(is_numeric)) { - PHALCON_INIT_VAR(t1); - ZVAL_LONG(t1, 7); - is_equal_function(is_numeric, type, t1 TSRMLS_CC); +// 330 "scanner.c" +jj36: + ++JJCURSOR; +// 172 "scanner.re" + { + s->active_line++; + token->opcode = PHANNOT_T_IGNORE; + return 0; } - - if (PHALCON_IS_TRUE(is_numeric)) { - PHALCON_OBS_VAR(scale); - phalcon_array_fetch_quick_string(&scale, definition, SS("scale"), 458672173UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_scale"), scale, 2819877996UL TSRMLS_CC); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column type does not support scale parameter"); - return; +// 339 "scanner.c" +jj38: + ++JJCURSOR; +// 178 "scanner.re" + { + status = PHANNOT_SCANNER_RETCODE_EOF; + break; } - } - - if (phalcon_array_isset_quick_string(definition, SS("unsigned"), 1143113122UL)) { - PHALCON_OBS_VAR(dunsigned); - phalcon_array_fetch_quick_string(&dunsigned, definition, SS("unsigned"), 1143113122UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_unsigned"), dunsigned, 127907201UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(definition, SS("isNumeric"), 1643974676UL)) { - PHALCON_OBS_NVAR(is_numeric); - phalcon_array_fetch_quick_string(&is_numeric, definition, SS("isNumeric"), 1643974676UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_isNumeric"), is_numeric, 2501917651UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(definition, SS("autoIncrement"), 2492144707UL)) { - if (PHALCON_IS_LONG(type, 0)) { - PHALCON_OBS_VAR(auto_increment); - phalcon_array_fetch_quick_string(&auto_increment, definition, SS("autoIncrement"), 2492144707UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_autoIncrement"), auto_increment, 3100381058UL TSRMLS_CC); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column type cannot be auto-increment"); - return; +// 347 "scanner.c" +jj40: + jjch = *++JJCURSOR; + goto jj3; +jj41: + ++JJCURSOR; + jjch = *JJCURSOR; +jj42: + switch (jjch) { + case '\t': + case '\r': + case ' ': goto jj41; + default: goto jj35; + } +jj43: + ++JJCURSOR; + jjch = *JJCURSOR; +jj44: + switch (jjch) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto jj43; + default: goto jj7; + } +jj45: + ++JJCURSOR; + jjch = *JJCURSOR; +jj46: + switch (jjch) { + case 0x00: goto jj47; + case '\'': goto jj49; + case '\\': goto jj48; + default: goto jj45; + } +jj47: + JJCURSOR = JJMARKER; + switch (jjaccept) { + case 0: goto jj5; + case 1: goto jj3; + } +jj48: + ++JJCURSOR; + jjch = *JJCURSOR; + switch (jjch) { + case '\n': goto jj47; + default: goto jj45; + } +jj49: + ++JJCURSOR; +// 100 "scanner.re" + { + token->opcode = PHANNOT_T_STRING; + token->value = estrndup(q, JJCURSOR - q - 1); + token->len = JJCURSOR - q - 1; + q = JJCURSOR; + return 0; } - } - - if (phalcon_array_isset_quick_string(definition, SS("first"), 4252613933UL)) { - PHALCON_OBS_VAR(first); - phalcon_array_fetch_quick_string(&first, definition, SS("first"), 4252613933UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_first"), first, 2318852460UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(definition, SS("after"), 4053435767UL)) { - PHALCON_OBS_VAR(after); - phalcon_array_fetch_quick_string(&after, definition, SS("after"), 4053435767UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_after"), after, 2119674294UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(definition, SS("bindType"), 1941857476UL)) { - PHALCON_OBS_VAR(bind_type); - phalcon_array_fetch_quick_string(&bind_type, definition, SS("bindType"), 1941857476UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_bindType"), bind_type, 926651555UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} +// 465 "scanner.c" +jj51: + ++JJCURSOR; + jjch = *JJCURSOR; +jj52: + switch (jjch) { + case 0x00: goto jj47; + case '"': goto jj49; + case '\\': goto jj53; + default: goto jj51; + } +jj53: + ++JJCURSOR; + jjch = *JJCURSOR; + switch (jjch) { + case '\n': goto jj47; + default: goto jj51; + } +jj54: + jjch = *++JJCURSOR; + switch (jjch) { + case 'U': + case 'u': goto jj55; + default: goto jj44; + } +jj55: + jjch = *++JJCURSOR; + switch (jjch) { + case 'E': + case 'e': goto jj56; + default: goto jj44; + } +jj56: + ++JJCURSOR; + switch ((jjch = *JJCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto jj43; + default: goto jj57; + } +jj57: +// 94 "scanner.re" + { + token->opcode = PHANNOT_T_TRUE; + return 0; + } +// 572 "scanner.c" +jj58: + jjch = *++JJCURSOR; + switch (jjch) { + case 'L': + case 'l': goto jj59; + default: goto jj44; + } +jj59: + jjch = *++JJCURSOR; + switch (jjch) { + case 'S': + case 's': goto jj60; + default: goto jj44; + } +jj60: + jjch = *++JJCURSOR; + switch (jjch) { + case 'E': + case 'e': goto jj61; + default: goto jj44; + } +jj61: + ++JJCURSOR; + switch ((jjch = *JJCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto jj43; + default: goto jj62; + } +jj62: +// 89 "scanner.re" + { + token->opcode = PHANNOT_T_FALSE; + return 0; + } +// 669 "scanner.c" +jj63: + jjch = *++JJCURSOR; + switch (jjch) { + case 'L': + case 'l': goto jj64; + default: goto jj44; + } +jj64: + jjch = *++JJCURSOR; + switch (jjch) { + case 'L': + case 'l': goto jj65; + default: goto jj44; + } +jj65: + ++JJCURSOR; + switch ((jjch = *JJCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto jj43; + default: goto jj66; + } +jj66: +// 84 "scanner.re" + { + token->opcode = PHANNOT_T_NULL; + return 0; + } +// 759 "scanner.c" +jj67: + jjch = *++JJCURSOR; + switch (jjch) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto jj70; + default: goto jj47; + } +jj68: + jjaccept = 0; + JJMARKER = ++JJCURSOR; + jjch = *JJCURSOR; +jj69: + switch (jjch) { + case '.': goto jj67; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto jj68; + default: goto jj5; + } +jj70: + ++JJCURSOR; + jjch = *JJCURSOR; + switch (jjch) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto jj70; + default: goto jj72; + } +jj72: +// 76 "scanner.re" + { + token->opcode = PHANNOT_T_DOUBLE; + token->value = estrndup(start, JJCURSOR - start); + token->len = JJCURSOR - start; + q = JJCURSOR; + return 0; + } +// 819 "scanner.c" + } +// 188 "scanner.re" -static PHP_METHOD(Phalcon_Db_Column, getSchemaName){ + } + } - RETURN_MEMBER_QUICK(this_ptr, "_schemaName", 851420310UL); + return status; } -static PHP_METHOD(Phalcon_Db_Column, getName){ - RETURN_MEMBER_QUICK(this_ptr, "_columnName", 3251978323UL); -} -static PHP_METHOD(Phalcon_Db_Column, getType){ +#ifdef HAVE_CONFIG_H +#endif - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); -} -static PHP_METHOD(Phalcon_Db_Column, getSize){ - RETURN_MEMBER_QUICK(this_ptr, "_size", 3990209087UL); + + +PHALCON_INIT_CLASS(Phalcon_Assets_Collection){ + + PHALCON_REGISTER_CLASS(Phalcon\\Assets, Collection, assets_collection, phalcon_assets_collection_method_entry, 0); + + zend_declare_property_null(phalcon_assets_collection_ce, SL("_prefix"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_assets_collection_ce, SL("_local"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_collection_ce, SL("_resources"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_collection_ce, SL("_position"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_collection_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_collection_ce, SL("_attributes"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_assets_collection_ce, SL("_join"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_collection_ce, SL("_targetUri"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_collection_ce, SL("_targetPath"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_collection_ce, SL("_sourcePath"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_assets_collection_ce TSRMLS_CC, 2, spl_ce_Countable, zend_ce_iterator); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Column, getScale){ +static PHP_METHOD(Phalcon_Assets_Collection, add){ + zval *resource; - RETURN_MEMBER_QUICK(this_ptr, "_scale", 2819877996UL); + phalcon_fetch_params(0, 1, 0, &resource); + + if (Z_TYPE_P(resource) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Resource must be an object"); + return; + } + phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC); + + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Column, isUnsigned){ +static PHP_METHOD(Phalcon_Assets_Collection, addCss){ + + zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *collection_local = NULL; + zval *collection_attributes = NULL, *resource; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_unsigned", 127907201UL); + phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); + + if (!local) { + PHALCON_INIT_VAR(local); + } + + if (!filter) { + PHALCON_INIT_VAR(filter); + ZVAL_BOOL(filter, 1); + } + + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } + + if (Z_TYPE_P(local) == IS_BOOL) { + PHALCON_CPY_WRT(collection_local, local); + } else { + PHALCON_OBS_NVAR(collection_local); + phalcon_read_property_this_quick(&collection_local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC); + } + if (Z_TYPE_P(attributes) == IS_ARRAY) { + PHALCON_CPY_WRT(collection_attributes, attributes); + } else { + PHALCON_OBS_NVAR(collection_attributes); + phalcon_read_property_this_quick(&collection_attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); + } + + PHALCON_INIT_VAR(resource); + object_init_ex(resource, phalcon_assets_resource_css_ce); + phalcon_call_method_p4_key(NULL, resource, "__construct", path, collection_local, filter, collection_attributes, 1107214344UL); + + phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC); + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Column, isNotNull){ +static PHP_METHOD(Phalcon_Assets_Collection, addJs){ + zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *collection_local = NULL; + zval *collection_attributes = NULL, *resource; - RETURN_MEMBER_QUICK(this_ptr, "_notNull", 628108368UL); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); + + if (!local) { + PHALCON_INIT_VAR(local); + } + + if (!filter) { + PHALCON_INIT_VAR(filter); + ZVAL_BOOL(filter, 1); + } + + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } + + if (Z_TYPE_P(local) == IS_BOOL) { + PHALCON_CPY_WRT(collection_local, local); + } else { + PHALCON_OBS_NVAR(collection_local); + phalcon_read_property_this_quick(&collection_local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC); + } + if (Z_TYPE_P(attributes) == IS_ARRAY) { + PHALCON_CPY_WRT(collection_attributes, attributes); + } else { + PHALCON_OBS_NVAR(collection_attributes); + phalcon_read_property_this_quick(&collection_attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); + } + + PHALCON_INIT_VAR(resource); + object_init_ex(resource, phalcon_assets_resource_js_ce); + phalcon_call_method_p4_key(NULL, resource, "__construct", path, collection_local, filter, collection_attributes, 1107214344UL); + + phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC); + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Column, isPrimary){ +static PHP_METHOD(Phalcon_Assets_Collection, getResources){ + + zval *resources; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_primary", 3445614760UL); + PHALCON_OBS_VAR(resources); + phalcon_read_property_this_quick(&resources, this_ptr, SL("_resources"), 3320036063UL, PH_NOISY_CC); + if (Z_TYPE_P(resources) != IS_ARRAY) { + RETURN_MM_EMPTY_ARRAY(); + } + + RETURN_CCTOR(resources); } -static PHP_METHOD(Phalcon_Db_Column, isAutoIncrement){ +static PHP_METHOD(Phalcon_Assets_Collection, count){ + zval *resources; - RETURN_MEMBER_QUICK(this_ptr, "_autoIncrement", 3100381058UL); + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(resources); + phalcon_read_property_this_quick(&resources, this_ptr, SL("_resources"), 3320036063UL, PH_NOISY_CC); + phalcon_fast_count(return_value, resources TSRMLS_CC); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Column, isNumeric){ +static PHP_METHOD(Phalcon_Assets_Collection, rewind){ - RETURN_MEMBER_QUICK(this_ptr, "_isNumeric", 2501917651UL); + phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC); + } -static PHP_METHOD(Phalcon_Db_Column, isFirst){ +static PHP_METHOD(Phalcon_Assets_Collection, current){ + + zval *position, *resources, *resource; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_first", 2318852460UL); + PHALCON_OBS_VAR(position); + phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(resources); + phalcon_read_property_this_quick(&resources, this_ptr, SL("_resources"), 3320036063UL, PH_NOISY_CC); + if (phalcon_array_isset(resources, position)) { + PHALCON_OBS_VAR(resource); + phalcon_array_fetch(&resource, resources, position, PH_NOISY); + RETURN_CCTOR(resource); + } + + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Db_Column, getAfterPosition){ +static PHP_METHOD(Phalcon_Assets_Collection, key){ - RETURN_MEMBER_QUICK(this_ptr, "_after", 2119674294UL); + RETURN_MEMBER_QUICK(this_ptr, "_position", 2925265369UL); } -static PHP_METHOD(Phalcon_Db_Column, getBindType){ +static PHP_METHOD(Phalcon_Assets_Collection, next){ - RETURN_MEMBER_QUICK(this_ptr, "_bindType", 926651555UL); + phalcon_property_incr(this_ptr, SL("_position") TSRMLS_CC); + } -static PHP_METHOD(Phalcon_Db_Column, __set_state){ +static PHP_METHOD(Phalcon_Assets_Collection, valid){ - zval *data, *definition, *column_name, *column_type; - zval *not_null, *primary, *size, *dunsigned, *after; - zval *is_numeric, *first, *bind_type; + zval *position, *resources; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &data); + PHALCON_OBS_VAR(position); + phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column state must be an array"); - return; + PHALCON_OBS_VAR(resources); + phalcon_read_property_this_quick(&resources, this_ptr, SL("_resources"), 3320036063UL, PH_NOISY_CC); + if (phalcon_array_isset(resources, position)) { + RETURN_MM_TRUE; } - PHALCON_INIT_VAR(definition); - array_init(definition); - if (!phalcon_array_isset_quick_string(data, SS("_columnName"), 3251978323UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column name is required"); + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Assets_Collection, setTargetPath){ + + zval *target_path; + + phalcon_fetch_params(0, 1, 0, &target_path); + + phalcon_update_property_this_quick(this_ptr, SL("_targetPath"), target_path, 3658201208UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Collection, getTargetPath){ + + + RETURN_MEMBER_QUICK(this_ptr, "_targetPath", 3658201208UL); +} + +static PHP_METHOD(Phalcon_Assets_Collection, setSourcePath){ + + zval *source_path; + + phalcon_fetch_params(0, 1, 0, &source_path); + + phalcon_update_property_this_quick(this_ptr, SL("_sourcePath"), source_path, 1419415746UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Collection, getSourcePath){ + + + RETURN_MEMBER_QUICK(this_ptr, "_sourcePath", 1419415746UL); +} + +static PHP_METHOD(Phalcon_Assets_Collection, setTargetUri){ + + zval *target_uri; + + phalcon_fetch_params(0, 1, 0, &target_uri); + + phalcon_update_property_this_quick(this_ptr, SL("_targetUri"), target_uri, 2193460699UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Collection, getTargetUri){ + + + RETURN_MEMBER_QUICK(this_ptr, "_targetUri", 2193460699UL); +} + +static PHP_METHOD(Phalcon_Assets_Collection, setPrefix){ + + zval *prefix; + + phalcon_fetch_params(0, 1, 0, &prefix); + + phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Collection, getPrefix){ + + + RETURN_MEMBER_QUICK(this_ptr, "_prefix", 3873791314UL); +} + +static PHP_METHOD(Phalcon_Assets_Collection, setLocal){ + + zval *local; + + phalcon_fetch_params(0, 1, 0, &local); + + phalcon_update_property_this_quick(this_ptr, SL("_local"), local, 2560221423UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Collection, getLocal){ + + + RETURN_MEMBER_QUICK(this_ptr, "_local", 2560221423UL); +} + +static PHP_METHOD(Phalcon_Assets_Collection, setAttributes){ + + zval *attributes; + + phalcon_fetch_params(0, 1, 0, &attributes); + + if (Z_TYPE_P(attributes) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Attributes must be an array"); return; } + phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC); - PHALCON_OBS_VAR(column_name); - phalcon_array_fetch_quick_string(&column_name, data, SS("_columnName"), 3251978323UL, PH_NOISY); - if (phalcon_array_isset_quick_string(data, SS("_type"), 3991959110UL)) { - PHALCON_OBS_VAR(column_type); - phalcon_array_fetch_quick_string(&column_type, data, SS("_type"), 3991959110UL, PH_NOISY); - phalcon_array_update_quick_string(&definition, SS("type"), 276192743UL, &column_type, PH_COPY | PH_SEPARATE); - } + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Collection, getAttributes){ + + + RETURN_MEMBER_QUICK(this_ptr, "_attributes", 1565778155UL); +} + +static PHP_METHOD(Phalcon_Assets_Collection, addFilter){ + + zval *filter; + + phalcon_fetch_params(0, 1, 0, &filter); - if (phalcon_array_isset_quick_string(data, SS("_notNull"), 628108368UL)) { - PHALCON_OBS_VAR(not_null); - phalcon_array_fetch_quick_string(¬_null, data, SS("_notNull"), 628108368UL, PH_NOISY); - phalcon_array_update_quick_string(&definition, SS("notNull"), 1960377425UL, ¬_null, PH_COPY | PH_SEPARATE); - } + phalcon_update_property_array_append(this_ptr, SL("_filters"), filter TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Collection, setFilters){ + + zval *filters; + + phalcon_fetch_params(0, 1, 0, &filters); - if (phalcon_array_isset_quick_string(data, SS("_primary"), 3445614760UL)) { - PHALCON_OBS_VAR(primary); - phalcon_array_fetch_quick_string(&primary, data, SS("_primary"), 3445614760UL, PH_NOISY); - phalcon_array_update_quick_string(&definition, SS("primary"), 482916521UL, &primary, PH_COPY | PH_SEPARATE); + if (Z_TYPE_P(filters) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Filters must be an array of filters"); + return; } + phalcon_update_property_this_quick(this_ptr, SL("_filters"), filters, 3850488637UL TSRMLS_CC); - if (phalcon_array_isset_quick_string(data, SS("_size"), 3990209087UL)) { - PHALCON_OBS_VAR(size); - phalcon_array_fetch_quick_string(&size, data, SS("_size"), 3990209087UL, PH_NOISY); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &size, PH_COPY | PH_SEPARATE); - } + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Collection, getFilters){ + + + RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL); +} + +static PHP_METHOD(Phalcon_Assets_Collection, join){ + + zval *join; + + phalcon_fetch_params(0, 1, 0, &join); - if (phalcon_array_isset_quick_string(data, SS("_unsigned"), 127907201UL)) { - PHALCON_OBS_VAR(dunsigned); - phalcon_array_fetch_quick_string(&dunsigned, data, SS("_unsigned"), 127907201UL, PH_NOISY); - phalcon_array_update_quick_string(&definition, SS("unsigned"), 1143113122UL, &dunsigned, PH_COPY | PH_SEPARATE); - } + phalcon_update_property_this_quick(this_ptr, SL("_join"), join, 3979733204UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Collection, getJoin){ + + + RETURN_MEMBER_QUICK(this_ptr, "_join", 3979733204UL); +} + +static PHP_METHOD(Phalcon_Assets_Collection, getRealTargetPath){ + + zval *base_path = NULL, *target_path, *complete_path; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &base_path); - if (phalcon_array_isset_quick_string(data, SS("_after"), 2119674294UL)) { - PHALCON_OBS_VAR(after); - phalcon_array_fetch_quick_string(&after, data, SS("_after"), 2119674294UL, PH_NOISY); - phalcon_array_update_quick_string(&definition, SS("after"), 4053435767UL, &after, PH_COPY | PH_SEPARATE); + if (!base_path) { + PHALCON_INIT_VAR(base_path); } - if (phalcon_array_isset_quick_string(data, SS("_isNumeric"), 2501917651UL)) { - PHALCON_OBS_VAR(is_numeric); - phalcon_array_fetch_quick_string(&is_numeric, data, SS("_isNumeric"), 2501917651UL, PH_NOISY); - phalcon_array_update_quick_string(&definition, SS("isNumeric"), 1643974676UL, &is_numeric, PH_COPY | PH_SEPARATE); - } + PHALCON_OBS_VAR(target_path); + phalcon_read_property_this_quick(&target_path, this_ptr, SL("_targetPath"), 3658201208UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(data, SS("_first"), 2318852460UL)) { - PHALCON_OBS_VAR(first); - phalcon_array_fetch_quick_string(&first, data, SS("_first"), 2318852460UL, PH_NOISY); - phalcon_array_update_quick_string(&definition, SS("first"), 4252613933UL, &first, PH_COPY | PH_SEPARATE); - } + PHALCON_INIT_VAR(complete_path); + PHALCON_CONCAT_VV(complete_path, base_path, target_path); - if (phalcon_array_isset_quick_string(data, SS("_bindType"), 926651555UL)) { - PHALCON_OBS_VAR(bind_type); - phalcon_array_fetch_quick_string(&bind_type, data, SS("_bindType"), 926651555UL, PH_NOISY); - phalcon_array_update_quick_string(&definition, SS("bindType"), 1941857476UL, &bind_type, PH_COPY | PH_SEPARATE); + if (phalcon_file_exists(complete_path TSRMLS_CC) == SUCCESS) { + phalcon_call_func_p1(return_value, "realpath", complete_path); + RETURN_MM(); } - object_init_ex(return_value, phalcon_db_column_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", column_name, definition, 1107214344UL); - - RETURN_MM(); + RETURN_CTOR(complete_path); } @@ -17205,9 +17204,12 @@ static PHP_METHOD(Phalcon_Db_Column, __set_state){ -PHALCON_INIT_CLASS(Phalcon_Db_ResultInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ResultInterface, db_resultinterface, phalcon_db_resultinterface_method_entry); + + +PHALCON_INIT_CLASS(Phalcon_Assets_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Assets, Exception, assets_exception, "phalcon\\exception", NULL, 0); return SUCCESS; } @@ -17216,9 +17218,17 @@ PHALCON_INIT_CLASS(Phalcon_Db_ResultInterface){ +#ifdef HAVE_CONFIG_H +#endif + +PHALCON_INIT_CLASS(Phalcon_Assets_FilterInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Assets, FilterInterface, assets_filterinterface, phalcon_assets_filterinterface_method_entry); + return SUCCESS; +} @@ -17234,310 +17244,307 @@ PHALCON_INIT_CLASS(Phalcon_Db_ResultInterface){ -PHALCON_INIT_CLASS(Phalcon_Db_Result_Pdo){ - - PHALCON_REGISTER_CLASS(Phalcon\\Db\\Result, Pdo, db_result_pdo, phalcon_db_result_pdo_method_entry, 0); +PHALCON_INIT_CLASS(Phalcon_Assets_Filters_Cssmin){ - zend_declare_property_null(phalcon_db_result_pdo_ce, SL("_connection"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_result_pdo_ce, SL("_result"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_db_result_pdo_ce, SL("_fetchMode"), 4, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_result_pdo_ce, SL("_pdoStatement"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_result_pdo_ce, SL("_sqlStatement"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_result_pdo_ce, SL("_bindParams"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_result_pdo_ce, SL("_bindTypes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_db_result_pdo_ce, SL("_rowCount"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_REGISTER_CLASS(Phalcon\\Assets\\Filters, Cssmin, assets_filters_cssmin, phalcon_assets_filters_cssmin_method_entry, 0); return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Result_Pdo, __construct){ +static PHP_METHOD(Phalcon_Assets_Filters_Cssmin, filter){ - zval *connection, *result, *sql_statement = NULL, *bind_params = NULL; - zval *bind_types = NULL; + zval *content; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 3, &connection, &result, &sql_statement, &bind_params, &bind_types); - - if (!sql_statement) { - PHALCON_INIT_VAR(sql_statement); - } - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } - - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } + phalcon_fetch_params(1, 1, 0, &content); - if (Z_TYPE_P(result) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid PDOStatement supplied to Phalcon\\Db\\Result\\Pdo"); + if (phalcon_cssmin(return_value, content TSRMLS_CC) == FAILURE) { return; } - phalcon_update_property_this_quick(this_ptr, SL("_connection"), connection, 3057302292UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_pdoStatement"), result, 650036348UL TSRMLS_CC); - if (Z_TYPE_P(sql_statement) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_sqlStatement"), sql_statement, 18972457UL TSRMLS_CC); - } - - if (Z_TYPE_P(bind_params) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_bindParams"), bind_params, 2293392709UL TSRMLS_CC); - } - - if (Z_TYPE_P(bind_types) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_bindTypes"), bind_types, 514734038UL TSRMLS_CC); - } - PHALCON_MM_RESTORE(); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Result_Pdo, execute){ - - zval *pdo_statement; - - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(pdo_statement); - phalcon_read_property_this_quick(&pdo_statement, this_ptr, SL("_pdoStatement"), 650036348UL, PH_NOISY_CC); - phalcon_call_method_key(return_value, pdo_statement, "execute", 3117639032UL); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Db_Result_Pdo, fetch){ +/* cssmin.c - zval *pdo_statement; +Copyright (c) 2010 (www.ryanday.org) - PHALCON_MM_GROW(); +w3c css spec: http://www.w3.org/TR/CSS2/syndata.html +this parser makes no attempt to understand css as such it does not interpret css to spec. - PHALCON_OBS_VAR(pdo_statement); - phalcon_read_property_this_quick(&pdo_statement, this_ptr, SL("_pdoStatement"), 650036348UL, PH_NOISY_CC); - phalcon_call_method_key(return_value, pdo_statement, "fetch", 4247924303UL); - RETURN_MM(); -} +** cannot handle nested { blocks but will ignore aditional { in parens () +** no in quote detection for ( or } -static PHP_METHOD(Phalcon_Db_Result_Pdo, fetchArray){ +function get, peek and general lookahead structure taken from.. - zval *pdo_statement; +jsmin.c - PHALCON_MM_GROW(); +Copyright (c) 2002 Douglas Crockford (www.crockford.com) - PHALCON_OBS_VAR(pdo_statement); - phalcon_read_property_this_quick(&pdo_statement, this_ptr, SL("_pdoStatement"), 650036348UL, PH_NOISY_CC); - phalcon_call_method_key(return_value, pdo_statement, "fetch", 4247924303UL); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Db_Result_Pdo, fetchAll){ +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: - zval *pdo_statement; +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. - PHALCON_MM_GROW(); +The Software shall be used for Good, not Evil. - PHALCON_OBS_VAR(pdo_statement); - phalcon_read_property_this_quick(&pdo_statement, this_ptr, SL("_pdoStatement"), 650036348UL, PH_NOISY_CC); - phalcon_call_method_key(return_value, pdo_statement, "fetchall", 1636682248UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Result_Pdo, numRows){ +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ - zval *row_count = NULL, *connection, *type, *pdo_statement = NULL; - zval *sql_statement, *bind_params, *bind_types; - zval *matches, *pattern, *match, *else_clauses; - zval *sql, *result, *row; +#ifdef HAVE_CONFIG_H +#endif - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(row_count); - phalcon_read_property_this_quick(&row_count, this_ptr, SL("_rowCount"), 1917183365UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(row_count)) { - - PHALCON_OBS_VAR(connection); - phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(type); - phalcon_call_method_key(type, connection, "gettype", 4294422375UL); - - if (PHALCON_IS_STRING(type, "mysql")) { - PHALCON_OBS_VAR(pdo_statement); - phalcon_read_property_this_quick(&pdo_statement, this_ptr, SL("_pdoStatement"), 650036348UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(row_count); - phalcon_call_method_key(row_count, pdo_statement, "rowcount", 4184721862UL); - } - - if (PHALCON_IS_STRING(type, "pgsql")) { - PHALCON_OBS_NVAR(pdo_statement); - phalcon_read_property_this_quick(&pdo_statement, this_ptr, SL("_pdoStatement"), 650036348UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(row_count); - phalcon_call_method_key(row_count, pdo_statement, "rowcount", 4184721862UL); - } - - if (PHALCON_IS_FALSE(row_count)) { - - PHALCON_OBS_VAR(sql_statement); - phalcon_read_property_this_quick(&sql_statement, this_ptr, SL("_sqlStatement"), 18972457UL, PH_NOISY_CC); - - if (!phalcon_start_with_str(sql_statement, SL("SELECT COUNT(*) "))) { - - PHALCON_OBS_VAR(bind_params); - phalcon_read_property_this_quick(&bind_params, this_ptr, SL("_bindParams"), 2293392709UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(bind_types); - phalcon_read_property_this_quick(&bind_types, this_ptr, SL("_bindTypes"), 514734038UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(matches); - - PHALCON_INIT_VAR(pattern); - ZVAL_STRING(pattern, "/^SELECT\\s+(.*)$/i", 1); - - PHALCON_INIT_VAR(match); - phalcon_preg_match(match, pattern, sql_statement, matches TSRMLS_CC); - - if (zend_is_true(match)) { - PHALCON_OBS_VAR(else_clauses); - phalcon_array_fetch_long(&else_clauses, matches, 1, PH_NOISY); - - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT COUNT(*) \"numrows\" FROM (SELECT ", else_clauses, ")"); - - PHALCON_INIT_VAR(result); - phalcon_call_method_p3_key(result, connection, "query", sql, bind_params, bind_types, 401898907UL); - - PHALCON_INIT_VAR(row); - phalcon_call_method_key(row, result, "fetch", 4247924303UL); - - PHALCON_OBS_NVAR(row_count); - phalcon_array_fetch_quick_string(&row_count, row, SS("numrows"), 887792640UL, PH_NOISY); - } - } else { - PHALCON_INIT_NVAR(row_count); - ZVAL_LONG(row_count, 1); - } - } - - phalcon_update_property_this_quick(this_ptr, SL("_rowCount"), row_count, 1917183365UL TSRMLS_CC); - } - - RETURN_CCTOR(row_count); -} -static PHP_METHOD(Phalcon_Db_Result_Pdo, dataSeek){ +#define STATE_FREE 1 +#define STATE_ATRULE 2 +#define STATE_SELECTOR 3 +#define STATE_BLOCK 4 +#define STATE_DECLARATION 5 +#define STATE_COMMENT 6 - long number = 0, n; - zval *connection, *pdo, *sql_statement; - zval *bind_params, *bind_types, *statement = NULL; - zval *temp_statement = NULL; - pdo_stmt_t *stmt; +typedef struct _cssmin_parser { + int tmp_state; + int state; + int last_state; + int in_paren; + zval *style; + zval **error; + smart_str *minified; + int style_pointer; +} cssmin_parser; - PHALCON_MM_GROW(); +/* get -- return the next character from stdin. Watch out for lookahead. If +the character is a control character, translate it to a space or +linefeed. +*/ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &number) == FAILURE) { - RETURN_MM_NULL(); +static char cssmin_peek(cssmin_parser *parser){ + char ch; + if (parser->style_pointer < Z_STRLEN_P(parser->style)) { + ch = Z_STRVAL_P(parser->style)[parser->style_pointer]; + return ch; } + return EOF; +} - PHALCON_OBS_VAR(connection); - phalcon_read_property(&connection, this_ptr, SL("_connection"), PH_NOISY_CC); +static char cssmin_back_peek(cssmin_parser *parser){ + char ch; + if (parser->style_pointer > 1) { + ch = Z_STRVAL_P(parser->style)[parser->style_pointer - 1]; + return ch; + } + return EOF; +} - PHALCON_INIT_VAR(pdo); - phalcon_call_method_key(pdo, connection, "getinternalhandler", 489229824UL); +/* machine - PHALCON_OBS_VAR(sql_statement); - phalcon_read_property(&sql_statement, this_ptr, SL("_sqlStatement"), PH_NOISY_CC); +*/ +static int phalcon_cssmin_machine(cssmin_parser *parser, unsigned char c TSRMLS_DC){ - PHALCON_OBS_VAR(bind_params); - phalcon_read_property(&bind_params, this_ptr, SL("_bindParams"), PH_NOISY_CC); + unsigned char p; - if (Z_TYPE_P(bind_params) == IS_ARRAY) { + if (parser->state != STATE_COMMENT) { + if (c == '/' && cssmin_peek(parser) == '*') { + parser->tmp_state = parser->state; + parser->state = STATE_COMMENT; + } + } - PHALCON_OBS_VAR(bind_types); - phalcon_read_property(&bind_types, this_ptr, SL("_bindTypes"), PH_NOISY_CC); + switch (parser->state) { + case STATE_FREE: + if (c == ' ' && c == '\t' && c == '\n' && c == '\r') { + c = 0; + } else if (c == '@'){ + parser->state = STATE_ATRULE; + break; + } else if(c > 0){ + //fprintf(stdout,"one to 3 - %c %i",c,c); + parser->state = STATE_SELECTOR; + } + /* no break */ + case STATE_SELECTOR: + if (c == '{') { + parser->state = STATE_BLOCK; + } else { + if(c == '\n' || c == '\r') { + c = 0; + } else { + if(c == '@'){ + parser->state = STATE_ATRULE; + } else { + if ((c == ' ' || c == '\t')) { + p = cssmin_peek(parser); + if (p == '{' || p == '\t' || p == ' ' || p == '>' || p == ',') { + c = 0; + } else { + p = cssmin_back_peek(parser); + if (p == ',' || p == '>' || p == ':') { + c = 0; + } else { + c = ' '; + } + } + } + } + } + } + break; + case STATE_ATRULE: + /* support + @import etc. + @font-face{ + */ + if (c == '\r' || c == '\n' || c == ';') { + c = ';'; + parser->state = STATE_FREE; + } else { + if(c == '{') { + parser->state = STATE_BLOCK; + } + } + break; + case STATE_BLOCK: + if (c == ' ' || c == '\t' || c == '\n' || c == '\r' ) { + c = 0; + break; + } else { + if (c == '}') { + parser->state = STATE_FREE; + //fprintf(stdout,"closing bracket found in block\n"); + break; + } else { + parser->state = STATE_DECLARATION; + } + } + /* no break */ + case STATE_DECLARATION: + if (c == '(') { + parser->in_paren = 1; + } + if (parser->in_paren == 0) { + if (c == ';') { + parser->state = STATE_BLOCK; + if (cssmin_peek(parser) == '}') { + c = 0; + } + } else if (c == '}') { + parser->state = STATE_FREE; + } else { + if (c == '\n' || c == '\r') { + c = 0; + } else { + if (c == ' ' || c == '\t') { + p = cssmin_peek(parser); + if (p == ' ' || p == '\t') { + c = 0; + } else { + c = ' '; + } + } + } + } - PHALCON_INIT_VAR(statement); - phalcon_call_method_p1_key(statement, pdo, "prepare", sql_statement, 329932052UL); - if (Z_TYPE_P(statement) == IS_OBJECT) { - PHALCON_INIT_VAR(temp_statement); - phalcon_call_method_p3_key(temp_statement, connection, "executeprepared", statement, bind_params, bind_types, 647421771UL); - PHALCON_CPY_WRT(statement, temp_statement); - } + } else { + if (c == ')') { + parser->in_paren = 0; + } + } - } else { - PHALCON_INIT_NVAR(statement); - phalcon_call_method_p1_key(statement, pdo, "query", sql_statement, 401898907UL); + break; + case STATE_COMMENT: + if (c == '*' && cssmin_peek(parser) == '/'){ + parser->style_pointer += 2; + parser->state = parser->tmp_state; + } + c = 0; + break; } - phalcon_update_property_zval(this_ptr, SL("_pdoStatement"), statement TSRMLS_CC); + return c; +} +static int phalcon_cssmin_internal(zval *return_value, zval *style, zval **error TSRMLS_DC) { - stmt = (pdo_stmt_t*) zend_object_store_get_object(statement TSRMLS_CC); - if (!stmt->dbh) { - PHALCON_MM_RESTORE(); - RETURN_FALSE; - } + int i; + unsigned char c; + cssmin_parser parser; + smart_str minified = {0}; - n = -1; - number--; - while (n != number) { + parser.state = 1; + parser.last_state = 1; + parser.in_paren = 0; + parser.style = style; + parser.error = error; + parser.minified = &minified; - if(!stmt->methods->fetcher(stmt, PDO_FETCH_ORI_NEXT, 0 TSRMLS_CC)) { - PHALCON_MM_RESTORE(); - RETURN_NULL(); + for (i = 0; i < Z_STRLEN_P(style); i++) { + parser.style_pointer = i + 1; + c = phalcon_cssmin_machine(&parser, Z_STRVAL_P(style)[i] TSRMLS_CC); + if (c != 0) { + smart_str_appendc(parser.minified, c); } - - n++; + i = parser.style_pointer - 1; } - PHALCON_MM_RESTORE(); -} + smart_str_0(&minified); -static PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ + if (minified.len) { + ZVAL_STRINGL(return_value, minified.c, minified.len, 0); + } else { + ZVAL_STRING(return_value, "", 1); + } + return SUCCESS; +} - long fetch_mode; - zval *pdo_statement, *fetch_type; +/* cssmin -- minify the css + removes comments + removes newlines and line feeds keeping + removes last semicolon from last property +*/ - PHALCON_MM_GROW(); +static int phalcon_cssmin(zval *return_value, zval *style TSRMLS_DC) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fetch_mode) == FAILURE) { - RETURN_MM_NULL(); - } + zval *error = NULL; - PHALCON_INIT_VAR(fetch_type); + ZVAL_NULL(return_value); - PHALCON_OBS_VAR(pdo_statement); - phalcon_read_property(&pdo_statement, this_ptr, SL("_pdoStatement"), PH_NOISY_CC); - if (fetch_mode == 1) { - ZVAL_LONG(fetch_type, 2); - } else if (fetch_mode == 2) { - ZVAL_LONG(fetch_type, 4); - } else if (fetch_mode == 3) { - ZVAL_LONG(fetch_type, 3); - } else if (fetch_mode == 4) { - ZVAL_LONG(fetch_type, 5); - } else { - ZVAL_LONG(fetch_type, 0); + if (Z_TYPE_P(style) != IS_STRING) { + phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Style must be a string"), 1 TSRMLS_CC); + return FAILURE; } - if (Z_LVAL_P(fetch_type) != 0) { - phalcon_call_method_p1_key(NULL, pdo_statement, "setfetchmode", fetch_type, 824603840UL); - phalcon_update_property_long(this_ptr, SL("_fetchMode"), Z_LVAL_P(fetch_type) TSRMLS_CC); + if (phalcon_cssmin_internal(return_value, style, &error TSRMLS_CC) == FAILURE) { + if (Z_TYPE_P(error) == IS_STRING) { + phalcon_throw_exception_string(phalcon_assets_exception_ce, Z_STRVAL_P(error), Z_STRLEN_P(error), 1 TSRMLS_CC); + } else { + phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Unknown error"), 1 TSRMLS_CC); + } + return FAILURE; } - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Db_Result_Pdo, getInternalResult){ - - - RETURN_MEMBER_QUICK(this_ptr, "_pdoStatement", 650036348UL); + return SUCCESS; } - #ifdef HAVE_CONFIG_H #endif @@ -17547,2894 +17554,3360 @@ static PHP_METHOD(Phalcon_Db_Result_Pdo, getInternalResult){ -PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Sqlite){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Sqlite, db_dialect_sqlite, "phalcon\\db\\dialect", phalcon_db_dialect_sqlite_method_entry, 0); - - zend_declare_property_string(phalcon_db_dialect_sqlite_ce, SL("_escapeChar"), "\"", ZEND_ACC_PROTECTED TSRMLS_CC); +PHALCON_INIT_CLASS(Phalcon_Assets_Filters_Jsmin){ - zend_class_implements(phalcon_db_dialect_sqlite_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); + PHALCON_REGISTER_CLASS(Phalcon\\Assets\\Filters, Jsmin, assets_filters_jsmin, phalcon_assets_filters_jsmin_method_entry, 0); return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, getColumnDefinition){ +static PHP_METHOD(Phalcon_Assets_Filters_Jsmin, filter){ - zval *column, *size, *column_type, *column_sql = NULL; - zval *scale; + zval *content; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &column); + phalcon_fetch_params(1, 1, 0, &content); - if (Z_TYPE_P(column) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column definition must be an instance of Phalcon\\Db\\Column"); + if (phalcon_jsmin(return_value, content TSRMLS_CC) == FAILURE) { return; } - PHALCON_INIT_VAR(size); - phalcon_call_method_key(size, column, "getsize", 4292672352UL); - - PHALCON_INIT_VAR(column_type); - phalcon_call_method_key(column_type, column, "gettype", 4294422375UL); - - switch (phalcon_get_intval(column_type)) { - - case 0: - PHALCON_INIT_VAR(column_sql); - ZVAL_STRING(column_sql, "INT", 1); - break; - - case 1: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "DATE", 1); - break; - - case 2: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "VARCHAR(", size, ")"); - break; - - case 3: - PHALCON_INIT_VAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); - - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVSVS(column_sql, "NUMERIC(", size, ",", scale, ")"); - break; - - case 4: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TIMESTAMP", 1); - break; - - case 5: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "CHARACTER(", size, ")"); - break; - - case 6: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TEXT", 1); - break; - - case 7: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "FLOAT", 1); - break; - - default: - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized SQLite data type"); - return; - - } - - RETURN_CTOR(column_sql); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addColumn){ - - zval *table_name, *schema_name, *column, *sql = NULL, *name; - zval *column_definition, *is_not_null; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); - if (Z_TYPE_P(column) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column parameter must be an instance of Phalcon\\Db\\Column"); - return; - } - PHALCON_INIT_VAR(sql); - if (zend_is_true(schema_name)) { - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE \"", schema_name, "\".\"", table_name, "\" ADD COLUMN "); - } - else { - PHALCON_CONCAT_SVS(sql, "ALTER TABLE \"", table_name, "\" ADD COLUMN "); - } +/* jsmin.c + 2013-03-29 - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, column, "getname", 4286441094UL); +Copyright (c) 2002 Douglas Crockford (www.crockford.com) - PHALCON_INIT_VAR(column_definition); - phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); - PHALCON_SCONCAT_SVSV(sql, "\"", name, "\" ", column_definition); +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: - PHALCON_INIT_VAR(is_not_null); - phalcon_call_method_key(is_not_null, column, "isnotnull", 760409005UL); - if (zend_is_true(is_not_null)) { - phalcon_concat_self_str(&sql, SL(" NOT NULL") TSRMLS_CC); - } +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. - RETURN_CTOR(sql); -} +The Software shall be used for Good, not Evil. -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, modifyColumn){ +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ - zval *table_name, *schema_name, *column; +#ifdef HAVE_CONFIG_H +#endif - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Altering a DB column is not supported by SQLite"); - return; -} -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropColumn){ - zval *table_name, *schema_name, *column_name; +#define JSMIN_ACTION_OUTPUT_NEXT 1 +#define JSMIN_ACTION_NEXT_DELETE 2 +#define JSMIN_ACTION_NEXT 3 - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Dropping DB column is not supported by SQLite"); - return; +typedef struct _jsmin_parser { + zval *script; + zval **error; + int script_pointer; + int inside_string; + smart_str *minified; + char theA; + char theB; + char theC; + char theX; + char theY; +} jsmin_parser; + +static void jsmin_error(jsmin_parser *parser, char* s, int s_length TSRMLS_DC) { + PHALCON_INIT_VAR(*parser->error); + ZVAL_STRINGL(*parser->error, s, s_length, 1); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addIndex){ +/* isAlphanum -- return true if the character is a letter, digit, underscore, + dollar sign, or non-ASCII character. +*/ - zval *table_name, *schema_name, *index, *sql = NULL, *columns; - zval *quoted_column_list, *name; +static int jsmin_isAlphanum(int c) { + return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c == '\\' || c > 126); +} - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); - - if (Z_TYPE_P(index) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Index parameter must be an instance of Phalcon\\Db\\Index"); - return; +/* get -- return the next character from stdin. Watch out for lookahead. If + the character is a control character, translate it to a space or + linefeed. +*/ + +static char jsmin_peek(jsmin_parser *parser){ + char ch; + if (parser->script_pointer < Z_STRLEN_P(parser->script)) { + ch = Z_STRVAL_P(parser->script)[parser->script_pointer]; + return ch; } + return EOF; +} - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, index, "getname", 4286441094UL); +static char jsmin_get(jsmin_parser *parser) { - PHALCON_INIT_VAR(sql); - if (zend_is_true(schema_name)) { - PHALCON_CONCAT_SVSVSVS(sql, "CREATE INDEX \"", schema_name, "\".\"", name, "\" ON \"", table_name, "\" ("); + char c; + + if (parser->script_pointer < Z_STRLEN_P(parser->script)) { + c = Z_STRVAL_P(parser->script)[parser->script_pointer]; + parser->script_pointer++; + } else { + c = EOF; } - else { - PHALCON_CONCAT_SVSVS(sql, "CREATE INDEX \"", name, "\" ON \"", table_name, "\" ("); + + parser->theC = c; + + if (parser->inside_string == 1) { + if (c >= ' ' || c == '\n' || c == '\t' || c == EOF) { + return c; + } + } else { + if (c >= ' ' || c == '\n' || c == EOF) { + return c; + } + } + if (c == '\r') { + return '\n'; } + return ' '; +} - PHALCON_INIT_VAR(columns); - phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); - PHALCON_INIT_VAR(quoted_column_list); - phalcon_call_method_p1_key(quoted_column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); +/* next -- get the next character, excluding comments. peek() is used to see + if a '/' is followed by a '/' or '*'. +*/ - PHALCON_SCONCAT_VS(sql, quoted_column_list, ")"); - RETURN_CTOR(sql); +static int jsmin_next(jsmin_parser *parser TSRMLS_DC) { + char c = jsmin_get(parser); + if (c == '/') { + switch (jsmin_peek(parser)) { + case '/': + for (;;) { + c = jsmin_get(parser); + if (c <= '\n') { + break; + } + } + break; + case '*': + jsmin_get(parser); + while (c != ' ') { + switch (jsmin_get(parser)) { + case '*': + if (jsmin_peek(parser) == '/') { + jsmin_get(parser); + c = ' '; + } + break; + case EOF: + jsmin_error(parser, SL("Unterminated comment.") TSRMLS_CC); + return FAILURE; + } + } + break; + } + } + parser->theY = parser->theX; + parser->theX = c; + return c; } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropIndex){ +/* action -- do something! What you do is determined by the argument: + 1 Output A. Copy B to A. Get the next B. + 2 Copy B to A. Get the next B. (Delete A). + 3 Get the next B. (Delete B). + action treats a string as a single character. Wow! + action recognizes a regular expression if it is preceded by ( or , or =. +*/ - zval *table_name, *schema_name, *index_name; - zval *sql = NULL; +static int jsmin_action(jsmin_parser *parser, char d TSRMLS_DC) { + switch (d) { + case JSMIN_ACTION_OUTPUT_NEXT: + smart_str_appendc(parser->minified, parser->theA); + if ( + (parser->theY == '\n' || parser->theY == ' ') && + (parser->theA == '+' || parser->theA == '-' || parser->theA == '*' || parser->theA == '/') && + (parser->theB == '+' || parser->theB == '-' || parser->theB == '*' || parser->theB == '/') + ) { + smart_str_appendc(parser->minified, parser->theY); + } + /* no break */ + case JSMIN_ACTION_NEXT_DELETE: + parser->theA = parser->theB; + if (parser->theA == '\'' || parser->theA == '"' || parser->theA == '`') { + parser->inside_string = 1; + for (;;) { + smart_str_appendc(parser->minified, parser->theA); + parser->theA = jsmin_get(parser); + if (parser->theA == parser->theB) { + break; + } + if (parser->theA == '\\') { + smart_str_appendc(parser->minified, parser->theA); + parser->theA = jsmin_get(parser); + } + if (parser->theA == EOF) { + jsmin_error(parser, SL("Unterminated string literal.") TSRMLS_CC); + return FAILURE; + } + } + parser->inside_string = 0; + } + /* no break */ + case JSMIN_ACTION_NEXT: + parser->theB = jsmin_next(parser TSRMLS_CC); + if (*parser->error != NULL) { + return FAILURE; + } + if (parser->theB == '/' && ( + parser->theA == '(' || parser->theA == ',' || parser->theA == '=' || parser->theA == ':' || + parser->theA == '[' || parser->theA == '!' || parser->theA == '&' || parser->theA == '|' || + parser->theA == '?' || parser->theA == '+' || parser->theA == '-' || parser->theA == '~' || + parser->theA == '*' || parser->theA == '/' || parser->theA == '{' || parser->theA == '\n' + )) { + smart_str_appendc(parser->minified, parser->theA); + if (parser->theA == '/' || parser->theA == '*') { + smart_str_appendc(parser->minified, ' '); + } + smart_str_appendc(parser->minified, parser->theB); + for (;;) { + parser->theA = jsmin_get(parser); + if (parser->theA == '[') { + for (;;) { + smart_str_appendc(parser->minified, parser->theA); + parser->theA = jsmin_get(parser); + if (parser->theA == ']') { + break; + } + if (parser->theA == '\\') { + smart_str_appendc(parser->minified, parser->theA); + parser->theA = jsmin_get(parser); + } + if (parser->theA == EOF) { + jsmin_error(parser, SL("Unterminated set in Regular Expression literal.") TSRMLS_CC); + return FAILURE; + } + } + } else { + if (parser->theA == '/') { + switch (jsmin_peek(parser)) { + case '/': + case '*': + jsmin_error(parser, SL("Unterminated set in Regular Expression literal.") TSRMLS_CC); + return FAILURE; + } + break; + } else { + if (parser->theA == '\\') { + smart_str_appendc(parser->minified, parser->theA); + parser->theA = jsmin_get(parser); + } + } + } + if (parser->theA == EOF) { + jsmin_error(parser, SL("Unterminated Regular Expression literal.") TSRMLS_CC); + return FAILURE; + } + smart_str_appendc(parser->minified, parser->theA); + } + parser->theB = jsmin_next(parser TSRMLS_CC); + if (*parser->error != NULL) { + return FAILURE; + } + } + } - PHALCON_MM_GROW(); + return SUCCESS; +} - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index_name); - PHALCON_INIT_VAR(sql); - if (zend_is_true(schema_name)) { - PHALCON_CONCAT_SVSVS(sql, "DROP INDEX \"", schema_name, "\".\"", index_name, "\""); +/* jsmin -- Copy the input to the output, deleting the characters which are + insignificant to JavaScript. Comments will be removed. Tabs will be + replaced with spaces. Carriage returns will be replaced with linefeeds. + Most spaces and linefeeds will be removed. +*/ + +static int phalcon_jsmin_internal(zval *return_value, zval *script, zval **error TSRMLS_DC) { + + jsmin_parser parser; + smart_str minified = {0}; + int status = SUCCESS; + + parser.theA = '\n'; + parser.theX = EOF; + parser.theY = EOF; + parser.script = script; + parser.error = error; + parser.script_pointer = 0; + parser.inside_string = 0; + parser.minified = &minified; + + if (jsmin_action(&parser, JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) { + return FAILURE; } - else { - PHALCON_CONCAT_SVS(sql, "DROP INDEX \"", index_name, "\""); + + while (parser.theA != EOF) { + if (status == FAILURE) { + break; + } + switch (parser.theA) { + case ' ': + if (jsmin_action(&parser, jsmin_isAlphanum(parser.theB) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT_DELETE TSRMLS_CC)) { + status = FAILURE; + break; + } + break; + case '\n': + switch (parser.theB) { + case '{': + case '[': + case '(': + case '+': + case '-': + case '!': + case '~': + if (jsmin_action(&parser, JSMIN_ACTION_OUTPUT_NEXT TSRMLS_CC) == FAILURE) { + status = FAILURE; + break; + } + break; + case ' ': + if (jsmin_action(&parser, JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) { + status = FAILURE; + break; + } + break; + default: + if (jsmin_action(&parser, jsmin_isAlphanum(parser.theB) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT_DELETE TSRMLS_CC) == FAILURE) { + status = FAILURE; + break; + } + } + break; + default: + switch (parser.theB) { + case ' ': + if (jsmin_action(&parser, jsmin_isAlphanum(parser.theA) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) { + status = FAILURE; + break; + } + break; + case '\n': + switch (parser.theA) { + case '}': + case ']': + case ')': + case '+': + case '-': + case '"': + case '\'': + case '`': + if (jsmin_action(&parser, JSMIN_ACTION_OUTPUT_NEXT TSRMLS_CC) == FAILURE) { + status = FAILURE; + break; + } + break; + default: + if (jsmin_action(&parser, jsmin_isAlphanum(parser.theA) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) { + status = FAILURE; + break; + } + } + break; + default: + if (jsmin_action(&parser, JSMIN_ACTION_OUTPUT_NEXT TSRMLS_CC) == FAILURE) { + status = FAILURE; + break; + } + break; + } + } } - RETURN_CTOR(sql); -} + if (status == FAILURE) { + smart_str_free(&minified); + return FAILURE; + } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addPrimaryKey){ + smart_str_0(&minified); - zval *table_name, *schema_name, *index; + if (minified.len) { + ZVAL_STRINGL(return_value, minified.c, minified.len, 0); + } else { + ZVAL_STRING(return_value, "", 1); + } - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Adding a primary key after table has been created is not supported by SQLite"); - return; + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropPrimaryKey){ +static int phalcon_jsmin(zval *return_value, zval *script TSRMLS_DC) { - zval *table_name, *schema_name; + zval *error = NULL; - phalcon_fetch_params(0, 2, 0, &table_name, &schema_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Removing a primary key after table has been created is not supported by SQLite"); - return; + ZVAL_NULL(return_value); + + if (Z_TYPE_P(script) != IS_STRING) { + phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Script must be a string"), 1 TSRMLS_CC); + return FAILURE; + } + + if (phalcon_jsmin_internal(return_value, script, &error TSRMLS_CC) == FAILURE){ + if (Z_TYPE_P(error) == IS_STRING) { + phalcon_throw_exception_string(phalcon_assets_exception_ce, Z_STRVAL_P(error), Z_STRLEN_P(error), 1 TSRMLS_CC); + } else { + phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Unknown error"), 1 TSRMLS_CC); + } + return FAILURE; + } + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addForeignKey){ - zval *table_name, *schema_name, *reference; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Adding a foreign key constraint to an existing table is not supported by SQLite"); - return; + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Assets_Filters_None){ + + PHALCON_REGISTER_CLASS(Phalcon\\Assets\\Filters, None, assets_filters_none, phalcon_assets_filters_none_method_entry, 0); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropForeignKey){ +static PHP_METHOD(Phalcon_Assets_Filters_None, filter){ - zval *table_name, *schema_name, *reference_name; + zval *content; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference_name); + phalcon_fetch_params(0, 1, 0, &content); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Dropping a foreign key constraint is not supported by SQLite"); - return; + RETURN_CCTORW(content); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, _getTableOptions){ - zval *definition; - phalcon_fetch_params(0, 1, 0, &definition); - array_init(return_value); -} -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, createTable){ +#ifdef HAVE_CONFIG_H +#endif - zval *table_name, *schema_name, *definition; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &definition); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + + + + + +PHALCON_INIT_CLASS(Phalcon_Assets_Manager){ + + PHALCON_REGISTER_CLASS(Phalcon\\Assets, Manager, assets_manager, phalcon_assets_manager_method_entry, 0); + + zend_declare_property_null(phalcon_assets_manager_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_manager_ce, SL("_collections"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_assets_manager_ce, SL("_implicitOutput"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropTable){ +static PHP_METHOD(Phalcon_Assets_Manager, __construct){ - zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; + zval *options = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); + phalcon_fetch_params(1, 0, 1, &options); - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if (!options) { + PHALCON_INIT_VAR(options); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(table); - PHALCON_CONCAT_VSV(table, schema_name, "\".\"", table_name); - } else { - PHALCON_CPY_WRT(table, table_name); - } - - PHALCON_INIT_VAR(sql); - if (zend_is_true(if_exists)) { - PHALCON_CONCAT_SVS(sql, "DROP TABLE IF EXISTS \"", table, "\""); - } else { - PHALCON_CONCAT_SVS(sql, "DROP TABLE \"", table, "\""); + if (Z_TYPE_P(options) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, createView){ - - zval *view_name, *definition, *schema_name, *view_sql; - zval *view = NULL, *sql; +static PHP_METHOD(Phalcon_Assets_Manager, setOptions){ - PHALCON_MM_GROW(); + zval *options; - phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); + phalcon_fetch_params(0, 1, 0, &options); - if (!phalcon_array_isset_quick_string(definition, SS("sql"), 2090732981UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'sql' is required in the definition array"); + if (Z_TYPE_P(options) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Options must be an array"); return; } + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - PHALCON_OBS_VAR(view_sql); - phalcon_array_fetch_quick_string(&view_sql, definition, SS("sql"), 2090732981UL, PH_NOISY); - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(view); - PHALCON_CONCAT_VSV(view, schema_name, "\".\"", view_name); - } else { - PHALCON_CPY_WRT(view, view_name); - } - - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW \"", view, "\" AS ", view_sql); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Manager, getOptions){ + + + RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); +} + +static PHP_METHOD(Phalcon_Assets_Manager, useImplicitOutput){ + + zval *implicit_output; + + phalcon_fetch_params(0, 1, 0, &implicit_output); - RETURN_CTOR(sql); + phalcon_update_property_this_quick(this_ptr, SL("_implicitOutput"), implicit_output, 3405432336UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropView){ +static PHP_METHOD(Phalcon_Assets_Manager, addCss){ - zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; - zval *sql = NULL; + zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type, *resource; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); + phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if (!local) { + PHALCON_INIT_VAR(local); + ZVAL_BOOL(local, 1); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(view); - PHALCON_CONCAT_VSV(view, schema_name, "\".\"", view_name); - } else { - PHALCON_CPY_WRT(view, view_name); + if (!filter) { + PHALCON_INIT_VAR(filter); + ZVAL_BOOL(filter, 1); } - if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "DROP VIEW IF EXISTS \"", view, "\""); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "DROP VIEW \"", view, "\""); + + if (!attributes) { + PHALCON_INIT_VAR(attributes); } - RETURN_CTOR(sql); + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "css", 1); + + PHALCON_INIT_VAR(resource); + object_init_ex(resource, phalcon_assets_resource_css_ce); + phalcon_call_method_p4_key(NULL, resource, "__construct", path, local, filter, attributes, 1107214344UL); + + phalcon_call_method_p2_key(NULL, this_ptr, "addresourcebytype", type, resource, 1257550035UL); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, tableExists){ +static PHP_METHOD(Phalcon_Assets_Manager, addJs){ - zval *table_name, *schema_name = NULL, *sql; + zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type, *resource; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!local) { + PHALCON_INIT_VAR(local); + ZVAL_BOOL(local, 1); } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM sqlite_master WHERE type='table' AND tbl_name='", table_name, "'"); - RETURN_CTOR(sql); + if (!filter) { + PHALCON_INIT_VAR(filter); + ZVAL_BOOL(filter, 1); + } + + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "js", 1); + + PHALCON_INIT_VAR(resource); + object_init_ex(resource, phalcon_assets_resource_js_ce); + phalcon_call_method_p4_key(NULL, resource, "__construct", path, local, filter, attributes, 1107214344UL); + + phalcon_call_method_p2_key(NULL, this_ptr, "addresourcebytype", type, resource, 1257550035UL); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, viewExists){ +static PHP_METHOD(Phalcon_Assets_Manager, addResourceByType){ - zval *view_name, *schema_name = NULL, *sql; + zval *type, *resource, *collections, *collection = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + phalcon_fetch_params(1, 2, 0, &type, &resource); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + PHALCON_OBS_VAR(collections); + phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC); + if (phalcon_array_isset(collections, type)) { + PHALCON_OBS_VAR(collection); + phalcon_array_fetch(&collection, collections, type, PH_NOISY); + } else { + PHALCON_INIT_NVAR(collection); + object_init_ex(collection, phalcon_assets_collection_ce); + phalcon_update_property_array(this_ptr, SL("_collections"), type, collection TSRMLS_CC); } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM sqlite_master WHERE type='view' AND tbl_name='", view_name, "'"); - RETURN_CTOR(sql); + phalcon_call_method_p1_key(NULL, collection, "add", resource, 2090071694UL); + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeColumns){ +static PHP_METHOD(Phalcon_Assets_Manager, addResource){ - zval *table, *schema = NULL, *sql; + zval *resource, *type; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 1, 0, &resource); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (Z_TYPE_P(resource) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Resource must be an object"); + return; } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "PRAGMA table_info('", table, "')"); - RETURN_CTOR(sql); + PHALCON_INIT_VAR(type); + phalcon_call_method_key(type, resource, "gettype", 4294422375UL); + + phalcon_call_method_p2_key(NULL, this_ptr, "addresourcebytype", type, resource, 1257550035UL); + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, listTables){ - - zval *schema_name = NULL, *sql; +static PHP_METHOD(Phalcon_Assets_Manager, set){ - PHALCON_MM_GROW(); + zval *id, *collection; - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(0, 2, 0, &id, &collection); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (unlikely(Z_TYPE_P(id) != IS_STRING)) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Collection-Id must be a string"); + return; + } + if (unlikely(Z_TYPE_P(collection) != IS_OBJECT)) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Collection must be an object"); + return; } - PHALCON_INIT_VAR(sql); - ZVAL_STRING(sql, "SELECT tbl_name FROM sqlite_master WHERE type = 'table' ORDER BY tbl_name", 1); - RETURN_CTOR(sql); + phalcon_update_property_array(this_ptr, SL("_collections"), id, collection TSRMLS_CC); + + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, listViews){ +static PHP_METHOD(Phalcon_Assets_Manager, get){ - zval *schema_name = NULL, *sql; + zval *id, *collections, *collection; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(1, 1, 0, &id); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (unlikely(Z_TYPE_P(id) != IS_STRING)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Collection-Id must be a string"); + return; } - PHALCON_INIT_VAR(sql); - ZVAL_STRING(sql, "SELECT tbl_name FROM sqlite_master WHERE type = 'view' ORDER BY tbl_name", 1); - RETURN_CTOR(sql); + PHALCON_OBS_VAR(collections); + phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC); + if (!phalcon_array_isset(collections, id)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "The collection does not exist in the manager"); + return; + } + + PHALCON_OBS_VAR(collection); + phalcon_array_fetch(&collection, collections, id, PH_NOISY); + + RETURN_CCTOR(collection); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeIndexes){ +static PHP_METHOD(Phalcon_Assets_Manager, getCss){ - zval *table, *schema = NULL, *sql; + zval *collections, *collection; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); + PHALCON_OBS_VAR(collections); + phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (!phalcon_array_isset_quick_string(collections, SS("css"), 2090160398UL)) { + object_init_ex(return_value, phalcon_assets_collection_ce); + RETURN_MM(); } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "PRAGMA index_list('", table, "')"); - RETURN_CTOR(sql); + PHALCON_OBS_VAR(collection); + phalcon_array_fetch_quick_string(&collection, collections, SS("css"), 2090160398UL, PH_NOISY); + + RETURN_CCTOR(collection); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeIndex){ +static PHP_METHOD(Phalcon_Assets_Manager, getJs){ - zval *index_name, *sql; + zval *collections, *collection; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &index_name); + PHALCON_OBS_VAR(collections); + phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC); - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "PRAGMA index_info('", index_name, "')"); - RETURN_CTOR(sql); + if (!phalcon_array_isset_quick_string(collections, SS("js"), 193496226UL)) { + object_init_ex(return_value, phalcon_assets_collection_ce); + RETURN_MM(); + } + + PHALCON_OBS_VAR(collection); + phalcon_array_fetch_quick_string(&collection, collections, SS("js"), 193496226UL, PH_NOISY); + + RETURN_CCTOR(collection); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeReferences){ +static PHP_METHOD(Phalcon_Assets_Manager, collection){ - zval *table, *schema = NULL, *sql; + zval *name, *collections, *collection = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 1, 0, &name); - if (!schema) { - PHALCON_INIT_VAR(schema); + PHALCON_OBS_VAR(collections); + phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC); + if (phalcon_array_isset(collections, name)) { + PHALCON_OBS_VAR(collection); + phalcon_array_fetch(&collection, collections, name, PH_NOISY); + } else { + PHALCON_INIT_NVAR(collection); + object_init_ex(collection, phalcon_assets_collection_ce); + phalcon_update_property_array(this_ptr, SL("_collections"), name, collection TSRMLS_CC); } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "PRAGMA foreign_key_list('", table, "')"); - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, tableOptions){ - - zval *table, *schema = NULL; - - phalcon_fetch_params(0, 1, 1, &table, &schema); - - RETURN_EMPTY_STRING(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Mysql){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Mysql, db_dialect_mysql, "phalcon\\db\\dialect", phalcon_db_dialect_mysql_method_entry, 0); - - zend_declare_property_string(phalcon_db_dialect_mysql_ce, SL("_escapeChar"), "`", ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_db_dialect_mysql_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); - - return SUCCESS; + RETURN_CCTOR(collection); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, getColumnDefinition){ +static PHP_METHOD(Phalcon_Assets_Manager, output){ - zval *column, *size, *column_type, *column_sql = NULL; - zval *is_unsigned = NULL, *scale = NULL; + zval *collection, *callback, *output, *use_implicit_output; + zval *resources, *filters, *prefix, *source_base_path = NULL; + zval *target_base_path = NULL, *options, *collection_source_path; + zval *complete_source_path = NULL, *collection_target_path; + zval *complete_target_path = NULL, *filtered_joined_content = NULL; + zval *join, *exception_message = NULL, *is_directory; + zval *resource = NULL, *filter_needed = NULL, *local = NULL, *source_path = NULL; + zval *target_path = NULL, *path = NULL, *prefixed_path = NULL, *attributes = NULL; + zval *parameters = NULL, *html = NULL, *content = NULL, *must_filter = NULL; + zval *filter = NULL, *filtered_content = NULL, *target_uri; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &column); + phalcon_fetch_params(1, 2, 0, &collection, &callback); - if (Z_TYPE_P(column) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column definition must be an object compatible with Phalcon\\Db\\ColumnInterface"); - return; - } + PHALCON_INIT_VAR(output); - PHALCON_INIT_VAR(size); - phalcon_call_method_key(size, column, "getsize", 4292672352UL); + PHALCON_OBS_VAR(use_implicit_output); + phalcon_read_property_this_quick(&use_implicit_output, this_ptr, SL("_implicitOutput"), 3405432336UL, PH_NOISY_CC); - PHALCON_INIT_VAR(column_type); - phalcon_call_method_key(column_type, column, "gettype", 4294422375UL); + PHALCON_INIT_VAR(resources); + phalcon_call_method_key(resources, collection, "getresources", 2001784992UL); - switch (phalcon_get_intval(column_type)) { + PHALCON_INIT_VAR(filters); + phalcon_call_method_key(filters, collection, "getfilters", 2910616766UL); - case 0: - PHALCON_INIT_VAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "INT(", size, ")"); + PHALCON_INIT_VAR(prefix); + phalcon_call_method_key(prefix, collection, "getprefix", 2543805107UL); - PHALCON_INIT_VAR(is_unsigned); - phalcon_call_method_key(is_unsigned, column, "isunsigned", 3241495646UL); - if (zend_is_true(is_unsigned)) { - phalcon_concat_self_str(&column_sql, SL(" UNSIGNED") TSRMLS_CC); - } + if (Z_TYPE_P(filters) == IS_ARRAY) { - break; + PHALCON_INIT_VAR(source_base_path); - case 1: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "DATE", 1); - break; + PHALCON_INIT_VAR(target_base_path); - case 2: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "VARCHAR(", size, ")"); - break; + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - case 3: - PHALCON_INIT_VAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + if (Z_TYPE_P(options) == IS_ARRAY) { - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVSVS(column_sql, "DECIMAL(", size, ",", scale, ")"); + if (phalcon_array_isset_quick_string(options, SS("sourceBasePath"), 4090541534UL)) { + PHALCON_OBS_NVAR(source_base_path); + phalcon_array_fetch_quick_string(&source_base_path, options, SS("sourceBasePath"), 4090541534UL, PH_NOISY); + } - PHALCON_INIT_NVAR(is_unsigned); - phalcon_call_method_key(is_unsigned, column, "isunsigned", 3241495646UL); - if (zend_is_true(is_unsigned)) { - phalcon_concat_self_str(&column_sql, SL(" UNSIGNED") TSRMLS_CC); + if (phalcon_array_isset_quick_string(options, SS("targetBasePath"), 2556086420UL)) { + PHALCON_OBS_NVAR(target_base_path); + phalcon_array_fetch_quick_string(&target_base_path, options, SS("targetBasePath"), 2556086420UL, PH_NOISY); } + } - break; + PHALCON_INIT_VAR(collection_source_path); + phalcon_call_method_key(collection_source_path, collection, "getsourcepath", 904752835UL); - case 4: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "DATETIME", 1); - break; + if (PHALCON_IS_NOT_EMPTY(collection_source_path)) { + PHALCON_INIT_VAR(complete_source_path); + PHALCON_CONCAT_VV(complete_source_path, source_base_path, collection_source_path); + } else { + PHALCON_CPY_WRT(complete_source_path, source_base_path); + } - case 5: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "CHAR(", size, ")"); - break; + PHALCON_INIT_VAR(collection_target_path); + phalcon_call_method_key(collection_target_path, collection, "gettargetpath", 3143538297UL); - case 6: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TEXT", 1); - break; + if (PHALCON_IS_NOT_EMPTY(collection_target_path)) { + PHALCON_INIT_VAR(complete_target_path); + PHALCON_CONCAT_VV(complete_target_path, target_base_path, collection_target_path); + } else { + PHALCON_CPY_WRT(complete_target_path, target_base_path); + } - case 7: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "FLOAT", 1); + PHALCON_INIT_VAR(filtered_joined_content); - PHALCON_INIT_NVAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); - if (zend_is_true(size)) { - PHALCON_SCONCAT_SV(column_sql, "(", size); - if (zend_is_true(scale)) { - PHALCON_SCONCAT_SVS(column_sql, ",", scale, ")"); - } else { - phalcon_concat_self_str(&column_sql, SL(")") TSRMLS_CC); - } - } + PHALCON_INIT_VAR(join); + phalcon_call_method_key(join, collection, "getjoin", 4282196469UL); - PHALCON_INIT_NVAR(is_unsigned); - phalcon_call_method_key(is_unsigned, column, "isunsigned", 3241495646UL); - if (zend_is_true(is_unsigned)) { - phalcon_concat_self_str(&column_sql, SL(" UNSIGNED") TSRMLS_CC); + if (zend_is_true(join)) { + + if (PHALCON_IS_EMPTY(complete_target_path)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Path '", complete_target_path, "' is not a valid target path (1)"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; } - break; + PHALCON_INIT_VAR(is_directory); + phalcon_call_func_p1(is_directory, "is_dir", complete_target_path); - case 8: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TINYINT(1)", 1); - break; + if (PHALCON_IS_TRUE(is_directory)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Path '", complete_target_path, "' is not a valid target path (2)"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; + } + } + } - default: - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized MySQL data type"); - return; + phalcon_is_iterable(resources, &ah0, &hp0, 0, 0); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - RETURN_CTOR(column_sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addColumn){ - - zval *table_name, *schema_name, *column, *sql = NULL, *name; - zval *column_definition, *is_not_null, *is_first; - zval *after_position; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); + PHALCON_GET_HVALUE(resource); - if (Z_TYPE_P(column) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column parameter must be an instance of Phalcon\\Db\\Column"); - return; - } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD "); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD "); - } + PHALCON_INIT_NVAR(filter_needed); + ZVAL_BOOL(filter_needed, 0); - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, column, "getname", 4286441094UL); + PHALCON_INIT_NVAR(local); + phalcon_call_method_key(local, resource, "getlocal", 3951574576UL); - PHALCON_INIT_VAR(column_definition); - phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); - PHALCON_SCONCAT_SVSV(sql, "`", name, "` ", column_definition); + if (Z_TYPE_P(filters) == IS_ARRAY) { + if (zend_is_true(join)) { + if (zend_is_true(local)) { - PHALCON_INIT_VAR(is_not_null); - phalcon_call_method_key(is_not_null, column, "isnotnull", 760409005UL); - if (zend_is_true(is_not_null)) { - phalcon_concat_self_str(&sql, SL(" NOT NULL") TSRMLS_CC); - } + PHALCON_INIT_NVAR(source_path); + phalcon_call_method_p1_key(source_path, resource, "getrealsourcepath", complete_source_path, 1163474055UL); - PHALCON_INIT_VAR(is_first); - phalcon_call_method_key(is_first, column, "isfirst", 3971456361UL); - if (zend_is_true(is_first)) { - phalcon_concat_self_str(&sql, SL(" FIRST") TSRMLS_CC); - } else { - PHALCON_INIT_VAR(after_position); - phalcon_call_method_key(after_position, column, "getafterposition", 4273952076UL); - if (zend_is_true(after_position)) { - PHALCON_SCONCAT_SV(sql, " AFTER ", after_position); - } - } + if (!zend_is_true(source_path)) { + PHALCON_INIT_NVAR(source_path); + phalcon_call_method_key(source_path, resource, "getpath", 4288820658UL); - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, modifyColumn){ - - zval *table_name, *schema_name, *column, *sql = NULL, *name; - zval *column_definition, *is_not_null; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); + 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 { + PHALCON_INIT_NVAR(source_path); + phalcon_call_method_key(source_path, resource, "getpath", 4288820658UL); - if (Z_TYPE_P(column) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column parameter must be an instance of Phalcon\\Db\\Column"); - return; - } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` MODIFY "); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` MODIFY "); - } + PHALCON_INIT_NVAR(filter_needed); + ZVAL_BOOL(filter_needed, 1); + } - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, column, "getname", 4286441094UL); + PHALCON_INIT_NVAR(target_path); + phalcon_call_method_p1_key(target_path, resource, "getrealtargetpath", complete_target_path, 3402259517UL); - PHALCON_INIT_VAR(column_definition); - phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); - PHALCON_SCONCAT_SVSV(sql, "`", name, "` ", column_definition); + 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; + } - PHALCON_INIT_VAR(is_not_null); - phalcon_call_method_key(is_not_null, column, "isnotnull", 760409005UL); - if (zend_is_true(is_not_null)) { - phalcon_concat_self_str(&sql, SL(" NOT NULL") TSRMLS_CC); - } + if (zend_is_true(local)) { - RETURN_CTOR(sql); + 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_BOOL(filter_needed, 1); + } + } else { + PHALCON_INIT_NVAR(filter_needed); + ZVAL_BOOL(filter_needed, 1); + } + } + } + } + + if (Z_TYPE_P(filters) != IS_ARRAY) { + + PHALCON_INIT_NVAR(path); + phalcon_call_method_key(path, resource, "getrealtargeturi", 4137962752UL); + if (Z_TYPE_P(prefix) != IS_NULL) { + PHALCON_INIT_NVAR(prefixed_path); + PHALCON_CONCAT_VV(prefixed_path, prefix, path); + } else { + PHALCON_CPY_WRT(prefixed_path, path); + } + + PHALCON_INIT_NVAR(attributes); + phalcon_call_method_key(attributes, resource, "getattributes", 1013165772UL); + + if (Z_TYPE_P(attributes) == IS_ARRAY) { + phalcon_array_update_long(&attributes, 0, &prefixed_path, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 2); + phalcon_array_append(¶meters, attributes, PH_SEPARATE); + phalcon_array_append(¶meters, local, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 2); + phalcon_array_append(¶meters, prefixed_path, PH_SEPARATE); + phalcon_array_append(¶meters, local, PH_SEPARATE); + } + + PHALCON_INIT_NVAR(html); + PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters); + + if (zend_is_true(use_implicit_output)) { + zend_print_zval(html, 0); + } else { + phalcon_concat_self(&output, html TSRMLS_CC); + } + + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + + if (zend_is_true(filter_needed)) { + + PHALCON_INIT_NVAR(content); + phalcon_call_method_p1_key(content, resource, "getcontent", complete_source_path, 3141446400UL); + + PHALCON_INIT_NVAR(must_filter); + phalcon_call_method_key(must_filter, resource, "getfilter", 2170608779UL); + + if (zend_is_true(must_filter)) { + + phalcon_is_iterable(filters, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(filter); + + if (Z_TYPE_P(filter) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Filter is invalid"); + return; + } + + PHALCON_INIT_NVAR(filtered_content); + phalcon_call_method_p1_key(filtered_content, filter, "filter", content, 2890214155UL); + + if (zend_is_true(join)) { + if (Z_TYPE_P(filtered_joined_content) == IS_NULL) { + PHALCON_INIT_NVAR(filtered_joined_content); + PHALCON_CONCAT_VS(filtered_joined_content, filtered_content, ";"); + } else { + PHALCON_SCONCAT_VS(filtered_joined_content, filtered_content, ";"); + } + } + + zend_hash_move_forward_ex(ah1, &hp1); + } + + } else { + if (zend_is_true(join)) { + if (Z_TYPE_P(filtered_joined_content) == IS_NULL) { + PHALCON_CPY_WRT(filtered_joined_content, content); + } else { + phalcon_concat_self(&filtered_joined_content, content TSRMLS_CC); + } + } else { + PHALCON_CPY_WRT(filtered_content, content); + } + } + + if (!zend_is_true(join)) { + phalcon_file_put_contents(NULL, target_path, filtered_content TSRMLS_CC); + } + } + + if (!zend_is_true(join)) { + + PHALCON_INIT_NVAR(path); + phalcon_call_method_key(path, resource, "getrealtargeturi", 4137962752UL); + if (Z_TYPE_P(prefix) != IS_NULL) { + PHALCON_INIT_NVAR(prefixed_path); + PHALCON_CONCAT_VV(prefixed_path, prefix, path); + } else { + PHALCON_CPY_WRT(prefixed_path, path); + } + + PHALCON_INIT_NVAR(attributes); + phalcon_call_method_key(attributes, resource, "getattributes", 1013165772UL); + + PHALCON_INIT_NVAR(local); + ZVAL_BOOL(local, 1); + + if (Z_TYPE_P(attributes) == IS_ARRAY) { + phalcon_array_update_long(&attributes, 0, &prefixed_path, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 2); + phalcon_array_append(¶meters, attributes, PH_SEPARATE); + phalcon_array_append(¶meters, local, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 2); + phalcon_array_append(¶meters, prefixed_path, PH_SEPARATE); + phalcon_array_append(¶meters, local, PH_SEPARATE); + } + + PHALCON_INIT_NVAR(html); + PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters); + + if (zend_is_true(use_implicit_output)) { + zend_print_zval(html, 0); + } else { + phalcon_concat_self(&output, html TSRMLS_CC); + } + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + if (Z_TYPE_P(filters) == IS_ARRAY) { + if (zend_is_true(join)) { + + phalcon_file_put_contents(NULL, complete_target_path, filtered_joined_content TSRMLS_CC); + + PHALCON_INIT_VAR(target_uri); + phalcon_call_method_key(target_uri, collection, "gettargeturi", 876359612UL); + if (Z_TYPE_P(prefix) != IS_NULL) { + PHALCON_INIT_NVAR(prefixed_path); + PHALCON_CONCAT_VV(prefixed_path, prefix, target_uri); + } else { + PHALCON_CPY_WRT(prefixed_path, target_uri); + } + + PHALCON_INIT_NVAR(attributes); + phalcon_call_method_key(attributes, collection, "getattributes", 1013165772UL); + + PHALCON_INIT_NVAR(local); + ZVAL_BOOL(local, 1); + + if (Z_TYPE_P(attributes) == IS_ARRAY) { + phalcon_array_update_long(&attributes, 0, &prefixed_path, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 2); + phalcon_array_append(¶meters, attributes, PH_SEPARATE); + phalcon_array_append(¶meters, local, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 2); + phalcon_array_append(¶meters, prefixed_path, PH_SEPARATE); + phalcon_array_append(¶meters, local, PH_SEPARATE); + } + + PHALCON_INIT_NVAR(html); + PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters); + + if (zend_is_true(use_implicit_output)) { + zend_print_zval(html, 0); + } else { + phalcon_concat_self(&output, html TSRMLS_CC); + } + } + } + + RETURN_CCTOR(output); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropColumn){ +static PHP_METHOD(Phalcon_Assets_Manager, outputCss){ - zval *table_name, *schema_name, *column_name; - zval *sql = NULL; + zval *collection_name = NULL, *collection = NULL, *callback; + zval *output; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column_name); + phalcon_fetch_params(1, 0, 1, &collection_name); - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` DROP COLUMN "); + if (!collection_name) { + PHALCON_INIT_VAR(collection_name); + } + + if (PHALCON_IS_EMPTY(collection_name)) { + PHALCON_INIT_VAR(collection); + phalcon_call_method_key(collection, this_ptr, "getcss", 4034032270UL); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` DROP COLUMN "); + PHALCON_INIT_NVAR(collection); + phalcon_call_method_p1_key(collection, this_ptr, "get", collection_name, 2090288933UL); } - PHALCON_SCONCAT_SVS(sql, "`", column_name, "`"); - RETURN_CTOR(sql); + PHALCON_INIT_VAR(callback); + array_init_size(callback, 2); + add_next_index_stringl(callback, SL("Phalcon\\Tag"), 1); + add_next_index_stringl(callback, SL("stylesheetLink"), 1); + + PHALCON_INIT_VAR(output); + phalcon_call_method_p2_key(output, this_ptr, "output", collection, callback, 2107509814UL); + + RETURN_CCTOR(output); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addIndex){ +static PHP_METHOD(Phalcon_Assets_Manager, outputJs){ - zval *table_name, *schema_name, *index, *sql = NULL, *columns; - zval *quoted_column_list, *name; + zval *collection_name = NULL, *collection = NULL, *callback; + zval *output; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); + phalcon_fetch_params(1, 0, 1, &collection_name); - if (Z_TYPE_P(index) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Index parameter must be an instance of Phalcon\\Db\\Index"); - return; + if (!collection_name) { + PHALCON_INIT_VAR(collection_name); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD INDEX "); + + if (PHALCON_IS_EMPTY(collection_name)) { + PHALCON_INIT_VAR(collection); + phalcon_call_method_key(collection, this_ptr, "getjs", 4287067682UL); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD INDEX "); + PHALCON_INIT_NVAR(collection); + phalcon_call_method_p1_key(collection, this_ptr, "get", collection_name, 2090288933UL); } - PHALCON_INIT_VAR(columns); - phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); - - PHALCON_INIT_VAR(quoted_column_list); - phalcon_call_method_p1_key(quoted_column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); + PHALCON_INIT_VAR(callback); + array_init_size(callback, 2); + add_next_index_stringl(callback, SL("Phalcon\\Tag"), 1); + add_next_index_stringl(callback, SL("javascriptInclude"), 1); - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, index, "getname", 4286441094UL); - PHALCON_SCONCAT_SVSVS(sql, "`", name, "` (", quoted_column_list, ")"); + PHALCON_INIT_VAR(output); + phalcon_call_method_p2_key(output, this_ptr, "output", collection, callback, 2107509814UL); - RETURN_CTOR(sql); + RETURN_CCTOR(output); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropIndex){ - zval *table_name, *schema_name, *index_name; - zval *sql = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index_name); - - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` DROP INDEX "); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` DROP INDEX "); - } - PHALCON_SCONCAT_SVS(sql, "`", index_name, "`"); - - RETURN_CTOR(sql); + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Assets_Resource_Css){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Assets\\Resource, Css, assets_resource_css, "phalcon\\assets\\resource", phalcon_assets_resource_css_method_entry, 0); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addPrimaryKey){ +static PHP_METHOD(Phalcon_Assets_Resource_Css, __construct){ - zval *table_name, *schema_name, *index, *sql = NULL, *columns; - zval *column_list; + zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type; + zval *p0[] = { NULL, NULL, NULL, NULL, NULL }; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); + phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); - if (Z_TYPE_P(index) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Index parameter must be an instance of Phalcon\\Db\\Index"); - return; + if (!local) { + PHALCON_INIT_VAR(local); + ZVAL_BOOL(local, 1); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD PRIMARY KEY "); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD PRIMARY KEY "); + + if (!filter) { + PHALCON_INIT_VAR(filter); + ZVAL_BOOL(filter, 1); } - PHALCON_INIT_VAR(columns); - phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - PHALCON_INIT_VAR(column_list); - phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); - PHALCON_SCONCAT_SVS(sql, "(", column_list, ")"); + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "css", 1); - RETURN_CTOR(sql); + p0[0] = type; + p0[1] = path; + p0[2] = local; + p0[3] = filter; + p0[4] = attributes; + PHALCON_CALL_PARENT_PARAMS_NORETURN(this_ptr, "Phalcon\\Assets\\Resource\\Css", "__construct", 5, p0); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropPrimaryKey){ - zval *table_name, *schema_name, *sql = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &table_name, &schema_name); - - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` DROP PRIMARY KEY"); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` DROP PRIMARY KEY"); - } - - RETURN_CTOR(sql); + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Assets_Resource_Js){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Assets\\Resource, Js, assets_resource_js, "phalcon\\assets\\resource", phalcon_assets_resource_js_method_entry, 0); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addForeignKey){ +static PHP_METHOD(Phalcon_Assets_Resource_Js, __construct){ - zval *table_name, *schema_name, *reference, *sql = NULL; - zval *columns, *quoted_column_list, *reference_name; - zval *referenced_schema, *referenced_columns; - zval *quoted_columns, *referenced_table; + zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type; + zval *p0[] = { NULL, NULL, NULL, NULL, NULL }; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference); + phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); - if (Z_TYPE_P(reference) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Reference parameter must be an instance of Phalcon\\Db\\Reference"); - return; - } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD FOREIGN KEY "); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD FOREIGN KEY "); + if (!local) { + PHALCON_INIT_VAR(local); + ZVAL_BOOL(local, 1); } - PHALCON_INIT_VAR(columns); - phalcon_call_method_key(columns, reference, "getcolumns", 3064648998UL); - - PHALCON_INIT_VAR(quoted_column_list); - phalcon_call_method_p1_key(quoted_column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); - - PHALCON_INIT_VAR(reference_name); - phalcon_call_method_key(reference_name, reference, "getname", 4286441094UL); - PHALCON_SCONCAT_SVSVS(sql, "`", reference_name, "`(", quoted_column_list, ") REFERENCES "); - - PHALCON_INIT_VAR(referenced_schema); - phalcon_call_method_key(referenced_schema, reference, "getreferencedschema", 1586168905UL); - if (zend_is_true(referenced_schema)) { - PHALCON_SCONCAT_SVS(sql, "`", referenced_schema, "`."); + if (!filter) { + PHALCON_INIT_VAR(filter); + ZVAL_BOOL(filter, 1); } - PHALCON_INIT_VAR(referenced_columns); - phalcon_call_method_key(referenced_columns, reference, "getreferencedcolumns", 301959449UL); + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - PHALCON_INIT_VAR(quoted_columns); - phalcon_call_method_p1_key(quoted_columns, this_ptr, "getcolumnlist", referenced_columns, 2735238095UL); + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "js", 1); - PHALCON_INIT_VAR(referenced_table); - phalcon_call_method_key(referenced_table, reference, "getreferencedtable", 735373536UL); - PHALCON_SCONCAT_SVSVS(sql, "`", referenced_table, "`(", quoted_columns, ")"); + p0[0] = type; + p0[1] = path; + p0[2] = local; + p0[3] = filter; + p0[4] = attributes; + PHALCON_CALL_PARENT_PARAMS_NORETURN(this_ptr, "Phalcon\\Assets\\Resource\\Js", "__construct", 5, p0); - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropForeignKey){ - zval *table_name, *schema_name, *reference_name; - zval *sql = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference_name); - - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` DROP FOREIGN KEY "); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` DROP FOREIGN KEY "); - } - PHALCON_SCONCAT_SVS(sql, "`", reference_name, "`"); - - RETURN_CTOR(sql); + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Assets_Resource){ + + PHALCON_REGISTER_CLASS(Phalcon\\Assets, Resource, assets_resource, phalcon_assets_resource_method_entry, 0); + + zend_declare_property_null(phalcon_assets_resource_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_resource_ce, SL("_path"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_resource_ce, SL("_local"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_resource_ce, SL("_filter"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_resource_ce, SL("_attributes"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_resource_ce, SL("_sourcePath"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_resource_ce, SL("_targetPath"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_assets_resource_ce, SL("_targetUri"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, _getTableOptions){ +static PHP_METHOD(Phalcon_Assets_Resource, __construct){ - zval *definition, *table_options, *options, *engine; - zval *sql_engine, *auto_increment, *sql_autoincrement; - zval *table_collation, *collation_parts, *first_part; - zval *sql_charset, *sql_collate, *sql_table_options; + zval *type, *path, *local = NULL, *filter = NULL, *attributes = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &definition); + phalcon_fetch_params(1, 2, 3, &type, &path, &local, &filter, &attributes); - if (phalcon_array_isset_quick_string(definition, SS("options"), 2952422065UL)) { + if (!local) { + PHALCON_INIT_VAR(local); + ZVAL_BOOL(local, 1); + } - PHALCON_INIT_VAR(table_options); - array_init(table_options); + if (!filter) { + PHALCON_INIT_VAR(filter); + ZVAL_BOOL(filter, 1); + } - PHALCON_OBS_VAR(options); - phalcon_array_fetch_quick_string(&options, definition, SS("options"), 2952422065UL, PH_NOISY); + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - if (phalcon_array_isset_quick_string(options, SS("ENGINE"), 2119337627UL)) { + phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_path"), path, 3986357393UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_local"), local, 2560221423UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); + if (Z_TYPE_P(attributes) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC); + } - PHALCON_OBS_VAR(engine); - phalcon_array_fetch_quick_string(&engine, options, SS("ENGINE"), 2119337627UL, PH_NOISY); - if (zend_is_true(engine)) { - PHALCON_INIT_VAR(sql_engine); - PHALCON_CONCAT_SV(sql_engine, "ENGINE=", engine); - phalcon_array_append(&table_options, sql_engine, PH_SEPARATE); - } - } + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Assets_Resource, setType){ + + zval *type; + + phalcon_fetch_params(0, 1, 0, &type); - if (phalcon_array_isset_quick_string(options, SS("AUTO_INCREMENT"), 656925090UL)) { + phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Resource, getType){ + + + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); +} + +static PHP_METHOD(Phalcon_Assets_Resource, setPath){ + + zval *path; + + phalcon_fetch_params(0, 1, 0, &path); - PHALCON_OBS_VAR(auto_increment); - phalcon_array_fetch_quick_string(&auto_increment, options, SS("AUTO_INCREMENT"), 656925090UL, PH_NOISY); - if (zend_is_true(auto_increment)) { - PHALCON_INIT_VAR(sql_autoincrement); - PHALCON_CONCAT_SV(sql_autoincrement, "AUTO_INCREMENT=", auto_increment); - phalcon_array_append(&table_options, sql_autoincrement, PH_SEPARATE); - } - } + phalcon_update_property_this_quick(this_ptr, SL("_path"), path, 3986357393UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Resource, getPath){ + + + RETURN_MEMBER_QUICK(this_ptr, "_path", 3986357393UL); +} + +static PHP_METHOD(Phalcon_Assets_Resource, setLocal){ + + zval *local; + + phalcon_fetch_params(0, 1, 0, &local); - if (phalcon_array_isset_quick_string(options, SS("TABLE_COLLATION"), 1457306353UL)) { + phalcon_update_property_this_quick(this_ptr, SL("_local"), local, 2560221423UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Resource, getLocal){ + + + RETURN_MEMBER_QUICK(this_ptr, "_local", 2560221423UL); +} + +static PHP_METHOD(Phalcon_Assets_Resource, setFilter){ + + zval *filter; + + phalcon_fetch_params(0, 1, 0, &filter); - PHALCON_OBS_VAR(table_collation); - phalcon_array_fetch_quick_string(&table_collation, options, SS("TABLE_COLLATION"), 1457306353UL, PH_NOISY); - if (zend_is_true(table_collation)) { - PHALCON_INIT_VAR(collation_parts); - phalcon_fast_explode_str(collation_parts, SL("_"), table_collation); + phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Resource, getFilter){ + + + RETURN_MEMBER_QUICK(this_ptr, "_filter", 3500594986UL); +} + +static PHP_METHOD(Phalcon_Assets_Resource, setAttributes){ + + zval *attributes; + + phalcon_fetch_params(0, 1, 0, &attributes); - PHALCON_OBS_VAR(first_part); - phalcon_array_fetch_long(&first_part, collation_parts, 0, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Resource, getAttributes){ + + + RETURN_MEMBER_QUICK(this_ptr, "_attributes", 1565778155UL); +} + +static PHP_METHOD(Phalcon_Assets_Resource, setTargetUri){ + + zval *target_uri; + + phalcon_fetch_params(0, 1, 0, &target_uri); - PHALCON_INIT_VAR(sql_charset); - PHALCON_CONCAT_SV(sql_charset, "DEFAULT CHARSET=", first_part); - phalcon_array_append(&table_options, sql_charset, PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_targetUri"), target_uri, 2193460699UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Resource, getTargetUri){ + + + RETURN_MEMBER_QUICK(this_ptr, "_targetUri", 2193460699UL); +} + +static PHP_METHOD(Phalcon_Assets_Resource, setSourcePath){ + + zval *source_path; + + phalcon_fetch_params(0, 1, 0, &source_path); - PHALCON_INIT_VAR(sql_collate); - PHALCON_CONCAT_SV(sql_collate, "COLLATE=", table_collation); - phalcon_array_append(&table_options, sql_collate, PH_SEPARATE); - } - } + phalcon_update_property_this_quick(this_ptr, SL("_sourcePath"), source_path, 1419415746UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Assets_Resource, getSourcePath){ + + + RETURN_MEMBER_QUICK(this_ptr, "_targetPath", 3658201208UL); +} + +static PHP_METHOD(Phalcon_Assets_Resource, setTargetPath){ + + zval *target_path; + + phalcon_fetch_params(0, 1, 0, &target_path); - if (phalcon_fast_count_ev(table_options TSRMLS_CC)) { - PHALCON_INIT_VAR(sql_table_options); - phalcon_fast_join_str(sql_table_options, SL(" "), table_options TSRMLS_CC); - RETURN_CTOR(sql_table_options); - } - } - RETURN_MM_NULL(); + phalcon_update_property_this_quick(this_ptr, SL("_targetPath"), target_path, 3658201208UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, createTable){ +static PHP_METHOD(Phalcon_Assets_Resource, getTargetPath){ - zval *table_name, *schema_name, *definition; - zval *table = NULL, *temporary = NULL, *options = NULL, *sql = NULL, *create_lines; - zval *columns = NULL, *column = NULL, *column_name = NULL, *column_definition = NULL; - zval *column_line = NULL, *attribute = NULL, *indexes, *index = NULL; - zval *index_name = NULL, *column_list = NULL, *index_sql = NULL, *references; - zval *reference = NULL, *name = NULL, *referenced_table = NULL, *referenced_columns = NULL; - zval *constaint_sql = NULL, *reference_sql = NULL, *joined_lines; - HashTable *ah0, *ah1, *ah2; - HashPosition hp0, hp1, hp2; - zval **hd; + + RETURN_MEMBER_QUICK(this_ptr, "_sourcePath", 1419415746UL); +} + +static PHP_METHOD(Phalcon_Assets_Resource, getContent){ + + zval *base_path = NULL, *source_path = NULL, *complete_path; + zval *local, *exception_message = NULL, *content; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &definition); - - if (!phalcon_array_isset_quick_string(definition, SS("columns"), 1041822630UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'columns' is required in the definition array"); - return; - } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(table); - PHALCON_CONCAT_SVSVS(table, "`", schema_name, "`.`", table_name, "`"); - } else { - PHALCON_INIT_NVAR(table); - PHALCON_CONCAT_SVS(table, "`", table_name, "`"); - } - - PHALCON_INIT_VAR(temporary); - ZVAL_BOOL(temporary, 0); - if (phalcon_array_isset_quick_string(definition, SS("options"), 2952422065UL)) { - - PHALCON_OBS_VAR(options); - phalcon_array_fetch_quick_string(&options, definition, SS("options"), 2952422065UL, PH_NOISY); - if (phalcon_array_isset_quick_string(options, SS("temporary"), 1346706536UL)) { - PHALCON_OBS_NVAR(temporary); - phalcon_array_fetch_quick_string(&temporary, options, SS("temporary"), 1346706536UL, PH_NOISY); - } - } - - if (zend_is_true(temporary)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "CREATE TEMPORARY TABLE ", table, " (\n\t"); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "CREATE TABLE ", table, " (\n\t"); - } - - PHALCON_INIT_VAR(create_lines); - array_init(create_lines); - - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); - - phalcon_is_iterable(columns, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(column); - - PHALCON_INIT_NVAR(column_name); - phalcon_call_method_key(column_name, column, "getname", 4286441094UL); - - PHALCON_INIT_NVAR(column_definition); - phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); - - PHALCON_INIT_NVAR(column_line); - PHALCON_CONCAT_SVSV(column_line, "`", column_name, "` ", column_definition); - - PHALCON_INIT_NVAR(attribute); - phalcon_call_method_key(attribute, column, "isnotnull", 760409005UL); - if (zend_is_true(attribute)) { - phalcon_concat_self_str(&column_line, SL(" NOT NULL") TSRMLS_CC); - } - - PHALCON_INIT_NVAR(attribute); - phalcon_call_method_key(attribute, column, "isautoincrement", 572890271UL); - if (zend_is_true(attribute)) { - phalcon_concat_self_str(&column_line, SL(" AUTO_INCREMENT") TSRMLS_CC); - } - - PHALCON_INIT_NVAR(attribute); - phalcon_call_method_key(attribute, column, "isprimary", 3539965925UL); - if (zend_is_true(attribute)) { - phalcon_concat_self_str(&column_line, SL(" PRIMARY KEY") TSRMLS_CC); - } - - phalcon_array_append(&create_lines, column_line, PH_SEPARATE); + phalcon_fetch_params(1, 0, 1, &base_path); - zend_hash_move_forward_ex(ah0, &hp0); + if (!base_path) { + PHALCON_INIT_VAR(base_path); } - if (phalcon_array_isset_quick_string(definition, SS("indexes"), 1726269685UL)) { - - PHALCON_OBS_VAR(indexes); - phalcon_array_fetch_quick_string(&indexes, definition, SS("indexes"), 1726269685UL, PH_NOISY); - - phalcon_is_iterable(indexes, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(index); - - PHALCON_INIT_NVAR(index_name); - phalcon_call_method_key(index_name, index, "getname", 4286441094UL); - - PHALCON_INIT_NVAR(columns); - phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); - - PHALCON_INIT_NVAR(column_list); - phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); - - if (PHALCON_IS_STRING(index_name, "PRIMARY")) { - PHALCON_INIT_NVAR(index_sql); - PHALCON_CONCAT_SVS(index_sql, "PRIMARY KEY (", column_list, ")"); - } else { - PHALCON_INIT_NVAR(index_sql); - PHALCON_CONCAT_SVSVS(index_sql, "KEY `", index_name, "` (", column_list, ")"); - } - - phalcon_array_append(&create_lines, index_sql, PH_SEPARATE); - - zend_hash_move_forward_ex(ah1, &hp1); - } - + PHALCON_OBS_VAR(source_path); + phalcon_read_property_this_quick(&source_path, this_ptr, SL("_sourcePath"), 1419415746UL, PH_NOISY_CC); + if (PHALCON_IS_EMPTY(source_path)) { + PHALCON_OBS_NVAR(source_path); + phalcon_read_property_this_quick(&source_path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); } - if (phalcon_array_isset_quick_string(definition, SS("references"), 3245500135UL)) { - - PHALCON_OBS_VAR(references); - phalcon_array_fetch_quick_string(&references, definition, SS("references"), 3245500135UL, PH_NOISY); - - phalcon_is_iterable(references, &ah2, &hp2, 0, 0); - - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - - PHALCON_GET_HVALUE(reference); - - PHALCON_INIT_NVAR(name); - phalcon_call_method_key(name, reference, "getname", 4286441094UL); - - PHALCON_INIT_NVAR(columns); - phalcon_call_method_key(columns, reference, "getcolumns", 3064648998UL); - - PHALCON_INIT_NVAR(column_list); - phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); - - PHALCON_INIT_NVAR(referenced_table); - phalcon_call_method_key(referenced_table, reference, "getreferencedtable", 735373536UL); - - PHALCON_INIT_NVAR(referenced_columns); - phalcon_call_method_key(referenced_columns, reference, "getreferencedcolumns", 301959449UL); - - PHALCON_INIT_NVAR(column_list); - phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", referenced_columns, 2735238095UL); + PHALCON_INIT_VAR(complete_path); + PHALCON_CONCAT_VV(complete_path, base_path, source_path); - PHALCON_INIT_NVAR(constaint_sql); - PHALCON_CONCAT_SVSVS(constaint_sql, "CONSTRAINT `", name, "` FOREIGN KEY (", column_list, ")"); + PHALCON_OBS_VAR(local); + phalcon_read_property_this_quick(&local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(reference_sql); - PHALCON_CONCAT_VSVSVS(reference_sql, constaint_sql, " REFERENCES `", referenced_table, "`(", column_list, ")"); - phalcon_array_append(&create_lines, reference_sql, PH_SEPARATE); + if (zend_is_true(local)) { - zend_hash_move_forward_ex(ah2, &hp2); + if (phalcon_file_exists(complete_path TSRMLS_CC) == FAILURE) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource's content for \"", complete_path, "\" cannot be loaded"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; } - } - PHALCON_INIT_VAR(joined_lines); - phalcon_fast_join_str(joined_lines, SL(",\n\t"), create_lines TSRMLS_CC); - PHALCON_SCONCAT_VS(sql, joined_lines, "\n)"); - if (phalcon_array_isset_quick_string(definition, SS("options"), 2952422065UL)) { - PHALCON_INIT_NVAR(options); - phalcon_call_method_p1_key(options, this_ptr, "_gettableoptions", definition, 2455363768UL); - PHALCON_SCONCAT_SV(sql, " ", options); + PHALCON_INIT_VAR(content); + phalcon_file_get_contents(content, complete_path TSRMLS_CC); + if (PHALCON_IS_FALSE(content)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Resource's content for \"", complete_path, "\" cannot be read"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); + return; } - RETURN_CTOR(sql); + RETURN_CCTOR(content); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropTable){ +static PHP_METHOD(Phalcon_Assets_Resource, getRealTargetUri){ - zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; + zval *target_uri = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); - - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); - } - - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(table); - PHALCON_CONCAT_SVSVS(table, "`", schema_name, "`.`", table_name, "`"); - } else { - PHALCON_INIT_NVAR(table); - PHALCON_CONCAT_SVS(table, "`", table_name, "`"); - } - if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SV(sql, "DROP TABLE IF EXISTS ", table); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DROP TABLE ", table); + PHALCON_OBS_VAR(target_uri); + phalcon_read_property_this_quick(&target_uri, this_ptr, SL("_targetUri"), 2193460699UL, PH_NOISY_CC); + if (PHALCON_IS_EMPTY(target_uri)) { + PHALCON_OBS_NVAR(target_uri); + phalcon_read_property_this_quick(&target_uri, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); } - RETURN_CTOR(sql); + RETURN_CCTOR(target_uri); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, createView){ +static PHP_METHOD(Phalcon_Assets_Resource, getRealSourcePath){ - zval *view_name, *definition, *schema_name, *view_sql; - zval *view = NULL, *sql; + zval *base_path = NULL, *source_path = NULL, *local, *complete_path; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); + phalcon_fetch_params(1, 0, 1, &base_path); - if (!phalcon_array_isset_quick_string(definition, SS("sql"), 2090732981UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'sql' is required in the definition array"); - return; + if (!base_path) { + PHALCON_INIT_VAR(base_path); } - PHALCON_OBS_VAR(view_sql); - phalcon_array_fetch_quick_string(&view_sql, definition, SS("sql"), 2090732981UL, PH_NOISY); - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(view); - PHALCON_CONCAT_SVSVS(view, "`", schema_name, "`.`", view_name, "`"); - } else { - PHALCON_INIT_NVAR(view); - PHALCON_CONCAT_SVS(view, "`", view_name, "`"); + PHALCON_OBS_VAR(source_path); + phalcon_read_property_this_quick(&source_path, this_ptr, SL("_sourcePath"), 1419415746UL, PH_NOISY_CC); + if (PHALCON_IS_EMPTY(source_path)) { + PHALCON_OBS_NVAR(source_path); + phalcon_read_property_this_quick(&source_path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); + PHALCON_OBS_VAR(local); + phalcon_read_property_this_quick(&local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC); + if (zend_is_true(local)) { + PHALCON_INIT_VAR(complete_path); + PHALCON_CONCAT_VV(complete_path, base_path, source_path); - RETURN_CTOR(sql); + phalcon_call_func_p1(return_value, "realpath", complete_path); + RETURN_MM(); + } + + RETURN_CCTOR(source_path); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropView){ +static PHP_METHOD(Phalcon_Assets_Resource, getRealTargetPath){ - zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; - zval *sql = NULL; + zval *base_path = NULL, *target_path = NULL, *local, *complete_path; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); + phalcon_fetch_params(1, 0, 1, &base_path); - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if (!base_path) { + PHALCON_INIT_VAR(base_path); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(view); - PHALCON_CONCAT_VSV(view, schema_name, ".", view_name); - } else { - PHALCON_CPY_WRT(view, view_name); + PHALCON_OBS_VAR(target_path); + phalcon_read_property_this_quick(&target_path, this_ptr, SL("_targetPath"), 3658201208UL, PH_NOISY_CC); + if (PHALCON_IS_EMPTY(target_path)) { + PHALCON_OBS_NVAR(target_path); + phalcon_read_property_this_quick(&target_path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); } - if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SV(sql, "DROP VIEW IF EXISTS ", view); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DROP VIEW ", view); + + PHALCON_OBS_VAR(local); + phalcon_read_property_this_quick(&local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC); + if (zend_is_true(local)) { + + PHALCON_INIT_VAR(complete_path); + PHALCON_CONCAT_VV(complete_path, base_path, target_path); + + if (phalcon_file_exists(complete_path TSRMLS_CC) == SUCCESS) { + phalcon_call_func_p1(return_value, "realpath", complete_path); + RETURN_MM(); + } + + RETURN_CTOR(complete_path); } - RETURN_CTOR(sql); + RETURN_CCTOR(target_path); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableExists){ - zval *table_name, *schema_name = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - if (zend_is_true(schema_name)) { - PHALCON_CONCAT_SVSVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`= '", table_name, "' AND `TABLE_SCHEMA`='", schema_name, "'"); - RETURN_MM(); - } - PHALCON_CONCAT_SVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`='", table_name, "'"); - - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, viewExists){ +#ifdef HAVE_CONFIG_H +#endif - zval *view_name, *schema_name = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - if (zend_is_true(schema_name)) { - PHALCON_CONCAT_SVSVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE `TABLE_NAME`= '", view_name, "' AND `TABLE_SCHEMA`='", schema_name, "'"); - RETURN_MM(); - } - PHALCON_CONCAT_SVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE `TABLE_NAME`='", view_name, "'"); - - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeColumns){ - zval *table, *schema = NULL; - PHALCON_MM_GROW(); +static int phalcon_cache_backend_is_apcu = -1; - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } - - if (zend_is_true(schema)) { - PHALCON_CONCAT_SVSVS(return_value, "DESCRIBE `", schema, "`.`", table, "`"); - RETURN_MM(); +PHALCON_INIT_CLASS(Phalcon_Cache_Backend_Apc){ + + if (-1 == phalcon_cache_backend_is_apcu) { + phalcon_cache_backend_is_apcu = zend_hash_exists(&module_registry, SS("apcu")); } - PHALCON_CONCAT_SVS(return_value, "DESCRIBE `", table, "`"); - - RETURN_MM(); + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, Apc, cache_backend_apc, "phalcon\\cache\\backend", phalcon_cache_backend_apc_method_entry, 0); + + zend_class_implements(phalcon_cache_backend_apc_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, listTables){ +static PHP_METHOD(Phalcon_Cache_Backend_Apc, get){ - zval *schema_name = NULL; + zval *key_name, *lifetime = NULL, *frontend, *prefix, *prefixed_key; + zval *cached_content, *processed; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } - if (zend_is_true(schema_name)) { - PHALCON_CONCAT_SVS(return_value, "SHOW TABLES FROM `", schema_name, "`"); - RETURN_MM(); + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(prefixed_key); + PHALCON_CONCAT_SVV(prefixed_key, "_PHCA", prefix, key_name); + phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), prefixed_key, 394299009UL TSRMLS_CC); + + PHALCON_INIT_VAR(cached_content); + phalcon_call_func_p1(cached_content, "apc_fetch", prefixed_key); + if (PHALCON_IS_FALSE(cached_content)) { + RETURN_MM_NULL(); } - RETURN_MM_STRING("SHOW TABLES", 1); + + PHALCON_INIT_VAR(processed); + phalcon_call_method_p1_key(processed, frontend, "afterretrieve", cached_content, 3229641981UL); + + RETURN_CCTOR(processed); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, listViews){ +static PHP_METHOD(Phalcon_Cache_Backend_Apc, save){ - zval *schema_name = NULL; + zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; + zval *last_key = NULL, *prefix, *frontend, *cached_content = NULL; + zval *prepared_content, *ttl = NULL, *is_buffering; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!key_name) { + PHALCON_INIT_VAR(key_name); } - if (zend_is_true(schema_name)) { - PHALCON_CONCAT_SVS(return_value, "SELECT `TABLE_NAME` AS view_name FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE `TABLE_SCHEMA` = '", schema_name, "' ORDER BY view_name"); - RETURN_MM(); + if (!content) { + PHALCON_INIT_VAR(content); } - RETURN_MM_STRING("SELECT `TABLE_NAME` AS view_name FROM `INFORMATION_SCHEMA`.`VIEWS` ORDER BY view_name", 1); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeIndexes){ - - zval *table, *schema = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } - if (zend_is_true(schema)) { - PHALCON_CONCAT_SVSVS(return_value, "SHOW INDEXES FROM `", schema, "`.`", table, "`"); - RETURN_MM(); + if (!stop_buffer) { + PHALCON_INIT_VAR(stop_buffer); + ZVAL_BOOL(stop_buffer, 1); } - PHALCON_CONCAT_SVS(return_value, "SHOW INDEXES FROM `", table, "`"); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeReferences){ - - zval *table, *schema = NULL, *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); + } else { + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - if (!schema) { - PHALCON_INIT_VAR(schema); + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_SVV(last_key, "_PHCA", prefix, key_name); + } + if (!zend_is_true(last_key)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); + return; } - PHALCON_INIT_VAR(sql); - ZVAL_STRING(sql, "SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME,REFERENCED_TABLE_SCHEMA,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME IS NOT NULL AND ", 1); - if (zend_is_true(schema)) { - PHALCON_SCONCAT_SVSVS(sql, "CONSTRAINT_SCHEMA = \"", schema, "\" AND TABLE_NAME = \"", table, "\""); + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + if (Z_TYPE_P(content) == IS_NULL) { + PHALCON_INIT_VAR(cached_content); + phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); } else { - PHALCON_SCONCAT_SVS(sql, "TABLE_NAME = \"", table, "\""); + PHALCON_CPY_WRT(cached_content, content); } - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableOptions){ - - zval *table, *schema = NULL, *sql; - - PHALCON_MM_GROW(); + PHALCON_INIT_VAR(prepared_content); + phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); + + if (Z_TYPE_P(lifetime) == IS_NULL) { - phalcon_fetch_params(1, 1, 1, &table, &schema); + PHALCON_OBS_VAR(ttl); + phalcon_read_property_this_quick(&ttl, this_ptr, SL("_lastLifetime"), 3936785351UL, PH_NOISY_CC); + if (Z_TYPE_P(ttl) == IS_NULL) { + PHALCON_INIT_NVAR(ttl); + phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); + } + } else { + PHALCON_CPY_WRT(ttl, lifetime); + } - if (!schema) { - PHALCON_INIT_VAR(schema); + phalcon_call_func_p3_noret("apc_store", last_key, prepared_content, ttl); + + PHALCON_INIT_VAR(is_buffering); + phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); + if (PHALCON_IS_TRUE(stop_buffer)) { + phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); } - PHALCON_INIT_VAR(sql); - ZVAL_STRING(sql, "SELECT TABLES.TABLE_TYPE AS table_type,TABLES.AUTO_INCREMENT AS auto_increment,TABLES.ENGINE AS engine,TABLES.TABLE_COLLATION AS table_collation FROM INFORMATION_SCHEMA.TABLES WHERE ", 1); - if (zend_is_true(schema)) { - PHALCON_SCONCAT_SVSVS(sql, "TABLES.TABLE_SCHEMA = \"", schema, "\" AND TABLES.TABLE_NAME = \"", table, "\""); - } else { - PHALCON_SCONCAT_SVS(sql, "TABLES.TABLE_NAME = \"", table, "\""); + if (PHALCON_IS_TRUE(is_buffering)) { + zend_print_zval(cached_content, 0); } - RETURN_CTOR(sql); + phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); + + PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Cache_Backend_Apc, delete){ + zval *key_name, *prefix, *key; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Oracle){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Oracle, db_dialect_oracle, "phalcon\\db\\dialect", phalcon_db_dialect_oracle_method_entry, 0); - - zend_declare_property_string(phalcon_db_dialect_oracle_ce, SL("_escapeChar"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_db_dialect_oracle_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); - - return SUCCESS; + phalcon_fetch_params(1, 1, 0, &key_name); + + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_SVV(key, "_PHCA", prefix, key_name); + + phalcon_call_func_p1(return_value, "apc_delete", key); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, getColumnDefinition){ +static PHP_METHOD(Phalcon_Cache_Backend_Apc, queryKeys){ - zval *column, *size, *column_type, *column_sql = NULL; - zval *scale = NULL; + zval *prefix = NULL, *keys, *type, *prefix_pattern, *iterator; + zval *key = NULL; + zend_class_entry *ce0; +#if PHP_VERSION_ID < 50500 + char *str_key; + uint str_key_len; + ulong int_key; + int key_type; +#else + zval *itkey = NULL; +#endif + zend_object_iterator *it; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &column); + phalcon_fetch_params(1, 0, 1, &prefix); - if (Z_TYPE_P(column) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column definition must be an object compatible with Phalcon\\Db\\ColumnInterface"); - return; + PHALCON_INIT_VAR(prefix_pattern); + if (!prefix) { + ZVAL_STRING(prefix_pattern, "/^_PHCA/", 1); + } + else { + PHALCON_CONCAT_SVS(prefix_pattern, "/^_PHCA", prefix, "/"); } - PHALCON_INIT_VAR(size); - phalcon_call_method_key(size, column, "getsize", 4292672352UL); - - PHALCON_INIT_VAR(column_type); - phalcon_call_method_key(column_type, column, "gettype", 4294422375UL); - - switch (phalcon_get_intval(column_type)) { - - case 0: - PHALCON_INIT_VAR(column_sql); - ZVAL_STRING(column_sql, "INTEGER", 1); - break; - - case 1: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "DATE", 1); - break; - - case 2: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "VARCHAR2(", size, ")"); - break; - - case 3: - PHALCON_INIT_VAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); - - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVSVS(column_sql, "NUMBER(", size, ",", scale, ")"); - break; - - case 4: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TIMESTAMP", 1); - break; - - case 5: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "CHAR(", size, ")"); - break; - - case 6: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TEXT", 1); - break; - - case 7: - PHALCON_INIT_NVAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); - - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVSVS(column_sql, "FLOAT(", size, ",", scale, ")"); - break; + PHALCON_INIT_VAR(keys); + array_init(keys); - case 8: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TINYINT(1)", 1); - break; + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "user", 1); - default: - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized Oracle data type"); - return; + ce0 = zend_fetch_class(SL("APCIterator"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + PHALCON_INIT_VAR(iterator); + object_init_ex(iterator, ce0); + if (phalcon_has_constructor(iterator TSRMLS_CC)) { + if (!phalcon_cache_backend_is_apcu) { + phalcon_call_method_p2_key(NULL, iterator, "__construct", type, prefix_pattern, 1107214344UL); + } + else { + phalcon_call_method_p1_key(NULL, iterator, "__construct", prefix_pattern, 1107214344UL); + } } - - RETURN_CTOR(column_sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addColumn){ - zval *table_name, *schema_name, *column; + /* APCIterator implements Iterator */ + assert(instanceof_function_ex(ce0, zend_ce_iterator, 1 TSRMLS_CC)); - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} + it = ce0->get_iterator(ce0, iterator, 0 TSRMLS_CC); -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, modifyColumn){ + /* APCIterator is an iterator */ + assert(it != NULL); - zval *table_name, *schema_name, *column; + /* APCIterator has key() method */ + assert(it->funcs->get_current_key != NULL); - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} + /* APCIterator has rewind() method */ + assert(it->funcs->rewind != NULL); -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropColumn){ + it->funcs->rewind(it TSRMLS_CC); + while (it->funcs->valid(it TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_NVAR(key); +#if PHP_VERSION_ID < 50500 + key_type = it->funcs->get_current_key(it, &str_key, &str_key_len, &int_key TSRMLS_CC); + if (likely(key_type == HASH_KEY_IS_STRING)) { + ZVAL_STRINGL(key, str_key + 5, str_key_len - 5 - 1, 1); + efree(str_key); - zval *table_name, *schema_name, *column_name; + phalcon_array_append(&keys, key, PH_COPY); + } +#else + PHALCON_INIT_NVAR(itkey); + it->funcs->get_current_key(it, itkey TSRMLS_CC); + if (likely(Z_TYPE_P(itkey) == IS_STRING)) { + ZVAL_STRINGL(key, Z_STRVAL_P(itkey) + 5, Z_STRLEN_P(itkey) - 5, 1); + phalcon_array_append(&keys, key, PH_COPY); + } +#endif - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column_name); + it->funcs->move_forward(it TSRMLS_CC); + } - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addIndex){ - - zval *table_name, *schema_name, *index; + it->funcs->dtor(it TSRMLS_CC); - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + RETURN_CTOR(keys); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropIndex){ - - zval *table_name, *schema_name, *index_name; - - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} +static PHP_METHOD(Phalcon_Cache_Backend_Apc, exists){ -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addPrimaryKey){ + zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *cache_exists; - zval *table_name, *schema_name, *index; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + if (!key_name) { + PHALCON_INIT_VAR(key_name); + } + + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); + } + + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); + } else { + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_SVV(last_key, "_PHCA", prefix, key_name); + } + if (zend_is_true(last_key)) { + + PHALCON_INIT_VAR(cache_exists); + phalcon_call_func_p1(cache_exists, "apc_exists", last_key); + if (PHALCON_IS_NOT_FALSE(cache_exists)) { + RETURN_MM_TRUE; + } + } + + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropPrimaryKey){ - - zval *table_name, *schema_name; - phalcon_fetch_params(0, 2, 0, &table_name, &schema_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addForeignKey){ - zval *table_name, *schema_name, *reference; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropForeignKey){ - zval *table_name, *schema_name, *reference_name; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, _getTableOptions){ - zval *definition, *empty_array; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &definition); - - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - RETURN_CTOR(empty_array); -} +PHALCON_INIT_CLASS(Phalcon_Cache_Backend_File){ -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, createTable){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, File, cache_backend_file, "phalcon\\cache\\backend", phalcon_cache_backend_file_method_entry, 0); - zval *table_name, *schema_name, *definition; + zend_class_implements(phalcon_cache_backend_file_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &definition); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropTable){ +static PHP_METHOD(Phalcon_Cache_Backend_File, __construct){ - zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; + zval *frontend, *options = NULL, *cache_dir; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); + phalcon_fetch_params(1, 1, 1, &frontend, &options); - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if (!options) { + PHALCON_INIT_VAR(options); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(table); - PHALCON_CONCAT_VSV(table, schema_name, ".", table_name); - } else { - PHALCON_CPY_WRT(table, table_name); - } - if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SV(sql, "DROP TABLE IF EXISTS ", table); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DROP TABLE ", table); + if (!phalcon_array_isset_quick_string(options, SS("cacheDir"), 1104587096UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cache directory must be specified with the option cacheDir"); + return; } - RETURN_CTOR(sql); + PHALCON_OBS_VAR(cache_dir); + phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); + PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\File", "__construct", frontend, options); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, createView){ +static PHP_METHOD(Phalcon_Cache_Backend_File, get){ - zval *view_name, *definition, *schema_name, *view_sql; - zval *view = NULL, *sql; + zval *key_name, *lifetime = NULL, *options, *prefix, *prefixed_key; + zval *cache_dir, *cache_file, *frontend, *timestamp; + zval *ttl = NULL, *modified_time, *difference, *not_expired; + zval *cached_content, *exception_message; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); - - if (!phalcon_array_isset_quick_string(definition, SS("sql"), 2090732981UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'sql' is required in the definition array"); - return; - } + phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - PHALCON_OBS_VAR(view_sql); - phalcon_array_fetch_quick_string(&view_sql, definition, SS("sql"), 2090732981UL, PH_NOISY); - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(view); - PHALCON_CONCAT_VSV(view, view_name, ".", schema_name); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } else { - PHALCON_CPY_WRT(view, view_name); + PHALCON_SEPARATE_PARAM(lifetime); } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropView){ - - zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; - zval *sql = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); - } + PHALCON_INIT_VAR(prefixed_key); + PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); + phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), prefixed_key, 394299009UL TSRMLS_CC); - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(view); - PHALCON_CONCAT_SVSVS(view, "`", schema_name, "`.`", view_name, "`"); - } else { - PHALCON_INIT_NVAR(view); - PHALCON_CONCAT_SVS(view, "`", view_name, "`"); - } - if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SV(sql, "DROP VIEW IF EXISTS ", view); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DROP VIEW ", view); + PHALCON_OBS_VAR(cache_dir); + phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); + + PHALCON_INIT_VAR(cache_file); + PHALCON_CONCAT_VV(cache_file, cache_dir, prefixed_key); + + if (phalcon_file_exists(cache_file TSRMLS_CC) == SUCCESS) { + + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(timestamp); + ZVAL_LONG(timestamp, (long) time(NULL)); + + if (Z_TYPE_P(lifetime) == IS_NULL) { + + PHALCON_OBS_NVAR(lifetime); + phalcon_read_property_this_quick(&lifetime, this_ptr, SL("_lastLifetime"), 3936785351UL, PH_NOISY_CC); + if (Z_TYPE_P(lifetime) == IS_NULL) { + PHALCON_INIT_VAR(ttl); + phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); + } else { + PHALCON_CPY_WRT(ttl, lifetime); + } + } else { + PHALCON_CPY_WRT(ttl, lifetime); + } + + PHALCON_INIT_VAR(modified_time); + phalcon_call_func_p1(modified_time, "filemtime", cache_file); + + PHALCON_INIT_VAR(difference); + sub_function(difference, timestamp, ttl TSRMLS_CC); + + PHALCON_INIT_VAR(not_expired); + is_smaller_function(not_expired, difference, modified_time TSRMLS_CC); + + if (PHALCON_IS_TRUE(not_expired)) { + + PHALCON_INIT_VAR(cached_content); + phalcon_file_get_contents(cached_content, cache_file TSRMLS_CC); + if (PHALCON_IS_FALSE(cached_content)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Cache file ", cache_file, " could not be opened"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_cache_exception_ce, exception_message); + return; + } + + phalcon_call_method_p1_key(return_value, frontend, "afterretrieve", cached_content, 3229641981UL); + RETURN_MM(); + } } - RETURN_CTOR(sql); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableExists){ +static PHP_METHOD(Phalcon_Cache_Backend_File, save){ - zval *table_name, *schema_name = NULL, *sql = NULL; + zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; + zval *last_key = NULL, *prefix, *frontend, *options, *cache_dir; + zval *cache_file, *cached_content = NULL, *prepared_content; + zval *status, *is_buffering; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!key_name) { + PHALCON_INIT_VAR(key_name); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_TABLES WHERE TABLE_NAME='", table_name, "' AND OWNER = '", schema_name, "'"); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_TABLES WHERE TABLE_NAME='", table_name, "'"); + if (!content) { + PHALCON_INIT_VAR(content); } - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, viewExists){ - - zval *view_name, *schema_name = NULL, *sql = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); + } - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!stop_buffer) { + PHALCON_INIT_VAR(stop_buffer); + ZVAL_BOOL(stop_buffer, 1); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_VIEWS WHERE VIEW_NAME='", view_name, "' AND OWNER='", schema_name, "'"); + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_VIEWS WHERE VIEW_NAME='", view_name, "'"); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_VV(last_key, prefix, key_name); + } + if (!zend_is_true(last_key)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); + return; } - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeColumns){ - - zval *table, *schema = NULL, *sql = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - if (!schema) { - PHALCON_INIT_VAR(schema); - } + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (zend_is_true(schema)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "SELECT TC.COLUMN_NAME, TC.DATA_TYPE, TC.DATA_LENGTH, TC.DATA_PRECISION, TC.DATA_SCALE, TC.NULLABLE, C.CONSTRAINT_TYPE, TC.DATA_DEFAULT, CC.POSITION FROM ALL_TAB_COLUMNS TC LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P')) ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME WHERE TC.TABLE_NAME = '", table, "' AND TC.OWNER = '", schema, "' ORDER BY TC.COLUMN_ID"); + PHALCON_OBS_VAR(cache_dir); + phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); + + PHALCON_INIT_VAR(cache_file); + PHALCON_CONCAT_VV(cache_file, cache_dir, last_key); + if (!zend_is_true(content)) { + PHALCON_INIT_VAR(cached_content); + phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT TC.COLUMN_NAME, TC.DATA_TYPE, TC.DATA_LENGTH, TC.DATA_PRECISION, TC.DATA_SCALE, TC.NULLABLE, C.CONSTRAINT_TYPE, TC.DATA_DEFAULT, CC.POSITION FROM ALL_TAB_COLUMNS TC LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P')) ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME WHERE TC.TABLE_NAME = '", table, "' ORDER BY TC.COLUMN_ID"); + PHALCON_CPY_WRT(cached_content, content); } - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, listTables){ - - zval *schema_name = NULL, *sql = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &schema_name); + PHALCON_INIT_VAR(prepared_content); + phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + PHALCON_INIT_VAR(status); + phalcon_file_put_contents(status, cache_file, prepared_content TSRMLS_CC); + if (PHALCON_IS_FALSE(status)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cache directory can't be written"); + return; } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT TABLE_NAME, OWNER FROM ALL_TABLES WHERE OWNER='", schema_name, "' ORDER BY OWNER, TABLE_NAME"); - } else { - PHALCON_INIT_NVAR(sql); - ZVAL_STRING(sql, "SELECT TABLE_NAME, OWNER FROM ALL_TABLES ORDER BY OWNER, TABLE_NAME ", 1); + PHALCON_INIT_VAR(is_buffering); + phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); + if (PHALCON_IS_TRUE(stop_buffer)) { + phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); } - RETURN_CTOR(sql); + if (PHALCON_IS_TRUE(is_buffering)) { + zend_print_zval(cached_content, 0); + } + + phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, listViews){ +static PHP_METHOD(Phalcon_Cache_Backend_File, delete){ - zval *schema_name = NULL, *sql = NULL; + zval *key_name, *options, *prefix, *prefixed_key; + zval *cache_dir, *cache_file; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(1, 1, 0, &key_name); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT VIEW_NAME FROM ALL_VIEWS WHERE OWNER='", schema_name, "' ORDER BY VIEW_NAME"); - } else { - PHALCON_INIT_NVAR(sql); - ZVAL_STRING(sql, "SELECT VIEW_NAME FROM ALL_VIEWS VIEW_NAME", 1); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(prefixed_key); + PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); + + PHALCON_OBS_VAR(cache_dir); + phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); + + PHALCON_INIT_VAR(cache_file); + PHALCON_CONCAT_VV(cache_file, cache_dir, prefixed_key); + + if (phalcon_file_exists(cache_file TSRMLS_CC) == SUCCESS) { + phalcon_call_func_p1(return_value, "unlink", cache_file); + RETURN_MM(); } - RETURN_CTOR(sql); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeIndexes){ +static PHP_METHOD(Phalcon_Cache_Backend_File, queryKeys){ - zval *table, *schema = NULL, *sql = NULL; + zval *prefix = NULL, *keys, *options, *cache_dir, *iterator; + zval *item = NULL, *is_directory = NULL, *key = NULL; + zval *r0 = NULL; + zend_class_entry *ce0; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 0, 1, &prefix); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (!prefix) { + PHALCON_INIT_VAR(prefix); } - if (zend_is_true(schema)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "SELECT I.TABLE_NAME, 0 AS C0, I.INDEX_NAME, IC.COLUMN_POSITION, IC.COLUMN_NAME FROM ALL_INDEXES I JOIN ALL_IND_COLUMNS IC ON I.INDEX_NAME = IC.INDEX_NAME WHERE I.TABLE_NAME = '", table, "' AND IC.INDEX_OWNER = '", schema, "'"); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT I.TABLE_NAME, 0 AS C0, I.INDEX_NAME, IC.COLUMN_POSITION, IC.COLUMN_NAME FROM ALL_INDEXES I JOIN ALL_IND_COLUMNS IC ON I.INDEX_NAME = IC.INDEX_NAME WHERE I.TABLE_NAME = '", table, "'"); - } + PHALCON_INIT_VAR(keys); + array_init(keys); - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeReferences){ - - zval *table, *schema = NULL, *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (!schema) { - PHALCON_INIT_VAR(schema); + PHALCON_OBS_VAR(cache_dir); + phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); + + ce0 = zend_fetch_class(SL("DirectoryIterator"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + + PHALCON_INIT_VAR(iterator); + object_init_ex(iterator, ce0); + if (phalcon_has_constructor(iterator TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, iterator, "__construct", cache_dir, 1107214344UL); } + phalcon_call_method_key(NULL, iterator, "rewind", 1064078190UL); - PHALCON_INIT_VAR(sql); - ZVAL_STRING(sql, "SELECT AC.TABLE_NAME, CC.COLUMN_NAME, AC.CONSTRAINT_NAME, AC.R_OWNER, RCC.TABLE_NAME R_TABLE_NAME, RCC.COLUMN_NAME R_COLUMN_NAME FROM ALL_CONSTRAINTS AC JOIN ALL_CONS_COLUMNS CC ON AC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME JOIN ALL_CONS_COLUMNS RCC ON AC.R_OWNER = RCC.OWNER AND AC.R_CONSTRAINT_NAME = RCC.CONSTRAINT_NAME WHERE AC.CONSTRAINT_TYPE='R' ", 1); - if (zend_is_true(schema)) { - PHALCON_SCONCAT_SVSVS(sql, "AND AC.OWNER='", schema, "' AND AC.TABLE_NAME = '", table, "'"); - } else { - PHALCON_SCONCAT_SVS(sql, "AND AC.TABLE_NAME = '", table, "'"); + while (1) { + + PHALCON_INIT_NVAR(r0); + phalcon_call_method_key(r0, iterator, "valid", 574098517UL); + if (zend_is_true(r0)) { + } else { + break; + } + + PHALCON_INIT_NVAR(item); + phalcon_call_method_key(item, iterator, "current", 431662984UL); + + PHALCON_INIT_NVAR(is_directory); + phalcon_call_method_key(is_directory, item, "isdir", 86397952UL); + if (PHALCON_IS_FALSE(is_directory)) { + + PHALCON_INIT_NVAR(key); + phalcon_call_method_key(key, item, "getfilename", 984101030UL); + if (zend_is_true(prefix)) { + if (!phalcon_start_with(key, prefix, NULL)) { + continue; + } + } + + phalcon_array_append(&keys, key, PH_SEPARATE); + } + + phalcon_call_method_key(NULL, iterator, "next", 268367684UL); } - RETURN_CTOR(sql); + RETURN_CTOR(keys); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableOptions){ +static PHP_METHOD(Phalcon_Cache_Backend_File, exists){ - zval *table, *schema = NULL; + zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *options; + zval *cache_dir, *cache_file, *frontend, *timestamp; + zval *ttl = NULL, *modified_time, *difference, *not_expired; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (!key_name) { + PHALCON_INIT_VAR(key_name); } - RETURN_MM_EMPTY_STRING(); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, getSqlTable){ - - zval *table, *escape_char = NULL, *table_name, *sql_table = NULL; - zval *schema_name, *sql_schema = NULL, *alias_name; - zval *sql_table_alias = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &escape_char); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); + } - if (!escape_char) { - PHALCON_INIT_VAR(escape_char); + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); } else { - PHALCON_SEPARATE_PARAM(escape_char); - } + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - if (Z_TYPE_P(escape_char) == IS_NULL) { - PHALCON_OBS_NVAR(escape_char); - phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_VV(last_key, prefix, key_name); } - if (Z_TYPE_P(table) == IS_ARRAY) { + if (zend_is_true(last_key)) { - PHALCON_OBS_VAR(table_name); - phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY); - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(sql_table); - PHALCON_CONCAT_VVV(sql_table, escape_char, table_name, escape_char); - } else { - PHALCON_CPY_WRT(sql_table, table_name); - } + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - PHALCON_OBS_VAR(schema_name); - phalcon_array_fetch_long(&schema_name, table, 1, PH_NOISY); - if (Z_TYPE_P(schema_name) != IS_NULL) { - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(sql_schema); - PHALCON_CONCAT_VVVSV(sql_schema, escape_char, schema_name, escape_char, ".", sql_table); - } else { - PHALCON_INIT_NVAR(sql_schema); - PHALCON_CONCAT_VSV(sql_schema, schema_name, ".", sql_table); - } - } else { - PHALCON_CPY_WRT(sql_schema, sql_table); - } + PHALCON_OBS_VAR(cache_dir); + phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); - if (phalcon_array_isset_long(table, 2)) { + PHALCON_INIT_VAR(cache_file); + PHALCON_CONCAT_VV(cache_file, cache_dir, last_key); - PHALCON_OBS_VAR(alias_name); - phalcon_array_fetch_long(&alias_name, table, 2, PH_NOISY); - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(sql_table_alias); - PHALCON_CONCAT_VSVVV(sql_table_alias, sql_schema, " ", escape_char, alias_name, escape_char); + if (phalcon_file_exists(cache_file TSRMLS_CC) == SUCCESS) { + + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(timestamp); + ZVAL_LONG(timestamp, (long) time(NULL)); + if (Z_TYPE_P(lifetime) == IS_NULL) { + PHALCON_INIT_VAR(ttl); + phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); } else { - PHALCON_INIT_NVAR(sql_table_alias); - PHALCON_CONCAT_VSV(sql_table_alias, sql_schema, " ", alias_name); + PHALCON_CPY_WRT(ttl, lifetime); } - } else { - PHALCON_CPY_WRT(sql_table_alias, sql_schema); - } - RETURN_CCTOR(sql_table_alias); - } + PHALCON_INIT_VAR(modified_time); + phalcon_call_func_p1(modified_time, "filemtime", cache_file); - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_NVAR(sql_table); - PHALCON_CONCAT_VVV(sql_table, escape_char, table, escape_char); - RETURN_CCTOR(sql_table); + PHALCON_INIT_VAR(difference); + sub_function(difference, timestamp, ttl TSRMLS_CC); + + PHALCON_INIT_VAR(not_expired); + is_smaller_function(not_expired, difference, modified_time TSRMLS_CC); + if (PHALCON_IS_TRUE(not_expired)) { + RETURN_MM_TRUE; + } + } } - RETURN_CCTOR(table); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, limit){ - zval *sql_query, *number, *limit, *sql_limit; - PHALCON_MM_GROW(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &sql_query, &number) == FAILURE) { - RETURN_MM_NULL(); - } - if (phalcon_is_numeric(number)) { +#ifdef HAVE_CONFIG_H +#endif - PHALCON_INIT_VAR(limit); - ZVAL_LONG(limit, phalcon_get_intval(number)); - PHALCON_INIT_VAR(sql_limit); - PHALCON_CONCAT_VSV(sql_limit, sql_query, " LIMIT ", limit); - RETURN_CTOR(sql_limit); - } - RETURN_CCTOR(sql_query); -} -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, select){ - zval *definition, *escape_char = NULL, *columns, *selected_columns; - zval *column = NULL, *column_item = NULL, *column_sql = NULL, *columns_sql = NULL; - zval *column_domain = NULL, *column_domain_sql = NULL, *column_alias = NULL; - zval *column_alias_sql = NULL, *tables, *selected_tables; - zval *table = NULL, *sql_table = NULL, *tables_sql = NULL, *sql, *joins; - zval *join = NULL, *type = NULL, *sql_join = NULL, *join_conditions_array = NULL; - zval *join_expressions = NULL, *join_condition = NULL, *join_expression = NULL; - zval *join_conditions = NULL, *where_conditions; - zval *where_expression, *group_items, *group_fields; - zval *group_field = NULL, *group_expression = NULL, *group_sql; - zval *group_clause, *having_conditions, *having_expression; - zval *order_fields, *order_items, *order_item = NULL; - zval *order_expression = NULL, *order_sql_item = NULL, *sql_order_type = NULL; - zval *order_sql_item_type = NULL, *order_sql, *limit_value; - zval *number, *offset; - zval *one, *ini_range, *end_range, *sql_limit; - HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5; - HashPosition hp0, hp1, hp2, hp3, hp4, hp5; - zval **hd; - PHALCON_MM_GROW(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &definition) == FAILURE) { - RETURN_MM_NULL(); - } +PHALCON_INIT_CLASS(Phalcon_Cache_Backend_Memcache){ - if (Z_TYPE_P(definition) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid SELECT definition"); - return; - } - if (!phalcon_array_isset_quick_string(definition, SS("tables"), 3465666720UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'tables' is required in the definition array"); - return; - } + PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, Memcache, cache_backend_memcache, "phalcon\\cache\\backend", phalcon_cache_backend_memcache_method_entry, 0); - if (!phalcon_array_isset_quick_string(definition, SS("columns"), 1041822630UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'columns' is required in the definition array"); - return; - } + zend_declare_property_null(phalcon_cache_backend_memcache_ce, SL("_memcache"), ZEND_ACC_PROTECTED TSRMLS_CC); - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_OBS_VAR(escape_char); - phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); - } else { - PHALCON_INIT_NVAR(escape_char); - } + zend_class_implements(phalcon_cache_backend_memcache_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); - if (Z_TYPE_P(columns) == IS_ARRAY) { + return SUCCESS; +} - PHALCON_INIT_VAR(selected_columns); - array_init(selected_columns); +static PHP_METHOD(Phalcon_Cache_Backend_Memcache, __construct){ - if (!phalcon_is_iterable_ex(columns, &ah0, &hp0, 0, 0)) { - return; - } + zval *frontend, *options = NULL; - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_FOREACH_VALUE(column); - - PHALCON_OBS_NVAR(column_item); - phalcon_array_fetch_long(&column_item, column, 0, PH_NOISY); - if (Z_TYPE_P(column_item) == IS_ARRAY) { - PHALCON_INIT_NVAR(column_sql); - phalcon_call_method_p2_key(column_sql, this_ptr, "getsqlexpression", column_item, escape_char, 3377787077UL); - } else { - if (PHALCON_IS_STRING(column_item, "*")) { - PHALCON_CPY_WRT(column_sql, column_item); - } else { - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_VVV(column_sql, escape_char, column_item, escape_char); - } else { - PHALCON_CPY_WRT(columns_sql, column_item); - } - } - } - - if (phalcon_array_isset_long(column, 1)) { + PHALCON_MM_GROW(); - PHALCON_OBS_NVAR(column_domain); - phalcon_array_fetch_long(&column_domain, column, 1, PH_NOISY); - if (zend_is_true(column_domain)) { - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_NVAR(column_domain_sql); - PHALCON_CONCAT_VVVSV(column_domain_sql, escape_char, column_domain, escape_char, ".", column_sql); - } else { - PHALCON_INIT_NVAR(column_domain_sql); - PHALCON_CONCAT_VSV(column_domain_sql, column_domain, ".", column_sql); - } - } else { - PHALCON_CPY_WRT(column_domain_sql, column_sql); - } - } else { - PHALCON_CPY_WRT(column_domain_sql, column_sql); - } + phalcon_fetch_params(1, 1, 1, &frontend, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } else { + PHALCON_SEPARATE_PARAM(options); + } + + if (Z_TYPE_P(options) != IS_ARRAY) { + PHALCON_INIT_NVAR(options); + array_init(options); + } + if (!phalcon_array_isset_quick_string(options, SS("host"), 261606083UL)) { + phalcon_array_update_string_string(&options, SL("host"), SL("127.0.0.1"), PH_SEPARATE); + } + + if (!phalcon_array_isset_quick_string(options, SS("port"), 271092362UL)) { + phalcon_array_update_string_string(&options, SL("port"), SL("11211"), PH_SEPARATE); + } + + if (!phalcon_array_isset_quick_string(options, SS("persistent"), 2222052598UL)) { + phalcon_array_update_string_bool(&options, SL("persistent"), 0, PH_SEPARATE); + } + + if (!phalcon_array_isset_quick_string(options, SS("statsKey"), 2508919229UL)) { + phalcon_array_update_string_string(&options, SL("statsKey"), SL("_PHCM"), PH_SEPARATE); + } + + PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\Memcache", "__construct", frontend, options); + + PHALCON_MM_RESTORE(); +} - if (phalcon_array_isset_long(column, 2)) { +static PHP_METHOD(Phalcon_Cache_Backend_Memcache, _connect){ - PHALCON_OBS_NVAR(column_alias); - phalcon_array_fetch_long(&column_alias, column, 2, PH_NOISY); - if (zend_is_true(column_alias)) { - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_NVAR(column_alias_sql); - PHALCON_CONCAT_VSVVV(column_alias_sql, column_domain_sql, " ", escape_char, column_alias, escape_char); - } else { - PHALCON_INIT_NVAR(column_alias_sql); - PHALCON_CONCAT_VSV(column_alias_sql, column_domain_sql, " ", column_alias); - } - } else { - PHALCON_CPY_WRT(column_alias_sql, column_domain_sql); - } - } else { - PHALCON_CPY_WRT(column_alias_sql, column_domain_sql); - } + zval *options, *memcache, *host, *port, *persistent; + zval *success; + zend_class_entry *ce0; - phalcon_array_append(&selected_columns, column_alias_sql, PH_SEPARATE); + PHALCON_MM_GROW(); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + ce0 = zend_fetch_class(SL("Memcache"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + + PHALCON_INIT_VAR(memcache); + object_init_ex(memcache, ce0); + if (phalcon_has_constructor(memcache TSRMLS_CC)) { + phalcon_call_method_key(NULL, memcache, "__construct", 1107214344UL); + } + + PHALCON_OBS_VAR(host); + phalcon_array_fetch_quick_string(&host, options, SS("host"), 261606083UL, PH_NOISY); + + PHALCON_OBS_VAR(port); + phalcon_array_fetch_quick_string(&port, options, SS("port"), 271092362UL, PH_NOISY); + + PHALCON_OBS_VAR(persistent); + phalcon_array_fetch_quick_string(&persistent, options, SS("persistent"), 2222052598UL, PH_NOISY); - PHALCON_INIT_VAR(columns_sql); - phalcon_fast_join_str(columns_sql, SL(", "), selected_columns TSRMLS_CC); + PHALCON_INIT_VAR(success); + if (zend_is_true(persistent)) { + phalcon_call_method_p2_key(success, memcache, "pconnect", host, port, 2937764031UL); } else { - PHALCON_CPY_WRT(columns_sql, columns); + phalcon_call_method_p2_key(success, memcache, "connect", host, port, 1111492527UL); + } + + if (!zend_is_true(success)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cannot connect to Memcached server"); + return; } + + phalcon_update_property_this_quick(this_ptr, SL("_memcache"), memcache, 958186231UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} - PHALCON_OBS_VAR(tables); - phalcon_array_fetch_quick_string(&tables, definition, SS("tables"), 3465666720UL, PH_NOISY); - if (Z_TYPE_P(tables) == IS_ARRAY) { +static PHP_METHOD(Phalcon_Cache_Backend_Memcache, get){ - PHALCON_INIT_VAR(selected_tables); - array_init(selected_tables); + zval *key_name, *lifetime = NULL, *memcache = NULL, *frontend; + zval *prefix, *prefixed_key, *cached_content; - if (!phalcon_is_iterable_ex(tables, &ah1, &hp1, 0, 0)) { - return; - } + PHALCON_MM_GROW(); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); + + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); + } + + PHALCON_OBS_VAR(memcache); + phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); + if (Z_TYPE_P(memcache) != IS_OBJECT) { + phalcon_call_method_key(NULL, this_ptr, "_connect", 4074190766UL); + + PHALCON_OBS_NVAR(memcache); + phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); + } + + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(prefixed_key); + PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); + phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), prefixed_key, 394299009UL TSRMLS_CC); + + PHALCON_INIT_VAR(cached_content); + phalcon_call_method_p1_key(cached_content, memcache, "get", prefixed_key, 2090288933UL); + if (PHALCON_IS_FALSE(cached_content)) { + RETURN_MM_NULL(); + } + + phalcon_call_method_p1_key(return_value, frontend, "afterretrieve", cached_content, 3229641981UL); + RETURN_MM(); +} - PHALCON_GET_FOREACH_VALUE(table); +static PHP_METHOD(Phalcon_Cache_Backend_Memcache, save){ - PHALCON_INIT_NVAR(sql_table); - phalcon_call_method_p2_key(sql_table, this_ptr, "getsqltable", table, escape_char, 2837135293UL); - phalcon_array_append(&selected_tables, sql_table, PH_SEPARATE); + zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; + zval *last_key = NULL, *prefix, *frontend, *memcache = NULL, *cached_content = NULL; + zval *prepared_content, *ttl = NULL, *flags, *success; + zval *options, *special_key, *keys = NULL, *is_buffering; - zend_hash_move_forward_ex(ah1, &hp1); - } + PHALCON_MM_GROW(); - PHALCON_INIT_VAR(tables_sql); - phalcon_fast_join_str(tables_sql, SL(", "), selected_tables TSRMLS_CC); + phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); + + if (!key_name) { + PHALCON_INIT_VAR(key_name); + } + + if (!content) { + PHALCON_INIT_VAR(content); + } + + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); + } + + if (!stop_buffer) { + PHALCON_INIT_VAR(stop_buffer); + ZVAL_BOOL(stop_buffer, 1); + } + + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); } else { - PHALCON_CPY_WRT(tables_sql, tables); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_VV(last_key, prefix, key_name); + } + if (!zend_is_true(last_key)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); + return; + } + + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(memcache); + phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); + if (Z_TYPE_P(memcache) != IS_OBJECT) { + phalcon_call_method_key(NULL, this_ptr, "_connect", 4074190766UL); + + PHALCON_OBS_NVAR(memcache); + phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); + } + + if (Z_TYPE_P(content) == IS_NULL) { + PHALCON_INIT_VAR(cached_content); + phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); + } else { + PHALCON_CPY_WRT(cached_content, content); + } + + PHALCON_INIT_VAR(prepared_content); + phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); + if (Z_TYPE_P(lifetime) == IS_NULL) { + PHALCON_INIT_VAR(ttl); + phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); + } else { + PHALCON_CPY_WRT(ttl, lifetime); + } + + PHALCON_INIT_VAR(flags); + ZVAL_LONG(flags, 0); + + PHALCON_INIT_VAR(success); + phalcon_call_method_p4_key(success, memcache, "set", last_key, prepared_content, flags, ttl, 2090720177UL); + if (!zend_is_true(success)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Failed storing data in memcached"); + return; + } + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(special_key); + phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); + + PHALCON_INIT_VAR(keys); + phalcon_call_method_p1_key(keys, memcache, "get", special_key, 2090288933UL); + if (Z_TYPE_P(keys) != IS_ARRAY) { + PHALCON_INIT_NVAR(keys); + array_init(keys); + } + + if (!phalcon_array_isset(keys, last_key)) { + phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); + phalcon_call_method_p2_key(NULL, memcache, "set", special_key, keys, 2090720177UL); + } + + PHALCON_INIT_VAR(is_buffering); + phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); + if (PHALCON_IS_TRUE(stop_buffer)) { + phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); + } + + if (PHALCON_IS_TRUE(is_buffering)) { + zend_print_zval(cached_content, 0); } + + phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "SELECT ", columns_sql, " FROM ", tables_sql); +static PHP_METHOD(Phalcon_Cache_Backend_Memcache, delete){ - if (phalcon_array_isset_quick_string(definition, SS("joins"), 120974824UL)) { + zval *key_name, *memcache = NULL, *prefix, *prefixed_key; + zval *options, *special_key, *keys; - PHALCON_OBS_VAR(joins); - phalcon_array_fetch_quick_string(&joins, definition, SS("joins"), 120974824UL, PH_NOISY); + PHALCON_MM_GROW(); - if (!phalcon_is_iterable_ex(joins, &ah2, &hp2, 0, 0)) { - return; - } + phalcon_fetch_params(1, 1, 0, &key_name); + + PHALCON_OBS_VAR(memcache); + phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); + if (Z_TYPE_P(memcache) != IS_OBJECT) { + phalcon_call_method_key(NULL, this_ptr, "_connect", 4074190766UL); + + PHALCON_OBS_NVAR(memcache); + phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); + } + + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(prefixed_key); + PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(special_key); + phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); + + PHALCON_INIT_VAR(keys); + phalcon_call_method_p1_key(keys, memcache, "get", special_key, 2090288933UL); + if (Z_TYPE_P(keys) == IS_ARRAY) { + phalcon_array_unset(&keys, prefixed_key, PH_SEPARATE); + phalcon_call_method_p2_key(NULL, memcache, "set", special_key, keys, 2090720177UL); + } + + phalcon_call_method_p1_key(return_value, memcache, "delete", prefixed_key, 150213496UL); + RETURN_MM(); +} - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { +static PHP_METHOD(Phalcon_Cache_Backend_Memcache, queryKeys){ - PHALCON_GET_FOREACH_VALUE(join); + zval *prefix = NULL, *memcache = NULL, *options, *special_key; + zval *keys, *prefixed_keys, *ttl = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, join, SS("type"), 276192743UL, PH_NOISY); + PHALCON_MM_GROW(); - PHALCON_OBS_NVAR(table); - phalcon_array_fetch_quick_string(&table, join, SS("source"), 2744839734UL, PH_NOISY); + phalcon_fetch_params(1, 0, 1, &prefix); + + if (!prefix) { + PHALCON_INIT_VAR(prefix); + } + + PHALCON_OBS_VAR(memcache); + phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); + if (Z_TYPE_P(memcache) != IS_OBJECT) { + phalcon_call_method_key(NULL, this_ptr, "_connect", 4074190766UL); + + PHALCON_OBS_NVAR(memcache); + phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); + } + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(special_key); + phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); + + PHALCON_INIT_VAR(keys); + phalcon_call_method_p1_key(keys, memcache, "get", special_key, 2090288933UL); + if (Z_TYPE_P(keys) == IS_ARRAY) { + + PHALCON_INIT_VAR(prefixed_keys); + array_init(prefixed_keys); + + phalcon_is_iterable(keys, &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(ttl); + + if (zend_is_true(prefix)) { + if (!phalcon_start_with(key, prefix, NULL)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } + phalcon_array_append(&prefixed_keys, key, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_CTOR(prefixed_keys); + } + + RETURN_MM_EMPTY_ARRAY(); +} - PHALCON_INIT_NVAR(sql_table); - phalcon_call_method_p2_key(sql_table, this_ptr, "getsqltable", table, escape_char, 2837135293UL); - phalcon_array_append(&selected_tables, sql_table, PH_SEPARATE); +static PHP_METHOD(Phalcon_Cache_Backend_Memcache, exists){ - PHALCON_INIT_NVAR(sql_join); - PHALCON_CONCAT_SVSV(sql_join, " ", type, " JOIN ", sql_table); + zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *memcache = NULL; + zval *cache_exists; - if (phalcon_array_isset_quick_string(join, SS("conditions"), 1055696255UL)) { + PHALCON_MM_GROW(); - PHALCON_OBS_NVAR(join_conditions_array); - phalcon_array_fetch_quick_string(&join_conditions_array, join, SS("conditions"), 1055696255UL, PH_NOISY); - if (phalcon_fast_count_ev(join_conditions_array TSRMLS_CC)) { + phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); + + if (!key_name) { + PHALCON_INIT_VAR(key_name); + } + + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); + } + + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); + } else { + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_VV(last_key, prefix, key_name); + } + if (zend_is_true(last_key)) { + + PHALCON_OBS_VAR(memcache); + phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); + if (Z_TYPE_P(memcache) != IS_OBJECT) { + phalcon_call_method_key(NULL, this_ptr, "_connect", 4074190766UL); + + PHALCON_OBS_NVAR(memcache); + phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); + } + + PHALCON_INIT_VAR(cache_exists); + phalcon_call_method_p1_key(cache_exists, memcache, "get", last_key, 2090288933UL); + if (PHALCON_IS_NOT_FALSE(cache_exists)) { + RETURN_MM_TRUE; + } + } + + RETURN_MM_FALSE; +} - PHALCON_INIT_NVAR(join_expressions); - array_init(join_expressions); - if (!phalcon_is_iterable_ex(join_conditions_array, &ah3, &hp3, 0, 0)) { - return; - } - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - PHALCON_GET_FOREACH_VALUE(join_condition); - PHALCON_INIT_NVAR(join_expression); - phalcon_call_method_p2_key(join_expression, this_ptr, "getsqlexpression", join_condition, escape_char, 3377787077UL); - phalcon_array_append(&join_expressions, join_expression, PH_SEPARATE); +#ifdef HAVE_CONFIG_H +#endif - zend_hash_move_forward_ex(ah3, &hp3); - } - PHALCON_INIT_NVAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), join_expressions TSRMLS_CC); - PHALCON_SCONCAT_SV(sql_join, " ON ", join_conditions); - } - } - phalcon_concat_self(&sql, sql_join TSRMLS_CC); - zend_hash_move_forward_ex(ah2, &hp2); - } - } - if (phalcon_array_isset_quick_string(definition, SS("where"), 621293632UL)) { - PHALCON_OBS_VAR(where_conditions); - phalcon_array_fetch_quick_string(&where_conditions, definition, SS("where"), 621293632UL, PH_NOISY); - if (Z_TYPE_P(where_conditions) == IS_ARRAY) { - PHALCON_INIT_VAR(where_expression); - phalcon_call_method_p2_key(where_expression, this_ptr, "getsqlexpression", where_conditions, escape_char, 3377787077UL); - PHALCON_SCONCAT_SV(sql, " WHERE ", where_expression); - } else { - PHALCON_SCONCAT_SV(sql, " WHERE ", where_conditions); - } - } +PHALCON_INIT_CLASS(Phalcon_Cache_Backend_Memory){ - if (phalcon_array_isset_quick_string(definition, SS("group"), 7349554UL)) { + PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, Memory, cache_backend_memory, "phalcon\\cache\\backend", phalcon_cache_backend_memory_method_entry, 0); - PHALCON_INIT_VAR(group_items); - array_init(group_items); + zend_declare_property_null(phalcon_cache_backend_memory_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); - PHALCON_OBS_VAR(group_fields); - phalcon_array_fetch_quick_string(&group_fields, definition, SS("group"), 7349554UL, PH_NOISY); + zend_class_implements(phalcon_cache_backend_memory_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); - if (!phalcon_is_iterable_ex(group_fields, &ah4, &hp4, 0, 0)) { - return; - } + return SUCCESS; +} - while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { +static PHP_METHOD(Phalcon_Cache_Backend_Memory, get){ - PHALCON_GET_FOREACH_VALUE(group_field); + zval *key_name, *lifetime = NULL, *last_key = NULL, *prefix, *data; + zval *cached_content, *frontend; - PHALCON_INIT_NVAR(group_expression); - phalcon_call_method_p2_key(group_expression, this_ptr, "getsqlexpression", group_field, escape_char, 3377787077UL); - phalcon_array_append(&group_items, group_expression, PH_SEPARATE); - - zend_hash_move_forward_ex(ah4, &hp4); - } - - PHALCON_INIT_VAR(group_sql); - phalcon_fast_join_str(group_sql, SL(", "), group_items TSRMLS_CC); - - PHALCON_INIT_VAR(group_clause); - PHALCON_CONCAT_SV(group_clause, " GROUP BY ", group_sql); - phalcon_concat_self(&sql, group_clause TSRMLS_CC); - - if (phalcon_array_isset_quick_string(definition, SS("having"), 876572994UL)) { - PHALCON_OBS_VAR(having_conditions); - phalcon_array_fetch_quick_string(&having_conditions, definition, SS("having"), 876572994UL, PH_NOISY); + PHALCON_MM_GROW(); - PHALCON_INIT_VAR(having_expression); - phalcon_call_method_p2_key(having_expression, this_ptr, "getsqlexpression", having_conditions, escape_char, 3377787077UL); - PHALCON_SCONCAT_SV(sql, " HAVING ", having_expression); - } + phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); + + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } - - if (phalcon_array_isset_quick_string(definition, SS("order"), 320020033UL)) { - - PHALCON_OBS_VAR(order_fields); - phalcon_array_fetch_quick_string(&order_fields, definition, SS("order"), 320020033UL, PH_NOISY); - - PHALCON_INIT_VAR(order_items); - array_init(order_items); - - if (!phalcon_is_iterable_ex(order_fields, &ah5, &hp5, 0, 0)) { - return; - } - - while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { - - PHALCON_GET_FOREACH_VALUE(order_item); - - PHALCON_OBS_NVAR(order_expression); - phalcon_array_fetch_long(&order_expression, order_item, 0, PH_NOISY); - - PHALCON_INIT_NVAR(order_sql_item); - phalcon_call_method_p2_key(order_sql_item, this_ptr, "getsqlexpression", order_expression, escape_char, 3377787077UL); - - if (phalcon_array_isset_long(order_item, 1)) { - PHALCON_OBS_NVAR(sql_order_type); - phalcon_array_fetch_long(&sql_order_type, order_item, 1, PH_NOISY); - - PHALCON_INIT_NVAR(order_sql_item_type); - PHALCON_CONCAT_VSV(order_sql_item_type, order_sql_item, " ", sql_order_type); - } else { - PHALCON_CPY_WRT(order_sql_item_type, order_sql_item); - } - - phalcon_array_append(&order_items, order_sql_item_type, PH_SEPARATE); - - zend_hash_move_forward_ex(ah5, &hp5); - } - - PHALCON_INIT_VAR(order_sql); - phalcon_fast_join_str(order_sql, SL(", "), order_items TSRMLS_CC); - PHALCON_SCONCAT_SV(sql, " ORDER BY ", order_sql); + + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); + } else { + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_VV(last_key, prefix, key_name); } - - if (phalcon_array_isset_quick_string(definition, SS("limit"), 192268420UL)) { - - PHALCON_OBS_VAR(limit_value); - phalcon_array_fetch_quick_string(&limit_value, definition, SS("limit"), 192268420UL, PH_NOISY); - - if (Z_TYPE_P(limit_value) == IS_ARRAY) { - - PHALCON_OBS_VAR(number); - phalcon_array_fetch_quick_string(&number, limit_value, SS("number"), 807219790UL, PH_NOISY); - - if (phalcon_array_isset_quick_string(limit_value, SS("offset"), 1503966412UL)) { - PHALCON_OBS_VAR(offset); - phalcon_array_fetch_quick_string(&offset, limit_value, SS("offset"), 1503966412UL, PH_NOISY); - } else { - PHALCON_INIT_VAR(offset); - ZVAL_LONG(offset, 0); - } - - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - PHALCON_INIT_VAR(ini_range); - phalcon_add_function(ini_range, offset, one TSRMLS_CC); - - PHALCON_INIT_VAR(end_range); - phalcon_add_function(end_range, offset, number TSRMLS_CC); - - PHALCON_INIT_VAR(sql_limit); - PHALCON_SCONCAT_SVSVSV(sql_limit,"SELECT Z2.* FROM (SELECT Z1.*, ROWNUM DB_ROWNUM FROM ( ", sql, " ) Z1 ) Z2 WHERE Z2.DB_ROWNUM BETWEEN ", ini_range , " AND ", end_range ); - PHALCON_CPY_WRT(sql, sql_limit); - - } else { - - PHALCON_INIT_VAR(offset); - ZVAL_LONG(offset, 0); - - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - PHALCON_INIT_VAR(ini_range); - phalcon_add_function(ini_range, offset, one TSRMLS_CC); - - PHALCON_INIT_VAR(end_range); - phalcon_add_function(end_range, offset, limit_value TSRMLS_CC); - - PHALCON_INIT_VAR(sql_limit); - PHALCON_SCONCAT_SVSVSV(sql_limit,"SELECT Z2.* FROM (SELECT Z1.*, ROWNUM DB_ROWNUM FROM ( ", sql, " ) Z1 ) Z2 WHERE Z2.DB_ROWNUM BETWEEN ", ini_range , " AND ", end_range ); - PHALCON_CPY_WRT(sql, sql_limit); - } + + PHALCON_OBS_VAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + if (!phalcon_array_isset(data, last_key)) { + RETURN_MM_NULL(); } - - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, supportsSavepoints){ - - - RETURN_FALSE; -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, supportsReleaseSavepoints){ - - - RETURN_FALSE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Postgresql){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Postgresql, db_dialect_postgresql, "phalcon\\db\\dialect", phalcon_db_dialect_postgresql_method_entry, 0); - - zend_declare_property_string(phalcon_db_dialect_postgresql_ce, SL("_escapeChar"), "\"", ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_db_dialect_postgresql_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); - - return SUCCESS; + + PHALCON_OBS_VAR(cached_content); + phalcon_array_fetch(&cached_content, data, last_key, PH_NOISY); + if (Z_TYPE_P(cached_content) == IS_NULL) { + RETURN_MM_NULL(); + } + + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, frontend, "afterretrieve", cached_content, 3229641981UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, getColumnDefinition){ +static PHP_METHOD(Phalcon_Cache_Backend_Memory, save){ - zval *column, *size, *column_type, *column_sql = NULL; - zval *scale; + zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; + zval *last_key = NULL, *prefix, *frontend, *cached_content = NULL; + zval *prepared_content, *is_buffering; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &column); + phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - if (Z_TYPE_P(column) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column definition must be an object compatible with Phalcon\\Db\\ColumnInterface"); - return; + if (!key_name) { + PHALCON_INIT_VAR(key_name); } - PHALCON_INIT_VAR(size); - phalcon_call_method_key(size, column, "getsize", 4292672352UL); - - PHALCON_INIT_VAR(column_type); - phalcon_call_method_key(column_type, column, "gettype", 4294422375UL); + if (!content) { + PHALCON_INIT_VAR(content); + } - switch (phalcon_get_intval(column_type)) { + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); + } - case 0: - PHALCON_INIT_VAR(column_sql); - ZVAL_STRING(column_sql, "INT", 1); - break; + if (!stop_buffer) { + PHALCON_INIT_VAR(stop_buffer); + ZVAL_BOOL(stop_buffer, 1); + } - case 1: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "DATE", 1); - break; + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); + } else { + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - case 2: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "CHARACTER VARYING(", size, ")"); - break; + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_VV(last_key, prefix, key_name); + } + if (!zend_is_true(last_key)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); + return; + } - case 3: - PHALCON_INIT_VAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + if (Z_TYPE_P(content) == IS_NULL) { + PHALCON_INIT_VAR(cached_content); + phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); + } else { + PHALCON_CPY_WRT(cached_content, content); + } - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVSVS(column_sql, "NUMERIC(", size, ",", scale, ")"); - break; + PHALCON_INIT_VAR(prepared_content); + phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); + phalcon_update_property_array(this_ptr, SL("_data"), last_key, prepared_content TSRMLS_CC); - case 4: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TIMESTAMP", 1); - break; + PHALCON_INIT_VAR(is_buffering); + phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); + if (PHALCON_IS_TRUE(stop_buffer)) { + phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); + } - case 5: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "CHARACTER(", size, ")"); - break; + if (PHALCON_IS_TRUE(is_buffering)) { + zend_print_zval(cached_content, 0); + } - case 6: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TEXT", 1); - break; + phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); - case 7: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "FLOAT", 1); - break; + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Cache_Backend_Memory, delete){ + + zval *key_name, *prefix, *key, *data; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &key_name); - case 8: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "SMALLINT(1)", 1); - break; + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - default: - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized PostgreSQL data type"); - return; + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_VV(key, prefix, key_name); + PHALCON_OBS_VAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + if (phalcon_array_isset(data, key)) { + phalcon_unset_property_array(this_ptr, SL("_data"), key TSRMLS_CC); + RETURN_MM_TRUE; } - RETURN_CTOR(column_sql); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addColumn){ - - zval *table_name, *schema_name, *column; - - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} +static PHP_METHOD(Phalcon_Cache_Backend_Memory, queryKeys){ -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, modifyColumn){ + zval *prefix = NULL, *keys; - zval *table_name, *schema_name, *column; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); + phalcon_fetch_params(1, 0, 1, &prefix); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropColumn){ - - zval *table_name, *schema_name, *column_name; - - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column_name); + if (!prefix) { + PHALCON_INIT_VAR(prefix); + ZVAL_STRING(prefix, "", 1); + } - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addIndex){ - - zval *table_name, *schema_name, *index; - - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + PHALCON_INIT_VAR(keys); + array_init(keys); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropIndex){ - - zval *table_name, *schema_name, *index_name; - - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} +static PHP_METHOD(Phalcon_Cache_Backend_Memory, exists){ -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addPrimaryKey){ + zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *data; - zval *table_name, *schema_name, *index; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + if (!key_name) { + PHALCON_INIT_VAR(key_name); + } + + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); + } + + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); + } else { + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_VV(last_key, prefix, key_name); + } + if (zend_is_true(last_key)) { + + PHALCON_OBS_VAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + if (phalcon_array_isset(data, last_key)) { + RETURN_MM_TRUE; + } + } + + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropPrimaryKey){ - zval *table_name, *schema_name; - phalcon_fetch_params(0, 2, 0, &table_name, &schema_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addForeignKey){ - zval *table_name, *schema_name, *reference; +#ifdef HAVE_CONFIG_H +#endif - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropForeignKey){ - zval *table_name, *schema_name, *reference_name; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, _getTableOptions){ - zval *definition; - phalcon_fetch_params(0, 1, 0, &definition); - - RETURN_EMPTY_ARRAY(); -} +PHALCON_INIT_CLASS(Phalcon_Cache_Backend_Mongo){ -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, createTable){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, Mongo, cache_backend_mongo, "phalcon\\cache\\backend", phalcon_cache_backend_mongo_method_entry, 0); - zval *table_name, *schema_name, *definition; + zend_declare_property_null(phalcon_cache_backend_mongo_ce, SL("_collection"), ZEND_ACC_PROTECTED TSRMLS_CC); - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &definition); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + zend_class_implements(phalcon_cache_backend_mongo_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropTable){ +static PHP_METHOD(Phalcon_Cache_Backend_Mongo, __construct){ - zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; + zval *frontend, *options = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); + phalcon_fetch_params(1, 1, 1, &frontend, &options); - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if (!options) { + PHALCON_INIT_VAR(options); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(table); - PHALCON_CONCAT_VSV(table, schema_name, ".", table_name); - } else { - PHALCON_CPY_WRT(table, table_name); - } - if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SV(sql, "DROP TABLE IF EXISTS ", table); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DROP TABLE ", table); + if (!phalcon_array_isset_quick_string(options, SS("mongo"), 238552933UL)) { + if (!phalcon_array_isset_quick_string(options, SS("server"), 2350074396UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'server' is required"); + return; + } } - - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, createView){ - - zval *view_name, *definition, *schema_name, *view_sql; - zval *view = NULL, *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); - - if (!phalcon_array_isset_quick_string(definition, SS("sql"), 2090732981UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'sql' is required in the definition array"); + if (!phalcon_array_isset_quick_string(options, SS("db"), 193489131UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'db' is required"); return; } - PHALCON_OBS_VAR(view_sql); - phalcon_array_fetch_quick_string(&view_sql, definition, SS("sql"), 2090732981UL, PH_NOISY); - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(view); - PHALCON_CONCAT_VSV(view, view_name, ".", schema_name); - } else { - PHALCON_CPY_WRT(view, view_name); + if (!phalcon_array_isset_quick_string(options, SS("collection"), 1563790257UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'collection' is required"); + return; } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); + PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\Mongo", "__construct", frontend, options); - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropView){ +static PHP_METHOD(Phalcon_Cache_Backend_Mongo, _getCollection){ - zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; - zval *sql = NULL; + zval *mongo_collection = NULL, *options, *mongo = NULL, *server; + zval *database, *collection, *mongo_database; + zend_class_entry *ce0; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); - - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); - } + PHALCON_OBS_VAR(mongo_collection); + phalcon_read_property_this_quick(&mongo_collection, this_ptr, SL("_collection"), 4106104656UL, PH_NOISY_CC); + if (Z_TYPE_P(mongo_collection) != IS_OBJECT) { - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(view); - PHALCON_CONCAT_VSV(view, view_name, ".", schema_name); - } else { - PHALCON_CPY_WRT(view, view_name); - } - if (zend_is_true(if_exists)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SV(sql, "DROP VIEW IF EXISTS ", view); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DROP VIEW ", view); + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + + if (phalcon_array_isset_quick_string(options, SS("mongo"), 238552933UL)) { + + PHALCON_OBS_VAR(mongo); + phalcon_array_fetch_quick_string(&mongo, options, SS("mongo"), 238552933UL, PH_NOISY); + if (Z_TYPE_P(mongo) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The 'mongo' parameter must be a valid Mongo instance"); + return; + } + } else { + PHALCON_OBS_VAR(server); + phalcon_array_fetch_quick_string(&server, options, SS("server"), 2350074396UL, PH_NOISY); + if (Z_TYPE_P(server) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB connection string"); + return; + } + + ce0 = zend_fetch_class(SL("Mongo"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + + PHALCON_INIT_NVAR(mongo); + object_init_ex(mongo, ce0); + if (phalcon_has_constructor(mongo TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, mongo, "__construct", server, 1107214344UL); + } + } + + PHALCON_OBS_VAR(database); + phalcon_array_fetch_quick_string(&database, options, SS("db"), 193489131UL, PH_NOISY); + if (Z_TYPE_P(database) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB db"); + return; + } + + PHALCON_OBS_VAR(collection); + phalcon_array_fetch_quick_string(&collection, options, SS("collection"), 1563790257UL, PH_NOISY); + if (Z_TYPE_P(collection) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB collection"); + return; + } + + PHALCON_INIT_VAR(mongo_database); + phalcon_call_method_p1_key(mongo_database, mongo, "selectdb", database, 3899113387UL); + + PHALCON_INIT_NVAR(mongo_collection); + phalcon_call_method_p1_key(mongo_collection, mongo_database, "selectcollection", collection, 3563037297UL); } - RETURN_CTOR(sql); + RETURN_CCTOR(mongo_collection); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, tableExists){ +static PHP_METHOD(Phalcon_Cache_Backend_Mongo, get){ - zval *table_name, *schema_name = NULL, *sql = NULL; + zval *key_name, *lifetime = NULL, *frontend, *prefix, *prefixed_key; + zval *collection, *conditions, *document, *timestamp; + zval *ttl = NULL, *modified_time, *difference, *not_expired; + zval *cached_content; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); + } else { + PHALCON_SEPARATE_PARAM(lifetime); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM information_schema.tables WHERE table_schema = '", schema_name, "' AND table_name='", table_name, "'"); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM information_schema.tables WHERE table_schema = 'public' AND table_name='", table_name, "'"); + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(prefixed_key); + PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); + phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), prefixed_key, 394299009UL TSRMLS_CC); + + PHALCON_INIT_VAR(collection); + phalcon_call_method_key(collection, this_ptr, "_getcollection", 4161728624UL); + + PHALCON_INIT_VAR(conditions); + array_init_size(conditions, 1); + phalcon_array_update_quick_string(&conditions, SS("key"), 2090432846UL, &prefixed_key, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(document); + phalcon_call_method_p1_key(document, collection, "findone", conditions, 947441000UL); + if (Z_TYPE_P(document) == IS_ARRAY) { + + PHALCON_INIT_VAR(timestamp); + ZVAL_LONG(timestamp, (long) time(NULL)); + + if (Z_TYPE_P(lifetime) == IS_NULL) { + + PHALCON_OBS_NVAR(lifetime); + phalcon_read_property_this_quick(&lifetime, this_ptr, SL("_lastLifetime"), 3936785351UL, PH_NOISY_CC); + if (Z_TYPE_P(lifetime) == IS_NULL) { + PHALCON_INIT_VAR(ttl); + phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); + } else { + PHALCON_CPY_WRT(ttl, lifetime); + } + } else { + PHALCON_CPY_WRT(ttl, lifetime); + } + + if (!phalcon_array_isset_quick_string(document, SS("time"), 275614484UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache is currupted"); + return; + } + + PHALCON_OBS_VAR(modified_time); + phalcon_array_fetch_quick_string(&modified_time, document, SS("time"), 275614484UL, PH_NOISY); + + PHALCON_INIT_VAR(difference); + sub_function(difference, timestamp, ttl TSRMLS_CC); + + PHALCON_INIT_VAR(not_expired); + is_smaller_function(not_expired, difference, modified_time TSRMLS_CC); + + if (PHALCON_IS_TRUE(not_expired)) { + if (!phalcon_array_isset_quick_string(document, SS("data"), 256359743UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache is currupted"); + return; + } + + PHALCON_OBS_VAR(cached_content); + phalcon_array_fetch_quick_string(&cached_content, document, SS("data"), 256359743UL, PH_NOISY); + phalcon_call_method_p1_key(return_value, frontend, "afterretrieve", cached_content, 3229641981UL); + RETURN_MM(); + } } - RETURN_CTOR(sql); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, viewExists){ +static PHP_METHOD(Phalcon_Cache_Backend_Mongo, save){ - zval *view_name, *schema_name = NULL, *sql = NULL; + zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; + zval *last_key = NULL, *prefix, *frontend, *cached_content = NULL; + zval *prepared_content, *ttl = NULL, *collection, *timestamp; + zval *conditions, *document, *data, *is_buffering; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!key_name) { + PHALCON_INIT_VAR(key_name); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM pg_views WHERE viewname='", view_name, "' AND schemaname='", schema_name, "'"); + if (!content) { + PHALCON_INIT_VAR(content); + } + + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); + } + + if (!stop_buffer) { + PHALCON_INIT_VAR(stop_buffer); + ZVAL_BOOL(stop_buffer, 1); + } + + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM pg_views WHERE viewname='", view_name, "'"); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_VV(last_key, prefix, key_name); + } + if (!zend_is_true(last_key)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); + return; } - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, describeColumns){ - - zval *table, *schema = NULL, *sql = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + if (Z_TYPE_P(content) == IS_NULL) { + PHALCON_INIT_VAR(cached_content); + phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); + } else { + PHALCON_CPY_WRT(cached_content, content); + } - if (!schema) { - PHALCON_INIT_VAR(schema); + PHALCON_INIT_VAR(prepared_content); + phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); + if (Z_TYPE_P(lifetime) == IS_NULL) { + PHALCON_INIT_VAR(ttl); + phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); + } else { + PHALCON_CPY_WRT(ttl, lifetime); } - if (zend_is_true(schema)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "SELECT DISTINCT c.column_name AS Field, c.data_type AS Type, c.character_maximum_length AS Size, c.numeric_precision AS NumericSize, c.is_nullable AS Null, CASE WHEN pkc.column_name NOTNULL THEN 'PRI' ELSE '' END AS Key, CASE WHEN c.data_type LIKE '%int%' AND c.column_default LIKE '%nextval%' THEN 'auto_increment' ELSE '' END AS Extra, c.ordinal_position AS Position FROM information_schema.columns c LEFT JOIN ( SELECT kcu.column_name, kcu.table_name, kcu.table_schema FROM information_schema.table_constraints tc INNER JOIN information_schema.key_column_usage kcu on (kcu.constraint_name = tc.constraint_name and kcu.table_name=tc.table_name and kcu.table_schema=tc.table_schema) WHERE tc.constraint_type='PRIMARY KEY') pkc ON (c.column_name=pkc.column_name AND c.table_schema = pkc.table_schema AND c.table_name=pkc.table_name) WHERE c.table_schema='", schema, "' AND c.table_name='", table, "' ORDER BY c.ordinal_position"); + PHALCON_INIT_VAR(collection); + phalcon_call_method_key(collection, this_ptr, "_getcollection", 4161728624UL); + + PHALCON_INIT_VAR(timestamp); + ZVAL_LONG(timestamp, (long) time(NULL)); + + PHALCON_INIT_NVAR(ttl); + phalcon_add_function(ttl, lifetime, timestamp TSRMLS_CC); + + PHALCON_INIT_VAR(conditions); + array_init_size(conditions, 1); + phalcon_array_update_quick_string(&conditions, SS("key"), 2090432846UL, &last_key, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(document); + phalcon_call_method_p1_key(document, collection, "findone", conditions, 947441000UL); + if (Z_TYPE_P(document) == IS_ARRAY) { + phalcon_array_update_quick_string(&document, SS("time"), 275614484UL, &ttl, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&document, SS("data"), 256359743UL, &prepared_content, PH_COPY | PH_SEPARATE); + phalcon_call_method_p1_key(NULL, collection, "save", document, 274150868UL); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT DISTINCT c.column_name AS Field, c.data_type AS Type, c.character_maximum_length AS Size, c.numeric_precision AS NumericSize, c.is_nullable AS Null, CASE WHEN pkc.column_name NOTNULL THEN 'PRI' ELSE '' END AS Key, CASE WHEN c.data_type LIKE '%int%' AND c.column_default LIKE '%nextval%' THEN 'auto_increment' ELSE '' END AS Extra, c.ordinal_position AS Position FROM information_schema.columns c LEFT JOIN ( SELECT kcu.column_name, kcu.table_name, kcu.table_schema FROM information_schema.table_constraints tc INNER JOIN information_schema.key_column_usage kcu on (kcu.constraint_name = tc.constraint_name and kcu.table_name=tc.table_name and kcu.table_schema=tc.table_schema) WHERE tc.constraint_type='PRIMARY KEY') pkc ON (c.column_name=pkc.column_name AND c.table_schema = pkc.table_schema AND c.table_name=pkc.table_name) WHERE c.table_schema='public' AND c.table_name='", table, "' ORDER BY c.ordinal_position"); + PHALCON_INIT_VAR(data); + array_init_size(data, 3); + phalcon_array_update_quick_string(&data, SS("key"), 2090432846UL, &last_key, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("time"), 275614484UL, &ttl, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("data"), 256359743UL, &prepared_content, PH_COPY | PH_SEPARATE); + phalcon_call_method_p1_key(NULL, collection, "save", data, 274150868UL); } - RETURN_CTOR(sql); + PHALCON_INIT_VAR(is_buffering); + phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); + if (PHALCON_IS_TRUE(stop_buffer)) { + phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); + } + + if (PHALCON_IS_TRUE(is_buffering)) { + zend_print_zval(cached_content, 0); + } + + phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, listTables){ +static PHP_METHOD(Phalcon_Cache_Backend_Mongo, delete){ - zval *schema_name = NULL, *sql = NULL; + zval *key_name, *prefix, *prefixed_key, *collection; + zval *conditions; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(1, 1, 0, &key_name); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT table_name FROM information_schema.tables WHERE table_schema = '", schema_name, "' ORDER BY table_name"); - } else { - PHALCON_INIT_NVAR(sql); - ZVAL_STRING(sql, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name", 1); - } + PHALCON_INIT_VAR(prefixed_key); + PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); - RETURN_CTOR(sql); + PHALCON_INIT_VAR(collection); + phalcon_call_method_key(collection, this_ptr, "_getcollection", 4161728624UL); + + PHALCON_INIT_VAR(conditions); + array_init_size(conditions, 1); + phalcon_array_update_quick_string(&conditions, SS("key"), 2090432846UL, &prefixed_key, PH_COPY | PH_SEPARATE); + phalcon_call_method_p1_key(NULL, collection, "remove", conditions, 1052443347UL); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, listViews){ +static PHP_METHOD(Phalcon_Cache_Backend_Mongo, queryKeys){ - zval *schema_name = NULL, *sql = NULL; + zval *prefix = NULL, *collection, *fields = NULL, *pattern, *regex; + zval *conditions = NULL, *documents, *keys, *documents_array; + zval *document = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + zend_class_entry *ce0; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(1, 0, 1, &prefix); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!prefix) { + PHALCON_INIT_VAR(prefix); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT viewname AS view_name FROM pg_views WHERE schemaname = '", schema_name, "' ORDER BY view_name"); + PHALCON_INIT_VAR(collection); + phalcon_call_method_key(collection, this_ptr, "_getcollection", 4161728624UL); + + PHALCON_INIT_VAR(fields); + array_init_size(fields, 1); + add_next_index_stringl(fields, SL("key"), 1); + if (Z_TYPE_P(prefix) != IS_NULL) { + PHALCON_INIT_VAR(pattern); + PHALCON_CONCAT_SVS(pattern, "/^", prefix, "/"); + ce0 = zend_fetch_class(SL("MongoRegex"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + + PHALCON_INIT_VAR(regex); + object_init_ex(regex, ce0); + if (phalcon_has_constructor(regex TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, regex, "__construct", pattern, 1107214344UL); + } + + PHALCON_INIT_VAR(conditions); + array_init_size(conditions, 1); + phalcon_array_update_quick_string(&conditions, SS("key"), 2090432846UL, ®ex, PH_COPY | PH_SEPARATE); } else { - PHALCON_INIT_NVAR(sql); - ZVAL_STRING(sql, "SELECT viewname AS view_name FROM pg_views WHERE schemaname = 'public' ORDER BY view_name", 1); + PHALCON_INIT_NVAR(conditions); + array_init(conditions); } - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, describeIndexes){ - - zval *table, *schema = NULL, *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); + PHALCON_INIT_NVAR(fields); + array_init_size(fields, 1); + add_next_index_stringl(fields, SL("key"), 1); - if (!schema) { - PHALCON_INIT_VAR(schema); + PHALCON_INIT_VAR(documents); + phalcon_call_method_p2_key(documents, collection, "find", conditions, fields, 259012646UL); + + PHALCON_INIT_VAR(keys); + array_init(keys); + + PHALCON_INIT_VAR(documents_array); + phalcon_call_func_p1(documents_array, "iterator_to_array", documents); + + 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_OBS_NVAR(key); + phalcon_array_fetch_quick_string(&key, document, SS("key"), 2090432846UL, PH_NOISY); + phalcon_array_append(&keys, key, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT 0 as c0, t.relname as table_name, i.relname as key_name, 3 as c3, a.attname as column_name FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND a.attnum = ANY(ix.indkey) AND t.relkind = 'r' AND t.relname = '", table, "' ORDER BY t.relname, i.relname;"); - RETURN_CTOR(sql); + RETURN_CTOR(keys); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, describeReferences){ +static PHP_METHOD(Phalcon_Cache_Backend_Mongo, exists){ - zval *table, *schema = NULL, *sql; + zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *collection; + zval *conditions, *number, *zero; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (!key_name) { + PHALCON_INIT_VAR(key_name); } - PHALCON_INIT_VAR(sql); - ZVAL_STRING(sql, "SELECT tc.table_name as TABLE_NAME, kcu.column_name as COLUMN_NAME, tc.constraint_name as CONSTRAINT_NAME, tc.table_catalog as REFERENCED_TABLE_SCHEMA, ccu.table_name AS REFERENCED_TABLE_NAME, ccu.column_name AS REFERENCED_COLUMN_NAME FROM information_schema.table_constraints AS tc JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name WHERE constraint_type = 'FOREIGN KEY' AND ", 1); - if (zend_is_true(schema)) { - PHALCON_SCONCAT_SVSVS(sql, "tc.table_schema = '", schema, "' AND tc.table_name='", table, "'"); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); + } + + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); } else { - PHALCON_SCONCAT_SVS(sql, "tc.table_name='", table, "'"); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_VV(last_key, prefix, key_name); } + if (zend_is_true(last_key)) { + PHALCON_INIT_VAR(collection); + phalcon_call_method_key(collection, this_ptr, "_getcollection", 4161728624UL); - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, tableOptions){ - - zval *table, *schema = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); + PHALCON_INIT_VAR(conditions); + array_init_size(conditions, 1); + phalcon_array_update_quick_string(&conditions, SS("key"), 2090432846UL, &last_key, PH_COPY | PH_SEPARATE); - if (!schema) { - PHALCON_INIT_VAR(schema); + PHALCON_INIT_VAR(number); + phalcon_call_method_p1_key(number, collection, "count", conditions, 4142425646UL); + + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + is_smaller_function(return_value, zero, number TSRMLS_CC); + RETURN_MM(); } - RETURN_MM_EMPTY_STRING(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Db_IndexInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, IndexInterface, db_indexinterface, phalcon_db_indexinterface_method_entry); - - return SUCCESS; + RETURN_MM_FALSE; } - - - - #ifdef HAVE_CONFIG_H #endif @@ -20444,1425 +20917,891 @@ PHALCON_INIT_CLASS(Phalcon_Db_IndexInterface){ -PHALCON_INIT_CLASS(Phalcon_Db_Adapter){ - - PHALCON_REGISTER_CLASS(Phalcon\\Db, Adapter, db_adapter, phalcon_db_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); +PHALCON_INIT_CLASS(Phalcon_Cache_Backend_Xcache){ - zend_declare_property_null(phalcon_db_adapter_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_adapter_ce, SL("_descriptor"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_adapter_ce, SL("_dialectType"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_adapter_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_adapter_ce, SL("_dialect"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_adapter_ce, SL("_connectionId"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_adapter_ce, SL("_sqlStatement"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_adapter_ce, SL("_sqlVariables"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_adapter_ce, SL("_sqlBindTypes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_db_adapter_ce, SL("_transactionLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_db_adapter_ce, SL("_transactionsWithSavepoints"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_db_adapter_ce, SL("_connectionConsecutive"), 0, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, Xcache, cache_backend_xcache, "phalcon\\cache\\backend", phalcon_cache_backend_xcache_method_entry, 0); - zend_class_implements(phalcon_db_adapter_ce TSRMLS_CC, 1, phalcon_events_eventsawareinterface_ce); + zend_class_implements(phalcon_cache_backend_xcache_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter, __construct){ +static PHP_METHOD(Phalcon_Cache_Backend_Xcache, __construct){ - zval *descriptor, *one, *connection_consecutive; - zval *next_consecutive, *dialect_type, *dialect_class = NULL; - zval *dialect_object; - zend_class_entry *ce0; + zval *frontend, *options = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &descriptor); - - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - PHALCON_OBS_VAR(connection_consecutive); - phalcon_read_static_property(&connection_consecutive, SL("phalcon\\db\\adapter"), SL("_connectionConsecutive") TSRMLS_CC); - - PHALCON_INIT_VAR(next_consecutive); - phalcon_add_function(next_consecutive, connection_consecutive, one TSRMLS_CC); - phalcon_update_static_property(SL("phalcon\\db\\adapter"), SL("_connectionConsecutive"), next_consecutive TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_connectionId"), connection_consecutive, 802624385UL TSRMLS_CC); - - if (!phalcon_array_isset_quick_string(descriptor, SS("dialectClass"), 2526466321UL)) { - PHALCON_OBS_VAR(dialect_type); - phalcon_read_property_this_quick(&dialect_type, this_ptr, SL("_dialectType"), 1868597628UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 1, &frontend, &options); - PHALCON_INIT_VAR(dialect_class); - PHALCON_CONCAT_SV(dialect_class, "phalcon\\db\\dialect\\", dialect_type); + if (!options) { + PHALCON_INIT_VAR(options); } else { - PHALCON_OBS_NVAR(dialect_class); - phalcon_array_fetch_quick_string(&dialect_class, descriptor, SS("dialectClass"), 2526466321UL, PH_NOISY); + PHALCON_SEPARATE_PARAM(options); } - if (likely(Z_TYPE_P(dialect_class) == IS_STRING)) { - ce0 = phalcon_fetch_class(dialect_class TSRMLS_CC); - PHALCON_INIT_VAR(dialect_object); - object_init_ex(dialect_object, ce0); - if (phalcon_has_constructor(dialect_object TSRMLS_CC)) { - phalcon_call_method_key(NULL, dialect_object, "__construct", 1107214344UL); - } - phalcon_update_property_this_quick(this_ptr, SL("_dialect"), dialect_object, 4072955610UL TSRMLS_CC); + if (Z_TYPE_P(options) != IS_ARRAY) { + PHALCON_INIT_NVAR(options); + array_init(options); + } + if (!phalcon_array_isset_quick_string(options, SS("statsKey"), 2508919229UL)) { + phalcon_array_update_string_string(&options, SL("statsKey"), SL("_PHCX"), PH_SEPARATE); } - phalcon_update_property_this_quick(this_ptr, SL("_descriptor"), descriptor, 691635363UL TSRMLS_CC); + PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\Xcache", "__construct", frontend, options); PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter, setEventsManager){ - - zval *events_manager; - - phalcon_fetch_params(0, 1, 0, &events_manager); - - phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Db_Adapter, getEventsManager){ - - - RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); -} - -static PHP_METHOD(Phalcon_Db_Adapter, setDialect){ - - zval *dialect; - - phalcon_fetch_params(0, 1, 0, &dialect); - - phalcon_update_property_this_quick(this_ptr, SL("_dialect"), dialect, 4072955610UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Db_Adapter, getDialect){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dialect", 4072955610UL); -} - -static PHP_METHOD(Phalcon_Db_Adapter, fetchOne){ +static PHP_METHOD(Phalcon_Cache_Backend_Xcache, get){ - zval *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL; - zval *result; + zval *key_name, *lifetime = NULL, *frontend, *prefix, *prefixed_key; + zval *cached_content; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 3, &sql_query, &fetch_mode, &bind_params, &bind_types); + phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - if (!fetch_mode) { - PHALCON_INIT_VAR(fetch_mode); - ZVAL_LONG(fetch_mode, 2); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - PHALCON_INIT_VAR(result); - phalcon_call_method_p3_key(result, this_ptr, "query", sql_query, bind_params, bind_types, 401898907UL); - if (Z_TYPE_P(result) == IS_OBJECT) { - if (Z_TYPE_P(fetch_mode) != IS_NULL) { - phalcon_call_method_p1_key(NULL, result, "setfetchmode", fetch_mode, 824603840UL); - } - phalcon_call_method_key(return_value, result, "fetch", 4247924303UL); - RETURN_MM(); + PHALCON_INIT_VAR(prefixed_key); + PHALCON_CONCAT_SVV(prefixed_key, "_PHCX", prefix, key_name); + phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), prefixed_key, 394299009UL TSRMLS_CC); + + PHALCON_INIT_VAR(cached_content); + phalcon_call_func_p1(cached_content, "xcache_get", prefixed_key); + if (Z_TYPE_P(cached_content) == IS_NULL) { + RETURN_MM_NULL(); } - RETURN_MM_EMPTY_ARRAY(); + phalcon_call_method_p1_key(return_value, frontend, "afterretrieve", cached_content, 3229641981UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, fetchAll){ +static PHP_METHOD(Phalcon_Cache_Backend_Xcache, save){ - zval *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL; - zval *results, *result, *row = NULL; - zval *r0 = NULL; + zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; + zval *last_key = NULL, *prefix, *frontend, *cached_content = NULL; + zval *prepared_content, *ttl = NULL, *success, *is_buffering; + zval *options, *special_key, *keys = NULL, *zero; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 3, &sql_query, &fetch_mode, &bind_params, &bind_types); + phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - if (!fetch_mode) { - PHALCON_INIT_VAR(fetch_mode); - ZVAL_LONG(fetch_mode, 2); + if (!key_name) { + PHALCON_INIT_VAR(key_name); } - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + if (!content) { + PHALCON_INIT_VAR(content); } - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } - PHALCON_INIT_VAR(results); - array_init(results); - - PHALCON_INIT_VAR(result); - phalcon_call_method_p3_key(result, this_ptr, "query", sql_query, bind_params, bind_types, 401898907UL); - if (likely(Z_TYPE_P(result) == IS_OBJECT)) { - if (Z_TYPE_P(fetch_mode) != IS_NULL) { - phalcon_call_method_p1_key(NULL, result, "setfetchmode", fetch_mode, 824603840UL); - } - - while (1) { - - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, result, "fetch", 4247924303UL); - PHALCON_CPY_WRT(row, r0); - if (zend_is_true(row)) { - } else { - break; - } - - phalcon_array_append(&results, row, PH_SEPARATE); - } + if (!stop_buffer) { + PHALCON_INIT_VAR(stop_buffer); + ZVAL_BOOL(stop_buffer, 1); } - RETURN_CTOR(results); -} - -static PHP_METHOD(Phalcon_Db_Adapter, insert){ - - zval *table, *values, *fields = NULL, *data_types = NULL, *exception_message; - zval *placeholders, *insert_values, *bind_data_types = NULL; - zval *value = NULL, *position = NULL, *str_value = NULL, *bind_type = NULL; - zval *escaped_table = NULL, *joined_values, *escaped_fields = NULL; - zval *field = NULL, *escaped_field = NULL, *joined_fields; - zval *insert_sql = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 2, &table, &values, &fields, &data_types); - - if (!fields) { - PHALCON_INIT_VAR(fields); - } + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); + } else { + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - if (!data_types) { - PHALCON_INIT_VAR(data_types); + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_SVV(last_key, "_PHCX", prefix, key_name); } - - if (unlikely(Z_TYPE_P(values) != IS_ARRAY)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The second parameter for insert isn't an Array"); + if (!zend_is_true(last_key)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); return; } - if (!phalcon_fast_count_ev(values TSRMLS_CC)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Unable to insert into ", table, " without data"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_db_exception_ce, exception_message); - return; + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + if (Z_TYPE_P(content) == IS_NULL) { + PHALCON_INIT_VAR(cached_content); + phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); + } else { + PHALCON_CPY_WRT(cached_content, content); } - PHALCON_INIT_VAR(placeholders); - array_init(placeholders); + PHALCON_INIT_VAR(prepared_content); + phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); - PHALCON_INIT_VAR(insert_values); - array_init(insert_values); - if (Z_TYPE_P(data_types) == IS_ARRAY) { - PHALCON_INIT_VAR(bind_data_types); - array_init(bind_data_types); + if (Z_TYPE_P(lifetime) == IS_NULL) { + + PHALCON_OBS_NVAR(ttl); + phalcon_read_property_this_quick(&ttl, this_ptr, SL("_lastLifetime"), 3936785351UL, PH_NOISY_CC); + if (Z_TYPE_P(ttl) == IS_NULL) { + PHALCON_INIT_NVAR(ttl); + phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); + } } else { - PHALCON_CPY_WRT(bind_data_types, data_types); + PHALCON_CPY_WRT(ttl, lifetime); } - phalcon_is_iterable(values, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(success); + phalcon_call_func_p3(success, "xcache_set", last_key, prepared_content, ttl); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(is_buffering); + phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); + if (PHALCON_IS_TRUE(stop_buffer)) { + phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); + } - PHALCON_GET_HKEY(position, ah0, hp0); - PHALCON_GET_HVALUE(value); + if (PHALCON_IS_TRUE(is_buffering)) { + zend_print_zval(cached_content, 0); + } - if (Z_TYPE_P(value) == IS_OBJECT) { - PHALCON_INIT_NVAR(str_value); - phalcon_call_func_p1(str_value, "strval", value); - phalcon_array_append(&placeholders, str_value, PH_SEPARATE); - } else { - if (Z_TYPE_P(value) == IS_NULL) { - phalcon_array_append_string(&placeholders, SL("null"), PH_SEPARATE); - } else { - phalcon_array_append_string(&placeholders, SL("?"), PH_SEPARATE); - phalcon_array_append(&insert_values, value, PH_SEPARATE); - if (Z_TYPE_P(data_types) == IS_ARRAY) { - if (!phalcon_array_isset(data_types, position)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Incomplete number of bind types"); - return; - } + phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); - PHALCON_OBS_NVAR(bind_type); - phalcon_array_fetch(&bind_type, data_types, position, PH_NOISY); - phalcon_array_append(&bind_data_types, bind_type, PH_SEPARATE); - } - } - } + if (zend_is_true(success)) { - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(escaped_table); - phalcon_call_method_p1_key(escaped_table, this_ptr, "escapeidentifier", table, 585773337UL); - } else { - PHALCON_CPY_WRT(escaped_table, table); - } + PHALCON_OBS_VAR(special_key); + phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); - PHALCON_INIT_VAR(joined_values); - phalcon_fast_join_str(joined_values, SL(", "), placeholders TSRMLS_CC); - if (Z_TYPE_P(fields) == IS_ARRAY) { - if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(keys); + phalcon_call_func_p1(keys, "xcache_get", special_key); + if (Z_TYPE_P(keys) != IS_ARRAY) { + PHALCON_INIT_NVAR(keys); + array_init(keys); + } - PHALCON_INIT_VAR(escaped_fields); - array_init(escaped_fields); + if (!zend_is_true(keys)) { + phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); - phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); + } + } - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Cache_Backend_Xcache, delete){ + + zval *key_name, *prefix, *prefixed_key, *success; + zval *options, *special_key, *keys, *zero; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &key_name); - PHALCON_GET_HVALUE(field); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(escaped_field); - phalcon_call_method_p1_key(escaped_field, this_ptr, "escapeidentifier", field, 585773337UL); - phalcon_array_append(&escaped_fields, escaped_field, PH_SEPARATE); + PHALCON_INIT_VAR(prefixed_key); + PHALCON_CONCAT_SVV(prefixed_key, "_PHCX", prefix, key_name); - zend_hash_move_forward_ex(ah1, &hp1); - } + PHALCON_INIT_VAR(success); + phalcon_call_func_p1(success, "xcache_unset", prefixed_key); - } else { - PHALCON_CPY_WRT(escaped_fields, fields); - } + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - PHALCON_INIT_VAR(joined_fields); - phalcon_fast_join_str(joined_fields, SL(", "), escaped_fields TSRMLS_CC); + PHALCON_OBS_VAR(special_key); + phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); - PHALCON_INIT_VAR(insert_sql); - PHALCON_CONCAT_SVSVSVS(insert_sql, "INSERT INTO ", escaped_table, " (", joined_fields, ") VALUES (", joined_values, ")"); - } else { - PHALCON_INIT_NVAR(insert_sql); - PHALCON_CONCAT_SVSVS(insert_sql, "INSERT INTO ", escaped_table, " VALUES (", joined_values, ")"); + PHALCON_INIT_VAR(keys); + phalcon_call_func_p1(keys, "xcache_get", special_key); + if (Z_TYPE_P(keys) == IS_ARRAY) { + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + phalcon_array_unset(&keys, special_key, PH_SEPARATE); + phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); } - phalcon_call_method_p3_key(return_value, this_ptr, "execute", insert_sql, insert_values, bind_data_types, 3117639032UL); - RETURN_MM(); + RETURN_CCTOR(success); } -static PHP_METHOD(Phalcon_Db_Adapter, update){ +static PHP_METHOD(Phalcon_Cache_Backend_Xcache, queryKeys){ - zval *table, *fields, *values, *where_condition = NULL; - zval *data_types = NULL, *placeholders, *update_values; - zval *bind_data_types = NULL, *value = NULL, *position = NULL, *field = NULL; - zval *escaped_field = NULL, *set_clause_part = NULL, *bind_type = NULL; - zval *escaped_table = NULL, *set_clause, *update_sql = NULL; - zval *conditions, *where_bind, *where_types; + zval *prefix = NULL, *prefixed, *options, *special_key; + zval *keys, *prefixed_keys, *ttl = NULL, *key = NULL, *real_key = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 2, &table, &fields, &values, &where_condition, &data_types); - - if (!where_condition) { - PHALCON_INIT_VAR(where_condition); - } - - if (!data_types) { - PHALCON_INIT_VAR(data_types); + phalcon_fetch_params(1, 0, 1, &prefix); + + PHALCON_INIT_VAR(prefixed); + if (!prefix) { + ZVAL_STRING(prefixed, "_PHCX", 1); } - - PHALCON_INIT_VAR(placeholders); - array_init(placeholders); - - PHALCON_INIT_VAR(update_values); - array_init(update_values); - if (Z_TYPE_P(data_types) == IS_ARRAY) { - PHALCON_INIT_VAR(bind_data_types); - array_init(bind_data_types); - } else { - PHALCON_CPY_WRT(bind_data_types, data_types); + else { + PHALCON_CONCAT_SV(prefixed, "_PHCX", prefix); } - phalcon_is_iterable(values, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(position, ah0, hp0); - PHALCON_GET_HVALUE(value); - - if (!phalcon_array_isset(fields, position)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The number of values in the update is not the same as fields"); - return; - } - - PHALCON_OBS_NVAR(field); - phalcon_array_fetch(&field, fields, position, PH_NOISY); - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_NVAR(escaped_field); - phalcon_call_method_p1_key(escaped_field, this_ptr, "escapeidentifier", field, 585773337UL); - } else { - PHALCON_CPY_WRT(escaped_field, field); - } - - if (Z_TYPE_P(value) == IS_OBJECT) { - PHALCON_INIT_NVAR(set_clause_part); - PHALCON_CONCAT_VSV(set_clause_part, escaped_field, " = ", value); - phalcon_array_append(&placeholders, set_clause_part, PH_SEPARATE); - } else { - if (Z_TYPE_P(value) == IS_NULL) { - PHALCON_INIT_NVAR(set_clause_part); - PHALCON_CONCAT_VS(set_clause_part, escaped_field, " = null"); - } else { - PHALCON_INIT_NVAR(set_clause_part); - PHALCON_CONCAT_VS(set_clause_part, escaped_field, " = ?"); - phalcon_array_append(&update_values, value, PH_SEPARATE); - if (Z_TYPE_P(data_types) == IS_ARRAY) { - if (!phalcon_array_isset(data_types, position)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Incomplete number of bind types"); - return; - } + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - PHALCON_OBS_NVAR(bind_type); - phalcon_array_fetch(&bind_type, data_types, position, PH_NOISY); - phalcon_array_append(&bind_data_types, bind_type, PH_SEPARATE); - } - } - phalcon_array_append(&placeholders, set_clause_part, PH_SEPARATE); - } + PHALCON_OBS_VAR(special_key); + phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_VAR(keys); + phalcon_call_func_p1(keys, "xcache_get", special_key); + if (Z_TYPE_P(keys) == IS_ARRAY) { - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(escaped_table); - phalcon_call_method_p1_key(escaped_table, this_ptr, "escapeidentifier", table, 585773337UL); - } else { - PHALCON_CPY_WRT(escaped_table, table); - } + PHALCON_INIT_VAR(prefixed_keys); + array_init(prefixed_keys); - PHALCON_INIT_VAR(set_clause); - phalcon_fast_join_str(set_clause, SL(", "), placeholders TSRMLS_CC); - if (Z_TYPE_P(where_condition) != IS_NULL) { + phalcon_is_iterable(keys, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(update_sql); - PHALCON_CONCAT_SVSVS(update_sql, "UPDATE ", escaped_table, " SET ", set_clause, " WHERE "); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (Z_TYPE_P(where_condition) == IS_STRING) { - phalcon_concat_self(&update_sql, where_condition TSRMLS_CC); - } else { - if (unlikely(Z_TYPE_P(where_condition) != IS_ARRAY)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid WHERE clause conditions"); - return; - } + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(ttl); - if (phalcon_array_isset_quick_string(where_condition, SS("conditions"), 1055696255UL)) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_quick_string(&conditions, where_condition, SS("conditions"), 1055696255UL, PH_NOISY); - phalcon_concat_self(&update_sql, conditions TSRMLS_CC); + if (!phalcon_memnstr(key, prefixed)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; } - if (phalcon_array_isset_quick_string(where_condition, SS("bind"), 254268962UL)) { - PHALCON_OBS_VAR(where_bind); - phalcon_array_fetch_quick_string(&where_bind, where_condition, SS("bind"), 254268962UL, PH_NOISY); - phalcon_merge_append(update_values, where_bind); - } + PHALCON_INIT_NVAR(real_key); + phalcon_substr(real_key, key, 5, 0); + phalcon_array_append(&prefixed_keys, real_key, PH_SEPARATE); - if (phalcon_array_isset_quick_string(where_condition, SS("bindTypes"), 3951758359UL)) { - PHALCON_OBS_VAR(where_types); - phalcon_array_fetch_quick_string(&where_types, where_condition, SS("bindTypes"), 3951758359UL, PH_NOISY); - phalcon_merge_append(bind_data_types, where_types); - } + zend_hash_move_forward_ex(ah0, &hp0); } - } else { - PHALCON_INIT_NVAR(update_sql); - PHALCON_CONCAT_SVSV(update_sql, "UPDATE ", escaped_table, " SET ", set_clause); + + RETURN_CTOR(prefixed_keys); } - phalcon_call_method_p3_key(return_value, this_ptr, "execute", update_sql, update_values, bind_data_types, 3117639032UL); - RETURN_MM(); + RETURN_MM_EMPTY_ARRAY(); } -static PHP_METHOD(Phalcon_Db_Adapter, delete){ +static PHP_METHOD(Phalcon_Cache_Backend_Xcache, exists){ - zval *table, *where_condition = NULL, *placeholders = NULL; - zval *data_types = NULL, *escaped_table = NULL, *sql = NULL; + zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *cache_exists; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 3, &table, &where_condition, &placeholders, &data_types); - - if (!where_condition) { - PHALCON_INIT_VAR(where_condition); - } + phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - if (!placeholders) { - PHALCON_INIT_VAR(placeholders); + if (!key_name) { + PHALCON_INIT_VAR(key_name); } - if (!data_types) { - PHALCON_INIT_VAR(data_types); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(escaped_table); - phalcon_call_method_p1_key(escaped_table, this_ptr, "escapeidentifier", table, 585773337UL); + if (Z_TYPE_P(key_name) == IS_NULL) { + PHALCON_OBS_VAR(last_key); + phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); } else { - PHALCON_CPY_WRT(escaped_table, table); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(last_key); + PHALCON_CONCAT_SVV(last_key, "_PHCX", prefix, key_name); } - if (PHALCON_IS_NOT_EMPTY(where_condition)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "DELETE FROM ", escaped_table, " WHERE ", where_condition); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DELETE FROM ", escaped_table); + if (zend_is_true(last_key)) { + + PHALCON_INIT_VAR(cache_exists); + phalcon_call_func_p1(cache_exists, "xcache_isset", last_key); + if (PHALCON_IS_NOT_FALSE(cache_exists)) { + RETURN_MM_TRUE; + } } - phalcon_call_method_p3_key(return_value, this_ptr, "execute", sql, placeholders, data_types, 3117639032UL); - RETURN_MM(); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Adapter, getColumnList){ - - zval *column_list, *dialect; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &column_list); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, dialect, "getcolumnlist", column_list, 2735238095UL); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Db_Adapter, limit){ - zval *sql_query, *number, *dialect; +#ifdef HAVE_CONFIG_H +#endif - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &sql_query, &number); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - phalcon_call_method_p2_key(return_value, dialect, "limit", sql_query, number, 192268420UL); - RETURN_MM(); + + + + + +PHALCON_INIT_CLASS(Phalcon_Cache_Backend){ + + PHALCON_REGISTER_CLASS(Phalcon\\Cache, Backend, cache_backend, phalcon_cache_backend_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_property_null(phalcon_cache_backend_ce, SL("_frontend"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cache_backend_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_cache_backend_ce, SL("_prefix"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_cache_backend_ce, SL("_lastKey"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cache_backend_ce, SL("_lastLifetime"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_cache_backend_ce, SL("_fresh"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_cache_backend_ce, SL("_started"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter, tableExists){ +static PHP_METHOD(Phalcon_Cache_Backend, __construct){ - zval *table_name, *schema_name = NULL, *dialect, *sql; - zval *fetch_num, *num, *first; + zval *frontend, *options = NULL, *prefix; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + phalcon_fetch_params(1, 1, 1, &frontend, &options); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!options) { + PHALCON_INIT_VAR(options); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "tableexists", table_name, schema_name, 1944065613UL); + if (Z_TYPE_P(frontend) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Frontend must be an Object"); + return; + } - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + if (phalcon_array_isset_quick_string(options, SS("prefix"), 3263410483UL)) { + PHALCON_OBS_VAR(prefix); + phalcon_array_fetch_quick_string(&prefix, options, SS("prefix"), 3263410483UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); + } - PHALCON_INIT_VAR(num); - phalcon_call_method_p2_key(num, this_ptr, "fetchone", sql, fetch_num, 1637187313UL); + phalcon_update_property_this_quick(this_ptr, SL("_frontend"), frontend, 3187914628UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - PHALCON_OBS_VAR(first); - phalcon_array_fetch_long(&first, num, 0, PH_NOISY); - RETURN_CCTOR(first); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter, viewExists){ +static PHP_METHOD(Phalcon_Cache_Backend, start){ - zval *view_name, *schema_name = NULL, *dialect, *sql, *fetch_num; - zval *num, *first; + zval *key_name, *lifetime = NULL, *existing_cache, *fresh = NULL; + zval *frontend; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + PHALCON_INIT_VAR(existing_cache); + phalcon_call_method_p2_key(existing_cache, this_ptr, "get", key_name, lifetime, 2090288933UL); + if (Z_TYPE_P(existing_cache) == IS_NULL) { + PHALCON_INIT_VAR(fresh); + ZVAL_BOOL(fresh, 1); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "viewexists", view_name, schema_name, 1384087744UL); + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + phalcon_call_method_key(NULL, frontend, "start", 478839859UL); + } else { + PHALCON_INIT_NVAR(fresh); + ZVAL_BOOL(fresh, 0); + } - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + phalcon_update_property_this_quick(this_ptr, SL("_fresh"), fresh, 2329058172UL TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_started"), 1 TSRMLS_CC); - PHALCON_INIT_VAR(num); - phalcon_call_method_p2_key(num, this_ptr, "fetchone", sql, fetch_num, 1637187313UL); + if (Z_TYPE_P(lifetime) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_lastLifetime"), lifetime, 3936785351UL TSRMLS_CC); + } - PHALCON_OBS_VAR(first); - phalcon_array_fetch_long(&first, num, 0, PH_NOISY); - RETURN_CCTOR(first); + RETURN_CCTOR(existing_cache); } -static PHP_METHOD(Phalcon_Db_Adapter, forUpdate){ +static PHP_METHOD(Phalcon_Cache_Backend, stop){ - zval *sql_query, *dialect; + zval *stop_buffer = NULL, *frontend; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &sql_query); + phalcon_fetch_params(1, 0, 1, &stop_buffer); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, dialect, "forupdate", sql_query, 3289499215UL); - RETURN_MM(); + if (!stop_buffer) { + PHALCON_INIT_VAR(stop_buffer); + ZVAL_BOOL(stop_buffer, 1); + } + + if (PHALCON_IS_TRUE(stop_buffer)) { + PHALCON_OBS_VAR(frontend); + phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); + phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); + } + phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter, sharedLock){ - - zval *sql_query, *dialect; +static PHP_METHOD(Phalcon_Cache_Backend, getFrontend){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &sql_query); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, dialect, "sharedlock", sql_query, 548439429UL); - RETURN_MM(); + RETURN_MEMBER_QUICK(this_ptr, "_frontend", 3187914628UL); } -static PHP_METHOD(Phalcon_Db_Adapter, createTable){ +static PHP_METHOD(Phalcon_Cache_Backend, getOptions){ - zval *table_name, *schema_name, *definition; - zval *exception_message, *columns, *dialect; - zval *sql; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); +} - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &definition); - - if (Z_TYPE_P(definition) != IS_ARRAY) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Invalid definition to create the table '", table_name, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_db_exception_ce, exception_message); - return; - } - if (!phalcon_array_isset_quick_string(definition, SS("columns"), 1041822630UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); - return; - } - - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); - if (!phalcon_fast_count_ev(columns TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); - return; - } - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "createtable", table_name, schema_name, definition, 3885129953UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); +static PHP_METHOD(Phalcon_Cache_Backend, isFresh){ + + + RETURN_MEMBER_QUICK(this_ptr, "_fresh", 2329058172UL); } -static PHP_METHOD(Phalcon_Db_Adapter, dropTable){ +static PHP_METHOD(Phalcon_Cache_Backend, isStarted){ - zval *table_name, *schema_name = NULL, *if_exists = NULL, *dialect; - zval *sql; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_started", 433407867UL); +} - phalcon_fetch_params(1, 1, 2, &table_name, &schema_name, &if_exists); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); - } +static PHP_METHOD(Phalcon_Cache_Backend, setLastKey){ + + zval *last_key; + + phalcon_fetch_params(0, 1, 0, &last_key); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), last_key, 394299009UL TSRMLS_CC); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "droptable", table_name, schema_name, if_exists, 3706194946UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, createView){ +static PHP_METHOD(Phalcon_Cache_Backend, getLastKey){ - zval *view_name, *definition, *schema_name = NULL, *exception_message; - zval *dialect, *sql; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_lastKey", 394299009UL); +} - phalcon_fetch_params(1, 2, 1, &view_name, &definition, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - if (Z_TYPE_P(definition) != IS_ARRAY) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Invalid definition to create the view '", view_name, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_db_exception_ce, exception_message); - return; - } - if (!phalcon_array_isset_quick_string(definition, SS("sql"), 2090732981UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); - return; - } - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "createview", view_name, definition, schema_name, 2593254036UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); +static PHP_METHOD(Phalcon_Cache_Backend, getLifetime){ + + + RETURN_MEMBER_QUICK(this_ptr, "_lastLifetime", 3936785351UL); } -static PHP_METHOD(Phalcon_Db_Adapter, dropView){ - zval *view_name, *schema_name = NULL, *if_exists = NULL, *dialect; - zval *sql; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &view_name, &schema_name, &if_exists); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); - } - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "dropview", view_name, schema_name, if_exists, 375272853UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Db_Adapter, addColumn){ +#ifdef HAVE_CONFIG_H +#endif - zval *table_name, *schema_name, *column, *dialect; - zval *sql; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "addcolumn", table_name, schema_name, column, 1469620764UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); +PHALCON_INIT_CLASS(Phalcon_Cache_BackendInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Cache, BackendInterface, cache_backendinterface, phalcon_cache_backendinterface_method_entry); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter, modifyColumn){ - zval *table_name, *schema_name, *column, *dialect; - zval *sql; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "modifycolumn", table_name, schema_name, column, 382554075UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Cache_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache, Exception, cache_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter, dropColumn){ - zval *table_name, *schema_name, *column_name; - zval *dialect, *sql; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column_name); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "dropcolumn", table_name, schema_name, column_name, 2125320424UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_Base64){ + + PHALCON_REGISTER_CLASS(Phalcon\\Cache\\Frontend, Base64, cache_frontend_base64, phalcon_cache_frontend_base64_method_entry, 0); + + zend_declare_property_null(phalcon_cache_frontend_base64_ce, SL("_frontendOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_cache_frontend_base64_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter, addIndex){ +static PHP_METHOD(Phalcon_Cache_Frontend_Base64, __construct){ - zval *table_name, *schema_name, *index, *dialect; - zval *sql; + zval *frontend_options = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); + phalcon_fetch_params(1, 0, 1, &frontend_options); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + if (!frontend_options) { + PHALCON_INIT_VAR(frontend_options); + } - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "addindex", table_name, schema_name, index, 1839662022UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); + phalcon_update_property_this_quick(this_ptr, SL("_frontendOptions"), frontend_options, 164501392UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter, dropIndex){ +static PHP_METHOD(Phalcon_Cache_Frontend_Base64, getLifetime){ - zval *table_name, *schema_name, *index_name; - zval *dialect, *sql; + zval *options, *lifetime; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index_name); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_frontendOptions"), 164501392UL, PH_NOISY_CC); + if (Z_TYPE_P(options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { + PHALCON_OBS_VAR(lifetime); + phalcon_array_fetch_quick_string(&lifetime, options, SS("lifetime"), 2639810228UL, PH_NOISY); + RETURN_CCTOR(lifetime); + } + } - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "dropindex", table_name, schema_name, index_name, 3291187474UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); + PHALCON_MM_RESTORE(); + RETURN_LONG(1); } -static PHP_METHOD(Phalcon_Db_Adapter, addPrimaryKey){ +static PHP_METHOD(Phalcon_Cache_Frontend_Base64, isBuffering){ - zval *table_name, *schema_name, *index, *dialect; - zval *sql; - PHALCON_MM_GROW(); + RETURN_FALSE; +} + +static PHP_METHOD(Phalcon_Cache_Frontend_Base64, start){ + - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "addprimarykey", table_name, schema_name, index, 1640564219UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, dropPrimaryKey){ +static PHP_METHOD(Phalcon_Cache_Frontend_Base64, getContent){ - zval *table_name, *schema_name, *dialect, *sql; - PHALCON_MM_GROW(); + RETURN_NULL(); +} + +static PHP_METHOD(Phalcon_Cache_Frontend_Base64, stop){ + - phalcon_fetch_params(1, 2, 0, &table_name, &schema_name); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "dropprimarykey", table_name, schema_name, 1513142983UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, addForeignKey){ +static PHP_METHOD(Phalcon_Cache_Frontend_Base64, beforeStore){ - zval *table_name, *schema_name, *reference, *dialect; - zval *sql; + zval *data; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 0, &data); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "addforeignkey", table_name, schema_name, reference, 599632289UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + phalcon_base64_encode(return_value, data); RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, dropForeignKey){ +static PHP_METHOD(Phalcon_Cache_Frontend_Base64, afterRetrieve){ - zval *table_name, *schema_name, *reference_name; - zval *dialect, *sql; + zval *data; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference_name); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 0, &data); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "dropforeignkey", table_name, schema_name, reference_name, 472211053UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + phalcon_base64_decode(return_value, data); RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, getColumnDefinition){ - zval *column, *dialect; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &column); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, dialect, "getcolumndefinition", column, 1668305756UL); - RETURN_MM(); + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_Data){ + + PHALCON_REGISTER_CLASS(Phalcon\\Cache\\Frontend, Data, cache_frontend_data, phalcon_cache_frontend_data_method_entry, 0); + + zend_declare_property_null(phalcon_cache_frontend_data_ce, SL("_frontendOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_cache_frontend_data_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter, listTables){ +static PHP_METHOD(Phalcon_Cache_Frontend_Data, __construct){ - zval *schema_name = NULL, *dialect, *sql, *fetch_num, *tables; - zval *all_tables, *table = NULL, *table_name = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *frontend_options = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(1, 0, 1, &frontend_options); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!frontend_options) { + PHALCON_INIT_VAR(frontend_options); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p1_key(sql, dialect, "listtables", schema_name, 57229948UL); + phalcon_update_property_this_quick(this_ptr, SL("_frontendOptions"), frontend_options, 164501392UL TSRMLS_CC); - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); - - PHALCON_INIT_VAR(tables); - phalcon_call_method_p2_key(tables, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - - PHALCON_INIT_VAR(all_tables); - array_init(all_tables); - - phalcon_is_iterable(tables, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(table); - - PHALCON_OBS_NVAR(table_name); - phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY); - phalcon_array_append(&all_tables, table_name, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CTOR(all_tables); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter, listViews){ +static PHP_METHOD(Phalcon_Cache_Frontend_Data, getLifetime){ - zval *schema_name = NULL, *dialect, *sql, *fetch_num, *tables; - zval *all_tables, *table = NULL, *table_name = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *options, *lifetime; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p1_key(sql, dialect, "listviews", schema_name, 3473526159UL); - - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); - - PHALCON_INIT_VAR(tables); - phalcon_call_method_p2_key(tables, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - - PHALCON_INIT_VAR(all_tables); - array_init(all_tables); - - phalcon_is_iterable(tables, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(table); - - PHALCON_OBS_NVAR(table_name); - phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY); - phalcon_array_append(&all_tables, table_name, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_frontendOptions"), 164501392UL, PH_NOISY_CC); + if (Z_TYPE_P(options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { + PHALCON_OBS_VAR(lifetime); + phalcon_array_fetch_quick_string(&lifetime, options, SS("lifetime"), 2639810228UL, PH_NOISY); + RETURN_CCTOR(lifetime); + } } - RETURN_CTOR(all_tables); + PHALCON_MM_RESTORE(); + RETURN_LONG(1); } -static PHP_METHOD(Phalcon_Db_Adapter, describeIndexes){ - - zval *table, *schema = NULL, *dialect, *fetch_num, *sql, *describe; - zval *indexes, *index = NULL, *key_name = NULL, *empty_arr = NULL, *column_name = NULL; - zval *index_objects, *index_columns = NULL, *name = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; +static PHP_METHOD(Phalcon_Cache_Frontend_Data, isBuffering){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describeindexes", table, schema, 689092630UL); - - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - - PHALCON_INIT_VAR(indexes); - array_init(indexes); - - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(index); - - PHALCON_OBS_NVAR(key_name); - phalcon_array_fetch_long(&key_name, index, 2, PH_NOISY); - if (!phalcon_array_isset(indexes, key_name)) { - PHALCON_INIT_NVAR(empty_arr); - array_init(empty_arr); - phalcon_array_update_zval(&indexes, key_name, &empty_arr, PH_COPY | PH_SEPARATE); - } - - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, index, 4, PH_NOISY); - phalcon_array_update_append_multi_2(&indexes, key_name, column_name, 0); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(index_objects); - array_init(index_objects); - - phalcon_is_iterable(indexes, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HKEY(name, ah1, hp1); - PHALCON_GET_HVALUE(index_columns); - - PHALCON_INIT_NVAR(index); - object_init_ex(index, phalcon_db_index_ce); - phalcon_call_method_p2_key(NULL, index, "__construct", name, index_columns, 1107214344UL); - - phalcon_array_update_zval(&index_objects, name, &index, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - RETURN_CTOR(index_objects); + RETURN_FALSE; } -static PHP_METHOD(Phalcon_Db_Adapter, describeReferences){ - - zval *table, *schema = NULL, *dialect, *fetch_num, *sql, *empty_arr; - zval *references, *describe, *reference = NULL, *constraint_name = NULL; - zval *referenced_schema = NULL, *referenced_table = NULL; - zval *reference_array = NULL, *column_name = NULL, *referenced_columns = NULL; - zval *reference_objects, *array_reference = NULL; - zval *name = NULL, *columns = NULL, *definition = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; +static PHP_METHOD(Phalcon_Cache_Frontend_Data, start){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describereferences", table, schema, 1939869288UL); - - PHALCON_INIT_VAR(empty_arr); - array_init(empty_arr); - - PHALCON_INIT_VAR(references); - array_init(references); - - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(reference); - - PHALCON_OBS_NVAR(constraint_name); - phalcon_array_fetch_long(&constraint_name, reference, 2, PH_NOISY); - if (!phalcon_array_isset(references, constraint_name)) { - PHALCON_OBS_NVAR(referenced_schema); - phalcon_array_fetch_long(&referenced_schema, reference, 3, PH_NOISY); - - PHALCON_OBS_NVAR(referenced_table); - phalcon_array_fetch_long(&referenced_table, reference, 4, PH_NOISY); - - PHALCON_INIT_NVAR(reference_array); - array_init_size(reference_array, 4); - phalcon_array_update_quick_string(&reference_array, SS("referencedSchema"), 3300645545UL, &referenced_schema, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&reference_array, SS("referencedTable"), 3390337856UL, &referenced_table, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&reference_array, SS("columns"), 1041822630UL, &empty_arr, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&reference_array, SS("referencedColumns"), 1045113721UL, &empty_arr, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&references, constraint_name, &reference_array, PH_COPY | PH_SEPARATE); - } - - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, reference, 1, PH_NOISY); - phalcon_array_update_zval_string_append_multi_3(&references, constraint_name, SL("columns"), &column_name, 0); - - PHALCON_OBS_NVAR(referenced_columns); - phalcon_array_fetch_long(&referenced_columns, reference, 5, PH_NOISY); - phalcon_array_update_zval_string_append_multi_3(&references, constraint_name, SL("referencedColumns"), &referenced_columns, 0); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(reference_objects); - array_init(reference_objects); - - phalcon_is_iterable(references, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HKEY(name, ah1, hp1); - PHALCON_GET_HVALUE(array_reference); - - PHALCON_OBS_NVAR(referenced_schema); - phalcon_array_fetch_quick_string(&referenced_schema, array_reference, SS("referencedSchema"), 3300645545UL, PH_NOISY); - - PHALCON_OBS_NVAR(referenced_table); - phalcon_array_fetch_quick_string(&referenced_table, array_reference, SS("referencedTable"), 3390337856UL, PH_NOISY); - - PHALCON_OBS_NVAR(columns); - phalcon_array_fetch_quick_string(&columns, array_reference, SS("columns"), 1041822630UL, PH_NOISY); - - PHALCON_OBS_NVAR(referenced_columns); - phalcon_array_fetch_quick_string(&referenced_columns, array_reference, SS("referencedColumns"), 1045113721UL, PH_NOISY); - - PHALCON_INIT_NVAR(definition); - array_init_size(definition, 4); - phalcon_array_update_quick_string(&definition, SS("referencedSchema"), 3300645545UL, &referenced_schema, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("referencedTable"), 3390337856UL, &referenced_table, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("columns"), 1041822630UL, &columns, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("referencedColumns"), 1045113721UL, &referenced_columns, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_NVAR(reference); - object_init_ex(reference, phalcon_db_reference_ce); - phalcon_call_method_p2_key(NULL, reference, "__construct", name, definition, 1107214344UL); - - phalcon_array_update_zval(&reference_objects, name, &reference, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah1, &hp1); - } - RETURN_CTOR(reference_objects); } -static PHP_METHOD(Phalcon_Db_Adapter, tableOptions){ +static PHP_METHOD(Phalcon_Cache_Frontend_Data, getContent){ - zval *table_name, *schema_name = NULL, *dialect, *sql; - zval *fetch_assoc, *describe, *first; - PHALCON_MM_GROW(); + RETURN_NULL(); +} + +static PHP_METHOD(Phalcon_Cache_Frontend_Data, stop){ + - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "tableoptions", table_name, schema_name, 3683930169UL); - if (zend_is_true(sql)) { - PHALCON_INIT_VAR(fetch_assoc); - ZVAL_LONG(fetch_assoc, 1); - - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_assoc, 1636682248UL); - - PHALCON_OBS_VAR(first); - phalcon_array_fetch_long(&first, describe, 0, PH_NOISY); - RETURN_CCTOR(first); - } - RETURN_MM_EMPTY_ARRAY(); } -static PHP_METHOD(Phalcon_Db_Adapter, createSavepoint){ +static PHP_METHOD(Phalcon_Cache_Frontend_Data, beforeStore){ - zval *name, *dialect, *supports_sp, *sql; + zval *data; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(supports_sp); - phalcon_call_method_key(supports_sp, dialect, "supportssavepoints", 1063347073UL); - if (!zend_is_true(supports_sp)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Savepoints are not supported by this database adapter."); - return; - } + phalcon_fetch_params(1, 1, 0, &data); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p1_key(sql, dialect, "createsavepoint", name, 2980652562UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + phalcon_serialize(return_value, &data TSRMLS_CC); RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, releaseSavepoint){ +static PHP_METHOD(Phalcon_Cache_Frontend_Data, afterRetrieve){ - zval *name, *dialect, *supports_sp, *supports_rsp; - zval *sql; + zval *data; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(supports_sp); - phalcon_call_method_key(supports_sp, dialect, "supportssavepoints", 1063347073UL); - if (!zend_is_true(supports_sp)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Savepoints are not supported by this database adapter"); - return; - } - - PHALCON_INIT_VAR(supports_rsp); - phalcon_call_method_key(supports_rsp, dialect, "supportsreleasesavepoints", 141567298UL); - if (!zend_is_true(supports_rsp)) { - RETURN_MM_FALSE; - } + phalcon_fetch_params(1, 1, 0, &data); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p1_key(sql, dialect, "releasesavepoint", name, 3823765247UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + phalcon_unserialize(return_value, data TSRMLS_CC); RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, rollbackSavepoint){ - zval *name, *dialect, *supports_sp, *sql; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(supports_sp); - phalcon_call_method_key(supports_sp, dialect, "supportssavepoints", 1063347073UL); - if (!zend_is_true(supports_sp)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Savepoints are not supported by this database adapter"); - return; - } - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p1_key(sql, dialect, "rollbacksavepoint", name, 3444395528UL); - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Db_Adapter, setNestedTransactionsWithSavepoints){ +#ifdef HAVE_CONFIG_H +#endif - zval *nested_transactions_with_savepoints; - zval *transaction_level, *dialect, *supports_sp; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &nested_transactions_with_savepoints); - - PHALCON_OBS_VAR(transaction_level); - phalcon_read_property_this_quick(&transaction_level, this_ptr, SL("_transactionLevel"), 2789346594UL, PH_NOISY_CC); - if (PHALCON_GT_LONG(transaction_level, 0)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Nested transaction with savepoints behavior cannot be changed while a transaction is open"); - return; - } - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(supports_sp); - phalcon_call_method_key(supports_sp, dialect, "supportssavepoints", 1063347073UL); - if (!zend_is_true(supports_sp)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Savepoints are not supported by this database adapter"); - return; - } - - phalcon_update_property_this_quick(this_ptr, SL("_transactionsWithSavepoints"), nested_transactions_with_savepoints, 2137960997UL TSRMLS_CC); - - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Db_Adapter, isNestedTransactionsWithSavepoints){ - RETURN_MEMBER_QUICK(this_ptr, "_transactionsWithSavepoints", 2137960997UL); + +PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_Igbinary){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Frontend, Igbinary, cache_frontend_igbinary, "phalcon\\cache\\frontend\\data", phalcon_cache_frontend_igbinary_method_entry, 0); + + zend_class_implements(phalcon_cache_frontend_igbinary_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter, getNestedTransactionSavepointName){ +static PHP_METHOD(Phalcon_Cache_Frontend_Igbinary, beforeStore){ - zval *transaction_level; + zval *data; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(transaction_level); - phalcon_read_property_this_quick(&transaction_level, this_ptr, SL("_transactionLevel"), 2789346594UL, PH_NOISY_CC); - PHALCON_CONCAT_SV(return_value, "PHALCON_SAVEPOINT_", transaction_level); + phalcon_fetch_params(1, 1, 0, &data); + + phalcon_call_func_p1(return_value, "igbinary_serialize", data); RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, getDefaultIdValue){ +static PHP_METHOD(Phalcon_Cache_Frontend_Igbinary, afterRetrieve){ - zval *null_value; + zval *data; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(null_value); - ZVAL_STRING(null_value, "null", 1); - object_init_ex(return_value, phalcon_db_rawvalue_ce); - phalcon_call_method_p1_key(NULL, return_value, "__construct", null_value, 1107214344UL); + phalcon_fetch_params(1, 1, 0, &data); + phalcon_call_func_p1(return_value, "igbinary_unserialize", data); RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, supportSequences){ - RETURN_FALSE; -} -static PHP_METHOD(Phalcon_Db_Adapter, useExplicitIdValue){ +#ifdef HAVE_CONFIG_H +#endif - RETURN_FALSE; + + + + + +PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_Json){ + + PHALCON_REGISTER_CLASS(Phalcon\\Cache\\Frontend, Json, cache_frontend_json, phalcon_cache_frontend_json_method_entry, 0); + + zend_declare_property_null(phalcon_cache_frontend_json_ce, SL("_frontendOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_cache_frontend_json_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter, getDescriptor){ +static PHP_METHOD(Phalcon_Cache_Frontend_Json, __construct){ + + zval *frontend_options = NULL; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_descriptor", 691635363UL); + phalcon_fetch_params(1, 0, 1, &frontend_options); + + if (!frontend_options) { + PHALCON_INIT_VAR(frontend_options); + } + + phalcon_update_property_this_quick(this_ptr, SL("_frontendOptions"), frontend_options, 164501392UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter, getConnectionId){ +static PHP_METHOD(Phalcon_Cache_Frontend_Json, getLifetime){ + zval *options, *lifetime; - RETURN_MEMBER_QUICK(this_ptr, "_connectionId", 802624385UL); + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_frontendOptions"), 164501392UL, PH_NOISY_CC); + if (Z_TYPE_P(options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { + PHALCON_OBS_VAR(lifetime); + phalcon_array_fetch_quick_string(&lifetime, options, SS("lifetime"), 2639810228UL, PH_NOISY); + RETURN_CCTOR(lifetime); + } + } + + PHALCON_MM_RESTORE(); + RETURN_LONG(1); } -static PHP_METHOD(Phalcon_Db_Adapter, getSQLStatement){ +static PHP_METHOD(Phalcon_Cache_Frontend_Json, isBuffering){ - RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); + RETURN_FALSE; } -static PHP_METHOD(Phalcon_Db_Adapter, getRealSQLStatement){ +static PHP_METHOD(Phalcon_Cache_Frontend_Json, start){ - RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); + } -static PHP_METHOD(Phalcon_Db_Adapter, getSQLVariables){ +static PHP_METHOD(Phalcon_Cache_Frontend_Json, getContent){ - RETURN_MEMBER_QUICK(this_ptr, "_sqlVariables", 3213579853UL); + RETURN_NULL(); } -static PHP_METHOD(Phalcon_Db_Adapter, getSQLBindTypes){ +static PHP_METHOD(Phalcon_Cache_Frontend_Json, stop){ - RETURN_MEMBER_QUICK(this_ptr, "_sqlBindTypes", 3288357222UL); + } -static PHP_METHOD(Phalcon_Db_Adapter, getType){ +static PHP_METHOD(Phalcon_Cache_Frontend_Json, beforeStore){ + zval *data; - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); + phalcon_fetch_params(1, 1, 0, &data); + + phalcon_json_encode(return_value, data, 0 TSRMLS_CC); } -static PHP_METHOD(Phalcon_Db_Adapter, getDialectType){ +static PHP_METHOD(Phalcon_Cache_Frontend_Json, afterRetrieve){ + zval *data; - RETURN_MEMBER_QUICK(this_ptr, "_dialectType", 1868597628UL); + phalcon_fetch_params(1, 1, 0, &data); + + phalcon_json_decode(return_value, data, 0 TSRMLS_CC); } @@ -21877,69 +21816,61 @@ static PHP_METHOD(Phalcon_Db_Adapter, getDialectType){ +PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_None){ -PHALCON_INIT_CLASS(Phalcon_Db_Index){ - - PHALCON_REGISTER_CLASS(Phalcon\\Db, Index, db_index, phalcon_db_index_method_entry, 0); - - zend_declare_property_null(phalcon_db_index_ce, SL("_indexName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_index_ce, SL("_columns"), ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_REGISTER_CLASS(Phalcon\\Cache\\Frontend, None, cache_frontend_none, phalcon_cache_frontend_none_method_entry, 0); - zend_class_implements(phalcon_db_index_ce TSRMLS_CC, 1, phalcon_db_indexinterface_ce); + zend_class_implements(phalcon_cache_frontend_none_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Index, __construct){ +static PHP_METHOD(Phalcon_Cache_Frontend_None, getLifetime){ - zval *index_name, *columns; - phalcon_fetch_params(0, 2, 0, &index_name, &columns); - - phalcon_update_property_this_quick(this_ptr, SL("_indexName"), index_name, 3837120573UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_columns"), columns, 4004520869UL TSRMLS_CC); - + RETURN_LONG(1); } -static PHP_METHOD(Phalcon_Db_Index, getName){ +static PHP_METHOD(Phalcon_Cache_Frontend_None, isBuffering){ - RETURN_MEMBER_QUICK(this_ptr, "_indexName", 3837120573UL); + RETURN_FALSE; } -static PHP_METHOD(Phalcon_Db_Index, getColumns){ +static PHP_METHOD(Phalcon_Cache_Frontend_None, start){ - RETURN_MEMBER_QUICK(this_ptr, "_columns", 4004520869UL); + } -static PHP_METHOD(Phalcon_Db_Index, __set_state){ - - zval *data, *index_name, *columns; +static PHP_METHOD(Phalcon_Cache_Frontend_None, getContent){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &data); - - if (!phalcon_array_isset_quick_string(data, SS("_indexName"), 3837120573UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "_indexName parameter is required"); - return; - } - if (!phalcon_array_isset_quick_string(data, SS("_columns"), 4004520869UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "_columns parameter is required"); - return; - } - PHALCON_OBS_VAR(index_name); - phalcon_array_fetch_quick_string(&index_name, data, SS("_indexName"), 3837120573UL, PH_NOISY); +} + +static PHP_METHOD(Phalcon_Cache_Frontend_None, stop){ + + - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, data, SS("_columns"), 4004520869UL, PH_NOISY); +} + +static PHP_METHOD(Phalcon_Cache_Frontend_None, beforeStore){ + + zval *data; + + phalcon_fetch_params(0, 1, 0, &data); - object_init_ex(return_value, phalcon_db_index_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", index_name, columns, 1107214344UL); + RETURN_CCTORW(data); +} + +static PHP_METHOD(Phalcon_Cache_Frontend_None, afterRetrieve){ + + zval *data; + + phalcon_fetch_params(0, 1, 0, &data); - RETURN_MM(); + RETURN_CCTORW(data); } @@ -21955,788 +21886,410 @@ static PHP_METHOD(Phalcon_Db_Index, __set_state){ -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo){ +PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_Output){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Adapter, Pdo, db_adapter_pdo, "phalcon\\db\\adapter", phalcon_db_adapter_pdo_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + PHALCON_REGISTER_CLASS(Phalcon\\Cache\\Frontend, Output, cache_frontend_output, phalcon_cache_frontend_output_method_entry, 0); - zend_declare_property_null(phalcon_db_adapter_pdo_ce, SL("_pdo"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_db_adapter_pdo_ce, SL("_affectedRows"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_db_adapter_pdo_ce, SL("_transactionLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_cache_frontend_output_ce, SL("_buffering"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cache_frontend_output_ce, SL("_frontendOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_cache_frontend_output_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, __construct){ +static PHP_METHOD(Phalcon_Cache_Frontend_Output, __construct){ - zval *descriptor; + zval *frontend_options = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &descriptor); + phalcon_fetch_params(1, 0, 1, &frontend_options); - if (Z_TYPE_P(descriptor) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The descriptor must be an array"); - return; + if (!frontend_options) { + PHALCON_INIT_VAR(frontend_options); } - phalcon_call_method_p1_key(NULL, this_ptr, "connect", descriptor, 1111492527UL); - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo", "__construct", descriptor); + + phalcon_update_property_this_quick(this_ptr, SL("_frontendOptions"), frontend_options, 164501392UL TSRMLS_CC); PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect){ +static PHP_METHOD(Phalcon_Cache_Frontend_Output, getLifetime){ - zval *descriptor = NULL, *username = NULL, *password = NULL, *dsn_parts; - zval *value = NULL, *key = NULL, *dsn_attribute = NULL, *dsn_attributes = NULL; - zval *pdo_type, *dsn, *options = NULL, *persistent, *pdo; - zend_class_entry *ce; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *options, *lifetime; PHALCON_MM_GROW(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { - RETURN_MM_NULL(); + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_frontendOptions"), 164501392UL, PH_NOISY_CC); + if (Z_TYPE_P(options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { + PHALCON_OBS_VAR(lifetime); + phalcon_array_fetch_quick_string(&lifetime, options, SS("lifetime"), 2639810228UL, PH_NOISY); + RETURN_CCTOR(lifetime); + } } + + PHALCON_MM_RESTORE(); + RETURN_LONG(1); +} - if (!descriptor) { - PHALCON_INIT_VAR(descriptor); - } else { - PHALCON_SEPARATE_PARAM(descriptor); - } +static PHP_METHOD(Phalcon_Cache_Frontend_Output, isBuffering){ - if (Z_TYPE_P(descriptor) == IS_NULL) { - PHALCON_OBS_NVAR(descriptor); - phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); - } - if (phalcon_array_isset_quick_string(descriptor, SS("username"), 3241309669UL)) { - PHALCON_OBS_VAR(username); - phalcon_array_fetch_quick_string(&username, descriptor, SS("username"), 3241309669UL, PH_NOISY); - phalcon_array_unset_string(&descriptor, SS("username"), PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(username); - } + RETURN_MEMBER_QUICK(this_ptr, "_buffering", 4086213532UL); +} - if (phalcon_array_isset_quick_string(descriptor, SS("password"), 382886712UL)) { - PHALCON_OBS_VAR(password); - phalcon_array_fetch_quick_string(&password, descriptor, SS("password"), 382886712UL, PH_NOISY); - phalcon_array_unset_string(&descriptor, SS("password"), PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(password); - } +static PHP_METHOD(Phalcon_Cache_Frontend_Output, start){ - if (phalcon_array_isset_quick_string(descriptor, SS("options"), 2952422065UL)) { - PHALCON_OBS_VAR(options); - phalcon_array_fetch_quick_string(&options, descriptor, SS("options"), 2952422065UL, PH_NOISY); - phalcon_array_unset_string(&descriptor, SS("options"), PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(options); - array_init(options); - } - if (!phalcon_array_isset_quick_string(descriptor, SS("dsn"), 2090196170UL)) { + PHALCON_MM_GROW(); - PHALCON_INIT_VAR(dsn_parts); - array_init(dsn_parts); + phalcon_update_property_bool(this_ptr, SL("_buffering"), 1 TSRMLS_CC); + phalcon_ob_start(TSRMLS_C); + + PHALCON_MM_RESTORE(); +} - if (!phalcon_is_iterable_ex(descriptor, &ah0, &hp0, 0, 0)) { - return; - } +static PHP_METHOD(Phalcon_Cache_Frontend_Output, getContent){ - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + zval *buffering; - PHALCON_GET_FOREACH_KEY(key, ah0, hp0); - PHALCON_GET_FOREACH_VALUE(value); + PHALCON_MM_GROW(); - PHALCON_INIT_NVAR(dsn_attribute); - PHALCON_CONCAT_VSV(dsn_attribute, key, "=", value); - phalcon_array_append(&dsn_parts, dsn_attribute, PH_SEPARATE); + PHALCON_OBS_VAR(buffering); + phalcon_read_property_this_quick(&buffering, this_ptr, SL("_buffering"), 4086213532UL, PH_NOISY_CC); + if (zend_is_true(buffering)) { + phalcon_ob_get_contents(return_value TSRMLS_CC); + RETURN_MM(); + } + + RETURN_MM_NULL(); +} - zend_hash_move_forward_ex(ah0, &hp0); - } +static PHP_METHOD(Phalcon_Cache_Frontend_Output, stop){ - PHALCON_INIT_VAR(dsn_attributes); - phalcon_fast_join_str(dsn_attributes, SL(";"), dsn_parts TSRMLS_CC); - } else { - PHALCON_OBS_NVAR(dsn_attributes); - phalcon_array_fetch_quick_string(&dsn_attributes, descriptor, SS("dsn"), 2090196170UL, PH_NOISY); + zval *buffering; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(buffering); + phalcon_read_property_this_quick(&buffering, this_ptr, SL("_buffering"), 4086213532UL, PH_NOISY_CC); + if (zend_is_true(buffering)) { + phalcon_ob_end_clean(TSRMLS_C); } + + phalcon_update_property_bool(this_ptr, SL("_buffering"), 0 TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} - PHALCON_OBS_VAR(pdo_type); - phalcon_read_property(&pdo_type, this_ptr, SL("_type"), PH_NOISY_CC); +static PHP_METHOD(Phalcon_Cache_Frontend_Output, beforeStore){ - PHALCON_INIT_VAR(dsn); - PHALCON_CONCAT_VSV(dsn, pdo_type, ":", dsn_attributes); + zval *data; - phalcon_array_update_long_long(&options, PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION, PH_SEPARATE); - //phalcon_array_update_long_long(&options, PDO_ATTR_CASE, PDO_CASE_LOWER, PH_SEPARATE); - //phalcon_array_update_long_long(&options, PDO_ATTR_CURSOR, PDO_CURSOR_SCROLL, PH_SEPARATE); + phalcon_fetch_params(0, 1, 0, &data); + + RETURN_CCTORW(data); +} - if (phalcon_array_isset_quick_string(descriptor, SS("persistent"), 2222052598UL)) { +static PHP_METHOD(Phalcon_Cache_Frontend_Output, afterRetrieve){ - PHALCON_OBS_VAR(persistent); - phalcon_array_fetch_quick_string(&persistent, descriptor, SS("persistent"), 2222052598UL, PH_NOISY); - if (zend_is_true(persistent)) { - phalcon_array_update_long_bool(&options, PDO_ATTR_PERSISTENT, 1, PH_SEPARATE); - } - } + zval *data; - ce = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + phalcon_fetch_params(0, 1, 0, &data); + + RETURN_CCTORW(data); +} - PHALCON_INIT_VAR(pdo); - object_init_ex(pdo, ce); - phalcon_call_method_p4_key(NULL, pdo, "__construct", dsn, username, password, options, 1107214344UL); - phalcon_update_property_zval(this_ptr, SL("_pdo"), pdo TSRMLS_CC); - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, prepare){ - zval *sql_statement, *pdo; +#ifdef HAVE_CONFIG_H +#endif - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &sql_statement); - - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, pdo, "prepare", sql_statement, 329932052UL); - RETURN_MM(); + +PHALCON_INIT_CLASS(Phalcon_Cache_FrontendInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Cache, FrontendInterface, cache_frontendinterface, phalcon_cache_frontendinterface_method_entry); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, executePrepared){ - zval *statement = NULL, *placeholders = NULL, *data_types = NULL; - zval *one, *value = NULL, *wildcard = NULL, *parameter = NULL, *type = NULL, *cast_value = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &statement, &placeholders, &data_types) == FAILURE) { - RETURN_MM_NULL(); - } - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - if (!phalcon_is_iterable_ex(placeholders, &ah0, &hp0, 0, 0)) { - return; - } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_GET_FOREACH_KEY(wildcard, ah0, hp0); - PHALCON_GET_FOREACH_VALUE(value); - if (Z_TYPE_P(wildcard) == IS_LONG) { - PHALCON_INIT_NVAR(parameter); - phalcon_add_function(parameter, wildcard, one TSRMLS_CC); - } else { - if (Z_TYPE_P(wildcard) == IS_STRING) { - PHALCON_CPY_WRT(parameter, wildcard); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid bind parameter"); - return; - } - } - if (Z_TYPE_P(data_types) == IS_ARRAY) { - if (likely(phalcon_array_isset(data_types, wildcard))) { - PHALCON_OBS_NVAR(type); - phalcon_array_fetch(&type, data_types, wildcard, PH_NOISY); - if (phalcon_compare_strict_long(type, 32 TSRMLS_CC)) { +#ifdef HAVE_CONFIG_H +#endif - PHALCON_INIT_NVAR(cast_value); - phalcon_cast(cast_value, value, IS_DOUBLE); - PHALCON_INIT_NVAR(type); - ZVAL_LONG(type, 1024); - } else { - PHALCON_CPY_WRT(cast_value, value); - } - Z_SET_ISREF_P(cast_value); - if (phalcon_compare_strict_long(type, 1024 TSRMLS_CC)) { - phalcon_call_method_p2_key(NULL, statement, "bindparam", parameter, cast_value, 724187283UL); - } else { - phalcon_call_method_p3_key(NULL, statement, "bindparam", parameter, cast_value, type, 724187283UL); - } - Z_UNSET_ISREF_P(cast_value); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid bind type parameter"); - return; - } - } else { - Z_SET_ISREF_P(value); - phalcon_call_method_p2_key(NULL, statement, "bindparam", parameter, value, 724187283UL); - Z_UNSET_ISREF_P(value); - } - zend_hash_move_forward_ex(ah0, &hp0); - } - phalcon_call_method_key(NULL, statement, "execute", 3117639032UL); - RETURN_CCTOR(statement); +PHALCON_INIT_CLASS(Phalcon_Cache_Multiple){ + + PHALCON_REGISTER_CLASS(Phalcon\\Cache, Multiple, cache_multiple, phalcon_cache_multiple_method_entry, 0); + + zend_declare_property_null(phalcon_cache_multiple_ce, SL("_backends"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, query){ +static PHP_METHOD(Phalcon_Cache_Multiple, __construct){ - zval *sql_statement, *bind_params = NULL, *bind_types = NULL; - zval *events_manager, *event_name = NULL, *status, *pdo; - zval *statement = NULL, *new_statement; + zval *backends = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &sql_statement, &bind_params, &bind_types); - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } - - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "db:beforeQuery", 1); - phalcon_update_property_this_quick(this_ptr, SL("_sqlStatement"), sql_statement, 18972457UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlVariables"), bind_params, 3213579853UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlBindTypes"), bind_types, 3288357222UL TSRMLS_CC); + phalcon_fetch_params(1, 0, 1, &backends); - PHALCON_INIT_VAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, bind_params, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } + if (!backends) { + PHALCON_INIT_VAR(backends); } - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); - if (Z_TYPE_P(bind_params) == IS_ARRAY) { - - PHALCON_INIT_VAR(statement); - phalcon_call_method_p1_key(statement, pdo, "prepare", sql_statement, 329932052UL); - if (Z_TYPE_P(statement) == IS_OBJECT) { - PHALCON_INIT_VAR(new_statement); - phalcon_call_method_p3_key(new_statement, this_ptr, "executeprepared", statement, bind_params, bind_types, 647421771UL); - PHALCON_CPY_WRT(statement, new_statement); + if (Z_TYPE_P(backends) != IS_NULL) { + if (Z_TYPE_P(backends) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backends must be an array"); + return; } - } else { - PHALCON_INIT_NVAR(statement); - phalcon_call_method_p1_key(statement, pdo, "query", sql_statement, 401898907UL); + phalcon_update_property_this_quick(this_ptr, SL("_backends"), backends, 2548946143UL TSRMLS_CC); } - if (likely(Z_TYPE_P(statement) == IS_OBJECT)) { - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "db:afterQuery", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, bind_params, 259017035UL); - } - object_init_ex(return_value, phalcon_db_result_pdo_ce); - phalcon_call_method_p5_key(NULL, return_value, "__construct", this_ptr, statement, sql_statement, bind_params, bind_types, 1107214344UL); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Cache_Multiple, push){ + + zval *backend; + + phalcon_fetch_params(0, 1, 0, &backend); - RETURN_MM(); + if (Z_TYPE_P(backend) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_cache_exception_ce, "The backend is not valid"); + return; } + phalcon_update_property_array_append(this_ptr, SL("_backends"), backend TSRMLS_CC); - RETURN_CCTOR(statement); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, execute){ +static PHP_METHOD(Phalcon_Cache_Multiple, get){ - zval *sql_statement, *bind_params = NULL, *bind_types = NULL; - zval *events_manager, *event_name = NULL, *status, *affected_rows = NULL; - zval *pdo, *statement, *new_statement; + zval *key_name, *lifetime = NULL, *backends, *backend = NULL; + zval *content = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &sql_statement, &bind_params, &bind_types); - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } + phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "db:beforeQuery", 1); - phalcon_update_property_this_quick(this_ptr, SL("_sqlStatement"), sql_statement, 18972457UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlVariables"), bind_params, 3213579853UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlBindTypes"), bind_types, 3288357222UL TSRMLS_CC); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, bind_params, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } + PHALCON_OBS_VAR(backends); + phalcon_read_property_this_quick(&backends, this_ptr, SL("_backends"), 2548946143UL, PH_NOISY_CC); - PHALCON_INIT_VAR(affected_rows); - ZVAL_LONG(affected_rows, 0); + phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); - if (Z_TYPE_P(bind_params) == IS_ARRAY) { + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(statement); - phalcon_call_method_p1_key(statement, pdo, "prepare", sql_statement, 329932052UL); - if (Z_TYPE_P(statement) == IS_OBJECT) { - PHALCON_INIT_VAR(new_statement); - phalcon_call_method_p3_key(new_statement, this_ptr, "executeprepared", statement, bind_params, bind_types, 647421771UL); + PHALCON_GET_HVALUE(backend); - phalcon_call_method_key(affected_rows, new_statement, "rowcount", 4184721862UL); + PHALCON_INIT_NVAR(content); + phalcon_call_method_p2_key(content, backend, "get", key_name, lifetime, 2090288933UL); + if (Z_TYPE_P(content) != IS_NULL) { + RETURN_CCTOR(content); } - } else { - PHALCON_INIT_NVAR(affected_rows); - phalcon_call_method_p1_key(affected_rows, pdo, "exec", sql_statement, 258355946UL); - } - if (Z_TYPE_P(affected_rows) == IS_LONG) { - phalcon_update_property_this_quick(this_ptr, SL("_affectedRows"), affected_rows, 3226297793UL TSRMLS_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "db:afterQuery", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, bind_params, 259017035UL); - } + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, affectedRows){ - - - RETURN_MEMBER_QUICK(this_ptr, "_affectedRows", 3226297793UL); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, close){ +static PHP_METHOD(Phalcon_Cache_Multiple, start){ - zval *pdo; + zval *key_name, *lifetime = NULL, *backends, *backend = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); - if (likely(Z_TYPE_P(pdo) == IS_OBJECT)) { - phalcon_update_property_null(this_ptr, SL("_pdo") TSRMLS_CC); - RETURN_MM_TRUE; + phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); + + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } - RETURN_MM_TRUE; + PHALCON_OBS_VAR(backends); + phalcon_read_property_this_quick(&backends, this_ptr, SL("_backends"), 2548946143UL, PH_NOISY_CC); + + phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(backend); + + phalcon_call_method_p2_key(NULL, backend, "start", key_name, lifetime, 478839859UL); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, escapeIdentifier){ +static PHP_METHOD(Phalcon_Cache_Multiple, save){ - zval *identifier, *domain, *name; + zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; + zval *backends, *backend = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &identifier); - - if (Z_TYPE_P(identifier) == IS_ARRAY) { - PHALCON_OBS_VAR(domain); - phalcon_array_fetch_long(&domain, identifier, 0, PH_NOISY); + phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - PHALCON_OBS_VAR(name); - phalcon_array_fetch_long(&name, identifier, 1, PH_NOISY); - PHALCON_CONCAT_SVSVS(return_value, "\"", domain, "\".\"", name, "\""); - RETURN_MM(); - } - PHALCON_CONCAT_SVS(return_value, "\"", identifier, "\""); - - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, escapeString){ - - zval *str, *pdo; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &str); - - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, pdo, "quote", str, 402259795UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, convertBoundParams){ - - zval *sql, *params, *query_params, *placeholders; - zval *matches, *set_order, *bind_pattern, *status; - zval *place_match = NULL, *numeric_place = NULL, *value = NULL, *str_place = NULL; - zval *question, *bound_sql = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &sql, ¶ms); - - PHALCON_INIT_VAR(query_params); - array_init(query_params); - - PHALCON_INIT_VAR(placeholders); - array_init(placeholders); - - PHALCON_INIT_VAR(matches); - - PHALCON_INIT_VAR(set_order); - ZVAL_LONG(set_order, 2); - - PHALCON_INIT_VAR(bind_pattern); - ZVAL_STRING(bind_pattern, "/\\?([0-9]+)|:([a-zA-Z0-9_]+):/", 1); - Z_SET_ISREF_P(matches); - - PHALCON_INIT_VAR(status); - phalcon_call_func_p4(status, "preg_match_all", bind_pattern, sql, matches, set_order); - Z_UNSET_ISREF_P(matches); - if (zend_is_true(status)) { - - phalcon_is_iterable(matches, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(place_match); - - PHALCON_OBS_NVAR(numeric_place); - phalcon_array_fetch_long(&numeric_place, place_match, 1, PH_NOISY); - if (phalcon_array_isset(params, numeric_place)) { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, params, numeric_place, PH_NOISY); - } else { - if (phalcon_array_isset_long(place_match, 2)) { - - PHALCON_OBS_NVAR(str_place); - phalcon_array_fetch_long(&str_place, place_match, 2, PH_NOISY); - if (phalcon_array_isset(params, str_place)) { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, params, str_place, PH_NOISY); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Matched parameter wasn't found in parameters list"); - return; - } - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Matched parameter wasn't found in parameters list"); - return; - } - } - - phalcon_array_append(&placeholders, value, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(question); - ZVAL_STRING(question, "?", 1); - - PHALCON_INIT_VAR(bound_sql); - phalcon_call_func_p3(bound_sql, "preg_replace", bind_pattern, question, sql); - } else { - PHALCON_CPY_WRT(bound_sql, sql); - } - - array_init_size(return_value, 2); - phalcon_array_update_quick_string(&return_value, SS("sql"), 2090732981UL, &bound_sql, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&return_value, SS("params"), 2613350281UL, &placeholders, PH_COPY | PH_SEPARATE); - - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, lastInsertId){ - - zval *sequence_name = NULL, *pdo; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &sequence_name); - - if (!sequence_name) { - PHALCON_INIT_VAR(sequence_name); + if (!key_name) { + PHALCON_INIT_VAR(key_name); } - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); - if (Z_TYPE_P(pdo) != IS_OBJECT) { - RETURN_MM_FALSE; + if (!content) { + PHALCON_INIT_VAR(content); } - phalcon_call_method_p1_key(return_value, pdo, "lastinsertid", sequence_name, 106913211UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, begin){ - - zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; - zval *event_name = NULL, *ntw_savepoint, *savepoint_name; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &nesting); - - if (!nesting) { - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 1); + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); - if (Z_TYPE_P(pdo) != IS_OBJECT) { - RETURN_MM_FALSE; + if (!stop_buffer) { + PHALCON_INIT_VAR(stop_buffer); + ZVAL_BOOL(stop_buffer, 1); } - phalcon_property_incr(this_ptr, SL("_transactionLevel") TSRMLS_CC); - - PHALCON_OBS_VAR(transaction_level); - phalcon_read_property_this_quick(&transaction_level, this_ptr, SL("_transactionLevel"), 2789346594UL, PH_NOISY_CC); - if (PHALCON_IS_LONG(transaction_level, 1)) { - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "db:beginTransaction", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); - } - - phalcon_call_method_key(return_value, pdo, "begintransaction", 4233116368UL); - RETURN_MM(); - } else { - if (zend_is_true(transaction_level)) { - if (zend_is_true(nesting)) { + PHALCON_OBS_VAR(backends); + phalcon_read_property_this_quick(&backends, this_ptr, SL("_backends"), 2548946143UL, PH_NOISY_CC); - PHALCON_INIT_VAR(ntw_savepoint); - phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); - if (zend_is_true(ntw_savepoint)) { + phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(savepoint_name); - phalcon_call_method_key(savepoint_name, this_ptr, "getnestedtransactionsavepointname", 1903082728UL); + PHALCON_GET_HVALUE(backend); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "db:createSavepoint", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, savepoint_name, 259017035UL); - } + phalcon_call_method_p4_key(NULL, backend, "save", key_name, content, lifetime, stop_buffer, 274150868UL); - phalcon_call_method_p1_key(return_value, this_ptr, "createsavepoint", savepoint_name, 2980652562UL); - RETURN_MM(); - } - } - } + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_MM_FALSE; + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, rollback){ +static PHP_METHOD(Phalcon_Cache_Multiple, delete){ - zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; - zval *event_name = NULL, *ntw_savepoint, *savepoint_name; + zval *key_name, *backends, *backend = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &nesting); - - if (!nesting) { - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 1); - } - - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); - if (Z_TYPE_P(pdo) != IS_OBJECT) { - RETURN_MM_FALSE; - } - - PHALCON_OBS_VAR(transaction_level); - phalcon_read_property_this_quick(&transaction_level, this_ptr, SL("_transactionLevel"), 2789346594UL, PH_NOISY_CC); - if (!zend_is_true(transaction_level)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "There is no active transaction"); - return; - } - - if (PHALCON_IS_LONG(transaction_level, 1)) { - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "db:rollbackTransaction", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); - } + phalcon_fetch_params(1, 1, 0, &key_name); - phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); - phalcon_call_method_key(return_value, pdo, "rollback", 3199546639UL); - RETURN_MM(); - } else { - if (zend_is_true(transaction_level)) { - if (zend_is_true(nesting)) { + PHALCON_OBS_VAR(backends); + phalcon_read_property_this_quick(&backends, this_ptr, SL("_backends"), 2548946143UL, PH_NOISY_CC); - PHALCON_INIT_VAR(ntw_savepoint); - phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); - if (zend_is_true(ntw_savepoint)) { + phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(savepoint_name); - phalcon_call_method_key(savepoint_name, this_ptr, "getnestedtransactionsavepointname", 1903082728UL); + PHALCON_GET_HVALUE(backend); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "db:rollbackSavepoint", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, savepoint_name, 259017035UL); - } + phalcon_call_method_p1_key(NULL, backend, "delete", key_name, 150213496UL); - phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); - phalcon_call_method_p1_key(return_value, this_ptr, "rollbacksavepoint", savepoint_name, 3444395528UL); - RETURN_MM(); - } - } - } + zend_hash_move_forward_ex(ah0, &hp0); } - if (PHALCON_GT_LONG(transaction_level, 0)) { - phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); - } - RETURN_MM_FALSE; + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, commit){ +static PHP_METHOD(Phalcon_Cache_Multiple, exists){ - zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; - zval *event_name = NULL, *ntw_savepoint, *savepoint_name; + zval *key_name = NULL, *lifetime = NULL, *backends, *backend = NULL; + zval *exists = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &nesting); - - if (!nesting) { - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 1); - } + phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); - if (Z_TYPE_P(pdo) != IS_OBJECT) { - RETURN_MM_FALSE; + if (!key_name) { + PHALCON_INIT_VAR(key_name); } - PHALCON_OBS_VAR(transaction_level); - phalcon_read_property_this_quick(&transaction_level, this_ptr, SL("_transactionLevel"), 2789346594UL, PH_NOISY_CC); - if (!zend_is_true(transaction_level)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "There is no active transaction"); - return; + if (!lifetime) { + PHALCON_INIT_VAR(lifetime); } - if (PHALCON_IS_LONG(transaction_level, 1)) { - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "db:commitTransaction", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); - } - - phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); - phalcon_call_method_key(return_value, pdo, "commit", 3546528686UL); - RETURN_MM(); - } else { - if (zend_is_true(transaction_level)) { - if (zend_is_true(nesting)) { - - PHALCON_INIT_VAR(ntw_savepoint); - phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); - if (zend_is_true(ntw_savepoint)) { + PHALCON_OBS_VAR(backends); + phalcon_read_property_this_quick(&backends, this_ptr, SL("_backends"), 2548946143UL, PH_NOISY_CC); - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(savepoint_name); - phalcon_call_method_key(savepoint_name, this_ptr, "getnestedtransactionsavepointname", 1903082728UL); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "db:releaseSavepoint", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, savepoint_name, 259017035UL); - } + PHALCON_GET_HVALUE(backend); - phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); - phalcon_call_method_p1_key(return_value, this_ptr, "releasesavepoint", savepoint_name, 3823765247UL); - RETURN_MM(); - } - } + PHALCON_INIT_NVAR(exists); + phalcon_call_method_p2_key(exists, backend, "exists", key_name, lifetime, 2182199749UL); + if (zend_is_true(exists)) { + RETURN_MM_TRUE; } - } - if (PHALCON_GT_LONG(transaction_level, 0)) { - phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); + zend_hash_move_forward_ex(ah0, &hp0); } RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, getTransactionLevel){ - RETURN_MEMBER_QUICK(this_ptr, "_transactionLevel", 2789346594UL); -} -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, isUnderTransaction){ - zval *pdo; +#ifdef HAVE_CONFIG_H +#endif - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); - if (likely(Z_TYPE_P(pdo) == IS_OBJECT)) { - phalcon_call_method_key(return_value, pdo, "intransaction", 3613210146UL); - RETURN_MM(); - } - - RETURN_MM_FALSE; -} -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, getInternalHandler){ - zval *pdo; - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(pdo); - phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); - RETURN_CCTOR(pdo); +PHALCON_INIT_CLASS(Phalcon_CLI_Console_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Console, Exception, cli_console_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } @@ -22752,383 +22305,282 @@ static PHP_METHOD(Phalcon_Db_Adapter_Pdo, getInternalHandler){ -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Sqlite){ +PHALCON_INIT_CLASS(Phalcon_CLI_Console){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Adapter\\Pdo, Sqlite, db_adapter_pdo_sqlite, "phalcon\\db\\adapter\\pdo", phalcon_db_adapter_pdo_sqlite_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\CLI, Console, cli_console, phalcon_cli_console_method_entry, 0); - zend_declare_property_string(phalcon_db_adapter_pdo_sqlite_ce, SL("_type"), "sqlite", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_db_adapter_pdo_sqlite_ce, SL("_dialectType"), "sqlite", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_console_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_console_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_console_ce, SL("_modules"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_console_ce, SL("_moduleObject"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_db_adapter_pdo_sqlite_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); + zend_class_implements(phalcon_cli_console_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_events_eventsawareinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, connect){ +static PHP_METHOD(Phalcon_CLI_Console, __construct){ - zval *descriptor = NULL, *dbname; + zval *dependency_injector = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &descriptor); + phalcon_fetch_params(1, 0, 1, &dependency_injector); - if (!descriptor) { - PHALCON_INIT_VAR(descriptor); - } else { - PHALCON_SEPARATE_PARAM(descriptor); + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); } - if (!zend_is_true(descriptor)) { - PHALCON_OBS_NVAR(descriptor); - phalcon_read_property_this_quick(&descriptor, this_ptr, SL("_descriptor"), 691635363UL, PH_NOISY_CC); - } - if (!phalcon_array_isset_quick_string(descriptor, SS("dbname"), 35027788UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "dbname must be specified"); - return; - } else { - PHALCON_OBS_VAR(dbname); - phalcon_array_fetch_quick_string(&dbname, descriptor, SS("dbname"), 35027788UL, PH_NOISY); - phalcon_array_update_quick_string(&descriptor, SS("dsn"), 2090196170UL, &dbname, PH_COPY | PH_SEPARATE); + if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); } - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Sqlite", "connect", descriptor); - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeColumns){ - - zval *table, *schema = NULL, *columns, *dialect, *size_pattern; - zval *sql, *fetch_num, *describe, *old_column = NULL, *field = NULL; - zval *definition = NULL, *column_type = NULL, *pos = NULL, *attribute = NULL; - zval *matches = NULL, *match_one = NULL, *column_name = NULL, *column = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; +static PHP_METHOD(Phalcon_CLI_Console, setDI){ - PHALCON_MM_GROW(); + zval *dependency_injector; - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(0, 1, 0, &dependency_injector); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_cli_console_exception_ce, "Dependency Injector is invalid"); + return; } + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - PHALCON_INIT_VAR(columns); - array_init(columns); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(size_pattern); - ZVAL_STRING(size_pattern, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); - - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); +} + +static PHP_METHOD(Phalcon_CLI_Console, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} + +static PHP_METHOD(Phalcon_CLI_Console, setEventsManager){ + + zval *events_manager; + + phalcon_fetch_params(0, 1, 0, &events_manager); - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); - PHALCON_INIT_VAR(old_column); +} + +static PHP_METHOD(Phalcon_CLI_Console, getEventsManager){ + + + RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); +} + +static PHP_METHOD(Phalcon_CLI_Console, registerModules){ + + zval *modules; + + phalcon_fetch_params(0, 1, 0, &modules); - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + if (Z_TYPE_P(modules) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_cli_console_exception_ce, "Modules must be an Array"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_modules"), modules, 379092157UL TSRMLS_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { +} + +static PHP_METHOD(Phalcon_CLI_Console, addModules){ + + zval *modules, *original_modules, *register_modules; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &modules); - PHALCON_GET_HVALUE(field); + if (Z_TYPE_P(modules) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cli_console_exception_ce, "Modules must be an Array"); + return; + } - PHALCON_INIT_NVAR(definition); - array_init_size(definition, 1); - add_assoc_long_ex(definition, SS("bindType"), 2); + PHALCON_OBS_VAR(original_modules); + phalcon_read_property_this_quick(&original_modules, this_ptr, SL("_modules"), 379092157UL, PH_NOISY_CC); - PHALCON_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 2, PH_NOISY); + PHALCON_INIT_VAR(register_modules); + phalcon_fast_array_merge(register_modules, &modules, &original_modules TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_modules"), register_modules, 379092157UL TSRMLS_CC); - PHALCON_INIT_NVAR(pos); - phalcon_fast_stripos_str(pos, column_type, SL("int")); - if (PHALCON_IS_NOT_FALSE(pos)) { - phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE); - phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE); - - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); - - if (zend_is_true(attribute)) { - phalcon_array_update_string_bool(&definition, SL("autoIncrement"), 1, PH_SEPARATE); - } - } else { - if (phalcon_memnstr_str(column_type, SL("varchar"))) { - phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("date"))) { - phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("decimal"))) { - phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE); - phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("char"))) { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("datetime"))) { - phalcon_array_update_string_long(&definition, SL("type"), 4, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("text"))) { - phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("float"))) { - phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE); - phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("enum"))) { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - } else { - phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); - } - } - } - } - } - } - } - } - } - - if (phalcon_memnstr_str(column_type, SL("("))) { - - PHALCON_INIT_NVAR(matches); - - PHALCON_INIT_NVAR(pos); - phalcon_preg_match(pos, size_pattern, column_type, matches TSRMLS_CC); - - if (zend_is_true(pos)) { - if (phalcon_array_isset_long(matches, 1)) { - PHALCON_OBS_NVAR(match_one); - phalcon_array_fetch_long(&match_one, matches, 1, PH_NOISY); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &match_one, PH_COPY | PH_SEPARATE); - } - } - } - - if (phalcon_memnstr_str(column_type, SL("unsigned"))) { - phalcon_array_update_string_bool(&definition, SL("unsigned"), 1, PH_SEPARATE); - } - - if (!zend_is_true(old_column)) { - phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_SEPARATE); - } else { - phalcon_array_update_quick_string(&definition, SS("after"), 4053435767UL, &old_column, PH_COPY | PH_SEPARATE); - } - - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); - if (zend_is_true(attribute)) { - phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE); - } - - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 3, PH_NOISY); - if (zend_is_true(attribute)) { - phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_SEPARATE); - } - - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, field, 1, PH_NOISY); - - PHALCON_INIT_NVAR(column); - object_init_ex(column, phalcon_db_column_ce); - phalcon_call_method_p2_key(NULL, column, "__construct", column_name, definition, 1107214344UL); - - phalcon_array_append(&columns, column, PH_SEPARATE); - PHALCON_CPY_WRT(old_column, column_name); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CTOR(columns); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeIndexes){ +static PHP_METHOD(Phalcon_CLI_Console, getModules){ - zval *table, *schema = NULL, *dialect, *fetch_num, *sql, *describe; - zval *indexes, *index = NULL, *key_name = NULL, *empty_arr = NULL, *sql_index_describe = NULL; - zval *describe_index = NULL, *index_column = NULL, *column_name = NULL; - zval *index_objects, *index_columns = NULL, *name = NULL; - HashTable *ah0, *ah1, *ah2; - HashPosition hp0, hp1, hp2; - zval **hd; + + RETURN_MEMBER_QUICK(this_ptr, "_modules", 379092157UL); +} + +static PHP_METHOD(Phalcon_CLI_Console, handle){ + + zval *arguments = NULL, *dependency_injector, *events_manager; + zval *service = NULL, *router, *module_name, *event_name = NULL; + zval *status = NULL, *modules, *exception_msg = NULL, *module; + zval *path, *class_name = NULL, *module_object, *task_name; + zval *action_name, *params, *dispatcher, *task; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 0, 1, &arguments); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (!arguments) { + PHALCON_INIT_VAR(arguments); + array_init(arguments); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cli_console_exception_ce, "A dependency injection object is required to access internal services"); + return; + } - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describeindexes", table, schema, 689092630UL); + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "router", 1); - PHALCON_INIT_VAR(indexes); - array_init(indexes); + PHALCON_INIT_VAR(router); + phalcon_call_method_p1_key(router, dependency_injector, "getshared", service, 1727570332UL); + phalcon_call_method_p1_key(NULL, router, "handle", arguments, 866903697UL); - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(module_name); + phalcon_call_method_key(module_name, router, "getmodulename", 3538616428UL); + if (zend_is_true(module_name)) { + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "console:beforeStartModule", 1); - PHALCON_GET_HVALUE(index); + PHALCON_INIT_VAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, module_name, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } - PHALCON_OBS_NVAR(key_name); - phalcon_array_fetch_long(&key_name, index, 1, PH_NOISY); - if (!phalcon_array_isset(indexes, key_name)) { - PHALCON_INIT_NVAR(empty_arr); - array_init(empty_arr); - phalcon_array_update_zval(&indexes, key_name, &empty_arr, PH_COPY | PH_SEPARATE); + PHALCON_OBS_VAR(modules); + phalcon_read_property_this_quick(&modules, this_ptr, SL("_modules"), 379092157UL, PH_NOISY_CC); + if (!phalcon_array_isset(modules, module_name)) { + PHALCON_INIT_VAR(exception_msg); + PHALCON_CONCAT_SVS(exception_msg, "Module '", module_name, "' isn't registered in the console container"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_cli_console_exception_ce, exception_msg); + return; } - PHALCON_INIT_NVAR(sql_index_describe); - phalcon_call_method_p1_key(sql_index_describe, dialect, "describeindex", key_name, 1925282846UL); + PHALCON_OBS_VAR(module); + phalcon_array_fetch(&module, modules, module_name, PH_NOISY); + if (Z_TYPE_P(module) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cli_console_exception_ce, "Invalid module definition path"); + return; + } - PHALCON_INIT_NVAR(describe_index); - phalcon_call_method_p2_key(describe_index, this_ptr, "fetchall", sql_index_describe, fetch_num, 1636682248UL); + if (phalcon_array_isset_quick_string(module, SS("path"), 270591026UL)) { - phalcon_is_iterable(describe_index, &ah1, &hp1, 0, 0); + PHALCON_OBS_VAR(path); + phalcon_array_fetch_quick_string(&path, module, SS("path"), 270591026UL, PH_NOISY); + if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { + if (phalcon_require(path TSRMLS_CC) == FAILURE) { + return; + } + } else { + PHALCON_INIT_NVAR(exception_msg); + PHALCON_CONCAT_SVS(exception_msg, "Module definition path '", path, "\" doesn't exist"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_cli_console_exception_ce, exception_msg); + return; + } + } - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + if (phalcon_array_isset_quick_string(module, SS("className"), 362439804UL)) { + PHALCON_OBS_VAR(class_name); + phalcon_array_fetch_quick_string(&class_name, module, SS("className"), 362439804UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(class_name); + ZVAL_STRING(class_name, "Module", 1); + } - PHALCON_GET_HVALUE(index_column); + PHALCON_INIT_VAR(module_object); + phalcon_call_method_p1_key(module_object, dependency_injector, "get", class_name, 2090288933UL); + phalcon_call_method_key(NULL, module_object, "registerautoloaders", 1488981101UL); + phalcon_call_method_p1_key(NULL, module_object, "registerservices", dependency_injector, 3636598030UL); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_moduleObject"), module_object, 121977121UL TSRMLS_CC); - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, index_column, 2, PH_NOISY); - phalcon_array_update_append_multi_2(&indexes, key_name, column_name, 0); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "console:afterStartModule", 1); - zend_hash_move_forward_ex(ah1, &hp1); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, module_name, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } } - - zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_INIT_VAR(index_objects); - array_init(index_objects); + PHALCON_INIT_VAR(task_name); + phalcon_call_method_key(task_name, router, "gettaskname", 1614697657UL); - phalcon_is_iterable(indexes, &ah2, &hp2, 0, 0); + PHALCON_INIT_VAR(action_name); + phalcon_call_method_key(action_name, router, "getactionname", 2461134148UL); - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + PHALCON_INIT_VAR(params); + phalcon_call_method_key(params, router, "getparams", 1893744905UL); - PHALCON_GET_HKEY(name, ah2, hp2); - PHALCON_GET_HVALUE(index_columns); + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "dispatcher", 1); - PHALCON_INIT_NVAR(index); - object_init_ex(index, phalcon_db_index_ce); - phalcon_call_method_p2_key(NULL, index, "__construct", name, index_columns, 1107214344UL); + PHALCON_INIT_VAR(dispatcher); + phalcon_call_method_p1_key(dispatcher, dependency_injector, "getshared", service, 1727570332UL); + phalcon_call_method_p1_key(NULL, dispatcher, "settaskname", task_name, 2879829317UL); + phalcon_call_method_p1_key(NULL, dispatcher, "setactionname", action_name, 1505009872UL); + phalcon_call_method_p1_key(NULL, dispatcher, "setparams", params, 2707361429UL); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_array_update_zval(&index_objects, name, &index, PH_COPY | PH_SEPARATE); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "console:beforeHandleTask", 1); - zend_hash_move_forward_ex(ah2, &hp2); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, dispatcher, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } } - RETURN_CTOR(index_objects); + PHALCON_INIT_VAR(task); + phalcon_call_method_key(task, dispatcher, "dispatch", 4202735573UL); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "console:afterHandleTask", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, task, 259017035UL); + } + + RETURN_CCTOR(task); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeReferences){ - zval *table, *schema = NULL, *dialect, *sql, *fetch_num, *describe; - zval *reference_objects, *reference_describe = NULL; - zval *number = NULL, *constraint_name = NULL, *referenced_table = NULL; - zval *from = NULL, *to = NULL, *columns = NULL, *referenced_columns = NULL; - zval *reference_array = NULL, *reference = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describereferences", table, schema, 1939869288UL); - - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); - - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - - PHALCON_INIT_VAR(reference_objects); - array_init(reference_objects); - - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(number, ah0, hp0); - PHALCON_GET_HVALUE(reference_describe); - - PHALCON_INIT_NVAR(constraint_name); - PHALCON_CONCAT_SV(constraint_name, "foreign_key_", number); - - PHALCON_OBS_NVAR(referenced_table); - phalcon_array_fetch_long(&referenced_table, reference_describe, 2, PH_NOISY); - - PHALCON_OBS_NVAR(from); - phalcon_array_fetch_long(&from, reference_describe, 3, PH_NOISY); - - PHALCON_OBS_NVAR(to); - phalcon_array_fetch_long(&to, reference_describe, 4, PH_NOISY); - - PHALCON_INIT_NVAR(columns); - array_init_size(columns, 1); - phalcon_array_append(&columns, from, PH_SEPARATE); - - PHALCON_INIT_NVAR(referenced_columns); - array_init_size(referenced_columns, 1); - phalcon_array_append(&referenced_columns, to, PH_SEPARATE); - - PHALCON_INIT_NVAR(reference_array); - array_init_size(reference_array, 4); - add_assoc_null_ex(reference_array, SS("referencedSchema")); - phalcon_array_update_quick_string(&reference_array, SS("referencedTable"), 3390337856UL, &referenced_table, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&reference_array, SS("columns"), 1041822630UL, &columns, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&reference_array, SS("referencedColumns"), 1045113721UL, &referenced_columns, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_NVAR(reference); - object_init_ex(reference, phalcon_db_reference_ce); - phalcon_call_method_p2_key(NULL, reference, "__construct", constraint_name, reference_array, 1107214344UL); - - phalcon_array_update_zval(&reference_objects, constraint_name, &reference, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CTOR(reference_objects); -} -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, useExplicitIdValue){ +#ifdef HAVE_CONFIG_H +#endif - RETURN_TRUE; + + + + +PHALCON_INIT_CLASS(Phalcon_CLI_Dispatcher_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Dispatcher, Exception, cli_dispatcher_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } @@ -23144,220 +22596,134 @@ static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, useExplicitIdValue){ -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Mysql){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Adapter\\Pdo, Mysql, db_adapter_pdo_mysql, "phalcon\\db\\adapter\\pdo", phalcon_db_adapter_pdo_mysql_method_entry, 0); +PHALCON_INIT_CLASS(Phalcon_CLI_Dispatcher){ - zend_declare_property_string(phalcon_db_adapter_pdo_mysql_ce, SL("_type"), "mysql", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_db_adapter_pdo_mysql_ce, SL("_dialectType"), "mysql", ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI, Dispatcher, cli_dispatcher, "phalcon\\dispatcher", phalcon_cli_dispatcher_method_entry, 0); - zend_class_implements(phalcon_db_adapter_pdo_mysql_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); + zend_declare_property_string(phalcon_cli_dispatcher_ce, SL("_handlerSuffix"), "Task", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_cli_dispatcher_ce, SL("_defaultHandler"), "main", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_cli_dispatcher_ce, SL("_defaultAction"), "main", ZEND_ACC_PROTECTED TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, escapeIdentifier){ - - zval *identifier, *domain, *name; +static PHP_METHOD(Phalcon_CLI_Dispatcher, setTaskSuffix){ - PHALCON_MM_GROW(); + zval *task_suffix; - phalcon_fetch_params(1, 1, 0, &identifier); + phalcon_fetch_params(0, 1, 0, &task_suffix); - if (Z_TYPE_P(identifier) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_handlerSuffix"), task_suffix, 1659190583UL TSRMLS_CC); - PHALCON_OBS_VAR(domain); - phalcon_array_fetch_long(&domain, identifier, 0, PH_NOISY); +} + +static PHP_METHOD(Phalcon_CLI_Dispatcher, setDefaultTask){ + + zval *task_name; + + phalcon_fetch_params(0, 1, 0, &task_name); - PHALCON_OBS_VAR(name); - phalcon_array_fetch_long(&name, identifier, 1, PH_NOISY); - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_CONCAT_SVSVS(return_value, "`", domain, "`.`", name, "`"); - RETURN_MM(); - } + phalcon_update_property_this_quick(this_ptr, SL("_defaultHandler"), task_name, 2940762855UL TSRMLS_CC); - PHALCON_CONCAT_VSV(return_value, domain, ".", name); +} + +static PHP_METHOD(Phalcon_CLI_Dispatcher, setTaskName){ + + zval *task_name; + + phalcon_fetch_params(0, 1, 0, &task_name); - RETURN_MM(); - } - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_CONCAT_SVS(return_value, "`", identifier, "`"); - RETURN_MM(); - } + phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), task_name, 2743819555UL TSRMLS_CC); - RETURN_CCTOR(identifier); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ +static PHP_METHOD(Phalcon_CLI_Dispatcher, getTaskName){ - zval *table, *schema = NULL, *dialect, *ztrue, *sql, *fetch_num; - zval *describe, *old_column = NULL, *size_pattern, *columns; - zval *field = NULL, *definition = NULL, *column_type = NULL, *matches = NULL; - zval *pos = NULL, *match_one = NULL, *attribute = NULL, *column_name = NULL; - zval *column = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + + RETURN_MEMBER_QUICK(this_ptr, "_handlerName", 2743819555UL); +} + +static PHP_METHOD(Phalcon_CLI_Dispatcher, _throwDispatchException){ + + zval *message, *exception_code = NULL, *exception, *events_manager; + zval *event_name, *status; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 1, 1, &message, &exception_code); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (!exception_code) { + PHALCON_INIT_VAR(exception_code); + ZVAL_LONG(exception_code, 0); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(ztrue); - ZVAL_BOOL(ztrue, 1); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); - - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); - - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - - PHALCON_INIT_VAR(old_column); + PHALCON_INIT_VAR(exception); + object_init_ex(exception, phalcon_cli_dispatcher_exception_ce); + phalcon_call_method_p2_key(NULL, exception, "__construct", message, exception_code, 1107214344UL); - PHALCON_INIT_VAR(size_pattern); - ZVAL_STRING(size_pattern, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_VAR(columns); - array_init(columns); + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "dispatch:beforeException", 1); - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, exception, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + phalcon_throw_exception(exception TSRMLS_CC); + return; +} + +static PHP_METHOD(Phalcon_CLI_Dispatcher, _handleException){ + + zval *exception, *events_manager, *event_name; + zval *status; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &exception); - PHALCON_GET_HVALUE(field); + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(definition); - array_init_size(definition, 1); - add_assoc_long_ex(definition, SS("bindType"), 2); + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "dispatch:beforeException", 1); - PHALCON_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); + PHALCON_INIT_VAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, exception, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } - while (1) { - - if (phalcon_memnstr_str(column_type, SL("enum"))) { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - break; - } - - if (phalcon_memnstr_str(column_type, SL("int"))) { - phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("isNumeric"), 1643974676UL, &ztrue, PH_COPY | PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE); - break; - } - - if (phalcon_memnstr_str(column_type, SL("varchar"))) { - phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); - break; - } - - if (phalcon_memnstr_str(column_type, SL("datetime"))) { - phalcon_array_update_string_long(&definition, SL("type"), 4, PH_SEPARATE); - break; - } - - if (phalcon_memnstr_str(column_type, SL("decimal"))) { - phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("isNumeric"), 1643974676UL, &ztrue, PH_COPY | PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); - break; - } - - if (phalcon_memnstr_str(column_type, SL("char"))) { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - break; - } - - if (phalcon_memnstr_str(column_type, SL("date"))) { - phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE); - break; - } - - if (phalcon_memnstr_str(column_type, SL("text"))) { - phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); - break; - } - - if (phalcon_memnstr_str(column_type, SL("float"))) { - phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("isNumeric"), 1643974676UL, &ztrue, PH_COPY | PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); - break; - } - - phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); - break; - } - - if (phalcon_memnstr_str(column_type, SL("("))) { - - PHALCON_INIT_NVAR(matches); - - PHALCON_INIT_NVAR(pos); - phalcon_preg_match(pos, size_pattern, column_type, matches TSRMLS_CC); + PHALCON_MM_RESTORE(); +} - if (zend_is_true(pos)) { - if (phalcon_array_isset_long(matches, 1)) { - PHALCON_OBS_NVAR(match_one); - phalcon_array_fetch_long(&match_one, matches, 1, PH_NOISY); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &match_one, PH_COPY | PH_SEPARATE); - } - } - } - - if (phalcon_memnstr_str(column_type, SL("unsigned"))) { - phalcon_array_update_quick_string(&definition, SS("unsigned"), 1143113122UL, &ztrue, PH_COPY | PH_SEPARATE); - } - - if (!zend_is_true(old_column)) { - phalcon_array_update_quick_string(&definition, SS("first"), 4252613933UL, &ztrue, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_quick_string(&definition, SS("after"), 4053435767UL, &old_column, PH_COPY | PH_SEPARATE); - } - - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 3, PH_NOISY); - if (PHALCON_IS_STRING(attribute, "PRI")) { - phalcon_array_update_quick_string(&definition, SS("primary"), 482916521UL, &ztrue, PH_COPY | PH_SEPARATE); - } - - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 2, PH_NOISY); - if (PHALCON_IS_STRING(attribute, "NO")) { - phalcon_array_update_quick_string(&definition, SS("notNull"), 1960377425UL, &ztrue, PH_COPY | PH_SEPARATE); - } - - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); - if (PHALCON_IS_STRING(attribute, "auto_increment")) { - phalcon_array_update_quick_string(&definition, SS("autoIncrement"), 2492144707UL, &ztrue, PH_COPY | PH_SEPARATE); - } - - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); - - PHALCON_INIT_NVAR(column); - object_init_ex(column, phalcon_db_column_ce); - phalcon_call_method_p2_key(NULL, column, "__construct", column_name, definition, 1107214344UL); - - phalcon_array_append(&columns, column, PH_SEPARATE); - PHALCON_CPY_WRT(old_column, column_name); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CTOR(columns); +static PHP_METHOD(Phalcon_CLI_Dispatcher, getTaskClass){ + + + PHALCON_MM_GROW(); + + phalcon_call_method_key(return_value, this_ptr, "gethandlername", 1725429572UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_CLI_Dispatcher, getLastTask){ + + + RETURN_MEMBER_QUICK(this_ptr, "_lastHandler", 1315517974UL); +} + +static PHP_METHOD(Phalcon_CLI_Dispatcher, getActiveTask){ + + + RETURN_MEMBER_QUICK(this_ptr, "_activeHandler", 2923197278UL); } @@ -23372,264 +22738,174 @@ static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ +PHALCON_INIT_CLASS(Phalcon_CLI_Router_Exception){ -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Oracle){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Router, Exception, cli_router_exception, "phalcon\\exception", NULL, 0); - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Adapter\\Pdo, Oracle, db_adapter_pdo_oracle, "phalcon\\db\\adapter\\pdo", phalcon_db_adapter_pdo_oracle_method_entry, 0); + return SUCCESS; +} - zend_declare_property_string(phalcon_db_adapter_pdo_oracle_ce, SL("_type"), "oci", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_db_adapter_pdo_oracle_ce, SL("_dialectType"), "oracle", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_db_adapter_pdo_oracle_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_CLI_Router){ + + PHALCON_REGISTER_CLASS(Phalcon\\CLI, Router, cli_router, phalcon_cli_router_method_entry, 0); + + zend_declare_property_null(phalcon_cli_router_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_router_ce, SL("_module"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_router_ce, SL("_task"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_router_ce, SL("_action"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_router_ce, SL("_params"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_router_ce, SL("_defaultModule"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_router_ce, SL("_defaultTask"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_router_ce, SL("_defaultAction"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_cli_router_ce, SL("_defaultParams"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_cli_router_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, connect){ - - zval *descriptor = NULL, *startup, *value = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; +static PHP_METHOD(Phalcon_CLI_Router, __construct){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &descriptor); - - if (!descriptor) { - PHALCON_INIT_VAR(descriptor); - } else { - PHALCON_SEPARATE_PARAM(descriptor); - } - - if (!zend_is_true(descriptor)) { - PHALCON_OBS_NVAR(descriptor); - phalcon_read_property_this_quick(&descriptor, this_ptr, SL("_descriptor"), 691635363UL, PH_NOISY_CC); - } + phalcon_update_property_empty_array(phalcon_cli_router_ce, this_ptr, SL("_params") TSRMLS_CC); - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Oracle", "connect", descriptor); + phalcon_update_property_empty_array(phalcon_cli_router_ce, this_ptr, SL("_defaultParams") TSRMLS_CC); - if (phalcon_array_isset_quick_string(descriptor, SS("startup"), 1765694744UL)) { +} + +static PHP_METHOD(Phalcon_CLI_Router, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); - PHALCON_OBS_VAR(startup); - phalcon_array_fetch_quick_string(&startup, descriptor, SS("startup"), 1765694744UL, PH_NOISY); - if (Z_TYPE_P(startup) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - phalcon_is_iterable(startup, &ah0, &hp0, 0, 0); +} + +static PHP_METHOD(Phalcon_CLI_Router, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} + +static PHP_METHOD(Phalcon_CLI_Router, setDefaultModule){ + + zval *module_name; + + phalcon_fetch_params(0, 1, 0, &module_name); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + phalcon_update_property_this_quick(this_ptr, SL("_defaultModule"), module_name, 3959488399UL TSRMLS_CC); - PHALCON_GET_HVALUE(value); +} + +static PHP_METHOD(Phalcon_CLI_Router, setDefaultTask){ + + zval *task_name; + + phalcon_fetch_params(0, 1, 0, &task_name); - phalcon_call_method_p1_key(NULL, this_ptr, "execute", value, 3117639032UL); + phalcon_update_property_this_quick(this_ptr, SL("_defaultTask"), task_name, 3852862556UL TSRMLS_CC); - zend_hash_move_forward_ex(ah0, &hp0); - } +} + +static PHP_METHOD(Phalcon_CLI_Router, setDefaultAction){ + + zval *action_name; + + phalcon_fetch_params(0, 1, 0, &action_name); - } - } + phalcon_update_property_this_quick(this_ptr, SL("_defaultAction"), action_name, 895696999UL TSRMLS_CC); - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, describeColumns){ +static PHP_METHOD(Phalcon_CLI_Router, handle){ - zval *table, *schema = NULL, *columns, *dialect, *sql, *fetch_num; - zval *describe, *old_column = NULL, *field = NULL, *definition = NULL; - zval *column_size = NULL, *column_precision = NULL, *column_scale = NULL; - zval *column_type = NULL, *attribute = NULL, *column_name = NULL; - zval *column = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *arguments = NULL, *module_name = NULL, *task_name = NULL, *action_name = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 0, 1, &arguments); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (!arguments) { + PHALCON_INIT_VAR(arguments); + array_init(arguments); + } else { + PHALCON_SEPARATE_PARAM(arguments); } - PHALCON_INIT_VAR(columns); - array_init(columns); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); - - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); - - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - - PHALCON_INIT_VAR(old_column); - - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(field); - - PHALCON_INIT_NVAR(definition); - array_init_size(definition, 1); - add_assoc_long_ex(definition, SS("bindType"), 2); - - PHALCON_OBS_NVAR(column_size); - phalcon_array_fetch_long(&column_size, field, 2, PH_NOISY); - - PHALCON_OBS_NVAR(column_precision); - phalcon_array_fetch_long(&column_precision, field, 3, PH_NOISY); - - PHALCON_OBS_NVAR(column_scale); - phalcon_array_fetch_long(&column_scale, field, 4, PH_NOISY); - - PHALCON_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); - - if (phalcon_memnstr_str(column_type, SL("NUMBER"))) { - phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE); - phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_precision, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("scale"), 458672173UL, &column_scale, PH_COPY | PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("INTEGER"))) { - phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE); - phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_precision, PH_COPY | PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("VARCHAR2"))) { - phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_size, PH_COPY | PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("FLOAT"))) { - phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE); - phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_size, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("scale"), 458672173UL, &column_scale, PH_COPY | PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("TIMESTAMP"))) { - phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("RAW"))) { - phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("BLOB"))) { - phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("CLOB"))) { - phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("VARCHAR2"))) { - phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_size, PH_COPY | PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("CHAR"))) { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_size, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); - } - } - } - } - } - } - } - } - } - } - - if (Z_TYPE_P(old_column) == IS_NULL) { - phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_SEPARATE); - } else { - phalcon_array_update_quick_string(&definition, SS("after"), 4053435767UL, &old_column, PH_COPY | PH_SEPARATE); - } + if (Z_TYPE_P(arguments) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_cli_router_exception_ce, "Arguments must be an Array"); + return; + } - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 6, PH_NOISY); - if (PHALCON_IS_STRING(attribute, "P")) { - phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE); - } + PHALCON_INIT_VAR(module_name); - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); - if (PHALCON_IS_STRING(attribute, "N")) { - phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_SEPARATE); - } + PHALCON_INIT_VAR(task_name); - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); + PHALCON_INIT_VAR(action_name); - PHALCON_INIT_NVAR(column); - object_init_ex(column, phalcon_db_column_ce); - phalcon_call_method_p2_key(NULL, column, "__construct", column_name, definition, 1107214344UL); + if (phalcon_array_isset_quick_string(arguments, SS("module"), 3565923467UL)) { + PHALCON_OBS_NVAR(module_name); + phalcon_array_fetch_quick_string(&module_name, arguments, SS("module"), 3565923467UL, PH_NOISY); + phalcon_array_unset_string(&arguments, SS("module"), PH_SEPARATE); + } - phalcon_array_append(&columns, column, PH_SEPARATE); - PHALCON_CPY_WRT(old_column, column_name); + if (phalcon_array_isset_quick_string(arguments, SS("task"), 275333720UL)) { + PHALCON_OBS_NVAR(task_name); + phalcon_array_fetch_quick_string(&task_name, arguments, SS("task"), 275333720UL, PH_NOISY); + phalcon_array_unset_string(&arguments, SS("task"), PH_SEPARATE); + } - zend_hash_move_forward_ex(ah0, &hp0); + if (phalcon_array_isset_quick_string(arguments, SS("action"), 502132067UL)) { + PHALCON_OBS_NVAR(action_name); + phalcon_array_fetch_quick_string(&action_name, arguments, SS("action"), 502132067UL, PH_NOISY); + phalcon_array_unset_string(&arguments, SS("action"), PH_SEPARATE); } - RETURN_CTOR(columns); + phalcon_update_property_this_quick(this_ptr, SL("_module"), module_name, 4176304298UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_task"), task_name, 3991100087UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_action"), action_name, 1112512898UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_params"), arguments, 3223731112UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, lastInsertId){ - - zval *sequence_name = NULL, *sql, *fetch_num, *ret, *insert_id; +static PHP_METHOD(Phalcon_CLI_Router, getModuleName){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &sequence_name); - - if (!sequence_name) { - PHALCON_INIT_VAR(sequence_name); - } - - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT ", sequence_name, ".CURRVAL FROM dual"); - - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); - - PHALCON_INIT_VAR(ret); - phalcon_call_method_p2_key(ret, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - - PHALCON_OBS_VAR(insert_id); - phalcon_array_fetch_long(&insert_id, ret, 0, PH_NOISY); - RETURN_CCTOR(insert_id); + RETURN_MEMBER_QUICK(this_ptr, "_module", 4176304298UL); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, useExplicitIdValue){ +static PHP_METHOD(Phalcon_CLI_Router, getTaskName){ - RETURN_FALSE; + RETURN_MEMBER_QUICK(this_ptr, "_task", 3991100087UL); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, getDefaultIdValue){ - - zval *null_value; +static PHP_METHOD(Phalcon_CLI_Router, getActionName){ - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(null_value); - ZVAL_STRING(null_value, "default", 1); - object_init_ex(return_value, phalcon_db_rawvalue_ce); - phalcon_call_method_p1_key(NULL, return_value, "__construct", null_value, 1107214344UL); - - RETURN_MM(); + RETURN_MEMBER_QUICK(this_ptr, "_action", 1112512898UL); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, supportSequences){ +static PHP_METHOD(Phalcon_CLI_Router, getParams){ - RETURN_TRUE; + RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); } @@ -23644,273 +22920,221 @@ static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, supportSequences){ +PHALCON_INIT_CLASS(Phalcon_CLI_Task){ -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Postgresql){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI, Task, cli_task, "phalcon\\di\\injectable", phalcon_cli_task_method_entry, 0); - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Adapter\\Pdo, Postgresql, db_adapter_pdo_postgresql, "phalcon\\db\\adapter\\pdo", phalcon_db_adapter_pdo_postgresql_method_entry, 0); + return SUCCESS; +} - zend_declare_property_string(phalcon_db_adapter_pdo_postgresql_ce, SL("_type"), "pgsql", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_db_adapter_pdo_postgresql_ce, SL("_dialectType"), "postgresql", ZEND_ACC_PROTECTED TSRMLS_CC); +static PHP_METHOD(Phalcon_CLI_Task, __construct){ - zend_class_implements(phalcon_db_adapter_pdo_postgresql_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); - return SUCCESS; + } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, connect){ - zval *descriptor = NULL, *schema = NULL, *sql; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &descriptor); - - if (!descriptor) { - PHALCON_INIT_VAR(descriptor); - } else { - PHALCON_SEPARATE_PARAM(descriptor); - } - - if (!zend_is_true(descriptor)) { - PHALCON_OBS_NVAR(descriptor); - phalcon_read_property_this_quick(&descriptor, this_ptr, SL("_descriptor"), 691635363UL, PH_NOISY_CC); - } - - PHALCON_INIT_VAR(schema); - if (phalcon_array_isset_quick_string(descriptor, SS("schema"), 2259341622UL)) { - PHALCON_OBS_NVAR(schema); - phalcon_array_fetch_quick_string(&schema, descriptor, SS("schema"), 2259341622UL, PH_NOISY); - phalcon_array_unset_string(&descriptor, SS("schema"), PH_SEPARATE); - } - - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Postgresql", "connect", descriptor); - - if (Z_TYPE_P(schema) == IS_STRING) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SET search_path TO '", schema, "'"); - phalcon_call_method_p1_key(NULL, this_ptr, "execute", sql, 3117639032UL); - } - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, describeColumns){ +#ifdef HAVE_CONFIG_H +#endif - zval *table, *schema = NULL, *columns, *dialect, *sql, *fetch_num; - zval *describe, *old_column = NULL, *field = NULL, *definition = NULL; - zval *char_size = NULL, *numeric_size = NULL, *column_type = NULL; - zval *attribute = NULL, *column_name = NULL, *column = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); + + + +static inline void phalcon_config_adapter_ini_update_zval_directive(zval **arr, zval *section, zval *directive, zval **value, int flags TSRMLS_DC) { + zval *temp1 = NULL, *temp2 = NULL, *index = NULL; + int i, n; + + n = zend_hash_num_elements(Z_ARRVAL_P(directive)); + + if (Z_TYPE_PP(arr) == IS_ARRAY) { + phalcon_array_fetch(&temp1, *arr, section, PH_SILENT); + if (Z_REFCOUNT_P(temp1) > 1) { + phalcon_array_update_zval(arr, section, &temp1, PH_COPY | PH_CTOR); + } + if (Z_TYPE_P(temp1) != IS_ARRAY) { + convert_to_array(temp1); + phalcon_array_update_zval(arr, section, &temp1, PH_COPY); + } + + for (i = 0; i < n - 1; i++) { + phalcon_array_fetch_long(&index, directive, i, PH_NOISY); + + phalcon_array_fetch(&temp2, temp1, index, PH_SILENT); + if (Z_REFCOUNT_P(temp2) > 1) { + phalcon_array_update_zval(&temp1, index, &temp2, PH_COPY | PH_CTOR); + } + if (Z_TYPE_P(temp2) != IS_ARRAY) { + convert_to_array(temp2); + phalcon_array_update_zval(&temp1, index, &temp2, PH_COPY); + } + zval_ptr_dtor(&index); + + if (temp1 != NULL) { + zval_ptr_dtor(&temp1); + } + temp1 = temp2; + temp2 = NULL; + } + + phalcon_array_fetch_long(&index, directive, n - 1, PH_NOISY); + phalcon_array_update_zval(&temp1, index, value, PH_COPY); + + zval_ptr_dtor(&index); + + if (temp1 != NULL) { + zval_ptr_dtor(&temp1); + } } +} + +PHALCON_INIT_CLASS(Phalcon_Config_Adapter_Ini){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Config\\Adapter, Ini, config_adapter_ini, "phalcon\\config", phalcon_config_adapter_ini_method_entry, 0); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct){ + + zval *file_path, *process_sections, *ini_config; + zval *exception_message, *config, *directives = NULL; + zval *section = NULL, *value = NULL, *key = NULL, *directive_parts = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &file_path); - PHALCON_INIT_VAR(columns); - array_init(columns); - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); + PHALCON_INIT_VAR(process_sections); + ZVAL_BOOL(process_sections, 1); - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + PHALCON_INIT_VAR(ini_config); + phalcon_call_func_p2(ini_config, "parse_ini_file", file_path, process_sections); - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + if (PHALCON_IS_FALSE(ini_config)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Configuration file ", file_path, " can't be loaded"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_config_exception_ce, exception_message); + return; + } - PHALCON_INIT_VAR(old_column); + PHALCON_INIT_VAR(config); + array_init(config); - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + phalcon_is_iterable(ini_config, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_GET_HVALUE(field); - - PHALCON_INIT_NVAR(definition); - array_init_size(definition, 1); - add_assoc_long_ex(definition, SS("bindType"), 2); - - PHALCON_OBS_NVAR(char_size); - phalcon_array_fetch_long(&char_size, field, 2, PH_NOISY); - - PHALCON_OBS_NVAR(numeric_size); - phalcon_array_fetch_long(&numeric_size, field, 3, PH_NOISY); - - PHALCON_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); + PHALCON_GET_HKEY(section, ah0, hp0); + PHALCON_GET_HVALUE(directives); - if (phalcon_memnstr_str(column_type, SL("int"))) { - phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE); - phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &numeric_size, PH_COPY | PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("varying"))) { - phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &char_size, PH_COPY | PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("date"))) { - phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("numeric"))) { - phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE); - phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &numeric_size, PH_COPY | PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("char"))) { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &char_size, PH_COPY | PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("timestamp"))) { - phalcon_array_update_string_long(&definition, SL("type"), 4, PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("text"))) { - phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &char_size, PH_COPY | PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("float"))) { - phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE); - phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &numeric_size, PH_COPY | PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("bool"))) { - phalcon_array_update_string_long(&definition, SL("type"), 8, PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("bindType"), 5, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(column_type, SL("uuid"))) { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - phalcon_array_update_string_long(&definition, SL("size"), 36, PH_SEPARATE); - } else { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &char_size, PH_COPY | PH_SEPARATE); - } - } - } - } - } - } - } - } + if (unlikely(Z_TYPE_P(directives) != IS_ARRAY)) { + Z_ADDREF_P(directives); + if (phalcon_array_update_zval(&config, section, &directives, 0) != SUCCESS) { + Z_DELREF_P(directives); } + zend_hash_move_forward_ex(ah0, &hp0); + continue; } - if (phalcon_memnstr_str(column_type, SL("unsigned"))) { - phalcon_array_update_string_bool(&definition, SL("unsigned"), 1, PH_SEPARATE); - } - - if (Z_TYPE_P(old_column) == IS_NULL) { - phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_SEPARATE); - } else { - phalcon_array_update_quick_string(&definition, SS("after"), 4053435767UL, &old_column, PH_COPY | PH_SEPARATE); - } - - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); - if (PHALCON_IS_STRING(attribute, "PRI")) { - phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE); - } + phalcon_is_iterable(directives, &ah1, &hp1, 0, 0); - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 4, PH_NOISY); - if (PHALCON_IS_STRING(attribute, "NO")) { - phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_SEPARATE); + if (zend_hash_num_elements(ah1) == 0) { + Z_ADDREF_P(directives); + phalcon_array_update_zval(&config, section, &directives, 0); + zend_hash_move_forward_ex(ah0, &hp0); + continue; } - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 6, PH_NOISY); - if (PHALCON_IS_STRING(attribute, "auto_increment")) { - phalcon_array_update_string_bool(&definition, SL("autoIncrement"), 1, PH_SEPARATE); - } + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); + PHALCON_GET_HKEY(key, ah1, hp1); + PHALCON_GET_HVALUE(value); - PHALCON_INIT_NVAR(column); - object_init_ex(column, phalcon_db_column_ce); - phalcon_call_method_p2_key(NULL, column, "__construct", column_name, definition, 1107214344UL); + if (phalcon_memnstr_str(key, SL("."))) { + PHALCON_INIT_NVAR(directive_parts); + phalcon_fast_explode_str(directive_parts, SL("."), key); + phalcon_config_adapter_ini_update_zval_directive(&config, section, directive_parts, &value, 0 TSRMLS_CC); + } else { + phalcon_array_update_multi_2(&config, section, key, &value, 0); + } - phalcon_array_append(&columns, column, PH_SEPARATE); - PHALCON_CPY_WRT(old_column, column_name); + zend_hash_move_forward_ex(ah1, &hp1); + } zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CTOR(columns); + PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Config\\Adapter\\Ini", "__construct", config); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, useExplicitIdValue){ - - RETURN_TRUE; -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, getDefaultIdValue){ - zval *null_value, *default_value; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(null_value); - ZVAL_STRING(null_value, "default", 1); - - PHALCON_INIT_VAR(default_value); - object_init_ex(default_value, phalcon_db_rawvalue_ce); - phalcon_call_method_p1_key(NULL, default_value, "__construct", null_value, 1107214344UL); - - RETURN_CTOR(default_value); -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, supportSequences){ - RETURN_TRUE; -} +PHALCON_INIT_CLASS(Phalcon_Config_Adapter_Json){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Config\\Adapter, Json, config_adapter_json, "phalcon\\config", phalcon_config_adapter_json_method_entry, 0); -#ifdef HAVE_CONFIG_H -#endif + return SUCCESS; +} +static PHP_METHOD(Phalcon_Config_Adapter_Json, __construct){ + zval *file_path, *contents, *array; + phalcon_fetch_params(0, 1, 0, &file_path); + ALLOC_INIT_ZVAL(contents); + ALLOC_INIT_ZVAL(array); + phalcon_file_get_contents(contents, file_path TSRMLS_CC); + if (Z_TYPE_P(contents) == IS_STRING) { + phalcon_json_decode(array, contents, 1 TSRMLS_CC); + } -PHALCON_INIT_CLASS(Phalcon_Db_Exception){ + zval_ptr_dtor(&contents); - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db, Exception, db_exception, "phalcon\\exception", NULL, 0); + if (Z_TYPE_P(array) != IS_ARRAY) { + zval_dtor(array); + array_init_size(array, 0); + } - return SUCCESS; + phalcon_config_construct_internal(getThis(), array TSRMLS_CC); + zval_ptr_dtor(&array); } - #ifdef HAVE_CONFIG_H #endif -PHALCON_INIT_CLASS(Phalcon_Db_ReferenceInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ReferenceInterface, db_referenceinterface, phalcon_db_referenceinterface_method_entry); + + +PHALCON_INIT_CLASS(Phalcon_Config_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Config, Exception, config_exception, "phalcon\\exception", NULL, 0); return SUCCESS; } @@ -23919,928 +23143,473 @@ PHALCON_INIT_CLASS(Phalcon_Db_ReferenceInterface){ +#ifdef HAVE_CONFIG_H +#endif +static zend_object_handlers phalcon_config_object_handlers; +typedef struct _phalcon_config_object { + zend_object obj; /**< Zend object data */ + HashTable* props; /**< Properties */ +} phalcon_config_object; -#ifdef HAVE_CONFIG_H +static inline phalcon_config_object* fetchPhalconConfigObject(zval* zobj TSRMLS_DC) +{ +#ifndef PHALCON_RELEASE + assert(Z_TYPE_P(zobj) == IS_OBJECT && instanceof_function(Z_OBJCE_P(zobj), phalcon_config_ce TSRMLS_CC)); #endif + return (phalcon_config_object*)zend_objects_get_address(zobj TSRMLS_CC); +} +static int phalcon_config_count_elements(zval *object, long int *count TSRMLS_DC) +{ + phalcon_config_object* obj = fetchPhalconConfigObject(object TSRMLS_CC); + *count = zend_hash_num_elements(obj->props); + return SUCCESS; +} +static zval* phalcon_config_read_internal(phalcon_config_object *object, zval *key, int type TSRMLS_DC) +{ + zval **retval; + if (UNEXPECTED(!key)) { + return EG(uninitialized_zval_ptr); + } + retval = phalcon_hash_get(object->props, key, type); + return retval ? *retval : NULL; +} +static zval* phalcon_config_read_property(zval *object, zval *offset, int type ZLK_DC TSRMLS_DC) +{ + phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC); + if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) { + return zend_get_std_object_handlers()->read_property(object, offset, type ZLK_CC TSRMLS_CC); + } -PHALCON_INIT_CLASS(Phalcon_Debug){ + return phalcon_config_read_internal(obj, offset, type TSRMLS_CC); +} - PHALCON_REGISTER_CLASS(Phalcon, Debug, debug, phalcon_debug_method_entry, 0); +static zval* phalcon_config_read_dimension(zval *object, zval *offset, int type TSRMLS_DC) +{ + phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC); - zend_declare_property_string(phalcon_debug_ce, SL("_uri"), "http://static.phalconphp.com/debug/1.2.0/", ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_string(phalcon_debug_ce, SL("_theme"), "default", ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_bool(phalcon_debug_ce, SL("_hideDocumentRoot"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_debug_ce, SL("_showBackTrace"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_debug_ce, SL("_showFiles"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_debug_ce, SL("_showFileFragment"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_debug_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_debug_ce, SL("_isActive"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) { + return zend_get_std_object_handlers()->read_dimension(object, offset, type TSRMLS_CC); + } - return SUCCESS; + return phalcon_config_read_internal(obj, offset, type TSRMLS_CC); } -static PHP_METHOD(Phalcon_Debug, setUri){ - - zval *uri; - - phalcon_fetch_params(0, 1, 0, &uri); - - phalcon_update_property_this_quick(this_ptr, SL("_uri"), uri, 251146964UL TSRMLS_CC); - RETURN_THISW(); +static void phalcon_config_write_internal(phalcon_config_object *object, zval *offset, zval *value TSRMLS_DC) +{ + if (Z_TYPE_P(value) == IS_ARRAY) { + zval *instance; + ALLOC_INIT_ZVAL(instance); + object_init_ex(instance, phalcon_config_ce); + phalcon_config_construct_internal(instance, value TSRMLS_CC); + phalcon_hash_update_or_insert(object->props, offset, instance); + } + else { + Z_ADDREF_P(value); + phalcon_hash_update_or_insert(object->props, offset, value); + } } -static PHP_METHOD(Phalcon_Debug, setShowBackTrace){ +static void phalcon_config_write_property(zval *object, zval *offset, zval *value ZLK_DC TSRMLS_DC) +{ + phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC); - zval *show_back_trace; + if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) { + zend_get_std_object_handlers()->write_property(object, offset, value ZLK_CC TSRMLS_CC); + } - phalcon_fetch_params(0, 1, 0, &show_back_trace); - - phalcon_update_property_this_quick(this_ptr, SL("_showBackTrace"), show_back_trace, 3370024901UL TSRMLS_CC); - RETURN_THISW(); + phalcon_config_write_internal(obj, offset, value TSRMLS_CC); } -static PHP_METHOD(Phalcon_Debug, setShowFiles){ +static void phalcon_config_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) +{ + phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC); - zval *show_files; + if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) { + zend_get_std_object_handlers()->write_dimension(object, offset, value TSRMLS_CC); + } - phalcon_fetch_params(0, 1, 0, &show_files); - - phalcon_update_property_this_quick(this_ptr, SL("_showFiles"), show_files, 1877855960UL TSRMLS_CC); - RETURN_THISW(); + phalcon_config_write_internal(obj, offset, value TSRMLS_CC); } -static PHP_METHOD(Phalcon_Debug, setShowFileFragment){ +static int phalcon_config_has_internal(phalcon_config_object *object, zval *key, int check_empty TSRMLS_DC) +{ + zval **tmp = phalcon_hash_get(object->props, key, BP_VAR_NA); - zval *show_file_fragment; + if (!tmp) { + return 0; + } - phalcon_fetch_params(0, 1, 0, &show_file_fragment); - - phalcon_update_property_this_quick(this_ptr, SL("_showFileFragment"), show_file_fragment, 3533221081UL TSRMLS_CC); - RETURN_THISW(); -} + if (0 == check_empty) { + return Z_TYPE_PP(tmp) != IS_NULL; + } -static PHP_METHOD(Phalcon_Debug, listen){ + if (1 == check_empty) { + return zend_is_true(*tmp); + } - zval *exceptions = NULL, *low_severity = NULL; + return 1; +} - PHALCON_MM_GROW(); +static int phalcon_config_has_property(zval *object, zval *offset, int has_set_exists ZLK_DC TSRMLS_DC) +{ + phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC); - phalcon_fetch_params(1, 0, 2, &exceptions, &low_severity); - - if (!exceptions) { - PHALCON_INIT_VAR(exceptions); - ZVAL_BOOL(exceptions, 1); - } - - if (!low_severity) { - PHALCON_INIT_VAR(low_severity); - ZVAL_BOOL(low_severity, 0); - } - - if (zend_is_true(exceptions)) { - phalcon_call_method_key(NULL, this_ptr, "listenexceptions", 2156957942UL); + if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) { + return zend_get_std_object_handlers()->has_property(object, offset, has_set_exists ZLK_CC TSRMLS_CC); } - if (zend_is_true(low_severity)) { - phalcon_call_method_key(NULL, this_ptr, "listenlowseverity", 1386787713UL); + + return phalcon_config_has_internal(obj, offset, 2 TSRMLS_CC); +} + +static int phalcon_config_has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC) +{ + phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC); + + if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) { + return zend_get_std_object_handlers()->has_dimension(object, offset, check_empty TSRMLS_CC); } - - RETURN_THIS(); + + return phalcon_config_has_internal(obj, offset, check_empty TSRMLS_CC); } -static PHP_METHOD(Phalcon_Debug, listenExceptions){ +static void phalcon_config_unset_internal(phalcon_config_object *obj, zval *key TSRMLS_DC) +{ + phalcon_hash_unset(obj->props, key); +} - zval *handler; +static void phalcon_config_unset_property(zval *object, zval *member ZLK_DC TSRMLS_DC) +{ + phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC); - PHALCON_MM_GROW(); + if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) { + zend_get_std_object_handlers()->unset_property(object, member ZLK_CC TSRMLS_CC); + } - PHALCON_INIT_VAR(handler); - array_init_size(handler, 2); - phalcon_array_append(&handler, this_ptr, PH_SEPARATE); - add_next_index_stringl(handler, SL("onUncaughtException"), 1); - phalcon_call_func_p1_noret("set_exception_handler", handler); - RETURN_THIS(); + phalcon_config_unset_internal(obj, member TSRMLS_CC); } -static PHP_METHOD(Phalcon_Debug, listenLowSeverity){ +static void phalcon_config_unset_dimension(zval *object, zval *offset TSRMLS_DC) +{ + phalcon_config_object *obj = fetchPhalconConfigObject(object TSRMLS_CC); - zval *handler; + if (obj->obj.ce->type != ZEND_INTERNAL_CLASS) { + zend_get_std_object_handlers()->unset_dimension(object, offset TSRMLS_CC); + } - PHALCON_MM_GROW(); + phalcon_config_unset_internal(obj, offset TSRMLS_CC); +} - PHALCON_INIT_VAR(handler); - array_init_size(handler, 2); - phalcon_array_append(&handler, this_ptr, PH_SEPARATE); - add_next_index_stringl(handler, SL("onUncaughtLowSeverity"), 1); - phalcon_call_func_p1_noret("set_exception_handler", handler); - RETURN_THIS(); +static HashTable* phalcon_config_get_properties(zval* object TSRMLS_DC) +{ + phalcon_config_object* obj = fetchPhalconConfigObject(object TSRMLS_CC); + HashTable* props = zend_std_get_properties(object TSRMLS_CC); + zval *tmp; + + zend_hash_copy(props, obj->props, (copy_ctor_func_t)zval_add_ref, (void*)&tmp, sizeof(zval*)); + return props; } -static PHP_METHOD(Phalcon_Debug, debugVar){ +static int phalcon_config_compare_objects(zval *object1, zval *object2 TSRMLS_DC) +{ + phalcon_config_object *zobj1, *zobj2; + zval result; - zval *var, *key = NULL, *ztime, *backtrace, *data; + zobj1 = fetchPhalconConfigObject(object1 TSRMLS_CC); + zobj2 = fetchPhalconConfigObject(object2 TSRMLS_CC); - PHALCON_MM_GROW(); + if (zobj1->obj.ce != zobj2->obj.ce) { + return 1; + } - phalcon_fetch_params(1, 1, 1, &var, &key); - - if (!key) { - PHALCON_INIT_VAR(key); + if (zobj1->props == zobj2->props) { + return 0; } - - PHALCON_INIT_VAR(ztime); - ZVAL_LONG(ztime, (long) time(NULL)); - - PHALCON_INIT_VAR(backtrace); -#if PHP_VERSION_ID < 50400 -#ifdef DEBUG_BACKTRACE_PROVIDE_OBJECT - zend_fetch_debug_backtrace(backtrace, 0, DEBUG_BACKTRACE_PROVIDE_OBJECT TSRMLS_CC); -#else - zend_fetch_debug_backtrace(backtrace, 0, 1 TSRMLS_CC); -#endif -#else - zend_fetch_debug_backtrace(backtrace, 0, DEBUG_BACKTRACE_PROVIDE_OBJECT, 0 TSRMLS_CC); -#endif - - PHALCON_INIT_VAR(data); - array_init_size(data, 3); - phalcon_array_append(&data, var, PH_SEPARATE); - phalcon_array_append(&data, backtrace, PH_SEPARATE); - phalcon_array_append(&data, ztime, PH_SEPARATE); - phalcon_update_property_array_append(this_ptr, SL("_data"), data TSRMLS_CC); - RETURN_THIS(); + + zend_compare_symbol_tables(&result, zobj1->props, zobj2->props TSRMLS_CC); + assert(Z_TYPE_P(&result) == IS_LONG); + return Z_LVAL_P(&result); } -static PHP_METHOD(Phalcon_Debug, clearVars){ +static void phalcon_config_object_dtor(void* v TSRMLS_DC) +{ + phalcon_config_object* obj = v; + if (obj->props) { + zend_hash_destroy(obj->props); + FREE_HASHTABLE(obj->props); + } - phalcon_update_property_null(this_ptr, SL("_data") TSRMLS_CC); - RETURN_THISW(); + zend_object_std_dtor(&(obj->obj) TSRMLS_CC); + efree(obj); } -static PHP_METHOD(Phalcon_Debug, _escapeString){ +static zend_object_value phalcon_config_object_ctor(zend_class_entry* ce TSRMLS_DC) +{ + phalcon_config_object* obj = ecalloc(1, sizeof(phalcon_config_object)); + zend_object_value retval; - zval *value, *charset, *ent_compat, *line_break; - zval *escaped_line_break, *replaced_value; + zend_object_std_init(&(obj->obj), ce TSRMLS_CC); + retval.handle = zend_objects_store_put( + obj, + (zend_objects_store_dtor_t)zend_objects_destroy_object, + phalcon_config_object_dtor, + NULL TSRMLS_CC + ); - PHALCON_MM_GROW(); + retval.handlers = &phalcon_config_object_handlers; - phalcon_fetch_params(1, 1, 0, &value); - - if (Z_TYPE_P(value) == IS_STRING) { - PHALCON_INIT_VAR(charset); - ZVAL_STRING(charset, "utf-8", 1); - - PHALCON_INIT_VAR(ent_compat); - ZVAL_LONG(ent_compat, 2); - - PHALCON_INIT_VAR(line_break); - ZVAL_STRING(line_break, "\n", 1); - - PHALCON_INIT_VAR(escaped_line_break); - ZVAL_STRING(escaped_line_break, "\\n", 1); - - PHALCON_INIT_VAR(replaced_value); - phalcon_fast_str_replace(replaced_value, line_break, escaped_line_break, value); - phalcon_call_func_p3(return_value, "htmlentities", replaced_value, ent_compat, charset); - RETURN_MM(); - } - - RETURN_CCTOR(value); + return retval; } -static PHP_METHOD(Phalcon_Debug, _getArrayDump){ +PHALCON_INIT_CLASS(Phalcon_Config){ - zval *argument, *n = NULL, *number_arguments, *one, *dump; - zval *v = NULL, *k = NULL, *var_dump = NULL, *escaped_string = NULL, *next = NULL, *array_dump = NULL; - zval *class_name = NULL, *joined_dump; + PHALCON_REGISTER_CLASS(Phalcon, Config, config, phalcon_config_method_entry, 0); + + phalcon_config_ce->create_object = phalcon_config_object_ctor; + + phalcon_config_object_handlers = *zend_get_std_object_handlers(); + phalcon_config_object_handlers.count_elements = phalcon_config_count_elements; + phalcon_config_object_handlers.read_property = phalcon_config_read_property; + phalcon_config_object_handlers.write_property = phalcon_config_write_property; + phalcon_config_object_handlers.unset_property = phalcon_config_unset_property; + phalcon_config_object_handlers.has_property = phalcon_config_has_property; + phalcon_config_object_handlers.read_dimension = phalcon_config_read_dimension; + phalcon_config_object_handlers.write_dimension = phalcon_config_write_dimension; + phalcon_config_object_handlers.unset_dimension = phalcon_config_unset_dimension; + phalcon_config_object_handlers.has_dimension = phalcon_config_has_dimension; + phalcon_config_object_handlers.get_properties = phalcon_config_get_properties; + phalcon_config_object_handlers.compare_objects = phalcon_config_compare_objects; + + zend_class_implements(phalcon_config_ce TSRMLS_CC, 2, zend_ce_arrayaccess, spl_ce_Countable); + + return SUCCESS; +} + +static void phalcon_config_construct_internal(zval* this_ptr, zval *array_config TSRMLS_DC) +{ HashTable *ah0; HashPosition hp0; zval **hd; + phalcon_config_object* obj; - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &argument, &n); - - if (!n) { - PHALCON_INIT_VAR(n); - ZVAL_LONG(n, 0); - } - - PHALCON_INIT_VAR(number_arguments); - phalcon_fast_count(number_arguments, argument TSRMLS_CC); - if (PHALCON_LT_LONG(n, 3)) { - if (PHALCON_GT_LONG(number_arguments, 0)) { - if (PHALCON_LT_LONG(number_arguments, 10)) { - - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - PHALCON_INIT_VAR(dump); - array_init(dump); - - phalcon_is_iterable(argument, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(k, ah0, hp0); - PHALCON_GET_HVALUE(v); - - if (PHALCON_IS_SCALAR(v)) { - if (PHALCON_IS_STRING(v, "")) { - PHALCON_INIT_NVAR(var_dump); - PHALCON_CONCAT_SVS(var_dump, "[", k, "] => (empty string)"); - } else { - PHALCON_INIT_NVAR(escaped_string); - phalcon_call_method_p1_key(escaped_string, this_ptr, "_escapestring", v, 1235002348UL); - - PHALCON_INIT_NVAR(var_dump); - PHALCON_CONCAT_SVSV(var_dump, "[", k, "] => ", escaped_string); - } - phalcon_array_append(&dump, var_dump, PH_SEPARATE); - } else { - if (Z_TYPE_P(v) == IS_ARRAY) { - PHALCON_INIT_NVAR(next); - phalcon_add_function(next, n, one TSRMLS_CC); - - PHALCON_INIT_NVAR(array_dump); - phalcon_call_method_p2_key(array_dump, this_ptr, "_getarraydump", v, next, 2678003289UL); - - PHALCON_INIT_NVAR(var_dump); - PHALCON_CONCAT_SVSVS(var_dump, "[", k, "] => Array(", array_dump, ")"); - phalcon_array_append(&dump, var_dump, PH_SEPARATE); - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - if (Z_TYPE_P(v) == IS_OBJECT) { - PHALCON_INIT_NVAR(class_name); - phalcon_get_class(class_name, v, 0 TSRMLS_CC); - - PHALCON_INIT_NVAR(var_dump); - PHALCON_CONCAT_SVSVS(var_dump, "[", k, "] => Object(", class_name, ")"); - phalcon_array_append(&dump, var_dump, PH_SEPARATE); - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - - if (Z_TYPE_P(v) == IS_NULL) { - PHALCON_INIT_NVAR(var_dump); - PHALCON_CONCAT_SVS(var_dump, "[", k, "] => null"); - phalcon_array_append(&dump, var_dump, PH_SEPARATE); - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - - PHALCON_INIT_NVAR(var_dump); - PHALCON_CONCAT_SVSV(var_dump, "[", k, "] => ", v); - phalcon_array_append(&dump, var_dump, PH_SEPARATE); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(joined_dump); - phalcon_fast_join_str(joined_dump, SL(", "), dump TSRMLS_CC); - - RETURN_CTOR(joined_dump); - } - - RETURN_NCTOR(number_arguments); - } + if (!array_config || Z_TYPE_P(array_config) == IS_NULL) { + obj = fetchPhalconConfigObject(getThis() TSRMLS_CC); + ALLOC_HASHTABLE(obj->props); + zend_hash_init(obj->props, 0, NULL, ZVAL_PTR_DTOR, 0); + return; } - - RETURN_MM_NULL(); -} -static PHP_METHOD(Phalcon_Debug, _getVarDump){ + phalcon_is_iterable(array_config, &ah0, &hp0, 0, 0); - zval *variable, *class_name, *dumped_object; - zval *array_dump = NULL, *dump = NULL; + obj = fetchPhalconConfigObject(getThis() TSRMLS_CC); + ALLOC_HASHTABLE(obj->props); + zend_hash_init(obj->props, zend_hash_num_elements(Z_ARRVAL_P(array_config)), NULL, ZVAL_PTR_DTOR, 0); - PHALCON_MM_GROW(); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - phalcon_fetch_params(1, 1, 0, &variable); - - if (PHALCON_IS_SCALAR(variable)) { - - if (Z_TYPE_P(variable) == IS_BOOL) { - if (zend_is_true(variable)) { - RETURN_MM_STRING("true", 1); - } else { - RETURN_MM_STRING("false", 1); - } - } - - if (Z_TYPE_P(variable) == IS_STRING) { - phalcon_call_method_p1_key(return_value, this_ptr, "_escapestring", variable, 1235002348UL); - RETURN_MM(); - } - - - RETURN_CCTOR(variable); + zval key = phalcon_get_current_key_w(ah0, &hp0); + phalcon_config_write_internal(obj, &key, *hd TSRMLS_CC); + + zend_hash_move_forward_ex(ah0, &hp0); } - - if (Z_TYPE_P(variable) == IS_OBJECT) { - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, variable, 0 TSRMLS_CC); - - if (phalcon_method_quick_exists_ex(variable, SS("dump"), 257071355UL TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_VAR(dumped_object); - phalcon_call_method_key(dumped_object, variable, "dump", 257071355UL); - - PHALCON_INIT_VAR(array_dump); - phalcon_call_method_p1_key(array_dump, this_ptr, "_getarraydump", dumped_object, 2678003289UL); - - PHALCON_INIT_VAR(dump); - PHALCON_CONCAT_SVSVS(dump, "Object(", class_name, ": ", array_dump, ")"); - } else { - PHALCON_INIT_NVAR(dump); - PHALCON_CONCAT_SVS(dump, "Object(", class_name, ")"); - } - - RETURN_CTOR(dump); +} + +static void phalcon_config_toarray_internal(zval *return_value, zval *this_ptr TSRMLS_DC) +{ + phalcon_config_object *obj = fetchPhalconConfigObject(this_ptr TSRMLS_CC); + + if (likely(obj->obj.ce == phalcon_config_ce)) { + zval *tmp; + array_init_size(return_value, zend_hash_num_elements(obj->props)); + zend_hash_copy(Z_ARRVAL_P(return_value), obj->props, (copy_ctor_func_t)zval_add_ref, (void*)&tmp, sizeof(zval*)); } - - if (Z_TYPE_P(variable) == IS_ARRAY) { - PHALCON_INIT_NVAR(array_dump); - phalcon_call_method_p1_key(array_dump, this_ptr, "_getarraydump", variable, 2678003289UL); - PHALCON_CONCAT_SVS(return_value, "Array(", array_dump, ")"); - RETURN_MM(); + else if (phalcon_method_quick_exists_ex(this_ptr, SS("toarray"), 3566966151UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_params_w(return_value, this_ptr, SL("toarray"), 0, NULL, 0, 0 TSRMLS_CC); + } + else { + phalcon_call_func_params_w(return_value, SL("get_object_vars"), 0, NULL TSRMLS_CC); } - - RETURN_MM_STRING(zend_zval_type_name(variable), 1); } -static PHP_METHOD(Phalcon_Debug, getMajorVersion){ - - zval *version, *parts, *major; +static PHP_METHOD(Phalcon_Config, __construct){ - PHALCON_MM_GROW(); + zval *array_config = NULL; - PHALCON_INIT_VAR(version); - PHALCON_CALL_STATIC(version, "phalcon\\version", "get"); - - PHALCON_INIT_VAR(parts); - phalcon_fast_explode_str(parts, SL(" "), version); + phalcon_fetch_params(0, 0, 1, &array_config); - PHALCON_OBS_VAR(major); - phalcon_array_fetch_long(&major, parts, 0, PH_NOISY); - RETURN_CCTOR(major); + if (array_config && Z_TYPE_P(array_config) != IS_ARRAY && Z_TYPE_P(array_config) != IS_NULL) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_config_exception_ce, "The configuration must be an Array"); + return; + } + + phalcon_config_construct_internal(getThis(), array_config TSRMLS_CC); } -static PHP_METHOD(Phalcon_Debug, getVersion){ +static PHP_METHOD(Phalcon_Config, offsetExists){ - zval *version; + zval *index; - PHALCON_MM_GROW(); + phalcon_fetch_params(0, 1, 0, &index); + RETURN_BOOL(phalcon_config_has_internal(fetchPhalconConfigObject(getThis() TSRMLS_CC), index, 0 TSRMLS_CC)); +} - PHALCON_INIT_VAR(version); - phalcon_call_method_key(version, this_ptr, "getmajorversion", 1927318692UL); - PHALCON_CONCAT_SVSVS(return_value, "
Phalcon Framework ", version, "
"); - RETURN_MM(); +static PHP_METHOD(Phalcon_Config, get){ + + zval *index, *default_value = NULL, *value; + + phalcon_fetch_params(0, 1, 1, &index, &default_value); + + value = phalcon_config_read_internal(fetchPhalconConfigObject(getThis() TSRMLS_CC), index, BP_VAR_NA TSRMLS_CC); + if (!value || Z_TYPE_P(value) == IS_NULL) { + if (default_value) { + RETURN_ZVAL(default_value, 1, 0); + } + + RETURN_NULL(); + } + + RETURN_ZVAL(value, 1, 0); } -static PHP_METHOD(Phalcon_Debug, getCssSources){ +static PHP_METHOD(Phalcon_Config, offsetGet){ - zval *uri, *sources; + zval *index; + zval* retval; - PHALCON_MM_GROW(); + phalcon_fetch_params(0, 1, 0, &index); - PHALCON_OBS_VAR(uri); - phalcon_read_property_this_quick(&uri, this_ptr, SL("_uri"), 251146964UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sources); - PHALCON_CONCAT_SVS(sources, ""); - PHALCON_SCONCAT_SVS(sources, ""); - RETURN_CTOR(sources); + retval = phalcon_config_read_internal(fetchPhalconConfigObject(getThis() TSRMLS_CC), index, BP_VAR_R TSRMLS_CC); + RETURN_ZVAL(retval, 1, 0); } -static PHP_METHOD(Phalcon_Debug, getJsSources){ +static PHP_METHOD(Phalcon_Config, offsetSet){ - zval *uri, *sources; + zval *index, *value; - PHALCON_MM_GROW(); + phalcon_fetch_params(0, 2, 0, &index, &value); + phalcon_config_write_internal(fetchPhalconConfigObject(getThis() TSRMLS_CC), index, value TSRMLS_CC); +} - PHALCON_OBS_VAR(uri); - phalcon_read_property_this_quick(&uri, this_ptr, SL("_uri"), 251146964UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sources); - PHALCON_CONCAT_SVS(sources, ""); - PHALCON_SCONCAT_SVS(sources, ""); - PHALCON_SCONCAT_SVS(sources, ""); - PHALCON_SCONCAT_SVS(sources, ""); - PHALCON_SCONCAT_SVS(sources, ""); - RETURN_CTOR(sources); +static PHP_METHOD(Phalcon_Config, offsetUnset){ + + zval *index; + + phalcon_fetch_params(0, 1, 0, &index); + phalcon_config_unset_internal(fetchPhalconConfigObject(getThis() TSRMLS_CC), index TSRMLS_CC); } -static PHP_METHOD(Phalcon_Debug, showTraceItem){ +static PHP_METHOD(Phalcon_Config, merge){ - zval *n, *trace, *space, *two_spaces, *underscore; - zval *minus, *html, *class_name, *pattern, *is_phalcon_class; - zval *namespace_separator, *prepare_uri_class; - zval *class_reflection, *is_internal = NULL, *lower_class_name; - zval *prepare_internal_class, *type, *function_name = NULL; - zval *function_reflection, *prepared_function_name; - zval *trace_args, *arguments, *argument = NULL, *dumped_argument = NULL; - zval *span_argument = NULL, *joined_arguments, *one; - zval *file, *line, *show_files, *lines, *number_lines; - zval *show_file_fragment, *seven, *before_line; - zval *first_line = NULL, *five, *after_line, *last_line = NULL; - zval *comment_pattern, *utf8, *ent_compat, *tab; - zval *comment, *i = NULL, *line_position = NULL, *current_line = NULL; - zval *trimmed = NULL, *is_comment = NULL, *spaced_current_line = NULL; - zval *escaped_line = NULL; + zval *config, *array_config, key, *active_value = NULL; HashTable *ah0; HashPosition hp0; zval **hd; - zend_class_entry *ce0, *ce1; - - PHALCON_MM_GROW(); + phalcon_config_object *obj; - phalcon_fetch_params(1, 2, 0, &n, &trace); - - PHALCON_INIT_VAR(space); - ZVAL_STRING(space, " ", 1); - - PHALCON_INIT_VAR(two_spaces); - ZVAL_STRING(two_spaces, " ", 1); - - PHALCON_INIT_VAR(underscore); - ZVAL_STRING(underscore, "_", 1); - - PHALCON_INIT_VAR(minus); - ZVAL_STRING(minus, "-", 1); - - PHALCON_INIT_VAR(html); - PHALCON_CONCAT_SVS(html, "#", n, ""); - if (phalcon_array_isset_quick_string(trace, SS("class"), 4138154555UL)) { - - PHALCON_OBS_VAR(class_name); - phalcon_array_fetch_quick_string(&class_name, trace, SS("class"), 4138154555UL, PH_NOISY); - - PHALCON_INIT_VAR(pattern); - ZVAL_STRING(pattern, "/^Phalcon/", 1); + phalcon_fetch_params(0, 1, 0, &config); - PHALCON_INIT_VAR(is_phalcon_class); + if (Z_TYPE_P(config) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_config_exception_ce, "Configuration must be an Object"); + return; + } + + ALLOC_INIT_ZVAL(array_config); + phalcon_config_toarray_internal(array_config, config TSRMLS_CC); - phalcon_preg_match(is_phalcon_class, pattern, class_name, NULL TSRMLS_CC); + phalcon_is_iterable(array_config, &ah0, &hp0, 0, 0); - if (zend_is_true(is_phalcon_class)) { - PHALCON_INIT_VAR(namespace_separator); - ZVAL_STRING(namespace_separator, "\\", 1); + obj = fetchPhalconConfigObject(getThis() TSRMLS_CC); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(prepare_uri_class); - phalcon_fast_str_replace(prepare_uri_class, namespace_separator, underscore, class_name); + key = phalcon_get_current_key_w(ah0, &hp0); - PHALCON_SCONCAT_SVSVS(html, "", class_name, ""); - } else { - ce0 = zend_fetch_class(SL("ReflectionClass"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - PHALCON_INIT_VAR(class_reflection); - object_init_ex(class_reflection, ce0); - if (phalcon_has_constructor(class_reflection TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, class_reflection, "__construct", class_name, 1107214344UL); + active_value = phalcon_config_read_internal(obj, &key, BP_VAR_NA TSRMLS_CC); + + if (active_value) { + if (Z_TYPE_PP(hd) == IS_OBJECT && Z_TYPE_P(active_value) == IS_OBJECT) { + if (phalcon_method_quick_exists_ex(active_value, SS("merge"), 226837141UL TSRMLS_CC) == SUCCESS) { /* Path AAA in the test */ + zval *params[] = {*hd}; + Z_ADDREF_PP(hd); + phalcon_call_method_params_w(NULL, active_value, SL("merge"), 1, params, 0, 0 TSRMLS_CC); + Z_DELREF_PP(hd); + } + else { /* Path AAB in the test */ + phalcon_config_write_internal(obj, &key, *hd TSRMLS_CC); + } } - - PHALCON_INIT_VAR(is_internal); - phalcon_call_method_key(is_internal, class_reflection, "isinternal", 2412550174UL); - if (zend_is_true(is_internal)) { - PHALCON_INIT_VAR(lower_class_name); - phalcon_fast_strtolower(lower_class_name, class_name); - - PHALCON_INIT_VAR(prepare_internal_class); - phalcon_fast_str_replace(prepare_internal_class, underscore, minus, lower_class_name); - - PHALCON_SCONCAT_SVSVS(html, "", class_name, ""); - } else { - PHALCON_SCONCAT_SVS(html, "", class_name, ""); + else { /* Path AE in the test */ + phalcon_config_write_internal(obj, &key, *hd TSRMLS_CC); } } + else { /* Path B in the test */ + phalcon_config_write_internal(obj, &key, *hd TSRMLS_CC); + } - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, trace, SS("type"), 276192743UL, PH_NOISY); - phalcon_concat_self(&html, type TSRMLS_CC); + zend_hash_move_forward_ex(ah0, &hp0); } - if (phalcon_array_isset_quick_string(trace, SS("class"), 4138154555UL)) { - PHALCON_OBS_VAR(function_name); - phalcon_array_fetch_quick_string(&function_name, trace, SS("function"), 1487618475UL, PH_NOISY); - PHALCON_SCONCAT_SVS(html, "", function_name, ""); - } else { - PHALCON_OBS_NVAR(function_name); - phalcon_array_fetch_quick_string(&function_name, trace, SS("function"), 1487618475UL, PH_NOISY); + zval_ptr_dtor(&array_config); +} + +static PHP_METHOD(Phalcon_Config, toArray){ + + zval key, *array_value = NULL, *tmp; + HashTable *ah0; + HashPosition hp0; + zval **hd; + phalcon_config_object *obj; + + obj = fetchPhalconConfigObject(getThis() TSRMLS_CC); + array_init_size(return_value, zend_hash_num_elements(obj->props)); + zend_hash_copy(Z_ARRVAL_P(return_value), obj->props, (copy_ctor_func_t)zval_add_ref, (void*)&tmp, sizeof(zval*)); + + phalcon_is_iterable(return_value, &ah0, &hp0, 0, 0); - if (phalcon_function_exists(function_name TSRMLS_CC) == SUCCESS) { - ce1 = zend_fetch_class(SL("ReflectionFunction"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - PHALCON_INIT_VAR(function_reflection); - object_init_ex(function_reflection, ce1); - if (phalcon_has_constructor(function_reflection TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, function_reflection, "__construct", function_name, 1107214344UL); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_NVAR(is_internal); - phalcon_call_method_key(is_internal, function_reflection, "isinternal", 2412550174UL); + key = phalcon_get_current_key_w(ah0, &hp0); - if (zend_is_true(is_internal)) { - PHALCON_INIT_VAR(prepared_function_name); - phalcon_fast_str_replace(prepared_function_name, underscore, minus, function_name); - PHALCON_SCONCAT_SVSVS(html, "", function_name, ""); - } else { - PHALCON_SCONCAT_SVS(html, "", function_name, ""); - } - } else { - PHALCON_SCONCAT_SVS(html, "", function_name, ""); - } - } - - if (phalcon_array_isset_quick_string(trace, SS("args"), 253399346UL)) { - - PHALCON_OBS_VAR(trace_args); - phalcon_array_fetch_quick_string(&trace_args, trace, SS("args"), 253399346UL, PH_NOISY); - if (phalcon_fast_count_ev(trace_args TSRMLS_CC)) { - - PHALCON_INIT_VAR(arguments); - array_init(arguments); - - phalcon_is_iterable(trace_args, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(argument); - - PHALCON_INIT_NVAR(dumped_argument); - phalcon_call_method_p1_key(dumped_argument, this_ptr, "_getvardump", argument, 2922816643UL); - - PHALCON_INIT_NVAR(span_argument); - PHALCON_CONCAT_SVS(span_argument, "", dumped_argument, ""); - - phalcon_array_append(&arguments, span_argument, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(joined_arguments); - phalcon_fast_join_str(joined_arguments, SL(", "), arguments TSRMLS_CC); - PHALCON_SCONCAT_SVS(html, "(", joined_arguments, ")"); - } else { - phalcon_concat_self_str(&html, SL("()") TSRMLS_CC); + if (Z_TYPE_PP(hd) == IS_OBJECT && phalcon_method_exists_ex(*hd, SS("toarray") TSRMLS_CC) == SUCCESS) { + ALLOC_INIT_ZVAL(array_value); + phalcon_call_method_params_w(array_value, *hd, SL("toarray"), 0, NULL, 0, 0 TSRMLS_CC); + phalcon_array_update_zval(&return_value, &key, &array_value, PH_SEPARATE); } - } - - if (phalcon_array_isset_quick_string(trace, SS("file"), 259010501UL)) { - - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - PHALCON_OBS_VAR(file); - phalcon_array_fetch_quick_string(&file, trace, SS("file"), 259010501UL, PH_NOISY); - - PHALCON_OBS_VAR(line); - phalcon_array_fetch_quick_string(&line, trace, SS("line"), 266128205UL, PH_NOISY); - - PHALCON_SCONCAT_SVSVS(html, "
", file, " (", line, ")
"); - - PHALCON_OBS_VAR(show_files); - phalcon_read_property_this_quick(&show_files, this_ptr, SL("_showFiles"), 1877855960UL, PH_NOISY_CC); - - if (zend_is_true(show_files)) { - - PHALCON_INIT_VAR(lines); - phalcon_call_func_p1(lines, "file", file); - - PHALCON_INIT_VAR(number_lines); - phalcon_fast_count(number_lines, lines TSRMLS_CC); - - PHALCON_OBS_VAR(show_file_fragment); - phalcon_read_property_this_quick(&show_file_fragment, this_ptr, SL("_showFileFragment"), 3533221081UL, PH_NOISY_CC); - - if (zend_is_true(show_file_fragment)) { - - PHALCON_INIT_VAR(seven); - ZVAL_LONG(seven, 7); - - PHALCON_INIT_VAR(before_line); - sub_function(before_line, line, seven TSRMLS_CC); - - if (PHALCON_LT_LONG(before_line, 1)) { - PHALCON_CPY_WRT(first_line, one); - } else { - PHALCON_CPY_WRT(first_line, before_line); - } - - PHALCON_INIT_VAR(five); - ZVAL_LONG(five, 5); - - PHALCON_INIT_VAR(after_line); - phalcon_add_function(after_line, line, five TSRMLS_CC); - - if (PHALCON_GT(after_line, number_lines)) { - PHALCON_CPY_WRT(last_line, number_lines); - } else { - PHALCON_CPY_WRT(last_line, after_line); - } - - PHALCON_SCONCAT_SVSVSVS(html, "
");
-			} else {
-				PHALCON_CPY_WRT(first_line, one);
-				PHALCON_CPY_WRT(last_line, number_lines);
-				PHALCON_SCONCAT_SVSVS(html, "
");
-			}
-	
-			PHALCON_INIT_VAR(comment_pattern);
-			ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1);
-	
-			PHALCON_INIT_VAR(utf8);
-			ZVAL_STRING(utf8, "UTF-8", 1);
-	
-			PHALCON_INIT_VAR(ent_compat);
-			ZVAL_LONG(ent_compat, 2);
-	
-			PHALCON_INIT_VAR(tab);
-			ZVAL_STRING(tab, "\t", 1);
-	
-			PHALCON_INIT_VAR(comment);
-			ZVAL_STRING(comment, "* /", 1);
-			PHALCON_CPY_WRT(i, first_line);
-	
-			while (1) {
-	
-				if (PHALCON_LE(i, last_line)) {
-				} else {
-					break;
-				}
-	
-				PHALCON_INIT_NVAR(line_position);
-				sub_function(line_position, i, one TSRMLS_CC);
-	
-				PHALCON_OBS_NVAR(current_line);
-				phalcon_array_fetch(¤t_line, lines, line_position, PH_NOISY);
-	
-				if (zend_is_true(show_file_fragment)) {
-					if (PHALCON_IS_EQUAL(i, first_line)) {
-	
-						PHALCON_INIT_NVAR(trimmed);
-						phalcon_fast_trim(trimmed, current_line, PHALCON_TRIM_RIGHT TSRMLS_CC);
-	
-						PHALCON_INIT_NVAR(is_comment);
-	
-						phalcon_preg_match(is_comment, comment_pattern, current_line, NULL TSRMLS_CC);
-	
-						if (zend_is_true(is_comment)) {
-							PHALCON_INIT_NVAR(spaced_current_line);
-							phalcon_fast_str_replace(spaced_current_line, comment, space, current_line);
-							PHALCON_CPY_WRT(current_line, spaced_current_line);
-						}
-					}
-				}
-	
-				if (PHALCON_IS_STRING(current_line, "\n")) {
-					phalcon_concat_self_str(&html, SL(" \n") TSRMLS_CC);
-				} else {
-					if (PHALCON_IS_STRING(current_line, "\r\n")) {
-						phalcon_concat_self_str(&html, SL(" \n") TSRMLS_CC);
-					} else {
-						PHALCON_INIT_NVAR(spaced_current_line);
-						phalcon_fast_str_replace(spaced_current_line, tab, two_spaces, current_line);
-	
-						PHALCON_INIT_NVAR(escaped_line);
-						phalcon_call_func_p3(escaped_line, "htmlentities", spaced_current_line, ent_compat, utf8);
-						phalcon_concat_self(&html, escaped_line TSRMLS_CC);
-					}
-				}
 	
-				PHALCON_SEPARATE(i);
-				phalcon_increment(i);
-			}
-			phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - } + zend_hash_move_forward_ex(ah0, &hp0); } - - phalcon_concat_self_str(&html, SL("") TSRMLS_CC); - - RETURN_CTOR(html); } -static PHP_METHOD(Phalcon_Debug, onUncaughtException){ +static PHP_METHOD(Phalcon_Config, count) +{ + long int cnt; - zval *exception, *is_active = NULL, *message = NULL; - zval *class_name, *css_sources, *escaped_message = NULL; - zval *html, *version, *file, *line, *show_back_trace; - zval *data_vars, *trace, *trace_item = NULL, *n = NULL, *html_item = NULL; - zval *_REQUEST, *value = NULL, *key_request = NULL, *_SERVER; - zval *key_server = NULL, *files, *key_file = NULL; - zval *memory, *data_var = NULL, *key_var = NULL, *variable = NULL, *dumped_argument = NULL; - zval *js_sources; - HashTable *ah0, *ah1, *ah2, *ah3, *ah4; - HashPosition hp0, hp1, hp2, hp3, hp4; - zval **hd; + phalcon_config_count_elements(getThis(), &cnt TSRMLS_CC); + RETURN_LONG(cnt); +} - PHALCON_MM_GROW(); +static PHP_METHOD(Phalcon_Config, __set_state){ - phalcon_fetch_params(1, 1, 0, &exception); - - if (phalcon_ob_get_level(TSRMLS_C) > 0) { - phalcon_ob_end_clean(TSRMLS_C); - } - - PHALCON_OBS_VAR(is_active); - phalcon_read_static_property(&is_active, SL("phalcon\\debug"), SL("_isActive") TSRMLS_CC); - - if (zend_is_true(is_active)) { - PHALCON_INIT_VAR(message); - phalcon_call_method_key(message, exception, "getmessage", 4288675242UL); - zend_print_zval(message, 0); - } - - PHALCON_INIT_NVAR(is_active); - ZVAL_BOOL(is_active, 1); - - phalcon_update_static_property(SL("phalcon\\debug"), SL("_isActive"), is_active TSRMLS_CC); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, exception, 0 TSRMLS_CC); - - PHALCON_INIT_NVAR(message); - phalcon_call_method_key(message, exception, "getmessage", 4288675242UL); - - PHALCON_INIT_VAR(css_sources); - phalcon_call_method_key(css_sources, this_ptr, "getcsssources", 3032989842UL); - - PHALCON_CPY_WRT(escaped_message, message); - - PHALCON_INIT_VAR(html); - PHALCON_CONCAT_SVSVS(html, "", class_name, ": ", escaped_message, ""); - PHALCON_SCONCAT_VS(html, css_sources, ""); - - PHALCON_INIT_VAR(version); - phalcon_call_method_key(version, this_ptr, "getversion", 1268766507UL); - phalcon_concat_self(&html, version TSRMLS_CC); - - PHALCON_INIT_VAR(file); - phalcon_call_method_key(file, exception, "getfile", 4277240133UL); - - PHALCON_INIT_VAR(line); - phalcon_call_method_key(line, exception, "getline", 4284357837UL); - - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - PHALCON_SCONCAT_SVSVS(html, "

", class_name, ": ", escaped_message, "

"); - PHALCON_SCONCAT_SVSVS(html, "", file, " (", line, ")"); - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - - PHALCON_OBS_VAR(show_back_trace); - phalcon_read_property_this_quick(&show_back_trace, this_ptr, SL("_showBackTrace"), 3370024901UL, PH_NOISY_CC); - - if (zend_is_true(show_back_trace)) { - - PHALCON_OBS_VAR(data_vars); - phalcon_read_property_this_quick(&data_vars, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - - phalcon_concat_self_str(&html, SL("
    ") TSRMLS_CC); - phalcon_concat_self_str(&html, SL("
  • Backtrace
  • ") TSRMLS_CC); - phalcon_concat_self_str(&html, SL("
  • Request
  • ") TSRMLS_CC); - phalcon_concat_self_str(&html, SL("
  • Server
  • ") TSRMLS_CC); - phalcon_concat_self_str(&html, SL("
  • Included Files
  • ") TSRMLS_CC); - phalcon_concat_self_str(&html, SL("
  • Memory
  • ") TSRMLS_CC); - if (Z_TYPE_P(data_vars) == IS_ARRAY) { - phalcon_concat_self_str(&html, SL("
  • Variables
  • ") TSRMLS_CC); - } - - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - - PHALCON_INIT_VAR(trace); - phalcon_call_method_key(trace, exception, "gettrace", 4268145556UL); - - phalcon_is_iterable(trace, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(n, ah0, hp0); - PHALCON_GET_HVALUE(trace_item); - - PHALCON_INIT_NVAR(html_item); - phalcon_call_method_p2_key(html_item, this_ptr, "showtraceitem", n, trace_item, 296427812UL); - phalcon_concat_self(&html, html_item TSRMLS_CC); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - phalcon_concat_self_str(&html, SL("") TSRMLS_CC); - phalcon_get_global(&_REQUEST, SS("_REQUEST") TSRMLS_CC); - - phalcon_is_iterable(_REQUEST, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HKEY(key_request, ah1, hp1); - PHALCON_GET_HVALUE(value); - - PHALCON_SCONCAT_SVSVS(html, ""); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - phalcon_concat_self_str(&html, SL("
KeyValue
", key_request, "", value, "
") TSRMLS_CC); - - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - phalcon_concat_self_str(&html, SL("") TSRMLS_CC); - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - - phalcon_is_iterable(_SERVER, &ah2, &hp2, 0, 0); - - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - - PHALCON_GET_HKEY(key_server, ah2, hp2); - PHALCON_GET_HVALUE(value); - - PHALCON_SCONCAT_SVSVS(html, ""); - - zend_hash_move_forward_ex(ah2, &hp2); - } - - phalcon_concat_self_str(&html, SL("
KeyValue
", key_server, "", value, "
") TSRMLS_CC); - - PHALCON_INIT_VAR(files); - phalcon_call_func(files, "get_included_files"); - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - phalcon_concat_self_str(&html, SL("") TSRMLS_CC); - - phalcon_is_iterable(files, &ah3, &hp3, 0, 0); - - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - - PHALCON_GET_HKEY(key_file, ah3, hp3); - PHALCON_GET_HVALUE(value); - - PHALCON_SCONCAT_SVSVS(html, ""); - - zend_hash_move_forward_ex(ah3, &hp3); - } - - phalcon_concat_self_str(&html, SL("
#Path
", key_file, "", value, "
") TSRMLS_CC); - - PHALCON_INIT_VAR(memory); - ZVAL_LONG(memory, zend_memory_usage(1 TSRMLS_CC)); - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - PHALCON_SCONCAT_SVS(html, ""); - phalcon_concat_self_str(&html, SL("
Memory
Usage", memory, "
") TSRMLS_CC); - - if (Z_TYPE_P(data_vars) == IS_ARRAY) { - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - phalcon_concat_self_str(&html, SL("") TSRMLS_CC); - - phalcon_is_iterable(data_vars, &ah4, &hp4, 0, 0); - - while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { - - PHALCON_GET_HKEY(key_var, ah4, hp4); - PHALCON_GET_HVALUE(data_var); - - PHALCON_OBS_NVAR(variable); - phalcon_array_fetch_long(&variable, data_var, 0, PH_NOISY); - - PHALCON_INIT_NVAR(dumped_argument); - phalcon_call_method_p1_key(dumped_argument, this_ptr, "_getvardump", variable, 2922816643UL); - PHALCON_SCONCAT_SVSVS(html, ""); - - zend_hash_move_forward_ex(ah4, &hp4); - } - - phalcon_concat_self_str(&html, SL("
KeyValue
", key_var, "", dumped_argument, "
") TSRMLS_CC); - } - - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - } - - PHALCON_INIT_VAR(js_sources); - phalcon_call_method_key(js_sources, this_ptr, "getjssources", 3049944486UL); - PHALCON_SCONCAT_VS(html, js_sources, "
"); - - zend_print_zval(html, 0); - - PHALCON_INIT_NVAR(is_active); - ZVAL_BOOL(is_active, 0); - - phalcon_update_static_property(SL("phalcon\\debug"), SL("_isActive"), is_active TSRMLS_CC); - RETURN_MM_TRUE; -} + zval *data; + + phalcon_fetch_params(0, 1, 0, &data); + object_init_ex(return_value, phalcon_config_ce); + phalcon_config_construct_internal(return_value, data TSRMLS_CC); +} @@ -24853,9 +23622,9 @@ static PHP_METHOD(Phalcon_Debug, onUncaughtException){ -PHALCON_INIT_CLASS(Phalcon_Loader_Exception){ +PHALCON_INIT_CLASS(Phalcon_Crypt_Exception){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Loader, Exception, loader_exception, "phalcon\\exception", NULL, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Crypt, Exception, crypt_exception, "phalcon\\exception", NULL, 0); return SUCCESS; } @@ -24869,288 +23638,512 @@ PHALCON_INIT_CLASS(Phalcon_Loader_Exception){ -PHALCON_INIT_CLASS(Phalcon_FilterInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon, FilterInterface, filterinterface, phalcon_filterinterface_method_entry); - return SUCCESS; -} +PHALCON_INIT_CLASS(Phalcon_Crypt){ + PHALCON_REGISTER_CLASS(Phalcon, Crypt, crypt, phalcon_crypt_method_entry, 0); + zend_declare_property_null(phalcon_crypt_ce, SL("_key"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_crypt_ce, SL("_mode"), "cbc", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_crypt_ce, SL("_cipher"), "rijndael-256", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_crypt_ce, SL("_padding"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_class_implements(phalcon_crypt_ce TSRMLS_CC, 1, phalcon_cryptinterface_ce); + zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_DEFAULT"), PHALCON_CRYPT_PADDING_DEFAULT TSRMLS_CC); + zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_ANSI_X_923"), PHALCON_CRYPT_PADDING_ANSI_X_923 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_PKCS7"), PHALCON_CRYPT_PADDING_PKCS7 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_ISO_10126"), PHALCON_CRYPT_PADDING_ISO_10126 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_ISO_IEC_7816_4"), PHALCON_CRYPT_PADDING_ISO_IEC_7816_4 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_ZERO"), PHALCON_CRYPT_PADDING_ZERO TSRMLS_CC); + zend_declare_class_constant_long(phalcon_crypt_ce, SL("PADDING_SPACE"), PHALCON_CRYPT_PADDING_SPACE TSRMLS_CC); + return SUCCESS; +} -#ifdef HAVE_CONFIG_H -#endif +static PHP_METHOD(Phalcon_Crypt, setCipher){ + zval *cipher; + phalcon_fetch_params(0, 1, 0, &cipher); + + phalcon_update_property_this_quick(this_ptr, SL("_cipher"), cipher, 3925470815UL TSRMLS_CC); + RETURN_THISW(); +} -PHALCON_INIT_CLASS(Phalcon_Translate_AdapterInterface){ +static PHP_METHOD(Phalcon_Crypt, getCipher){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Translate, AdapterInterface, translate_adapterinterface, phalcon_translate_adapterinterface_method_entry); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_cipher", 3925470815UL); } +static PHP_METHOD(Phalcon_Crypt, setMode){ + zval *mode; + phalcon_fetch_params(0, 1, 0, &mode); + if (Z_TYPE_P(mode) != IS_STRING) { + PHALCON_SEPARATE_PARAM_NMO(mode); + convert_to_string(mode); + } + else { + Z_ADDREF_P(mode); + } + phalcon_update_property_this_quick(this_ptr, SL("_mode"), mode, 3983285225UL TSRMLS_CC); + zval_ptr_dtor(&mode); + RETURN_THISW(); +} +static PHP_METHOD(Phalcon_Crypt, getMode){ + RETURN_MEMBER_QUICK(this_ptr, "_mode", 3983285225UL); +} +static PHP_METHOD(Phalcon_Crypt, setKey){ -#ifdef HAVE_CONFIG_H -#endif + zval *key; + phalcon_fetch_params(0, 1, 0, &key); + if (Z_TYPE_P(key) != IS_STRING) { + PHALCON_SEPARATE_PARAM_NMO(key); + convert_to_string(key); + } + else { + Z_ADDREF_P(key); + } + phalcon_update_property_this_quick(this_ptr, SL("_key"), key, 250773965UL TSRMLS_CC); + zval_ptr_dtor(&key); + RETURN_THISW(); +} +static PHP_METHOD(Phalcon_Crypt, getKey){ + RETURN_MEMBER_QUICK(this_ptr, "_key", 250773965UL); +} -PHALCON_INIT_CLASS(Phalcon_Translate_Adapter){ +static PHP_METHOD(Phalcon_Crypt, setPadding) { - PHALCON_REGISTER_CLASS(Phalcon\\Translate, Adapter, translate_adapter, phalcon_translate_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + zval *scheme; - zend_class_implements(phalcon_translate_adapter_ce TSRMLS_CC, 1, zend_ce_arrayaccess); + phalcon_fetch_params(0, 1, 0, &scheme); + if (Z_TYPE_P(scheme) != IS_LONG) { + PHALCON_SEPARATE_PARAM_NMO(scheme); + convert_to_long(scheme); + } + else { + Z_ADDREF_P(scheme); + } - return SUCCESS; + phalcon_update_property_this_quick(this_ptr, SL("_padding"), scheme, 2759428059UL TSRMLS_CC); + zval_ptr_dtor(&scheme); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Translate_Adapter, _){ +static PHP_METHOD(Phalcon_Crypt, getPadding) { - zval *translate_key, *placeholders = NULL; + RETURN_MEMBER_QUICK(this_ptr, "_padding", 2759428059UL); +} - PHALCON_MM_GROW(); +static void phalcon_crypt_pad_text(zval *return_value, zval *text, zval *mode, uint block_size, int padding_type TSRMLS_DC) +{ + uint padding_size, i; + char padding[256]; + char *str_mode; - phalcon_fetch_params(1, 1, 1, &translate_key, &placeholders); - - if (!placeholders) { - PHALCON_INIT_VAR(placeholders); - } - - phalcon_call_method_p2_key(return_value, this_ptr, "query", translate_key, placeholders, 401898907UL); - RETURN_MM(); -} + assert(Z_TYPE_P(text) == IS_STRING); + assert(Z_TYPE_P(mode) == IS_STRING); -static PHP_METHOD(Phalcon_Translate_Adapter, offsetSet){ + padding_size = 0; + str_mode = Z_STRVAL_P(mode); - zval *offset, *value; + if (!strcmp(str_mode, "ecb") || !strcmp(str_mode, "cbc")) { + padding_size = block_size - (Z_STRLEN_P(text) % block_size); - phalcon_fetch_params(0, 2, 0, &offset, &value); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_translate_exception_ce, "Translate is an immutable ArrayAccess object"); - return; -} + switch (padding_type) { + case PHALCON_CRYPT_PADDING_ANSI_X_923: + memset(padding, 0, padding_size - 1); + padding[padding_size-1] = (unsigned char)padding_size; + break; -static PHP_METHOD(Phalcon_Translate_Adapter, offsetExists){ + case PHALCON_CRYPT_PADDING_PKCS7: + memset(padding, padding_size, padding_size); + break; - zval *translate_key; + case PHALCON_CRYPT_PADDING_ISO_10126: + for (i=0; i 0 && str_text[i] == 0x00 && padding_size < block_size) { + ++padding_size; + --i; + } + padding_size = ((unsigned char)str_text[i] == 0x80) ? (padding_size + 1) : 0; + break; + case PHALCON_CRYPT_PADDING_ZERO: + i = text_len - 1; + while (i >= 0 && str_text[i] == 0x00 && padding_size <= block_size) { + ++padding_size; + --i; + } -PHALCON_INIT_CLASS(Phalcon_Translate_Adapter_NativeArray){ + break; - PHALCON_REGISTER_CLASS_EX(Phalcon\\Translate\\Adapter, NativeArray, translate_adapter_nativearray, "phalcon\\translate\\adapter", phalcon_translate_adapter_nativearray_method_entry, 0); + case PHALCON_CRYPT_PADDING_SPACE: + i = text_len - 1; + while (i >= 0 && str_text[i] == 0x20 && padding_size <= block_size) { + ++padding_size; + --i; + } - zend_declare_property_null(phalcon_translate_adapter_nativearray_ce, SL("_translate"), ZEND_ACC_PROTECTED TSRMLS_CC); + break; - zend_class_implements(phalcon_translate_adapter_nativearray_ce TSRMLS_CC, 1, phalcon_translate_adapterinterface_ce); + default: + break; + } - return SUCCESS; + if (padding_size && padding_size <= block_size) { + assert(padding_size <= text_len); + if (padding_size < text_len) { + phalcon_substr(return_value, text, 0, text_len - padding_size); + } + else { + ZVAL_EMPTY_STRING(return_value); + } + } + else { + padding_size = 0; + } + } + + if (!padding_size) { + ZVAL_ZVAL(return_value, text, 1, 0); + } } -static PHP_METHOD(Phalcon_Translate_Adapter_NativeArray, __construct){ +static PHP_METHOD(Phalcon_Crypt, encrypt){ - zval *options, *data; + zval *source, *text = NULL, *key = NULL, *encrypt_key = NULL, *cipher, *mode, *padding_type, *iv_size; + zval *rand, *iv, *encrypt, *block_size, *padded; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &options); + phalcon_fetch_params(1, 1, 1, &source, &key); + + /* Do not use make_printable_zval() here: we need the conversion with type juggling */ + if (Z_TYPE_P(source) != IS_STRING) { + PHALCON_INIT_VAR(text); + phalcon_cast(text, source, IS_STRING); + } + else { + PHALCON_CPY_WRT(text, source); + } + + if (!key) { + PHALCON_INIT_VAR(key); + } - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_translate_exception_ce, "Invalid options"); + if (phalcon_function_quick_exists_ex(SS("mcrypt_get_iv_size"), 547857179UL TSRMLS_CC) == FAILURE) { + PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "mcrypt extension is required"); return; } - if (!phalcon_array_isset_quick_string(options, SS("content"), 1118620032UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_translate_exception_ce, "Translation content was not provided"); + if (Z_TYPE_P(key) == IS_NULL) { + PHALCON_OBS_VAR(encrypt_key); + phalcon_read_property_this_quick(&encrypt_key, this_ptr, SL("_key"), 250773965UL, PH_NOISY_CC); + } else { + PHALCON_CPY_WRT(encrypt_key, key); + if (Z_TYPE_P(encrypt_key) != IS_STRING) { + convert_to_string(encrypt_key); + } + } + + if (PHALCON_IS_EMPTY(encrypt_key)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "Encryption key cannot be empty"); return; } - PHALCON_OBS_VAR(data); - phalcon_array_fetch_quick_string(&data, options, SS("content"), 1118620032UL, PH_NOISY); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_translate_exception_ce, "Translation data must be an array"); + PHALCON_OBS_VAR(cipher); + phalcon_read_property_this_quick(&cipher, this_ptr, SL("_cipher"), 3925470815UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(mode); + phalcon_read_property_this_quick(&mode, this_ptr, SL("_mode"), 3983285225UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(iv_size); + phalcon_call_func_p2(iv_size, "mcrypt_get_iv_size", cipher, mode); + if (unlikely(Z_TYPE_P(iv_size) != IS_LONG)) { + convert_to_long(iv_size); + } + + if (Z_STRLEN_P(encrypt_key) > Z_LVAL_P(iv_size)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "Size of key is too large for this algorithm"); return; } - phalcon_update_property_this_quick(this_ptr, SL("_translate"), data, 3382158994UL TSRMLS_CC); + PHALCON_INIT_VAR(rand); + ZVAL_LONG(rand, 2); - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(iv); + phalcon_call_func_p2(iv, "mcrypt_create_iv", iv_size, rand); + if (unlikely(Z_TYPE_P(iv) != IS_STRING)) { + convert_to_string(iv); + } + + PHALCON_INIT_VAR(block_size); + phalcon_call_func_p2(block_size, "mcrypt_get_block_size", cipher, mode); + if (unlikely(Z_TYPE_P(block_size) != IS_LONG)) { + convert_to_long(block_size); + } + + PHALCON_OBS_VAR(padding_type); + phalcon_read_property_this_quick(&padding_type, this_ptr, SL("_padding"), 2759428059UL, PH_NOISY_CC); + + assert(Z_TYPE_P(padding_type) == IS_LONG); + assert(Z_TYPE_P(block_size) == IS_LONG); + assert(Z_TYPE_P(mode) == IS_STRING); + assert(Z_TYPE_P(text) == IS_STRING); + + PHALCON_INIT_VAR(padded); + phalcon_crypt_pad_text(padded, text, mode, Z_LVAL_P(block_size), Z_LVAL_P(padding_type) TSRMLS_CC); + assert(Z_TYPE_P(padded) == IS_STRING); + + PHALCON_INIT_VAR(encrypt); + phalcon_call_func_p5(encrypt, "mcrypt_encrypt", cipher, encrypt_key, padded, mode, iv); + + PHALCON_CONCAT_VV(return_value, iv, encrypt); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Translate_Adapter_NativeArray, query){ +static PHP_METHOD(Phalcon_Crypt, decrypt){ - zval *index, *placeholders = NULL, *translate, *translation = NULL; - zval *value = NULL, *key = NULL, *key_placeholder = NULL, *replaced = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *text, *key = NULL, *decrypt_key = NULL, *cipher, *mode, *iv_size; + zval *key_size, *text_size, *iv, *text_to_decipher, *decrypted; + zval *padding_type, *block_size; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &index, &placeholders); + phalcon_fetch_params(1, 1, 1, &text, &key); - if (!placeholders) { - PHALCON_INIT_VAR(placeholders); + if (!key) { + PHALCON_INIT_VAR(key); } - PHALCON_OBS_VAR(translate); - phalcon_read_property_this_quick(&translate, this_ptr, SL("_translate"), 3382158994UL, PH_NOISY_CC); - if (phalcon_array_isset(translate, index)) { - - PHALCON_OBS_VAR(translation); - phalcon_array_fetch(&translation, translate, index, PH_NOISY); - if (Z_TYPE_P(placeholders) == IS_ARRAY) { - if (phalcon_fast_count_ev(placeholders TSRMLS_CC)) { - - phalcon_is_iterable(placeholders, &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_function_quick_exists_ex(SS("mcrypt_get_iv_size"), 547857179UL TSRMLS_CC) == FAILURE) { + PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "mcrypt extension is required"); + return; + } + if (Z_TYPE_P(key) == IS_NULL) { + PHALCON_OBS_VAR(decrypt_key); + phalcon_read_property_this_quick(&decrypt_key, this_ptr, SL("_key"), 250773965UL, PH_NOISY_CC); + } else { + PHALCON_CPY_WRT(decrypt_key, key); + } - PHALCON_INIT_NVAR(key_placeholder); - PHALCON_CONCAT_SVS(key_placeholder, "%", key, "%"); + if (PHALCON_IS_EMPTY(decrypt_key)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "Decryption key cannot be empty"); + return; + } - PHALCON_INIT_NVAR(replaced); - phalcon_fast_str_replace(replaced, key_placeholder, value, translation); - PHALCON_CPY_WRT(translation, replaced); + PHALCON_OBS_VAR(cipher); + phalcon_read_property_this_quick(&cipher, this_ptr, SL("_cipher"), 3925470815UL, PH_NOISY_CC); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_OBS_VAR(mode); + phalcon_read_property_this_quick(&mode, this_ptr, SL("_mode"), 3983285225UL, PH_NOISY_CC); - } - } + PHALCON_INIT_VAR(iv_size); + phalcon_call_func_p2(iv_size, "mcrypt_get_iv_size", cipher, mode); + if (unlikely(Z_TYPE_P(iv_size) != IS_LONG)) { + convert_to_long(iv_size); + } - RETURN_CCTOR(translation); + PHALCON_INIT_VAR(key_size); + phalcon_fast_strlen(key_size, decrypt_key); + if (PHALCON_GT(key_size, iv_size)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "Size of key is too large for this algorithm"); + return; } - RETURN_CCTOR(index); -} - -static PHP_METHOD(Phalcon_Translate_Adapter_NativeArray, exists){ - - zval *index, *translate, *exists = NULL; - zval *r0 = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &index); + PHALCON_INIT_VAR(text_size); + phalcon_fast_strlen(text_size, text); + if (PHALCON_GT(key_size, text_size)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_crypt_exception_ce, "Size of IV is larger than text to decrypt"); + return; + } - PHALCON_OBS_VAR(translate); - phalcon_read_property_this_quick(&translate, this_ptr, SL("_translate"), 3382158994UL, PH_NOISY_CC); + PHALCON_INIT_VAR(iv); + phalcon_substr(iv, text, 0, Z_LVAL_P(iv_size)); - PHALCON_INIT_VAR(r0); - ZVAL_BOOL(r0, phalcon_array_isset(translate, index)); - PHALCON_CPY_WRT(exists, r0); - RETURN_NCTOR(exists); -} - - - - + PHALCON_INIT_VAR(text_to_decipher); + phalcon_substr(text_to_decipher, text, Z_LVAL_P(iv_size), 0); -#ifdef HAVE_CONFIG_H -#endif + PHALCON_INIT_VAR(decrypted); + phalcon_call_func_p5(decrypted, "mcrypt_decrypt", cipher, decrypt_key, text_to_decipher, mode, iv); + if (unlikely(Z_TYPE_P(decrypted) != IS_STRING)) { + convert_to_string(decrypted); + } + PHALCON_INIT_VAR(block_size); + phalcon_call_func_p2(block_size, "mcrypt_get_block_size", cipher, mode); + if (unlikely(Z_TYPE_P(block_size) != IS_LONG)) { + convert_to_long(block_size); + } + PHALCON_OBS_VAR(padding_type); + phalcon_read_property_this_quick(&padding_type, this_ptr, SL("_padding"), 2759428059UL, PH_NOISY_CC); + assert(Z_TYPE_P(padding_type) == IS_LONG); + assert(Z_TYPE_P(block_size) == IS_LONG); + assert(Z_TYPE_P(mode) == IS_STRING); + assert(Z_TYPE_P(decrypted) == IS_STRING); + phalcon_crypt_unpad_text(return_value, decrypted, mode, Z_LVAL_P(block_size), Z_LVAL_P(padding_type) TSRMLS_CC); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Crypt, encryptBase64){ -PHALCON_INIT_CLASS(Phalcon_Translate_Exception){ + zval *text, *key = NULL, *encrypted; - PHALCON_REGISTER_CLASS_EX(Phalcon\\Translate, Exception, translate_exception, "phalcon\\exception", NULL, 0); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 1, 1, &text, &key); + + if (!key) { + PHALCON_INIT_VAR(key); + } + + PHALCON_INIT_VAR(encrypted); + phalcon_call_method_p2_key(encrypted, this_ptr, "encrypt", text, key, 3027519146UL); + phalcon_base64_encode(return_value, encrypted); + RETURN_MM(); } +static PHP_METHOD(Phalcon_Crypt, decryptBase64){ + zval *text, *key = NULL, *decrypt_text; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 1, &text, &key); + + if (!key) { + PHALCON_INIT_VAR(key); + } + + PHALCON_INIT_VAR(decrypt_text); + phalcon_base64_decode(decrypt_text, text); + phalcon_call_method_p2_key(return_value, this_ptr, "decrypt", decrypt_text, key, 325472000UL); + RETURN_MM(); +} -#ifdef HAVE_CONFIG_H -#endif - - +static PHP_METHOD(Phalcon_Crypt, getAvailableCiphers){ + PHALCON_MM_GROW(); + phalcon_call_func(return_value, "mcrypt_list_algorithms"); + RETURN_MM(); +} -PHALCON_INIT_CLASS(Phalcon_Logger){ +static PHP_METHOD(Phalcon_Crypt, getAvailableModes){ - PHALCON_REGISTER_CLASS(Phalcon, Logger, logger, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - zend_declare_class_constant_long(phalcon_logger_ce, SL("SPECIAL"), 9 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_logger_ce, SL("CUSTOM"), 8 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_logger_ce, SL("DEBUG"), 7 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_logger_ce, SL("INFO"), 6 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_logger_ce, SL("NOTICE"), 5 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_logger_ce, SL("WARNING"), 4 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_logger_ce, SL("ERROR"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_logger_ce, SL("ALERT"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_logger_ce, SL("CRITICAL"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_logger_ce, SL("EMERGENCE"), 0 TSRMLS_CC); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_call_func(return_value, "mcrypt_list_modes"); + RETURN_MM(); } @@ -25162,12 +24155,9 @@ PHALCON_INIT_CLASS(Phalcon_Logger){ +PHALCON_INIT_CLASS(Phalcon_CryptInterface){ - - -PHALCON_INIT_CLASS(Phalcon_Security_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Security, Exception, security_exception, "phalcon\\exception", NULL, 0); + PHALCON_REGISTER_INTERFACE(Phalcon, CryptInterface, cryptinterface, phalcon_cryptinterface_method_entry); return SUCCESS; } @@ -25176,20 +24166,13 @@ PHALCON_INIT_CLASS(Phalcon_Security_Exception){ -#ifdef HAVE_CONFIG_H -#endif - -PHALCON_INIT_CLASS(Phalcon_Session){ - PHALCON_REGISTER_CLASS(Phalcon, Session, session, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - return SUCCESS; -} @@ -25204,195 +24187,220 @@ PHALCON_INIT_CLASS(Phalcon_Session){ -PHALCON_INIT_CLASS(Phalcon_Flash_Session){ +PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Mysql){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Flash, Session, flash_session, "phalcon\\flash", phalcon_flash_session_method_entry, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Adapter\\Pdo, Mysql, db_adapter_pdo_mysql, "phalcon\\db\\adapter\\pdo", phalcon_db_adapter_pdo_mysql_method_entry, 0); - zend_declare_property_null(phalcon_flash_session_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_db_adapter_pdo_mysql_ce, SL("_type"), "mysql", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_db_adapter_pdo_mysql_ce, SL("_dialectType"), "mysql", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_flash_session_ce TSRMLS_CC, 2, phalcon_flashinterface_ce, phalcon_di_injectionawareinterface_ce); + zend_class_implements(phalcon_db_adapter_pdo_mysql_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Flash_Session, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Flash_Session, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -static PHP_METHOD(Phalcon_Flash_Session, _getSessionMessages){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, escapeIdentifier){ - zval *remove, *dependency_injector, *service; - zval *session, *index_name, *messages; + zval *identifier, *domain, *name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &remove); + phalcon_fetch_params(1, 1, 0, &identifier); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (unlikely(Z_TYPE_P(dependency_injector) != IS_OBJECT)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); - return; - } + if (Z_TYPE_P(identifier) == IS_ARRAY) { - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "session", 1); + PHALCON_OBS_VAR(domain); + phalcon_array_fetch_long(&domain, identifier, 0, PH_NOISY); - PHALCON_INIT_VAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + PHALCON_OBS_VAR(name); + phalcon_array_fetch_long(&name, identifier, 1, PH_NOISY); + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_CONCAT_SVSVS(return_value, "`", domain, "`.`", name, "`"); + RETURN_MM(); + } - PHALCON_INIT_VAR(index_name); - ZVAL_STRING(index_name, "_flashMessages", 1); + PHALCON_CONCAT_VSV(return_value, domain, ".", name); - PHALCON_INIT_VAR(messages); - phalcon_call_method_p1_key(messages, session, "get", index_name, 2090288933UL); - if (PHALCON_IS_TRUE(remove)) { - phalcon_call_method_p1_key(NULL, session, "remove", index_name, 1052443347UL); + RETURN_MM(); + } + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_CONCAT_SVS(return_value, "`", identifier, "`"); + RETURN_MM(); } - RETURN_CCTOR(messages); + RETURN_CCTOR(identifier); } -static PHP_METHOD(Phalcon_Flash_Session, _setSessionMessages){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ - zval *messages, *dependency_injector, *service; - zval *session, *index_name; + zval *table, *schema = NULL, *dialect, *ztrue, *sql, *fetch_num; + zval *describe, *old_column = NULL, *size_pattern, *columns; + zval *field = NULL, *definition = NULL, *column_type = NULL, *matches = NULL; + zval *pos = NULL, *match_one = NULL, *attribute = NULL, *column_name = NULL; + zval *column = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &messages); + phalcon_fetch_params(1, 1, 1, &table, &schema); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (unlikely(Z_TYPE_P(dependency_injector) != IS_OBJECT)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); - return; + if (!schema) { + PHALCON_INIT_VAR(schema); } - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "session", 1); + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - PHALCON_INIT_VAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + PHALCON_INIT_VAR(ztrue); + ZVAL_BOOL(ztrue, 1); - PHALCON_INIT_VAR(index_name); - ZVAL_STRING(index_name, "_flashMessages", 1); - phalcon_call_method_p2_key(NULL, session, "set", index_name, messages, 2090720177UL); + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); - RETURN_CCTOR(messages); -} - -static PHP_METHOD(Phalcon_Flash_Session, message){ - - zval *type, *message, *remove, *messages = NULL, *empty_array; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &type, &message); + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 0); + PHALCON_INIT_VAR(describe); + phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - PHALCON_INIT_VAR(messages); - phalcon_call_method_p1_key(messages, this_ptr, "_getsessionmessages", remove, 1351193184UL); - if (Z_TYPE_P(messages) != IS_ARRAY) { - PHALCON_INIT_NVAR(messages); - array_init(messages); - } + PHALCON_INIT_VAR(old_column); - if (!phalcon_array_isset(messages, type)) { - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_array_update_zval(&messages, type, &empty_array, PH_COPY | PH_SEPARATE); - } + PHALCON_INIT_VAR(size_pattern); + ZVAL_STRING(size_pattern, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); - phalcon_array_update_append_multi_2(&messages, type, message, 0); - phalcon_call_method_p1_key(NULL, this_ptr, "_setsessionmessages", messages, 2596691308UL); + PHALCON_INIT_VAR(columns); + array_init(columns); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Flash_Session, getMessages){ - - zval *type = NULL, *remove = NULL, *messages, *return_messages; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &type, &remove); + phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); - if (!type) { - PHALCON_INIT_VAR(type); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (!remove) { - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 1); - } + PHALCON_GET_HVALUE(field); - PHALCON_INIT_VAR(messages); - phalcon_call_method_p1_key(messages, this_ptr, "_getsessionmessages", remove, 1351193184UL); - if (Z_TYPE_P(messages) == IS_ARRAY) { - if (likely(Z_TYPE_P(type) == IS_STRING)) { - if (phalcon_array_isset(messages, type)) { - PHALCON_OBS_VAR(return_messages); - phalcon_array_fetch(&return_messages, messages, type, PH_NOISY); - RETURN_CCTOR(return_messages); + PHALCON_INIT_NVAR(definition); + array_init_size(definition, 1); + add_assoc_long_ex(definition, SS("bindType"), 2); + + PHALCON_OBS_NVAR(column_type); + phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); + + while (1) { + + if (phalcon_memnstr_str(column_type, SL("enum"))) { + phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); + break; + } + + if (phalcon_memnstr_str(column_type, SL("int"))) { + phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("isNumeric"), 1643974676UL, &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE); + break; + } + + if (phalcon_memnstr_str(column_type, SL("varchar"))) { + phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); + break; + } + + if (phalcon_memnstr_str(column_type, SL("datetime"))) { + phalcon_array_update_string_long(&definition, SL("type"), 4, PH_SEPARATE); + break; + } + + if (phalcon_memnstr_str(column_type, SL("decimal"))) { + phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("isNumeric"), 1643974676UL, &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); + break; + } + + if (phalcon_memnstr_str(column_type, SL("char"))) { + phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); + break; + } + + if (phalcon_memnstr_str(column_type, SL("date"))) { + phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE); + break; + } + + if (phalcon_memnstr_str(column_type, SL("text"))) { + phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); + break; + } + + if (phalcon_memnstr_str(column_type, SL("float"))) { + phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("isNumeric"), 1643974676UL, &ztrue, PH_COPY | PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); + break; } + + phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); + break; } - RETURN_CCTOR(messages); - } + if (phalcon_memnstr_str(column_type, SL("("))) { - RETURN_MM_EMPTY_ARRAY(); -} - -static PHP_METHOD(Phalcon_Flash_Session, output){ - - zval *remove = NULL, *messages, *message = NULL, *type = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); + PHALCON_INIT_NVAR(matches); + + PHALCON_INIT_NVAR(pos); + phalcon_preg_match(pos, size_pattern, column_type, matches TSRMLS_CC); - phalcon_fetch_params(1, 0, 1, &remove); + if (zend_is_true(pos)) { + if (phalcon_array_isset_long(matches, 1)) { + PHALCON_OBS_NVAR(match_one); + phalcon_array_fetch_long(&match_one, matches, 1, PH_NOISY); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &match_one, PH_COPY | PH_SEPARATE); + } + } + } - if (!remove) { - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 1); - } + if (phalcon_memnstr_str(column_type, SL("unsigned"))) { + phalcon_array_update_quick_string(&definition, SS("unsigned"), 1143113122UL, &ztrue, PH_COPY | PH_SEPARATE); + } - PHALCON_INIT_VAR(messages); - phalcon_call_method_p1_key(messages, this_ptr, "_getsessionmessages", remove, 1351193184UL); - if (Z_TYPE_P(messages) == IS_ARRAY) { + if (!zend_is_true(old_column)) { + phalcon_array_update_quick_string(&definition, SS("first"), 4252613933UL, &ztrue, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_quick_string(&definition, SS("after"), 4053435767UL, &old_column, PH_COPY | PH_SEPARATE); + } - phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, field, 3, PH_NOISY); + if (PHALCON_IS_STRING(attribute, "PRI")) { + phalcon_array_update_quick_string(&definition, SS("primary"), 482916521UL, &ztrue, PH_COPY | PH_SEPARATE); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, field, 2, PH_NOISY); + if (PHALCON_IS_STRING(attribute, "NO")) { + phalcon_array_update_quick_string(&definition, SS("notNull"), 1960377425UL, &ztrue, PH_COPY | PH_SEPARATE); + } - PHALCON_GET_HKEY(type, ah0, hp0); - PHALCON_GET_HVALUE(message); + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); + if (PHALCON_IS_STRING(attribute, "auto_increment")) { + phalcon_array_update_quick_string(&definition, SS("autoIncrement"), 2492144707UL, &ztrue, PH_COPY | PH_SEPARATE); + } - phalcon_call_method_p2_key(NULL, this_ptr, "outputmessage", type, message, 924206491UL); + PHALCON_OBS_NVAR(column_name); + phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_NVAR(column); + object_init_ex(column, phalcon_db_column_ce); + phalcon_call_method_p2_key(NULL, column, "__construct", column_name, definition, 1107214344UL); + + phalcon_array_append(&columns, column, PH_SEPARATE); + PHALCON_CPY_WRT(old_column, column_name); + zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_MM_RESTORE(); + RETURN_CTOR(columns); } @@ -25408,69 +24416,264 @@ static PHP_METHOD(Phalcon_Flash_Session, output){ -PHALCON_INIT_CLASS(Phalcon_Flash_Direct){ +PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Oracle){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Flash, Direct, flash_direct, "phalcon\\flash", phalcon_flash_direct_method_entry, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Adapter\\Pdo, Oracle, db_adapter_pdo_oracle, "phalcon\\db\\adapter\\pdo", phalcon_db_adapter_pdo_oracle_method_entry, 0); - zend_class_implements(phalcon_flash_direct_ce TSRMLS_CC, 1, phalcon_flashinterface_ce); + zend_declare_property_string(phalcon_db_adapter_pdo_oracle_ce, SL("_type"), "oci", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_db_adapter_pdo_oracle_ce, SL("_dialectType"), "oracle", ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_db_adapter_pdo_oracle_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Flash_Direct, message){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, connect){ - zval *type, *message; + zval *descriptor = NULL, *startup, *value = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &type, &message); + phalcon_fetch_params(1, 0, 1, &descriptor); - phalcon_call_method_p2_key(return_value, this_ptr, "outputmessage", type, message, 924206491UL); - RETURN_MM(); + if (!descriptor) { + PHALCON_INIT_VAR(descriptor); + } else { + PHALCON_SEPARATE_PARAM(descriptor); + } + + if (!zend_is_true(descriptor)) { + PHALCON_OBS_NVAR(descriptor); + phalcon_read_property_this_quick(&descriptor, this_ptr, SL("_descriptor"), 691635363UL, PH_NOISY_CC); + } + + PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Oracle", "connect", descriptor); + + if (phalcon_array_isset_quick_string(descriptor, SS("startup"), 1765694744UL)) { + + PHALCON_OBS_VAR(startup); + phalcon_array_fetch_quick_string(&startup, descriptor, SS("startup"), 1765694744UL, PH_NOISY); + if (Z_TYPE_P(startup) == IS_ARRAY) { + + phalcon_is_iterable(startup, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(value); + + phalcon_call_method_p1_key(NULL, this_ptr, "execute", value, 3117639032UL); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } + } + + PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, describeColumns){ + zval *table, *schema = NULL, *columns, *dialect, *sql, *fetch_num; + zval *describe, *old_column = NULL, *field = NULL, *definition = NULL; + zval *column_size = NULL, *column_precision = NULL, *column_scale = NULL; + zval *column_type = NULL, *attribute = NULL, *column_name = NULL; + zval *column = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Flash_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Flash, Exception, flash_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + PHALCON_INIT_VAR(columns); + array_init(columns); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); + + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); + + PHALCON_INIT_VAR(describe); + phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + + PHALCON_INIT_VAR(old_column); + + phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(field); + + PHALCON_INIT_NVAR(definition); + array_init_size(definition, 1); + add_assoc_long_ex(definition, SS("bindType"), 2); + + PHALCON_OBS_NVAR(column_size); + phalcon_array_fetch_long(&column_size, field, 2, PH_NOISY); + + PHALCON_OBS_NVAR(column_precision); + phalcon_array_fetch_long(&column_precision, field, 3, PH_NOISY); + + PHALCON_OBS_NVAR(column_scale); + phalcon_array_fetch_long(&column_scale, field, 4, PH_NOISY); + + PHALCON_OBS_NVAR(column_type); + phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); + + if (phalcon_memnstr_str(column_type, SL("NUMBER"))) { + phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE); + phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_precision, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("scale"), 458672173UL, &column_scale, PH_COPY | PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("INTEGER"))) { + phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE); + phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_precision, PH_COPY | PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("VARCHAR2"))) { + phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_size, PH_COPY | PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("FLOAT"))) { + phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE); + phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_size, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("scale"), 458672173UL, &column_scale, PH_COPY | PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("TIMESTAMP"))) { + phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("RAW"))) { + phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("BLOB"))) { + phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("CLOB"))) { + phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("VARCHAR2"))) { + phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_size, PH_COPY | PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("CHAR"))) { + phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &column_size, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); + } + } + } + } + } + } + } + } + } + } + + if (Z_TYPE_P(old_column) == IS_NULL) { + phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_SEPARATE); + } else { + phalcon_array_update_quick_string(&definition, SS("after"), 4053435767UL, &old_column, PH_COPY | PH_SEPARATE); + } + + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, field, 6, PH_NOISY); + if (PHALCON_IS_STRING(attribute, "P")) { + phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE); + } + + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); + if (PHALCON_IS_STRING(attribute, "N")) { + phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_SEPARATE); + } + + PHALCON_OBS_NVAR(column_name); + phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); + + PHALCON_INIT_NVAR(column); + object_init_ex(column, phalcon_db_column_ce); + phalcon_call_method_p2_key(NULL, column, "__construct", column_name, definition, 1107214344UL); + + phalcon_array_append(&columns, column, PH_SEPARATE); + PHALCON_CPY_WRT(old_column, column_name); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_CTOR(columns); } +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, lastInsertId){ + zval *sequence_name = NULL, *sql, *fetch_num, *ret, *insert_id; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 0, 1, &sequence_name); + + if (!sequence_name) { + PHALCON_INIT_VAR(sequence_name); + } + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT ", sequence_name, ".CURRVAL FROM dual"); + + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); + + PHALCON_INIT_VAR(ret); + phalcon_call_method_p2_key(ret, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + + PHALCON_OBS_VAR(insert_id); + phalcon_array_fetch_long(&insert_id, ret, 0, PH_NOISY); + RETURN_CCTOR(insert_id); +} -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_EscaperInterface){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, useExplicitIdValue){ - PHALCON_REGISTER_INTERFACE(Phalcon, EscaperInterface, escaperinterface, phalcon_escaperinterface_method_entry); - return SUCCESS; + RETURN_FALSE; } +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, getDefaultIdValue){ + zval *null_value; + PHALCON_MM_GROW(); + PHALCON_INIT_VAR(null_value); + ZVAL_STRING(null_value, "default", 1); + object_init_ex(return_value, phalcon_db_rawvalue_ce); + phalcon_call_method_p1_key(NULL, return_value, "__construct", null_value, 1107214344UL); + + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, supportSequences){ - + RETURN_TRUE; +} @@ -25485,578 +24688,631 @@ PHALCON_INIT_CLASS(Phalcon_EscaperInterface){ -PHALCON_INIT_CLASS(Phalcon_DI_FactoryDefault){ +PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Postgresql){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\DI, FactoryDefault, di_factorydefault, "phalcon\\di", phalcon_di_factorydefault_method_entry, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Adapter\\Pdo, Postgresql, db_adapter_pdo_postgresql, "phalcon\\db\\adapter\\pdo", phalcon_db_adapter_pdo_postgresql_method_entry, 0); + + zend_declare_property_string(phalcon_db_adapter_pdo_postgresql_ce, SL("_type"), "pgsql", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_db_adapter_pdo_postgresql_ce, SL("_dialectType"), "postgresql", ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_db_adapter_pdo_postgresql_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_DI_FactoryDefault, __construct){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, connect){ - zval *shared, *name = NULL, *definition = NULL, *router, *dispatcher; - zval *url, *models_manager, *models_metadata; - zval *response, *cookies, *request, *filter, *escaper; - zval *annotations, *security, *crypt, *flash, *flash_session; - zval *tag, *session, *session_bag, *events_manager; - zval *transaction_manager, *assets, *services; + zval *descriptor = NULL, *schema = NULL, *sql; PHALCON_MM_GROW(); - PHALCON_CALL_PARENT_NORETURN(this_ptr, "Phalcon\\DI\\FactoryDefault", "__construct"); - - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 1); + phalcon_fetch_params(1, 0, 1, &descriptor); - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "router", 1); + if (!descriptor) { + PHALCON_INIT_VAR(descriptor); + } else { + PHALCON_SEPARATE_PARAM(descriptor); + } - PHALCON_INIT_VAR(definition); - ZVAL_STRING(definition, "Phalcon\\Mvc\\Router", 1); + if (!zend_is_true(descriptor)) { + PHALCON_OBS_NVAR(descriptor); + phalcon_read_property_this_quick(&descriptor, this_ptr, SL("_descriptor"), 691635363UL, PH_NOISY_CC); + } - PHALCON_INIT_VAR(router); - object_init_ex(router, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, router, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "dispatcher", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Mvc\\Dispatcher", 1); - - PHALCON_INIT_VAR(dispatcher); - object_init_ex(dispatcher, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, dispatcher, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "url", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Mvc\\Url", 1); - - PHALCON_INIT_VAR(url); - object_init_ex(url, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, url, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "modelsManager", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Manager", 1); - - PHALCON_INIT_VAR(models_manager); - object_init_ex(models_manager, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, models_manager, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "modelsMetadata", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\MetaData\\Memory", 1); - - PHALCON_INIT_VAR(models_metadata); - object_init_ex(models_metadata, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, models_metadata, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "response", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Http\\Response", 1); - - PHALCON_INIT_VAR(response); - object_init_ex(response, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, response, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "cookies", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Http\\Response\\Cookies", 1); - - PHALCON_INIT_VAR(cookies); - object_init_ex(cookies, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, cookies, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "request", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Http\\Request", 1); - - PHALCON_INIT_VAR(request); - object_init_ex(request, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, request, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "filter", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Filter", 1); - - PHALCON_INIT_VAR(filter); - object_init_ex(filter, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, filter, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "escaper", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Escaper", 1); - - PHALCON_INIT_VAR(escaper); - object_init_ex(escaper, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, escaper, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "annotations", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Annotations\\Adapter\\Memory", 1); - - PHALCON_INIT_VAR(annotations); - object_init_ex(annotations, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, annotations, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "security", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Security", 1); - - PHALCON_INIT_VAR(security); - object_init_ex(security, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, security, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "crypt", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Crypt", 1); + PHALCON_INIT_VAR(schema); + if (phalcon_array_isset_quick_string(descriptor, SS("schema"), 2259341622UL)) { + PHALCON_OBS_NVAR(schema); + phalcon_array_fetch_quick_string(&schema, descriptor, SS("schema"), 2259341622UL, PH_NOISY); + phalcon_array_unset_string(&descriptor, SS("schema"), PH_SEPARATE); + } - PHALCON_INIT_VAR(crypt); - object_init_ex(crypt, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, crypt, "__construct", name, definition, shared, 1107214344UL); + PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Postgresql", "connect", descriptor); - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "flash", 1); + if (Z_TYPE_P(schema) == IS_STRING) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "SET search_path TO '", schema, "'"); + phalcon_call_method_p1_key(NULL, this_ptr, "execute", sql, 3117639032UL); + } - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Flash\\Direct", 1); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, describeColumns){ + + zval *table, *schema = NULL, *columns, *dialect, *sql, *fetch_num; + zval *describe, *old_column = NULL, *field = NULL, *definition = NULL; + zval *char_size = NULL, *numeric_size = NULL, *column_type = NULL; + zval *attribute = NULL, *column_name = NULL, *column = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &table, &schema); - PHALCON_INIT_VAR(flash); - object_init_ex(flash, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, flash, "__construct", name, definition, shared, 1107214344UL); + if (!schema) { + PHALCON_INIT_VAR(schema); + } - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "flashSession", 1); + PHALCON_INIT_VAR(columns); + array_init(columns); - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Flash\\Session", 1); + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - PHALCON_INIT_VAR(flash_session); - object_init_ex(flash_session, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, flash_session, "__construct", name, definition, shared, 1107214344UL); + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "tag", 1); + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Tag", 1); + PHALCON_INIT_VAR(describe); + phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - PHALCON_INIT_VAR(tag); - object_init_ex(tag, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, tag, "__construct", name, definition, shared, 1107214344UL); + PHALCON_INIT_VAR(old_column); - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "session", 1); + phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Session\\Adapter\\Files", 1); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(session); - object_init_ex(session, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, session, "__construct", name, definition, shared, 1107214344UL); + PHALCON_GET_HVALUE(field); - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "sessionBag", 1); + PHALCON_INIT_NVAR(definition); + array_init_size(definition, 1); + add_assoc_long_ex(definition, SS("bindType"), 2); - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Session\\Bag", 1); + PHALCON_OBS_NVAR(char_size); + phalcon_array_fetch_long(&char_size, field, 2, PH_NOISY); - PHALCON_INIT_VAR(session_bag); - object_init_ex(session_bag, phalcon_di_service_ce); - phalcon_call_method_p2_key(NULL, session_bag, "__construct", name, definition, 1107214344UL); + PHALCON_OBS_NVAR(numeric_size); + phalcon_array_fetch_long(&numeric_size, field, 3, PH_NOISY); - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "eventsManager", 1); + PHALCON_OBS_NVAR(column_type); + phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Events\\Manager", 1); + if (phalcon_memnstr_str(column_type, SL("int"))) { + phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE); + phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &numeric_size, PH_COPY | PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("varying"))) { + phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &char_size, PH_COPY | PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("date"))) { + phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("numeric"))) { + phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE); + phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &numeric_size, PH_COPY | PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("char"))) { + phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &char_size, PH_COPY | PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("timestamp"))) { + phalcon_array_update_string_long(&definition, SL("type"), 4, PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("text"))) { + phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &char_size, PH_COPY | PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("float"))) { + phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE); + phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &numeric_size, PH_COPY | PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("bool"))) { + phalcon_array_update_string_long(&definition, SL("type"), 8, PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("size"), 0, PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 5, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("uuid"))) { + phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("size"), 36, PH_SEPARATE); + } else { + phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &char_size, PH_COPY | PH_SEPARATE); + } + } + } + } + } + } + } + } + } + } - PHALCON_INIT_VAR(events_manager); - object_init_ex(events_manager, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, events_manager, "__construct", name, definition, shared, 1107214344UL); + if (phalcon_memnstr_str(column_type, SL("unsigned"))) { + phalcon_array_update_string_bool(&definition, SL("unsigned"), 1, PH_SEPARATE); + } - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "transactions", 1); + if (Z_TYPE_P(old_column) == IS_NULL) { + phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_SEPARATE); + } else { + phalcon_array_update_quick_string(&definition, SS("after"), 4053435767UL, &old_column, PH_COPY | PH_SEPARATE); + } - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Transaction\\Manager", 1); + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); + if (PHALCON_IS_STRING(attribute, "PRI")) { + phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE); + } - PHALCON_INIT_VAR(transaction_manager); - object_init_ex(transaction_manager, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, transaction_manager, "__construct", name, definition, shared, 1107214344UL); + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, field, 4, PH_NOISY); + if (PHALCON_IS_STRING(attribute, "NO")) { + phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_SEPARATE); + } - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "assets", 1); + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, field, 6, PH_NOISY); + if (PHALCON_IS_STRING(attribute, "auto_increment")) { + phalcon_array_update_string_bool(&definition, SL("autoIncrement"), 1, PH_SEPARATE); + } - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Assets\\Manager", 1); + PHALCON_OBS_NVAR(column_name); + phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); - PHALCON_INIT_VAR(assets); - object_init_ex(assets, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, assets, "__construct", name, definition, shared, 1107214344UL); + PHALCON_INIT_NVAR(column); + object_init_ex(column, phalcon_db_column_ce); + phalcon_call_method_p2_key(NULL, column, "__construct", column_name, definition, 1107214344UL); - PHALCON_INIT_VAR(services); - array_init_size(services, 21); - phalcon_array_update_quick_string(&services, SS("router"), 1453446246UL, &router, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("dispatcher"), 2638982508UL, &dispatcher, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("url"), 2090805944UL, &url, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("modelsManager"), 3091111524UL, &models_manager, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("modelsMetadata"), 1052689642UL, &models_metadata, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("response"), 2839663316UL, &response, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("cookies"), 1147216050UL, &cookies, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("request"), 533957326UL, &request, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("filter"), 2890214155UL, &filter, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("escaper"), 874428264UL, &escaper, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("security"), 1509414237UL, &security, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("crypt"), 4146129335UL, &crypt, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("annotations"), 3222607251UL, &annotations, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("flash"), 4255560371UL, &flash, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("flashSession"), 1805780183UL, &flash_session, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("tag"), 2090751329UL, &tag, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("session"), 278765481UL, &session, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("sessionBag"), 2133837299UL, &session_bag, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("eventsManager"), 190863765UL, &events_manager, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("transactionManager"), 2946122822UL, &transaction_manager, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("assets"), 1126974296UL, &assets, PH_COPY | PH_SEPARATE); + phalcon_array_append(&columns, column, PH_SEPARATE); + PHALCON_CPY_WRT(old_column, column_name); - phalcon_update_property_this_quick(this_ptr, SL("_services"), services, 2714588616UL TSRMLS_CC); + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_MM_RESTORE(); + RETURN_CTOR(columns); } +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, useExplicitIdValue){ + RETURN_TRUE; +} +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, getDefaultIdValue){ -#ifdef HAVE_CONFIG_H -#endif + zval *null_value, *default_value; + PHALCON_MM_GROW(); + PHALCON_INIT_VAR(null_value); + ZVAL_STRING(null_value, "default", 1); + + PHALCON_INIT_VAR(default_value); + object_init_ex(default_value, phalcon_db_rawvalue_ce); + phalcon_call_method_p1_key(NULL, default_value, "__construct", null_value, 1107214344UL); + + RETURN_CTOR(default_value); +} +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, supportSequences){ + RETURN_TRUE; +} -PHALCON_INIT_CLASS(Phalcon_DI_Service){ - PHALCON_REGISTER_CLASS(Phalcon\\DI, Service, di_service, phalcon_di_service_method_entry, 0); - zend_declare_property_null(phalcon_di_service_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_di_service_ce, SL("_definition"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_di_service_ce, SL("_shared"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_di_service_ce, SL("_sharedInstance"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_di_service_ce TSRMLS_CC, 1, phalcon_di_serviceinterface_ce); +#ifdef HAVE_CONFIG_H +#endif - return SUCCESS; -} -static PHP_METHOD(Phalcon_DI_Service, __construct){ - zval *name, *definition, *shared = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &name, &definition, &shared); - - if (!shared) { - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 0); - } - - phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_definition"), definition, 2496408365UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_shared"), shared, 3057556539UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_DI_Service, getName){ +PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Sqlite){ - RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); -} + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Adapter\\Pdo, Sqlite, db_adapter_pdo_sqlite, "phalcon\\db\\adapter\\pdo", phalcon_db_adapter_pdo_sqlite_method_entry, 0); -static PHP_METHOD(Phalcon_DI_Service, setShared){ + zend_declare_property_string(phalcon_db_adapter_pdo_sqlite_ce, SL("_type"), "sqlite", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_db_adapter_pdo_sqlite_ce, SL("_dialectType"), "sqlite", ZEND_ACC_PROTECTED TSRMLS_CC); - zval *shared; + zend_class_implements(phalcon_db_adapter_pdo_sqlite_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); - phalcon_fetch_params(0, 1, 0, &shared); - - phalcon_update_property_this_quick(this_ptr, SL("_shared"), shared, 3057556539UL TSRMLS_CC); - + return SUCCESS; } -static PHP_METHOD(Phalcon_DI_Service, isShared){ - - - RETURN_MEMBER_QUICK(this_ptr, "_shared", 3057556539UL); -} +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, connect){ -static PHP_METHOD(Phalcon_DI_Service, setSharedInstance){ + zval *descriptor = NULL, *dbname; - zval *shared_instance; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &shared_instance); + phalcon_fetch_params(1, 0, 1, &descriptor); - phalcon_update_property_this_quick(this_ptr, SL("_sharedInstance"), shared_instance, 665278864UL TSRMLS_CC); + if (!descriptor) { + PHALCON_INIT_VAR(descriptor); + } else { + PHALCON_SEPARATE_PARAM(descriptor); + } -} - -static PHP_METHOD(Phalcon_DI_Service, setDefinition){ - - zval *definition; - - phalcon_fetch_params(0, 1, 0, &definition); + if (!zend_is_true(descriptor)) { + PHALCON_OBS_NVAR(descriptor); + phalcon_read_property_this_quick(&descriptor, this_ptr, SL("_descriptor"), 691635363UL, PH_NOISY_CC); + } + if (!phalcon_array_isset_quick_string(descriptor, SS("dbname"), 35027788UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "dbname must be specified"); + return; + } else { + PHALCON_OBS_VAR(dbname); + phalcon_array_fetch_quick_string(&dbname, descriptor, SS("dbname"), 35027788UL, PH_NOISY); + phalcon_array_update_quick_string(&descriptor, SS("dsn"), 2090196170UL, &dbname, PH_COPY | PH_SEPARATE); + } - phalcon_update_property_this_quick(this_ptr, SL("_definition"), definition, 2496408365UL TSRMLS_CC); + PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Sqlite", "connect", descriptor); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_DI_Service, getDefinition){ - - - RETURN_MEMBER_QUICK(this_ptr, "_definition", 2496408365UL); -} - -static PHP_METHOD(Phalcon_DI_Service, resolve){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeColumns){ - zval *parameters = NULL, *dependency_injector = NULL, *shared; - zval *shared_instance, *found = NULL, *instance = NULL, *definition; - zval *builder, *name, *exception_message; + zval *table, *schema = NULL, *columns, *dialect, *size_pattern; + zval *sql, *fetch_num, *describe, *old_column = NULL, *field = NULL; + zval *definition = NULL, *column_type = NULL, *pos = NULL, *attribute = NULL; + zval *matches = NULL, *match_one = NULL, *column_name = NULL, *column = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, ¶meters, &dependency_injector); + phalcon_fetch_params(1, 1, 1, &table, &schema); - if (!parameters) { - PHALCON_INIT_VAR(parameters); + if (!schema) { + PHALCON_INIT_VAR(schema); } - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } + PHALCON_INIT_VAR(columns); + array_init(columns); - PHALCON_OBS_VAR(shared); - phalcon_read_property_this_quick(&shared, this_ptr, SL("_shared"), 3057556539UL, PH_NOISY_CC); + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - if (zend_is_true(shared)) { + PHALCON_INIT_VAR(size_pattern); + ZVAL_STRING(size_pattern, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); - PHALCON_OBS_VAR(shared_instance); - phalcon_read_property_this_quick(&shared_instance, this_ptr, SL("_sharedInstance"), 665278864UL, PH_NOISY_CC); - if (Z_TYPE_P(shared_instance) != IS_NULL) { - RETURN_CCTOR(shared_instance); - } - } + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); - PHALCON_INIT_VAR(found); - ZVAL_BOOL(found, 1); + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); - PHALCON_INIT_VAR(instance); + PHALCON_INIT_VAR(describe); + phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - PHALCON_OBS_VAR(definition); - phalcon_read_property_this_quick(&definition, this_ptr, SL("_definition"), 2496408365UL, PH_NOISY_CC); - if (Z_TYPE_P(definition) == IS_STRING) { + PHALCON_INIT_VAR(old_column); - if (phalcon_class_exists(definition, 1 TSRMLS_CC)) { - if (Z_TYPE_P(parameters) == IS_ARRAY) { - if (phalcon_fast_count_ev(parameters TSRMLS_CC)) { - if (phalcon_create_instance_params(instance, definition, parameters TSRMLS_CC) == FAILURE) { - return; - } + phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(field); + + PHALCON_INIT_NVAR(definition); + array_init_size(definition, 1); + add_assoc_long_ex(definition, SS("bindType"), 2); + + PHALCON_OBS_NVAR(column_type); + phalcon_array_fetch_long(&column_type, field, 2, PH_NOISY); + + PHALCON_INIT_NVAR(pos); + phalcon_fast_stripos_str(pos, column_type, SL("int")); + if (PHALCON_IS_NOT_FALSE(pos)) { + phalcon_array_update_string_long(&definition, SL("type"), 0, PH_SEPARATE); + phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 1, PH_SEPARATE); + + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); + + if (zend_is_true(attribute)) { + phalcon_array_update_string_bool(&definition, SL("autoIncrement"), 1, PH_SEPARATE); + } + } else { + if (phalcon_memnstr_str(column_type, SL("varchar"))) { + phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("date"))) { + phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE); } else { - PHALCON_INIT_NVAR(instance); - if (phalcon_create_instance(instance, definition TSRMLS_CC) == FAILURE) { - return; + if (phalcon_memnstr_str(column_type, SL("decimal"))) { + phalcon_array_update_string_long(&definition, SL("type"), 3, PH_SEPARATE); + phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("char"))) { + phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("datetime"))) { + phalcon_array_update_string_long(&definition, SL("type"), 4, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("text"))) { + phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("float"))) { + phalcon_array_update_string_long(&definition, SL("type"), 7, PH_SEPARATE); + phalcon_array_update_string_bool(&definition, SL("isNumeric"), 1, PH_SEPARATE); + phalcon_array_update_string_long(&definition, SL("bindType"), 32, PH_SEPARATE); + } else { + if (phalcon_memnstr_str(column_type, SL("enum"))) { + phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); + } else { + phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); + } + } + } + } + } } } - } else { - PHALCON_INIT_NVAR(instance); - if (phalcon_create_instance(instance, definition TSRMLS_CC) == FAILURE) { - return; - } } - } else { - ZVAL_BOOL(found, 0); } - } else { - if (likely(Z_TYPE_P(definition) == IS_OBJECT)) { - if (phalcon_is_instance_of(definition, SL("Closure") TSRMLS_CC)) { - if (Z_TYPE_P(parameters) == IS_ARRAY) { - PHALCON_INIT_NVAR(instance); - PHALCON_CALL_USER_FUNC_ARRAY(instance, definition, parameters); - } else { - PHALCON_INIT_NVAR(instance); - PHALCON_CALL_USER_FUNC(instance, definition); + + if (phalcon_memnstr_str(column_type, SL("("))) { + + PHALCON_INIT_NVAR(matches); + + PHALCON_INIT_NVAR(pos); + phalcon_preg_match(pos, size_pattern, column_type, matches TSRMLS_CC); + + if (zend_is_true(pos)) { + if (phalcon_array_isset_long(matches, 1)) { + PHALCON_OBS_NVAR(match_one); + phalcon_array_fetch_long(&match_one, matches, 1, PH_NOISY); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &match_one, PH_COPY | PH_SEPARATE); } - } else { - PHALCON_CPY_WRT(instance, definition); } + } + + if (phalcon_memnstr_str(column_type, SL("unsigned"))) { + phalcon_array_update_string_bool(&definition, SL("unsigned"), 1, PH_SEPARATE); + } + + if (!zend_is_true(old_column)) { + phalcon_array_update_string_bool(&definition, SL("first"), 1, PH_SEPARATE); } else { - if (Z_TYPE_P(definition) == IS_ARRAY) { - PHALCON_INIT_VAR(builder); - object_init_ex(builder, phalcon_di_service_builder_ce); + phalcon_array_update_quick_string(&definition, SS("after"), 4053435767UL, &old_column, PH_COPY | PH_SEPARATE); + } - PHALCON_INIT_NVAR(instance); - phalcon_call_method_p3_key(instance, builder, "build", dependency_injector, definition, parameters, 4109971829UL); - } else { - PHALCON_INIT_NVAR(found); - ZVAL_BOOL(found, 0); - } + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); + if (zend_is_true(attribute)) { + phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE); } - } - if (PHALCON_IS_FALSE(found)) { - PHALCON_OBS_VAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, field, 3, PH_NOISY); + if (zend_is_true(attribute)) { + phalcon_array_update_string_bool(&definition, SL("notNull"), 1, PH_SEPARATE); + } - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Service '", name, "' cannot be resolved"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } + PHALCON_OBS_NVAR(column_name); + phalcon_array_fetch_long(&column_name, field, 1, PH_NOISY); - if (zend_is_true(shared)) { - phalcon_update_property_this_quick(this_ptr, SL("_sharedInstance"), instance, 665278864UL TSRMLS_CC); + PHALCON_INIT_NVAR(column); + object_init_ex(column, phalcon_db_column_ce); + phalcon_call_method_p2_key(NULL, column, "__construct", column_name, definition, 1107214344UL); + + phalcon_array_append(&columns, column, PH_SEPARATE); + PHALCON_CPY_WRT(old_column, column_name); + + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CCTOR(instance); + RETURN_CTOR(columns); } -static PHP_METHOD(Phalcon_DI_Service, setParameter){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeIndexes){ - zval *position, *parameter, *definition, *arguments = NULL; + zval *table, *schema = NULL, *dialect, *fetch_num, *sql, *describe; + zval *indexes, *index = NULL, *key_name = NULL, *empty_arr = NULL, *sql_index_describe = NULL; + zval *describe_index = NULL, *index_column = NULL, *column_name = NULL; + zval *index_objects, *index_columns = NULL, *name = NULL; + HashTable *ah0, *ah1, *ah2; + HashPosition hp0, hp1, hp2; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &position, ¶meter); + phalcon_fetch_params(1, 1, 1, &table, &schema); - PHALCON_OBS_VAR(definition); - phalcon_read_property_this_quick(&definition, this_ptr, SL("_definition"), 2496408365UL, PH_NOISY_CC); - if (unlikely(Z_TYPE_P(definition) != IS_ARRAY)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Definition must be an array to update its parameters"); - return; + if (!schema) { + PHALCON_INIT_VAR(schema); } - if (unlikely(Z_TYPE_P(position) != IS_LONG)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Position must be integer"); - return; - } + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - if (unlikely(Z_TYPE_P(parameter) != IS_ARRAY)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The parameter must be an array"); - return; - } + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); - if (phalcon_array_isset_quick_string(definition, SS("arguments"), 3751272283UL)) { - PHALCON_OBS_VAR(arguments); - phalcon_array_fetch_quick_string(&arguments, definition, SS("arguments"), 3751272283UL, PH_NOISY); - phalcon_array_update_zval(&arguments, position, ¶meter, PH_COPY | PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(arguments); - array_init_size(arguments, 1); - phalcon_array_update_zval(&arguments, position, ¶meter, PH_COPY | PH_SEPARATE); - } + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "describeindexes", table, schema, 689092630UL); - phalcon_array_update_quick_string(&definition, SS("arguments"), 3751272283UL, &arguments, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(describe); + phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); - phalcon_update_property_this_quick(this_ptr, SL("_definition"), definition, 2496408365UL TSRMLS_CC); + PHALCON_INIT_VAR(indexes); + array_init(indexes); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_DI_Service, getParameter){ - - zval *position, *definition, *arguments, *parameter; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &position); + phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); - PHALCON_OBS_VAR(definition); - phalcon_read_property_this_quick(&definition, this_ptr, SL("_definition"), 2496408365UL, PH_NOISY_CC); - if (Z_TYPE_P(definition) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Definition must be an array to obtain its parameters"); - return; - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (Z_TYPE_P(position) != IS_LONG) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Position must be integer"); - return; - } + PHALCON_GET_HVALUE(index); - if (phalcon_array_isset_quick_string(definition, SS("arguments"), 3751272283UL)) { + PHALCON_OBS_NVAR(key_name); + phalcon_array_fetch_long(&key_name, index, 1, PH_NOISY); + if (!phalcon_array_isset(indexes, key_name)) { + PHALCON_INIT_NVAR(empty_arr); + array_init(empty_arr); + phalcon_array_update_zval(&indexes, key_name, &empty_arr, PH_COPY | PH_SEPARATE); + } - PHALCON_OBS_VAR(arguments); - phalcon_array_fetch_quick_string(&arguments, definition, SS("arguments"), 3751272283UL, PH_NOISY); - if (phalcon_array_isset(arguments, position)) { - PHALCON_OBS_VAR(parameter); - phalcon_array_fetch(¶meter, arguments, position, PH_NOISY); - RETURN_CCTOR(parameter); + PHALCON_INIT_NVAR(sql_index_describe); + phalcon_call_method_p1_key(sql_index_describe, dialect, "describeindex", key_name, 1925282846UL); + + PHALCON_INIT_NVAR(describe_index); + phalcon_call_method_p2_key(describe_index, this_ptr, "fetchall", sql_index_describe, fetch_num, 1636682248UL); + + phalcon_is_iterable(describe_index, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(index_column); + + PHALCON_OBS_NVAR(column_name); + phalcon_array_fetch_long(&column_name, index_column, 2, PH_NOISY); + phalcon_array_update_append_multi_2(&indexes, key_name, column_name, 0); + + zend_hash_move_forward_ex(ah1, &hp1); } + + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_MM_NULL(); + PHALCON_INIT_VAR(index_objects); + array_init(index_objects); + + phalcon_is_iterable(indexes, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HKEY(name, ah2, hp2); + PHALCON_GET_HVALUE(index_columns); + + PHALCON_INIT_NVAR(index); + object_init_ex(index, phalcon_db_index_ce); + phalcon_call_method_p2_key(NULL, index, "__construct", name, index_columns, 1107214344UL); + + phalcon_array_update_zval(&index_objects, name, &index, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah2, &hp2); + } + + RETURN_CTOR(index_objects); } -static PHP_METHOD(Phalcon_DI_Service, __set_state){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeReferences){ - zval *attributes, *name, *definition, *shared; + zval *table, *schema = NULL, *dialect, *sql, *fetch_num, *describe; + zval *reference_objects, *reference_describe = NULL; + zval *number = NULL, *constraint_name = NULL, *referenced_table = NULL; + zval *from = NULL, *to = NULL, *columns = NULL, *referenced_columns = NULL; + zval *reference_array = NULL, *reference = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &attributes); + phalcon_fetch_params(1, 1, 1, &table, &schema); - if (phalcon_array_isset_quick_string(attributes, SS("_name"), 3983977829UL)) { - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, attributes, SS("_name"), 3983977829UL, PH_NOISY); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The attribute '_name' is required"); - return; - } - if (phalcon_array_isset_quick_string(attributes, SS("_definition"), 2496408365UL)) { - PHALCON_OBS_VAR(definition); - phalcon_array_fetch_quick_string(&definition, attributes, SS("_definition"), 2496408365UL, PH_NOISY); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The attribute '_name' is required"); - return; + if (!schema) { + PHALCON_INIT_VAR(schema); } - if (phalcon_array_isset_quick_string(attributes, SS("_shared"), 3057556539UL)) { - PHALCON_OBS_VAR(shared); - phalcon_array_fetch_quick_string(&shared, attributes, SS("_shared"), 3057556539UL, PH_NOISY); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The attribute '_shared' is required"); - return; - } + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - object_init_ex(return_value, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, return_value, "__construct", name, definition, shared, 1107214344UL); + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "describereferences", table, schema, 1939869288UL); - RETURN_MM(); + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); + + PHALCON_INIT_VAR(describe); + phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + + PHALCON_INIT_VAR(reference_objects); + array_init(reference_objects); + + phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(number, ah0, hp0); + PHALCON_GET_HVALUE(reference_describe); + + PHALCON_INIT_NVAR(constraint_name); + PHALCON_CONCAT_SV(constraint_name, "foreign_key_", number); + + PHALCON_OBS_NVAR(referenced_table); + phalcon_array_fetch_long(&referenced_table, reference_describe, 2, PH_NOISY); + + PHALCON_OBS_NVAR(from); + phalcon_array_fetch_long(&from, reference_describe, 3, PH_NOISY); + + PHALCON_OBS_NVAR(to); + phalcon_array_fetch_long(&to, reference_describe, 4, PH_NOISY); + + PHALCON_INIT_NVAR(columns); + array_init_size(columns, 1); + phalcon_array_append(&columns, from, PH_SEPARATE); + + PHALCON_INIT_NVAR(referenced_columns); + array_init_size(referenced_columns, 1); + phalcon_array_append(&referenced_columns, to, PH_SEPARATE); + + PHALCON_INIT_NVAR(reference_array); + array_init_size(reference_array, 4); + add_assoc_null_ex(reference_array, SS("referencedSchema")); + phalcon_array_update_quick_string(&reference_array, SS("referencedTable"), 3390337856UL, &referenced_table, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&reference_array, SS("columns"), 1041822630UL, &columns, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&reference_array, SS("referencedColumns"), 1045113721UL, &referenced_columns, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(reference); + object_init_ex(reference, phalcon_db_reference_ce); + phalcon_call_method_p2_key(NULL, reference, "__construct", constraint_name, reference_array, 1107214344UL); + + phalcon_array_update_zval(&reference_objects, constraint_name, &reference, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_CTOR(reference_objects); +} + +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, useExplicitIdValue){ + + + RETURN_TRUE; } @@ -26072,676 +25328,788 @@ static PHP_METHOD(Phalcon_DI_Service, __set_state){ -PHALCON_INIT_CLASS(Phalcon_DI_Service_Builder){ +PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo){ - PHALCON_REGISTER_CLASS(Phalcon\\DI\\Service, Builder, di_service_builder, phalcon_di_service_builder_method_entry, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Adapter, Pdo, db_adapter_pdo, "phalcon\\db\\adapter", phalcon_db_adapter_pdo_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_property_null(phalcon_db_adapter_pdo_ce, SL("_pdo"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_adapter_pdo_ce, SL("_affectedRows"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_db_adapter_pdo_ce, SL("_transactionLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_DI_Service_Builder, _buildParameter){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, __construct){ - zval *dependency_injector, *position, *argument; - zval *exception_message = NULL, *type, *name = NULL, *value = NULL, *instance_arguments; + zval *descriptor; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &dependency_injector, &position, &argument); - - if (Z_TYPE_P(argument) != IS_ARRAY) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Argument at position ", position, " must be an array"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } + phalcon_fetch_params(1, 1, 0, &descriptor); - if (!phalcon_array_isset_quick_string(argument, SS("type"), 276192743UL)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Argument at position ", position, " must have a type"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + if (Z_TYPE_P(descriptor) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The descriptor must be an array"); return; } + phalcon_call_method_p1_key(NULL, this_ptr, "connect", descriptor, 1111492527UL); + PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo", "__construct", descriptor); - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, argument, SS("type"), 276192743UL, PH_NOISY); - - if (PHALCON_IS_STRING(type, "service")) { - if (!phalcon_array_isset_quick_string(argument, SS("name"), 268211462UL)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Service 'name' is required in parameter on position ", position); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The dependency injector container is not valid"); - return; - } - - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, argument, SS("name"), 268211462UL, PH_NOISY); - phalcon_call_method_p1_key(return_value, dependency_injector, "get", name, 2090288933UL); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(type, "parameter")) { - if (!phalcon_array_isset_quick_string(argument, SS("value"), 574111618UL)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Service 'value' is required in parameter on position ", position); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } - - PHALCON_OBS_VAR(value); - phalcon_array_fetch_quick_string(&value, argument, SS("value"), 574111618UL, PH_NOISY); - - RETURN_CCTOR(value); - } - - if (PHALCON_IS_STRING(type, "instance")) { - if (!phalcon_array_isset_quick_string(argument, SS("className"), 362439804UL)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Service 'className' is required in parameter on position ", position); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The dependency injector container is not valid"); - return; - } - - PHALCON_OBS_NVAR(name); - phalcon_array_fetch_quick_string(&name, argument, SS("className"), 362439804UL, PH_NOISY); - if (!phalcon_array_isset_quick_string(argument, SS("arguments"), 3751272283UL)) { - PHALCON_INIT_NVAR(value); - phalcon_call_method_p1_key(value, dependency_injector, "get", name, 2090288933UL); - } else { - PHALCON_OBS_VAR(instance_arguments); - phalcon_array_fetch_quick_string(&instance_arguments, argument, SS("arguments"), 3751272283UL, PH_NOISY); - - phalcon_call_method_p2_key(return_value, dependency_injector, "get", name, instance_arguments, 2090288933UL); - RETURN_MM(); - } - - RETURN_CCTOR(value); - } - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Unknown service type in parameter on position ", position); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_DI_Service_Builder, _buildParameters){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect){ - zval *dependency_injector, *arguments, *build_arguments; - zval *argument = NULL, *position = NULL, *value = NULL; + zval *descriptor = NULL, *username = NULL, *password = NULL, *dsn_parts; + zval *value = NULL, *key = NULL, *dsn_attribute = NULL, *dsn_attributes = NULL; + zval *pdo_type, *dsn, *options = NULL, *persistent, *pdo; + zend_class_entry *ce; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &dependency_injector, &arguments); - - if (Z_TYPE_P(arguments) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Definition arguments must be an array"); - return; - } - - PHALCON_INIT_VAR(build_arguments); - array_init(build_arguments); - - phalcon_is_iterable(arguments, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(position, ah0, hp0); - PHALCON_GET_HVALUE(argument); - - PHALCON_INIT_NVAR(value); - phalcon_call_method_p3_key(value, this_ptr, "_buildparameter", dependency_injector, position, argument, 1973645589UL); - phalcon_array_append(&build_arguments, value, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { + RETURN_MM_NULL(); } - - RETURN_CTOR(build_arguments); -} -static PHP_METHOD(Phalcon_DI_Service_Builder, build){ + if (!descriptor) { + PHALCON_INIT_VAR(descriptor); + } else { + PHALCON_SEPARATE_PARAM(descriptor); + } - zval *dependency_injector, *definition, *parameters = NULL; - zval *class_name, *instance = NULL, *arguments = NULL, *build_arguments = NULL; - zval *param_calls = NULL, *method = NULL, *method_position = NULL; - zval *exception_message = NULL, *method_name = NULL, *method_call = NULL; - zval *status = NULL, *property = NULL, *property_position = NULL; - zval *property_name = NULL, *property_value = NULL, *value = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &dependency_injector, &definition, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - if (Z_TYPE_P(definition) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service definition must be an array"); - return; - } - - if (!phalcon_array_isset_quick_string(definition, SS("className"), 362439804UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Invalid service definition. Missing 'className' parameter"); - return; + if (Z_TYPE_P(descriptor) == IS_NULL) { + PHALCON_OBS_NVAR(descriptor); + phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); } - - PHALCON_OBS_VAR(class_name); - phalcon_array_fetch_quick_string(&class_name, definition, SS("className"), 362439804UL, PH_NOISY); - if (Z_TYPE_P(parameters) == IS_ARRAY) { - - if (phalcon_fast_count_ev(parameters TSRMLS_CC)) { - PHALCON_INIT_VAR(instance); - if (phalcon_create_instance_params(instance, class_name, parameters TSRMLS_CC) == FAILURE) { - return; - } - } else { - PHALCON_INIT_NVAR(instance); - if (phalcon_create_instance(instance, class_name TSRMLS_CC) == FAILURE) { - return; - } - } + + if (phalcon_array_isset_quick_string(descriptor, SS("username"), 3241309669UL)) { + PHALCON_OBS_VAR(username); + phalcon_array_fetch_quick_string(&username, descriptor, SS("username"), 3241309669UL, PH_NOISY); + phalcon_array_unset_string(&descriptor, SS("username"), PH_SEPARATE); } else { - if (phalcon_array_isset_quick_string(definition, SS("arguments"), 3751272283UL)) { - PHALCON_OBS_VAR(arguments); - phalcon_array_fetch_quick_string(&arguments, definition, SS("arguments"), 3751272283UL, PH_NOISY); - - PHALCON_INIT_VAR(build_arguments); - phalcon_call_method_p2_key(build_arguments, this_ptr, "_buildparameters", dependency_injector, arguments, 705798792UL); - - PHALCON_INIT_NVAR(instance); - if (phalcon_create_instance_params(instance, class_name, build_arguments TSRMLS_CC) == FAILURE) { - return; - } - } else { - PHALCON_INIT_NVAR(instance); - if (phalcon_create_instance(instance, class_name TSRMLS_CC) == FAILURE) { - return; - } - } - } - - if (phalcon_array_isset_quick_string(definition, SS("calls"), 4125497108UL)) { - if (Z_TYPE_P(instance) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The definition has setter injection parameters but the constructor didn't return an instance"); - return; - } - - PHALCON_OBS_VAR(param_calls); - phalcon_array_fetch_quick_string(¶m_calls, definition, SS("calls"), 4125497108UL, PH_NOISY); - if (Z_TYPE_P(param_calls) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Setter injection parameters must be an array"); - return; - } - - phalcon_is_iterable(param_calls, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(method_position, ah0, hp0); - PHALCON_GET_HVALUE(method); - - if (Z_TYPE_P(method) != IS_ARRAY) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Method call must be an array on position ", method_position); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } - - if (!phalcon_array_isset_quick_string(method, SS("method"), 3193080326UL)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "The method name is required on position ", method_position); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } - - PHALCON_OBS_NVAR(method_name); - phalcon_array_fetch_quick_string(&method_name, method, SS("method"), 3193080326UL, PH_NOISY); - - PHALCON_INIT_NVAR(method_call); - array_init_size(method_call, 2); - phalcon_array_append(&method_call, instance, PH_SEPARATE); - phalcon_array_append(&method_call, method_name, PH_SEPARATE); - if (phalcon_array_isset_quick_string(method, SS("arguments"), 3751272283UL)) { - - PHALCON_OBS_NVAR(arguments); - phalcon_array_fetch_quick_string(&arguments, method, SS("arguments"), 3751272283UL, PH_NOISY); - if (Z_TYPE_P(arguments) != IS_ARRAY) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Call arguments must be an array ", method_position); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } - - if (phalcon_fast_count_ev(arguments TSRMLS_CC)) { - PHALCON_INIT_NVAR(build_arguments); - phalcon_call_method_p2_key(build_arguments, this_ptr, "_buildparameters", dependency_injector, arguments, 705798792UL); - - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC_ARRAY(status, method_call, build_arguments); - - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC(status, method_call); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - if (phalcon_array_isset_quick_string(definition, SS("properties"), 1619284338UL)) { - if (Z_TYPE_P(instance) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The definition has properties injection parameters but the constructor didn't return an instance"); - return; - } - - PHALCON_OBS_NVAR(param_calls); - phalcon_array_fetch_quick_string(¶m_calls, definition, SS("properties"), 1619284338UL, PH_NOISY); - if (Z_TYPE_P(param_calls) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Setter injection parameters must be an array"); - return; - } - - phalcon_is_iterable(param_calls, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HKEY(property_position, ah1, hp1); - PHALCON_GET_HVALUE(property); - - if (Z_TYPE_P(property) != IS_ARRAY) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Property must be an array on position ", property_position); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } - - if (!phalcon_array_isset_quick_string(property, SS("name"), 268211462UL)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "The property name is required on position ", property_position); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } - - if (!phalcon_array_isset_quick_string(property, SS("value"), 574111618UL)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "The property value is required on position ", property_position); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } - - PHALCON_OBS_NVAR(property_name); - phalcon_array_fetch_quick_string(&property_name, property, SS("name"), 268211462UL, PH_NOISY); - - PHALCON_OBS_NVAR(property_value); - phalcon_array_fetch_quick_string(&property_value, property, SS("value"), 574111618UL, PH_NOISY); - - PHALCON_INIT_NVAR(value); - phalcon_call_method_p3_key(value, this_ptr, "_buildparameter", dependency_injector, property_position, property_value, 1973645589UL); - - phalcon_update_property_zval_zval(instance, property_name, value TSRMLS_CC); - - zend_hash_move_forward_ex(ah1, &hp1); - } - + PHALCON_INIT_NVAR(username); } - - RETURN_CTOR(instance); -} - - + if (phalcon_array_isset_quick_string(descriptor, SS("password"), 382886712UL)) { + PHALCON_OBS_VAR(password); + phalcon_array_fetch_quick_string(&password, descriptor, SS("password"), 382886712UL, PH_NOISY); + phalcon_array_unset_string(&descriptor, SS("password"), PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(password); + } + if (phalcon_array_isset_quick_string(descriptor, SS("options"), 2952422065UL)) { + PHALCON_OBS_VAR(options); + phalcon_array_fetch_quick_string(&options, descriptor, SS("options"), 2952422065UL, PH_NOISY); + phalcon_array_unset_string(&descriptor, SS("options"), PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(options); + array_init(options); + } -#ifdef HAVE_CONFIG_H -#endif + if (!phalcon_array_isset_quick_string(descriptor, SS("dsn"), 2090196170UL)) { + PHALCON_INIT_VAR(dsn_parts); + array_init(dsn_parts); + if (!phalcon_is_iterable_ex(descriptor, &ah0, &hp0, 0, 0)) { + return; + } -PHALCON_INIT_CLASS(Phalcon_DI_ServiceInterface){ + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_REGISTER_INTERFACE(Phalcon\\DI, ServiceInterface, di_serviceinterface, phalcon_di_serviceinterface_method_entry); + PHALCON_GET_FOREACH_KEY(key, ah0, hp0); + PHALCON_GET_FOREACH_VALUE(value); - return SUCCESS; -} + PHALCON_INIT_NVAR(dsn_attribute); + PHALCON_CONCAT_VSV(dsn_attribute, key, "=", value); + phalcon_array_append(&dsn_parts, dsn_attribute, PH_SEPARATE); + zend_hash_move_forward_ex(ah0, &hp0); + } + PHALCON_INIT_VAR(dsn_attributes); + phalcon_fast_join_str(dsn_attributes, SL(";"), dsn_parts TSRMLS_CC); + } else { + PHALCON_OBS_NVAR(dsn_attributes); + phalcon_array_fetch_quick_string(&dsn_attributes, descriptor, SS("dsn"), 2090196170UL, PH_NOISY); + } + PHALCON_OBS_VAR(pdo_type); + phalcon_read_property(&pdo_type, this_ptr, SL("_type"), PH_NOISY_CC); + PHALCON_INIT_VAR(dsn); + PHALCON_CONCAT_VSV(dsn, pdo_type, ":", dsn_attributes); + phalcon_array_update_long_long(&options, PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION, PH_SEPARATE); + //phalcon_array_update_long_long(&options, PDO_ATTR_CASE, PDO_CASE_LOWER, PH_SEPARATE); + //phalcon_array_update_long_long(&options, PDO_ATTR_CURSOR, PDO_CURSOR_SCROLL, PH_SEPARATE); + if (phalcon_array_isset_quick_string(descriptor, SS("persistent"), 2222052598UL)) { + PHALCON_OBS_VAR(persistent); + phalcon_array_fetch_quick_string(&persistent, descriptor, SS("persistent"), 2222052598UL, PH_NOISY); + if (zend_is_true(persistent)) { + phalcon_array_update_long_bool(&options, PDO_ATTR_PERSISTENT, 1, PH_SEPARATE); + } + } + ce = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + PHALCON_INIT_VAR(pdo); + object_init_ex(pdo, ce); + phalcon_call_method_p4_key(NULL, pdo, "__construct", dsn, username, password, options, 1107214344UL); + phalcon_update_property_zval(this_ptr, SL("_pdo"), pdo TSRMLS_CC); + PHALCON_MM_RESTORE(); +} +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, prepare){ -#ifdef HAVE_CONFIG_H -#endif + zval *sql_statement, *pdo; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &sql_statement); + + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, pdo, "prepare", sql_statement, 329932052UL); + RETURN_MM(); +} -PHALCON_INIT_CLASS(Phalcon_DI_InjectionAwareInterface){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, executePrepared){ - PHALCON_REGISTER_INTERFACE(Phalcon\\DI, InjectionAwareInterface, di_injectionawareinterface, phalcon_di_injectionawareinterface_method_entry); + zval *statement = NULL, *placeholders = NULL, *data_types = NULL; + zval *one, *value = NULL, *wildcard = NULL, *parameter = NULL, *type = NULL, *cast_value = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - return SUCCESS; -} + PHALCON_MM_GROW(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &statement, &placeholders, &data_types) == FAILURE) { + RETURN_MM_NULL(); + } + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + if (!phalcon_is_iterable_ex(placeholders, &ah0, &hp0, 0, 0)) { + return; + } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_GET_FOREACH_KEY(wildcard, ah0, hp0); + PHALCON_GET_FOREACH_VALUE(value); + if (Z_TYPE_P(wildcard) == IS_LONG) { + PHALCON_INIT_NVAR(parameter); + phalcon_add_function(parameter, wildcard, one TSRMLS_CC); + } else { + if (Z_TYPE_P(wildcard) == IS_STRING) { + PHALCON_CPY_WRT(parameter, wildcard); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid bind parameter"); + return; + } + } -#ifdef HAVE_CONFIG_H -#endif + if (Z_TYPE_P(data_types) == IS_ARRAY) { + if (likely(phalcon_array_isset(data_types, wildcard))) { + PHALCON_OBS_NVAR(type); + phalcon_array_fetch(&type, data_types, wildcard, PH_NOISY); + if (phalcon_compare_strict_long(type, 32 TSRMLS_CC)) { + PHALCON_INIT_NVAR(cast_value); + phalcon_cast(cast_value, value, IS_DOUBLE); + PHALCON_INIT_NVAR(type); + ZVAL_LONG(type, 1024); + } else { + PHALCON_CPY_WRT(cast_value, value); + } + Z_SET_ISREF_P(cast_value); + if (phalcon_compare_strict_long(type, 1024 TSRMLS_CC)) { + phalcon_call_method_p2_key(NULL, statement, "bindparam", parameter, cast_value, 724187283UL); + } else { + phalcon_call_method_p3_key(NULL, statement, "bindparam", parameter, cast_value, type, 724187283UL); + } + Z_UNSET_ISREF_P(cast_value); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid bind type parameter"); + return; + } + } else { + Z_SET_ISREF_P(value); + phalcon_call_method_p2_key(NULL, statement, "bindparam", parameter, value, 724187283UL); + Z_UNSET_ISREF_P(value); + } -PHALCON_INIT_CLASS(Phalcon_DI_FactoryDefault_CLI){ + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_REGISTER_CLASS_EX(Phalcon\\DI\\FactoryDefault, CLI, di_factorydefault_cli, "phalcon\\di\\factorydefault", phalcon_di_factorydefault_cli_method_entry, 0); + phalcon_call_method_key(NULL, statement, "execute", 3117639032UL); - return SUCCESS; + RETURN_CCTOR(statement); } -static PHP_METHOD(Phalcon_DI_FactoryDefault_CLI, __construct){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, query){ - zval *shared, *name = NULL, *definition = NULL, *router, *dispatcher; - zval *models_manager, *models_metadata, *filter; - zval *escaper, *annotations, *security, *events_manager; - zval *transaction_manager, *services; + zval *sql_statement, *bind_params = NULL, *bind_types = NULL; + zval *events_manager, *event_name = NULL, *status, *pdo; + zval *statement = NULL, *new_statement; PHALCON_MM_GROW(); - PHALCON_CALL_PARENT_NORETURN(this_ptr, "Phalcon\\DI\\FactoryDefault\\CLI", "__construct"); - - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 1); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "router", 1); + phalcon_fetch_params(1, 1, 2, &sql_statement, &bind_params, &bind_types); - PHALCON_INIT_VAR(definition); - ZVAL_STRING(definition, "Phalcon\\CLI\\Router", 1); + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); + } - PHALCON_INIT_VAR(router); - object_init_ex(router, phalcon_di_service_ce); - phalcon_call_method_p2_key(NULL, router, "__construct", name, definition, 1107214344UL); + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "dispatcher", 1); + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\CLI\\Dispatcher", 1); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_VAR(dispatcher); - object_init_ex(dispatcher, phalcon_di_service_ce); - phalcon_call_method_p2_key(NULL, dispatcher, "__construct", name, definition, 1107214344UL); + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "db:beforeQuery", 1); + phalcon_update_property_this_quick(this_ptr, SL("_sqlStatement"), sql_statement, 18972457UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlVariables"), bind_params, 3213579853UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlBindTypes"), bind_types, 3288357222UL TSRMLS_CC); - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "modelsManager", 1); + PHALCON_INIT_VAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, bind_params, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Manager", 1); + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + if (Z_TYPE_P(bind_params) == IS_ARRAY) { - PHALCON_INIT_VAR(models_manager); - object_init_ex(models_manager, phalcon_di_service_ce); - phalcon_call_method_p2_key(NULL, models_manager, "__construct", name, definition, 1107214344UL); + PHALCON_INIT_VAR(statement); + phalcon_call_method_p1_key(statement, pdo, "prepare", sql_statement, 329932052UL); + if (Z_TYPE_P(statement) == IS_OBJECT) { + PHALCON_INIT_VAR(new_statement); + phalcon_call_method_p3_key(new_statement, this_ptr, "executeprepared", statement, bind_params, bind_types, 647421771UL); + PHALCON_CPY_WRT(statement, new_statement); + } + } else { + PHALCON_INIT_NVAR(statement); + phalcon_call_method_p1_key(statement, pdo, "query", sql_statement, 401898907UL); + } - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "modelsMetadata", 1); + if (likely(Z_TYPE_P(statement) == IS_OBJECT)) { + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "db:afterQuery", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, bind_params, 259017035UL); + } + object_init_ex(return_value, phalcon_db_result_pdo_ce); + phalcon_call_method_p5_key(NULL, return_value, "__construct", this_ptr, statement, sql_statement, bind_params, bind_types, 1107214344UL); - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Metadata\\Memory", 1); + RETURN_MM(); + } - PHALCON_INIT_VAR(models_metadata); - object_init_ex(models_metadata, phalcon_di_service_ce); - phalcon_call_method_p2_key(NULL, models_metadata, "__construct", name, definition, 1107214344UL); + RETURN_CCTOR(statement); +} + +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, execute){ + + zval *sql_statement, *bind_params = NULL, *bind_types = NULL; + zval *events_manager, *event_name = NULL, *status, *affected_rows = NULL; + zval *pdo, *statement, *new_statement; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &sql_statement, &bind_params, &bind_types); - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "filter", 1); + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); + } - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Filter", 1); + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } - PHALCON_INIT_VAR(filter); - object_init_ex(filter, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, filter, "__construct", name, definition, shared, 1107214344UL); + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "escaper", 1); + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "db:beforeQuery", 1); + phalcon_update_property_this_quick(this_ptr, SL("_sqlStatement"), sql_statement, 18972457UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlVariables"), bind_params, 3213579853UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlBindTypes"), bind_types, 3288357222UL TSRMLS_CC); - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Escaper", 1); + PHALCON_INIT_VAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, bind_params, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } - PHALCON_INIT_VAR(escaper); - object_init_ex(escaper, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, escaper, "__construct", name, definition, shared, 1107214344UL); + PHALCON_INIT_VAR(affected_rows); + ZVAL_LONG(affected_rows, 0); - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "annotations", 1); + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + if (Z_TYPE_P(bind_params) == IS_ARRAY) { - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Annotations\\Adapter\\Memory", 1); + PHALCON_INIT_VAR(statement); + phalcon_call_method_p1_key(statement, pdo, "prepare", sql_statement, 329932052UL); + if (Z_TYPE_P(statement) == IS_OBJECT) { + PHALCON_INIT_VAR(new_statement); + phalcon_call_method_p3_key(new_statement, this_ptr, "executeprepared", statement, bind_params, bind_types, 647421771UL); - PHALCON_INIT_VAR(annotations); - object_init_ex(annotations, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, annotations, "__construct", name, definition, shared, 1107214344UL); + phalcon_call_method_key(affected_rows, new_statement, "rowcount", 4184721862UL); + } + } else { + PHALCON_INIT_NVAR(affected_rows); + phalcon_call_method_p1_key(affected_rows, pdo, "exec", sql_statement, 258355946UL); + } - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "security", 1); + if (Z_TYPE_P(affected_rows) == IS_LONG) { + phalcon_update_property_this_quick(this_ptr, SL("_affectedRows"), affected_rows, 3226297793UL TSRMLS_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "db:afterQuery", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, bind_params, 259017035UL); + } + } - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Security", 1); - - PHALCON_INIT_VAR(security); - object_init_ex(security, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, security, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(name); - ZVAL_STRING(name, "eventsManager", 1); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Events\\Manager", 1); - - PHALCON_INIT_VAR(events_manager); - object_init_ex(events_manager, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, events_manager, "__construct", name, definition, shared, 1107214344UL); - - PHALCON_INIT_NVAR(definition); - ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Transaction\\Manager", 1); - - PHALCON_INIT_VAR(transaction_manager); - object_init_ex(transaction_manager, phalcon_di_service_ce); - phalcon_call_method_p2_key(NULL, transaction_manager, "__construct", name, definition, 1107214344UL); - - PHALCON_INIT_VAR(services); - array_init_size(services, 10); - phalcon_array_update_quick_string(&services, SS("router"), 1453446246UL, &router, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("dispatcher"), 2638982508UL, &dispatcher, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("modelsManager"), 3091111524UL, &models_manager, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("modelsMetadata"), 1052689642UL, &models_metadata, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("filter"), 2890214155UL, &filter, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("escaper"), 874428264UL, &escaper, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("annotations"), 3222607251UL, &annotations, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("security"), 1509414237UL, &security, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("eventsManager"), 190863765UL, &events_manager, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&services, SS("transactionManager"), 2946122822UL, &transaction_manager, PH_COPY | PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_services"), services, 2714588616UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); + RETURN_MM_TRUE; } +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, affectedRows){ + RETURN_MEMBER_QUICK(this_ptr, "_affectedRows", 3226297793UL); +} +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, close){ -#ifdef HAVE_CONFIG_H -#endif - + zval *pdo; + PHALCON_MM_GROW(); + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + if (likely(Z_TYPE_P(pdo) == IS_OBJECT)) { + phalcon_update_property_null(this_ptr, SL("_pdo") TSRMLS_CC); + RETURN_MM_TRUE; + } + + RETURN_MM_TRUE; +} +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, escapeIdentifier){ + zval *identifier, *domain, *name; + PHALCON_MM_GROW(); -PHALCON_INIT_CLASS(Phalcon_DI_Injectable){ + phalcon_fetch_params(1, 1, 0, &identifier); + + if (Z_TYPE_P(identifier) == IS_ARRAY) { + PHALCON_OBS_VAR(domain); + phalcon_array_fetch_long(&domain, identifier, 0, PH_NOISY); + + PHALCON_OBS_VAR(name); + phalcon_array_fetch_long(&name, identifier, 1, PH_NOISY); + PHALCON_CONCAT_SVSVS(return_value, "\"", domain, "\".\"", name, "\""); + RETURN_MM(); + } + PHALCON_CONCAT_SVS(return_value, "\"", identifier, "\""); + + RETURN_MM(); +} - PHALCON_REGISTER_CLASS(Phalcon\\DI, Injectable, di_injectable, phalcon_di_injectable_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, escapeString){ - zend_declare_property_null(phalcon_di_injectable_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_di_injectable_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zval *str, *pdo; - zend_class_implements(phalcon_di_injectable_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_events_eventsawareinterface_ce); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 1, 0, &str); + + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, pdo, "quote", str, 402259795UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_DI_Injectable, setDI){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, convertBoundParams){ - zval *dependency_injector; + zval *sql, *params, *query_params, *placeholders; + zval *matches, *set_order, *bind_pattern, *status; + zval *place_match = NULL, *numeric_place = NULL, *value = NULL, *str_place = NULL; + zval *question, *bound_sql = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - phalcon_fetch_params(0, 1, 0, &dependency_injector); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &sql, ¶ms); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "Dependency Injector is invalid"); - return; + PHALCON_INIT_VAR(query_params); + array_init(query_params); + + PHALCON_INIT_VAR(placeholders); + array_init(placeholders); + + PHALCON_INIT_VAR(matches); + + PHALCON_INIT_VAR(set_order); + ZVAL_LONG(set_order, 2); + + PHALCON_INIT_VAR(bind_pattern); + ZVAL_STRING(bind_pattern, "/\\?([0-9]+)|:([a-zA-Z0-9_]+):/", 1); + Z_SET_ISREF_P(matches); + + PHALCON_INIT_VAR(status); + phalcon_call_func_p4(status, "preg_match_all", bind_pattern, sql, matches, set_order); + Z_UNSET_ISREF_P(matches); + if (zend_is_true(status)) { + + phalcon_is_iterable(matches, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(place_match); + + PHALCON_OBS_NVAR(numeric_place); + phalcon_array_fetch_long(&numeric_place, place_match, 1, PH_NOISY); + if (phalcon_array_isset(params, numeric_place)) { + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, params, numeric_place, PH_NOISY); + } else { + if (phalcon_array_isset_long(place_match, 2)) { + + PHALCON_OBS_NVAR(str_place); + phalcon_array_fetch_long(&str_place, place_match, 2, PH_NOISY); + if (phalcon_array_isset(params, str_place)) { + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, params, str_place, PH_NOISY); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Matched parameter wasn't found in parameters list"); + return; + } + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Matched parameter wasn't found in parameters list"); + return; + } + } + + phalcon_array_append(&placeholders, value, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(question); + ZVAL_STRING(question, "?", 1); + + PHALCON_INIT_VAR(bound_sql); + phalcon_call_func_p3(bound_sql, "preg_replace", bind_pattern, question, sql); + } else { + PHALCON_CPY_WRT(bound_sql, sql); } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + array_init_size(return_value, 2); + phalcon_array_update_quick_string(&return_value, SS("sql"), 2090732981UL, &bound_sql, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&return_value, SS("params"), 2613350281UL, &placeholders, PH_COPY | PH_SEPARATE); + + RETURN_MM(); } -static PHP_METHOD(Phalcon_DI_Injectable, getDI){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, lastInsertId){ - zval *dependency_injector = NULL; + zval *sequence_name = NULL, *pdo; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + phalcon_fetch_params(1, 0, 1, &sequence_name); + + if (!sequence_name) { + PHALCON_INIT_VAR(sequence_name); } - RETURN_CCTOR(dependency_injector); + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + if (Z_TYPE_P(pdo) != IS_OBJECT) { + RETURN_MM_FALSE; + } + + phalcon_call_method_p1_key(return_value, pdo, "lastinsertid", sequence_name, 106913211UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_DI_Injectable, setEventsManager){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, begin){ - zval *events_manager; + zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; + zval *event_name = NULL, *ntw_savepoint, *savepoint_name; - phalcon_fetch_params(0, 1, 0, &events_manager); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &nesting); - phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); + if (!nesting) { + PHALCON_INIT_VAR(nesting); + ZVAL_BOOL(nesting, 1); + } + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + if (Z_TYPE_P(pdo) != IS_OBJECT) { + RETURN_MM_FALSE; + } + + phalcon_property_incr(this_ptr, SL("_transactionLevel") TSRMLS_CC); + + PHALCON_OBS_VAR(transaction_level); + phalcon_read_property_this_quick(&transaction_level, this_ptr, SL("_transactionLevel"), 2789346594UL, PH_NOISY_CC); + if (PHALCON_IS_LONG(transaction_level, 1)) { + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "db:beginTransaction", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } + + phalcon_call_method_key(return_value, pdo, "begintransaction", 4233116368UL); + RETURN_MM(); + } else { + if (zend_is_true(transaction_level)) { + if (zend_is_true(nesting)) { + + PHALCON_INIT_VAR(ntw_savepoint); + phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); + if (zend_is_true(ntw_savepoint)) { + + PHALCON_OBS_NVAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(savepoint_name); + phalcon_call_method_key(savepoint_name, this_ptr, "getnestedtransactionsavepointname", 1903082728UL); + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "db:createSavepoint", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, savepoint_name, 259017035UL); + } + + phalcon_call_method_p1_key(return_value, this_ptr, "createsavepoint", savepoint_name, 2980652562UL); + RETURN_MM(); + } + } + } + } + + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_DI_Injectable, getEventsManager){ - - - RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); -} - -static PHP_METHOD(Phalcon_DI_Injectable, __get){ - +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, rollback){ - zval *property_name, *dependency_injector = NULL; - zval *has_service, *service = NULL, *class_name, *arguments; - zval *persistent; + zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; + zval *event_name = NULL, *ntw_savepoint, *savepoint_name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &property_name); - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "A dependency injection object is required to access the application services"); - return; - } + phalcon_fetch_params(1, 0, 1, &nesting); + + if (!nesting) { + PHALCON_INIT_VAR(nesting); + ZVAL_BOOL(nesting, 1); } - - PHALCON_INIT_VAR(has_service); - phalcon_call_method_p1_key(has_service, dependency_injector, "has", property_name, 2090320481UL); - if (zend_is_true(has_service)) { - PHALCON_INIT_VAR(service); - phalcon_call_method_p1_key(service, dependency_injector, "getshared", property_name, 1727570332UL); - phalcon_update_property_zval_zval(this_ptr, property_name, service TSRMLS_CC); - RETURN_CCTOR(service); + + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + if (Z_TYPE_P(pdo) != IS_OBJECT) { + RETURN_MM_FALSE; } - - if (PHALCON_IS_STRING(property_name, "di")) { - phalcon_update_property_this_quick(this_ptr, SL("di"), dependency_injector, 193489362UL TSRMLS_CC); - RETURN_CCTOR(dependency_injector); + + PHALCON_OBS_VAR(transaction_level); + phalcon_read_property_this_quick(&transaction_level, this_ptr, SL("_transactionLevel"), 2789346594UL, PH_NOISY_CC); + if (!zend_is_true(transaction_level)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "There is no active transaction"); + return; + } + + if (PHALCON_IS_LONG(transaction_level, 1)) { + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "db:rollbackTransaction", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } + + phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); + phalcon_call_method_key(return_value, pdo, "rollback", 3199546639UL); + RETURN_MM(); + } else { + if (zend_is_true(transaction_level)) { + if (zend_is_true(nesting)) { + + PHALCON_INIT_VAR(ntw_savepoint); + phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); + if (zend_is_true(ntw_savepoint)) { + + PHALCON_OBS_NVAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(savepoint_name); + phalcon_call_method_key(savepoint_name, this_ptr, "getnestedtransactionsavepointname", 1903082728UL); + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "db:rollbackSavepoint", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, savepoint_name, 259017035UL); + } + + phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); + phalcon_call_method_p1_key(return_value, this_ptr, "rollbacksavepoint", savepoint_name, 3444395528UL); + RETURN_MM(); + } + } + } + } + + if (PHALCON_GT_LONG(transaction_level, 0)) { + phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); } + + RETURN_MM_FALSE; +} - if (PHALCON_IS_STRING(property_name, "persistent")) { - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, commit){ - PHALCON_INIT_VAR(arguments); - array_init_size(arguments, 1); - phalcon_array_append(&arguments, class_name, PH_SEPARATE); + zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; + zval *event_name = NULL, *ntw_savepoint, *savepoint_name; - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "sessionBag", 1); + PHALCON_MM_GROW(); - PHALCON_INIT_VAR(persistent); - phalcon_call_method_p2_key(persistent, dependency_injector, "get", service, arguments, 2090288933UL); - phalcon_update_property_this_quick(this_ptr, SL("persistent"), persistent, 2222052598UL TSRMLS_CC); - RETURN_CCTOR(persistent); + phalcon_fetch_params(1, 0, 1, &nesting); + + if (!nesting) { + PHALCON_INIT_VAR(nesting); + ZVAL_BOOL(nesting, 1); } - - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Access to undefined property %s", Z_STRVAL_P(property_name)); - RETURN_MM_NULL(); + + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + if (Z_TYPE_P(pdo) != IS_OBJECT) { + RETURN_MM_FALSE; + } + + PHALCON_OBS_VAR(transaction_level); + phalcon_read_property_this_quick(&transaction_level, this_ptr, SL("_transactionLevel"), 2789346594UL, PH_NOISY_CC); + if (!zend_is_true(transaction_level)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "There is no active transaction"); + return; + } + + if (PHALCON_IS_LONG(transaction_level, 1)) { + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "db:commitTransaction", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } + + phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); + phalcon_call_method_key(return_value, pdo, "commit", 3546528686UL); + RETURN_MM(); + } else { + if (zend_is_true(transaction_level)) { + if (zend_is_true(nesting)) { + + PHALCON_INIT_VAR(ntw_savepoint); + phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); + if (zend_is_true(ntw_savepoint)) { + + PHALCON_OBS_NVAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(savepoint_name); + phalcon_call_method_key(savepoint_name, this_ptr, "getnestedtransactionsavepointname", 1903082728UL); + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "db:releaseSavepoint", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, savepoint_name, 259017035UL); + } + + phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); + phalcon_call_method_p1_key(return_value, this_ptr, "releasesavepoint", savepoint_name, 3823765247UL); + RETURN_MM(); + } + } + } + } + + if (PHALCON_GT_LONG(transaction_level, 0)) { + phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); + } + + RETURN_MM_FALSE; } +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, getTransactionLevel){ + RETURN_MEMBER_QUICK(this_ptr, "_transactionLevel", 2789346594UL); +} +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, isUnderTransaction){ -#ifdef HAVE_CONFIG_H -#endif - - + zval *pdo; + PHALCON_MM_GROW(); + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + if (likely(Z_TYPE_P(pdo) == IS_OBJECT)) { + phalcon_call_method_key(return_value, pdo, "intransaction", 3613210146UL); + RETURN_MM(); + } + + RETURN_MM_FALSE; +} +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, getInternalHandler){ -PHALCON_INIT_CLASS(Phalcon_DI_Exception){ + zval *pdo; - PHALCON_REGISTER_CLASS_EX(Phalcon\\DI, Exception, di_exception, "phalcon\\exception", NULL, 0); + PHALCON_MM_GROW(); - return SUCCESS; + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + RETURN_CCTOR(pdo); } @@ -26753,1137 +26121,1443 @@ PHALCON_INIT_CLASS(Phalcon_DI_Exception){ -PHALCON_INIT_CLASS(Phalcon_Events_ManagerInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Events, ManagerInterface, events_managerinterface, phalcon_events_managerinterface_method_entry); - - return SUCCESS; -} - - - - +PHALCON_INIT_CLASS(Phalcon_Db_Adapter){ -#ifdef HAVE_CONFIG_H -#endif + PHALCON_REGISTER_CLASS(Phalcon\\Db, Adapter, db_adapter, phalcon_db_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + zend_declare_property_null(phalcon_db_adapter_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_adapter_ce, SL("_descriptor"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_adapter_ce, SL("_dialectType"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_adapter_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_adapter_ce, SL("_dialect"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_adapter_ce, SL("_connectionId"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_adapter_ce, SL("_sqlStatement"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_adapter_ce, SL("_sqlVariables"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_adapter_ce, SL("_sqlBindTypes"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_db_adapter_ce, SL("_transactionLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_db_adapter_ce, SL("_transactionsWithSavepoints"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_db_adapter_ce, SL("_connectionConsecutive"), 0, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + zend_class_implements(phalcon_db_adapter_ce TSRMLS_CC, 1, phalcon_events_eventsawareinterface_ce); + return SUCCESS; +} +static PHP_METHOD(Phalcon_Db_Adapter, __construct){ + zval *descriptor, *one, *connection_consecutive; + zval *next_consecutive, *dialect_type, *dialect_class = NULL; + zval *dialect_object; + zend_class_entry *ce0; + PHALCON_MM_GROW(); -PHALCON_INIT_CLASS(Phalcon_Events_Manager){ - - PHALCON_REGISTER_CLASS(Phalcon\\Events, Manager, events_manager, phalcon_events_manager_method_entry, 0); - - zend_declare_property_null(phalcon_events_manager_ce, SL("_events"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_events_manager_ce, SL("_collect"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_events_manager_ce, SL("_enablePriorities"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_events_manager_ce, SL("_responses"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_events_manager_ce TSRMLS_CC, 1, phalcon_events_managerinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Events_Manager, attach){ - - zval *event_type, *handler, *priority = NULL, *events = NULL; - zval *enable_priorities, *priority_queue = NULL; - zval *mode; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &event_type, &handler, &priority); - - if (!priority) { - PHALCON_INIT_VAR(priority); - ZVAL_LONG(priority, 100); - } - - if (unlikely(Z_TYPE_P(event_type) != IS_STRING)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event type must be a string"); - return; - } - if (unlikely(Z_TYPE_P(handler) != IS_OBJECT)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event handler must be an Object"); - return; - } - - PHALCON_OBS_VAR(events); - phalcon_read_property_this_quick(&events, this_ptr, SL("_events"), 2709386425UL, PH_NOISY_CC); - if (Z_TYPE_P(events) != IS_ARRAY) { - PHALCON_INIT_NVAR(events); - array_init(events); - } + phalcon_fetch_params(1, 1, 0, &descriptor); - if (!phalcon_array_isset(events, event_type)) { + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); - PHALCON_OBS_VAR(enable_priorities); - phalcon_read_property_this_quick(&enable_priorities, this_ptr, SL("_enablePriorities"), 914030005UL, PH_NOISY_CC); - if (zend_is_true(enable_priorities)) { - PHALCON_INIT_VAR(priority_queue); - object_init_ex(priority_queue, spl_ce_SplPriorityQueue); - if (phalcon_has_constructor(priority_queue TSRMLS_CC)) { - phalcon_call_method_key(NULL, priority_queue, "__construct", 1107214344UL); - } + PHALCON_OBS_VAR(connection_consecutive); + phalcon_read_static_property(&connection_consecutive, SL("phalcon\\db\\adapter"), SL("_connectionConsecutive") TSRMLS_CC); - PHALCON_INIT_VAR(mode); - ZVAL_LONG(mode, 1); + PHALCON_INIT_VAR(next_consecutive); + phalcon_add_function(next_consecutive, connection_consecutive, one TSRMLS_CC); + phalcon_update_static_property(SL("phalcon\\db\\adapter"), SL("_connectionConsecutive"), next_consecutive TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_connectionId"), connection_consecutive, 802624385UL TSRMLS_CC); - phalcon_call_method_p1_key(NULL, priority_queue, "setextractflags", mode, 1392794841UL); + if (!phalcon_array_isset_quick_string(descriptor, SS("dialectClass"), 2526466321UL)) { + PHALCON_OBS_VAR(dialect_type); + phalcon_read_property_this_quick(&dialect_type, this_ptr, SL("_dialectType"), 1868597628UL, PH_NOISY_CC); - phalcon_array_update_zval(&events, event_type, &priority_queue, PH_COPY | PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_events"), events, 2709386425UL TSRMLS_CC); - } else { - PHALCON_INIT_NVAR(priority_queue); - array_init(priority_queue); - } + PHALCON_INIT_VAR(dialect_class); + PHALCON_CONCAT_SV(dialect_class, "phalcon\\db\\dialect\\", dialect_type); } else { - PHALCON_OBS_NVAR(priority_queue); - phalcon_array_fetch(&priority_queue, events, event_type, PH_NOISY); + PHALCON_OBS_NVAR(dialect_class); + phalcon_array_fetch_quick_string(&dialect_class, descriptor, SS("dialectClass"), 2526466321UL, PH_NOISY); } - if (unlikely(Z_TYPE_P(priority_queue) == IS_OBJECT)) { - phalcon_call_method_p2_key(NULL, priority_queue, "insert", handler, priority, 2673104346UL); - } else { - phalcon_array_append(&priority_queue, handler, PH_SEPARATE); - - phalcon_array_update_zval(&events, event_type, &priority_queue, PH_COPY | PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_events"), events, 2709386425UL TSRMLS_CC); + if (likely(Z_TYPE_P(dialect_class) == IS_STRING)) { + ce0 = phalcon_fetch_class(dialect_class TSRMLS_CC); + PHALCON_INIT_VAR(dialect_object); + object_init_ex(dialect_object, ce0); + if (phalcon_has_constructor(dialect_object TSRMLS_CC)) { + phalcon_call_method_key(NULL, dialect_object, "__construct", 1107214344UL); + } + phalcon_update_property_this_quick(this_ptr, SL("_dialect"), dialect_object, 4072955610UL TSRMLS_CC); } + phalcon_update_property_this_quick(this_ptr, SL("_descriptor"), descriptor, 691635363UL TSRMLS_CC); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Events_Manager, enablePriorities){ +static PHP_METHOD(Phalcon_Db_Adapter, setEventsManager){ - zval *enable_priorities; + zval *events_manager; - phalcon_fetch_params(0, 1, 0, &enable_priorities); + phalcon_fetch_params(0, 1, 0, &events_manager); - phalcon_update_property_this_quick(this_ptr, SL("_enablePriorities"), enable_priorities, 914030005UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); } -static PHP_METHOD(Phalcon_Events_Manager, arePrioritiesEnabled){ +static PHP_METHOD(Phalcon_Db_Adapter, getEventsManager){ - RETURN_MEMBER_QUICK(this_ptr, "_enablePriorities", 914030005UL); + RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); } -static PHP_METHOD(Phalcon_Events_Manager, collectResponses){ +static PHP_METHOD(Phalcon_Db_Adapter, setDialect){ - zval *collect; + zval *dialect; - phalcon_fetch_params(0, 1, 0, &collect); + phalcon_fetch_params(0, 1, 0, &dialect); - phalcon_update_property_this_quick(this_ptr, SL("_collect"), collect, 3993548138UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_dialect"), dialect, 4072955610UL TSRMLS_CC); } -static PHP_METHOD(Phalcon_Events_Manager, isCollecting){ - - - RETURN_MEMBER_QUICK(this_ptr, "_collect", 3993548138UL); -} - -static PHP_METHOD(Phalcon_Events_Manager, getResponses){ +static PHP_METHOD(Phalcon_Db_Adapter, getDialect){ - RETURN_MEMBER_QUICK(this_ptr, "_responses", 77555686UL); + RETURN_MEMBER_QUICK(this_ptr, "_dialect", 4072955610UL); } -static PHP_METHOD(Phalcon_Events_Manager, dettachAll){ +static PHP_METHOD(Phalcon_Db_Adapter, fetchOne){ - zval *type = NULL, *events = NULL, *null_value; + zval *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL; + zval *result; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &type); + phalcon_fetch_params(1, 1, 3, &sql_query, &fetch_mode, &bind_params, &bind_types); - if (!type) { - PHALCON_INIT_VAR(type); + if (!fetch_mode) { + PHALCON_INIT_VAR(fetch_mode); + ZVAL_LONG(fetch_mode, 2); } - PHALCON_OBS_VAR(events); - phalcon_read_property_this_quick(&events, this_ptr, SL("_events"), 2709386425UL, PH_NOISY_CC); - if (Z_TYPE_P(type) == IS_NULL) { - PHALCON_INIT_NVAR(events); - } else { - if (phalcon_array_isset(events, type)) { - PHALCON_INIT_VAR(null_value); - phalcon_array_update_zval(&events, type, &null_value, PH_COPY | PH_SEPARATE); - } + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); } - phalcon_update_property_this_quick(this_ptr, SL("_events"), events, 2709386425UL TSRMLS_CC); + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(result); + phalcon_call_method_p3_key(result, this_ptr, "query", sql_query, bind_params, bind_types, 401898907UL); + if (Z_TYPE_P(result) == IS_OBJECT) { + if (Z_TYPE_P(fetch_mode) != IS_NULL) { + phalcon_call_method_p1_key(NULL, result, "setfetchmode", fetch_mode, 824603840UL); + } + phalcon_call_method_key(return_value, result, "fetch", 4247924303UL); + RETURN_MM(); + } + + RETURN_MM_EMPTY_ARRAY(); } -static PHP_METHOD(Phalcon_Events_Manager, fireQueue){ +static PHP_METHOD(Phalcon_Db_Adapter, fetchAll){ - zval *queue, *event, *status = NULL, *arguments = NULL, *event_name; - zval *source, *data, *cancelable, *collect, *iterator; - zval *handler = NULL, *is_stopped = NULL; + zval *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL; + zval *results, *result, *row = NULL; zval *r0 = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &queue, &event); + phalcon_fetch_params(1, 1, 3, &sql_query, &fetch_mode, &bind_params, &bind_types); - if (unlikely(Z_TYPE_P(queue) != IS_ARRAY)) { - if (Z_TYPE_P(queue) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The SplPriorityQueue is not valid"); - return; - } - } - if (unlikely(Z_TYPE_P(event) != IS_OBJECT)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The event is not valid"); - return; + if (!fetch_mode) { + PHALCON_INIT_VAR(fetch_mode); + ZVAL_LONG(fetch_mode, 2); } - PHALCON_INIT_VAR(status); - - PHALCON_INIT_VAR(arguments); - - PHALCON_INIT_VAR(event_name); - phalcon_call_method_key(event_name, event, "gettype", 4294422375UL); - if (unlikely(Z_TYPE_P(event_name) != IS_STRING)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The event type not valid"); - return; + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); } - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, event, "getsource", 2025234358UL); - - PHALCON_INIT_VAR(data); - phalcon_call_method_key(data, event, "getdata", 4274589375UL); - - PHALCON_INIT_VAR(cancelable); - phalcon_call_method_key(cancelable, event, "getcancelable", 1233464063UL); + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } - PHALCON_OBS_VAR(collect); - phalcon_read_property_this_quick(&collect, this_ptr, SL("_collect"), 3993548138UL, PH_NOISY_CC); - if (Z_TYPE_P(queue) == IS_OBJECT) { + PHALCON_INIT_VAR(results); + array_init(results); - PHALCON_INIT_VAR(iterator); - if (phalcon_clone(iterator, queue TSRMLS_CC) == FAILURE) { - return; + PHALCON_INIT_VAR(result); + phalcon_call_method_p3_key(result, this_ptr, "query", sql_query, bind_params, bind_types, 401898907UL); + if (likely(Z_TYPE_P(result) == IS_OBJECT)) { + if (Z_TYPE_P(fetch_mode) != IS_NULL) { + phalcon_call_method_p1_key(NULL, result, "setfetchmode", fetch_mode, 824603840UL); } - phalcon_call_method_key(NULL, iterator, "top", 2090766872UL); - while (1) { PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, iterator, "valid", 574098517UL); - if (zend_is_true(r0)) { + phalcon_call_method_key(r0, result, "fetch", 4247924303UL); + PHALCON_CPY_WRT(row, r0); + if (zend_is_true(row)) { } else { break; } - PHALCON_INIT_NVAR(handler); - phalcon_call_method_key(handler, iterator, "current", 431662984UL); + phalcon_array_append(&results, row, PH_SEPARATE); + } + } - if (likely(Z_TYPE_P(handler) == IS_OBJECT)) { + RETURN_CTOR(results); +} + +static PHP_METHOD(Phalcon_Db_Adapter, insert){ + + zval *table, *values, *fields = NULL, *data_types = NULL, *exception_message; + zval *placeholders, *insert_values, *bind_data_types = NULL; + zval *value = NULL, *position = NULL, *str_value = NULL, *bind_type = NULL; + zval *escaped_table = NULL, *joined_values, *escaped_fields = NULL; + zval *field = NULL, *escaped_field = NULL, *joined_fields; + zval *insert_sql = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 2, &table, &values, &fields, &data_types); - if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) { + if (!fields) { + PHALCON_INIT_VAR(fields); + } - if (Z_TYPE_P(arguments) == IS_NULL) { - PHALCON_INIT_NVAR(arguments); - array_init_size(arguments, 3); - phalcon_array_append(&arguments, event, PH_SEPARATE); - phalcon_array_append(&arguments, source, PH_SEPARATE); - phalcon_array_append(&arguments, data, PH_SEPARATE); - } + if (!data_types) { + PHALCON_INIT_VAR(data_types); + } - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments); + if (unlikely(Z_TYPE_P(values) != IS_ARRAY)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The second parameter for insert isn't an Array"); + return; + } - if (zend_is_true(collect)) { - phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); - } + if (!phalcon_fast_count_ev(values TSRMLS_CC)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Unable to insert into ", table, " without data"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_db_exception_ce, exception_message); + return; + } - if (zend_is_true(cancelable)) { + PHALCON_INIT_VAR(placeholders); + array_init(placeholders); - PHALCON_INIT_NVAR(is_stopped); - phalcon_call_method_key(is_stopped, event, "isstopped", 1073138944UL); - if (zend_is_true(is_stopped)) { - break; - } - } - } else { - if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_VAR(insert_values); + array_init(insert_values); + if (Z_TYPE_P(data_types) == IS_ARRAY) { + PHALCON_INIT_VAR(bind_data_types); + array_init(bind_data_types); + } else { + PHALCON_CPY_WRT(bind_data_types, data_types); + } - PHALCON_INIT_NVAR(status); - phalcon_call_method_zval_p3(status, handler, event_name, event, source, data); + phalcon_is_iterable(values, &ah0, &hp0, 0, 0); - if (zend_is_true(collect)) { - phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (zend_is_true(cancelable)) { + PHALCON_GET_HKEY(position, ah0, hp0); + PHALCON_GET_HVALUE(value); - PHALCON_INIT_NVAR(is_stopped); - phalcon_call_method_key(is_stopped, event, "isstopped", 1073138944UL); - if (zend_is_true(is_stopped)) { - break; - } - } + if (Z_TYPE_P(value) == IS_OBJECT) { + PHALCON_INIT_NVAR(str_value); + phalcon_call_func_p1(str_value, "strval", value); + phalcon_array_append(&placeholders, str_value, PH_SEPARATE); + } else { + if (Z_TYPE_P(value) == IS_NULL) { + phalcon_array_append_string(&placeholders, SL("null"), PH_SEPARATE); + } else { + phalcon_array_append_string(&placeholders, SL("?"), PH_SEPARATE); + phalcon_array_append(&insert_values, value, PH_SEPARATE); + if (Z_TYPE_P(data_types) == IS_ARRAY) { + if (!phalcon_array_isset(data_types, position)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Incomplete number of bind types"); + return; } + + PHALCON_OBS_NVAR(bind_type); + phalcon_array_fetch(&bind_type, data_types, position, PH_NOISY); + phalcon_array_append(&bind_data_types, bind_type, PH_SEPARATE); } } - - phalcon_call_method_key(NULL, iterator, "next", 268367684UL); } - } else { - - phalcon_is_iterable(queue, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(handler); - - if (likely(Z_TYPE_P(handler) == IS_OBJECT)) { - - if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) { - if (Z_TYPE_P(arguments) == IS_NULL) { - PHALCON_INIT_NVAR(arguments); - array_init_size(arguments, 3); - phalcon_array_append(&arguments, event, PH_SEPARATE); - phalcon_array_append(&arguments, source, PH_SEPARATE); - phalcon_array_append(&arguments, data, PH_SEPARATE); - } + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments); + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(escaped_table); + phalcon_call_method_p1_key(escaped_table, this_ptr, "escapeidentifier", table, 585773337UL); + } else { + PHALCON_CPY_WRT(escaped_table, table); + } - if (zend_is_true(collect)) { - phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); - } + PHALCON_INIT_VAR(joined_values); + phalcon_fast_join_str(joined_values, SL(", "), placeholders TSRMLS_CC); + if (Z_TYPE_P(fields) == IS_ARRAY) { + if (PHALCON_GLOBAL(db).escape_identifiers) { - if (zend_is_true(cancelable)) { + PHALCON_INIT_VAR(escaped_fields); + array_init(escaped_fields); - PHALCON_INIT_NVAR(is_stopped); - phalcon_call_method_key(is_stopped, event, "isstopped", 1073138944UL); - if (zend_is_true(is_stopped)) { - break; - } - } - } else { - if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { + phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); - PHALCON_INIT_NVAR(status); - phalcon_call_method_zval_p3(status, handler, event_name, event, source, data); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - if (zend_is_true(collect)) { - phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); - } + PHALCON_GET_HVALUE(field); - if (zend_is_true(cancelable)) { + PHALCON_INIT_NVAR(escaped_field); + phalcon_call_method_p1_key(escaped_field, this_ptr, "escapeidentifier", field, 585773337UL); + phalcon_array_append(&escaped_fields, escaped_field, PH_SEPARATE); - PHALCON_INIT_NVAR(is_stopped); - phalcon_call_method_key(is_stopped, event, "isstopped", 1073138944UL); - if (zend_is_true(is_stopped)) { - break; - } - } - } - } + zend_hash_move_forward_ex(ah1, &hp1); } - zend_hash_move_forward_ex(ah0, &hp0); + } else { + PHALCON_CPY_WRT(escaped_fields, fields); } + PHALCON_INIT_VAR(joined_fields); + phalcon_fast_join_str(joined_fields, SL(", "), escaped_fields TSRMLS_CC); + + PHALCON_INIT_VAR(insert_sql); + PHALCON_CONCAT_SVSVSVS(insert_sql, "INSERT INTO ", escaped_table, " (", joined_fields, ") VALUES (", joined_values, ")"); + } else { + PHALCON_INIT_NVAR(insert_sql); + PHALCON_CONCAT_SVSVS(insert_sql, "INSERT INTO ", escaped_table, " VALUES (", joined_values, ")"); } - RETURN_CCTOR(status); + phalcon_call_method_p3_key(return_value, this_ptr, "execute", insert_sql, insert_values, bind_data_types, 3117639032UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Events_Manager, fire){ +static PHP_METHOD(Phalcon_Db_Adapter, update){ - zval *event_type, *source, *data = NULL, *cancelable = NULL, *events; - zval *exception_message, *event_parts, *type; - zval *event_name, *status = NULL, *collect, *event = NULL, *fire_events = NULL; + zval *table, *fields, *values, *where_condition = NULL; + zval *data_types = NULL, *placeholders, *update_values; + zval *bind_data_types = NULL, *value = NULL, *position = NULL, *field = NULL; + zval *escaped_field = NULL, *set_clause_part = NULL, *bind_type = NULL; + zval *escaped_table = NULL, *set_clause, *update_sql = NULL; + zval *conditions, *where_bind, *where_types; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 2, &event_type, &source, &data, &cancelable); - - if (!data) { - PHALCON_INIT_VAR(data); - } - - if (!cancelable) { - PHALCON_INIT_VAR(cancelable); - ZVAL_BOOL(cancelable, 1); - } - - if (unlikely(Z_TYPE_P(event_type) != IS_STRING)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event type must be a string"); - return; - } + phalcon_fetch_params(1, 3, 2, &table, &fields, &values, &where_condition, &data_types); - PHALCON_OBS_VAR(events); - phalcon_read_property_this_quick(&events, this_ptr, SL("_events"), 2709386425UL, PH_NOISY_CC); - if (Z_TYPE_P(events) != IS_ARRAY) { - RETURN_MM_NULL(); + if (!where_condition) { + PHALCON_INIT_VAR(where_condition); } - if (!phalcon_memnstr_str(event_type, SL(":"))) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Invalid event type ", event_type); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_events_exception_ce, exception_message); - return; + if (!data_types) { + PHALCON_INIT_VAR(data_types); } - PHALCON_INIT_VAR(event_parts); - phalcon_fast_explode_str(event_parts, SL(":"), event_type); - - PHALCON_OBS_VAR(type); - phalcon_array_fetch_long(&type, event_parts, 0, PH_NOISY); - - PHALCON_OBS_VAR(event_name); - phalcon_array_fetch_long(&event_name, event_parts, 1, PH_NOISY); - - PHALCON_INIT_VAR(status); + PHALCON_INIT_VAR(placeholders); + array_init(placeholders); - PHALCON_OBS_VAR(collect); - phalcon_read_property_this_quick(&collect, this_ptr, SL("_collect"), 3993548138UL, PH_NOISY_CC); - if (zend_is_true(collect)) { - phalcon_update_property_null(this_ptr, SL("_responses") TSRMLS_CC); + PHALCON_INIT_VAR(update_values); + array_init(update_values); + if (Z_TYPE_P(data_types) == IS_ARRAY) { + PHALCON_INIT_VAR(bind_data_types); + array_init(bind_data_types); + } else { + PHALCON_CPY_WRT(bind_data_types, data_types); } - PHALCON_INIT_VAR(event); + phalcon_is_iterable(values, &ah0, &hp0, 0, 0); - if (phalcon_array_isset(events, type)) { + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_OBS_VAR(fire_events); - phalcon_array_fetch(&fire_events, events, type, PH_NOISY); - if (Z_TYPE_P(fire_events) == IS_ARRAY || Z_TYPE_P(fire_events) == IS_OBJECT) { - object_init_ex(event, phalcon_events_event_ce); - phalcon_call_method_p4_key(NULL, event, "__construct", event_name, source, data, cancelable, 1107214344UL); + PHALCON_GET_HKEY(position, ah0, hp0); + PHALCON_GET_HVALUE(value); - phalcon_call_method_p2_key(status, this_ptr, "firequeue", fire_events, event, 1024348976UL); + if (!phalcon_array_isset(fields, position)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The number of values in the update is not the same as fields"); + return; } - } - if (phalcon_array_isset(events, event_type)) { + PHALCON_OBS_NVAR(field); + phalcon_array_fetch(&field, fields, position, PH_NOISY); + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_NVAR(escaped_field); + phalcon_call_method_p1_key(escaped_field, this_ptr, "escapeidentifier", field, 585773337UL); + } else { + PHALCON_CPY_WRT(escaped_field, field); + } - PHALCON_OBS_NVAR(fire_events); - phalcon_array_fetch(&fire_events, events, event_type, PH_NOISY); - if (Z_TYPE_P(fire_events) == IS_ARRAY || Z_TYPE_P(fire_events) == IS_OBJECT) { + if (Z_TYPE_P(value) == IS_OBJECT) { + PHALCON_INIT_NVAR(set_clause_part); + PHALCON_CONCAT_VSV(set_clause_part, escaped_field, " = ", value); + phalcon_array_append(&placeholders, set_clause_part, PH_SEPARATE); + } else { + if (Z_TYPE_P(value) == IS_NULL) { + PHALCON_INIT_NVAR(set_clause_part); + PHALCON_CONCAT_VS(set_clause_part, escaped_field, " = null"); + } else { + PHALCON_INIT_NVAR(set_clause_part); + PHALCON_CONCAT_VS(set_clause_part, escaped_field, " = ?"); + phalcon_array_append(&update_values, value, PH_SEPARATE); + if (Z_TYPE_P(data_types) == IS_ARRAY) { + if (!phalcon_array_isset(data_types, position)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Incomplete number of bind types"); + return; + } - if (Z_TYPE_P(event) == IS_NULL) { - PHALCON_INIT_NVAR(event); - object_init_ex(event, phalcon_events_event_ce); - phalcon_call_method_p4_key(NULL, event, "__construct", event_name, source, data, cancelable, 1107214344UL); + PHALCON_OBS_NVAR(bind_type); + phalcon_array_fetch(&bind_type, data_types, position, PH_NOISY); + phalcon_array_append(&bind_data_types, bind_type, PH_SEPARATE); + } + } + phalcon_array_append(&placeholders, set_clause_part, PH_SEPARATE); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(escaped_table); + phalcon_call_method_p1_key(escaped_table, this_ptr, "escapeidentifier", table, 585773337UL); + } else { + PHALCON_CPY_WRT(escaped_table, table); + } + + PHALCON_INIT_VAR(set_clause); + phalcon_fast_join_str(set_clause, SL(", "), placeholders TSRMLS_CC); + if (Z_TYPE_P(where_condition) != IS_NULL) { + + PHALCON_INIT_VAR(update_sql); + PHALCON_CONCAT_SVSVS(update_sql, "UPDATE ", escaped_table, " SET ", set_clause, " WHERE "); + if (Z_TYPE_P(where_condition) == IS_STRING) { + phalcon_concat_self(&update_sql, where_condition TSRMLS_CC); + } else { + if (unlikely(Z_TYPE_P(where_condition) != IS_ARRAY)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid WHERE clause conditions"); + return; } - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, this_ptr, "firequeue", fire_events, event, 1024348976UL); + if (phalcon_array_isset_quick_string(where_condition, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_VAR(conditions); + phalcon_array_fetch_quick_string(&conditions, where_condition, SS("conditions"), 1055696255UL, PH_NOISY); + phalcon_concat_self(&update_sql, conditions TSRMLS_CC); + } + + if (phalcon_array_isset_quick_string(where_condition, SS("bind"), 254268962UL)) { + PHALCON_OBS_VAR(where_bind); + phalcon_array_fetch_quick_string(&where_bind, where_condition, SS("bind"), 254268962UL, PH_NOISY); + phalcon_merge_append(update_values, where_bind); + } + + if (phalcon_array_isset_quick_string(where_condition, SS("bindTypes"), 3951758359UL)) { + PHALCON_OBS_VAR(where_types); + phalcon_array_fetch_quick_string(&where_types, where_condition, SS("bindTypes"), 3951758359UL, PH_NOISY); + phalcon_merge_append(bind_data_types, where_types); + } } + } else { + PHALCON_INIT_NVAR(update_sql); + PHALCON_CONCAT_SVSV(update_sql, "UPDATE ", escaped_table, " SET ", set_clause); } - RETURN_CCTOR(status); + phalcon_call_method_p3_key(return_value, this_ptr, "execute", update_sql, update_values, bind_data_types, 3117639032UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Events_Manager, hasListeners){ +static PHP_METHOD(Phalcon_Db_Adapter, delete){ - zval *type, *events; + zval *table, *where_condition = NULL, *placeholders = NULL; + zval *data_types = NULL, *escaped_table = NULL, *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &type); + phalcon_fetch_params(1, 1, 3, &table, &where_condition, &placeholders, &data_types); - PHALCON_OBS_VAR(events); - phalcon_read_property_this_quick(&events, this_ptr, SL("_events"), 2709386425UL, PH_NOISY_CC); - if (Z_TYPE_P(events) == IS_ARRAY) { - if (phalcon_array_isset(events, type)) { - RETURN_MM_TRUE; - } + if (!where_condition) { + PHALCON_INIT_VAR(where_condition); } - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Events_Manager, getListeners){ - - zval *type, *events, *fire_events; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &type); + if (!placeholders) { + PHALCON_INIT_VAR(placeholders); + } - PHALCON_OBS_VAR(events); - phalcon_read_property_this_quick(&events, this_ptr, SL("_events"), 2709386425UL, PH_NOISY_CC); - if (Z_TYPE_P(events) == IS_ARRAY) { - if (phalcon_array_isset(events, type)) { - PHALCON_OBS_VAR(fire_events); - phalcon_array_fetch(&fire_events, events, type, PH_NOISY); - RETURN_CCTOR(fire_events); - } + if (!data_types) { + PHALCON_INIT_VAR(data_types); } - RETURN_MM_EMPTY_ARRAY(); + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(escaped_table); + phalcon_call_method_p1_key(escaped_table, this_ptr, "escapeidentifier", table, 585773337UL); + } else { + PHALCON_CPY_WRT(escaped_table, table); + } + if (PHALCON_IS_NOT_EMPTY(where_condition)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "DELETE FROM ", escaped_table, " WHERE ", where_condition); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SV(sql, "DELETE FROM ", escaped_table); + } + + phalcon_call_method_p3_key(return_value, this_ptr, "execute", sql, placeholders, data_types, 3117639032UL); + RETURN_MM(); } +static PHP_METHOD(Phalcon_Db_Adapter, getColumnList){ + zval *column_list, *dialect; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &column_list); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, dialect, "getcolumnlist", column_list, 2735238095UL); + RETURN_MM(); +} -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Events_Event){ +static PHP_METHOD(Phalcon_Db_Adapter, limit){ - PHALCON_REGISTER_CLASS(Phalcon\\Events, Event, events_event, phalcon_events_event_method_entry, 0); + zval *sql_query, *number, *dialect; - zend_declare_property_null(phalcon_events_event_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_events_event_ce, SL("_source"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_events_event_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_events_event_ce, SL("_stopped"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_events_event_ce, SL("_cancelable"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 2, 0, &sql_query, &number); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + phalcon_call_method_p2_key(return_value, dialect, "limit", sql_query, number, 192268420UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Events_Event, __construct){ +static PHP_METHOD(Phalcon_Db_Adapter, tableExists){ - zval *type, *source, *data = NULL, *cancelable = NULL; + zval *table_name, *schema_name = NULL, *dialect, *sql; + zval *fetch_num, *num, *first; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 2, &type, &source, &data, &cancelable); + phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - if (!data) { - PHALCON_INIT_VAR(data); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - if (!cancelable) { - PHALCON_INIT_VAR(cancelable); - ZVAL_BOOL(cancelable, 1); - } + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_source"), source, 3355220565UL TSRMLS_CC); - if (Z_TYPE_P(data) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC); - } + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "tableexists", table_name, schema_name, 1944065613UL); - if (PHALCON_IS_NOT_TRUE(cancelable)) { - phalcon_update_property_this_quick(this_ptr, SL("_cancelable"), cancelable, 1786076446UL TSRMLS_CC); - } + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(num); + phalcon_call_method_p2_key(num, this_ptr, "fetchone", sql, fetch_num, 1637187313UL); + + PHALCON_OBS_VAR(first); + phalcon_array_fetch_long(&first, num, 0, PH_NOISY); + RETURN_CCTOR(first); } -static PHP_METHOD(Phalcon_Events_Event, setType){ +static PHP_METHOD(Phalcon_Db_Adapter, viewExists){ - zval *event_type; + zval *view_name, *schema_name = NULL, *dialect, *sql, *fetch_num; + zval *num, *first; - phalcon_fetch_params(0, 1, 0, &event_type); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - phalcon_update_property_this_quick(this_ptr, SL("_type"), event_type, 3991959110UL TSRMLS_CC); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "viewexists", view_name, schema_name, 1384087744UL); + + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); + PHALCON_INIT_VAR(num); + phalcon_call_method_p2_key(num, this_ptr, "fetchone", sql, fetch_num, 1637187313UL); + + PHALCON_OBS_VAR(first); + phalcon_array_fetch_long(&first, num, 0, PH_NOISY); + RETURN_CCTOR(first); } -static PHP_METHOD(Phalcon_Events_Event, getType){ +static PHP_METHOD(Phalcon_Db_Adapter, forUpdate){ + zval *sql_query, *dialect; - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &sql_query); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, dialect, "forupdate", sql_query, 3289499215UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Events_Event, getSource){ +static PHP_METHOD(Phalcon_Db_Adapter, sharedLock){ + zval *sql_query, *dialect; - RETURN_MEMBER_QUICK(this_ptr, "_source", 3355220565UL); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &sql_query); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, dialect, "sharedlock", sql_query, 548439429UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Events_Event, setData){ +static PHP_METHOD(Phalcon_Db_Adapter, createTable){ - zval *data; + zval *table_name, *schema_name, *definition; + zval *exception_message, *columns, *dialect; + zval *sql; - phalcon_fetch_params(0, 1, 0, &data); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &definition); - phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC); + if (Z_TYPE_P(definition) != IS_ARRAY) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Invalid definition to create the table '", table_name, "'"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_db_exception_ce, exception_message); + return; + } + if (!phalcon_array_isset_quick_string(definition, SS("columns"), 1041822630UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); + return; + } + + PHALCON_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); + if (!phalcon_fast_count_ev(columns TSRMLS_CC)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); + return; + } + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "createtable", table_name, schema_name, definition, 3885129953UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Events_Event, getData){ - - - RETURN_MEMBER_QUICK(this_ptr, "_data", 3972126110UL); -} +static PHP_METHOD(Phalcon_Db_Adapter, dropTable){ -static PHP_METHOD(Phalcon_Events_Event, setCancelable){ + zval *table_name, *schema_name = NULL, *if_exists = NULL, *dialect; + zval *sql; - zval *cancelable; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &cancelable); + phalcon_fetch_params(1, 1, 2, &table_name, &schema_name, &if_exists); - phalcon_update_property_this_quick(this_ptr, SL("_cancelable"), cancelable, 1786076446UL TSRMLS_CC); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); + } + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "droptable", table_name, schema_name, if_exists, 3706194946UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Events_Event, getCancelable){ +static PHP_METHOD(Phalcon_Db_Adapter, createView){ + zval *view_name, *definition, *schema_name = NULL, *exception_message; + zval *dialect, *sql; - RETURN_MEMBER_QUICK(this_ptr, "_cancelable", 1786076446UL); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 1, &view_name, &definition, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + if (Z_TYPE_P(definition) != IS_ARRAY) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Invalid definition to create the view '", view_name, "'"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_db_exception_ce, exception_message); + return; + } + if (!phalcon_array_isset_quick_string(definition, SS("sql"), 2090732981UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); + return; + } + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "createview", view_name, definition, schema_name, 2593254036UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Events_Event, stop){ +static PHP_METHOD(Phalcon_Db_Adapter, dropView){ - zval *cancelable; + zval *view_name, *schema_name = NULL, *if_exists = NULL, *dialect; + zval *sql; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(cancelable); - phalcon_read_property_this_quick(&cancelable, this_ptr, SL("_cancelable"), 1786076446UL, PH_NOISY_CC); - if (zend_is_true(cancelable)) { - phalcon_update_property_bool(this_ptr, SL("_stopped"), 1 TSRMLS_CC); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Trying to cancel a non-cancelable event"); - return; + phalcon_fetch_params(1, 1, 2, &view_name, &schema_name, &if_exists); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - PHALCON_MM_RESTORE(); + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); + } + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "dropview", view_name, schema_name, if_exists, 375272853UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Events_Event, isStopped){ - +static PHP_METHOD(Phalcon_Db_Adapter, addColumn){ - RETURN_MEMBER_QUICK(this_ptr, "_stopped", 978787779UL); -} + zval *table_name, *schema_name, *column, *dialect; + zval *sql; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "addcolumn", table_name, schema_name, column, 1469620764UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Db_Adapter, modifyColumn){ + zval *table_name, *schema_name, *column, *dialect; + zval *sql; -#ifdef HAVE_CONFIG_H -#endif + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "modifycolumn", table_name, schema_name, column, 382554075UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Db_Adapter, dropColumn){ -PHALCON_INIT_CLASS(Phalcon_Events_EventsAwareInterface){ + zval *table_name, *schema_name, *column_name; + zval *dialect, *sql; - PHALCON_REGISTER_INTERFACE(Phalcon\\Events, EventsAwareInterface, events_eventsawareinterface, phalcon_events_eventsawareinterface_method_entry); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column_name); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "dropcolumn", table_name, schema_name, column_name, 2125320424UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); } +static PHP_METHOD(Phalcon_Db_Adapter, addIndex){ + + zval *table_name, *schema_name, *index, *dialect; + zval *sql; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "addindex", table_name, schema_name, index, 1839662022UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Db_Adapter, dropIndex){ + zval *table_name, *schema_name, *index_name; + zval *dialect, *sql; + PHALCON_MM_GROW(); -#ifdef HAVE_CONFIG_H -#endif + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index_name); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "dropindex", table_name, schema_name, index_name, 3291187474UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Db_Adapter, addPrimaryKey){ + zval *table_name, *schema_name, *index, *dialect; + zval *sql; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "addprimarykey", table_name, schema_name, index, 1640564219UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Db_Adapter, dropPrimaryKey){ -PHALCON_INIT_CLASS(Phalcon_Events_Exception){ + zval *table_name, *schema_name, *dialect, *sql; - PHALCON_REGISTER_CLASS_EX(Phalcon\\Events, Exception, events_exception, "phalcon\\exception", NULL, 0); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 2, 0, &table_name, &schema_name); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "dropprimarykey", table_name, schema_name, 1513142983UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); } +static PHP_METHOD(Phalcon_Db_Adapter, addForeignKey){ + zval *table_name, *schema_name, *reference, *dialect; + zval *sql; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "addforeignkey", table_name, schema_name, reference, 599632289UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); +} -#ifdef HAVE_CONFIG_H -#endif +static PHP_METHOD(Phalcon_Db_Adapter, dropForeignKey){ + zval *table_name, *schema_name, *reference_name; + zval *dialect, *sql; + PHALCON_MM_GROW(); -PHALCON_INIT_CLASS(Phalcon_Assets_FilterInterface){ + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference_name); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p3_key(sql, dialect, "dropforeignkey", table_name, schema_name, reference_name, 472211053UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); +} - PHALCON_REGISTER_INTERFACE(Phalcon\\Assets, FilterInterface, assets_filterinterface, phalcon_assets_filterinterface_method_entry); +static PHP_METHOD(Phalcon_Db_Adapter, getColumnDefinition){ - return SUCCESS; -} + zval *column, *dialect; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &column); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, dialect, "getcolumndefinition", column, 1668305756UL); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Db_Adapter, listTables){ + zval *schema_name = NULL, *dialect, *sql, *fetch_num, *tables; + zval *all_tables, *table = NULL, *table_name = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + PHALCON_MM_GROW(); -#ifdef HAVE_CONFIG_H -#endif + phalcon_fetch_params(1, 0, 1, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p1_key(sql, dialect, "listtables", schema_name, 57229948UL); + + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); + + PHALCON_INIT_VAR(tables); + phalcon_call_method_p2_key(tables, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + + PHALCON_INIT_VAR(all_tables); + array_init(all_tables); + + phalcon_is_iterable(tables, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(table); + + PHALCON_OBS_NVAR(table_name); + phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY); + phalcon_array_append(&all_tables, table_name, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_CTOR(all_tables); +} +static PHP_METHOD(Phalcon_Db_Adapter, listViews){ + zval *schema_name = NULL, *dialect, *sql, *fetch_num, *tables; + zval *all_tables, *table = NULL, *table_name = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 0, 1, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p1_key(sql, dialect, "listviews", schema_name, 3473526159UL); + + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); + + PHALCON_INIT_VAR(tables); + phalcon_call_method_p2_key(tables, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + + PHALCON_INIT_VAR(all_tables); + array_init(all_tables); + + phalcon_is_iterable(tables, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(table); + + PHALCON_OBS_NVAR(table_name); + phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY); + phalcon_array_append(&all_tables, table_name, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_CTOR(all_tables); +} +static PHP_METHOD(Phalcon_Db_Adapter, describeIndexes){ -PHALCON_INIT_CLASS(Phalcon_Assets_Filters_None){ + zval *table, *schema = NULL, *dialect, *fetch_num, *sql, *describe; + zval *indexes, *index = NULL, *key_name = NULL, *empty_arr = NULL, *column_name = NULL; + zval *index_objects, *index_columns = NULL, *name = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; - PHALCON_REGISTER_CLASS(Phalcon\\Assets\\Filters, None, assets_filters_none, phalcon_assets_filters_none_method_entry, 0); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "describeindexes", table, schema, 689092630UL); + + PHALCON_INIT_VAR(describe); + phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + + PHALCON_INIT_VAR(indexes); + array_init(indexes); + + phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(index); + + PHALCON_OBS_NVAR(key_name); + phalcon_array_fetch_long(&key_name, index, 2, PH_NOISY); + if (!phalcon_array_isset(indexes, key_name)) { + PHALCON_INIT_NVAR(empty_arr); + array_init(empty_arr); + phalcon_array_update_zval(&indexes, key_name, &empty_arr, PH_COPY | PH_SEPARATE); + } + + PHALCON_OBS_NVAR(column_name); + phalcon_array_fetch_long(&column_name, index, 4, PH_NOISY); + phalcon_array_update_append_multi_2(&indexes, key_name, column_name, 0); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(index_objects); + array_init(index_objects); + + phalcon_is_iterable(indexes, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HKEY(name, ah1, hp1); + PHALCON_GET_HVALUE(index_columns); + + PHALCON_INIT_NVAR(index); + object_init_ex(index, phalcon_db_index_ce); + phalcon_call_method_p2_key(NULL, index, "__construct", name, index_columns, 1107214344UL); + + phalcon_array_update_zval(&index_objects, name, &index, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); + } + + RETURN_CTOR(index_objects); } -static PHP_METHOD(Phalcon_Assets_Filters_None, filter){ +static PHP_METHOD(Phalcon_Db_Adapter, describeReferences){ - zval *content; + zval *table, *schema = NULL, *dialect, *fetch_num, *sql, *empty_arr; + zval *references, *describe, *reference = NULL, *constraint_name = NULL; + zval *referenced_schema = NULL, *referenced_table = NULL; + zval *reference_array = NULL, *column_name = NULL, *referenced_columns = NULL; + zval *reference_objects, *array_reference = NULL; + zval *name = NULL, *columns = NULL, *definition = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; - phalcon_fetch_params(0, 1, 0, &content); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &table, &schema); - RETURN_CCTORW(content); + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "describereferences", table, schema, 1939869288UL); + + PHALCON_INIT_VAR(empty_arr); + array_init(empty_arr); + + PHALCON_INIT_VAR(references); + array_init(references); + + PHALCON_INIT_VAR(describe); + phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + + phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(reference); + + PHALCON_OBS_NVAR(constraint_name); + phalcon_array_fetch_long(&constraint_name, reference, 2, PH_NOISY); + if (!phalcon_array_isset(references, constraint_name)) { + PHALCON_OBS_NVAR(referenced_schema); + phalcon_array_fetch_long(&referenced_schema, reference, 3, PH_NOISY); + + PHALCON_OBS_NVAR(referenced_table); + phalcon_array_fetch_long(&referenced_table, reference, 4, PH_NOISY); + + PHALCON_INIT_NVAR(reference_array); + array_init_size(reference_array, 4); + phalcon_array_update_quick_string(&reference_array, SS("referencedSchema"), 3300645545UL, &referenced_schema, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&reference_array, SS("referencedTable"), 3390337856UL, &referenced_table, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&reference_array, SS("columns"), 1041822630UL, &empty_arr, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&reference_array, SS("referencedColumns"), 1045113721UL, &empty_arr, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&references, constraint_name, &reference_array, PH_COPY | PH_SEPARATE); + } + + PHALCON_OBS_NVAR(column_name); + phalcon_array_fetch_long(&column_name, reference, 1, PH_NOISY); + phalcon_array_update_zval_string_append_multi_3(&references, constraint_name, SL("columns"), &column_name, 0); + + PHALCON_OBS_NVAR(referenced_columns); + phalcon_array_fetch_long(&referenced_columns, reference, 5, PH_NOISY); + phalcon_array_update_zval_string_append_multi_3(&references, constraint_name, SL("referencedColumns"), &referenced_columns, 0); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(reference_objects); + array_init(reference_objects); + + phalcon_is_iterable(references, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HKEY(name, ah1, hp1); + PHALCON_GET_HVALUE(array_reference); + + PHALCON_OBS_NVAR(referenced_schema); + phalcon_array_fetch_quick_string(&referenced_schema, array_reference, SS("referencedSchema"), 3300645545UL, PH_NOISY); + + PHALCON_OBS_NVAR(referenced_table); + phalcon_array_fetch_quick_string(&referenced_table, array_reference, SS("referencedTable"), 3390337856UL, PH_NOISY); + + PHALCON_OBS_NVAR(columns); + phalcon_array_fetch_quick_string(&columns, array_reference, SS("columns"), 1041822630UL, PH_NOISY); + + PHALCON_OBS_NVAR(referenced_columns); + phalcon_array_fetch_quick_string(&referenced_columns, array_reference, SS("referencedColumns"), 1045113721UL, PH_NOISY); + + PHALCON_INIT_NVAR(definition); + array_init_size(definition, 4); + phalcon_array_update_quick_string(&definition, SS("referencedSchema"), 3300645545UL, &referenced_schema, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("referencedTable"), 3390337856UL, &referenced_table, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("columns"), 1041822630UL, &columns, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&definition, SS("referencedColumns"), 1045113721UL, &referenced_columns, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(reference); + object_init_ex(reference, phalcon_db_reference_ce); + phalcon_call_method_p2_key(NULL, reference, "__construct", name, definition, 1107214344UL); + + phalcon_array_update_zval(&reference_objects, name, &reference, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); + } + + RETURN_CTOR(reference_objects); } +static PHP_METHOD(Phalcon_Db_Adapter, tableOptions){ + zval *table_name, *schema_name = NULL, *dialect, *sql; + zval *fetch_assoc, *describe, *first; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "tableoptions", table_name, schema_name, 3683930169UL); + if (zend_is_true(sql)) { + PHALCON_INIT_VAR(fetch_assoc); + ZVAL_LONG(fetch_assoc, 1); + + PHALCON_INIT_VAR(describe); + phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_assoc, 1636682248UL); + + PHALCON_OBS_VAR(first); + phalcon_array_fetch_long(&first, describe, 0, PH_NOISY); + RETURN_CCTOR(first); + } + + RETURN_MM_EMPTY_ARRAY(); +} -#ifdef HAVE_CONFIG_H -#endif - - +static PHP_METHOD(Phalcon_Db_Adapter, createSavepoint){ + zval *name, *dialect, *supports_sp, *sql; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &name); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(supports_sp); + phalcon_call_method_key(supports_sp, dialect, "supportssavepoints", 1063347073UL); + if (!zend_is_true(supports_sp)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Savepoints are not supported by this database adapter."); + return; + } + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p1_key(sql, dialect, "createsavepoint", name, 2980652562UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Db_Adapter, releaseSavepoint){ -PHALCON_INIT_CLASS(Phalcon_Assets_Filters_Cssmin){ + zval *name, *dialect, *supports_sp, *supports_rsp; + zval *sql; - PHALCON_REGISTER_CLASS(Phalcon\\Assets\\Filters, Cssmin, assets_filters_cssmin, phalcon_assets_filters_cssmin_method_entry, 0); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 1, 0, &name); + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(supports_sp); + phalcon_call_method_key(supports_sp, dialect, "supportssavepoints", 1063347073UL); + if (!zend_is_true(supports_sp)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Savepoints are not supported by this database adapter"); + return; + } + + PHALCON_INIT_VAR(supports_rsp); + phalcon_call_method_key(supports_rsp, dialect, "supportsreleasesavepoints", 141567298UL); + if (!zend_is_true(supports_rsp)) { + RETURN_MM_FALSE; + } + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p1_key(sql, dialect, "releasesavepoint", name, 3823765247UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Assets_Filters_Cssmin, filter){ +static PHP_METHOD(Phalcon_Db_Adapter, rollbackSavepoint){ - zval *content; + zval *name, *dialect, *supports_sp, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &content); + phalcon_fetch_params(1, 1, 0, &name); - if (phalcon_cssmin(return_value, content TSRMLS_CC) == FAILURE) { + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(supports_sp); + phalcon_call_method_key(supports_sp, dialect, "supportssavepoints", 1063347073UL); + if (!zend_is_true(supports_sp)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Savepoints are not supported by this database adapter"); return; } + PHALCON_INIT_VAR(sql); + phalcon_call_method_p1_key(sql, dialect, "rollbacksavepoint", name, 3444395528UL); + phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); RETURN_MM(); } +static PHP_METHOD(Phalcon_Db_Adapter, setNestedTransactionsWithSavepoints){ + zval *nested_transactions_with_savepoints; + zval *transaction_level, *dialect, *supports_sp; -/* jsmin.c - 2013-03-29 + PHALCON_MM_GROW(); -Copyright (c) 2002 Douglas Crockford (www.crockford.com) + phalcon_fetch_params(1, 1, 0, &nested_transactions_with_savepoints); + + PHALCON_OBS_VAR(transaction_level); + phalcon_read_property_this_quick(&transaction_level, this_ptr, SL("_transactionLevel"), 2789346594UL, PH_NOISY_CC); + if (PHALCON_GT_LONG(transaction_level, 0)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Nested transaction with savepoints behavior cannot be changed while a transaction is open"); + return; + } + + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(supports_sp); + phalcon_call_method_key(supports_sp, dialect, "supportssavepoints", 1063347073UL); + if (!zend_is_true(supports_sp)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Savepoints are not supported by this database adapter"); + return; + } + + phalcon_update_property_this_quick(this_ptr, SL("_transactionsWithSavepoints"), nested_transactions_with_savepoints, 2137960997UL TSRMLS_CC); + + RETURN_THIS(); +} -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: +static PHP_METHOD(Phalcon_Db_Adapter, isNestedTransactionsWithSavepoints){ -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -The Software shall be used for Good, not Evil. + RETURN_MEMBER_QUICK(this_ptr, "_transactionsWithSavepoints", 2137960997UL); +} -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +static PHP_METHOD(Phalcon_Db_Adapter, getNestedTransactionSavepointName){ -#ifdef HAVE_CONFIG_H -#endif + zval *transaction_level; + PHALCON_MM_GROW(); + PHALCON_OBS_VAR(transaction_level); + phalcon_read_property_this_quick(&transaction_level, this_ptr, SL("_transactionLevel"), 2789346594UL, PH_NOISY_CC); + PHALCON_CONCAT_SV(return_value, "PHALCON_SAVEPOINT_", transaction_level); + RETURN_MM(); +} -#define JSMIN_ACTION_OUTPUT_NEXT 1 -#define JSMIN_ACTION_NEXT_DELETE 2 -#define JSMIN_ACTION_NEXT 3 +static PHP_METHOD(Phalcon_Db_Adapter, getDefaultIdValue){ -typedef struct _jsmin_parser { - zval *script; - zval **error; - int script_pointer; - int inside_string; - smart_str *minified; - char theA; - char theB; - char theC; - char theX; - char theY; -} jsmin_parser; + zval *null_value; -static void jsmin_error(jsmin_parser *parser, char* s, int s_length TSRMLS_DC) { - PHALCON_INIT_VAR(*parser->error); - ZVAL_STRINGL(*parser->error, s, s_length, 1); + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(null_value); + ZVAL_STRING(null_value, "null", 1); + object_init_ex(return_value, phalcon_db_rawvalue_ce); + phalcon_call_method_p1_key(NULL, return_value, "__construct", null_value, 1107214344UL); + + RETURN_MM(); } -/* isAlphanum -- return true if the character is a letter, digit, underscore, - dollar sign, or non-ASCII character. -*/ +static PHP_METHOD(Phalcon_Db_Adapter, supportSequences){ -static int jsmin_isAlphanum(int c) { - return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c == '\\' || c > 126); + + RETURN_FALSE; } +static PHP_METHOD(Phalcon_Db_Adapter, useExplicitIdValue){ -/* get -- return the next character from stdin. Watch out for lookahead. If - the character is a control character, translate it to a space or - linefeed. -*/ -static char jsmin_peek(jsmin_parser *parser){ - char ch; - if (parser->script_pointer < Z_STRLEN_P(parser->script)) { - ch = Z_STRVAL_P(parser->script)[parser->script_pointer]; - return ch; - } - return EOF; + RETURN_FALSE; } -static char jsmin_get(jsmin_parser *parser) { +static PHP_METHOD(Phalcon_Db_Adapter, getDescriptor){ - char c; - if (parser->script_pointer < Z_STRLEN_P(parser->script)) { - c = Z_STRVAL_P(parser->script)[parser->script_pointer]; - parser->script_pointer++; - } else { - c = EOF; - } + RETURN_MEMBER_QUICK(this_ptr, "_descriptor", 691635363UL); +} - parser->theC = c; +static PHP_METHOD(Phalcon_Db_Adapter, getConnectionId){ - if (parser->inside_string == 1) { - if (c >= ' ' || c == '\n' || c == '\t' || c == EOF) { - return c; - } - } else { - if (c >= ' ' || c == '\n' || c == EOF) { - return c; - } - } - if (c == '\r') { - return '\n'; - } - return ' '; + + RETURN_MEMBER_QUICK(this_ptr, "_connectionId", 802624385UL); } +static PHP_METHOD(Phalcon_Db_Adapter, getSQLStatement){ -/* next -- get the next character, excluding comments. peek() is used to see - if a '/' is followed by a '/' or '*'. -*/ -static int jsmin_next(jsmin_parser *parser TSRMLS_DC) { - char c = jsmin_get(parser); - if (c == '/') { - switch (jsmin_peek(parser)) { - case '/': - for (;;) { - c = jsmin_get(parser); - if (c <= '\n') { - break; - } - } - break; - case '*': - jsmin_get(parser); - while (c != ' ') { - switch (jsmin_get(parser)) { - case '*': - if (jsmin_peek(parser) == '/') { - jsmin_get(parser); - c = ' '; - } - break; - case EOF: - jsmin_error(parser, SL("Unterminated comment.") TSRMLS_CC); - return FAILURE; - } - } - break; - } - } - parser->theY = parser->theX; - parser->theX = c; - return c; + RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); } -/* action -- do something! What you do is determined by the argument: - 1 Output A. Copy B to A. Get the next B. - 2 Copy B to A. Get the next B. (Delete A). - 3 Get the next B. (Delete B). - action treats a string as a single character. Wow! - action recognizes a regular expression if it is preceded by ( or , or =. -*/ +static PHP_METHOD(Phalcon_Db_Adapter, getRealSQLStatement){ -static int jsmin_action(jsmin_parser *parser, char d TSRMLS_DC) { - switch (d) { - case JSMIN_ACTION_OUTPUT_NEXT: - smart_str_appendc(parser->minified, parser->theA); - if ( - (parser->theY == '\n' || parser->theY == ' ') && - (parser->theA == '+' || parser->theA == '-' || parser->theA == '*' || parser->theA == '/') && - (parser->theB == '+' || parser->theB == '-' || parser->theB == '*' || parser->theB == '/') - ) { - smart_str_appendc(parser->minified, parser->theY); - } - /* no break */ - case JSMIN_ACTION_NEXT_DELETE: - parser->theA = parser->theB; - if (parser->theA == '\'' || parser->theA == '"' || parser->theA == '`') { - parser->inside_string = 1; - for (;;) { - smart_str_appendc(parser->minified, parser->theA); - parser->theA = jsmin_get(parser); - if (parser->theA == parser->theB) { - break; - } - if (parser->theA == '\\') { - smart_str_appendc(parser->minified, parser->theA); - parser->theA = jsmin_get(parser); - } - if (parser->theA == EOF) { - jsmin_error(parser, SL("Unterminated string literal.") TSRMLS_CC); - return FAILURE; - } - } - parser->inside_string = 0; - } - /* no break */ - case JSMIN_ACTION_NEXT: - parser->theB = jsmin_next(parser TSRMLS_CC); - if (*parser->error != NULL) { - return FAILURE; - } - if (parser->theB == '/' && ( - parser->theA == '(' || parser->theA == ',' || parser->theA == '=' || parser->theA == ':' || - parser->theA == '[' || parser->theA == '!' || parser->theA == '&' || parser->theA == '|' || - parser->theA == '?' || parser->theA == '+' || parser->theA == '-' || parser->theA == '~' || - parser->theA == '*' || parser->theA == '/' || parser->theA == '{' || parser->theA == '\n' - )) { - smart_str_appendc(parser->minified, parser->theA); - if (parser->theA == '/' || parser->theA == '*') { - smart_str_appendc(parser->minified, ' '); - } - smart_str_appendc(parser->minified, parser->theB); - for (;;) { - parser->theA = jsmin_get(parser); - if (parser->theA == '[') { - for (;;) { - smart_str_appendc(parser->minified, parser->theA); - parser->theA = jsmin_get(parser); - if (parser->theA == ']') { - break; - } - if (parser->theA == '\\') { - smart_str_appendc(parser->minified, parser->theA); - parser->theA = jsmin_get(parser); - } - if (parser->theA == EOF) { - jsmin_error(parser, SL("Unterminated set in Regular Expression literal.") TSRMLS_CC); - return FAILURE; - } - } - } else { - if (parser->theA == '/') { - switch (jsmin_peek(parser)) { - case '/': - case '*': - jsmin_error(parser, SL("Unterminated set in Regular Expression literal.") TSRMLS_CC); - return FAILURE; - } - break; - } else { - if (parser->theA == '\\') { - smart_str_appendc(parser->minified, parser->theA); - parser->theA = jsmin_get(parser); - } - } - } - if (parser->theA == EOF) { - jsmin_error(parser, SL("Unterminated Regular Expression literal.") TSRMLS_CC); - return FAILURE; - } - smart_str_appendc(parser->minified, parser->theA); - } - parser->theB = jsmin_next(parser TSRMLS_CC); - if (*parser->error != NULL) { - return FAILURE; - } - } - } - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); } +static PHP_METHOD(Phalcon_Db_Adapter, getSQLVariables){ -/* jsmin -- Copy the input to the output, deleting the characters which are - insignificant to JavaScript. Comments will be removed. Tabs will be - replaced with spaces. Carriage returns will be replaced with linefeeds. - Most spaces and linefeeds will be removed. -*/ -static int phalcon_jsmin_internal(zval *return_value, zval *script, zval **error TSRMLS_DC) { + RETURN_MEMBER_QUICK(this_ptr, "_sqlVariables", 3213579853UL); +} - jsmin_parser parser; - smart_str minified = {0}; - int status = SUCCESS; +static PHP_METHOD(Phalcon_Db_Adapter, getSQLBindTypes){ - parser.theA = '\n'; - parser.theX = EOF; - parser.theY = EOF; - parser.script = script; - parser.error = error; - parser.script_pointer = 0; - parser.inside_string = 0; - parser.minified = &minified; - if (jsmin_action(&parser, JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) { - return FAILURE; - } + RETURN_MEMBER_QUICK(this_ptr, "_sqlBindTypes", 3288357222UL); +} - while (parser.theA != EOF) { - if (status == FAILURE) { - break; - } - switch (parser.theA) { - case ' ': - if (jsmin_action(&parser, jsmin_isAlphanum(parser.theB) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT_DELETE TSRMLS_CC)) { - status = FAILURE; - break; - } - break; - case '\n': - switch (parser.theB) { - case '{': - case '[': - case '(': - case '+': - case '-': - case '!': - case '~': - if (jsmin_action(&parser, JSMIN_ACTION_OUTPUT_NEXT TSRMLS_CC) == FAILURE) { - status = FAILURE; - break; - } - break; - case ' ': - if (jsmin_action(&parser, JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) { - status = FAILURE; - break; - } - break; - default: - if (jsmin_action(&parser, jsmin_isAlphanum(parser.theB) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT_DELETE TSRMLS_CC) == FAILURE) { - status = FAILURE; - break; - } - } - break; - default: - switch (parser.theB) { - case ' ': - if (jsmin_action(&parser, jsmin_isAlphanum(parser.theA) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) { - status = FAILURE; - break; - } - break; - case '\n': - switch (parser.theA) { - case '}': - case ']': - case ')': - case '+': - case '-': - case '"': - case '\'': - case '`': - if (jsmin_action(&parser, JSMIN_ACTION_OUTPUT_NEXT TSRMLS_CC) == FAILURE) { - status = FAILURE; - break; - } - break; - default: - if (jsmin_action(&parser, jsmin_isAlphanum(parser.theA) ? JSMIN_ACTION_OUTPUT_NEXT : JSMIN_ACTION_NEXT TSRMLS_CC) == FAILURE) { - status = FAILURE; - break; - } - } - break; - default: - if (jsmin_action(&parser, JSMIN_ACTION_OUTPUT_NEXT TSRMLS_CC) == FAILURE) { - status = FAILURE; - break; - } - break; - } - } - } +static PHP_METHOD(Phalcon_Db_Adapter, getType){ - if (status == FAILURE) { - smart_str_free(&minified); - return FAILURE; - } - smart_str_0(&minified); + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); +} - if (minified.len) { - ZVAL_STRINGL(return_value, minified.c, minified.len, 0); - } else { - ZVAL_STRING(return_value, "", 1); - } +static PHP_METHOD(Phalcon_Db_Adapter, getDialectType){ - return SUCCESS; + + RETURN_MEMBER_QUICK(this_ptr, "_dialectType", 1868597628UL); } -static int phalcon_jsmin(zval *return_value, zval *script TSRMLS_DC) { - zval *error = NULL; - ZVAL_NULL(return_value); - if (Z_TYPE_P(script) != IS_STRING) { - phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Script must be a string"), 1 TSRMLS_CC); - return FAILURE; - } - if (phalcon_jsmin_internal(return_value, script, &error TSRMLS_CC) == FAILURE){ - if (Z_TYPE_P(error) == IS_STRING) { - phalcon_throw_exception_string(phalcon_assets_exception_ce, Z_STRVAL_P(error), Z_STRLEN_P(error), 1 TSRMLS_CC); - } else { - phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Unknown error"), 1 TSRMLS_CC); - } - return FAILURE; - } +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Db_AdapterInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Db, AdapterInterface, db_adapterinterface, phalcon_db_adapterinterface_method_entry); return SUCCESS; } @@ -27891,8 +27565,6 @@ static int phalcon_jsmin(zval *return_value, zval *script TSRMLS_DC) { -#ifdef HAVE_CONFIG_H -#endif @@ -27900,303 +27572,60 @@ static int phalcon_jsmin(zval *return_value, zval *script TSRMLS_DC) { -PHALCON_INIT_CLASS(Phalcon_Assets_Filters_Jsmin){ - PHALCON_REGISTER_CLASS(Phalcon\\Assets\\Filters, Jsmin, assets_filters_jsmin, phalcon_assets_filters_jsmin_method_entry, 0); - return SUCCESS; -} -static PHP_METHOD(Phalcon_Assets_Filters_Jsmin, filter){ - zval *content; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &content); - - if (phalcon_jsmin(return_value, content TSRMLS_CC) == FAILURE) { - return; - } - - RETURN_MM(); -} -/* cssmin.c -Copyright (c) 2010 (www.ryanday.org) -w3c css spec: http://www.w3.org/TR/CSS2/syndata.html -this parser makes no attempt to understand css as such it does not interpret css to spec. -** cannot handle nested { blocks but will ignore aditional { in parens () -** no in quote detection for ( or } -function get, peek and general lookahead structure taken from.. -jsmin.c -Copyright (c) 2002 Douglas Crockford (www.crockford.com) -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -The Software shall be used for Good, not Evil. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ -#ifdef HAVE_CONFIG_H -#endif -#define STATE_FREE 1 -#define STATE_ATRULE 2 -#define STATE_SELECTOR 3 -#define STATE_BLOCK 4 -#define STATE_DECLARATION 5 -#define STATE_COMMENT 6 -typedef struct _cssmin_parser { - int tmp_state; - int state; - int last_state; - int in_paren; - zval *style; - zval **error; - smart_str *minified; - int style_pointer; -} cssmin_parser; -/* get -- return the next character from stdin. Watch out for lookahead. If -the character is a control character, translate it to a space or -linefeed. -*/ -static char cssmin_peek(cssmin_parser *parser){ - char ch; - if (parser->style_pointer < Z_STRLEN_P(parser->style)) { - ch = Z_STRVAL_P(parser->style)[parser->style_pointer]; - return ch; - } - return EOF; -} -static char cssmin_back_peek(cssmin_parser *parser){ - char ch; - if (parser->style_pointer > 1) { - ch = Z_STRVAL_P(parser->style)[parser->style_pointer - 1]; - return ch; - } - return EOF; -} -/* machine -*/ -static int phalcon_cssmin_machine(cssmin_parser *parser, unsigned char c TSRMLS_DC){ - unsigned char p; - if (parser->state != STATE_COMMENT) { - if (c == '/' && cssmin_peek(parser) == '*') { - parser->tmp_state = parser->state; - parser->state = STATE_COMMENT; - } - } - switch (parser->state) { - case STATE_FREE: - if (c == ' ' && c == '\t' && c == '\n' && c == '\r') { - c = 0; - } else if (c == '@'){ - parser->state = STATE_ATRULE; - break; - } else if(c > 0){ - //fprintf(stdout,"one to 3 - %c %i",c,c); - parser->state = STATE_SELECTOR; - } - /* no break */ - case STATE_SELECTOR: - if (c == '{') { - parser->state = STATE_BLOCK; - } else { - if(c == '\n' || c == '\r') { - c = 0; - } else { - if(c == '@'){ - parser->state = STATE_ATRULE; - } else { - if ((c == ' ' || c == '\t')) { - p = cssmin_peek(parser); - if (p == '{' || p == '\t' || p == ' ' || p == '>' || p == ',') { - c = 0; - } else { - p = cssmin_back_peek(parser); - if (p == ',' || p == '>' || p == ':') { - c = 0; - } else { - c = ' '; - } - } - } - } - } - } - break; - case STATE_ATRULE: - /* support - @import etc. - @font-face{ - */ - if (c == '\r' || c == '\n' || c == ';') { - c = ';'; - parser->state = STATE_FREE; - } else { - if(c == '{') { - parser->state = STATE_BLOCK; - } - } - break; - case STATE_BLOCK: - if (c == ' ' || c == '\t' || c == '\n' || c == '\r' ) { - c = 0; - break; - } else { - if (c == '}') { - parser->state = STATE_FREE; - //fprintf(stdout,"closing bracket found in block\n"); - break; - } else { - parser->state = STATE_DECLARATION; - } - } - /* no break */ - case STATE_DECLARATION: - if (c == '(') { - parser->in_paren = 1; - } - if (parser->in_paren == 0) { - if (c == ';') { - parser->state = STATE_BLOCK; - if (cssmin_peek(parser) == '}') { - c = 0; - } - } else if (c == '}') { - parser->state = STATE_FREE; - } else { - if (c == '\n' || c == '\r') { - c = 0; - } else { - if (c == ' ' || c == '\t') { - p = cssmin_peek(parser); - if (p == ' ' || p == '\t') { - c = 0; - } else { - c = ' '; - } - } - } - } - } else { - if (c == ')') { - parser->in_paren = 0; - } - } - break; - case STATE_COMMENT: - if (c == '*' && cssmin_peek(parser) == '/'){ - parser->style_pointer += 2; - parser->state = parser->tmp_state; - } - c = 0; - break; - } - return c; -} -static int phalcon_cssmin_internal(zval *return_value, zval *style, zval **error TSRMLS_DC) { - int i; - unsigned char c; - cssmin_parser parser; - smart_str minified = {0}; - parser.state = 1; - parser.last_state = 1; - parser.in_paren = 0; - parser.style = style; - parser.error = error; - parser.minified = &minified; - for (i = 0; i < Z_STRLEN_P(style); i++) { - parser.style_pointer = i + 1; - c = phalcon_cssmin_machine(&parser, Z_STRVAL_P(style)[i] TSRMLS_CC); - if (c != 0) { - smart_str_appendc(parser.minified, c); - } - i = parser.style_pointer - 1; - } - smart_str_0(&minified); - if (minified.len) { - ZVAL_STRINGL(return_value, minified.c, minified.len, 0); - } else { - ZVAL_STRING(return_value, "", 1); - } - return SUCCESS; -} -/* cssmin -- minify the css - removes comments - removes newlines and line feeds keeping - removes last semicolon from last property -*/ -static int phalcon_cssmin(zval *return_value, zval *style TSRMLS_DC) { - zval *error = NULL; - ZVAL_NULL(return_value); - if (Z_TYPE_P(style) != IS_STRING) { - phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Style must be a string"), 1 TSRMLS_CC); - return FAILURE; - } - if (phalcon_cssmin_internal(return_value, style, &error TSRMLS_CC) == FAILURE) { - if (Z_TYPE_P(error) == IS_STRING) { - phalcon_throw_exception_string(phalcon_assets_exception_ce, Z_STRVAL_P(error), Z_STRLEN_P(error), 1 TSRMLS_CC); - } else { - phalcon_throw_exception_string(phalcon_assets_exception_ce, SL("Unknown error"), 1 TSRMLS_CC); - } - return FAILURE; - } - return SUCCESS; -} + + + + @@ -28210,1421 +27639,1276 @@ static int phalcon_cssmin(zval *return_value, zval *style TSRMLS_DC) { -PHALCON_INIT_CLASS(Phalcon_Assets_Manager){ +PHALCON_INIT_CLASS(Phalcon_Db_Column){ - PHALCON_REGISTER_CLASS(Phalcon\\Assets, Manager, assets_manager, phalcon_assets_manager_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Db, Column, db_column, phalcon_db_column_method_entry, 0); - zend_declare_property_null(phalcon_assets_manager_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_manager_ce, SL("_collections"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_assets_manager_ce, SL("_implicitOutput"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_column_ce, SL("_columnName"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_column_ce, SL("_schemaName"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_column_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_db_column_ce, SL("_isNumeric"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_db_column_ce, SL("_size"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_db_column_ce, SL("_scale"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_db_column_ce, SL("_unsigned"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_db_column_ce, SL("_notNull"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_db_column_ce, SL("_primary"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_db_column_ce, SL("_autoIncrement"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_db_column_ce, SL("_first"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_column_ce, SL("_after"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_db_column_ce, SL("_bindType"), 2, ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_INTEGER"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_DATE"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_VARCHAR"), 2 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_DECIMAL"), 3 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_DATETIME"), 4 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_CHAR"), 5 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_TEXT"), 6 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_FLOAT"), 7 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("TYPE_BOOLEAN"), 8 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_PARAM_NULL"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_PARAM_INT"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_PARAM_STR"), 2 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_PARAM_BOOL"), 5 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_PARAM_DECIMAL"), 32 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_column_ce, SL("BIND_SKIP"), 1024 TSRMLS_CC); + + zend_class_implements(phalcon_db_column_ce TSRMLS_CC, 1, phalcon_db_columninterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Assets_Manager, __construct){ +static PHP_METHOD(Phalcon_Db_Column, __construct){ - zval *options = NULL; + zval *column_name, *definition, *type, *not_null; + zval *primary, *size, *is_numeric = NULL, *scale, *dunsigned; + zval *auto_increment, *first, *after, *bind_type; + zval *t0 = NULL, *t1 = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &options); + phalcon_fetch_params(1, 2, 0, &column_name, &definition); - if (!options) { - PHALCON_INIT_VAR(options); + phalcon_update_property_this_quick(this_ptr, SL("_columnName"), column_name, 3251978323UL TSRMLS_CC); + + if (phalcon_array_isset_quick_string(definition, SS("type"), 276192743UL)) { + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, definition, SS("type"), 276192743UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column type is required"); + return; } - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + if (phalcon_array_isset_quick_string(definition, SS("notNull"), 1960377425UL)) { + PHALCON_OBS_VAR(not_null); + phalcon_array_fetch_quick_string(¬_null, definition, SS("notNull"), 1960377425UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_notNull"), not_null, 628108368UL TSRMLS_CC); } - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Assets_Manager, setOptions){ - - zval *options; - - phalcon_fetch_params(0, 1, 0, &options); + if (phalcon_array_isset_quick_string(definition, SS("primary"), 482916521UL)) { + PHALCON_OBS_VAR(primary); + phalcon_array_fetch_quick_string(&primary, definition, SS("primary"), 482916521UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_primary"), primary, 3445614760UL TSRMLS_CC); + } - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Options must be an array"); - return; + if (phalcon_array_isset_quick_string(definition, SS("size"), 274442720UL)) { + PHALCON_OBS_VAR(size); + phalcon_array_fetch_quick_string(&size, definition, SS("size"), 274442720UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_size"), size, 3990209087UL TSRMLS_CC); } - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Manager, getOptions){ - - - RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); -} - -static PHP_METHOD(Phalcon_Assets_Manager, useImplicitOutput){ - - zval *implicit_output; - - phalcon_fetch_params(0, 1, 0, &implicit_output); + if (phalcon_array_isset_quick_string(definition, SS("scale"), 458672173UL)) { - phalcon_update_property_this_quick(this_ptr, SL("_implicitOutput"), implicit_output, 3405432336UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Manager, addCss){ - - zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type, *resource; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); + PHALCON_INIT_VAR(t0); + ZVAL_LONG(t0, 3); + PHALCON_INIT_VAR(is_numeric); + is_equal_function(is_numeric, type, t0 TSRMLS_CC); + if (PHALCON_IS_NOT_TRUE(is_numeric)) { + PHALCON_INIT_VAR(t1); + ZVAL_LONG(t1, 7); + is_equal_function(is_numeric, type, t1 TSRMLS_CC); + } - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); + if (PHALCON_IS_TRUE(is_numeric)) { + PHALCON_OBS_VAR(scale); + phalcon_array_fetch_quick_string(&scale, definition, SS("scale"), 458672173UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_scale"), scale, 2819877996UL TSRMLS_CC); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column type does not support scale parameter"); + return; + } } - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); + if (phalcon_array_isset_quick_string(definition, SS("unsigned"), 1143113122UL)) { + PHALCON_OBS_VAR(dunsigned); + phalcon_array_fetch_quick_string(&dunsigned, definition, SS("unsigned"), 1143113122UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_unsigned"), dunsigned, 127907201UL TSRMLS_CC); } - if (!attributes) { - PHALCON_INIT_VAR(attributes); + if (phalcon_array_isset_quick_string(definition, SS("isNumeric"), 1643974676UL)) { + PHALCON_OBS_NVAR(is_numeric); + phalcon_array_fetch_quick_string(&is_numeric, definition, SS("isNumeric"), 1643974676UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_isNumeric"), is_numeric, 2501917651UL TSRMLS_CC); } - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "css", 1); - - PHALCON_INIT_VAR(resource); - object_init_ex(resource, phalcon_assets_resource_css_ce); - phalcon_call_method_p4_key(NULL, resource, "__construct", path, local, filter, attributes, 1107214344UL); - - phalcon_call_method_p2_key(NULL, this_ptr, "addresourcebytype", type, resource, 1257550035UL); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Assets_Manager, addJs){ - - zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type, *resource; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); - - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); + if (phalcon_array_isset_quick_string(definition, SS("autoIncrement"), 2492144707UL)) { + if (PHALCON_IS_LONG(type, 0)) { + PHALCON_OBS_VAR(auto_increment); + phalcon_array_fetch_quick_string(&auto_increment, definition, SS("autoIncrement"), 2492144707UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_autoIncrement"), auto_increment, 3100381058UL TSRMLS_CC); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column type cannot be auto-increment"); + return; + } } - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); + if (phalcon_array_isset_quick_string(definition, SS("first"), 4252613933UL)) { + PHALCON_OBS_VAR(first); + phalcon_array_fetch_quick_string(&first, definition, SS("first"), 4252613933UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_first"), first, 2318852460UL TSRMLS_CC); } - if (!attributes) { - PHALCON_INIT_VAR(attributes); + if (phalcon_array_isset_quick_string(definition, SS("after"), 4053435767UL)) { + PHALCON_OBS_VAR(after); + phalcon_array_fetch_quick_string(&after, definition, SS("after"), 4053435767UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_after"), after, 2119674294UL TSRMLS_CC); } - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "js", 1); - - PHALCON_INIT_VAR(resource); - object_init_ex(resource, phalcon_assets_resource_js_ce); - phalcon_call_method_p4_key(NULL, resource, "__construct", path, local, filter, attributes, 1107214344UL); + if (phalcon_array_isset_quick_string(definition, SS("bindType"), 1941857476UL)) { + PHALCON_OBS_VAR(bind_type); + phalcon_array_fetch_quick_string(&bind_type, definition, SS("bindType"), 1941857476UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_bindType"), bind_type, 926651555UL TSRMLS_CC); + } - phalcon_call_method_p2_key(NULL, this_ptr, "addresourcebytype", type, resource, 1257550035UL); - RETURN_THIS(); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Assets_Manager, addResourceByType){ +static PHP_METHOD(Phalcon_Db_Column, getSchemaName){ - zval *type, *resource, *collections, *collection = NULL; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_schemaName", 851420310UL); +} - phalcon_fetch_params(1, 2, 0, &type, &resource); - - PHALCON_OBS_VAR(collections); - phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC); - if (phalcon_array_isset(collections, type)) { - PHALCON_OBS_VAR(collection); - phalcon_array_fetch(&collection, collections, type, PH_NOISY); - } else { - PHALCON_INIT_NVAR(collection); - object_init_ex(collection, phalcon_assets_collection_ce); - phalcon_update_property_array(this_ptr, SL("_collections"), type, collection TSRMLS_CC); - } - - phalcon_call_method_p1_key(NULL, collection, "add", resource, 2090071694UL); - - RETURN_THIS(); +static PHP_METHOD(Phalcon_Db_Column, getName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_columnName", 3251978323UL); } -static PHP_METHOD(Phalcon_Assets_Manager, addResource){ +static PHP_METHOD(Phalcon_Db_Column, getType){ - zval *resource, *type; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); +} - phalcon_fetch_params(1, 1, 0, &resource); - - if (Z_TYPE_P(resource) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Resource must be an object"); - return; - } - - PHALCON_INIT_VAR(type); - phalcon_call_method_key(type, resource, "gettype", 4294422375UL); - - phalcon_call_method_p2_key(NULL, this_ptr, "addresourcebytype", type, resource, 1257550035UL); - - RETURN_THIS(); +static PHP_METHOD(Phalcon_Db_Column, getSize){ + + + RETURN_MEMBER_QUICK(this_ptr, "_size", 3990209087UL); } -static PHP_METHOD(Phalcon_Assets_Manager, set){ +static PHP_METHOD(Phalcon_Db_Column, getScale){ - zval *id, *collection; - phalcon_fetch_params(0, 2, 0, &id, &collection); - - if (unlikely(Z_TYPE_P(id) != IS_STRING)) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Collection-Id must be a string"); - return; - } - if (unlikely(Z_TYPE_P(collection) != IS_OBJECT)) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Collection must be an object"); - return; - } - - phalcon_update_property_array(this_ptr, SL("_collections"), id, collection TSRMLS_CC); - - RETURN_THISW(); + RETURN_MEMBER_QUICK(this_ptr, "_scale", 2819877996UL); } -static PHP_METHOD(Phalcon_Assets_Manager, get){ +static PHP_METHOD(Phalcon_Db_Column, isUnsigned){ - zval *id, *collections, *collection; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_unsigned", 127907201UL); +} - phalcon_fetch_params(1, 1, 0, &id); - - if (unlikely(Z_TYPE_P(id) != IS_STRING)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Collection-Id must be a string"); - return; - } - - PHALCON_OBS_VAR(collections); - phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC); - if (!phalcon_array_isset(collections, id)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "The collection does not exist in the manager"); - return; - } - - PHALCON_OBS_VAR(collection); - phalcon_array_fetch(&collection, collections, id, PH_NOISY); - - RETURN_CCTOR(collection); +static PHP_METHOD(Phalcon_Db_Column, isNotNull){ + + + RETURN_MEMBER_QUICK(this_ptr, "_notNull", 628108368UL); } -static PHP_METHOD(Phalcon_Assets_Manager, getCss){ +static PHP_METHOD(Phalcon_Db_Column, isPrimary){ - zval *collections, *collection; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_primary", 3445614760UL); +} - PHALCON_OBS_VAR(collections); - phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC); - - if (!phalcon_array_isset_quick_string(collections, SS("css"), 2090160398UL)) { - object_init_ex(return_value, phalcon_assets_collection_ce); - RETURN_MM(); - } - - PHALCON_OBS_VAR(collection); - phalcon_array_fetch_quick_string(&collection, collections, SS("css"), 2090160398UL, PH_NOISY); - - RETURN_CCTOR(collection); +static PHP_METHOD(Phalcon_Db_Column, isAutoIncrement){ + + + RETURN_MEMBER_QUICK(this_ptr, "_autoIncrement", 3100381058UL); } -static PHP_METHOD(Phalcon_Assets_Manager, getJs){ +static PHP_METHOD(Phalcon_Db_Column, isNumeric){ - zval *collections, *collection; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_isNumeric", 2501917651UL); +} - PHALCON_OBS_VAR(collections); - phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC); - - if (!phalcon_array_isset_quick_string(collections, SS("js"), 193496226UL)) { - object_init_ex(return_value, phalcon_assets_collection_ce); - RETURN_MM(); - } - - PHALCON_OBS_VAR(collection); - phalcon_array_fetch_quick_string(&collection, collections, SS("js"), 193496226UL, PH_NOISY); - - RETURN_CCTOR(collection); +static PHP_METHOD(Phalcon_Db_Column, isFirst){ + + + RETURN_MEMBER_QUICK(this_ptr, "_first", 2318852460UL); } -static PHP_METHOD(Phalcon_Assets_Manager, collection){ +static PHP_METHOD(Phalcon_Db_Column, getAfterPosition){ - zval *name, *collections, *collection = NULL; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_after", 2119674294UL); +} - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(collections); - phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC); - if (phalcon_array_isset(collections, name)) { - PHALCON_OBS_VAR(collection); - phalcon_array_fetch(&collection, collections, name, PH_NOISY); - } else { - PHALCON_INIT_NVAR(collection); - object_init_ex(collection, phalcon_assets_collection_ce); - phalcon_update_property_array(this_ptr, SL("_collections"), name, collection TSRMLS_CC); - } - - RETURN_CCTOR(collection); +static PHP_METHOD(Phalcon_Db_Column, getBindType){ + + + RETURN_MEMBER_QUICK(this_ptr, "_bindType", 926651555UL); } -static PHP_METHOD(Phalcon_Assets_Manager, output){ +static PHP_METHOD(Phalcon_Db_Column, __set_state){ - zval *collection, *callback, *output, *use_implicit_output; - zval *resources, *filters, *prefix, *source_base_path = NULL; - zval *target_base_path = NULL, *options, *collection_source_path; - zval *complete_source_path = NULL, *collection_target_path; - zval *complete_target_path = NULL, *filtered_joined_content = NULL; - zval *join, *exception_message = NULL, *is_directory; - zval *resource = NULL, *filter_needed = NULL, *local = NULL, *source_path = NULL; - zval *target_path = NULL, *path = NULL, *prefixed_path = NULL, *attributes = NULL; - zval *parameters = NULL, *html = NULL, *content = NULL, *must_filter = NULL; - zval *filter = NULL, *filtered_content = NULL, *target_uri; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; + zval *data, *definition, *column_name, *column_type; + zval *not_null, *primary, *size, *dunsigned, *after; + zval *is_numeric, *first, *bind_type; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &collection, &callback); + phalcon_fetch_params(1, 1, 0, &data); - PHALCON_INIT_VAR(output); + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column state must be an array"); + return; + } - PHALCON_OBS_VAR(use_implicit_output); - phalcon_read_property_this_quick(&use_implicit_output, this_ptr, SL("_implicitOutput"), 3405432336UL, PH_NOISY_CC); + PHALCON_INIT_VAR(definition); + array_init(definition); + if (!phalcon_array_isset_quick_string(data, SS("_columnName"), 3251978323UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column name is required"); + return; + } - PHALCON_INIT_VAR(resources); - phalcon_call_method_key(resources, collection, "getresources", 2001784992UL); + PHALCON_OBS_VAR(column_name); + phalcon_array_fetch_quick_string(&column_name, data, SS("_columnName"), 3251978323UL, PH_NOISY); + if (phalcon_array_isset_quick_string(data, SS("_type"), 3991959110UL)) { + PHALCON_OBS_VAR(column_type); + phalcon_array_fetch_quick_string(&column_type, data, SS("_type"), 3991959110UL, PH_NOISY); + phalcon_array_update_quick_string(&definition, SS("type"), 276192743UL, &column_type, PH_COPY | PH_SEPARATE); + } - PHALCON_INIT_VAR(filters); - phalcon_call_method_key(filters, collection, "getfilters", 2910616766UL); + if (phalcon_array_isset_quick_string(data, SS("_notNull"), 628108368UL)) { + PHALCON_OBS_VAR(not_null); + phalcon_array_fetch_quick_string(¬_null, data, SS("_notNull"), 628108368UL, PH_NOISY); + phalcon_array_update_quick_string(&definition, SS("notNull"), 1960377425UL, ¬_null, PH_COPY | PH_SEPARATE); + } - PHALCON_INIT_VAR(prefix); - phalcon_call_method_key(prefix, collection, "getprefix", 2543805107UL); + if (phalcon_array_isset_quick_string(data, SS("_primary"), 3445614760UL)) { + PHALCON_OBS_VAR(primary); + phalcon_array_fetch_quick_string(&primary, data, SS("_primary"), 3445614760UL, PH_NOISY); + phalcon_array_update_quick_string(&definition, SS("primary"), 482916521UL, &primary, PH_COPY | PH_SEPARATE); + } - if (Z_TYPE_P(filters) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(data, SS("_size"), 3990209087UL)) { + PHALCON_OBS_VAR(size); + phalcon_array_fetch_quick_string(&size, data, SS("_size"), 3990209087UL, PH_NOISY); + phalcon_array_update_quick_string(&definition, SS("size"), 274442720UL, &size, PH_COPY | PH_SEPARATE); + } - PHALCON_INIT_VAR(source_base_path); + if (phalcon_array_isset_quick_string(data, SS("_unsigned"), 127907201UL)) { + PHALCON_OBS_VAR(dunsigned); + phalcon_array_fetch_quick_string(&dunsigned, data, SS("_unsigned"), 127907201UL, PH_NOISY); + phalcon_array_update_quick_string(&definition, SS("unsigned"), 1143113122UL, &dunsigned, PH_COPY | PH_SEPARATE); + } - PHALCON_INIT_VAR(target_base_path); + if (phalcon_array_isset_quick_string(data, SS("_after"), 2119674294UL)) { + PHALCON_OBS_VAR(after); + phalcon_array_fetch_quick_string(&after, data, SS("_after"), 2119674294UL, PH_NOISY); + phalcon_array_update_quick_string(&definition, SS("after"), 4053435767UL, &after, PH_COPY | PH_SEPARATE); + } - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(data, SS("_isNumeric"), 2501917651UL)) { + PHALCON_OBS_VAR(is_numeric); + phalcon_array_fetch_quick_string(&is_numeric, data, SS("_isNumeric"), 2501917651UL, PH_NOISY); + phalcon_array_update_quick_string(&definition, SS("isNumeric"), 1643974676UL, &is_numeric, PH_COPY | PH_SEPARATE); + } - if (Z_TYPE_P(options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(data, SS("_first"), 2318852460UL)) { + PHALCON_OBS_VAR(first); + phalcon_array_fetch_quick_string(&first, data, SS("_first"), 2318852460UL, PH_NOISY); + phalcon_array_update_quick_string(&definition, SS("first"), 4252613933UL, &first, PH_COPY | PH_SEPARATE); + } - if (phalcon_array_isset_quick_string(options, SS("sourceBasePath"), 4090541534UL)) { - PHALCON_OBS_NVAR(source_base_path); - phalcon_array_fetch_quick_string(&source_base_path, options, SS("sourceBasePath"), 4090541534UL, PH_NOISY); - } + if (phalcon_array_isset_quick_string(data, SS("_bindType"), 926651555UL)) { + PHALCON_OBS_VAR(bind_type); + phalcon_array_fetch_quick_string(&bind_type, data, SS("_bindType"), 926651555UL, PH_NOISY); + phalcon_array_update_quick_string(&definition, SS("bindType"), 1941857476UL, &bind_type, PH_COPY | PH_SEPARATE); + } - if (phalcon_array_isset_quick_string(options, SS("targetBasePath"), 2556086420UL)) { - PHALCON_OBS_NVAR(target_base_path); - phalcon_array_fetch_quick_string(&target_base_path, options, SS("targetBasePath"), 2556086420UL, PH_NOISY); - } - } - - PHALCON_INIT_VAR(collection_source_path); - phalcon_call_method_key(collection_source_path, collection, "getsourcepath", 904752835UL); - - if (PHALCON_IS_NOT_EMPTY(collection_source_path)) { - PHALCON_INIT_VAR(complete_source_path); - PHALCON_CONCAT_VV(complete_source_path, source_base_path, collection_source_path); - } else { - PHALCON_CPY_WRT(complete_source_path, source_base_path); - } - - PHALCON_INIT_VAR(collection_target_path); - phalcon_call_method_key(collection_target_path, collection, "gettargetpath", 3143538297UL); - - if (PHALCON_IS_NOT_EMPTY(collection_target_path)) { - PHALCON_INIT_VAR(complete_target_path); - PHALCON_CONCAT_VV(complete_target_path, target_base_path, collection_target_path); - } else { - PHALCON_CPY_WRT(complete_target_path, target_base_path); - } - - PHALCON_INIT_VAR(filtered_joined_content); - - PHALCON_INIT_VAR(join); - phalcon_call_method_key(join, collection, "getjoin", 4282196469UL); - - if (zend_is_true(join)) { - - if (PHALCON_IS_EMPTY(complete_target_path)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Path '", complete_target_path, "' is not a valid target path (1)"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } + object_init_ex(return_value, phalcon_db_column_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", column_name, definition, 1107214344UL); - PHALCON_INIT_VAR(is_directory); - phalcon_call_func_p1(is_directory, "is_dir", complete_target_path); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Db_ColumnInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ColumnInterface, db_columninterface, phalcon_db_columninterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Mysql){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Mysql, db_dialect_mysql, "phalcon\\db\\dialect", phalcon_db_dialect_mysql_method_entry, 0); + + zend_declare_property_string(phalcon_db_dialect_mysql_ce, SL("_escapeChar"), "`", ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_db_dialect_mysql_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, getColumnDefinition){ + + zval *column, *size, *column_type, *column_sql = NULL; + zval *is_unsigned = NULL, *scale = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &column); - if (PHALCON_IS_TRUE(is_directory)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Path '", complete_target_path, "' is not a valid target path (2)"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } - } + if (Z_TYPE_P(column) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column definition must be an object compatible with Phalcon\\Db\\ColumnInterface"); + return; } - phalcon_is_iterable(resources, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(resource); - - PHALCON_INIT_NVAR(filter_needed); - ZVAL_BOOL(filter_needed, 0); - - PHALCON_INIT_NVAR(local); - phalcon_call_method_key(local, resource, "getlocal", 3951574576UL); - - if (Z_TYPE_P(filters) == IS_ARRAY) { - if (zend_is_true(join)) { - if (zend_is_true(local)) { - - PHALCON_INIT_NVAR(source_path); - phalcon_call_method_p1_key(source_path, resource, "getrealsourcepath", complete_source_path, 1163474055UL); - - if (!zend_is_true(source_path)) { - PHALCON_INIT_NVAR(source_path); - phalcon_call_method_key(source_path, resource, "getpath", 4288820658UL); - - 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 { - PHALCON_INIT_NVAR(source_path); - phalcon_call_method_key(source_path, resource, "getpath", 4288820658UL); - - PHALCON_INIT_NVAR(filter_needed); - ZVAL_BOOL(filter_needed, 1); - } + PHALCON_INIT_VAR(size); + phalcon_call_method_key(size, column, "getsize", 4292672352UL); - PHALCON_INIT_NVAR(target_path); - phalcon_call_method_p1_key(target_path, resource, "getrealtargetpath", complete_target_path, 3402259517UL); + PHALCON_INIT_VAR(column_type); + phalcon_call_method_key(column_type, column, "gettype", 4294422375UL); - 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; - } + switch (phalcon_get_intval(column_type)) { - if (zend_is_true(local)) { + case 0: + PHALCON_INIT_VAR(column_sql); + PHALCON_CONCAT_SVS(column_sql, "INT(", size, ")"); - 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_BOOL(filter_needed, 1); - } - } else { - PHALCON_INIT_NVAR(filter_needed); - ZVAL_BOOL(filter_needed, 1); - } - } + PHALCON_INIT_VAR(is_unsigned); + phalcon_call_method_key(is_unsigned, column, "isunsigned", 3241495646UL); + if (zend_is_true(is_unsigned)) { + phalcon_concat_self_str(&column_sql, SL(" UNSIGNED") TSRMLS_CC); } - } - - if (Z_TYPE_P(filters) != IS_ARRAY) { - PHALCON_INIT_NVAR(path); - phalcon_call_method_key(path, resource, "getrealtargeturi", 4137962752UL); - if (Z_TYPE_P(prefix) != IS_NULL) { - PHALCON_INIT_NVAR(prefixed_path); - PHALCON_CONCAT_VV(prefixed_path, prefix, path); - } else { - PHALCON_CPY_WRT(prefixed_path, path); - } + break; - PHALCON_INIT_NVAR(attributes); - phalcon_call_method_key(attributes, resource, "getattributes", 1013165772UL); + case 1: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "DATE", 1); + break; - if (Z_TYPE_P(attributes) == IS_ARRAY) { - phalcon_array_update_long(&attributes, 0, &prefixed_path, PH_COPY | PH_SEPARATE); + case 2: + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVS(column_sql, "VARCHAR(", size, ")"); + break; - PHALCON_INIT_NVAR(parameters); - array_init_size(parameters, 2); - phalcon_array_append(¶meters, attributes, PH_SEPARATE); - phalcon_array_append(¶meters, local, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(parameters); - array_init_size(parameters, 2); - phalcon_array_append(¶meters, prefixed_path, PH_SEPARATE); - phalcon_array_append(¶meters, local, PH_SEPARATE); - } + case 3: + PHALCON_INIT_VAR(scale); + phalcon_call_method_key(scale, column, "getscale", 4211231149UL); - PHALCON_INIT_NVAR(html); - PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters); + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVSVS(column_sql, "DECIMAL(", size, ",", scale, ")"); - if (zend_is_true(use_implicit_output)) { - zend_print_zval(html, 0); - } else { - phalcon_concat_self(&output, html TSRMLS_CC); + PHALCON_INIT_NVAR(is_unsigned); + phalcon_call_method_key(is_unsigned, column, "isunsigned", 3241495646UL); + if (zend_is_true(is_unsigned)) { + phalcon_concat_self_str(&column_sql, SL(" UNSIGNED") TSRMLS_CC); } - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - - if (zend_is_true(filter_needed)) { - - PHALCON_INIT_NVAR(content); - phalcon_call_method_p1_key(content, resource, "getcontent", complete_source_path, 3141446400UL); - - PHALCON_INIT_NVAR(must_filter); - phalcon_call_method_key(must_filter, resource, "getfilter", 2170608779UL); - - if (zend_is_true(must_filter)) { - - phalcon_is_iterable(filters, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(filter); + break; - if (Z_TYPE_P(filter) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Filter is invalid"); - return; - } + case 4: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "DATETIME", 1); + break; - PHALCON_INIT_NVAR(filtered_content); - phalcon_call_method_p1_key(filtered_content, filter, "filter", content, 2890214155UL); + case 5: + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVS(column_sql, "CHAR(", size, ")"); + break; - if (zend_is_true(join)) { - if (Z_TYPE_P(filtered_joined_content) == IS_NULL) { - PHALCON_INIT_NVAR(filtered_joined_content); - PHALCON_CONCAT_VS(filtered_joined_content, filtered_content, ";"); - } else { - PHALCON_SCONCAT_VS(filtered_joined_content, filtered_content, ";"); - } - } + case 6: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "TEXT", 1); + break; - zend_hash_move_forward_ex(ah1, &hp1); - } + case 7: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "FLOAT", 1); - } else { - if (zend_is_true(join)) { - if (Z_TYPE_P(filtered_joined_content) == IS_NULL) { - PHALCON_CPY_WRT(filtered_joined_content, content); - } else { - phalcon_concat_self(&filtered_joined_content, content TSRMLS_CC); - } + PHALCON_INIT_NVAR(scale); + phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + if (zend_is_true(size)) { + PHALCON_SCONCAT_SV(column_sql, "(", size); + if (zend_is_true(scale)) { + PHALCON_SCONCAT_SVS(column_sql, ",", scale, ")"); } else { - PHALCON_CPY_WRT(filtered_content, content); + phalcon_concat_self_str(&column_sql, SL(")") TSRMLS_CC); } } - if (!zend_is_true(join)) { - phalcon_file_put_contents(NULL, target_path, filtered_content TSRMLS_CC); - } - } - - if (!zend_is_true(join)) { - - PHALCON_INIT_NVAR(path); - phalcon_call_method_key(path, resource, "getrealtargeturi", 4137962752UL); - if (Z_TYPE_P(prefix) != IS_NULL) { - PHALCON_INIT_NVAR(prefixed_path); - PHALCON_CONCAT_VV(prefixed_path, prefix, path); - } else { - PHALCON_CPY_WRT(prefixed_path, path); - } - - PHALCON_INIT_NVAR(attributes); - phalcon_call_method_key(attributes, resource, "getattributes", 1013165772UL); - - PHALCON_INIT_NVAR(local); - ZVAL_BOOL(local, 1); - - if (Z_TYPE_P(attributes) == IS_ARRAY) { - phalcon_array_update_long(&attributes, 0, &prefixed_path, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_NVAR(parameters); - array_init_size(parameters, 2); - phalcon_array_append(¶meters, attributes, PH_SEPARATE); - phalcon_array_append(¶meters, local, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(parameters); - array_init_size(parameters, 2); - phalcon_array_append(¶meters, prefixed_path, PH_SEPARATE); - phalcon_array_append(¶meters, local, PH_SEPARATE); - } - - PHALCON_INIT_NVAR(html); - PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters); - - if (zend_is_true(use_implicit_output)) { - zend_print_zval(html, 0); - } else { - phalcon_concat_self(&output, html TSRMLS_CC); - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - if (Z_TYPE_P(filters) == IS_ARRAY) { - if (zend_is_true(join)) { - - phalcon_file_put_contents(NULL, complete_target_path, filtered_joined_content TSRMLS_CC); - - PHALCON_INIT_VAR(target_uri); - phalcon_call_method_key(target_uri, collection, "gettargeturi", 876359612UL); - if (Z_TYPE_P(prefix) != IS_NULL) { - PHALCON_INIT_NVAR(prefixed_path); - PHALCON_CONCAT_VV(prefixed_path, prefix, target_uri); - } else { - PHALCON_CPY_WRT(prefixed_path, target_uri); + PHALCON_INIT_NVAR(is_unsigned); + phalcon_call_method_key(is_unsigned, column, "isunsigned", 3241495646UL); + if (zend_is_true(is_unsigned)) { + phalcon_concat_self_str(&column_sql, SL(" UNSIGNED") TSRMLS_CC); } - PHALCON_INIT_NVAR(attributes); - phalcon_call_method_key(attributes, collection, "getattributes", 1013165772UL); - - PHALCON_INIT_NVAR(local); - ZVAL_BOOL(local, 1); - - if (Z_TYPE_P(attributes) == IS_ARRAY) { - phalcon_array_update_long(&attributes, 0, &prefixed_path, PH_COPY | PH_SEPARATE); + break; - PHALCON_INIT_NVAR(parameters); - array_init_size(parameters, 2); - phalcon_array_append(¶meters, attributes, PH_SEPARATE); - phalcon_array_append(¶meters, local, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(parameters); - array_init_size(parameters, 2); - phalcon_array_append(¶meters, prefixed_path, PH_SEPARATE); - phalcon_array_append(¶meters, local, PH_SEPARATE); - } + case 8: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "TINYINT(1)", 1); + break; - PHALCON_INIT_NVAR(html); - PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters); + default: + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized MySQL data type"); + return; - if (zend_is_true(use_implicit_output)) { - zend_print_zval(html, 0); - } else { - phalcon_concat_self(&output, html TSRMLS_CC); - } - } } - RETURN_CCTOR(output); + RETURN_CTOR(column_sql); } -static PHP_METHOD(Phalcon_Assets_Manager, outputCss){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addColumn){ - zval *collection_name = NULL, *collection = NULL, *callback; - zval *output; + zval *table_name, *schema_name, *column, *sql = NULL, *name; + zval *column_definition, *is_not_null, *is_first; + zval *after_position; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &collection_name); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); - if (!collection_name) { - PHALCON_INIT_VAR(collection_name); + if (Z_TYPE_P(column) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column parameter must be an instance of Phalcon\\Db\\Column"); + return; } - - if (PHALCON_IS_EMPTY(collection_name)) { - PHALCON_INIT_VAR(collection); - phalcon_call_method_key(collection, this_ptr, "getcss", 4034032270UL); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD "); } else { - PHALCON_INIT_NVAR(collection); - phalcon_call_method_p1_key(collection, this_ptr, "get", collection_name, 2090288933UL); + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD "); } - PHALCON_INIT_VAR(callback); - array_init_size(callback, 2); - add_next_index_stringl(callback, SL("Phalcon\\Tag"), 1); - add_next_index_stringl(callback, SL("stylesheetLink"), 1); + PHALCON_INIT_VAR(name); + phalcon_call_method_key(name, column, "getname", 4286441094UL); - PHALCON_INIT_VAR(output); - phalcon_call_method_p2_key(output, this_ptr, "output", collection, callback, 2107509814UL); + PHALCON_INIT_VAR(column_definition); + phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); + PHALCON_SCONCAT_SVSV(sql, "`", name, "` ", column_definition); - RETURN_CCTOR(output); + PHALCON_INIT_VAR(is_not_null); + phalcon_call_method_key(is_not_null, column, "isnotnull", 760409005UL); + if (zend_is_true(is_not_null)) { + phalcon_concat_self_str(&sql, SL(" NOT NULL") TSRMLS_CC); + } + + PHALCON_INIT_VAR(is_first); + phalcon_call_method_key(is_first, column, "isfirst", 3971456361UL); + if (zend_is_true(is_first)) { + phalcon_concat_self_str(&sql, SL(" FIRST") TSRMLS_CC); + } else { + PHALCON_INIT_VAR(after_position); + phalcon_call_method_key(after_position, column, "getafterposition", 4273952076UL); + if (zend_is_true(after_position)) { + PHALCON_SCONCAT_SV(sql, " AFTER ", after_position); + } + } + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Manager, outputJs){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, modifyColumn){ - zval *collection_name = NULL, *collection = NULL, *callback; - zval *output; + zval *table_name, *schema_name, *column, *sql = NULL, *name; + zval *column_definition, *is_not_null; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &collection_name); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); - if (!collection_name) { - PHALCON_INIT_VAR(collection_name); + if (Z_TYPE_P(column) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column parameter must be an instance of Phalcon\\Db\\Column"); + return; } - - if (PHALCON_IS_EMPTY(collection_name)) { - PHALCON_INIT_VAR(collection); - phalcon_call_method_key(collection, this_ptr, "getjs", 4287067682UL); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` MODIFY "); } else { - PHALCON_INIT_NVAR(collection); - phalcon_call_method_p1_key(collection, this_ptr, "get", collection_name, 2090288933UL); + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` MODIFY "); } - PHALCON_INIT_VAR(callback); - array_init_size(callback, 2); - add_next_index_stringl(callback, SL("Phalcon\\Tag"), 1); - add_next_index_stringl(callback, SL("javascriptInclude"), 1); + PHALCON_INIT_VAR(name); + phalcon_call_method_key(name, column, "getname", 4286441094UL); - PHALCON_INIT_VAR(output); - phalcon_call_method_p2_key(output, this_ptr, "output", collection, callback, 2107509814UL); + PHALCON_INIT_VAR(column_definition); + phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); + PHALCON_SCONCAT_SVSV(sql, "`", name, "` ", column_definition); - RETURN_CCTOR(output); + PHALCON_INIT_VAR(is_not_null); + phalcon_call_method_key(is_not_null, column, "isnotnull", 760409005UL); + if (zend_is_true(is_not_null)) { + phalcon_concat_self_str(&sql, SL(" NOT NULL") TSRMLS_CC); + } + + RETURN_CTOR(sql); } +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropColumn){ + zval *table_name, *schema_name, *column_name; + zval *sql = NULL; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Assets_Resource){ - - PHALCON_REGISTER_CLASS(Phalcon\\Assets, Resource, assets_resource, phalcon_assets_resource_method_entry, 0); - - zend_declare_property_null(phalcon_assets_resource_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_resource_ce, SL("_path"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_resource_ce, SL("_local"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_resource_ce, SL("_filter"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_resource_ce, SL("_attributes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_resource_ce, SL("_sourcePath"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_resource_ce, SL("_targetPath"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_resource_ce, SL("_targetUri"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column_name); + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` DROP COLUMN "); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` DROP COLUMN "); + } + PHALCON_SCONCAT_SVS(sql, "`", column_name, "`"); + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Resource, __construct){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addIndex){ - zval *type, *path, *local = NULL, *filter = NULL, *attributes = NULL; + zval *table_name, *schema_name, *index, *sql = NULL, *columns; + zval *quoted_column_list, *name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 3, &type, &path, &local, &filter, &attributes); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); + if (Z_TYPE_P(index) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Index parameter must be an instance of Phalcon\\Db\\Index"); + return; } - - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD INDEX "); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD INDEX "); } - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } + PHALCON_INIT_VAR(columns); + phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_path"), path, 3986357393UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_local"), local, 2560221423UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); - if (Z_TYPE_P(attributes) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC); - } + PHALCON_INIT_VAR(quoted_column_list); + phalcon_call_method_p1_key(quoted_column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Assets_Resource, setType){ - - zval *type; - - phalcon_fetch_params(0, 1, 0, &type); + PHALCON_INIT_VAR(name); + phalcon_call_method_key(name, index, "getname", 4286441094UL); + PHALCON_SCONCAT_SVSVS(sql, "`", name, "` (", quoted_column_list, ")"); - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - RETURN_THISW(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Resource, getType){ - - - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); -} +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropIndex){ -static PHP_METHOD(Phalcon_Assets_Resource, setPath){ + zval *table_name, *schema_name, *index_name; + zval *sql = NULL; - zval *path; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &path); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index_name); - phalcon_update_property_this_quick(this_ptr, SL("_path"), path, 3986357393UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Resource, getPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_path", 3986357393UL); -} - -static PHP_METHOD(Phalcon_Assets_Resource, setLocal){ - - zval *local; - - phalcon_fetch_params(0, 1, 0, &local); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` DROP INDEX "); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` DROP INDEX "); + } + PHALCON_SCONCAT_SVS(sql, "`", index_name, "`"); - phalcon_update_property_this_quick(this_ptr, SL("_local"), local, 2560221423UL TSRMLS_CC); - RETURN_THISW(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Resource, getLocal){ - - - RETURN_MEMBER_QUICK(this_ptr, "_local", 2560221423UL); -} +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addPrimaryKey){ -static PHP_METHOD(Phalcon_Assets_Resource, setFilter){ + zval *table_name, *schema_name, *index, *sql = NULL, *columns; + zval *column_list; - zval *filter; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &filter); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); - phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Resource, getFilter){ - - - RETURN_MEMBER_QUICK(this_ptr, "_filter", 3500594986UL); -} - -static PHP_METHOD(Phalcon_Assets_Resource, setAttributes){ - - zval *attributes; - - phalcon_fetch_params(0, 1, 0, &attributes); + if (Z_TYPE_P(index) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Index parameter must be an instance of Phalcon\\Db\\Index"); + return; + } + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD PRIMARY KEY "); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD PRIMARY KEY "); + } - phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Resource, getAttributes){ - - - RETURN_MEMBER_QUICK(this_ptr, "_attributes", 1565778155UL); -} - -static PHP_METHOD(Phalcon_Assets_Resource, setTargetUri){ - - zval *target_uri; - - phalcon_fetch_params(0, 1, 0, &target_uri); + PHALCON_INIT_VAR(columns); + phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); - phalcon_update_property_this_quick(this_ptr, SL("_targetUri"), target_uri, 2193460699UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Resource, getTargetUri){ - - - RETURN_MEMBER_QUICK(this_ptr, "_targetUri", 2193460699UL); -} - -static PHP_METHOD(Phalcon_Assets_Resource, setSourcePath){ - - zval *source_path; - - phalcon_fetch_params(0, 1, 0, &source_path); + PHALCON_INIT_VAR(column_list); + phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); + PHALCON_SCONCAT_SVS(sql, "(", column_list, ")"); - phalcon_update_property_this_quick(this_ptr, SL("_sourcePath"), source_path, 1419415746UL TSRMLS_CC); - RETURN_THISW(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Resource, getSourcePath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_targetPath", 3658201208UL); -} +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropPrimaryKey){ -static PHP_METHOD(Phalcon_Assets_Resource, setTargetPath){ + zval *table_name, *schema_name, *sql = NULL; - zval *target_path; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &target_path); + phalcon_fetch_params(1, 2, 0, &table_name, &schema_name); - phalcon_update_property_this_quick(this_ptr, SL("_targetPath"), target_path, 3658201208UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Resource, getTargetPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_sourcePath", 1419415746UL); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` DROP PRIMARY KEY"); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` DROP PRIMARY KEY"); + } + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Resource, getContent){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addForeignKey){ - zval *base_path = NULL, *source_path = NULL, *complete_path; - zval *local, *exception_message = NULL, *content; + zval *table_name, *schema_name, *reference, *sql = NULL; + zval *columns, *quoted_column_list, *reference_name; + zval *referenced_schema, *referenced_columns; + zval *quoted_columns, *referenced_table; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &base_path); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference); - if (!base_path) { - PHALCON_INIT_VAR(base_path); + if (Z_TYPE_P(reference) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Reference parameter must be an instance of Phalcon\\Db\\Reference"); + return; } - - PHALCON_OBS_VAR(source_path); - phalcon_read_property_this_quick(&source_path, this_ptr, SL("_sourcePath"), 1419415746UL, PH_NOISY_CC); - if (PHALCON_IS_EMPTY(source_path)) { - PHALCON_OBS_NVAR(source_path); - phalcon_read_property_this_quick(&source_path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD FOREIGN KEY "); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD FOREIGN KEY "); } - PHALCON_INIT_VAR(complete_path); - PHALCON_CONCAT_VV(complete_path, base_path, source_path); + PHALCON_INIT_VAR(columns); + phalcon_call_method_key(columns, reference, "getcolumns", 3064648998UL); - PHALCON_OBS_VAR(local); - phalcon_read_property_this_quick(&local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC); + PHALCON_INIT_VAR(quoted_column_list); + phalcon_call_method_p1_key(quoted_column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); - if (zend_is_true(local)) { + PHALCON_INIT_VAR(reference_name); + phalcon_call_method_key(reference_name, reference, "getname", 4286441094UL); + PHALCON_SCONCAT_SVSVS(sql, "`", reference_name, "`(", quoted_column_list, ") REFERENCES "); - if (phalcon_file_exists(complete_path TSRMLS_CC) == FAILURE) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource's content for \"", complete_path, "\" cannot be loaded"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } + PHALCON_INIT_VAR(referenced_schema); + phalcon_call_method_key(referenced_schema, reference, "getreferencedschema", 1586168905UL); + if (zend_is_true(referenced_schema)) { + PHALCON_SCONCAT_SVS(sql, "`", referenced_schema, "`."); } - PHALCON_INIT_VAR(content); - phalcon_file_get_contents(content, complete_path TSRMLS_CC); - if (PHALCON_IS_FALSE(content)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource's content for \"", complete_path, "\" cannot be read"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } + PHALCON_INIT_VAR(referenced_columns); + phalcon_call_method_key(referenced_columns, reference, "getreferencedcolumns", 301959449UL); - RETURN_CCTOR(content); + PHALCON_INIT_VAR(quoted_columns); + phalcon_call_method_p1_key(quoted_columns, this_ptr, "getcolumnlist", referenced_columns, 2735238095UL); + + PHALCON_INIT_VAR(referenced_table); + phalcon_call_method_key(referenced_table, reference, "getreferencedtable", 735373536UL); + PHALCON_SCONCAT_SVSVS(sql, "`", referenced_table, "`(", quoted_columns, ")"); + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Resource, getRealTargetUri){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropForeignKey){ - zval *target_uri = NULL; + zval *table_name, *schema_name, *reference_name; + zval *sql = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(target_uri); - phalcon_read_property_this_quick(&target_uri, this_ptr, SL("_targetUri"), 2193460699UL, PH_NOISY_CC); - if (PHALCON_IS_EMPTY(target_uri)) { - PHALCON_OBS_NVAR(target_uri); - phalcon_read_property_this_quick(&target_uri, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference_name); + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` DROP FOREIGN KEY "); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` DROP FOREIGN KEY "); } + PHALCON_SCONCAT_SVS(sql, "`", reference_name, "`"); - RETURN_CCTOR(target_uri); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Resource, getRealSourcePath){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, _getTableOptions){ - zval *base_path = NULL, *source_path = NULL, *local, *complete_path; + zval *definition, *table_options, *options, *engine; + zval *sql_engine, *auto_increment, *sql_autoincrement; + zval *table_collation, *collation_parts, *first_part; + zval *sql_charset, *sql_collate, *sql_table_options; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &base_path); + phalcon_fetch_params(1, 1, 0, &definition); - if (!base_path) { - PHALCON_INIT_VAR(base_path); - } + if (phalcon_array_isset_quick_string(definition, SS("options"), 2952422065UL)) { - PHALCON_OBS_VAR(source_path); - phalcon_read_property_this_quick(&source_path, this_ptr, SL("_sourcePath"), 1419415746UL, PH_NOISY_CC); - if (PHALCON_IS_EMPTY(source_path)) { - PHALCON_OBS_NVAR(source_path); - phalcon_read_property_this_quick(&source_path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); - } + PHALCON_INIT_VAR(table_options); + array_init(table_options); - PHALCON_OBS_VAR(local); - phalcon_read_property_this_quick(&local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC); - if (zend_is_true(local)) { - PHALCON_INIT_VAR(complete_path); - PHALCON_CONCAT_VV(complete_path, base_path, source_path); + PHALCON_OBS_VAR(options); + phalcon_array_fetch_quick_string(&options, definition, SS("options"), 2952422065UL, PH_NOISY); - phalcon_call_func_p1(return_value, "realpath", complete_path); - RETURN_MM(); - } + if (phalcon_array_isset_quick_string(options, SS("ENGINE"), 2119337627UL)) { - RETURN_CCTOR(source_path); -} - -static PHP_METHOD(Phalcon_Assets_Resource, getRealTargetPath){ - - zval *base_path = NULL, *target_path = NULL, *local, *complete_path; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &base_path); + PHALCON_OBS_VAR(engine); + phalcon_array_fetch_quick_string(&engine, options, SS("ENGINE"), 2119337627UL, PH_NOISY); + if (zend_is_true(engine)) { + PHALCON_INIT_VAR(sql_engine); + PHALCON_CONCAT_SV(sql_engine, "ENGINE=", engine); + phalcon_array_append(&table_options, sql_engine, PH_SEPARATE); + } + } - if (!base_path) { - PHALCON_INIT_VAR(base_path); - } + if (phalcon_array_isset_quick_string(options, SS("AUTO_INCREMENT"), 656925090UL)) { - PHALCON_OBS_VAR(target_path); - phalcon_read_property_this_quick(&target_path, this_ptr, SL("_targetPath"), 3658201208UL, PH_NOISY_CC); - if (PHALCON_IS_EMPTY(target_path)) { - PHALCON_OBS_NVAR(target_path); - phalcon_read_property_this_quick(&target_path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); - } + PHALCON_OBS_VAR(auto_increment); + phalcon_array_fetch_quick_string(&auto_increment, options, SS("AUTO_INCREMENT"), 656925090UL, PH_NOISY); + if (zend_is_true(auto_increment)) { + PHALCON_INIT_VAR(sql_autoincrement); + PHALCON_CONCAT_SV(sql_autoincrement, "AUTO_INCREMENT=", auto_increment); + phalcon_array_append(&table_options, sql_autoincrement, PH_SEPARATE); + } + } - PHALCON_OBS_VAR(local); - phalcon_read_property_this_quick(&local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC); - if (zend_is_true(local)) { + if (phalcon_array_isset_quick_string(options, SS("TABLE_COLLATION"), 1457306353UL)) { - PHALCON_INIT_VAR(complete_path); - PHALCON_CONCAT_VV(complete_path, base_path, target_path); + PHALCON_OBS_VAR(table_collation); + phalcon_array_fetch_quick_string(&table_collation, options, SS("TABLE_COLLATION"), 1457306353UL, PH_NOISY); + if (zend_is_true(table_collation)) { + PHALCON_INIT_VAR(collation_parts); + phalcon_fast_explode_str(collation_parts, SL("_"), table_collation); - if (phalcon_file_exists(complete_path TSRMLS_CC) == SUCCESS) { - phalcon_call_func_p1(return_value, "realpath", complete_path); - RETURN_MM(); + PHALCON_OBS_VAR(first_part); + phalcon_array_fetch_long(&first_part, collation_parts, 0, PH_NOISY); + + PHALCON_INIT_VAR(sql_charset); + PHALCON_CONCAT_SV(sql_charset, "DEFAULT CHARSET=", first_part); + phalcon_array_append(&table_options, sql_charset, PH_SEPARATE); + + PHALCON_INIT_VAR(sql_collate); + PHALCON_CONCAT_SV(sql_collate, "COLLATE=", table_collation); + phalcon_array_append(&table_options, sql_collate, PH_SEPARATE); + } } - RETURN_CTOR(complete_path); + if (phalcon_fast_count_ev(table_options TSRMLS_CC)) { + PHALCON_INIT_VAR(sql_table_options); + phalcon_fast_join_str(sql_table_options, SL(" "), table_options TSRMLS_CC); + RETURN_CTOR(sql_table_options); + } } - - RETURN_CCTOR(target_path); + RETURN_MM_NULL(); } +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, createTable){ + zval *table_name, *schema_name, *definition; + zval *table = NULL, *temporary = NULL, *options = NULL, *sql = NULL, *create_lines; + zval *columns = NULL, *column = NULL, *column_name = NULL, *column_definition = NULL; + zval *column_line = NULL, *attribute = NULL, *indexes, *index = NULL; + zval *index_name = NULL, *column_list = NULL, *index_sql = NULL, *references; + zval *reference = NULL, *name = NULL, *referenced_table = NULL, *referenced_columns = NULL; + zval *constaint_sql = NULL, *reference_sql = NULL, *joined_lines; + HashTable *ah0, *ah1, *ah2; + HashPosition hp0, hp1, hp2; + zval **hd; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Assets_Collection){ - - PHALCON_REGISTER_CLASS(Phalcon\\Assets, Collection, assets_collection, phalcon_assets_collection_method_entry, 0); - - zend_declare_property_null(phalcon_assets_collection_ce, SL("_prefix"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_assets_collection_ce, SL("_local"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_collection_ce, SL("_resources"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_collection_ce, SL("_position"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_collection_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_collection_ce, SL("_attributes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_assets_collection_ce, SL("_join"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_collection_ce, SL("_targetUri"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_collection_ce, SL("_targetPath"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_assets_collection_ce, SL("_sourcePath"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_assets_collection_ce TSRMLS_CC, 2, spl_ce_Countable, zend_ce_iterator); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Assets_Collection, add){ - - zval *resource; - - phalcon_fetch_params(0, 1, 0, &resource); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &definition); - if (Z_TYPE_P(resource) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Resource must be an object"); + if (!phalcon_array_isset_quick_string(definition, SS("columns"), 1041822630UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'columns' is required in the definition array"); return; } - phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(table); + PHALCON_CONCAT_SVSVS(table, "`", schema_name, "`.`", table_name, "`"); + } else { + PHALCON_INIT_NVAR(table); + PHALCON_CONCAT_SVS(table, "`", table_name, "`"); + } - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Collection, addCss){ - - zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *collection_local = NULL; - zval *collection_attributes = NULL, *resource; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); + PHALCON_INIT_VAR(temporary); + ZVAL_BOOL(temporary, 0); + if (phalcon_array_isset_quick_string(definition, SS("options"), 2952422065UL)) { - if (!local) { - PHALCON_INIT_VAR(local); + PHALCON_OBS_VAR(options); + phalcon_array_fetch_quick_string(&options, definition, SS("options"), 2952422065UL, PH_NOISY); + if (phalcon_array_isset_quick_string(options, SS("temporary"), 1346706536UL)) { + PHALCON_OBS_NVAR(temporary); + phalcon_array_fetch_quick_string(&temporary, options, SS("temporary"), 1346706536UL, PH_NOISY); + } } - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); + if (zend_is_true(temporary)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "CREATE TEMPORARY TABLE ", table, " (\n\t"); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "CREATE TABLE ", table, " (\n\t"); } - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } + PHALCON_INIT_VAR(create_lines); + array_init(create_lines); - if (Z_TYPE_P(local) == IS_BOOL) { - PHALCON_CPY_WRT(collection_local, local); - } else { - PHALCON_OBS_NVAR(collection_local); - phalcon_read_property_this_quick(&collection_local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC); + PHALCON_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); + + phalcon_is_iterable(columns, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(column); + + PHALCON_INIT_NVAR(column_name); + phalcon_call_method_key(column_name, column, "getname", 4286441094UL); + + PHALCON_INIT_NVAR(column_definition); + phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); + + PHALCON_INIT_NVAR(column_line); + PHALCON_CONCAT_SVSV(column_line, "`", column_name, "` ", column_definition); + + PHALCON_INIT_NVAR(attribute); + phalcon_call_method_key(attribute, column, "isnotnull", 760409005UL); + if (zend_is_true(attribute)) { + phalcon_concat_self_str(&column_line, SL(" NOT NULL") TSRMLS_CC); + } + + PHALCON_INIT_NVAR(attribute); + phalcon_call_method_key(attribute, column, "isautoincrement", 572890271UL); + if (zend_is_true(attribute)) { + phalcon_concat_self_str(&column_line, SL(" AUTO_INCREMENT") TSRMLS_CC); + } + + PHALCON_INIT_NVAR(attribute); + phalcon_call_method_key(attribute, column, "isprimary", 3539965925UL); + if (zend_is_true(attribute)) { + phalcon_concat_self_str(&column_line, SL(" PRIMARY KEY") TSRMLS_CC); + } + + phalcon_array_append(&create_lines, column_line, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } - if (Z_TYPE_P(attributes) == IS_ARRAY) { - PHALCON_CPY_WRT(collection_attributes, attributes); - } else { - PHALCON_OBS_NVAR(collection_attributes); - phalcon_read_property_this_quick(&collection_attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); + + if (phalcon_array_isset_quick_string(definition, SS("indexes"), 1726269685UL)) { + + PHALCON_OBS_VAR(indexes); + phalcon_array_fetch_quick_string(&indexes, definition, SS("indexes"), 1726269685UL, PH_NOISY); + + phalcon_is_iterable(indexes, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(index); + + PHALCON_INIT_NVAR(index_name); + phalcon_call_method_key(index_name, index, "getname", 4286441094UL); + + PHALCON_INIT_NVAR(columns); + phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); + + PHALCON_INIT_NVAR(column_list); + phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); + + if (PHALCON_IS_STRING(index_name, "PRIMARY")) { + PHALCON_INIT_NVAR(index_sql); + PHALCON_CONCAT_SVS(index_sql, "PRIMARY KEY (", column_list, ")"); + } else { + PHALCON_INIT_NVAR(index_sql); + PHALCON_CONCAT_SVSVS(index_sql, "KEY `", index_name, "` (", column_list, ")"); + } + + phalcon_array_append(&create_lines, index_sql, PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); + } + } - PHALCON_INIT_VAR(resource); - object_init_ex(resource, phalcon_assets_resource_css_ce); - phalcon_call_method_p4_key(NULL, resource, "__construct", path, collection_local, filter, collection_attributes, 1107214344UL); + if (phalcon_array_isset_quick_string(definition, SS("references"), 3245500135UL)) { - phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC); + PHALCON_OBS_VAR(references); + phalcon_array_fetch_quick_string(&references, definition, SS("references"), 3245500135UL, PH_NOISY); - RETURN_THIS(); + phalcon_is_iterable(references, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HVALUE(reference); + + PHALCON_INIT_NVAR(name); + phalcon_call_method_key(name, reference, "getname", 4286441094UL); + + PHALCON_INIT_NVAR(columns); + phalcon_call_method_key(columns, reference, "getcolumns", 3064648998UL); + + PHALCON_INIT_NVAR(column_list); + phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); + + PHALCON_INIT_NVAR(referenced_table); + phalcon_call_method_key(referenced_table, reference, "getreferencedtable", 735373536UL); + + PHALCON_INIT_NVAR(referenced_columns); + phalcon_call_method_key(referenced_columns, reference, "getreferencedcolumns", 301959449UL); + + PHALCON_INIT_NVAR(column_list); + phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", referenced_columns, 2735238095UL); + + PHALCON_INIT_NVAR(constaint_sql); + PHALCON_CONCAT_SVSVS(constaint_sql, "CONSTRAINT `", name, "` FOREIGN KEY (", column_list, ")"); + + PHALCON_INIT_NVAR(reference_sql); + PHALCON_CONCAT_VSVSVS(reference_sql, constaint_sql, " REFERENCES `", referenced_table, "`(", column_list, ")"); + phalcon_array_append(&create_lines, reference_sql, PH_SEPARATE); + + zend_hash_move_forward_ex(ah2, &hp2); + } + + } + + PHALCON_INIT_VAR(joined_lines); + phalcon_fast_join_str(joined_lines, SL(",\n\t"), create_lines TSRMLS_CC); + PHALCON_SCONCAT_VS(sql, joined_lines, "\n)"); + if (phalcon_array_isset_quick_string(definition, SS("options"), 2952422065UL)) { + PHALCON_INIT_NVAR(options); + phalcon_call_method_p1_key(options, this_ptr, "_gettableoptions", definition, 2455363768UL); + PHALCON_SCONCAT_SV(sql, " ", options); + } + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Collection, addJs){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropTable){ - zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *collection_local = NULL; - zval *collection_attributes = NULL, *resource; + zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; + zval *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); - - if (!local) { - PHALCON_INIT_VAR(local); - } - - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); - } + phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); - if (!attributes) { - PHALCON_INIT_VAR(attributes); + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); } - if (Z_TYPE_P(local) == IS_BOOL) { - PHALCON_CPY_WRT(collection_local, local); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(table); + PHALCON_CONCAT_SVSVS(table, "`", schema_name, "`.`", table_name, "`"); } else { - PHALCON_OBS_NVAR(collection_local); - phalcon_read_property_this_quick(&collection_local, this_ptr, SL("_local"), 2560221423UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(table); + PHALCON_CONCAT_SVS(table, "`", table_name, "`"); } - if (Z_TYPE_P(attributes) == IS_ARRAY) { - PHALCON_CPY_WRT(collection_attributes, attributes); + if (zend_is_true(if_exists)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SV(sql, "DROP TABLE IF EXISTS ", table); } else { - PHALCON_OBS_NVAR(collection_attributes); - phalcon_read_property_this_quick(&collection_attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SV(sql, "DROP TABLE ", table); } - PHALCON_INIT_VAR(resource); - object_init_ex(resource, phalcon_assets_resource_js_ce); - phalcon_call_method_p4_key(NULL, resource, "__construct", path, collection_local, filter, collection_attributes, 1107214344UL); - - phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC); - - RETURN_THIS(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Collection, getResources){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, createView){ - zval *resources; + zval *view_name, *definition, *schema_name, *view_sql; + zval *view = NULL, *sql; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(resources); - phalcon_read_property_this_quick(&resources, this_ptr, SL("_resources"), 3320036063UL, PH_NOISY_CC); - if (Z_TYPE_P(resources) != IS_ARRAY) { - RETURN_MM_EMPTY_ARRAY(); + phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); + + if (!phalcon_array_isset_quick_string(definition, SS("sql"), 2090732981UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'sql' is required in the definition array"); + return; } - RETURN_CCTOR(resources); + PHALCON_OBS_VAR(view_sql); + phalcon_array_fetch_quick_string(&view_sql, definition, SS("sql"), 2090732981UL, PH_NOISY); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(view); + PHALCON_CONCAT_SVSVS(view, "`", schema_name, "`.`", view_name, "`"); + } else { + PHALCON_INIT_NVAR(view); + PHALCON_CONCAT_SVS(view, "`", view_name, "`"); + } + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Collection, count){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropView){ - zval *resources; + zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; + zval *sql = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(resources); - phalcon_read_property_this_quick(&resources, this_ptr, SL("_resources"), 3320036063UL, PH_NOISY_CC); - phalcon_fast_count(return_value, resources TSRMLS_CC); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Assets_Collection, rewind){ - - - phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC); + phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); + + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); + } + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(view); + PHALCON_CONCAT_VSV(view, schema_name, ".", view_name); + } else { + PHALCON_CPY_WRT(view, view_name); + } + if (zend_is_true(if_exists)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SV(sql, "DROP VIEW IF EXISTS ", view); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SV(sql, "DROP VIEW ", view); + } + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Collection, current){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableExists){ - zval *position, *resources, *resource; + zval *table_name, *schema_name = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - PHALCON_OBS_VAR(resources); - phalcon_read_property_this_quick(&resources, this_ptr, SL("_resources"), 3320036063UL, PH_NOISY_CC); - if (phalcon_array_isset(resources, position)) { - PHALCON_OBS_VAR(resource); - phalcon_array_fetch(&resource, resources, position, PH_NOISY); - RETURN_CCTOR(resource); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Assets_Collection, key){ - - - RETURN_MEMBER_QUICK(this_ptr, "_position", 2925265369UL); -} - -static PHP_METHOD(Phalcon_Assets_Collection, next){ - - - phalcon_property_incr(this_ptr, SL("_position") TSRMLS_CC); + if (zend_is_true(schema_name)) { + PHALCON_CONCAT_SVSVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`= '", table_name, "' AND `TABLE_SCHEMA`='", schema_name, "'"); + RETURN_MM(); + } + PHALCON_CONCAT_SVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`='", table_name, "'"); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Assets_Collection, valid){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, viewExists){ - zval *position, *resources; + zval *view_name, *schema_name = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - PHALCON_OBS_VAR(resources); - phalcon_read_property_this_quick(&resources, this_ptr, SL("_resources"), 3320036063UL, PH_NOISY_CC); - if (phalcon_array_isset(resources, position)) { - RETURN_MM_TRUE; + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Assets_Collection, setTargetPath){ - - zval *target_path; - - phalcon_fetch_params(0, 1, 0, &target_path); + if (zend_is_true(schema_name)) { + PHALCON_CONCAT_SVSVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE `TABLE_NAME`= '", view_name, "' AND `TABLE_SCHEMA`='", schema_name, "'"); + RETURN_MM(); + } + PHALCON_CONCAT_SVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE `TABLE_NAME`='", view_name, "'"); - phalcon_update_property_this_quick(this_ptr, SL("_targetPath"), target_path, 3658201208UL TSRMLS_CC); - RETURN_THISW(); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Assets_Collection, getTargetPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_targetPath", 3658201208UL); -} +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeColumns){ -static PHP_METHOD(Phalcon_Assets_Collection, setSourcePath){ + zval *table, *schema = NULL; - zval *source_path; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &source_path); + phalcon_fetch_params(1, 1, 1, &table, &schema); - phalcon_update_property_this_quick(this_ptr, SL("_sourcePath"), source_path, 1419415746UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Collection, getSourcePath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_sourcePath", 1419415746UL); -} - -static PHP_METHOD(Phalcon_Assets_Collection, setTargetUri){ - - zval *target_uri; - - phalcon_fetch_params(0, 1, 0, &target_uri); + if (!schema) { + PHALCON_INIT_VAR(schema); + } - phalcon_update_property_this_quick(this_ptr, SL("_targetUri"), target_uri, 2193460699UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Collection, getTargetUri){ - - - RETURN_MEMBER_QUICK(this_ptr, "_targetUri", 2193460699UL); -} - -static PHP_METHOD(Phalcon_Assets_Collection, setPrefix){ - - zval *prefix; - - phalcon_fetch_params(0, 1, 0, &prefix); + if (zend_is_true(schema)) { + PHALCON_CONCAT_SVSVS(return_value, "DESCRIBE `", schema, "`.`", table, "`"); + RETURN_MM(); + } + PHALCON_CONCAT_SVS(return_value, "DESCRIBE `", table, "`"); - phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); - RETURN_THISW(); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Assets_Collection, getPrefix){ - - - RETURN_MEMBER_QUICK(this_ptr, "_prefix", 3873791314UL); -} +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, listTables){ -static PHP_METHOD(Phalcon_Assets_Collection, setLocal){ + zval *schema_name = NULL; - zval *local; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &local); + phalcon_fetch_params(1, 0, 1, &schema_name); - phalcon_update_property_this_quick(this_ptr, SL("_local"), local, 2560221423UL TSRMLS_CC); - RETURN_THISW(); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + if (zend_is_true(schema_name)) { + PHALCON_CONCAT_SVS(return_value, "SHOW TABLES FROM `", schema_name, "`"); + RETURN_MM(); + } + RETURN_MM_STRING("SHOW TABLES", 1); } -static PHP_METHOD(Phalcon_Assets_Collection, getLocal){ - - - RETURN_MEMBER_QUICK(this_ptr, "_local", 2560221423UL); -} +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, listViews){ -static PHP_METHOD(Phalcon_Assets_Collection, setAttributes){ + zval *schema_name = NULL; - zval *attributes; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &attributes); + phalcon_fetch_params(1, 0, 1, &schema_name); - if (Z_TYPE_P(attributes) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Attributes must be an array"); - return; + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC); - RETURN_THISW(); + if (zend_is_true(schema_name)) { + PHALCON_CONCAT_SVS(return_value, "SELECT `TABLE_NAME` AS view_name FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE `TABLE_SCHEMA` = '", schema_name, "' ORDER BY view_name"); + RETURN_MM(); + } + RETURN_MM_STRING("SELECT `TABLE_NAME` AS view_name FROM `INFORMATION_SCHEMA`.`VIEWS` ORDER BY view_name", 1); } -static PHP_METHOD(Phalcon_Assets_Collection, getAttributes){ - - - RETURN_MEMBER_QUICK(this_ptr, "_attributes", 1565778155UL); -} +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeIndexes){ -static PHP_METHOD(Phalcon_Assets_Collection, addFilter){ + zval *table, *schema = NULL; - zval *filter; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &filter); + phalcon_fetch_params(1, 1, 1, &table, &schema); - phalcon_update_property_array_append(this_ptr, SL("_filters"), filter TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Collection, setFilters){ - - zval *filters; - - phalcon_fetch_params(0, 1, 0, &filters); + if (!schema) { + PHALCON_INIT_VAR(schema); + } - if (Z_TYPE_P(filters) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Filters must be an array of filters"); - return; + if (zend_is_true(schema)) { + PHALCON_CONCAT_SVSVS(return_value, "SHOW INDEXES FROM `", schema, "`.`", table, "`"); + RETURN_MM(); } - phalcon_update_property_this_quick(this_ptr, SL("_filters"), filters, 3850488637UL TSRMLS_CC); + PHALCON_CONCAT_SVS(return_value, "SHOW INDEXES FROM `", table, "`"); - RETURN_THISW(); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Assets_Collection, getFilters){ - - - RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL); -} +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeReferences){ -static PHP_METHOD(Phalcon_Assets_Collection, join){ + zval *table, *schema = NULL, *sql; - zval *join; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &join); + phalcon_fetch_params(1, 1, 1, &table, &schema); - phalcon_update_property_this_quick(this_ptr, SL("_join"), join, 3979733204UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Assets_Collection, getJoin){ - - - RETURN_MEMBER_QUICK(this_ptr, "_join", 3979733204UL); + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + PHALCON_INIT_VAR(sql); + ZVAL_STRING(sql, "SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME,REFERENCED_TABLE_SCHEMA,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_NAME IS NOT NULL AND ", 1); + if (zend_is_true(schema)) { + PHALCON_SCONCAT_SVSVS(sql, "CONSTRAINT_SCHEMA = \"", schema, "\" AND TABLE_NAME = \"", table, "\""); + } else { + PHALCON_SCONCAT_SVS(sql, "TABLE_NAME = \"", table, "\""); + } + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Assets_Collection, getRealTargetPath){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableOptions){ - zval *base_path = NULL, *target_path, *complete_path; + zval *table, *schema = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &base_path); + phalcon_fetch_params(1, 1, 1, &table, &schema); - if (!base_path) { - PHALCON_INIT_VAR(base_path); + if (!schema) { + PHALCON_INIT_VAR(schema); } - PHALCON_OBS_VAR(target_path); - phalcon_read_property_this_quick(&target_path, this_ptr, SL("_targetPath"), 3658201208UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(complete_path); - PHALCON_CONCAT_VV(complete_path, base_path, target_path); - - if (phalcon_file_exists(complete_path TSRMLS_CC) == SUCCESS) { - phalcon_call_func_p1(return_value, "realpath", complete_path); - RETURN_MM(); + PHALCON_INIT_VAR(sql); + ZVAL_STRING(sql, "SELECT TABLES.TABLE_TYPE AS table_type,TABLES.AUTO_INCREMENT AS auto_increment,TABLES.ENGINE AS engine,TABLES.TABLE_COLLATION AS table_collation FROM INFORMATION_SCHEMA.TABLES WHERE ", 1); + if (zend_is_true(schema)) { + PHALCON_SCONCAT_SVSVS(sql, "TABLES.TABLE_SCHEMA = \"", schema, "\" AND TABLES.TABLE_NAME = \"", table, "\""); + } else { + PHALCON_SCONCAT_SVS(sql, "TABLES.TABLE_NAME = \"", table, "\""); } - RETURN_CTOR(complete_path); + RETURN_CTOR(sql); } @@ -29639,2947 +28923,2784 @@ static PHP_METHOD(Phalcon_Assets_Collection, getRealTargetPath){ -PHALCON_INIT_CLASS(Phalcon_Assets_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Assets, Exception, assets_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - +PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Oracle){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Oracle, db_dialect_oracle, "phalcon\\db\\dialect", phalcon_db_dialect_oracle_method_entry, 0); -PHALCON_INIT_CLASS(Phalcon_Assets_Resource_Js){ + zend_declare_property_string(phalcon_db_dialect_oracle_ce, SL("_escapeChar"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - PHALCON_REGISTER_CLASS_EX(Phalcon\\Assets\\Resource, Js, assets_resource_js, "phalcon\\assets\\resource", phalcon_assets_resource_js_method_entry, 0); + zend_class_implements(phalcon_db_dialect_oracle_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Assets_Resource_Js, __construct){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, getColumnDefinition){ - zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type; - zval *p0[] = { NULL, NULL, NULL, NULL, NULL }; + zval *column, *size, *column_type, *column_sql = NULL; + zval *scale = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); + phalcon_fetch_params(1, 1, 0, &column); - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); + if (Z_TYPE_P(column) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column definition must be an object compatible with Phalcon\\Db\\ColumnInterface"); + return; } - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); - } + PHALCON_INIT_VAR(size); + phalcon_call_method_key(size, column, "getsize", 4292672352UL); - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } + PHALCON_INIT_VAR(column_type); + phalcon_call_method_key(column_type, column, "gettype", 4294422375UL); - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "js", 1); + switch (phalcon_get_intval(column_type)) { - p0[0] = type; - p0[1] = path; - p0[2] = local; - p0[3] = filter; - p0[4] = attributes; - PHALCON_CALL_PARENT_PARAMS_NORETURN(this_ptr, "Phalcon\\Assets\\Resource\\Js", "__construct", 5, p0); + case 0: + PHALCON_INIT_VAR(column_sql); + ZVAL_STRING(column_sql, "INTEGER", 1); + break; - PHALCON_MM_RESTORE(); + case 1: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "DATE", 1); + break; + + case 2: + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVS(column_sql, "VARCHAR2(", size, ")"); + break; + + case 3: + PHALCON_INIT_VAR(scale); + phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVSVS(column_sql, "NUMBER(", size, ",", scale, ")"); + break; + + case 4: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "TIMESTAMP", 1); + break; + + case 5: + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVS(column_sql, "CHAR(", size, ")"); + break; + + case 6: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "TEXT", 1); + break; + + case 7: + PHALCON_INIT_NVAR(scale); + phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVSVS(column_sql, "FLOAT(", size, ",", scale, ")"); + break; + + case 8: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "TINYINT(1)", 1); + break; + + default: + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized Oracle data type"); + return; + + } + + RETURN_CTOR(column_sql); } +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addColumn){ + + zval *table_name, *schema_name, *column; + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; +} +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, modifyColumn){ + zval *table_name, *schema_name, *column; -#ifdef HAVE_CONFIG_H -#endif + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; +} +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropColumn){ + zval *table_name, *schema_name, *column_name; + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column_name); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; +} +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addIndex){ + zval *table_name, *schema_name, *index; + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; +} -PHALCON_INIT_CLASS(Phalcon_Assets_Resource_Css){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropIndex){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Assets\\Resource, Css, assets_resource_css, "phalcon\\assets\\resource", phalcon_assets_resource_css_method_entry, 0); + zval *table_name, *schema_name, *index_name; - return SUCCESS; + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index_name); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -static PHP_METHOD(Phalcon_Assets_Resource_Css, __construct){ - - zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type; - zval *p0[] = { NULL, NULL, NULL, NULL, NULL }; +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addPrimaryKey){ - PHALCON_MM_GROW(); + zval *table_name, *schema_name, *index; - phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); - - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); - } - - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); - } - - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "css", 1); - - p0[0] = type; - p0[1] = path; - p0[2] = local; - p0[3] = filter; - p0[4] = attributes; - PHALCON_CALL_PARENT_PARAMS_NORETURN(this_ptr, "Phalcon\\Assets\\Resource\\Css", "__construct", 5, p0); + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); - PHALCON_MM_RESTORE(); + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropPrimaryKey){ + + zval *table_name, *schema_name; + phalcon_fetch_params(0, 2, 0, &table_name, &schema_name); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; +} +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addForeignKey){ + zval *table_name, *schema_name, *reference; -#ifdef HAVE_CONFIG_H -#endif + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; +} +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropForeignKey){ + zval *table_name, *schema_name, *reference_name; + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference_name); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; +} +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, _getTableOptions){ + zval *definition, *empty_array; + PHALCON_MM_GROW(); -PHALCON_INIT_CLASS(Phalcon_Annotations_Reflection){ + phalcon_fetch_params(1, 1, 0, &definition); + + PHALCON_INIT_VAR(empty_array); + array_init(empty_array); + RETURN_CTOR(empty_array); +} - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Reflection, annotations_reflection, phalcon_annotations_reflection_method_entry, 0); +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, createTable){ - zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_reflectionData"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_classAnnotations"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_methodAnnotations"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_annotations_reflection_ce, SL("_propertyAnnotations"), ZEND_ACC_PROTECTED TSRMLS_CC); + zval *table_name, *schema_name, *definition; - return SUCCESS; + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &definition); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -static PHP_METHOD(Phalcon_Annotations_Reflection, __construct){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropTable){ - zval *reflection_data = NULL; + zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; + zval *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &reflection_data); + phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); - if (!reflection_data) { - PHALCON_INIT_VAR(reflection_data); + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); } - if (Z_TYPE_P(reflection_data) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_reflectionData"), reflection_data, 3848141129UL TSRMLS_CC); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(table); + PHALCON_CONCAT_VSV(table, schema_name, ".", table_name); + } else { + PHALCON_CPY_WRT(table, table_name); + } + if (zend_is_true(if_exists)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SV(sql, "DROP TABLE IF EXISTS ", table); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SV(sql, "DROP TABLE ", table); } - PHALCON_MM_RESTORE(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Annotations_Reflection, getClassAnnotations){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, createView){ - zval *annotations, *reflection_data, *reflection_class; - zval *collection; + zval *view_name, *definition, *schema_name, *view_sql; + zval *view = NULL, *sql; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(annotations); - phalcon_read_property_this_quick(&annotations, this_ptr, SL("_classAnnotations"), 372163368UL, PH_NOISY_CC); - if (Z_TYPE_P(annotations) != IS_OBJECT) { - - PHALCON_OBS_VAR(reflection_data); - phalcon_read_property_this_quick(&reflection_data, this_ptr, SL("_reflectionData"), 3848141129UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(reflection_data, SS("class"), 4138154555UL)) { - PHALCON_OBS_VAR(reflection_class); - phalcon_array_fetch_quick_string(&reflection_class, reflection_data, SS("class"), 4138154555UL, PH_NOISY); - - PHALCON_INIT_VAR(collection); - object_init_ex(collection, phalcon_annotations_collection_ce); - phalcon_call_method_p1_key(NULL, collection, "__construct", reflection_class, 1107214344UL); + phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); - phalcon_update_property_this_quick(this_ptr, SL("_classAnnotations"), collection, 372163368UL TSRMLS_CC); - RETURN_CTOR(collection); - } + if (!phalcon_array_isset_quick_string(definition, SS("sql"), 2090732981UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'sql' is required in the definition array"); + return; + } - phalcon_update_property_bool(this_ptr, SL("_classAnnotations"), 0 TSRMLS_CC); - RETURN_MM_FALSE; + PHALCON_OBS_VAR(view_sql); + phalcon_array_fetch_quick_string(&view_sql, definition, SS("sql"), 2090732981UL, PH_NOISY); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(view); + PHALCON_CONCAT_VSV(view, view_name, ".", schema_name); + } else { + PHALCON_CPY_WRT(view, view_name); } - RETURN_CCTOR(annotations); + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Annotations_Reflection, getMethodsAnnotations){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropView){ - zval *annotations, *reflection_data, *reflection_methods; - zval *collections, *reflection_method = NULL, *method_name = NULL; - zval *collection = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; + zval *sql = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(annotations); - phalcon_read_property_this_quick(&annotations, this_ptr, SL("_methodAnnotations"), 4229536243UL, PH_NOISY_CC); - if (Z_TYPE_P(annotations) != IS_OBJECT) { - - PHALCON_OBS_VAR(reflection_data); - phalcon_read_property_this_quick(&reflection_data, this_ptr, SL("_reflectionData"), 3848141129UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(reflection_data, SS("methods"), 2292439449UL)) { - - PHALCON_OBS_VAR(reflection_methods); - phalcon_array_fetch_quick_string(&reflection_methods, reflection_data, SS("methods"), 2292439449UL, PH_NOISY); - if (phalcon_fast_count_ev(reflection_methods TSRMLS_CC)) { - - PHALCON_INIT_VAR(collections); - array_init(collections); - - phalcon_is_iterable(reflection_methods, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(method_name, ah0, hp0); - PHALCON_GET_HVALUE(reflection_method); - - PHALCON_INIT_NVAR(collection); - object_init_ex(collection, phalcon_annotations_collection_ce); - phalcon_call_method_p1_key(NULL, collection, "__construct", reflection_method, 1107214344UL); - - phalcon_array_update_zval(&collections, method_name, &collection, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - phalcon_update_property_this_quick(this_ptr, SL("_methodAnnotations"), collections, 4229536243UL TSRMLS_CC); + phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); - RETURN_CTOR(collections); - } - } + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); + } - phalcon_update_property_bool(this_ptr, SL("_methodAnnotations"), 0 TSRMLS_CC); - RETURN_MM_FALSE; + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(view); + PHALCON_CONCAT_SVSVS(view, "`", schema_name, "`.`", view_name, "`"); + } else { + PHALCON_INIT_NVAR(view); + PHALCON_CONCAT_SVS(view, "`", view_name, "`"); + } + if (zend_is_true(if_exists)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SV(sql, "DROP VIEW IF EXISTS ", view); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SV(sql, "DROP VIEW ", view); } - RETURN_CCTOR(annotations); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Annotations_Reflection, getPropertiesAnnotations){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableExists){ - zval *annotations, *reflection_data, *reflection_properties; - zval *collections, *reflection_property = NULL, *property = NULL; - zval *collection = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *table_name, *schema_name = NULL, *sql = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(annotations); - phalcon_read_property_this_quick(&annotations, this_ptr, SL("_propertyAnnotations"), 762458551UL, PH_NOISY_CC); - if (Z_TYPE_P(annotations) != IS_OBJECT) { - - PHALCON_OBS_VAR(reflection_data); - phalcon_read_property_this_quick(&reflection_data, this_ptr, SL("_reflectionData"), 3848141129UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(reflection_data, SS("properties"), 1619284338UL)) { - - PHALCON_OBS_VAR(reflection_properties); - phalcon_array_fetch_quick_string(&reflection_properties, reflection_data, SS("properties"), 1619284338UL, PH_NOISY); - if (phalcon_fast_count_ev(reflection_properties TSRMLS_CC)) { - - PHALCON_INIT_VAR(collections); - array_init(collections); - - phalcon_is_iterable(reflection_properties, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(property, ah0, hp0); - PHALCON_GET_HVALUE(reflection_property); - - PHALCON_INIT_NVAR(collection); - object_init_ex(collection, phalcon_annotations_collection_ce); - phalcon_call_method_p1_key(NULL, collection, "__construct", reflection_property, 1107214344UL); - - phalcon_array_update_zval(&collections, property, &collection, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - phalcon_update_property_this_quick(this_ptr, SL("_propertyAnnotations"), collections, 762458551UL TSRMLS_CC); + phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - RETURN_CTOR(collections); - } - } + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } - phalcon_update_property_bool(this_ptr, SL("_propertyAnnotations"), 0 TSRMLS_CC); - RETURN_MM_FALSE; + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_TABLES WHERE TABLE_NAME='", table_name, "' AND OWNER = '", schema_name, "'"); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_TABLES WHERE TABLE_NAME='", table_name, "'"); } - RETURN_CCTOR(annotations); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Annotations_Reflection, getReflectionData){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, viewExists){ + zval *view_name, *schema_name = NULL, *sql = NULL; - RETURN_MEMBER_QUICK(this_ptr, "_reflectionData", 3848141129UL); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_VIEWS WHERE VIEW_NAME='", view_name, "' AND OWNER='", schema_name, "'"); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END RET FROM ALL_VIEWS WHERE VIEW_NAME='", view_name, "'"); + } + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Annotations_Reflection, __set_state){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeColumns){ - zval *data, *reflection_data; + zval *table, *schema = NULL, *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &data); - - if (Z_TYPE_P(data) == IS_ARRAY) { + phalcon_fetch_params(1, 1, 1, &table, &schema); - if (phalcon_array_isset_quick_string(data, SS("_reflectionData"), 3848141129UL)) { - PHALCON_OBS_VAR(reflection_data); - phalcon_array_fetch_quick_string(&reflection_data, data, SS("_reflectionData"), 3848141129UL, PH_NOISY); - object_init_ex(return_value, phalcon_annotations_reflection_ce); - phalcon_call_method_p1_key(NULL, return_value, "__construct", reflection_data, 1107214344UL); + if (!schema) { + PHALCON_INIT_VAR(schema); + } - RETURN_MM(); - } + if (zend_is_true(schema)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "SELECT TC.COLUMN_NAME, TC.DATA_TYPE, TC.DATA_LENGTH, TC.DATA_PRECISION, TC.DATA_SCALE, TC.NULLABLE, C.CONSTRAINT_TYPE, TC.DATA_DEFAULT, CC.POSITION FROM ALL_TAB_COLUMNS TC LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P')) ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME WHERE TC.TABLE_NAME = '", table, "' AND TC.OWNER = '", schema, "' ORDER BY TC.COLUMN_ID"); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT TC.COLUMN_NAME, TC.DATA_TYPE, TC.DATA_LENGTH, TC.DATA_PRECISION, TC.DATA_SCALE, TC.NULLABLE, C.CONSTRAINT_TYPE, TC.DATA_DEFAULT, CC.POSITION FROM ALL_TAB_COLUMNS TC LEFT JOIN (ALL_CONS_COLUMNS CC JOIN ALL_CONSTRAINTS C ON (CC.CONSTRAINT_NAME = C.CONSTRAINT_NAME AND CC.TABLE_NAME = C.TABLE_NAME AND CC.OWNER = C.OWNER AND C.CONSTRAINT_TYPE = 'P')) ON TC.TABLE_NAME = CC.TABLE_NAME AND TC.COLUMN_NAME = CC.COLUMN_NAME WHERE TC.TABLE_NAME = '", table, "' ORDER BY TC.COLUMN_ID"); } - object_init_ex(return_value, phalcon_annotations_reflection_ce); - phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL); - RETURN_MM(); + RETURN_CTOR(sql); } +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, listTables){ + zval *schema_name = NULL, *sql = NULL; -/* Driver template for the LEMON parser generator. -** The author disclaims copyright to this source code. -*/ -/* First off, code is include which follows the "include" declaration -** in the input file. */ -#include -// 28 "parser.lemon" - + PHALCON_MM_GROW(); -#ifdef HAVE_CONFIG_H -#endif + phalcon_fetch_params(1, 0, 1, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT TABLE_NAME, OWNER FROM ALL_TABLES WHERE OWNER='", schema_name, "' ORDER BY OWNER, TABLE_NAME"); + } else { + PHALCON_INIT_NVAR(sql); + ZVAL_STRING(sql, "SELECT TABLE_NAME, OWNER FROM ALL_TABLES ORDER BY OWNER, TABLE_NAME ", 1); + } + + RETURN_CTOR(sql); +} +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, listViews){ + zval *schema_name = NULL, *sql = NULL; + PHALCON_MM_GROW(); -static zval *phannot_ret_literal_zval(int type, phannot_parser_token *T) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", type); - if (T) { - add_assoc_stringl(ret, "value", T->token, T->token_len, 0); - efree(T); + phalcon_fetch_params(1, 0, 1, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - - return ret; + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT VIEW_NAME FROM ALL_VIEWS WHERE OWNER='", schema_name, "' ORDER BY VIEW_NAME"); + } else { + PHALCON_INIT_NVAR(sql); + ZVAL_STRING(sql, "SELECT VIEW_NAME FROM ALL_VIEWS VIEW_NAME", 1); + } + + RETURN_CTOR(sql); } -static zval *phannot_ret_array(zval *items) -{ - zval *ret; +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeIndexes){ - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", PHANNOT_T_ARRAY); + zval *table, *schema = NULL, *sql = NULL; - if (items) { - add_assoc_zval(ret, "items", items); - } + PHALCON_MM_GROW(); - return ret; + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + if (zend_is_true(schema)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "SELECT I.TABLE_NAME, 0 AS C0, I.INDEX_NAME, IC.COLUMN_POSITION, IC.COLUMN_NAME FROM ALL_INDEXES I JOIN ALL_IND_COLUMNS IC ON I.INDEX_NAME = IC.INDEX_NAME WHERE I.TABLE_NAME = '", table, "' AND IC.INDEX_OWNER = '", schema, "'"); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT I.TABLE_NAME, 0 AS C0, I.INDEX_NAME, IC.COLUMN_POSITION, IC.COLUMN_NAME FROM ALL_INDEXES I JOIN ALL_IND_COLUMNS IC ON I.INDEX_NAME = IC.INDEX_NAME WHERE I.TABLE_NAME = '", table, "'"); + } + + RETURN_CTOR(sql); } -static zval *phannot_ret_zval_list(zval *list_left, zval *right_list) -{ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeReferences){ - zval *ret; - HashPosition pos; - HashTable *list; + zval *table, *schema = NULL, *sql; - MAKE_STD_ZVAL(ret); - array_init(ret); + PHALCON_MM_GROW(); - if (list_left) { + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + PHALCON_INIT_VAR(sql); + ZVAL_STRING(sql, "SELECT AC.TABLE_NAME, CC.COLUMN_NAME, AC.CONSTRAINT_NAME, AC.R_OWNER, RCC.TABLE_NAME R_TABLE_NAME, RCC.COLUMN_NAME R_COLUMN_NAME FROM ALL_CONSTRAINTS AC JOIN ALL_CONS_COLUMNS CC ON AC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME JOIN ALL_CONS_COLUMNS RCC ON AC.R_OWNER = RCC.OWNER AND AC.R_CONSTRAINT_NAME = RCC.CONSTRAINT_NAME WHERE AC.CONSTRAINT_TYPE='R' ", 1); + if (zend_is_true(schema)) { + PHALCON_SCONCAT_SVSVS(sql, "AND AC.OWNER='", schema, "' AND AC.TABLE_NAME = '", table, "'"); + } else { + PHALCON_SCONCAT_SVS(sql, "AND AC.TABLE_NAME = '", table, "'"); + } + + RETURN_CTOR(sql); +} - list = Z_ARRVAL_P(list_left); - if (zend_hash_index_exists(list, 0)) { - zend_hash_internal_pointer_reset_ex(list, &pos); - for (;; zend_hash_move_forward_ex(list, &pos)) { +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableOptions){ - zval ** item; + zval *table, *schema = NULL; - if (zend_hash_get_current_data_ex(list, (void**) &item, &pos) == FAILURE) { - break; - } + PHALCON_MM_GROW(); - Z_ADDREF_PP(item); - add_next_index_zval(ret, *item); + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + RETURN_MM_EMPTY_STRING(); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, getSqlTable){ + + zval *table, *escape_char = NULL, *table_name, *sql_table = NULL; + zval *schema_name, *sql_schema = NULL, *alias_name; + zval *sql_table_alias = NULL; + + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 1, &table, &escape_char); + + if (!escape_char) { + PHALCON_INIT_VAR(escape_char); + } else { + PHALCON_SEPARATE_PARAM(escape_char); + } + + if (Z_TYPE_P(escape_char) == IS_NULL) { + PHALCON_OBS_NVAR(escape_char); + phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); + } + if (Z_TYPE_P(table) == IS_ARRAY) { + + PHALCON_OBS_VAR(table_name); + phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY); + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(sql_table); + PHALCON_CONCAT_VVV(sql_table, escape_char, table_name, escape_char); + } else { + PHALCON_CPY_WRT(sql_table, table_name); + } + + PHALCON_OBS_VAR(schema_name); + phalcon_array_fetch_long(&schema_name, table, 1, PH_NOISY); + if (Z_TYPE_P(schema_name) != IS_NULL) { + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(sql_schema); + PHALCON_CONCAT_VVVSV(sql_schema, escape_char, schema_name, escape_char, ".", sql_table); + } else { + PHALCON_INIT_NVAR(sql_schema); + PHALCON_CONCAT_VSV(sql_schema, schema_name, ".", sql_table); } - zval_ptr_dtor(&list_left); } else { - add_next_index_zval(ret, list_left); + PHALCON_CPY_WRT(sql_schema, sql_table); } + + if (phalcon_array_isset_long(table, 2)) { + + PHALCON_OBS_VAR(alias_name); + phalcon_array_fetch_long(&alias_name, table, 2, PH_NOISY); + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(sql_table_alias); + PHALCON_CONCAT_VSVVV(sql_table_alias, sql_schema, " ", escape_char, alias_name, escape_char); + } else { + PHALCON_INIT_NVAR(sql_table_alias); + PHALCON_CONCAT_VSV(sql_table_alias, sql_schema, " ", alias_name); + } + } else { + PHALCON_CPY_WRT(sql_table_alias, sql_schema); + } + + RETURN_CCTOR(sql_table_alias); + } + + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_NVAR(sql_table); + PHALCON_CONCAT_VVV(sql_table, escape_char, table, escape_char); + RETURN_CCTOR(sql_table); } + + RETURN_CCTOR(table); +} - add_next_index_zval(ret, right_list); +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, limit){ - return ret; -} + zval *sql_query, *number, *limit, *sql_limit; -static zval *phannot_ret_named_item(phannot_parser_token *name, zval *expr) -{ - zval *ret; + PHALCON_MM_GROW(); - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_zval(ret, "expr", expr); - if (name != NULL) { - add_assoc_stringl(ret, "name", name->token, name->token_len, 0); - efree(name); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &sql_query, &number) == FAILURE) { + RETURN_MM_NULL(); } - return ret; + if (phalcon_is_numeric(number)) { + + PHALCON_INIT_VAR(limit); + ZVAL_LONG(limit, phalcon_get_intval(number)); + + PHALCON_INIT_VAR(sql_limit); + PHALCON_CONCAT_VSV(sql_limit, sql_query, " LIMIT ", limit); + RETURN_CTOR(sql_limit); + } + + RETURN_CCTOR(sql_query); } -static zval *phannot_ret_annotation(phannot_parser_token *name, zval *arguments, phannot_scanner_state *state) -{ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, select){ - zval *ret; + zval *definition, *escape_char = NULL, *columns, *selected_columns; + zval *column = NULL, *column_item = NULL, *column_sql = NULL, *columns_sql = NULL; + zval *column_domain = NULL, *column_domain_sql = NULL, *column_alias = NULL; + zval *column_alias_sql = NULL, *tables, *selected_tables; + zval *table = NULL, *sql_table = NULL, *tables_sql = NULL, *sql, *joins; + zval *join = NULL, *type = NULL, *sql_join = NULL, *join_conditions_array = NULL; + zval *join_expressions = NULL, *join_condition = NULL, *join_expression = NULL; + zval *join_conditions = NULL, *where_conditions; + zval *where_expression, *group_items, *group_fields; + zval *group_field = NULL, *group_expression = NULL, *group_sql; + zval *group_clause, *having_conditions, *having_expression; + zval *order_fields, *order_items, *order_item = NULL; + zval *order_expression = NULL, *order_sql_item = NULL, *sql_order_type = NULL; + zval *order_sql_item_type = NULL, *order_sql, *limit_value; + zval *number, *offset; + zval *one, *ini_range, *end_range, *sql_limit; + HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5; + HashPosition hp0, hp1, hp2, hp3, hp4, hp5; + zval **hd; - MAKE_STD_ZVAL(ret); - array_init(ret); + PHALCON_MM_GROW(); - add_assoc_long(ret, "type", PHANNOT_T_ANNOTATION); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &definition) == FAILURE) { + RETURN_MM_NULL(); + } - if (name) { - add_assoc_stringl(ret, "name", name->token, name->token_len, 0); - efree(name); + if (Z_TYPE_P(definition) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid SELECT definition"); + return; + } + if (!phalcon_array_isset_quick_string(definition, SS("tables"), 3465666720UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'tables' is required in the definition array"); + return; } - if (arguments) { - add_assoc_zval(ret, "arguments", arguments); + if (!phalcon_array_isset_quick_string(definition, SS("columns"), 1041822630UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'columns' is required in the definition array"); + return; } - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_OBS_VAR(escape_char); + phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); + } else { + PHALCON_INIT_NVAR(escape_char); + } - return ret; -} + PHALCON_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); + if (Z_TYPE_P(columns) == IS_ARRAY) { + PHALCON_INIT_VAR(selected_columns); + array_init(selected_columns); -// 139 "parser.c" -/* Next is all token values, in a form suitable for use by makeheaders. -** This section will be null unless lemon is run with the -m switch. -*/ -/* Make sure the INTERFACE macro is defined. -*/ -#ifndef INTERFACE -# define INTERFACE 1 -#endif -/* The next thing included is series of defines which control -** various aspects of the generated parser. -** JJCODETYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 terminals -** and nonterminals. "int" is used otherwise. -** JJNOCODE is a number of type JJCODETYPE which corresponds -** to no legal terminal or nonterminal number. This -** number is used to fill in empty slots of the hash -** table. -** JJFALLBACK If defined, this indicates that one or more tokens -** have fall-back values which should be used if the -** original value of the token will not parse. -** JJACTIONTYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 rules and -** states combined. "int" is used otherwise. -** phannot_JTOKENTYPE is the data type used for minor tokens given -** directly to the parser from the tokenizer. -** JJMINORTYPE is the data type used for all minor tokens. -** This is typically a union of many types, one of -** which is phannot_JTOKENTYPE. The entry in the union -** for base tokens is called "jj0". -** JJSTACKDEPTH is the maximum depth of the parser's stack. -** phannot_ARG_SDECL A static variable declaration for the %extra_argument -** phannot_ARG_PDECL A parameter declaration for the %extra_argument -** phannot_ARG_STORE Code to store %extra_argument into jjpParser -** phannot_ARG_FETCH Code to extract %extra_argument from jjpParser -** JJNSTATE the combined number of states. -** JJNRULE the number of rules in the grammar -** JJERRORSYMBOL is the code number of the error symbol. If not -** defined, then do no error processing. -*/ -#define JJCODETYPE unsigned char -#define JJNOCODE 28 -#define JJACTIONTYPE unsigned char -#define phannot_JTOKENTYPE phannot_parser_token* -typedef union { - phannot_JTOKENTYPE jj0; - zval* jj36; - int jj55; -} JJMINORTYPE; -#define JJSTACKDEPTH 100 -#define phannot_ARG_SDECL phannot_parser_status *status; -#define phannot_ARG_PDECL ,phannot_parser_status *status -#define phannot_ARG_FETCH phannot_parser_status *status = jjpParser->status -#define phannot_ARG_STORE jjpParser->status = status -#define JJNSTATE 40 -#define JJNRULE 25 -#define JJERRORSYMBOL 18 -#define JJERRSYMDT jj55 -#define JJ_NO_ACTION (JJNSTATE+JJNRULE+2) -#define JJ_ACCEPT_ACTION (JJNSTATE+JJNRULE+1) -#define JJ_ERROR_ACTION (JJNSTATE+JJNRULE) + if (!phalcon_is_iterable_ex(columns, &ah0, &hp0, 0, 0)) { + return; + } -/* Next are that tables used to determine what action to take based on the -** current state and lookahead token. These tables are used to implement -** functions that take a state number and lookahead value and return an -** action integer. -** -** Suppose the action integer is N. Then the action is determined as -** follows -** -** 0 <= N < JJNSTATE Shift N. That is, push the lookahead -** token onto the stack and goto state N. -** -** JJNSTATE <= N < JJNSTATE+JJNRULE Reduce by rule N-JJNSTATE. -** -** N == JJNSTATE+JJNRULE A syntax error has occurred. -** -** N == JJNSTATE+JJNRULE+1 The parser accepts its input. -** -** N == JJNSTATE+JJNRULE+2 No such action. Denotes unused -** slots in the jj_action[] table. -** -** The action table is constructed as a single large table named jj_action[]. -** Given state S and lookahead X, the action is computed as -** -** jj_action[ jj_shift_ofst[S] + X ] -** -** If the index value jj_shift_ofst[S]+X is out of range or if the value -** jj_lookahead[jj_shift_ofst[S]+X] is not equal to X or if jj_shift_ofst[S] -** is equal to JJ_SHIFT_USE_DFLT, it means that the action is not in the table -** and that jj_default[S] should be used instead. -** -** The formula above is for computing the action when the lookahead is -** a terminal symbol. If the lookahead is a non-terminal (as occurs after -** a reduce action) then the jj_reduce_ofst[] array is used in place of -** the jj_shift_ofst[] array and JJ_REDUCE_USE_DFLT is used in place of -** JJ_SHIFT_USE_DFLT. -** -** The following are the tables generated in this section: -** -** jj_action[] A single table containing all actions. -** jj_lookahead[] A table containing the lookahead for each entry in -** jj_action. Used to detect hash collisions. -** jj_shift_ofst[] For each state, the offset into jj_action for -** shifting terminals. -** jj_reduce_ofst[] For each state, the offset into jj_action for -** shifting non-terminals after a reduce. -** jj_default[] Default action for each state. -*/ -static JJACTIONTYPE jj_action[] = { - /* 0 */ 4, 28, 15, 38, 12, 14, 16, 18, 20, 21, - /* 10 */ 22, 23, 24, 4, 31, 4, 28, 15, 40, 12, - /* 20 */ 30, 16, 18, 20, 21, 22, 23, 24, 3, 31, - /* 30 */ 4, 17, 15, 6, 19, 35, 16, 18, 20, 21, - /* 40 */ 22, 23, 24, 5, 31, 15, 7, 27, 11, 16, - /* 50 */ 54, 54, 15, 25, 27, 11, 16, 15, 32, 27, - /* 60 */ 11, 16, 66, 1, 2, 39, 41, 15, 4, 10, - /* 70 */ 11, 16, 15, 9, 9, 37, 16, 8, 13, 36, - /* 80 */ 9, 29, 34, 54, 54, 54, 54, 54, 26, 54, - /* 90 */ 54, 54, 54, 54, 54, 54, 33, -}; -static JJCODETYPE jj_lookahead[] = { - /* 0 */ 2, 3, 22, 5, 6, 25, 26, 9, 10, 11, - /* 10 */ 12, 13, 14, 2, 16, 2, 3, 22, 0, 6, - /* 20 */ 25, 26, 9, 10, 11, 12, 13, 14, 22, 16, - /* 30 */ 2, 3, 22, 4, 6, 25, 26, 9, 10, 11, - /* 40 */ 12, 13, 14, 3, 16, 22, 23, 24, 25, 26, - /* 50 */ 27, 27, 22, 23, 24, 25, 26, 22, 23, 24, - /* 60 */ 25, 26, 19, 20, 21, 22, 0, 22, 2, 24, - /* 70 */ 25, 26, 22, 1, 1, 25, 26, 5, 7, 8, - /* 80 */ 1, 7, 8, 27, 27, 27, 27, 27, 15, 27, - /* 90 */ 27, 27, 27, 27, 27, 27, 17, -}; -#define JJ_SHIFT_USE_DFLT (-3) -static signed char jj_shift_ofst[] = { - /* 0 */ 11, 18, 66, -3, 40, 29, -2, 72, -3, 13, - /* 10 */ -3, -3, 71, 28, -3, -3, -3, -3, -3, -3, - /* 20 */ -3, -3, -3, -3, 13, 73, -3, -3, 74, 28, - /* 30 */ -3, 13, 79, -3, 28, -3, 28, -3, -3, -3, -}; -#define JJ_REDUCE_USE_DFLT (-21) -static signed char jj_reduce_ofst[] = { - /* 0 */ 43, -21, 6, -21, -21, -21, 23, -21, -21, 45, - /* 10 */ -21, -21, -21, -20, -21, -21, -21, -21, -21, -21, - /* 20 */ -21, -21, -21, -21, 30, -21, -21, -21, -21, -5, - /* 30 */ -21, 35, -21, -21, 10, -21, 50, -21, -21, -21, -}; -static JJACTIONTYPE jj_default[] = { - /* 0 */ 65, 65, 65, 42, 65, 46, 65, 65, 44, 65, - /* 10 */ 47, 49, 58, 65, 50, 54, 55, 56, 57, 58, - /* 20 */ 59, 60, 61, 62, 65, 65, 63, 48, 56, 65, - /* 30 */ 52, 65, 65, 64, 65, 53, 65, 51, 45, 43, -}; -#define JJ_SZ_ACTTAB (sizeof(jj_action)/sizeof(jj_action[0])) + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { -/* The next table maps tokens into fallback tokens. If a construct -** like the following: -** -** %fallback ID X Y Z. -** -** appears in the grammer, then ID becomes a fallback token for X, Y, -** and Z. Whenever one of the tokens X, Y, or Z is input to the parser -** but it does not parse, the type of the token is changed to ID and -** the parse is retried before an error is thrown. -*/ -#ifdef JJFALLBACK -static const JJCODETYPE jjFallback[] = { -}; -#endif /* JJFALLBACK */ + PHALCON_GET_FOREACH_VALUE(column); -/* The following structure represents a single element of the -** parser's stack. Information stored includes: -** -** + The state number for the parser at this level of the stack. -** -** + The value of the token stored at this level of the stack. -** (In other words, the "major" token.) -** -** + The semantic value stored at this level of the stack. This is -** the information used by the action routines in the grammar. -** It is sometimes called the "minor" token. -*/ -struct jjStackEntry { - int stateno; /* The state-number */ - int major; /* The major token value. This is the code - ** number for the token at this stack level */ - JJMINORTYPE minor; /* The user-supplied minor token value. This - ** is the value of the token */ -}; -typedef struct jjStackEntry jjStackEntry; + PHALCON_OBS_NVAR(column_item); + phalcon_array_fetch_long(&column_item, column, 0, PH_NOISY); + if (Z_TYPE_P(column_item) == IS_ARRAY) { + PHALCON_INIT_NVAR(column_sql); + phalcon_call_method_p2_key(column_sql, this_ptr, "getsqlexpression", column_item, escape_char, 3377787077UL); + } else { + if (PHALCON_IS_STRING(column_item, "*")) { + PHALCON_CPY_WRT(column_sql, column_item); + } else { + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_VVV(column_sql, escape_char, column_item, escape_char); + } else { + PHALCON_CPY_WRT(columns_sql, column_item); + } + } + } -/* The state of the parser is completely contained in an instance of -** the following structure */ -struct jjParser { - int jjidx; /* Index of top element in stack */ - int jjerrcnt; /* Shifts left before out of the error */ - phannot_ARG_SDECL /* A place to hold %extra_argument */ - jjStackEntry jjstack[JJSTACKDEPTH]; /* The parser's stack */ -}; -typedef struct jjParser jjParser; + if (phalcon_array_isset_long(column, 1)) { -#ifndef NDEBUG -#include -static FILE *jjTraceFILE = 0; -static char *jjTracePrompt = 0; -#endif /* NDEBUG */ + PHALCON_OBS_NVAR(column_domain); + phalcon_array_fetch_long(&column_domain, column, 1, PH_NOISY); + if (zend_is_true(column_domain)) { + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_NVAR(column_domain_sql); + PHALCON_CONCAT_VVVSV(column_domain_sql, escape_char, column_domain, escape_char, ".", column_sql); + } else { + PHALCON_INIT_NVAR(column_domain_sql); + PHALCON_CONCAT_VSV(column_domain_sql, column_domain, ".", column_sql); + } + } else { + PHALCON_CPY_WRT(column_domain_sql, column_sql); + } + } else { + PHALCON_CPY_WRT(column_domain_sql, column_sql); + } -#ifndef NDEBUG -static void phannot_Trace(FILE *TraceFILE, char *zTracePrompt){ - jjTraceFILE = TraceFILE; - jjTracePrompt = zTracePrompt; - if( jjTraceFILE==0 ) jjTracePrompt = 0; - else if( jjTracePrompt==0 ) jjTraceFILE = 0; -} -#endif /* NDEBUG */ + if (phalcon_array_isset_long(column, 2)) { -#ifndef NDEBUG -/* For tracing shifts, the names of all terminals and nonterminals -** are required. The following table supplies these names */ -static const char *jjTokenName[] = { - "$", "COMMA", "AT", "IDENTIFIER", - "PARENTHESES_OPEN", "PARENTHESES_CLOSE", "STRING", "EQUALS", - "COLON", "INTEGER", "DOUBLE", "NULL", - "FALSE", "TRUE", "BRACKET_OPEN", "BRACKET_CLOSE", - "SBRACKET_OPEN", "SBRACKET_CLOSE", "error", "program", - "annotation_language", "annotation_list", "annotation", "argument_list", - "argument_item", "expr", "array", -}; -#endif /* NDEBUG */ + PHALCON_OBS_NVAR(column_alias); + phalcon_array_fetch_long(&column_alias, column, 2, PH_NOISY); + if (zend_is_true(column_alias)) { + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_NVAR(column_alias_sql); + PHALCON_CONCAT_VSVVV(column_alias_sql, column_domain_sql, " ", escape_char, column_alias, escape_char); + } else { + PHALCON_INIT_NVAR(column_alias_sql); + PHALCON_CONCAT_VSV(column_alias_sql, column_domain_sql, " ", column_alias); + } + } else { + PHALCON_CPY_WRT(column_alias_sql, column_domain_sql); + } + } else { + PHALCON_CPY_WRT(column_alias_sql, column_domain_sql); + } -#ifndef NDEBUG -/* For tracing reduce actions, the names of all rules are required. -*/ -static const char *jjRuleName[] = { - /* 0 */ "program ::= annotation_language", - /* 1 */ "annotation_language ::= annotation_list", - /* 2 */ "annotation_list ::= annotation_list annotation", - /* 3 */ "annotation_list ::= annotation", - /* 4 */ "annotation ::= AT IDENTIFIER PARENTHESES_OPEN argument_list PARENTHESES_CLOSE", - /* 5 */ "annotation ::= AT IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE", - /* 6 */ "annotation ::= AT IDENTIFIER", - /* 7 */ "argument_list ::= argument_list COMMA argument_item", - /* 8 */ "argument_list ::= argument_item", - /* 9 */ "argument_item ::= expr", - /* 10 */ "argument_item ::= STRING EQUALS expr", - /* 11 */ "argument_item ::= STRING COLON expr", - /* 12 */ "argument_item ::= IDENTIFIER EQUALS expr", - /* 13 */ "argument_item ::= IDENTIFIER COLON expr", - /* 14 */ "expr ::= annotation", - /* 15 */ "expr ::= array", - /* 16 */ "expr ::= IDENTIFIER", - /* 17 */ "expr ::= INTEGER", - /* 18 */ "expr ::= STRING", - /* 19 */ "expr ::= DOUBLE", - /* 20 */ "expr ::= NULL", - /* 21 */ "expr ::= FALSE", - /* 22 */ "expr ::= TRUE", - /* 23 */ "array ::= BRACKET_OPEN argument_list BRACKET_CLOSE", - /* 24 */ "array ::= SBRACKET_OPEN argument_list SBRACKET_CLOSE", -}; -#endif /* NDEBUG */ + phalcon_array_append(&selected_columns, column_alias_sql, PH_SEPARATE); -const char *phannot_TokenName(int tokenType){ -#ifndef NDEBUG - if( tokenType>0 && tokenType<(sizeof(jjTokenName)/sizeof(jjTokenName[0])) ){ - return jjTokenName[tokenType]; - }else{ - return "Unknown"; - } -#else - return ""; -#endif -} + zend_hash_move_forward_ex(ah0, &hp0); + } -void *phannot_Alloc(void *(*mallocProc)(size_t)){ - jjParser *pParser; - pParser = (jjParser*)(*mallocProc)( (size_t)sizeof(jjParser) ); - if( pParser ){ - pParser->jjidx = -1; - } - return pParser; -} + PHALCON_INIT_VAR(columns_sql); + phalcon_fast_join_str(columns_sql, SL(", "), selected_columns TSRMLS_CC); + } else { + PHALCON_CPY_WRT(columns_sql, columns); + } -/* The following function deletes the value associated with a -** symbol. The symbol can be either a terminal or nonterminal. -** "jjmajor" is the symbol code, and "jjpminor" is a pointer to -** the value. -*/ -static void jj_destructor(JJCODETYPE jjmajor, JJMINORTYPE *jjpminor){ - switch( jjmajor ){ - /* Here is inserted the actions which take place when a - ** terminal or non-terminal is destroyed. This can happen - ** when the symbol is popped from the stack during a - ** reduce or during error processing or when a parser is - ** being destroyed before it is finished parsing. - ** - ** Note: during a reduce, the only symbols destroyed are those - ** which appear on the RHS of the rule, but which are not used - ** inside the C code. - */ - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: -// 222 "parser.lemon" -{ - if ((jjpminor->jj0)) { - if ((jjpminor->jj0)->free_flag) { - efree((jjpminor->jj0)->token); + PHALCON_OBS_VAR(tables); + phalcon_array_fetch_quick_string(&tables, definition, SS("tables"), 3465666720UL, PH_NOISY); + if (Z_TYPE_P(tables) == IS_ARRAY) { + + PHALCON_INIT_VAR(selected_tables); + array_init(selected_tables); + + if (!phalcon_is_iterable_ex(tables, &ah1, &hp1, 0, 0)) { + return; } - efree((jjpminor->jj0)); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_FOREACH_VALUE(table); + + PHALCON_INIT_NVAR(sql_table); + phalcon_call_method_p2_key(sql_table, this_ptr, "getsqltable", table, escape_char, 2837135293UL); + phalcon_array_append(&selected_tables, sql_table, PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); + } + + PHALCON_INIT_VAR(tables_sql); + phalcon_fast_join_str(tables_sql, SL(", "), selected_tables TSRMLS_CC); + } else { + PHALCON_CPY_WRT(tables_sql, tables); } -} -// 507 "parser.c" - break; - case 20: - case 21: - case 22: - case 23: - case 24: - case 25: -// 235 "parser.lemon" -{ zval_ptr_dtor(&(jjpminor->jj36)); } -// 517 "parser.c" - break; - default: break; /* If no destructor action specified: do nothing */ - } -} -static int jj_pop_parser_stack(jjParser *pParser){ - JJCODETYPE jjmajor; - jjStackEntry *jjtos = &pParser->jjstack[pParser->jjidx]; + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "SELECT ", columns_sql, " FROM ", tables_sql); - if( pParser->jjidx<0 ) return 0; -#ifndef NDEBUG - if( jjTraceFILE && pParser->jjidx>=0 ){ - fprintf(jjTraceFILE,"%sPopping %s\n", - jjTracePrompt, - jjTokenName[jjtos->major]); - } -#endif - jjmajor = jjtos->major; - jj_destructor( jjmajor, &jjtos->minor); - pParser->jjidx--; - return jjmajor; -} + if (phalcon_array_isset_quick_string(definition, SS("joins"), 120974824UL)) { -static void phannot_Free( - void *p, /* The parser to be deleted */ - void (*freeProc)(void*) /* Function used to reclaim memory */ -){ - jjParser *pParser = (jjParser*)p; - if( pParser==0 ) return; - while( pParser->jjidx>=0 ) jj_pop_parser_stack(pParser); - (*freeProc)((void*)pParser); + PHALCON_OBS_VAR(joins); + phalcon_array_fetch_quick_string(&joins, definition, SS("joins"), 120974824UL, PH_NOISY); + + if (!phalcon_is_iterable_ex(joins, &ah2, &hp2, 0, 0)) { + return; + } + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_FOREACH_VALUE(join); + + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, join, SS("type"), 276192743UL, PH_NOISY); + + PHALCON_OBS_NVAR(table); + phalcon_array_fetch_quick_string(&table, join, SS("source"), 2744839734UL, PH_NOISY); + + PHALCON_INIT_NVAR(sql_table); + phalcon_call_method_p2_key(sql_table, this_ptr, "getsqltable", table, escape_char, 2837135293UL); + phalcon_array_append(&selected_tables, sql_table, PH_SEPARATE); + + PHALCON_INIT_NVAR(sql_join); + PHALCON_CONCAT_SVSV(sql_join, " ", type, " JOIN ", sql_table); + + if (phalcon_array_isset_quick_string(join, SS("conditions"), 1055696255UL)) { + + PHALCON_OBS_NVAR(join_conditions_array); + phalcon_array_fetch_quick_string(&join_conditions_array, join, SS("conditions"), 1055696255UL, PH_NOISY); + if (phalcon_fast_count_ev(join_conditions_array TSRMLS_CC)) { + + PHALCON_INIT_NVAR(join_expressions); + array_init(join_expressions); + + if (!phalcon_is_iterable_ex(join_conditions_array, &ah3, &hp3, 0, 0)) { + return; + } + + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { + + PHALCON_GET_FOREACH_VALUE(join_condition); + + PHALCON_INIT_NVAR(join_expression); + phalcon_call_method_p2_key(join_expression, this_ptr, "getsqlexpression", join_condition, escape_char, 3377787077UL); + phalcon_array_append(&join_expressions, join_expression, PH_SEPARATE); + + zend_hash_move_forward_ex(ah3, &hp3); + } + + PHALCON_INIT_NVAR(join_conditions); + phalcon_fast_join_str(join_conditions, SL(" AND "), join_expressions TSRMLS_CC); + PHALCON_SCONCAT_SV(sql_join, " ON ", join_conditions); + } + } + + phalcon_concat_self(&sql, sql_join TSRMLS_CC); + + zend_hash_move_forward_ex(ah2, &hp2); + } + + } + + if (phalcon_array_isset_quick_string(definition, SS("where"), 621293632UL)) { + + PHALCON_OBS_VAR(where_conditions); + phalcon_array_fetch_quick_string(&where_conditions, definition, SS("where"), 621293632UL, PH_NOISY); + if (Z_TYPE_P(where_conditions) == IS_ARRAY) { + PHALCON_INIT_VAR(where_expression); + phalcon_call_method_p2_key(where_expression, this_ptr, "getsqlexpression", where_conditions, escape_char, 3377787077UL); + PHALCON_SCONCAT_SV(sql, " WHERE ", where_expression); + } else { + PHALCON_SCONCAT_SV(sql, " WHERE ", where_conditions); + } + } + + if (phalcon_array_isset_quick_string(definition, SS("group"), 7349554UL)) { + + PHALCON_INIT_VAR(group_items); + array_init(group_items); + + PHALCON_OBS_VAR(group_fields); + phalcon_array_fetch_quick_string(&group_fields, definition, SS("group"), 7349554UL, PH_NOISY); + + if (!phalcon_is_iterable_ex(group_fields, &ah4, &hp4, 0, 0)) { + return; + } + + while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { + + PHALCON_GET_FOREACH_VALUE(group_field); + + PHALCON_INIT_NVAR(group_expression); + phalcon_call_method_p2_key(group_expression, this_ptr, "getsqlexpression", group_field, escape_char, 3377787077UL); + phalcon_array_append(&group_items, group_expression, PH_SEPARATE); + + zend_hash_move_forward_ex(ah4, &hp4); + } + + PHALCON_INIT_VAR(group_sql); + phalcon_fast_join_str(group_sql, SL(", "), group_items TSRMLS_CC); + + PHALCON_INIT_VAR(group_clause); + PHALCON_CONCAT_SV(group_clause, " GROUP BY ", group_sql); + phalcon_concat_self(&sql, group_clause TSRMLS_CC); + + if (phalcon_array_isset_quick_string(definition, SS("having"), 876572994UL)) { + PHALCON_OBS_VAR(having_conditions); + phalcon_array_fetch_quick_string(&having_conditions, definition, SS("having"), 876572994UL, PH_NOISY); + + PHALCON_INIT_VAR(having_expression); + phalcon_call_method_p2_key(having_expression, this_ptr, "getsqlexpression", having_conditions, escape_char, 3377787077UL); + PHALCON_SCONCAT_SV(sql, " HAVING ", having_expression); + } + } + + if (phalcon_array_isset_quick_string(definition, SS("order"), 320020033UL)) { + + PHALCON_OBS_VAR(order_fields); + phalcon_array_fetch_quick_string(&order_fields, definition, SS("order"), 320020033UL, PH_NOISY); + + PHALCON_INIT_VAR(order_items); + array_init(order_items); + + if (!phalcon_is_iterable_ex(order_fields, &ah5, &hp5, 0, 0)) { + return; + } + + while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { + + PHALCON_GET_FOREACH_VALUE(order_item); + + PHALCON_OBS_NVAR(order_expression); + phalcon_array_fetch_long(&order_expression, order_item, 0, PH_NOISY); + + PHALCON_INIT_NVAR(order_sql_item); + phalcon_call_method_p2_key(order_sql_item, this_ptr, "getsqlexpression", order_expression, escape_char, 3377787077UL); + + if (phalcon_array_isset_long(order_item, 1)) { + PHALCON_OBS_NVAR(sql_order_type); + phalcon_array_fetch_long(&sql_order_type, order_item, 1, PH_NOISY); + + PHALCON_INIT_NVAR(order_sql_item_type); + PHALCON_CONCAT_VSV(order_sql_item_type, order_sql_item, " ", sql_order_type); + } else { + PHALCON_CPY_WRT(order_sql_item_type, order_sql_item); + } + + phalcon_array_append(&order_items, order_sql_item_type, PH_SEPARATE); + + zend_hash_move_forward_ex(ah5, &hp5); + } + + PHALCON_INIT_VAR(order_sql); + phalcon_fast_join_str(order_sql, SL(", "), order_items TSRMLS_CC); + PHALCON_SCONCAT_SV(sql, " ORDER BY ", order_sql); + } + + if (phalcon_array_isset_quick_string(definition, SS("limit"), 192268420UL)) { + + PHALCON_OBS_VAR(limit_value); + phalcon_array_fetch_quick_string(&limit_value, definition, SS("limit"), 192268420UL, PH_NOISY); + + if (Z_TYPE_P(limit_value) == IS_ARRAY) { + + PHALCON_OBS_VAR(number); + phalcon_array_fetch_quick_string(&number, limit_value, SS("number"), 807219790UL, PH_NOISY); + + if (phalcon_array_isset_quick_string(limit_value, SS("offset"), 1503966412UL)) { + PHALCON_OBS_VAR(offset); + phalcon_array_fetch_quick_string(&offset, limit_value, SS("offset"), 1503966412UL, PH_NOISY); + } else { + PHALCON_INIT_VAR(offset); + ZVAL_LONG(offset, 0); + } + + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + + PHALCON_INIT_VAR(ini_range); + phalcon_add_function(ini_range, offset, one TSRMLS_CC); + + PHALCON_INIT_VAR(end_range); + phalcon_add_function(end_range, offset, number TSRMLS_CC); + + PHALCON_INIT_VAR(sql_limit); + PHALCON_SCONCAT_SVSVSV(sql_limit,"SELECT Z2.* FROM (SELECT Z1.*, ROWNUM DB_ROWNUM FROM ( ", sql, " ) Z1 ) Z2 WHERE Z2.DB_ROWNUM BETWEEN ", ini_range , " AND ", end_range ); + PHALCON_CPY_WRT(sql, sql_limit); + + } else { + + PHALCON_INIT_VAR(offset); + ZVAL_LONG(offset, 0); + + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + + PHALCON_INIT_VAR(ini_range); + phalcon_add_function(ini_range, offset, one TSRMLS_CC); + + PHALCON_INIT_VAR(end_range); + phalcon_add_function(end_range, offset, limit_value TSRMLS_CC); + + PHALCON_INIT_VAR(sql_limit); + PHALCON_SCONCAT_SVSVSV(sql_limit,"SELECT Z2.* FROM (SELECT Z1.*, ROWNUM DB_ROWNUM FROM ( ", sql, " ) Z1 ) Z2 WHERE Z2.DB_ROWNUM BETWEEN ", ini_range , " AND ", end_range ); + PHALCON_CPY_WRT(sql, sql_limit); + } + } + + RETURN_CTOR(sql); } -static int jj_find_shift_action( - jjParser *pParser, /* The parser */ - int iLookAhead /* The look-ahead token */ -){ - int i; - int stateno = pParser->jjstack[pParser->jjidx].stateno; - - /* if( pParser->jjidx<0 ) return JJ_NO_ACTION; */ - i = jj_shift_ofst[stateno]; - if( i==JJ_SHIFT_USE_DFLT ){ - return jj_default[stateno]; - } - if( iLookAhead==JJNOCODE ){ - return JJ_NO_ACTION; - } - i += iLookAhead; - if( i<0 || i>=JJ_SZ_ACTTAB || jj_lookahead[i]!=iLookAhead ){ -#ifdef JJFALLBACK - int iFallback; /* Fallback token */ - if( iLookAhead %s\n", - jjTracePrompt, jjTokenName[iLookAhead], jjTokenName[iFallback]); - } -#endif - return jj_find_shift_action(pParser, iFallback); - } -#endif - return jj_default[stateno]; - }else{ - return jj_action[i]; - } +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, supportsSavepoints){ + + + RETURN_FALSE; } -static int jj_find_reduce_action( - jjParser *pParser, /* The parser */ - int iLookAhead /* The look-ahead token */ -){ - int i; - int stateno = pParser->jjstack[pParser->jjidx].stateno; - - i = jj_reduce_ofst[stateno]; - if( i==JJ_REDUCE_USE_DFLT ){ - return jj_default[stateno]; - } - if( iLookAhead==JJNOCODE ){ - return JJ_NO_ACTION; - } - i += iLookAhead; - if( i<0 || i>=JJ_SZ_ACTTAB || jj_lookahead[i]!=iLookAhead ){ - return jj_default[stateno]; - }else{ - return jj_action[i]; - } +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, supportsReleaseSavepoints){ + + + RETURN_FALSE; } -static void jj_shift( - jjParser *jjpParser, /* The parser to be shifted */ - int jjNewState, /* The new state to shift in */ - int jjMajor, /* The major token to shift in */ - JJMINORTYPE *jjpMinor /* Pointer ot the minor token to shift in */ -){ - jjStackEntry *jjtos; - jjpParser->jjidx++; - if( jjpParser->jjidx>=JJSTACKDEPTH ){ - phannot_ARG_FETCH; - jjpParser->jjidx--; -#ifndef NDEBUG - if( jjTraceFILE ){ - fprintf(jjTraceFILE,"%sStack Overflow!\n",jjTracePrompt); - } -#endif - while( jjpParser->jjidx>=0 ) jj_pop_parser_stack(jjpParser); - /* Here code is inserted which will execute if the parser - ** stack every overflows */ - phannot_ARG_STORE; /* Suppress warning about unused %extra_argument var */ - return; - } - jjtos = &jjpParser->jjstack[jjpParser->jjidx]; - jjtos->stateno = jjNewState; - jjtos->major = jjMajor; - jjtos->minor = *jjpMinor; -#ifndef NDEBUG - if( jjTraceFILE && jjpParser->jjidx>0 ){ - int i; - fprintf(jjTraceFILE,"%sShift %d\n",jjTracePrompt,jjNewState); - fprintf(jjTraceFILE,"%sStack:",jjTracePrompt); - for(i=1; i<=jjpParser->jjidx; i++) - fprintf(jjTraceFILE," %s",jjTokenName[jjpParser->jjstack[i].major]); - fprintf(jjTraceFILE,"\n"); - } + + + + +#ifdef HAVE_CONFIG_H #endif -} -/* The following table contains information about every rule that -** is used during the reduce. -*/ -static struct { - JJCODETYPE lhs; /* Symbol on the left-hand side of the rule */ - unsigned char nrhs; /* Number of right-hand side symbols in the rule */ -} jjRuleInfo[] = { - { 19, 1 }, - { 20, 1 }, - { 21, 2 }, - { 21, 1 }, - { 22, 5 }, - { 22, 4 }, - { 22, 2 }, - { 23, 3 }, - { 23, 1 }, - { 24, 1 }, - { 24, 3 }, - { 24, 3 }, - { 24, 3 }, - { 24, 3 }, - { 25, 1 }, - { 25, 1 }, - { 25, 1 }, - { 25, 1 }, - { 25, 1 }, - { 25, 1 }, - { 25, 1 }, - { 25, 1 }, - { 25, 1 }, - { 26, 3 }, - { 26, 3 }, -}; -static void jj_accept(jjParser*); /* Forward Declaration */ -static void jj_reduce( - jjParser *jjpParser, /* The parser */ - int jjruleno /* Number of the rule by which to reduce */ -){ - int jjgoto; /* The next state */ - int jjact; /* The next action */ - JJMINORTYPE jjgotominor; /* The LHS of the rule reduced */ - jjStackEntry *jjmsp; /* The top of the parser's stack */ - int jjsize; /* Amount to pop the stack */ - phannot_ARG_FETCH; - jjmsp = &jjpParser->jjstack[jjpParser->jjidx]; -#ifndef NDEBUG - if( jjTraceFILE && jjruleno>=0 - && jjruleno - ** { ... } // User supplied code - ** // - ** break; - */ - case 0: -// 231 "parser.lemon" -{ - status->ret = jjmsp[0].minor.jj36; -} -// 759 "parser.c" - break; - case 1: - case 14: - case 15: -// 237 "parser.lemon" -{ - jjgotominor.jj36 = jjmsp[0].minor.jj36; -} -// 768 "parser.c" - break; - case 2: -// 243 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_zval_list(jjmsp[-1].minor.jj36, jjmsp[0].minor.jj36); -} -// 775 "parser.c" - break; - case 3: - case 8: -// 247 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_zval_list(NULL, jjmsp[0].minor.jj36); -} -// 783 "parser.c" - break; - case 4: -// 254 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_annotation(jjmsp[-3].minor.jj0, jjmsp[-1].minor.jj36, status->scanner_state); - jj_destructor(2,&jjmsp[-4].minor); - jj_destructor(4,&jjmsp[-2].minor); - jj_destructor(5,&jjmsp[0].minor); -} -// 793 "parser.c" - break; - case 5: -// 258 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_annotation(jjmsp[-2].minor.jj0, NULL, status->scanner_state); - jj_destructor(2,&jjmsp[-3].minor); - jj_destructor(4,&jjmsp[-1].minor); - jj_destructor(5,&jjmsp[0].minor); -} -// 803 "parser.c" - break; - case 6: -// 262 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_annotation(jjmsp[0].minor.jj0, NULL, status->scanner_state); - jj_destructor(2,&jjmsp[-1].minor); -} -// 811 "parser.c" - break; - case 7: -// 268 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_zval_list(jjmsp[-2].minor.jj36, jjmsp[0].minor.jj36); - jj_destructor(1,&jjmsp[-1].minor); -} -// 819 "parser.c" - break; - case 9: -// 278 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_named_item(NULL, jjmsp[0].minor.jj36); -} -// 826 "parser.c" - break; - case 10: - case 12: -// 282 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_named_item(jjmsp[-2].minor.jj0, jjmsp[0].minor.jj36); - jj_destructor(7,&jjmsp[-1].minor); -} -// 835 "parser.c" - break; - case 11: - case 13: -// 286 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_named_item(jjmsp[-2].minor.jj0, jjmsp[0].minor.jj36); - jj_destructor(8,&jjmsp[-1].minor); -} -// 844 "parser.c" - break; - case 16: -// 308 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_IDENTIFIER, jjmsp[0].minor.jj0); + + + +PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Postgresql){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Postgresql, db_dialect_postgresql, "phalcon\\db\\dialect", phalcon_db_dialect_postgresql_method_entry, 0); + + zend_declare_property_string(phalcon_db_dialect_postgresql_ce, SL("_escapeChar"), "\"", ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_db_dialect_postgresql_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); + + return SUCCESS; } -// 851 "parser.c" - break; - case 17: -// 312 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_INTEGER, jjmsp[0].minor.jj0); + +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, getColumnDefinition){ + + zval *column, *size, *column_type, *column_sql = NULL; + zval *scale; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &column); + + if (Z_TYPE_P(column) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column definition must be an object compatible with Phalcon\\Db\\ColumnInterface"); + return; + } + + PHALCON_INIT_VAR(size); + phalcon_call_method_key(size, column, "getsize", 4292672352UL); + + PHALCON_INIT_VAR(column_type); + phalcon_call_method_key(column_type, column, "gettype", 4294422375UL); + + switch (phalcon_get_intval(column_type)) { + + case 0: + PHALCON_INIT_VAR(column_sql); + ZVAL_STRING(column_sql, "INT", 1); + break; + + case 1: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "DATE", 1); + break; + + case 2: + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVS(column_sql, "CHARACTER VARYING(", size, ")"); + break; + + case 3: + PHALCON_INIT_VAR(scale); + phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVSVS(column_sql, "NUMERIC(", size, ",", scale, ")"); + break; + + case 4: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "TIMESTAMP", 1); + break; + + case 5: + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVS(column_sql, "CHARACTER(", size, ")"); + break; + + case 6: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "TEXT", 1); + break; + + case 7: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "FLOAT", 1); + break; + + case 8: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "SMALLINT(1)", 1); + break; + + default: + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized PostgreSQL data type"); + return; + + } + + RETURN_CTOR(column_sql); } -// 858 "parser.c" - break; - case 18: -// 316 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_STRING, jjmsp[0].minor.jj0); + +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addColumn){ + + zval *table_name, *schema_name, *column; + + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -// 865 "parser.c" - break; - case 19: -// 320 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_DOUBLE, jjmsp[0].minor.jj0); + +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, modifyColumn){ + + zval *table_name, *schema_name, *column; + + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -// 872 "parser.c" - break; - case 20: -// 324 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_NULL, NULL); - jj_destructor(11,&jjmsp[0].minor); + +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropColumn){ + + zval *table_name, *schema_name, *column_name; + + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column_name); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -// 880 "parser.c" - break; - case 21: -// 328 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_FALSE, NULL); - jj_destructor(12,&jjmsp[0].minor); + +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addIndex){ + + zval *table_name, *schema_name, *index; + + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -// 888 "parser.c" - break; - case 22: -// 332 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_literal_zval(PHANNOT_T_TRUE, NULL); - jj_destructor(13,&jjmsp[0].minor); + +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropIndex){ + + zval *table_name, *schema_name, *index_name; + + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index_name); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -// 896 "parser.c" - break; - case 23: -// 336 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_array(jjmsp[-1].minor.jj36); - jj_destructor(14,&jjmsp[-2].minor); - jj_destructor(15,&jjmsp[0].minor); + +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addPrimaryKey){ + + zval *table_name, *schema_name, *index; + + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -// 905 "parser.c" - break; - case 24: -// 340 "parser.lemon" -{ - jjgotominor.jj36 = phannot_ret_array(jjmsp[-1].minor.jj36); - jj_destructor(16,&jjmsp[-2].minor); - jj_destructor(17,&jjmsp[0].minor); + +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropPrimaryKey){ + + zval *table_name, *schema_name; + + phalcon_fetch_params(0, 2, 0, &table_name, &schema_name); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -// 914 "parser.c" - break; - }; - jjgoto = jjRuleInfo[jjruleno].lhs; - jjsize = jjRuleInfo[jjruleno].nrhs; - jjpParser->jjidx -= jjsize; - jjact = jj_find_reduce_action(jjpParser,jjgoto); - if( jjact < JJNSTATE ){ - jj_shift(jjpParser,jjact,jjgoto,&jjgotominor); - }else if( jjact == JJNSTATE + JJNRULE + 1 ){ - jj_accept(jjpParser); - } + +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addForeignKey){ + + zval *table_name, *schema_name, *reference; + + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -static void jj_parse_failed( - jjParser *jjpParser /* The parser */ -){ - phannot_ARG_FETCH; -#ifndef NDEBUG - if( jjTraceFILE ){ - fprintf(jjTraceFILE,"%sFail!\n",jjTracePrompt); - } -#endif - while( jjpParser->jjidx>=0 ) jj_pop_parser_stack(jjpParser); - /* Here code is inserted which will be executed whenever the - ** parser fails */ - phannot_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropForeignKey){ + + zval *table_name, *schema_name, *reference_name; + + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference_name); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -static void jj_syntax_error( - jjParser *jjpParser, /* The parser */ - int jjmajor, /* The major type of the error token */ - JJMINORTYPE jjminor /* The minor type of the error token */ -){ - phannot_ARG_FETCH; -#define JTOKEN (jjminor.jj0) -// 159 "parser.lemon" +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, _getTableOptions){ - if (status->scanner_state->start_length) { - { + zval *definition; - char *token_name = NULL; - const phannot_token_names *tokens = phannot_tokens; - int token_found = 0; - int active_token = status->scanner_state->active_token; - int near_length = status->scanner_state->start_length; + phalcon_fetch_params(0, 1, 0, &definition); + + RETURN_EMPTY_ARRAY(); +} - if (active_token) { - do { - if (tokens->code == active_token) { - token_found = 1; - token_name = tokens->name; - break; - } - ++tokens; - } while (tokens[0].code != 0); - } +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, createTable){ - if (!token_name) { - token_found = 0; - token_name = estrndup("UNKNOWN", strlen("UNKNOWN")); - } + zval *table_name, *schema_name, *definition; - status->syntax_error_len = 128 + strlen(token_name) + Z_STRLEN_P(status->scanner_state->active_file); - status->syntax_error = emalloc(sizeof(char) * status->syntax_error_len); + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &definition); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; +} - if (near_length > 0) { - if (status->token->value) { - snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), near to '%s' in %s on line %d", token_name, status->token->value, status->scanner_state->start, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line); - } else { - snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, near to '%s' in %s on line %d", token_name, status->scanner_state->start, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line); - } - } else { - if (active_token != PHANNOT_T_IGNORE) { - if (status->token->value) { - snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), at the end of docblock in %s on line %d", token_name, status->token->value, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line); - } else { - snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, at the end of docblock in %s on line %d", token_name, Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line); - } - } else { - snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected EOF, at the end of docblock in %s on line %d", Z_STRVAL_P(status->scanner_state->active_file), status->scanner_state->active_line); - } - status->syntax_error[status->syntax_error_len-1] = '\0'; - } +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropTable){ - if (!token_found) { - if (token_name) { - efree(token_name); - } - } - } + zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; + zval *sql = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); + + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); + } + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(table); + PHALCON_CONCAT_VSV(table, schema_name, ".", table_name); } else { - status->syntax_error_len = 48 + Z_STRLEN_P(status->scanner_state->active_file); - status->syntax_error = emalloc(sizeof(char) * status->syntax_error_len); - sprintf(status->syntax_error, "Syntax error, unexpected EOF in %s", Z_STRVAL_P(status->scanner_state->active_file)); + PHALCON_CPY_WRT(table, table_name); } + if (zend_is_true(if_exists)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SV(sql, "DROP TABLE IF EXISTS ", table); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SV(sql, "DROP TABLE ", table); + } + + RETURN_CTOR(sql); +} - status->status = PHANNOT_PARSING_FAILED; +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, createView){ -// 1019 "parser.c" - phannot_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} + zval *view_name, *definition, *schema_name, *view_sql; + zval *view = NULL, *sql; -static void jj_accept( - jjParser *jjpParser /* The parser */ -){ - phannot_ARG_FETCH; -#ifndef NDEBUG - if( jjTraceFILE ){ - fprintf(jjTraceFILE,"%sAccept!\n",jjTracePrompt); - } -#endif - while( jjpParser->jjidx>=0 ) jj_pop_parser_stack(jjpParser); - /* Here code is inserted which will be executed whenever the - ** parser accepts */ - phannot_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); + + if (!phalcon_array_isset_quick_string(definition, SS("sql"), 2090732981UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'sql' is required in the definition array"); + return; + } + + PHALCON_OBS_VAR(view_sql); + phalcon_array_fetch_quick_string(&view_sql, definition, SS("sql"), 2090732981UL, PH_NOISY); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(view); + PHALCON_CONCAT_VSV(view, view_name, ".", schema_name); + } else { + PHALCON_CPY_WRT(view, view_name); + } + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); + + RETURN_CTOR(sql); } -/* The main parser program. -** The first argument is a pointer to a structure obtained from -** "phannot_Alloc" which describes the current state of the parser. -** The second argument is the major token number. The third is -** the minor token. The fourth optional argument is whatever the -** user wants (and specified in the grammar) and is available for -** use by the action routines. -** -** Inputs: -**
    -**
  • A pointer to the parser (an opaque structure.) -**
  • The major token number. -**
  • The minor token number. -**
  • An option argument of a grammar-specified type. -**
-** -** Outputs: -** None. -*/ -static void phannot_( - void *jjp, /* The parser */ - int jjmajor, /* The major token code number */ - phannot_JTOKENTYPE jjminor /* The value for the token */ - phannot_ARG_PDECL /* Optional %extra_argument parameter */ -){ - JJMINORTYPE jjminorunion; - int jjact; /* The parser action. */ - int jjendofinput; /* True if we are at the end of input */ - int jjerrorhit = 0; /* True if jjmajor has invoked an error */ - jjParser *jjpParser; /* The parser */ +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropView){ - /* (re)initialize the parser, if necessary */ - jjpParser = (jjParser*)jjp; - if( jjpParser->jjidx<0 ){ - if( jjmajor==0 ) return; - jjpParser->jjidx = 0; - jjpParser->jjerrcnt = -1; - jjpParser->jjstack[0].stateno = 0; - jjpParser->jjstack[0].major = 0; - } - jjminorunion.jj0 = jjminor; - jjendofinput = (jjmajor==0); - phannot_ARG_STORE; + zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; + zval *sql = NULL; -#ifndef NDEBUG - if( jjTraceFILE ){ - fprintf(jjTraceFILE,"%sInput %s\n",jjTracePrompt,jjTokenName[jjmajor]); - } -#endif + PHALCON_MM_GROW(); - do{ - jjact = jj_find_shift_action(jjpParser,jjmajor); - if( jjactjjerrcnt--; - if( jjendofinput && jjpParser->jjidx>=0 ){ - jjmajor = 0; - }else{ - jjmajor = JJNOCODE; - } - }else if( jjact < JJNSTATE + JJNRULE ){ - jj_reduce(jjpParser,jjact-JJNSTATE); - }else if( jjact == JJ_ERROR_ACTION ){ - int jjmx; -#ifndef NDEBUG - if( jjTraceFILE ){ - fprintf(jjTraceFILE,"%sSyntax Error!\n",jjTracePrompt); - } -#endif -#ifdef JJERRORSYMBOL - /* A syntax error has occurred. - ** The response to an error depends upon whether or not the - ** grammar defines an error token "ERROR". - ** - ** This is what we do if the grammar does define ERROR: - ** - ** * Call the %syntax_error function. - ** - ** * Begin popping the stack until we enter a state where - ** it is legal to shift the error symbol, then shift - ** the error symbol. - ** - ** * Set the error count to three. - ** - ** * Begin accepting and shifting new tokens. No new error - ** processing will occur until three tokens have been - ** shifted successfully. - ** - */ - if( jjpParser->jjerrcnt<0 ){ - jj_syntax_error(jjpParser,jjmajor,jjminorunion); - } - jjmx = jjpParser->jjstack[jjpParser->jjidx].major; - if( jjmx==JJERRORSYMBOL || jjerrorhit ){ -#ifndef NDEBUG - if( jjTraceFILE ){ - fprintf(jjTraceFILE,"%sDiscard input token %s\n", - jjTracePrompt,jjTokenName[jjmajor]); - } -#endif - jj_destructor(jjmajor,&jjminorunion); - jjmajor = JJNOCODE; - }else{ - while( - jjpParser->jjidx >= 0 && - jjmx != JJERRORSYMBOL && - (jjact = jj_find_shift_action(jjpParser,JJERRORSYMBOL)) >= JJNSTATE - ){ - jj_pop_parser_stack(jjpParser); - } - if( jjpParser->jjidx < 0 || jjmajor==0 ){ - jj_destructor(jjmajor,&jjminorunion); - jj_parse_failed(jjpParser); - jjmajor = JJNOCODE; - }else if( jjmx!=JJERRORSYMBOL ){ - JJMINORTYPE u2; - u2.JJERRSYMDT = 0; - jj_shift(jjpParser,jjact,JJERRORSYMBOL,&u2); - } - } - jjpParser->jjerrcnt = 3; - jjerrorhit = 1; -#else /* JJERRORSYMBOL is not defined */ - /* This is what we do if the grammar does not define ERROR: - ** - ** * Report an error message, and throw away the input token. - ** - ** * If the input token is $, then fail the parse. - ** - ** As before, subsequent error messages are suppressed until - ** three input tokens have been successfully shifted. - */ - if( jjpParser->jjerrcnt<=0 ){ - jj_syntax_error(jjpParser,jjmajor,jjminorunion); - } - jjpParser->jjerrcnt = 3; - jj_destructor(jjmajor,&jjminorunion); - if( jjendofinput ){ - jj_parse_failed(jjpParser); - } - jjmajor = JJNOCODE; -#endif - }else{ - jj_accept(jjpParser); - jjmajor = JJNOCODE; - } - }while( jjmajor!=JJNOCODE && jjpParser->jjidx>=0 ); - return; + phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); + + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); + } + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(view); + PHALCON_CONCAT_VSV(view, view_name, ".", schema_name); + } else { + PHALCON_CPY_WRT(view, view_name); + } + if (zend_is_true(if_exists)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SV(sql, "DROP VIEW IF EXISTS ", view); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SV(sql, "DROP VIEW ", view); + } + + RETURN_CTOR(sql); } +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, tableExists){ -const phannot_token_names phannot_tokens[] = -{ - { "INTEGER", PHANNOT_T_INTEGER }, - { "DOUBLE", PHANNOT_T_DOUBLE }, - { "STRING", PHANNOT_T_STRING }, - { "IDENTIFIER", PHANNOT_T_IDENTIFIER }, - { "@", PHANNOT_T_AT }, - { ",", PHANNOT_T_COMMA }, - { "=", PHANNOT_T_EQUALS }, - { ":", PHANNOT_T_COLON }, - { "(", PHANNOT_T_PARENTHESES_OPEN }, - { ")", PHANNOT_T_PARENTHESES_CLOSE }, - { "{", PHANNOT_T_BRACKET_OPEN }, - { "}", PHANNOT_T_BRACKET_CLOSE }, - { "[", PHANNOT_T_SBRACKET_OPEN }, - { "]", PHANNOT_T_SBRACKET_CLOSE }, - { "ARBITRARY TEXT", PHANNOT_T_ARBITRARY_TEXT }, - { NULL, 0 } -}; + zval *table_name, *schema_name = NULL, *sql = NULL; -static void *phannot_wrapper_alloc(size_t bytes){ - return emalloc(bytes); -} + PHALCON_MM_GROW(); -static void phannot_wrapper_free(void *pointer){ - efree(pointer); + phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM information_schema.tables WHERE table_schema = '", schema_name, "' AND table_name='", table_name, "'"); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM information_schema.tables WHERE table_schema = 'public' AND table_name='", table_name, "'"); + } + + RETURN_CTOR(sql); } -static void phannot_parse_with_token(void* phannot_parser, int opcode, int parsercode, phannot_scanner_token *token, phannot_parser_status *parser_status){ - - phannot_parser_token *pToken; +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, viewExists){ - pToken = emalloc(sizeof(phannot_parser_token)); - pToken->opcode = opcode; - pToken->token = token->value; - pToken->token_len = token->len; - pToken->free_flag = 1; + zval *view_name, *schema_name = NULL, *sql = NULL; - phannot_(phannot_parser, parsercode, pToken, parser_status); + PHALCON_MM_GROW(); - token->value = NULL; - token->len = 0; + phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM pg_views WHERE viewname='", view_name, "' AND schemaname='", schema_name, "'"); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM pg_views WHERE viewname='", view_name, "'"); + } + + RETURN_CTOR(sql); } -static void phannot_scanner_error_msg(phannot_parser_status *parser_status, zval **error_msg TSRMLS_DC){ +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, describeColumns){ - int error_length; - char *error, *error_part; - phannot_scanner_state *state = parser_status->scanner_state; + zval *table, *schema = NULL, *sql = NULL; - PHALCON_INIT_VAR(*error_msg); - if (state->start) { - error_length = 128 + state->start_length + Z_STRLEN_P(state->active_file); - error = emalloc(sizeof(char) * error_length); - if (state->start_length > 16) { - error_part = estrndup(state->start, 16); - snprintf(error, 64 + state->start_length, "Scanning error before '%s...' in %s on line %d", error_part, Z_STRVAL_P(state->active_file), state->active_line); - efree(error_part); - } else { - snprintf(error, error_length - 1, "Scanning error before '%s' in %s on line %d", state->start, Z_STRVAL_P(state->active_file), state->active_line); - } - error[error_length - 1] = '\0'; - ZVAL_STRING(*error_msg, error, 1); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + if (zend_is_true(schema)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSVS(sql, "SELECT DISTINCT c.column_name AS Field, c.data_type AS Type, c.character_maximum_length AS Size, c.numeric_precision AS NumericSize, c.is_nullable AS Null, CASE WHEN pkc.column_name NOTNULL THEN 'PRI' ELSE '' END AS Key, CASE WHEN c.data_type LIKE '%int%' AND c.column_default LIKE '%nextval%' THEN 'auto_increment' ELSE '' END AS Extra, c.ordinal_position AS Position FROM information_schema.columns c LEFT JOIN ( SELECT kcu.column_name, kcu.table_name, kcu.table_schema FROM information_schema.table_constraints tc INNER JOIN information_schema.key_column_usage kcu on (kcu.constraint_name = tc.constraint_name and kcu.table_name=tc.table_name and kcu.table_schema=tc.table_schema) WHERE tc.constraint_type='PRIMARY KEY') pkc ON (c.column_name=pkc.column_name AND c.table_schema = pkc.table_schema AND c.table_name=pkc.table_name) WHERE c.table_schema='", schema, "' AND c.table_name='", table, "' ORDER BY c.ordinal_position"); } else { - error_length = sizeof(char) * (64 + Z_STRLEN_P(state->active_file)); - error = emalloc(error_length); - snprintf(error, error_length - 1, "Scanning error near to EOF in %s", Z_STRVAL_P(state->active_file)); - ZVAL_STRING(*error_msg, error, 1); - error[error_length - 1] = '\0'; + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT DISTINCT c.column_name AS Field, c.data_type AS Type, c.character_maximum_length AS Size, c.numeric_precision AS NumericSize, c.is_nullable AS Null, CASE WHEN pkc.column_name NOTNULL THEN 'PRI' ELSE '' END AS Key, CASE WHEN c.data_type LIKE '%int%' AND c.column_default LIKE '%nextval%' THEN 'auto_increment' ELSE '' END AS Extra, c.ordinal_position AS Position FROM information_schema.columns c LEFT JOIN ( SELECT kcu.column_name, kcu.table_name, kcu.table_schema FROM information_schema.table_constraints tc INNER JOIN information_schema.key_column_usage kcu on (kcu.constraint_name = tc.constraint_name and kcu.table_name=tc.table_name and kcu.table_schema=tc.table_schema) WHERE tc.constraint_type='PRIMARY KEY') pkc ON (c.column_name=pkc.column_name AND c.table_schema = pkc.table_schema AND c.table_name=pkc.table_name) WHERE c.table_schema='public' AND c.table_name='", table, "' ORDER BY c.ordinal_position"); } - efree(error); + + RETURN_CTOR(sql); } -static int phannot_parse_annotations(zval *result, zval *comment, zval *file_path, zval *line TSRMLS_DC){ +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, listTables){ - zval *error_msg = NULL; + zval *schema_name = NULL, *sql = NULL; - ZVAL_NULL(result); + PHALCON_MM_GROW(); - if (Z_TYPE_P(comment) != IS_STRING) { - phalcon_throw_exception_string(phalcon_annotations_exception_ce, SL("Comment must be a string"), 1 TSRMLS_CC); - return FAILURE; + phalcon_fetch_params(1, 0, 1, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - - if(phannot_internal_parse_annotations(&result, comment, file_path, line, &error_msg TSRMLS_CC) == FAILURE){ - phalcon_throw_exception_string(phalcon_annotations_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC); - return FAILURE; + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT table_name FROM information_schema.tables WHERE table_schema = '", schema_name, "' ORDER BY table_name"); + } else { + PHALCON_INIT_NVAR(sql); + ZVAL_STRING(sql, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name", 1); } - - return SUCCESS; + + RETURN_CTOR(sql); } -static void phannot_remove_comment_separators(zval *return_value, char *comment, int length, int *start_lines) { - - int start_mode = 1, j, i, open_parentheses; - smart_str processed_str = {0}; - char ch; +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, listViews){ - (*start_lines) = 0; + zval *schema_name = NULL, *sql = NULL; - for (i = 0; i < length; i++) { + PHALCON_MM_GROW(); - ch = comment[i]; + phalcon_fetch_params(1, 0, 1, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT viewname AS view_name FROM pg_views WHERE schemaname = '", schema_name, "' ORDER BY view_name"); + } else { + PHALCON_INIT_NVAR(sql); + ZVAL_STRING(sql, "SELECT viewname AS view_name FROM pg_views WHERE schemaname = 'public' ORDER BY view_name", 1); + } + + RETURN_CTOR(sql); +} - if (start_mode) { - if (ch == ' ' || ch == '*' || ch == '/' || ch == '\t' || ch == 11) { - continue; - } - start_mode = 0; - } +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, describeIndexes){ - if (ch == '@') { + zval *table, *schema = NULL, *sql; - smart_str_appendc(&processed_str, ch); - i++; + PHALCON_MM_GROW(); - open_parentheses = 0; - for (j = i; j < length; j++) { + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT 0 as c0, t.relname as table_name, i.relname as key_name, 3 as c3, a.attname as column_name FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND a.attnum = ANY(ix.indkey) AND t.relkind = 'r' AND t.relname = '", table, "' ORDER BY t.relname, i.relname;"); + RETURN_CTOR(sql); +} - ch = comment[j]; +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, describeReferences){ - if (start_mode) { - if (ch == ' ' || ch == '*' || ch == '/' || ch == '\t' || ch == 11) { - continue; - } - start_mode = 0; - } + zval *table, *schema = NULL, *sql; - if (open_parentheses == 0) { + PHALCON_MM_GROW(); - if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { - smart_str_appendc(&processed_str, ch); - continue; - } + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + PHALCON_INIT_VAR(sql); + ZVAL_STRING(sql, "SELECT tc.table_name as TABLE_NAME, kcu.column_name as COLUMN_NAME, tc.constraint_name as CONSTRAINT_NAME, tc.table_catalog as REFERENCED_TABLE_SCHEMA, ccu.table_name AS REFERENCED_TABLE_NAME, ccu.column_name AS REFERENCED_COLUMN_NAME FROM information_schema.table_constraints AS tc JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name WHERE constraint_type = 'FOREIGN KEY' AND ", 1); + if (zend_is_true(schema)) { + PHALCON_SCONCAT_SVSVS(sql, "tc.table_schema = '", schema, "' AND tc.table_name='", table, "'"); + } else { + PHALCON_SCONCAT_SVS(sql, "tc.table_name='", table, "'"); + } + + RETURN_CTOR(sql); +} - if (ch == '(') { - smart_str_appendc(&processed_str, ch); - open_parentheses++; - continue; - } +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, tableOptions){ - } else { + zval *table, *schema = NULL; - smart_str_appendc(&processed_str, ch); + PHALCON_MM_GROW(); - if (ch == '(') { - open_parentheses++; - } else { - if (ch == ')') { - open_parentheses--; - } else { - if (ch == '\n') { - (*start_lines)++; - start_mode = 1; - } - } - } + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + RETURN_MM_EMPTY_STRING(); +} - if (open_parentheses > 0) { - continue; - } - } - i = j; - smart_str_appendc(&processed_str, ' '); - break; - } - } - if (ch == '\n') { - (*start_lines)++; - start_mode = 1; - } - } - smart_str_0(&processed_str); - if (processed_str.len) { - RETURN_STRINGL(processed_str.c, processed_str.len, 0); - } else { - RETURN_EMPTY_STRING(); - } -} +#ifdef HAVE_CONFIG_H +#endif -static int phannot_internal_parse_annotations(zval **result, zval *comment, zval *file_path, zval *line, zval **error_msg TSRMLS_DC) { - char *error; - phannot_scanner_state *state; - phannot_scanner_token token; - int scanner_status, status = SUCCESS, start_lines, error_length; - phannot_parser_status *parser_status = NULL; - void* phannot_parser; - zval processed_comment; - if (!Z_STRVAL_P(comment)) { - ZVAL_BOOL(*result, 0); - return FAILURE; - } - if (Z_STRLEN_P(comment) < 2) { - ZVAL_BOOL(*result, 0); - return SUCCESS; - } - phannot_remove_comment_separators(&processed_comment, Z_STRVAL_P(comment), Z_STRLEN_P(comment), &start_lines); - if (Z_STRLEN(processed_comment) < 2) { - ZVAL_BOOL(*result, 0); - efree(Z_STRVAL(processed_comment)); - return SUCCESS; - } - phannot_parser = phannot_Alloc(phannot_wrapper_alloc); +PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Sqlite){ - parser_status = emalloc(sizeof(phannot_parser_status)); - state = emalloc(sizeof(phannot_scanner_state)); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Sqlite, db_dialect_sqlite, "phalcon\\db\\dialect", phalcon_db_dialect_sqlite_method_entry, 0); - parser_status->status = PHANNOT_PARSING_OK; - parser_status->scanner_state = state; - parser_status->ret = NULL; - parser_status->token = &token; - parser_status->syntax_error = NULL; + zend_declare_property_string(phalcon_db_dialect_sqlite_ce, SL("_escapeChar"), "\"", ZEND_ACC_PROTECTED TSRMLS_CC); - state->active_token = 0; - state->start = Z_STRVAL(processed_comment); - state->start_length = 0; - state->mode = PHANNOT_MODE_RAW; - state->active_file = file_path; + zend_class_implements(phalcon_db_dialect_sqlite_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); - token.value = NULL; - token.len = 0; + return SUCCESS; +} - if (Z_TYPE_P(line) == IS_LONG) { - state->active_line = Z_LVAL_P(line) - start_lines; - } else { - state->active_line = 1; +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, getColumnDefinition){ + + zval *column, *size, *column_type, *column_sql = NULL; + zval *scale; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &column); + + if (Z_TYPE_P(column) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column definition must be an instance of Phalcon\\Db\\Column"); + return; + } + + PHALCON_INIT_VAR(size); + phalcon_call_method_key(size, column, "getsize", 4292672352UL); + + PHALCON_INIT_VAR(column_type); + phalcon_call_method_key(column_type, column, "gettype", 4294422375UL); + + switch (phalcon_get_intval(column_type)) { + + case 0: + PHALCON_INIT_VAR(column_sql); + ZVAL_STRING(column_sql, "INT", 1); + break; + + case 1: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "DATE", 1); + break; + + case 2: + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVS(column_sql, "VARCHAR(", size, ")"); + break; + + case 3: + PHALCON_INIT_VAR(scale); + phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVSVS(column_sql, "NUMERIC(", size, ",", scale, ")"); + break; + + case 4: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "TIMESTAMP", 1); + break; + + case 5: + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_SVS(column_sql, "CHARACTER(", size, ")"); + break; + + case 6: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "TEXT", 1); + break; + + case 7: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "FLOAT", 1); + break; + + default: + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized SQLite data type"); + return; + } + + RETURN_CTOR(column_sql); +} - state->end = state->start; +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addColumn){ - while(0 <= (scanner_status = phannot_get_token(state, &token))) { + zval *table_name, *schema_name, *column, *sql = NULL, *name; + zval *column_definition, *is_not_null; - state->active_token = token.opcode; + PHALCON_MM_GROW(); - state->start_length = (Z_STRVAL(processed_comment) + Z_STRLEN(processed_comment) - state->start); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); - switch (token.opcode) { + if (Z_TYPE_P(column) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column parameter must be an instance of Phalcon\\Db\\Column"); + return; + } - case PHANNOT_T_IGNORE: - break; + PHALCON_INIT_VAR(sql); + if (zend_is_true(schema_name)) { + PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE \"", schema_name, "\".\"", table_name, "\" ADD COLUMN "); + } + else { + PHALCON_CONCAT_SVS(sql, "ALTER TABLE \"", table_name, "\" ADD COLUMN "); + } - case PHANNOT_T_AT: - phannot_(phannot_parser, PHANNOT_AT, NULL, parser_status); - break; - case PHANNOT_T_COMMA: - phannot_(phannot_parser, PHANNOT_COMMA, NULL, parser_status); - break; - case PHANNOT_T_EQUALS: - phannot_(phannot_parser, PHANNOT_EQUALS, NULL, parser_status); - break; - case PHANNOT_T_COLON: - phannot_(phannot_parser, PHANNOT_COLON, NULL, parser_status); - break; + PHALCON_INIT_VAR(name); + phalcon_call_method_key(name, column, "getname", 4286441094UL); - case PHANNOT_T_PARENTHESES_OPEN: - phannot_(phannot_parser, PHANNOT_PARENTHESES_OPEN, NULL, parser_status); - break; - case PHANNOT_T_PARENTHESES_CLOSE: - phannot_(phannot_parser, PHANNOT_PARENTHESES_CLOSE, NULL, parser_status); - break; + PHALCON_INIT_VAR(column_definition); + phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); + PHALCON_SCONCAT_SVSV(sql, "\"", name, "\" ", column_definition); - case PHANNOT_T_BRACKET_OPEN: - phannot_(phannot_parser, PHANNOT_BRACKET_OPEN, NULL, parser_status); - break; - case PHANNOT_T_BRACKET_CLOSE: - phannot_(phannot_parser, PHANNOT_BRACKET_CLOSE, NULL, parser_status); - break; + PHALCON_INIT_VAR(is_not_null); + phalcon_call_method_key(is_not_null, column, "isnotnull", 760409005UL); + if (zend_is_true(is_not_null)) { + phalcon_concat_self_str(&sql, SL(" NOT NULL") TSRMLS_CC); + } - case PHANNOT_T_SBRACKET_OPEN: - phannot_(phannot_parser, PHANNOT_SBRACKET_OPEN, NULL, parser_status); - break; - case PHANNOT_T_SBRACKET_CLOSE: - phannot_(phannot_parser, PHANNOT_SBRACKET_CLOSE, NULL, parser_status); - break; + RETURN_CTOR(sql); +} - case PHANNOT_T_NULL: - phannot_(phannot_parser, PHANNOT_NULL, NULL, parser_status); - break; - case PHANNOT_T_TRUE: - phannot_(phannot_parser, PHANNOT_TRUE, NULL, parser_status); - break; - case PHANNOT_T_FALSE: - phannot_(phannot_parser, PHANNOT_FALSE, NULL, parser_status); - break; +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, modifyColumn){ - case PHANNOT_T_INTEGER: - phannot_parse_with_token(phannot_parser, PHANNOT_T_INTEGER, PHANNOT_INTEGER, &token, parser_status); - break; - case PHANNOT_T_DOUBLE: - phannot_parse_with_token(phannot_parser, PHANNOT_T_DOUBLE, PHANNOT_DOUBLE, &token, parser_status); - break; - case PHANNOT_T_STRING: - phannot_parse_with_token(phannot_parser, PHANNOT_T_STRING, PHANNOT_STRING, &token, parser_status); - break; - case PHANNOT_T_IDENTIFIER: - phannot_parse_with_token(phannot_parser, PHANNOT_T_IDENTIFIER, PHANNOT_IDENTIFIER, &token, parser_status); - break; - /*case PHANNOT_T_ARBITRARY_TEXT: - phannot_parse_with_token(phannot_parser, PHANNOT_T_ARBITRARY_TEXT, PHANNOT_ARBITRARY_TEXT, &token, parser_status); - break;*/ + zval *table_name, *schema_name, *column; - default: - parser_status->status = PHANNOT_PARSING_FAILED; - if (!*error_msg) { - error_length = sizeof(char) * (48 + Z_STRLEN_P(state->active_file)); - error = emalloc(error_length); - snprintf(error, error_length - 1, "Scanner: unknown opcode %d on in %s line %d", token.opcode, Z_STRVAL_P(state->active_file), state->active_line); - error[error_length - 1] = '\0'; - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, error, 1); - efree(error); - } - break; - } + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Altering a DB column is not supported by SQLite"); + return; +} - if (parser_status->status != PHANNOT_PARSING_OK) { - status = FAILURE; - break; - } +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropColumn){ - state->end = state->start; - } + zval *table_name, *schema_name, *column_name; - if (status != FAILURE) { - switch (scanner_status) { - case PHANNOT_SCANNER_RETCODE_ERR: - case PHANNOT_SCANNER_RETCODE_IMPOSSIBLE: - if (!*error_msg) { - phannot_scanner_error_msg(parser_status, error_msg TSRMLS_CC); - } - status = FAILURE; - break; - default: - phannot_(phannot_parser, 0, NULL, parser_status); - } + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column_name); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Dropping DB column is not supported by SQLite"); + return; +} + +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addIndex){ + + zval *table_name, *schema_name, *index, *sql = NULL, *columns; + zval *quoted_column_list, *name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); + + if (Z_TYPE_P(index) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Index parameter must be an instance of Phalcon\\Db\\Index"); + return; } - state->active_token = 0; - state->start = NULL; + PHALCON_INIT_VAR(name); + phalcon_call_method_key(name, index, "getname", 4286441094UL); - if (parser_status->status != PHANNOT_PARSING_OK) { - status = FAILURE; - if (parser_status->syntax_error) { - if (!*error_msg) { - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, parser_status->syntax_error, 1); - } - efree(parser_status->syntax_error); - } + PHALCON_INIT_VAR(sql); + if (zend_is_true(schema_name)) { + PHALCON_CONCAT_SVSVSVS(sql, "CREATE INDEX \"", schema_name, "\".\"", name, "\" ON \"", table_name, "\" ("); + } + else { + PHALCON_CONCAT_SVSVS(sql, "CREATE INDEX \"", name, "\" ON \"", table_name, "\" ("); } - phannot_Free(phannot_parser, phannot_wrapper_free); + PHALCON_INIT_VAR(columns); + phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); - if (status != FAILURE) { - if (parser_status->status == PHANNOT_PARSING_OK) { - if (parser_status->ret) { - ZVAL_ZVAL(*result, parser_status->ret, 0, 0); - ZVAL_NULL(parser_status->ret); - zval_ptr_dtor(&parser_status->ret); - } else { - array_init(*result); - } - } + PHALCON_INIT_VAR(quoted_column_list); + phalcon_call_method_p1_key(quoted_column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); + + PHALCON_SCONCAT_VS(sql, quoted_column_list, ")"); + RETURN_CTOR(sql); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropIndex){ + + zval *table_name, *schema_name, *index_name; + zval *sql = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index_name); + + PHALCON_INIT_VAR(sql); + if (zend_is_true(schema_name)) { + PHALCON_CONCAT_SVSVS(sql, "DROP INDEX \"", schema_name, "\".\"", index_name, "\""); + } + else { + PHALCON_CONCAT_SVS(sql, "DROP INDEX \"", index_name, "\""); } - efree(Z_STRVAL(processed_comment)); + RETURN_CTOR(sql); +} - efree(parser_status); - efree(state); +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addPrimaryKey){ - return status; + zval *table_name, *schema_name, *index; + + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Adding a primary key after table has been created is not supported by SQLite"); + return; } +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropPrimaryKey){ + zval *table_name, *schema_name; + phalcon_fetch_params(0, 2, 0, &table_name, &schema_name); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Removing a primary key after table has been created is not supported by SQLite"); + return; +} -#ifdef HAVE_CONFIG_H -#endif +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addForeignKey){ + zval *table_name, *schema_name, *reference; + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Adding a foreign key constraint to an existing table is not supported by SQLite"); + return; +} -PHALCON_INIT_CLASS(Phalcon_Annotations_AdapterInterface){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropForeignKey){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Annotations, AdapterInterface, annotations_adapterinterface, phalcon_annotations_adapterinterface_method_entry); + zval *table_name, *schema_name, *reference_name; - return SUCCESS; + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference_name); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Dropping a foreign key constraint is not supported by SQLite"); + return; } +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, _getTableOptions){ + zval *definition; + phalcon_fetch_params(0, 1, 0, &definition); + array_init(return_value); +} +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, createTable){ + zval *table_name, *schema_name, *definition; + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &definition); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; +} +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropTable){ + zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; + zval *sql = NULL; -/* Generated by re2c 0.13.5 on Fri Jun 28 19:00:52 2013 */ -// 1 "scanner.re" + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); + + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); + } + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(table); + PHALCON_CONCAT_VSV(table, schema_name, "\".\"", table_name); + } else { + PHALCON_CPY_WRT(table, table_name); + } -#ifdef HAVE_CONFIG_H -#endif + PHALCON_INIT_VAR(sql); + if (zend_is_true(if_exists)) { + PHALCON_CONCAT_SVS(sql, "DROP TABLE IF EXISTS \"", table, "\""); + } else { + PHALCON_CONCAT_SVS(sql, "DROP TABLE \"", table, "\""); + } + + RETURN_CTOR(sql); +} +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, createView){ + zval *view_name, *definition, *schema_name, *view_sql; + zval *view = NULL, *sql; -#define JJCTYPE unsigned char -#define JJCURSOR (s->start) -#define JJLIMIT (s->end) -#define JJMARKER q + PHALCON_MM_GROW(); -static int phannot_get_token(phannot_scanner_state *s, phannot_scanner_token *token) { + phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); + + if (!phalcon_array_isset_quick_string(definition, SS("sql"), 2090732981UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'sql' is required in the definition array"); + return; + } + + PHALCON_OBS_VAR(view_sql); + phalcon_array_fetch_quick_string(&view_sql, definition, SS("sql"), 2090732981UL, PH_NOISY); + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(view); + PHALCON_CONCAT_VSV(view, schema_name, "\".\"", view_name); + } else { + PHALCON_CPY_WRT(view, view_name); + } + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "CREATE VIEW \"", view, "\" AS ", view_sql); + + RETURN_CTOR(sql); +} - char next, *q = JJCURSOR, *start = JJCURSOR; - int status = PHANNOT_SCANNER_RETCODE_IMPOSSIBLE; +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropView){ - while (PHANNOT_SCANNER_RETCODE_IMPOSSIBLE == status) { + zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; + zval *sql = NULL; - if (s->mode == PHANNOT_MODE_RAW) { + PHALCON_MM_GROW(); - if (*JJCURSOR == '\n') { - s->active_line++; - } + phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); + + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); + } + + if (zend_is_true(schema_name)) { + PHALCON_INIT_VAR(view); + PHALCON_CONCAT_VSV(view, schema_name, "\".\"", view_name); + } else { + PHALCON_CPY_WRT(view, view_name); + } + if (zend_is_true(if_exists)) { + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "DROP VIEW IF EXISTS \"", view, "\""); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "DROP VIEW \"", view, "\""); + } + + RETURN_CTOR(sql); +} - next = *(JJCURSOR+1); +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, tableExists){ - if (*JJCURSOR == '\0' || *JJCURSOR == '@') { - if ((next >= 'A' && next <= 'Z') || (next >= 'a' && next <= 'z')) { - s->mode = PHANNOT_MODE_ANNOTATION; - continue; - } - } + zval *table_name, *schema_name = NULL, *sql; - ++JJCURSOR; - token->opcode = PHANNOT_T_IGNORE; - return 0; + PHALCON_MM_GROW(); - } else { + phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM sqlite_master WHERE type='table' AND tbl_name='", table_name, "'"); + RETURN_CTOR(sql); +} - -// 66 "scanner.c" - { - JJCTYPE jjch; - unsigned int jjaccept = 0; +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, viewExists){ - jjch = *JJCURSOR; - switch (jjch) { - case 0x00: goto jj38; - case '\t': - case '\r': - case ' ': goto jj34; - case '\n': goto jj36; - case '"': goto jj10; - case '\'': goto jj11; - case '(': goto jj14; - case ')': goto jj16; - case ',': goto jj32; - case '-': goto jj2; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto jj4; - case ':': goto jj30; - case '=': goto jj28; - case '@': goto jj26; - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto jj13; - case 'F': - case 'f': goto jj8; - case 'N': - case 'n': goto jj6; - case 'T': - case 't': goto jj9; - case '[': goto jj22; - case '\\': goto jj12; - case ']': goto jj24; - case '{': goto jj18; - case '}': goto jj20; - default: goto jj40; - } -jj2: - ++JJCURSOR; - switch ((jjch = *JJCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto jj68; - default: goto jj3; - } -jj3: -// 183 "scanner.re" - { - status = PHANNOT_SCANNER_RETCODE_ERR; - break; + zval *view_name, *schema_name = NULL, *sql; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "SELECT CASE WHEN COUNT(*) > 0 THEN 1 ELSE 0 END FROM sqlite_master WHERE type='view' AND tbl_name='", view_name, "'"); + RETURN_CTOR(sql); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeColumns){ + + zval *table, *schema = NULL, *sql; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "PRAGMA table_info('", table, "')"); + RETURN_CTOR(sql); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, listTables){ + + zval *schema_name = NULL, *sql; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + PHALCON_INIT_VAR(sql); + ZVAL_STRING(sql, "SELECT tbl_name FROM sqlite_master WHERE type = 'table' ORDER BY tbl_name", 1); + RETURN_CTOR(sql); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, listViews){ + + zval *schema_name = NULL, *sql; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } + + PHALCON_INIT_VAR(sql); + ZVAL_STRING(sql, "SELECT tbl_name FROM sqlite_master WHERE type = 'view' ORDER BY tbl_name", 1); + RETURN_CTOR(sql); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeIndexes){ + + zval *table, *schema = NULL, *sql; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "PRAGMA index_list('", table, "')"); + RETURN_CTOR(sql); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeIndex){ + + zval *index_name, *sql; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &index_name); + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "PRAGMA index_info('", index_name, "')"); + RETURN_CTOR(sql); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeReferences){ + + zval *table, *schema = NULL, *sql; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "PRAGMA foreign_key_list('", table, "')"); + RETURN_CTOR(sql); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, tableOptions){ + + zval *table, *schema = NULL; + + phalcon_fetch_params(0, 1, 1, &table, &schema); + + RETURN_EMPTY_STRING(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Db_Dialect){ + + PHALCON_REGISTER_CLASS(Phalcon\\Db, Dialect, db_dialect, phalcon_db_dialect_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_property_null(phalcon_db_dialect_ce, SL("_escapeChar"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Db_Dialect, limit){ + + zval *sql_query, *number, *limit; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &sql_query, &number); + + if (phalcon_is_numeric(number)) { + PHALCON_INIT_VAR(limit); + ZVAL_LONG(limit, phalcon_get_intval(number)); + PHALCON_CONCAT_VSV(return_value, sql_query, " LIMIT ", limit); + RETURN_MM(); + } + + RETURN_CCTOR(sql_query); +} + +static PHP_METHOD(Phalcon_Db_Dialect, forUpdate){ + + zval *sql_query; + + phalcon_fetch_params(0, 1, 0, &sql_query); + + PHALCON_CONCAT_VS(return_value, sql_query, " FOR UPDATE"); + return; +} + +static PHP_METHOD(Phalcon_Db_Dialect, sharedLock){ + + zval *sql_query; + + phalcon_fetch_params(0, 1, 0, &sql_query); + + PHALCON_CONCAT_VS(return_value, sql_query, " LOCK IN SHARE MODE"); + return; +} + +static PHP_METHOD(Phalcon_Db_Dialect, getColumnList){ + + zval *column_list, *str_list, *escape_char, *column = NULL; + zval *column_quoted = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &column_list); + + PHALCON_INIT_VAR(str_list); + array_init(str_list); + + PHALCON_OBS_VAR(escape_char); + phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); + + phalcon_is_iterable(column_list, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(column); + + PHALCON_INIT_NVAR(column_quoted); + PHALCON_CONCAT_VVV(column_quoted, escape_char, column, escape_char); + phalcon_array_append(&str_list, column_quoted, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_fast_join_str(return_value, SL(", "), str_list TSRMLS_CC); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Db_Dialect, getSqlExpression){ + + zval *expression, *escape_char = NULL, *type, *name = NULL, *escaped_name = NULL; + zval *domain, *escaped_domain = NULL, *value = NULL, *operator = NULL; + zval *left = NULL, *expression_left = NULL, *right = NULL, *expression_right = NULL; + zval *expression_group, *sql_arguments, *arguments; + zval *argument = NULL, *argument_expression = NULL, *arguments_joined; + zval *sql_items, *items, *item = NULL, *item_expression = NULL; + zval *list_expression, *exception_message; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &expression, &escape_char); + + if (!escape_char) { + PHALCON_INIT_VAR(escape_char); + } else { + PHALCON_SEPARATE_PARAM(escape_char); + } + + if (PHALCON_GLOBAL(db).escape_identifiers) { + if (Z_TYPE_P(escape_char) == IS_NULL) { + PHALCON_OBS_NVAR(escape_char); + phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); } -// 178 "scanner.c" -jj4: - jjaccept = 0; - jjch = *(JJMARKER = ++JJCURSOR); - goto jj69; -jj5: -// 67 "scanner.re" - { - token->opcode = PHANNOT_T_INTEGER; - token->value = estrndup(start, JJCURSOR - start); - token->len = JJCURSOR - start; - q = JJCURSOR; - return 0; + } + if (Z_TYPE_P(expression) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid SQL expression"); + return; + } + + if (!phalcon_array_isset_quick_string(expression, SS("type"), 276192743UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid SQL expression"); + return; + } + + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, expression, SS("type"), 276192743UL, PH_NOISY); + + if (PHALCON_IS_STRING(type, "qualified")) { + + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, expression, SS("name"), 268211462UL, PH_NOISY); + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(escaped_name); + PHALCON_CONCAT_VVV(escaped_name, escape_char, name, escape_char); + } else { + PHALCON_CPY_WRT(escaped_name, name); } -// 192 "scanner.c" -jj6: - ++JJCURSOR; - switch ((jjch = *JJCURSOR)) { - case 'U': - case 'u': goto jj63; - default: goto jj44; + + if (phalcon_array_isset_quick_string(expression, SS("domain"), 542597917UL)) { + + PHALCON_OBS_VAR(domain); + phalcon_array_fetch_quick_string(&domain, expression, SS("domain"), 542597917UL, PH_NOISY); + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(escaped_domain); + PHALCON_CONCAT_VVVSV(escaped_domain, escape_char, domain, escape_char, ".", escaped_name); + } else { + PHALCON_INIT_NVAR(escaped_domain); + PHALCON_CONCAT_VSV(escaped_domain, domain, ".", escaped_name); } -jj7: -// 109 "scanner.re" - { - token->opcode = PHANNOT_T_IDENTIFIER; - token->value = estrndup(start, JJCURSOR - start); - token->len = JJCURSOR - start; - q = JJCURSOR; - return 0; + + RETURN_CTOR(escaped_domain); } -// 209 "scanner.c" -jj8: - jjch = *++JJCURSOR; - switch (jjch) { - case 'A': - case 'a': goto jj58; - default: goto jj44; - } -jj9: - jjch = *++JJCURSOR; - switch (jjch) { - case 'R': - case 'r': goto jj54; - default: goto jj44; - } -jj10: - jjaccept = 1; - jjch = *(JJMARKER = ++JJCURSOR); - if (jjch <= 0x00) goto jj3; - goto jj52; -jj11: - jjaccept = 1; - jjch = *(JJMARKER = ++JJCURSOR); - if (jjch <= 0x00) goto jj3; - goto jj46; -jj12: - jjch = *++JJCURSOR; - goto jj44; -jj13: - jjch = *++JJCURSOR; - goto jj44; -jj14: - ++JJCURSOR; -// 117 "scanner.re" - { - token->opcode = PHANNOT_T_PARENTHESES_OPEN; - return 0; + + RETURN_CCTOR(escaped_name); + } + + if (PHALCON_IS_STRING(type, "literal")) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch_quick_string(&value, expression, SS("value"), 574111618UL, PH_NOISY); + RETURN_CCTOR(value); + } + + if (PHALCON_IS_STRING(type, "binary-op")) { + PHALCON_OBS_VAR(operator); + phalcon_array_fetch_quick_string(&operator, expression, SS("op"), 193501572UL, PH_NOISY); + + PHALCON_OBS_VAR(left); + phalcon_array_fetch_quick_string(&left, expression, SS("left"), 265976240UL, PH_NOISY); + + PHALCON_INIT_VAR(expression_left); + phalcon_call_method_p2_key(expression_left, this_ptr, "getsqlexpression", left, escape_char, 3377787077UL); + + PHALCON_OBS_VAR(right); + phalcon_array_fetch_quick_string(&right, expression, SS("right"), 426864067UL, PH_NOISY); + + PHALCON_INIT_VAR(expression_right); + phalcon_call_method_p2_key(expression_right, this_ptr, "getsqlexpression", right, escape_char, 3377787077UL); + PHALCON_CONCAT_VSVSV(return_value, expression_left, " ", operator, " ", expression_right); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(type, "unary-op")) { + + PHALCON_OBS_NVAR(operator); + phalcon_array_fetch_quick_string(&operator, expression, SS("op"), 193501572UL, PH_NOISY); + + if (phalcon_array_isset_quick_string(expression, SS("left"), 265976240UL)) { + PHALCON_OBS_NVAR(left); + phalcon_array_fetch_quick_string(&left, expression, SS("left"), 265976240UL, PH_NOISY); + + PHALCON_INIT_NVAR(expression_left); + phalcon_call_method_p2_key(expression_left, this_ptr, "getsqlexpression", left, escape_char, 3377787077UL); + PHALCON_CONCAT_VV(return_value, expression_left, operator); + RETURN_MM(); } -// 247 "scanner.c" -jj16: - ++JJCURSOR; -// 122 "scanner.re" - { - token->opcode = PHANNOT_T_PARENTHESES_CLOSE; - return 0; + + if (phalcon_array_isset_quick_string(expression, SS("right"), 426864067UL)) { + PHALCON_OBS_NVAR(right); + phalcon_array_fetch_quick_string(&right, expression, SS("right"), 426864067UL, PH_NOISY); + + PHALCON_INIT_NVAR(expression_right); + phalcon_call_method_p2_key(expression_right, this_ptr, "getsqlexpression", right, escape_char, 3377787077UL); + PHALCON_CONCAT_VV(return_value, operator, expression_right); + RETURN_MM(); } -// 255 "scanner.c" -jj18: - ++JJCURSOR; -// 127 "scanner.re" - { - token->opcode = PHANNOT_T_BRACKET_OPEN; - return 0; + } + + if (PHALCON_IS_STRING(type, "placeholder")) { + PHALCON_OBS_NVAR(value); + phalcon_array_fetch_quick_string(&value, expression, SS("value"), 574111618UL, PH_NOISY); + RETURN_CCTOR(value); + } + + if (PHALCON_IS_STRING(type, "parentheses")) { + PHALCON_OBS_NVAR(left); + phalcon_array_fetch_quick_string(&left, expression, SS("left"), 265976240UL, PH_NOISY); + + PHALCON_INIT_NVAR(expression_left); + phalcon_call_method_p2_key(expression_left, this_ptr, "getsqlexpression", left, escape_char, 3377787077UL); + + PHALCON_INIT_VAR(expression_group); + PHALCON_CONCAT_SVS(expression_group, "(", expression_left, ")"); + RETURN_CTOR(expression_group); + } + + if (PHALCON_IS_STRING(type, "functionCall")) { + + PHALCON_OBS_NVAR(name); + phalcon_array_fetch_quick_string(&name, expression, SS("name"), 268211462UL, PH_NOISY); + + PHALCON_INIT_VAR(sql_arguments); + array_init(sql_arguments); + if (phalcon_array_isset_quick_string(expression, SS("arguments"), 3751272283UL)) { + + PHALCON_OBS_VAR(arguments); + phalcon_array_fetch_quick_string(&arguments, expression, SS("arguments"), 3751272283UL, PH_NOISY); + + phalcon_is_iterable(arguments, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(argument); + + PHALCON_INIT_NVAR(argument_expression); + phalcon_call_method_p2_key(argument_expression, this_ptr, "getsqlexpression", argument, escape_char, 3377787077UL); + phalcon_array_append(&sql_arguments, argument_expression, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(arguments_joined); + phalcon_fast_join_str(arguments_joined, SL(", "), sql_arguments TSRMLS_CC); + PHALCON_CONCAT_VSVS(return_value, name, "(", arguments_joined, ")"); + + RETURN_MM(); + } else { + PHALCON_CONCAT_VS(return_value, name, "()"); + RETURN_MM(); } -// 263 "scanner.c" -jj20: - ++JJCURSOR; -// 132 "scanner.re" - { - token->opcode = PHANNOT_T_BRACKET_CLOSE; - return 0; + } + + if (PHALCON_IS_STRING(type, "list")) { + + PHALCON_INIT_VAR(sql_items); + array_init(sql_items); + + PHALCON_OBS_VAR(items); + phalcon_array_fetch_long(&items, expression, 0, PH_NOISY); + + phalcon_is_iterable(items, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(item); + + PHALCON_INIT_NVAR(item_expression); + phalcon_call_method_p2_key(item_expression, this_ptr, "getsqlexpression", item, escape_char, 3377787077UL); + phalcon_array_append(&sql_items, item_expression, PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); } -// 271 "scanner.c" -jj22: - ++JJCURSOR; -// 137 "scanner.re" - { - token->opcode = PHANNOT_T_SBRACKET_OPEN; - return 0; + + PHALCON_INIT_VAR(list_expression); + phalcon_fast_join_str(list_expression, SL(", "), sql_items TSRMLS_CC); + PHALCON_CONCAT_SVS(return_value, "(", list_expression, ")"); + + RETURN_MM(); + } + + if (PHALCON_IS_STRING(type, "all")) { + RETURN_MM_STRING("*", 1); + } + + if (PHALCON_IS_STRING(type, "cast")) { + PHALCON_OBS_NVAR(left); + phalcon_array_fetch_quick_string(&left, expression, SS("left"), 265976240UL, PH_NOISY); + + PHALCON_INIT_NVAR(expression_left); + phalcon_call_method_p2_key(expression_left, this_ptr, "getsqlexpression", left, escape_char, 3377787077UL); + + PHALCON_OBS_NVAR(right); + phalcon_array_fetch_quick_string(&right, expression, SS("right"), 426864067UL, PH_NOISY); + + PHALCON_INIT_NVAR(expression_right); + phalcon_call_method_p2_key(expression_right, this_ptr, "getsqlexpression", right, escape_char, 3377787077UL); + PHALCON_CONCAT_SVSVS(return_value, "CAST(", expression_left, " AS ", expression_right, ")"); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(type, "convert")) { + PHALCON_OBS_NVAR(left); + phalcon_array_fetch_quick_string(&left, expression, SS("left"), 265976240UL, PH_NOISY); + + PHALCON_INIT_NVAR(expression_left); + phalcon_call_method_p2_key(expression_left, this_ptr, "getsqlexpression", left, escape_char, 3377787077UL); + + PHALCON_OBS_NVAR(right); + phalcon_array_fetch_quick_string(&right, expression, SS("right"), 426864067UL, PH_NOISY); + + PHALCON_INIT_NVAR(expression_right); + phalcon_call_method_p2_key(expression_right, this_ptr, "getsqlexpression", right, escape_char, 3377787077UL); + PHALCON_CONCAT_SVSVS(return_value, "CONVERT(", expression_left, " USING ", expression_right, ")"); + RETURN_MM(); + } + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Invalid SQL expression type '", type, "'"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_db_exception_ce, exception_message); + return; +} + +static PHP_METHOD(Phalcon_Db_Dialect, getSqlTable){ + + zval *table, *escape_char = NULL, *table_name, *sql_table = NULL; + zval *schema_name, *sql_schema = NULL, *alias_name; + zval *sql_table_alias = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &table, &escape_char); + + if (!escape_char) { + PHALCON_INIT_VAR(escape_char); + } else { + PHALCON_SEPARATE_PARAM(escape_char); + } + + if (Z_TYPE_P(escape_char) == IS_NULL) { + PHALCON_OBS_NVAR(escape_char); + phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); + } + if (Z_TYPE_P(table) == IS_ARRAY) { + + PHALCON_OBS_VAR(table_name); + phalcon_array_fetch_long(&table_name, table, 0, PH_NOISY); + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(sql_table); + PHALCON_CONCAT_VVV(sql_table, escape_char, table_name, escape_char); + } else { + PHALCON_CPY_WRT(sql_table, table_name); } -// 279 "scanner.c" -jj24: - ++JJCURSOR; -// 142 "scanner.re" - { - token->opcode = PHANNOT_T_SBRACKET_CLOSE; - return 0; + + PHALCON_OBS_VAR(schema_name); + phalcon_array_fetch_long(&schema_name, table, 1, PH_NOISY); + if (Z_TYPE_P(schema_name) != IS_NULL) { + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(sql_schema); + PHALCON_CONCAT_VVVSV(sql_schema, escape_char, schema_name, escape_char, ".", sql_table); + } else { + PHALCON_INIT_NVAR(sql_schema); + PHALCON_CONCAT_VSV(sql_schema, schema_name, ".", sql_table); + } + } else { + PHALCON_CPY_WRT(sql_schema, sql_table); } -// 287 "scanner.c" -jj26: - ++JJCURSOR; -// 147 "scanner.re" - { - token->opcode = PHANNOT_T_AT; - return 0; + + if (phalcon_array_isset_long(table, 2)) { + + PHALCON_OBS_VAR(alias_name); + phalcon_array_fetch_long(&alias_name, table, 2, PH_NOISY); + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_VAR(sql_table_alias); + PHALCON_CONCAT_VSVVV(sql_table_alias, sql_schema, " AS ", escape_char, alias_name, escape_char); + } else { + PHALCON_INIT_NVAR(sql_table_alias); + PHALCON_CONCAT_VSV(sql_table_alias, sql_schema, " AS ", alias_name); + } + } else { + PHALCON_CPY_WRT(sql_table_alias, sql_schema); } -// 295 "scanner.c" -jj28: - ++JJCURSOR; -// 152 "scanner.re" - { - token->opcode = PHANNOT_T_EQUALS; - return 0; + + RETURN_CCTOR(sql_table_alias); + } + + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_CONCAT_VVV(return_value, escape_char, table, escape_char); + RETURN_MM(); + } + + RETURN_CCTOR(table); +} + +static PHP_METHOD(Phalcon_Db_Dialect, select){ + + zval *definition, *escape_char = NULL, *columns, *selected_columns; + zval *column = NULL, *column_item = NULL, *column_sql = NULL, *column_domain = NULL; + zval *column_domain_sql = NULL, *column_alias = NULL, *column_alias_sql = NULL; + zval *columns_sql = NULL, *tables, *selected_tables; + zval *table = NULL, *sql_table = NULL, *tables_sql = NULL, *sql, *joins; + zval *join = NULL, *type = NULL, *sql_join = NULL, *join_conditions_array = NULL; + zval *join_expressions = NULL, *join_condition = NULL, *join_expression = NULL; + zval *join_conditions = NULL, *where_conditions; + zval *where_expression, *group_items, *group_fields; + zval *group_field = NULL, *group_expression = NULL, *group_sql; + zval *group_clause, *having_conditions, *having_expression; + zval *order_fields, *order_items, *order_item = NULL; + zval *order_expression = NULL, *order_sql_item = NULL, *sql_order_type = NULL; + zval *order_sql_item_type = NULL, *order_sql, *limit_value; + zval *number, *offset; + HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5; + HashPosition hp0, hp1, hp2, hp3, hp4, hp5; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &definition); + + if (Z_TYPE_P(definition) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid SELECT definition"); + return; + } + if (!phalcon_array_isset_quick_string(definition, SS("tables"), 3465666720UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'tables' is required in the definition array"); + return; + } + + if (!phalcon_array_isset_quick_string(definition, SS("columns"), 1041822630UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'columns' is required in the definition array"); + return; + } + + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_OBS_VAR(escape_char); + phalcon_read_property_this_quick(&escape_char, this_ptr, SL("_escapeChar"), 543241491UL, PH_NOISY_CC); + } else { + PHALCON_INIT_NVAR(escape_char); + } + + PHALCON_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); + if (Z_TYPE_P(columns) == IS_ARRAY) { + + PHALCON_INIT_VAR(selected_columns); + array_init(selected_columns); + + phalcon_is_iterable(columns, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(column); + + PHALCON_OBS_NVAR(column_item); + phalcon_array_fetch_long(&column_item, column, 0, PH_NOISY); + if (Z_TYPE_P(column_item) == IS_ARRAY) { + PHALCON_INIT_NVAR(column_sql); + phalcon_call_method_p2_key(column_sql, this_ptr, "getsqlexpression", column_item, escape_char, 3377787077UL); + } else { + if (PHALCON_IS_STRING(column_item, "*")) { + PHALCON_CPY_WRT(column_sql, column_item); + } else { + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_NVAR(column_sql); + PHALCON_CONCAT_VVV(column_sql, escape_char, column_item, escape_char); + } else { + PHALCON_CPY_WRT(column_sql, column_item); + } + } + } + + if (phalcon_array_isset_long(column, 1)) { + + PHALCON_OBS_NVAR(column_domain); + phalcon_array_fetch_long(&column_domain, column, 1, PH_NOISY); + if (zend_is_true(column_domain)) { + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_NVAR(column_domain_sql); + PHALCON_CONCAT_VVVSV(column_domain_sql, escape_char, column_domain, escape_char, ".", column_sql); + } else { + PHALCON_INIT_NVAR(column_domain_sql); + PHALCON_CONCAT_VSV(column_domain_sql, column_domain, ".", column_sql); + } + } else { + PHALCON_CPY_WRT(column_domain_sql, column_sql); + } + } else { + PHALCON_CPY_WRT(column_domain_sql, column_sql); + } + + if (phalcon_array_isset_long(column, 2)) { + + PHALCON_OBS_NVAR(column_alias); + phalcon_array_fetch_long(&column_alias, column, 2, PH_NOISY); + if (zend_is_true(column_alias)) { + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_INIT_NVAR(column_alias_sql); + PHALCON_CONCAT_VSVVV(column_alias_sql, column_domain_sql, " AS ", escape_char, column_alias, escape_char); + } else { + PHALCON_INIT_NVAR(column_alias_sql); + PHALCON_CONCAT_VSV(column_alias_sql, column_domain_sql, " AS ", column_alias); + } + } else { + PHALCON_CPY_WRT(column_alias_sql, column_domain_sql); + } + } else { + PHALCON_CPY_WRT(column_alias_sql, column_domain_sql); + } + + phalcon_array_append(&selected_columns, column_alias_sql, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } -// 303 "scanner.c" -jj30: - ++JJCURSOR; -// 157 "scanner.re" - { - token->opcode = PHANNOT_T_COLON; - return 0; + + PHALCON_INIT_VAR(columns_sql); + phalcon_fast_join_str(columns_sql, SL(", "), selected_columns TSRMLS_CC); + } else { + PHALCON_CPY_WRT(columns_sql, columns); + } + + PHALCON_OBS_VAR(tables); + phalcon_array_fetch_quick_string(&tables, definition, SS("tables"), 3465666720UL, PH_NOISY); + if (Z_TYPE_P(tables) == IS_ARRAY) { + + PHALCON_INIT_VAR(selected_tables); + array_init(selected_tables); + + phalcon_is_iterable(tables, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(table); + + PHALCON_INIT_NVAR(sql_table); + phalcon_call_method_p2_key(sql_table, this_ptr, "getsqltable", table, escape_char, 2837135293UL); + phalcon_array_append(&selected_tables, sql_table, PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); } -// 311 "scanner.c" -jj32: - ++JJCURSOR; -// 162 "scanner.re" - { - token->opcode = PHANNOT_T_COMMA; - return 0; + + PHALCON_INIT_VAR(tables_sql); + phalcon_fast_join_str(tables_sql, SL(", "), selected_tables TSRMLS_CC); + } else { + PHALCON_CPY_WRT(tables_sql, tables); + } + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "SELECT ", columns_sql, " FROM ", tables_sql); + + if (phalcon_array_isset_quick_string(definition, SS("joins"), 120974824UL)) { + + PHALCON_OBS_VAR(joins); + phalcon_array_fetch_quick_string(&joins, definition, SS("joins"), 120974824UL, PH_NOISY); + + phalcon_is_iterable(joins, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HVALUE(join); + + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, join, SS("type"), 276192743UL, PH_NOISY); + + PHALCON_OBS_NVAR(table); + phalcon_array_fetch_quick_string(&table, join, SS("source"), 2744839734UL, PH_NOISY); + + PHALCON_INIT_NVAR(sql_table); + phalcon_call_method_p2_key(sql_table, this_ptr, "getsqltable", table, escape_char, 2837135293UL); + phalcon_array_append(&selected_tables, sql_table, PH_SEPARATE); + + PHALCON_INIT_NVAR(sql_join); + PHALCON_CONCAT_SVSV(sql_join, " ", type, " JOIN ", sql_table); + + if (phalcon_array_isset_quick_string(join, SS("conditions"), 1055696255UL)) { + + PHALCON_OBS_NVAR(join_conditions_array); + phalcon_array_fetch_quick_string(&join_conditions_array, join, SS("conditions"), 1055696255UL, PH_NOISY); + if (phalcon_fast_count_ev(join_conditions_array TSRMLS_CC)) { + + PHALCON_INIT_NVAR(join_expressions); + array_init(join_expressions); + + phalcon_is_iterable(join_conditions_array, &ah3, &hp3, 0, 0); + + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { + + PHALCON_GET_HVALUE(join_condition); + + PHALCON_INIT_NVAR(join_expression); + phalcon_call_method_p2_key(join_expression, this_ptr, "getsqlexpression", join_condition, escape_char, 3377787077UL); + phalcon_array_append(&join_expressions, join_expression, PH_SEPARATE); + + zend_hash_move_forward_ex(ah3, &hp3); + } + + PHALCON_INIT_NVAR(join_conditions); + phalcon_fast_join_str(join_conditions, SL(" AND "), join_expressions TSRMLS_CC); + PHALCON_SCONCAT_SVS(sql_join, " ON ", join_conditions, " "); + } + } + + phalcon_concat_self(&sql, sql_join TSRMLS_CC); + + zend_hash_move_forward_ex(ah2, &hp2); } -// 319 "scanner.c" -jj34: - ++JJCURSOR; - jjch = *JJCURSOR; - goto jj42; -jj35: -// 167 "scanner.re" - { - token->opcode = PHANNOT_T_IGNORE; - return 0; + + } + + if (phalcon_array_isset_quick_string(definition, SS("where"), 621293632UL)) { + + PHALCON_OBS_VAR(where_conditions); + phalcon_array_fetch_quick_string(&where_conditions, definition, SS("where"), 621293632UL, PH_NOISY); + if (Z_TYPE_P(where_conditions) == IS_ARRAY) { + PHALCON_INIT_VAR(where_expression); + phalcon_call_method_p2_key(where_expression, this_ptr, "getsqlexpression", where_conditions, escape_char, 3377787077UL); + PHALCON_SCONCAT_SV(sql, " WHERE ", where_expression); + } else { + PHALCON_SCONCAT_SV(sql, " WHERE ", where_conditions); } -// 330 "scanner.c" -jj36: - ++JJCURSOR; -// 172 "scanner.re" - { - s->active_line++; - token->opcode = PHANNOT_T_IGNORE; - return 0; + } + + if (phalcon_array_isset_quick_string(definition, SS("group"), 7349554UL)) { + + PHALCON_INIT_VAR(group_items); + array_init(group_items); + + PHALCON_OBS_VAR(group_fields); + phalcon_array_fetch_quick_string(&group_fields, definition, SS("group"), 7349554UL, PH_NOISY); + + phalcon_is_iterable(group_fields, &ah4, &hp4, 0, 0); + + while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { + + PHALCON_GET_HVALUE(group_field); + + PHALCON_INIT_NVAR(group_expression); + phalcon_call_method_p2_key(group_expression, this_ptr, "getsqlexpression", group_field, escape_char, 3377787077UL); + phalcon_array_append(&group_items, group_expression, PH_SEPARATE); + + zend_hash_move_forward_ex(ah4, &hp4); } -// 339 "scanner.c" -jj38: - ++JJCURSOR; -// 178 "scanner.re" - { - status = PHANNOT_SCANNER_RETCODE_EOF; - break; + + PHALCON_INIT_VAR(group_sql); + phalcon_fast_join_str(group_sql, SL(", "), group_items TSRMLS_CC); + + PHALCON_INIT_VAR(group_clause); + PHALCON_CONCAT_SV(group_clause, " GROUP BY ", group_sql); + phalcon_concat_self(&sql, group_clause TSRMLS_CC); + + if (phalcon_array_isset_quick_string(definition, SS("having"), 876572994UL)) { + PHALCON_OBS_VAR(having_conditions); + phalcon_array_fetch_quick_string(&having_conditions, definition, SS("having"), 876572994UL, PH_NOISY); + + PHALCON_INIT_VAR(having_expression); + phalcon_call_method_p2_key(having_expression, this_ptr, "getsqlexpression", having_conditions, escape_char, 3377787077UL); + PHALCON_SCONCAT_SV(sql, " HAVING ", having_expression); } -// 347 "scanner.c" -jj40: - jjch = *++JJCURSOR; - goto jj3; -jj41: - ++JJCURSOR; - jjch = *JJCURSOR; -jj42: - switch (jjch) { - case '\t': - case '\r': - case ' ': goto jj41; - default: goto jj35; - } -jj43: - ++JJCURSOR; - jjch = *JJCURSOR; -jj44: - switch (jjch) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto jj43; - default: goto jj7; - } -jj45: - ++JJCURSOR; - jjch = *JJCURSOR; -jj46: - switch (jjch) { - case 0x00: goto jj47; - case '\'': goto jj49; - case '\\': goto jj48; - default: goto jj45; - } -jj47: - JJCURSOR = JJMARKER; - switch (jjaccept) { - case 0: goto jj5; - case 1: goto jj3; - } -jj48: - ++JJCURSOR; - jjch = *JJCURSOR; - switch (jjch) { - case '\n': goto jj47; - default: goto jj45; - } -jj49: - ++JJCURSOR; -// 100 "scanner.re" - { - token->opcode = PHANNOT_T_STRING; - token->value = estrndup(q, JJCURSOR - q - 1); - token->len = JJCURSOR - q - 1; - q = JJCURSOR; - return 0; - } -// 465 "scanner.c" -jj51: - ++JJCURSOR; - jjch = *JJCURSOR; -jj52: - switch (jjch) { - case 0x00: goto jj47; - case '"': goto jj49; - case '\\': goto jj53; - default: goto jj51; - } -jj53: - ++JJCURSOR; - jjch = *JJCURSOR; - switch (jjch) { - case '\n': goto jj47; - default: goto jj51; - } -jj54: - jjch = *++JJCURSOR; - switch (jjch) { - case 'U': - case 'u': goto jj55; - default: goto jj44; - } -jj55: - jjch = *++JJCURSOR; - switch (jjch) { - case 'E': - case 'e': goto jj56; - default: goto jj44; - } -jj56: - ++JJCURSOR; - switch ((jjch = *JJCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto jj43; - default: goto jj57; - } -jj57: -// 94 "scanner.re" - { - token->opcode = PHANNOT_T_TRUE; - return 0; - } -// 572 "scanner.c" -jj58: - jjch = *++JJCURSOR; - switch (jjch) { - case 'L': - case 'l': goto jj59; - default: goto jj44; - } -jj59: - jjch = *++JJCURSOR; - switch (jjch) { - case 'S': - case 's': goto jj60; - default: goto jj44; - } -jj60: - jjch = *++JJCURSOR; - switch (jjch) { - case 'E': - case 'e': goto jj61; - default: goto jj44; - } -jj61: - ++JJCURSOR; - switch ((jjch = *JJCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto jj43; - default: goto jj62; - } -jj62: -// 89 "scanner.re" - { - token->opcode = PHANNOT_T_FALSE; - return 0; - } -// 669 "scanner.c" -jj63: - jjch = *++JJCURSOR; - switch (jjch) { - case 'L': - case 'l': goto jj64; - default: goto jj44; - } -jj64: - jjch = *++JJCURSOR; - switch (jjch) { - case 'L': - case 'l': goto jj65; - default: goto jj44; - } -jj65: - ++JJCURSOR; - switch ((jjch = *JJCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto jj43; - default: goto jj66; + } + + if (phalcon_array_isset_quick_string(definition, SS("order"), 320020033UL)) { + + PHALCON_OBS_VAR(order_fields); + phalcon_array_fetch_quick_string(&order_fields, definition, SS("order"), 320020033UL, PH_NOISY); + + PHALCON_INIT_VAR(order_items); + array_init(order_items); + + phalcon_is_iterable(order_fields, &ah5, &hp5, 0, 0); + + while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { + + PHALCON_GET_HVALUE(order_item); + + PHALCON_OBS_NVAR(order_expression); + phalcon_array_fetch_long(&order_expression, order_item, 0, PH_NOISY); + + PHALCON_INIT_NVAR(order_sql_item); + phalcon_call_method_p2_key(order_sql_item, this_ptr, "getsqlexpression", order_expression, escape_char, 3377787077UL); + + if (phalcon_array_isset_long(order_item, 1)) { + PHALCON_OBS_NVAR(sql_order_type); + phalcon_array_fetch_long(&sql_order_type, order_item, 1, PH_NOISY); + + PHALCON_INIT_NVAR(order_sql_item_type); + PHALCON_CONCAT_VSV(order_sql_item_type, order_sql_item, " ", sql_order_type); + } else { + PHALCON_CPY_WRT(order_sql_item_type, order_sql_item); } -jj66: -// 84 "scanner.re" - { - token->opcode = PHANNOT_T_NULL; - return 0; + + phalcon_array_append(&order_items, order_sql_item_type, PH_SEPARATE); + + zend_hash_move_forward_ex(ah5, &hp5); } -// 759 "scanner.c" -jj67: - jjch = *++JJCURSOR; - switch (jjch) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto jj70; - default: goto jj47; - } -jj68: - jjaccept = 0; - JJMARKER = ++JJCURSOR; - jjch = *JJCURSOR; -jj69: - switch (jjch) { - case '.': goto jj67; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto jj68; - default: goto jj5; - } -jj70: - ++JJCURSOR; - jjch = *JJCURSOR; - switch (jjch) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto jj70; - default: goto jj72; + + PHALCON_INIT_VAR(order_sql); + phalcon_fast_join_str(order_sql, SL(", "), order_items TSRMLS_CC); + PHALCON_SCONCAT_SV(sql, " ORDER BY ", order_sql); + } + + if (phalcon_array_isset_quick_string(definition, SS("limit"), 192268420UL)) { + + PHALCON_OBS_VAR(limit_value); + phalcon_array_fetch_quick_string(&limit_value, definition, SS("limit"), 192268420UL, PH_NOISY); + if (Z_TYPE_P(limit_value) == IS_ARRAY) { + + PHALCON_OBS_VAR(number); + phalcon_array_fetch_quick_string(&number, limit_value, SS("number"), 807219790UL, PH_NOISY); + + if (phalcon_array_isset_quick_string(limit_value, SS("offset"), 1503966412UL)) { + PHALCON_OBS_VAR(offset); + phalcon_array_fetch_quick_string(&offset, limit_value, SS("offset"), 1503966412UL, PH_NOISY); + PHALCON_SCONCAT_SVSV(sql, " LIMIT ", number, " OFFSET ", offset); + } else { + PHALCON_SCONCAT_SV(sql, " LIMIT ", number); } -jj72: -// 76 "scanner.re" - { - token->opcode = PHANNOT_T_DOUBLE; - token->value = estrndup(start, JJCURSOR - start); - token->len = JJCURSOR - start; - q = JJCURSOR; - return 0; - } -// 819 "scanner.c" - } -// 188 "scanner.re" - - + } else { + PHALCON_SCONCAT_SV(sql, " LIMIT ", limit_value); } } - - return status; + + RETURN_CTOR(sql); } +static PHP_METHOD(Phalcon_Db_Dialect, supportsSavepoints){ + RETURN_TRUE; +} -#ifdef HAVE_CONFIG_H -#endif +static PHP_METHOD(Phalcon_Db_Dialect, supportsReleaseSavepoints){ + PHALCON_MM_GROW(); + phalcon_call_method_key(return_value, this_ptr, "supportssavepoints", 1063347073UL); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Db_Dialect, createSavepoint){ + zval *name; + phalcon_fetch_params(0, 1, 0, &name); + + PHALCON_CONCAT_SV(return_value, "SAVEPOINT ", name); + return; +} -PHALCON_INIT_CLASS(Phalcon_Annotations_Annotation){ +static PHP_METHOD(Phalcon_Db_Dialect, releaseSavepoint){ - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Annotation, annotations_annotation, phalcon_annotations_annotation_method_entry, 0); - - zend_declare_property_null(phalcon_annotations_annotation_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_annotations_annotation_ce, SL("_arguments"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_annotations_annotation_ce, SL("_exprArguments"), ZEND_ACC_PROTECTED TSRMLS_CC); + zval *name; - return SUCCESS; + phalcon_fetch_params(0, 1, 0, &name); + + PHALCON_CONCAT_SV(return_value, "RELEASE SAVEPOINT ", name); + return; } -static PHP_METHOD(Phalcon_Annotations_Annotation, __construct){ - - zval *reflection_data, *name = NULL, *arguments, *expr_arguments; - zval *argument = NULL, *expr = NULL, *resolved_argument = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; +static PHP_METHOD(Phalcon_Db_Dialect, rollbackSavepoint){ - PHALCON_MM_GROW(); + zval *name; - phalcon_fetch_params(1, 1, 0, &reflection_data); - - if (Z_TYPE_P(reflection_data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Reflection data must be an array"); - return; - } - - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, reflection_data, SS("name"), 268211462UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); - - if (phalcon_array_isset_quick_string(reflection_data, SS("arguments"), 3751272283UL)) { - - PHALCON_INIT_VAR(arguments); - array_init(arguments); - - PHALCON_OBS_VAR(expr_arguments); - phalcon_array_fetch_quick_string(&expr_arguments, reflection_data, SS("arguments"), 3751272283UL, PH_NOISY); - - phalcon_is_iterable(expr_arguments, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(argument); - - PHALCON_OBS_NVAR(expr); - phalcon_array_fetch_quick_string(&expr, argument, SS("expr"), 258368420UL, PH_NOISY); - - PHALCON_INIT_NVAR(resolved_argument); - phalcon_call_method_p1_key(resolved_argument, this_ptr, "getexpression", expr, 2208543925UL); - if (phalcon_array_isset_quick_string(argument, SS("name"), 268211462UL)) { - PHALCON_OBS_NVAR(name); - phalcon_array_fetch_quick_string(&name, argument, SS("name"), 268211462UL, PH_NOISY); - phalcon_array_update_zval(&arguments, name, &resolved_argument, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_append(&arguments, resolved_argument, PH_SEPARATE); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - phalcon_update_property_this_quick(this_ptr, SL("_arguments"), arguments, 314247962UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_exprArguments"), expr_arguments, 3152251737UL TSRMLS_CC); - } + phalcon_fetch_params(0, 1, 0, &name); - PHALCON_MM_RESTORE(); + PHALCON_CONCAT_SV(return_value, "ROLLBACK TO SAVEPOINT ", name); + return; } -static PHP_METHOD(Phalcon_Annotations_Annotation, getName){ - RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); -} -static PHP_METHOD(Phalcon_Annotations_Annotation, getExpression){ - zval *expr = NULL, *type, *value = NULL, *array_value, *items, *item = NULL; - zval *resolved_item = NULL, *name = NULL, *exception_message; - HashTable *ah0; - HashPosition hp0; - zval **hd; +#ifdef HAVE_CONFIG_H +#endif - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &expr); - - PHALCON_SEPARATE_PARAM(expr); - - if (Z_TYPE_P(expr) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "The expression is not valid"); - return; - } - - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, expr, SS("type"), 276192743UL, PH_NOISY); - - switch (phalcon_get_intval(type)) { - - case 301: - PHALCON_OBS_VAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - RETURN_CCTOR(value); - - case 302: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - RETURN_CCTOR(value); - - case 303: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - RETURN_CCTOR(value); - - case 307: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - RETURN_CCTOR(value); - - case 304: - RETURN_MM_NULL(); - - case 305: - RETURN_MM_FALSE; - - case 306: - RETURN_MM_TRUE; - - case 308: - PHALCON_INIT_VAR(array_value); - array_init(array_value); - - PHALCON_OBS_VAR(items); - phalcon_array_fetch_quick_string(&items, expr, SS("items"), 87624199UL, PH_NOISY); - - phalcon_is_iterable(items, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(item); - - PHALCON_OBS_NVAR(expr); - phalcon_array_fetch_quick_string(&expr, item, SS("expr"), 258368420UL, PH_NOISY); - - PHALCON_INIT_NVAR(resolved_item); - phalcon_call_method_p1_key(resolved_item, this_ptr, "getexpression", expr, 2208543925UL); - if (phalcon_array_isset_quick_string(item, SS("name"), 268211462UL)) { - PHALCON_OBS_NVAR(name); - phalcon_array_fetch_quick_string(&name, item, SS("name"), 268211462UL, PH_NOISY); - phalcon_array_update_zval(&array_value, name, &resolved_item, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_append(&array_value, resolved_item, PH_SEPARATE); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CTOR(array_value); - - case 300: - object_init_ex(return_value, phalcon_annotations_annotation_ce); - phalcon_call_method_p1_key(NULL, return_value, "__construct", expr, 1107214344UL); - - RETURN_MM(); - - default: - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "The expression ", type, " is unknown"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_annotations_exception_ce, exception_message); - return; - - } - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Annotations_Annotation, getExprArguments){ +PHALCON_INIT_CLASS(Phalcon_Db_DialectInterface){ + PHALCON_REGISTER_INTERFACE(Phalcon\\Db, DialectInterface, db_dialectinterface, phalcon_db_dialectinterface_method_entry); - RETURN_MEMBER_QUICK(this_ptr, "_exprArguments", 3152251737UL); + return SUCCESS; } -static PHP_METHOD(Phalcon_Annotations_Annotation, getArguments){ - RETURN_MEMBER_QUICK(this_ptr, "_arguments", 314247962UL); -} -static PHP_METHOD(Phalcon_Annotations_Annotation, numberArguments){ - zval *arguments, *number; - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(arguments); - phalcon_read_property_this_quick(&arguments, this_ptr, SL("_arguments"), 314247962UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(number); - phalcon_fast_count(number, arguments TSRMLS_CC); - RETURN_NCTOR(number); -} -static PHP_METHOD(Phalcon_Annotations_Annotation, getArgument){ - zval *position, *arguments, *value; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &position); - - PHALCON_OBS_VAR(arguments); - phalcon_read_property_this_quick(&arguments, this_ptr, SL("_arguments"), 314247962UL, PH_NOISY_CC); - if (phalcon_array_isset(arguments, position)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, arguments, position, PH_NOISY); - RETURN_CCTOR(value); - } - - RETURN_MM_NULL(); -} -static PHP_METHOD(Phalcon_Annotations_Annotation, hasArgument){ - zval *position, *arguments; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &position); - - PHALCON_OBS_VAR(arguments); - phalcon_read_property_this_quick(&arguments, this_ptr, SL("_arguments"), 314247962UL, PH_NOISY_CC); - if (phalcon_array_isset(arguments, position)) { - RETURN_MM_TRUE; - } - - RETURN_MM_FALSE; -} -static PHP_METHOD(Phalcon_Annotations_Annotation, getNamedArgument){ - zval *name, *arguments, *value; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(arguments); - phalcon_read_property_this_quick(&arguments, this_ptr, SL("_arguments"), 314247962UL, PH_NOISY_CC); - if (phalcon_array_isset(arguments, name)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, arguments, name, PH_NOISY); - RETURN_CCTOR(value); - } - - RETURN_MM_NULL(); -} -static PHP_METHOD(Phalcon_Annotations_Annotation, getNamedParameter){ - zval *name, *arguments, *value; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(arguments); - phalcon_read_property_this_quick(&arguments, this_ptr, SL("_arguments"), 314247962UL, PH_NOISY_CC); - if (phalcon_array_isset(arguments, name)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, arguments, name, PH_NOISY); - RETURN_CCTOR(value); - } - - RETURN_MM_NULL(); -} -static PHP_METHOD(Phalcon_Annotations_Annotation, hasNamedArgument){ - zval *name, *arguments; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(arguments); - phalcon_read_property_this_quick(&arguments, this_ptr, SL("_arguments"), 314247962UL, PH_NOISY_CC); - if (phalcon_array_isset(arguments, name)) { - RETURN_MM_TRUE; - } - - RETURN_MM_FALSE; + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Db_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db, Exception, db_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } @@ -32595,221 +31716,89 @@ static PHP_METHOD(Phalcon_Annotations_Annotation, hasNamedArgument){ -PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter){ +PHALCON_INIT_CLASS(Phalcon_Db_Index){ - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Adapter, annotations_adapter, phalcon_annotations_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + PHALCON_REGISTER_CLASS(Phalcon\\Db, Index, db_index, phalcon_db_index_method_entry, 0); - zend_declare_property_null(phalcon_annotations_adapter_ce, SL("_reader"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_annotations_adapter_ce, SL("_annotations"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_index_ce, SL("_indexName"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_index_ce, SL("_columns"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_db_index_ce TSRMLS_CC, 1, phalcon_db_indexinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Annotations_Adapter, setReader){ +static PHP_METHOD(Phalcon_Db_Index, __construct){ - zval *reader; + zval *index_name, *columns; - phalcon_fetch_params(0, 1, 0, &reader); + phalcon_fetch_params(0, 2, 0, &index_name, &columns); - if (Z_TYPE_P(reader) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, "Invalid annotations reader"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_reader"), reader, 1648179735UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_indexName"), index_name, 3837120573UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_columns"), columns, 4004520869UL TSRMLS_CC); } -static PHP_METHOD(Phalcon_Annotations_Adapter, getReader){ +static PHP_METHOD(Phalcon_Db_Index, getName){ - zval *reader = NULL; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_indexName", 3837120573UL); +} - PHALCON_OBS_VAR(reader); - phalcon_read_property_this_quick(&reader, this_ptr, SL("_reader"), 1648179735UL, PH_NOISY_CC); - if (Z_TYPE_P(reader) != IS_OBJECT) { - PHALCON_INIT_NVAR(reader); - object_init_ex(reader, phalcon_annotations_reader_ce); - phalcon_update_property_this_quick(this_ptr, SL("_reader"), reader, 1648179735UL TSRMLS_CC); - } - - RETURN_CCTOR(reader); +static PHP_METHOD(Phalcon_Db_Index, getColumns){ + + + RETURN_MEMBER_QUICK(this_ptr, "_columns", 4004520869UL); } -static PHP_METHOD(Phalcon_Annotations_Adapter, get){ +static PHP_METHOD(Phalcon_Db_Index, __set_state){ - zval *class_name, *real_class_name = NULL, *annotations; - zval *class_annotations = NULL, *reader, *parsed_annotations; + zval *data, *index_name, *columns; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &class_name); + phalcon_fetch_params(1, 1, 0, &data); - if (Z_TYPE_P(class_name) == IS_OBJECT) { - PHALCON_INIT_VAR(real_class_name); - phalcon_get_class(real_class_name, class_name, 0 TSRMLS_CC); - } else { - PHALCON_CPY_WRT(real_class_name, class_name); + if (!phalcon_array_isset_quick_string(data, SS("_indexName"), 3837120573UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "_indexName parameter is required"); + return; } - - PHALCON_OBS_VAR(annotations); - phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC); - if (Z_TYPE_P(annotations) == IS_ARRAY) { - if (phalcon_array_isset(annotations, real_class_name)) { - PHALCON_OBS_VAR(class_annotations); - phalcon_array_fetch(&class_annotations, annotations, real_class_name, PH_NOISY); - RETURN_CCTOR(class_annotations); - } + if (!phalcon_array_isset_quick_string(data, SS("_columns"), 4004520869UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "_columns parameter is required"); + return; } - PHALCON_INIT_NVAR(class_annotations); - phalcon_call_method_p1_key(class_annotations, this_ptr, "read", real_class_name, 273085793UL); - if (Z_TYPE_P(class_annotations) == IS_NULL) { - - PHALCON_INIT_VAR(reader); - phalcon_call_method_key(reader, this_ptr, "getreader", 318193528UL); - - PHALCON_INIT_VAR(parsed_annotations); - phalcon_call_method_p1_key(parsed_annotations, reader, "parse", real_class_name, 339512704UL); + PHALCON_OBS_VAR(index_name); + phalcon_array_fetch_quick_string(&index_name, data, SS("_indexName"), 3837120573UL, PH_NOISY); - if (Z_TYPE_P(parsed_annotations) == IS_ARRAY) { - PHALCON_INIT_NVAR(class_annotations); - object_init_ex(class_annotations, phalcon_annotations_reflection_ce); - phalcon_call_method_p1_key(NULL, class_annotations, "__construct", parsed_annotations, 1107214344UL); + PHALCON_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, data, SS("_columns"), 4004520869UL, PH_NOISY); - phalcon_update_property_array(this_ptr, SL("_annotations"), real_class_name, class_annotations TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "write", real_class_name, class_annotations, 633298768UL); - } - } + object_init_ex(return_value, phalcon_db_index_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", index_name, columns, 1107214344UL); - RETURN_CCTOR(class_annotations); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Annotations_Adapter, getMethods){ - - zval *class_name, *class_annotations; - - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &class_name); - - PHALCON_INIT_VAR(class_annotations); - phalcon_call_method_p1_key(class_annotations, this_ptr, "get", class_name, 2090288933UL); - - if (Z_TYPE_P(class_annotations) == IS_OBJECT) { - phalcon_call_method_key(return_value, class_annotations, "getmethodsannotations", 2860599943UL); - RETURN_MM(); - } - - RETURN_MM_EMPTY_ARRAY(); -} -static PHP_METHOD(Phalcon_Annotations_Adapter, getMethod){ - zval *class_name, *method_name, *class_annotations; - zval *methods, *method = NULL, *name = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); +#ifdef HAVE_CONFIG_H +#endif - phalcon_fetch_params(1, 2, 0, &class_name, &method_name); - - PHALCON_INIT_VAR(class_annotations); - phalcon_call_method_p1_key(class_annotations, this_ptr, "get", class_name, 2090288933UL); - - if (Z_TYPE_P(class_annotations) == IS_OBJECT) { - - PHALCON_INIT_VAR(methods); - phalcon_call_method_key(methods, class_annotations, "getmethodsannotations", 2860599943UL); - if (Z_TYPE_P(methods) == IS_ARRAY) { - - phalcon_is_iterable(methods, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(name, ah0, hp0); - PHALCON_GET_HVALUE(method); - - if (PHALCON_IS_EQUAL(name, method_name)) { - RETURN_CCTOR(method); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - } - - object_init_ex(return_value, phalcon_annotations_collection_ce); - phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL); - - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Annotations_Adapter, getProperties){ - zval *class_name, *class_annotations; +PHALCON_INIT_CLASS(Phalcon_Db_IndexInterface){ - PHALCON_MM_GROW(); + PHALCON_REGISTER_INTERFACE(Phalcon\\Db, IndexInterface, db_indexinterface, phalcon_db_indexinterface_method_entry); - phalcon_fetch_params(1, 1, 0, &class_name); - - PHALCON_INIT_VAR(class_annotations); - phalcon_call_method_p1_key(class_annotations, this_ptr, "get", class_name, 2090288933UL); - - if (Z_TYPE_P(class_annotations) == IS_OBJECT) { - phalcon_call_method_key(return_value, class_annotations, "getpropertiesannotations", 3353352384UL); - RETURN_MM(); - } - - RETURN_MM_EMPTY_ARRAY(); + return SUCCESS; } -static PHP_METHOD(Phalcon_Annotations_Adapter, getProperty){ - zval *class_name, *property_name, *class_annotations; - zval *properties, *property = NULL, *name = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &class_name, &property_name); - - PHALCON_INIT_VAR(class_annotations); - phalcon_call_method_p1_key(class_annotations, this_ptr, "get", class_name, 2090288933UL); - - if (Z_TYPE_P(class_annotations) == IS_OBJECT) { - - PHALCON_INIT_VAR(properties); - phalcon_call_method_key(properties, class_annotations, "getpropertyannotations", 2404243672UL); - if (Z_TYPE_P(properties) == IS_ARRAY) { - - phalcon_is_iterable(properties, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(name, ah0, hp0); - PHALCON_GET_HVALUE(property); - - if (PHALCON_IS_EQUAL(name, property_name)) { - RETURN_CCTOR(property); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - } - - object_init_ex(return_value, phalcon_annotations_collection_ce); - phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL); - - RETURN_MM(); -} @@ -32824,111 +31813,78 @@ static PHP_METHOD(Phalcon_Annotations_Adapter, getProperty){ -PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Files){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Files, annotations_adapter_files, "phalcon\\annotations\\adapter", phalcon_annotations_adapter_files_method_entry, 0); +PHALCON_INIT_CLASS(Phalcon_Db_Profiler_Item){ - zend_declare_property_string(phalcon_annotations_adapter_files_ce, SL("_annotationsDir"), "./", ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_REGISTER_CLASS(Phalcon\\Db\\Profiler, Item, db_profiler_item, phalcon_db_profiler_item_method_entry, 0); - zend_class_implements(phalcon_annotations_adapter_files_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce); + zend_declare_property_null(phalcon_db_profiler_item_ce, SL("_sqlStatement"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_profiler_item_ce, SL("_initialTime"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_db_profiler_item_ce, SL("_finalTime"), ZEND_ACC_PROTECTED TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_Annotations_Adapter_Files, __construct){ - - zval *options = NULL, *annotations_dir; +static PHP_METHOD(Phalcon_Db_Profiler_Item, setSQLStatement){ - PHALCON_MM_GROW(); + zval *sql_statement; - phalcon_fetch_params(1, 0, 1, &options); + phalcon_fetch_params(0, 1, 0, &sql_statement); - if (!options) { - PHALCON_INIT_VAR(options); - } + phalcon_update_property_this_quick(this_ptr, SL("_sqlStatement"), sql_statement, 18972457UL TSRMLS_CC); - if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(options, SS("annotationsDir"), 1341171666UL)) { - PHALCON_OBS_VAR(annotations_dir); - phalcon_array_fetch_quick_string(&annotations_dir, options, SS("annotationsDir"), 1341171666UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_annotationsDir"), annotations_dir, 4233102065UL TSRMLS_CC); - } - } - - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Annotations_Adapter_Files, read){ +static PHP_METHOD(Phalcon_Db_Profiler_Item, getSQLStatement){ - zval *key, *annotations_dir, *separator, *virtual_key; - zval *path, *data; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); +} - phalcon_fetch_params(1, 1, 0, &key); - - PHALCON_OBS_VAR(annotations_dir); - phalcon_read_property_this_quick(&annotations_dir, this_ptr, SL("_annotationsDir"), 4233102065UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(separator); - ZVAL_STRING(separator, "_", 1); +static PHP_METHOD(Phalcon_Db_Profiler_Item, setInitialTime){ + + zval *initial_time; + + phalcon_fetch_params(0, 1, 0, &initial_time); - PHALCON_INIT_VAR(virtual_key); - phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_initialTime"), initial_time, 3347691997UL TSRMLS_CC); - PHALCON_INIT_VAR(path); - PHALCON_CONCAT_VVS(path, annotations_dir, virtual_key, ".php"); +} + +static PHP_METHOD(Phalcon_Db_Profiler_Item, setFinalTime){ + + zval *final_time; + + phalcon_fetch_params(0, 1, 0, &final_time); - if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_VAR(data); - if (phalcon_require_ret(data, path TSRMLS_CC) == FAILURE) { - return; - } - RETURN_CCTOR(data); - } + phalcon_update_property_this_quick(this_ptr, SL("_finalTime"), final_time, 2101629981UL TSRMLS_CC); - RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Annotations_Adapter_Files, write){ +static PHP_METHOD(Phalcon_Db_Profiler_Item, getInitialTime){ - zval *key, *data, *annotations_dir, *separator; - zval *virtual_key, *path, *to_string, *export, *php_export; - zval *status; + + RETURN_MEMBER_QUICK(this_ptr, "_initialTime", 3347691997UL); +} + +static PHP_METHOD(Phalcon_Db_Profiler_Item, getFinalTime){ + + + RETURN_MEMBER_QUICK(this_ptr, "_finalTime", 2101629981UL); +} + +static PHP_METHOD(Phalcon_Db_Profiler_Item, getTotalElapsedSeconds){ + + zval *final_time, *initial_time; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &key, &data); - - PHALCON_OBS_VAR(annotations_dir); - phalcon_read_property_this_quick(&annotations_dir, this_ptr, SL("_annotationsDir"), 4233102065UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(separator); - ZVAL_STRING(separator, "_", 1); - - PHALCON_INIT_VAR(virtual_key); - phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); - - PHALCON_INIT_VAR(path); - PHALCON_CONCAT_VVS(path, annotations_dir, virtual_key, ".php"); - - PHALCON_INIT_VAR(to_string); - ZVAL_BOOL(to_string, 1); - - PHALCON_INIT_VAR(export); - phalcon_call_func_p2(export, "var_export", data, to_string); - - PHALCON_INIT_VAR(php_export); - PHALCON_CONCAT_SVS(php_export, "dbh) { + PHALCON_MM_RESTORE(); + RETURN_FALSE; + } + n = -1; + number--; + while (n != number) { + if(!stmt->methods->fetcher(stmt, PDO_FETCH_ORI_NEXT, 0 TSRMLS_CC)) { + PHALCON_MM_RESTORE(); + RETURN_NULL(); + } -#ifdef HAVE_CONFIG_H -#endif + n++; + } + PHALCON_MM_RESTORE(); +} +static PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ + long fetch_mode; + zval *pdo_statement, *fetch_type; + PHALCON_MM_GROW(); -PHALCON_INIT_CLASS(Phalcon_Annotations_Exception){ + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fetch_mode) == FAILURE) { + RETURN_MM_NULL(); + } - PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations, Exception, annotations_exception, "phalcon\\exception", NULL, 0); + PHALCON_INIT_VAR(fetch_type); - return SUCCESS; + PHALCON_OBS_VAR(pdo_statement); + phalcon_read_property(&pdo_statement, this_ptr, SL("_pdoStatement"), PH_NOISY_CC); + if (fetch_mode == 1) { + ZVAL_LONG(fetch_type, 2); + } else if (fetch_mode == 2) { + ZVAL_LONG(fetch_type, 4); + } else if (fetch_mode == 3) { + ZVAL_LONG(fetch_type, 3); + } else if (fetch_mode == 4) { + ZVAL_LONG(fetch_type, 5); + } else { + ZVAL_LONG(fetch_type, 0); + } + + if (Z_LVAL_P(fetch_type) != 0) { + phalcon_call_method_p1_key(NULL, pdo_statement, "setfetchmode", fetch_type, 824603840UL); + phalcon_update_property_long(this_ptr, SL("_fetchMode"), Z_LVAL_P(fetch_type) TSRMLS_CC); + } + + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Db_Result_Pdo, getInternalResult){ + + + RETURN_MEMBER_QUICK(this_ptr, "_pdoStatement", 650036348UL); } @@ -33607,9 +32594,9 @@ PHALCON_INIT_CLASS(Phalcon_Annotations_Exception){ -PHALCON_INIT_CLASS(Phalcon_Annotations_ReaderInterface){ +PHALCON_INIT_CLASS(Phalcon_Db_ResultInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Annotations, ReaderInterface, annotations_readerinterface, phalcon_annotations_readerinterface_method_entry); + PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ResultInterface, db_resultinterface, phalcon_db_resultinterface_method_entry); return SUCCESS; } @@ -33620,19 +32607,15 @@ PHALCON_INIT_CLASS(Phalcon_Annotations_ReaderInterface){ -#ifdef HAVE_CONFIG_H -#endif -PHALCON_INIT_CLASS(Phalcon_DiInterface){ - PHALCON_REGISTER_INTERFACE_EX(Phalcon, DiInterface, diinterface, "arrayaccess", phalcon_diinterface_method_entry); - return SUCCESS; -} +#ifdef HAVE_CONFIG_H +#endif @@ -33640,12 +32623,39 @@ PHALCON_INIT_CLASS(Phalcon_DiInterface){ +PHALCON_INIT_CLASS(Phalcon_Db){ + + PHALCON_REGISTER_CLASS(Phalcon, Db, db, phalcon_db_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_ASSOC"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_BOTH"), 2 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_NUM"), 3 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_db_ce, SL("FETCH_OBJ"), 4 TSRMLS_CC); + return SUCCESS; +} +static PHP_METHOD(Phalcon_Db, setup){ + zval *options, *escape_identifiers; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &options); + + if (Z_TYPE_P(options) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Options must be an array"); + return; + } + + if (phalcon_array_isset_quick_string(options, SS("escapeSqlIdentifiers"), 2537413436UL)) { + PHALCON_OBS_VAR(escape_identifiers); + phalcon_array_fetch_quick_string(&escape_identifiers, options, SS("escapeSqlIdentifiers"), 2537413436UL, PH_NOISY); + PHALCON_GLOBAL(db).escape_identifiers = zend_is_true(escape_identifiers); + } + + PHALCON_MM_RESTORE(); +} @@ -33660,784 +32670,909 @@ PHALCON_INIT_CLASS(Phalcon_DiInterface){ -PHALCON_INIT_CLASS(Phalcon_Dispatcher){ +PHALCON_INIT_CLASS(Phalcon_Debug){ - PHALCON_REGISTER_CLASS(Phalcon, Dispatcher, dispatcher, phalcon_dispatcher_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + PHALCON_REGISTER_CLASS(Phalcon, Debug, debug, phalcon_debug_method_entry, 0); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_activeHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_finished"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_dispatcher_ce, SL("_forwarded"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_moduleName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_namespaceName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_handlerName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_actionName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_params"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_returnedValue"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_lastHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_defaultNamespace"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_dispatcher_ce, SL("_defaultHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_dispatcher_ce, SL("_defaultAction"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_dispatcher_ce, SL("_handlerSuffix"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_dispatcher_ce, SL("_actionSuffix"), "Action", ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_NO_DI"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_CYCLIC_ROUTING"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_HANDLER_NOT_FOUND"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_INVALID_HANDLER"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_INVALID_PARAMS"), 4 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_ACTION_NOT_FOUND"), 5 TSRMLS_CC); - - zend_class_implements(phalcon_dispatcher_ce TSRMLS_CC, 3, phalcon_dispatcherinterface_ce, phalcon_di_injectionawareinterface_ce, phalcon_events_eventsawareinterface_ce); + zend_declare_property_string(phalcon_debug_ce, SL("_uri"), "http://static.phalconphp.com/debug/1.2.0/", ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_string(phalcon_debug_ce, SL("_theme"), "default", ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_bool(phalcon_debug_ce, SL("_hideDocumentRoot"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_debug_ce, SL("_showBackTrace"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_debug_ce, SL("_showFiles"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_debug_ce, SL("_showFileFragment"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_debug_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_debug_ce, SL("_isActive"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_Dispatcher, __construct){ +static PHP_METHOD(Phalcon_Debug, setUri){ + zval *uri; - phalcon_update_property_empty_array(phalcon_dispatcher_ce, this_ptr, SL("_params") TSRMLS_CC); + phalcon_fetch_params(0, 1, 0, &uri); + phalcon_update_property_this_quick(this_ptr, SL("_uri"), uri, 251146964UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Dispatcher, setDI){ +static PHP_METHOD(Phalcon_Debug, setShowBackTrace){ - zval *dependency_injector; + zval *show_back_trace; - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + phalcon_fetch_params(0, 1, 0, &show_back_trace); + phalcon_update_property_this_quick(this_ptr, SL("_showBackTrace"), show_back_trace, 3370024901UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Dispatcher, getDI){ +static PHP_METHOD(Phalcon_Debug, setShowFiles){ + zval *show_files; - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); + phalcon_fetch_params(0, 1, 0, &show_files); + + phalcon_update_property_this_quick(this_ptr, SL("_showFiles"), show_files, 1877855960UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Dispatcher, setEventsManager){ +static PHP_METHOD(Phalcon_Debug, setShowFileFragment){ - zval *events_manager; + zval *show_file_fragment; - phalcon_fetch_params(0, 1, 0, &events_manager); - - phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); + phalcon_fetch_params(0, 1, 0, &show_file_fragment); + phalcon_update_property_this_quick(this_ptr, SL("_showFileFragment"), show_file_fragment, 3533221081UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Dispatcher, getEventsManager){ - - - RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); -} +static PHP_METHOD(Phalcon_Debug, listen){ -static PHP_METHOD(Phalcon_Dispatcher, setActionSuffix){ + zval *exceptions = NULL, *low_severity = NULL; - zval *action_suffix; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &action_suffix); + phalcon_fetch_params(1, 0, 2, &exceptions, &low_severity); - phalcon_update_property_this_quick(this_ptr, SL("_actionSuffix"), action_suffix, 879621975UL TSRMLS_CC); + if (!exceptions) { + PHALCON_INIT_VAR(exceptions); + ZVAL_BOOL(exceptions, 1); + } -} - -static PHP_METHOD(Phalcon_Dispatcher, setModuleName){ - - zval *module_name; - - phalcon_fetch_params(0, 1, 0, &module_name); + if (!low_severity) { + PHALCON_INIT_VAR(low_severity); + ZVAL_BOOL(low_severity, 0); + } - phalcon_update_property_this_quick(this_ptr, SL("_moduleName"), module_name, 4053279339UL TSRMLS_CC); + if (zend_is_true(exceptions)) { + phalcon_call_method_key(NULL, this_ptr, "listenexceptions", 2156957942UL); + } + if (zend_is_true(low_severity)) { + phalcon_call_method_key(NULL, this_ptr, "listenlowseverity", 1386787713UL); + } + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Dispatcher, getModuleName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_moduleName", 4053279339UL); -} +static PHP_METHOD(Phalcon_Debug, listenExceptions){ -static PHP_METHOD(Phalcon_Dispatcher, setNamespaceName){ + zval *handler; - zval *namespace_name; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &namespace_name); - - phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC); - + PHALCON_INIT_VAR(handler); + array_init_size(handler, 2); + phalcon_array_append(&handler, this_ptr, PH_SEPARATE); + add_next_index_stringl(handler, SL("onUncaughtException"), 1); + phalcon_call_func_p1_noret("set_exception_handler", handler); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Dispatcher, getNamespaceName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_namespaceName", 816833906UL); -} +static PHP_METHOD(Phalcon_Debug, listenLowSeverity){ -static PHP_METHOD(Phalcon_Dispatcher, setDefaultNamespace){ + zval *handler; - zval *namespace; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &namespace); - - phalcon_update_property_this_quick(this_ptr, SL("_defaultNamespace"), namespace, 761145590UL TSRMLS_CC); - + PHALCON_INIT_VAR(handler); + array_init_size(handler, 2); + phalcon_array_append(&handler, this_ptr, PH_SEPARATE); + add_next_index_stringl(handler, SL("onUncaughtLowSeverity"), 1); + phalcon_call_func_p1_noret("set_exception_handler", handler); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Dispatcher, getDefaultNamespace){ - - - RETURN_MEMBER_QUICK(this_ptr, "_defaultNamespace", 761145590UL); -} +static PHP_METHOD(Phalcon_Debug, debugVar){ -static PHP_METHOD(Phalcon_Dispatcher, setDefaultAction){ + zval *var, *key = NULL, *ztime, *backtrace, *data; - zval *action_name; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &action_name); + phalcon_fetch_params(1, 1, 1, &var, &key); - phalcon_update_property_this_quick(this_ptr, SL("_defaultAction"), action_name, 895696999UL TSRMLS_CC); + if (!key) { + PHALCON_INIT_VAR(key); + } -} - -static PHP_METHOD(Phalcon_Dispatcher, setActionName){ - - zval *action_name; - - phalcon_fetch_params(0, 1, 0, &action_name); + PHALCON_INIT_VAR(ztime); + ZVAL_LONG(ztime, (long) time(NULL)); - phalcon_update_property_this_quick(this_ptr, SL("_actionName"), action_name, 2975797059UL TSRMLS_CC); + PHALCON_INIT_VAR(backtrace); +#if PHP_VERSION_ID < 50400 +#ifdef DEBUG_BACKTRACE_PROVIDE_OBJECT + zend_fetch_debug_backtrace(backtrace, 0, DEBUG_BACKTRACE_PROVIDE_OBJECT TSRMLS_CC); +#else + zend_fetch_debug_backtrace(backtrace, 0, 1 TSRMLS_CC); +#endif +#else + zend_fetch_debug_backtrace(backtrace, 0, DEBUG_BACKTRACE_PROVIDE_OBJECT, 0 TSRMLS_CC); +#endif + PHALCON_INIT_VAR(data); + array_init_size(data, 3); + phalcon_array_append(&data, var, PH_SEPARATE); + phalcon_array_append(&data, backtrace, PH_SEPARATE); + phalcon_array_append(&data, ztime, PH_SEPARATE); + phalcon_update_property_array_append(this_ptr, SL("_data"), data TSRMLS_CC); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Dispatcher, getActionName){ +static PHP_METHOD(Phalcon_Debug, clearVars){ - RETURN_MEMBER_QUICK(this_ptr, "_actionName", 2975797059UL); + phalcon_update_property_null(this_ptr, SL("_data") TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Dispatcher, setParams){ +static PHP_METHOD(Phalcon_Debug, _escapeString){ - zval *params, *exception_message; + zval *value, *charset, *ent_compat, *line_break; + zval *escaped_line_break, *replaced_value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶ms); + phalcon_fetch_params(1, 1, 0, &value); - if (Z_TYPE_P(params) != IS_ARRAY) { - PHALCON_INIT_VAR(exception_message); - ZVAL_STRING(exception_message, "Parameters must be an Array", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "_throwdispatchexception", exception_message, 3996129271UL); - RETURN_MM_NULL(); + if (Z_TYPE_P(value) == IS_STRING) { + PHALCON_INIT_VAR(charset); + ZVAL_STRING(charset, "utf-8", 1); + + PHALCON_INIT_VAR(ent_compat); + ZVAL_LONG(ent_compat, 2); + + PHALCON_INIT_VAR(line_break); + ZVAL_STRING(line_break, "\n", 1); + + PHALCON_INIT_VAR(escaped_line_break); + ZVAL_STRING(escaped_line_break, "\\n", 1); + + PHALCON_INIT_VAR(replaced_value); + phalcon_fast_str_replace(replaced_value, line_break, escaped_line_break, value); + phalcon_call_func_p3(return_value, "htmlentities", replaced_value, ent_compat, charset); + RETURN_MM(); } - phalcon_update_property_this_quick(this_ptr, SL("_params"), params, 3223731112UL TSRMLS_CC); - PHALCON_MM_RESTORE(); + RETURN_CCTOR(value); } -static PHP_METHOD(Phalcon_Dispatcher, getParams){ - - - RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); -} +static PHP_METHOD(Phalcon_Debug, _getArrayDump){ -static PHP_METHOD(Phalcon_Dispatcher, setParam){ + zval *argument, *n = NULL, *number_arguments, *one, *dump; + zval *v = NULL, *k = NULL, *var_dump = NULL, *escaped_string = NULL, *next = NULL, *array_dump = NULL; + zval *class_name = NULL, *joined_dump; + HashTable *ah0; + HashPosition hp0; + zval **hd; - zval *param, *value; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 2, 0, ¶m, &value); + phalcon_fetch_params(1, 1, 1, &argument, &n); - phalcon_update_property_array(this_ptr, SL("_params"), param, value TSRMLS_CC); + if (!n) { + PHALCON_INIT_VAR(n); + ZVAL_LONG(n, 0); + } + + PHALCON_INIT_VAR(number_arguments); + phalcon_fast_count(number_arguments, argument TSRMLS_CC); + if (PHALCON_LT_LONG(n, 3)) { + if (PHALCON_GT_LONG(number_arguments, 0)) { + if (PHALCON_LT_LONG(number_arguments, 10)) { + + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + + PHALCON_INIT_VAR(dump); + array_init(dump); + phalcon_is_iterable(argument, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(k, ah0, hp0); + PHALCON_GET_HVALUE(v); + + if (PHALCON_IS_SCALAR(v)) { + if (PHALCON_IS_STRING(v, "")) { + PHALCON_INIT_NVAR(var_dump); + PHALCON_CONCAT_SVS(var_dump, "[", k, "] => (empty string)"); + } else { + PHALCON_INIT_NVAR(escaped_string); + phalcon_call_method_p1_key(escaped_string, this_ptr, "_escapestring", v, 1235002348UL); + + PHALCON_INIT_NVAR(var_dump); + PHALCON_CONCAT_SVSV(var_dump, "[", k, "] => ", escaped_string); + } + phalcon_array_append(&dump, var_dump, PH_SEPARATE); + } else { + if (Z_TYPE_P(v) == IS_ARRAY) { + PHALCON_INIT_NVAR(next); + phalcon_add_function(next, n, one TSRMLS_CC); + + PHALCON_INIT_NVAR(array_dump); + phalcon_call_method_p2_key(array_dump, this_ptr, "_getarraydump", v, next, 2678003289UL); + + PHALCON_INIT_NVAR(var_dump); + PHALCON_CONCAT_SVSVS(var_dump, "[", k, "] => Array(", array_dump, ")"); + phalcon_array_append(&dump, var_dump, PH_SEPARATE); + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + if (Z_TYPE_P(v) == IS_OBJECT) { + PHALCON_INIT_NVAR(class_name); + phalcon_get_class(class_name, v, 0 TSRMLS_CC); + + PHALCON_INIT_NVAR(var_dump); + PHALCON_CONCAT_SVSVS(var_dump, "[", k, "] => Object(", class_name, ")"); + phalcon_array_append(&dump, var_dump, PH_SEPARATE); + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + + if (Z_TYPE_P(v) == IS_NULL) { + PHALCON_INIT_NVAR(var_dump); + PHALCON_CONCAT_SVS(var_dump, "[", k, "] => null"); + phalcon_array_append(&dump, var_dump, PH_SEPARATE); + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + + PHALCON_INIT_NVAR(var_dump); + PHALCON_CONCAT_SVSV(var_dump, "[", k, "] => ", v); + phalcon_array_append(&dump, var_dump, PH_SEPARATE); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(joined_dump); + phalcon_fast_join_str(joined_dump, SL(", "), dump TSRMLS_CC); + + RETURN_CTOR(joined_dump); + } + + RETURN_NCTOR(number_arguments); + } + } + + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Dispatcher, getParam){ +static PHP_METHOD(Phalcon_Debug, _getVarDump){ - zval *param, *filters = NULL, *default_value = NULL, *params; - zval *param_value, *dependency_injector, *exception_code; - zval *exception_message, *service, *filter; + zval *variable, *class_name, *dumped_object; + zval *array_dump = NULL, *dump = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, ¶m, &filters, &default_value); + phalcon_fetch_params(1, 1, 0, &variable); - if (!filters) { - PHALCON_INIT_VAR(filters); - } + if (PHALCON_IS_SCALAR(variable)) { - if (!default_value) { - PHALCON_INIT_VAR(default_value); - } + if (Z_TYPE_P(variable) == IS_BOOL) { + if (zend_is_true(variable)) { + RETURN_MM_STRING("true", 1); + } else { + RETURN_MM_STRING("false", 1); + } + } - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset(params, param)) { + if (Z_TYPE_P(variable) == IS_STRING) { + phalcon_call_method_p1_key(return_value, this_ptr, "_escapestring", variable, 1235002348UL); + RETURN_MM(); + } - PHALCON_OBS_VAR(param_value); - phalcon_array_fetch(¶m_value, params, param, PH_NOISY); - if (Z_TYPE_P(filters) != IS_NULL) { - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_VAR(exception_code); - ZVAL_LONG(exception_code, 0); + RETURN_CCTOR(variable); + } - PHALCON_INIT_VAR(exception_message); - ZVAL_STRING(exception_message, "A dependency injection object is required to access the 'filter' service", 1); - phalcon_call_method_p2_key(NULL, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); - } + if (Z_TYPE_P(variable) == IS_OBJECT) { - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "filter", 1); + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, variable, 0 TSRMLS_CC); - PHALCON_INIT_VAR(filter); - phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service, 1727570332UL); - phalcon_call_method_p2_key(return_value, filter, "sanitize", param_value, filters, 3688332940UL); - RETURN_MM(); + if (phalcon_method_quick_exists_ex(variable, SS("dump"), 257071355UL TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_VAR(dumped_object); + phalcon_call_method_key(dumped_object, variable, "dump", 257071355UL); + + PHALCON_INIT_VAR(array_dump); + phalcon_call_method_p1_key(array_dump, this_ptr, "_getarraydump", dumped_object, 2678003289UL); + + PHALCON_INIT_VAR(dump); + PHALCON_CONCAT_SVSVS(dump, "Object(", class_name, ": ", array_dump, ")"); } else { - RETURN_CCTOR(param_value); + PHALCON_INIT_NVAR(dump); + PHALCON_CONCAT_SVS(dump, "Object(", class_name, ")"); } + + RETURN_CTOR(dump); } - RETURN_CCTOR(default_value); + if (Z_TYPE_P(variable) == IS_ARRAY) { + PHALCON_INIT_NVAR(array_dump); + phalcon_call_method_p1_key(array_dump, this_ptr, "_getarraydump", variable, 2678003289UL); + PHALCON_CONCAT_SVS(return_value, "Array(", array_dump, ")"); + RETURN_MM(); + } + + RETURN_MM_STRING(zend_zval_type_name(variable), 1); } -static PHP_METHOD(Phalcon_Dispatcher, getActiveMethod){ +static PHP_METHOD(Phalcon_Debug, getMajorVersion){ - zval *suffix, *action_name; + zval *version, *parts, *major; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(suffix); - phalcon_read_property_this_quick(&suffix, this_ptr, SL("_actionSuffix"), 879621975UL, PH_NOISY_CC); + PHALCON_INIT_VAR(version); + PHALCON_CALL_STATIC(version, "phalcon\\version", "get"); - PHALCON_OBS_VAR(action_name); - phalcon_read_property_this_quick(&action_name, this_ptr, SL("_actionName"), 2975797059UL, PH_NOISY_CC); - PHALCON_CONCAT_VV(return_value, action_name, suffix); - RETURN_MM(); + PHALCON_INIT_VAR(parts); + phalcon_fast_explode_str(parts, SL(" "), version); + + PHALCON_OBS_VAR(major); + phalcon_array_fetch_long(&major, parts, 0, PH_NOISY); + RETURN_CCTOR(major); } -static PHP_METHOD(Phalcon_Dispatcher, isFinished){ +static PHP_METHOD(Phalcon_Debug, getVersion){ + + zval *version; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_finished", 385784334UL); + PHALCON_INIT_VAR(version); + phalcon_call_method_key(version, this_ptr, "getmajorversion", 1927318692UL); + PHALCON_CONCAT_SVSVS(return_value, "
Phalcon Framework ", version, "
"); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Dispatcher, setReturnedValue){ +static PHP_METHOD(Phalcon_Debug, getCssSources){ - zval *value; + zval *uri, *sources; - phalcon_fetch_params(0, 1, 0, &value); - - phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC); + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(uri); + phalcon_read_property_this_quick(&uri, this_ptr, SL("_uri"), 251146964UL, PH_NOISY_CC); + PHALCON_INIT_VAR(sources); + PHALCON_CONCAT_SVS(sources, ""); + PHALCON_SCONCAT_SVS(sources, ""); + RETURN_CTOR(sources); } -static PHP_METHOD(Phalcon_Dispatcher, getReturnedValue){ +static PHP_METHOD(Phalcon_Debug, getJsSources){ + zval *uri, *sources; - RETURN_MEMBER_QUICK(this_ptr, "_returnedValue", 4143876906UL); + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(uri); + phalcon_read_property_this_quick(&uri, this_ptr, SL("_uri"), 251146964UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(sources); + PHALCON_CONCAT_SVS(sources, ""); + PHALCON_SCONCAT_SVS(sources, ""); + PHALCON_SCONCAT_SVS(sources, ""); + PHALCON_SCONCAT_SVS(sources, ""); + PHALCON_SCONCAT_SVS(sources, ""); + RETURN_CTOR(sources); } -static PHP_METHOD(Phalcon_Dispatcher, dispatch){ +static PHP_METHOD(Phalcon_Debug, showTraceItem){ - zval *dependency_injector, *exception_code = NULL; - zval *exception_message = NULL, *events_manager; - zval *event_name = NULL, *status = NULL, *value = NULL, *handler = NULL, *number_dispatches; - zval *handler_suffix, *action_suffix, *finished = NULL; - zval *namespace_name = NULL, *handler_name = NULL, *action_name = NULL; - zval *camelized_class = NULL, *handler_class = NULL, *has_service = NULL; - zval *was_fresh = NULL, *action_method = NULL, *params = NULL, *call_object = NULL; - zval *exception = NULL; + zval *n, *trace, *space, *two_spaces, *underscore; + zval *minus, *html, *class_name, *pattern, *is_phalcon_class; + zval *namespace_separator, *prepare_uri_class; + zval *class_reflection, *is_internal = NULL, *lower_class_name; + zval *prepare_internal_class, *type, *function_name = NULL; + zval *function_reflection, *prepared_function_name; + zval *trace_args, *arguments, *argument = NULL, *dumped_argument = NULL; + zval *span_argument = NULL, *joined_arguments, *one; + zval *file, *line, *show_files, *lines, *number_lines; + zval *show_file_fragment, *seven, *before_line; + zval *first_line = NULL, *five, *after_line, *last_line = NULL; + zval *comment_pattern, *utf8, *ent_compat, *tab; + zval *comment, *i = NULL, *line_position = NULL, *current_line = NULL; + zval *trimmed = NULL, *is_comment = NULL, *spaced_current_line = NULL; + zval *escaped_line = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + zend_class_entry *ce0, *ce1; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_VAR(exception_code); - ZVAL_LONG(exception_code, 0); - - PHALCON_INIT_VAR(exception_message); - ZVAL_STRING(exception_message, "A dependency injection container is required to access related dispatching services", 1); - phalcon_call_method_p2_key(NULL, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); - RETURN_MM_FALSE; - } + phalcon_fetch_params(1, 2, 0, &n, &trace); - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_VAR(space); + ZVAL_STRING(space, " ", 1); - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "dispatch:beforeDispatchLoop", 1); + PHALCON_INIT_VAR(two_spaces); + ZVAL_STRING(two_spaces, " ", 1); - PHALCON_INIT_VAR(status); - phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } - - PHALCON_INIT_VAR(value); - - PHALCON_INIT_VAR(handler); - - PHALCON_INIT_VAR(number_dispatches); - ZVAL_LONG(number_dispatches, 0); + PHALCON_INIT_VAR(underscore); + ZVAL_STRING(underscore, "_", 1); - PHALCON_OBS_VAR(handler_suffix); - phalcon_read_property_this_quick(&handler_suffix, this_ptr, SL("_handlerSuffix"), 1659190583UL, PH_NOISY_CC); + PHALCON_INIT_VAR(minus); + ZVAL_STRING(minus, "-", 1); - PHALCON_OBS_VAR(action_suffix); - phalcon_read_property_this_quick(&action_suffix, this_ptr, SL("_actionSuffix"), 879621975UL, PH_NOISY_CC); + PHALCON_INIT_VAR(html); + PHALCON_CONCAT_SVS(html, "#", n, ""); + if (phalcon_array_isset_quick_string(trace, SS("class"), 4138154555UL)) { - phalcon_update_property_bool(this_ptr, SL("_finished"), 0 TSRMLS_CC); + PHALCON_OBS_VAR(class_name); + phalcon_array_fetch_quick_string(&class_name, trace, SS("class"), 4138154555UL, PH_NOISY); - while (1) { + PHALCON_INIT_VAR(pattern); + ZVAL_STRING(pattern, "/^Phalcon/", 1); - PHALCON_OBS_NVAR(finished); - phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); - if (zend_is_true(finished)) { - break; - } + PHALCON_INIT_VAR(is_phalcon_class); - PHALCON_SEPARATE(number_dispatches); - phalcon_increment(number_dispatches); + phalcon_preg_match(is_phalcon_class, pattern, class_name, NULL TSRMLS_CC); - if (PHALCON_IS_LONG(number_dispatches, 256)) { - PHALCON_INIT_NVAR(exception_code); - ZVAL_LONG(exception_code, 1); + if (zend_is_true(is_phalcon_class)) { + PHALCON_INIT_VAR(namespace_separator); + ZVAL_STRING(namespace_separator, "\\", 1); - PHALCON_INIT_NVAR(exception_message); - ZVAL_STRING(exception_message, "Dispatcher has detected a cyclic routing causing stability problems", 1); - phalcon_call_method_p2_key(NULL, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); - break; - } + PHALCON_INIT_VAR(prepare_uri_class); + phalcon_fast_str_replace(prepare_uri_class, namespace_separator, underscore, class_name); - phalcon_update_property_bool(this_ptr, SL("_finished"), 1 TSRMLS_CC); + PHALCON_SCONCAT_SVSVS(html, "", class_name, ""); + } else { + ce0 = zend_fetch_class(SL("ReflectionClass"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + PHALCON_INIT_VAR(class_reflection); + object_init_ex(class_reflection, ce0); + if (phalcon_has_constructor(class_reflection TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, class_reflection, "__construct", class_name, 1107214344UL); + } - PHALCON_OBS_NVAR(namespace_name); - phalcon_read_property_this_quick(&namespace_name, this_ptr, SL("_namespaceName"), 816833906UL, PH_NOISY_CC); - if (!zend_is_true(namespace_name)) { - PHALCON_OBS_NVAR(namespace_name); - phalcon_read_property_this_quick(&namespace_name, this_ptr, SL("_defaultNamespace"), 761145590UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC); - } + PHALCON_INIT_VAR(is_internal); + phalcon_call_method_key(is_internal, class_reflection, "isinternal", 2412550174UL); + if (zend_is_true(is_internal)) { + PHALCON_INIT_VAR(lower_class_name); + phalcon_fast_strtolower(lower_class_name, class_name); - PHALCON_OBS_NVAR(handler_name); - phalcon_read_property_this_quick(&handler_name, this_ptr, SL("_handlerName"), 2743819555UL, PH_NOISY_CC); - if (!zend_is_true(handler_name)) { - PHALCON_OBS_NVAR(handler_name); - phalcon_read_property_this_quick(&handler_name, this_ptr, SL("_defaultHandler"), 2940762855UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), handler_name, 2743819555UL TSRMLS_CC); - } + PHALCON_INIT_VAR(prepare_internal_class); + phalcon_fast_str_replace(prepare_internal_class, underscore, minus, lower_class_name); - PHALCON_OBS_NVAR(action_name); - phalcon_read_property_this_quick(&action_name, this_ptr, SL("_actionName"), 2975797059UL, PH_NOISY_CC); - if (!zend_is_true(action_name)) { - PHALCON_OBS_NVAR(action_name); - phalcon_read_property_this_quick(&action_name, this_ptr, SL("_defaultAction"), 895696999UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_actionName"), action_name, 2975797059UL TSRMLS_CC); + PHALCON_SCONCAT_SVSVS(html, "", class_name, ""); + } else { + PHALCON_SCONCAT_SVS(html, "", class_name, ""); + } } - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "dispatch:beforeDispatch", 1); + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, trace, SS("type"), 276192743UL, PH_NOISY); + phalcon_concat_self(&html, type TSRMLS_CC); + } - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - continue; - } + if (phalcon_array_isset_quick_string(trace, SS("class"), 4138154555UL)) { + PHALCON_OBS_VAR(function_name); + phalcon_array_fetch_quick_string(&function_name, trace, SS("function"), 1487618475UL, PH_NOISY); + PHALCON_SCONCAT_SVS(html, "", function_name, ""); + } else { + PHALCON_OBS_NVAR(function_name); + phalcon_array_fetch_quick_string(&function_name, trace, SS("function"), 1487618475UL, PH_NOISY); - PHALCON_OBS_NVAR(finished); - phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(finished)) { - continue; + if (phalcon_function_exists(function_name TSRMLS_CC) == SUCCESS) { + ce1 = zend_fetch_class(SL("ReflectionFunction"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + PHALCON_INIT_VAR(function_reflection); + object_init_ex(function_reflection, ce1); + if (phalcon_has_constructor(function_reflection TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, function_reflection, "__construct", function_name, 1107214344UL); } - } - if (!phalcon_memnstr_str(handler_name, SL("\\"))) { - PHALCON_INIT_NVAR(camelized_class); - phalcon_camelize(camelized_class, handler_name); - } else { - PHALCON_CPY_WRT(camelized_class, handler_name); - } + PHALCON_INIT_NVAR(is_internal); + phalcon_call_method_key(is_internal, function_reflection, "isinternal", 2412550174UL); - if (zend_is_true(namespace_name)) { - if (phalcon_end_with_str(namespace_name, SL("\\"))) { - PHALCON_INIT_NVAR(handler_class); - PHALCON_CONCAT_VVV(handler_class, namespace_name, camelized_class, handler_suffix); + if (zend_is_true(is_internal)) { + PHALCON_INIT_VAR(prepared_function_name); + phalcon_fast_str_replace(prepared_function_name, underscore, minus, function_name); + PHALCON_SCONCAT_SVSVS(html, "", function_name, ""); } else { - PHALCON_INIT_NVAR(handler_class); - PHALCON_CONCAT_VSVV(handler_class, namespace_name, "\\", camelized_class, handler_suffix); + PHALCON_SCONCAT_SVS(html, "", function_name, ""); } } else { - PHALCON_INIT_NVAR(handler_class); - PHALCON_CONCAT_VV(handler_class, camelized_class, handler_suffix); - } - - PHALCON_INIT_NVAR(has_service); - phalcon_call_method_p1_key(has_service, dependency_injector, "has", handler_class, 2090320481UL); - if (!zend_is_true(has_service)) { - PHALCON_INIT_NVAR(has_service); - ZVAL_LONG(has_service, phalcon_class_exists(handler_class, 1 TSRMLS_CC)); + PHALCON_SCONCAT_SVS(html, "", function_name, ""); } + } - if (!zend_is_true(has_service)) { - - PHALCON_INIT_NVAR(exception_code); - ZVAL_LONG(exception_code, 2); + if (phalcon_array_isset_quick_string(trace, SS("args"), 253399346UL)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_VS(exception_message, handler_class, " handler class cannot be loaded"); + PHALCON_OBS_VAR(trace_args); + phalcon_array_fetch_quick_string(&trace_args, trace, SS("args"), 253399346UL, PH_NOISY); + if (phalcon_fast_count_ev(trace_args TSRMLS_CC)) { - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); - if (PHALCON_IS_FALSE(status)) { + PHALCON_INIT_VAR(arguments); + array_init(arguments); - PHALCON_OBS_NVAR(finished); - phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(finished)) { - continue; - } - } + phalcon_is_iterable(trace_args, &ah0, &hp0, 0, 0); - break; - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_NVAR(handler); - phalcon_call_method_p1_key(handler, dependency_injector, "getshared", handler_class, 1727570332UL); - if (Z_TYPE_P(handler) != IS_OBJECT) { + PHALCON_GET_HVALUE(argument); - PHALCON_INIT_NVAR(exception_code); - ZVAL_LONG(exception_code, 3); + PHALCON_INIT_NVAR(dumped_argument); + phalcon_call_method_p1_key(dumped_argument, this_ptr, "_getvardump", argument, 2922816643UL); - PHALCON_INIT_NVAR(exception_message); - ZVAL_STRING(exception_message, "Invalid handler returned from the services container", 1); + PHALCON_INIT_NVAR(span_argument); + PHALCON_CONCAT_SVS(span_argument, "", dumped_argument, ""); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); - if (PHALCON_IS_FALSE(status)) { + phalcon_array_append(&arguments, span_argument, PH_SEPARATE); - PHALCON_OBS_NVAR(finished); - phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(finished)) { - continue; - } + zend_hash_move_forward_ex(ah0, &hp0); } - break; + PHALCON_INIT_VAR(joined_arguments); + phalcon_fast_join_str(joined_arguments, SL(", "), arguments TSRMLS_CC); + PHALCON_SCONCAT_SVS(html, "(", joined_arguments, ")"); + } else { + phalcon_concat_self_str(&html, SL("()") TSRMLS_CC); } + } - PHALCON_INIT_NVAR(was_fresh); - phalcon_call_method_key(was_fresh, dependency_injector, "wasfreshinstance", 2047300349UL); - - phalcon_update_property_this_quick(this_ptr, SL("_activeHandler"), handler, 2923197278UL TSRMLS_CC); - - PHALCON_INIT_NVAR(action_method); - PHALCON_CONCAT_VV(action_method, action_name, action_suffix); - if (phalcon_method_exists(handler, action_method TSRMLS_CC) == FAILURE) { - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "dispatch:beforeNotFoundAction", 1); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - continue; - } - - PHALCON_OBS_NVAR(finished); - phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(finished)) { - continue; - } - } - - PHALCON_INIT_NVAR(exception_code); - ZVAL_LONG(exception_code, 5); + if (phalcon_array_isset_quick_string(trace, SS("file"), 259010501UL)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVS(exception_message, "Action '", action_name, "' was not found on handler '", handler_name, "'"); + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); - if (PHALCON_IS_FALSE(status)) { + PHALCON_OBS_VAR(file); + phalcon_array_fetch_quick_string(&file, trace, SS("file"), 259010501UL, PH_NOISY); - PHALCON_OBS_NVAR(finished); - phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(finished)) { - continue; - } - } + PHALCON_OBS_VAR(line); + phalcon_array_fetch_quick_string(&line, trace, SS("line"), 266128205UL, PH_NOISY); - break; - } + PHALCON_SCONCAT_SVSVS(html, "
", file, " (", line, ")
"); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_OBS_VAR(show_files); + phalcon_read_property_this_quick(&show_files, this_ptr, SL("_showFiles"), 1877855960UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "dispatch:beforeExecuteRoute", 1); + if (zend_is_true(show_files)) { - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - continue; - } + PHALCON_INIT_VAR(lines); + phalcon_call_func_p1(lines, "file", file); - PHALCON_OBS_NVAR(finished); - phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(finished)) { - continue; - } - } + PHALCON_INIT_VAR(number_lines); + phalcon_fast_count(number_lines, lines TSRMLS_CC); - if (phalcon_method_quick_exists_ex(handler, SS("beforeexecuteroute"), 3852116986UL TSRMLS_CC) == SUCCESS) { + PHALCON_OBS_VAR(show_file_fragment); + phalcon_read_property_this_quick(&show_file_fragment, this_ptr, SL("_showFileFragment"), 3533221081UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, handler, "beforeexecuteroute", this_ptr, 3852116986UL); - if (PHALCON_IS_FALSE(status)) { - continue; - } + if (zend_is_true(show_file_fragment)) { - PHALCON_OBS_NVAR(finished); - phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(finished)) { - continue; - } - } + PHALCON_INIT_VAR(seven); + ZVAL_LONG(seven, 7); - PHALCON_OBS_NVAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (Z_TYPE_P(params) != IS_ARRAY) { + PHALCON_INIT_VAR(before_line); + sub_function(before_line, line, seven TSRMLS_CC); - PHALCON_INIT_NVAR(exception_code); - ZVAL_LONG(exception_code, 4); + if (PHALCON_LT_LONG(before_line, 1)) { + PHALCON_CPY_WRT(first_line, one); + } else { + PHALCON_CPY_WRT(first_line, before_line); + } - PHALCON_INIT_NVAR(exception_message); - ZVAL_STRING(exception_message, "Action parameters must be an Array", 1); + PHALCON_INIT_VAR(five); + ZVAL_LONG(five, 5); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); - if (PHALCON_IS_FALSE(status)) { + PHALCON_INIT_VAR(after_line); + phalcon_add_function(after_line, line, five TSRMLS_CC); - PHALCON_OBS_NVAR(finished); - phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(finished)) { - continue; + if (PHALCON_GT(after_line, number_lines)) { + PHALCON_CPY_WRT(last_line, number_lines); + } else { + PHALCON_CPY_WRT(last_line, after_line); } - } - - break; - } - if (PHALCON_IS_TRUE(was_fresh)) { - if (phalcon_method_quick_exists_ex(handler, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, handler, "initialize", 2896075127UL); + PHALCON_SCONCAT_SVSVSVS(html, "
");
+			} else {
+				PHALCON_CPY_WRT(first_line, one);
+				PHALCON_CPY_WRT(last_line, number_lines);
+				PHALCON_SCONCAT_SVSVS(html, "
");
 			}
-		}
-	
-		PHALCON_INIT_NVAR(call_object);
-		array_init_size(call_object, 2);
-		phalcon_array_append(&call_object, handler, PH_SEPARATE);
-		phalcon_array_append(&call_object, action_method, PH_SEPARATE);
 	
-		if (Z_TYPE_P(events_manager) == IS_OBJECT) {
+			PHALCON_INIT_VAR(comment_pattern);
+			ZVAL_STRING(comment_pattern, "#\\*\\/$#", 1);
 	
-			PHALCON_INIT_NVAR(value);
-			PHALCON_CALL_USER_FUNC_ARRAY_NOEX(value, call_object, params);
+			PHALCON_INIT_VAR(utf8);
+			ZVAL_STRING(utf8, "UTF-8", 1);
 	
-			if (EG(exception)) {
+			PHALCON_INIT_VAR(ent_compat);
+			ZVAL_LONG(ent_compat, 2);
 	
-				PHALCON_CPY_WRT(exception, EG(exception));
+			PHALCON_INIT_VAR(tab);
+			ZVAL_STRING(tab, "\t", 1);
 	
-				zend_clear_exception(TSRMLS_C);
+			PHALCON_INIT_VAR(comment);
+			ZVAL_STRING(comment, "* /", 1);
+			PHALCON_CPY_WRT(i, first_line);
 	
-				PHALCON_INIT_NVAR(status);
-				phalcon_call_method_p1_key(status, this_ptr, "_handleexception", exception, 2165668191UL);
-				if (PHALCON_IS_FALSE(status)) {
+			while (1) {
 	
-					PHALCON_OBS_NVAR(finished);
-					phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC);
-					if (PHALCON_IS_FALSE(finished)) {
-						continue;
-					}
+				if (PHALCON_LE(i, last_line)) {
 				} else {
-					phalcon_throw_exception(exception TSRMLS_CC);
-					return;
+					break;
 				}
-			} else {
-				phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC);
-			}
-		} else {
-			PHALCON_INIT_NVAR(value);
-			PHALCON_CALL_USER_FUNC_ARRAY(value, call_object, params);
-	
-			phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC);
-		}
 	
-		phalcon_update_property_this_quick(this_ptr, SL("_lastHandler"), handler, 1315517974UL TSRMLS_CC);
+				PHALCON_INIT_NVAR(line_position);
+				sub_function(line_position, i, one TSRMLS_CC);
 	
-		if (Z_TYPE_P(events_manager) == IS_OBJECT) {
+				PHALCON_OBS_NVAR(current_line);
+				phalcon_array_fetch(¤t_line, lines, line_position, PH_NOISY);
 	
-			PHALCON_INIT_NVAR(event_name);
-			ZVAL_STRING(event_name, "dispatch:afterExecuteRoute", 1);
+				if (zend_is_true(show_file_fragment)) {
+					if (PHALCON_IS_EQUAL(i, first_line)) {
 	
-			PHALCON_INIT_NVAR(status);
-			phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, value, 259017035UL);
-			if (PHALCON_IS_FALSE(status)) {
-				continue;
-			}
+						PHALCON_INIT_NVAR(trimmed);
+						phalcon_fast_trim(trimmed, current_line, PHALCON_TRIM_RIGHT TSRMLS_CC);
 	
-			PHALCON_OBS_NVAR(finished);
-			phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC);
-			if (PHALCON_IS_FALSE(finished)) {
-				continue;
-			}
+						PHALCON_INIT_NVAR(is_comment);
 	
-			PHALCON_INIT_NVAR(event_name);
-			ZVAL_STRING(event_name, "dispatch:afterDispatch", 1);
+						phalcon_preg_match(is_comment, comment_pattern, current_line, NULL TSRMLS_CC);
 	
-			phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL);
-		}
+						if (zend_is_true(is_comment)) {
+							PHALCON_INIT_NVAR(spaced_current_line);
+							phalcon_fast_str_replace(spaced_current_line, comment, space, current_line);
+							PHALCON_CPY_WRT(current_line, spaced_current_line);
+						}
+					}
+				}
 	
-		if (phalcon_method_quick_exists_ex(handler, SS("afterexecuteroute"), 2573764025UL TSRMLS_CC) == SUCCESS) {
+				if (PHALCON_IS_STRING(current_line, "\n")) {
+					phalcon_concat_self_str(&html, SL(" \n") TSRMLS_CC);
+				} else {
+					if (PHALCON_IS_STRING(current_line, "\r\n")) {
+						phalcon_concat_self_str(&html, SL(" \n") TSRMLS_CC);
+					} else {
+						PHALCON_INIT_NVAR(spaced_current_line);
+						phalcon_fast_str_replace(spaced_current_line, tab, two_spaces, current_line);
 	
-			PHALCON_INIT_NVAR(status);
-			phalcon_call_method_p2_key(status, handler, "afterexecuteroute", this_ptr, value, 2573764025UL);
-			if (PHALCON_IS_FALSE(status)) {
-				continue;
-			}
+						PHALCON_INIT_NVAR(escaped_line);
+						phalcon_call_func_p3(escaped_line, "htmlentities", spaced_current_line, ent_compat, utf8);
+						phalcon_concat_self(&html, escaped_line TSRMLS_CC);
+					}
+				}
 	
-			PHALCON_OBS_NVAR(finished);
-			phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC);
-			if (PHALCON_IS_FALSE(finished)) {
-				continue;
+				PHALCON_SEPARATE(i);
+				phalcon_increment(i);
 			}
+			phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); } } - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "dispatch:afterDispatchLoop", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); - } + phalcon_concat_self_str(&html, SL("") TSRMLS_CC); - RETURN_CCTOR(handler); + RETURN_CTOR(html); } -static PHP_METHOD(Phalcon_Dispatcher, forward){ +static PHP_METHOD(Phalcon_Debug, onUncaughtException){ - zval *forward, *exception_message, *namespace_name; - zval *controller_name, *task_name, *action_name; - zval *params; + zval *exception, *is_active = NULL, *message = NULL; + zval *class_name, *css_sources, *escaped_message = NULL; + zval *html, *version, *file, *line, *show_back_trace; + zval *data_vars, *trace, *trace_item = NULL, *n = NULL, *html_item = NULL; + zval *_REQUEST, *value = NULL, *key_request = NULL, *_SERVER; + zval *key_server = NULL, *files, *key_file = NULL; + zval *memory, *data_var = NULL, *key_var = NULL, *variable = NULL, *dumped_argument = NULL; + zval *js_sources; + HashTable *ah0, *ah1, *ah2, *ah3, *ah4; + HashPosition hp0, hp1, hp2, hp3, hp4; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &forward); - - if (Z_TYPE_P(forward) != IS_ARRAY) { - PHALCON_INIT_VAR(exception_message); - ZVAL_STRING(exception_message, "Forward parameter must be an Array", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "_throwdispatchexception", exception_message, 3996129271UL); - RETURN_MM_NULL(); - } + phalcon_fetch_params(1, 1, 0, &exception); - if (phalcon_array_isset_quick_string(forward, SS("namespace"), 545490034UL)) { - PHALCON_OBS_VAR(namespace_name); - phalcon_array_fetch_quick_string(&namespace_name, forward, SS("namespace"), 545490034UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC); + if (phalcon_ob_get_level(TSRMLS_C) > 0) { + phalcon_ob_end_clean(TSRMLS_C); } - if (phalcon_array_isset_quick_string(forward, SS("controller"), 2892024105UL)) { - PHALCON_OBS_VAR(controller_name); - phalcon_array_fetch_quick_string(&controller_name, forward, SS("controller"), 2892024105UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), controller_name, 2743819555UL TSRMLS_CC); - } else { - if (phalcon_array_isset_quick_string(forward, SS("task"), 275333720UL)) { - PHALCON_OBS_VAR(task_name); - phalcon_array_fetch_quick_string(&task_name, forward, SS("task"), 275333720UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), task_name, 2743819555UL TSRMLS_CC); - } - } + PHALCON_OBS_VAR(is_active); + phalcon_read_static_property(&is_active, SL("phalcon\\debug"), SL("_isActive") TSRMLS_CC); - if (phalcon_array_isset_quick_string(forward, SS("action"), 502132067UL)) { - PHALCON_OBS_VAR(action_name); - phalcon_array_fetch_quick_string(&action_name, forward, SS("action"), 502132067UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_actionName"), action_name, 2975797059UL TSRMLS_CC); + if (zend_is_true(is_active)) { + PHALCON_INIT_VAR(message); + phalcon_call_method_key(message, exception, "getmessage", 4288675242UL); + zend_print_zval(message, 0); } - if (phalcon_array_isset_quick_string(forward, SS("params"), 2613350281UL)) { - PHALCON_OBS_VAR(params); - phalcon_array_fetch_quick_string(¶ms, forward, SS("params"), 2613350281UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_params"), params, 3223731112UL TSRMLS_CC); - } + PHALCON_INIT_NVAR(is_active); + ZVAL_BOOL(is_active, 1); - phalcon_update_property_bool(this_ptr, SL("_finished"), 0 TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_forwarded"), 1 TSRMLS_CC); + phalcon_update_static_property(SL("phalcon\\debug"), SL("_isActive"), is_active TSRMLS_CC); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Dispatcher, wasForwarded){ - - - RETURN_MEMBER_QUICK(this_ptr, "_forwarded", 1865074274UL); -} - -static PHP_METHOD(Phalcon_Dispatcher, getHandlerClass){ - - zval *handler_suffix, *namespace_name = NULL, *handler_name = NULL; - zval *camelized_class = NULL, *handler_class = NULL; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(handler_suffix); - phalcon_read_property_this_quick(&handler_suffix, this_ptr, SL("_handlerSuffix"), 1659190583UL, PH_NOISY_CC); + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, exception, 0 TSRMLS_CC); - PHALCON_OBS_VAR(namespace_name); - phalcon_read_property_this_quick(&namespace_name, this_ptr, SL("_namespaceName"), 816833906UL, PH_NOISY_CC); - if (!zend_is_true(namespace_name)) { - PHALCON_OBS_NVAR(namespace_name); - phalcon_read_property_this_quick(&namespace_name, this_ptr, SL("_defaultNamespace"), 761145590UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC); - } + PHALCON_INIT_NVAR(message); + phalcon_call_method_key(message, exception, "getmessage", 4288675242UL); - PHALCON_OBS_VAR(handler_name); - phalcon_read_property_this_quick(&handler_name, this_ptr, SL("_handlerName"), 2743819555UL, PH_NOISY_CC); - if (!zend_is_true(handler_name)) { - PHALCON_OBS_NVAR(handler_name); - phalcon_read_property_this_quick(&handler_name, this_ptr, SL("_defaultHandler"), 2940762855UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), handler_name, 2743819555UL TSRMLS_CC); - } + PHALCON_INIT_VAR(css_sources); + phalcon_call_method_key(css_sources, this_ptr, "getcsssources", 3032989842UL); - if (!phalcon_memnstr_str(handler_name, SL("\\"))) { - PHALCON_INIT_VAR(camelized_class); - phalcon_camelize(camelized_class, handler_name); - } else { - PHALCON_CPY_WRT(camelized_class, handler_name); - } + PHALCON_CPY_WRT(escaped_message, message); - if (zend_is_true(namespace_name)) { - if (phalcon_end_with_str(namespace_name, SL("\\"))) { - PHALCON_INIT_VAR(handler_class); - PHALCON_CONCAT_VVV(handler_class, namespace_name, camelized_class, handler_suffix); - } else { - PHALCON_INIT_NVAR(handler_class); - PHALCON_CONCAT_VSVV(handler_class, namespace_name, "\\", camelized_class, handler_suffix); + PHALCON_INIT_VAR(html); + PHALCON_CONCAT_SVSVS(html, "", class_name, ": ", escaped_message, ""); + PHALCON_SCONCAT_VS(html, css_sources, ""); + + PHALCON_INIT_VAR(version); + phalcon_call_method_key(version, this_ptr, "getversion", 1268766507UL); + phalcon_concat_self(&html, version TSRMLS_CC); + + PHALCON_INIT_VAR(file); + phalcon_call_method_key(file, exception, "getfile", 4277240133UL); + + PHALCON_INIT_VAR(line); + phalcon_call_method_key(line, exception, "getline", 4284357837UL); + + phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + PHALCON_SCONCAT_SVSVS(html, "

", class_name, ": ", escaped_message, "

"); + PHALCON_SCONCAT_SVSVS(html, "", file, " (", line, ")"); + phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + + PHALCON_OBS_VAR(show_back_trace); + phalcon_read_property_this_quick(&show_back_trace, this_ptr, SL("_showBackTrace"), 3370024901UL, PH_NOISY_CC); + + if (zend_is_true(show_back_trace)) { + + PHALCON_OBS_VAR(data_vars); + phalcon_read_property_this_quick(&data_vars, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + + phalcon_concat_self_str(&html, SL("
    ") TSRMLS_CC); + phalcon_concat_self_str(&html, SL("
  • Backtrace
  • ") TSRMLS_CC); + phalcon_concat_self_str(&html, SL("
  • Request
  • ") TSRMLS_CC); + phalcon_concat_self_str(&html, SL("
  • Server
  • ") TSRMLS_CC); + phalcon_concat_self_str(&html, SL("
  • Included Files
  • ") TSRMLS_CC); + phalcon_concat_self_str(&html, SL("
  • Memory
  • ") TSRMLS_CC); + if (Z_TYPE_P(data_vars) == IS_ARRAY) { + phalcon_concat_self_str(&html, SL("
  • Variables
  • ") TSRMLS_CC); } - } else { - PHALCON_INIT_NVAR(handler_class); - PHALCON_CONCAT_VV(handler_class, camelized_class, handler_suffix); + + phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + + phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + + PHALCON_INIT_VAR(trace); + phalcon_call_method_key(trace, exception, "gettrace", 4268145556UL); + + phalcon_is_iterable(trace, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(n, ah0, hp0); + PHALCON_GET_HVALUE(trace_item); + + PHALCON_INIT_NVAR(html_item); + phalcon_call_method_p2_key(html_item, this_ptr, "showtraceitem", n, trace_item, 296427812UL); + phalcon_concat_self(&html, html_item TSRMLS_CC); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + + phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + phalcon_concat_self_str(&html, SL("") TSRMLS_CC); + phalcon_get_global(&_REQUEST, SS("_REQUEST") TSRMLS_CC); + + phalcon_is_iterable(_REQUEST, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HKEY(key_request, ah1, hp1); + PHALCON_GET_HVALUE(value); + + PHALCON_SCONCAT_SVSVS(html, ""); + + zend_hash_move_forward_ex(ah1, &hp1); + } + + phalcon_concat_self_str(&html, SL("
KeyValue
", key_request, "", value, "
") TSRMLS_CC); + + phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + phalcon_concat_self_str(&html, SL("") TSRMLS_CC); + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + + phalcon_is_iterable(_SERVER, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HKEY(key_server, ah2, hp2); + PHALCON_GET_HVALUE(value); + + PHALCON_SCONCAT_SVSVS(html, ""); + + zend_hash_move_forward_ex(ah2, &hp2); + } + + phalcon_concat_self_str(&html, SL("
KeyValue
", key_server, "", value, "
") TSRMLS_CC); + + PHALCON_INIT_VAR(files); + phalcon_call_func(files, "get_included_files"); + phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + phalcon_concat_self_str(&html, SL("") TSRMLS_CC); + + phalcon_is_iterable(files, &ah3, &hp3, 0, 0); + + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { + + PHALCON_GET_HKEY(key_file, ah3, hp3); + PHALCON_GET_HVALUE(value); + + PHALCON_SCONCAT_SVSVS(html, ""); + + zend_hash_move_forward_ex(ah3, &hp3); + } + + phalcon_concat_self_str(&html, SL("
#Path
", key_file, "", value, "
") TSRMLS_CC); + + PHALCON_INIT_VAR(memory); + ZVAL_LONG(memory, zend_memory_usage(1 TSRMLS_CC)); + phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + PHALCON_SCONCAT_SVS(html, ""); + phalcon_concat_self_str(&html, SL("
Memory
Usage", memory, "
") TSRMLS_CC); + + if (Z_TYPE_P(data_vars) == IS_ARRAY) { + phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + phalcon_concat_self_str(&html, SL("") TSRMLS_CC); + + phalcon_is_iterable(data_vars, &ah4, &hp4, 0, 0); + + while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { + + PHALCON_GET_HKEY(key_var, ah4, hp4); + PHALCON_GET_HVALUE(data_var); + + PHALCON_OBS_NVAR(variable); + phalcon_array_fetch_long(&variable, data_var, 0, PH_NOISY); + + PHALCON_INIT_NVAR(dumped_argument); + phalcon_call_method_p1_key(dumped_argument, this_ptr, "_getvardump", variable, 2922816643UL); + PHALCON_SCONCAT_SVSVS(html, ""); + + zend_hash_move_forward_ex(ah4, &hp4); + } + + phalcon_concat_self_str(&html, SL("
KeyValue
", key_var, "", dumped_argument, "
") TSRMLS_CC); + } + + phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); } - RETURN_CTOR(handler_class); + PHALCON_INIT_VAR(js_sources); + phalcon_call_method_key(js_sources, this_ptr, "getjssources", 3049944486UL); + PHALCON_SCONCAT_VS(html, js_sources, "
"); + + zend_print_zval(html, 0); + + PHALCON_INIT_NVAR(is_active); + ZVAL_BOOL(is_active, 0); + + phalcon_update_static_property(SL("phalcon\\debug"), SL("_isActive"), is_active TSRMLS_CC); + RETURN_MM_TRUE; } @@ -34452,226 +33587,433 @@ static PHP_METHOD(Phalcon_Dispatcher, getHandlerClass){ +PHALCON_INIT_CLASS(Phalcon_DI_Exception){ -PHALCON_INIT_CLASS(Phalcon_Flash){ - - PHALCON_REGISTER_CLASS(Phalcon, Flash, flash, phalcon_flash_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - zend_declare_property_null(phalcon_flash_ce, SL("_cssClasses"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_flash_ce, SL("_implicitFlush"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_flash_ce, SL("_automaticHtml"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_REGISTER_CLASS_EX(Phalcon\\DI, Exception, di_exception, "phalcon\\exception", NULL, 0); return SUCCESS; } -static PHP_METHOD(Phalcon_Flash, __construct){ - - zval *css_classes = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &css_classes); - - if (!css_classes) { - PHALCON_INIT_VAR(css_classes); - } else { - PHALCON_SEPARATE_PARAM(css_classes); - } - - if (Z_TYPE_P(css_classes) != IS_ARRAY) { - PHALCON_INIT_NVAR(css_classes); - array_init_size(css_classes, 4); - add_assoc_stringl_ex(css_classes, SS("error"), SL("errorMessage"), 1); - add_assoc_stringl_ex(css_classes, SS("notice"), SL("noticeMessage"), 1); - add_assoc_stringl_ex(css_classes, SS("success"), SL("successMessage"), 1); - add_assoc_stringl_ex(css_classes, SS("warning"), SL("warningMessage"), 1); - } - phalcon_update_property_this_quick(this_ptr, SL("_cssClasses"), css_classes, 1944388667UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Flash, setImplicitFlush){ - zval *implicit_flush; - phalcon_fetch_params(0, 1, 0, &implicit_flush); - - phalcon_update_property_this_quick(this_ptr, SL("_implicitFlush"), implicit_flush, 521244897UL TSRMLS_CC); - RETURN_THISW(); -} -static PHP_METHOD(Phalcon_Flash, setAutomaticHtml){ +#ifdef HAVE_CONFIG_H +#endif - zval *automatic_html; - phalcon_fetch_params(0, 1, 0, &automatic_html); - - phalcon_update_property_this_quick(this_ptr, SL("_automaticHtml"), automatic_html, 1414140864UL TSRMLS_CC); - RETURN_THISW(); -} -static PHP_METHOD(Phalcon_Flash, setCssClasses){ - zval *css_classes; - phalcon_fetch_params(0, 1, 0, &css_classes); - - if (Z_TYPE_P(css_classes) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_cssClasses"), css_classes, 1944388667UL TSRMLS_CC); - RETURN_THISW(); - } - PHALCON_THROW_EXCEPTION_STRW(phalcon_flash_exception_ce, "CSS classes must be an Array"); - return; -} -static PHP_METHOD(Phalcon_Flash, error){ - zval *message, *type; +PHALCON_INIT_CLASS(Phalcon_DI_FactoryDefault_CLI){ - PHALCON_MM_GROW(); + PHALCON_REGISTER_CLASS_EX(Phalcon\\DI\\FactoryDefault, CLI, di_factorydefault_cli, "phalcon\\di\\factorydefault", phalcon_di_factorydefault_cli_method_entry, 0); - phalcon_fetch_params(1, 1, 0, &message); - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "error", 1); - phalcon_call_method_p2_key(return_value, this_ptr, "message", type, message, 2265848874UL); - RETURN_MM(); + return SUCCESS; } -static PHP_METHOD(Phalcon_Flash, notice){ +static PHP_METHOD(Phalcon_DI_FactoryDefault_CLI, __construct){ - zval *message, *type; + zval *shared, *name = NULL, *definition = NULL, *router, *dispatcher; + zval *models_manager, *models_metadata, *filter; + zval *escaper, *annotations, *security, *events_manager; + zval *transaction_manager, *services; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + PHALCON_CALL_PARENT_NORETURN(this_ptr, "Phalcon\\DI\\FactoryDefault\\CLI", "__construct"); - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "notice", 1); - phalcon_call_method_p2_key(return_value, this_ptr, "message", type, message, 2265848874UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Flash, success){ - - zval *message, *type; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &message); + PHALCON_INIT_VAR(shared); + ZVAL_BOOL(shared, 1); - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "success", 1); - phalcon_call_method_p2_key(return_value, this_ptr, "message", type, message, 2265848874UL); - RETURN_MM(); + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "router", 1); + + PHALCON_INIT_VAR(definition); + ZVAL_STRING(definition, "Phalcon\\CLI\\Router", 1); + + PHALCON_INIT_VAR(router); + object_init_ex(router, phalcon_di_service_ce); + phalcon_call_method_p2_key(NULL, router, "__construct", name, definition, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "dispatcher", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\CLI\\Dispatcher", 1); + + PHALCON_INIT_VAR(dispatcher); + object_init_ex(dispatcher, phalcon_di_service_ce); + phalcon_call_method_p2_key(NULL, dispatcher, "__construct", name, definition, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "modelsManager", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Manager", 1); + + PHALCON_INIT_VAR(models_manager); + object_init_ex(models_manager, phalcon_di_service_ce); + phalcon_call_method_p2_key(NULL, models_manager, "__construct", name, definition, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "modelsMetadata", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Metadata\\Memory", 1); + + PHALCON_INIT_VAR(models_metadata); + object_init_ex(models_metadata, phalcon_di_service_ce); + phalcon_call_method_p2_key(NULL, models_metadata, "__construct", name, definition, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "filter", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Filter", 1); + + PHALCON_INIT_VAR(filter); + object_init_ex(filter, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, filter, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "escaper", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Escaper", 1); + + PHALCON_INIT_VAR(escaper); + object_init_ex(escaper, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, escaper, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "annotations", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Annotations\\Adapter\\Memory", 1); + + PHALCON_INIT_VAR(annotations); + object_init_ex(annotations, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, annotations, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "security", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Security", 1); + + PHALCON_INIT_VAR(security); + object_init_ex(security, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, security, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "eventsManager", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Events\\Manager", 1); + + PHALCON_INIT_VAR(events_manager); + object_init_ex(events_manager, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, events_manager, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Transaction\\Manager", 1); + + PHALCON_INIT_VAR(transaction_manager); + object_init_ex(transaction_manager, phalcon_di_service_ce); + phalcon_call_method_p2_key(NULL, transaction_manager, "__construct", name, definition, 1107214344UL); + + PHALCON_INIT_VAR(services); + array_init_size(services, 10); + phalcon_array_update_quick_string(&services, SS("router"), 1453446246UL, &router, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("dispatcher"), 2638982508UL, &dispatcher, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("modelsManager"), 3091111524UL, &models_manager, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("modelsMetadata"), 1052689642UL, &models_metadata, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("filter"), 2890214155UL, &filter, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("escaper"), 874428264UL, &escaper, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("annotations"), 3222607251UL, &annotations, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("security"), 1509414237UL, &security, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("eventsManager"), 190863765UL, &events_manager, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("transactionManager"), 2946122822UL, &transaction_manager, PH_COPY | PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_services"), services, 2714588616UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Flash, warning){ - - zval *message, *type; - - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "warning", 1); - phalcon_call_method_p2_key(return_value, this_ptr, "message", type, message, 2265848874UL); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Flash, outputMessage){ - zval *type, *message, *automatic_html, *classes; - zval *type_classes, *joined_classes, *css_classes = NULL; - zval *implicit_flush, *content, *msg = NULL, *html_message = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - int flag_automatic_html; - int flag_implicit_flush; - PHALCON_MM_GROW(); +#ifdef HAVE_CONFIG_H +#endif - phalcon_fetch_params(1, 2, 0, &type, &message); - PHALCON_OBS_VAR(automatic_html); - phalcon_read_property_this_quick(&automatic_html, this_ptr, SL("_automaticHtml"), 1414140864UL, PH_NOISY_CC); - flag_automatic_html = PHALCON_IS_TRUE(automatic_html) ? 1 : 0; - if (flag_automatic_html) { - PHALCON_OBS_VAR(classes); - phalcon_read_property_this_quick(&classes, this_ptr, SL("_cssClasses"), 1944388667UL, PH_NOISY_CC); - if (phalcon_array_isset(classes, type)) { - PHALCON_OBS_VAR(type_classes); - phalcon_array_fetch(&type_classes, classes, type, PH_NOISY); - if (Z_TYPE_P(type_classes) == IS_ARRAY) { - PHALCON_INIT_VAR(joined_classes); - phalcon_fast_join_str(joined_classes, SL(" "), type_classes TSRMLS_CC); - PHALCON_INIT_VAR(css_classes); - PHALCON_CONCAT_SVS(css_classes, " class=\"", joined_classes, "\""); - } else { - PHALCON_INIT_NVAR(css_classes); - PHALCON_CONCAT_SVS(css_classes, " class=\"", type_classes, "\""); - } - } else { - PHALCON_INIT_NVAR(css_classes); - ZVAL_STRING(css_classes, "", 1); - } - } - PHALCON_OBS_VAR(implicit_flush); - phalcon_read_property_this_quick(&implicit_flush, this_ptr, SL("_implicitFlush"), 521244897UL, PH_NOISY_CC); - flag_implicit_flush = PHALCON_IS_TRUE(implicit_flush) ? 1 : 0; - if (Z_TYPE_P(message) == IS_ARRAY) { - if (!flag_implicit_flush) { - PHALCON_INIT_VAR(content); - ZVAL_STRING(content, "", 1); - } +PHALCON_INIT_CLASS(Phalcon_DI_FactoryDefault){ - phalcon_is_iterable(message, &ah0, &hp0, 0, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\DI, FactoryDefault, di_factorydefault, "phalcon\\di", phalcon_di_factorydefault_method_entry, 0); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + return SUCCESS; +} - PHALCON_GET_HVALUE(msg); +static PHP_METHOD(Phalcon_DI_FactoryDefault, __construct){ - if (flag_automatic_html) { - PHALCON_INIT_NVAR(html_message); - PHALCON_CONCAT_SVSVS(html_message, "", msg, "
" PHP_EOL); - } else { - PHALCON_CPY_WRT(html_message, msg); - } - if (flag_implicit_flush) { - zend_print_zval(html_message, 0); - } else { - phalcon_concat_self(&content, html_message TSRMLS_CC); - } + zval *shared, *name = NULL, *definition = NULL, *router, *dispatcher; + zval *url, *models_manager, *models_metadata; + zval *response, *cookies, *request, *filter, *escaper; + zval *annotations, *security, *crypt, *flash, *flash_session; + zval *tag, *session, *session_bag, *events_manager; + zval *transaction_manager, *assets, *services; - zend_hash_move_forward_ex(ah0, &hp0); - } - - if (!flag_implicit_flush) { - RETURN_CTOR(content); - } - } else { - if (flag_automatic_html) { - PHALCON_INIT_NVAR(html_message); - PHALCON_CONCAT_SVSVS(html_message, "", message, "
" PHP_EOL); - } else { - PHALCON_CPY_WRT(html_message, message); - } - - if (flag_implicit_flush) { - zend_print_zval(html_message, 0); - } else { - RETURN_CCTOR(html_message); - } - } + PHALCON_MM_GROW(); + PHALCON_CALL_PARENT_NORETURN(this_ptr, "Phalcon\\DI\\FactoryDefault", "__construct"); + + PHALCON_INIT_VAR(shared); + ZVAL_BOOL(shared, 1); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "router", 1); + + PHALCON_INIT_VAR(definition); + ZVAL_STRING(definition, "Phalcon\\Mvc\\Router", 1); + + PHALCON_INIT_VAR(router); + object_init_ex(router, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, router, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "dispatcher", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Mvc\\Dispatcher", 1); + + PHALCON_INIT_VAR(dispatcher); + object_init_ex(dispatcher, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, dispatcher, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "url", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Mvc\\Url", 1); + + PHALCON_INIT_VAR(url); + object_init_ex(url, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, url, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "modelsManager", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Manager", 1); + + PHALCON_INIT_VAR(models_manager); + object_init_ex(models_manager, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, models_manager, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "modelsMetadata", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\MetaData\\Memory", 1); + + PHALCON_INIT_VAR(models_metadata); + object_init_ex(models_metadata, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, models_metadata, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "response", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Http\\Response", 1); + + PHALCON_INIT_VAR(response); + object_init_ex(response, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, response, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "cookies", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Http\\Response\\Cookies", 1); + + PHALCON_INIT_VAR(cookies); + object_init_ex(cookies, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, cookies, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "request", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Http\\Request", 1); + + PHALCON_INIT_VAR(request); + object_init_ex(request, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, request, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "filter", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Filter", 1); + + PHALCON_INIT_VAR(filter); + object_init_ex(filter, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, filter, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "escaper", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Escaper", 1); + + PHALCON_INIT_VAR(escaper); + object_init_ex(escaper, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, escaper, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "annotations", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Annotations\\Adapter\\Memory", 1); + + PHALCON_INIT_VAR(annotations); + object_init_ex(annotations, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, annotations, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "security", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Security", 1); + + PHALCON_INIT_VAR(security); + object_init_ex(security, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, security, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "crypt", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Crypt", 1); + + PHALCON_INIT_VAR(crypt); + object_init_ex(crypt, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, crypt, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "flash", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Flash\\Direct", 1); + + PHALCON_INIT_VAR(flash); + object_init_ex(flash, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, flash, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "flashSession", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Flash\\Session", 1); + + PHALCON_INIT_VAR(flash_session); + object_init_ex(flash_session, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, flash_session, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "tag", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Tag", 1); + + PHALCON_INIT_VAR(tag); + object_init_ex(tag, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, tag, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "session", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Session\\Adapter\\Files", 1); + + PHALCON_INIT_VAR(session); + object_init_ex(session, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, session, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "sessionBag", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Session\\Bag", 1); + + PHALCON_INIT_VAR(session_bag); + object_init_ex(session_bag, phalcon_di_service_ce); + phalcon_call_method_p2_key(NULL, session_bag, "__construct", name, definition, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "eventsManager", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Events\\Manager", 1); + + PHALCON_INIT_VAR(events_manager); + object_init_ex(events_manager, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, events_manager, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "transactions", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Mvc\\Model\\Transaction\\Manager", 1); + + PHALCON_INIT_VAR(transaction_manager); + object_init_ex(transaction_manager, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, transaction_manager, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_NVAR(name); + ZVAL_STRING(name, "assets", 1); + + PHALCON_INIT_NVAR(definition); + ZVAL_STRING(definition, "Phalcon\\Assets\\Manager", 1); + + PHALCON_INIT_VAR(assets); + object_init_ex(assets, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, assets, "__construct", name, definition, shared, 1107214344UL); + + PHALCON_INIT_VAR(services); + array_init_size(services, 21); + phalcon_array_update_quick_string(&services, SS("router"), 1453446246UL, &router, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("dispatcher"), 2638982508UL, &dispatcher, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("url"), 2090805944UL, &url, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("modelsManager"), 3091111524UL, &models_manager, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("modelsMetadata"), 1052689642UL, &models_metadata, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("response"), 2839663316UL, &response, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("cookies"), 1147216050UL, &cookies, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("request"), 533957326UL, &request, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("filter"), 2890214155UL, &filter, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("escaper"), 874428264UL, &escaper, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("security"), 1509414237UL, &security, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("crypt"), 4146129335UL, &crypt, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("annotations"), 3222607251UL, &annotations, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("flash"), 4255560371UL, &flash, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("flashSession"), 1805780183UL, &flash_session, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("tag"), 2090751329UL, &tag, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("session"), 278765481UL, &session, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("sessionBag"), 2133837299UL, &session_bag, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("eventsManager"), 190863765UL, &events_manager, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("transactionManager"), 2946122822UL, &transaction_manager, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&services, SS("assets"), 1126974296UL, &assets, PH_COPY | PH_SEPARATE); + + phalcon_update_property_this_quick(this_ptr, SL("_services"), services, 2714588616UL TSRMLS_CC); + PHALCON_MM_RESTORE(); } @@ -34688,40 +34030,49 @@ static PHP_METHOD(Phalcon_Flash, outputMessage){ -PHALCON_INIT_CLASS(Phalcon_Loader){ +PHALCON_INIT_CLASS(Phalcon_DI_Injectable){ - PHALCON_REGISTER_CLASS(Phalcon, Loader, loader, phalcon_loader_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\DI, Injectable, di_injectable, phalcon_di_injectable_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - zend_declare_property_null(phalcon_loader_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_loader_ce, SL("_foundPath"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_loader_ce, SL("_checkedPath"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_loader_ce, SL("_prefixes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_loader_ce, SL("_classes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_loader_ce, SL("_extensions"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_loader_ce, SL("_namespaces"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_loader_ce, SL("_directories"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_loader_ce, SL("_registered"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_di_injectable_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_di_injectable_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_loader_ce TSRMLS_CC, 1, phalcon_events_eventsawareinterface_ce); + zend_class_implements(phalcon_di_injectable_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_events_eventsawareinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Loader, __construct){ +static PHP_METHOD(Phalcon_DI_Injectable, setDI){ - zval *extensions; + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "Dependency Injector is invalid"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_DI_Injectable, getDI){ + + zval *dependency_injector = NULL; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(extensions); - array_init_size(extensions, 1); - add_next_index_stringl(extensions, SL("php"), 1); - phalcon_update_property_this_quick(this_ptr, SL("_extensions"), extensions, 726159316UL TSRMLS_CC); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_NVAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + } - PHALCON_MM_RESTORE(); + RETURN_CCTOR(dependency_injector); } -static PHP_METHOD(Phalcon_Loader, setEventsManager){ +static PHP_METHOD(Phalcon_DI_Injectable, setEventsManager){ zval *events_manager; @@ -34731,515 +34082,433 @@ static PHP_METHOD(Phalcon_Loader, setEventsManager){ } -static PHP_METHOD(Phalcon_Loader, getEventsManager){ +static PHP_METHOD(Phalcon_DI_Injectable, getEventsManager){ RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); } -static PHP_METHOD(Phalcon_Loader, setExtensions){ - - zval *extensions; +static PHP_METHOD(Phalcon_DI_Injectable, __get){ - phalcon_fetch_params(0, 1, 0, &extensions); - - if (Z_TYPE_P(extensions) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_loader_exception_ce, "Parameter extensions must be an array"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_extensions"), extensions, 726159316UL TSRMLS_CC); - - RETURN_THISW(); -} -static PHP_METHOD(Phalcon_Loader, getExtensions){ + zval *property_name, *dependency_injector = NULL; + zval *has_service, *service = NULL, *class_name, *arguments; + zval *persistent; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_extensions", 726159316UL); -} + phalcon_fetch_params(1, 1, 0, &property_name); -static PHP_METHOD(Phalcon_Loader, registerNamespaces){ + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - zval *namespaces, *merge = NULL, *current_namespaces; - zval *merged_namespaces = NULL; + PHALCON_INIT_NVAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - PHALCON_MM_GROW(); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "A dependency injection object is required to access the application services"); + return; + } + } - phalcon_fetch_params(1, 1, 1, &namespaces, &merge); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); + PHALCON_INIT_VAR(has_service); + phalcon_call_method_p1_key(has_service, dependency_injector, "has", property_name, 2090320481UL); + if (zend_is_true(has_service)) { + PHALCON_INIT_VAR(service); + phalcon_call_method_p1_key(service, dependency_injector, "getshared", property_name, 1727570332UL); + phalcon_update_property_zval_zval(this_ptr, property_name, service TSRMLS_CC); + RETURN_CCTOR(service); } - - if (Z_TYPE_P(namespaces) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter namespaces must be an array"); - return; + + if (PHALCON_IS_STRING(property_name, "di")) { + phalcon_update_property_this_quick(this_ptr, SL("di"), dependency_injector, 193489362UL TSRMLS_CC); + RETURN_CCTOR(dependency_injector); } - if (zend_is_true(merge)) { - - PHALCON_OBS_VAR(current_namespaces); - phalcon_read_property_this_quick(¤t_namespaces, this_ptr, SL("_namespaces"), 3363620132UL, PH_NOISY_CC); - if (Z_TYPE_P(current_namespaces) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_namespaces); - phalcon_fast_array_merge(merged_namespaces, ¤t_namespaces, &namespaces TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_namespaces, namespaces); - } - - phalcon_update_property_this_quick(this_ptr, SL("_namespaces"), merged_namespaces, 3363620132UL TSRMLS_CC); - } else { - phalcon_update_property_this_quick(this_ptr, SL("_namespaces"), namespaces, 3363620132UL TSRMLS_CC); + + if (PHALCON_IS_STRING(property_name, "persistent")) { + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); + + PHALCON_INIT_VAR(arguments); + array_init_size(arguments, 1); + phalcon_array_append(&arguments, class_name, PH_SEPARATE); + + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "sessionBag", 1); + + PHALCON_INIT_VAR(persistent); + phalcon_call_method_p2_key(persistent, dependency_injector, "get", service, arguments, 2090288933UL); + phalcon_update_property_this_quick(this_ptr, SL("persistent"), persistent, 2222052598UL TSRMLS_CC); + RETURN_CCTOR(persistent); } - - RETURN_THIS(); + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Access to undefined property %s", Z_STRVAL_P(property_name)); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Loader, getNamespaces){ - RETURN_MEMBER_QUICK(this_ptr, "_namespaces", 3363620132UL); -} -static PHP_METHOD(Phalcon_Loader, registerPrefixes){ - zval *prefixes, *merge = NULL, *current_prefixes, *merged_prefixes = NULL; +#ifdef HAVE_CONFIG_H +#endif - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &prefixes, &merge); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } - - if (Z_TYPE_P(prefixes) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter prefixes must be an array"); - return; - } - if (zend_is_true(merge)) { - - PHALCON_OBS_VAR(current_prefixes); - phalcon_read_property_this_quick(¤t_prefixes, this_ptr, SL("_prefixes"), 900970058UL, PH_NOISY_CC); - if (Z_TYPE_P(current_prefixes) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_prefixes); - phalcon_fast_array_merge(merged_prefixes, ¤t_prefixes, &prefixes TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_prefixes, prefixes); - } - - phalcon_update_property_this_quick(this_ptr, SL("_prefixes"), merged_prefixes, 900970058UL TSRMLS_CC); - } else { - phalcon_update_property_this_quick(this_ptr, SL("_prefixes"), prefixes, 900970058UL TSRMLS_CC); - } - - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Loader, getPrefixes){ +PHALCON_INIT_CLASS(Phalcon_DI_InjectionAwareInterface){ + PHALCON_REGISTER_INTERFACE(Phalcon\\DI, InjectionAwareInterface, di_injectionawareinterface, phalcon_di_injectionawareinterface_method_entry); - RETURN_MEMBER_QUICK(this_ptr, "_prefixes", 900970058UL); + return SUCCESS; } -static PHP_METHOD(Phalcon_Loader, registerDirs){ - zval *directories, *merge = NULL, *current_directories; - zval *merged_directories = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &directories, &merge); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } - - if (Z_TYPE_P(directories) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter directories must be an array"); - return; - } - if (zend_is_true(merge)) { - - PHALCON_OBS_VAR(current_directories); - phalcon_read_property_this_quick(¤t_directories, this_ptr, SL("_directories"), 3207828897UL, PH_NOISY_CC); - if (Z_TYPE_P(current_directories) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_directories); - phalcon_fast_array_merge(merged_directories, ¤t_directories, &directories TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_directories, directories); - } - - phalcon_update_property_this_quick(this_ptr, SL("_directories"), merged_directories, 3207828897UL TSRMLS_CC); - } else { - phalcon_update_property_this_quick(this_ptr, SL("_directories"), directories, 3207828897UL TSRMLS_CC); - } - - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Loader, getDirs){ - RETURN_MEMBER_QUICK(this_ptr, "_directories", 3207828897UL); +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_DI_Service_Builder){ + + PHALCON_REGISTER_CLASS(Phalcon\\DI\\Service, Builder, di_service_builder, phalcon_di_service_builder_method_entry, 0); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Loader, registerClasses){ +static PHP_METHOD(Phalcon_DI_Service_Builder, _buildParameter){ - zval *classes, *merge = NULL, *current_classes, *merged_classes = NULL; + zval *dependency_injector, *position, *argument; + zval *exception_message = NULL, *type, *name = NULL, *value = NULL, *instance_arguments; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &classes, &merge); + phalcon_fetch_params(1, 3, 0, &dependency_injector, &position, &argument); - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); + if (Z_TYPE_P(argument) != IS_ARRAY) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Argument at position ", position, " must be an array"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; } - if (Z_TYPE_P(classes) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter classes must be an array"); + if (!phalcon_array_isset_quick_string(argument, SS("type"), 276192743UL)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Argument at position ", position, " must have a type"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); return; } - if (zend_is_true(merge)) { - PHALCON_OBS_VAR(current_classes); - phalcon_read_property_this_quick(¤t_classes, this_ptr, SL("_classes"), 3992428914UL, PH_NOISY_CC); - if (Z_TYPE_P(current_classes) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_classes); - phalcon_fast_array_merge(merged_classes, ¤t_classes, &classes TSRMLS_CC); + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, argument, SS("type"), 276192743UL, PH_NOISY); + + if (PHALCON_IS_STRING(type, "service")) { + if (!phalcon_array_isset_quick_string(argument, SS("name"), 268211462UL)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Service 'name' is required in parameter on position ", position); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; + } + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The dependency injector container is not valid"); + return; + } + + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, argument, SS("name"), 268211462UL, PH_NOISY); + phalcon_call_method_p1_key(return_value, dependency_injector, "get", name, 2090288933UL); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(type, "parameter")) { + if (!phalcon_array_isset_quick_string(argument, SS("value"), 574111618UL)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Service 'value' is required in parameter on position ", position); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; + } + + PHALCON_OBS_VAR(value); + phalcon_array_fetch_quick_string(&value, argument, SS("value"), 574111618UL, PH_NOISY); + + RETURN_CCTOR(value); + } + + if (PHALCON_IS_STRING(type, "instance")) { + if (!phalcon_array_isset_quick_string(argument, SS("className"), 362439804UL)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Service 'className' is required in parameter on position ", position); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; + } + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The dependency injector container is not valid"); + return; + } + + PHALCON_OBS_NVAR(name); + phalcon_array_fetch_quick_string(&name, argument, SS("className"), 362439804UL, PH_NOISY); + if (!phalcon_array_isset_quick_string(argument, SS("arguments"), 3751272283UL)) { + PHALCON_INIT_NVAR(value); + phalcon_call_method_p1_key(value, dependency_injector, "get", name, 2090288933UL); } else { - PHALCON_CPY_WRT(merged_classes, classes); + PHALCON_OBS_VAR(instance_arguments); + phalcon_array_fetch_quick_string(&instance_arguments, argument, SS("arguments"), 3751272283UL, PH_NOISY); + + phalcon_call_method_p2_key(return_value, dependency_injector, "get", name, instance_arguments, 2090288933UL); + RETURN_MM(); } - phalcon_update_property_this_quick(this_ptr, SL("_classes"), merged_classes, 3992428914UL TSRMLS_CC); - } else { - phalcon_update_property_this_quick(this_ptr, SL("_classes"), classes, 3992428914UL TSRMLS_CC); + RETURN_CCTOR(value); } - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Loader, getClasses){ - - - RETURN_MEMBER_QUICK(this_ptr, "_classes", 3992428914UL); + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Unknown service type in parameter on position ", position); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; } -static PHP_METHOD(Phalcon_Loader, register){ +static PHP_METHOD(Phalcon_DI_Service_Builder, _buildParameters){ - zval *registered, *autoloader; + zval *dependency_injector, *arguments, *build_arguments; + zval *argument = NULL, *position = NULL, *value = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(registered); - phalcon_read_property_this_quick(®istered, this_ptr, SL("_registered"), 3990603890UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(registered)) { - PHALCON_INIT_VAR(autoloader); - array_init_size(autoloader, 2); - phalcon_array_append(&autoloader, this_ptr, PH_SEPARATE); - add_next_index_stringl(autoloader, SL("autoLoad"), 1); - phalcon_call_func_p1_noret("spl_autoload_register", autoloader); - phalcon_update_property_bool(this_ptr, SL("_registered"), 1 TSRMLS_CC); + phalcon_fetch_params(1, 2, 0, &dependency_injector, &arguments); + + if (Z_TYPE_P(arguments) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Definition arguments must be an array"); + return; } - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Loader, unregister){ - - zval *registered, *autoloader; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(registered); - phalcon_read_property_this_quick(®istered, this_ptr, SL("_registered"), 3990603890UL, PH_NOISY_CC); - if (PHALCON_IS_TRUE(registered)) { - PHALCON_INIT_VAR(autoloader); - array_init_size(autoloader, 2); - phalcon_array_append(&autoloader, this_ptr, PH_SEPARATE); - add_next_index_stringl(autoloader, SL("autoLoad"), 1); - phalcon_call_func_p1_noret("spl_autoload_unregister", autoloader); - phalcon_update_property_bool(this_ptr, SL("_registered"), 0 TSRMLS_CC); + PHALCON_INIT_VAR(build_arguments); + array_init(build_arguments); + + phalcon_is_iterable(arguments, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(position, ah0, hp0); + PHALCON_GET_HVALUE(argument); + + PHALCON_INIT_NVAR(value); + phalcon_call_method_p3_key(value, this_ptr, "_buildparameter", dependency_injector, position, argument, 1973645589UL); + phalcon_array_append(&build_arguments, value, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_THIS(); + RETURN_CTOR(build_arguments); } -static PHP_METHOD(Phalcon_Loader, autoLoad){ +static PHP_METHOD(Phalcon_DI_Service_Builder, build){ - zval *class_name, *events_manager, *event_name = NULL; - zval *classes, *file_path = NULL, *extensions, *ds, *namespace_separator; - zval *empty_str, *zero, *namespaces, *directory = NULL; - zval *ns_prefix = NULL, *file_name = NULL, *fixed_directory = NULL; - zval *extension = NULL, *pseudo_separator, *prefixes; - zval *prefix = NULL, *ds_class_name, *ns_class_name; - zval *directories; - HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5; - HashPosition hp0, hp1, hp2, hp3, hp4, hp5; + zval *dependency_injector, *definition, *parameters = NULL; + zval *class_name, *instance = NULL, *arguments = NULL, *build_arguments = NULL; + zval *param_calls = NULL, *method = NULL, *method_position = NULL; + zval *exception_message = NULL, *method_name = NULL, *method_call = NULL; + zval *status = NULL, *property = NULL, *property_position = NULL; + zval *property_name = NULL, *property_value = NULL, *value = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &class_name); + phalcon_fetch_params(1, 2, 1, &dependency_injector, &definition, ¶meters); - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "loader:beforeCheckClass", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, class_name, 259017035UL); + if (!parameters) { + PHALCON_INIT_VAR(parameters); } - PHALCON_OBS_VAR(classes); - phalcon_read_property_this_quick(&classes, this_ptr, SL("_classes"), 3992428914UL, PH_NOISY_CC); - if (Z_TYPE_P(classes) == IS_ARRAY) { - if (phalcon_array_isset(classes, class_name)) { + if (Z_TYPE_P(definition) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service definition must be an array"); + return; + } - PHALCON_OBS_VAR(file_path); - phalcon_array_fetch(&file_path, classes, class_name, PH_NOISY); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC); + if (!phalcon_array_isset_quick_string(definition, SS("className"), 362439804UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Invalid service definition. Missing 'className' parameter"); + return; + } - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "loader:pathFound", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); - } + PHALCON_OBS_VAR(class_name); + phalcon_array_fetch_quick_string(&class_name, definition, SS("className"), 362439804UL, PH_NOISY); + if (Z_TYPE_P(parameters) == IS_ARRAY) { - if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { + if (phalcon_fast_count_ev(parameters TSRMLS_CC)) { + PHALCON_INIT_VAR(instance); + if (phalcon_create_instance_params(instance, class_name, parameters TSRMLS_CC) == FAILURE) { + return; + } + } else { + PHALCON_INIT_NVAR(instance); + if (phalcon_create_instance(instance, class_name TSRMLS_CC) == FAILURE) { return; } - RETURN_MM_TRUE; } - } - - PHALCON_OBS_VAR(extensions); - phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(ds); - ZVAL_STRING(ds, PHALCON_DIRECTORY_SEPARATOR, 1); - - PHALCON_INIT_VAR(namespace_separator); - ZVAL_STRING(namespace_separator, "\\", 1); - - PHALCON_INIT_VAR(empty_str); - ZVAL_STRING(empty_str, "", 1); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - - PHALCON_OBS_VAR(namespaces); - phalcon_read_property_this_quick(&namespaces, this_ptr, SL("_namespaces"), 3363620132UL, PH_NOISY_CC); - if (Z_TYPE_P(namespaces) == IS_ARRAY) { - - phalcon_is_iterable(namespaces, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(ns_prefix, ah0, hp0); - PHALCON_GET_HVALUE(directory); - - if (phalcon_start_with(class_name, ns_prefix, NULL)) { - - PHALCON_INIT_NVAR(file_name); - phalcon_possible_autoload_filepath(file_name, ns_prefix, class_name, ds, NULL TSRMLS_CC); - if (zend_is_true(file_name)) { - - PHALCON_INIT_NVAR(fixed_directory); - phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC); - - phalcon_is_iterable(extensions, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(extension); - - PHALCON_INIT_NVAR(file_path); - PHALCON_CONCAT_VVSV(file_path, fixed_directory, file_name, ".", extension); - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC); - - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "loader:beforeCheckPath", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); - } - - if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) { - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC); - - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "loader:pathFound", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); - } - - if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; - } - - RETURN_MM_TRUE; - } + } else { + if (phalcon_array_isset_quick_string(definition, SS("arguments"), 3751272283UL)) { + PHALCON_OBS_VAR(arguments); + phalcon_array_fetch_quick_string(&arguments, definition, SS("arguments"), 3751272283UL, PH_NOISY); - zend_hash_move_forward_ex(ah1, &hp1); - } + PHALCON_INIT_VAR(build_arguments); + phalcon_call_method_p2_key(build_arguments, this_ptr, "_buildparameters", dependency_injector, arguments, 705798792UL); - } + PHALCON_INIT_NVAR(instance); + if (phalcon_create_instance_params(instance, class_name, build_arguments TSRMLS_CC) == FAILURE) { + return; + } + } else { + PHALCON_INIT_NVAR(instance); + if (phalcon_create_instance(instance, class_name TSRMLS_CC) == FAILURE) { + return; } - - zend_hash_move_forward_ex(ah0, &hp0); } - } - PHALCON_INIT_VAR(pseudo_separator); - ZVAL_STRING(pseudo_separator, "_", 1); - - PHALCON_OBS_VAR(prefixes); - phalcon_read_property_this_quick(&prefixes, this_ptr, SL("_prefixes"), 900970058UL, PH_NOISY_CC); - if (Z_TYPE_P(prefixes) == IS_ARRAY) { - - phalcon_is_iterable(prefixes, &ah2, &hp2, 0, 0); - - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - - PHALCON_GET_HKEY(prefix, ah2, hp2); - PHALCON_GET_HVALUE(directory); - - if (phalcon_start_with(class_name, prefix, NULL)) { - - PHALCON_INIT_NVAR(file_name); - phalcon_possible_autoload_filepath(file_name, prefix, class_name, ds, pseudo_separator TSRMLS_CC); - if (zend_is_true(file_name)) { + if (phalcon_array_isset_quick_string(definition, SS("calls"), 4125497108UL)) { + if (Z_TYPE_P(instance) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The definition has setter injection parameters but the constructor didn't return an instance"); + return; + } - PHALCON_INIT_NVAR(fixed_directory); - phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC); + PHALCON_OBS_VAR(param_calls); + phalcon_array_fetch_quick_string(¶m_calls, definition, SS("calls"), 4125497108UL, PH_NOISY); + if (Z_TYPE_P(param_calls) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Setter injection parameters must be an array"); + return; + } - phalcon_is_iterable(extensions, &ah3, &hp3, 0, 0); + phalcon_is_iterable(param_calls, &ah0, &hp0, 0, 0); - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_GET_HVALUE(extension); + PHALCON_GET_HKEY(method_position, ah0, hp0); + PHALCON_GET_HVALUE(method); - PHALCON_INIT_NVAR(file_path); - PHALCON_CONCAT_VVSV(file_path, fixed_directory, file_name, ".", extension); + if (Z_TYPE_P(method) != IS_ARRAY) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Method call must be an array on position ", method_position); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; + } - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC); + if (!phalcon_array_isset_quick_string(method, SS("method"), 3193080326UL)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "The method name is required on position ", method_position); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; + } - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "loader:beforeCheckPath", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); - } + PHALCON_OBS_NVAR(method_name); + phalcon_array_fetch_quick_string(&method_name, method, SS("method"), 3193080326UL, PH_NOISY); - if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_NVAR(method_call); + array_init_size(method_call, 2); + phalcon_array_append(&method_call, instance, PH_SEPARATE); + phalcon_array_append(&method_call, method_name, PH_SEPARATE); + if (phalcon_array_isset_quick_string(method, SS("arguments"), 3751272283UL)) { - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC); + PHALCON_OBS_NVAR(arguments); + phalcon_array_fetch_quick_string(&arguments, method, SS("arguments"), 3751272283UL, PH_NOISY); + if (Z_TYPE_P(arguments) != IS_ARRAY) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Call arguments must be an array ", method_position); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; + } - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "loader:pathFound", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); - } - if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; - } - RETURN_MM_TRUE; - } + if (phalcon_fast_count_ev(arguments TSRMLS_CC)) { + PHALCON_INIT_NVAR(build_arguments); + phalcon_call_method_p2_key(build_arguments, this_ptr, "_buildparameters", dependency_injector, arguments, 705798792UL); - zend_hash_move_forward_ex(ah3, &hp3); - } + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC_ARRAY(status, method_call, build_arguments); + zend_hash_move_forward_ex(ah0, &hp0); + continue; } } - zend_hash_move_forward_ex(ah2, &hp2); + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC(status, method_call); + + zend_hash_move_forward_ex(ah0, &hp0); } } - PHALCON_INIT_VAR(ds_class_name); - phalcon_fast_str_replace(ds_class_name, pseudo_separator, ds, class_name); - - PHALCON_INIT_VAR(ns_class_name); - phalcon_fast_str_replace(ns_class_name, namespace_separator, ds, ds_class_name); - - PHALCON_OBS_VAR(directories); - phalcon_read_property_this_quick(&directories, this_ptr, SL("_directories"), 3207828897UL, PH_NOISY_CC); - if (Z_TYPE_P(directories) == IS_ARRAY) { - - phalcon_is_iterable(directories, &ah4, &hp4, 0, 0); - - while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { - - PHALCON_GET_HVALUE(directory); - - PHALCON_INIT_NVAR(fixed_directory); - phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC); - - phalcon_is_iterable(extensions, &ah5, &hp5, 0, 0); + if (phalcon_array_isset_quick_string(definition, SS("properties"), 1619284338UL)) { + if (Z_TYPE_P(instance) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The definition has properties injection parameters but the constructor didn't return an instance"); + return; + } - while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { + PHALCON_OBS_NVAR(param_calls); + phalcon_array_fetch_quick_string(¶m_calls, definition, SS("properties"), 1619284338UL, PH_NOISY); + if (Z_TYPE_P(param_calls) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Setter injection parameters must be an array"); + return; + } - PHALCON_GET_HVALUE(extension); + phalcon_is_iterable(param_calls, &ah1, &hp1, 0, 0); - PHALCON_INIT_NVAR(file_path); - PHALCON_CONCAT_VVSV(file_path, fixed_directory, ns_class_name, ".", extension); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC); + PHALCON_GET_HKEY(property_position, ah1, hp1); + PHALCON_GET_HVALUE(property); - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "loader:beforeCheckPath", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); - } + if (Z_TYPE_P(property) != IS_ARRAY) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Property must be an array on position ", property_position); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; + } - if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) { + if (!phalcon_array_isset_quick_string(property, SS("name"), 268211462UL)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "The property name is required on position ", property_position); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; + } - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC); + if (!phalcon_array_isset_quick_string(property, SS("value"), 574111618UL)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "The property value is required on position ", property_position); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; + } - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "loader:pathFound", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); - } + PHALCON_OBS_NVAR(property_name); + phalcon_array_fetch_quick_string(&property_name, property, SS("name"), 268211462UL, PH_NOISY); - if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; - } + PHALCON_OBS_NVAR(property_value); + phalcon_array_fetch_quick_string(&property_value, property, SS("value"), 574111618UL, PH_NOISY); - RETURN_MM_TRUE; - } + PHALCON_INIT_NVAR(value); + phalcon_call_method_p3_key(value, this_ptr, "_buildparameter", dependency_injector, property_position, property_value, 1973645589UL); - zend_hash_move_forward_ex(ah5, &hp5); - } + phalcon_update_property_zval_zval(instance, property_name, value TSRMLS_CC); - zend_hash_move_forward_ex(ah4, &hp4); + zend_hash_move_forward_ex(ah1, &hp1); } } - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "loader:afterCheckClass", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, class_name, 259017035UL); - } - - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Loader, getFoundPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_foundPath", 2210068013UL); -} - -static PHP_METHOD(Phalcon_Loader, getCheckedPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_checkedPath", 2930914648UL); + RETURN_CTOR(instance); } @@ -35254,400 +34523,304 @@ static PHP_METHOD(Phalcon_Loader, getCheckedPath){ -PHALCON_INIT_CLASS(Phalcon_Translate){ - - PHALCON_REGISTER_CLASS(Phalcon, Translate, translate, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - return SUCCESS; -} +PHALCON_INIT_CLASS(Phalcon_DI_Service){ + PHALCON_REGISTER_CLASS(Phalcon\\DI, Service, di_service, phalcon_di_service_method_entry, 0); + zend_declare_property_null(phalcon_di_service_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_di_service_ce, SL("_definition"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_di_service_ce, SL("_shared"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_di_service_ce, SL("_sharedInstance"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_class_implements(phalcon_di_service_ce TSRMLS_CC, 1, phalcon_di_serviceinterface_ce); -#ifdef HAVE_CONFIG_H -#endif + return SUCCESS; +} +static PHP_METHOD(Phalcon_DI_Service, __construct){ + zval *name, *definition, *shared = NULL; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 2, 1, &name, &definition, &shared); + + if (!shared) { + PHALCON_INIT_VAR(shared); + ZVAL_BOOL(shared, 0); + } + + phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_definition"), definition, 2496408365UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_shared"), shared, 3057556539UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} +static PHP_METHOD(Phalcon_DI_Service, getName){ -PHALCON_INIT_CLASS(Phalcon_Validation){ + RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); +} - PHALCON_REGISTER_CLASS_EX(Phalcon, Validation, validation, "phalcon\\di\\injectable", phalcon_validation_method_entry, 0); +static PHP_METHOD(Phalcon_DI_Service, setShared){ - zend_declare_property_null(phalcon_validation_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_validation_ce, SL("_entity"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_validation_ce, SL("_validators"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_validation_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_validation_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_validation_ce, SL("_values"), ZEND_ACC_PROTECTED TSRMLS_CC); + zval *shared; - return SUCCESS; + phalcon_fetch_params(0, 1, 0, &shared); + + phalcon_update_property_this_quick(this_ptr, SL("_shared"), shared, 3057556539UL TSRMLS_CC); + } -static PHP_METHOD(Phalcon_Validation, __construct){ +static PHP_METHOD(Phalcon_DI_Service, isShared){ - zval *validators = NULL; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_shared", 3057556539UL); +} - phalcon_fetch_params(1, 0, 1, &validators); +static PHP_METHOD(Phalcon_DI_Service, setSharedInstance){ + + zval *shared_instance; + + phalcon_fetch_params(0, 1, 0, &shared_instance); - if (!validators) { - PHALCON_INIT_VAR(validators); - } + phalcon_update_property_this_quick(this_ptr, SL("_sharedInstance"), shared_instance, 665278864UL TSRMLS_CC); - if (Z_TYPE_P(validators) != IS_NULL) { - if (Z_TYPE_P(validators) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "Validators must be an array"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_validators"), validators, 2342846045UL TSRMLS_CC); - } +} + +static PHP_METHOD(Phalcon_DI_Service, setDefinition){ + + zval *definition; + + phalcon_fetch_params(0, 1, 0, &definition); - if (phalcon_method_quick_exists_ex(this_ptr, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); - } + phalcon_update_property_this_quick(this_ptr, SL("_definition"), definition, 2496408365UL TSRMLS_CC); - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Validation, validate){ +static PHP_METHOD(Phalcon_DI_Service, getDefinition){ - zval *data = NULL, *entity = NULL, *validators, *messages = NULL, *status = NULL; - zval *cancel_on_fail, *scope = NULL, *attribute = NULL, *validator = NULL; - zval *must_cancel = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + + RETURN_MEMBER_QUICK(this_ptr, "_definition", 2496408365UL); +} + +static PHP_METHOD(Phalcon_DI_Service, resolve){ + + zval *parameters = NULL, *dependency_injector = NULL, *shared; + zval *shared_instance, *found = NULL, *instance = NULL, *definition; + zval *builder, *name, *exception_message; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &data, &entity); - - if (!data) { - PHALCON_INIT_VAR(data); - } + phalcon_fetch_params(1, 0, 2, ¶meters, &dependency_injector); - if (!entity) { - PHALCON_INIT_VAR(entity); + if (!parameters) { + PHALCON_INIT_VAR(parameters); } - PHALCON_OBS_VAR(validators); - phalcon_read_property_this_quick(&validators, this_ptr, SL("_validators"), 2342846045UL, PH_NOISY_CC); - if (Z_TYPE_P(validators) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "There are no validators to validate"); - return; + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); } - phalcon_update_property_null(this_ptr, SL("_values") TSRMLS_CC); - - PHALCON_INIT_VAR(messages); - object_init_ex(messages, phalcon_validation_message_group_ce); - phalcon_call_method_key(NULL, messages, "__construct", 1107214344UL); - - if (phalcon_method_quick_exists_ex(this_ptr, SS("beforevalidation"), 4025473891UL TSRMLS_CC) == SUCCESS) { + PHALCON_OBS_VAR(shared); + phalcon_read_property_this_quick(&shared, this_ptr, SL("_shared"), 3057556539UL, PH_NOISY_CC); - PHALCON_INIT_VAR(status); - phalcon_call_method_p3_key(status, this_ptr, "beforevalidation", data, entity, messages, 4025473891UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_CCTOR(status); - } - } + if (zend_is_true(shared)) { - phalcon_update_property_this_quick(this_ptr, SL("_messages"), messages, 743366684UL TSRMLS_CC); - if (Z_TYPE_P(data) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC); - } else { - if (Z_TYPE_P(data) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC); + PHALCON_OBS_VAR(shared_instance); + phalcon_read_property_this_quick(&shared_instance, this_ptr, SL("_sharedInstance"), 665278864UL, PH_NOISY_CC); + if (Z_TYPE_P(shared_instance) != IS_NULL) { + RETURN_CCTOR(shared_instance); } } - PHALCON_INIT_VAR(cancel_on_fail); - ZVAL_STRING(cancel_on_fail, "cancelOnFail", 1); - - phalcon_is_iterable(validators, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(scope); + PHALCON_INIT_VAR(found); + ZVAL_BOOL(found, 1); - if (Z_TYPE_P(scope) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The validator scope is not valid"); - return; - } + PHALCON_INIT_VAR(instance); - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, scope, 0, PH_NOISY); + PHALCON_OBS_VAR(definition); + phalcon_read_property_this_quick(&definition, this_ptr, SL("_definition"), 2496408365UL, PH_NOISY_CC); + if (Z_TYPE_P(definition) == IS_STRING) { - PHALCON_OBS_NVAR(validator); - phalcon_array_fetch_long(&validator, scope, 1, PH_NOISY); - if (Z_TYPE_P(validator) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "One of the validators is not valid"); - return; + if (phalcon_class_exists(definition, 1 TSRMLS_CC)) { + if (Z_TYPE_P(parameters) == IS_ARRAY) { + if (phalcon_fast_count_ev(parameters TSRMLS_CC)) { + if (phalcon_create_instance_params(instance, definition, parameters TSRMLS_CC) == FAILURE) { + return; + } + } else { + PHALCON_INIT_NVAR(instance); + if (phalcon_create_instance(instance, definition TSRMLS_CC) == FAILURE) { + return; + } + } + } else { + PHALCON_INIT_NVAR(instance); + if (phalcon_create_instance(instance, definition TSRMLS_CC) == FAILURE) { + return; + } + } + } else { + ZVAL_BOOL(found, 0); } + } else { + if (likely(Z_TYPE_P(definition) == IS_OBJECT)) { + if (phalcon_is_instance_of(definition, SL("Closure") TSRMLS_CC)) { + if (Z_TYPE_P(parameters) == IS_ARRAY) { + PHALCON_INIT_NVAR(instance); + PHALCON_CALL_USER_FUNC_ARRAY(instance, definition, parameters); + } else { + PHALCON_INIT_NVAR(instance); + PHALCON_CALL_USER_FUNC(instance, definition); + } + } else { + PHALCON_CPY_WRT(instance, definition); + } + } else { + if (Z_TYPE_P(definition) == IS_ARRAY) { + PHALCON_INIT_VAR(builder); + object_init_ex(builder, phalcon_di_service_builder_ce); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, validator, "validate", this_ptr, attribute, 2654098287UL); - - if (PHALCON_IS_FALSE(status)) { - - PHALCON_INIT_NVAR(must_cancel); - phalcon_call_method_p1_key(must_cancel, validator, "getoption", cancel_on_fail, 1191969182UL); - if (zend_is_true(must_cancel)) { - break; + PHALCON_INIT_NVAR(instance); + phalcon_call_method_p3_key(instance, builder, "build", dependency_injector, definition, parameters, 4109971829UL); + } else { + PHALCON_INIT_NVAR(found); + ZVAL_BOOL(found, 0); } } + } - zend_hash_move_forward_ex(ah0, &hp0); + if (PHALCON_IS_FALSE(found)) { + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Service '", name, "' cannot be resolved"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; } - PHALCON_OBS_NVAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (phalcon_method_quick_exists_ex(this_ptr, SS("aftervalidation"), 1795965282UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_p3_key(NULL, this_ptr, "aftervalidation", data, entity, messages, 1795965282UL); + if (zend_is_true(shared)) { + phalcon_update_property_this_quick(this_ptr, SL("_sharedInstance"), instance, 665278864UL TSRMLS_CC); } - RETURN_CCTOR(messages); + RETURN_CCTOR(instance); } -static PHP_METHOD(Phalcon_Validation, add){ +static PHP_METHOD(Phalcon_DI_Service, setParameter){ - zval *attribute, *validator, *scope; + zval *position, *parameter, *definition, *arguments = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &attribute, &validator); + phalcon_fetch_params(1, 2, 0, &position, ¶meter); - if (Z_TYPE_P(attribute) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The attribute must be a string"); + PHALCON_OBS_VAR(definition); + phalcon_read_property_this_quick(&definition, this_ptr, SL("_definition"), 2496408365UL, PH_NOISY_CC); + if (unlikely(Z_TYPE_P(definition) != IS_ARRAY)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Definition must be an array to update its parameters"); return; } - if (Z_TYPE_P(validator) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The validator must be an object"); + + if (unlikely(Z_TYPE_P(position) != IS_LONG)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Position must be integer"); return; } - PHALCON_INIT_VAR(scope); - array_init_size(scope, 2); - phalcon_array_append(&scope, attribute, PH_SEPARATE); - phalcon_array_append(&scope, validator, PH_SEPARATE); - phalcon_update_property_array_append(this_ptr, SL("_validators"), scope TSRMLS_CC); - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Validation, setFilters){ - - zval *attribute, *filters; - - phalcon_fetch_params(0, 2, 0, &attribute, &filters); - - phalcon_update_property_array(this_ptr, SL("_filters"), attribute, filters TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Validation, getFilters){ - - zval *attribute = NULL, *filters, *attribute_filters; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &attribute); - - if (!attribute) { - PHALCON_INIT_VAR(attribute); + if (unlikely(Z_TYPE_P(parameter) != IS_ARRAY)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The parameter must be an array"); + return; } - PHALCON_OBS_VAR(filters); - phalcon_read_property_this_quick(&filters, this_ptr, SL("_filters"), 3850488637UL, PH_NOISY_CC); - if (Z_TYPE_P(attribute) == IS_STRING) { - if (phalcon_array_isset(filters, attribute)) { - PHALCON_OBS_VAR(attribute_filters); - phalcon_array_fetch(&attribute_filters, filters, attribute, PH_NOISY); - RETURN_CCTOR(attribute_filters); - } - RETURN_MM_NULL(); + if (phalcon_array_isset_quick_string(definition, SS("arguments"), 3751272283UL)) { + PHALCON_OBS_VAR(arguments); + phalcon_array_fetch_quick_string(&arguments, definition, SS("arguments"), 3751272283UL, PH_NOISY); + phalcon_array_update_zval(&arguments, position, ¶meter, PH_COPY | PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(arguments); + array_init_size(arguments, 1); + phalcon_array_update_zval(&arguments, position, ¶meter, PH_COPY | PH_SEPARATE); } - RETURN_CCTOR(filters); -} - -static PHP_METHOD(Phalcon_Validation, getValidators){ - - - RETURN_MEMBER_QUICK(this_ptr, "_validators", 2342846045UL); -} - -static PHP_METHOD(Phalcon_Validation, getEntity){ - - - RETURN_MEMBER_QUICK(this_ptr, "_entity", 2413912609UL); -} - -static PHP_METHOD(Phalcon_Validation, getMessages){ - - - RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); + phalcon_array_update_quick_string(&definition, SS("arguments"), 3751272283UL, &arguments, PH_COPY | PH_SEPARATE); + + phalcon_update_property_this_quick(this_ptr, SL("_definition"), definition, 2496408365UL TSRMLS_CC); + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Validation, appendMessage){ +static PHP_METHOD(Phalcon_DI_Service, getParameter){ - zval *message, *messages; + zval *position, *definition, *arguments, *parameter; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 0, &position); - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - phalcon_call_method_p1_key(NULL, messages, "appendmessage", message, 2313005058UL); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Validation, bind){ - - zval *entity, *data; - - phalcon_fetch_params(0, 2, 0, &entity, &data); + PHALCON_OBS_VAR(definition); + phalcon_read_property_this_quick(&definition, this_ptr, SL("_definition"), 2496408365UL, PH_NOISY_CC); + if (Z_TYPE_P(definition) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Definition must be an array to obtain its parameters"); + return; + } - if (Z_TYPE_P(entity) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "The entity must be an object"); + if (Z_TYPE_P(position) != IS_LONG) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "Position must be integer"); return; } - if (Z_TYPE_P(data) != IS_ARRAY) { - if (Z_TYPE_P(data) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "The data to validate must be an array or object"); - return; + + if (phalcon_array_isset_quick_string(definition, SS("arguments"), 3751272283UL)) { + + PHALCON_OBS_VAR(arguments); + phalcon_array_fetch_quick_string(&arguments, definition, SS("arguments"), 3751272283UL, PH_NOISY); + if (phalcon_array_isset(arguments, position)) { + PHALCON_OBS_VAR(parameter); + phalcon_array_fetch(¶meter, arguments, position, PH_NOISY); + RETURN_CCTOR(parameter); } } - phalcon_update_property_this_quick(this_ptr, SL("_entity"), entity, 2413912609UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC); - - RETURN_THISW(); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Validation, getValue){ +static PHP_METHOD(Phalcon_DI_Service, __set_state){ - zval *attribute, *entity, *method, *value = NULL, *data, *values; - zval *filters, *field_filters, *service_name; - zval *dependency_injector = NULL, *filter_service; + zval *attributes, *name, *definition, *shared; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &attribute); - - PHALCON_OBS_VAR(entity); - phalcon_read_property_this_quick(&entity, this_ptr, SL("_entity"), 2413912609UL, PH_NOISY_CC); - - if (Z_TYPE_P(entity) == IS_OBJECT) { - - PHALCON_INIT_VAR(method); - PHALCON_CONCAT_SV(method, "get", attribute); - if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_VAR(value); - phalcon_call_method_zval(value, entity, method); - } else { - if (phalcon_method_quick_exists_ex(entity, SS("readattribute"), 95450773UL TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_NVAR(value); - phalcon_call_method_key(value, entity, "readattribute", 95450773UL); - } else { - if (phalcon_isset_property_zval(entity, attribute TSRMLS_CC)) { - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, entity, attribute, PH_NOISY_CC); - } else { - PHALCON_INIT_NVAR(value); - } - } - } - - RETURN_CCTOR(value); - } + phalcon_fetch_params(1, 1, 0, &attributes); - PHALCON_OBS_VAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - if (Z_TYPE_P(data) != IS_ARRAY) { - if (Z_TYPE_P(data) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "There is no data to validate"); - return; - } + if (phalcon_array_isset_quick_string(attributes, SS("_name"), 3983977829UL)) { + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, attributes, SS("_name"), 3983977829UL, PH_NOISY); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The attribute '_name' is required"); + return; } - - PHALCON_OBS_VAR(values); - phalcon_read_property_this_quick(&values, this_ptr, SL("_values"), 2376198836UL, PH_NOISY_CC); - if (phalcon_array_isset(values, attribute)) { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, values, attribute, PH_NOISY); - RETURN_CCTOR(value); + if (phalcon_array_isset_quick_string(attributes, SS("_definition"), 2496408365UL)) { + PHALCON_OBS_VAR(definition); + phalcon_array_fetch_quick_string(&definition, attributes, SS("_definition"), 2496408365UL, PH_NOISY); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The attribute '_name' is required"); + return; } - PHALCON_INIT_NVAR(value); - - if (Z_TYPE_P(data) == IS_ARRAY) { - if (phalcon_array_isset(data, attribute)) { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, data, attribute, PH_NOISY); - } + if (phalcon_array_isset_quick_string(attributes, SS("_shared"), 3057556539UL)) { + PHALCON_OBS_VAR(shared); + phalcon_array_fetch_quick_string(&shared, attributes, SS("_shared"), 3057556539UL, PH_NOISY); } else { - if (Z_TYPE_P(data) == IS_OBJECT) { - if (phalcon_isset_property_zval(data, attribute TSRMLS_CC)) { - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, data, attribute, PH_NOISY_CC); - } - } + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The attribute '_shared' is required"); + return; } - if (Z_TYPE_P(value) != IS_NULL) { - - PHALCON_OBS_VAR(filters); - phalcon_read_property_this_quick(&filters, this_ptr, SL("_filters"), 3850488637UL, PH_NOISY_CC); - if (Z_TYPE_P(filters) == IS_ARRAY) { - if (phalcon_array_isset(filters, attribute)) { - - PHALCON_OBS_VAR(field_filters); - phalcon_array_fetch(&field_filters, filters, attribute, PH_NOISY); - if (zend_is_true(field_filters)) { - - PHALCON_INIT_VAR(service_name); - ZVAL_STRING(service_name, "filter", 1); - - PHALCON_INIT_VAR(dependency_injector); - phalcon_call_method_key(dependency_injector, this_ptr, "getdi", 4287060818UL); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "A dependency injector is required to obtain the 'filter' service"); - return; - } - } - - PHALCON_INIT_VAR(filter_service); - phalcon_call_method_p1_key(filter_service, dependency_injector, "getshared", service_name, 1727570332UL); - if (Z_TYPE_P(filter_service) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "Returned 'filter' service is invalid"); - return; - } - - phalcon_call_method_p2_key(return_value, filter_service, "sanitize", value, field_filters, 3688332940UL); - RETURN_MM(); - } - } - } - - phalcon_update_property_array(this_ptr, SL("_values"), attribute, value TSRMLS_CC); - - RETURN_CCTOR(value); - } + object_init_ex(return_value, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, return_value, "__construct", name, definition, shared, 1107214344UL); - RETURN_MM_NULL(); + RETURN_MM(); } @@ -35659,40 +34832,21 @@ static PHP_METHOD(Phalcon_Validation, getValue){ +PHALCON_INIT_CLASS(Phalcon_DI_ServiceInterface){ - - -PHALCON_INIT_CLASS(Phalcon_Config_Adapter_Json){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Config\\Adapter, Json, config_adapter_json, "phalcon\\config", phalcon_config_adapter_json_method_entry, 0); + PHALCON_REGISTER_INTERFACE(Phalcon\\DI, ServiceInterface, di_serviceinterface, phalcon_di_serviceinterface_method_entry); return SUCCESS; } -static PHP_METHOD(Phalcon_Config_Adapter_Json, __construct){ - zval *file_path, *contents, *array; - phalcon_fetch_params(0, 1, 0, &file_path); - ALLOC_INIT_ZVAL(contents); - ALLOC_INIT_ZVAL(array); - phalcon_file_get_contents(contents, file_path TSRMLS_CC); - if (Z_TYPE_P(contents) == IS_STRING) { - phalcon_json_decode(array, contents, 1 TSRMLS_CC); - } - zval_ptr_dtor(&contents); - if (Z_TYPE_P(array) != IS_ARRAY) { - zval_dtor(array); - array_init_size(array, 0); - } - phalcon_config_construct_internal(getThis(), array TSRMLS_CC); - zval_ptr_dtor(&array); -} + @@ -35705,255 +34859,431 @@ static PHP_METHOD(Phalcon_Config_Adapter_Json, __construct){ -static inline void phalcon_config_adapter_ini_update_zval_directive(zval **arr, zval *section, zval *directive, zval **value, int flags TSRMLS_DC) { - zval *temp1 = NULL, *temp2 = NULL, *index = NULL; - int i, n; - n = zend_hash_num_elements(Z_ARRVAL_P(directive)); +PHALCON_INIT_CLASS(Phalcon_DI){ - if (Z_TYPE_PP(arr) == IS_ARRAY) { - phalcon_array_fetch(&temp1, *arr, section, PH_SILENT); - if (Z_REFCOUNT_P(temp1) > 1) { - phalcon_array_update_zval(arr, section, &temp1, PH_COPY | PH_CTOR); - } - if (Z_TYPE_P(temp1) != IS_ARRAY) { - convert_to_array(temp1); - phalcon_array_update_zval(arr, section, &temp1, PH_COPY); - } - - for (i = 0; i < n - 1; i++) { - phalcon_array_fetch_long(&index, directive, i, PH_NOISY); - - phalcon_array_fetch(&temp2, temp1, index, PH_SILENT); - if (Z_REFCOUNT_P(temp2) > 1) { - phalcon_array_update_zval(&temp1, index, &temp2, PH_COPY | PH_CTOR); - } - if (Z_TYPE_P(temp2) != IS_ARRAY) { - convert_to_array(temp2); - phalcon_array_update_zval(&temp1, index, &temp2, PH_COPY); - } - zval_ptr_dtor(&index); - - if (temp1 != NULL) { - zval_ptr_dtor(&temp1); - } - temp1 = temp2; - temp2 = NULL; - } + PHALCON_REGISTER_CLASS(Phalcon, DI, di, phalcon_di_method_entry, 0); - phalcon_array_fetch_long(&index, directive, n - 1, PH_NOISY); - phalcon_array_update_zval(&temp1, index, value, PH_COPY); + zend_declare_property_null(phalcon_di_ce, SL("_services"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_di_ce, SL("_sharedInstances"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_di_ce, SL("_freshInstance"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_di_ce, SL("_default"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zval_ptr_dtor(&index); + zend_class_implements(phalcon_di_ce TSRMLS_CC, 1, phalcon_diinterface_ce); - if (temp1 != NULL) { - zval_ptr_dtor(&temp1); - } - } + return SUCCESS; } -PHALCON_INIT_CLASS(Phalcon_Config_Adapter_Ini){ +static PHP_METHOD(Phalcon_DI, __construct){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Config\\Adapter, Ini, config_adapter_ini, "phalcon\\config", phalcon_config_adapter_ini_method_entry, 0); + zval *default_di; - return SUCCESS; + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(default_di); + phalcon_read_static_property(&default_di, SL("phalcon\\di"), SL("_default") TSRMLS_CC); + if (!zend_is_true(default_di)) { + phalcon_update_static_property(SL("phalcon\\di"), SL("_default"), this_ptr TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct){ +static PHP_METHOD(Phalcon_DI, set){ - zval *file_path, *process_sections, *ini_config; - zval *exception_message, *config, *directives = NULL; - zval *section = NULL, *value = NULL, *key = NULL, *directive_parts = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; + zval *name, *definition, *shared = NULL, *service; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &file_path); - - PHALCON_INIT_VAR(process_sections); - ZVAL_BOOL(process_sections, 1); + phalcon_fetch_params(1, 2, 1, &name, &definition, &shared); - PHALCON_INIT_VAR(ini_config); - phalcon_call_func_p2(ini_config, "parse_ini_file", file_path, process_sections); + if (!shared) { + PHALCON_INIT_VAR(shared); + ZVAL_BOOL(shared, 0); + } - if (PHALCON_IS_FALSE(ini_config)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Configuration file ", file_path, " can't be loaded"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_config_exception_ce, exception_message); + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service name must be a string"); return; } - PHALCON_INIT_VAR(config); - array_init(config); - - phalcon_is_iterable(ini_config, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(section, ah0, hp0); - PHALCON_GET_HVALUE(directives); - - if (unlikely(Z_TYPE_P(directives) != IS_ARRAY)) { - Z_ADDREF_P(directives); - if (phalcon_array_update_zval(&config, section, &directives, 0) != SUCCESS) { - Z_DELREF_P(directives); - } - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - - phalcon_is_iterable(directives, &ah1, &hp1, 0, 0); - - if (zend_hash_num_elements(ah1) == 0) { - Z_ADDREF_P(directives); - phalcon_array_update_zval(&config, section, &directives, 0); - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } + PHALCON_INIT_VAR(service); + object_init_ex(service, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, service, "__construct", name, definition, shared, 1107214344UL); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + phalcon_update_property_array(this_ptr, SL("_services"), name, service TSRMLS_CC); - PHALCON_GET_HKEY(key, ah1, hp1); - PHALCON_GET_HVALUE(value); + RETURN_CTOR(service); +} + +static PHP_METHOD(Phalcon_DI, setShared){ + + zval *name, *definition, *shared, *service; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &name, &definition); - if (phalcon_memnstr_str(key, SL("."))) { - PHALCON_INIT_NVAR(directive_parts); - phalcon_fast_explode_str(directive_parts, SL("."), key); - phalcon_config_adapter_ini_update_zval_directive(&config, section, directive_parts, &value, 0 TSRMLS_CC); - } else { - phalcon_array_update_multi_2(&config, section, key, &value, 0); - } + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service name must be a string"); + return; + } - zend_hash_move_forward_ex(ah1, &hp1); - } + PHALCON_INIT_VAR(shared); + ZVAL_BOOL(shared, 1); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_VAR(service); + object_init_ex(service, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, service, "__construct", name, definition, shared, 1107214344UL); - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Config\\Adapter\\Ini", "__construct", config); + phalcon_update_property_array(this_ptr, SL("_services"), name, service TSRMLS_CC); - PHALCON_MM_RESTORE(); + RETURN_CTOR(service); } +static PHP_METHOD(Phalcon_DI, remove){ + zval *name; - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Config_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Config, Exception, config_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; + phalcon_fetch_params(0, 1, 0, &name); + + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "The service name must be a string"); + return; + } + phalcon_unset_property_array(this_ptr, SL("_services"), name TSRMLS_CC); + } +static PHP_METHOD(Phalcon_DI, attempt){ + zval *name, *definition, *shared = NULL, *services, *service; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Acl_AdapterInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Acl, AdapterInterface, acl_adapterinterface, phalcon_acl_adapterinterface_method_entry); - - return SUCCESS; + phalcon_fetch_params(1, 2, 1, &name, &definition, &shared); + + if (!shared) { + PHALCON_INIT_VAR(shared); + ZVAL_BOOL(shared, 0); + } + + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service name must be a string"); + return; + } + + PHALCON_OBS_VAR(services); + phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); + if (!phalcon_array_isset(services, name)) { + PHALCON_INIT_VAR(service); + object_init_ex(service, phalcon_di_service_ce); + phalcon_call_method_p3_key(NULL, service, "__construct", name, definition, shared, 1107214344UL); + + phalcon_update_property_array(this_ptr, SL("_services"), name, service TSRMLS_CC); + RETURN_CTOR(service); + } + + RETURN_MM_NULL(); } +static PHP_METHOD(Phalcon_DI, setRaw){ + zval *name, *raw_definition; + phalcon_fetch_params(0, 2, 0, &name, &raw_definition); + + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "The service name must be a string"); + return; + } + if (Z_TYPE_P(raw_definition) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "The service definition must be an object"); + return; + } + + phalcon_update_property_array(this_ptr, SL("_services"), name, raw_definition TSRMLS_CC); + + RETURN_CCTORW(raw_definition); +} +static PHP_METHOD(Phalcon_DI, getRaw){ + zval *name, *services, *service, *exception_message; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &name); + + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service name must be a string"); + return; + } + + PHALCON_OBS_VAR(services); + phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); + if (phalcon_array_isset(services, name)) { + PHALCON_OBS_VAR(service); + phalcon_array_fetch(&service, services, name, PH_NOISY); + phalcon_call_method_key(return_value, service, "getdefinition", 1943795982UL); + RETURN_MM(); + } + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Service '", name, "' wasn't found in the dependency injection container"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; +} +static PHP_METHOD(Phalcon_DI, getService){ + zval *name, *services, *service, *exception_message; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &name); + + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service name must be a string"); + return; + } + + PHALCON_OBS_VAR(services); + phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); + if (phalcon_array_isset(services, name)) { + PHALCON_OBS_VAR(service); + phalcon_array_fetch(&service, services, name, PH_NOISY); + RETURN_CCTOR(service); + } + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Service '", name, "' wasn't found in the dependency injection container"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; +} +static PHP_METHOD(Phalcon_DI, get){ + zval *name, *parameters = NULL, *services, *service, *instance = NULL; + zval *exception_message; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 1, &name, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } + + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service alias must be a string"); + return; + } + + PHALCON_OBS_VAR(services); + phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); + if (phalcon_array_isset(services, name)) { + PHALCON_OBS_VAR(service); + phalcon_array_fetch(&service, services, name, PH_NOISY); + + PHALCON_INIT_VAR(instance); + phalcon_call_method_p2_key(instance, service, "resolve", parameters, this_ptr, 605366917UL); + } else { + if (phalcon_class_exists(name, 1 TSRMLS_CC)) { + if (Z_TYPE_P(parameters) == IS_ARRAY) { + if (phalcon_fast_count_ev(parameters TSRMLS_CC)) { + PHALCON_INIT_NVAR(instance); + if (phalcon_create_instance_params(instance, name, parameters TSRMLS_CC) == FAILURE) { + return; + } + } else { + PHALCON_INIT_NVAR(instance); + if (phalcon_create_instance(instance, name TSRMLS_CC) == FAILURE) { + return; + } + } + } else { + PHALCON_INIT_NVAR(instance); + if (phalcon_create_instance(instance, name TSRMLS_CC) == FAILURE) { + return; + } + } + } else { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Service '", name, "' wasn't found in the dependency injection container"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; + } + } + + if (Z_TYPE_P(instance) == IS_OBJECT) { + if (phalcon_method_quick_exists_ex(instance, SS("setdi"), 461718238UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_p1_key(NULL, instance, "setdi", this_ptr, 461718238UL); + } + } + + RETURN_CCTOR(instance); +} +static PHP_METHOD(Phalcon_DI, getShared){ + zval *name, *parameters = NULL, *shared_instances, *instance = NULL; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 1, &name, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } + + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service alias must be a string"); + return; + } + + PHALCON_OBS_VAR(shared_instances); + phalcon_read_property_this_quick(&shared_instances, this_ptr, SL("_sharedInstances"), 479369827UL, PH_NOISY_CC); + if (phalcon_array_isset(shared_instances, name)) { + PHALCON_OBS_VAR(instance); + phalcon_array_fetch(&instance, shared_instances, name, PH_NOISY); + phalcon_update_property_bool(this_ptr, SL("_freshInstance"), 0 TSRMLS_CC); + } else { + PHALCON_INIT_NVAR(instance); + phalcon_call_method_p2_key(instance, this_ptr, "get", name, parameters, 2090288933UL); + + phalcon_update_property_array(this_ptr, SL("_sharedInstances"), name, instance TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_freshInstance"), 1 TSRMLS_CC); + } + + RETURN_CCTOR(instance); +} +static PHP_METHOD(Phalcon_DI, has){ + zval *name, *services, *is_set_service = NULL; + zval *r0 = NULL; -#ifdef HAVE_CONFIG_H -#endif + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &name); + + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service alias must be a string"); + return; + } + + PHALCON_OBS_VAR(services); + phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(r0); + ZVAL_BOOL(r0, phalcon_array_isset(services, name)); + PHALCON_CPY_WRT(is_set_service, r0); + + RETURN_NCTOR(is_set_service); +} +static PHP_METHOD(Phalcon_DI, wasFreshInstance){ + RETURN_MEMBER_QUICK(this_ptr, "_freshInstance", 1734543825UL); +} +static PHP_METHOD(Phalcon_DI, getServices){ -PHALCON_INIT_CLASS(Phalcon_Acl_Resource){ + RETURN_MEMBER_QUICK(this_ptr, "_services", 2714588616UL); +} - PHALCON_REGISTER_CLASS(Phalcon\\Acl, Resource, acl_resource, phalcon_acl_resource_method_entry, 0); - zend_declare_property_null(phalcon_acl_resource_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_acl_resource_ce, SL("_description"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_acl_resource_ce TSRMLS_CC, 1, phalcon_acl_resourceinterface_ce); - return SUCCESS; -} -static PHP_METHOD(Phalcon_Acl_Resource, __construct){ +static PHP_METHOD(Phalcon_DI, __call){ - zval *name, *description = NULL; + zval *method, *arguments = NULL, *services, *service_name = NULL; + zval *possible_service = NULL, *handler, *exception_message; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, &description); + phalcon_fetch_params(1, 1, 1, &method, &arguments); - if (!description) { - PHALCON_INIT_VAR(description); + if (!arguments) { + PHALCON_INIT_VAR(arguments); } - if (PHALCON_IS_STRING(name, "*")) { - PHALCON_THROW_EXCEPTION_STR(phalcon_acl_exception_ce, "Resource name cannot be \"*\""); - return; + if (phalcon_start_with_str(method, SL("get"))) { + + PHALCON_OBS_VAR(services); + phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(service_name); + phalcon_substr(service_name, method, 3, 0); + + PHALCON_INIT_VAR(possible_service); + phalcon_lcfirst(possible_service, service_name); + if (phalcon_array_isset(services, possible_service)) { + if (phalcon_fast_count_ev(arguments TSRMLS_CC)) { + phalcon_call_method_p2_key(return_value, this_ptr, "get", possible_service, arguments, 2090288933UL); + RETURN_MM(); + } + phalcon_call_method_p1_key(return_value, this_ptr, "get", possible_service, 2090288933UL); + RETURN_MM(); + } } - phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); - if (Z_TYPE_P(description) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_description"), description, 1348915240UL TSRMLS_CC); + + if (phalcon_start_with_str(method, SL("set"))) { + if (phalcon_array_isset_long(arguments, 0)) { + PHALCON_INIT_NVAR(service_name); + phalcon_substr(service_name, method, 3, 0); + + PHALCON_INIT_NVAR(possible_service); + phalcon_lcfirst(possible_service, service_name); + + PHALCON_OBS_VAR(handler); + phalcon_array_fetch_long(&handler, arguments, 0, PH_NOISY); + phalcon_call_method_p2_key(NULL, this_ptr, "set", possible_service, handler, 2090720177UL); + RETURN_MM_NULL(); + } } - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Call to undefined method or service '", method, "'"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); + return; } -static PHP_METHOD(Phalcon_Acl_Resource, getName){ +static PHP_METHOD(Phalcon_DI, setDefault){ + zval *dependency_injector; - RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + phalcon_update_static_property(SL("phalcon\\di"), SL("_default"), dependency_injector TSRMLS_CC); + } -static PHP_METHOD(Phalcon_Acl_Resource, getDescription){ +static PHP_METHOD(Phalcon_DI, getDefault){ + zval *default_di; - RETURN_MEMBER_QUICK(this_ptr, "_description", 1348915240UL); + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(default_di); + phalcon_read_static_property(&default_di, SL("phalcon\\di"), SL("_default") TSRMLS_CC); + RETURN_CCTOR(default_di); } -static PHP_METHOD(Phalcon_Acl_Resource, __toString){ +static PHP_METHOD(Phalcon_DI, reset){ + + zval *null_value; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); + PHALCON_INIT_VAR(null_value); + phalcon_update_static_property(SL("phalcon\\di"), SL("_default"), null_value TSRMLS_CC); + + PHALCON_MM_RESTORE(); } @@ -35965,9 +35295,9 @@ static PHP_METHOD(Phalcon_Acl_Resource, __toString){ -PHALCON_INIT_CLASS(Phalcon_Acl_ResourceInterface){ +PHALCON_INIT_CLASS(Phalcon_DiInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Acl, ResourceInterface, acl_resourceinterface, phalcon_acl_resourceinterface_method_entry); + PHALCON_REGISTER_INTERFACE_EX(Phalcon, DiInterface, diinterface, "arrayaccess", phalcon_diinterface_method_entry); return SUCCESS; } @@ -35980,8 +35310,6 @@ PHALCON_INIT_CLASS(Phalcon_Acl_ResourceInterface){ -#ifdef HAVE_CONFIG_H -#endif @@ -35989,90 +35317,77 @@ PHALCON_INIT_CLASS(Phalcon_Acl_ResourceInterface){ -PHALCON_INIT_CLASS(Phalcon_Acl_Role){ - PHALCON_REGISTER_CLASS(Phalcon\\Acl, Role, acl_role, phalcon_acl_role_method_entry, 0); - zend_declare_property_null(phalcon_acl_role_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_acl_role_ce, SL("_description"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_acl_role_ce TSRMLS_CC, 1, phalcon_acl_roleinterface_ce); - return SUCCESS; -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Acl_Role, __construct){ - zval *name, *description = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, &description); - - if (!description) { - PHALCON_INIT_VAR(description); - } - - if (PHALCON_IS_STRING(name, "*")) { - PHALCON_THROW_EXCEPTION_STR(phalcon_acl_exception_ce, "Role name cannot be \"*\""); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); - if (Z_TYPE_P(description) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_description"), description, 1348915240UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Acl_Role, getName){ - RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); -} -static PHP_METHOD(Phalcon_Acl_Role, getDescription){ +PHALCON_INIT_CLASS(Phalcon_Dispatcher){ + PHALCON_REGISTER_CLASS(Phalcon, Dispatcher, dispatcher, phalcon_dispatcher_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - RETURN_MEMBER_QUICK(this_ptr, "_description", 1348915240UL); -} + zend_declare_property_null(phalcon_dispatcher_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_activeHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_finished"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_dispatcher_ce, SL("_forwarded"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_moduleName"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_namespaceName"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_handlerName"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_actionName"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_params"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_returnedValue"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_lastHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_defaultNamespace"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_dispatcher_ce, SL("_defaultHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_dispatcher_ce, SL("_defaultAction"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_dispatcher_ce, SL("_handlerSuffix"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_dispatcher_ce, SL("_actionSuffix"), "Action", ZEND_ACC_PROTECTED TSRMLS_CC); -static PHP_METHOD(Phalcon_Acl_Role, __toString){ + zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_NO_DI"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_CYCLIC_ROUTING"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_HANDLER_NOT_FOUND"), 2 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_INVALID_HANDLER"), 3 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_INVALID_PARAMS"), 4 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_dispatcher_ce, SL("EXCEPTION_ACTION_NOT_FOUND"), 5 TSRMLS_CC); + zend_class_implements(phalcon_dispatcher_ce TSRMLS_CC, 3, phalcon_dispatcherinterface_ce, phalcon_di_injectionawareinterface_ce, phalcon_events_eventsawareinterface_ce); - RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); + return SUCCESS; } +static PHP_METHOD(Phalcon_Dispatcher, __construct){ + phalcon_update_property_empty_array(phalcon_dispatcher_ce, this_ptr, SL("_params") TSRMLS_CC); + +} +static PHP_METHOD(Phalcon_Dispatcher, setDI){ -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Acl_Adapter){ + zval *dependency_injector; - PHALCON_REGISTER_CLASS(Phalcon\\Acl, Adapter, acl_adapter, phalcon_acl_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + +} - zend_declare_property_null(phalcon_acl_adapter_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_acl_adapter_ce, SL("_defaultAccess"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_acl_adapter_ce, SL("_accessGranted"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_acl_adapter_ce, SL("_activeRole"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_acl_adapter_ce, SL("_activeResource"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_acl_adapter_ce, SL("_activeAccess"), ZEND_ACC_PROTECTED TSRMLS_CC); +static PHP_METHOD(Phalcon_Dispatcher, getDI){ - zend_class_implements(phalcon_acl_adapter_ce TSRMLS_CC, 1, phalcon_events_eventsawareinterface_ce); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -static PHP_METHOD(Phalcon_Acl_Adapter, setEventsManager){ +static PHP_METHOD(Phalcon_Dispatcher, setEventsManager){ zval *events_manager; @@ -36082,724 +35397,731 @@ static PHP_METHOD(Phalcon_Acl_Adapter, setEventsManager){ } -static PHP_METHOD(Phalcon_Acl_Adapter, getEventsManager){ +static PHP_METHOD(Phalcon_Dispatcher, getEventsManager){ RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); } -static PHP_METHOD(Phalcon_Acl_Adapter, setDefaultAction){ +static PHP_METHOD(Phalcon_Dispatcher, setActionSuffix){ - zval *default_access; + zval *action_suffix; - phalcon_fetch_params(0, 1, 0, &default_access); + phalcon_fetch_params(0, 1, 0, &action_suffix); - phalcon_update_property_this_quick(this_ptr, SL("_defaultAccess"), default_access, 875397115UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_actionSuffix"), action_suffix, 879621975UL TSRMLS_CC); } -static PHP_METHOD(Phalcon_Acl_Adapter, getDefaultAction){ +static PHP_METHOD(Phalcon_Dispatcher, setModuleName){ + zval *module_name; - RETURN_MEMBER_QUICK(this_ptr, "_defaultAccess", 875397115UL); + phalcon_fetch_params(0, 1, 0, &module_name); + + phalcon_update_property_this_quick(this_ptr, SL("_moduleName"), module_name, 4053279339UL TSRMLS_CC); + } -static PHP_METHOD(Phalcon_Acl_Adapter, getActiveRole){ +static PHP_METHOD(Phalcon_Dispatcher, getModuleName){ - RETURN_MEMBER_QUICK(this_ptr, "_activeRole", 3079165426UL); + RETURN_MEMBER_QUICK(this_ptr, "_moduleName", 4053279339UL); } -static PHP_METHOD(Phalcon_Acl_Adapter, getActiveResource){ +static PHP_METHOD(Phalcon_Dispatcher, setNamespaceName){ + zval *namespace_name; - RETURN_MEMBER_QUICK(this_ptr, "_activeResource", 1323587080UL); + phalcon_fetch_params(0, 1, 0, &namespace_name); + + phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC); + } -static PHP_METHOD(Phalcon_Acl_Adapter, getActiveAccess){ +static PHP_METHOD(Phalcon_Dispatcher, getNamespaceName){ - RETURN_MEMBER_QUICK(this_ptr, "_activeAccess", 2176370066UL); + RETURN_MEMBER_QUICK(this_ptr, "_namespaceName", 816833906UL); } +static PHP_METHOD(Phalcon_Dispatcher, setDefaultNamespace){ + zval *namespace; - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Acl_RoleInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Acl, RoleInterface, acl_roleinterface, phalcon_acl_roleinterface_method_entry); - - return SUCCESS; + phalcon_fetch_params(0, 1, 0, &namespace); + + phalcon_update_property_this_quick(this_ptr, SL("_defaultNamespace"), namespace, 761145590UL TSRMLS_CC); + } +static PHP_METHOD(Phalcon_Dispatcher, getDefaultNamespace){ + RETURN_MEMBER_QUICK(this_ptr, "_defaultNamespace", 761145590UL); +} +static PHP_METHOD(Phalcon_Dispatcher, setDefaultAction){ + zval *action_name; + phalcon_fetch_params(0, 1, 0, &action_name); + + phalcon_update_property_this_quick(this_ptr, SL("_defaultAction"), action_name, 895696999UL TSRMLS_CC); + +} +static PHP_METHOD(Phalcon_Dispatcher, setActionName){ + zval *action_name; -#ifdef HAVE_CONFIG_H -#endif - + phalcon_fetch_params(0, 1, 0, &action_name); + + phalcon_update_property_this_quick(this_ptr, SL("_actionName"), action_name, 2975797059UL TSRMLS_CC); + +} +static PHP_METHOD(Phalcon_Dispatcher, getActionName){ + RETURN_MEMBER_QUICK(this_ptr, "_actionName", 2975797059UL); +} +static PHP_METHOD(Phalcon_Dispatcher, setParams){ + zval *params, *exception_message; -PHALCON_INIT_CLASS(Phalcon_Acl_Adapter_Memory){ + PHALCON_MM_GROW(); - PHALCON_REGISTER_CLASS_EX(Phalcon\\Acl\\Adapter, Memory, acl_adapter_memory, "phalcon\\acl\\adapter", phalcon_acl_adapter_memory_method_entry, 0); + phalcon_fetch_params(1, 1, 0, ¶ms); + + if (Z_TYPE_P(params) != IS_ARRAY) { + PHALCON_INIT_VAR(exception_message); + ZVAL_STRING(exception_message, "Parameters must be an Array", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "_throwdispatchexception", exception_message, 3996129271UL); + RETURN_MM_NULL(); + } + phalcon_update_property_this_quick(this_ptr, SL("_params"), params, 3223731112UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} - zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_rolesNames"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_roles"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_resourcesNames"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_resources"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_access"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_roleInherits"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_acl_adapter_memory_ce, SL("_accessList"), ZEND_ACC_PROTECTED TSRMLS_CC); +static PHP_METHOD(Phalcon_Dispatcher, getParams){ - zend_class_implements(phalcon_acl_adapter_memory_ce TSRMLS_CC, 1, phalcon_acl_adapterinterface_ce); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); } -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, __construct){ - - zval *ztrue, *resources_names, *access_list; +static PHP_METHOD(Phalcon_Dispatcher, setParam){ - PHALCON_MM_GROW(); + zval *param, *value; - PHALCON_INIT_VAR(ztrue); - ZVAL_BOOL(ztrue, 1); - - PHALCON_INIT_VAR(resources_names); - array_init_size(resources_names, 1); - phalcon_array_update_string(&resources_names, SL("*"), &ztrue, PH_COPY | PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_resourcesNames"), resources_names, 2424408563UL TSRMLS_CC); + phalcon_fetch_params(0, 2, 0, ¶m, &value); - PHALCON_INIT_VAR(access_list); - array_init_size(access_list, 1); - phalcon_array_update_string(&access_list, SL("*!*"), &ztrue, PH_COPY | PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_accessList"), access_list, 2206680658UL TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_params"), param, value TSRMLS_CC); - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addRole){ +static PHP_METHOD(Phalcon_Dispatcher, getParam){ - zval *role, *access_inherits = NULL, *role_name = NULL, *object = NULL; - zval *roles_names, *exists, *default_access; - zval *key; + zval *param, *filters = NULL, *default_value = NULL, *params; + zval *param_value, *dependency_injector, *exception_code; + zval *exception_message, *service, *filter; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &role, &access_inherits); + phalcon_fetch_params(1, 1, 2, ¶m, &filters, &default_value); - if (!access_inherits) { - PHALCON_INIT_VAR(access_inherits); + if (!filters) { + PHALCON_INIT_VAR(filters); } - if (Z_TYPE_P(role) == IS_OBJECT) { - PHALCON_INIT_VAR(role_name); - phalcon_call_method_key(role_name, role, "getname", 4286441094UL); - PHALCON_CPY_WRT(object, role); - } else { - PHALCON_CPY_WRT(role_name, role); + if (!default_value) { + PHALCON_INIT_VAR(default_value); + } - PHALCON_INIT_NVAR(object); - object_init_ex(object, phalcon_acl_role_ce); - phalcon_call_method_p1_key(NULL, object, "__construct", role, 1107214344UL); + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset(params, param)) { - } + PHALCON_OBS_VAR(param_value); + phalcon_array_fetch(¶m_value, params, param, PH_NOISY); + if (Z_TYPE_P(filters) != IS_NULL) { - PHALCON_OBS_VAR(roles_names); - phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC); - if (phalcon_array_isset(roles_names, role_name)) { - RETURN_MM_FALSE; - } + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_VAR(exception_code); + ZVAL_LONG(exception_code, 0); - PHALCON_INIT_VAR(exists); - ZVAL_BOOL(exists, 1); - phalcon_update_property_array_append(this_ptr, SL("_roles"), object TSRMLS_CC); - phalcon_update_property_array(this_ptr, SL("_rolesNames"), role_name, exists TSRMLS_CC); + PHALCON_INIT_VAR(exception_message); + ZVAL_STRING(exception_message, "A dependency injection object is required to access the 'filter' service", 1); + phalcon_call_method_p2_key(NULL, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); + } - PHALCON_OBS_VAR(default_access); - phalcon_read_property_this_quick(&default_access, this_ptr, SL("_defaultAccess"), 875397115UL, PH_NOISY_CC); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "filter", 1); - PHALCON_INIT_VAR(key); - PHALCON_CONCAT_VS(key, role_name, "!*!*"); - phalcon_update_property_array(this_ptr, SL("_access"), key, default_access TSRMLS_CC); - if (Z_TYPE_P(access_inherits) != IS_NULL) { - phalcon_call_method_p2_key(return_value, this_ptr, "addinherit", role_name, access_inherits, 2093626145UL); - RETURN_MM(); + PHALCON_INIT_VAR(filter); + phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service, 1727570332UL); + phalcon_call_method_p2_key(return_value, filter, "sanitize", param_value, filters, 3688332940UL); + RETURN_MM(); + } else { + RETURN_CCTOR(param_value); + } } - RETURN_MM_TRUE; + RETURN_CCTOR(default_value); } -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addInherit){ +static PHP_METHOD(Phalcon_Dispatcher, getActiveMethod){ - zval *role_name, *role_to_inherit, *roles_names; - zval *exception_message = NULL, *role_inherit_name = NULL; - zval *roles_inherits, *empty_arr, *_roleInherits; + zval *suffix, *action_name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &role_name, &role_to_inherit); - - PHALCON_OBS_VAR(roles_names); - phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC); - if (!phalcon_array_isset(roles_names, role_name)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Role '", role_name, "' does not exist in the role list"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); - return; - } - - if (Z_TYPE_P(role_to_inherit) == IS_OBJECT) { - PHALCON_INIT_VAR(role_inherit_name); - phalcon_call_method_key(role_inherit_name, role_to_inherit, "getname", 4286441094UL); - } else { - PHALCON_CPY_WRT(role_inherit_name, role_to_inherit); - } - - if (!phalcon_array_isset(roles_names, role_inherit_name)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Role '", role_inherit_name, "' (to inherit) does not exist in the role list"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); - return; - } - - if (PHALCON_IS_EQUAL(role_inherit_name, role_name)) { - RETURN_MM_FALSE; - } - - PHALCON_OBS_VAR(roles_inherits); - phalcon_read_property_this_quick(&roles_inherits, this_ptr, SL("_roleInherits"), 1806479324UL, PH_NOISY_CC); - if (!phalcon_array_isset(roles_inherits, role_name)) { - PHALCON_INIT_VAR(empty_arr); - array_init(empty_arr); - phalcon_update_property_array(this_ptr, SL("_roleInherits"), role_name, empty_arr TSRMLS_CC); - } + PHALCON_OBS_VAR(suffix); + phalcon_read_property_this_quick(&suffix, this_ptr, SL("_actionSuffix"), 879621975UL, PH_NOISY_CC); - PHALCON_OBS_VAR(_roleInherits); - phalcon_read_property_this_quick(&_roleInherits, this_ptr, SL("_roleInherits"), 1806479324UL, PH_NOISY_CC); - phalcon_array_update_append_multi_2(&_roleInherits, role_name, role_inherit_name, 0); - phalcon_update_property_this_quick(this_ptr, SL("_roleInherits"), _roleInherits, 1806479324UL TSRMLS_CC); - RETURN_MM_TRUE; + PHALCON_OBS_VAR(action_name); + phalcon_read_property_this_quick(&action_name, this_ptr, SL("_actionName"), 2975797059UL, PH_NOISY_CC); + PHALCON_CONCAT_VV(return_value, action_name, suffix); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isRole){ - - zval *role_name, *roles_names; +static PHP_METHOD(Phalcon_Dispatcher, isFinished){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &role_name); - - PHALCON_OBS_VAR(roles_names); - phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC); - if (phalcon_array_isset(roles_names, role_name)) { - RETURN_MM_TRUE; - } - - RETURN_MM_FALSE; + RETURN_MEMBER_QUICK(this_ptr, "_finished", 385784334UL); } -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isResource){ - - zval *resource_name, *resources_names; +static PHP_METHOD(Phalcon_Dispatcher, setReturnedValue){ - PHALCON_MM_GROW(); + zval *value; - phalcon_fetch_params(1, 1, 0, &resource_name); + phalcon_fetch_params(0, 1, 0, &value); - PHALCON_OBS_VAR(resources_names); - phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC); - if (phalcon_array_isset(resources_names, resource_name)) { - RETURN_MM_TRUE; - } + phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC); - RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResource){ - - zval *resource, *access_list = NULL, *resource_name = NULL; - zval *object = NULL, *resources_names, *exists; +static PHP_METHOD(Phalcon_Dispatcher, getReturnedValue){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &resource, &access_list); - - if (!access_list) { - PHALCON_INIT_VAR(access_list); - } - - if (Z_TYPE_P(resource) == IS_OBJECT) { - PHALCON_INIT_VAR(resource_name); - phalcon_call_method_key(resource_name, resource, "getname", 4286441094UL); - PHALCON_CPY_WRT(object, resource); - } else { - PHALCON_CPY_WRT(resource_name, resource); - - PHALCON_INIT_NVAR(object); - object_init_ex(object, phalcon_acl_resource_ce); - phalcon_call_method_p1_key(NULL, object, "__construct", resource_name, 1107214344UL); - - } - - PHALCON_OBS_VAR(resources_names); - phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC); - if (!phalcon_array_isset(resources_names, resource_name)) { - PHALCON_INIT_VAR(exists); - ZVAL_BOOL(exists, 1); - phalcon_update_property_array_append(this_ptr, SL("_resources"), object TSRMLS_CC); - phalcon_update_property_array(this_ptr, SL("_resourcesNames"), resource_name, exists TSRMLS_CC); - } - - phalcon_call_method_p2_key(return_value, this_ptr, "addresourceaccess", resource_name, access_list, 3379195048UL); - RETURN_MM(); + RETURN_MEMBER_QUICK(this_ptr, "_returnedValue", 4143876906UL); } -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, addResourceAccess){ +static PHP_METHOD(Phalcon_Dispatcher, dispatch){ - zval *resource_name, *access_list, *resources_names; - zval *exception_message, *exists, *internal_access_list; - zval *access_name = NULL, *access_key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *dependency_injector, *exception_code = NULL; + zval *exception_message = NULL, *events_manager; + zval *event_name = NULL, *status = NULL, *value = NULL, *handler = NULL, *number_dispatches; + zval *handler_suffix, *action_suffix, *finished = NULL; + zval *namespace_name = NULL, *handler_name = NULL, *action_name = NULL; + zval *camelized_class = NULL, *handler_class = NULL, *has_service = NULL; + zval *was_fresh = NULL, *action_method = NULL, *params = NULL, *call_object = NULL; + zval *exception = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &resource_name, &access_list); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_VAR(exception_code); + ZVAL_LONG(exception_code, 0); - PHALCON_OBS_VAR(resources_names); - phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC); - if (!phalcon_array_isset(resources_names, resource_name)) { PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", resource_name, "' does not exist in ACL"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); - return; + ZVAL_STRING(exception_message, "A dependency injection container is required to access related dispatching services", 1); + phalcon_call_method_p2_key(NULL, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); + RETURN_MM_FALSE; } - PHALCON_INIT_VAR(exists); - ZVAL_BOOL(exists, 1); + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_OBS_VAR(internal_access_list); - phalcon_read_property_this_quick(&internal_access_list, this_ptr, SL("_accessList"), 2206680658UL, PH_NOISY_CC); - if (Z_TYPE_P(access_list) == IS_ARRAY) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "dispatch:beforeDispatchLoop", 1); - phalcon_is_iterable(access_list, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(value); - PHALCON_GET_HVALUE(access_name); + PHALCON_INIT_VAR(handler); - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name); - if (!phalcon_array_isset(internal_access_list, access_key)) { - phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, exists TSRMLS_CC); - } + PHALCON_INIT_VAR(number_dispatches); + ZVAL_LONG(number_dispatches, 0); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_OBS_VAR(handler_suffix); + phalcon_read_property_this_quick(&handler_suffix, this_ptr, SL("_handlerSuffix"), 1659190583UL, PH_NOISY_CC); - } else { - if (Z_TYPE_P(access_list) == IS_STRING) { + PHALCON_OBS_VAR(action_suffix); + phalcon_read_property_this_quick(&action_suffix, this_ptr, SL("_actionSuffix"), 879621975UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_list); - if (!phalcon_array_isset(internal_access_list, access_key)) { - phalcon_update_property_array(this_ptr, SL("_accessList"), access_key, exists TSRMLS_CC); - } - } - } + phalcon_update_property_bool(this_ptr, SL("_finished"), 0 TSRMLS_CC); - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, dropResourceAccess){ - - zval *resource_name, *access_list, *access_name = NULL; - zval *access_key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &resource_name, &access_list); + while (1) { - if (Z_TYPE_P(access_list) == IS_ARRAY) { + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (zend_is_true(finished)) { + break; + } - phalcon_is_iterable(access_list, &ah0, &hp0, 0, 0); + PHALCON_SEPARATE(number_dispatches); + phalcon_increment(number_dispatches); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (PHALCON_IS_LONG(number_dispatches, 256)) { + PHALCON_INIT_NVAR(exception_code); + ZVAL_LONG(exception_code, 1); - PHALCON_GET_HVALUE(access_name); + PHALCON_INIT_NVAR(exception_message); + ZVAL_STRING(exception_message, "Dispatcher has detected a cyclic routing causing stability problems", 1); + phalcon_call_method_p2_key(NULL, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); + break; + } - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name); - phalcon_unset_property_array(this_ptr, SL("_accessList"), access_key TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_finished"), 1 TSRMLS_CC); - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_OBS_NVAR(namespace_name); + phalcon_read_property_this_quick(&namespace_name, this_ptr, SL("_namespaceName"), 816833906UL, PH_NOISY_CC); + if (!zend_is_true(namespace_name)) { + PHALCON_OBS_NVAR(namespace_name); + phalcon_read_property_this_quick(&namespace_name, this_ptr, SL("_defaultNamespace"), 761145590UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC); } - } else { - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name); - phalcon_unset_property_array(this_ptr, SL("_accessList"), access_key TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, _allowOrDeny){ - - zval *role_name, *resource_name, *access, *action; - zval *roles_names, *exception_message = NULL, *resources_names; - zval *default_access, *access_list, *internal_access; - zval *access_name = NULL, *access_key = NULL, *access_key_all = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 4, 0, &role_name, &resource_name, &access, &action); - - PHALCON_OBS_VAR(roles_names); - phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC); - if (!phalcon_array_isset(roles_names, role_name)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Role \"", role_name, "\" does not exist in ACL"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); - return; - } - - PHALCON_OBS_VAR(resources_names); - phalcon_read_property_this_quick(&resources_names, this_ptr, SL("_resourcesNames"), 2424408563UL, PH_NOISY_CC); - if (!phalcon_array_isset(resources_names, resource_name)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource \"", resource_name, "\" does not exist in ACL"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); - return; - } + PHALCON_OBS_NVAR(handler_name); + phalcon_read_property_this_quick(&handler_name, this_ptr, SL("_handlerName"), 2743819555UL, PH_NOISY_CC); + if (!zend_is_true(handler_name)) { + PHALCON_OBS_NVAR(handler_name); + phalcon_read_property_this_quick(&handler_name, this_ptr, SL("_defaultHandler"), 2940762855UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), handler_name, 2743819555UL TSRMLS_CC); + } - PHALCON_OBS_VAR(default_access); - phalcon_read_property_this_quick(&default_access, this_ptr, SL("_defaultAccess"), 875397115UL, PH_NOISY_CC); + PHALCON_OBS_NVAR(action_name); + phalcon_read_property_this_quick(&action_name, this_ptr, SL("_actionName"), 2975797059UL, PH_NOISY_CC); + if (!zend_is_true(action_name)) { + PHALCON_OBS_NVAR(action_name); + phalcon_read_property_this_quick(&action_name, this_ptr, SL("_defaultAction"), 895696999UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_actionName"), action_name, 2975797059UL TSRMLS_CC); + } - PHALCON_OBS_VAR(access_list); - phalcon_read_property_this_quick(&access_list, this_ptr, SL("_accessList"), 2206680658UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_OBS_VAR(internal_access); - phalcon_read_property_this_quick(&internal_access, this_ptr, SL("_access"), 1092213014UL, PH_NOISY_CC); - if (Z_TYPE_P(access) == IS_ARRAY) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "dispatch:beforeDispatch", 1); - phalcon_is_iterable(access, &ah0, &hp0, 0, 0); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + continue; + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(finished)) { + continue; + } + } - PHALCON_GET_HVALUE(access_name); + if (!phalcon_memnstr_str(handler_name, SL("\\"))) { + PHALCON_INIT_NVAR(camelized_class); + phalcon_camelize(camelized_class, handler_name); + } else { + PHALCON_CPY_WRT(camelized_class, handler_name); + } - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSV(access_key, resource_name, "!", access_name); - if (!phalcon_array_isset(access_list, access_key)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVS(exception_message, "Acccess '", access_name, "' does not exist in resource '", resource_name, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); - return; + if (zend_is_true(namespace_name)) { + if (phalcon_end_with_str(namespace_name, SL("\\"))) { + PHALCON_INIT_NVAR(handler_class); + PHALCON_CONCAT_VVV(handler_class, namespace_name, camelized_class, handler_suffix); + } else { + PHALCON_INIT_NVAR(handler_class); + PHALCON_CONCAT_VSVV(handler_class, namespace_name, "\\", camelized_class, handler_suffix); } + } else { + PHALCON_INIT_NVAR(handler_class); + PHALCON_CONCAT_VV(handler_class, camelized_class, handler_suffix); + } - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_INIT_NVAR(has_service); + phalcon_call_method_p1_key(has_service, dependency_injector, "has", handler_class, 2090320481UL); + if (!zend_is_true(has_service)) { + PHALCON_INIT_NVAR(has_service); + ZVAL_LONG(has_service, phalcon_class_exists(handler_class, 1 TSRMLS_CC)); } - phalcon_is_iterable(access, &ah1, &hp1, 0, 0); + if (!zend_is_true(has_service)) { - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + PHALCON_INIT_NVAR(exception_code); + ZVAL_LONG(exception_code, 2); - PHALCON_GET_HVALUE(access_name); + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_VS(exception_message, handler_class, " handler class cannot be loaded"); - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSVSV(access_key, role_name, "!", resource_name, "!", access_name); - phalcon_update_property_array(this_ptr, SL("_access"), access_key, action TSRMLS_CC); - if (!PHALCON_IS_STRING(access_name, "*")) { + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); + if (PHALCON_IS_FALSE(status)) { - PHALCON_INIT_NVAR(access_key_all); - PHALCON_CONCAT_VSVS(access_key_all, role_name, "!", resource_name, "!*"); - if (!phalcon_array_isset(internal_access, access_key_all)) { - phalcon_update_property_array(this_ptr, SL("_access"), access_key_all, default_access TSRMLS_CC); + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(finished)) { + continue; } } - zend_hash_move_forward_ex(ah1, &hp1); + break; } - } else { - if (!PHALCON_IS_STRING(access, "*")) { - - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSV(access_key, resource_name, "!", access); - if (!phalcon_array_isset(access_list, access_key)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVS(exception_message, "Acccess '", access, "' does not exist in resource '", resource_name, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_acl_exception_ce, exception_message); - return; - } - } + PHALCON_INIT_NVAR(handler); + phalcon_call_method_p1_key(handler, dependency_injector, "getshared", handler_class, 1727570332UL); + if (Z_TYPE_P(handler) != IS_OBJECT) { - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSVSV(access_key, role_name, "!", resource_name, "!", access); + PHALCON_INIT_NVAR(exception_code); + ZVAL_LONG(exception_code, 3); - phalcon_update_property_array(this_ptr, SL("_access"), access_key, action TSRMLS_CC); - if (!PHALCON_IS_STRING(access, "*")) { + PHALCON_INIT_NVAR(exception_message); + ZVAL_STRING(exception_message, "Invalid handler returned from the services container", 1); - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSVS(access_key, role_name, "!", resource_name, "!*"); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); + if (PHALCON_IS_FALSE(status)) { - if (!phalcon_array_isset(internal_access, access_key)) { - phalcon_update_property_array(this_ptr, SL("_access"), access_key, default_access TSRMLS_CC); + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(finished)) { + continue; + } } + + break; } - } - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, allow){ - - zval *role_name, *resource_name, *access, *action; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &role_name, &resource_name, &access); + PHALCON_INIT_NVAR(was_fresh); + phalcon_call_method_key(was_fresh, dependency_injector, "wasfreshinstance", 2047300349UL); - PHALCON_INIT_VAR(action); - ZVAL_LONG(action, 1); - phalcon_call_method_p4_key(return_value, this_ptr, "_allowordeny", role_name, resource_name, access, action, 726543028UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, deny){ - - zval *role_name, *resource_name, *access, *action; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &role_name, &resource_name, &access); + phalcon_update_property_this_quick(this_ptr, SL("_activeHandler"), handler, 2923197278UL TSRMLS_CC); - PHALCON_INIT_VAR(action); - ZVAL_LONG(action, 0); - phalcon_call_method_p4_key(return_value, this_ptr, "_allowordeny", role_name, resource_name, access, action, 726543028UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, isAllowed){ - - zval *role, *resource, *access, *events_manager; - zval *event_name = NULL, *status, *default_access, *roles_names; - zval *have_access = NULL, *access_list, *access_key = NULL; - zval *role_inherits, *inherited_roles = NULL, *inherited_role = NULL; - HashTable *ah0, *ah1, *ah2; - HashPosition hp0, hp1, hp2; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &role, &resource, &access); + PHALCON_INIT_NVAR(action_method); + PHALCON_CONCAT_VV(action_method, action_name, action_suffix); + if (phalcon_method_exists(handler, action_method TSRMLS_CC) == FAILURE) { - phalcon_update_property_this_quick(this_ptr, SL("_activeRole"), role, 3079165426UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_activeResource"), resource, 1323587080UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_activeAccess"), access, 2176370066UL TSRMLS_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "dispatch:beforeNotFoundAction", 1); - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "acl:beforeCheckAccess", 1); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + continue; + } - PHALCON_INIT_VAR(status); - phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_CCTOR(status); - } - } + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(finished)) { + continue; + } + } - PHALCON_OBS_VAR(default_access); - phalcon_read_property_this_quick(&default_access, this_ptr, SL("_defaultAccess"), 875397115UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(exception_code); + ZVAL_LONG(exception_code, 5); - PHALCON_OBS_VAR(roles_names); - phalcon_read_property_this_quick(&roles_names, this_ptr, SL("_rolesNames"), 1388130141UL, PH_NOISY_CC); - if (!phalcon_array_isset(roles_names, role)) { - RETURN_CCTOR(default_access); - } + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVS(exception_message, "Action '", action_name, "' was not found on handler '", handler_name, "'"); - PHALCON_INIT_VAR(have_access); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); + if (PHALCON_IS_FALSE(status)) { - PHALCON_OBS_VAR(access_list); - phalcon_read_property_this_quick(&access_list, this_ptr, SL("_access"), 1092213014UL, PH_NOISY_CC); + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(finished)) { + continue; + } + } - PHALCON_INIT_VAR(access_key); - PHALCON_CONCAT_VSVSV(access_key, role, "!", resource, "!", access); + break; + } - if (phalcon_array_isset(access_list, access_key)) { - PHALCON_OBS_NVAR(have_access); - phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); - } + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - if (Z_TYPE_P(have_access) == IS_NULL) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "dispatch:beforeExecuteRoute", 1); - PHALCON_OBS_VAR(role_inherits); - phalcon_read_property_this_quick(&role_inherits, this_ptr, SL("_roleInherits"), 1806479324UL, PH_NOISY_CC); - if (phalcon_array_isset(role_inherits, role)) { - PHALCON_OBS_VAR(inherited_roles); - phalcon_array_fetch(&inherited_roles, role_inherits, role, PH_NOISY); - } else { - PHALCON_INIT_NVAR(inherited_roles); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + continue; + } + + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(finished)) { + continue; + } } - if (Z_TYPE_P(inherited_roles) == IS_ARRAY) { + if (phalcon_method_quick_exists_ex(handler, SS("beforeexecuteroute"), 3852116986UL TSRMLS_CC) == SUCCESS) { - phalcon_is_iterable(inherited_roles, &ah0, &hp0, 0, 0); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, handler, "beforeexecuteroute", this_ptr, 3852116986UL); + if (PHALCON_IS_FALSE(status)) { + continue; + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(finished)) { + continue; + } + } - PHALCON_GET_HVALUE(inherited_role); + PHALCON_OBS_NVAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (Z_TYPE_P(params) != IS_ARRAY) { - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSVSV(access_key, inherited_role, "!", resource, "!", access); + PHALCON_INIT_NVAR(exception_code); + ZVAL_LONG(exception_code, 4); - if (phalcon_array_isset(access_list, access_key)) { - PHALCON_OBS_NVAR(have_access); - phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); - break; - } + PHALCON_INIT_NVAR(exception_message); + ZVAL_STRING(exception_message, "Action parameters must be an Array", 1); - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, this_ptr, "_throwdispatchexception", exception_message, exception_code, 3996129271UL); + if (PHALCON_IS_FALSE(status)) { + + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(finished)) { + continue; + } } + break; } - } - if (Z_TYPE_P(have_access) == IS_NULL) { + if (PHALCON_IS_TRUE(was_fresh)) { + if (phalcon_method_quick_exists_ex(handler, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, handler, "initialize", 2896075127UL); + } + } - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSVS(access_key, role, "!", resource, "!*"); + PHALCON_INIT_NVAR(call_object); + array_init_size(call_object, 2); + phalcon_array_append(&call_object, handler, PH_SEPARATE); + phalcon_array_append(&call_object, action_method, PH_SEPARATE); - if (phalcon_array_isset(access_list, access_key)) { - PHALCON_OBS_NVAR(have_access); - phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); - } else { - if (Z_TYPE_P(inherited_roles) == IS_ARRAY) { + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_is_iterable(inherited_roles, &ah1, &hp1, 0, 0); + PHALCON_INIT_NVAR(value); + PHALCON_CALL_USER_FUNC_ARRAY_NOEX(value, call_object, params); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + if (EG(exception)) { - PHALCON_GET_HVALUE(inherited_role); + PHALCON_CPY_WRT(exception, EG(exception)); - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VSVS(access_key, inherited_role, "!", resource, "!*"); + zend_clear_exception(TSRMLS_C); - if (phalcon_array_isset(access_list, access_key)) { - PHALCON_OBS_NVAR(have_access); - phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); - break; - } + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, this_ptr, "_handleexception", exception, 2165668191UL); + if (PHALCON_IS_FALSE(status)) { - zend_hash_move_forward_ex(ah1, &hp1); + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(finished)) { + continue; + } + } else { + phalcon_throw_exception(exception TSRMLS_CC); + return; } - + } else { + phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC); } + } else { + PHALCON_INIT_NVAR(value); + PHALCON_CALL_USER_FUNC_ARRAY(value, call_object, params); + + phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), value, 4143876906UL TSRMLS_CC); } - } - if (Z_TYPE_P(have_access) == IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_lastHandler"), handler, 1315517974UL TSRMLS_CC); - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VS(access_key, role, "!*!*"); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - if (phalcon_array_isset(access_list, access_key)) { - PHALCON_OBS_NVAR(have_access); - phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); - } else { - if (Z_TYPE_P(inherited_roles) == IS_ARRAY) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "dispatch:afterExecuteRoute", 1); - phalcon_is_iterable(inherited_roles, &ah2, &hp2, 0, 0); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, value, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + continue; + } - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(finished)) { + continue; + } - PHALCON_GET_HVALUE(inherited_role); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "dispatch:afterDispatch", 1); - PHALCON_INIT_NVAR(access_key); - PHALCON_CONCAT_VS(access_key, inherited_role, "!*!*"); - if (phalcon_array_isset(access_list, access_key)) { - PHALCON_OBS_NVAR(have_access); - phalcon_array_fetch(&have_access, access_list, access_key, PH_NOISY); - break; - } + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } - zend_hash_move_forward_ex(ah2, &hp2); - } + if (phalcon_method_quick_exists_ex(handler, SS("afterexecuteroute"), 2573764025UL TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, handler, "afterexecuteroute", this_ptr, value, 2573764025UL); + if (PHALCON_IS_FALSE(status)) { + continue; + } + + PHALCON_OBS_NVAR(finished); + phalcon_read_property_this_quick(&finished, this_ptr, SL("_finished"), 385784334UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(finished)) { + continue; } } } - phalcon_update_property_this_quick(this_ptr, SL("_accessGranted"), have_access, 3188809627UL TSRMLS_CC); if (Z_TYPE_P(events_manager) == IS_OBJECT) { PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "acl:afterCheckAccess", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, have_access, 259017035UL); - } - - if (Z_TYPE_P(have_access) == IS_NULL) { - PHALCON_MM_RESTORE(); - RETURN_LONG(0); + ZVAL_STRING(event_name, "dispatch:afterDispatchLoop", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); } - RETURN_CCTOR(have_access); + RETURN_CCTOR(handler); } -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, getRoles){ +static PHP_METHOD(Phalcon_Dispatcher, forward){ + zval *forward, *exception_message, *namespace_name; + zval *controller_name, *task_name, *action_name; + zval *params; - RETURN_MEMBER_QUICK(this_ptr, "_roles", 2795361801UL); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &forward); + + if (Z_TYPE_P(forward) != IS_ARRAY) { + PHALCON_INIT_VAR(exception_message); + ZVAL_STRING(exception_message, "Forward parameter must be an Array", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "_throwdispatchexception", exception_message, 3996129271UL); + RETURN_MM_NULL(); + } + + if (phalcon_array_isset_quick_string(forward, SS("namespace"), 545490034UL)) { + PHALCON_OBS_VAR(namespace_name); + phalcon_array_fetch_quick_string(&namespace_name, forward, SS("namespace"), 545490034UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC); + } + + if (phalcon_array_isset_quick_string(forward, SS("controller"), 2892024105UL)) { + PHALCON_OBS_VAR(controller_name); + phalcon_array_fetch_quick_string(&controller_name, forward, SS("controller"), 2892024105UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), controller_name, 2743819555UL TSRMLS_CC); + } else { + if (phalcon_array_isset_quick_string(forward, SS("task"), 275333720UL)) { + PHALCON_OBS_VAR(task_name); + phalcon_array_fetch_quick_string(&task_name, forward, SS("task"), 275333720UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), task_name, 2743819555UL TSRMLS_CC); + } + } + + if (phalcon_array_isset_quick_string(forward, SS("action"), 502132067UL)) { + PHALCON_OBS_VAR(action_name); + phalcon_array_fetch_quick_string(&action_name, forward, SS("action"), 502132067UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_actionName"), action_name, 2975797059UL TSRMLS_CC); + } + + if (phalcon_array_isset_quick_string(forward, SS("params"), 2613350281UL)) { + PHALCON_OBS_VAR(params); + phalcon_array_fetch_quick_string(¶ms, forward, SS("params"), 2613350281UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_params"), params, 3223731112UL TSRMLS_CC); + } + + phalcon_update_property_bool(this_ptr, SL("_finished"), 0 TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_forwarded"), 1 TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Acl_Adapter_Memory, getResources){ +static PHP_METHOD(Phalcon_Dispatcher, wasForwarded){ - RETURN_MEMBER_QUICK(this_ptr, "_resources", 3320036063UL); + RETURN_MEMBER_QUICK(this_ptr, "_forwarded", 1865074274UL); } +static PHP_METHOD(Phalcon_Dispatcher, getHandlerClass){ + zval *handler_suffix, *namespace_name = NULL, *handler_name = NULL; + zval *camelized_class = NULL, *handler_class = NULL; + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(handler_suffix); + phalcon_read_property_this_quick(&handler_suffix, this_ptr, SL("_handlerSuffix"), 1659190583UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(namespace_name); + phalcon_read_property_this_quick(&namespace_name, this_ptr, SL("_namespaceName"), 816833906UL, PH_NOISY_CC); + if (!zend_is_true(namespace_name)) { + PHALCON_OBS_NVAR(namespace_name); + phalcon_read_property_this_quick(&namespace_name, this_ptr, SL("_defaultNamespace"), 761145590UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_namespaceName"), namespace_name, 816833906UL TSRMLS_CC); + } + + PHALCON_OBS_VAR(handler_name); + phalcon_read_property_this_quick(&handler_name, this_ptr, SL("_handlerName"), 2743819555UL, PH_NOISY_CC); + if (!zend_is_true(handler_name)) { + PHALCON_OBS_NVAR(handler_name); + phalcon_read_property_this_quick(&handler_name, this_ptr, SL("_defaultHandler"), 2940762855UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), handler_name, 2743819555UL TSRMLS_CC); + } + + if (!phalcon_memnstr_str(handler_name, SL("\\"))) { + PHALCON_INIT_VAR(camelized_class); + phalcon_camelize(camelized_class, handler_name); + } else { + PHALCON_CPY_WRT(camelized_class, handler_name); + } + + if (zend_is_true(namespace_name)) { + if (phalcon_end_with_str(namespace_name, SL("\\"))) { + PHALCON_INIT_VAR(handler_class); + PHALCON_CONCAT_VVV(handler_class, namespace_name, camelized_class, handler_suffix); + } else { + PHALCON_INIT_NVAR(handler_class); + PHALCON_CONCAT_VSVV(handler_class, namespace_name, "\\", camelized_class, handler_suffix); + } + } else { + PHALCON_INIT_NVAR(handler_class); + PHALCON_CONCAT_VV(handler_class, camelized_class, handler_suffix); + } + + RETURN_CTOR(handler_class); +} -#ifdef HAVE_CONFIG_H -#endif +#ifdef HAVE_CONFIG_H +#endif -PHALCON_INIT_CLASS(Phalcon_Acl_Exception){ +PHALCON_INIT_CLASS(Phalcon_DispatcherInterface){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Acl, Exception, acl_exception, "phalcon\\exception", NULL, 0); + PHALCON_REGISTER_INTERFACE(Phalcon, DispatcherInterface, dispatcherinterface, phalcon_dispatcherinterface_method_entry); return SUCCESS; } @@ -36808,96 +36130,32 @@ PHALCON_INIT_CLASS(Phalcon_Acl_Exception){ -#ifdef HAVE_CONFIG_H -#endif - - - - -PHALCON_INIT_CLASS(Phalcon_Validation_Validator){ - PHALCON_REGISTER_CLASS(Phalcon\\Validation, Validator, validation_validator, phalcon_validation_validator_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - zend_declare_property_null(phalcon_validation_validator_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); - return SUCCESS; -} -static PHP_METHOD(Phalcon_Validation_Validator, __construct){ - zval *options = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (Z_TYPE_P(options) != IS_ARRAY) { - if (Z_TYPE_P(options) != IS_NULL) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The attribute must be a string"); - return; - } - } else { - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Validation_Validator, isSetOption){ - zval *key, *options; - PHALCON_MM_GROW(); +#ifdef HAVE_CONFIG_H +#endif - phalcon_fetch_params(1, 1, 0, &key); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset(options, key)) { - RETURN_MM_TRUE; - } - } - - RETURN_MM_FALSE; -} -static PHP_METHOD(Phalcon_Validation_Validator, getOption){ - zval *key, *options, *value; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &key); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset(options, key)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, options, key, PH_NOISY); - RETURN_CCTOR(value); - } - } - - RETURN_MM_NULL(); -} -static PHP_METHOD(Phalcon_Validation_Validator, setOption){ +PHALCON_INIT_CLASS(Phalcon_Escaper_Exception){ - zval *key, *value; + PHALCON_REGISTER_CLASS_EX(Phalcon\\Escaper, Exception, escaper_exception, "phalcon\\exception", NULL, 0); - phalcon_fetch_params(0, 2, 0, &key, &value); - - phalcon_update_property_array(this_ptr, SL("_options"), key, value TSRMLS_CC); - + return SUCCESS; } @@ -36913,281 +36171,266 @@ static PHP_METHOD(Phalcon_Validation_Validator, setOption){ -PHALCON_INIT_CLASS(Phalcon_Validation_Message){ +PHALCON_INIT_CLASS(Phalcon_Escaper){ - PHALCON_REGISTER_CLASS(Phalcon\\Validation, Message, validation_message, phalcon_validation_message_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon, Escaper, escaper, phalcon_escaper_method_entry, 0); - zend_declare_property_null(phalcon_validation_message_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_validation_message_ce, SL("_message"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_validation_message_ce, SL("_field"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_escaper_ce, SL("_encoding"), "utf-8", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_escaper_ce, SL("_htmlEscapeMap"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_escaper_ce, SL("_htmlQuoteType"), 3, ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_escaper_ce TSRMLS_CC, 1, phalcon_escaperinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Validation_Message, __construct){ +static PHP_METHOD(Phalcon_Escaper, setEncoding){ - zval *message, *field = NULL, *type = NULL; + zval *encoding; - PHALCON_MM_GROW(); + phalcon_fetch_params(0, 1, 0, &encoding); - phalcon_fetch_params(1, 1, 2, &message, &field, &type); - - if (!field) { - PHALCON_INIT_VAR(field); - } - - if (!type) { - PHALCON_INIT_VAR(type); + if (unlikely(Z_TYPE_P(encoding) != IS_STRING)) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_escaper_exception_ce, "The character set must be string"); + return; } - - phalcon_update_property_this_quick(this_ptr, SL("_message"), message, 933579817UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_field"), field, 2318377128UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); + phalcon_update_property_this_quick(this_ptr, SL("_encoding"), encoding, 4261080171UL TSRMLS_CC); + } -static PHP_METHOD(Phalcon_Validation_Message, setType){ +static PHP_METHOD(Phalcon_Escaper, getEncoding){ - zval *type; - phalcon_fetch_params(0, 1, 0, &type); - - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - RETURN_THISW(); + RETURN_MEMBER_QUICK(this_ptr, "_encoding", 4261080171UL); } -static PHP_METHOD(Phalcon_Validation_Message, getType){ - +static PHP_METHOD(Phalcon_Escaper, setHtmlQuoteType){ - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); -} + zval *quote_type; -static PHP_METHOD(Phalcon_Validation_Message, setMessage){ + phalcon_fetch_params(0, 1, 0, "e_type); - zval *message; + if (Z_TYPE_P(quote_type) != IS_LONG) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_escaper_exception_ce, "The quoting type is not valid"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_htmlQuoteType"), quote_type, 477993385UL TSRMLS_CC); - phalcon_fetch_params(0, 1, 0, &message); - - phalcon_update_property_this_quick(this_ptr, SL("_message"), message, 933579817UL TSRMLS_CC); - RETURN_THISW(); } -static PHP_METHOD(Phalcon_Validation_Message, getMessage){ +static PHP_METHOD(Phalcon_Escaper, detectEncoding){ + zval *str, *charset = NULL, *strict_check, *detected = NULL; - RETURN_MEMBER_QUICK(this_ptr, "_message", 933579817UL); -} + PHALCON_MM_GROW(); -static PHP_METHOD(Phalcon_Validation_Message, setField){ + phalcon_fetch_params(1, 1, 0, &str); - zval *field; + PHALCON_INIT_VAR(charset); + phalcon_is_basic_charset(charset, str); + if (Z_TYPE_P(charset) == IS_STRING) { + RETURN_CTOR(charset); + } - phalcon_fetch_params(0, 1, 0, &field); - - phalcon_update_property_this_quick(this_ptr, SL("_field"), field, 2318377128UL TSRMLS_CC); - RETURN_THISW(); -} + if (phalcon_function_quick_exists_ex(SS("mb_detect_encoding"), 2715391634UL TSRMLS_CC) == FAILURE) { + RETURN_MM_NULL(); + } -static PHP_METHOD(Phalcon_Validation_Message, getField){ + PHALCON_INIT_VAR(strict_check); + ZVAL_BOOL(strict_check, 1); + PHALCON_INIT_NVAR(charset); + ZVAL_STRING(charset, "UTF-32", 1); - RETURN_MEMBER_QUICK(this_ptr, "_field", 2318377128UL); -} + PHALCON_INIT_VAR(detected); + phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check); + if (zend_is_true(detected)) { + RETURN_CTOR(charset); + } -static PHP_METHOD(Phalcon_Validation_Message, __toString){ + PHALCON_INIT_NVAR(charset); + ZVAL_STRING(charset, "UTF-16", 1); + PHALCON_INIT_NVAR(detected); + phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check); + if (zend_is_true(detected)) { + RETURN_CTOR(charset); + } - RETURN_MEMBER_QUICK(this_ptr, "_message", 933579817UL); -} + PHALCON_INIT_NVAR(charset); + ZVAL_STRING(charset, "UTF-8", 1); -static PHP_METHOD(Phalcon_Validation_Message, __set_state){ + PHALCON_INIT_NVAR(detected); + phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check); + if (zend_is_true(detected)) { + RETURN_CTOR(charset); + } - zval *message, *message_text, *field, *type; + PHALCON_INIT_NVAR(charset); + ZVAL_STRING(charset, "ISO-8859-1", 1); - PHALCON_MM_GROW(); + PHALCON_INIT_NVAR(detected); + phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check); + if (zend_is_true(detected)) { + RETURN_CTOR(charset); + } - phalcon_fetch_params(1, 1, 0, &message); - - PHALCON_OBS_VAR(message_text); - phalcon_array_fetch_quick_string(&message_text, message, SS("_message"), 933579817UL, PH_NOISY); - - PHALCON_OBS_VAR(field); - phalcon_array_fetch_quick_string(&field, message, SS("_field"), 2318377128UL, PH_NOISY); - - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, message, SS("_type"), 3991959110UL, PH_NOISY); - object_init_ex(return_value, phalcon_validation_message_ce); - phalcon_call_method_p3_key(NULL, return_value, "__construct", message_text, field, type, 1107214344UL); - + PHALCON_INIT_NVAR(charset); + ZVAL_STRING(charset, "ASCII", 1); + + PHALCON_INIT_NVAR(detected); + phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check); + if (zend_is_true(detected)) { + RETURN_CTOR(charset); + } + + phalcon_call_func_p1(return_value, "mb_detect_encoding", str); RETURN_MM(); } +static PHP_METHOD(Phalcon_Escaper, normalizeEncoding){ + zval *str, *encoding, *charset; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &str); -#ifdef HAVE_CONFIG_H -#endif + if (phalcon_function_quick_exists_ex(SS("mb_convert_encoding"), 2165643194UL TSRMLS_CC) == FAILURE) { + PHALCON_THROW_EXCEPTION_STR(phalcon_escaper_exception_ce, "Extension 'mbstring' is required"); + return; + } + PHALCON_INIT_VAR(encoding); + phalcon_call_method_p1_key(encoding, this_ptr, "detectencoding", str, 3095134469UL); + PHALCON_INIT_VAR(charset); + ZVAL_STRING(charset, "UTF-32", 1); -PHALCON_INIT_CLASS(Phalcon_Validation_ValidatorInterface){ + phalcon_call_func_p3(return_value, "mb_convert_encoding", str, charset, encoding); + RETURN_MM(); +} - PHALCON_REGISTER_INTERFACE(Phalcon\\Validation, ValidatorInterface, validation_validatorinterface, phalcon_validation_validatorinterface_method_entry); +static PHP_METHOD(Phalcon_Escaper, escapeHtml){ - return SUCCESS; -} + zval *text, *html_quote_type, *encoding; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &text); + + if (Z_TYPE_P(text) == IS_STRING) { + PHALCON_OBS_VAR(html_quote_type); + phalcon_read_property_this_quick(&html_quote_type, this_ptr, SL("_htmlQuoteType"), 477993385UL, PH_NOISY_CC); + PHALCON_OBS_VAR(encoding); + phalcon_read_property_this_quick(&encoding, this_ptr, SL("_encoding"), 4261080171UL, PH_NOISY_CC); + phalcon_call_func_p3(return_value, "htmlspecialchars", text, html_quote_type, encoding); + RETURN_MM(); + } + RETURN_CCTOR(text); +} +static PHP_METHOD(Phalcon_Escaper, escapeHtmlAttr){ + zval *attribute, *normalized; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &attribute); + if (Z_TYPE_P(attribute) == IS_STRING) { + if (zend_is_true(attribute)) { -#ifdef HAVE_CONFIG_H -#endif + PHALCON_INIT_VAR(normalized); + phalcon_call_method_p1_key(normalized, this_ptr, "normalizeencoding", attribute, 3216085085UL); + phalcon_escape_htmlattr(return_value, normalized); + RETURN_MM(); + } + } + RETURN_CCTOR(attribute); +} +static PHP_METHOD(Phalcon_Escaper, escapeCss){ + zval *css, *normalized; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &css); -PHALCON_INIT_CLASS(Phalcon_Validation_Validator_Between){ + if (Z_TYPE_P(css) == IS_STRING) { + if (zend_is_true(css)) { - PHALCON_REGISTER_CLASS_EX(Phalcon\\Validation\\Validator, Between, validation_validator_between, "phalcon\\validation\\validator", phalcon_validation_validator_between_method_entry, 0); + PHALCON_INIT_VAR(normalized); + phalcon_call_method_p1_key(normalized, this_ptr, "normalizeencoding", css, 3216085085UL); - zend_class_implements(phalcon_validation_validator_between_ce TSRMLS_CC, 1, phalcon_validation_validatorinterface_ce); + phalcon_escape_css(return_value, normalized); + RETURN_MM(); + } + } - return SUCCESS; + RETURN_CCTOR(css); } -static PHP_METHOD(Phalcon_Validation_Validator_Between, validate){ +static PHP_METHOD(Phalcon_Escaper, escapeJs){ - zval *validator, *attribute, *value, *option = NULL, *minimum; - zval *maximum, *valid = NULL, *type, *message_str = NULL, *message; + zval *js, *normalized; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &validator, &attribute); - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, validator, "getvalue", attribute, 31703298UL); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "minimum", 1); - - PHALCON_INIT_VAR(minimum); - phalcon_call_method_p1_key(minimum, this_ptr, "getoption", option, 1191969182UL); - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "maximum", 1); - - PHALCON_INIT_VAR(maximum); - phalcon_call_method_p1_key(maximum, this_ptr, "getoption", option, 1191969182UL); - - PHALCON_INIT_VAR(valid); - is_smaller_or_equal_function(valid, minimum, value TSRMLS_CC); - if (zend_is_true(valid)) { - is_smaller_or_equal_function(valid, value, maximum TSRMLS_CC); - } - - if (PHALCON_IS_FALSE(valid)) { - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Between", 1); - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message_str); - phalcon_call_method_p1_key(message_str, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message_str)) { - PHALCON_INIT_NVAR(message_str); - PHALCON_CONCAT_VS(message_str, attribute, " is not between a valid range"); + phalcon_fetch_params(1, 1, 0, &js); + + if (Z_TYPE_P(js) == IS_STRING) { + if (zend_is_true(js)) { + + PHALCON_INIT_VAR(normalized); + phalcon_call_method_p1_key(normalized, this_ptr, "normalizeencoding", js, 3216085085UL); + + phalcon_escape_js(return_value, normalized); + RETURN_MM(); } - - PHALCON_INIT_VAR(message); - object_init_ex(message, phalcon_validation_message_ce); - phalcon_call_method_p3_key(NULL, message, "__construct", message_str, attribute, type, 1107214344UL); - - phalcon_call_method_p1_key(NULL, validator, "appendmessage", message, 2313005058UL); - RETURN_MM_FALSE; } - - RETURN_MM_TRUE; -} + RETURN_CCTOR(js); +} +static PHP_METHOD(Phalcon_Escaper, escapeUrl){ + zval *url; + phalcon_fetch_params(0, 1, 0, &url); -#ifdef HAVE_CONFIG_H -#endif + phalcon_raw_url_encode(return_value, url); + return; +} +#ifdef HAVE_CONFIG_H +#endif -PHALCON_INIT_CLASS(Phalcon_Validation_Validator_Confirmation){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Validation\\Validator, Confirmation, validation_validator_confirmation, "phalcon\\validation\\validator", phalcon_validation_validator_confirmation_method_entry, 0); +PHALCON_INIT_CLASS(Phalcon_EscaperInterface){ - zend_class_implements(phalcon_validation_validator_confirmation_ce TSRMLS_CC, 1, phalcon_validation_validatorinterface_ce); + PHALCON_REGISTER_INTERFACE(Phalcon, EscaperInterface, escaperinterface, phalcon_escaperinterface_method_entry); return SUCCESS; } -static PHP_METHOD(Phalcon_Validation_Validator_Confirmation, validate){ - zval *validator, *attribute, *with, *with_attribute; - zval *value, *with_value, *option, *message_str = NULL; - zval *type, *message; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &validator, &attribute); - - PHALCON_INIT_VAR(with); - ZVAL_STRING(with, "with", 1); - - PHALCON_INIT_VAR(with_attribute); - phalcon_call_method_p1_key(with_attribute, this_ptr, "getoption", with, 1191969182UL); - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, validator, "getvalue", attribute, 31703298UL); - - PHALCON_INIT_VAR(with_value); - phalcon_call_method_p1_key(with_value, validator, "getvalue", with_attribute, 31703298UL); - if (!PHALCON_IS_EQUAL(value, with_value)) { - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message_str); - phalcon_call_method_p1_key(message_str, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message_str)) { - PHALCON_INIT_NVAR(message_str); - PHALCON_CONCAT_SVSVS(message_str, "Value of '", attribute, "' and '", with, "' don't match"); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Confirmation", 1); - - PHALCON_INIT_VAR(message); - object_init_ex(message, phalcon_validation_message_ce); - phalcon_call_method_p3_key(NULL, message, "__construct", message_str, attribute, type, 1107214344UL); - - phalcon_call_method_p1_key(NULL, validator, "appendmessage", message, 2313005058UL); - RETURN_MM_FALSE; - } - - RETURN_MM_TRUE; -} + + + + @@ -37202,336 +36445,144 @@ static PHP_METHOD(Phalcon_Validation_Validator_Confirmation, validate){ -PHALCON_INIT_CLASS(Phalcon_Validation_Validator_PresenceOf){ +PHALCON_INIT_CLASS(Phalcon_Events_Event){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Validation\\Validator, PresenceOf, validation_validator_presenceof, "phalcon\\validation\\validator", phalcon_validation_validator_presenceof_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Events, Event, events_event, phalcon_events_event_method_entry, 0); - zend_class_implements(phalcon_validation_validator_presenceof_ce TSRMLS_CC, 1, phalcon_validation_validatorinterface_ce); + zend_declare_property_null(phalcon_events_event_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_events_event_ce, SL("_source"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_events_event_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_events_event_ce, SL("_stopped"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_events_event_ce, SL("_cancelable"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_Validation_Validator_PresenceOf, validate){ +static PHP_METHOD(Phalcon_Events_Event, __construct){ - zval *validator, *attribute, *value, *type, *option; - zval *message_str = NULL, *message; + zval *type, *source, *data = NULL, *cancelable = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &validator, &attribute); - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, validator, "getvalue", attribute, 31703298UL); - if (PHALCON_IS_EMPTY(value)) { + phalcon_fetch_params(1, 2, 2, &type, &source, &data, &cancelable); - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "PresenceOf", 1); + if (!data) { + PHALCON_INIT_VAR(data); + } - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "message", 1); + if (!cancelable) { + PHALCON_INIT_VAR(cancelable); + ZVAL_BOOL(cancelable, 1); + } - PHALCON_INIT_VAR(message_str); - phalcon_call_method_p1_key(message_str, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message_str)) { - PHALCON_INIT_NVAR(message_str); - PHALCON_CONCAT_VS(message_str, attribute, " is required"); - } + phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_source"), source, 3355220565UL TSRMLS_CC); + if (Z_TYPE_P(data) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC); + } - PHALCON_INIT_VAR(message); - object_init_ex(message, phalcon_validation_message_ce); - phalcon_call_method_p3_key(NULL, message, "__construct", message_str, attribute, type, 1107214344UL); - - phalcon_call_method_p1_key(NULL, validator, "appendmessage", message, 2313005058UL); - RETURN_MM_FALSE; + if (PHALCON_IS_NOT_TRUE(cancelable)) { + phalcon_update_property_this_quick(this_ptr, SL("_cancelable"), cancelable, 1786076446UL TSRMLS_CC); } - RETURN_MM_TRUE; + PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Events_Event, setType){ + zval *event_type; + phalcon_fetch_params(0, 1, 0, &event_type); + + phalcon_update_property_this_quick(this_ptr, SL("_type"), event_type, 3991959110UL TSRMLS_CC); + +} - -#ifdef HAVE_CONFIG_H -#endif - - - - - +static PHP_METHOD(Phalcon_Events_Event, getType){ -PHALCON_INIT_CLASS(Phalcon_Validation_Validator_Identical){ + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); +} - PHALCON_REGISTER_CLASS_EX(Phalcon\\Validation\\Validator, Identical, validation_validator_identical, "phalcon\\validation\\validator", phalcon_validation_validator_identical_method_entry, 0); +static PHP_METHOD(Phalcon_Events_Event, getSource){ - zend_class_implements(phalcon_validation_validator_identical_ce TSRMLS_CC, 1, phalcon_validation_validatorinterface_ce); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_source", 3355220565UL); } -static PHP_METHOD(Phalcon_Validation_Validator_Identical, validate){ - - zval *validator, *attribute, *value, *option = NULL, *identical_value; - zval *message_str = NULL, *type, *message; +static PHP_METHOD(Phalcon_Events_Event, setData){ - PHALCON_MM_GROW(); + zval *data; - phalcon_fetch_params(1, 2, 0, &validator, &attribute); - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, validator, "getvalue", attribute, 31703298UL); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "value", 1); - - PHALCON_INIT_VAR(identical_value); - phalcon_call_method_p1_key(identical_value, this_ptr, "getoption", option, 1191969182UL); - if (!PHALCON_IS_EQUAL(value, identical_value)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message_str); - phalcon_call_method_p1_key(message_str, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message_str)) { - PHALCON_INIT_NVAR(message_str); - PHALCON_CONCAT_VS(message_str, attribute, " does not have the expected value"); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Identical", 1); - - PHALCON_INIT_VAR(message); - object_init_ex(message, phalcon_validation_message_ce); - phalcon_call_method_p3_key(NULL, message, "__construct", message_str, attribute, type, 1107214344UL); + phalcon_fetch_params(0, 1, 0, &data); - phalcon_call_method_p1_key(NULL, validator, "appendmessage", message, 2313005058UL); - RETURN_MM_FALSE; - } + phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC); - RETURN_MM_TRUE; } +static PHP_METHOD(Phalcon_Events_Event, getData){ + RETURN_MEMBER_QUICK(this_ptr, "_data", 3972126110UL); +} +static PHP_METHOD(Phalcon_Events_Event, setCancelable){ -#ifdef HAVE_CONFIG_H -#endif - - - - - - + zval *cancelable; -PHALCON_INIT_CLASS(Phalcon_Validation_Validator_Regex){ + phalcon_fetch_params(0, 1, 0, &cancelable); + + phalcon_update_property_this_quick(this_ptr, SL("_cancelable"), cancelable, 1786076446UL TSRMLS_CC); + +} - PHALCON_REGISTER_CLASS_EX(Phalcon\\Validation\\Validator, Regex, validation_validator_regex, "phalcon\\validation\\validator", phalcon_validation_validator_regex_method_entry, 0); +static PHP_METHOD(Phalcon_Events_Event, getCancelable){ - zend_class_implements(phalcon_validation_validator_regex_ce TSRMLS_CC, 1, phalcon_validation_validatorinterface_ce); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_cancelable", 1786076446UL); } -static PHP_METHOD(Phalcon_Validation_Validator_Regex, validate){ +static PHP_METHOD(Phalcon_Events_Event, stop){ - zval *validator, *attribute, *value, *option = NULL, *pattern; - zval *matches, *match_pattern, *match_zero, *failed = NULL; - zval *message_str = NULL, *type, *message; + zval *cancelable; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &validator, &attribute); - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, validator, "getvalue", attribute, 31703298UL); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "pattern", 1); - - PHALCON_INIT_VAR(pattern); - phalcon_call_method_p1_key(pattern, this_ptr, "getoption", option, 1191969182UL); - - PHALCON_INIT_VAR(matches); - - PHALCON_INIT_VAR(match_pattern); - phalcon_preg_match(match_pattern, pattern, value, matches TSRMLS_CC); - - if (zend_is_true(match_pattern)) { - PHALCON_OBS_VAR(match_zero); - phalcon_array_fetch_long(&match_zero, matches, 0, PH_NOISY); - - PHALCON_INIT_VAR(failed); - is_not_equal_function(failed, match_zero, value TSRMLS_CC); + PHALCON_OBS_VAR(cancelable); + phalcon_read_property_this_quick(&cancelable, this_ptr, SL("_cancelable"), 1786076446UL, PH_NOISY_CC); + if (zend_is_true(cancelable)) { + phalcon_update_property_bool(this_ptr, SL("_stopped"), 1 TSRMLS_CC); } else { - PHALCON_INIT_NVAR(failed); - ZVAL_BOOL(failed, 1); - } - - if (PHALCON_IS_TRUE(failed)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message_str); - phalcon_call_method_p1_key(message_str, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message_str)) { - PHALCON_INIT_NVAR(message_str); - PHALCON_CONCAT_SVS(message_str, "Value of field '", attribute, "' doesn't match regular expression"); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Regex", 1); - - PHALCON_INIT_VAR(message); - object_init_ex(message, phalcon_validation_message_ce); - phalcon_call_method_p3_key(NULL, message, "__construct", message_str, attribute, type, 1107214344UL); - - phalcon_call_method_p1_key(NULL, validator, "appendmessage", message, 2313005058UL); - RETURN_MM_FALSE; + PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Trying to cancel a non-cancelable event"); + return; } - RETURN_MM_TRUE; + PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Events_Event, isStopped){ - - -#ifdef HAVE_CONFIG_H -#endif + RETURN_MEMBER_QUICK(this_ptr, "_stopped", 978787779UL); +} +#ifdef HAVE_CONFIG_H +#endif -PHALCON_INIT_CLASS(Phalcon_Validation_Validator_StringLength){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Validation\\Validator, StringLength, validation_validator_stringlength, "phalcon\\validation\\validator", phalcon_validation_validator_stringlength_method_entry, 0); +PHALCON_INIT_CLASS(Phalcon_Events_EventsAwareInterface){ - zend_class_implements(phalcon_validation_validator_stringlength_ce TSRMLS_CC, 1, phalcon_validation_validatorinterface_ce); + PHALCON_REGISTER_INTERFACE(Phalcon\\Events, EventsAwareInterface, events_eventsawareinterface, phalcon_events_eventsawareinterface_method_entry); return SUCCESS; } -static PHP_METHOD(Phalcon_Validation_Validator_StringLength, validate){ - - zval *validator, *attribute, *option = NULL, *is_set_min; - zval *is_set_max, *value, *length = NULL, *invalid_maximum = NULL; - zval *invalid_minimum = NULL, *maximum, *message_str = NULL; - zval *type = NULL, *message = NULL, *minimum; - - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &validator, &attribute); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "min", 1); - - PHALCON_INIT_VAR(is_set_min); - phalcon_call_method_p1_key(is_set_min, this_ptr, "issetoption", option, 2532732262UL); - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "max", 1); - - PHALCON_INIT_VAR(is_set_max); - phalcon_call_method_p1_key(is_set_max, this_ptr, "issetoption", option, 2532732262UL); - if (!zend_is_true(is_set_min)) { - if (!zend_is_true(is_set_max)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A minimum or maximum must be set"); - return; - } - } - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, validator, "getvalue", attribute, 31703298UL); - - if (phalcon_function_quick_exists_ex(SS("mb_strlen"), 3716840971UL TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_VAR(length); - phalcon_call_func_p1(length, "mb_strlen", value); - } else { - PHALCON_INIT_NVAR(length); - phalcon_fast_strlen(length, value); - } - - PHALCON_INIT_VAR(invalid_maximum); - ZVAL_BOOL(invalid_maximum, 0); - - PHALCON_INIT_VAR(invalid_minimum); - ZVAL_BOOL(invalid_minimum, 0); - - if (zend_is_true(is_set_max)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "max", 1); - - PHALCON_INIT_VAR(maximum); - phalcon_call_method_p1_key(maximum, this_ptr, "getoption", option, 1191969182UL); - - is_smaller_function(invalid_maximum, maximum, length TSRMLS_CC); - if (PHALCON_IS_TRUE(invalid_maximum)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "messageMaximum", 1); - - PHALCON_INIT_VAR(message_str); - phalcon_call_method_p1_key(message_str, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message_str)) { - PHALCON_INIT_NVAR(message_str); - PHALCON_CONCAT_SVSVS(message_str, "Value of field '", attribute, "' exceeds the maximum ", maximum, " characters"); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "TooLong", 1); - - PHALCON_INIT_VAR(message); - object_init_ex(message, phalcon_validation_message_ce); - phalcon_call_method_p3_key(NULL, message, "__construct", message_str, attribute, type, 1107214344UL); - - phalcon_call_method_p1_key(NULL, validator, "appendmessage", message, 2313005058UL); - RETURN_MM_FALSE; - } - } - - if (zend_is_true(is_set_min)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "min", 1); - - PHALCON_INIT_VAR(minimum); - phalcon_call_method_p1_key(minimum, this_ptr, "getoption", option, 1191969182UL); - - is_smaller_function(invalid_minimum, length, minimum TSRMLS_CC); - if (PHALCON_IS_TRUE(invalid_minimum)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "messageMinimum", 1); - - PHALCON_INIT_NVAR(message_str); - phalcon_call_method_p1_key(message_str, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message_str)) { - PHALCON_INIT_NVAR(message_str); - PHALCON_CONCAT_SVSVS(message_str, "Value of field '", attribute, "' is less than the minimum ", minimum, " characters"); - } - - PHALCON_INIT_NVAR(type); - ZVAL_STRING(type, "TooShort", 1); - - PHALCON_INIT_NVAR(message); - object_init_ex(message, phalcon_validation_message_ce); - phalcon_call_method_p3_key(NULL, message, "__construct", message_str, attribute, type, 1107214344UL); - - phalcon_call_method_p1_key(NULL, validator, "appendmessage", message, 2313005058UL); - RETURN_MM_FALSE; - } - } - - RETURN_MM_TRUE; -} @@ -37545,60 +36596,13 @@ static PHP_METHOD(Phalcon_Validation_Validator_StringLength, validate){ +PHALCON_INIT_CLASS(Phalcon_Events_Exception){ -PHALCON_INIT_CLASS(Phalcon_Validation_Validator_Email){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Validation\\Validator, Email, validation_validator_email, "phalcon\\validation\\validator", phalcon_validation_validator_email_method_entry, 0); - - zend_class_implements(phalcon_validation_validator_email_ce TSRMLS_CC, 1, phalcon_validation_validatorinterface_ce); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Events, Exception, events_exception, "phalcon\\exception", NULL, 0); return SUCCESS; } -static PHP_METHOD(Phalcon_Validation_Validator_Email, validate){ - - zval *validator, *attribute, *value, *validate_email; - zval *validation, *option, *message_str = NULL, *type; - zval *message; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &validator, &attribute); - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, validator, "getvalue", attribute, 31703298UL); - - PHALCON_INIT_VAR(validate_email); - ZVAL_LONG(validate_email, 274); - - PHALCON_INIT_VAR(validation); - phalcon_call_func_p2(validation, "filter_var", value, validate_email); - if (!zend_is_true(validation)) { - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message_str); - phalcon_call_method_p1_key(message_str, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message_str)) { - PHALCON_INIT_NVAR(message_str); - PHALCON_CONCAT_SVS(message_str, "Value of field '", attribute, "' must have a valid e-mail format"); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Email", 1); - - PHALCON_INIT_VAR(message); - object_init_ex(message, phalcon_validation_message_ce); - phalcon_call_method_p3_key(NULL, message, "__construct", message_str, attribute, type, 1107214344UL); - - phalcon_call_method_p1_key(NULL, validator, "appendmessage", message, 2313005058UL); - RETURN_MM_FALSE; - } - - RETURN_MM_TRUE; -} - @@ -37612,345 +36616,329 @@ static PHP_METHOD(Phalcon_Validation_Validator_Email, validate){ -PHALCON_INIT_CLASS(Phalcon_Validation_Validator_ExclusionIn){ +PHALCON_INIT_CLASS(Phalcon_Events_Manager){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Validation\\Validator, ExclusionIn, validation_validator_exclusionin, "phalcon\\validation\\validator", phalcon_validation_validator_exclusionin_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Events, Manager, events_manager, phalcon_events_manager_method_entry, 0); - zend_class_implements(phalcon_validation_validator_exclusionin_ce TSRMLS_CC, 1, phalcon_validation_validatorinterface_ce); + zend_declare_property_null(phalcon_events_manager_ce, SL("_events"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_events_manager_ce, SL("_collect"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_events_manager_ce, SL("_enablePriorities"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_events_manager_ce, SL("_responses"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_events_manager_ce TSRMLS_CC, 1, phalcon_events_managerinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Validation_Validator_ExclusionIn, validate){ +static PHP_METHOD(Phalcon_Events_Manager, attach){ - zval *validator, *attribute, *value, *option = NULL, *domain; - zval *message_str = NULL, *joined_domain, *type, *message; + zval *event_type, *handler, *priority = NULL, *events = NULL; + zval *enable_priorities, *priority_queue = NULL; + zval *mode; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &validator, &attribute); - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, validator, "getvalue", attribute, 31703298UL); + phalcon_fetch_params(1, 2, 1, &event_type, &handler, &priority); - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "domain", 1); + if (!priority) { + PHALCON_INIT_VAR(priority); + ZVAL_LONG(priority, 100); + } - PHALCON_INIT_VAR(domain); - phalcon_call_method_p1_key(domain, this_ptr, "getoption", option, 1191969182UL); - if (Z_TYPE_P(domain) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "Option 'domain' must be an array"); + if (unlikely(Z_TYPE_P(event_type) != IS_STRING)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event type must be a string"); + return; + } + if (unlikely(Z_TYPE_P(handler) != IS_OBJECT)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event handler must be an Object"); return; } - if (phalcon_fast_in_array(value, domain TSRMLS_CC)) { + PHALCON_OBS_VAR(events); + phalcon_read_property_this_quick(&events, this_ptr, SL("_events"), 2709386425UL, PH_NOISY_CC); + if (Z_TYPE_P(events) != IS_ARRAY) { + PHALCON_INIT_NVAR(events); + array_init(events); + } - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); + if (!phalcon_array_isset(events, event_type)) { - PHALCON_INIT_VAR(message_str); - phalcon_call_method_p1_key(message_str, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message_str)) { - PHALCON_INIT_VAR(joined_domain); - phalcon_fast_join_str(joined_domain, SL(", "), domain TSRMLS_CC); + PHALCON_OBS_VAR(enable_priorities); + phalcon_read_property_this_quick(&enable_priorities, this_ptr, SL("_enablePriorities"), 914030005UL, PH_NOISY_CC); + if (zend_is_true(enable_priorities)) { + PHALCON_INIT_VAR(priority_queue); + object_init_ex(priority_queue, spl_ce_SplPriorityQueue); + if (phalcon_has_constructor(priority_queue TSRMLS_CC)) { + phalcon_call_method_key(NULL, priority_queue, "__construct", 1107214344UL); + } - PHALCON_INIT_NVAR(message_str); - PHALCON_CONCAT_SVSV(message_str, "Value of field '", attribute, "' must not be part of list: ", joined_domain); - } + PHALCON_INIT_VAR(mode); + ZVAL_LONG(mode, 1); - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "ExclusionIn", 1); + phalcon_call_method_p1_key(NULL, priority_queue, "setextractflags", mode, 1392794841UL); - PHALCON_INIT_VAR(message); - object_init_ex(message, phalcon_validation_message_ce); - phalcon_call_method_p3_key(NULL, message, "__construct", message_str, attribute, type, 1107214344UL); + phalcon_array_update_zval(&events, event_type, &priority_queue, PH_COPY | PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_events"), events, 2709386425UL TSRMLS_CC); + } else { + PHALCON_INIT_NVAR(priority_queue); + array_init(priority_queue); + } + } else { + PHALCON_OBS_NVAR(priority_queue); + phalcon_array_fetch(&priority_queue, events, event_type, PH_NOISY); + } - phalcon_call_method_p1_key(NULL, validator, "appendmessage", message, 2313005058UL); - RETURN_MM_FALSE; + if (unlikely(Z_TYPE_P(priority_queue) == IS_OBJECT)) { + phalcon_call_method_p2_key(NULL, priority_queue, "insert", handler, priority, 2673104346UL); + } else { + phalcon_array_append(&priority_queue, handler, PH_SEPARATE); + + phalcon_array_update_zval(&events, event_type, &priority_queue, PH_COPY | PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_events"), events, 2709386425UL TSRMLS_CC); } - RETURN_MM_TRUE; + PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Events_Manager, enablePriorities){ + zval *enable_priorities; + phalcon_fetch_params(0, 1, 0, &enable_priorities); + + phalcon_update_property_this_quick(this_ptr, SL("_enablePriorities"), enable_priorities, 914030005UL TSRMLS_CC); + +} +static PHP_METHOD(Phalcon_Events_Manager, arePrioritiesEnabled){ -#ifdef HAVE_CONFIG_H -#endif + RETURN_MEMBER_QUICK(this_ptr, "_enablePriorities", 914030005UL); +} +static PHP_METHOD(Phalcon_Events_Manager, collectResponses){ + zval *collect; + phalcon_fetch_params(0, 1, 0, &collect); + + phalcon_update_property_this_quick(this_ptr, SL("_collect"), collect, 3993548138UL TSRMLS_CC); + +} +static PHP_METHOD(Phalcon_Events_Manager, isCollecting){ -PHALCON_INIT_CLASS(Phalcon_Validation_Validator_InclusionIn){ + RETURN_MEMBER_QUICK(this_ptr, "_collect", 3993548138UL); +} - PHALCON_REGISTER_CLASS_EX(Phalcon\\Validation\\Validator, InclusionIn, validation_validator_inclusionin, "phalcon\\validation\\validator", phalcon_validation_validator_inclusionin_method_entry, 0); +static PHP_METHOD(Phalcon_Events_Manager, getResponses){ - zend_class_implements(phalcon_validation_validator_inclusionin_ce TSRMLS_CC, 1, phalcon_validation_validatorinterface_ce); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_responses", 77555686UL); } -static PHP_METHOD(Phalcon_Validation_Validator_InclusionIn, validate){ +static PHP_METHOD(Phalcon_Events_Manager, dettachAll){ - zval *validator, *attribute, *value, *option = NULL, *domain; - zval *message_str = NULL, *joined_domain, *type, *message; + zval *type = NULL, *events = NULL, *null_value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &validator, &attribute); - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, validator, "getvalue", attribute, 31703298UL); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "domain", 1); + phalcon_fetch_params(1, 0, 1, &type); - PHALCON_INIT_VAR(domain); - phalcon_call_method_p1_key(domain, this_ptr, "getoption", option, 1191969182UL); - if (Z_TYPE_P(domain) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "Option 'domain' must be an array"); - return; + if (!type) { + PHALCON_INIT_VAR(type); } - if (!phalcon_fast_in_array(value, domain TSRMLS_CC)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message_str); - phalcon_call_method_p1_key(message_str, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message_str)) { - PHALCON_INIT_VAR(joined_domain); - phalcon_fast_join_str(joined_domain, SL(", "), domain TSRMLS_CC); - - PHALCON_INIT_NVAR(message_str); - PHALCON_CONCAT_SVSV(message_str, "Value of field '", attribute, "' must be part of list: ", joined_domain); + PHALCON_OBS_VAR(events); + phalcon_read_property_this_quick(&events, this_ptr, SL("_events"), 2709386425UL, PH_NOISY_CC); + if (Z_TYPE_P(type) == IS_NULL) { + PHALCON_INIT_NVAR(events); + } else { + if (phalcon_array_isset(events, type)) { + PHALCON_INIT_VAR(null_value); + phalcon_array_update_zval(&events, type, &null_value, PH_COPY | PH_SEPARATE); } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "InclusionIn", 1); - - PHALCON_INIT_VAR(message); - object_init_ex(message, phalcon_validation_message_ce); - phalcon_call_method_p3_key(NULL, message, "__construct", message_str, attribute, type, 1107214344UL); - - phalcon_call_method_p1_key(NULL, validator, "appendmessage", message, 2313005058UL); - RETURN_MM_FALSE; } - RETURN_MM_TRUE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Validation_Message_Group){ - - PHALCON_REGISTER_CLASS(Phalcon\\Validation\\Message, Group, validation_message_group, phalcon_validation_message_group_method_entry, 0); - - zend_declare_property_null(phalcon_validation_message_group_ce, SL("_position"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_validation_message_group_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_validation_message_group_ce TSRMLS_CC, 3, spl_ce_Countable, zend_ce_arrayaccess, zend_ce_iterator); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Validation_Message_Group, __construct){ - - zval *messages = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &messages); - - if (!messages) { - PHALCON_INIT_VAR(messages); - } - - if (Z_TYPE_P(messages) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_messages"), messages, 743366684UL TSRMLS_CC); - } + phalcon_update_property_this_quick(this_ptr, SL("_events"), events, 2709386425UL TSRMLS_CC); PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Validation_Message_Group, offsetGet){ +static PHP_METHOD(Phalcon_Events_Manager, fireQueue){ - zval *index, *messages, *message; + zval *queue, *event, *status = NULL, *arguments = NULL, *event_name; + zval *source, *data, *cancelable, *collect, *iterator; + zval *handler = NULL, *is_stopped = NULL; + zval *r0 = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &index); + phalcon_fetch_params(1, 2, 0, &queue, &event); - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (phalcon_array_isset(messages, index)) { - PHALCON_OBS_VAR(message); - phalcon_array_fetch(&message, messages, index, PH_NOISY); - RETURN_CCTOR(message); + if (unlikely(Z_TYPE_P(queue) != IS_ARRAY)) { + if (Z_TYPE_P(queue) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The SplPriorityQueue is not valid"); + return; + } } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Validation_Message_Group, offsetSet){ - - zval *index, *message; - - phalcon_fetch_params(0, 2, 0, &index, &message); - - if (Z_TYPE_P(message) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "The message must be an object"); + if (unlikely(Z_TYPE_P(event) != IS_OBJECT)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The event is not valid"); return; } - phalcon_update_property_array(this_ptr, SL("_messages"), index, message TSRMLS_CC); -} - -static PHP_METHOD(Phalcon_Validation_Message_Group, offsetExists){ - - zval *index, *messages; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &index); - - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (phalcon_array_isset(messages, index)) { - RETURN_MM_TRUE; - } + PHALCON_INIT_VAR(status); - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Validation_Message_Group, offsetUnset){ - - zval *index, *messages; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &index); + PHALCON_INIT_VAR(arguments); - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (phalcon_array_isset(messages, index)) { - phalcon_unset_property_array(this_ptr, SL("_messages"), index TSRMLS_CC); + PHALCON_INIT_VAR(event_name); + phalcon_call_method_key(event_name, event, "gettype", 4294422375UL); + if (unlikely(Z_TYPE_P(event_name) != IS_STRING)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The event type not valid"); + return; } - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Validation_Message_Group, appendMessage){ - - zval *message; - - phalcon_fetch_params(0, 1, 0, &message); + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, event, "getsource", 2025234358UL); - if (Z_TYPE_P(message) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "The message must be an object"); - return; - } - phalcon_update_property_array_append(this_ptr, SL("_messages"), message TSRMLS_CC); + PHALCON_INIT_VAR(data); + phalcon_call_method_key(data, event, "getdata", 4274589375UL); -} - -static PHP_METHOD(Phalcon_Validation_Message_Group, appendMessages){ - - zval *messages, *current_messages, *final_messages = NULL; - zval *message = NULL; - zval *r0 = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &messages); + PHALCON_INIT_VAR(cancelable); + phalcon_call_method_key(cancelable, event, "getcancelable", 1233464063UL); - if (Z_TYPE_P(messages) != IS_ARRAY) { - if (Z_TYPE_P(messages) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The messages must be array or object"); + PHALCON_OBS_VAR(collect); + phalcon_read_property_this_quick(&collect, this_ptr, SL("_collect"), 3993548138UL, PH_NOISY_CC); + if (Z_TYPE_P(queue) == IS_OBJECT) { + + PHALCON_INIT_VAR(iterator); + if (phalcon_clone(iterator, queue TSRMLS_CC) == FAILURE) { return; } - } - - PHALCON_OBS_VAR(current_messages); - phalcon_read_property_this_quick(¤t_messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (Z_TYPE_P(messages) == IS_ARRAY) { - if (Z_TYPE_P(current_messages) == IS_ARRAY) { - PHALCON_INIT_VAR(final_messages); - phalcon_fast_array_merge(final_messages, ¤t_messages, &messages TSRMLS_CC); - } else { - PHALCON_CPY_WRT(final_messages, messages); - } - phalcon_update_property_this_quick(this_ptr, SL("_messages"), final_messages, 743366684UL TSRMLS_CC); - } else { - phalcon_call_method_key(NULL, messages, "rewind", 1064078190UL); + phalcon_call_method_key(NULL, iterator, "top", 2090766872UL); while (1) { PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, messages, "valid", 574098517UL); - if (PHALCON_IS_NOT_FALSE(r0)) { + phalcon_call_method_key(r0, iterator, "valid", 574098517UL); + if (zend_is_true(r0)) { } else { break; } - PHALCON_INIT_NVAR(message); - phalcon_call_method_key(message, messages, "current", 431662984UL); - phalcon_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - phalcon_call_method_key(NULL, messages, "next", 268367684UL); - } - } + PHALCON_INIT_NVAR(handler); + phalcon_call_method_key(handler, iterator, "current", 431662984UL); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Validation_Message_Group, filter){ - - zval *field_name, *filtered, *messages, *message = NULL; - zval *field = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &field_name); + if (likely(Z_TYPE_P(handler) == IS_OBJECT)) { - PHALCON_INIT_VAR(filtered); - array_init(filtered); + if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) { - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (Z_TYPE_P(messages) == IS_ARRAY) { + if (Z_TYPE_P(arguments) == IS_NULL) { + PHALCON_INIT_NVAR(arguments); + array_init_size(arguments, 3); + phalcon_array_append(&arguments, event, PH_SEPARATE); + phalcon_array_append(&arguments, source, PH_SEPARATE); + phalcon_array_append(&arguments, data, PH_SEPARATE); + } - phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments); + + if (zend_is_true(collect)) { + phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); + } + + if (zend_is_true(cancelable)) { + + PHALCON_INIT_NVAR(is_stopped); + phalcon_call_method_key(is_stopped, event, "isstopped", 1073138944UL); + if (zend_is_true(is_stopped)) { + break; + } + } + } else { + if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { + + PHALCON_INIT_NVAR(status); + phalcon_call_method_zval_p3(status, handler, event_name, event, source, data); + + if (zend_is_true(collect)) { + phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); + } + + if (zend_is_true(cancelable)) { + + PHALCON_INIT_NVAR(is_stopped); + phalcon_call_method_key(is_stopped, event, "isstopped", 1073138944UL); + if (zend_is_true(is_stopped)) { + break; + } + } + } + } + } + + phalcon_call_method_key(NULL, iterator, "next", 268367684UL); + } + } else { + + phalcon_is_iterable(queue, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_GET_HVALUE(message); + PHALCON_GET_HVALUE(handler); - if (phalcon_method_quick_exists_ex(message, SS("getfield"), 3709730281UL TSRMLS_CC) == SUCCESS) { + if (likely(Z_TYPE_P(handler) == IS_OBJECT)) { - PHALCON_INIT_NVAR(field); - phalcon_call_method_key(field, message, "getfield", 3709730281UL); - if (PHALCON_IS_EQUAL(field_name, field)) { - phalcon_array_append(&filtered, message, PH_SEPARATE); + if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) { + + if (Z_TYPE_P(arguments) == IS_NULL) { + PHALCON_INIT_NVAR(arguments); + array_init_size(arguments, 3); + phalcon_array_append(&arguments, event, PH_SEPARATE); + phalcon_array_append(&arguments, source, PH_SEPARATE); + phalcon_array_append(&arguments, data, PH_SEPARATE); + } + + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments); + + if (zend_is_true(collect)) { + phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); + } + + if (zend_is_true(cancelable)) { + + PHALCON_INIT_NVAR(is_stopped); + phalcon_call_method_key(is_stopped, event, "isstopped", 1073138944UL); + if (zend_is_true(is_stopped)) { + break; + } + } + } else { + if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { + + PHALCON_INIT_NVAR(status); + phalcon_call_method_zval_p3(status, handler, event_name, event, source, data); + + if (zend_is_true(collect)) { + phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); + } + + if (zend_is_true(cancelable)) { + + PHALCON_INIT_NVAR(is_stopped); + phalcon_call_method_key(is_stopped, event, "isstopped", 1073138944UL); + if (zend_is_true(is_stopped)) { + break; + } + } + } } } @@ -37959,93 +36947,136 @@ static PHP_METHOD(Phalcon_Validation_Message_Group, filter){ } - RETURN_CTOR(filtered); + RETURN_CCTOR(status); } -static PHP_METHOD(Phalcon_Validation_Message_Group, count){ +static PHP_METHOD(Phalcon_Events_Manager, fire){ - zval *messages; + zval *event_type, *source, *data = NULL, *cancelable = NULL, *events; + zval *exception_message, *event_parts, *type; + zval *event_name, *status = NULL, *collect, *event = NULL, *fire_events = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - phalcon_fast_count(return_value, messages TSRMLS_CC); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Validation_Message_Group, rewind){ - - - phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC); + phalcon_fetch_params(1, 2, 2, &event_type, &source, &data, &cancelable); -} - -static PHP_METHOD(Phalcon_Validation_Message_Group, current){ - - zval *position, *messages, *message; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); + if (!data) { + PHALCON_INIT_VAR(data); + } - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (phalcon_array_isset(messages, position)) { - PHALCON_OBS_VAR(message); - phalcon_array_fetch(&message, messages, position, PH_NOISY); - RETURN_CCTOR(message); + if (!cancelable) { + PHALCON_INIT_VAR(cancelable); + ZVAL_BOOL(cancelable, 1); } - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Validation_Message_Group, key){ - - - RETURN_MEMBER_QUICK(this_ptr, "_position", 2925265369UL); -} - -static PHP_METHOD(Phalcon_Validation_Message_Group, next){ - - - phalcon_property_incr(this_ptr, SL("_position") TSRMLS_CC); + if (unlikely(Z_TYPE_P(event_type) != IS_STRING)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event type must be a string"); + return; + } + + PHALCON_OBS_VAR(events); + phalcon_read_property_this_quick(&events, this_ptr, SL("_events"), 2709386425UL, PH_NOISY_CC); + if (Z_TYPE_P(events) != IS_ARRAY) { + RETURN_MM_NULL(); + } + + if (!phalcon_memnstr_str(event_type, SL(":"))) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Invalid event type ", event_type); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_events_exception_ce, exception_message); + return; + } + + PHALCON_INIT_VAR(event_parts); + phalcon_fast_explode_str(event_parts, SL(":"), event_type); + + PHALCON_OBS_VAR(type); + phalcon_array_fetch_long(&type, event_parts, 0, PH_NOISY); + + PHALCON_OBS_VAR(event_name); + phalcon_array_fetch_long(&event_name, event_parts, 1, PH_NOISY); + + PHALCON_INIT_VAR(status); + + PHALCON_OBS_VAR(collect); + phalcon_read_property_this_quick(&collect, this_ptr, SL("_collect"), 3993548138UL, PH_NOISY_CC); + if (zend_is_true(collect)) { + phalcon_update_property_null(this_ptr, SL("_responses") TSRMLS_CC); + } + + PHALCON_INIT_VAR(event); + + if (phalcon_array_isset(events, type)) { + + PHALCON_OBS_VAR(fire_events); + phalcon_array_fetch(&fire_events, events, type, PH_NOISY); + if (Z_TYPE_P(fire_events) == IS_ARRAY || Z_TYPE_P(fire_events) == IS_OBJECT) { + object_init_ex(event, phalcon_events_event_ce); + phalcon_call_method_p4_key(NULL, event, "__construct", event_name, source, data, cancelable, 1107214344UL); + + phalcon_call_method_p2_key(status, this_ptr, "firequeue", fire_events, event, 1024348976UL); + } + } + + if (phalcon_array_isset(events, event_type)) { + + PHALCON_OBS_NVAR(fire_events); + phalcon_array_fetch(&fire_events, events, event_type, PH_NOISY); + if (Z_TYPE_P(fire_events) == IS_ARRAY || Z_TYPE_P(fire_events) == IS_OBJECT) { + + if (Z_TYPE_P(event) == IS_NULL) { + PHALCON_INIT_NVAR(event); + object_init_ex(event, phalcon_events_event_ce); + phalcon_call_method_p4_key(NULL, event, "__construct", event_name, source, data, cancelable, 1107214344UL); + + } + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, this_ptr, "firequeue", fire_events, event, 1024348976UL); + } + } + RETURN_CCTOR(status); } -static PHP_METHOD(Phalcon_Validation_Message_Group, valid){ +static PHP_METHOD(Phalcon_Events_Manager, hasListeners){ - zval *position, *messages; + zval *type, *events; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 0, &type); - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (phalcon_array_isset(messages, position)) { - RETURN_MM_TRUE; + PHALCON_OBS_VAR(events); + phalcon_read_property_this_quick(&events, this_ptr, SL("_events"), 2709386425UL, PH_NOISY_CC); + if (Z_TYPE_P(events) == IS_ARRAY) { + if (phalcon_array_isset(events, type)) { + RETURN_MM_TRUE; + } } RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Validation_Message_Group, __set_state){ +static PHP_METHOD(Phalcon_Events_Manager, getListeners){ - zval *group, *messages; + zval *type, *events, *fire_events; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &group); + phalcon_fetch_params(1, 1, 0, &type); - PHALCON_OBS_VAR(messages); - phalcon_array_fetch_quick_string(&messages, group, SS("_messages"), 743366684UL, PH_NOISY); - object_init_ex(return_value, phalcon_validation_message_group_ce); - phalcon_call_method_p1_key(NULL, return_value, "__construct", messages, 1107214344UL); + PHALCON_OBS_VAR(events); + phalcon_read_property_this_quick(&events, this_ptr, SL("_events"), 2709386425UL, PH_NOISY_CC); + if (Z_TYPE_P(events) == IS_ARRAY) { + if (phalcon_array_isset(events, type)) { + PHALCON_OBS_VAR(fire_events); + phalcon_array_fetch(&fire_events, events, type, PH_NOISY); + RETURN_CCTOR(fire_events); + } + } - RETURN_MM(); + RETURN_MM_EMPTY_ARRAY(); } @@ -38057,12 +37088,9 @@ static PHP_METHOD(Phalcon_Validation_Message_Group, __set_state){ +PHALCON_INIT_CLASS(Phalcon_Events_ManagerInterface){ - - -PHALCON_INIT_CLASS(Phalcon_Validation_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Validation, Exception, validation_exception, "phalcon\\exception", NULL, 0); + PHALCON_REGISTER_INTERFACE(Phalcon\\Events, ManagerInterface, events_managerinterface, phalcon_events_managerinterface_method_entry); return SUCCESS; } @@ -38071,23 +37099,24 @@ PHALCON_INIT_CLASS(Phalcon_Validation_Exception){ -#ifdef HAVE_CONFIG_H -#endif -PHALCON_INIT_CLASS(Phalcon_Mvc_DispatcherInterface){ - PHALCON_REGISTER_INTERFACE_EX(Phalcon\\Mvc, DispatcherInterface, mvc_dispatcherinterface, "phalcon\\dispatcherinterface", phalcon_mvc_dispatcherinterface_method_entry); +#ifdef HAVE_CONFIG_H +#endif + - return SUCCESS; -} +PHALCON_INIT_CLASS(Phalcon_Exception){ + PHALCON_REGISTER_CLASS_EX(Phalcon, Exception, exception, "exception", NULL, 0); + return SUCCESS; +} @@ -38098,36 +37127,39 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_DispatcherInterface){ -PHALCON_INIT_CLASS(Phalcon_Mvc_ViewInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ViewInterface, mvc_viewinterface, phalcon_mvc_viewinterface_method_entry); - - return SUCCESS; -} - - - +PHALCON_INIT_CLASS(Phalcon_Filter_Exception){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Filter, Exception, filter_exception, "phalcon\\exception", NULL, 0); + return SUCCESS; +} +#ifdef HAVE_CONFIG_H +#endif +PHALCON_INIT_CLASS(Phalcon_Filter_UserFilterInterface){ + PHALCON_REGISTER_INTERFACE(Phalcon\\Filter, UserFilterInterface, filter_userfilterinterface, phalcon_filter_userfilterinterface_method_entry); + return SUCCESS; +} +#ifdef HAVE_CONFIG_H +#endif @@ -38135,29 +37167,257 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_ViewInterface){ +PHALCON_INIT_CLASS(Phalcon_Filter){ + PHALCON_REGISTER_CLASS(Phalcon, Filter, filter, phalcon_filter_method_entry, 0); + zend_declare_property_null(phalcon_filter_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_class_implements(phalcon_filter_ce TSRMLS_CC, 1, phalcon_filterinterface_ce); + return SUCCESS; +} +static PHP_METHOD(Phalcon_Filter, add){ + zval *name, *handler; + phalcon_fetch_params(0, 2, 0, &name, &handler); + + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_filter_exception_ce, "Filter name must be string"); + return; + } + if (Z_TYPE_P(handler) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_filter_exception_ce, "Filter must be an object"); + return; + } + + phalcon_update_property_array(this_ptr, SL("_filters"), name, handler TSRMLS_CC); + + RETURN_THISW(); +} +static PHP_METHOD(Phalcon_Filter, sanitize){ + zval *value, *filters, *new_value = NULL, *filter = NULL, *array_value = NULL; + zval *item_value = NULL, *item_key = NULL, *filter_value = NULL, *sanizited_value = NULL; + zval *key = NULL; + HashTable *ah0, *ah1, *ah2; + HashPosition hp0, hp1, hp2; + zval **hd; -#ifdef HAVE_CONFIG_H -#endif + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 2, 0, &value, &filters); + + if (Z_TYPE_P(filters) == IS_ARRAY) { + PHALCON_CPY_WRT(new_value, value); + if (Z_TYPE_P(value) != IS_NULL) { + + phalcon_is_iterable(filters, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(filter); + + if (Z_TYPE_P(new_value) == IS_ARRAY) { + + PHALCON_INIT_NVAR(array_value); + array_init(array_value); + + phalcon_is_iterable(new_value, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HKEY(item_key, ah1, hp1); + PHALCON_GET_HVALUE(item_value); + + PHALCON_INIT_NVAR(filter_value); + phalcon_call_method_p2_key(filter_value, this_ptr, "_sanitize", item_value, filter, 2673127019UL); + phalcon_array_update_zval(&array_value, item_key, &filter_value, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); + } + + PHALCON_CPY_WRT(new_value, array_value); + } else { + PHALCON_INIT_NVAR(filter_value); + phalcon_call_method_p2_key(filter_value, this_ptr, "_sanitize", new_value, filter, 2673127019UL); + PHALCON_CPY_WRT(new_value, filter_value); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } + + RETURN_CCTOR(new_value); + } + + if (Z_TYPE_P(value) == IS_ARRAY) { + + PHALCON_INIT_VAR(sanizited_value); + array_init(sanizited_value); + + phalcon_is_iterable(value, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HKEY(key, ah2, hp2); + PHALCON_GET_HVALUE(item_value); + + PHALCON_INIT_NVAR(filter_value); + phalcon_call_method_p2_key(filter_value, this_ptr, "_sanitize", item_value, filters, 2673127019UL); + phalcon_array_update_zval(&sanizited_value, key, &filter_value, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah2, &hp2); + } + + } else { + PHALCON_INIT_NVAR(sanizited_value); + phalcon_call_method_p2_key(sanizited_value, this_ptr, "_sanitize", value, filters, 2673127019UL); + } + + RETURN_CCTOR(sanizited_value); +} +static PHP_METHOD(Phalcon_Filter, _sanitize){ + zval *value, *filter, *filters, *filter_object; + zval *arguments, *type = NULL, *quote, *empty_str, *escaped; + zval *filtered = NULL, *allow_fraction, *options, *exception_message; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 2, 0, &value, &filter); + + PHALCON_OBS_VAR(filters); + phalcon_read_property_this_quick(&filters, this_ptr, SL("_filters"), 3850488637UL, PH_NOISY_CC); + if (phalcon_array_isset(filters, filter)) { + + PHALCON_OBS_VAR(filter_object); + phalcon_array_fetch(&filter_object, filters, filter, PH_NOISY); + + if (phalcon_is_instance_of(filter_object, SL("Closure") TSRMLS_CC)) { + PHALCON_INIT_VAR(arguments); + array_init_size(arguments, 1); + phalcon_array_append(&arguments, value, PH_SEPARATE); + PHALCON_CALL_USER_FUNC_ARRAY(return_value, filter_object, arguments); + RETURN_MM(); + } + + phalcon_call_method_p1_key(return_value, filter_object, "filter", value, 2890214155UL); + RETURN_MM(); + } + + + if (PHALCON_IS_STRING(filter, "email")) { + PHALCON_INIT_VAR(type); + ZVAL_LONG(type, 517); + + PHALCON_INIT_VAR(quote); + ZVAL_STRING(quote, "'", 1); + + PHALCON_INIT_VAR(empty_str); + ZVAL_STRING(empty_str, "", 1); + + PHALCON_INIT_VAR(escaped); + phalcon_fast_str_replace(escaped, quote, empty_str, value); + + PHALCON_INIT_VAR(filtered); + phalcon_call_func_p2(filtered, "filter_var", escaped, type); + goto ph_end_0; + } + + if (PHALCON_IS_STRING(filter, "int")) { + PHALCON_INIT_NVAR(type); + ZVAL_LONG(type, 519); + + PHALCON_INIT_NVAR(filtered); + phalcon_call_func_p2(filtered, "filter_var", value, type); + goto ph_end_0; + } + + if (PHALCON_IS_STRING(filter, "string")) { + PHALCON_INIT_NVAR(type); + ZVAL_LONG(type, 513); + + PHALCON_INIT_NVAR(filtered); + phalcon_call_func_p2(filtered, "filter_var", value, type); + goto ph_end_0; + } + + if (PHALCON_IS_STRING(filter, "float")) { + PHALCON_INIT_VAR(allow_fraction); + ZVAL_LONG(allow_fraction, 4096); + + PHALCON_INIT_VAR(options); + array_init_size(options, 1); + phalcon_array_update_quick_string(&options, SS("flags"), 4255547666UL, &allow_fraction, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(type); + ZVAL_LONG(type, 520); + + PHALCON_INIT_NVAR(filtered); + phalcon_call_func_p3(filtered, "filter_var", value, type, options); + goto ph_end_0; + } + + if (PHALCON_IS_STRING(filter, "alphanum")) { + PHALCON_INIT_NVAR(filtered); + phalcon_filter_alphanum(filtered, value); + goto ph_end_0; + } + + if (PHALCON_IS_STRING(filter, "trim")) { + PHALCON_INIT_NVAR(filtered); + phalcon_fast_trim(filtered, value, PHALCON_TRIM_BOTH TSRMLS_CC); + goto ph_end_0; + } + + if (PHALCON_IS_STRING(filter, "striptags")) { + PHALCON_INIT_NVAR(filtered); + phalcon_fast_strip_tags(filtered, value); + goto ph_end_0; + } + + if (PHALCON_IS_STRING(filter, "lower")) { + if (phalcon_function_quick_exists_ex(SS("mb_strtolower"), 3802586680UL TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_NVAR(filtered); + phalcon_call_func_p1(filtered, "mb_strtolower", value); + } else { + PHALCON_INIT_NVAR(filtered); + phalcon_fast_strtolower(filtered, value); + } + goto ph_end_0; + } + + if (PHALCON_IS_STRING(filter, "upper")) { + if (phalcon_function_quick_exists_ex(SS("mb_strtoupper"), 4155739579UL TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_NVAR(filtered); + phalcon_call_func_p1(filtered, "mb_strtoupper", value); + } else { + PHALCON_INIT_NVAR(filtered); + phalcon_fast_strtoupper(filtered, value); + } + goto ph_end_0; + } + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Sanitize filter ", filter, " is not supported"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_filter_exception_ce, exception_message); + return; + + ph_end_0: + + RETURN_CCTOR(filtered); +} -PHALCON_INIT_CLASS(Phalcon_Mvc_Url_Exception){ +static PHP_METHOD(Phalcon_Filter, getFilters){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Url, Exception, mvc_url_exception, "phalcon\\exception", NULL, 0); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL); } @@ -38169,28 +37429,15 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Url_Exception){ +PHALCON_INIT_CLASS(Phalcon_FilterInterface){ - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Controller){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, Controller, mvc_controller, "phalcon\\di\\injectable", phalcon_mvc_controller_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + PHALCON_REGISTER_INTERFACE(Phalcon, FilterInterface, filterinterface, phalcon_filterinterface_method_entry); return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Controller, __construct){ - - PHALCON_MM_GROW(); - if (phalcon_method_quick_exists_ex(this_ptr, SS("onconstruct"), 564344039UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, this_ptr, "onconstruct", 564344039UL); - } - - PHALCON_MM_RESTORE(); -} @@ -38205,89 +37452,25 @@ static PHP_METHOD(Phalcon_Mvc_Controller, __construct){ -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Behavior_SoftDelete){ +PHALCON_INIT_CLASS(Phalcon_Flash_Direct){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Behavior, SoftDelete, mvc_model_behavior_softdelete, "phalcon\\mvc\\model\\behavior", phalcon_mvc_model_behavior_softdelete_method_entry, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Flash, Direct, flash_direct, "phalcon\\flash", phalcon_flash_direct_method_entry, 0); - zend_class_implements(phalcon_mvc_model_behavior_softdelete_ce TSRMLS_CC, 1, phalcon_mvc_model_behaviorinterface_ce); + zend_class_implements(phalcon_flash_direct_ce TSRMLS_CC, 1, phalcon_flashinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Model_Behavior_SoftDelete, notify){ +static PHP_METHOD(Phalcon_Flash_Direct, message){ - zval *type, *model, *options, *skip, *value, *field, *actual_value; - zval *update_model, *status, *messages, *message = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *type, *message; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &type, &model); - - if (PHALCON_IS_STRING(type, "beforeDelete")) { - - PHALCON_INIT_VAR(options); - phalcon_call_method_key(options, this_ptr, "getoptions", 680281137UL); - if (!phalcon_array_isset_quick_string(options, SS("value"), 574111618UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'value' is required"); - return; - } - - if (!phalcon_array_isset_quick_string(options, SS("field"), 4252138601UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'field' is required"); - return; - } - - PHALCON_INIT_VAR(skip); - ZVAL_BOOL(skip, 1); - - phalcon_call_method_p1_key(NULL, model, "skipoperation", skip, 1652216141UL); - - PHALCON_OBS_VAR(value); - phalcon_array_fetch_quick_string(&value, options, SS("value"), 574111618UL, PH_NOISY); - - PHALCON_OBS_VAR(field); - phalcon_array_fetch_quick_string(&field, options, SS("field"), 4252138601UL, PH_NOISY); - - PHALCON_INIT_VAR(actual_value); - phalcon_call_method_p1_key(actual_value, model, "readattribute", field, 95450773UL); - - if (!PHALCON_IS_EQUAL(actual_value, value)) { - - PHALCON_INIT_VAR(update_model); - if (phalcon_clone(update_model, model TSRMLS_CC) == FAILURE) { - return; - } - phalcon_call_method_p2_key(NULL, update_model, "writeattribute", field, value, 3716971876UL); - - PHALCON_INIT_VAR(status); - phalcon_call_method_key(status, update_model, "save", 274150868UL); - if (!zend_is_true(status)) { - - PHALCON_INIT_VAR(messages); - phalcon_call_method_key(messages, update_model, "getmessages", 4087333309UL); - - 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_call_method_p1_key(NULL, model, "appendmessage", message, 2313005058UL); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_MM_FALSE; - } - - phalcon_call_method_p2_key(NULL, model, "writeattribute", field, value, 3716971876UL); - } - } + phalcon_fetch_params(1, 2, 0, &type, &message); - PHALCON_MM_RESTORE(); + phalcon_call_method_p2_key(return_value, this_ptr, "outputmessage", type, message, 924206491UL); + RETURN_MM(); } @@ -38302,4269 +37485,5164 @@ static PHP_METHOD(Phalcon_Mvc_Model_Behavior_SoftDelete, notify){ +PHALCON_INIT_CLASS(Phalcon_Flash_Exception){ -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Behavior_Timestampable){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Behavior, Timestampable, mvc_model_behavior_timestampable, "phalcon\\mvc\\model\\behavior", phalcon_mvc_model_behavior_timestampable_method_entry, 0); - - zend_class_implements(phalcon_mvc_model_behavior_timestampable_ce TSRMLS_CC, 1, phalcon_mvc_model_behaviorinterface_ce); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Flash, Exception, flash_exception, "phalcon\\exception", NULL, 0); return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Model_Behavior_Timestampable, notify){ - zval *type, *model, *take_action, *options, *timestamp = NULL; - zval *format, *generator, *field, *single_field = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &type, &model); - - PHALCON_INIT_VAR(take_action); - phalcon_call_method_p1_key(take_action, this_ptr, "musttakeaction", type, 4279140401UL); - if (PHALCON_IS_NOT_TRUE(take_action)) { - RETURN_MM_NULL(); - } - - PHALCON_INIT_VAR(options); - phalcon_call_method_p1_key(options, this_ptr, "getoptions", type, 680281137UL); - if (Z_TYPE_P(options) == IS_ARRAY) { - - if (!phalcon_array_isset_quick_string(options, SS("field"), 4252138601UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'field' is required"); - return; - } - - PHALCON_INIT_VAR(timestamp); - if (phalcon_array_isset_quick_string(options, SS("format"), 3131886190UL)) { - PHALCON_OBS_VAR(format); - phalcon_array_fetch_quick_string(&format, options, SS("format"), 3131886190UL, PH_NOISY); - - phalcon_call_func_p1(timestamp, "date", format); - } else { - if (phalcon_array_isset_quick_string(options, SS("generator"), 3205705004UL)) { - - PHALCON_OBS_VAR(generator); - phalcon_array_fetch_quick_string(&generator, options, SS("generator"), 3205705004UL, PH_NOISY); - if (Z_TYPE_P(generator) == IS_OBJECT) { - if (phalcon_is_instance_of(generator, SL("Closure") TSRMLS_CC)) { - PHALCON_INIT_NVAR(timestamp); - PHALCON_CALL_USER_FUNC(timestamp, generator); - } - } - } - } - - if (Z_TYPE_P(timestamp) == IS_NULL) { - PHALCON_INIT_NVAR(timestamp); - ZVAL_LONG(timestamp, (long) time(NULL)); - } - - PHALCON_OBS_VAR(field); - phalcon_array_fetch_quick_string(&field, options, SS("field"), 4252138601UL, PH_NOISY); - - if (unlikely(Z_TYPE_P(field) == IS_ARRAY)) { - - phalcon_is_iterable(field, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(single_field); - - phalcon_call_method_p2_key(NULL, model, "writeattribute", single_field, timestamp, 3716971876UL); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } else { - phalcon_call_method_p2_key(NULL, model, "writeattribute", field, timestamp, 3716971876UL); - } - } - - PHALCON_MM_RESTORE(); -} +#ifdef HAVE_CONFIG_H +#endif -#ifdef HAVE_CONFIG_H -#endif +PHALCON_INIT_CLASS(Phalcon_Flash_Session){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Flash, Session, flash_session, "phalcon\\flash", phalcon_flash_session_method_entry, 0); + zend_declare_property_null(phalcon_flash_session_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_class_implements(phalcon_flash_session_ce TSRMLS_CC, 2, phalcon_flashinterface_ce, phalcon_di_injectionawareinterface_ce); -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query){ + return SUCCESS; +} - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Query, mvc_model_query, phalcon_mvc_model_query_method_entry, 0); +static PHP_METHOD(Phalcon_Flash_Session, setDI){ - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_manager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_metaData"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_phql"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_ast"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_intermediate"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_models"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_sqlAliases"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_sqlAliasesModels"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_sqlModelsAliases"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_sqlAliasesModelsInstances"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_sqlColumnAliases"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_modelsInstances"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_cache"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_cacheOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_uniqueRow"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_bindParams"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_bindTypes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_irPhqlCache"), ZEND_ACC_STATIC|ZEND_ACC_PROTECTED TSRMLS_CC); + zval *dependency_injector; - zend_declare_class_constant_long(phalcon_mvc_model_query_ce, SL("TYPE_SELECT"), 309 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_query_ce, SL("TYPE_INSERT"), 306 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_query_ce, SL("TYPE_UPDATE"), 300 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_query_ce, SL("TYPE_DELETE"), 303 TSRMLS_CC); + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + +} - zend_class_implements(phalcon_mvc_model_query_ce TSRMLS_CC, 2, phalcon_mvc_model_queryinterface_ce, phalcon_di_injectionawareinterface_ce); +static PHP_METHOD(Phalcon_Flash_Session, getDI){ - return SUCCESS; + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, __construct){ +static PHP_METHOD(Phalcon_Flash_Session, _getSessionMessages){ - zval *phql = NULL, *dependency_injector = NULL; + zval *remove, *dependency_injector, *service; + zval *session, *index_name, *messages; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &phql, &dependency_injector); + phalcon_fetch_params(1, 1, 0, &remove); - if (!phql) { - PHALCON_INIT_VAR(phql); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (unlikely(Z_TYPE_P(dependency_injector) != IS_OBJECT)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); + return; } - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "session", 1); - if (Z_TYPE_P(phql) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_phql"), phql, 3986605817UL TSRMLS_CC); - } - if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { - phalcon_call_method_p1_key(NULL, this_ptr, "setdi", dependency_injector, 461718238UL); + PHALCON_INIT_VAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + + PHALCON_INIT_VAR(index_name); + ZVAL_STRING(index_name, "_flashMessages", 1); + + PHALCON_INIT_VAR(messages); + phalcon_call_method_p1_key(messages, session, "get", index_name, 2090288933UL); + if (PHALCON_IS_TRUE(remove)) { + phalcon_call_method_p1_key(NULL, session, "remove", index_name, 1052443347UL); } - PHALCON_MM_RESTORE(); + RETURN_CCTOR(messages); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, setDI){ +static PHP_METHOD(Phalcon_Flash_Session, _setSessionMessages){ - zval *dependency_injector, *service = NULL, *manager; - zval *meta_data; + zval *messages, *dependency_injector, *service; + zval *session, *index_name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &dependency_injector); + phalcon_fetch_params(1, 1, 0, &messages); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the ORM services"); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (unlikely(Z_TYPE_P(dependency_injector) != IS_OBJECT)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); return; } PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "modelsManager", 1); + ZVAL_STRING(service, "session", 1); - PHALCON_INIT_VAR(manager); - phalcon_call_method_p1_key(manager, dependency_injector, "getshared", service, 1727570332UL); - if (Z_TYPE_P(manager) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Injected service 'modelsManager' is invalid"); - return; - } - - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "modelsMetadata", 1); - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_p1_key(meta_data, dependency_injector, "getshared", service, 1727570332UL); - if (Z_TYPE_P(meta_data) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Injected service 'modelsMetadata' is invalid"); - return; - } + PHALCON_INIT_VAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_property_this_quick(this_ptr, SL("_manager"), manager, 4140832863UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), meta_data, 1295805989UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + PHALCON_INIT_VAR(index_name); + ZVAL_STRING(index_name, "_flashMessages", 1); + phalcon_call_method_p2_key(NULL, session, "set", index_name, messages, 2090720177UL); - PHALCON_MM_RESTORE(); + RETURN_CCTOR(messages); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} +static PHP_METHOD(Phalcon_Flash_Session, message){ -static PHP_METHOD(Phalcon_Mvc_Model_Query, setUniqueRow){ + zval *type, *message, *remove, *messages = NULL, *empty_array; - zval *unique_row; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &unique_row); + phalcon_fetch_params(1, 2, 0, &type, &message); - phalcon_update_property_this_quick(this_ptr, SL("_uniqueRow"), unique_row, 1221667347UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query, getUniqueRow){ - - - RETURN_MEMBER_QUICK(this_ptr, "_uniqueRow", 1221667347UL); + PHALCON_INIT_VAR(remove); + ZVAL_BOOL(remove, 0); + + PHALCON_INIT_VAR(messages); + phalcon_call_method_p1_key(messages, this_ptr, "_getsessionmessages", remove, 1351193184UL); + if (Z_TYPE_P(messages) != IS_ARRAY) { + PHALCON_INIT_NVAR(messages); + array_init(messages); + } + + if (!phalcon_array_isset(messages, type)) { + PHALCON_INIT_VAR(empty_array); + array_init(empty_array); + phalcon_array_update_zval(&messages, type, &empty_array, PH_COPY | PH_SEPARATE); + } + + phalcon_array_update_append_multi_2(&messages, type, message, 0); + phalcon_call_method_p1_key(NULL, this_ptr, "_setsessionmessages", messages, 2596691308UL); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getQualified){ +static PHP_METHOD(Phalcon_Flash_Session, getMessages){ - zval *expr, *column_name, *sql_column_aliases; - zval *source_column = NULL, *meta_data, *column_domain; - zval *sql_aliases, *phql = NULL, *exception_message = NULL; - zval *source = NULL, *sql_aliases_models_instances; - zval *model = NULL, *column_map = NULL, *real_column_name = NULL; - zval *number, *has_model = NULL, *models_instances; - zval *has_attribute = NULL, *models, *class_name; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *type = NULL, *remove = NULL, *messages, *return_messages; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &expr); - - PHALCON_OBS_VAR(column_name); - phalcon_array_fetch_quick_string(&column_name, expr, SS("name"), 268211462UL, PH_NOISY); - - PHALCON_OBS_VAR(sql_column_aliases); - phalcon_read_property_this_quick(&sql_column_aliases, this_ptr, SL("_sqlColumnAliases"), 3031417188UL, PH_NOISY_CC); + phalcon_fetch_params(1, 0, 2, &type, &remove); - if (phalcon_array_isset(sql_column_aliases, column_name)) { - PHALCON_INIT_VAR(source_column); - array_init_size(source_column, 2); - add_assoc_stringl_ex(source_column, SS("type"), SL("qualified"), 1); - phalcon_array_update_quick_string(&source_column, SS("name"), 268211462UL, &column_name, PH_COPY | PH_SEPARATE); - RETURN_CTOR(source_column); + if (!type) { + PHALCON_INIT_VAR(type); } - PHALCON_OBS_VAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - - if (phalcon_array_isset_quick_string(expr, SS("domain"), 542597917UL)) { - - PHALCON_OBS_VAR(column_domain); - phalcon_array_fetch_quick_string(&column_domain, expr, SS("domain"), 542597917UL, PH_NOISY); - - PHALCON_OBS_VAR(sql_aliases); - phalcon_read_property_this_quick(&sql_aliases, this_ptr, SL("_sqlAliases"), 3407085878UL, PH_NOISY_CC); - - if (!phalcon_array_isset(sql_aliases, column_domain)) { - PHALCON_OBS_VAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Unknown model or alias '", column_domain, "' (1), when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_VAR(source); - phalcon_array_fetch(&source, sql_aliases, column_domain, PH_NOISY); - - if (PHALCON_GLOBAL(orm).column_renaming) { - - PHALCON_OBS_VAR(sql_aliases_models_instances); - phalcon_read_property_this_quick(&sql_aliases_models_instances, this_ptr, SL("_sqlAliasesModelsInstances"), 3347052930UL, PH_NOISY_CC); - - if (!phalcon_array_isset(sql_aliases_models_instances, column_domain)) { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + if (!remove) { + PHALCON_INIT_VAR(remove); + ZVAL_BOOL(remove, 1); + } - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "There is no model related to model or alias '", column_domain, "', when executing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; + PHALCON_INIT_VAR(messages); + phalcon_call_method_p1_key(messages, this_ptr, "_getsessionmessages", remove, 1351193184UL); + if (Z_TYPE_P(messages) == IS_ARRAY) { + if (likely(Z_TYPE_P(type) == IS_STRING)) { + if (phalcon_array_isset(messages, type)) { + PHALCON_OBS_VAR(return_messages); + phalcon_array_fetch(&return_messages, messages, type, PH_NOISY); + RETURN_CCTOR(return_messages); } - - PHALCON_OBS_VAR(model); - phalcon_array_fetch(&model, sql_aliases_models_instances, column_domain, PH_NOISY); - - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getreversecolumnmap", model, 817005101UL); - } else { - PHALCON_INIT_NVAR(column_map); } - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, column_name)) { - PHALCON_OBS_VAR(real_column_name); - phalcon_array_fetch(&real_column_name, column_map, column_name, PH_NOISY); - } else { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + RETURN_CCTOR(messages); + } - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVSV(exception_message, "Column '", column_name, "' doesn't belong to the model or alias '", column_domain, "', when executing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(real_column_name, column_name); - } - } else { - PHALCON_INIT_VAR(number); - ZVAL_LONG(number, 0); + RETURN_MM_EMPTY_ARRAY(); +} + +static PHP_METHOD(Phalcon_Flash_Session, output){ + + zval *remove = NULL, *messages, *message = NULL, *type = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &remove); - PHALCON_INIT_VAR(has_model); - ZVAL_BOOL(has_model, 0); + if (!remove) { + PHALCON_INIT_VAR(remove); + ZVAL_BOOL(remove, 1); + } - PHALCON_OBS_VAR(models_instances); - phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); + PHALCON_INIT_VAR(messages); + phalcon_call_method_p1_key(messages, this_ptr, "_getsessionmessages", remove, 1351193184UL); + if (Z_TYPE_P(messages) == IS_ARRAY) { - phalcon_is_iterable(models_instances, &ah0, &hp0, 0, 0); + phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_GET_HVALUE(model); - - PHALCON_INIT_NVAR(has_attribute); - phalcon_call_method_p2_key(has_attribute, meta_data, "hasattribute", model, column_name, 3258442645UL); - if (zend_is_true(has_attribute)) { - PHALCON_SEPARATE(number); - phalcon_increment(number); - if (PHALCON_GT_LONG(number, 1)) { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "The column '", column_name, "' is ambiguous, when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + PHALCON_GET_HKEY(type, ah0, hp0); + PHALCON_GET_HVALUE(message); - PHALCON_CPY_WRT(has_model, model); - } + phalcon_call_method_p2_key(NULL, this_ptr, "outputmessage", type, message, 924206491UL); zend_hash_move_forward_ex(ah0, &hp0); } - if (PHALCON_IS_FALSE(has_model)) { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Column '", column_name, "' doesn't belong to any of the selected models (1), when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + } - PHALCON_OBS_VAR(models); - phalcon_read_property_this_quick(&models, this_ptr, SL("_models"), 4175729768UL, PH_NOISY_CC); - if (Z_TYPE_P(models) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The models list was not loaded correctly"); - return; - } + PHALCON_MM_RESTORE(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Flash){ + + PHALCON_REGISTER_CLASS(Phalcon, Flash, flash, phalcon_flash_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_property_null(phalcon_flash_ce, SL("_cssClasses"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_flash_ce, SL("_implicitFlush"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_flash_ce, SL("_automaticHtml"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Flash, __construct){ + + zval *css_classes = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &css_classes); - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, has_model, 0 TSRMLS_CC); - if (phalcon_array_isset(models, class_name)) { - PHALCON_OBS_NVAR(source); - phalcon_array_fetch(&source, models, class_name, PH_NOISY); - } else { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + if (!css_classes) { + PHALCON_INIT_VAR(css_classes); + } else { + PHALCON_SEPARATE_PARAM(css_classes); + } - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Column '", column_name, "' doesn't belong to any of the selected models (2), when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + if (Z_TYPE_P(css_classes) != IS_ARRAY) { + PHALCON_INIT_NVAR(css_classes); + array_init_size(css_classes, 4); + add_assoc_stringl_ex(css_classes, SS("error"), SL("errorMessage"), 1); + add_assoc_stringl_ex(css_classes, SS("notice"), SL("noticeMessage"), 1); + add_assoc_stringl_ex(css_classes, SS("success"), SL("successMessage"), 1); + add_assoc_stringl_ex(css_classes, SS("warning"), SL("warningMessage"), 1); + } + phalcon_update_property_this_quick(this_ptr, SL("_cssClasses"), css_classes, 1944388667UL TSRMLS_CC); - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_NVAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getreversecolumnmap", has_model, 817005101UL); - } else { - PHALCON_INIT_NVAR(column_map); - } + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Flash, setImplicitFlush){ + + zval *implicit_flush; + + phalcon_fetch_params(0, 1, 0, &implicit_flush); - if (Z_TYPE_P(column_map) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_implicitFlush"), implicit_flush, 521244897UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Flash, setAutomaticHtml){ + + zval *automatic_html; + + phalcon_fetch_params(0, 1, 0, &automatic_html); - if (phalcon_array_isset(column_map, column_name)) { - PHALCON_OBS_NVAR(real_column_name); - phalcon_array_fetch(&real_column_name, column_map, column_name, PH_NOISY); - } else { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_automaticHtml"), automatic_html, 1414140864UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Flash, setCssClasses){ + + zval *css_classes; + + phalcon_fetch_params(0, 1, 0, &css_classes); - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Column '", column_name, "' doesn't belong to any of the selected models (3), when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(real_column_name, column_name); - } + if (Z_TYPE_P(css_classes) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_cssClasses"), css_classes, 1944388667UL TSRMLS_CC); + RETURN_THISW(); } + PHALCON_THROW_EXCEPTION_STRW(phalcon_flash_exception_ce, "CSS classes must be an Array"); + return; +} + +static PHP_METHOD(Phalcon_Flash, error){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); - PHALCON_INIT_NVAR(source_column); - array_init_size(source_column, 4); - add_assoc_stringl_ex(source_column, SS("type"), SL("qualified"), 1); - phalcon_array_update_quick_string(&source_column, SS("domain"), 542597917UL, &source, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&source_column, SS("name"), 268211462UL, &real_column_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&source_column, SS("balias"), 1705826801UL, &column_name, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "error", 1); + phalcon_call_method_p2_key(return_value, this_ptr, "message", type, message, 2265848874UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Flash, notice){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); - RETURN_CTOR(source_column); + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "notice", 1); + phalcon_call_method_p2_key(return_value, this_ptr, "message", type, message, 2265848874UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getCallArgument){ +static PHP_METHOD(Phalcon_Flash, success){ - zval *argument, *argument_type; + zval *message, *type; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &argument); + phalcon_fetch_params(1, 1, 0, &message); - PHALCON_OBS_VAR(argument_type); - phalcon_array_fetch_quick_string(&argument_type, argument, SS("type"), 276192743UL, PH_NOISY); - if (PHALCON_IS_LONG(argument_type, 352)) { - array_init_size(return_value, 1); - add_assoc_stringl_ex(return_value, SS("type"), SL("all"), 1); - RETURN_MM(); - } + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "success", 1); + phalcon_call_method_p2_key(return_value, this_ptr, "message", type, message, 2265848874UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Flash, warning){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); - phalcon_call_method_p1_key(return_value, this_ptr, "_getexpression", argument, 2816780276UL); + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "warning", 1); + phalcon_call_method_p2_key(return_value, this_ptr, "message", type, message, 2265848874UL); RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getFunctionCall){ +static PHP_METHOD(Phalcon_Flash, outputMessage){ - zval *expr, *name, *arguments, *function_args = NULL, *argument = NULL; - zval *argument_expr = NULL, *function_call = NULL; + zval *type, *message, *automatic_html, *classes; + zval *type_classes, *joined_classes, *css_classes = NULL; + zval *implicit_flush, *content, *msg = NULL, *html_message = NULL; HashTable *ah0; HashPosition hp0; zval **hd; + int flag_automatic_html; + int flag_implicit_flush; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &expr); - - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, expr, SS("name"), 268211462UL, PH_NOISY); - if (phalcon_array_isset_quick_string(expr, SS("arguments"), 3751272283UL)) { - - PHALCON_OBS_VAR(arguments); - phalcon_array_fetch_quick_string(&arguments, expr, SS("arguments"), 3751272283UL, PH_NOISY); - if (phalcon_array_isset_long(arguments, 0)) { - - PHALCON_INIT_VAR(function_args); - array_init(function_args); - - phalcon_is_iterable(arguments, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(argument); - - PHALCON_INIT_NVAR(argument_expr); - phalcon_call_method_p1_key(argument_expr, this_ptr, "_getcallargument", argument, 3276339843UL); - phalcon_array_append(&function_args, argument_expr, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); + phalcon_fetch_params(1, 2, 0, &type, &message); + + PHALCON_OBS_VAR(automatic_html); + phalcon_read_property_this_quick(&automatic_html, this_ptr, SL("_automaticHtml"), 1414140864UL, PH_NOISY_CC); + flag_automatic_html = PHALCON_IS_TRUE(automatic_html) ? 1 : 0; + if (flag_automatic_html) { + + PHALCON_OBS_VAR(classes); + phalcon_read_property_this_quick(&classes, this_ptr, SL("_cssClasses"), 1944388667UL, PH_NOISY_CC); + if (phalcon_array_isset(classes, type)) { + + PHALCON_OBS_VAR(type_classes); + phalcon_array_fetch(&type_classes, classes, type, PH_NOISY); + if (Z_TYPE_P(type_classes) == IS_ARRAY) { + PHALCON_INIT_VAR(joined_classes); + phalcon_fast_join_str(joined_classes, SL(" "), type_classes TSRMLS_CC); + + PHALCON_INIT_VAR(css_classes); + PHALCON_CONCAT_SVS(css_classes, " class=\"", joined_classes, "\""); + } else { + PHALCON_INIT_NVAR(css_classes); + PHALCON_CONCAT_SVS(css_classes, " class=\"", type_classes, "\""); } - } else { - PHALCON_INIT_NVAR(argument_expr); - phalcon_call_method_p1_key(argument_expr, this_ptr, "_getcallargument", arguments, 3276339843UL); - - PHALCON_INIT_NVAR(function_args); - array_init_size(function_args, 1); - phalcon_array_append(&function_args, argument_expr, PH_SEPARATE); + PHALCON_INIT_NVAR(css_classes); + ZVAL_STRING(css_classes, "", 1); } - - PHALCON_INIT_VAR(function_call); - array_init_size(function_call, 3); - add_assoc_stringl_ex(function_call, SS("type"), SL("functionCall"), 1); - phalcon_array_update_quick_string(&function_call, SS("name"), 268211462UL, &name, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&function_call, SS("arguments"), 3751272283UL, &function_args, PH_COPY | PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(function_call); - array_init_size(function_call, 2); - add_assoc_stringl_ex(function_call, SS("type"), SL("functionCall"), 1); - phalcon_array_update_quick_string(&function_call, SS("name"), 268211462UL, &name, PH_COPY | PH_SEPARATE); } - - RETURN_CTOR(function_call); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getExpression){ + PHALCON_OBS_VAR(implicit_flush); + phalcon_read_property_this_quick(&implicit_flush, this_ptr, SL("_implicitFlush"), 521244897UL, PH_NOISY_CC); + flag_implicit_flush = PHALCON_IS_TRUE(implicit_flush) ? 1 : 0; + if (Z_TYPE_P(message) == IS_ARRAY) { - zval *expr, *quoting = NULL, *temp_not_quoting, *expr_left; - zval *left, *expr_right, *right, *expr_type, *expr_return = NULL; - zval *expr_value = NULL, *value = NULL, *escaped_value = NULL, *question_mark; - zval *double_colon, *placeholder = NULL, *expression_message; - zval *expression, *list_items, *expr_list_item = NULL; - zval *expr_item = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + if (!flag_implicit_flush) { + PHALCON_INIT_VAR(content); + ZVAL_STRING(content, "", 1); + } - PHALCON_MM_GROW(); + phalcon_is_iterable(message, &ah0, &hp0, 0, 0); - phalcon_fetch_params(1, 1, 1, &expr, "ing); - - if (!quoting) { - PHALCON_INIT_VAR(quoting); - ZVAL_BOOL(quoting, 1); - } - - if (phalcon_array_isset_quick_string(expr, SS("type"), 276192743UL)) { - - PHALCON_INIT_VAR(temp_not_quoting); - ZVAL_BOOL(temp_not_quoting, 1); - - if (phalcon_array_isset_quick_string(expr, SS("left"), 265976240UL)) { - PHALCON_OBS_VAR(expr_left); - phalcon_array_fetch_quick_string(&expr_left, expr, SS("left"), 265976240UL, PH_NOISY); - - PHALCON_INIT_VAR(left); - phalcon_call_method_p2_key(left, this_ptr, "_getexpression", expr_left, temp_not_quoting, 2816780276UL); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(msg); + + if (flag_automatic_html) { + PHALCON_INIT_NVAR(html_message); + PHALCON_CONCAT_SVSVS(html_message, "", msg, "" PHP_EOL); + } else { + PHALCON_CPY_WRT(html_message, msg); + } + if (flag_implicit_flush) { + zend_print_zval(html_message, 0); + } else { + phalcon_concat_self(&content, html_message TSRMLS_CC); + } + + zend_hash_move_forward_ex(ah0, &hp0); } - - if (phalcon_array_isset_quick_string(expr, SS("right"), 426864067UL)) { - PHALCON_OBS_VAR(expr_right); - phalcon_array_fetch_quick_string(&expr_right, expr, SS("right"), 426864067UL, PH_NOISY); - - PHALCON_INIT_VAR(right); - phalcon_call_method_p2_key(right, this_ptr, "_getexpression", expr_right, temp_not_quoting, 2816780276UL); + + if (!flag_implicit_flush) { + RETURN_CTOR(content); + } + } else { + if (flag_automatic_html) { + PHALCON_INIT_NVAR(html_message); + PHALCON_CONCAT_SVSVS(html_message, "", message, "" PHP_EOL); + } else { + PHALCON_CPY_WRT(html_message, message); + } + + if (flag_implicit_flush) { + zend_print_zval(html_message, 0); + } else { + RETURN_CCTOR(html_message); } + } + + PHALCON_MM_RESTORE(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_FlashInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon, FlashInterface, flashinterface, phalcon_flashinterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element_Check){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Check, forms_element_check, "phalcon\\forms\\element", phalcon_forms_element_check_method_entry, 0); + + zend_class_implements(phalcon_forms_element_check_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element_Check, render){ + + zval *attributes = NULL, *use_checked, *widget_attributes; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &attributes); - PHALCON_OBS_VAR(expr_type); - phalcon_array_fetch_quick_string(&expr_type, expr, SS("type"), 276192743UL, PH_NOISY); + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - switch (phalcon_get_intval(expr_type)) { + PHALCON_INIT_VAR(use_checked); + ZVAL_BOOL(use_checked, 1); - case 60: - PHALCON_INIT_VAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("<"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + PHALCON_INIT_VAR(widget_attributes); + phalcon_call_method_p2_key(widget_attributes, this_ptr, "prepareattributes", attributes, use_checked, 597834619UL); + PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "checkfield", widget_attributes); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element_Date){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Date, forms_element_date, "phalcon\\forms\\element", phalcon_forms_element_date_method_entry, 0); + + zend_class_implements(phalcon_forms_element_date_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element_Date, render){ + + zval *attributes = NULL, *widget_attributes; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &attributes); - case 61: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("="), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - case 62: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL(">"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + PHALCON_INIT_VAR(widget_attributes); + phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); + PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "datefield", widget_attributes); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element_Email){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Email, forms_element_email, "phalcon\\forms\\element", phalcon_forms_element_email_method_entry, 0); + + zend_class_implements(phalcon_forms_element_email_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element_Email, render){ + + zval *attributes = NULL, *widget_attributes; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &attributes); - case 270: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("<>"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - case 271: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("<="), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + PHALCON_INIT_VAR(widget_attributes); + phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); + PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "emailfield", widget_attributes); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element_File){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, File, forms_element_file, "phalcon\\forms\\element", phalcon_forms_element_file_method_entry, 0); + + zend_class_implements(phalcon_forms_element_file_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element_File, render){ + + zval *attributes = NULL, *widget_attributes; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &attributes); - case 272: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL(">="), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - case 266: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("AND"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + PHALCON_INIT_VAR(widget_attributes); + phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); + PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "filefield", widget_attributes); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element_Hidden){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Hidden, forms_element_hidden, "phalcon\\forms\\element", phalcon_forms_element_hidden_method_entry, 0); + + zend_class_implements(phalcon_forms_element_hidden_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element_Hidden, render){ + + zval *attributes = NULL, *widget_attributes; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &attributes); - case 267: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("OR"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - case 355: - PHALCON_INIT_NVAR(expr_return); - phalcon_call_method_p1_key(expr_return, this_ptr, "_getqualified", expr, 3068781464UL); - break; + PHALCON_INIT_VAR(widget_attributes); + phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); + PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "hiddenfield", widget_attributes); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element_Numeric){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Numeric, forms_element_numeric, "phalcon\\forms\\element", phalcon_forms_element_numeric_method_entry, 0); + + zend_class_implements(phalcon_forms_element_numeric_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element_Numeric, render){ + + zval *attributes = NULL, *widget_attributes; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &attributes); - case 359: - PHALCON_INIT_NVAR(expr_return); - phalcon_call_method_p1_key(expr_return, this_ptr, "_getaliased", expr, 2254100183UL); - break; + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - case 43: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("+"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + PHALCON_INIT_VAR(widget_attributes); + phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); + PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "numericfield", widget_attributes); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element_Password){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Password, forms_element_password, "phalcon\\forms\\element", phalcon_forms_element_password_method_entry, 0); + + zend_class_implements(phalcon_forms_element_password_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element_Password, render){ + + zval *attributes = NULL, *widget_attributes; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &attributes); - case 45: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("-"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - case 42: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("*"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + PHALCON_INIT_VAR(widget_attributes); + phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); + PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "passwordfield", widget_attributes); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element_Select){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Select, forms_element_select, "phalcon\\forms\\element", phalcon_forms_element_select_method_entry, 0); + + zend_declare_property_null(phalcon_forms_element_select_ce, SL("_optionsValues"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_forms_element_select_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element_Select, __construct){ + + zval *name, *options = NULL, *attributes = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &name, &options, &attributes); - case 47: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("/"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + if (!options) { + PHALCON_INIT_VAR(options); + } - case 37: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("%"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - case 38: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("&"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + phalcon_update_property_this_quick(this_ptr, SL("_optionsValues"), options, 842653632UL TSRMLS_CC); + PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Forms\\Element\\Select", "__construct", name, attributes); - case 124: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("|"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Forms_Element_Select, setOptions){ + + zval *options; + + phalcon_fetch_params(0, 1, 0, &options); - case 356: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 2); - add_assoc_stringl_ex(expr_return, SS("type"), SL("parentheses"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - break; + phalcon_update_property_this_quick(this_ptr, SL("_optionsValues"), options, 842653632UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element_Select, getOptions){ + + + RETURN_MEMBER_QUICK(this_ptr, "_optionsValues", 842653632UL); +} + +static PHP_METHOD(Phalcon_Forms_Element_Select, addOption){ + + zval *option; + + phalcon_fetch_params(0, 1, 0, &option); - case 367: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 3); - add_assoc_stringl_ex(expr_return, SS("type"), SL("unary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("-"), 1); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + phalcon_update_property_array_append(this_ptr, SL("_optionsValues"), option TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element_Select, render){ + + zval *attributes = NULL, *options, *widget_attributes; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &attributes); - case 258: - PHALCON_OBS_VAR(expr_value); - phalcon_array_fetch_quick_string(&expr_value, expr, SS("value"), 574111618UL, PH_NOISY); + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 2); - add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); - phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &expr_value, PH_COPY | PH_SEPARATE); - break; + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_optionsValues"), 842653632UL, PH_NOISY_CC); - case 259: - PHALCON_OBS_NVAR(expr_value); - phalcon_array_fetch_quick_string(&expr_value, expr, SS("value"), 574111618UL, PH_NOISY); + PHALCON_INIT_VAR(widget_attributes); + phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); + PHALCON_CALL_STATIC_PARAMS_2(return_value, "phalcon\\tag\\select", "selectfield", widget_attributes, options); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element_Submit){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Submit, forms_element_submit, "phalcon\\forms\\element", phalcon_forms_element_submit_method_entry, 0); + + zend_class_implements(phalcon_forms_element_submit_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element_Submit, render){ + + zval *attributes = NULL, *widget_attributes, *code; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &attributes); - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 2); - add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); - phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &expr_value, PH_COPY | PH_SEPARATE); - break; + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - case 333: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 2); - add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); - add_assoc_stringl_ex(expr_return, SS("value"), SL("TRUE"), 1); - break; + PHALCON_INIT_VAR(widget_attributes); + phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); - case 334: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 2); - add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); - add_assoc_stringl_ex(expr_return, SS("value"), SL("FALSE"), 1); - break; + PHALCON_INIT_VAR(code); + PHALCON_CALL_STATIC_PARAMS_1(code, "phalcon\\tag", "submitbutton", widget_attributes); + RETURN_CCTOR(code); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element_Text){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Text, forms_element_text, "phalcon\\forms\\element", phalcon_forms_element_text_method_entry, 0); + + zend_class_implements(phalcon_forms_element_text_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element_Text, render){ + + zval *attributes = NULL, *widget_attributes; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &attributes); - case 260: - PHALCON_OBS_VAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - if (PHALCON_IS_TRUE(quoting)) { + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - if (phalcon_memnstr_str(value, SL("'"))) { - PHALCON_INIT_VAR(escaped_value); - phalcon_orm_singlequotes(escaped_value, value TSRMLS_CC); - } else { - PHALCON_CPY_WRT(escaped_value, value); - } + PHALCON_INIT_VAR(widget_attributes); + phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); + PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "textfield", widget_attributes); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element_TextArea){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, TextArea, forms_element_textarea, "phalcon\\forms\\element", phalcon_forms_element_textarea_method_entry, 0); + + zend_class_implements(phalcon_forms_element_textarea_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element_TextArea, render){ + + zval *attributes = NULL, *widget_attributes; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &attributes); - PHALCON_INIT_NVAR(expr_value); - PHALCON_CONCAT_SVS(expr_value, "'", escaped_value, "'"); - } else { - PHALCON_CPY_WRT(expr_value, value); - } + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 2); - add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); - phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &expr_value, PH_COPY | PH_SEPARATE); - break; + PHALCON_INIT_VAR(widget_attributes); + phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); + PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "textarea", widget_attributes); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Element){ + + PHALCON_REGISTER_CLASS(Phalcon\\Forms, Element, forms_element, phalcon_forms_element_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_property_null(phalcon_forms_element_ce, SL("_form"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_element_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_element_ce, SL("_value"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_element_ce, SL("_label"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_element_ce, SL("_attributes"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_element_ce, SL("_validators"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_element_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_element_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_element_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Element, __construct){ + + zval *name, *attributes = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &name, &attributes); - case 273: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - PHALCON_INIT_VAR(question_mark); - ZVAL_STRING(question_mark, "?", 1); + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The element's name must be a string"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); + if (Z_TYPE_P(attributes) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC); + } - PHALCON_INIT_VAR(double_colon); - ZVAL_STRING(double_colon, ":", 1); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Forms_Element, setForm){ + + zval *form; + + phalcon_fetch_params(0, 1, 0, &form); - PHALCON_INIT_VAR(placeholder); - phalcon_fast_str_replace(placeholder, question_mark, double_colon, value); + phalcon_update_property_this_quick(this_ptr, SL("_form"), form, 3974999288UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element, getForm){ + + + RETURN_MEMBER_QUICK(this_ptr, "_form", 3974999288UL); +} + +static PHP_METHOD(Phalcon_Forms_Element, setName){ + + zval *name; + + phalcon_fetch_params(0, 1, 0, &name); - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 2); - add_assoc_stringl_ex(expr_return, SS("type"), SL("placeholder"), 1); - phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &placeholder, PH_COPY | PH_SEPARATE); - break; + phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element, getName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); +} + +static PHP_METHOD(Phalcon_Forms_Element, setFilters){ + + zval *filters; + + phalcon_fetch_params(0, 1, 0, &filters); - case 274: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_filters"), filters, 3850488637UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element, addFilter){ + + zval *filter, *filters, *new_filters; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &filter); - PHALCON_INIT_NVAR(placeholder); - PHALCON_CONCAT_SV(placeholder, ":", value); + PHALCON_OBS_VAR(filters); + phalcon_read_property_this_quick(&filters, this_ptr, SL("_filters"), 3850488637UL, PH_NOISY_CC); + if (Z_TYPE_P(filters) == IS_ARRAY) { + phalcon_update_property_array_append(this_ptr, SL("_filters"), filter TSRMLS_CC); + } else { + PHALCON_INIT_VAR(new_filters); + array_init_size(new_filters, 2); + phalcon_array_append(&new_filters, filters, PH_SEPARATE); + phalcon_array_append(&new_filters, filter, PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_filters"), new_filters, 3850488637UL TSRMLS_CC); + } - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 2); - add_assoc_stringl_ex(expr_return, SS("type"), SL("placeholder"), 1); - phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &placeholder, PH_COPY | PH_SEPARATE); - break; + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Forms_Element, getFilters){ + + + RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL); +} + +static PHP_METHOD(Phalcon_Forms_Element, addValidators){ + + zval *validators, *merge = NULL, *current_validators; + zval *merged_validators = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &validators, &merge); - case 322: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 2); - add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); - add_assoc_stringl_ex(expr_return, SS("value"), SL("NULL"), 1); - break; + if (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 1); + } - case 268: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("LIKE"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + if (Z_TYPE_P(validators) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The validators parameter must be an array"); + return; + } + if (zend_is_true(merge)) { - case 351: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("NOT LIKE"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + PHALCON_OBS_VAR(current_validators); + phalcon_read_property_this_quick(¤t_validators, this_ptr, SL("_validators"), 2342846045UL, PH_NOISY_CC); + if (Z_TYPE_P(current_validators) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_validators); + phalcon_fast_array_merge(merged_validators, ¤t_validators, &validators TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_validators, validators); + } - case 275: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("ILIKE"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + phalcon_update_property_this_quick(this_ptr, SL("_validators"), merged_validators, 2342846045UL TSRMLS_CC); + } - case 357: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("NOT ILIKE"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Forms_Element, addValidator){ + + zval *validator; + + phalcon_fetch_params(0, 1, 0, &validator); - case 33: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 3); - add_assoc_stringl_ex(expr_return, SS("type"), SL("unary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("NOT "), 1); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + if (Z_TYPE_P(validator) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The validators parameter must be an object"); + return; + } + phalcon_update_property_array_append(this_ptr, SL("_validators"), validator TSRMLS_CC); - case 365: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 3); - add_assoc_stringl_ex(expr_return, SS("type"), SL("unary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL(" IS NULL"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - break; + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element, getValidators){ + + + RETURN_MEMBER_QUICK(this_ptr, "_validators", 2342846045UL); +} + +static PHP_METHOD(Phalcon_Forms_Element, prepareAttributes){ + + zval *attributes = NULL, *use_checked = NULL, *name, *widget_attributes = NULL; + zval *default_attributes, *merged_attributes = NULL; + zval *value, *current_value; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &attributes, &use_checked); - case 366: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 3); - add_assoc_stringl_ex(expr_return, SS("type"), SL("unary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL(" IS NOT NULL"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - break; + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - case 315: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("IN"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + if (!use_checked) { + PHALCON_INIT_VAR(use_checked); + ZVAL_BOOL(use_checked, 0); + } - case 323: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("NOT IN"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - case 330: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 3); - add_assoc_stringl_ex(expr_return, SS("type"), SL("unary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("DISTINCT "), 1); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; - - case 331: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("BETWEEN"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; - - case 276: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 4); - add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(expr_return, SS("op"), SL("AGAINST"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; - - case 332: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 3); - add_assoc_stringl_ex(expr_return, SS("type"), SL("cast"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; - - case 335: - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 3); - add_assoc_stringl_ex(expr_return, SS("type"), SL("convert"), 1); - phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); - break; - - case 358: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("name"), 268211462UL, PH_NOISY); + if (Z_TYPE_P(attributes) != IS_ARRAY) { + PHALCON_INIT_VAR(widget_attributes); + array_init(widget_attributes); + } else { + PHALCON_CPY_WRT(widget_attributes, attributes); + } - PHALCON_INIT_NVAR(expr_return); - array_init_size(expr_return, 2); - add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); - phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); - break; + phalcon_array_update_long(&widget_attributes, 0, &name, PH_COPY | PH_SEPARATE); - case 350: - PHALCON_INIT_NVAR(expr_return); - phalcon_call_method_p1_key(expr_return, this_ptr, "_getfunctioncall", expr, 410399654UL); - break; + PHALCON_OBS_VAR(default_attributes); + phalcon_read_property_this_quick(&default_attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); + if (Z_TYPE_P(default_attributes) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_attributes); + phalcon_fast_array_merge(merged_attributes, &default_attributes, &widget_attributes TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_attributes, widget_attributes); + } - default: - PHALCON_INIT_VAR(expression_message); - PHALCON_CONCAT_SV(expression_message, "Unknown expression type ", expr_type); + PHALCON_INIT_VAR(value); + phalcon_call_method_key(value, this_ptr, "getvalue", 31703298UL); - PHALCON_INIT_VAR(expression); - object_init_ex(expression, phalcon_mvc_model_exception_ce); - phalcon_call_method_p1_key(NULL, expression, "__construct", expression_message, 1107214344UL); + if (Z_TYPE_P(value) != IS_NULL) { + if (zend_is_true(use_checked)) { - phalcon_throw_exception(expression TSRMLS_CC); - return; + if (phalcon_array_isset_quick_string(merged_attributes, SS("value"), 574111618UL)) { + PHALCON_OBS_VAR(current_value); + phalcon_array_fetch_quick_string(¤t_value, merged_attributes, SS("value"), 574111618UL, PH_NOISY); + if (PHALCON_IS_EQUAL(current_value, value)) { + phalcon_array_update_string_string(&merged_attributes, SL("checked"), SL("checked"), PH_SEPARATE); + } + } else { + if (zend_is_true(value)) { + phalcon_array_update_string_string(&merged_attributes, SL("checked"), SL("checked"), PH_SEPARATE); + } + phalcon_array_update_quick_string(&merged_attributes, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); + } + } else { + phalcon_array_update_quick_string(&merged_attributes, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); } - - RETURN_CCTOR(expr_return); - } - - if (phalcon_array_isset_quick_string(expr, SS("domain"), 542597917UL)) { - phalcon_call_method_p1_key(return_value, this_ptr, "_getqualified", expr, 3068781464UL); - RETURN_MM(); } - if (phalcon_array_isset_long(expr, 0)) { - - PHALCON_INIT_VAR(list_items); - array_init(list_items); - - phalcon_is_iterable(expr, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + RETURN_CCTOR(merged_attributes); +} + +static PHP_METHOD(Phalcon_Forms_Element, setAttribute){ + + zval *attribute, *value; + + phalcon_fetch_params(0, 2, 0, &attribute, &value); - PHALCON_GET_HVALUE(expr_list_item); + phalcon_update_property_array(this_ptr, SL("_attributes"), attribute, value TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element, getAttribute){ + + zval *attribute, *default_value = NULL, *attributes; + zval *value; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &attribute, &default_value); - PHALCON_INIT_NVAR(expr_item); - phalcon_call_method_p1_key(expr_item, this_ptr, "_getexpression", expr_list_item, 2816780276UL); - phalcon_array_append(&list_items, expr_item, PH_SEPARATE); + if (!default_value) { + PHALCON_INIT_VAR(default_value); + } - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_OBS_VAR(attributes); + phalcon_read_property_this_quick(&attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); + if (phalcon_array_isset(attributes, attribute)) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, attributes, attribute, PH_NOISY); + RETURN_CCTOR(value); + } - array_init_size(return_value, 2); - add_assoc_stringl_ex(return_value, SS("type"), SL("list"), 1); - phalcon_array_append(&return_value, list_items, PH_SEPARATE); + RETURN_CCTOR(default_value); +} + +static PHP_METHOD(Phalcon_Forms_Element, setAttributes){ + + zval *attributes; + + phalcon_fetch_params(0, 1, 0, &attributes); - RETURN_MM(); + if (Z_TYPE_P(attributes) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "Parameter 'attributes' must be an array"); + return; } + phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC); - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Unknown expression"); - return; + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getSelectColumn){ +static PHP_METHOD(Phalcon_Forms_Element, getAttributes){ - zval *column, *sql_columns, *column_type, *models; - zval *source = NULL, *model_name = NULL, *sql_column = NULL, *sql_aliases; - zval *column_domain, *phql, *exception_message = NULL; - zval *sql_column_alias = NULL, *sql_aliases_models; - zval *sql_models_aliases, *best_alias, *prepared_alias = NULL; - zval *column_data, *sql_expr_column, *balias; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *attributes; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &column); - - if (!phalcon_array_isset_quick_string(column, SS("type"), 276192743UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); - return; + PHALCON_OBS_VAR(attributes); + phalcon_read_property_this_quick(&attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); + if (Z_TYPE_P(attributes) != IS_ARRAY) { + RETURN_MM_EMPTY_ARRAY(); } - PHALCON_INIT_VAR(sql_columns); - array_init(sql_columns); - - PHALCON_OBS_VAR(column_type); - phalcon_array_fetch_quick_string(&column_type, column, SS("type"), 276192743UL, PH_NOISY); - if (PHALCON_IS_LONG(column_type, 352)) { - - PHALCON_OBS_VAR(models); - phalcon_read_property_this_quick(&models, this_ptr, SL("_models"), 4175729768UL, PH_NOISY_CC); - - phalcon_is_iterable(models, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(model_name, ah0, hp0); - PHALCON_GET_HVALUE(source); - - PHALCON_INIT_NVAR(sql_column); - array_init_size(sql_column, 3); - add_assoc_stringl_ex(sql_column, SS("type"), SL("object"), 1); - phalcon_array_update_quick_string(&sql_column, SS("model"), 238191286UL, &model_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_column, SS("column"), 3545634419UL, &source, PH_COPY | PH_SEPARATE); - phalcon_array_append(&sql_columns, sql_column, PH_SEPARATE); + RETURN_CCTOR(attributes); +} + +static PHP_METHOD(Phalcon_Forms_Element, setUserOption){ + + zval *option, *value; + + phalcon_fetch_params(0, 2, 0, &option, &value); - zend_hash_move_forward_ex(ah0, &hp0); - } + phalcon_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element, getUserOption){ + + zval *option, *default_value = NULL, *options, *value; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &option, &default_value); - RETURN_CTOR(sql_columns); + if (!default_value) { + PHALCON_INIT_VAR(default_value); } - if (!phalcon_array_isset_quick_string(column, SS("column"), 3545634419UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); - return; + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (phalcon_array_isset(options, option)) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, options, option, PH_NOISY); + RETURN_CCTOR(value); } - if (PHALCON_IS_LONG(column_type, 353)) { - - PHALCON_OBS_VAR(sql_aliases); - phalcon_read_property_this_quick(&sql_aliases, this_ptr, SL("_sqlAliases"), 3407085878UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(column_domain); - phalcon_array_fetch_quick_string(&column_domain, column, SS("column"), 3545634419UL, PH_NOISY); - if (!phalcon_array_isset(sql_aliases, column_domain)) { - PHALCON_OBS_VAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Unknown model or alias '", column_domain, "' (2), when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_VAR(source); - phalcon_array_fetch(&source, sql_aliases, column_domain, PH_NOISY); - PHALCON_CPY_WRT(sql_column_alias, source); - - PHALCON_OBS_VAR(sql_aliases_models); - phalcon_read_property_this_quick(&sql_aliases_models, this_ptr, SL("_sqlAliasesModels"), 848643194UL, PH_NOISY_CC); + RETURN_CCTOR(default_value); +} + +static PHP_METHOD(Phalcon_Forms_Element, setUserOptions){ + + zval *options; + + phalcon_fetch_params(0, 1, 0, &options); - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch(&model_name, sql_aliases_models, column_domain, PH_NOISY); + 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); - PHALCON_OBS_VAR(sql_models_aliases); - phalcon_read_property_this_quick(&sql_models_aliases, this_ptr, SL("_sqlModelsAliases"), 1781491322UL, PH_NOISY_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element, getUserOptions){ + + + RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); +} + +static PHP_METHOD(Phalcon_Forms_Element, setLabel){ + + zval *label; + + phalcon_fetch_params(0, 1, 0, &label); - PHALCON_OBS_VAR(best_alias); - phalcon_array_fetch(&best_alias, sql_models_aliases, model_name, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_label"), label, 2543586948UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element, getLabel){ + + + RETURN_MEMBER_QUICK(this_ptr, "_label", 2543586948UL); +} + +static PHP_METHOD(Phalcon_Forms_Element, label){ + + zval *label, *attributes, *name = NULL, *html = NULL; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(label); + phalcon_read_property_this_quick(&label, this_ptr, SL("_label"), 2543586948UL, PH_NOISY_CC); - if (PHALCON_IS_EQUAL(best_alias, model_name)) { - PHALCON_INIT_VAR(prepared_alias); - phalcon_lcfirst(prepared_alias, model_name); - } else { - PHALCON_CPY_WRT(prepared_alias, best_alias); - } + PHALCON_OBS_VAR(attributes); + phalcon_read_property_this_quick(&attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(sql_column); - array_init_size(sql_column, 4); - add_assoc_stringl_ex(sql_column, SS("type"), SL("object"), 1); - phalcon_array_update_quick_string(&sql_column, SS("model"), 238191286UL, &model_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_column, SS("column"), 3545634419UL, &sql_column_alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_column, SS("balias"), 1705826801UL, &prepared_alias, PH_COPY | PH_SEPARATE); - phalcon_array_append(&sql_columns, sql_column, PH_SEPARATE); + if (phalcon_array_isset_quick_string(attributes, SS("id"), 193494642UL)) { + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, attributes, SS("id"), 193494642UL, PH_NOISY); + } else { + PHALCON_OBS_NVAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); + } - RETURN_CTOR(sql_columns); + if (zend_is_true(label)) { + PHALCON_INIT_VAR(html); + PHALCON_CONCAT_SVSVS(html, ""); + } else { + PHALCON_INIT_NVAR(html); + PHALCON_CONCAT_SVSVS(html, ""); } - if (PHALCON_IS_LONG(column_type, 354)) { + RETURN_CTOR(html); +} + +static PHP_METHOD(Phalcon_Forms_Element, setDefault){ + + zval *value; + + phalcon_fetch_params(0, 1, 0, &value); - PHALCON_INIT_NVAR(sql_column); - array_init_size(sql_column, 1); - add_assoc_stringl_ex(sql_column, SS("type"), SL("scalar"), 1); + phalcon_update_property_this_quick(this_ptr, SL("_value"), value, 2935317441UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element, getDefault){ + + + RETURN_MEMBER_QUICK(this_ptr, "_value", 2935317441UL); +} + +static PHP_METHOD(Phalcon_Forms_Element, getValue){ + + zval *name, *value = NULL, *form, *has_default_value; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - PHALCON_OBS_VAR(column_data); - phalcon_array_fetch_quick_string(&column_data, column, SS("column"), 3545634419UL, PH_NOISY); + PHALCON_INIT_VAR(value); - PHALCON_INIT_VAR(sql_expr_column); - phalcon_call_method_p1_key(sql_expr_column, this_ptr, "_getexpression", column_data, 2816780276UL); + PHALCON_OBS_VAR(form); + phalcon_read_property_this_quick(&form, this_ptr, SL("_form"), 3974999288UL, PH_NOISY_CC); + if (Z_TYPE_P(form) == IS_OBJECT) { - if (phalcon_array_isset_quick_string(sql_expr_column, SS("balias"), 1705826801UL)) { - PHALCON_OBS_VAR(balias); - phalcon_array_fetch_quick_string(&balias, sql_expr_column, SS("balias"), 1705826801UL, PH_NOISY); - phalcon_array_update_quick_string(&sql_column, SS("balias"), 1705826801UL, &balias, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_column, SS("sqlAlias"), 2820722015UL, &balias, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(has_default_value); + PHALCON_CALL_STATIC_PARAMS_1(has_default_value, "phalcon\\tag", "hasvalue", name); + if (!zend_is_true(has_default_value)) { + phalcon_call_method_p1_key(value, form, "getvalue", name, 31703298UL); } + } - phalcon_array_update_quick_string(&sql_column, SS("column"), 3545634419UL, &sql_expr_column, PH_COPY | PH_SEPARATE); - phalcon_array_append(&sql_columns, sql_column, PH_SEPARATE); - - RETURN_CTOR(sql_columns); + if (Z_TYPE_P(value) == IS_NULL) { + PHALCON_OBS_NVAR(value); + phalcon_read_property_this_quick(&value, this_ptr, SL("_value"), 2935317441UL, PH_NOISY_CC); } - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Unknown type of column ", column_type); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; + RETURN_CCTOR(value); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getTable){ +static PHP_METHOD(Phalcon_Forms_Element, getMessages){ - zval *manager, *qualified_name, *model_name; - zval *model, *source, *schema, *complete_source; + zval *messages = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &manager, &qualified_name); - - if (phalcon_array_isset_quick_string(qualified_name, SS("name"), 268211462UL)) { - - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); - - PHALCON_INIT_VAR(model); - phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + PHALCON_OBS_VAR(messages); + phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); + if (Z_TYPE_P(messages) == IS_OBJECT) { + RETURN_CCTOR(messages); + } - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, model, "getsource", 2025234358UL); + PHALCON_INIT_NVAR(messages); + object_init_ex(messages, phalcon_validation_message_group_ce); + phalcon_call_method_key(NULL, messages, "__construct", 1107214344UL); - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - if (zend_is_true(schema)) { - PHALCON_INIT_VAR(complete_source); - array_init_size(complete_source, 2); - phalcon_array_append(&complete_source, schema, PH_SEPARATE); - phalcon_array_append(&complete_source, source, PH_SEPARATE); - RETURN_CTOR(complete_source); - } + phalcon_update_property_this_quick(this_ptr, SL("_messages"), messages, 743366684UL TSRMLS_CC); - RETURN_CCTOR(source); - } - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); - return; + RETURN_CCTOR(messages); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getJoin){ +static PHP_METHOD(Phalcon_Forms_Element, hasMessages){ - zval *manager, *join, *qualified, *qualified_type; - zval *model_name, *model, *source, *schema, *data; + zval *messages; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &manager, &join); + PHALCON_OBS_VAR(messages); + phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); + if (Z_TYPE_P(messages) == IS_OBJECT) { + if (phalcon_fast_count_ev(messages TSRMLS_CC)) { + RETURN_MM_TRUE; + } + } - if (phalcon_array_isset_quick_string(join, SS("qualified"), 907647673UL)) { + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Forms_Element, setMessages){ + + zval *group; + + phalcon_fetch_params(0, 1, 0, &group); - PHALCON_OBS_VAR(qualified); - phalcon_array_fetch_quick_string(&qualified, join, SS("qualified"), 907647673UL, PH_NOISY); + if (Z_TYPE_P(group) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The message group is not valid"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_messages"), group, 743366684UL TSRMLS_CC); - PHALCON_OBS_VAR(qualified_type); - phalcon_array_fetch_quick_string(&qualified_type, qualified, SS("type"), 276192743UL, PH_NOISY); - if (PHALCON_IS_LONG(qualified_type, 355)) { - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch_quick_string(&model_name, qualified, SS("name"), 268211462UL, PH_NOISY); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Element, appendMessage){ + + zval *message, *messages = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); - PHALCON_INIT_VAR(model); - phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + PHALCON_OBS_VAR(messages); + phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); + if (Z_TYPE_P(messages) != IS_OBJECT) { + PHALCON_INIT_NVAR(messages); + object_init_ex(messages, phalcon_validation_message_group_ce); + phalcon_call_method_key(NULL, messages, "__construct", 1107214344UL); - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, model, "getsource", 2025234358UL); + phalcon_update_property_this_quick(this_ptr, SL("_messages"), messages, 743366684UL TSRMLS_CC); + } - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, model, "getschema", 1539736246UL); + phalcon_call_method_p1_key(NULL, messages, "appendmessage", message, 2313005058UL); - PHALCON_INIT_VAR(data); - array_init_size(data, 4); - phalcon_array_update_quick_string(&data, SS("schema"), 2259341622UL, &schema, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("source"), 2744839734UL, &source, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("modelName"), 440103543UL, &model_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("model"), 238191286UL, &model, PH_COPY | PH_SEPARATE); - RETURN_CTOR(data); - } - } - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); - return; + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getJoinType){ +static PHP_METHOD(Phalcon_Forms_Element, clear){ - zval *join, *type, *join_type = NULL, *phql, *exception_message; + zval *znull, *name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &join); + PHALCON_INIT_VAR(znull); - if (!phalcon_array_isset_quick_string(join, SS("type"), 276192743UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); - return; + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); + PHALCON_CALL_STATIC_PARAMS_2_NORETURN("phalcon\\tag", "setdefault", name, znull); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Forms_Element, __toString){ + + + PHALCON_MM_GROW(); + + phalcon_call_method_key(return_value, this_ptr, "render", 1053215877UL); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Forms_ElementInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Forms, ElementInterface, forms_elementinterface, phalcon_forms_elementinterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms, Exception, forms_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Form){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms, Form, forms_form, "phalcon\\di\\injectable", phalcon_forms_form_method_entry, 0); + + zend_declare_property_null(phalcon_forms_form_ce, SL("_position"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_form_ce, SL("_entity"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_form_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_form_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_form_ce, SL("_elements"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_form_ce, SL("_elementsIndexed"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_form_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_forms_form_ce, SL("_action"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_forms_form_ce TSRMLS_CC, 2, spl_ce_Countable, zend_ce_iterator); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Form, __construct){ + + zval *entity = NULL, *user_options = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &entity, &user_options); + + if (!entity) { + PHALCON_INIT_VAR(entity); } - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, join, SS("type"), 276192743UL, PH_NOISY); + if (!user_options) { + PHALCON_INIT_VAR(user_options); + } - switch (phalcon_get_intval(type)) { + if (Z_TYPE_P(entity) != IS_NULL) { + if (Z_TYPE_P(entity) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The base entity is not valid"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_entity"), entity, 2413912609UL TSRMLS_CC); + } - case 360: - PHALCON_INIT_VAR(join_type); - ZVAL_STRING(join_type, "INNER", 1); - break; + if (Z_TYPE_P(user_options) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_options"), user_options, 1620153008UL TSRMLS_CC); + } - case 361: - PHALCON_INIT_NVAR(join_type); - ZVAL_STRING(join_type, "LEFT", 1); - break; + if (phalcon_method_quick_exists_ex(this_ptr, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_p2_key(NULL, this_ptr, "initialize", entity, user_options, 2896075127UL); + } - case 362: - PHALCON_INIT_NVAR(join_type); - ZVAL_STRING(join_type, "RIGHT", 1); - break; + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Forms_Form, setAction){ + + zval *action; + + phalcon_fetch_params(0, 1, 0, &action); - case 363: - PHALCON_INIT_NVAR(join_type); - ZVAL_STRING(join_type, "CROSS", 1); - break; + phalcon_update_property_this_quick(this_ptr, SL("_action"), action, 1112512898UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Form, getAction){ + + + RETURN_MEMBER_QUICK(this_ptr, "_action", 1112512898UL); +} + +static PHP_METHOD(Phalcon_Forms_Form, setUserOption){ + + zval *option, *value; + + phalcon_fetch_params(0, 2, 0, &option, &value); - case 364: - PHALCON_INIT_NVAR(join_type); - ZVAL_STRING(join_type, "FULL OUTER", 1); - break; + phalcon_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Form, getUserOption){ + + zval *option, *default_value = NULL, *options, *value; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &option, &default_value); - default: - PHALCON_OBS_VAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + if (!default_value) { + PHALCON_INIT_VAR(default_value); + } - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Unknown join type ", type, ", when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (phalcon_array_isset(options, option)) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, options, option, PH_NOISY); + RETURN_CCTOR(value); + } + + RETURN_CCTOR(default_value); +} + +static PHP_METHOD(Phalcon_Forms_Form, setUserOptions){ + + zval *options; + + phalcon_fetch_params(0, 1, 0, &options); + 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_CTOR(join_type); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getSingleJoin){ +static PHP_METHOD(Phalcon_Forms_Form, getUserOptions){ - zval *join_type, *join_source, *model_alias; - zval *join_alias, *relation, *fields, *referenced_fields; - zval *left = NULL, *left_expr = NULL, *right = NULL, *right_expr = NULL, *sql_join_condition; - zval *sql_join_conditions, *sql_join_partial_conditions; - zval *field = NULL, *position = NULL, *phql = NULL, *exception_message = NULL; - zval *referenced_field = NULL, *sql_equals_join_condition = NULL; - zval *sql_joins; + + RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); +} + +static PHP_METHOD(Phalcon_Forms_Form, setEntity){ + + zval *entity; + + phalcon_fetch_params(0, 1, 0, &entity); + + phalcon_update_property_this_quick(this_ptr, SL("_entity"), entity, 2413912609UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Forms_Form, getEntity){ + + + RETURN_MEMBER_QUICK(this_ptr, "_entity", 2413912609UL); +} + +static PHP_METHOD(Phalcon_Forms_Form, getElements){ + + + RETURN_MEMBER_QUICK(this_ptr, "_elements", 3134610529UL); +} + +static PHP_METHOD(Phalcon_Forms_Form, bind){ + + zval *data, *entity, *whitelist = NULL, *elements, *filter = NULL; + zval *value = NULL, *key = NULL, *element = NULL, *filters = NULL, *service_name = NULL; + zval *dependency_injector = NULL, *filtered_value = NULL; + zval *method = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 5, 0, &join_type, &join_source, &model_alias, &join_alias, &relation); - - PHALCON_INIT_VAR(fields); - phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - - PHALCON_INIT_VAR(referenced_fields); - phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - if (Z_TYPE_P(fields) != IS_ARRAY) { - PHALCON_INIT_VAR(left); - array_init_size(left, 3); - add_assoc_long_ex(left, SS("type"), 355); - phalcon_array_update_quick_string(&left, SS("domain"), 542597917UL, &model_alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&left, SS("name"), 268211462UL, &fields, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(left_expr); - phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); + phalcon_fetch_params(1, 2, 1, &data, &entity, &whitelist); - PHALCON_INIT_VAR(right); - array_init_size(right, 3); - add_assoc_stringl_ex(right, SS("type"), SL("qualified"), 1); - phalcon_array_update_quick_string(&right, SS("domain"), 542597917UL, &join_alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&right, SS("name"), 268211462UL, &referenced_fields, PH_COPY | PH_SEPARATE); + if (!whitelist) { + PHALCON_INIT_VAR(whitelist); + } - PHALCON_INIT_VAR(right_expr); - phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The data must be an array"); + return; + } - PHALCON_INIT_VAR(sql_join_condition); - array_init_size(sql_join_condition, 4); - add_assoc_stringl_ex(sql_join_condition, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(sql_join_condition, SS("op"), SL("="), 1); - phalcon_array_update_quick_string(&sql_join_condition, SS("left"), 265976240UL, &left_expr, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_join_condition, SS("right"), 426864067UL, &right_expr, PH_COPY | PH_SEPARATE); + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); + 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(sql_join_conditions); - array_init_size(sql_join_conditions, 1); - phalcon_array_append(&sql_join_conditions, sql_join_condition, PH_SEPARATE); - } else { - PHALCON_INIT_VAR(sql_join_partial_conditions); - array_init(sql_join_partial_conditions); + PHALCON_INIT_VAR(filter); - phalcon_is_iterable(fields, &ah0, &hp0, 0, 0); + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_GET_HKEY(position, ah0, hp0); - PHALCON_GET_HVALUE(field); + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - if (!phalcon_array_isset(referenced_fields, position)) { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + if (!phalcon_array_isset(elements, key)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "The number of fields must be equal to the number of referenced fields in join ", model_alias, "-", join_alias); - PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; + 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(referenced_field); - phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); + PHALCON_OBS_NVAR(element); + phalcon_array_fetch(&element, elements, key, PH_NOISY); - PHALCON_INIT_NVAR(left); - array_init_size(left, 3); - add_assoc_long_ex(left, SS("type"), 355); - phalcon_array_update_quick_string(&left, SS("domain"), 542597917UL, &model_alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&left, SS("name"), 268211462UL, &field, PH_COPY | PH_SEPARATE); + PHALCON_INIT_NVAR(filters); + phalcon_call_method_key(filters, element, "getfilters", 2910616766UL); + if (zend_is_true(filters)) { + if (Z_TYPE_P(filter) != IS_OBJECT) { + PHALCON_INIT_NVAR(service_name); + ZVAL_STRING(service_name, "filter", 1); - PHALCON_INIT_NVAR(left_expr); - phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); + PHALCON_INIT_NVAR(dependency_injector); + phalcon_call_method_key(dependency_injector, this_ptr, "getdi", 4287060818UL); - PHALCON_INIT_NVAR(right); - array_init_size(right, 3); - add_assoc_stringl_ex(right, SS("type"), SL("qualified"), 1); - phalcon_array_update_quick_string(&right, SS("domain"), 542597917UL, &join_alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&right, SS("name"), 268211462UL, &referenced_field, PH_COPY | PH_SEPARATE); + PHALCON_INIT_NVAR(filter); + phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service_name, 1727570332UL); + } - PHALCON_INIT_NVAR(right_expr); - phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); + PHALCON_INIT_NVAR(filtered_value); + phalcon_call_method_p2_key(filtered_value, filter, "sanitize", value, filters, 3688332940UL); + } else { + PHALCON_CPY_WRT(filtered_value, value); + } - PHALCON_INIT_NVAR(sql_equals_join_condition); - array_init_size(sql_equals_join_condition, 4); - add_assoc_stringl_ex(sql_equals_join_condition, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(sql_equals_join_condition, SS("op"), SL("="), 1); - phalcon_array_update_quick_string(&sql_equals_join_condition, SS("left"), 265976240UL, &left_expr, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_equals_join_condition, SS("right"), 426864067UL, &right_expr, PH_COPY | PH_SEPARATE); - phalcon_array_append(&sql_join_partial_conditions, sql_equals_join_condition, PH_SEPARATE); + PHALCON_INIT_NVAR(method); + PHALCON_CONCAT_SV(method, "set", key); + if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { + phalcon_call_method_zval_p1_noret(entity, 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_INIT_VAR(sql_joins); - array_init_size(sql_joins, 3); - phalcon_array_update_quick_string(&sql_joins, SS("type"), 276192743UL, &join_type, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_joins, SS("source"), 2744839734UL, &join_source, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_joins, SS("conditions"), 1055696255UL, &sql_join_conditions, PH_COPY | PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC); - RETURN_CTOR(sql_joins); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getMultiJoin){ +static PHP_METHOD(Phalcon_Forms_Form, isValid){ - zval *join_type, *join_source, *model_alias; - zval *join_alias, *relation, *sql_joins, *fields; - zval *referenced_fields, *intermediate_model_name; - zval *manager, *intermediate_model, *intermediate_source; - zval *intermediate_schema, *intermediate_full_source; - zval *intermediate_fields, *intermediate_referenced_fields; - zval *referenced_model_name, *field = NULL, *position = NULL; - zval *phql = NULL, *exception_message = NULL, *intermediate_field = NULL; - zval *left = NULL, *left_expr = NULL, *right = NULL, *right_expr = NULL, *sql_equals_join_condition = NULL; - zval *sql_join_condition_first, *sql_join_conditions_first; - zval *sql_join_first, *sql_join_condition_second; - zval *sql_join_conditions_second, *sql_join_second; - HashTable *ah0; - HashPosition hp0; + zval *data = NULL, *entity = NULL, *elements, *status, *not_failed = NULL; + zval *messages, *element = NULL, *validators = NULL, *name = NULL, *prepared_validators = NULL; + zval *validator = NULL, *scope = NULL, *validation = NULL, *filters = NULL; + zval *element_messages = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 5, 0, &join_type, &join_source, &model_alias, &join_alias, &relation); + phalcon_fetch_params(1, 0, 2, &data, &entity); - PHALCON_INIT_VAR(sql_joins); - array_init(sql_joins); + if (!data) { + PHALCON_INIT_VAR(data); + } else { + PHALCON_SEPARATE_PARAM(data); + } - PHALCON_INIT_VAR(fields); - phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); + if (!entity) { + PHALCON_INIT_VAR(entity); + } - PHALCON_INIT_VAR(referenced_fields); - phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); + if (Z_TYPE_P(elements) != IS_ARRAY) { + RETURN_MM_TRUE; + } - PHALCON_INIT_VAR(intermediate_model_name); - phalcon_call_method_key(intermediate_model_name, relation, "getintermediatemodel", 851527441UL); + if (Z_TYPE_P(entity) == IS_OBJECT) { + phalcon_call_method_p2_key(NULL, this_ptr, "bind", data, entity, 254268962UL); + } - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_OBS_NVAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + } - PHALCON_INIT_VAR(intermediate_model); - phalcon_call_method_p1_key(intermediate_model, manager, "load", intermediate_model_name, 266329637UL); + if (phalcon_method_quick_exists_ex(this_ptr, SS("beforevalidation"), 4025473891UL TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_VAR(intermediate_source); - phalcon_call_method_key(intermediate_source, intermediate_model, "getsource", 2025234358UL); + PHALCON_INIT_VAR(status); + phalcon_call_method_p2_key(status, this_ptr, "beforevalidation", data, entity, 4025473891UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_CCTOR(status); + } + } - PHALCON_INIT_VAR(intermediate_schema); - phalcon_call_method_key(intermediate_schema, intermediate_model, "getschema", 1539736246UL); + PHALCON_INIT_VAR(not_failed); + ZVAL_BOOL(not_failed, 1); - PHALCON_INIT_VAR(intermediate_full_source); - array_init_size(intermediate_full_source, 2); - phalcon_array_append(&intermediate_full_source, intermediate_schema, PH_SEPARATE); - phalcon_array_append(&intermediate_full_source, intermediate_source, PH_SEPARATE); + PHALCON_INIT_VAR(messages); + array_init(messages); - phalcon_update_property_array(this_ptr, SL("_sqlAliases"), intermediate_model_name, intermediate_source TSRMLS_CC); + phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); - phalcon_update_property_array(this_ptr, SL("_sqlAliasesModelsInstances"), intermediate_model_name, intermediate_model TSRMLS_CC); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(intermediate_fields); - phalcon_call_method_key(intermediate_fields, relation, "getintermediatefields", 1646880791UL); + PHALCON_GET_HVALUE(element); - PHALCON_INIT_VAR(intermediate_referenced_fields); - phalcon_call_method_key(intermediate_referenced_fields, relation, "getintermediatereferencedfields", 3001626474UL); + PHALCON_INIT_NVAR(validators); + phalcon_call_method_key(validators, element, "getvalidators", 1790233662UL); + if (Z_TYPE_P(validators) == IS_ARRAY) { + if (phalcon_fast_count_ev(validators TSRMLS_CC)) { - PHALCON_INIT_VAR(referenced_model_name); - phalcon_call_method_key(referenced_model_name, relation, "getreferencedmodel", 478093161UL); - if (Z_TYPE_P(fields) == IS_ARRAY) { + PHALCON_INIT_NVAR(name); + phalcon_call_method_key(name, element, "getname", 4286441094UL); - phalcon_is_iterable(fields, &ah0, &hp0, 0, 0); + PHALCON_INIT_NVAR(prepared_validators); + array_init(prepared_validators); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + phalcon_is_iterable(validators, &ah1, &hp1, 0, 0); - PHALCON_GET_HKEY(position, ah0, hp0); - PHALCON_GET_HVALUE(field); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - if (!phalcon_array_isset(referenced_fields, position)) { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + PHALCON_GET_HVALUE(validator); - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "The number of fields must be equal to the number of referenced fields in join ", model_alias, "-", join_alias); - PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_NVAR(intermediate_field); - phalcon_array_fetch(&intermediate_field, intermediate_fields, position, PH_NOISY); + PHALCON_INIT_NVAR(scope); + array_init_size(scope, 2); + phalcon_array_append(&scope, name, PH_SEPARATE); + phalcon_array_append(&scope, validator, PH_SEPARATE); + phalcon_array_append(&prepared_validators, scope, PH_SEPARATE); - PHALCON_INIT_NVAR(left); - array_init_size(left, 3); - add_assoc_long_ex(left, SS("type"), 355); - phalcon_array_update_quick_string(&left, SS("domain"), 542597917UL, &model_alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&left, SS("name"), 268211462UL, &field, PH_COPY | PH_SEPARATE); + zend_hash_move_forward_ex(ah1, &hp1); + } - PHALCON_INIT_NVAR(left_expr); - phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); + PHALCON_INIT_NVAR(validation); + object_init_ex(validation, phalcon_validation_ce); + phalcon_call_method_p1_key(NULL, validation, "__construct", prepared_validators, 1107214344UL); - PHALCON_INIT_NVAR(right); - array_init_size(right, 3); - add_assoc_stringl_ex(right, SS("type"), SL("qualified"), 1); - phalcon_array_update_quick_string(&right, SS("domain"), 542597917UL, &join_alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&right, SS("name"), 268211462UL, &referenced_fields, PH_COPY | PH_SEPARATE); + PHALCON_INIT_NVAR(filters); + phalcon_call_method_key(filters, element, "getfilters", 2910616766UL); - PHALCON_INIT_NVAR(right_expr); - phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); + if (Z_TYPE_P(filters) == IS_ARRAY) { + PHALCON_INIT_NVAR(name); + phalcon_call_method_key(name, element, "getname", 4286441094UL); + phalcon_call_method_p2_key(NULL, validation, "setfilters", name, filters, 3990158282UL); + } - PHALCON_INIT_NVAR(sql_equals_join_condition); - array_init_size(sql_equals_join_condition, 4); - add_assoc_stringl_ex(sql_equals_join_condition, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(sql_equals_join_condition, SS("op"), SL("="), 1); - phalcon_array_update_quick_string(&sql_equals_join_condition, SS("left"), 265976240UL, &left_expr, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_equals_join_condition, SS("right"), 426864067UL, &right_expr, PH_COPY | PH_SEPARATE); + PHALCON_INIT_NVAR(element_messages); + phalcon_call_method_p2_key(element_messages, validation, "validate", data, entity, 2654098287UL); + if (phalcon_fast_count_ev(element_messages TSRMLS_CC)) { + PHALCON_INIT_NVAR(name); + phalcon_call_method_key(name, element, "getname", 4286441094UL); + phalcon_array_update_zval(&messages, name, &element_messages, PH_COPY | PH_SEPARATE); - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_INIT_NVAR(not_failed); + ZVAL_BOOL(not_failed, 0); + } + } } - } else { - PHALCON_INIT_NVAR(left); - array_init_size(left, 3); - add_assoc_long_ex(left, SS("type"), 355); - phalcon_array_update_quick_string(&left, SS("domain"), 542597917UL, &model_alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&left, SS("name"), 268211462UL, &fields, PH_COPY | PH_SEPARATE); + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_INIT_NVAR(left_expr); - phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); + if (!zend_is_true(not_failed)) { + phalcon_update_property_this_quick(this_ptr, SL("_messages"), messages, 743366684UL TSRMLS_CC); + } - PHALCON_INIT_NVAR(right); - array_init_size(right, 3); - add_assoc_stringl_ex(right, SS("type"), SL("qualified"), 1); - phalcon_array_update_quick_string(&right, SS("domain"), 542597917UL, &intermediate_model_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&right, SS("name"), 268211462UL, &intermediate_fields, PH_COPY | PH_SEPARATE); + if (phalcon_method_quick_exists_ex(this_ptr, SS("aftervalidation"), 1795965282UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_p1_key(NULL, this_ptr, "aftervalidation", messages, 1795965282UL); + } - PHALCON_INIT_NVAR(right_expr); - phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); - PHALCON_INIT_VAR(sql_join_condition_first); - array_init_size(sql_join_condition_first, 4); - add_assoc_stringl_ex(sql_join_condition_first, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(sql_join_condition_first, SS("op"), SL("="), 1); - phalcon_array_update_quick_string(&sql_join_condition_first, SS("left"), 265976240UL, &left_expr, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_join_condition_first, SS("right"), 426864067UL, &right_expr, PH_COPY | PH_SEPARATE); + RETURN_NCTOR(not_failed); +} + +static PHP_METHOD(Phalcon_Forms_Form, getMessages){ + + zval *by_item_name = NULL, *messages, *group, *element_messages = NULL; + zval *element = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &by_item_name); - PHALCON_INIT_VAR(sql_join_conditions_first); - array_init_size(sql_join_conditions_first, 1); - phalcon_array_append(&sql_join_conditions_first, sql_join_condition_first, PH_SEPARATE); + if (!by_item_name) { + PHALCON_INIT_VAR(by_item_name); + ZVAL_BOOL(by_item_name, 0); + } - PHALCON_INIT_VAR(sql_join_first); - array_init_size(sql_join_first, 3); - phalcon_array_update_quick_string(&sql_join_first, SS("type"), 276192743UL, &join_type, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_join_first, SS("source"), 2744839734UL, &intermediate_source, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_join_first, SS("conditions"), 1055696255UL, &sql_join_conditions_first, PH_COPY | PH_SEPARATE); + PHALCON_OBS_VAR(messages); + phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); + if (zend_is_true(by_item_name)) { + if (Z_TYPE_P(messages) != IS_ARRAY) { + object_init_ex(return_value, phalcon_validation_message_group_ce); + phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL); - PHALCON_INIT_NVAR(left); - array_init_size(left, 3); - add_assoc_long_ex(left, SS("type"), 355); - phalcon_array_update_quick_string(&left, SS("domain"), 542597917UL, &intermediate_model_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&left, SS("name"), 268211462UL, &intermediate_referenced_fields, PH_COPY | PH_SEPARATE); + RETURN_MM(); + } - PHALCON_INIT_NVAR(left_expr); - phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); + RETURN_CCTOR(messages); + } - PHALCON_INIT_NVAR(right); - array_init_size(right, 3); - add_assoc_stringl_ex(right, SS("type"), SL("qualified"), 1); - phalcon_array_update_quick_string(&right, SS("domain"), 542597917UL, &referenced_model_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&right, SS("name"), 268211462UL, &referenced_fields, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(group); + object_init_ex(group, phalcon_validation_message_group_ce); + phalcon_call_method_key(NULL, group, "__construct", 1107214344UL); - PHALCON_INIT_NVAR(right_expr); - phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); + phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(sql_join_condition_second); - array_init_size(sql_join_condition_second, 4); - add_assoc_stringl_ex(sql_join_condition_second, SS("type"), SL("binary-op"), 1); - add_assoc_stringl_ex(sql_join_condition_second, SS("op"), SL("="), 1); - phalcon_array_update_quick_string(&sql_join_condition_second, SS("left"), 265976240UL, &left_expr, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_join_condition_second, SS("right"), 426864067UL, &right_expr, PH_COPY | PH_SEPARATE); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(sql_join_conditions_second); - array_init_size(sql_join_conditions_second, 1); - phalcon_array_append(&sql_join_conditions_second, sql_join_condition_second, PH_SEPARATE); + PHALCON_GET_HKEY(element, ah0, hp0); + PHALCON_GET_HVALUE(element_messages); - PHALCON_INIT_VAR(sql_join_second); - array_init_size(sql_join_second, 3); - phalcon_array_update_quick_string(&sql_join_second, SS("type"), 276192743UL, &join_type, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_join_second, SS("source"), 2744839734UL, &join_source, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_join_second, SS("conditions"), 1055696255UL, &sql_join_conditions_second, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&sql_joins, 0, &sql_join_first, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&sql_joins, 1, &sql_join_second, PH_COPY | PH_SEPARATE); + phalcon_call_method_p1_key(NULL, group, "appendmessages", element_messages, 3314726677UL); + + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CTOR(sql_joins); + RETURN_CTOR(group); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getJoins){ +static PHP_METHOD(Phalcon_Forms_Form, getMessagesFor){ - zval *select, *models, *sql_aliases, *sql_aliases_models; - zval *sql_models_aliases, *sql_aliases_models_instances; - zval *models_instances, *from_models = NULL, *sql_joins = NULL; - zval *join_models, *join_sources, *join_types; - zval *join_pre_condition, *join_prepared; - zval *manager = NULL, *joins, *select_joins = NULL, *join_item = NULL; - zval *join_data = NULL, *source = NULL, *schema = NULL, *model = NULL, *model_name = NULL; - zval *complete_source = NULL, *join_type = NULL, *alias_expr = NULL; - zval *alias = NULL, *phql = NULL, *exception_message = NULL, *join_alias_name = NULL; - zval *join_expr = NULL, *pre_condition = NULL, *from_model_name = NULL; - zval *join_model = NULL, *join_alias = NULL, *join_source = NULL; - zval *model_name_alias = NULL, *relation = NULL, *relations = NULL; - zval *number_relations = NULL, *model_alias = NULL, *is_through = NULL; - zval *sql_join = NULL, *new_sql_joins = NULL, *sql_join_conditions = NULL; - HashTable *ah0, *ah1, *ah2, *ah3; - HashPosition hp0, hp1, hp2, hp3; - zval **hd; + zval *name, *messages, *element_messages, *group; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &select); - - PHALCON_OBS_VAR(models); - phalcon_read_property_this_quick(&models, this_ptr, SL("_models"), 4175729768UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 0, &name); - PHALCON_OBS_VAR(sql_aliases); - phalcon_read_property_this_quick(&sql_aliases, this_ptr, SL("_sqlAliases"), 3407085878UL, PH_NOISY_CC); + PHALCON_OBS_VAR(messages); + phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); + if (phalcon_array_isset(messages, name)) { + PHALCON_OBS_VAR(element_messages); + phalcon_array_fetch(&element_messages, messages, name, PH_NOISY); + RETURN_CCTOR(element_messages); + } - PHALCON_OBS_VAR(sql_aliases_models); - phalcon_read_property_this_quick(&sql_aliases_models, this_ptr, SL("_sqlAliasesModels"), 848643194UL, PH_NOISY_CC); + PHALCON_INIT_VAR(group); + object_init_ex(group, phalcon_validation_message_group_ce); + phalcon_call_method_key(NULL, group, "__construct", 1107214344UL); - PHALCON_OBS_VAR(sql_models_aliases); - phalcon_read_property_this_quick(&sql_models_aliases, this_ptr, SL("_sqlModelsAliases"), 1781491322UL, PH_NOISY_CC); + phalcon_update_property_array(this_ptr, SL("_messages"), name, group TSRMLS_CC); - PHALCON_OBS_VAR(sql_aliases_models_instances); - phalcon_read_property_this_quick(&sql_aliases_models_instances, this_ptr, SL("_sqlAliasesModelsInstances"), 3347052930UL, PH_NOISY_CC); + RETURN_CTOR(group); +} + +static PHP_METHOD(Phalcon_Forms_Form, hasMessagesFor){ + + zval *name, *messages, *element_messages; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - PHALCON_OBS_VAR(models_instances); - phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); - PHALCON_CPY_WRT(from_models, models); + PHALCON_OBS_VAR(messages); + phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); + if (phalcon_array_isset(messages, name)) { + PHALCON_OBS_VAR(element_messages); + phalcon_array_fetch(&element_messages, messages, name, PH_NOISY); + RETURN_CCTOR(element_messages); + } - PHALCON_INIT_VAR(sql_joins); - array_init(sql_joins); + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Forms_Form, add){ + + zval *element, *name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &element); - PHALCON_INIT_VAR(join_models); - array_init(join_models); + if (Z_TYPE_P(element) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The element is not valid"); + return; + } - PHALCON_INIT_VAR(join_sources); - array_init(join_sources); + PHALCON_INIT_VAR(name); + phalcon_call_method_key(name, element, "getname", 4286441094UL); - PHALCON_INIT_VAR(join_types); - array_init(join_types); + phalcon_call_method_p1_key(NULL, element, "setform", this_ptr, 302702757UL); - PHALCON_INIT_VAR(join_pre_condition); - array_init(join_pre_condition); + phalcon_update_property_array(this_ptr, SL("_elements"), name, element TSRMLS_CC); - PHALCON_INIT_VAR(join_prepared); - array_init(join_prepared); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Forms_Form, render){ + + zval *name, *attributes = NULL, *elements, *exception_message; + zval *element, *code; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &name, &attributes); - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + if (!attributes) { + PHALCON_INIT_VAR(attributes); + } - PHALCON_OBS_VAR(joins); - phalcon_array_fetch_quick_string(&joins, select, SS("joins"), 120974824UL, PH_NOISY); - if (!phalcon_array_isset_long(joins, 0)) { - PHALCON_INIT_VAR(select_joins); - array_init_size(select_joins, 1); - phalcon_array_append(&select_joins, joins, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(select_joins, joins); + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The name must be a string"); + return; } - phalcon_is_iterable(select_joins, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); + if (!phalcon_array_isset(elements, name)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); + return; + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_VAR(element); + phalcon_array_fetch(&element, elements, name, PH_NOISY); - PHALCON_GET_HVALUE(join_item); + PHALCON_INIT_VAR(code); + phalcon_call_method_p1_key(code, element, "render", attributes, 1053215877UL); - PHALCON_INIT_NVAR(join_data); - phalcon_call_method_p2_key(join_data, this_ptr, "_getjoin", manager, join_item, 2949927412UL); + RETURN_CCTOR(code); +} + +static PHP_METHOD(Phalcon_Forms_Form, get){ + + zval *name, *elements, *exception_message, *element; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - PHALCON_OBS_NVAR(source); - phalcon_array_fetch_quick_string(&source, join_data, SS("source"), 2744839734UL, PH_NOISY); + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); + if (!phalcon_array_isset(elements, name)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); + return; + } - PHALCON_OBS_NVAR(schema); - phalcon_array_fetch_quick_string(&schema, join_data, SS("schema"), 2259341622UL, PH_NOISY); + PHALCON_OBS_VAR(element); + phalcon_array_fetch(&element, elements, name, PH_NOISY); - PHALCON_OBS_NVAR(model); - phalcon_array_fetch_quick_string(&model, join_data, SS("model"), 238191286UL, PH_NOISY); + RETURN_CCTOR(element); +} + +static PHP_METHOD(Phalcon_Forms_Form, label){ + + zval *name, *elements, *exception_message, *element; + zval *html; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - PHALCON_OBS_NVAR(model_name); - phalcon_array_fetch_quick_string(&model_name, join_data, SS("modelName"), 440103543UL, PH_NOISY); + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); + if (!phalcon_array_isset(elements, name)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); + return; + } - PHALCON_INIT_NVAR(complete_source); - array_init_size(complete_source, 2); - phalcon_array_append(&complete_source, source, PH_SEPARATE); - phalcon_array_append(&complete_source, schema, PH_SEPARATE); + PHALCON_OBS_VAR(element); + phalcon_array_fetch(&element, elements, name, PH_NOISY); - PHALCON_INIT_NVAR(join_type); - phalcon_call_method_p1_key(join_type, this_ptr, "_getjointype", join_item, 1296796086UL); + PHALCON_INIT_VAR(html); + phalcon_call_method_key(html, element, "label", 182381125UL); - if (phalcon_array_isset_quick_string(join_item, SS("alias"), 4060151663UL)) { + RETURN_CCTOR(html); +} + +static PHP_METHOD(Phalcon_Forms_Form, getLabel){ + + zval *name, *elements, *exception_message, *element; + zval *label; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - PHALCON_OBS_NVAR(alias_expr); - phalcon_array_fetch_quick_string(&alias_expr, join_item, SS("alias"), 4060151663UL, PH_NOISY); + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); + if (!phalcon_array_isset(elements, name)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); + return; + } - PHALCON_OBS_NVAR(alias); - phalcon_array_fetch_quick_string(&alias, alias_expr, SS("name"), 268211462UL, PH_NOISY); + PHALCON_OBS_VAR(element); + phalcon_array_fetch(&element, elements, name, PH_NOISY); - if (phalcon_array_isset(join_models, alias)) { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + PHALCON_INIT_VAR(label); + phalcon_call_method_key(label, element, "getlabel", 3934940101UL); - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Cannot use '", alias, "' as join alias because it was already used"); - PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + if (!zend_is_true(label)) { + RETURN_CCTOR(name); + } - phalcon_array_append(&complete_source, alias, PH_SEPARATE); + RETURN_CCTOR(label); +} + +static PHP_METHOD(Phalcon_Forms_Form, getValue){ + + zval *name, *entity, *method, *value = NULL, *data; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - phalcon_array_update_zval(&join_types, alias, &join_type, PH_COPY | PH_SEPARATE); + PHALCON_OBS_VAR(entity); + phalcon_read_property_this_quick(&entity, this_ptr, SL("_entity"), 2413912609UL, PH_NOISY_CC); + if (Z_TYPE_P(entity) == IS_OBJECT) { - phalcon_array_update_zval(&sql_aliases, alias, &alias, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(method); + PHALCON_CONCAT_SV(method, "get", name); + if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { + phalcon_call_method_zval(return_value, entity, method); + RETURN_MM(); + } - phalcon_array_update_zval(&join_models, alias, &model_name, PH_COPY | PH_SEPARATE); + if (phalcon_isset_property_zval(entity, name TSRMLS_CC)) { + PHALCON_OBS_VAR(value); + phalcon_read_property_zval(&value, entity, name, PH_NOISY_CC); + RETURN_CCTOR(value); + } + } - phalcon_array_update_zval(&sql_models_aliases, model_name, &alias, PH_COPY | PH_SEPARATE); + PHALCON_OBS_VAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + if (Z_TYPE_P(data) == IS_ARRAY) { - phalcon_array_update_zval(&sql_aliases_models, alias, &model_name, PH_COPY | PH_SEPARATE); + if (phalcon_array_isset(data, name)) { + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, data, name, PH_NOISY); + RETURN_CCTOR(value); + } + } - phalcon_array_update_zval(&sql_aliases_models_instances, alias, &model, PH_COPY | PH_SEPARATE); + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Forms_Form, has){ + + zval *name, *elements; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - phalcon_array_update_zval(&models, model_name, &alias, PH_COPY | PH_SEPARATE); + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - phalcon_array_update_zval(&join_sources, alias, &complete_source, PH_COPY | PH_SEPARATE); + if (phalcon_array_isset(elements, name)) { + RETURN_MM_TRUE; + } - phalcon_array_update_zval(&join_prepared, alias, &join_item, PH_COPY | PH_SEPARATE); - } else { - if (phalcon_array_isset(join_models, model_name)) { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Forms_Form, remove){ + + zval *name, *elements; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Cannot use '", model_name, "' as join alias because it was already used"); - PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - phalcon_array_update_zval(&join_types, model_name, &join_type, PH_COPY | PH_SEPARATE); + if (phalcon_array_isset(elements, name)) { + phalcon_unset_property_array(this_ptr, SL("_elements"), name TSRMLS_CC); + RETURN_MM_TRUE; + } - phalcon_array_update_zval(&sql_aliases, model_name, &source, PH_COPY | PH_SEPARATE); + phalcon_update_property_null(this_ptr, SL("_elementsIndexed") TSRMLS_CC); + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Forms_Form, clear){ + + zval *fields = NULL, *elements, *element = NULL, *name = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &fields); - phalcon_array_update_zval(&join_models, model_name, &source, PH_COPY | PH_SEPARATE); + if (!fields) { + PHALCON_INIT_VAR(fields); + } - phalcon_array_update_zval(&sql_models_aliases, model_name, &model_name, PH_COPY | PH_SEPARATE); + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); + if (Z_TYPE_P(elements) == IS_ARRAY) { - phalcon_array_update_zval(&sql_aliases_models, model_name, &model_name, PH_COPY | PH_SEPARATE); + phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); - phalcon_array_update_zval(&sql_aliases_models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - phalcon_array_update_zval(&models, model_name, &source, PH_COPY | PH_SEPARATE); + PHALCON_GET_HVALUE(element); - phalcon_array_update_zval(&join_sources, model_name, &complete_source, PH_COPY | PH_SEPARATE); + if (Z_TYPE_P(fields) != IS_ARRAY) { + phalcon_call_method_key(NULL, element, "clear", 4138278668UL); + } else { + PHALCON_INIT_NVAR(name); + phalcon_call_method_key(name, element, "getname", 4286441094UL); + if (phalcon_fast_in_array(name, fields TSRMLS_CC)) { + phalcon_call_method_key(NULL, element, "clear", 4138278668UL); + } + } - phalcon_array_update_zval(&join_prepared, model_name, &join_item, PH_COPY | PH_SEPARATE); + zend_hash_move_forward_ex(ah0, &hp0); } - phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); } - phalcon_update_property_this_quick(this_ptr, SL("_models"), models, 4175729768UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlAliases"), sql_aliases, 3407085878UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModels"), sql_aliases_models, 848643194UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlModelsAliases"), sql_models_aliases, 1781491322UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModelsInstances"), sql_aliases_models_instances, 3347052930UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_modelsInstances"), models_instances, 457905456UL TSRMLS_CC); - - phalcon_is_iterable(join_prepared, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Forms_Form, count){ + + zval *elements; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); + phalcon_fast_count(return_value, elements TSRMLS_CC); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Forms_Form, rewind){ + + zval *elements, *elements_indexed; + + PHALCON_MM_GROW(); + + phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC); - PHALCON_GET_HKEY(join_alias_name, ah1, hp1); - PHALCON_GET_HVALUE(join_item); + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(join_item, SS("conditions"), 1055696255UL)) { - PHALCON_OBS_NVAR(join_expr); - phalcon_array_fetch_quick_string(&join_expr, join_item, SS("conditions"), 1055696255UL, PH_NOISY); + PHALCON_INIT_VAR(elements_indexed); + phalcon_call_func_p1(elements_indexed, "array_values", elements); + phalcon_update_property_this_quick(this_ptr, SL("_elementsIndexed"), elements_indexed, 4269762082UL TSRMLS_CC); - PHALCON_INIT_NVAR(pre_condition); - phalcon_call_method_p1_key(pre_condition, this_ptr, "_getexpression", join_expr, 2816780276UL); - phalcon_array_update_zval(&join_pre_condition, join_alias_name, &pre_condition, PH_COPY | PH_SEPARATE); - } + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Forms_Form, current){ + + zval *position, *elements, *element; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(position); + phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); - zend_hash_move_forward_ex(ah1, &hp1); + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elementsIndexed"), 4269762082UL, PH_NOISY_CC); + if (phalcon_array_isset(elements, position)) { + PHALCON_OBS_VAR(element); + phalcon_array_fetch(&element, elements, position, PH_NOISY); + RETURN_CCTOR(element); } - PHALCON_OBS_NVAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - - phalcon_is_iterable(from_models, &ah2, &hp2, 0, 0); - - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - - PHALCON_GET_HKEY(from_model_name, ah2, hp2); - PHALCON_GET_HVALUE(source); - - phalcon_is_iterable(join_models, &ah3, &hp3, 0, 0); - - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - - PHALCON_GET_HKEY(join_alias, ah3, hp3); - PHALCON_GET_HVALUE(join_model); - - PHALCON_OBS_NVAR(join_source); - phalcon_array_fetch(&join_source, join_sources, join_alias, PH_NOISY); - - PHALCON_OBS_NVAR(join_type); - phalcon_array_fetch(&join_type, join_types, join_alias, PH_NOISY); - - if (!phalcon_array_isset(join_pre_condition, join_alias)) { + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Forms_Form, key){ + + + RETURN_MEMBER_QUICK(this_ptr, "_position", 2925265369UL); +} + +static PHP_METHOD(Phalcon_Forms_Form, next){ + + + phalcon_property_incr(this_ptr, SL("_position") TSRMLS_CC); - PHALCON_OBS_NVAR(model_name_alias); - phalcon_array_fetch(&model_name_alias, sql_aliases_models, join_alias, PH_NOISY); +} + +static PHP_METHOD(Phalcon_Forms_Form, valid){ + + zval *position, *elements; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(position); + phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(relation); - phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", from_model_name, model_name_alias, 785467656UL); - if (PHALCON_IS_FALSE(relation)) { + PHALCON_OBS_VAR(elements); + phalcon_read_property_this_quick(&elements, this_ptr, SL("_elementsIndexed"), 4269762082UL, PH_NOISY_CC); + if (phalcon_array_isset(elements, position)) { + RETURN_MM_TRUE; + } - PHALCON_INIT_NVAR(relations); - phalcon_call_method_p2_key(relations, manager, "getrelationsbetween", from_model_name, model_name_alias, 3538247200UL); - if (Z_TYPE_P(relations) == IS_ARRAY) { + RETURN_MM_FALSE; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Forms_Manager){ + + PHALCON_REGISTER_CLASS(Phalcon\\Forms, Manager, forms_manager, phalcon_forms_manager_method_entry, 0); + + zend_declare_property_null(phalcon_forms_manager_ce, SL("_forms"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Forms_Manager, create){ + + zval *name = NULL, *entity = NULL, *form; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &name, &entity); - PHALCON_INIT_NVAR(number_relations); - phalcon_fast_count(number_relations, relations TSRMLS_CC); - if (!PHALCON_IS_LONG(number_relations, 1)) { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + if (!name) { + PHALCON_INIT_VAR(name); + } - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVS(exception_message, "There is more than one relation between models '", model_name, "' and '", join_model, "\", the join must be done using an alias"); - PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + if (!entity) { + PHALCON_INIT_VAR(entity); + } - PHALCON_OBS_NVAR(relation); - phalcon_array_fetch_long(&relation, relations, 0, PH_NOISY); - } - } + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The form name must be string"); + return; + } - if (Z_TYPE_P(relation) == IS_OBJECT) { + PHALCON_INIT_VAR(form); + object_init_ex(form, phalcon_forms_form_ce); + phalcon_call_method_p1_key(NULL, form, "__construct", entity, 1107214344UL); - PHALCON_OBS_NVAR(model_alias); - phalcon_array_fetch(&model_alias, sql_models_aliases, from_model_name, PH_NOISY); + phalcon_update_property_array(this_ptr, SL("_forms"), name, form TSRMLS_CC); - PHALCON_INIT_NVAR(is_through); - phalcon_call_method_key(is_through, relation, "isthrough", 2540564770UL); - if (!zend_is_true(is_through)) { - PHALCON_INIT_NVAR(sql_join); - phalcon_call_method_p5(sql_join, this_ptr, "_getsinglejoin", join_type, join_source, model_alias, join_alias, relation); - } else { - PHALCON_INIT_NVAR(sql_join); - phalcon_call_method_p5(sql_join, this_ptr, "_getmultijoin", join_type, join_source, model_alias, join_alias, relation); - } + RETURN_CTOR(form); +} + +static PHP_METHOD(Phalcon_Forms_Manager, get){ + + zval *name, *forms, *exception_message, *form; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - if (phalcon_array_isset_long(sql_join, 0)) { - PHALCON_INIT_NVAR(new_sql_joins); - phalcon_fast_array_merge(new_sql_joins, &sql_joins, &sql_join TSRMLS_CC); - PHALCON_CPY_WRT(sql_joins, new_sql_joins); - } else { - phalcon_array_append(&sql_joins, sql_join, PH_SEPARATE); - } - } else { - PHALCON_INIT_NVAR(sql_join_conditions); - array_init(sql_join_conditions); + PHALCON_OBS_VAR(forms); + phalcon_read_property_this_quick(&forms, this_ptr, SL("_forms"), 2325961419UL, PH_NOISY_CC); + if (!phalcon_array_isset(forms, name)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "There is no form with name='", name, "'"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); + return; + } - PHALCON_INIT_NVAR(sql_join); - array_init_size(sql_join, 3); - phalcon_array_update_quick_string(&sql_join, SS("type"), 276192743UL, &join_type, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_join, SS("source"), 2744839734UL, &join_source, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_join, SS("conditions"), 1055696255UL, &sql_join_conditions, PH_COPY | PH_SEPARATE); - phalcon_array_append(&sql_joins, sql_join, PH_SEPARATE); - } - } else { - PHALCON_OBS_NVAR(pre_condition); - phalcon_array_fetch(&pre_condition, join_pre_condition, join_alias, PH_NOISY); + PHALCON_OBS_VAR(form); + phalcon_array_fetch(&form, forms, name, PH_NOISY); - PHALCON_INIT_NVAR(sql_join_conditions); - array_init_size(sql_join_conditions, 1); - phalcon_array_append(&sql_join_conditions, pre_condition, PH_SEPARATE); + RETURN_CCTOR(form); +} + +static PHP_METHOD(Phalcon_Forms_Manager, has){ + + zval *name, *forms; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - PHALCON_INIT_NVAR(sql_join); - array_init_size(sql_join, 3); - phalcon_array_update_quick_string(&sql_join, SS("type"), 276192743UL, &join_type, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_join, SS("source"), 2744839734UL, &join_source, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_join, SS("conditions"), 1055696255UL, &sql_join_conditions, PH_COPY | PH_SEPARATE); - phalcon_array_append(&sql_joins, sql_join, PH_SEPARATE); - } + PHALCON_OBS_VAR(forms); + phalcon_read_property_this_quick(&forms, this_ptr, SL("_forms"), 2325961419UL, PH_NOISY_CC); + if (!phalcon_array_isset(forms, name)) { + RETURN_MM_TRUE; + } - zend_hash_move_forward_ex(ah3, &hp3); - } + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Forms_Manager, set){ + + zval *name, *form; + + phalcon_fetch_params(0, 2, 0, &name, &form); - zend_hash_move_forward_ex(ah2, &hp2); + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The form name must be string"); + return; + } + if (Z_TYPE_P(form) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The form is not valid"); + return; } - RETURN_CCTOR(sql_joins); + phalcon_update_property_array(this_ptr, SL("_forms"), name, form TSRMLS_CC); + + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getOrderClause){ - zval *order, *order_columns = NULL, *order_parts, *order_item = NULL; - zval *order_column = NULL, *order_part_expr = NULL, *order_sort = NULL; - zval *order_part_sort = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Http_Cookie_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Http\\Cookie, Exception, http_cookie_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Http_Cookie){ + + PHALCON_REGISTER_CLASS(Phalcon\\Http, Cookie, http_cookie, phalcon_http_cookie_method_entry, 0); + + zend_declare_property_bool(phalcon_http_cookie_ce, SL("_readed"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_http_cookie_ce, SL("_restored"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_http_cookie_ce, SL("_useEncryption"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_cookie_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_cookie_ce, SL("_filter"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_cookie_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_cookie_ce, SL("_value"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_cookie_ce, SL("_expire"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_http_cookie_ce, SL("_path"), "/", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_cookie_ce, SL("_domain"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_cookie_ce, SL("_secure"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_http_cookie_ce, SL("_httpOnly"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_http_cookie_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Http_Cookie, __construct){ + + zval *name, *value = NULL, *expire = NULL, *path = NULL, *secure = NULL, *domain = NULL; + zval *http_only = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &order); + phalcon_fetch_params(1, 1, 6, &name, &value, &expire, &path, &secure, &domain, &http_only); - if (!phalcon_array_isset_long(order, 0)) { - PHALCON_INIT_VAR(order_columns); - array_init_size(order_columns, 1); - phalcon_array_append(&order_columns, order, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(order_columns, order); + if (!value) { + PHALCON_INIT_VAR(value); } - PHALCON_INIT_VAR(order_parts); - array_init(order_parts); + if (!expire) { + PHALCON_INIT_VAR(expire); + ZVAL_LONG(expire, 0); + } - phalcon_is_iterable(order_columns, &ah0, &hp0, 0, 0); + if (!path) { + PHALCON_INIT_VAR(path); + ZVAL_STRING(path, "/", 1); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_cookie_exception_ce, "The cookie name must be string"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); + if (Z_TYPE_P(value) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_value"), value, 2935317441UL TSRMLS_CC); + } - PHALCON_GET_HVALUE(order_item); + phalcon_update_property_this_quick(this_ptr, SL("_expire"), expire, 2800520017UL TSRMLS_CC); + if (Z_TYPE_P(path) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_path"), path, 3986357393UL TSRMLS_CC); + } - PHALCON_OBS_NVAR(order_column); - phalcon_array_fetch_quick_string(&order_column, order_item, SS("column"), 3545634419UL, PH_NOISY); + if (secure && Z_TYPE_P(secure) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_secure"), secure, 2942644203UL TSRMLS_CC); + } - PHALCON_INIT_NVAR(order_part_expr); - phalcon_call_method_p1_key(order_part_expr, this_ptr, "_getexpression", order_column, 2816780276UL); + if (domain && Z_TYPE_P(domain) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_domain"), domain, 1152978748UL TSRMLS_CC); + } - if (phalcon_array_isset_quick_string(order_item, SS("sort"), 274650125UL)) { + if (http_only && Z_TYPE_P(http_only) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_httpOnly"), http_only, 41231174UL TSRMLS_CC); + } - PHALCON_OBS_NVAR(order_sort); - phalcon_array_fetch_quick_string(&order_sort, order_item, SS("sort"), 274650125UL, PH_NOISY); - if (PHALCON_IS_LONG(order_sort, 327)) { - PHALCON_INIT_NVAR(order_part_sort); - array_init_size(order_part_sort, 2); - phalcon_array_append(&order_part_sort, order_part_expr, PH_SEPARATE); - add_next_index_stringl(order_part_sort, SL("ASC"), 1); - } else { - PHALCON_INIT_NVAR(order_part_sort); - array_init_size(order_part_sort, 2); - phalcon_array_append(&order_part_sort, order_part_expr, PH_SEPARATE); - add_next_index_stringl(order_part_sort, SL("DESC"), 1); - } - } else { - PHALCON_INIT_NVAR(order_part_sort); - array_init_size(order_part_sort, 1); - phalcon_array_append(&order_part_sort, order_part_expr, PH_SEPARATE); - } + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Http_Cookie, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); - phalcon_array_append(&order_parts, order_part_sort, PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - zend_hash_move_forward_ex(ah0, &hp0); - } +} + +static PHP_METHOD(Phalcon_Http_Cookie, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} + +static PHP_METHOD(Phalcon_Http_Cookie, setValue){ + + zval *value; + + phalcon_fetch_params(0, 1, 0, &value); - RETURN_CTOR(order_parts); + phalcon_update_property_this_quick(this_ptr, SL("_value"), value, 2935317441UL TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_readed"), 1 TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getGroupClause){ +static PHP_METHOD(Phalcon_Http_Cookie, getValue){ - zval *group, *group_parts = NULL, *group_item = NULL, *group_part_expr = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *filters = NULL, *default_value = NULL, *restored, *dependency_injector = NULL; + zval *readed, *name, *_COOKIE, *value = NULL, *encryption; + zval *service = NULL, *crypt, *decrypted_value = NULL, *filter = NULL; + zval *sanitized_value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &group); + phalcon_fetch_params(1, 0, 2, &filters, &default_value); - if (phalcon_array_isset_long(group, 0)) { + if (!filters) { + PHALCON_INIT_VAR(filters); + } - PHALCON_INIT_VAR(group_parts); - array_init(group_parts); + if (!default_value) { + PHALCON_INIT_VAR(default_value); + } - phalcon_is_iterable(group, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { + phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(dependency_injector); - PHALCON_GET_HVALUE(group_item); + PHALCON_OBS_VAR(readed); + phalcon_read_property_this_quick(&readed, this_ptr, SL("_readed"), 1648179273UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(readed)) { - PHALCON_INIT_NVAR(group_part_expr); - phalcon_call_method_p1_key(group_part_expr, this_ptr, "_getexpression", group_item, 2816780276UL); - phalcon_array_append(&group_parts, group_part_expr, PH_SEPARATE); + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); + phalcon_get_global(&_COOKIE, SS("_COOKIE") TSRMLS_CC); + if (phalcon_array_isset(_COOKIE, name)) { - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, _COOKIE, name, PH_NOISY); - } else { - PHALCON_INIT_NVAR(group_part_expr); - phalcon_call_method_p1_key(group_part_expr, this_ptr, "_getexpression", group, 2816780276UL); + PHALCON_OBS_VAR(encryption); + phalcon_read_property_this_quick(&encryption, this_ptr, SL("_useEncryption"), 2628069468UL, PH_NOISY_CC); + if (zend_is_true(encryption)) { - PHALCON_INIT_NVAR(group_parts); - array_init_size(group_parts, 1); - phalcon_array_append(&group_parts, group_part_expr, PH_SEPARATE); - } + PHALCON_OBS_NVAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "A dependency injection object is required to access the 'filter' service"); + return; + } - RETURN_CTOR(group_parts); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareSelect){ - - zval *ast, *select, *sql_models, *sql_tables, *sql_aliases; - zval *sql_columns, *sql_aliases_models, *sql_models_aliases; - zval *sql_aliases_models_instances, *models; - zval *models_instances, *tables, *selected_models = NULL; - zval *manager, *meta_data, *selected_model = NULL, *qualified_name = NULL; - zval *model_name = NULL, *ns_alias = NULL, *real_namespace = NULL; - zval *real_model_name = NULL, *model = NULL, *schema = NULL, *source = NULL; - zval *complete_source = NULL, *alias = NULL, *phql = NULL, *exception_message = NULL; - zval *joins, *sql_joins = NULL, *columns, *select_columns = NULL; - zval *position, *sql_column_aliases, *column = NULL; - zval *sql_column_group = NULL, *sql_column = NULL, *type = NULL, *sql_select; - zval *where, *where_expr, *group_by, *sql_group; - zval *having, *having_expr, *order, *sql_order; - zval *limit; - HashTable *ah0, *ah1, *ah2; - HashPosition hp0, hp1, hp2; - zval **hd; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(ast); - phalcon_read_property_this_quick(&ast, this_ptr, SL("_ast"), 250429676UL, PH_NOISY_CC); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "crypt", 1); - PHALCON_OBS_VAR(select); - phalcon_array_fetch_quick_string(&select, ast, SS("select"), 2342345829UL, PH_NOISY); - if (!phalcon_array_isset_quick_string(select, SS("tables"), 3465666720UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); - return; - } + PHALCON_INIT_VAR(crypt); + phalcon_call_method_p1_key(crypt, dependency_injector, "getshared", service, 1727570332UL); - if (!phalcon_array_isset_quick_string(select, SS("columns"), 1041822630UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); - return; - } + PHALCON_INIT_VAR(decrypted_value); + phalcon_call_method_p1_key(decrypted_value, crypt, "decryptbase64", value, 588154501UL); + } else { + PHALCON_CPY_WRT(decrypted_value, value); + } - PHALCON_INIT_VAR(sql_models); - array_init(sql_models); + phalcon_update_property_this_quick(this_ptr, SL("_value"), decrypted_value, 2935317441UL TSRMLS_CC); + if (Z_TYPE_P(filters) != IS_NULL) { - PHALCON_INIT_VAR(sql_tables); - array_init(sql_tables); + PHALCON_OBS_VAR(filter); + phalcon_read_property_this_quick(&filter, this_ptr, SL("_filter"), 3500594986UL, PH_NOISY_CC); + if (Z_TYPE_P(filter) != IS_OBJECT) { + if (Z_TYPE_P(dependency_injector) == IS_NULL) { - PHALCON_INIT_VAR(sql_aliases); - array_init(sql_aliases); + PHALCON_OBS_NVAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "A dependency injection object is required to access the 'filter' service"); + return; + } + } - PHALCON_INIT_VAR(sql_columns); - array_init(sql_columns); + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "filter", 1); - PHALCON_INIT_VAR(sql_aliases_models); - array_init(sql_aliases_models); + PHALCON_INIT_NVAR(filter); + phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service, 1727570332UL); + phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); + } - PHALCON_INIT_VAR(sql_models_aliases); - array_init(sql_models_aliases); + PHALCON_INIT_VAR(sanitized_value); + phalcon_call_method_p2_key(sanitized_value, filter, "sanitize", decrypted_value, filters, 3688332940UL); - PHALCON_INIT_VAR(sql_aliases_models_instances); - array_init(sql_aliases_models_instances); + RETURN_CCTOR(sanitized_value); + } - PHALCON_INIT_VAR(models); - array_init(models); - PHALCON_INIT_VAR(models_instances); - array_init(models_instances); + RETURN_CCTOR(decrypted_value); + } - PHALCON_OBS_VAR(tables); - phalcon_array_fetch_quick_string(&tables, select, SS("tables"), 3465666720UL, PH_NOISY); - if (!phalcon_array_isset_long(tables, 0)) { - PHALCON_INIT_VAR(selected_models); - array_init_size(selected_models, 1); - phalcon_array_append(&selected_models, tables, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(selected_models, tables); + RETURN_CCTOR(default_value); } - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - - phalcon_is_iterable(selected_models, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(selected_model); - - PHALCON_OBS_NVAR(qualified_name); - phalcon_array_fetch_quick_string(&qualified_name, selected_model, SS("qualifiedName"), 2418332666UL, PH_NOISY); - - PHALCON_OBS_NVAR(model_name); - phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); - - if (phalcon_array_isset_quick_string(qualified_name, SS("ns-alias"), 2470863549UL)) { - PHALCON_OBS_NVAR(ns_alias); - phalcon_array_fetch_quick_string(&ns_alias, qualified_name, SS("ns-alias"), 2470863549UL, PH_NOISY); - - PHALCON_INIT_NVAR(real_namespace); - phalcon_call_method_p1_key(real_namespace, manager, "getnamespacealias", ns_alias, 3487123420UL); - - PHALCON_INIT_NVAR(real_model_name); - PHALCON_CONCAT_VSV(real_model_name, real_namespace, "\\", model_name); - } else { - PHALCON_CPY_WRT(real_model_name, model_name); - } + PHALCON_OBS_NVAR(value); + phalcon_read_property_this_quick(&value, this_ptr, SL("_value"), 2935317441UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(model); - phalcon_call_method_p1_key(model, manager, "load", real_model_name, 266329637UL); + RETURN_CCTOR(value); +} + +static PHP_METHOD(Phalcon_Http_Cookie, send){ + + zval *name, *value, *expire, *domain, *path, *secure; + zval *http_only, *dependency_injector, *definition; + zval *service = NULL, *session, *key, *encryption, *crypt; + zval *encrypt_value = NULL, *has_session; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(schema); - phalcon_call_method_key(schema, model, "getschema", 1539736246UL); + PHALCON_OBS_VAR(value); + phalcon_read_property_this_quick(&value, this_ptr, SL("_value"), 2935317441UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(source); - phalcon_call_method_key(source, model, "getsource", 2025234358UL); + PHALCON_OBS_VAR(expire); + phalcon_read_property_this_quick(&expire, this_ptr, SL("_expire"), 2800520017UL, PH_NOISY_CC); - if (zend_is_true(schema)) { - PHALCON_INIT_NVAR(complete_source); - array_init_size(complete_source, 2); - phalcon_array_append(&complete_source, source, PH_SEPARATE); - phalcon_array_append(&complete_source, schema, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(complete_source, source); - } + PHALCON_OBS_VAR(domain); + phalcon_read_property_this_quick(&domain, this_ptr, SL("_domain"), 1152978748UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(selected_model, SS("alias"), 4060151663UL)) { + PHALCON_OBS_VAR(path); + phalcon_read_property_this_quick(&path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); - PHALCON_OBS_NVAR(alias); - phalcon_array_fetch_quick_string(&alias, selected_model, SS("alias"), 4060151663UL, PH_NOISY); + PHALCON_OBS_VAR(secure); + phalcon_read_property_this_quick(&secure, this_ptr, SL("_secure"), 2942644203UL, PH_NOISY_CC); - if (phalcon_array_isset(sql_aliases, alias)) { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + PHALCON_OBS_VAR(http_only); + phalcon_read_property_this_quick(&http_only, this_ptr, SL("_httpOnly"), 41231174UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Alias \"", alias, " is already used"); - PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + PHALCON_INIT_VAR(service); + PHALCON_INIT_VAR(has_session); + ZVAL_STRING(service, "session", 1); + + phalcon_call_method_p1_key(has_session, dependency_injector, "has", service, 2090320481UL); + if (zend_is_true(has_session)) { + PHALCON_INIT_VAR(definition); + array_init(definition); + if (!PHALCON_IS_LONG(expire, 0)) { + phalcon_array_update_quick_string(&definition, SS("expire"), 2190139186UL, &expire, PH_COPY); } - - phalcon_array_update_zval(&sql_aliases, alias, &alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&sql_aliases_models, alias, &model_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&sql_models_aliases, model_name, &alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&sql_aliases_models_instances, alias, &model, PH_COPY | PH_SEPARATE); - - if (Z_TYPE_P(complete_source) == IS_ARRAY) { - phalcon_array_append(&complete_source, alias, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(complete_source); - array_init_size(complete_source, 3); - phalcon_array_append(&complete_source, source, PH_SEPARATE); - add_next_index_null(complete_source); - phalcon_array_append(&complete_source, alias, PH_SEPARATE); + + if (PHALCON_IS_NOT_EMPTY(path)) { + phalcon_array_update_quick_string(&definition, SS("path"), 270591026UL, &path, PH_COPY); + } + + if (PHALCON_IS_NOT_EMPTY(domain)) { + phalcon_array_update_quick_string(&definition, SS("domain"), 542597917UL, &domain, PH_COPY); + } + + if (PHALCON_IS_NOT_EMPTY(secure)) { + phalcon_array_update_quick_string(&definition, SS("secure"), 2332263372UL, &secure, PH_COPY); + } + + if (PHALCON_IS_NOT_EMPTY(http_only)) { + phalcon_array_update_quick_string(&definition, SS("httpOnly"), 1056437095UL, &http_only, PH_COPY); + } + + if (phalcon_fast_count_ev(definition TSRMLS_CC)) { + + PHALCON_INIT_VAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + + if (Z_TYPE_P(session) != IS_NULL) { + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_SV(key, "_PHCOOKIE_", name); + phalcon_call_method_p2_key(NULL, session, "set", key, definition, 2090720177UL); + } } - - phalcon_array_update_zval(&models, model_name, &alias, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_zval(&sql_aliases, model_name, &source, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&sql_aliases_models, model_name, &model_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&sql_models_aliases, model_name, &model_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&sql_aliases_models_instances, model_name, &model, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&models, model_name, &source, PH_COPY | PH_SEPARATE); } - - phalcon_array_append(&sql_models, model_name, PH_SEPARATE); - phalcon_array_append(&sql_tables, complete_source, PH_SEPARATE); - phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); } - phalcon_update_property_this_quick(this_ptr, SL("_models"), models, 4175729768UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_modelsInstances"), models_instances, 457905456UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlAliases"), sql_aliases, 3407085878UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModels"), sql_aliases_models, 848643194UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlModelsAliases"), sql_models_aliases, 1781491322UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModelsInstances"), sql_aliases_models_instances, 3347052930UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_modelsInstances"), models_instances, 457905456UL TSRMLS_CC); - - if (phalcon_array_isset_quick_string(select, SS("joins"), 120974824UL)) { - - PHALCON_OBS_VAR(joins); - phalcon_array_fetch_quick_string(&joins, select, SS("joins"), 120974824UL, PH_NOISY); - if (phalcon_fast_count_ev(joins TSRMLS_CC)) { - PHALCON_INIT_VAR(sql_joins); - phalcon_call_method_p1_key(sql_joins, this_ptr, "_getjoins", select, 2858327879UL); - } else { - PHALCON_INIT_NVAR(sql_joins); - array_init(sql_joins); + PHALCON_OBS_VAR(encryption); + phalcon_read_property_this_quick(&encryption, this_ptr, SL("_useEncryption"), 2628069468UL, PH_NOISY_CC); + if (zend_is_true(encryption) && PHALCON_IS_NOT_EMPTY(value)) { + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "A dependency injection object is required to access the 'filter' service"); + return; } + + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "crypt", 1); + + PHALCON_INIT_VAR(crypt); + phalcon_call_method_p1_key(crypt, dependency_injector, "getshared", service, 1727570332UL); + + PHALCON_INIT_VAR(encrypt_value); + phalcon_call_method_p1_key(encrypt_value, crypt, "encryptbase64", value, 681973167UL); } else { - PHALCON_INIT_NVAR(sql_joins); - array_init(sql_joins); - } - - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, select, SS("columns"), 1041822630UL, PH_NOISY); - if (!phalcon_array_isset_long(columns, 0)) { - PHALCON_INIT_VAR(select_columns); - array_init_size(select_columns, 1); - phalcon_array_append(&select_columns, columns, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(select_columns, columns); + PHALCON_CPY_WRT(encrypt_value, value); } - PHALCON_INIT_VAR(position); - ZVAL_LONG(position, 0); + convert_to_string_ex(&name); + convert_to_string_ex(&encrypt_value); + convert_to_long_ex(&expire); + convert_to_string_ex(&path); + convert_to_string_ex(&domain); + convert_to_long_ex(&secure); + convert_to_long_ex(&http_only); + + php_setcookie( + Z_STRVAL_P(name), Z_STRLEN_P(name), + Z_STRVAL_P(encrypt_value), Z_STRLEN_P(encrypt_value), + Z_LVAL_P(expire), + Z_STRVAL_P(path), Z_STRLEN_P(path), + Z_STRVAL_P(domain), Z_STRLEN_P(domain), + Z_LVAL_P(secure), + 1, + Z_LVAL_P(http_only) TSRMLS_CC + ); - PHALCON_INIT_VAR(sql_column_aliases); - array_init(sql_column_aliases); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Http_Cookie, restore){ + + zval *restored, *dependency_injector, *service; + zval *session, *name, *key, *definition, *expire, *domain; + zval *path, *secure, *http_only; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { - phalcon_is_iterable(select_columns, &ah1, &hp1, 0, 0); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "session", 1); - PHALCON_GET_HVALUE(column); + PHALCON_INIT_VAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); - PHALCON_INIT_NVAR(sql_column_group); - phalcon_call_method_p1_key(sql_column_group, this_ptr, "_getselectcolumn", column, 3762838962UL); + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - phalcon_is_iterable(sql_column_group, &ah2, &hp2, 0, 0); + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_SV(key, "_PHCOOKIE_", name); - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + PHALCON_INIT_VAR(definition); + phalcon_call_method_p1_key(definition, session, "get", key, 2090288933UL); + if (Z_TYPE_P(definition) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(definition, SS("expire"), 2190139186UL)) { + PHALCON_OBS_VAR(expire); + phalcon_array_fetch_quick_string(&expire, definition, SS("expire"), 2190139186UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_expire"), expire, 2800520017UL TSRMLS_CC); + } + if (phalcon_array_isset_quick_string(definition, SS("domain"), 542597917UL)) { + PHALCON_OBS_VAR(domain); + phalcon_array_fetch_quick_string(&domain, definition, SS("domain"), 542597917UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_domain"), domain, 1152978748UL TSRMLS_CC); + } - PHALCON_GET_HVALUE(sql_column); + if (phalcon_array_isset_quick_string(definition, SS("path"), 270591026UL)) { + PHALCON_OBS_VAR(path); + phalcon_array_fetch_quick_string(&path, definition, SS("path"), 270591026UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_path"), path, 3986357393UL TSRMLS_CC); + } - if (phalcon_array_isset_quick_string(column, SS("alias"), 4060151663UL)) { - PHALCON_OBS_NVAR(alias); - phalcon_array_fetch_quick_string(&alias, column, SS("alias"), 4060151663UL, PH_NOISY); + if (phalcon_array_isset_quick_string(definition, SS("secure"), 2332263372UL)) { + PHALCON_OBS_VAR(secure); + phalcon_array_fetch_quick_string(&secure, definition, SS("secure"), 2332263372UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_secure"), secure, 2942644203UL TSRMLS_CC); + } - phalcon_array_update_quick_string(&sql_column, SS("balias"), 1705826801UL, &alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_column, SS("sqlAlias"), 2820722015UL, &alias, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&sql_columns, alias, &sql_column, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval_bool(&sql_column_aliases, alias, 1, PH_SEPARATE); - } else { - if (phalcon_array_isset_quick_string(sql_column, SS("balias"), 1705826801UL)) { - PHALCON_OBS_NVAR(alias); - phalcon_array_fetch_quick_string(&alias, sql_column, SS("balias"), 1705826801UL, PH_NOISY); - phalcon_array_update_zval(&sql_columns, alias, &sql_column, PH_COPY | PH_SEPARATE); - } else { - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, sql_column, SS("type"), 276192743UL, PH_NOISY); - if (PHALCON_IS_STRING(type, "scalar")) { - PHALCON_INIT_NVAR(alias); - PHALCON_CONCAT_SV(alias, "_", position); - phalcon_array_update_zval(&sql_columns, alias, &sql_column, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_append(&sql_columns, sql_column, PH_SEPARATE); - } + if (phalcon_array_isset_quick_string(definition, SS("httpOnly"), 1056437095UL)) { + PHALCON_OBS_VAR(http_only); + phalcon_array_fetch_quick_string(&http_only, definition, SS("httpOnly"), 1056437095UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_httpOnly"), http_only, 41231174UL TSRMLS_CC); } } - PHALCON_SEPARATE(position); - phalcon_increment(position); - - zend_hash_move_forward_ex(ah2, &hp2); } - zend_hash_move_forward_ex(ah1, &hp1); - } - - phalcon_update_property_this_quick(this_ptr, SL("_sqlColumnAliases"), sql_column_aliases, 3031417188UL TSRMLS_CC); - - PHALCON_INIT_VAR(sql_select); - array_init_size(sql_select, 3); - phalcon_array_update_quick_string(&sql_select, SS("models"), 3565348937UL, &sql_models, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_select, SS("tables"), 3465666720UL, &sql_tables, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_select, SS("columns"), 1041822630UL, &sql_columns, PH_COPY | PH_SEPARATE); - if (phalcon_fast_count_ev(sql_joins TSRMLS_CC)) { - phalcon_array_update_quick_string(&sql_select, SS("joins"), 120974824UL, &sql_joins, PH_COPY | PH_SEPARATE); + phalcon_update_property_bool(this_ptr, SL("_restored"), 1 TSRMLS_CC); } - if (phalcon_array_isset_quick_string(ast, SS("where"), 621293632UL)) { - PHALCON_OBS_VAR(where); - phalcon_array_fetch_quick_string(&where, ast, SS("where"), 621293632UL, PH_NOISY); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Http_Cookie, delete){ + + zval *name, *domain, *path, *secure, *http_only, *dependency_injector; + zval *service, *session, *key; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - PHALCON_INIT_VAR(where_expr); - phalcon_call_method_p1_key(where_expr, this_ptr, "_getexpression", where, 2816780276UL); - phalcon_array_update_quick_string(&sql_select, SS("where"), 621293632UL, &where_expr, PH_COPY | PH_SEPARATE); - } + PHALCON_OBS_VAR(domain); + phalcon_read_property_this_quick(&domain, this_ptr, SL("_domain"), 1152978748UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(ast, SS("groupBy"), 3708772877UL)) { - PHALCON_OBS_VAR(group_by); - phalcon_array_fetch_quick_string(&group_by, ast, SS("groupBy"), 3708772877UL, PH_NOISY); + PHALCON_OBS_VAR(path); + phalcon_read_property_this_quick(&path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); - PHALCON_INIT_VAR(sql_group); - phalcon_call_method_p1_key(sql_group, this_ptr, "_getgroupclause", group_by, 2246953294UL); - phalcon_array_update_quick_string(&sql_select, SS("group"), 7349554UL, &sql_group, PH_COPY | PH_SEPARATE); - } + PHALCON_OBS_VAR(secure); + phalcon_read_property_this_quick(&secure, this_ptr, SL("_secure"), 2942644203UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(ast, SS("having"), 876572994UL)) { - PHALCON_OBS_VAR(having); - phalcon_array_fetch_quick_string(&having, ast, SS("having"), 876572994UL, PH_NOISY); + PHALCON_OBS_VAR(http_only); + phalcon_read_property_this_quick(&http_only, this_ptr, SL("_httpOnly"), 41231174UL, PH_NOISY_CC); - PHALCON_INIT_VAR(having_expr); - phalcon_call_method_p1_key(having_expr, this_ptr, "_getexpression", having, 2816780276UL); - phalcon_array_update_quick_string(&sql_select, SS("having"), 876572994UL, &having_expr, PH_COPY | PH_SEPARATE); - } + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "session", 1); - if (phalcon_array_isset_quick_string(ast, SS("orderBy"), 609540828UL)) { - PHALCON_OBS_VAR(order); - phalcon_array_fetch_quick_string(&order, ast, SS("orderBy"), 609540828UL, PH_NOISY); + PHALCON_INIT_VAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); - PHALCON_INIT_VAR(sql_order); - phalcon_call_method_p1_key(sql_order, this_ptr, "_getorderclause", order, 1909526941UL); - phalcon_array_update_quick_string(&sql_select, SS("order"), 320020033UL, &sql_order, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_SV(key, "_PHCOOKIE_", name); + phalcon_call_method_p1_key(NULL, session, "remove", key, 1052443347UL); } - if (phalcon_array_isset_quick_string(ast, SS("limit"), 192268420UL)) { - PHALCON_OBS_VAR(limit); - phalcon_array_fetch_quick_string(&limit, ast, SS("limit"), 192268420UL, PH_NOISY); - phalcon_array_update_quick_string(&sql_select, SS("limit"), 192268420UL, &limit, PH_COPY | PH_SEPARATE); - } + phalcon_update_property_null(this_ptr, SL("_value") TSRMLS_CC); + + convert_to_string_ex(&name); + convert_to_string_ex(&path); + convert_to_string_ex(&domain); + convert_to_long_ex(&secure); + convert_to_long_ex(&http_only); + + php_setcookie( + Z_STRVAL_P(name), Z_STRLEN_P(name), + NULL, 0, + time(NULL) - 691200, + Z_STRVAL_P(path), Z_STRLEN_P(path), + Z_STRVAL_P(domain), Z_STRLEN_P(domain), + Z_LVAL_P(secure), + 1, + Z_LVAL_P(http_only) TSRMLS_CC + ); - RETURN_CTOR(sql_select); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareInsert){ +static PHP_METHOD(Phalcon_Http_Cookie, useEncryption){ - zval *ast, *qualified_name, *manager, *model_name; - zval *model, *source = NULL, *schema, *sql_aliases, *not_quoting; - zval *expr_values, *values, *expr_value = NULL, *expr_insert = NULL; - zval *expr_type = NULL, *value = NULL, *sql_insert, *meta_data; - zval *sql_fields, *fields, *field = NULL, *name = NULL, *has_attribute = NULL; - zval *phql = NULL, *exception_message = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; + zval *use_encryption; + + phalcon_fetch_params(0, 1, 0, &use_encryption); + + phalcon_update_property_this_quick(this_ptr, SL("_useEncryption"), use_encryption, 2628069468UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Http_Cookie, isUsingEncryption){ + + + RETURN_MEMBER_QUICK(this_ptr, "_useEncryption", 2628069468UL); +} + +static PHP_METHOD(Phalcon_Http_Cookie, setExpiration){ + + zval *expire, *restored; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(ast); - phalcon_read_property_this_quick(&ast, this_ptr, SL("_ast"), 250429676UL, PH_NOISY_CC); - if (!phalcon_array_isset_quick_string(ast, SS("qualifiedName"), 2418332666UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted INSERT AST"); - return; - } - - if (!phalcon_array_isset_quick_string(ast, SS("values"), 1765818005UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted INSERT AST"); - return; - } - - PHALCON_OBS_VAR(qualified_name); - phalcon_array_fetch_quick_string(&qualified_name, ast, SS("qualifiedName"), 2418332666UL, PH_NOISY); + phalcon_fetch_params(1, 1, 0, &expire); - if (!phalcon_array_isset_quick_string(qualified_name, SS("name"), 268211462UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted INSERT AST"); - return; + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { + phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); } - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); - - PHALCON_INIT_VAR(model); - phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); - - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, model, "getsource", 2025234358UL); + phalcon_update_property_this_quick(this_ptr, SL("_expire"), expire, 2800520017UL TSRMLS_CC); - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - if (zend_is_true(schema)) { - PHALCON_INIT_NVAR(source); - array_init_size(source, 2); - phalcon_array_append(&source, schema, PH_SEPARATE); - phalcon_array_append(&source, source, PH_SEPARATE); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Http_Cookie, getExpiration){ + + zval *restored, *expire; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { + phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); } - PHALCON_INIT_VAR(sql_aliases); - array_init(sql_aliases); - - PHALCON_INIT_VAR(not_quoting); - ZVAL_BOOL(not_quoting, 0); - - PHALCON_INIT_VAR(expr_values); - array_init(expr_values); - - PHALCON_OBS_VAR(values); - phalcon_array_fetch_quick_string(&values, ast, SS("values"), 1765818005UL, PH_NOISY); - - phalcon_is_iterable(values, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(expr_value); - - PHALCON_INIT_NVAR(expr_insert); - phalcon_call_method_p2_key(expr_insert, this_ptr, "_getexpression", expr_value, not_quoting, 2816780276UL); - - PHALCON_OBS_NVAR(expr_type); - phalcon_array_fetch_quick_string(&expr_type, expr_value, SS("type"), 276192743UL, PH_NOISY); + PHALCON_OBS_VAR(expire); + phalcon_read_property_this_quick(&expire, this_ptr, SL("_expire"), 2800520017UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(value); - array_init_size(value, 2); - phalcon_array_update_quick_string(&value, SS("type"), 276192743UL, &expr_type, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&value, SS("value"), 574111618UL, &expr_insert, PH_COPY | PH_SEPARATE); - phalcon_array_append(&expr_values, value, PH_SEPARATE); + RETURN_CCTOR(expire); +} + +static PHP_METHOD(Phalcon_Http_Cookie, setPath){ + + zval *path, *restored; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &path); - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { + phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); } - PHALCON_INIT_VAR(sql_insert); - array_init(sql_insert); - phalcon_array_update_quick_string(&sql_insert, SS("model"), 238191286UL, &model_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_insert, SS("table"), 495471661UL, &source, PH_COPY | PH_SEPARATE); - - PHALCON_OBS_VAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(ast, SS("fields"), 2881624156UL)) { - - PHALCON_INIT_VAR(sql_fields); - array_init(sql_fields); - - PHALCON_OBS_VAR(fields); - phalcon_array_fetch_quick_string(&fields, ast, SS("fields"), 2881624156UL, PH_NOISY); - - phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(field); - - PHALCON_OBS_NVAR(name); - phalcon_array_fetch_quick_string(&name, field, SS("name"), 268211462UL, PH_NOISY); - - PHALCON_INIT_NVAR(has_attribute); - phalcon_call_method_p2_key(has_attribute, meta_data, "hasattribute", model, name, 3258442645UL); - if (!zend_is_true(has_attribute)) { - PHALCON_OBS_NVAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVS(exception_message, "The model '", model_name, "' doesn't have the attribute '", name, "'"); - PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - phalcon_array_append(&sql_fields, name, PH_SEPARATE); - - zend_hash_move_forward_ex(ah1, &hp1); - } + phalcon_update_property_this_quick(this_ptr, SL("_path"), path, 3986357393UL TSRMLS_CC); - phalcon_array_update_quick_string(&sql_insert, SS("fields"), 2881624156UL, &sql_fields, PH_COPY | PH_SEPARATE); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Http_Cookie, getPath){ + + zval *restored, *path; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { + phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); } - phalcon_array_update_quick_string(&sql_insert, SS("values"), 1765818005UL, &expr_values, PH_COPY | PH_SEPARATE); + PHALCON_OBS_VAR(path); + phalcon_read_property_this_quick(&path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); - RETURN_CTOR(sql_insert); + RETURN_CCTOR(path); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareUpdate){ +static PHP_METHOD(Phalcon_Http_Cookie, setDomain){ - zval *ast, *update, *models, *models_instances; - zval *sql_tables, *sql_models, *sql_aliases; - zval *sql_aliases_models_instances, *tables; - zval *update_tables = NULL, *manager, *table = NULL, *qualified_name = NULL; - zval *model_name = NULL, *ns_alias = NULL, *real_namespace = NULL; - zval *real_model_name = NULL, *model = NULL, *source = NULL, *schema = NULL; - zval *complete_source = NULL, *alias = NULL, *sql_fields, *sql_values; - zval *values, *update_values = NULL, *not_quoting = NULL, *update_value = NULL; - zval *column = NULL, *sql_column = NULL, *expr_column = NULL, *expr_value = NULL; - zval *type = NULL, *value = NULL, *sql_update, *where, *where_expr; - zval *limit; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; + zval *domain, *restored; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(ast); - phalcon_read_property_this_quick(&ast, this_ptr, SL("_ast"), 250429676UL, PH_NOISY_CC); - if (!phalcon_array_isset_quick_string(ast, SS("update"), 1051190696UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted UPDATE AST"); - return; - } - - PHALCON_OBS_VAR(update); - phalcon_array_fetch_quick_string(&update, ast, SS("update"), 1051190696UL, PH_NOISY); - if (!phalcon_array_isset_quick_string(update, SS("tables"), 3465666720UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted UPDATE AST"); - return; - } + phalcon_fetch_params(1, 1, 0, &domain); - if (!phalcon_array_isset_quick_string(update, SS("values"), 1765818005UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted UPDATE AST"); - return; + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { + phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); } - PHALCON_INIT_VAR(models); - array_init(models); - - PHALCON_INIT_VAR(models_instances); - array_init(models_instances); - - PHALCON_INIT_VAR(sql_tables); - array_init(sql_tables); - - PHALCON_INIT_VAR(sql_models); - array_init(sql_models); - - PHALCON_INIT_VAR(sql_aliases); - array_init(sql_aliases); - - PHALCON_INIT_VAR(sql_aliases_models_instances); - array_init(sql_aliases_models_instances); + phalcon_update_property_this_quick(this_ptr, SL("_domain"), domain, 1152978748UL TSRMLS_CC); - PHALCON_OBS_VAR(tables); - phalcon_array_fetch_quick_string(&tables, update, SS("tables"), 3465666720UL, PH_NOISY); - if (!phalcon_array_isset_long(tables, 0)) { - PHALCON_INIT_VAR(update_tables); - array_init_size(update_tables, 1); - phalcon_array_append(&update_tables, tables, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(update_tables, tables); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Http_Cookie, getDomain){ + + zval *restored, *domain; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { + phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); } - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - - phalcon_is_iterable(update_tables, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(table); - - PHALCON_OBS_NVAR(qualified_name); - phalcon_array_fetch_quick_string(&qualified_name, table, SS("qualifiedName"), 2418332666UL, PH_NOISY); - - PHALCON_OBS_NVAR(model_name); - phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); - - if (phalcon_array_isset_quick_string(qualified_name, SS("ns-alias"), 2470863549UL)) { - PHALCON_OBS_NVAR(ns_alias); - phalcon_array_fetch_quick_string(&ns_alias, qualified_name, SS("ns-alias"), 2470863549UL, PH_NOISY); - - PHALCON_INIT_NVAR(real_namespace); - phalcon_call_method_p1_key(real_namespace, manager, "getnamespacealias", ns_alias, 3487123420UL); - - PHALCON_INIT_NVAR(real_model_name); - PHALCON_CONCAT_VSV(real_model_name, real_namespace, "\\", model_name); - } else { - PHALCON_CPY_WRT(real_model_name, model_name); - } - - PHALCON_INIT_NVAR(model); - phalcon_call_method_p1_key(model, manager, "load", real_model_name, 266329637UL); - - PHALCON_INIT_NVAR(source); - phalcon_call_method_key(source, model, "getsource", 2025234358UL); - - PHALCON_INIT_NVAR(schema); - phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - - if (zend_is_true(schema)) { - PHALCON_INIT_NVAR(complete_source); - array_init_size(complete_source, 2); - phalcon_array_append(&complete_source, source, PH_SEPARATE); - phalcon_array_append(&complete_source, schema, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(complete_source); - array_init_size(complete_source, 2); - phalcon_array_append(&complete_source, source, PH_SEPARATE); - add_next_index_null(complete_source); - } - - if (phalcon_array_isset_quick_string(table, SS("alias"), 4060151663UL)) { - PHALCON_OBS_NVAR(alias); - phalcon_array_fetch_quick_string(&alias, table, SS("alias"), 4060151663UL, PH_NOISY); - phalcon_array_update_zval(&sql_aliases, alias, &alias, PH_COPY | PH_SEPARATE); - phalcon_array_append(&complete_source, alias, PH_SEPARATE); - phalcon_array_append(&sql_tables, complete_source, PH_SEPARATE); - phalcon_array_update_zval(&sql_aliases_models_instances, alias, &model, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&models, alias, &model_name, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_zval(&sql_aliases, model_name, &source, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&sql_aliases_models_instances, model_name, &model, PH_COPY | PH_SEPARATE); - phalcon_array_append(&sql_tables, source, PH_SEPARATE); - phalcon_array_update_zval(&models, model_name, &source, PH_COPY | PH_SEPARATE); - } + PHALCON_OBS_VAR(domain); + phalcon_read_property_this_quick(&domain, this_ptr, SL("_domain"), 1152978748UL, PH_NOISY_CC); - phalcon_array_append(&sql_models, model_name, PH_SEPARATE); - phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + RETURN_CCTOR(domain); +} + +static PHP_METHOD(Phalcon_Http_Cookie, setSecure){ + + zval *secure, *restored; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &secure); - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { + phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); } - phalcon_update_property_this_quick(this_ptr, SL("_models"), models, 4175729768UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_modelsInstances"), models_instances, 457905456UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlAliases"), sql_aliases, 3407085878UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModelsInstances"), sql_aliases_models_instances, 3347052930UL TSRMLS_CC); - - PHALCON_INIT_VAR(sql_fields); - array_init(sql_fields); - - PHALCON_INIT_VAR(sql_values); - array_init(sql_values); + phalcon_update_property_this_quick(this_ptr, SL("_secure"), secure, 2942644203UL TSRMLS_CC); - PHALCON_OBS_VAR(values); - phalcon_array_fetch_quick_string(&values, update, SS("values"), 1765818005UL, PH_NOISY); - if (!phalcon_array_isset_long(values, 0)) { - PHALCON_INIT_VAR(update_values); - array_init_size(update_values, 1); - phalcon_array_append(&update_values, values, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(update_values, values); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Http_Cookie, getSecure){ + + zval *restored, *secure; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { + phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); } - PHALCON_INIT_VAR(not_quoting); - ZVAL_BOOL(not_quoting, 0); - - phalcon_is_iterable(update_values, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(update_value); - - PHALCON_OBS_NVAR(column); - phalcon_array_fetch_quick_string(&column, update_value, SS("column"), 3545634419UL, PH_NOISY); - - PHALCON_INIT_NVAR(sql_column); - phalcon_call_method_p2_key(sql_column, this_ptr, "_getexpression", column, not_quoting, 2816780276UL); - phalcon_array_append(&sql_fields, sql_column, PH_SEPARATE); - - PHALCON_OBS_NVAR(expr_column); - phalcon_array_fetch_quick_string(&expr_column, update_value, SS("expr"), 258368420UL, PH_NOISY); - - PHALCON_INIT_NVAR(expr_value); - phalcon_call_method_p2_key(expr_value, this_ptr, "_getexpression", expr_column, not_quoting, 2816780276UL); - - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, expr_column, SS("type"), 276192743UL, PH_NOISY); + PHALCON_OBS_VAR(secure); + phalcon_read_property_this_quick(&secure, this_ptr, SL("_secure"), 2942644203UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(value); - array_init_size(value, 2); - phalcon_array_update_quick_string(&value, SS("type"), 276192743UL, &type, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&value, SS("value"), 574111618UL, &expr_value, PH_COPY | PH_SEPARATE); - phalcon_array_append(&sql_values, value, PH_SEPARATE); + RETURN_CCTOR(secure); +} + +static PHP_METHOD(Phalcon_Http_Cookie, setHttpOnly){ + + zval *http_only, *restored; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &http_only); - zend_hash_move_forward_ex(ah1, &hp1); + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { + phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); } - PHALCON_INIT_VAR(sql_update); - array_init(sql_update); - phalcon_array_update_quick_string(&sql_update, SS("tables"), 3465666720UL, &sql_tables, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_update, SS("models"), 3565348937UL, &sql_models, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_update, SS("fields"), 2881624156UL, &sql_fields, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_update, SS("values"), 1765818005UL, &sql_values, PH_COPY | PH_SEPARATE); - if (phalcon_array_isset_quick_string(ast, SS("where"), 621293632UL)) { - ZVAL_BOOL(not_quoting, 1); - - PHALCON_OBS_VAR(where); - phalcon_array_fetch_quick_string(&where, ast, SS("where"), 621293632UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_httpOnly"), http_only, 41231174UL TSRMLS_CC); - PHALCON_INIT_VAR(where_expr); - phalcon_call_method_p2_key(where_expr, this_ptr, "_getexpression", where, not_quoting, 2816780276UL); - phalcon_array_update_quick_string(&sql_update, SS("where"), 621293632UL, &where_expr, PH_COPY | PH_SEPARATE); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Http_Cookie, getHttpOnly){ + + zval *restored, *http_only; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(restored); + phalcon_read_property_this_quick(&restored, this_ptr, SL("_restored"), 1981127436UL, PH_NOISY_CC); + if (!zend_is_true(restored)) { + phalcon_call_method_key(NULL, this_ptr, "restore", 611399977UL); } - if (phalcon_array_isset_quick_string(ast, SS("limit"), 192268420UL)) { - PHALCON_OBS_VAR(limit); - phalcon_array_fetch_quick_string(&limit, ast, SS("limit"), 192268420UL, PH_NOISY); - phalcon_array_update_quick_string(&sql_update, SS("limit"), 192268420UL, &limit, PH_COPY | PH_SEPARATE); - } + PHALCON_OBS_VAR(http_only); + phalcon_read_property_this_quick(&http_only, this_ptr, SL("_httpOnly"), 41231174UL, PH_NOISY_CC); - RETURN_CTOR(sql_update); + RETURN_CCTOR(http_only); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareDelete){ +static PHP_METHOD(Phalcon_Http_Cookie, __toString){ - zval *ast, *delete, *models, *models_instances; - zval *sql_tables, *sql_models, *sql_aliases; - zval *sql_aliases_models_instances, *tables; - zval *delete_tables = NULL, *manager, *table = NULL, *qualified_name = NULL; - zval *model_name = NULL, *ns_alias = NULL, *real_namespace = NULL; - zval *real_model_name = NULL, *model = NULL, *source = NULL, *schema = NULL; - zval *complete_source = NULL, *alias = NULL, *sql_delete, *not_quoting; - zval *where, *where_expr, *limit; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *value = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(ast); - phalcon_read_property_this_quick(&ast, this_ptr, SL("_ast"), 250429676UL, PH_NOISY_CC); - if (!phalcon_array_isset_quick_string(ast, SS("delete"), 150213496UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted DELETE AST"); - return; - } - - PHALCON_OBS_VAR(delete); - phalcon_array_fetch_quick_string(&delete, ast, SS("delete"), 150213496UL, PH_NOISY); - if (!phalcon_array_isset_quick_string(delete, SS("tables"), 3465666720UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted DELETE AST"); - return; + PHALCON_OBS_VAR(value); + phalcon_read_property_this_quick(&value, this_ptr, SL("_value"), 2935317441UL, PH_NOISY_CC); + if (Z_TYPE_P(value) == IS_NULL) { + PHALCON_INIT_NVAR(value); + phalcon_call_method_key(value, this_ptr, "getvalue", 31703298UL); } - PHALCON_INIT_VAR(models); - array_init(models); - - PHALCON_INIT_VAR(models_instances); - array_init(models_instances); - - PHALCON_INIT_VAR(sql_tables); - array_init(sql_tables); - - PHALCON_INIT_VAR(sql_models); - array_init(sql_models); - - PHALCON_INIT_VAR(sql_aliases); - array_init(sql_aliases); - - PHALCON_INIT_VAR(sql_aliases_models_instances); - array_init(sql_aliases_models_instances); - - PHALCON_OBS_VAR(tables); - phalcon_array_fetch_quick_string(&tables, delete, SS("tables"), 3465666720UL, PH_NOISY); - if (!phalcon_array_isset_long(tables, 0)) { - PHALCON_INIT_VAR(delete_tables); - array_init_size(delete_tables, 1); - phalcon_array_append(&delete_tables, tables, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(delete_tables, tables); - } - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + RETURN_CCTOR(value); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Http_Request_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Http\\Request, Exception, http_request_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Http_Request_File){ + + PHALCON_REGISTER_CLASS(Phalcon\\Http\\Request, File, http_request_file, phalcon_http_request_file_method_entry, 0); + + zend_declare_property_null(phalcon_http_request_file_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_request_file_ce, SL("_tmp"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_request_file_ce, SL("_size"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_request_file_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_request_file_ce, SL("_error"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_request_file_ce, SL("_key"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_http_request_file_ce TSRMLS_CC, 1, phalcon_http_request_fileinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Http_Request_File, __construct){ + + zval *file, *name, *temp_name, *size, *type, *error, *key = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &file, &key); - phalcon_is_iterable(delete_tables, &ah0, &hp0, 0, 0); + if (Z_TYPE_P(file) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "Phalcon\\Http\\Request\\File requires a valid uploaded file"); + return; + } + if (phalcon_array_isset_quick_string(file, SS("name"), 268211462UL)) { + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, file, SS("name"), 268211462UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (phalcon_array_isset_quick_string(file, SS("tmp_name"), 3852050422UL)) { + PHALCON_OBS_VAR(temp_name); + phalcon_array_fetch_quick_string(&temp_name, file, SS("tmp_name"), 3852050422UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_tmp"), temp_name, 251105813UL TSRMLS_CC); + } - PHALCON_GET_HVALUE(table); + if (phalcon_array_isset_quick_string(file, SS("size"), 274442720UL)) { + PHALCON_OBS_VAR(size); + phalcon_array_fetch_quick_string(&size, file, SS("size"), 274442720UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_size"), size, 3990209087UL TSRMLS_CC); + } - PHALCON_OBS_NVAR(qualified_name); - phalcon_array_fetch_quick_string(&qualified_name, table, SS("qualifiedName"), 2418332666UL, PH_NOISY); + if (phalcon_array_isset_quick_string(file, SS("type"), 276192743UL)) { + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, file, SS("type"), 276192743UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); + } + + if (phalcon_array_isset_quick_string(file, SS("error"), 4224147407UL)) { + PHALCON_OBS_VAR(error); + phalcon_array_fetch_quick_string(&error, file, SS("error"), 4224147407UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_error"), error, 2290385934UL TSRMLS_CC); + } + + if (key) { + phalcon_update_property_this_quick(this_ptr, SL("_key"), key, 250773965UL TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Http_Request_File, getSize){ + + + RETURN_MEMBER_QUICK(this_ptr, "_size", 3990209087UL); +} + +static PHP_METHOD(Phalcon_Http_Request_File, getName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); +} + +static PHP_METHOD(Phalcon_Http_Request_File, getTempName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_tmp", 251105813UL); +} + +static PHP_METHOD(Phalcon_Http_Request_File, getType){ + + + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); +} + +static PHP_METHOD(Phalcon_Http_Request_File, getRealType){ + + - PHALCON_OBS_NVAR(model_name); - phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); +} + +static PHP_METHOD(Phalcon_Http_Request_File, getError){ + + + RETURN_MEMBER_QUICK(this_ptr, "_error", 2290385934UL); +} + +static PHP_METHOD(Phalcon_Http_Request_File, getKey){ + + RETURN_MEMBER_QUICK(this_ptr, "_key", 250773965UL); +} + +static PHP_METHOD(Phalcon_Http_Request_File, isUploadedFile) { + + zval *tmp_name; + + if (!SG(rfc1867_uploaded_files)) { + RETURN_FALSE; + } + + PHALCON_ALLOC_ZVAL(tmp_name); + if (phalcon_call_method_params_w(tmp_name, getThis(), SL("gettempname"), 0, NULL, 0, 0 TSRMLS_CC) == SUCCESS) { + if (Z_TYPE_P(tmp_name) == IS_STRING && zend_hash_exists(SG(rfc1867_uploaded_files), Z_STRVAL_P(tmp_name), Z_STRLEN_P(tmp_name) + 1)) { + RETVAL_TRUE; + } + else { + RETVAL_FALSE; + } + } + + zval_ptr_dtor(&tmp_name); +} + +static PHP_METHOD(Phalcon_Http_Request_File, moveTo){ + + zval *destination, *temp_file; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &destination); - if (phalcon_array_isset_quick_string(qualified_name, SS("ns-alias"), 2470863549UL)) { - PHALCON_OBS_NVAR(ns_alias); - phalcon_array_fetch_quick_string(&ns_alias, qualified_name, SS("ns-alias"), 2470863549UL, PH_NOISY); + PHALCON_OBS_VAR(temp_file); + phalcon_read_property_this_quick(&temp_file, this_ptr, SL("_tmp"), 251105813UL, PH_NOISY_CC); + phalcon_call_func_p2(return_value, "move_uploaded_file", temp_file, destination); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request_File, __set_state) { + + zval *data; + + phalcon_fetch_params(0, 1, 0, &data); + + object_init_ex(return_value, phalcon_http_request_file_ce); + + PHALCON_MM_GROW(); + phalcon_call_method_p1_key(NULL, return_value, "__construct", data, 1107214344UL); + PHALCON_MM_RESTORE(); +} + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Http_Request_FileInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Http\\Request, FileInterface, http_request_fileinterface, phalcon_http_request_fileinterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Http_Request){ + + PHALCON_REGISTER_CLASS(Phalcon\\Http, Request, http_request, phalcon_http_request_method_entry, 0); + + zend_declare_property_null(phalcon_http_request_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_request_ce, SL("_filter"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_http_request_ce TSRMLS_CC, 2, phalcon_http_requestinterface_ce, phalcon_di_injectionawareinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Http_Request, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); - PHALCON_INIT_NVAR(real_namespace); - phalcon_call_method_p1_key(real_namespace, manager, "getnamespacealias", ns_alias, 3487123420UL); + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - PHALCON_INIT_NVAR(real_model_name); - PHALCON_CONCAT_VSV(real_model_name, real_namespace, "\\", model_name); - } else { - PHALCON_CPY_WRT(real_model_name, model_name); - } +} + +static PHP_METHOD(Phalcon_Http_Request, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} + +static PHP_METHOD(Phalcon_Http_Request, get){ + + zval *name = NULL, *filters = NULL, *default_value = NULL, *request = NULL; + zval *_REQUEST, *value, *filter = NULL, *dependency_injector; + zval *service; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 3, &name, &filters, &default_value); - PHALCON_INIT_NVAR(model); - phalcon_call_method_p1_key(model, manager, "load", real_model_name, 266329637UL); + if (!name) { + PHALCON_INIT_VAR(name); + } - PHALCON_INIT_NVAR(source); - phalcon_call_method_key(source, model, "getsource", 2025234358UL); + if (!filters) { + PHALCON_INIT_VAR(filters); + } - PHALCON_INIT_NVAR(schema); - phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - if (zend_is_true(schema)) { - PHALCON_INIT_NVAR(complete_source); - array_init_size(complete_source, 2); - phalcon_array_append(&complete_source, source, PH_SEPARATE); - phalcon_array_append(&complete_source, schema, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(complete_source); - array_init_size(complete_source, 2); - phalcon_array_append(&complete_source, source, PH_SEPARATE); - add_next_index_null(complete_source); - } + if (!default_value) { + PHALCON_INIT_VAR(default_value); + } - if (phalcon_array_isset_quick_string(table, SS("alias"), 4060151663UL)) { - PHALCON_OBS_NVAR(alias); - phalcon_array_fetch_quick_string(&alias, table, SS("alias"), 4060151663UL, PH_NOISY); - phalcon_array_update_zval(&sql_aliases, alias, &alias, PH_COPY | PH_SEPARATE); - phalcon_array_append(&complete_source, alias, PH_SEPARATE); - phalcon_array_append(&sql_tables, complete_source, PH_SEPARATE); - phalcon_array_update_zval(&sql_aliases_models_instances, alias, &model, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&models, alias, &model_name, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_zval(&sql_aliases, model_name, &source, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&sql_aliases_models_instances, model_name, &model, PH_COPY | PH_SEPARATE); - phalcon_array_append(&sql_tables, source, PH_SEPARATE); - phalcon_array_update_zval(&models, model_name, &source, PH_COPY | PH_SEPARATE); - } + phalcon_get_global(&_REQUEST, SS("_REQUEST") TSRMLS_CC); + PHALCON_CPY_WRT(request, _REQUEST); + if (Z_TYPE_P(name) != IS_NULL) { + if (phalcon_array_isset(request, name)) { - phalcon_array_append(&sql_models, model_name, PH_SEPARATE); - phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, request, name, PH_NOISY); + if (Z_TYPE_P(filters) != IS_NULL) { - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_OBS_VAR(filter); + phalcon_read_property_this_quick(&filter, this_ptr, SL("_filter"), 3500594986UL, PH_NOISY_CC); + if (Z_TYPE_P(filter) != IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_models"), models, 4175729768UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_modelsInstances"), models_instances, 457905456UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlAliases"), sql_aliases, 3407085878UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModelsInstances"), sql_aliases_models_instances, 3347052930UL TSRMLS_CC); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service"); + return; + } - PHALCON_INIT_VAR(sql_delete); - array_init(sql_delete); - phalcon_array_update_quick_string(&sql_delete, SS("tables"), 3465666720UL, &sql_tables, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&sql_delete, SS("models"), 3565348937UL, &sql_models, PH_COPY | PH_SEPARATE); - if (phalcon_array_isset_quick_string(ast, SS("where"), 621293632UL)) { - PHALCON_INIT_VAR(not_quoting); - ZVAL_BOOL(not_quoting, 1); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "filter", 1); - PHALCON_OBS_VAR(where); - phalcon_array_fetch_quick_string(&where, ast, SS("where"), 621293632UL, PH_NOISY); + PHALCON_INIT_NVAR(filter); + phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service, 1727570332UL); + phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); + } - PHALCON_INIT_VAR(where_expr); - phalcon_call_method_p2_key(where_expr, this_ptr, "_getexpression", where, not_quoting, 2816780276UL); - phalcon_array_update_quick_string(&sql_delete, SS("where"), 621293632UL, &where_expr, PH_COPY | PH_SEPARATE); - } + phalcon_call_method_p2_key(return_value, filter, "sanitize", value, filters, 3688332940UL); + RETURN_MM(); + } else { + RETURN_CCTOR(value); + } + } - if (phalcon_array_isset_quick_string(ast, SS("limit"), 192268420UL)) { - PHALCON_OBS_VAR(limit); - phalcon_array_fetch_quick_string(&limit, ast, SS("limit"), 192268420UL, PH_NOISY); - phalcon_array_update_quick_string(&sql_delete, SS("limit"), 192268420UL, &limit, PH_COPY | PH_SEPARATE); + RETURN_CCTOR(default_value); } - RETURN_CTOR(sql_delete); + RETURN_CCTOR(request); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, parse){ +static PHP_METHOD(Phalcon_Http_Request, getPost){ - zval *intermediate, *phql, *ast, *ir_phql = NULL, *ir_phql_cache = NULL; - zval *unique_id = NULL, *type = NULL, *exception_message; + zval *name = NULL, *filters = NULL, *default_value = NULL, *post = NULL, *_POST; + zval *value, *filter = NULL, *dependency_injector, *service; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(intermediate); - phalcon_read_property_this_quick(&intermediate, this_ptr, SL("_intermediate"), 1829292799UL, PH_NOISY_CC); - if (Z_TYPE_P(intermediate) == IS_ARRAY) { - RETURN_CCTOR(intermediate); - } - - PHALCON_OBS_VAR(phql); - phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + phalcon_fetch_params(1, 0, 3, &name, &filters, &default_value); - PHALCON_INIT_VAR(ast); - if (phql_parse_phql(ast, phql TSRMLS_CC) == FAILURE) { - return; + if (!name) { + PHALCON_INIT_VAR(name); } - PHALCON_INIT_VAR(ir_phql); + if (!filters) { + PHALCON_INIT_VAR(filters); + } - PHALCON_INIT_VAR(ir_phql_cache); + if (!default_value) { + PHALCON_INIT_VAR(default_value); + } - PHALCON_INIT_VAR(unique_id); + phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); + PHALCON_CPY_WRT(post, _POST); + if (Z_TYPE_P(name) != IS_NULL) { + if (phalcon_array_isset(post, name)) { - if (Z_TYPE_P(ast) == IS_ARRAY) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, post, name, PH_NOISY); + if (Z_TYPE_P(filters) != IS_NULL) { - if (phalcon_array_isset_quick_string(ast, SS("id"), 193494642UL)) { + PHALCON_OBS_VAR(filter); + phalcon_read_property_this_quick(&filter, this_ptr, SL("_filter"), 3500594986UL, PH_NOISY_CC); + if (Z_TYPE_P(filter) != IS_OBJECT) { - PHALCON_OBS_NVAR(unique_id); - phalcon_array_fetch_quick_string(&unique_id, ast, SS("id"), 193494642UL, PH_NOISY); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service"); + return; + } - PHALCON_OBS_NVAR(ir_phql_cache); - phalcon_read_static_property(&ir_phql_cache, SL("phalcon\\mvc\\model\\query"), SL("_irPhqlCache") TSRMLS_CC); - if (phalcon_array_isset(ir_phql_cache, unique_id)) { + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "filter", 1); - PHALCON_OBS_NVAR(ir_phql); - phalcon_array_fetch(&ir_phql, ir_phql_cache, unique_id, PH_NOISY); - if (Z_TYPE_P(ir_phql) == IS_ARRAY) { - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, ast, SS("type"), 276192743UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - RETURN_CCTOR(ir_phql); + PHALCON_INIT_NVAR(filter); + phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service, 1727570332UL); + phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); } + + phalcon_call_method_p2_key(return_value, filter, "sanitize", value, filters, 3688332940UL); + RETURN_MM(); + } else { + RETURN_CCTOR(value); } } - if (phalcon_array_isset_quick_string(ast, SS("type"), 276192743UL)) { - phalcon_update_property_this_quick(this_ptr, SL("_ast"), ast, 250429676UL TSRMLS_CC); - - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, ast, SS("type"), 276192743UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - - switch (phalcon_get_intval(type)) { - - case 309: - PHALCON_INIT_NVAR(ir_phql); - phalcon_call_method_key(ir_phql, this_ptr, "_prepareselect", 1122471507UL); - break; - - case 306: - PHALCON_INIT_NVAR(ir_phql); - phalcon_call_method_key(ir_phql, this_ptr, "_prepareinsert", 1453230024UL); - break; - - case 300: - PHALCON_INIT_NVAR(ir_phql); - phalcon_call_method_key(ir_phql, this_ptr, "_prepareupdate", 4126283670UL); - break; - - case 303: - PHALCON_INIT_NVAR(ir_phql); - phalcon_call_method_key(ir_phql, this_ptr, "_preparedelete", 3225306470UL); - break; + RETURN_CCTOR(default_value); + } - default: - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Unknown statement ", type, ", when preparing: ", phql); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; + RETURN_CCTOR(post); +} + +static PHP_METHOD(Phalcon_Http_Request, getQuery){ + + zval *name = NULL, *filters = NULL, *default_value = NULL, *get = NULL, *_GET; + zval *value, *filter = NULL, *dependency_injector, *service; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 3, &name, &filters, &default_value); - } - } + if (!name) { + PHALCON_INIT_VAR(name); } - if (Z_TYPE_P(ir_phql) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted AST"); - return; + if (!filters) { + PHALCON_INIT_VAR(filters); } - if (Z_TYPE_P(unique_id) == IS_LONG) { - if (Z_TYPE_P(ir_phql_cache) != IS_ARRAY) { - PHALCON_INIT_NVAR(ir_phql_cache); - array_init(ir_phql_cache); - } - phalcon_array_update_zval(&ir_phql_cache, unique_id, &ir_phql, PH_COPY | PH_SEPARATE); - phalcon_update_static_property(SL("phalcon\\mvc\\model\\query"), SL("_irPhqlCache"), ir_phql_cache TSRMLS_CC); + if (!default_value) { + PHALCON_INIT_VAR(default_value); } - phalcon_update_property_this_quick(this_ptr, SL("_intermediate"), ir_phql, 1829292799UL TSRMLS_CC); + phalcon_get_global(&_GET, SS("_GET") TSRMLS_CC); + PHALCON_CPY_WRT(get, _GET); + if (Z_TYPE_P(name) != IS_NULL) { + if (phalcon_array_isset(get, name)) { - RETURN_CCTOR(ir_phql); + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, get, name, PH_NOISY); + if (Z_TYPE_P(filters) != IS_NULL) { + + PHALCON_OBS_VAR(filter); + phalcon_read_property_this_quick(&filter, this_ptr, SL("_filter"), 3500594986UL, PH_NOISY_CC); + if (Z_TYPE_P(filter) != IS_OBJECT) { + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service"); + return; + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "filter", 1); + + PHALCON_INIT_NVAR(filter); + phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service, 1727570332UL); + phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); + } + + phalcon_call_method_p2_key(return_value, filter, "sanitize", value, filters, 3688332940UL); + RETURN_MM(); + } else { + RETURN_CCTOR(value); + } + } + + RETURN_CCTOR(default_value); + } + + RETURN_CCTOR(get); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, cache){ +static PHP_METHOD(Phalcon_Http_Request, getServer){ - zval *cache_options; + zval *name, *_SERVER, *server_value; - phalcon_fetch_params(0, 1, 0, &cache_options); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - phalcon_update_property_this_quick(this_ptr, SL("_cacheOptions"), cache_options, 528255652UL TSRMLS_CC); - RETURN_THISW(); + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + if (phalcon_array_isset(_SERVER, name)) { + PHALCON_OBS_VAR(server_value); + phalcon_array_fetch(&server_value, _SERVER, name, PH_NOISY); + RETURN_CCTOR(server_value); + } + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, getCacheOptions){ +static PHP_METHOD(Phalcon_Http_Request, has){ + zval *name, *_REQUEST; - RETURN_MEMBER_QUICK(this_ptr, "_cacheOptions", 528255652UL); + phalcon_fetch_params(0, 1, 0, &name); + + phalcon_get_global(&_REQUEST, SS("_REQUEST") TSRMLS_CC); + if (phalcon_array_isset(_REQUEST, name)) { + RETURN_TRUE; + } + RETURN_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Model_Query, getCache){ +static PHP_METHOD(Phalcon_Http_Request, hasPost){ + zval *name, *_POST; - RETURN_MEMBER_QUICK(this_ptr, "_cache", 2191407384UL); + phalcon_fetch_params(0, 1, 0, &name); + + phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); + if (phalcon_array_isset(_POST, name)) { + RETURN_TRUE; + } + RETURN_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _executeSelect){ - - zval *intermediate, *bind_params, *bind_types; - zval *manager, *models_instances = NULL, *models, *number_models; - zval *model_name = NULL, *model = NULL, *connection = NULL, *connections; - zval *type = NULL, *connection_types = NULL, *columns, *have_objects = NULL; - zval *have_scalars = NULL, *is_complex = NULL, *number_objects; - zval *column = NULL, *column_type = NULL, *is_simple_std = NULL, *select_columns; - zval *simple_column_map = NULL, *meta_data, *znull; - zval *alias_copy = NULL, *sql_column = NULL, *instance = NULL, *attributes = NULL; - zval *column_map = NULL, *attribute = NULL, *hidden_alias = NULL; - zval *column_alias = NULL, *is_keeping_snapshots = NULL; - zval *sql_alias = NULL, *dialect, *sql_select, *processed = NULL; - zval *value = NULL, *wildcard = NULL, *string_wildcard = NULL, *processed_types = NULL; - zval *type_wildcard = NULL, *result, *count, *result_data = NULL; - zval *cache, *result_object = NULL, *resultset = NULL; - HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5, *ah6; - HashPosition hp0, hp1, hp2, hp3, hp4, hp5, hp6; - zval **hd; +static PHP_METHOD(Phalcon_Http_Request, hasQuery){ - PHALCON_MM_GROW(); + zval *name, *_GET; - phalcon_fetch_params(1, 3, 0, &intermediate, &bind_params, &bind_types); - - PHALCON_SEPARATE_PARAM(intermediate); - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + phalcon_fetch_params(0, 1, 0, &name); - PHALCON_OBS_VAR(models_instances); - phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); - if (Z_TYPE_P(models_instances) != IS_ARRAY) { - PHALCON_INIT_NVAR(models_instances); - array_init(models_instances); + phalcon_get_global(&_GET, SS("_GET") TSRMLS_CC); + if (phalcon_array_isset(_GET, name)) { + RETURN_TRUE; } + RETURN_FALSE; +} + +static PHP_METHOD(Phalcon_Http_Request, hasServer){ + + zval *name, *_SERVER; + + phalcon_fetch_params(0, 1, 0, &name); - PHALCON_OBS_VAR(models); - phalcon_array_fetch_quick_string(&models, intermediate, SS("models"), 3565348937UL, PH_NOISY); - - PHALCON_INIT_VAR(number_models); - phalcon_fast_count(number_models, models TSRMLS_CC); - if (PHALCON_IS_LONG(number_models, 1)) { + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + if (phalcon_array_isset(_SERVER, name)) { + RETURN_TRUE; + } + RETURN_FALSE; +} + +static PHP_METHOD(Phalcon_Http_Request, getHeader){ + + zval *header, *_SERVER, *server_value = NULL, *key; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &header); - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); - if (!phalcon_array_isset(models_instances, model_name)) { - PHALCON_INIT_VAR(model); - phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); - phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); - } else { - PHALCON_OBS_NVAR(model); - phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + if (phalcon_array_isset(_SERVER, header)) { + PHALCON_OBS_VAR(server_value); + phalcon_array_fetch(&server_value, _SERVER, header, PH_NOISY); + RETURN_CCTOR(server_value); + } else { + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_SV(key, "HTTP_", header); + if (phalcon_array_isset(_SERVER, key)) { + PHALCON_OBS_NVAR(server_value); + phalcon_array_fetch(&server_value, _SERVER, key, PH_NOISY); + RETURN_CCTOR(server_value); } + } + RETURN_MM_EMPTY_STRING(); +} + +static PHP_METHOD(Phalcon_Http_Request, getScheme){ + + zval *https_header, *https, *scheme = NULL; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(https_header); + ZVAL_STRING(https_header, "HTTPS", 1); - if (phalcon_method_quick_exists_ex(model, SS("selectreadconnection"), 2893916401UL TSRMLS_CC) == SUCCESS) { - - PHALCON_INIT_VAR(connection); - phalcon_call_method_p3_key(connection, model, "selectreadconnection", intermediate, bind_params, bind_types, 2893916401UL); - if (Z_TYPE_P(connection) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "'selectReadConnection' didn't returned a valid connection"); - return; - } + PHALCON_INIT_VAR(https); + phalcon_call_method_p1_key(https, this_ptr, "getserver", https_header, 1630469020UL); + if (zend_is_true(https)) { + if (PHALCON_IS_STRING(https, "off")) { + PHALCON_INIT_VAR(scheme); + ZVAL_STRING(scheme, "http", 1); } else { - PHALCON_INIT_NVAR(connection); - phalcon_call_method_key(connection, model, "getreadconnection", 488334257UL); + PHALCON_INIT_NVAR(scheme); + ZVAL_STRING(scheme, "https", 1); } } else { - PHALCON_INIT_VAR(connections); - array_init(connections); + PHALCON_INIT_NVAR(scheme); + ZVAL_STRING(scheme, "http", 1); + } - phalcon_is_iterable(models, &ah0, &hp0, 0, 0); + RETURN_CTOR(scheme); +} + +static PHP_METHOD(Phalcon_Http_Request, isAjax){ + + zval *requested_header, *xml_http_request; + zval *requested_with; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(requested_header); + ZVAL_STRING(requested_header, "HTTP_X_REQUESTED_WITH", 1); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(xml_http_request); + ZVAL_STRING(xml_http_request, "XMLHttpRequest", 1); - PHALCON_GET_HVALUE(model_name); + PHALCON_INIT_VAR(requested_with); + phalcon_call_method_p1_key(requested_with, this_ptr, "getheader", requested_header, 288415726UL); + is_equal_function(return_value, requested_with, xml_http_request TSRMLS_CC); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, isSoapRequested){ + + zval *server = NULL, *_SERVER, *content_type; + + PHALCON_MM_GROW(); + + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + PHALCON_CPY_WRT(server, _SERVER); + if (phalcon_array_isset_quick_string(server, SS("HTTP_SOAPACTION"), 1001189845UL)) { + RETURN_MM_TRUE; + } else { + if (phalcon_array_isset_quick_string(server, SS("CONTENT_TYPE"), 3407676833UL)) { - if (!phalcon_array_isset(models_instances, model_name)) { - PHALCON_INIT_NVAR(model); - phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); - phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); - } else { - PHALCON_OBS_NVAR(model); - phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); + PHALCON_OBS_VAR(content_type); + phalcon_array_fetch_quick_string(&content_type, server, SS("CONTENT_TYPE"), 3407676833UL, PH_NOISY); + if (phalcon_memnstr_str(content_type, SL("application/soap+xml"))) { + RETURN_MM_TRUE; } + } + } - PHALCON_INIT_NVAR(connection); - phalcon_call_method_key(connection, model, "getreadconnection", 488334257UL); + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Http_Request, isSecureRequest){ + + zval *scheme, *https; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(scheme); + phalcon_call_method_key(scheme, this_ptr, "getscheme", 1539736378UL); - PHALCON_INIT_NVAR(type); - phalcon_call_method_key(type, connection, "gettype", 4294422375UL); + PHALCON_INIT_VAR(https); + ZVAL_STRING(https, "https", 1); + is_identical_function(return_value, https, scheme TSRMLS_CC); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, getRawBody){ + + if (SG(request_info).raw_post_data) { + RETURN_STRINGL(SG(request_info).raw_post_data, SG(request_info).raw_post_data_length, 1); + } + + if (sapi_module.read_post) { + int read_bytes; + char *buf = emalloc(8192); + smart_str raw_data = { NULL, 0, 0 }; + + while ((read_bytes = sapi_module.read_post(buf, 8192 TSRMLS_CC)) > 0) { + smart_str_appendl(&raw_data, buf, read_bytes); + SG(read_post_bytes) += read_bytes; + } + + efree(buf); + if (raw_data.c) { + RETURN_STRINGL(raw_data.c, raw_data.len, 0); + } + } + + RETURN_EMPTY_STRING(); +} + +static PHP_METHOD(Phalcon_Http_Request, getJsonRawBody){ + + zval *raw_body; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(raw_body); + phalcon_call_method_key(raw_body, this_ptr, "getrawbody", 1898502173UL); + if (Z_TYPE_P(raw_body) == IS_STRING) { + phalcon_json_decode(return_value, raw_body, 0 TSRMLS_CC); + RETURN_MM(); + } - phalcon_array_update_zval_bool(&connections, type, 1, PH_SEPARATE); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Http_Request, getServerAddress){ + + zval *server = NULL, *_SERVER, *server_addr, *localhost; + + PHALCON_MM_GROW(); + + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + PHALCON_CPY_WRT(server, _SERVER); + if (phalcon_array_isset_quick_string(server, SS("SERVER_ADDR"), 3472224502UL)) { + PHALCON_OBS_VAR(server_addr); + phalcon_array_fetch_quick_string(&server_addr, server, SS("SERVER_ADDR"), 3472224502UL, PH_NOISY); + RETURN_CCTOR(server_addr); + } - PHALCON_INIT_NVAR(connection_types); - phalcon_fast_count(connection_types, connections TSRMLS_CC); + PHALCON_INIT_VAR(localhost); + ZVAL_STRING(localhost, "localhost", 1); + phalcon_call_func_p1(return_value, "gethostbyname", localhost); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, getServerName){ + + zval *server = NULL, *_SERVER, *server_name = NULL; + + PHALCON_MM_GROW(); + + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + PHALCON_CPY_WRT(server, _SERVER); + if (phalcon_array_isset_quick_string(server, SS("SERVER_NAME"), 3487543036UL)) { + PHALCON_OBS_VAR(server_name); + phalcon_array_fetch_quick_string(&server_name, server, SS("SERVER_NAME"), 3487543036UL, PH_NOISY); + RETURN_CCTOR(server_name); + } - if (PHALCON_IS_LONG(connection_types, 2)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Cannot use models of different database systems in the same query"); - return; - } + PHALCON_INIT_NVAR(server_name); + ZVAL_STRING(server_name, "localhost", 1); - zend_hash_move_forward_ex(ah0, &hp0); - } + RETURN_CCTOR(server_name); +} + +static PHP_METHOD(Phalcon_Http_Request, getHttpHost){ + + zval *host, *http_host, *scheme, *server_name, *name; + zval *server_port, *port, *http, *standard_port; + zval *is_std_name, *is_std_port, *is_std_http; + zval *https, *secure_port, *is_secure_scheme; + zval *is_secure_port, *is_secure_http; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(host); + ZVAL_STRING(host, "HTTP_HOST", 1); + PHALCON_INIT_VAR(http_host); + phalcon_call_method_p1_key(http_host, this_ptr, "getserver", host, 1630469020UL); + if (zend_is_true(http_host)) { + RETURN_CCTOR(http_host); } - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, intermediate, SS("columns"), 1041822630UL, PH_NOISY); + PHALCON_INIT_VAR(scheme); + phalcon_call_method_key(scheme, this_ptr, "getscheme", 1539736378UL); - PHALCON_INIT_VAR(have_objects); - ZVAL_BOOL(have_objects, 0); + PHALCON_INIT_VAR(server_name); + ZVAL_STRING(server_name, "SERVER_NAME", 1); - PHALCON_INIT_VAR(have_scalars); - ZVAL_BOOL(have_scalars, 0); + PHALCON_INIT_VAR(name); + phalcon_call_method_p1_key(name, this_ptr, "getserver", server_name, 1630469020UL); - PHALCON_INIT_VAR(is_complex); - ZVAL_BOOL(is_complex, 0); + PHALCON_INIT_VAR(server_port); + ZVAL_STRING(server_port, "SERVER_PORT", 1); - PHALCON_INIT_VAR(number_objects); - ZVAL_LONG(number_objects, 0); + PHALCON_INIT_VAR(port); + phalcon_call_method_p1_key(port, this_ptr, "getserver", server_port, 1630469020UL); - phalcon_is_iterable(columns, &ah1, &hp1, 0, 0); + PHALCON_INIT_VAR(http); + ZVAL_STRING(http, "http", 1); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + PHALCON_INIT_VAR(standard_port); + ZVAL_LONG(standard_port, 80); - PHALCON_GET_HVALUE(column); + PHALCON_INIT_VAR(is_std_name); + is_equal_function(is_std_name, scheme, http TSRMLS_CC); - PHALCON_OBS_NVAR(column_type); - phalcon_array_fetch_quick_string(&column_type, column, SS("type"), 276192743UL, PH_NOISY); - if (PHALCON_IS_STRING(column_type, "scalar")) { - if (!phalcon_array_isset_quick_string(column, SS("balias"), 1705826801UL)) { - PHALCON_INIT_NVAR(is_complex); - ZVAL_BOOL(is_complex, 1); - } + PHALCON_INIT_VAR(is_std_port); + is_equal_function(is_std_port, port, standard_port TSRMLS_CC); - PHALCON_INIT_NVAR(have_scalars); - ZVAL_BOOL(have_scalars, 1); - } else { - PHALCON_INIT_NVAR(have_objects); - ZVAL_BOOL(have_objects, 1); - PHALCON_SEPARATE(number_objects); - phalcon_increment(number_objects); - } + PHALCON_INIT_VAR(is_std_http); + phalcon_and_function(is_std_http, is_std_name, is_std_port); - zend_hash_move_forward_ex(ah1, &hp1); - } + PHALCON_INIT_VAR(https); + ZVAL_STRING(https, "https", 1); - if (PHALCON_IS_FALSE(is_complex)) { - if (PHALCON_IS_TRUE(have_objects)) { - if (PHALCON_IS_TRUE(have_scalars)) { - PHALCON_INIT_NVAR(is_complex); - ZVAL_BOOL(is_complex, 1); - } else { - if (PHALCON_IS_LONG(number_objects, 1)) { - PHALCON_INIT_VAR(is_simple_std); - ZVAL_BOOL(is_simple_std, 0); - } else { - PHALCON_INIT_NVAR(is_complex); - ZVAL_BOOL(is_complex, 1); - } - } - } else { - PHALCON_INIT_NVAR(is_simple_std); - ZVAL_BOOL(is_simple_std, 1); - } - } + PHALCON_INIT_VAR(secure_port); + ZVAL_LONG(secure_port, 443); - PHALCON_INIT_VAR(select_columns); - array_init(select_columns); + PHALCON_INIT_VAR(is_secure_scheme); + is_equal_function(is_secure_scheme, scheme, https TSRMLS_CC); - PHALCON_INIT_VAR(simple_column_map); - array_init(simple_column_map); + PHALCON_INIT_VAR(is_secure_port); + is_equal_function(is_secure_port, port, secure_port TSRMLS_CC); - PHALCON_OBS_VAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); + PHALCON_INIT_VAR(is_secure_http); + phalcon_and_function(is_secure_http, is_secure_scheme, is_secure_port); - PHALCON_INIT_VAR(znull); + if (PHALCON_IS_TRUE(is_std_http)) { + RETURN_CCTOR(name); + } - phalcon_is_iterable(columns, &ah2, &hp2, 1, 0); + if (PHALCON_IS_TRUE(is_secure_http)) { + RETURN_CCTOR(name); + } - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + PHALCON_CONCAT_VSV(return_value, name, ":", port); - PHALCON_GET_HMKEY(alias_copy, ah2, hp2); - PHALCON_GET_HVALUE(column); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, getClientAddress){ + + zval *trust_forwarded_header = NULL, *address = NULL, *_SERVER; + zval *addresses, *first; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &trust_forwarded_header); - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, column, SS("type"), 276192743UL, PH_NOISY); + if (!trust_forwarded_header) { + PHALCON_INIT_VAR(trust_forwarded_header); + ZVAL_BOOL(trust_forwarded_header, 0); + } - PHALCON_OBS_NVAR(sql_column); - phalcon_array_fetch_quick_string(&sql_column, column, SS("column"), 3545634419UL, PH_NOISY); + PHALCON_INIT_VAR(address); - if (PHALCON_IS_STRING(type, "object")) { + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + if (phalcon_array_isset_quick_string(_SERVER, SS("HTTP_X_FORWARDED_FOR"), 243594879UL)) { + if (zend_is_true(trust_forwarded_header)) { + PHALCON_OBS_NVAR(address); + phalcon_array_fetch_quick_string(&address, _SERVER, SS("HTTP_X_FORWARDED_FOR"), 243594879UL, PH_NOISY); + } + } - PHALCON_OBS_NVAR(model_name); - phalcon_array_fetch_quick_string(&model_name, column, SS("model"), 238191286UL, PH_NOISY); + if (Z_TYPE_P(address) == IS_NULL) { + if (phalcon_array_isset_quick_string(_SERVER, SS("REMOTE_ADDR"), 1233979979UL)) { + PHALCON_OBS_NVAR(address); + phalcon_array_fetch_quick_string(&address, _SERVER, SS("REMOTE_ADDR"), 1233979979UL, PH_NOISY); + } + } - if (phalcon_array_isset(models_instances, model_name)) { - PHALCON_OBS_NVAR(instance); - phalcon_array_fetch(&instance, models_instances, model_name, PH_NOISY); - } else { - PHALCON_INIT_NVAR(instance); - phalcon_call_method_p1_key(instance, manager, "load", model_name, 266329637UL); - phalcon_array_update_zval(&models_instances, model_name, &instance, PH_COPY | PH_SEPARATE); - } + if (Z_TYPE_P(address) == IS_STRING) { + if (phalcon_memnstr_str(address, SL(","))) { + PHALCON_INIT_VAR(addresses); + phalcon_fast_explode_str(addresses, SL(","), address); - PHALCON_INIT_NVAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getattributes", instance, 1013165772UL); - if (PHALCON_IS_TRUE(is_complex)) { - - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_NVAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", instance, 213063537UL); - } else { - PHALCON_CPY_WRT(column_map, znull); - } - - phalcon_is_iterable(attributes, &ah3, &hp3, 0, 0); - - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - - PHALCON_GET_HVALUE(attribute); - - PHALCON_INIT_NVAR(hidden_alias); - PHALCON_CONCAT_SVSV(hidden_alias, "_", sql_column, "_", attribute); - - PHALCON_INIT_NVAR(column_alias); - array_init_size(column_alias, 3); - phalcon_array_append(&column_alias, attribute, PH_SEPARATE); - phalcon_array_append(&column_alias, sql_column, PH_SEPARATE); - phalcon_array_append(&column_alias, hidden_alias, PH_SEPARATE); - phalcon_array_append(&select_columns, column_alias, PH_SEPARATE); - - zend_hash_move_forward_ex(ah3, &hp3); - } - - phalcon_array_update_string_multi_2(&columns, alias_copy, SL("instance"), &instance, 0); - phalcon_array_update_string_multi_2(&columns, alias_copy, SL("attributes"), &attributes, 0); - phalcon_array_update_string_multi_2(&columns, alias_copy, SL("columnMap"), &column_map, 0); - - PHALCON_INIT_NVAR(is_keeping_snapshots); - phalcon_call_method_p1_key(is_keeping_snapshots, manager, "iskeepingsnapshots", instance, 2646609383UL); - if (zend_is_true(is_keeping_snapshots)) { - phalcon_array_update_string_multi_2(&columns, alias_copy, SL("keepSnapshots"), &is_keeping_snapshots, 0); - } - } else { - phalcon_is_iterable(attributes, &ah4, &hp4, 0, 0); - - while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { - - PHALCON_GET_HVALUE(attribute); - - PHALCON_INIT_NVAR(column_alias); - array_init_size(column_alias, 2); - phalcon_array_append(&column_alias, attribute, PH_SEPARATE); - phalcon_array_append(&column_alias, sql_column, PH_SEPARATE); - phalcon_array_append(&select_columns, column_alias, PH_SEPARATE); - - zend_hash_move_forward_ex(ah4, &hp4); - } - - } - } else { - if (Z_TYPE_P(alias_copy) == IS_LONG) { - PHALCON_INIT_NVAR(column_alias); - array_init_size(column_alias, 2); - phalcon_array_append(&column_alias, sql_column, PH_SEPARATE); - phalcon_array_append(&column_alias, znull, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(column_alias); - array_init_size(column_alias, 3); - phalcon_array_append(&column_alias, sql_column, PH_SEPARATE); - phalcon_array_append(&column_alias, znull, PH_SEPARATE); - phalcon_array_append(&column_alias, alias_copy, PH_SEPARATE); - } - phalcon_array_append(&select_columns, column_alias, PH_SEPARATE); - } - - if (PHALCON_IS_FALSE(is_complex)) { - if (PHALCON_IS_TRUE(is_simple_std)) { - if (phalcon_array_isset_quick_string(column, SS("sqlAlias"), 2820722015UL)) { - PHALCON_OBS_NVAR(sql_alias); - phalcon_array_fetch_quick_string(&sql_alias, column, SS("sqlAlias"), 2820722015UL, PH_NOISY); - phalcon_array_update_zval(&simple_column_map, sql_alias, &alias_copy, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_zval(&simple_column_map, alias_copy, &alias_copy, PH_COPY | PH_SEPARATE); - } - } + PHALCON_OBS_VAR(first); + phalcon_array_fetch_long(&first, addresses, 0, PH_NOISY); + RETURN_CCTOR(first); } - zend_hash_move_forward_ex(ah2, &hp2); + RETURN_CCTOR(address); } - zend_hash_destroy(ah2); - efree(ah2); - - phalcon_array_update_quick_string(&intermediate, SS("columns"), 1041822630UL, &select_columns, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(dialect); - phalcon_call_method_key(dialect, connection, "getdialect", 3133083739UL); - - PHALCON_INIT_VAR(sql_select); - phalcon_call_method_p1_key(sql_select, dialect, "select", intermediate, 2342345829UL); - if (Z_TYPE_P(bind_params) == IS_ARRAY) { - - PHALCON_INIT_VAR(processed); - array_init(processed); - - phalcon_is_iterable(bind_params, &ah5, &hp5, 0, 0); - - while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { - - PHALCON_GET_HKEY(wildcard, ah5, hp5); - PHALCON_GET_HVALUE(value); - - if (Z_TYPE_P(wildcard) == IS_LONG) { - PHALCON_INIT_NVAR(string_wildcard); - PHALCON_CONCAT_SV(string_wildcard, ":", wildcard); - phalcon_array_update_zval(&processed, string_wildcard, &value, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_zval(&processed, wildcard, &value, PH_COPY | PH_SEPARATE); - } - - zend_hash_move_forward_ex(ah5, &hp5); + RETURN_MM_FALSE; +} + +static const char* phalcon_http_request_getmethod_helper(TSRMLS_D) +{ + zval **value; + const char *method = SG(request_info).request_method; + if (unlikely(!method)) { + zval *_SERVER, key; + + INIT_ZVAL(key); + ZVAL_STRING(&key, "REQUEST_METHOD", 0); + + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + value = phalcon_hash_get(Z_ARRVAL_P(_SERVER), &key, BP_VAR_NA); + if (value && Z_TYPE_PP(value) == IS_STRING) { + return Z_STRVAL_PP(value); } - - } else { - PHALCON_CPY_WRT(processed, bind_params); + + return ""; } - - if (Z_TYPE_P(bind_types) == IS_ARRAY) { - - PHALCON_INIT_VAR(processed_types); - array_init(processed_types); - - phalcon_is_iterable(bind_types, &ah6, &hp6, 0, 0); - - while (zend_hash_get_current_data_ex(ah6, (void**) &hd, &hp6) == SUCCESS) { - - PHALCON_GET_HKEY(type_wildcard, ah6, hp6); - PHALCON_GET_HVALUE(value); - - if (Z_TYPE_P(type_wildcard) == IS_LONG) { - PHALCON_INIT_NVAR(string_wildcard); - PHALCON_CONCAT_SV(string_wildcard, ":", type_wildcard); - phalcon_array_update_zval(&processed_types, string_wildcard, &value, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_zval(&processed_types, type_wildcard, &value, PH_COPY | PH_SEPARATE); - } - - zend_hash_move_forward_ex(ah6, &hp6); - } - - } else { - PHALCON_CPY_WRT(processed_types, bind_types); + + return method; +} + +static PHP_METHOD(Phalcon_Http_Request, getMethod){ + + const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); + if (method) { + RETURN_STRING(method, 1); } - - PHALCON_INIT_VAR(result); - phalcon_call_method_p3_key(result, connection, "query", sql_select, processed, processed_types, 401898907UL); - - PHALCON_INIT_VAR(count); - phalcon_call_method_p1_key(count, result, "numrows", result, 887792640UL); - if (zend_is_true(count)) { - PHALCON_CPY_WRT(result_data, result); + + RETURN_EMPTY_STRING(); +} + +static PHP_METHOD(Phalcon_Http_Request, getUserAgent){ + + zval *server = NULL, *_SERVER, *user_agent = NULL; + + PHALCON_MM_GROW(); + + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + PHALCON_CPY_WRT(server, _SERVER); + if (phalcon_array_isset_quick_string(server, SS("HTTP_USER_AGENT"), 12675185UL)) { + PHALCON_OBS_VAR(user_agent); + phalcon_array_fetch_quick_string(&user_agent, server, SS("HTTP_USER_AGENT"), 12675185UL, PH_NOISY); } else { - PHALCON_INIT_NVAR(result_data); - ZVAL_BOOL(result_data, 0); - } - - PHALCON_OBS_VAR(cache); - phalcon_read_property_this_quick(&cache, this_ptr, SL("_cache"), 2191407384UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(is_complex)) { - - if (PHALCON_IS_TRUE(is_simple_std)) { - PHALCON_INIT_VAR(result_object); - object_init_ex(result_object, phalcon_mvc_model_row_ce); - - PHALCON_INIT_NVAR(is_keeping_snapshots); - ZVAL_BOOL(is_keeping_snapshots, 0); - } else { - PHALCON_CPY_WRT(result_object, model); - - PHALCON_INIT_NVAR(simple_column_map); - phalcon_call_method_p1_key(simple_column_map, meta_data, "getcolumnmap", model, 213063537UL); - - PHALCON_INIT_NVAR(is_keeping_snapshots); - phalcon_call_method_p1_key(is_keeping_snapshots, manager, "iskeepingsnapshots", model, 2646609383UL); - } - - PHALCON_INIT_VAR(resultset); - object_init_ex(resultset, phalcon_mvc_model_resultset_simple_ce); - phalcon_call_method_p5_key(NULL, resultset, "__construct", simple_column_map, result_object, result_data, cache, is_keeping_snapshots, 1107214344UL); - - RETURN_CTOR(resultset); + PHALCON_INIT_NVAR(user_agent); + ZVAL_STRING(user_agent, "", 1); } - PHALCON_INIT_NVAR(resultset); - object_init_ex(resultset, phalcon_mvc_model_resultset_complex_ce); - phalcon_call_method_p3_key(NULL, resultset, "__construct", columns, result_data, cache, 1107214344UL); - - RETURN_CTOR(resultset); + RETURN_CCTOR(user_agent); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _executeInsert){ +static PHP_METHOD(Phalcon_Http_Request, isMethod){ - zval *intermediate, *bind_params, *bind_types; - zval *model_name, *manager, *models_instances; - zval *model = NULL, *connection, *meta_data, *attributes; - zval *automatic_fields = NULL, *fields = NULL, *column_map = NULL; - zval *values, *number_fields, *number_values; - zval *dialect, *double_colon, *empty_string; - zval *null_value, *not_exists, *insert_values; - zval *value = NULL, *number = NULL, *type = NULL, *expr_value = NULL, *insert_value = NULL; - zval *insert_expr = NULL, *wildcard = NULL, *exception_message = NULL; - zval *field_name = NULL, *attribute_name = NULL, *base_model; - zval *insert_model, *success; + zval *methods, *http_method, *is_equals, *method = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &intermediate, &bind_params, &bind_types); - - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch_quick_string(&model_name, intermediate, SS("model"), 238191286UL, PH_NOISY); - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 0, &methods); - PHALCON_OBS_VAR(models_instances); - phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); - if (phalcon_array_isset(models_instances, model_name)) { - PHALCON_OBS_VAR(model); - phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); + PHALCON_INIT_VAR(http_method); + phalcon_call_method_key(http_method, this_ptr, "getmethod", 2473474950UL); + + if (Z_TYPE_P(methods) == IS_STRING) { + PHALCON_INIT_VAR(is_equals); + is_equal_function(is_equals, methods, http_method TSRMLS_CC); + RETURN_NCTOR(is_equals); } else { - PHALCON_INIT_NVAR(model); - phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); - } - PHALCON_INIT_VAR(connection); - phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); + phalcon_is_iterable(methods, &ah0, &hp0, 0, 0); - PHALCON_OBS_VAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getattributes", model, 1013165772UL); + PHALCON_GET_HVALUE(method); - PHALCON_INIT_VAR(automatic_fields); - ZVAL_BOOL(automatic_fields, 0); + if (PHALCON_IS_EQUAL(method, http_method)) { + RETURN_MM_TRUE; + } - if (phalcon_array_isset_quick_string(intermediate, SS("fields"), 2881624156UL)) { - PHALCON_OBS_VAR(fields); - phalcon_array_fetch_quick_string(&fields, intermediate, SS("fields"), 2881624156UL, PH_NOISY); - } else { - ZVAL_BOOL(automatic_fields, 1); - PHALCON_CPY_WRT(fields, attributes); - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", model, 213063537UL); - } else { - PHALCON_INIT_NVAR(column_map); + zend_hash_move_forward_ex(ah0, &hp0); } - } - - PHALCON_OBS_VAR(values); - phalcon_array_fetch_quick_string(&values, intermediate, SS("values"), 1765818005UL, PH_NOISY); - - PHALCON_INIT_VAR(number_fields); - phalcon_fast_count(number_fields, fields TSRMLS_CC); - PHALCON_INIT_VAR(number_values); - phalcon_fast_count(number_values, values TSRMLS_CC); - - if (!PHALCON_IS_EQUAL(number_fields, number_values)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The column count does not match the values count"); - return; } - PHALCON_INIT_VAR(dialect); - phalcon_call_method_key(dialect, connection, "getdialect", 3133083739UL); - - PHALCON_INIT_VAR(double_colon); - ZVAL_STRING(double_colon, ":", 1); - - PHALCON_INIT_VAR(empty_string); - ZVAL_STRING(empty_string, "", 1); - - PHALCON_INIT_VAR(null_value); - - PHALCON_INIT_VAR(not_exists); - ZVAL_BOOL(not_exists, 0); - - PHALCON_INIT_VAR(insert_values); - array_init(insert_values); - - phalcon_is_iterable(values, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(number, ah0, hp0); - PHALCON_GET_HVALUE(value); - - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, value, SS("type"), 276192743UL, PH_NOISY); - - PHALCON_OBS_NVAR(expr_value); - phalcon_array_fetch_quick_string(&expr_value, value, SS("value"), 574111618UL, PH_NOISY); - - switch (phalcon_get_intval(type)) { - - case 260: - PHALCON_INIT_NVAR(insert_value); - phalcon_call_method_p1_key(insert_value, dialect, "getsqlexpression", expr_value, 3377787077UL); - break; - - case 258: - PHALCON_INIT_NVAR(insert_value); - phalcon_call_method_p1_key(insert_value, dialect, "getsqlexpression", expr_value, 3377787077UL); - break; - - case 259: - PHALCON_INIT_NVAR(insert_value); - phalcon_call_method_p1_key(insert_value, dialect, "getsqlexpression", expr_value, 3377787077UL); - break; - - case 322: - PHALCON_CPY_WRT(insert_value, null_value); - break; - - case 273: - if (Z_TYPE_P(bind_params) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Bound parameter cannot be replaced because placeholders is not an array"); - return; - } - - PHALCON_INIT_NVAR(insert_expr); - phalcon_call_method_p1_key(insert_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); - - PHALCON_INIT_NVAR(wildcard); - phalcon_fast_str_replace(wildcard, double_colon, empty_string, insert_expr); - if (!phalcon_array_isset(bind_params, wildcard)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Bound parameter '", wildcard, "' cannot be replaced because it isn't in the placeholders list"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_NVAR(insert_value); - phalcon_array_fetch(&insert_value, bind_params, wildcard, PH_NOISY); - break; - - case 274: - if (Z_TYPE_P(bind_params) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Bound parameter cannot be replaced because placeholders is not an array"); - return; - } - - PHALCON_INIT_NVAR(insert_expr); - phalcon_call_method_p1_key(insert_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); - - PHALCON_INIT_NVAR(wildcard); - phalcon_fast_str_replace(wildcard, double_colon, empty_string, insert_expr); - if (!phalcon_array_isset(bind_params, wildcard)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Bound parameter '", wildcard, "' cannot be replaced because it's not in the placeholders list"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_NVAR(insert_value); - phalcon_array_fetch(&insert_value, bind_params, wildcard, PH_NOISY); - break; - - default: - PHALCON_INIT_NVAR(insert_expr); - phalcon_call_method_p1_key(insert_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); - - PHALCON_INIT_NVAR(insert_value); - object_init_ex(insert_value, phalcon_db_rawvalue_ce); - phalcon_call_method_p1_key(NULL, insert_value, "__construct", insert_expr, 1107214344UL); - - break; - - } - - PHALCON_OBS_NVAR(field_name); - phalcon_array_fetch(&field_name, fields, number, PH_NOISY); - - if (PHALCON_IS_TRUE(automatic_fields)) { - - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, field_name)) { - PHALCON_OBS_NVAR(attribute_name); - phalcon_array_fetch(&attribute_name, column_map, field_name, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", field_name, "\" isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(attribute_name, field_name); - } - } else { - PHALCON_CPY_WRT(attribute_name, field_name); - } - - phalcon_array_update_zval(&insert_values, attribute_name, &insert_value, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Http_Request, isPost){ + + zval *post, *method; + + if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { + const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); + RETURN_BOOL(!strcmp(method, "POST")); } - - PHALCON_INIT_VAR(base_model); - phalcon_call_method_p1_key(base_model, manager, "load", model_name, 266329637UL); - - PHALCON_INIT_VAR(insert_model); - if (phalcon_clone(insert_model, base_model TSRMLS_CC) == FAILURE) { - return; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(post); + ZVAL_STRING(post, "POST", 1); + + PHALCON_INIT_VAR(method); + phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); + is_equal_function(return_value, method, post TSRMLS_CC); + + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, isGet){ + + zval *get, *method; + + if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { + const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); + RETURN_BOOL(!strcmp(method, "GET")); } - - PHALCON_INIT_VAR(success); - phalcon_call_method_p1_key(success, insert_model, "create", insert_values, 3654027737UL); - - object_init_ex(return_value, phalcon_mvc_model_query_status_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", success, insert_model, 1107214344UL); - + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(get); + ZVAL_STRING(get, "GET", 1); + + PHALCON_INIT_VAR(method); + phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); + is_equal_function(return_value, method, get TSRMLS_CC); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getRelatedRecords){ +static PHP_METHOD(Phalcon_Http_Request, isPut){ - zval *model, *intermediate, *bind_params, *bind_types; - zval *selected_tables, *selected_models, *source; - zval *model_name, *select_column, *selected_columns; - zval *select_ir, *where_conditions, *limit_conditions; - zval *type_select, *dependency_injector, *query; - zval *records; - zval *a0 = NULL; + zval *put, *method; + + if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { + const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); + RETURN_BOOL(!strcmp(method, "PUT")); + } PHALCON_MM_GROW(); - phalcon_fetch_params(1, 4, 0, &model, &intermediate, &bind_params, &bind_types); - - PHALCON_OBS_VAR(selected_tables); - phalcon_array_fetch_quick_string(&selected_tables, intermediate, SS("tables"), 3465666720UL, PH_NOISY); - - PHALCON_OBS_VAR(selected_models); - phalcon_array_fetch_quick_string(&selected_models, intermediate, SS("models"), 3565348937UL, PH_NOISY); - - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, model, "getsource", 2025234358UL); - - PHALCON_INIT_VAR(model_name); - phalcon_get_class(model_name, model, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(select_column); - array_init_size(select_column, 1); - - PHALCON_INIT_VAR(a0); - array_init_size(a0, 3); - add_assoc_stringl_ex(a0, SS("type"), SL("object"), 1); - phalcon_array_update_quick_string(&a0, SS("model"), 238191286UL, &model_name, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&a0, SS("column"), 3545634419UL, &source, PH_COPY | PH_SEPARATE); - phalcon_array_append(&select_column, a0, PH_SEPARATE); - - PHALCON_INIT_VAR(selected_columns); - array_init_size(selected_columns, 1); - phalcon_array_append(&selected_columns, select_column, PH_SEPARATE); - - PHALCON_INIT_VAR(select_ir); - array_init_size(select_ir, 3); - phalcon_array_update_quick_string(&select_ir, SS("columns"), 1041822630UL, &select_column, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&select_ir, SS("models"), 3565348937UL, &selected_models, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&select_ir, SS("tables"), 3465666720UL, &selected_tables, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(put); + ZVAL_STRING(put, "PUT", 1); + + PHALCON_INIT_VAR(method); + phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); + is_equal_function(return_value, method, put TSRMLS_CC); - if (phalcon_array_isset_quick_string(intermediate, SS("where"), 621293632UL)) { - PHALCON_OBS_VAR(where_conditions); - phalcon_array_fetch_quick_string(&where_conditions, intermediate, SS("where"), 621293632UL, PH_NOISY); - phalcon_array_update_quick_string(&select_ir, SS("where"), 621293632UL, &where_conditions, PH_COPY | PH_SEPARATE); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, isPatch){ + + zval *patch, *method; + + if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { + const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); + RETURN_BOOL(!strcmp(method, "PATCH")); } + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(patch); + ZVAL_STRING(patch, "PATCH", 1); + + PHALCON_INIT_VAR(method); + phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); + is_equal_function(return_value, method, patch TSRMLS_CC); - if (phalcon_array_isset_quick_string(intermediate, SS("limit"), 192268420UL)) { - PHALCON_OBS_VAR(limit_conditions); - phalcon_array_fetch_quick_string(&limit_conditions, intermediate, SS("limit"), 192268420UL, PH_NOISY); - phalcon_array_update_quick_string(&select_ir, SS("limit"), 192268420UL, &limit_conditions, PH_COPY | PH_SEPARATE); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, isHead){ + + zval *head, *method; + + if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { + const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); + RETURN_BOOL(!strcmp(method, "HEAD")); } + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(head); + ZVAL_STRING(head, "HEAD", 1); + + PHALCON_INIT_VAR(method); + phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); + is_equal_function(return_value, method, head TSRMLS_CC); - PHALCON_INIT_VAR(type_select); - ZVAL_LONG(type_select, 309); - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, isDelete){ + + zval *delete, *method; + + if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { + const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); + RETURN_BOOL(!strcmp(method, "DELETE")); + } + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(delete); + ZVAL_STRING(delete, "DELETE", 1); + + PHALCON_INIT_VAR(method); + phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); + is_equal_function(return_value, method, delete TSRMLS_CC); - PHALCON_INIT_VAR(query); - object_init_ex(query, phalcon_mvc_model_query_ce); - phalcon_call_method_key(NULL, query, "__construct", 1107214344UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, isOptions){ + + zval *options, *method; + + if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { + const char *method = phalcon_http_request_getmethod_helper(TSRMLS_C); + RETURN_BOOL(!strcmp(method, "OPTIONS")); + } + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(options); + ZVAL_STRING(options, "OPTIONS", 1); + + PHALCON_INIT_VAR(method); + phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); + is_equal_function(return_value, method, options TSRMLS_CC); - phalcon_call_method_p1_key(NULL, query, "setdi", dependency_injector, 461718238UL); - phalcon_call_method_p1_key(NULL, query, "settype", type_select, 319662579UL); - phalcon_call_method_p1_key(NULL, query, "setintermediate", select_ir, 3787545516UL); + RETURN_MM(); +} + +static int phalcon_http_request_hasfiles_helper(zval *arr, int only_successful) +{ + HashTable *ah0; + HashPosition hp0; + zval **hd; + int nfiles = 0; + + assert(Z_TYPE_P(arr) == IS_ARRAY); + + phalcon_is_iterable_ex(arr, &ah0, &hp0, 0, 0); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (Z_TYPE_PP(hd) < IS_ARRAY) { + if (!zend_is_true(*hd) || !only_successful) { + ++nfiles; + } + } + else if (Z_TYPE_PP(hd) == IS_ARRAY) { + nfiles += phalcon_http_request_hasfiles_helper(*hd, only_successful); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + return nfiles; +} + +static PHP_METHOD(Phalcon_Http_Request, hasFiles){ + + zval *not_errored = NULL, *_FILES, *error = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + int nfiles = 0; + int only_successful; + + phalcon_fetch_params(0, 0, 1, ¬_errored); - PHALCON_INIT_VAR(records); - phalcon_call_method_p2_key(records, query, "execute", bind_params, bind_types, 3117639032UL); + only_successful = not_errored ? phalcon_get_intval(not_errored) : 1; - RETURN_CCTOR(records); + phalcon_get_global(&_FILES, SS("_FILES") TSRMLS_CC); + if (unlikely(Z_TYPE_P(_FILES) != IS_ARRAY)) { + RETURN_LONG(0); + } + + phalcon_is_iterable(_FILES, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + if (phalcon_array_isset_string(*hd, SS("error"))) { + phalcon_array_fetch_string(&error, *hd, SL("error"), PH_NOISY); + assert(Z_REFCOUNT_P(error) > 1); + Z_DELREF_P(error); + + if (Z_TYPE_P(error) < IS_ARRAY) { + if (!zend_is_true(error) || !only_successful) { + ++nfiles; + } + } + else if (Z_TYPE_P(error) == IS_ARRAY) { + nfiles += phalcon_http_request_hasfiles_helper(error, only_successful); + } + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_LONG(nfiles); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _executeUpdate){ +static void phalcon_http_request_getuploadedfiles_helper(zval **return_value, zval *name, zval *type, zval *tmp_name, zval *error, zval *size, int only_successful, smart_str *prefix TSRMLS_DC) +{ + if ( + Z_TYPE_P(name) == IS_ARRAY && Z_TYPE_P(type) == IS_ARRAY + && Z_TYPE_P(tmp_name) == IS_ARRAY && Z_TYPE_P(error) == IS_ARRAY + && Z_TYPE_P(size) == IS_ARRAY + ) { + HashPosition pos_name, pos_type, pos_tmp, pos_error, pos_size; + zval **dname, **dtype, **dtmp, **derror, **dsize; + zval *arr, *file, *key; + size_t prefix_len = prefix->len; + zval *params[2]; + int res; - zval *intermediate, *bind_params, *bind_types; - zval *models, *model_name, *models_instances; - zval *model = NULL, *manager, *connection = NULL, *dialect, *double_colon; - zval *empty_string, *fields, *values, *update_values; - zval *select_bind_params = NULL, *select_bind_types = NULL; - zval *null_value, *field = NULL, *number = NULL, *field_name = NULL; - zval *value = NULL, *type = NULL, *expr_value = NULL, *update_value = NULL; - zval *update_expr = NULL, *wildcard = NULL, *exception_message = NULL; - zval *records, *success = NULL, *record = NULL; - zval *r0 = NULL; + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(name), &pos_name); + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(type), &pos_type); + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(tmp_name), &pos_tmp); + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(error), &pos_error); + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(size), &pos_size); + + while ( + zend_hash_get_current_data_ex(Z_ARRVAL_P(name), (void**)&dname, &pos_name) == SUCCESS + && zend_hash_get_current_data_ex(Z_ARRVAL_P(type), (void**)&dtype, &pos_type) == SUCCESS + && zend_hash_get_current_data_ex(Z_ARRVAL_P(tmp_name), (void**)&dtmp, &pos_tmp) == SUCCESS + && zend_hash_get_current_data_ex(Z_ARRVAL_P(error), (void**)&derror, &pos_error) == SUCCESS + && zend_hash_get_current_data_ex(Z_ARRVAL_P(size), (void**)&dsize, &pos_size) == SUCCESS + && !EG(exception) + ) { + zval index = phalcon_get_current_key_w(Z_ARRVAL_P(name), &pos_name); + + if (Z_TYPE(index) == IS_STRING) { + smart_str_appendl(prefix, Z_STRVAL(index), Z_STRLEN(index)); + } + else { + smart_str_append_long(prefix, Z_LVAL(index)); + } + + if (Z_TYPE_PP(derror) < IS_ARRAY) { + if (!zend_is_true(*derror) || !only_successful) { + Z_ADDREF_PP(dname); + Z_ADDREF_PP(dtype); + Z_ADDREF_PP(dtmp); + Z_ADDREF_PP(derror); + Z_ADDREF_PP(dsize); + + ALLOC_INIT_ZVAL(arr); + array_init_size(arr, 5); + add_assoc_zval_ex(arr, SS("name"), *dname); + add_assoc_zval_ex(arr, SS("type"), *dtype); + add_assoc_zval_ex(arr, SS("tmp_name"), *dtmp); + add_assoc_zval_ex(arr, SS("error"), *derror); + add_assoc_zval_ex(arr, SS("size"), *dsize); + + ALLOC_INIT_ZVAL(key); + ZVAL_STRINGL(key, prefix->c, prefix->len, 1); + prefix->len = prefix_len; + + ALLOC_INIT_ZVAL(file); + object_init_ex(file, phalcon_http_request_file_ce); + + params[0] = arr; + params[1] = key; + res = phalcon_call_method_params_w(NULL, file, SL("__construct"), 2, params, 0, 0 TSRMLS_CC); + + zval_ptr_dtor(&arr); + zval_ptr_dtor(&key); + + if (res != FAILURE) { + add_next_index_zval(*return_value, file); + } + else { + break; + } + } + } + else if (Z_TYPE_PP(derror) == IS_ARRAY) { + smart_str_appendc(prefix, '.'); + phalcon_http_request_getuploadedfiles_helper(return_value, *dname, *dtype, *dtmp, *derror, *dsize, only_successful, prefix TSRMLS_CC); + prefix->len = prefix_len; + } + + zend_hash_move_forward_ex(Z_ARRVAL_P(name), &pos_name); + zend_hash_move_forward_ex(Z_ARRVAL_P(type), &pos_type); + zend_hash_move_forward_ex(Z_ARRVAL_P(tmp_name), &pos_tmp); + zend_hash_move_forward_ex(Z_ARRVAL_P(error), &pos_error); + zend_hash_move_forward_ex(Z_ARRVAL_P(size), &pos_size); + } + } +} + +static PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ + + zval *name = NULL, *type = NULL, *tmp_name = NULL, *error = NULL, *size = NULL; + zval *not_errored = NULL, *_FILES, *request_file = NULL, *key = NULL; + zval index; HashTable *ah0; HashPosition hp0; zval **hd; + int only_successful; + smart_str prefix = { NULL, 0, 0 }; + + phalcon_fetch_params(0, 0, 1, ¬_errored); + + only_successful = not_errored ? phalcon_get_intval(not_errored) : 1; + + array_init(return_value); + + phalcon_get_global(&_FILES, SS("_FILES") TSRMLS_CC); + if (Z_TYPE_P(_FILES) != IS_ARRAY || !zend_hash_num_elements(Z_ARRVAL_P(_FILES))) { + return; + } PHALCON_MM_GROW(); + phalcon_is_iterable(_FILES, &ah0, &hp0, 0, 0); - phalcon_fetch_params(1, 3, 0, &intermediate, &bind_params, &bind_types); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS && !EG(exception)) { + + if (phalcon_array_isset_string(*hd, SS("error"))) { + PHALCON_OBS_NVAR(error); + phalcon_array_fetch_string(&error, *hd, SL("error"), PH_NOISY); + index = phalcon_get_current_key_w(ah0, &hp0); + + if (Z_TYPE_P(error) < IS_ARRAY) { + if (!zend_is_true(error) || !only_successful) { + PHALCON_INIT_NVAR(request_file); + object_init_ex(request_file, phalcon_http_request_file_ce); + + PHALCON_INIT_NVAR(key); + ZVAL_STRINGL(key, Z_STRVAL(index), Z_STRLEN(index), 1); + + Z_ADDREF_PP(hd); + phalcon_call_method_p2_noret(request_file, "__construct", *hd, key); + + phalcon_array_append(&return_value, request_file, 0); + } + } + else if (Z_TYPE_P(error) == IS_ARRAY) { + PHALCON_OBS_NVAR(name); + PHALCON_OBS_NVAR(type); + PHALCON_OBS_NVAR(tmp_name); + PHALCON_OBS_NVAR(size); + phalcon_array_fetch_string(&name, *hd, SL("name"), PH_NOISY); + phalcon_array_fetch_string(&type, *hd, SL("type"), PH_NOISY); + phalcon_array_fetch_string(&tmp_name, *hd, SL("tmp_name"), PH_NOISY); + phalcon_array_fetch_string(&size, *hd, SL("size"), PH_NOISY); + + if (prefix.len) { + prefix.len = 0; + } + + if (likely(Z_TYPE(index) == IS_STRING)) { + smart_str_appendl(&prefix, Z_STRVAL(index), Z_STRLEN(index)); + } + else { + smart_str_append_long(&prefix, Z_LVAL(index)); + } + + smart_str_appendc(&prefix, '.'); + phalcon_http_request_getuploadedfiles_helper(&return_value, name, type, tmp_name, error, size, only_successful, &prefix TSRMLS_CC); + } + } + + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_OBS_VAR(models); - phalcon_array_fetch_quick_string(&models, intermediate, SS("models"), 3565348937UL, PH_NOISY); - if (phalcon_array_isset_long(models, 1)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Updating several models at the same time is still not supported"); + if (prefix.c) { + smart_str_free(&prefix); + } + + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, getHeaders){ + + zval *_SERVER, *key = NULL, *header = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + array_init(return_value); + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + if (unlikely(Z_TYPE_P(_SERVER) != IS_ARRAY)) { return; } + + PHALCON_MM_GROW(); - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); - - PHALCON_OBS_VAR(models_instances); - phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); - if (phalcon_array_isset(models_instances, model_name)) { - PHALCON_OBS_VAR(model); - phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); - } else { - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(model); - phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); - } + phalcon_is_iterable(_SERVER, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(connection); - phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(dialect); - phalcon_call_method_key(dialect, connection, "getdialect", 3133083739UL); + PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_INIT_VAR(double_colon); - ZVAL_STRING(double_colon, ":", 1); + if (phalcon_start_with_str(key, SL("HTTP_"))) { + PHALCON_INIT_NVAR(header); + phalcon_substr(header, key, 5, 0); + phalcon_array_update_zval(&return_value, header, hd, PH_COPY); + } - PHALCON_INIT_VAR(empty_string); - ZVAL_STRING(empty_string, "", 1); + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_OBS_VAR(fields); - phalcon_array_fetch_quick_string(&fields, intermediate, SS("fields"), 2881624156UL, PH_NOISY); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Http_Request, getHTTPReferer){ + + zval *_SERVER, *http_referer; + + PHALCON_MM_GROW(); + + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + if (phalcon_array_isset_quick_string(_SERVER, SS("HTTP_REFERER"), 609736271UL)) { + PHALCON_OBS_VAR(http_referer); + phalcon_array_fetch_quick_string(&http_referer, _SERVER, SS("HTTP_REFERER"), 609736271UL, PH_NOISY); + RETURN_CCTOR(http_referer); + } + RETURN_MM_EMPTY_STRING(); +} + +static PHP_METHOD(Phalcon_Http_Request, _getQualityHeader){ + + zval *server_index, *name, *quality_one; + zval *http_server, *pattern, *parts, *part = NULL, *header_parts = NULL; + zval *quality_part = NULL, *quality = NULL, *header_name = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &server_index, &name); - PHALCON_OBS_VAR(values); - phalcon_array_fetch_quick_string(&values, intermediate, SS("values"), 1765818005UL, PH_NOISY); + PHALCON_INIT_VAR(quality_one); + ZVAL_DOUBLE(quality_one, 1); - PHALCON_INIT_VAR(update_values); - array_init(update_values); + array_init(return_value); - PHALCON_CPY_WRT(select_bind_params, bind_params); - PHALCON_CPY_WRT(select_bind_types, bind_types); + PHALCON_INIT_VAR(http_server); + phalcon_call_method_p1_key(http_server, this_ptr, "getserver", server_index, 1630469020UL); - PHALCON_INIT_VAR(null_value); + PHALCON_INIT_VAR(pattern); + ZVAL_STRING(pattern, "/,\\s*/", 1); + PHALCON_INIT_VAR(parts); + phalcon_call_func_p2(parts, "preg_split", pattern, http_server); - phalcon_is_iterable(fields, &ah0, &hp0, 0, 0); + phalcon_is_iterable(parts, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_GET_HKEY(number, ah0, hp0); - PHALCON_GET_HVALUE(field); + PHALCON_GET_HVALUE(part); - PHALCON_OBS_NVAR(field_name); - phalcon_array_fetch_quick_string(&field_name, field, SS("name"), 268211462UL, PH_NOISY); + PHALCON_INIT_NVAR(header_parts); + phalcon_fast_explode_str(header_parts, SL(";"), part); + if (phalcon_array_isset_long(header_parts, 1)) { + PHALCON_OBS_NVAR(quality_part); + phalcon_array_fetch_long(&quality_part, header_parts, 1, PH_NOISY); - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, values, number, PH_NOISY); + PHALCON_INIT_NVAR(quality); + phalcon_substr(quality, quality_part, 2, 0); + } else { + PHALCON_CPY_WRT(quality, quality_one); + } - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, value, SS("type"), 276192743UL, PH_NOISY); + PHALCON_OBS_NVAR(header_name); + phalcon_array_fetch_long(&header_name, header_parts, 0, PH_NOISY); - PHALCON_OBS_NVAR(expr_value); - phalcon_array_fetch_quick_string(&expr_value, value, SS("value"), 574111618UL, PH_NOISY); + PHALCON_INIT_NVAR(quality_part); + array_init_size(quality_part, 2); + phalcon_array_update_zval(&quality_part, name, &header_name, PH_COPY); + phalcon_array_update_quick_string(&quality_part, SS("quality"), 3712111054UL, &quality, PH_COPY); + phalcon_array_append(&return_value, quality_part, 0); - switch (phalcon_get_intval(type)) { + zend_hash_move_forward_ex(ah0, &hp0); + } - case 260: - PHALCON_INIT_NVAR(update_value); - phalcon_call_method_p1_key(update_value, dialect, "getsqlexpression", expr_value, 3377787077UL); - break; - - case 258: - PHALCON_INIT_NVAR(update_value); - phalcon_call_method_p1_key(update_value, dialect, "getsqlexpression", expr_value, 3377787077UL); - break; - - case 259: - PHALCON_INIT_NVAR(update_value); - phalcon_call_method_p1_key(update_value, dialect, "getsqlexpression", expr_value, 3377787077UL); - break; - - case 322: - PHALCON_CPY_WRT(update_value, null_value); - break; - - case 273: - if (Z_TYPE_P(bind_params) == IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Bound parameter cannot be replaced because placeholders is not an array"); - return; - } - - PHALCON_INIT_NVAR(update_expr); - phalcon_call_method_p1_key(update_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); - - PHALCON_INIT_NVAR(wildcard); - phalcon_fast_str_replace(wildcard, double_colon, empty_string, update_expr); - if (phalcon_array_isset(bind_params, wildcard)) { - PHALCON_OBS_NVAR(update_value); - phalcon_array_fetch(&update_value, bind_params, wildcard, PH_NOISY); - phalcon_array_unset(&select_bind_params, wildcard, PH_SEPARATE); - phalcon_array_unset(&select_bind_types, wildcard, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Bound parameter '", wildcard, "' cannot be replaced because it's not in the placeholders list"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Http_Request, _getBestQuality){ + + zval *quality_parts, *name, *quality = NULL, *selected_name = NULL; + zval *accept = NULL, *accept_quality = NULL, *best_quality = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + long int i = 0; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &quality_parts, &name); - break; + PHALCON_INIT_VAR(quality); + ZVAL_LONG(quality, 0); - case 274: - if (Z_TYPE_P(bind_params) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Bound parameter cannot be replaced because placeholders is not an array"); - return; - } + PHALCON_INIT_VAR(selected_name); + ZVAL_EMPTY_STRING(selected_name); - PHALCON_INIT_NVAR(update_expr); - phalcon_call_method_p1_key(update_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); + phalcon_is_iterable(quality_parts, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(wildcard); - phalcon_fast_str_replace(wildcard, double_colon, empty_string, update_expr); - if (phalcon_array_isset(bind_params, wildcard)) { - PHALCON_OBS_NVAR(update_value); - phalcon_array_fetch(&update_value, bind_params, wildcard, PH_NOISY); - phalcon_array_unset(&select_bind_params, wildcard, PH_SEPARATE); - phalcon_array_unset(&select_bind_types, wildcard, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Bound parameter '", wildcard, "' cannot be replaced because it's not in the placeholders list"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - break; + PHALCON_GET_HVALUE(accept); - default: - PHALCON_INIT_NVAR(update_expr); - phalcon_call_method_p1_key(update_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); + if (i == 0) { + PHALCON_OBS_NVAR(quality); + phalcon_array_fetch_quick_string(&quality, accept, SS("quality"), 3712111054UL, PH_NOISY); - PHALCON_INIT_NVAR(update_value); - object_init_ex(update_value, phalcon_db_rawvalue_ce); - phalcon_call_method_p1_key(NULL, update_value, "__construct", update_expr, 1107214344UL); + PHALCON_OBS_NVAR(selected_name); + phalcon_array_fetch(&selected_name, accept, name, PH_NOISY); + } else { + PHALCON_OBS_NVAR(accept_quality); + phalcon_array_fetch_quick_string(&accept_quality, accept, SS("quality"), 3712111054UL, PH_NOISY); - break; + PHALCON_INIT_NVAR(best_quality); + is_smaller_function(best_quality, quality, accept_quality TSRMLS_CC); + if (PHALCON_IS_TRUE(best_quality)) { + PHALCON_CPY_WRT(quality, accept_quality); + PHALCON_OBS_NVAR(selected_name); + phalcon_array_fetch(&selected_name, accept, name, PH_NOISY); + } } - phalcon_array_update_zval(&update_values, field_name, &update_value, PH_COPY | PH_SEPARATE); - + + ++i; zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_INIT_VAR(records); - phalcon_call_method_p4_key(records, this_ptr, "_getrelatedrecords", model, intermediate, select_bind_params, select_bind_types, 1071693079UL); - - if (!phalcon_fast_count_ev(records TSRMLS_CC)) { - PHALCON_INIT_VAR(success); - ZVAL_BOOL(success, 1); - object_init_ex(return_value, phalcon_mvc_model_query_status_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", success, null_value, 1107214344UL); - - RETURN_MM(); - } - - PHALCON_INIT_NVAR(connection); - phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); - - phalcon_call_method_key(NULL, connection, "begin", 4090922282UL); - phalcon_call_method_key(NULL, records, "rewind", 1064078190UL); + RETURN_CCTOR(selected_name); +} + +static PHP_METHOD(Phalcon_Http_Request, getAcceptableContent){ + + zval *accept_header, *quality_index; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(accept_header); + ZVAL_STRING(accept_header, "HTTP_ACCEPT", 1); - while (1) { + PHALCON_INIT_VAR(quality_index); + ZVAL_STRING(quality_index, "accept", 1); + phalcon_call_method_p2_key(return_value, this_ptr, "_getqualityheader", accept_header, quality_index, 757409206UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, getBestAccept){ + + zval *quality_index, *acceptable_content; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(quality_index); + ZVAL_STRING(quality_index, "accept", 1); - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, records, "valid", 574098517UL); - if (PHALCON_IS_NOT_FALSE(r0)) { - } else { - break; - } + PHALCON_INIT_VAR(acceptable_content); + phalcon_call_method_key(acceptable_content, this_ptr, "getacceptablecontent", 3152475684UL); + phalcon_call_method_p2_key(return_value, this_ptr, "_getbestquality", acceptable_content, quality_index, 2752999675UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, getClientCharsets){ + + zval *charset_header, *quality_index; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(charset_header); + ZVAL_STRING(charset_header, "HTTP_ACCEPT_CHARSET", 1); - PHALCON_INIT_NVAR(record); - phalcon_call_method_key(record, records, "current", 431662984UL); + PHALCON_INIT_VAR(quality_index); + ZVAL_STRING(quality_index, "charset", 1); + phalcon_call_method_p2_key(return_value, this_ptr, "_getqualityheader", charset_header, quality_index, 757409206UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, getBestCharset){ + + zval *quality_index, *client_charsets; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(quality_index); + ZVAL_STRING(quality_index, "charset", 1); - PHALCON_INIT_NVAR(success); - phalcon_call_method_p1_key(success, record, "update", update_values, 1051190696UL); - if (!zend_is_true(success)) { - phalcon_call_method_key(NULL, connection, "rollback", 3199546639UL); - object_init_ex(return_value, phalcon_mvc_model_query_status_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", success, record, 1107214344UL); + PHALCON_INIT_VAR(client_charsets); + phalcon_call_method_key(client_charsets, this_ptr, "getclientcharsets", 166081441UL); + phalcon_call_method_p2_key(return_value, this_ptr, "_getbestquality", client_charsets, quality_index, 2752999675UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, getLanguages){ + + zval *language_header, *quality_index; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(language_header); + ZVAL_STRING(language_header, "HTTP_ACCEPT_LANGUAGE", 1); - RETURN_MM(); - } + PHALCON_INIT_VAR(quality_index); + ZVAL_STRING(quality_index, "language", 1); + phalcon_call_method_p2_key(return_value, this_ptr, "_getqualityheader", language_header, quality_index, 757409206UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Http_Request, getBestLanguage){ + + zval *languages, *quality_index; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(languages); + phalcon_call_method_key(languages, this_ptr, "getlanguages", 2261985372UL); - phalcon_call_method_key(NULL, records, "next", 268367684UL); - } + PHALCON_INIT_VAR(quality_index); + ZVAL_STRING(quality_index, "language", 1); + phalcon_call_method_p2_key(return_value, this_ptr, "_getbestquality", languages, quality_index, 2752999675UL); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Http_RequestInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Http, RequestInterface, http_requestinterface, phalcon_http_requestinterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Http_Response_Cookies){ + + PHALCON_REGISTER_CLASS(Phalcon\\Http\\Response, Cookies, http_response_cookies, phalcon_http_response_cookies_method_entry, 0); + + zend_declare_property_null(phalcon_http_response_cookies_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_http_response_cookies_ce, SL("_registered"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_http_response_cookies_ce, SL("_useEncryption"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_response_cookies_ce, SL("_cookies"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_http_response_cookies_ce TSRMLS_CC, 2, phalcon_http_response_cookiesinterface_ce, phalcon_di_injectionawareinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Http_Response_Cookies, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); - phalcon_call_method_key(NULL, connection, "commit", 3546528686UL); + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - PHALCON_INIT_NVAR(success); - ZVAL_BOOL(success, 1); - object_init_ex(return_value, phalcon_mvc_model_query_status_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", success, null_value, 1107214344UL); +} + +static PHP_METHOD(Phalcon_Http_Response_Cookies, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} + +static PHP_METHOD(Phalcon_Http_Response_Cookies, useEncryption){ + + zval *use_encryption; + + phalcon_fetch_params(0, 1, 0, &use_encryption); - RETURN_MM(); + phalcon_update_property_this_quick(this_ptr, SL("_useEncryption"), use_encryption, 2628069468UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, _executeDelete){ +static PHP_METHOD(Phalcon_Http_Response_Cookies, isUsingEncryption){ - zval *intermediate, *bind_params, *bind_types; - zval *models, *model_name, *models_instances; - zval *model = NULL, *manager, *records, *success = NULL, *null_value = NULL; - zval *connection, *record = NULL; - zval *r0 = NULL; + + RETURN_MEMBER_QUICK(this_ptr, "_useEncryption", 2628069468UL); +} + +static PHP_METHOD(Phalcon_Http_Response_Cookies, set){ + + zval *name, *value = NULL, *expire = NULL, *path = NULL, *secure = NULL, *domain = NULL; + zval *http_only = NULL, *cookies, *encryption, *dependency_injector = NULL; + zval *cookie = NULL, *registered, *service, *response; + zval *p0[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &intermediate, &bind_params, &bind_types); + phalcon_fetch_params(1, 1, 6, &name, &value, &expire, &path, &secure, &domain, &http_only); - PHALCON_OBS_VAR(models); - phalcon_array_fetch_quick_string(&models, intermediate, SS("models"), 3565348937UL, PH_NOISY); - if (phalcon_array_isset_long(models, 1)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Delete from several models at the same time is still not supported"); - return; + if (!value) { + PHALCON_INIT_VAR(value); } - PHALCON_OBS_VAR(model_name); - phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); - - PHALCON_OBS_VAR(models_instances); - phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); - if (phalcon_array_isset(models_instances, model_name)) { - PHALCON_OBS_VAR(model); - phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); - } else { - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + if (!expire) { + PHALCON_INIT_VAR(expire); + ZVAL_LONG(expire, 0); + } - PHALCON_INIT_NVAR(model); - phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + if (!path) { + PHALCON_INIT_VAR(path); + ZVAL_STRING(path, "/", 1); } - PHALCON_INIT_VAR(records); - phalcon_call_method_p4_key(records, this_ptr, "_getrelatedrecords", model, intermediate, bind_params, bind_types, 1071693079UL); + if (!secure) { + PHALCON_INIT_VAR(secure); + } - if (!phalcon_fast_count_ev(records TSRMLS_CC)) { - PHALCON_INIT_VAR(success); - ZVAL_BOOL(success, 1); + if (!domain) { + PHALCON_INIT_VAR(domain); + } - PHALCON_INIT_VAR(null_value); - object_init_ex(return_value, phalcon_mvc_model_query_status_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", success, null_value, 1107214344UL); + if (!http_only) { + PHALCON_INIT_VAR(http_only); + } - RETURN_MM(); + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_cookie_exception_ce, "The cookie name must be string"); + return; } - PHALCON_INIT_VAR(connection); - phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); + PHALCON_OBS_VAR(cookies); + phalcon_read_property_this_quick(&cookies, this_ptr, SL("_cookies"), 4109914289UL, PH_NOISY_CC); - phalcon_call_method_key(NULL, connection, "begin", 4090922282UL); - phalcon_call_method_key(NULL, records, "rewind", 1064078190UL); + PHALCON_OBS_VAR(encryption); + phalcon_read_property_this_quick(&encryption, this_ptr, SL("_useEncryption"), 2628069468UL, PH_NOISY_CC); - while (1) { + if (!phalcon_array_isset(cookies, name)) { - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, records, "valid", 574098517UL); - if (PHALCON_IS_NOT_FALSE(r0)) { - } else { - break; - } + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(record); - phalcon_call_method_key(record, records, "current", 431662984UL); + PHALCON_INIT_VAR(cookie); + object_init_ex(cookie, phalcon_http_cookie_ce); - PHALCON_INIT_NVAR(success); - phalcon_call_method_key(success, record, "delete", 150213496UL); - if (!zend_is_true(success)) { - phalcon_call_method_key(NULL, connection, "rollback", 3199546639UL); - object_init_ex(return_value, phalcon_mvc_model_query_status_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", success, record, 1107214344UL); + p0[0] = name; + p0[1] = value; + p0[2] = expire; + p0[3] = path; + p0[4] = secure; + p0[5] = domain; + p0[6] = http_only; + phalcon_call_method_pn_noret(cookie, "__construct", 7, p0); - RETURN_MM(); + phalcon_call_method_p1_key(NULL, cookie, "setdi", dependency_injector, 461718238UL); + + if (zend_is_true(encryption)) { + phalcon_call_method_p1_key(NULL, cookie, "useencryption", encryption, 603643197UL); } - phalcon_call_method_key(NULL, records, "next", 268367684UL); + phalcon_update_property_array(this_ptr, SL("_cookies"), name, cookie TSRMLS_CC); + } else { + PHALCON_OBS_NVAR(cookie); + phalcon_array_fetch(&cookie, cookies, name, PH_NOISY); + + phalcon_call_method_p1_key(NULL, cookie, "setvalue", value, 2008616206UL); + phalcon_call_method_p1_key(NULL, cookie, "setexpiration", expire, 3139452756UL); + phalcon_call_method_p1_key(NULL, cookie, "setpath", path, 314060862UL); + phalcon_call_method_p1_key(NULL, cookie, "setsecure", secure, 2426274520UL); + phalcon_call_method_p1_key(NULL, cookie, "setdomain", domain, 636609065UL); + phalcon_call_method_p1_key(NULL, cookie, "sethttponly", http_only, 393311635UL); } - phalcon_call_method_key(NULL, connection, "commit", 3546528686UL); + PHALCON_OBS_VAR(registered); + phalcon_read_property_this_quick(®istered, this_ptr, SL("_registered"), 3990603890UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(registered)) { - PHALCON_INIT_NVAR(success); - ZVAL_BOOL(success, 1); + PHALCON_OBS_NVAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_cookie_exception_ce, "A dependency injection object is required to access the 'response' service"); + return; + } - PHALCON_INIT_NVAR(null_value); - ZVAL_BOOL(null_value, 1); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "response", 1); - object_init_ex(return_value, phalcon_mvc_model_query_status_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", success, null_value, 1107214344UL); + PHALCON_INIT_VAR(response); + phalcon_call_method_p1_key(response, dependency_injector, "getshared", service, 1727570332UL); - RETURN_MM(); + phalcon_call_method_p1_key(NULL, response, "setcookies", this_ptr, 4249583934UL); + } + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, execute){ +static PHP_METHOD(Phalcon_Http_Response_Cookies, get){ - zval *bind_params = NULL, *bind_types = NULL, *unique_row; - zval *cache_options, *key, *lifetime = NULL, *cache_service = NULL; - zval *dependency_injector, *cache, *result = NULL, *is_fresh; - zval *prepared_result = NULL, *intermediate, *default_bind_params; - zval *merged_params = NULL, *default_bind_types; - zval *merged_types = NULL, *type, *exception_message; + zval *name, *cookies, *cookie = NULL, *dependency_injector; + zval *encryption; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &bind_params, &bind_types); + phalcon_fetch_params(1, 1, 0, &name); - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_cookie_exception_ce, "The cookie name must be string"); + return; } - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + PHALCON_OBS_VAR(cookies); + phalcon_read_property_this_quick(&cookies, this_ptr, SL("_cookies"), 4109914289UL, PH_NOISY_CC); + if (phalcon_array_isset(cookies, name)) { + PHALCON_OBS_VAR(cookie); + phalcon_array_fetch(&cookie, cookies, name, PH_NOISY); + RETURN_CCTOR(cookie); } - PHALCON_OBS_VAR(unique_row); - phalcon_read_property_this_quick(&unique_row, this_ptr, SL("_uniqueRow"), 1221667347UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(cache_options); - phalcon_read_property_this_quick(&cache_options, this_ptr, SL("_cacheOptions"), 528255652UL, PH_NOISY_CC); - if (Z_TYPE_P(cache_options) != IS_NULL) { - if (Z_TYPE_P(cache_options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid caching options"); - return; - } - - if (phalcon_array_isset_quick_string(cache_options, SS("key"), 2090432846UL)) { - PHALCON_OBS_VAR(key); - phalcon_array_fetch_quick_string(&key, cache_options, SS("key"), 2090432846UL, PH_NOISY); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A cache key must be provided to identify the cached resultset in the cache backend"); - return; - } + PHALCON_INIT_NVAR(cookie); + object_init_ex(cookie, phalcon_http_cookie_ce); + phalcon_call_method_p1_key(NULL, cookie, "__construct", name, 1107214344UL); - if (phalcon_array_isset_quick_string(cache_options, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_VAR(lifetime); - phalcon_array_fetch_quick_string(&lifetime, cache_options, SS("lifetime"), 2639810228UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(lifetime); - ZVAL_LONG(lifetime, 3600); - } + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { - if (phalcon_array_isset_quick_string(cache_options, SS("service"), 243174486UL)) { - PHALCON_OBS_VAR(cache_service); - phalcon_array_fetch_quick_string(&cache_service, cache_options, SS("service"), 243174486UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(cache_service); - ZVAL_STRING(cache_service, "modelsCache", 1); - } + phalcon_call_method_p1_key(NULL, cookie, "setdi", dependency_injector, 461718238UL); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + PHALCON_OBS_VAR(encryption); + phalcon_read_property_this_quick(&encryption, this_ptr, SL("_useEncryption"), 2628069468UL, PH_NOISY_CC); - PHALCON_INIT_VAR(cache); - phalcon_call_method_p1_key(cache, dependency_injector, "getshared", cache_service, 1727570332UL); - if (Z_TYPE_P(cache) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The cache service must be an object"); - return; + if (zend_is_true(encryption)) { + phalcon_call_method_p1_key(NULL, cookie, "useencryption", encryption, 603643197UL); } + } - PHALCON_INIT_VAR(result); - phalcon_call_method_p2_key(result, cache, "get", key, lifetime, 2090288933UL); - if (Z_TYPE_P(result) != IS_NULL) { - if (Z_TYPE_P(result) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The cache didn't return a valid resultset"); - return; - } - - PHALCON_INIT_VAR(is_fresh); - ZVAL_BOOL(is_fresh, 0); - phalcon_call_method_p1_key(NULL, result, "setisfresh", is_fresh, 2789062661UL); - - if (zend_is_true(unique_row)) { - PHALCON_INIT_VAR(prepared_result); - phalcon_call_method_key(prepared_result, result, "getfirst", 3710205613UL); - } else { - PHALCON_CPY_WRT(prepared_result, result); - } - - RETURN_CCTOR(prepared_result); - } + phalcon_update_property_array(this_ptr, SL("_cookies"), name, cookie TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); - } + RETURN_CCTOR(cookie); +} + +static PHP_METHOD(Phalcon_Http_Response_Cookies, has){ + + zval *name, *cookies, *_COOKIE; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - PHALCON_INIT_VAR(intermediate); - phalcon_call_method_key(intermediate, this_ptr, "parse", 339512704UL); + PHALCON_OBS_VAR(cookies); + phalcon_read_property_this_quick(&cookies, this_ptr, SL("_cookies"), 4109914289UL, PH_NOISY_CC); - PHALCON_OBS_VAR(default_bind_params); - phalcon_read_property_this_quick(&default_bind_params, this_ptr, SL("_bindParams"), 2293392709UL, PH_NOISY_CC); - if (Z_TYPE_P(default_bind_params) == IS_ARRAY) { - if (Z_TYPE_P(bind_params) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, &default_bind_params, &bind_params TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params, default_bind_params); - } - } else { - PHALCON_CPY_WRT(merged_params, bind_params); + if (phalcon_array_isset(cookies, name)) { + RETURN_MM_TRUE; } - PHALCON_OBS_VAR(default_bind_types); - phalcon_read_property_this_quick(&default_bind_types, this_ptr, SL("_bindTypes"), 514734038UL, PH_NOISY_CC); - if (Z_TYPE_P(default_bind_types) == IS_ARRAY) { - if (Z_TYPE_P(bind_types) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_types); - phalcon_fast_array_merge(merged_types, &default_bind_types, &bind_types TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_types, default_bind_types); - } - } else { - PHALCON_CPY_WRT(merged_types, bind_types); + phalcon_get_global(&_COOKIE, SS("_COOKIE") TSRMLS_CC); + if (phalcon_array_isset(_COOKIE, name)) { + RETURN_MM_TRUE; } - PHALCON_OBS_VAR(type); - phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Http_Response_Cookies, delete){ + + zval *name, *cookies, *cookie; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - switch (phalcon_get_intval(type)) { + PHALCON_OBS_VAR(cookies); + phalcon_read_property_this_quick(&cookies, this_ptr, SL("_cookies"), 4109914289UL, PH_NOISY_CC); - case 309: - PHALCON_INIT_NVAR(result); - phalcon_call_method_p3_key(result, this_ptr, "_executeselect", intermediate, merged_params, merged_types, 125194679UL); - break; + if (phalcon_array_isset(cookies, name)) { + PHALCON_OBS_VAR(cookie); + phalcon_array_fetch(&cookie, cookies, name, PH_NOISY); + phalcon_call_method_key(NULL, cookie, "delete", 150213496UL); + RETURN_MM_TRUE; + } - case 306: - PHALCON_INIT_NVAR(result); - phalcon_call_method_p3_key(result, this_ptr, "_executeinsert", intermediate, merged_params, merged_types, 455953196UL); - break; + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Http_Response_Cookies, send){ + + zval *cookies, *cookie = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + if (!SG(headers_sent)) { - case 300: - PHALCON_INIT_NVAR(result); - phalcon_call_method_p3_key(result, this_ptr, "_executeupdate", intermediate, merged_params, merged_types, 3129006842UL); - break; + PHALCON_OBS_VAR(cookies); + phalcon_read_property_this_quick(&cookies, this_ptr, SL("_cookies"), 4109914289UL, PH_NOISY_CC); - case 303: - PHALCON_INIT_NVAR(result); - phalcon_call_method_p3_key(result, this_ptr, "_executedelete", intermediate, merged_params, merged_types, 2228029642UL); - break; + phalcon_is_iterable(cookies, &ah0, &hp0, 0, 0); - default: - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Unknown statement ", type); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - } + PHALCON_GET_HVALUE(cookie); - if (Z_TYPE_P(cache_options) != IS_NULL) { + phalcon_call_method_key(NULL, cookie, "send", 274285871UL); - if (!PHALCON_IS_LONG(type, 309)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Only PHQL statements that return resultsets can be cached"); - return; + zend_hash_move_forward_ex(ah0, &hp0); } - phalcon_call_method_p3_key(NULL, cache, "save", key, result, lifetime, 274150868UL); - } - if (zend_is_true(unique_row)) { - PHALCON_INIT_NVAR(prepared_result); - phalcon_call_method_key(prepared_result, result, "getfirst", 3710205613UL); - } else { - PHALCON_CPY_WRT(prepared_result, result); + RETURN_MM_TRUE; } - RETURN_CCTOR(prepared_result); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Model_Query, getSingleResult){ +static PHP_METHOD(Phalcon_Http_Response_Cookies, reset){ - zval *bind_params = NULL, *bind_types = NULL, *unique_row; - zval *result = NULL, *first_result; + zval *empty_array; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &bind_params, &bind_types); - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } - - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } - - PHALCON_OBS_VAR(unique_row); - phalcon_read_property_this_quick(&unique_row, this_ptr, SL("_uniqueRow"), 1221667347UL, PH_NOISY_CC); - - if (zend_is_true(unique_row)) { - PHALCON_INIT_VAR(result); - phalcon_call_method_p2_key(result, this_ptr, "execute", bind_params, bind_types, 3117639032UL); - RETURN_CCTOR(result); - } - - PHALCON_INIT_NVAR(result); - phalcon_call_method_p2_key(result, this_ptr, "execute", bind_params, bind_types, 3117639032UL); - - PHALCON_INIT_VAR(first_result); - phalcon_call_method_key(first_result, result, "getfirst", 3710205613UL); - - RETURN_CCTOR(result); + PHALCON_INIT_VAR(empty_array); + array_init(empty_array); + phalcon_update_property_this_quick(this_ptr, SL("_cookies"), empty_array, 4109914289UL TSRMLS_CC); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query, setType){ - zval *type; - phalcon_fetch_params(0, 1, 0, &type); - - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - RETURN_THISW(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query, getType){ +#ifdef HAVE_CONFIG_H +#endif - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query, setBindParams){ - zval *bind_params; +PHALCON_INIT_CLASS(Phalcon_Http_Response_CookiesInterface){ - phalcon_fetch_params(0, 1, 0, &bind_params); - - if (Z_TYPE_P(bind_params) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Bind parameters must be an array"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_bindParams"), bind_params, 2293392709UL TSRMLS_CC); - - RETURN_THISW(); + PHALCON_REGISTER_INTERFACE(Phalcon\\Http\\Response, CookiesInterface, http_response_cookiesinterface, phalcon_http_response_cookiesinterface_method_entry); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Model_Query, getBindParams){ - RETURN_MEMBER_QUICK(this_ptr, "_bindParams", 2293392709UL); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query, setBindTypes){ - zval *bind_types; - phalcon_fetch_params(0, 1, 0, &bind_types); - - if (Z_TYPE_P(bind_types) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Bind types must be an array"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_bindTypes"), bind_types, 514734038UL TSRMLS_CC); - - RETURN_THISW(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query, getBindTypes){ - RETURN_MEMBER_QUICK(this_ptr, "_bindTypes", 514734038UL); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query, setIntermediate){ - zval *intermediate; - phalcon_fetch_params(0, 1, 0, &intermediate); - - phalcon_update_property_this_quick(this_ptr, SL("_intermediate"), intermediate, 1829292799UL TSRMLS_CC); - RETURN_THISW(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query, getIntermediate){ +#ifdef HAVE_CONFIG_H +#endif - RETURN_MEMBER_QUICK(this_ptr, "_intermediate", 1829292799UL); -} +PHALCON_INIT_CLASS(Phalcon_Http_Response_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Http\\Response, Exception, http_response_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; +} + + + #ifdef HAVE_CONFIG_H #endif @@ -42575,1892 +42653,1481 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query, getIntermediate){ -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Resultset){ - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Resultset, mvc_model_resultset, phalcon_mvc_model_resultset_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); +PHALCON_INIT_CLASS(Phalcon_Http_Response_Headers){ - zend_declare_property_long(phalcon_mvc_model_resultset_ce, SL("_type"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_result"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_cache"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_model_resultset_ce, SL("_isFresh"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_model_resultset_ce, SL("_pointer"), -1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_count"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_activeRow"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_rows"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_errorMessages"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_model_resultset_ce, SL("_hydrateMode"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_REGISTER_CLASS(Phalcon\\Http\\Response, Headers, http_response_headers, phalcon_http_response_headers_method_entry, 0); - zend_declare_class_constant_long(phalcon_mvc_model_resultset_ce, SL("TYPE_RESULT_FULL"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_resultset_ce, SL("TYPE_RESULT_PARTIAL"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_resultset_ce, SL("HYDRATE_RECORDS"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_resultset_ce, SL("HYDRATE_OBJECTS"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_resultset_ce, SL("HYDRATE_ARRAYS"), 1 TSRMLS_CC); + zend_declare_property_null(phalcon_http_response_headers_ce, SL("_headers"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_mvc_model_resultset_ce TSRMLS_CC, 6, phalcon_mvc_model_resultsetinterface_ce, zend_ce_iterator, spl_ce_SeekableIterator, spl_ce_Countable, zend_ce_arrayaccess, zend_ce_serializable); + zend_class_implements(phalcon_http_response_headers_ce TSRMLS_CC, 1, phalcon_http_response_headersinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, next){ +static PHP_METHOD(Phalcon_Http_Response_Headers, set){ + zval *name, *value; - phalcon_property_incr(this_ptr, SL("_pointer") TSRMLS_CC); + phalcon_fetch_params(0, 2, 0, &name, &value); + + phalcon_update_property_array(this_ptr, SL("_headers"), name, value TSRMLS_CC); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, key){ +static PHP_METHOD(Phalcon_Http_Response_Headers, get){ + zval *name, *headers, *header_value; - RETURN_MEMBER_QUICK(this_ptr, "_pointer", 3868032485UL); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); + + PHALCON_OBS_VAR(headers); + phalcon_read_property_this_quick(&headers, this_ptr, SL("_headers"), 1867660032UL, PH_NOISY_CC); + if (phalcon_array_isset(headers, name)) { + PHALCON_OBS_VAR(header_value); + phalcon_array_fetch(&header_value, headers, name, PH_NOISY); + RETURN_CCTOR(header_value); + } + + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, rewind){ +static PHP_METHOD(Phalcon_Http_Response_Headers, setRaw){ - zval *type, *result = NULL, *active_row, *zero, *rows = NULL; + zval *header, *zval_null; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(type); - phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); - if (zend_is_true(type)) { + phalcon_fetch_params(1, 1, 0, &header); - PHALCON_OBS_VAR(result); - phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); - if (PHALCON_IS_NOT_FALSE(result)) { + PHALCON_INIT_VAR(zval_null); + phalcon_update_property_array(this_ptr, SL("_headers"), header, zval_null TSRMLS_CC); - PHALCON_OBS_VAR(active_row); - phalcon_read_property_this_quick(&active_row, this_ptr, SL("_activeRow"), 3086770360UL, PH_NOISY_CC); - if (Z_TYPE_P(active_row) != IS_NULL) { - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - phalcon_call_method_p1_key(NULL, result, "dataseek", zero, 3282855015UL); - } - } - } else { - PHALCON_OBS_VAR(rows); - phalcon_read_property_this_quick(&rows, this_ptr, SL("_rows"), 3989235983UL, PH_NOISY_CC); - if (Z_TYPE_P(rows) == IS_NULL) { + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Http_Response_Headers, send){ + + zval *headers, *value = NULL, *header = NULL; + zval *http_header = NULL; + zval copy; + int use_copy; + HashTable *ah0; + HashPosition hp0; + zval **hd; + sapi_header_line ctr = { NULL, 0, 0 }; + + PHALCON_MM_GROW(); + + if (!SG(headers_sent)) { - PHALCON_OBS_NVAR(result); - phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); - if (Z_TYPE_P(result) == IS_OBJECT) { - PHALCON_INIT_NVAR(rows); - phalcon_call_method_key(rows, result, "fetchall", 1636682248UL); - phalcon_update_property_this_quick(this_ptr, SL("_rows"), rows, 3989235983UL TSRMLS_CC); + PHALCON_OBS_VAR(headers); + phalcon_read_property_this_quick(&headers, this_ptr, SL("_headers"), 1867660032UL, PH_NOISY_CC); + + phalcon_is_iterable(headers, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(header, ah0, hp0); + PHALCON_GET_HVALUE(value); + + if (PHALCON_IS_NOT_EMPTY(value)) { + PHALCON_INIT_NVAR(http_header); + PHALCON_CONCAT_VSV(http_header, header, ": ", value); + ctr.line = Z_STRVAL_P(http_header); + ctr.line_len = Z_STRLEN_P(http_header); + sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC); + } else { + zend_make_printable_zval(header, ©, &use_copy); + if (unlikely(use_copy)) { + header = © + } + + ctr.line = Z_STRVAL_P(header); + ctr.line_len = Z_STRLEN_P(header); + sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC); + + if (unlikely(use_copy)) { + zval_dtor(©); + } } + + zend_hash_move_forward_ex(ah0, &hp0); } - if (Z_TYPE_P(rows) == IS_ARRAY) { - Z_SET_ISREF_P(rows); - phalcon_call_func_p1_noret("reset", rows); - Z_UNSET_ISREF_P(rows); - } + RETURN_MM_TRUE; } - phalcon_update_property_long(this_ptr, SL("_pointer"), 0 TSRMLS_CC); + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Http_Response_Headers, reset){ + + zval *empty_array; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(empty_array); + array_init(empty_array); + phalcon_update_property_this_quick(this_ptr, SL("_headers"), empty_array, 1867660032UL TSRMLS_CC); PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, seek){ +static PHP_METHOD(Phalcon_Http_Response_Headers, __set_state){ - long i; - zval *type, *result, *rows, *position; - zval *pointer, *is_different; + zval *data, *headers, *data_headers, *value = NULL, *key = NULL; HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &position) == FAILURE) { - PHALCON_MM_RESTORE(); - RETURN_NULL(); + phalcon_fetch_params(1, 1, 0, &data); + + PHALCON_INIT_VAR(headers); + object_init_ex(headers, phalcon_http_response_headers_ce); + if (phalcon_array_isset_quick_string(data, SS("_headers"), 1867660032UL)) { + + PHALCON_OBS_VAR(data_headers); + phalcon_array_fetch_quick_string(&data_headers, data, SS("_headers"), 1867660032UL, PH_NOISY); + + phalcon_is_iterable(data_headers, &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_p2_key(NULL, headers, "set", key, value, 2090720177UL); + + zend_hash_move_forward_ex(ah0, &hp0); + } + } + + RETURN_CTOR(headers); +} - PHALCON_OBS_VAR(pointer); - phalcon_read_property(&pointer, this_ptr, SL("_pointer"), PH_NOISY_CC); - PHALCON_INIT_VAR(is_different); - is_not_equal_function(is_different, pointer, position TSRMLS_CC); - if (PHALCON_IS_TRUE(is_different)) { - PHALCON_OBS_VAR(type); - phalcon_read_property(&type, this_ptr, SL("_type"), PH_NOISY_CC); - if (zend_is_true(type)) { - PHALCON_OBS_VAR(result); - phalcon_read_property(&result, this_ptr, SL("_result"), PH_NOISY_CC); - phalcon_call_method_p1_key(NULL, result, "dataseek", position, 3282855015UL); - } else { +#ifdef HAVE_CONFIG_H +#endif - PHALCON_OBS_VAR(rows); - phalcon_read_property(&rows, this_ptr, SL("_rows"), PH_NOISY_CC); - if (Z_TYPE_P(rows) == IS_NULL) { - PHALCON_OBS_VAR(result); - phalcon_read_property(&result, this_ptr, SL("_result"), PH_NOISY_CC); - if (PHALCON_IS_NOT_FALSE(result)) { - PHALCON_INIT_NVAR(rows); - phalcon_call_method_key(rows, result, "fetchall", 1636682248UL); - phalcon_update_property_zval(this_ptr, SL("_rows"), rows TSRMLS_CC); - } - } - convert_to_long(position); +PHALCON_INIT_CLASS(Phalcon_Http_Response_HeadersInterface){ - if(Z_TYPE_P(rows) == IS_ARRAY){ + PHALCON_REGISTER_INTERFACE(Phalcon\\Http\\Response, HeadersInterface, http_response_headersinterface, phalcon_http_response_headersinterface_method_entry); - ah0 = Z_ARRVAL_P(rows); - zend_hash_internal_pointer_reset(ah0); + return SUCCESS; +} - i = 0; - while (1) { - if (i >= Z_LVAL_P(position)) { - break; - } - zend_hash_move_forward(ah0); - i++; - } - } - phalcon_update_property_zval(this_ptr, SL("_pointer"), position TSRMLS_CC); - } - } - PHALCON_MM_RESTORE();} -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, count){ - zval *count = NULL, *type, *result = NULL, *number_rows, *rows = NULL; - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(count); - phalcon_read_property_this_quick(&count, this_ptr, SL("_count"), 2208664173UL, PH_NOISY_CC); - - if (Z_TYPE_P(count) == IS_NULL) { - - PHALCON_INIT_NVAR(count); - ZVAL_LONG(count, 0); - - PHALCON_OBS_VAR(type); - phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); - if (zend_is_true(type)) { - - PHALCON_OBS_VAR(result); - phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); - if (PHALCON_IS_NOT_FALSE(result)) { - PHALCON_INIT_VAR(number_rows); - phalcon_call_method_key(number_rows, result, "numrows", 887792640UL); - - PHALCON_INIT_NVAR(count); - ZVAL_LONG(count, phalcon_get_intval(number_rows)); - } - } else { - PHALCON_OBS_VAR(rows); - phalcon_read_property_this_quick(&rows, this_ptr, SL("_rows"), 3989235983UL, PH_NOISY_CC); - if (Z_TYPE_P(rows) == IS_NULL) { - - PHALCON_OBS_NVAR(result); - phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); - if (Z_TYPE_P(result) == IS_OBJECT) { - PHALCON_INIT_NVAR(rows); - phalcon_call_method_key(rows, result, "fetchall", 1636682248UL); - phalcon_update_property_this_quick(this_ptr, SL("_rows"), rows, 3989235983UL TSRMLS_CC); - } - } - - PHALCON_INIT_NVAR(count); - phalcon_fast_count(count, rows TSRMLS_CC); - } - - phalcon_update_property_this_quick(this_ptr, SL("_count"), count, 2208664173UL TSRMLS_CC); - } - - RETURN_CCTOR(count); -} -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetExists){ - zval *index, *count; +#ifdef HAVE_CONFIG_H +#endif - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &index); - - PHALCON_INIT_VAR(count); - phalcon_call_method_key(count, this_ptr, "count", 4142425646UL); - is_smaller_function(return_value, index, count TSRMLS_CC); - RETURN_MM(); + + + + + +PHALCON_INIT_CLASS(Phalcon_Http_Response){ + + PHALCON_REGISTER_CLASS(Phalcon\\Http, Response, http_response, phalcon_http_response_method_entry, 0); + + zend_declare_property_bool(phalcon_http_response_ce, SL("_sent"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_response_ce, SL("_content"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_response_ce, SL("_headers"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_response_ce, SL("_cookies"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_response_ce, SL("_file"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_http_response_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_http_response_ce TSRMLS_CC, 2, phalcon_http_responseinterface_ce, phalcon_di_injectionawareinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetGet){ +static PHP_METHOD(Phalcon_Http_Response, __construct){ - zval *index, *count, *pointer, *valid; + zval *content = NULL, *code = NULL, *status = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &index); - - PHALCON_INIT_VAR(count); - phalcon_call_method_key(count, this_ptr, "count", 4142425646UL); - if (PHALCON_LT(index, count)) { + phalcon_fetch_params(1, 0, 3, &content, &code, &status); - PHALCON_OBS_VAR(pointer); - phalcon_read_property_this_quick(&pointer, this_ptr, SL("_pointer"), 3868032485UL, PH_NOISY_CC); - if (PHALCON_IS_EQUAL(pointer, index)) { - phalcon_call_method_key(return_value, this_ptr, "current", 431662984UL); - RETURN_MM(); - } + if (!content) { + PHALCON_INIT_VAR(content); + } - phalcon_call_method_p1_key(NULL, this_ptr, "seek", index, 274276301UL); + if (!code) { + PHALCON_INIT_VAR(code); + } - PHALCON_INIT_VAR(valid); - phalcon_call_method_key(valid, this_ptr, "valid", 574098517UL); - if (PHALCON_IS_NOT_FALSE(valid)) { - phalcon_call_method_key(return_value, this_ptr, "current", 431662984UL); - RETURN_MM(); - } + if (!status) { + PHALCON_INIT_VAR(status); + } - RETURN_MM_FALSE; + if (Z_TYPE_P(content) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_content"), content, 4081318271UL TSRMLS_CC); + } + if (Z_TYPE_P(code) != IS_NULL) { + phalcon_call_method_p2_key(NULL, this_ptr, "setstatuscode", code, status, 1498183248UL); } - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The index does not exist in the cursor"); - return; + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetSet){ +static PHP_METHOD(Phalcon_Http_Response, setDI){ - zval *index, *value; + zval *dependency_injector; - phalcon_fetch_params(0, 2, 0, &index, &value); + phalcon_fetch_params(0, 1, 0, &dependency_injector); - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Cursor is an immutable ArrayAccess object"); - return; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetUnset){ - - zval *offset; - - phalcon_fetch_params(0, 1, 0, &offset); + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Cursor is an immutable ArrayAccess object"); - return; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getType){ - - - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getFirst){ +static PHP_METHOD(Phalcon_Http_Response, getDI){ - zval *pointer, *valid; + zval *dependency_injector = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(pointer); - phalcon_read_property_this_quick(&pointer, this_ptr, SL("_pointer"), 3868032485UL, PH_NOISY_CC); - if (PHALCON_IS_LONG(pointer, 0)) { - phalcon_call_method_key(return_value, this_ptr, "current", 431662984UL); - RETURN_MM(); - } + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - phalcon_call_method_key(NULL, this_ptr, "rewind", 1064078190UL); + PHALCON_INIT_NVAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - PHALCON_INIT_VAR(valid); - phalcon_call_method_key(valid, this_ptr, "valid", 574098517UL); - if (PHALCON_IS_NOT_FALSE(valid)) { - phalcon_call_method_key(return_value, this_ptr, "current", 431662984UL); - RETURN_MM(); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'url' service"); + return; + } + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); } - RETURN_MM_FALSE; + RETURN_CCTOR(dependency_injector); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getLast){ +static PHP_METHOD(Phalcon_Http_Response, setStatusCode){ - zval *one, *count, *pre_count, *valid; + zval *code, *message, *headers, *header_value, *status_value; + zval *status_header; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); + phalcon_fetch_params(1, 2, 0, &code, &message); - PHALCON_INIT_VAR(count); - phalcon_call_method_key(count, this_ptr, "count", 4142425646UL); + PHALCON_INIT_VAR(headers); + phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); - PHALCON_INIT_VAR(pre_count); - sub_function(pre_count, count, one TSRMLS_CC); - phalcon_call_method_p1_key(NULL, this_ptr, "seek", pre_count, 274276301UL); + PHALCON_INIT_VAR(header_value); + PHALCON_CONCAT_SVSV(header_value, "HTTP/1.1 ", code, " ", message); + phalcon_call_method_p1_key(NULL, headers, "setraw", header_value, 2352298299UL); - PHALCON_INIT_VAR(valid); - phalcon_call_method_key(valid, this_ptr, "valid", 574098517UL); - if (PHALCON_IS_NOT_FALSE(valid)) { - phalcon_call_method_key(return_value, this_ptr, "current", 431662984UL); - RETURN_MM(); - } + PHALCON_INIT_VAR(status_value); + PHALCON_CONCAT_VSV(status_value, code, " ", message); - RETURN_MM_FALSE; + PHALCON_INIT_VAR(status_header); + ZVAL_STRING(status_header, "Status", 1); + phalcon_call_method_p2_key(NULL, headers, "set", status_header, status_value, 2090720177UL); + phalcon_update_property_this_quick(this_ptr, SL("_headers"), headers, 1867660032UL TSRMLS_CC); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, setIsFresh){ +static PHP_METHOD(Phalcon_Http_Response, setHeaders){ - zval *is_fresh; + zval *headers; - phalcon_fetch_params(0, 1, 0, &is_fresh); + phalcon_fetch_params(0, 1, 0, &headers); - phalcon_update_property_this_quick(this_ptr, SL("_isFresh"), is_fresh, 1397060440UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_headers"), headers, 1867660032UL TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, isFresh){ +static PHP_METHOD(Phalcon_Http_Response, getHeaders){ + + zval *headers = NULL; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_isFresh", 1397060440UL); + PHALCON_OBS_VAR(headers); + phalcon_read_property_this_quick(&headers, this_ptr, SL("_headers"), 1867660032UL, PH_NOISY_CC); + if (Z_TYPE_P(headers) == IS_NULL) { + PHALCON_INIT_NVAR(headers); + object_init_ex(headers, phalcon_http_response_headers_ce); + phalcon_update_property_this_quick(this_ptr, SL("_headers"), headers, 1867660032UL TSRMLS_CC); + } + + RETURN_CCTOR(headers); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, setHydrateMode){ +static PHP_METHOD(Phalcon_Http_Response, setCookies){ - zval *hydrate_mode; + zval *cookies; - phalcon_fetch_params(0, 1, 0, &hydrate_mode); + phalcon_fetch_params(0, 1, 0, &cookies); + + if (Z_TYPE_P(cookies) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_http_response_exception_ce, "The cookies bag is not valid"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_cookies"), cookies, 4109914289UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_hydrateMode"), hydrate_mode, 2551752186UL TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getHydrateMode){ +static PHP_METHOD(Phalcon_Http_Response, getCookies){ - RETURN_MEMBER_QUICK(this_ptr, "_hydrateMode", 2551752186UL); + RETURN_MEMBER_QUICK(this_ptr, "_cookies", 4109914289UL); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getCache){ +static PHP_METHOD(Phalcon_Http_Response, setHeader){ + + zval *name, *value, *headers; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_cache", 2191407384UL); + phalcon_fetch_params(1, 2, 0, &name, &value); + + PHALCON_INIT_VAR(headers); + phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); + phalcon_call_method_p2_key(NULL, headers, "set", name, value, 2090720177UL); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, current){ +static PHP_METHOD(Phalcon_Http_Response, setRawHeader){ + + zval *header, *headers; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_activeRow", 3086770360UL); + phalcon_fetch_params(1, 1, 0, &header); + + PHALCON_INIT_VAR(headers); + phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); + phalcon_call_method_p1_key(NULL, headers, "setraw", header, 2352298299UL); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getMessages){ +static PHP_METHOD(Phalcon_Http_Response, resetHeaders){ + + zval *headers; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_errorMessages", 1019066246UL); + PHALCON_INIT_VAR(headers); + phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); + phalcon_call_method_key(NULL, headers, "reset", 422548360UL); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, delete){ +static PHP_METHOD(Phalcon_Http_Response, setExpires){ - zval *condition_callback = NULL, *transaction = NULL, *record = NULL; - zval *connection = NULL, *parameters = NULL, *status = NULL, *messages = NULL; - zval *r0 = NULL; + zval *datetime, *headers, *date, *utc_zone, *timezone; + zval *format, *utc_format, *utc_date, *expires_header; + zend_class_entry *ce0; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &condition_callback); + phalcon_fetch_params(1, 1, 0, &datetime); - if (!condition_callback) { - PHALCON_INIT_VAR(condition_callback); + if (Z_TYPE_P(datetime) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "datetime parameter must be an instance of DateTime"); + return; } - PHALCON_INIT_VAR(transaction); - ZVAL_BOOL(transaction, 0); - phalcon_call_method_key(NULL, this_ptr, "rewind", 1064078190UL); - - while (1) { - - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, this_ptr, "valid", 574098517UL); - if (zend_is_true(r0)) { - } else { - break; - } - - PHALCON_INIT_NVAR(record); - phalcon_call_method_key(record, this_ptr, "current", 431662984UL); - if (PHALCON_IS_FALSE(transaction)) { - - if (phalcon_method_quick_exists_ex(record, SS("getwriteconnection"), 4280185952UL TSRMLS_CC) == FAILURE) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The returned record is not valid"); - return; - } - - PHALCON_INIT_NVAR(connection); - phalcon_call_method_key(connection, record, "getwriteconnection", 4280185952UL); - phalcon_call_method_key(NULL, connection, "begin", 4090922282UL); - - PHALCON_INIT_NVAR(transaction); - ZVAL_BOOL(transaction, 1); - } + PHALCON_INIT_VAR(headers); + phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); - if (Z_TYPE_P(condition_callback) == IS_OBJECT) { + PHALCON_INIT_VAR(date); + if (phalcon_clone(date, datetime TSRMLS_CC) == FAILURE) { + return; + } - PHALCON_INIT_NVAR(parameters); - array_init_size(parameters, 1); - phalcon_array_append(¶meters, record, PH_SEPARATE); + PHALCON_INIT_VAR(utc_zone); + ZVAL_STRING(utc_zone, "UTC", 1); + ce0 = zend_fetch_class(SL("DateTimeZone"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC_ARRAY(status, condition_callback, parameters); - if (PHALCON_IS_FALSE(status)) { - continue; - } - } + PHALCON_INIT_VAR(timezone); + object_init_ex(timezone, ce0); + if (phalcon_has_constructor(timezone TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, timezone, "__construct", utc_zone, 1107214344UL); + } - PHALCON_INIT_NVAR(status); - phalcon_call_method_key(status, record, "delete", 150213496UL); - if (!zend_is_true(status)) { - PHALCON_INIT_NVAR(messages); - phalcon_call_method_key(messages, record, "getmessages", 4087333309UL); - phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), messages, 1019066246UL TSRMLS_CC); + phalcon_call_method_p1_key(NULL, date, "settimezone", timezone, 851039132UL); - phalcon_call_method_key(NULL, connection, "rollback", 3199546639UL); + PHALCON_INIT_VAR(format); + ZVAL_STRING(format, "D, d M Y H:i:s", 1); - PHALCON_INIT_NVAR(transaction); - ZVAL_BOOL(transaction, 0); - break; - } + PHALCON_INIT_VAR(utc_format); + phalcon_call_method_p1_key(utc_format, date, "format", format, 3131886190UL); - phalcon_call_method_key(NULL, this_ptr, "next", 268367684UL); - } + PHALCON_INIT_VAR(utc_date); + PHALCON_CONCAT_VS(utc_date, utc_format, " GMT"); - if (PHALCON_IS_TRUE(transaction)) { - phalcon_call_method_key(NULL, connection, "commit", 3546528686UL); - } + PHALCON_INIT_VAR(expires_header); + ZVAL_STRING(expires_header, "Expires", 1); + phalcon_call_method_p2_key(NULL, this_ptr, "setheader", expires_header, utc_date, 1102032250UL); - RETURN_MM_TRUE; + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, filter){ +static PHP_METHOD(Phalcon_Http_Response, setNotModified){ - zval *filter, *records, *parameters, *record = NULL, *processed_record = NULL; - zval *r0 = NULL; + zval *code, *status; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &filter); - - PHALCON_INIT_VAR(records); - array_init(records); - phalcon_call_method_key(NULL, this_ptr, "rewind", 1064078190UL); - - PHALCON_INIT_VAR(parameters); - array_init(parameters); - - while (1) { - - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, this_ptr, "valid", 574098517UL); - if (zend_is_true(r0)) { - } else { - break; - } + PHALCON_INIT_VAR(code); + ZVAL_LONG(code, 304); - PHALCON_INIT_NVAR(record); - phalcon_call_method_key(record, this_ptr, "current", 431662984UL); - phalcon_array_update_long(¶meters, 0, &record, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(status); + ZVAL_STRING(status, "Not modified", 1); + phalcon_call_method_p2_key(NULL, this_ptr, "setstatuscode", code, status, 1498183248UL); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Http_Response, setContentType){ + + zval *content_type, *charset = NULL, *headers, *name, *header_value; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &content_type, &charset); - PHALCON_INIT_NVAR(processed_record); - PHALCON_CALL_USER_FUNC_ARRAY(processed_record, filter, parameters); + if (!charset) { + PHALCON_INIT_VAR(charset); + } - if (Z_TYPE_P(processed_record) != IS_OBJECT) { - if (Z_TYPE_P(processed_record) != IS_ARRAY) { - continue; - } - } + PHALCON_INIT_VAR(headers); + phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); - phalcon_array_append(&records, processed_record, PH_SEPARATE); - phalcon_call_method_key(NULL, this_ptr, "next", 268367684UL); + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "Content-Type", 1); + if (Z_TYPE_P(charset) == IS_NULL) { + phalcon_call_method_p2_key(NULL, headers, "set", name, content_type, 2090720177UL); + } else { + PHALCON_INIT_VAR(header_value); + PHALCON_CONCAT_VSV(header_value, content_type, "; charset=", charset); + phalcon_call_method_p2_key(NULL, headers, "set", name, header_value, 2090720177UL); } - RETURN_CTOR(records); + RETURN_THIS(); } +static PHP_METHOD(Phalcon_Http_Response, setEtag){ + zval *etag, *name, *headers; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Validator, mvc_model_validator, phalcon_mvc_model_validator_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - zend_declare_property_null(phalcon_mvc_model_validator_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_validator_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Validator, __construct){ - - zval *options; - - phalcon_fetch_params(0, 1, 0, &options); + phalcon_fetch_params(1, 1, 0, &etag); - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "$options argument must be an Array"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "Etag", 1); + PHALCON_INIT_VAR(headers); + phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); + phalcon_call_method_p2_key(NULL, headers, "set", name, etag, 2090720177UL); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Validator, appendMessage){ +static PHP_METHOD(Phalcon_Http_Response, redirect){ - zval *message, *field = NULL, *type = NULL, *class_name, *suffix; - zval *empty_string, *model_message; + zval *location = NULL, *external_redirect = NULL, *status_code = NULL; + zval *header = NULL, *dependency_injector, *service; + zval *url, *status_text, *header_name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &message, &field, &type); + phalcon_fetch_params(1, 0, 3, &location, &external_redirect, &status_code); - if (!field) { - PHALCON_INIT_VAR(field); + if (!location) { + PHALCON_INIT_VAR(location); } - if (!type) { - PHALCON_INIT_VAR(type); - } else { - PHALCON_SEPARATE_PARAM(type); + if (!external_redirect) { + PHALCON_INIT_VAR(external_redirect); + ZVAL_BOOL(external_redirect, 0); } - if (!zend_is_true(type)) { - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); + if (!status_code) { + PHALCON_INIT_VAR(status_code); + ZVAL_LONG(status_code, 302); + } - PHALCON_INIT_VAR(suffix); - ZVAL_STRING(suffix, "Validator", 1); + if (zend_is_true(external_redirect)) { + PHALCON_CPY_WRT(header, location); + } else { + PHALCON_INIT_VAR(dependency_injector); + phalcon_call_method_key(dependency_injector, this_ptr, "getdi", 4287060818UL); - PHALCON_INIT_VAR(empty_string); - ZVAL_STRING(empty_string, "", 1); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "url", 1); - PHALCON_INIT_NVAR(type); - phalcon_fast_str_replace(type, suffix, empty_string, class_name); + PHALCON_INIT_VAR(url); + phalcon_call_method_p1_key(url, dependency_injector, "getshared", service, 1727570332UL); + + PHALCON_INIT_NVAR(header); + phalcon_call_method_p1_key(header, url, "get", location, 2090288933UL); } - PHALCON_INIT_VAR(model_message); - object_init_ex(model_message, phalcon_mvc_model_message_ce); - phalcon_call_method_p3_key(NULL, model_message, "__construct", message, field, type, 1107214344UL); + PHALCON_INIT_VAR(status_text); + ZVAL_STRING(status_text, "Redirect", 1); + phalcon_call_method_p2_key(NULL, this_ptr, "setstatuscode", status_code, status_text, 1498183248UL); - phalcon_update_property_array_append(this_ptr, SL("_messages"), model_message TSRMLS_CC); + PHALCON_INIT_VAR(header_name); + ZVAL_STRING(header_name, "Location", 1); + phalcon_call_method_p2_key(NULL, this_ptr, "setheader", header_name, header, 1102032250UL); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Validator, getMessages){ - - - RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Validator, getOptions){ +static PHP_METHOD(Phalcon_Http_Response, setContent){ + zval *content; - RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); + phalcon_fetch_params(0, 1, 0, &content); + + phalcon_update_property_this_quick(this_ptr, SL("_content"), content, 4081318271UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Model_Validator, getOption){ +static PHP_METHOD(Phalcon_Http_Response, setJsonContent){ - zval *option, *options, *value; + zval *content, *json_options = NULL, *json_content; + int options = 0; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &option); + phalcon_fetch_params(1, 1, 1, &content, &json_options); - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (phalcon_array_isset(options, option)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, options, option, PH_NOISY); - RETURN_CCTOR(value); + if (json_options) { + options = phalcon_get_intval(json_options); } - RETURN_MM_EMPTY_STRING(); + PHALCON_INIT_VAR(json_content); + phalcon_json_encode(json_content, content, options TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_content"), json_content, 4081318271UL TSRMLS_CC); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Validator, isSetOption){ +static PHP_METHOD(Phalcon_Http_Response, appendContent){ - zval *option, *options, *is_set = NULL; + zval *content, *_content; zval *r0 = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &option); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 0, &content); - PHALCON_INIT_VAR(r0); - ZVAL_BOOL(r0, phalcon_array_isset(options, option)); - PHALCON_CPY_WRT(is_set, r0); - RETURN_NCTOR(is_set); + PHALCON_OBS_VAR(_content); + phalcon_read_property_this_quick(&_content, this_ptr, SL("_content"), 4081318271UL, PH_NOISY_CC); + PHALCON_ALLOC_ZVAL_MM(r0); + concat_function(r0, _content, content TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_content"), r0, 4081318271UL TSRMLS_CC); + RETURN_THIS(); } +static PHP_METHOD(Phalcon_Http_Response, getContent){ + RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); +} - -#ifdef HAVE_CONFIG_H -#endif - +static PHP_METHOD(Phalcon_Http_Response, isSent){ + RETURN_MEMBER_QUICK(this_ptr, "_sent", 3990052766UL); +} +static PHP_METHOD(Phalcon_Http_Response, sendHeaders){ + zval *headers; + PHALCON_MM_GROW(); -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query_Builder){ + PHALCON_OBS_VAR(headers); + phalcon_read_property_this_quick(&headers, this_ptr, SL("_headers"), 1867660032UL, PH_NOISY_CC); + if (Z_TYPE_P(headers) == IS_OBJECT) { + phalcon_call_method_key(NULL, headers, "send", 274285871UL); + } + + RETURN_THIS(); +} - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\Query, Builder, mvc_model_query_builder, phalcon_mvc_model_query_builder_method_entry, 0); +static PHP_METHOD(Phalcon_Http_Response, sendCookies){ - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_columns"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_models"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_joins"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_conditions"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_group"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_having"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_order"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_limit"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_offset"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_forUpdate"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_sharedLock"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_bindParams"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_builder_ce, SL("_bindTypes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_model_query_builder_ce, SL("_hiddenParamNumber"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zval *cookies; - zend_class_implements(phalcon_mvc_model_query_builder_ce TSRMLS_CC, 2, phalcon_mvc_model_query_builderinterface_ce, phalcon_di_injectionawareinterface_ce); + PHALCON_MM_GROW(); - return SUCCESS; + PHALCON_OBS_VAR(cookies); + phalcon_read_property_this_quick(&cookies, this_ptr, SL("_cookies"), 4109914289UL, PH_NOISY_CC); + if (Z_TYPE_P(cookies) == IS_OBJECT) { + phalcon_call_method_key(NULL, cookies, "send", 274285871UL); + } + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, __construct){ +static PHP_METHOD(Phalcon_Http_Response, send){ - zval *params = NULL, *dependency_injector = NULL, *conditions = NULL; - zval *columns, *group_clause, *having_clause; - zval *order_clause, *limit_clause, *for_update; - zval *shared_lock; + zval *sent, *headers, *cookies, *content, *file; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, ¶ms, &dependency_injector); - - if (!params) { - PHALCON_INIT_VAR(params); - } - - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } - - if (Z_TYPE_P(params) == IS_ARRAY) { - - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_long(&conditions, params, 0, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_conditions"), conditions, 3598010654UL TSRMLS_CC); - } else { - if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { - PHALCON_OBS_NVAR(conditions); - phalcon_array_fetch_quick_string(&conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_conditions"), conditions, 3598010654UL TSRMLS_CC); - } - } + PHALCON_OBS_VAR(sent); + phalcon_read_property_this_quick(&sent, this_ptr, SL("_sent"), 3990052766UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(sent)) { - if (phalcon_array_isset_quick_string(params, SS("columns"), 1041822630UL)) { - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, params, SS("columns"), 1041822630UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_columns"), columns, 4004520869UL TSRMLS_CC); + PHALCON_OBS_VAR(headers); + phalcon_read_property_this_quick(&headers, this_ptr, SL("_headers"), 1867660032UL, PH_NOISY_CC); + if (Z_TYPE_P(headers) == IS_OBJECT) { + phalcon_call_method_key(NULL, headers, "send", 274285871UL); } - if (phalcon_array_isset_quick_string(params, SS("group"), 7349554UL)) { - PHALCON_OBS_VAR(group_clause); - phalcon_array_fetch_quick_string(&group_clause, params, SS("group"), 7349554UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_group"), group_clause, 2368555377UL TSRMLS_CC); + PHALCON_OBS_VAR(cookies); + phalcon_read_property_this_quick(&cookies, this_ptr, SL("_cookies"), 4109914289UL, PH_NOISY_CC); + if (Z_TYPE_P(cookies) == IS_OBJECT) { + phalcon_call_method_key(NULL, cookies, "send", 274285871UL); } - if (phalcon_array_isset_quick_string(params, SS("having"), 876572994UL)) { - PHALCON_OBS_VAR(having_clause); - phalcon_array_fetch_quick_string(&having_clause, params, SS("having"), 876572994UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_group"), having_clause, 2368555377UL TSRMLS_CC); + PHALCON_OBS_VAR(content); + phalcon_read_property_this_quick(&content, this_ptr, SL("_content"), 4081318271UL, PH_NOISY_CC); + if (Z_STRLEN_P(content)) { + zend_print_zval(content, 0); } - - if (phalcon_array_isset_quick_string(params, SS("order"), 320020033UL)) { - PHALCON_OBS_VAR(order_clause); - phalcon_array_fetch_quick_string(&order_clause, params, SS("order"), 320020033UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_order"), order_clause, 2681225856UL TSRMLS_CC); + else { + PHALCON_OBS_VAR(file); + phalcon_read_property_this_quick(&file, this_ptr, SL("_file"), 3974776868UL, PH_NOISY_CC); + + if (Z_STRLEN_P(file)) { + php_stream *stream; + + stream = php_stream_open_wrapper(Z_STRVAL_P(file), "rb", REPORT_ERRORS, NULL); + if (stream != NULL) { + php_stream_passthru(stream); + php_stream_close(stream); + } + } } + + phalcon_update_property_bool(this_ptr, SL("_sent"), 1 TSRMLS_CC); - if (phalcon_array_isset_quick_string(params, SS("limit"), 192268420UL)) { - PHALCON_OBS_VAR(limit_clause); - phalcon_array_fetch_quick_string(&limit_clause, params, SS("limit"), 192268420UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_limit"), limit_clause, 2553474243UL TSRMLS_CC); - } + RETURN_THIS(); + } - if (phalcon_array_isset_quick_string(params, SS("for_update"), 2511308622UL)) { - PHALCON_OBS_VAR(for_update); - phalcon_array_fetch_quick_string(&for_update, params, SS("for_update"), 2511308622UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_forUpdate"), for_update, 1475172846UL TSRMLS_CC); - } + PHALCON_THROW_EXCEPTION_STR(phalcon_http_response_exception_ce, "Response was already sent"); + return; +} + +static PHP_METHOD(Phalcon_Http_Response, setFileToSend){ + + zval *file_path, *attachment_name = NULL, *attachment = NULL, *base_path = NULL; + zval *headers, *content_description, *content_disposition; + zval *content_transfer; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &file_path, &attachment_name, &attachment); - if (phalcon_array_isset_quick_string(params, SS("shared_lock"), 406740164UL)) { - PHALCON_OBS_VAR(shared_lock); - phalcon_array_fetch_quick_string(&shared_lock, params, SS("shared_lock"), 406740164UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_sharedLock"), shared_lock, 3052804356UL TSRMLS_CC); - } + if (!attachment_name) { + PHALCON_INIT_VAR(attachment_name); + } + + if (!attachment) { + PHALCON_INIT_VAR(attachment); + ZVAL_BOOL(attachment, 1); } - if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + if (Z_TYPE_P(attachment_name) != IS_STRING) { + PHALCON_INIT_VAR(base_path); + phalcon_call_func_p1(base_path, "basename", file_path); + } else { + PHALCON_CPY_WRT(base_path, attachment_name); } - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, setDI){ - - zval *dependency_injector; + if (zend_is_true(attachment)) { + PHALCON_INIT_VAR(headers); + phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL); - phalcon_fetch_params(0, 1, 0, &dependency_injector); + PHALCON_INIT_VAR(content_description); + ZVAL_STRING(content_description, "Content-Description: File Transfer", 1); + phalcon_call_method_p1_key(NULL, headers, "setraw", content_description, 2352298299UL); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The dependency injector must be an Object"); - return; + PHALCON_INIT_VAR(content_disposition); + PHALCON_CONCAT_SV(content_disposition, "Content-Disposition: attachment; filename=", base_path); + phalcon_call_method_p1_key(NULL, headers, "setraw", content_disposition, 2352298299UL); + + PHALCON_INIT_VAR(content_transfer); + ZVAL_STRING(content_transfer, "Content-Transfer-Encoding: binary", 1); + phalcon_call_method_p1_key(NULL, headers, "setraw", content_transfer, 2352298299UL); } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_file"), file_path, 3974776868UL TSRMLS_CC); - RETURN_THISW(); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getDI){ - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, columns){ - zval *columns; +#ifdef HAVE_CONFIG_H +#endif - phalcon_fetch_params(0, 1, 0, &columns); - - phalcon_update_property_this_quick(this_ptr, SL("_columns"), columns, 4004520869UL TSRMLS_CC); - RETURN_THISW(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getColumns){ +PHALCON_INIT_CLASS(Phalcon_Http_ResponseInterface){ - RETURN_MEMBER_QUICK(this_ptr, "_columns", 4004520869UL); + PHALCON_REGISTER_INTERFACE(Phalcon\\Http, ResponseInterface, http_responseinterface, phalcon_http_responseinterface_method_entry); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, from){ - zval *models; - phalcon_fetch_params(0, 1, 0, &models); - - phalcon_update_property_this_quick(this_ptr, SL("_models"), models, 4175729768UL TSRMLS_CC); - RETURN_THISW(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, addFrom){ - zval *model, *alias = NULL, *models = NULL, *current_model = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &model, &alias); - - if (!alias) { - PHALCON_INIT_VAR(alias); - } - - PHALCON_OBS_VAR(models); - phalcon_read_property_this_quick(&models, this_ptr, SL("_models"), 4175729768UL, PH_NOISY_CC); - if (Z_TYPE_P(models) != IS_ARRAY) { - if (Z_TYPE_P(models) != IS_NULL) { - PHALCON_CPY_WRT(current_model, models); - - PHALCON_INIT_NVAR(models); - array_init(models); - phalcon_array_append(&models, current_model, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(models); - array_init(models); - } - } - - if (Z_TYPE_P(alias) == IS_STRING) { - phalcon_array_update_zval(&models, alias, &model, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_append(&models, model, PH_SEPARATE); - } - - phalcon_update_property_this_quick(this_ptr, SL("_models"), models, 4175729768UL TSRMLS_CC); - - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getFrom){ - RETURN_MEMBER_QUICK(this_ptr, "_models", 4175729768UL); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, join){ - zval *model, *conditions = NULL, *alias = NULL, *type = NULL, *join; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 3, &model, &conditions, &alias, &type); - - if (!conditions) { - PHALCON_INIT_VAR(conditions); - } - - if (!alias) { - PHALCON_INIT_VAR(alias); - } - - if (!type) { - PHALCON_INIT_VAR(type); - } - - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); - phalcon_update_property_array_append(this_ptr, SL("_joins"), join TSRMLS_CC); - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, innerJoin){ - zval *model, *conditions = NULL, *alias = NULL, *type, *join; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); - - if (!conditions) { - PHALCON_INIT_VAR(conditions); - } - - if (!alias) { - PHALCON_INIT_VAR(alias); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "INNER", 1); - - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); - phalcon_update_property_array_append(this_ptr, SL("_joins"), join TSRMLS_CC); - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, leftJoin){ - zval *model, *conditions = NULL, *alias = NULL, *type, *join; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); - - if (!conditions) { - PHALCON_INIT_VAR(conditions); - } - - if (!alias) { - PHALCON_INIT_VAR(alias); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "LEFT", 1); - - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); - phalcon_update_property_array_append(this_ptr, SL("_joins"), join TSRMLS_CC); - RETURN_THIS(); -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, rightJoin){ - zval *model, *conditions = NULL, *alias = NULL, *type, *join; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); - - if (!conditions) { - PHALCON_INIT_VAR(conditions); - } - - if (!alias) { - PHALCON_INIT_VAR(alias); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "RIGHT", 1); - - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_joins"), join, 2482180647UL TSRMLS_CC); - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, where){ - zval *conditions, *bind_params = NULL, *bind_types = NULL; - zval *current_bind_params, *merged_params = NULL; - zval *current_bind_types, *merged_types = NULL; +PHALCON_INIT_CLASS(Phalcon_Kernel){ - PHALCON_MM_GROW(); + PHALCON_REGISTER_CLASS(Phalcon, Kernel, kernel, phalcon_kernel_method_entry, 0); - phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } - - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } - - phalcon_update_property_this_quick(this_ptr, SL("_conditions"), conditions, 3598010654UL TSRMLS_CC); - - if (Z_TYPE_P(bind_params) == IS_ARRAY) { - - PHALCON_OBS_VAR(current_bind_params); - phalcon_read_property_this_quick(¤t_bind_params, this_ptr, SL("_bindParams"), 2293392709UL, PH_NOISY_CC); - if (Z_TYPE_P(current_bind_params) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params, bind_params); - } - - phalcon_update_property_this_quick(this_ptr, SL("_bindParams"), merged_params, 2293392709UL TSRMLS_CC); - } - - if (Z_TYPE_P(bind_types) == IS_ARRAY) { - - PHALCON_OBS_VAR(current_bind_types); - phalcon_read_property_this_quick(¤t_bind_types, this_ptr, SL("_bindTypes"), 514734038UL, PH_NOISY_CC); - if (Z_TYPE_P(current_bind_types) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_types); - phalcon_fast_array_merge(merged_types, ¤t_bind_types, &bind_types TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_types, bind_types); - } - - phalcon_update_property_this_quick(this_ptr, SL("_bindTypes"), merged_types, 514734038UL TSRMLS_CC); - } - - RETURN_THIS(); + return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, andWhere){ - - zval *conditions, *bind_params = NULL, *bind_types = NULL; - zval *current_conditions, *new_conditions = NULL; - zval *current_bind_params, *merged_params = NULL; - zval *current_bind_types, *merged_types = NULL; +static PHP_METHOD(Phalcon_Kernel, preComputeHashKey){ - PHALCON_MM_GROW(); + char *arKey, *strKey; + unsigned int nKeyLength; + register ulong hash = 5381; - phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { + RETURN_NULL(); } - - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } - - PHALCON_OBS_VAR(current_conditions); - phalcon_read_property_this_quick(¤t_conditions, this_ptr, SL("_conditions"), 3598010654UL, PH_NOISY_CC); - - if (zend_is_true(current_conditions)) { - PHALCON_INIT_VAR(new_conditions); - PHALCON_CONCAT_SVSVS(new_conditions, "(", current_conditions, ") AND (", conditions, ")"); - } else { - PHALCON_CPY_WRT(new_conditions, conditions); - } - - phalcon_update_property_this_quick(this_ptr, SL("_conditions"), new_conditions, 3598010654UL TSRMLS_CC); - - if (Z_TYPE_P(bind_params) == IS_ARRAY) { - - PHALCON_OBS_VAR(current_bind_params); - phalcon_read_property_this_quick(¤t_bind_params, this_ptr, SL("_bindParams"), 2293392709UL, PH_NOISY_CC); - if (Z_TYPE_P(current_bind_params) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params, bind_params); - } - - phalcon_update_property_this_quick(this_ptr, SL("_bindParams"), merged_params, 2293392709UL TSRMLS_CC); + + nKeyLength++; + + /* variant with the hash unrolled eight times */ + for (; nKeyLength >= 8; nKeyLength -= 8) { + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; } - - if (Z_TYPE_P(bind_types) == IS_ARRAY) { - - PHALCON_OBS_VAR(current_bind_types); - phalcon_read_property_this_quick(¤t_bind_types, this_ptr, SL("_bindTypes"), 514734038UL, PH_NOISY_CC); - if (Z_TYPE_P(current_bind_types) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_types); - phalcon_fast_array_merge(merged_types, ¤t_bind_types, &bind_types TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_types, bind_types); - } - - phalcon_update_property_this_quick(this_ptr, SL("_bindTypes"), merged_types, 514734038UL TSRMLS_CC); + + switch (nKeyLength) { + case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 1: hash = ((hash << 5) + hash) + *arKey++; break; + case 0: break; } - - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orWhere){ + strKey = emalloc(24); + sprintf(strKey, "%lu", hash); - zval *conditions, *bind_params = NULL, *bind_types = NULL; - zval *current_conditions, *new_conditions = NULL; - zval *current_bind_params, *merged_params = NULL; - zval *current_bind_types, *merged_types = NULL; + RETURN_STRING(strKey, 0); +} - PHALCON_MM_GROW(); +static PHP_METHOD(Phalcon_Kernel, preComputeHashKey32){ - phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } - - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + char *arKey, *strKey; + unsigned int nKeyLength; + ulong hash; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { + RETURN_NULL(); } - - PHALCON_OBS_VAR(current_conditions); - phalcon_read_property_this_quick(¤t_conditions, this_ptr, SL("_conditions"), 3598010654UL, PH_NOISY_CC); - - if (zend_is_true(current_conditions)) { - PHALCON_INIT_VAR(new_conditions); - PHALCON_CONCAT_SVSVS(new_conditions, "(", current_conditions, ") OR (", conditions, ")"); - } else { - PHALCON_CPY_WRT(new_conditions, conditions); + + nKeyLength++; + hash = zend_inline_hash_func(arKey, nKeyLength) & 0xFFFFFFFFul; + strKey = emalloc(24); + sprintf(strKey, "%lu", hash); + + RETURN_STRING(strKey, 0); +} + +static PHP_METHOD(Phalcon_Kernel, preComputeHashKey64){ + + char *arKey, *strKey; + unsigned int nKeyLength; + register unsigned long long hash = 5381; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { + RETURN_NULL(); } - - phalcon_update_property_this_quick(this_ptr, SL("_conditions"), new_conditions, 3598010654UL TSRMLS_CC); - - if (Z_TYPE_P(bind_params) == IS_ARRAY) { - - PHALCON_OBS_VAR(current_bind_params); - phalcon_read_property_this_quick(¤t_bind_params, this_ptr, SL("_bindParams"), 2293392709UL, PH_NOISY_CC); - if (Z_TYPE_P(current_bind_params) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params, bind_params); - } - - phalcon_update_property_this_quick(this_ptr, SL("_bindParams"), merged_params, 2293392709UL TSRMLS_CC); + + nKeyLength++; + + /* variant with the hash unrolled eight times */ + for (; nKeyLength >= 8; nKeyLength -= 8) { + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; + hash = ((hash << 5) + hash) + *arKey++; } - - if (Z_TYPE_P(bind_types) == IS_ARRAY) { - - PHALCON_OBS_VAR(current_bind_types); - phalcon_read_property_this_quick(¤t_bind_types, this_ptr, SL("_bindTypes"), 514734038UL, PH_NOISY_CC); - if (Z_TYPE_P(current_bind_types) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_types); - phalcon_fast_array_merge(merged_types, ¤t_bind_types, &bind_types TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_types, bind_types); - } - - phalcon_update_property_this_quick(this_ptr, SL("_bindTypes"), merged_types, 514734038UL TSRMLS_CC); + + switch (nKeyLength) { + case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */ + case 1: hash = ((hash << 5) + hash) + *arKey++; break; + case 0: break; } - - RETURN_THIS(); + + strKey = emalloc(24); + sprintf(strKey, "%llu", hash); + + RETURN_STRING(strKey, 0); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, betweenWhere){ - zval *expr, *minimum, *maximum, *hidden_param, *one; - zval *next_hidden_param, *minimum_key, *maximum_key; - zval *conditions, *bind_params; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &expr, &minimum, &maximum); - - PHALCON_OBS_VAR(hidden_param); - phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - PHALCON_INIT_VAR(next_hidden_param); - phalcon_add_function(next_hidden_param, hidden_param, one TSRMLS_CC); - - PHALCON_INIT_VAR(minimum_key); - PHALCON_CONCAT_SV(minimum_key, "phb", hidden_param); - - PHALCON_INIT_VAR(maximum_key); - PHALCON_CONCAT_SV(maximum_key, "phb", next_hidden_param); - - PHALCON_INIT_VAR(conditions); - PHALCON_CONCAT_VSVSVS(conditions, expr, " BETWEEN :", minimum_key, ": AND :", maximum_key, ":"); - - PHALCON_INIT_VAR(bind_params); - array_init_size(bind_params, 2); - phalcon_array_update_zval(&bind_params, minimum_key, &minimum, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&bind_params, maximum_key, &maximum, PH_COPY | PH_SEPARATE); - - phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); - PHALCON_SEPARATE(next_hidden_param); - phalcon_increment(next_hidden_param); - phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), next_hidden_param, 3119958698UL TSRMLS_CC); - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, notBetweenWhere){ +#ifdef HAVE_CONFIG_H +#endif - zval *expr, *minimum, *maximum, *hidden_param, *one; - zval *next_hidden_param, *minimum_key, *maximum_key; - zval *conditions, *bind_params; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &expr, &minimum, &maximum); - - PHALCON_OBS_VAR(hidden_param); - phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - PHALCON_INIT_VAR(next_hidden_param); - phalcon_add_function(next_hidden_param, hidden_param, one TSRMLS_CC); - - PHALCON_INIT_VAR(minimum_key); - PHALCON_CONCAT_SV(minimum_key, "phb", hidden_param); - - PHALCON_INIT_VAR(maximum_key); - PHALCON_CONCAT_SV(maximum_key, "phb", next_hidden_param); - - PHALCON_INIT_VAR(conditions); - PHALCON_CONCAT_VSVSVS(conditions, expr, " NOT BETWEEN :", minimum_key, ": AND :", maximum_key, ":"); - - PHALCON_INIT_VAR(bind_params); - array_init_size(bind_params, 2); - phalcon_array_update_zval(&bind_params, minimum_key, &minimum, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&bind_params, maximum_key, &maximum, PH_COPY | PH_SEPARATE); - - phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); - PHALCON_SEPARATE(next_hidden_param); - phalcon_increment(next_hidden_param); - phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), next_hidden_param, 3119958698UL TSRMLS_CC); - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, inWhere){ - zval *expr, *values, *hidden_param, *bind_params; - zval *bind_keys, *value = NULL, *key = NULL, *query_key = NULL, *joined_keys; - zval *conditions; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); +PHALCON_INIT_CLASS(Phalcon_Loader_Exception){ - phalcon_fetch_params(1, 2, 0, &expr, &values); - - if (Z_TYPE_P(values) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Values must be an array"); - return; - } - - PHALCON_OBS_VAR(hidden_param); - phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(bind_params); - array_init(bind_params); - - PHALCON_INIT_VAR(bind_keys); - array_init(bind_keys); - - phalcon_is_iterable(values, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(value); - - PHALCON_INIT_NVAR(key); - PHALCON_CONCAT_SV(key, "phi", hidden_param); - - PHALCON_INIT_NVAR(query_key); - PHALCON_CONCAT_SVS(query_key, ":", key, ":"); - phalcon_array_append(&bind_keys, query_key, PH_SEPARATE); - phalcon_array_update_zval(&bind_params, key, &value, PH_COPY | PH_SEPARATE); - PHALCON_SEPARATE(hidden_param); - phalcon_increment(hidden_param); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(joined_keys); - phalcon_fast_join_str(joined_keys, SL(", "), bind_keys TSRMLS_CC); - - PHALCON_INIT_VAR(conditions); - PHALCON_CONCAT_VSVS(conditions, expr, " IN (", joined_keys, ")"); - - phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); - phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), hidden_param, 3119958698UL TSRMLS_CC); - - RETURN_THIS(); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Loader, Exception, loader_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, notInWhere){ - zval *expr, *values, *hidden_param, *bind_params; - zval *bind_keys, *value = NULL, *key = NULL, *query_key = NULL, *joined_keys; - zval *conditions; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &expr, &values); - - if (Z_TYPE_P(values) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Values must be an array"); - return; - } - - PHALCON_OBS_VAR(hidden_param); - phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(bind_params); - array_init(bind_params); - - PHALCON_INIT_VAR(bind_keys); - array_init(bind_keys); - - phalcon_is_iterable(values, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(value); - - PHALCON_INIT_NVAR(key); - PHALCON_CONCAT_SV(key, "phi", hidden_param); - - PHALCON_INIT_NVAR(query_key); - PHALCON_CONCAT_SVS(query_key, ":", key, ":"); - phalcon_array_append(&bind_keys, query_key, PH_SEPARATE); - phalcon_array_update_zval(&bind_params, key, &value, PH_COPY | PH_SEPARATE); - PHALCON_SEPARATE(hidden_param); - phalcon_increment(hidden_param); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(joined_keys); - phalcon_fast_join_str(joined_keys, SL(", "), bind_keys TSRMLS_CC); - - PHALCON_INIT_VAR(conditions); - PHALCON_CONCAT_VSVS(conditions, expr, " NOT IN (", joined_keys, ")"); - - phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); - phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), hidden_param, 3119958698UL TSRMLS_CC); - - RETURN_THIS(); + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Loader){ + + PHALCON_REGISTER_CLASS(Phalcon, Loader, loader, phalcon_loader_method_entry, 0); + + zend_declare_property_null(phalcon_loader_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_loader_ce, SL("_foundPath"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_loader_ce, SL("_checkedPath"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_loader_ce, SL("_prefixes"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_loader_ce, SL("_classes"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_loader_ce, SL("_extensions"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_loader_ce, SL("_namespaces"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_loader_ce, SL("_directories"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_loader_ce, SL("_registered"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_loader_ce TSRMLS_CC, 1, phalcon_events_eventsawareinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getWhere){ +static PHP_METHOD(Phalcon_Loader, __construct){ + zval *extensions; - RETURN_MEMBER_QUICK(this_ptr, "_conditions", 3598010654UL); + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(extensions); + array_init_size(extensions, 1); + add_next_index_stringl(extensions, SL("php"), 1); + phalcon_update_property_this_quick(this_ptr, SL("_extensions"), extensions, 726159316UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orderBy){ +static PHP_METHOD(Phalcon_Loader, setEventsManager){ - zval *order_by; + zval *events_manager; - phalcon_fetch_params(0, 1, 0, &order_by); + phalcon_fetch_params(0, 1, 0, &events_manager); + + phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_order"), order_by, 2681225856UL TSRMLS_CC); - RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getOrderBy){ +static PHP_METHOD(Phalcon_Loader, getEventsManager){ - RETURN_MEMBER_QUICK(this_ptr, "_order", 2681225856UL); + RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, having){ +static PHP_METHOD(Phalcon_Loader, setExtensions){ - zval *having; + zval *extensions; - phalcon_fetch_params(0, 1, 0, &having); + phalcon_fetch_params(0, 1, 0, &extensions); + + if (Z_TYPE_P(extensions) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_loader_exception_ce, "Parameter extensions must be an array"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_extensions"), extensions, 726159316UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_having"), having, 1486953825UL TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getHaving){ +static PHP_METHOD(Phalcon_Loader, getExtensions){ - RETURN_MEMBER_QUICK(this_ptr, "_having", 1486953825UL); + RETURN_MEMBER_QUICK(this_ptr, "_extensions", 726159316UL); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, limit){ +static PHP_METHOD(Phalcon_Loader, registerNamespaces){ - zval *limit, *offset = NULL; + zval *namespaces, *merge = NULL, *current_namespaces; + zval *merged_namespaces = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &limit, &offset); + phalcon_fetch_params(1, 1, 1, &namespaces, &merge); - if (!offset) { - PHALCON_INIT_VAR(offset); + if (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 0); } - if (phalcon_is_numeric(limit)) { - phalcon_update_property_this_quick(this_ptr, SL("_limit"), limit, 2553474243UL TSRMLS_CC); + if (Z_TYPE_P(namespaces) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter namespaces must be an array"); + return; } - if (Z_TYPE_P(offset) != IS_NULL) { - if (phalcon_is_numeric(offset)) { - phalcon_update_property_this_quick(this_ptr, SL("_offset"), offset, 2114347243UL TSRMLS_CC); + if (zend_is_true(merge)) { + + PHALCON_OBS_VAR(current_namespaces); + phalcon_read_property_this_quick(¤t_namespaces, this_ptr, SL("_namespaces"), 3363620132UL, PH_NOISY_CC); + if (Z_TYPE_P(current_namespaces) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_namespaces); + phalcon_fast_array_merge(merged_namespaces, ¤t_namespaces, &namespaces TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_namespaces, namespaces); } + + phalcon_update_property_this_quick(this_ptr, SL("_namespaces"), merged_namespaces, 3363620132UL TSRMLS_CC); + } else { + phalcon_update_property_this_quick(this_ptr, SL("_namespaces"), namespaces, 3363620132UL TSRMLS_CC); } RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getLimit){ +static PHP_METHOD(Phalcon_Loader, getNamespaces){ - RETURN_MEMBER_QUICK(this_ptr, "_limit", 2553474243UL); + RETURN_MEMBER_QUICK(this_ptr, "_namespaces", 3363620132UL); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, offset){ +static PHP_METHOD(Phalcon_Loader, registerPrefixes){ - zval *offset; + zval *prefixes, *merge = NULL, *current_prefixes, *merged_prefixes = NULL; - phalcon_fetch_params(0, 1, 0, &offset); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &prefixes, &merge); - phalcon_update_property_this_quick(this_ptr, SL("_offset"), offset, 2114347243UL TSRMLS_CC); - RETURN_THISW(); + if (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 0); + } + + if (Z_TYPE_P(prefixes) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter prefixes must be an array"); + return; + } + if (zend_is_true(merge)) { + + PHALCON_OBS_VAR(current_prefixes); + phalcon_read_property_this_quick(¤t_prefixes, this_ptr, SL("_prefixes"), 900970058UL, PH_NOISY_CC); + if (Z_TYPE_P(current_prefixes) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_prefixes); + phalcon_fast_array_merge(merged_prefixes, ¤t_prefixes, &prefixes TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_prefixes, prefixes); + } + + phalcon_update_property_this_quick(this_ptr, SL("_prefixes"), merged_prefixes, 900970058UL TSRMLS_CC); + } else { + phalcon_update_property_this_quick(this_ptr, SL("_prefixes"), prefixes, 900970058UL TSRMLS_CC); + } + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getOffset){ +static PHP_METHOD(Phalcon_Loader, getPrefixes){ - RETURN_MEMBER_QUICK(this_ptr, "_offset", 2114347243UL); + RETURN_MEMBER_QUICK(this_ptr, "_prefixes", 900970058UL); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, groupBy){ +static PHP_METHOD(Phalcon_Loader, registerDirs){ - zval *group; + zval *directories, *merge = NULL, *current_directories; + zval *merged_directories = NULL; - phalcon_fetch_params(0, 1, 0, &group); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &directories, &merge); - phalcon_update_property_this_quick(this_ptr, SL("_group"), group, 2368555377UL TSRMLS_CC); - RETURN_THISW(); + if (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 0); + } + + if (Z_TYPE_P(directories) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter directories must be an array"); + return; + } + if (zend_is_true(merge)) { + + PHALCON_OBS_VAR(current_directories); + phalcon_read_property_this_quick(¤t_directories, this_ptr, SL("_directories"), 3207828897UL, PH_NOISY_CC); + if (Z_TYPE_P(current_directories) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_directories); + phalcon_fast_array_merge(merged_directories, ¤t_directories, &directories TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_directories, directories); + } + + phalcon_update_property_this_quick(this_ptr, SL("_directories"), merged_directories, 3207828897UL TSRMLS_CC); + } else { + phalcon_update_property_this_quick(this_ptr, SL("_directories"), directories, 3207828897UL TSRMLS_CC); + } + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getGroupBy){ +static PHP_METHOD(Phalcon_Loader, getDirs){ - RETURN_MEMBER_QUICK(this_ptr, "_group", 2368555377UL); + RETURN_MEMBER_QUICK(this_ptr, "_directories", 3207828897UL); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getPhql){ +static PHP_METHOD(Phalcon_Loader, registerClasses){ - zval *dependency_injector = NULL, *models, *conditions = NULL; - zval *one, *number_models, *invalid_condition; - zval *model = NULL, *service_name, *meta_data, *model_instance; - zval *no_primary = NULL, *primary_keys, *first_primary_key; - zval *column_map = NULL, *attribute_field = NULL, *exception_message; - zval *primary_key_condition, *phql, *columns; - zval *selected_columns = NULL, *column = NULL, *column_alias = NULL; - zval *aliased_column = NULL, *joined_columns = NULL, *model_column_alias = NULL; - zval *selected_column = NULL, *selected_models, *model_alias = NULL; - zval *selected_model = NULL, *joined_models, *joins; - zval *join = NULL, *join_model = NULL, *join_conditions = NULL, *join_alias = NULL; - zval *join_type = NULL, *group, *group_items, *group_item = NULL; - zval *escaped_item = NULL, *joined_items = NULL, *having, *order; - zval *order_items, *order_item = NULL, *limit, *number; - zval *offset = NULL; - HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5; - HashPosition hp0, hp1, hp2, hp3, hp4, hp5; - zval **hd; - zend_class_entry *ce0; + zval *classes, *merge = NULL, *current_classes, *merged_classes = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + phalcon_fetch_params(1, 1, 1, &classes, &merge); + + if (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 0); } - PHALCON_OBS_VAR(models); - phalcon_read_property_this_quick(&models, this_ptr, SL("_models"), 4175729768UL, PH_NOISY_CC); - if (Z_TYPE_P(models) == IS_ARRAY) { - if (!phalcon_fast_count_ev(models TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "At least one model is required to build the query"); - return; + if (Z_TYPE_P(classes) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter classes must be an array"); + return; + } + if (zend_is_true(merge)) { + + PHALCON_OBS_VAR(current_classes); + phalcon_read_property_this_quick(¤t_classes, this_ptr, SL("_classes"), 3992428914UL, PH_NOISY_CC); + if (Z_TYPE_P(current_classes) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_classes); + phalcon_fast_array_merge(merged_classes, ¤t_classes, &classes TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_classes, classes); } + + phalcon_update_property_this_quick(this_ptr, SL("_classes"), merged_classes, 3992428914UL TSRMLS_CC); } else { - if (!zend_is_true(models)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "At least one model is required to build the query"); - return; - } + phalcon_update_property_this_quick(this_ptr, SL("_classes"), classes, 3992428914UL TSRMLS_CC); } - PHALCON_OBS_VAR(conditions); - phalcon_read_property_this_quick(&conditions, this_ptr, SL("_conditions"), 3598010654UL, PH_NOISY_CC); - if (phalcon_is_numeric(conditions)) { - - if (Z_TYPE_P(models) == IS_ARRAY) { + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Loader, getClasses){ + + + RETURN_MEMBER_QUICK(this_ptr, "_classes", 3992428914UL); +} + +static PHP_METHOD(Phalcon_Loader, register){ + + zval *registered, *autoloader; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(registered); + phalcon_read_property_this_quick(®istered, this_ptr, SL("_registered"), 3990603890UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(registered)) { + PHALCON_INIT_VAR(autoloader); + array_init_size(autoloader, 2); + phalcon_array_append(&autoloader, this_ptr, PH_SEPARATE); + add_next_index_stringl(autoloader, SL("autoLoad"), 1); + phalcon_call_func_p1_noret("spl_autoload_register", autoloader); + phalcon_update_property_bool(this_ptr, SL("_registered"), 1 TSRMLS_CC); + } - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Loader, unregister){ + + zval *registered, *autoloader; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(registered); + phalcon_read_property_this_quick(®istered, this_ptr, SL("_registered"), 3990603890UL, PH_NOISY_CC); + if (PHALCON_IS_TRUE(registered)) { + PHALCON_INIT_VAR(autoloader); + array_init_size(autoloader, 2); + phalcon_array_append(&autoloader, this_ptr, PH_SEPARATE); + add_next_index_stringl(autoloader, SL("autoLoad"), 1); + phalcon_call_func_p1_noret("spl_autoload_unregister", autoloader); + phalcon_update_property_bool(this_ptr, SL("_registered"), 0 TSRMLS_CC); + } - PHALCON_INIT_VAR(number_models); - phalcon_fast_count(number_models, models TSRMLS_CC); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Loader, autoLoad){ + + zval *class_name, *events_manager, *event_name = NULL; + zval *classes, *file_path = NULL, *extensions, *ds, *namespace_separator; + zval *empty_str, *zero, *namespaces, *directory = NULL; + zval *ns_prefix = NULL, *file_name = NULL, *fixed_directory = NULL; + zval *extension = NULL, *pseudo_separator, *prefixes; + zval *prefix = NULL, *ds_class_name, *ns_class_name; + zval *directories; + HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5; + HashPosition hp0, hp1, hp2, hp3, hp4, hp5; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &class_name); - PHALCON_INIT_VAR(invalid_condition); - is_smaller_function(invalid_condition, one, number_models TSRMLS_CC); - if (PHALCON_IS_TRUE(invalid_condition)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Cannot build the query. Invalid condition"); - return; - } + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "loader:beforeCheckClass", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, class_name, 259017035UL); + } - PHALCON_OBS_VAR(model); - phalcon_array_fetch_long(&model, models, 0, PH_NOISY); - } else { - PHALCON_CPY_WRT(model, models); - } + PHALCON_OBS_VAR(classes); + phalcon_read_property_this_quick(&classes, this_ptr, SL("_classes"), 3992428914UL, PH_NOISY_CC); + if (Z_TYPE_P(classes) == IS_ARRAY) { + if (phalcon_array_isset(classes, class_name)) { - PHALCON_INIT_VAR(service_name); - ZVAL_STRING(service_name, "modelsMetadata", 1); + PHALCON_OBS_VAR(file_path); + phalcon_array_fetch(&file_path, classes, class_name, PH_NOISY); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC); - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_p1_key(meta_data, dependency_injector, "getshared", service_name, 1727570332UL); - ce0 = phalcon_fetch_class(model TSRMLS_CC); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "loader:pathFound", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); + } - PHALCON_INIT_VAR(model_instance); - object_init_ex(model_instance, ce0); - if (phalcon_has_constructor(model_instance TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, model_instance, "__construct", dependency_injector, 1107214344UL); + if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { + return; + } + RETURN_MM_TRUE; } + } - PHALCON_INIT_VAR(no_primary); - ZVAL_BOOL(no_primary, 1); + PHALCON_OBS_VAR(extensions); + phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); - PHALCON_INIT_VAR(primary_keys); - phalcon_call_method_p1_key(primary_keys, meta_data, "getprimarykeyattributes", model_instance, 692945721UL); - if (phalcon_fast_count_ev(primary_keys TSRMLS_CC)) { - if (phalcon_array_isset_long(primary_keys, 0)) { + PHALCON_INIT_VAR(ds); + ZVAL_STRING(ds, PHALCON_DIRECTORY_SEPARATOR, 1); - PHALCON_OBS_VAR(first_primary_key); - phalcon_array_fetch_long(&first_primary_key, primary_keys, 0, PH_NOISY); + PHALCON_INIT_VAR(namespace_separator); + ZVAL_STRING(namespace_separator, "\\", 1); - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", model_instance, 213063537UL); - } else { - PHALCON_INIT_NVAR(column_map); - } + PHALCON_INIT_VAR(empty_str); + ZVAL_STRING(empty_str, "", 1); - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, first_primary_key)) { - PHALCON_OBS_VAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, first_primary_key, PH_NOISY); - } else { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", first_primary_key, "\" isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(attribute_field, first_primary_key); - } + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); - PHALCON_INIT_VAR(primary_key_condition); - PHALCON_CONCAT_SVSVSV(primary_key_condition, "[", model, "].[", attribute_field, "] = ", conditions); - PHALCON_CPY_WRT(conditions, primary_key_condition); + PHALCON_OBS_VAR(namespaces); + phalcon_read_property_this_quick(&namespaces, this_ptr, SL("_namespaces"), 3363620132UL, PH_NOISY_CC); + if (Z_TYPE_P(namespaces) == IS_ARRAY) { - ZVAL_BOOL(no_primary, 0); - } - } + phalcon_is_iterable(namespaces, &ah0, &hp0, 0, 0); - if (PHALCON_IS_TRUE(no_primary)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Source related to this model does not have a primary key defined"); - return; - } - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(phql); - ZVAL_STRING(phql, "SELECT ", 1); + PHALCON_GET_HKEY(ns_prefix, ah0, hp0); + PHALCON_GET_HVALUE(directory); - PHALCON_OBS_VAR(columns); - phalcon_read_property_this_quick(&columns, this_ptr, SL("_columns"), 4004520869UL, PH_NOISY_CC); - if (Z_TYPE_P(columns) != IS_NULL) { + if (phalcon_start_with(class_name, ns_prefix, NULL)) { - if (Z_TYPE_P(columns) == IS_ARRAY) { + PHALCON_INIT_NVAR(file_name); + phalcon_possible_autoload_filepath(file_name, ns_prefix, class_name, ds, NULL TSRMLS_CC); + if (zend_is_true(file_name)) { - PHALCON_INIT_VAR(selected_columns); - array_init(selected_columns); + PHALCON_INIT_NVAR(fixed_directory); + phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC); - phalcon_is_iterable(columns, &ah0, &hp0, 0, 0); + phalcon_is_iterable(extensions, &ah1, &hp1, 0, 0); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_GET_HKEY(column_alias, ah0, hp0); - PHALCON_GET_HVALUE(column); + PHALCON_GET_HVALUE(extension); - if (Z_TYPE_P(column_alias) == IS_LONG) { - phalcon_array_append(&selected_columns, column, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(aliased_column); - PHALCON_CONCAT_VSV(aliased_column, column, " AS ", column_alias); - phalcon_array_append(&selected_columns, aliased_column, PH_SEPARATE); - } + PHALCON_INIT_NVAR(file_path); + PHALCON_CONCAT_VVSV(file_path, fixed_directory, file_name, ".", extension); - zend_hash_move_forward_ex(ah0, &hp0); - } + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC); - PHALCON_INIT_VAR(joined_columns); - phalcon_fast_join_str(joined_columns, SL(", "), selected_columns TSRMLS_CC); - phalcon_concat_self(&phql, joined_columns TSRMLS_CC); - } else { - phalcon_concat_self(&phql, columns TSRMLS_CC); - } - } else { - if (Z_TYPE_P(models) == IS_ARRAY) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "loader:beforeCheckPath", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } - PHALCON_INIT_NVAR(selected_columns); - array_init(selected_columns); + if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) { + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC); - phalcon_is_iterable(models, &ah1, &hp1, 0, 0); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "loader:pathFound", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); + } - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { + return; + } - PHALCON_GET_HKEY(model_column_alias, ah1, hp1); - PHALCON_GET_HVALUE(model); + RETURN_MM_TRUE; + } - if (Z_TYPE_P(model_column_alias) == IS_LONG) { - PHALCON_INIT_NVAR(selected_column); - PHALCON_CONCAT_SVS(selected_column, "[", model, "].*"); - } else { - PHALCON_INIT_NVAR(selected_column); - PHALCON_CONCAT_SVS(selected_column, "[", model_column_alias, "].*"); - } - phalcon_array_append(&selected_columns, selected_column, PH_SEPARATE); + zend_hash_move_forward_ex(ah1, &hp1); + } - zend_hash_move_forward_ex(ah1, &hp1); + } } - PHALCON_INIT_NVAR(joined_columns); - phalcon_fast_join_str(joined_columns, SL(", "), selected_columns TSRMLS_CC); - phalcon_concat_self(&phql, joined_columns TSRMLS_CC); - } else { - PHALCON_SCONCAT_SVS(phql, "[", models, "].*"); + zend_hash_move_forward_ex(ah0, &hp0); } + } - if (Z_TYPE_P(models) == IS_ARRAY) { + PHALCON_INIT_VAR(pseudo_separator); + ZVAL_STRING(pseudo_separator, "_", 1); - PHALCON_INIT_VAR(selected_models); - array_init(selected_models); + PHALCON_OBS_VAR(prefixes); + phalcon_read_property_this_quick(&prefixes, this_ptr, SL("_prefixes"), 900970058UL, PH_NOISY_CC); + if (Z_TYPE_P(prefixes) == IS_ARRAY) { - phalcon_is_iterable(models, &ah2, &hp2, 0, 0); + phalcon_is_iterable(prefixes, &ah2, &hp2, 0, 0); while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - PHALCON_GET_HKEY(model_alias, ah2, hp2); - PHALCON_GET_HVALUE(model); + PHALCON_GET_HKEY(prefix, ah2, hp2); + PHALCON_GET_HVALUE(directory); - if (Z_TYPE_P(model_alias) == IS_STRING) { - PHALCON_INIT_NVAR(selected_model); - PHALCON_CONCAT_SVSVS(selected_model, "[", model, "] AS [", model_alias, "]"); - } else { - PHALCON_INIT_NVAR(selected_model); - PHALCON_CONCAT_SVS(selected_model, "[", model, "]"); - } - phalcon_array_append(&selected_models, selected_model, PH_SEPARATE); + if (phalcon_start_with(class_name, prefix, NULL)) { - zend_hash_move_forward_ex(ah2, &hp2); - } + PHALCON_INIT_NVAR(file_name); + phalcon_possible_autoload_filepath(file_name, prefix, class_name, ds, pseudo_separator TSRMLS_CC); + if (zend_is_true(file_name)) { - PHALCON_INIT_VAR(joined_models); - phalcon_fast_join_str(joined_models, SL(", "), selected_models TSRMLS_CC); - PHALCON_SCONCAT_SV(phql, " FROM ", joined_models); - } else { - PHALCON_SCONCAT_SVS(phql, " FROM [", models, "]"); - } + PHALCON_INIT_NVAR(fixed_directory); + phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC); - PHALCON_OBS_VAR(joins); - phalcon_read_property_this_quick(&joins, this_ptr, SL("_joins"), 2482180647UL, PH_NOISY_CC); - if (Z_TYPE_P(joins) == IS_ARRAY) { + phalcon_is_iterable(extensions, &ah3, &hp3, 0, 0); - phalcon_is_iterable(joins, &ah3, &hp3, 0, 0); + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { + PHALCON_GET_HVALUE(extension); - PHALCON_GET_HVALUE(join); + PHALCON_INIT_NVAR(file_path); + PHALCON_CONCAT_VVSV(file_path, fixed_directory, file_name, ".", extension); - PHALCON_OBS_NVAR(join_model); - phalcon_array_fetch_long(&join_model, join, 0, PH_NOISY); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC); - PHALCON_OBS_NVAR(join_conditions); - phalcon_array_fetch_long(&join_conditions, join, 1, PH_NOISY); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "loader:beforeCheckPath", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); + } - PHALCON_OBS_NVAR(join_alias); - phalcon_array_fetch_long(&join_alias, join, 2, PH_NOISY); + if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) { - PHALCON_OBS_NVAR(join_type); - phalcon_array_fetch_long(&join_type, join, 3, PH_NOISY); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC); - if (zend_is_true(join_type)) { - PHALCON_SCONCAT_SVSVS(phql, " ", join_type, " JOIN [", join_model, "]"); - } else { - PHALCON_SCONCAT_SVS(phql, " JOIN [", join_model, "]"); - } + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "loader:pathFound", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); + } + if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { + return; + } + RETURN_MM_TRUE; + } - if (zend_is_true(join_alias)) { - PHALCON_SCONCAT_SVS(phql, " AS [", join_alias, "]"); - } + zend_hash_move_forward_ex(ah3, &hp3); + } - if (zend_is_true(join_conditions)) { - PHALCON_SCONCAT_SV(phql, " ON ", join_conditions); + } } - zend_hash_move_forward_ex(ah3, &hp3); + zend_hash_move_forward_ex(ah2, &hp2); } } - if (Z_TYPE_P(conditions) == IS_STRING) { - if (PHALCON_IS_NOT_EMPTY(conditions)) { - PHALCON_SCONCAT_SV(phql, " WHERE ", conditions); - } - } - - PHALCON_OBS_VAR(group); - phalcon_read_property_this_quick(&group, this_ptr, SL("_group"), 2368555377UL, PH_NOISY_CC); - if (Z_TYPE_P(group) != IS_NULL) { - if (Z_TYPE_P(group) == IS_ARRAY) { + PHALCON_INIT_VAR(ds_class_name); + phalcon_fast_str_replace(ds_class_name, pseudo_separator, ds, class_name); - PHALCON_INIT_VAR(group_items); - array_init(group_items); + PHALCON_INIT_VAR(ns_class_name); + phalcon_fast_str_replace(ns_class_name, namespace_separator, ds, ds_class_name); - phalcon_is_iterable(group, &ah4, &hp4, 0, 0); + PHALCON_OBS_VAR(directories); + phalcon_read_property_this_quick(&directories, this_ptr, SL("_directories"), 3207828897UL, PH_NOISY_CC); + if (Z_TYPE_P(directories) == IS_ARRAY) { - while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { + phalcon_is_iterable(directories, &ah4, &hp4, 0, 0); - PHALCON_GET_HVALUE(group_item); + while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { - if (phalcon_is_numeric(group_item)) { - phalcon_array_append(&group_items, group_item, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(group_item, SL("."))) { - phalcon_array_append(&group_items, group_item, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(escaped_item); - PHALCON_CONCAT_SVS(escaped_item, "[", group_item, "]"); - phalcon_array_append(&group_items, escaped_item, PH_SEPARATE); - } - } + PHALCON_GET_HVALUE(directory); - zend_hash_move_forward_ex(ah4, &hp4); - } + PHALCON_INIT_NVAR(fixed_directory); + phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC); - PHALCON_INIT_VAR(joined_items); - phalcon_fast_join_str(joined_items, SL(", "), group_items TSRMLS_CC); - PHALCON_SCONCAT_SV(phql, " GROUP BY ", joined_items); - } else { - if (phalcon_is_numeric(group)) { - PHALCON_SCONCAT_SV(phql, " GROUP BY ", group); - } else { - if (phalcon_memnstr_str(group, SL("."))) { - PHALCON_SCONCAT_SV(phql, " GROUP BY ", group); - } else { - PHALCON_SCONCAT_SVS(phql, " GROUP BY [", group, "]"); - } - } - } + phalcon_is_iterable(extensions, &ah5, &hp5, 0, 0); - PHALCON_OBS_VAR(having); - phalcon_read_property_this_quick(&having, this_ptr, SL("_having"), 1486953825UL, PH_NOISY_CC); - if (Z_TYPE_P(having) != IS_NULL) { - if (PHALCON_IS_NOT_EMPTY(having)) { - PHALCON_SCONCAT_SV(phql, " HAVING ", having); - } - } - } + while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { - PHALCON_OBS_VAR(order); - phalcon_read_property_this_quick(&order, this_ptr, SL("_order"), 2681225856UL, PH_NOISY_CC); - if (Z_TYPE_P(order) != IS_NULL) { - if (Z_TYPE_P(order) == IS_ARRAY) { + PHALCON_GET_HVALUE(extension); - PHALCON_INIT_VAR(order_items); - array_init(order_items); + PHALCON_INIT_NVAR(file_path); + PHALCON_CONCAT_VVSV(file_path, fixed_directory, ns_class_name, ".", extension); - phalcon_is_iterable(order, &ah5, &hp5, 0, 0); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC); - while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "loader:beforeCheckPath", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); + } - PHALCON_GET_HVALUE(order_item); + if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) { - if (phalcon_is_numeric(order_item)) { - phalcon_array_append(&order_items, order_item, PH_SEPARATE); - } else { - if (phalcon_memnstr_str(order_item, SL("."))) { - phalcon_array_append(&order_items, order_item, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(escaped_item); - PHALCON_CONCAT_SVS(escaped_item, "[", order_item, "]"); - phalcon_array_append(&order_items, escaped_item, PH_SEPARATE); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC); + + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "loader:pathFound", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); + } + + if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { + return; } + + RETURN_MM_TRUE; } zend_hash_move_forward_ex(ah5, &hp5); } - PHALCON_INIT_NVAR(joined_items); - phalcon_fast_join_str(joined_items, SL(", "), order_items TSRMLS_CC); - PHALCON_SCONCAT_SV(phql, " ORDER BY ", joined_items); - } else { - PHALCON_SCONCAT_SV(phql, " ORDER BY ", order); + zend_hash_move_forward_ex(ah4, &hp4); } - } - - PHALCON_OBS_VAR(limit); - phalcon_read_property_this_quick(&limit, this_ptr, SL("_limit"), 2553474243UL, PH_NOISY_CC); - if (Z_TYPE_P(limit) != IS_NULL) { - if (Z_TYPE_P(limit) == IS_ARRAY) { - PHALCON_OBS_VAR(number); - phalcon_array_fetch_quick_string(&number, limit, SS("number"), 807219790UL, PH_NOISY); - if (phalcon_array_isset_quick_string(limit, SS("offset"), 1503966412UL)) { - - PHALCON_OBS_VAR(offset); - phalcon_array_fetch_quick_string(&offset, limit, SS("offset"), 1503966412UL, PH_NOISY); - if (phalcon_is_numeric(offset)) { - PHALCON_SCONCAT_SVSV(phql, " LIMIT ", number, " OFFSET ", offset); - } else { - PHALCON_SCONCAT_SVS(phql, " LIMIT ", number, " OFFSET 0"); - } - } else { - PHALCON_SCONCAT_SV(phql, " LIMIT ", number); - } - } else { - if (phalcon_is_numeric(limit)) { - PHALCON_SCONCAT_SV(phql, " LIMIT ", limit); + } - PHALCON_OBS_NVAR(offset); - phalcon_read_property_this_quick(&offset, this_ptr, SL("_offset"), 2114347243UL, PH_NOISY_CC); - if (Z_TYPE_P(offset) != IS_NULL) { - if (phalcon_is_numeric(offset)) { - PHALCON_SCONCAT_SV(phql, " OFFSET ", offset); - } else { - phalcon_concat_self_str(&phql, SL(" OFFSET 0") TSRMLS_CC); - } - } - } - } + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "loader:afterCheckClass", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, class_name, 259017035UL); } - RETURN_CTOR(phql); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getQuery){ +static PHP_METHOD(Phalcon_Loader, getFoundPath){ - zval *phql, *dependency_injector, *query, *bind_params; - zval *bind_types; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_foundPath", 2210068013UL); +} - PHALCON_INIT_VAR(phql); - phalcon_call_method_key(phql, this_ptr, "getphql", 4289069082UL); - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(query); - object_init_ex(query, phalcon_mvc_model_query_ce); - phalcon_call_method_p2_key(NULL, query, "__construct", phql, dependency_injector, 1107214344UL); - - PHALCON_OBS_VAR(bind_params); - phalcon_read_property_this_quick(&bind_params, this_ptr, SL("_bindParams"), 2293392709UL, PH_NOISY_CC); - - if (Z_TYPE_P(bind_params) == IS_ARRAY) { - phalcon_call_method_p1_key(NULL, query, "setbindparams", bind_params, 3456925394UL); - } - - PHALCON_OBS_VAR(bind_types); - phalcon_read_property_this_quick(&bind_types, this_ptr, SL("_bindTypes"), 514734038UL, PH_NOISY_CC); - - if (Z_TYPE_P(bind_types) == IS_ARRAY) { - phalcon_call_method_p1_key(NULL, query, "setbindtypes", bind_types, 3543454659UL); - } - - RETURN_CTOR(query); +static PHP_METHOD(Phalcon_Loader, getCheckedPath){ + + + RETURN_MEMBER_QUICK(this_ptr, "_checkedPath", 2930914648UL); } -/* Driver template for the LEMON parser generator. -** The author disclaims copyright to this source code. -*/ -/* First off, code is include which follows the "include" declaration -** in the input file. */ -#include -// 38 "parser.lemon" #ifdef HAVE_CONFIG_H @@ -44469,9437 +44136,9147 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getQuery){ -static zval *phql_ret_literal_zval(int type, phql_parser_token *T) -{ - zval *ret; - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", type); - if (T) { - add_assoc_stringl(ret, "value", T->token, T->token_len, 0); - efree(T); - } - return ret; -} -static zval *phql_ret_placeholder_zval(int type, phql_parser_token *T) -{ - zval *ret; +PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_File){ - MAKE_STD_ZVAL(ret); - array_init_size(ret, 2); - add_assoc_long(ret, "type", type); - add_assoc_stringl(ret, "value", T->token, T->token_len, 0); - efree(T); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, File, logger_adapter_file, "phalcon\\logger\\adapter", phalcon_logger_adapter_file_method_entry, 0); - return ret; + zend_declare_property_null(phalcon_logger_adapter_file_ce, SL("_fileHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_logger_adapter_file_ce, SL("_path"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_logger_adapter_file_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_logger_adapter_file_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + + return SUCCESS; } -static zval *phql_ret_qualified_name(phql_parser_token *A, phql_parser_token *B, phql_parser_token *C) -{ - zval *ret; +static PHP_METHOD(Phalcon_Logger_Adapter_File, __construct){ - MAKE_STD_ZVAL(ret); - array_init(ret); + zval *name, *options = NULL, *mode = NULL, *handler, *exception_message; - add_assoc_long(ret, "type", PHQL_T_QUALIFIED); + PHALCON_MM_GROW(); - if (A != NULL) { - add_assoc_stringl(ret, "ns-alias", A->token, A->token_len, 0); - efree(A); + phalcon_fetch_params(1, 1, 1, &name, &options); + + if (!options) { + PHALCON_INIT_VAR(options); } - - if (B != NULL) { - add_assoc_stringl(ret, "domain", B->token, B->token_len, 0); - efree(B); + + if (phalcon_array_isset_quick_string(options, SS("mode"), 267518858UL)) { + + PHALCON_OBS_VAR(mode); + phalcon_array_fetch_quick_string(&mode, options, SS("mode"), 267518858UL, PH_NOISY); + if (phalcon_memnstr_str(mode, SL("r"))) { + PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Logger must be opened in append or write mode"); + return; + } + } else { + PHALCON_INIT_NVAR(mode); + ZVAL_STRING(mode, "ab", 1); + } + + PHALCON_INIT_VAR(handler); + phalcon_call_func_p2(handler, "fopen", name, mode); + if (!zend_is_true(handler)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Can't open log file at '", name, "'"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_logger_exception_ce, exception_message); + return; } + + phalcon_update_property_this_quick(this_ptr, SL("_path"), name, 3986357393UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_fileHandler"), handler, 1678121186UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} - add_assoc_stringl(ret, "name", C->token, C->token_len, 0); - efree(C); +static PHP_METHOD(Phalcon_Logger_Adapter_File, getFormatter){ - return ret; + zval *formatter = NULL; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(formatter); + phalcon_read_property_this_quick(&formatter, this_ptr, SL("_formatter"), 1838243768UL, PH_NOISY_CC); + if (Z_TYPE_P(formatter) != IS_OBJECT) { + PHALCON_INIT_NVAR(formatter); + object_init_ex(formatter, phalcon_logger_formatter_line_ce); + phalcon_call_method_key(NULL, formatter, "__construct", 1107214344UL); + + phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); + } + + RETURN_CCTOR(formatter); } -static zval *phql_ret_raw_qualified_name(phql_parser_token *A, phql_parser_token *B) -{ - zval *ret; +static PHP_METHOD(Phalcon_Logger_Adapter_File, logInternal){ - MAKE_STD_ZVAL(ret); - array_init(ret); + zval *message, *type, *time, *file_handler, *formatter; + zval *applied_format; - add_assoc_long(ret, "type", PHQL_T_RAW_QUALIFIED); - if (B != NULL) { - add_assoc_stringl(ret, "domain", A->token, A->token_len, 0); - add_assoc_stringl(ret, "name", B->token, B->token_len, 0); - efree(B); - } else { - add_assoc_stringl(ret, "name", A->token, A->token_len, 0); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &message, &type, &time); + + PHALCON_OBS_VAR(file_handler); + phalcon_read_property_this_quick(&file_handler, this_ptr, SL("_fileHandler"), 1678121186UL, PH_NOISY_CC); + if (!zend_is_true(file_handler)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Cannot send message to the log because it is invalid"); + return; } - efree(A); + + PHALCON_INIT_VAR(formatter); + phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); + + PHALCON_INIT_VAR(applied_format); + phalcon_call_method_p3_key(applied_format, formatter, "format", message, type, time, 3131886190UL); + phalcon_call_func_p2_noret("fwrite", file_handler, applied_format); + + PHALCON_MM_RESTORE(); +} - return ret; +static PHP_METHOD(Phalcon_Logger_Adapter_File, close){ + + zval *file_handler; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(file_handler); + phalcon_read_property_this_quick(&file_handler, this_ptr, SL("_fileHandler"), 1678121186UL, PH_NOISY_CC); + phalcon_call_func_p1(return_value, "fclose", file_handler); + RETURN_MM(); } -static zval *phql_ret_select_statement(zval *S, zval *W, zval *O, zval *G, zval *H, zval *L) -{ - zval *ret; +static PHP_METHOD(Phalcon_Logger_Adapter_File, __wakeup){ - MAKE_STD_ZVAL(ret); - array_init(ret); + zval *path, *options, *mode = NULL, *file_handler; - add_assoc_long(ret, "type", PHQL_T_SELECT); - add_assoc_zval(ret, "select", S); + PHALCON_MM_GROW(); - if (W != NULL) { - add_assoc_zval(ret, "where", W); - } - if (O != NULL) { - add_assoc_zval(ret, "orderBy", O); - } - if (G != NULL) { - add_assoc_zval(ret, "groupBy", G); - } - if (H != NULL) { - add_assoc_zval(ret, "having", H); - } - if (L != NULL) { - add_assoc_zval(ret, "limit", L); + PHALCON_OBS_VAR(path); + phalcon_read_property_this_quick(&path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(options, SS("mode"), 267518858UL)) { + PHALCON_OBS_VAR(mode); + phalcon_array_fetch_quick_string(&mode, options, SS("mode"), 267518858UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(mode); + ZVAL_STRING(mode, "ab", 1); } - - return ret; + + PHALCON_INIT_VAR(file_handler); + phalcon_call_func_p2(file_handler, "fopen", path, mode); + phalcon_update_property_this_quick(this_ptr, SL("_fileHandler"), file_handler, 1678121186UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static zval *phql_ret_select_clause(zval *columns, zval *tables, zval *join_list) -{ - zval *ret; - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_zval(ret, "columns", columns); - add_assoc_zval(ret, "tables", tables); - if (join_list) { - add_assoc_zval(ret, "joins", join_list); - } - return ret; -} -static zval *phql_ret_order_item(zval *column, int sort){ - zval *ret; +#ifdef HAVE_CONFIG_H +#endif - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_zval(ret, "column", column); - if (sort != 0 ) { - add_assoc_long(ret, "sort", sort); - } - return ret; -} -static zval *phql_ret_limit_clause(phql_parser_token *L, phql_parser_token *O) -{ - zval *ret; - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_stringl(ret, "number", L->token, L->token_len, 0); - efree(L); - if (O != NULL) { - add_assoc_stringl(ret, "offset", O->token, O->token_len, 0); - efree(O); - } - return ret; -} -static zval *phql_ret_insert_statement(zval *Q, zval *F, zval *V) -{ - zval *ret; +PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_Firephp){ - MAKE_STD_ZVAL(ret); - array_init(ret); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, Firephp, logger_adapter_firephp, "phalcon\\logger\\adapter", phalcon_logger_adapter_firephp_method_entry, 0); - add_assoc_long(ret, "type", PHQL_T_INSERT); - add_assoc_zval(ret, "qualifiedName", Q); - if (F != NULL) { - add_assoc_zval(ret, "fields", F); - } - add_assoc_zval(ret, "values", V); + zend_declare_property_bool(phalcon_logger_adapter_firephp_ce, SL("_initialized"), 0, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC TSRMLS_CC); + zend_declare_property_long(phalcon_logger_adapter_firephp_ce, SL("_index"), 1, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC TSRMLS_CC); - return ret; + zend_class_implements(phalcon_logger_adapter_firephp_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + + return SUCCESS; } -static zval *phql_ret_update_statement(zval *U, zval *W, zval *L) -{ - zval *ret; +static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, getFormatter){ - MAKE_STD_ZVAL(ret); - array_init(ret); + zval *formatter = NULL; - add_assoc_long(ret, "type", PHQL_T_UPDATE); - add_assoc_zval(ret, "update", U); - if (W != NULL) { - add_assoc_zval(ret, "where", W); - } - if (L != NULL) { - add_assoc_zval(ret, "limit", L); + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(formatter); + phalcon_read_property_this_quick(&formatter, this_ptr, SL("_formatter"), 1838243768UL, PH_NOISY_CC); + if (Z_TYPE_P(formatter) != IS_OBJECT) { + /* This will update $this->_formatter, no need to call phalcon_update_property_this() explicitly */ + object_init_ex(formatter, phalcon_logger_formatter_firephp_ce); } - return ret; + RETURN_CCTOR(formatter); } -static zval *phql_ret_update_clause(zval *tables, zval *values) -{ - zval *ret; +static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, logInternal){ - MAKE_STD_ZVAL(ret); - array_init_size(ret, 2); - add_assoc_zval(ret, "tables", tables); - add_assoc_zval(ret, "values", values); + zval *message, *type, *time, *formatter, *applied_format; + zval *initialized, *index; + sapi_header_line h = { NULL, 0, 0 }; + smart_str str = { NULL, 0, 0 }; + int size, offset, num_bytes; + const int chunk = 4960; - return ret; -} + /* If headers has already been sent, we can do nothing. Exit early. */ + if (SG(headers_sent)) { + RETURN_FALSE; + } -static zval *phql_ret_update_item(zval *column, zval *expr) -{ + PHALCON_MM_GROW(); - zval *ret; + phalcon_fetch_params(1, 3, 0, &message, &type, &time); - MAKE_STD_ZVAL(ret); - array_init_size(ret, 2); - add_assoc_zval(ret, "column", column); - add_assoc_zval(ret, "expr", expr); + PHALCON_INIT_VAR(formatter); + phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); - return ret; -} + PHALCON_OBS_VAR(initialized); + phalcon_read_static_property(&initialized, SL("phalcon\\logger\\adapter\\firephp"), SL("_initialized") TSRMLS_CC); + if (!zend_is_true(initialized)) { + h.line = "X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2"; + h.line_len = sizeof("X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2")-1; + sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC); -static zval *phql_ret_delete_statement(zval *D, zval *W, zval *L) -{ - zval *ret; + h.line = "X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3"; + h.line_len = sizeof("X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3")-1; + sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC); - MAKE_STD_ZVAL(ret); - array_init(ret); + h.line = "X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1"; + h.line_len = sizeof("X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1")-1; + sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC); - add_assoc_long(ret, "type", PHQL_T_DELETE); - add_assoc_zval(ret, "delete", D); - if (W != NULL) { - add_assoc_zval(ret, "where", W); + ZVAL_TRUE(initialized); /* This will also update the property because "initialized" was not separated */ } - if (L != NULL) { - add_assoc_zval(ret, "limit", L); + + PHALCON_INIT_VAR(applied_format); + phalcon_call_method_p3_key(applied_format, formatter, "format", message, type, time, 3131886190UL); + if (Z_TYPE_P(applied_format) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "The formatted message is not valid"); + return; } - return ret; -} + PHALCON_OBS_VAR(index); + phalcon_read_static_property(&index, SL("phalcon\\logger\\adapter\\firephp"), SL("_index") TSRMLS_CC); -static zval *phql_ret_delete_clause(zval *tables) -{ - zval *ret; + size = Z_STRLEN_P(applied_format); + offset = 0; - MAKE_STD_ZVAL(ret); - array_init_size(ret, 1); - add_assoc_zval(ret, "tables", tables); + smart_str_alloc4(&str, (size > chunk ? chunk : size), 0, num_bytes); - return ret; -} + while (size > 0) { + smart_str_appends(&str, "X-Wf-1-1-1-"); + smart_str_append_long(&str, Z_LVAL_P(index)); + smart_str_appends(&str, ": "); + num_bytes = size > chunk ? chunk : size; -static zval *phql_ret_zval_list(zval *list_left, zval *right_list) -{ + if (offset) { + /* This is not the first chunk, prepend the payload with "|" */ + smart_str_appendc(&str, '|'); + } - zval *ret; - HashPosition pos; - HashTable *list; + /* Grab the chunk from the encoded string */ + smart_str_appendl(&str, Z_STRVAL_P(applied_format) + offset, num_bytes); - MAKE_STD_ZVAL(ret); - array_init(ret); + size -= num_bytes; + offset += num_bytes; - list = Z_ARRVAL_P(list_left); - if (zend_hash_index_exists(list, 0)) { - zend_hash_internal_pointer_reset_ex(list, &pos); - for (;; zend_hash_move_forward_ex(list, &pos)) { + if (size) { + /* If we have more data to send, append "|/" */ + smart_str_appendl(&str, "|\\", 2); + } - zval ** item; + smart_str_0(&str); /* Not strictly necessary but just to be safe */ - if (zend_hash_get_current_data_ex(list, (void**)&item, &pos) == FAILURE) { - break; - } + /* Send the result */ + h.line = str.c; + h.line_len = str.len; + sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC); - Z_ADDREF_PP(item); - add_next_index_zval(ret, *item); + /* Update header index; this will update Phalcon\Logger\Adapter\Firephp as well */ + ZVAL_LONG(index, Z_LVAL_P(index)+1); - } - zval_ptr_dtor(&list_left); - } else { - add_next_index_zval(ret, list_left); + str.len = 0; } - if (right_list) { - add_next_index_zval(ret, right_list); + /* Deallocate the smnart string if it is not empty */ + if (str.c) { + smart_str_free(&str); } - return ret; + PHALCON_MM_RESTORE(); } -static zval *phql_ret_column_item(int type, zval *column, phql_parser_token *identifier_column, phql_parser_token *alias) -{ +static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, close){ - zval *ret; + RETURN_TRUE; +} - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", type); - if (column) { - add_assoc_zval(ret, "column", column); + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_Stream){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, Stream, logger_adapter_stream, "phalcon\\logger\\adapter", phalcon_logger_adapter_stream_method_entry, 0); + + zend_declare_property_null(phalcon_logger_adapter_stream_ce, SL("_stream"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_logger_adapter_stream_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Logger_Adapter_Stream, __construct){ + + zval *name, *options = NULL, *mode = NULL, *stream, *exception_message; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &name, &options); + + if (!options) { + PHALCON_INIT_VAR(options); } - if (identifier_column) { - add_assoc_stringl(ret, "column", identifier_column->token, identifier_column->token_len, 0); - efree(identifier_column); + + if (phalcon_array_isset_quick_string(options, SS("mode"), 267518858UL)) { + + PHALCON_OBS_VAR(mode); + phalcon_array_fetch_quick_string(&mode, options, SS("mode"), 267518858UL, PH_NOISY); + if (phalcon_memnstr_str(mode, SL("r"))) { + PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Stream must be opened in append or write mode"); + return; + } + } else { + PHALCON_INIT_NVAR(mode); + ZVAL_STRING(mode, "ab", 1); } - if (alias) { - add_assoc_stringl(ret, "alias", alias->token, alias->token_len, 0); - efree(alias); + + PHALCON_INIT_VAR(stream); + phalcon_call_func_p2(stream, "fopen", name, mode); + if (!zend_is_true(stream)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Can't open stream '", name, "'"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_logger_exception_ce, exception_message); + return; } + + phalcon_update_property_this_quick(this_ptr, SL("_stream"), stream, 3546870672UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} - return ret; +static PHP_METHOD(Phalcon_Logger_Adapter_Stream, getFormatter){ + + zval *formatter = NULL; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(formatter); + phalcon_read_property_this_quick(&formatter, this_ptr, SL("_formatter"), 1838243768UL, PH_NOISY_CC); + if (Z_TYPE_P(formatter) != IS_OBJECT) { + PHALCON_INIT_NVAR(formatter); + object_init_ex(formatter, phalcon_logger_formatter_line_ce); + phalcon_call_method_key(NULL, formatter, "__construct", 1107214344UL); + + phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); + } + + RETURN_CCTOR(formatter); } -static zval *phql_ret_assoc_name(zval *qualified_name, phql_parser_token *alias) -{ +static PHP_METHOD(Phalcon_Logger_Adapter_Stream, logInternal){ - zval *ret; + zval *message, *type, *time, *stream, *formatter, *applied_format; - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_zval(ret, "qualifiedName", qualified_name); - if (alias) { - add_assoc_stringl(ret, "alias", alias->token, alias->token_len, 0); - efree(alias); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &message, &type, &time); + + PHALCON_OBS_VAR(stream); + phalcon_read_property_this_quick(&stream, this_ptr, SL("_stream"), 3546870672UL, PH_NOISY_CC); + if (!zend_is_true(stream)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Cannot send message to the log because it is invalid"); + return; } + + PHALCON_INIT_VAR(formatter); + phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); + + PHALCON_INIT_VAR(applied_format); + phalcon_call_method_p3_key(applied_format, formatter, "format", message, type, time, 3131886190UL); + phalcon_call_func_p2_noret("fwrite", stream, applied_format); + + PHALCON_MM_RESTORE(); +} - return ret; +static PHP_METHOD(Phalcon_Logger_Adapter_Stream, close){ + zval *stream; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(stream); + phalcon_read_property_this_quick(&stream, this_ptr, SL("_stream"), 3546870672UL, PH_NOISY_CC); + phalcon_call_func_p1(return_value, "fclose", stream); + RETURN_MM(); } -static zval *phql_ret_join_type(int type) -{ - zval *ret; - MAKE_STD_ZVAL(ret); - ZVAL_LONG(ret, type); - return ret; + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_Syslog){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, Syslog, logger_adapter_syslog, "phalcon\\logger\\adapter", phalcon_logger_adapter_syslog_method_entry, 0); + + zend_declare_property_bool(phalcon_logger_adapter_syslog_ce, SL("_opened"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_logger_adapter_syslog_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + + return SUCCESS; } -static zval *phql_ret_join_item(zval *type, zval *qualified, zval *alias, zval *conditions) -{ +static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, __construct){ - zval *ret; + zval *name, *options = NULL, *option = NULL, *facility = NULL; - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_zval(ret, "type", type); + PHALCON_MM_GROW(); - if (qualified) { - add_assoc_zval(ret, "qualified", qualified); + phalcon_fetch_params(1, 1, 1, &name, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } + + if (zend_is_true(name)) { + if (phalcon_array_isset_quick_string(options, SS("option"), 1911574558UL)) { + PHALCON_OBS_VAR(option); + phalcon_array_fetch_quick_string(&option, options, SS("option"), 1911574558UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(option); + ZVAL_LONG(option, 4); + } + if (phalcon_array_isset_quick_string(options, SS("facility"), 2721335866UL)) { + PHALCON_OBS_VAR(facility); + phalcon_array_fetch_quick_string(&facility, options, SS("facility"), 2721335866UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(facility); + ZVAL_LONG(facility, 8); + } + + phalcon_call_func_p3_noret("openlog", name, option, facility); + phalcon_update_property_bool(this_ptr, SL("_opened"), 1 TSRMLS_CC); } + + PHALCON_MM_RESTORE(); +} - if (alias) { - add_assoc_zval(ret, "alias", alias); +static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, getFormatter){ + + zval *formatter = NULL; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(formatter); + phalcon_read_property_this_quick(&formatter, this_ptr, SL("_formatter"), 1838243768UL, PH_NOISY_CC); + if (Z_TYPE_P(formatter) != IS_OBJECT) { + PHALCON_INIT_NVAR(formatter); + object_init_ex(formatter, phalcon_logger_formatter_syslog_ce); + phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); } + + RETURN_CCTOR(formatter); +} - if (conditions) { - add_assoc_zval(ret, "conditions", conditions); +static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, logInternal){ + + zval *message, *type, *time, *formatter, *applied_format; + zval *syslog_type, *syslog_message; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &message, &type, &time); + + PHALCON_INIT_VAR(formatter); + phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); + + PHALCON_INIT_VAR(applied_format); + phalcon_call_method_p3_key(applied_format, formatter, "format", message, type, time, 3131886190UL); + if (Z_TYPE_P(applied_format) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "The formatted message is not valid"); + return; } + + PHALCON_OBS_VAR(syslog_type); + phalcon_array_fetch_long(&syslog_type, applied_format, 0, PH_NOISY); + + PHALCON_OBS_VAR(syslog_message); + phalcon_array_fetch_long(&syslog_message, applied_format, 1, PH_NOISY); + phalcon_call_func_p2_noret("syslog", syslog_type, syslog_message); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, close){ + + zval *opened; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(opened); + phalcon_read_property_this_quick(&opened, this_ptr, SL("_opened"), 2504335039UL, PH_NOISY_CC); + if (zend_is_true(opened)) { + phalcon_call_func_noret("closelog"); + } + + PHALCON_MM_RESTORE(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + - return ret; + + +PHALCON_INIT_CLASS(Phalcon_Logger_Adapter){ + + PHALCON_REGISTER_CLASS(Phalcon\\Logger, Adapter, logger_adapter, phalcon_logger_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_property_bool(phalcon_logger_adapter_ce, SL("_transaction"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_logger_adapter_ce, SL("_queue"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_logger_adapter_ce, SL("_formatter"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_logger_adapter_ce, SL("_logLevel"), 9, ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; } -static zval *phql_ret_expr(int type, zval *left, zval *right) -{ - zval *ret; +static PHP_METHOD(Phalcon_Logger_Adapter, setLogLevel){ - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", type); - if (left) { - add_assoc_zval(ret, "left", left); + zval *level; + + phalcon_fetch_params(0, 1, 0, &level); + + if (Z_TYPE_P(level) != IS_LONG) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "The log level is not valid"); + return; } - if (right) { - add_assoc_zval(ret, "right", right); + phalcon_update_property_this_quick(this_ptr, SL("_logLevel"), level, 4227944734UL TSRMLS_CC); + + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Logger_Adapter, getLogLevel){ + + + RETURN_MEMBER_QUICK(this_ptr, "_logLevel", 4227944734UL); +} + +static PHP_METHOD(Phalcon_Logger_Adapter, setFormatter){ + + zval *formatter; + + phalcon_fetch_params(0, 1, 0, &formatter); + + if (Z_TYPE_P(formatter) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "The formatter is not valid"); + return; } + phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); + + RETURN_THISW(); +} - return ret; +static PHP_METHOD(Phalcon_Logger_Adapter, begin){ + + + phalcon_update_property_bool(this_ptr, SL("_transaction"), 1 TSRMLS_CC); + RETURN_THISW(); } -static zval *phql_ret_func_call(phql_parser_token *name, zval *arguments) -{ +static PHP_METHOD(Phalcon_Logger_Adapter, commit){ - zval *ret; + zval *transaction, *queue, *message = NULL, *message_str = NULL; + zval *type = NULL, *time = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", PHQL_T_FCALL); - add_assoc_stringl(ret, "name", name->token, name->token_len, 0); - efree(name); + PHALCON_MM_GROW(); - if (arguments) { - add_assoc_zval(ret, "arguments", arguments); + PHALCON_OBS_VAR(transaction); + phalcon_read_property_this_quick(&transaction, this_ptr, SL("_transaction"), 1141465066UL, PH_NOISY_CC); + if (!zend_is_true(transaction)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "There is no active transaction"); + return; + } + + phalcon_update_property_bool(this_ptr, SL("_transaction"), 0 TSRMLS_CC); + + PHALCON_OBS_VAR(queue); + phalcon_read_property_this_quick(&queue, this_ptr, SL("_queue"), 2763107337UL, PH_NOISY_CC); + if (Z_TYPE_P(queue) == IS_ARRAY) { + + phalcon_is_iterable(queue, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(message); + + PHALCON_INIT_NVAR(message_str); + phalcon_call_method_key(message_str, message, "getmessage", 4288675242UL); + + PHALCON_INIT_NVAR(type); + phalcon_call_method_key(type, message, "gettype", 4294422375UL); + + PHALCON_INIT_NVAR(time); + phalcon_call_method_key(time, message, "gettime", 4293844116UL); + phalcon_call_method_p3_key(NULL, this_ptr, "loginternal", message_str, type, time, 2472438692UL); + + zend_hash_move_forward_ex(ah0, &hp0); + } + } + + RETURN_THIS(); +} - return ret; +static PHP_METHOD(Phalcon_Logger_Adapter, rollback){ + + zval *transaction, *queue; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(transaction); + phalcon_read_property_this_quick(&transaction, this_ptr, SL("_transaction"), 1141465066UL, PH_NOISY_CC); + if (!zend_is_true(transaction)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "There is no active transaction"); + return; + } + + phalcon_update_property_bool(this_ptr, SL("_transaction"), 0 TSRMLS_CC); + + PHALCON_INIT_VAR(queue); + array_init(queue); + phalcon_update_property_this_quick(this_ptr, SL("_queue"), queue, 2763107337UL TSRMLS_CC); + + RETURN_THIS(); } +static PHP_METHOD(Phalcon_Logger_Adapter, emergence){ -// 416 "parser.c" -/* Next is all token values, in a form suitable for use by makeheaders. -** This section will be null unless lemon is run with the -m switch. -*/ -/* Make sure the INTERFACE macro is defined. -*/ -#ifndef INTERFACE -# define INTERFACE 1 -#endif -/* The next thing included is series of defines which control -** various aspects of the generated parser. -** YYCODETYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 terminals -** and nonterminals. "int" is used otherwise. -** YYNOCODE is a number of type YYCODETYPE which corresponds -** to no legal terminal or nonterminal number. This -** number is used to fill in empty slots of the hash -** table. -** YYFALLBACK If defined, this indicates that one or more tokens -** have fall-back values which should be used if the -** original value of the token will not parse. -** YYACTIONTYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 rules and -** states combined. "int" is used otherwise. -** phql_TOKENTYPE is the data type used for minor tokens given -** directly to the parser from the tokenizer. -** YYMINORTYPE is the data type used for all minor tokens. -** This is typically a union of many types, one of -** which is phql_TOKENTYPE. The entry in the union -** for base tokens is called "yy0". -** YYSTACKDEPTH is the maximum depth of the parser's stack. -** phql_ARG_SDECL A static variable declaration for the %extra_argument -** phql_ARG_PDECL A parameter declaration for the %extra_argument -** phql_ARG_STORE Code to store %extra_argument into yypParser -** phql_ARG_FETCH Code to extract %extra_argument from yypParser -** YYNSTATE the combined number of states. -** YYNRULE the number of rules in the grammar -** YYERRORSYMBOL is the code number of the error symbol. If not -** defined, then do no error processing. -*/ -#define YYCODETYPE unsigned char -#define YYNOCODE 114 -#define YYACTIONTYPE unsigned short int -#define phql_TOKENTYPE phql_parser_token* -typedef union { - phql_TOKENTYPE yy0; - zval* yy132; - int yy227; -} YYMINORTYPE; -#define YYSTACKDEPTH 100 -#define phql_ARG_SDECL phql_parser_status *status; -#define phql_ARG_PDECL ,phql_parser_status *status -#define phql_ARG_FETCH phql_parser_status *status = yypParser->status -#define phql_ARG_STORE yypParser->status = status -#define YYNSTATE 263 -#define YYNRULE 154 -#define YYERRORSYMBOL 69 -#define YYERRSYMDT yy227 -#define YY_NO_ACTION (YYNSTATE+YYNRULE+2) -#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) -#define YY_ERROR_ACTION (YYNSTATE+YYNRULE) + zval *message, *type; -/* Next are that tables used to determine what action to take based on the -** current state and lookahead token. These tables are used to implement -** functions that take a state number and lookahead value and return an -** action integer. -** -** Suppose the action integer is N. Then the action is determined as -** follows -** -** 0 <= N < YYNSTATE Shift N. That is, push the lookahead -** token onto the stack and goto state N. -** -** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE. -** -** N == YYNSTATE+YYNRULE A syntax error has occurred. -** -** N == YYNSTATE+YYNRULE+1 The parser accepts its input. -** -** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused -** slots in the yy_action[] table. -** -** The action table is constructed as a single large table named yy_action[]. -** Given state S and lookahead X, the action is computed as -** -** yy_action[ yy_shift_ofst[S] + X ] -** -** If the index value yy_shift_ofst[S]+X is out of range or if the value -** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] -** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table -** and that yy_default[S] should be used instead. -** -** The formula above is for computing the action when the lookahead is -** a terminal symbol. If the lookahead is a non-terminal (as occurs after -** a reduce action) then the yy_reduce_ofst[] array is used in place of -** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of -** YY_SHIFT_USE_DFLT. -** -** The following are the tables generated in this section: -** -** yy_action[] A single table containing all actions. -** yy_lookahead[] A table containing the lookahead for each entry in -** yy_action. Used to detect hash collisions. -** yy_shift_ofst[] For each state, the offset into yy_action for -** shifting terminals. -** yy_reduce_ofst[] For each state, the offset into yy_action for -** shifting non-terminals after a reduce. -** yy_default[] Default action for each state. -*/ -static YYACTIONTYPE yy_action[] = { - /* 0 */ 72, 78, 50, 52, 54, 56, 58, 60, 40, 42, - /* 10 */ 62, 67, 44, 46, 48, 36, 34, 38, 32, 29, - /* 20 */ 74, 69, 69, 64, 64, 72, 78, 50, 52, 54, - /* 30 */ 56, 58, 60, 40, 42, 62, 67, 44, 46, 48, - /* 40 */ 36, 34, 38, 32, 29, 74, 69, 263, 64, 18, - /* 50 */ 27, 28, 20, 215, 203, 213, 201, 72, 78, 50, - /* 60 */ 52, 54, 56, 58, 60, 40, 42, 62, 67, 44, - /* 70 */ 46, 48, 36, 34, 38, 32, 29, 74, 69, 264, - /* 80 */ 64, 32, 29, 74, 69, 155, 64, 83, 157, 72, - /* 90 */ 78, 50, 52, 54, 56, 58, 60, 40, 42, 62, - /* 100 */ 67, 44, 46, 48, 36, 34, 38, 32, 29, 74, - /* 110 */ 69, 265, 64, 240, 72, 78, 50, 52, 54, 56, - /* 120 */ 58, 60, 40, 42, 62, 67, 44, 46, 48, 36, - /* 130 */ 34, 38, 32, 29, 74, 69, 244, 64, 44, 46, - /* 140 */ 48, 36, 34, 38, 32, 29, 74, 69, 89, 64, - /* 150 */ 36, 34, 38, 32, 29, 74, 69, 108, 64, 72, - /* 160 */ 78, 50, 52, 54, 56, 58, 60, 40, 42, 62, - /* 170 */ 67, 44, 46, 48, 36, 34, 38, 32, 29, 74, - /* 180 */ 69, 266, 64, 50, 52, 54, 56, 58, 60, 40, - /* 190 */ 42, 62, 67, 44, 46, 48, 36, 34, 38, 32, - /* 200 */ 29, 74, 69, 99, 64, 136, 30, 17, 138, 100, - /* 210 */ 102, 104, 198, 65, 128, 93, 181, 182, 184, 186, - /* 220 */ 99, 190, 194, 30, 130, 267, 100, 102, 104, 106, - /* 230 */ 118, 257, 93, 181, 182, 184, 186, 9, 190, 194, - /* 240 */ 8, 16, 110, 141, 80, 86, 106, 113, 111, 112, - /* 250 */ 114, 115, 116, 117, 259, 26, 7, 149, 151, 110, - /* 260 */ 159, 80, 86, 277, 113, 111, 112, 114, 115, 116, - /* 270 */ 117, 208, 109, 162, 30, 23, 135, 100, 102, 104, - /* 280 */ 92, 71, 152, 209, 154, 158, 30, 217, 97, 100, - /* 290 */ 102, 104, 245, 270, 260, 93, 166, 106, 109, 170, - /* 300 */ 204, 168, 169, 361, 96, 126, 92, 119, 11, 106, - /* 310 */ 110, 179, 80, 86, 13, 113, 111, 112, 114, 115, - /* 320 */ 116, 117, 110, 15, 80, 86, 268, 113, 111, 112, - /* 330 */ 114, 115, 116, 117, 40, 42, 62, 67, 44, 46, - /* 340 */ 48, 36, 34, 38, 32, 29, 74, 69, 10, 64, - /* 350 */ 62, 67, 44, 46, 48, 36, 34, 38, 32, 29, - /* 360 */ 74, 69, 76, 64, 362, 71, 418, 1, 2, 3, - /* 370 */ 4, 5, 6, 19, 160, 21, 167, 168, 169, 142, - /* 380 */ 269, 10, 109, 285, 199, 71, 207, 212, 200, 95, - /* 390 */ 92, 119, 271, 164, 206, 239, 147, 226, 22, 75, - /* 400 */ 179, 256, 109, 163, 109, 222, 216, 212, 227, 132, - /* 410 */ 92, 119, 92, 109, 109, 286, 272, 226, 144, 148, - /* 420 */ 226, 92, 92, 26, 109, 233, 71, 229, 227, 21, - /* 430 */ 238, 225, 92, 142, 109, 10, 147, 109, 254, 360, - /* 440 */ 109, 21, 92, 109, 25, 92, 139, 10, 92, 124, - /* 450 */ 97, 92, 98, 109, 165, 109, 253, 279, 205, 146, - /* 460 */ 24, 92, 200, 92, 21, 21, 127, 12, 134, 139, - /* 470 */ 10, 10, 31, 33, 179, 74, 69, 35, 64, 124, - /* 480 */ 171, 175, 37, 39, 41, 109, 70, 120, 43, 109, - /* 490 */ 109, 275, 94, 92, 109, 45, 14, 92, 92, 109, - /* 500 */ 109, 109, 92, 64, 47, 109, 49, 92, 92, 92, - /* 510 */ 51, 53, 109, 92, 246, 55, 57, 120, 200, 77, - /* 520 */ 92, 109, 59, 109, 81, 211, 61, 109, 109, 92, - /* 530 */ 179, 92, 109, 109, 84, 92, 92, 125, 63, 109, - /* 540 */ 92, 92, 66, 109, 97, 68, 10, 92, 73, 79, - /* 550 */ 87, 92, 82, 288, 88, 109, 220, 228, 101, 109, - /* 560 */ 133, 103, 109, 92, 105, 109, 109, 92, 330, 109, - /* 570 */ 92, 109, 210, 92, 92, 109, 107, 92, 109, 92, - /* 580 */ 129, 109, 140, 92, 339, 94, 92, 161, 178, 92, - /* 590 */ 176, 273, 174, 109, 248, 255, 251, 109, 173, 109, - /* 600 */ 280, 92, 21, 281, 109, 92, 282, 92, 10, 109, - /* 610 */ 120, 262, 92, 224, 187, 200, 160, 92, 188, 219, - /* 620 */ 191, 195, 235, 242, 192, 196, 224, 179, 331, 223, - /* 630 */ 340, 179, 160, 250, 251, 122, 85, 90, 230, 242, - /* 640 */ 91, 121, 234, 123, 125, 131, 10, 137, 274, 278, - /* 650 */ 276, 143, 145, 150, 283, 10, 153, 284, 10, 156, - /* 660 */ 290, 10, 289, 287, 291, 180, 173, 172, 177, 312, - /* 670 */ 183, 313, 314, 185, 315, 316, 189, 221, 218, 193, - /* 680 */ 317, 318, 319, 242, 322, 242, 323, 197, 320, 333, - /* 690 */ 202, 236, 363, 332, 214, 237, 342, 241, 231, 249, - /* 700 */ 341, 232, 252, 261, 258, 269, 269, 269, 269, 269, - /* 710 */ 269, 269, 269, 269, 247, 269, 269, 269, 269, 269, - /* 720 */ 269, 269, 269, 243, -}; -static YYCODETYPE yy_lookahead[] = { - /* 0 */ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - /* 10 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - /* 20 */ 21, 22, 22, 24, 24, 1, 2, 3, 4, 5, - /* 30 */ 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - /* 40 */ 16, 17, 18, 19, 20, 21, 22, 0, 24, 78, - /* 50 */ 51, 52, 81, 29, 29, 31, 31, 1, 2, 3, - /* 60 */ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - /* 70 */ 14, 15, 16, 17, 18, 19, 20, 21, 22, 0, - /* 80 */ 24, 19, 20, 21, 22, 78, 24, 31, 81, 1, - /* 90 */ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, - /* 100 */ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, - /* 110 */ 22, 0, 24, 77, 1, 2, 3, 4, 5, 6, - /* 120 */ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - /* 130 */ 17, 18, 19, 20, 21, 22, 100, 24, 13, 14, - /* 140 */ 15, 16, 17, 18, 19, 20, 21, 22, 60, 24, - /* 150 */ 16, 17, 18, 19, 20, 21, 22, 44, 24, 1, - /* 160 */ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, - /* 170 */ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, - /* 180 */ 22, 0, 24, 3, 4, 5, 6, 7, 8, 9, - /* 190 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - /* 200 */ 20, 21, 22, 17, 24, 78, 20, 80, 81, 23, - /* 210 */ 24, 25, 28, 11, 12, 29, 32, 33, 34, 35, - /* 220 */ 17, 37, 38, 20, 22, 0, 23, 24, 25, 43, - /* 230 */ 44, 77, 29, 32, 33, 34, 35, 81, 37, 38, - /* 240 */ 78, 79, 56, 81, 58, 59, 43, 61, 62, 63, - /* 250 */ 64, 65, 66, 67, 100, 86, 77, 78, 79, 56, - /* 260 */ 81, 58, 59, 0, 61, 62, 63, 64, 65, 66, - /* 270 */ 67, 17, 103, 26, 20, 106, 107, 23, 24, 25, - /* 280 */ 111, 86, 78, 29, 80, 81, 20, 40, 28, 23, - /* 290 */ 24, 25, 45, 0, 47, 29, 84, 43, 103, 91, - /* 300 */ 88, 89, 90, 0, 44, 110, 111, 112, 56, 43, - /* 310 */ 56, 103, 58, 59, 56, 61, 62, 63, 64, 65, - /* 320 */ 66, 67, 56, 56, 58, 59, 0, 61, 62, 63, - /* 330 */ 64, 65, 66, 67, 9, 10, 11, 12, 13, 14, - /* 340 */ 15, 16, 17, 18, 19, 20, 21, 22, 55, 24, - /* 350 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - /* 360 */ 21, 22, 24, 24, 0, 86, 70, 71, 72, 73, - /* 370 */ 74, 75, 76, 81, 48, 49, 88, 89, 90, 53, - /* 380 */ 0, 55, 103, 0, 87, 86, 85, 86, 91, 110, - /* 390 */ 111, 112, 0, 27, 28, 99, 86, 86, 50, 61, - /* 400 */ 103, 105, 103, 82, 103, 94, 85, 86, 97, 110, - /* 410 */ 111, 112, 111, 103, 103, 0, 0, 86, 108, 109, - /* 420 */ 86, 111, 111, 86, 103, 94, 86, 95, 97, 49, - /* 430 */ 98, 97, 111, 53, 103, 55, 86, 103, 86, 0, - /* 440 */ 103, 49, 111, 103, 107, 111, 54, 55, 111, 30, - /* 450 */ 28, 111, 112, 103, 83, 103, 104, 0, 87, 109, - /* 460 */ 28, 111, 91, 111, 49, 49, 44, 28, 86, 54, - /* 470 */ 55, 55, 86, 86, 103, 21, 22, 86, 24, 30, - /* 480 */ 92, 93, 86, 86, 86, 103, 43, 68, 86, 103, - /* 490 */ 103, 0, 43, 111, 103, 86, 57, 111, 111, 103, - /* 500 */ 103, 103, 111, 24, 86, 103, 86, 111, 111, 111, - /* 510 */ 86, 86, 103, 111, 87, 86, 86, 68, 91, 61, - /* 520 */ 111, 103, 86, 103, 43, 17, 86, 103, 103, 111, - /* 530 */ 103, 111, 103, 103, 29, 111, 111, 29, 86, 103, - /* 540 */ 111, 111, 86, 103, 28, 86, 55, 111, 86, 86, - /* 550 */ 43, 111, 86, 0, 86, 103, 42, 43, 86, 103, - /* 560 */ 44, 86, 103, 111, 86, 103, 103, 111, 0, 103, - /* 570 */ 111, 103, 30, 111, 111, 103, 86, 111, 103, 111, - /* 580 */ 86, 103, 86, 111, 0, 43, 111, 86, 29, 111, - /* 590 */ 31, 0, 86, 103, 101, 102, 103, 103, 39, 103, - /* 600 */ 0, 111, 49, 0, 103, 111, 0, 111, 55, 103, - /* 610 */ 68, 87, 111, 28, 32, 91, 48, 111, 36, 91, - /* 620 */ 32, 32, 28, 55, 36, 36, 28, 103, 0, 44, - /* 630 */ 0, 103, 48, 102, 103, 30, 44, 29, 44, 55, - /* 640 */ 44, 29, 44, 29, 29, 43, 55, 81, 0, 0, - /* 650 */ 0, 50, 28, 81, 0, 55, 81, 0, 55, 81, - /* 660 */ 0, 55, 0, 0, 0, 29, 39, 93, 29, 29, - /* 670 */ 32, 29, 29, 32, 29, 29, 32, 43, 41, 32, - /* 680 */ 29, 29, 29, 55, 0, 55, 0, 32, 29, 0, - /* 690 */ 29, 98, 0, 0, 29, 29, 0, 100, 42, 28, - /* 700 */ 0, 43, 3, 27, 100, 113, 113, 113, 113, 113, - /* 710 */ 113, 113, 113, 113, 46, 113, 113, 113, 113, 113, - /* 720 */ 113, 113, 113, 56, -}; -#define YY_SHIFT_USE_DFLT (-2) -static short yy_shift_ofst[] = { - /* 0 */ 247, 47, 79, 111, 181, 225, 326, 380, 293, 263, - /* 10 */ 252, 439, 258, 303, 267, 364, 392, 416, 491, 383, - /* 20 */ 457, 348, 266, 432, 266, -2, -1, -2, -2, 266, - /* 30 */ 266, 454, 266, 454, 266, 62, 266, 62, 266, 62, - /* 40 */ 266, 339, 266, 339, 266, 134, 266, 134, 266, 134, - /* 50 */ 266, 325, 266, 325, 266, 325, 266, 325, 266, 325, - /* 60 */ 266, 325, 266, 125, 202, 266, 479, 266, 125, 443, - /* 70 */ 203, 158, 266, 158, 338, -2, 458, -2, 266, 180, - /* 80 */ 481, 266, 56, 505, 592, -2, 507, 266, 88, 608, - /* 90 */ 596, -2, -2, 449, 186, 260, -2, 203, -2, -2, - /* 100 */ 266, 0, 266, 479, 266, 479, 266, 113, -2, -2, - /* 110 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - /* 120 */ 612, 605, 614, -2, 615, -2, 422, -2, 266, 479, - /* 130 */ 602, 203, 516, -2, 454, -2, 591, 648, 649, 266, - /* 140 */ 158, 650, 601, 266, 624, 266, -2, 158, -2, 600, - /* 150 */ 654, 415, 603, 657, 553, 606, 660, 662, 663, 664, - /* 160 */ 266, 158, 254, 366, 636, 184, 201, -2, -2, 636, - /* 170 */ 559, 627, -2, 266, 158, -2, 639, -2, -2, -2, - /* 180 */ 419, 640, 638, 642, 641, 643, 582, 645, 644, 646, - /* 190 */ 588, 651, 647, 652, 589, 653, 655, 659, 636, -2, - /* 200 */ 25, 661, -2, -2, -2, -2, 254, -2, -2, 542, - /* 210 */ 508, -2, 24, 665, -2, -2, -2, 637, 636, 514, - /* 220 */ 634, 266, 585, 684, 266, -2, 158, -2, 666, 594, - /* 230 */ 656, 658, 266, 598, 686, 666, -2, -2, -2, 568, - /* 240 */ 628, 689, 667, 692, 693, 636, 668, 636, 671, 636, - /* 250 */ -2, 699, 266, -2, 158, -2, 584, 630, 696, 700, - /* 260 */ 676, 636, -2, -}; -#define YY_REDUCE_USE_DFLT (-30) -static short yy_reduce_ofst[] = { - /* 0 */ 296, -30, -30, -30, -30, -30, 179, 162, 156, -30, - /* 10 */ -30, -30, -30, -30, -30, -30, 127, -29, 292, -30, - /* 20 */ -30, -30, 169, -30, 337, -30, -30, -30, -30, 382, - /* 30 */ 386, -30, 387, -30, 391, -30, 396, -30, 397, -30, - /* 40 */ 398, -30, 402, -30, 409, -30, 418, -30, 420, -30, - /* 50 */ 424, -30, 425, -30, 429, -30, 430, -30, 436, -30, - /* 60 */ 440, -30, 452, -30, -30, 456, -30, 459, -30, -30, - /* 70 */ 195, -30, 462, -30, -30, -30, -30, -30, 463, -30, - /* 80 */ -30, 466, -30, -30, -30, -30, -30, 468, -30, -30, - /* 90 */ -30, -30, -30, -30, 279, -30, -30, 340, -30, -30, - /* 100 */ 472, -30, 475, -30, 478, -30, 490, -30, -30, -30, - /* 110 */ -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, - /* 120 */ -30, -30, -30, -30, -30, -30, -30, -30, 494, -30, - /* 130 */ -30, 299, -30, -30, -30, -30, 566, -30, -30, 496, - /* 140 */ -30, -30, -30, 310, -30, 350, -30, -30, -30, 572, - /* 150 */ -30, 204, 575, -30, 7, 578, -30, -30, -30, -30, - /* 160 */ 501, -30, 321, -30, 371, 212, 288, -30, -30, 208, - /* 170 */ 388, 574, -30, 506, -30, -30, -30, -30, -30, -30, - /* 180 */ -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, - /* 190 */ -30, -30, -30, -30, -30, -30, -30, -30, 297, -30, - /* 200 */ -30, -30, -30, -30, -30, -30, 301, -30, -30, -30, - /* 210 */ -30, -30, -30, -30, -30, -30, -30, -30, 528, -30, - /* 220 */ -30, 311, -30, -30, 334, -30, -30, -30, 332, -30, - /* 230 */ -30, -30, 331, -30, -30, 593, -30, -30, -30, 36, - /* 240 */ 597, -30, -30, -30, -30, 427, -30, 493, -30, 531, - /* 250 */ -30, -30, 352, -30, -30, -30, 154, 604, -30, -30, - /* 260 */ -30, 524, -30, -}; -static YYACTIONTYPE yy_default[] = { - /* 0 */ 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, - /* 10 */ 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, - /* 20 */ 417, 417, 417, 349, 417, 350, 352, 353, 354, 417, - /* 30 */ 417, 364, 417, 366, 417, 367, 417, 368, 417, 369, - /* 40 */ 417, 370, 417, 371, 417, 372, 417, 373, 417, 374, - /* 50 */ 417, 375, 417, 376, 417, 377, 417, 378, 417, 379, - /* 60 */ 417, 380, 417, 381, 417, 417, 382, 417, 383, 417, - /* 70 */ 417, 396, 417, 387, 417, 397, 417, 398, 417, 400, - /* 80 */ 417, 417, 417, 417, 417, 388, 417, 417, 417, 417, - /* 90 */ 417, 389, 390, 416, 417, 417, 391, 417, 393, 395, - /* 100 */ 417, 399, 417, 401, 417, 402, 417, 417, 403, 404, - /* 110 */ 405, 406, 407, 408, 409, 410, 411, 412, 392, 394, - /* 120 */ 417, 414, 417, 413, 417, 415, 417, 385, 417, 384, - /* 130 */ 417, 417, 417, 386, 365, 351, 417, 417, 417, 417, - /* 140 */ 359, 417, 417, 417, 355, 417, 356, 358, 357, 417, - /* 150 */ 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, - /* 160 */ 417, 348, 417, 417, 417, 292, 293, 303, 305, 417, - /* 170 */ 306, 307, 309, 417, 321, 308, 417, 310, 311, 347, - /* 180 */ 416, 417, 417, 417, 417, 417, 417, 417, 417, 417, - /* 190 */ 417, 417, 417, 417, 417, 417, 417, 417, 417, 301, - /* 200 */ 346, 417, 344, 345, 304, 302, 417, 294, 296, 416, - /* 210 */ 417, 297, 300, 417, 298, 299, 295, 417, 417, 417, - /* 220 */ 417, 417, 417, 417, 417, 324, 326, 325, 417, 417, - /* 230 */ 417, 417, 417, 417, 417, 417, 327, 329, 328, 417, - /* 240 */ 417, 417, 417, 417, 417, 417, 417, 417, 334, 417, - /* 250 */ 335, 417, 417, 337, 338, 336, 417, 417, 417, 417, - /* 260 */ 417, 417, 343, -}; -#define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0])) + PHALCON_MM_GROW(); -/* The next table maps tokens into fallback tokens. If a construct -** like the following: -** -** %fallback ID X Y Z. -** -** appears in the grammer, then ID becomes a fallback token for X, Y, -** and Z. Whenever one of the tokens X, Y, or Z is input to the parser -** but it does not parse, the type of the token is changed to ID and -** the parse is retried before an error is thrown. -*/ -#ifdef YYFALLBACK -static const YYCODETYPE yyFallback[] = { -}; -#endif /* YYFALLBACK */ + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("EMERGENCE") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + RETURN_THIS(); +} -/* The following structure represents a single element of the -** parser's stack. Information stored includes: -** -** + The state number for the parser at this level of the stack. -** -** + The value of the token stored at this level of the stack. -** (In other words, the "major" token.) -** -** + The semantic value stored at this level of the stack. This is -** the information used by the action routines in the grammar. -** It is sometimes called the "minor" token. -*/ -struct yyStackEntry { - int stateno; /* The state-number */ - int major; /* The major token value. This is the code - ** number for the token at this stack level */ - YYMINORTYPE minor; /* The user-supplied minor token value. This - ** is the value of the token */ -}; -typedef struct yyStackEntry yyStackEntry; +static PHP_METHOD(Phalcon_Logger_Adapter, debug){ -/* The state of the parser is completely contained in an instance of -** the following structure */ -struct yyParser { - int yyidx; /* Index of top element in stack */ - int yyerrcnt; /* Shifts left before out of the error */ - phql_ARG_SDECL /* A place to hold %extra_argument */ - yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ -}; -typedef struct yyParser yyParser; + zval *message, *type; -#ifndef NDEBUG -#include -static FILE *yyTraceFILE = 0; -static char *yyTracePrompt = 0; -#endif /* NDEBUG */ + PHALCON_MM_GROW(); -#ifndef NDEBUG -static void phql_Trace(FILE *TraceFILE, char *zTracePrompt){ - yyTraceFILE = TraceFILE; - yyTracePrompt = zTracePrompt; - if( yyTraceFILE==0 ) yyTracePrompt = 0; - else if( yyTracePrompt==0 ) yyTraceFILE = 0; + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("DEBUG") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + RETURN_THIS(); } -#endif /* NDEBUG */ -#ifndef NDEBUG -/* For tracing shifts, the names of all terminals and nonterminals -** are required. The following table supplies these names */ -static const char *yyTokenName[] = { - "$", "AGAINST", "BETWEEN", "EQUALS", - "NOTEQUALS", "LESS", "GREATER", "GREATEREQUAL", - "LESSEQUAL", "AND", "OR", "LIKE", - "ILIKE", "BITWISE_AND", "BITWISE_OR", "BITWISE_XOR", - "DIVIDE", "TIMES", "MOD", "PLUS", - "MINUS", "IS", "IN", "DISTINCT", - "NOT", "BITWISE_NOT", "SELECT", "FROM", - "COMMA", "IDENTIFIER", "DOT", "AS", - "JOIN", "INNER", "CROSS", "LEFT", - "OUTER", "RIGHT", "FULL", "ON", - "INSERT", "INTO", "VALUES", "PARENTHESES_OPEN", - "PARENTHESES_CLOSE", "UPDATE", "SET", "DELETE", - "WHERE", "ORDER", "BY", "ASC", - "DESC", "GROUP", "HAVING", "LIMIT", - "INTEGER", "OFFSET", "CAST", "CONVERT", - "USING", "NULL", "STRING", "DOUBLE", - "TRUE", "FALSE", "NPLACEHOLDER", "SPLACEHOLDER", - "COLON", "error", "program", "query_language", - "select_statement", "insert_statement", "update_statement", "delete_statement", - "select_clause", "where_clause", "order_clause", "group_clause", - "having_clause", "select_limit_clause", "column_list", "associated_name_list", - "join_list", "column_item", "expr", "associated_name", - "join_item", "join_clause", "join_type", "aliased_or_qualified_name", - "join_associated_name", "join_conditions", "values_list", "field_list", - "value_list", "value_item", "field_item", "update_clause", - "limit_clause", "update_item_list", "update_item", "qualified_name", - "new_value", "delete_clause", "order_list", "order_item", - "group_list", "group_item", "argument_list", "function_call", - "argument_item", -}; -#endif /* NDEBUG */ +static PHP_METHOD(Phalcon_Logger_Adapter, error){ -#ifndef NDEBUG -/* For tracing reduce actions, the names of all rules are required. -*/ -static const char *yyRuleName[] = { - /* 0 */ "program ::= query_language", - /* 1 */ "query_language ::= select_statement", - /* 2 */ "query_language ::= insert_statement", - /* 3 */ "query_language ::= update_statement", - /* 4 */ "query_language ::= delete_statement", - /* 5 */ "select_statement ::= select_clause", - /* 6 */ "select_statement ::= select_clause where_clause", - /* 7 */ "select_statement ::= select_clause where_clause order_clause", - /* 8 */ "select_statement ::= select_clause where_clause group_clause", - /* 9 */ "select_statement ::= select_clause where_clause group_clause having_clause", - /* 10 */ "select_statement ::= select_clause where_clause group_clause order_clause", - /* 11 */ "select_statement ::= select_clause where_clause group_clause order_clause select_limit_clause", - /* 12 */ "select_statement ::= select_clause where_clause group_clause having_clause order_clause", - /* 13 */ "select_statement ::= select_clause where_clause select_limit_clause", - /* 14 */ "select_statement ::= select_clause where_clause order_clause select_limit_clause", - /* 15 */ "select_statement ::= select_clause where_clause group_clause select_limit_clause", - /* 16 */ "select_statement ::= select_clause where_clause group_clause having_clause select_limit_clause", - /* 17 */ "select_statement ::= select_clause order_clause", - /* 18 */ "select_statement ::= select_clause group_clause order_clause", - /* 19 */ "select_statement ::= select_clause group_clause having_clause order_clause", - /* 20 */ "select_statement ::= select_clause order_clause select_limit_clause", - /* 21 */ "select_statement ::= select_clause group_clause order_clause select_limit_clause", - /* 22 */ "select_statement ::= select_clause where_clause group_clause having_clause order_clause select_limit_clause", - /* 23 */ "select_statement ::= select_clause group_clause", - /* 24 */ "select_statement ::= select_clause group_clause select_limit_clause", - /* 25 */ "select_statement ::= select_clause group_clause having_clause", - /* 26 */ "select_statement ::= select_clause group_clause having_clause select_limit_clause", - /* 27 */ "select_statement ::= select_clause group_clause having_clause order_clause select_limit_clause", - /* 28 */ "select_statement ::= select_clause select_limit_clause", - /* 29 */ "select_clause ::= SELECT column_list FROM associated_name_list", - /* 30 */ "select_clause ::= SELECT column_list FROM associated_name_list join_list", - /* 31 */ "column_list ::= column_list COMMA column_item", - /* 32 */ "column_list ::= column_item", - /* 33 */ "column_item ::= TIMES", - /* 34 */ "column_item ::= IDENTIFIER DOT TIMES", - /* 35 */ "column_item ::= expr AS IDENTIFIER", - /* 36 */ "column_item ::= expr IDENTIFIER", - /* 37 */ "column_item ::= expr", - /* 38 */ "associated_name_list ::= associated_name_list COMMA associated_name", - /* 39 */ "associated_name_list ::= associated_name", - /* 40 */ "join_list ::= join_list join_item", - /* 41 */ "join_list ::= join_item", - /* 42 */ "join_item ::= join_clause", - /* 43 */ "join_clause ::= join_type aliased_or_qualified_name", - /* 44 */ "join_clause ::= join_type aliased_or_qualified_name join_associated_name", - /* 45 */ "join_clause ::= join_type aliased_or_qualified_name join_conditions", - /* 46 */ "join_clause ::= join_type aliased_or_qualified_name join_associated_name join_conditions", - /* 47 */ "join_associated_name ::= AS IDENTIFIER", - /* 48 */ "join_associated_name ::= IDENTIFIER", - /* 49 */ "join_type ::= JOIN", - /* 50 */ "join_type ::= INNER JOIN", - /* 51 */ "join_type ::= CROSS JOIN", - /* 52 */ "join_type ::= LEFT JOIN", - /* 53 */ "join_type ::= LEFT OUTER JOIN", - /* 54 */ "join_type ::= RIGHT JOIN", - /* 55 */ "join_type ::= RIGHT OUTER JOIN", - /* 56 */ "join_type ::= FULL JOIN", - /* 57 */ "join_type ::= FULL OUTER JOIN", - /* 58 */ "join_conditions ::= ON expr", - /* 59 */ "insert_statement ::= INSERT INTO aliased_or_qualified_name VALUES PARENTHESES_OPEN values_list PARENTHESES_CLOSE", - /* 60 */ "insert_statement ::= INSERT INTO aliased_or_qualified_name PARENTHESES_OPEN field_list PARENTHESES_CLOSE VALUES PARENTHESES_OPEN values_list PARENTHESES_CLOSE", - /* 61 */ "values_list ::= values_list COMMA value_item", - /* 62 */ "values_list ::= value_item", - /* 63 */ "value_item ::= expr", - /* 64 */ "field_list ::= field_list COMMA field_item", - /* 65 */ "field_list ::= field_item", - /* 66 */ "field_item ::= IDENTIFIER", - /* 67 */ "update_statement ::= update_clause", - /* 68 */ "update_statement ::= update_clause where_clause", - /* 69 */ "update_statement ::= update_clause limit_clause", - /* 70 */ "update_statement ::= update_clause where_clause limit_clause", - /* 71 */ "update_clause ::= UPDATE associated_name SET update_item_list", - /* 72 */ "update_item_list ::= update_item_list COMMA update_item", - /* 73 */ "update_item_list ::= update_item", - /* 74 */ "update_item ::= qualified_name EQUALS new_value", - /* 75 */ "new_value ::= expr", - /* 76 */ "delete_statement ::= delete_clause", - /* 77 */ "delete_statement ::= delete_clause where_clause", - /* 78 */ "delete_statement ::= delete_clause limit_clause", - /* 79 */ "delete_statement ::= delete_clause where_clause limit_clause", - /* 80 */ "delete_clause ::= DELETE FROM associated_name", - /* 81 */ "associated_name ::= aliased_or_qualified_name AS IDENTIFIER", - /* 82 */ "associated_name ::= aliased_or_qualified_name IDENTIFIER", - /* 83 */ "associated_name ::= aliased_or_qualified_name", - /* 84 */ "aliased_or_qualified_name ::= qualified_name", - /* 85 */ "where_clause ::= WHERE expr", - /* 86 */ "order_clause ::= ORDER BY order_list", - /* 87 */ "order_list ::= order_list COMMA order_item", - /* 88 */ "order_list ::= order_item", - /* 89 */ "order_item ::= expr", - /* 90 */ "order_item ::= expr ASC", - /* 91 */ "order_item ::= expr DESC", - /* 92 */ "group_clause ::= GROUP BY group_list", - /* 93 */ "group_list ::= group_list COMMA group_item", - /* 94 */ "group_list ::= group_item", - /* 95 */ "group_item ::= expr", - /* 96 */ "having_clause ::= HAVING expr", - /* 97 */ "select_limit_clause ::= LIMIT INTEGER", - /* 98 */ "select_limit_clause ::= LIMIT INTEGER COMMA INTEGER", - /* 99 */ "select_limit_clause ::= LIMIT INTEGER OFFSET INTEGER", - /* 100 */ "limit_clause ::= LIMIT INTEGER", - /* 101 */ "expr ::= MINUS expr", - /* 102 */ "expr ::= expr MINUS expr", - /* 103 */ "expr ::= expr PLUS expr", - /* 104 */ "expr ::= expr TIMES expr", - /* 105 */ "expr ::= expr DIVIDE expr", - /* 106 */ "expr ::= expr MOD expr", - /* 107 */ "expr ::= expr AND expr", - /* 108 */ "expr ::= expr OR expr", - /* 109 */ "expr ::= expr BITWISE_AND expr", - /* 110 */ "expr ::= expr BITWISE_OR expr", - /* 111 */ "expr ::= expr BITWISE_XOR expr", - /* 112 */ "expr ::= expr EQUALS expr", - /* 113 */ "expr ::= expr NOTEQUALS expr", - /* 114 */ "expr ::= expr LESS expr", - /* 115 */ "expr ::= expr GREATER expr", - /* 116 */ "expr ::= expr GREATEREQUAL expr", - /* 117 */ "expr ::= expr LESSEQUAL expr", - /* 118 */ "expr ::= expr LIKE expr", - /* 119 */ "expr ::= expr NOT LIKE expr", - /* 120 */ "expr ::= expr ILIKE expr", - /* 121 */ "expr ::= expr NOT ILIKE expr", - /* 122 */ "expr ::= expr IN PARENTHESES_OPEN argument_list PARENTHESES_CLOSE", - /* 123 */ "expr ::= expr NOT IN PARENTHESES_OPEN argument_list PARENTHESES_CLOSE", - /* 124 */ "expr ::= expr AGAINST expr", - /* 125 */ "expr ::= CAST PARENTHESES_OPEN expr AS IDENTIFIER PARENTHESES_CLOSE", - /* 126 */ "expr ::= CONVERT PARENTHESES_OPEN expr USING IDENTIFIER PARENTHESES_CLOSE", - /* 127 */ "expr ::= function_call", - /* 128 */ "function_call ::= IDENTIFIER PARENTHESES_OPEN argument_list PARENTHESES_CLOSE", - /* 129 */ "function_call ::= IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE", - /* 130 */ "argument_list ::= argument_list COMMA argument_item", - /* 131 */ "argument_list ::= argument_item", - /* 132 */ "argument_item ::= TIMES", - /* 133 */ "argument_item ::= expr", - /* 134 */ "expr ::= expr IS NULL", - /* 135 */ "expr ::= expr IS NOT NULL", - /* 136 */ "expr ::= DISTINCT expr", - /* 137 */ "expr ::= expr BETWEEN expr", - /* 138 */ "expr ::= NOT expr", - /* 139 */ "expr ::= BITWISE_NOT expr", - /* 140 */ "expr ::= PARENTHESES_OPEN expr PARENTHESES_CLOSE", - /* 141 */ "expr ::= qualified_name", - /* 142 */ "expr ::= INTEGER", - /* 143 */ "expr ::= STRING", - /* 144 */ "expr ::= DOUBLE", - /* 145 */ "expr ::= NULL", - /* 146 */ "expr ::= TRUE", - /* 147 */ "expr ::= FALSE", - /* 148 */ "expr ::= NPLACEHOLDER", - /* 149 */ "expr ::= SPLACEHOLDER", - /* 150 */ "qualified_name ::= IDENTIFIER COLON IDENTIFIER DOT IDENTIFIER", - /* 151 */ "qualified_name ::= IDENTIFIER COLON IDENTIFIER", - /* 152 */ "qualified_name ::= IDENTIFIER DOT IDENTIFIER", - /* 153 */ "qualified_name ::= IDENTIFIER", -}; -#endif /* NDEBUG */ + zval *message, *type; -const char *phql_TokenName(int tokenType){ -#ifndef NDEBUG - if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){ - return yyTokenName[tokenType]; - }else{ - return "Unknown"; - } -#else - return ""; -#endif + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("ERROR") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + RETURN_THIS(); } -void *phql_Alloc(void *(*mallocProc)(size_t)){ - yyParser *pParser; - pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); - if( pParser ){ - pParser->yyidx = -1; - } - return pParser; +static PHP_METHOD(Phalcon_Logger_Adapter, info){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("INFO") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + RETURN_THIS(); } -/* The following function deletes the value associated with a -** symbol. The symbol can be either a terminal or nonterminal. -** "yymajor" is the symbol code, and "yypminor" is a pointer to -** the value. -*/ -static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ - switch( yymajor ){ - /* Here is inserted the actions which take place when a - ** terminal or non-terminal is destroyed. This can happen - ** when the symbol is popped from the stack during a - ** reduce or during error processing or when a parser is - ** being destroyed before it is finished parsing. - ** - ** Note: during a reduce, the only symbols destroyed are those - ** which appear on the RHS of the rule, but which are not used - ** inside the C code. - */ - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - case 18: - case 19: - case 20: - case 21: - case 22: - case 23: - case 24: - case 25: - case 26: - case 27: - case 28: - case 29: - case 30: - case 31: - case 32: - case 33: - case 34: - case 35: - case 36: - case 37: - case 38: - case 39: - case 40: - case 41: - case 42: - case 43: - case 44: - case 45: - case 46: - case 47: - case 48: - case 49: - case 50: - case 51: - case 52: - case 53: - case 54: - case 55: - case 56: - case 57: - case 58: - case 59: - case 60: - case 61: - case 62: - case 63: - case 64: - case 65: - case 66: - case 67: - case 68: -// 513 "parser.lemon" -{ - if ((yypminor->yy0)) { - if ((yypminor->yy0)->free_flag) { - efree((yypminor->yy0)->token); - } - efree((yypminor->yy0)); - } +static PHP_METHOD(Phalcon_Logger_Adapter, notice){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("NOTICE") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + RETURN_THIS(); } -// 1181 "parser.c" - break; - case 71: - case 72: - case 73: - case 74: - case 75: - case 76: - case 77: - case 78: - case 79: - case 80: - case 81: - case 82: - case 83: - case 84: - case 85: - case 86: - case 87: - case 88: - case 89: - case 90: - case 91: - case 92: - case 93: - case 95: - case 96: - case 98: - case 99: - case 100: - case 101: - case 102: - case 103: - case 105: - case 106: - case 107: - case 108: - case 109: - case 110: - case 111: - case 112: -// 526 "parser.lemon" -{ zval_ptr_dtor(&(yypminor->yy132)); } -// 1224 "parser.c" - break; - default: break; /* If no destructor action specified: do nothing */ - } + +static PHP_METHOD(Phalcon_Logger_Adapter, warning){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("WARNING") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + RETURN_THIS(); } -static int yy_pop_parser_stack(yyParser *pParser){ - YYCODETYPE yymajor; - yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; +static PHP_METHOD(Phalcon_Logger_Adapter, alert){ - if( pParser->yyidx<0 ) return 0; -#ifndef NDEBUG - if( yyTraceFILE && pParser->yyidx>=0 ){ - fprintf(yyTraceFILE,"%sPopping %s\n", - yyTracePrompt, - yyTokenName[yytos->major]); - } -#endif - yymajor = yytos->major; - yy_destructor( yymajor, &yytos->minor); - pParser->yyidx--; - return yymajor; + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("ALERT") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + RETURN_THIS(); } -static void phql_Free( - void *p, /* The parser to be deleted */ - void (*freeProc)(void*) /* Function used to reclaim memory */ -){ - yyParser *pParser = (yyParser*)p; - if( pParser==0 ) return; - while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); - (*freeProc)((void*)pParser); +static PHP_METHOD(Phalcon_Logger_Adapter, log){ + + zval *message, *type = NULL, *timestamp, *transaction; + zval *queue_item, *log_level; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &message, &type); + + if (!type) { + PHALCON_INIT_VAR(type); + ZVAL_LONG(type, 7); + } + + PHALCON_INIT_VAR(timestamp); + ZVAL_LONG(timestamp, (long) time(NULL)); + + PHALCON_OBS_VAR(transaction); + phalcon_read_property_this_quick(&transaction, this_ptr, SL("_transaction"), 1141465066UL, PH_NOISY_CC); + if (zend_is_true(transaction)) { + PHALCON_INIT_VAR(queue_item); + object_init_ex(queue_item, phalcon_logger_item_ce); + phalcon_call_method_p3_key(NULL, queue_item, "__construct", message, type, timestamp, 1107214344UL); + + phalcon_update_property_array_append(this_ptr, SL("_queue"), queue_item TSRMLS_CC); + RETURN_THIS(); + } + + PHALCON_OBS_VAR(log_level); + phalcon_read_property_this_quick(&log_level, this_ptr, SL("_logLevel"), 4227944734UL, PH_NOISY_CC); + + if (PHALCON_GE(log_level, type)) { + phalcon_call_method_p3_key(NULL, this_ptr, "loginternal", message, type, timestamp, 2472438692UL); + } + + RETURN_THIS(); } -static int yy_find_shift_action( - yyParser *pParser, /* The parser */ - int iLookAhead /* The look-ahead token */ -){ - int i; - int stateno = pParser->yystack[pParser->yyidx].stateno; - - /* if( pParser->yyidx<0 ) return YY_NO_ACTION; */ - i = yy_shift_ofst[stateno]; - if( i==YY_SHIFT_USE_DFLT ){ - return yy_default[stateno]; - } - if( iLookAhead==YYNOCODE ){ - return YY_NO_ACTION; - } - i += iLookAhead; - if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ -#ifdef YYFALLBACK - int iFallback; /* Fallback token */ - if( iLookAhead %s\n", - yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); - } -#endif - return yy_find_shift_action(pParser, iFallback); - } + + + + +#ifdef HAVE_CONFIG_H #endif - return yy_default[stateno]; - }else{ - return yy_action[i]; - } -} -static int yy_find_reduce_action( - yyParser *pParser, /* The parser */ - int iLookAhead /* The look-ahead token */ -){ - int i; - int stateno = pParser->yystack[pParser->yyidx].stateno; - - i = yy_reduce_ofst[stateno]; - if( i==YY_REDUCE_USE_DFLT ){ - return yy_default[stateno]; - } - if( iLookAhead==YYNOCODE ){ - return YY_NO_ACTION; - } - i += iLookAhead; - if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ - return yy_default[stateno]; - }else{ - return yy_action[i]; - } + + +PHALCON_INIT_CLASS(Phalcon_Logger_AdapterInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Logger, AdapterInterface, logger_adapterinterface, phalcon_logger_adapterinterface_method_entry); + + return SUCCESS; } -static void yy_shift( - yyParser *yypParser, /* The parser to be shifted */ - int yyNewState, /* The new state to shift in */ - int yyMajor, /* The major token to shift in */ - YYMINORTYPE *yypMinor /* Pointer ot the minor token to shift in */ -){ - yyStackEntry *yytos; - yypParser->yyidx++; - if( yypParser->yyidx>=YYSTACKDEPTH ){ - phql_ARG_FETCH; - yypParser->yyidx--; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); - } + + + + + + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H #endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will execute if the parser - ** stack every overflows */ - phql_ARG_STORE; /* Suppress warning about unused %extra_argument var */ - return; - } - yytos = &yypParser->yystack[yypParser->yyidx]; - yytos->stateno = yyNewState; - yytos->major = yyMajor; - yytos->minor = *yypMinor; -#ifndef NDEBUG - if( yyTraceFILE && yypParser->yyidx>0 ){ - int i; - fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState); - fprintf(yyTraceFILE,"%sStack:",yyTracePrompt); - for(i=1; i<=yypParser->yyidx; i++) - fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); - fprintf(yyTraceFILE,"\n"); - } + + + + + + +PHALCON_INIT_CLASS(Phalcon_Logger_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger, Exception, logger_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H #endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Logger_Formatter_Firephp){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Formatter, Firephp, logger_formatter_firephp, "phalcon\\logger\\formatter", phalcon_logger_formatter_firephp_method_entry, 0); + + zend_class_implements(phalcon_logger_formatter_firephp_ce TSRMLS_CC, 1, phalcon_logger_formatterinterface_ce); + + return SUCCESS; } -/* The following table contains information about every rule that -** is used during the reduce. -*/ -static struct { - YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ - unsigned char nrhs; /* Number of right-hand side symbols in the rule */ -} yyRuleInfo[] = { - { 70, 1 }, - { 71, 1 }, - { 71, 1 }, - { 71, 1 }, - { 71, 1 }, - { 72, 1 }, - { 72, 2 }, - { 72, 3 }, - { 72, 3 }, - { 72, 4 }, - { 72, 4 }, - { 72, 5 }, - { 72, 5 }, - { 72, 3 }, - { 72, 4 }, - { 72, 4 }, - { 72, 5 }, - { 72, 2 }, - { 72, 3 }, - { 72, 4 }, - { 72, 3 }, - { 72, 4 }, - { 72, 6 }, - { 72, 2 }, - { 72, 3 }, - { 72, 3 }, - { 72, 4 }, - { 72, 5 }, - { 72, 2 }, - { 76, 4 }, - { 76, 5 }, - { 82, 3 }, - { 82, 1 }, - { 85, 1 }, - { 85, 3 }, - { 85, 3 }, - { 85, 2 }, - { 85, 1 }, - { 83, 3 }, - { 83, 1 }, - { 84, 2 }, - { 84, 1 }, - { 88, 1 }, - { 89, 2 }, - { 89, 3 }, - { 89, 3 }, - { 89, 4 }, - { 92, 2 }, - { 92, 1 }, - { 90, 1 }, - { 90, 2 }, - { 90, 2 }, - { 90, 2 }, - { 90, 3 }, - { 90, 2 }, - { 90, 3 }, - { 90, 2 }, - { 90, 3 }, - { 93, 2 }, - { 73, 7 }, - { 73, 10 }, - { 94, 3 }, - { 94, 1 }, - { 97, 1 }, - { 95, 3 }, - { 95, 1 }, - { 98, 1 }, - { 74, 1 }, - { 74, 2 }, - { 74, 2 }, - { 74, 3 }, - { 99, 4 }, - { 101, 3 }, - { 101, 1 }, - { 102, 3 }, - { 104, 1 }, - { 75, 1 }, - { 75, 2 }, - { 75, 2 }, - { 75, 3 }, - { 105, 3 }, - { 87, 3 }, - { 87, 2 }, - { 87, 1 }, - { 91, 1 }, - { 77, 2 }, - { 78, 3 }, - { 106, 3 }, - { 106, 1 }, - { 107, 1 }, - { 107, 2 }, - { 107, 2 }, - { 79, 3 }, - { 108, 3 }, - { 108, 1 }, - { 109, 1 }, - { 80, 2 }, - { 81, 2 }, - { 81, 4 }, - { 81, 4 }, - { 100, 2 }, - { 86, 2 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 3 }, - { 86, 4 }, - { 86, 3 }, - { 86, 4 }, - { 86, 5 }, - { 86, 6 }, - { 86, 3 }, - { 86, 6 }, - { 86, 6 }, - { 86, 1 }, - { 111, 4 }, - { 111, 3 }, - { 110, 3 }, - { 110, 1 }, - { 112, 1 }, - { 112, 1 }, - { 86, 3 }, - { 86, 4 }, - { 86, 2 }, - { 86, 3 }, - { 86, 2 }, - { 86, 2 }, - { 86, 3 }, - { 86, 1 }, - { 86, 1 }, - { 86, 1 }, - { 86, 1 }, - { 86, 1 }, - { 86, 1 }, - { 86, 1 }, - { 86, 1 }, - { 86, 1 }, - { 103, 5 }, - { 103, 3 }, - { 103, 3 }, - { 103, 1 }, -}; +static PHP_METHOD(Phalcon_Logger_Formatter_Firephp, getTypeString) { -static void yy_accept(yyParser*); /* Forward Declaration */ + static const char* lut[10] = { + "ERROR", "ERROR", "WARN", "ERROR", "WARN", + "INFO", "INFO", "LOG", "INFO", "LOG" + }; -static void yy_reduce( - yyParser *yypParser, /* The parser */ - int yyruleno /* Number of the rule by which to reduce */ -){ - int yygoto; /* The next state */ - int yyact; /* The next action */ - YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ - yyStackEntry *yymsp; /* The top of the parser's stack */ - int yysize; /* Amount to pop the stack */ - phql_ARG_FETCH; - yymsp = &yypParser->yystack[yypParser->yyidx]; -#ifndef NDEBUG - if( yyTraceFILE && yyruleno>=0 - && yyruleno - ** { ... } // User supplied code - ** // - ** break; - */ - case 0: -// 522 "parser.lemon" -{ - status->ret = yymsp[0].minor.yy132; + phalcon_fetch_params(0, 1, 0, &type); + + itype = phalcon_get_intval(type); + if (itype > 0 && itype < 10) { + RETURN_STRING(lut[itype], 1); + } + + RETURN_STRING("CUSTOM", 1); } -// 1595 "parser.c" - break; - case 1: - case 2: - case 3: - case 4: - case 32: - case 39: - case 41: - case 42: - case 62: - case 63: - case 65: - case 73: - case 75: - case 84: - case 88: - case 94: - case 95: - case 127: - case 133: - case 141: -// 528 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; + +static PHP_METHOD(Phalcon_Logger_Formatter_Firephp, format) { + + zval *message, *type, *type_str, *timestamp; + zval *payload, *backtrace, *meta, *encoded; + smart_str result = { NULL, 0, 0 }; + int i; + Bucket *p; + + phalcon_fetch_params(0, 3, 0, &message, &type, ×tamp); + + + PHALCON_ALLOC_ZVAL(type_str); + phalcon_call_method_p1_key(type_str, this_ptr, "gettypestring", type, 2427941566UL); + + PHALCON_ALLOC_ZVAL(backtrace); +#if PHP_VERSION_ID < 50306 + zend_fetch_debug_backtrace(backtrace, 1, 0 TSRMLS_CC); +#elif PHP_VERSION_ID < 50400 + zend_fetch_debug_backtrace(backtrace, 1, DEBUG_BACKTRACE_IGNORE_ARGS TSRMLS_CC); +#else + zend_fetch_debug_backtrace(backtrace, 1, DEBUG_BACKTRACE_IGNORE_ARGS, 0 TSRMLS_CC); +#endif + + if (Z_TYPE_P(backtrace) == IS_ARRAY) { + HashPosition pos; + HashTable *ht = Z_ARRVAL_P(backtrace); + zval **ppzval; + int found = 0; + ulong idx; + char *key; + uint key_len; + + + for ( + zend_hash_internal_pointer_reset_ex(ht, &pos); + zend_hash_has_more_elements_ex(ht, &pos) == SUCCESS; + ) { + zend_hash_get_current_data_ex(ht, (void**)&ppzval, &pos); + zend_hash_get_current_key_ex(ht, &key, &key_len, &idx, 0, &pos); + zend_hash_move_forward_ex(ht, &pos); + + if (Z_TYPE_PP(ppzval) == IS_ARRAY) { + if (!found && !zend_hash_exists(Z_ARRVAL_PP(ppzval), SS("file"))) { + zend_hash_index_del(ht, idx); + } + else { + zend_hash_del(Z_ARRVAL_PP(ppzval), "args", sizeof("args")); + zend_hash_del(Z_ARRVAL_PP(ppzval), "object", sizeof("object")); + found = 1; + } + } + } + + p = ht->pListHead; + i = 0; + while (p != NULL) { + p->nKeyLength = 0; + p->h = i++; + p = p->pListNext; + } + + ht->nNextFreeElement = i; + zend_hash_rehash(ht); + } + + PHALCON_ALLOC_ZVAL(payload); + array_init_size(payload, 2); + + PHALCON_ALLOC_ZVAL(meta); + array_init_size(meta, 2); + add_assoc_zval(meta, "type", type_str); + add_assoc_zval(meta, "backtrace", backtrace); + + add_next_index_zval(payload, meta); + add_next_index_zval(payload, message); + + ALLOC_INIT_ZVAL(encoded); + phalcon_json_encode(encoded, payload, 0 TSRMLS_CC); + + zval_ptr_dtor(&payload); + + smart_str_alloc4(&result, Z_STRLEN_P(encoded) + 2 + 5, 0, i); + + smart_str_append_long(&result, Z_STRLEN_P(encoded)); + smart_str_appendc(&result, '|'); + smart_str_appendl(&result, Z_STRVAL_P(encoded), Z_STRLEN_P(encoded)); + smart_str_appendc(&result, '|'); + smart_str_0(&result); + + /* We don't need the JSON message anymore */ + zval_ptr_dtor(&encoded); + /* Do not free the samrt string because we steal its data for zval */ + RETURN_STRINGL(result.c, result.len, 0); } -// 1621 "parser.c" - break; - case 5: -// 546 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[0].minor.yy132, NULL, NULL, NULL, NULL, NULL); + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Logger_Formatter_Json){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Formatter, Json, logger_formatter_json, "phalcon\\logger\\formatter", phalcon_logger_formatter_json_method_entry, 0); + + zend_class_implements(phalcon_logger_formatter_json_ce TSRMLS_CC, 1, phalcon_logger_formatterinterface_ce); + + return SUCCESS; } -// 1628 "parser.c" - break; - case 6: -// 550 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL, NULL, NULL, NULL); + +static PHP_METHOD(Phalcon_Logger_Formatter_Json, format){ + + zval *message, *type, *timestamp, *type_str, *log; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &message, &type, ×tamp); + + PHALCON_INIT_VAR(type_str); + phalcon_call_method_p1_key(type_str, this_ptr, "gettypestring", type, 2427941566UL); + + PHALCON_INIT_VAR(log); + array_init_size(log, 3); + phalcon_array_update_quick_string(&log, SS("type"), 276192743UL, &type_str, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&log, SS("message"), 2265848874UL, &message, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&log, SS("timestamp"), 3706650937UL, ×tamp, PH_COPY | PH_SEPARATE); + phalcon_json_encode(return_value, log, 0 TSRMLS_CC); + RETURN_MM(); } -// 1635 "parser.c" - break; - case 7: -// 554 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL, NULL, NULL); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Logger_Formatter_Line){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Formatter, Line, logger_formatter_line, "phalcon\\logger\\formatter", phalcon_logger_formatter_line_method_entry, 0); + + zend_declare_property_string(phalcon_logger_formatter_line_ce, SL("_dateFormat"), "D, d M y H:i:s O", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_logger_formatter_line_ce, SL("_format"), "[%date%][%type%] %message%", ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_logger_formatter_line_ce TSRMLS_CC, 1, phalcon_logger_formatterinterface_ce); + + return SUCCESS; } -// 1642 "parser.c" - break; - case 8: -// 558 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132, NULL, NULL); + +static PHP_METHOD(Phalcon_Logger_Formatter_Line, __construct){ + + zval *format = NULL, *date_format = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &format, &date_format); + + if (!format) { + PHALCON_INIT_VAR(format); + } + + if (!date_format) { + PHALCON_INIT_VAR(date_format); + } + + if (Z_TYPE_P(format) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_format"), format, 3742267021UL TSRMLS_CC); + } + if (Z_TYPE_P(date_format) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_dateFormat"), date_format, 959184011UL TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); } -// 1649 "parser.c" - break; - case 9: -// 562 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, NULL, yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); + +static PHP_METHOD(Phalcon_Logger_Formatter_Line, setFormat){ + + zval *format; + + phalcon_fetch_params(0, 1, 0, &format); + + phalcon_update_property_this_quick(this_ptr, SL("_format"), format, 3742267021UL TSRMLS_CC); + } -// 1656 "parser.c" - break; - case 10: -// 566 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, yymsp[0].minor.yy132, yymsp[-1].minor.yy132, NULL, NULL); + +static PHP_METHOD(Phalcon_Logger_Formatter_Line, getFormat){ + + + RETURN_MEMBER_QUICK(this_ptr, "_format", 3742267021UL); } -// 1663 "parser.c" - break; - case 11: -// 570 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-4].minor.yy132, yymsp[-3].minor.yy132, yymsp[-1].minor.yy132, yymsp[-2].minor.yy132, NULL, yymsp[0].minor.yy132); + +static PHP_METHOD(Phalcon_Logger_Formatter_Line, setDateFormat){ + + zval *date; + + phalcon_fetch_params(0, 1, 0, &date); + + phalcon_update_property_this_quick(this_ptr, SL("_dateFormat"), date, 959184011UL TSRMLS_CC); + } -// 1670 "parser.c" - break; - case 12: -// 574 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-4].minor.yy132, yymsp[-3].minor.yy132, yymsp[0].minor.yy132, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL); + +static PHP_METHOD(Phalcon_Logger_Formatter_Line, getDateFormat){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dateFormat", 959184011UL); } -// 1677 "parser.c" - break; - case 13: -// 578 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL, NULL, NULL, yymsp[0].minor.yy132); + +static PHP_METHOD(Phalcon_Logger_Formatter_Line, format){ + + zval *message, *type, *timestamp, *format = NULL, *date_format; + zval *date, *date_wildcard, *new_format = NULL, *type_string; + zval *type_wildcard, *message_wildcard, *eol; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &message, &type, ×tamp); + + PHALCON_OBS_VAR(format); + phalcon_read_property_this_quick(&format, this_ptr, SL("_format"), 3742267021UL, PH_NOISY_CC); + + if (phalcon_memnstr_str(format, SL("%date%"))) { + PHALCON_OBS_VAR(date_format); + phalcon_read_property_this_quick(&date_format, this_ptr, SL("_dateFormat"), 959184011UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(date); + phalcon_call_func_p2(date, "date", date_format, timestamp); + + PHALCON_INIT_VAR(date_wildcard); + ZVAL_STRING(date_wildcard, "%date%", 1); + + PHALCON_INIT_VAR(new_format); + phalcon_fast_str_replace(new_format, date_wildcard, date, format); + } else { + PHALCON_CPY_WRT(new_format, format); + } + + if (phalcon_memnstr_str(format, SL("%type%"))) { + PHALCON_INIT_VAR(type_string); + phalcon_call_method_p1_key(type_string, this_ptr, "gettypestring", type, 2427941566UL); + + PHALCON_INIT_VAR(type_wildcard); + ZVAL_STRING(type_wildcard, "%type%", 1); + + PHALCON_INIT_NVAR(format); + phalcon_fast_str_replace(format, type_wildcard, type_string, new_format); + } else { + PHALCON_CPY_WRT(format, new_format); + } + + PHALCON_INIT_VAR(message_wildcard); + ZVAL_STRING(message_wildcard, "%message%", 1); + + PHALCON_INIT_NVAR(new_format); + phalcon_fast_str_replace(new_format, message_wildcard, message, format); + + PHALCON_INIT_VAR(eol); + ZVAL_STRING(eol, PHP_EOL, 1); + PHALCON_CONCAT_VV(return_value, new_format, eol); + + RETURN_MM(); } -// 1684 "parser.c" - break; - case 14: -// 582 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL, NULL, yymsp[0].minor.yy132); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Logger_Formatter_Syslog){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Formatter, Syslog, logger_formatter_syslog, "phalcon\\logger\\formatter", phalcon_logger_formatter_syslog_method_entry, 0); + + zend_class_implements(phalcon_logger_formatter_syslog_ce TSRMLS_CC, 1, phalcon_logger_formatterinterface_ce); + + return SUCCESS; } -// 1691 "parser.c" - break; - case 15: -// 586 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, NULL, yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); + +static PHP_METHOD(Phalcon_Logger_Formatter_Syslog, format){ + + zval *message, *type, *timestamp; + + phalcon_fetch_params(0, 3, 0, &message, &type, ×tamp); + + array_init_size(return_value, 2); + phalcon_array_append(&return_value, type, PH_SEPARATE); + phalcon_array_append(&return_value, message, PH_SEPARATE); + return; } -// 1698 "parser.c" - break; - case 16: -// 590 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-4].minor.yy132, yymsp[-3].minor.yy132, NULL, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); -} -// 1705 "parser.c" - break; - case 17: -// 594 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132, NULL, NULL, NULL); -} -// 1712 "parser.c" - break; - case 18: -// 598 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, NULL, yymsp[0].minor.yy132, yymsp[-1].minor.yy132, NULL, NULL); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Logger_Formatter){ + + PHALCON_REGISTER_CLASS(Phalcon\\Logger, Formatter, logger_formatter, phalcon_logger_formatter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + return SUCCESS; } -// 1719 "parser.c" - break; - case 19: -// 602 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, NULL, yymsp[0].minor.yy132, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL); + +static PHP_METHOD(Phalcon_Logger_Formatter, getTypeString){ + + static const char *lut[10] = { + "EMERGENCY", "CRITICAL", "ALERT", "ERROR", "WARNING", + "NOTICE", "INFO", "DEBUG", "CUSTOM", "SPECIAL" + }; + + zval *type; + int itype; + + phalcon_fetch_params(0, 1, 0, &type); + + itype = phalcon_get_intval(type); + if (itype > 0 && itype < 10) { + RETURN_STRING(lut[itype], 1); + } + + RETURN_STRING("CUSTOM", 1); } -// 1726 "parser.c" - break; - case 20: -// 606 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, NULL, yymsp[-1].minor.yy132, NULL, NULL, yymsp[0].minor.yy132); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Logger_FormatterInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Logger, FormatterInterface, logger_formatterinterface, phalcon_logger_formatterinterface_method_entry); + + return SUCCESS; } -// 1733 "parser.c" - break; - case 21: -// 610 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, NULL, yymsp[-1].minor.yy132, yymsp[-2].minor.yy132, NULL, yymsp[0].minor.yy132); + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Logger_Item){ + + PHALCON_REGISTER_CLASS(Phalcon\\Logger, Item, logger_item, phalcon_logger_item_method_entry, 0); + + zend_declare_property_null(phalcon_logger_item_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_logger_item_ce, SL("_message"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_logger_item_ce, SL("_time"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; } -// 1740 "parser.c" - break; - case 22: -// 614 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-5].minor.yy132, yymsp[-4].minor.yy132, yymsp[-1].minor.yy132, yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + +static PHP_METHOD(Phalcon_Logger_Item, __construct){ + + zval *message, *type, *time = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 1, &message, &type, &time); + + if (!time) { + PHALCON_INIT_VAR(time); + ZVAL_LONG(time, 0); + } + + phalcon_update_property_this_quick(this_ptr, SL("_message"), message, 933579817UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_time"), time, 3991380851UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -// 1747 "parser.c" - break; - case 23: -// 618 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-1].minor.yy132, NULL, NULL, yymsp[0].minor.yy132, NULL, NULL); + +static PHP_METHOD(Phalcon_Logger_Item, getMessage){ + + + RETURN_MEMBER_QUICK(this_ptr, "_message", 933579817UL); } -// 1754 "parser.c" - break; - case 24: -// 622 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, NULL, NULL, yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); + +static PHP_METHOD(Phalcon_Logger_Item, getType){ + + + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); } -// 1761 "parser.c" - break; - case 25: -// 626 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, NULL, NULL, yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); + +static PHP_METHOD(Phalcon_Logger_Item, getTime){ + + + RETURN_MEMBER_QUICK(this_ptr, "_time", 3991380851UL); } -// 1768 "parser.c" - break; - case 26: -// 630 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, NULL, NULL, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Logger_Multiple){ + + PHALCON_REGISTER_CLASS(Phalcon\\Logger, Multiple, logger_multiple, phalcon_logger_multiple_method_entry, 0); + + zend_declare_property_null(phalcon_logger_multiple_ce, SL("_loggers"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_logger_multiple_ce, SL("_formatter"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; } -// 1775 "parser.c" - break; - case 27: -// 634 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-4].minor.yy132, NULL, yymsp[-1].minor.yy132, yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + +static PHP_METHOD(Phalcon_Logger_Multiple, push){ + + zval *logger; + + phalcon_fetch_params(0, 1, 0, &logger); + + if (Z_TYPE_P(logger) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "The logger is invalid"); + return; + } + phalcon_update_property_array_append(this_ptr, SL("_loggers"), logger TSRMLS_CC); + } -// 1782 "parser.c" - break; - case 28: -// 638 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[-1].minor.yy132, NULL, NULL, NULL, NULL, yymsp[0].minor.yy132); + +static PHP_METHOD(Phalcon_Logger_Multiple, getLoggers){ + + + RETURN_MEMBER_QUICK(this_ptr, "_loggers", 810888023UL); } -// 1789 "parser.c" - break; - case 29: -// 644 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_clause(yymsp[-2].minor.yy132, yymsp[0].minor.yy132, NULL); - yy_destructor(26,&yymsp[-3].minor); - yy_destructor(27,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Logger_Multiple, setFormatter){ + + zval *formatter, *loggers, *logger = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &formatter); + + PHALCON_OBS_VAR(loggers); + phalcon_read_property_this_quick(&loggers, this_ptr, SL("_loggers"), 810888023UL, PH_NOISY_CC); + if (Z_TYPE_P(loggers) == IS_ARRAY) { + + phalcon_is_iterable(loggers, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(logger); + + phalcon_call_method_p1_key(NULL, logger, "setformatter", formatter, 3614631813UL); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } + + phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -// 1798 "parser.c" - break; - case 30: -// 648 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_clause(yymsp[-3].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(26,&yymsp[-4].minor); - yy_destructor(27,&yymsp[-2].minor); + +static PHP_METHOD(Phalcon_Logger_Multiple, getFormatter){ + + + RETURN_MEMBER_QUICK(this_ptr, "_formatter", 1838243768UL); } -// 1807 "parser.c" - break; - case 31: - case 38: - case 61: - case 64: - case 72: - case 87: - case 93: - case 130: -// 654 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_zval_list(yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(28,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Logger_Multiple, log){ + + zval *message, *type = NULL, *loggers, *logger = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &message, &type); + + if (!type) { + PHALCON_INIT_VAR(type); + ZVAL_LONG(type, 7); + } + + PHALCON_OBS_VAR(loggers); + phalcon_read_property_this_quick(&loggers, this_ptr, SL("_loggers"), 810888023UL, PH_NOISY_CC); + if (Z_TYPE_P(loggers) == IS_ARRAY) { + + phalcon_is_iterable(loggers, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(logger); + + phalcon_call_method_p2_key(NULL, logger, "log", message, type, 2090479079UL); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } + + PHALCON_MM_RESTORE(); } -// 1822 "parser.c" - break; - case 33: - case 132: -// 664 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_column_item(PHQL_T_ALL, NULL, NULL, NULL); - yy_destructor(17,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Logger_Multiple, emergence){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("EMERGENCE") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + + PHALCON_MM_RESTORE(); } -// 1831 "parser.c" - break; - case 34: -// 668 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_column_item(PHQL_T_DOMAINALL, NULL, yymsp[-2].minor.yy0, NULL); - yy_destructor(30,&yymsp[-1].minor); - yy_destructor(17,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Logger_Multiple, debug){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("DEBUG") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + + PHALCON_MM_RESTORE(); } -// 1840 "parser.c" - break; - case 35: -// 672 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_column_item(PHQL_T_EXPR, yymsp[-2].minor.yy132, NULL, yymsp[0].minor.yy0); - yy_destructor(31,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Logger_Multiple, error){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("ERROR") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + + PHALCON_MM_RESTORE(); } -// 1848 "parser.c" - break; - case 36: -// 676 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_column_item(PHQL_T_EXPR, yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy0); + +static PHP_METHOD(Phalcon_Logger_Multiple, info){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("INFO") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + + PHALCON_MM_RESTORE(); } -// 1855 "parser.c" - break; - case 37: -// 680 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_column_item(PHQL_T_EXPR, yymsp[0].minor.yy132, NULL, NULL); + +static PHP_METHOD(Phalcon_Logger_Multiple, notice){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("NOTICE") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + + PHALCON_MM_RESTORE(); } -// 1862 "parser.c" - break; - case 40: -// 696 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_zval_list(yymsp[-1].minor.yy132, yymsp[0].minor.yy132); + +static PHP_METHOD(Phalcon_Logger_Multiple, warning){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("WARNING") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + + PHALCON_MM_RESTORE(); } -// 1869 "parser.c" - break; - case 43: -// 713 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_item(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL, NULL); + +static PHP_METHOD(Phalcon_Logger_Multiple, alert){ + + zval *message, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); + + PHALCON_INIT_VAR(type); + phalcon_get_class_constant(type, phalcon_logger_ce, SS("ALERT") TSRMLS_CC); + phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + + PHALCON_MM_RESTORE(); } -// 1876 "parser.c" - break; - case 44: -// 718 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_item(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Logger){ + + PHALCON_REGISTER_CLASS(Phalcon, Logger, logger, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_class_constant_long(phalcon_logger_ce, SL("SPECIAL"), 9 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_logger_ce, SL("CUSTOM"), 8 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_logger_ce, SL("DEBUG"), 7 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_logger_ce, SL("INFO"), 6 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_logger_ce, SL("NOTICE"), 5 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_logger_ce, SL("WARNING"), 4 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_logger_ce, SL("ERROR"), 3 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_logger_ce, SL("ALERT"), 2 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_logger_ce, SL("CRITICAL"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_logger_ce, SL("EMERGENCE"), 0 TSRMLS_CC); + + return SUCCESS; } -// 1883 "parser.c" - break; - case 45: -// 723 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_item(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); -} -// 1890 "parser.c" - break; - case 46: -// 728 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_item(yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Application_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Application, Exception, mvc_application_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } -// 1897 "parser.c" - break; - case 47: -// 734 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_qualified_name(NULL, NULL, yymsp[0].minor.yy0); - yy_destructor(31,&yymsp[-1].minor); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Application){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, Application, mvc_application, "phalcon\\di\\injectable", phalcon_mvc_application_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_application_ce, SL("_defaultModule"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_application_ce, SL("_modules"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_application_ce, SL("_moduleObject"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_application_ce, SL("_implicitView"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; } -// 1905 "parser.c" - break; - case 48: - case 66: - case 153: -// 738 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_qualified_name(NULL, NULL, yymsp[0].minor.yy0); + +static PHP_METHOD(Phalcon_Mvc_Application, __construct){ + + zval *dependency_injector = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &dependency_injector); + + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); + } + + if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); } -// 1914 "parser.c" - break; - case 49: -// 744 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_type(PHQL_T_INNERJOIN); - yy_destructor(32,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Mvc_Application, useImplicitView){ + + zval *implicit_view; + + phalcon_fetch_params(0, 1, 0, &implicit_view); + + phalcon_update_property_this_quick(this_ptr, SL("_implicitView"), implicit_view, 1205999546UL TSRMLS_CC); + RETURN_THISW(); } -// 1922 "parser.c" - break; - case 50: -// 748 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_type(PHQL_T_INNERJOIN); - yy_destructor(33,&yymsp[-1].minor); - yy_destructor(32,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Mvc_Application, registerModules){ + + zval *modules, *merge = NULL, *registered_modules, *merged_modules = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &modules, &merge); + + if (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 0); + } + + if (Z_TYPE_P(modules) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "Modules must be an Array"); + return; + } + if (PHALCON_IS_FALSE(merge)) { + phalcon_update_property_this_quick(this_ptr, SL("_modules"), modules, 379092157UL TSRMLS_CC); + } else { + PHALCON_OBS_VAR(registered_modules); + phalcon_read_property_this_quick(®istered_modules, this_ptr, SL("_modules"), 379092157UL, PH_NOISY_CC); + if (Z_TYPE_P(registered_modules) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_modules); + phalcon_fast_array_merge(merged_modules, ®istered_modules, &modules TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_modules, modules); + } + + phalcon_update_property_this_quick(this_ptr, SL("_modules"), merged_modules, 379092157UL TSRMLS_CC); + } + + RETURN_THIS(); } -// 1931 "parser.c" - break; - case 51: -// 752 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_type(PHQL_T_CROSSJOIN); - yy_destructor(34,&yymsp[-1].minor); - yy_destructor(32,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Mvc_Application, getModules){ + + + RETURN_MEMBER_QUICK(this_ptr, "_modules", 379092157UL); } -// 1940 "parser.c" - break; - case 52: -// 756 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_type(PHQL_T_LEFTJOIN); - yy_destructor(35,&yymsp[-1].minor); - yy_destructor(32,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Mvc_Application, setDefaultModule){ + + zval *default_module; + + phalcon_fetch_params(0, 1, 0, &default_module); + + phalcon_update_property_this_quick(this_ptr, SL("_defaultModule"), default_module, 3959488399UL TSRMLS_CC); + RETURN_THISW(); } -// 1949 "parser.c" - break; - case 53: -// 760 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_type(PHQL_T_LEFTJOIN); - yy_destructor(35,&yymsp[-2].minor); - yy_destructor(36,&yymsp[-1].minor); - yy_destructor(32,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Mvc_Application, getDefaultModule){ + + + RETURN_MEMBER_QUICK(this_ptr, "_defaultModule", 3959488399UL); } -// 1959 "parser.c" - break; - case 54: -// 764 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_type(PHQL_T_RIGHTJOIN); - yy_destructor(37,&yymsp[-1].minor); - yy_destructor(32,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Mvc_Application, handle){ + + zval *uri = NULL, *dependency_injector, *events_manager; + zval *event_name = NULL, *status = NULL, *service = NULL, *router, *module_name = NULL; + zval *module_object = NULL, *modules, *exception_msg = NULL; + zval *module, *class_name = NULL, *path, *module_params; + zval *implicit_view, *view, *namespace_name; + zval *controller_name = NULL, *action_name = NULL, *params = NULL; + zval *dispatcher, *controller, *returned_response = NULL; + zval *possible_response, *render_status = NULL, *response = NULL; + zval *content; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &uri); + + if (!uri) { + PHALCON_INIT_VAR(uri); + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "A dependency injection object is required to access internal services"); + return; + } + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "application:boot", 1); + + PHALCON_INIT_VAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "router", 1); + + PHALCON_INIT_VAR(router); + phalcon_call_method_p1_key(router, dependency_injector, "getshared", service, 1727570332UL); + + phalcon_call_method_p1_key(NULL, router, "handle", uri, 866903697UL); + + PHALCON_INIT_VAR(module_name); + phalcon_call_method_key(module_name, router, "getmodulename", 3538616428UL); + + if (!zend_is_true(module_name)) { + PHALCON_OBS_NVAR(module_name); + phalcon_read_property_this_quick(&module_name, this_ptr, SL("_defaultModule"), 3959488399UL, PH_NOISY_CC); + } + + PHALCON_INIT_VAR(module_object); + + if (zend_is_true(module_name)) { + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "application:beforeStartModule", 1); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, module_name, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } + + PHALCON_OBS_VAR(modules); + phalcon_read_property_this_quick(&modules, this_ptr, SL("_modules"), 379092157UL, PH_NOISY_CC); + if (!phalcon_array_isset(modules, module_name)) { + PHALCON_INIT_VAR(exception_msg); + PHALCON_CONCAT_SVS(exception_msg, "Module '", module_name, "' isn't registered in the application container"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_application_exception_ce, exception_msg); + return; + } + + PHALCON_OBS_VAR(module); + phalcon_array_fetch(&module, modules, module_name, PH_NOISY); + if (Z_TYPE_P(module) != IS_ARRAY) { + if (Z_TYPE_P(module) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "Invalid module definition"); + return; + } + } + + if (Z_TYPE_P(module) == IS_ARRAY) { + + if (phalcon_array_isset_quick_string(module, SS("className"), 362439804UL)) { + PHALCON_OBS_VAR(class_name); + phalcon_array_fetch_quick_string(&class_name, module, SS("className"), 362439804UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(class_name); + ZVAL_STRING(class_name, "Module", 1); + } + + if (phalcon_array_isset_quick_string(module, SS("path"), 270591026UL)) { + + PHALCON_OBS_VAR(path); + phalcon_array_fetch_quick_string(&path, module, SS("path"), 270591026UL, PH_NOISY); + if (!phalcon_class_exists(class_name, 0 TSRMLS_CC)) { + if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { + if (phalcon_require(path TSRMLS_CC) == FAILURE) { + return; + } + } else { + PHALCON_INIT_NVAR(exception_msg); + PHALCON_CONCAT_SVS(exception_msg, "Module definition path '", path, "' doesn't exist"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_application_exception_ce, exception_msg); + return; + } + } + } + + phalcon_call_method_p1_key(module_object, dependency_injector, "get", class_name, 2090288933UL); + + phalcon_call_method_p1_key(NULL, module_object, "registerautoloaders", dependency_injector, 1488981101UL); + phalcon_call_method_p1_key(NULL, module_object, "registerservices", dependency_injector, 3636598030UL); + } else { + if (phalcon_is_instance_of(module, SL("Closure") TSRMLS_CC)) { + PHALCON_INIT_VAR(module_params); + array_init_size(module_params, 1); + phalcon_array_append(&module_params, dependency_injector, PH_SEPARATE); + + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC_ARRAY(status, module, module_params); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "Invalid module definition"); + return; + } + } + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_moduleObject"), module_object, 121977121UL TSRMLS_CC); + + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "application:afterStartModule", 1); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, module_name, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } + } + + PHALCON_OBS_VAR(implicit_view); + phalcon_read_property_this_quick(&implicit_view, this_ptr, SL("_implicitView"), 1205999546UL, PH_NOISY_CC); + if (PHALCON_IS_TRUE(implicit_view)) { + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "view", 1); + + PHALCON_INIT_VAR(view); + phalcon_call_method_p1_key(view, dependency_injector, "getshared", service, 1727570332UL); + } + + PHALCON_INIT_NVAR(module_name); + phalcon_call_method_key(module_name, router, "getmodulename", 3538616428UL); + + PHALCON_INIT_VAR(namespace_name); + phalcon_call_method_key(namespace_name, router, "getnamespacename", 1552352211UL); + + PHALCON_INIT_VAR(controller_name); + phalcon_call_method_key(controller_name, router, "getcontrollername", 620100618UL); + + PHALCON_INIT_VAR(action_name); + phalcon_call_method_key(action_name, router, "getactionname", 2461134148UL); + + PHALCON_INIT_VAR(params); + phalcon_call_method_key(params, router, "getparams", 1893744905UL); + + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "dispatcher", 1); + + PHALCON_INIT_VAR(dispatcher); + phalcon_call_method_p1_key(dispatcher, dependency_injector, "getshared", service, 1727570332UL); + + phalcon_call_method_p1_key(NULL, dispatcher, "setmodulename", module_name, 2582492152UL); + phalcon_call_method_p1_key(NULL, dispatcher, "setnamespacename", namespace_name, 1052613599UL); + phalcon_call_method_p1_key(NULL, dispatcher, "setcontrollername", controller_name, 1308595606UL); + phalcon_call_method_p1_key(NULL, dispatcher, "setactionname", action_name, 1505009872UL); + phalcon_call_method_p1_key(NULL, dispatcher, "setparams", params, 2707361429UL); + + if (PHALCON_IS_TRUE(implicit_view)) { + phalcon_call_method_key(NULL, view, "start", 478839859UL); + } + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "application:beforeHandleRequest", 1); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, dispatcher, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } + + PHALCON_INIT_VAR(controller); + phalcon_call_method_key(controller, dispatcher, "dispatch", 4202735573UL); + + PHALCON_INIT_VAR(returned_response); + ZVAL_BOOL(returned_response, 0); + + PHALCON_INIT_VAR(possible_response); + phalcon_call_method_key(possible_response, dispatcher, "getreturnedvalue", 1798811019UL); + if (Z_TYPE_P(possible_response) == IS_OBJECT) { + phalcon_instance_of(returned_response, possible_response, phalcon_http_responseinterface_ce TSRMLS_CC); + } + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "application:afterHandleRequest", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, controller, 259017035UL); + } + + if (PHALCON_IS_FALSE(returned_response)) { + if (PHALCON_IS_TRUE(implicit_view)) { + + if (Z_TYPE_P(controller) == IS_OBJECT) { + + PHALCON_INIT_VAR(render_status); + ZVAL_BOOL(render_status, 1); + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "application:viewRender", 1); + + phalcon_call_method_p3_key(render_status, events_manager, "fire", event_name, this_ptr, view, 259017035UL); + } + + if (PHALCON_IS_NOT_FALSE(render_status)) { + PHALCON_INIT_NVAR(controller_name); + phalcon_call_method_key(controller_name, dispatcher, "getcontrollername", 620100618UL); + + PHALCON_INIT_NVAR(action_name); + phalcon_call_method_key(action_name, dispatcher, "getactionname", 2461134148UL); + + PHALCON_INIT_NVAR(params); + phalcon_call_method_key(params, dispatcher, "getparams", 1893744905UL); + + phalcon_call_method_p3_key(NULL, view, "render", controller_name, action_name, params, 1053215877UL); + } + } + } + } + + if (PHALCON_IS_TRUE(implicit_view)) { + phalcon_call_method_key(NULL, view, "finish", 2892205606UL); + } + + if (PHALCON_IS_FALSE(returned_response)) { + + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "response", 1); + + PHALCON_INIT_VAR(response); + phalcon_call_method_p1_key(response, dependency_injector, "getshared", service, 1727570332UL); + if (PHALCON_IS_TRUE(implicit_view)) { + PHALCON_INIT_VAR(content); + phalcon_call_method_key(content, view, "getcontent", 3141446400UL); + phalcon_call_method_p1_key(NULL, response, "setcontent", content, 4220987916UL); + } + } else { + PHALCON_CPY_WRT(response, possible_response); + } + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "application:beforeSendResponse", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, response, 259017035UL); + } + + phalcon_call_method_key(NULL, response, "sendheaders", 1941404491UL); + + phalcon_call_method_key(NULL, response, "sendcookies", 4183658748UL); + + + RETURN_CCTOR(response); } -// 1968 "parser.c" - break; - case 55: -// 768 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_type(PHQL_T_RIGHTJOIN); - yy_destructor(37,&yymsp[-2].minor); - yy_destructor(36,&yymsp[-1].minor); - yy_destructor(32,&yymsp[0].minor); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Collection_Document){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Collection, Document, mvc_collection_document, phalcon_mvc_collection_document_method_entry, 0); + + zend_class_implements(phalcon_mvc_collection_document_ce TSRMLS_CC, 1, zend_ce_arrayaccess); + + return SUCCESS; } -// 1978 "parser.c" - break; - case 56: -// 772 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_type(PHQL_T_FULLJOIN); - yy_destructor(38,&yymsp[-1].minor); - yy_destructor(32,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetExists){ + + zval *index; + + phalcon_fetch_params(0, 1, 0, &index); + + if (phalcon_isset_property_zval(this_ptr, index TSRMLS_CC)) { + RETURN_TRUE; + } + RETURN_FALSE; } -// 1987 "parser.c" - break; - case 57: -// 776 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_type(PHQL_T_FULLJOIN); - yy_destructor(38,&yymsp[-2].minor); - yy_destructor(36,&yymsp[-1].minor); - yy_destructor(32,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetGet){ + + zval *index, *value; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &index); + + if (phalcon_isset_property_zval(this_ptr, index TSRMLS_CC)) { + PHALCON_OBS_VAR(value); + phalcon_read_property_zval(&value, this_ptr, index, PH_NOISY_CC); + RETURN_CCTOR(value); + } + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The index does not exist in the row"); + return; } -// 1997 "parser.c" - break; - case 58: -// 782 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; - yy_destructor(39,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetSet){ + + zval *index, *value; + + phalcon_fetch_params(0, 2, 0, &index, &value); + + phalcon_update_property_zval_zval(this_ptr, index, value TSRMLS_CC); + } -// 2005 "parser.c" - break; - case 59: -// 789 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_insert_statement(yymsp[-4].minor.yy132, NULL, yymsp[-1].minor.yy132); - yy_destructor(40,&yymsp[-6].minor); - yy_destructor(41,&yymsp[-5].minor); - yy_destructor(42,&yymsp[-3].minor); - yy_destructor(43,&yymsp[-2].minor); - yy_destructor(44,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetUnset){ + + zval *offset; + + phalcon_fetch_params(0, 1, 0, &offset); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_collection_exception_ce, "The index does not exist in the row"); + return; } -// 2017 "parser.c" - break; - case 60: -// 793 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_insert_statement(yymsp[-7].minor.yy132, yymsp[-5].minor.yy132, yymsp[-1].minor.yy132); - yy_destructor(40,&yymsp[-9].minor); - yy_destructor(41,&yymsp[-8].minor); - yy_destructor(43,&yymsp[-6].minor); - yy_destructor(44,&yymsp[-4].minor); - yy_destructor(42,&yymsp[-3].minor); - yy_destructor(43,&yymsp[-2].minor); - yy_destructor(44,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Document, readAttribute){ + + zval *attribute, *attribute_value; + + 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_CC); + RETURN_CCTOR(attribute_value); + } + RETURN_MM_NULL(); } -// 2031 "parser.c" - break; - case 67: -// 831 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_statement(yymsp[0].minor.yy132, NULL, NULL); + +static PHP_METHOD(Phalcon_Mvc_Collection_Document, writeAttribute){ + + zval *attribute, *value; + + phalcon_fetch_params(0, 2, 0, &attribute, &value); + + phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); + } -// 2038 "parser.c" - break; - case 68: -// 835 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Collection_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Collection, Exception, mvc_collection_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } -// 2045 "parser.c" - break; - case 69: -// 839 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Collection_Manager){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Collection, Manager, mvc_collection_manager, phalcon_mvc_collection_manager_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_initialized"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_lastInitialized"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_customEventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_connectionServices"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_implicitObjectsIds"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_collection_manager_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_events_eventsawareinterface_ce); + + return SUCCESS; } -// 2052 "parser.c" - break; - case 70: -// 843 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_statement(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + } -// 2059 "parser.c" - break; - case 71: -// 849 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_clause(yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(45,&yymsp[-3].minor); - yy_destructor(46,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -// 2068 "parser.c" - break; - case 74: -// 865 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_item(yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(3,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, setEventsManager){ + + zval *events_manager; + + phalcon_fetch_params(0, 1, 0, &events_manager); + + phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); + } -// 2076 "parser.c" - break; - case 76: -// 877 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_delete_statement(yymsp[0].minor.yy132, NULL, NULL); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getEventsManager){ + + + RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); } -// 2083 "parser.c" - break; - case 77: -// 881 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_delete_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, setCustomEventsManager){ + + zval *model, *events_manager, *class_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &events_manager); + + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 1 TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_customEventsManager"), class_name, events_manager TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -// 2090 "parser.c" - break; - case 78: -// 885 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_delete_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getCustomEventsManager){ + + zval *model, *custom_events_manager, *class_name; + zval *events_manager; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_OBS_VAR(custom_events_manager); + phalcon_read_property_this_quick(&custom_events_manager, this_ptr, SL("_customEventsManager"), 542727151UL, PH_NOISY_CC); + if (Z_TYPE_P(custom_events_manager) == IS_ARRAY) { + + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(custom_events_manager, class_name)) { + PHALCON_OBS_VAR(events_manager); + phalcon_array_fetch(&events_manager, custom_events_manager, class_name, PH_NOISY); + RETURN_CCTOR(events_manager); + } + } + + RETURN_MM_NULL(); } -// 2097 "parser.c" - break; - case 79: -// 889 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_delete_statement(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, initialize){ + + zval *model, *class_name, *initialized, *events_manager; + zval *event_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 1 TSRMLS_CC); + + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); + + if (!phalcon_array_isset(initialized, class_name)) { + + if (phalcon_method_quick_exists_ex(model, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, model, "initialize", 2896075127UL); + } + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "collectionManager:afterInitialize", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } + + phalcon_update_property_array(this_ptr, SL("_initialized"), class_name, model TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_lastInitialized"), model, 1491101038UL TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); } -// 2104 "parser.c" - break; - case 80: -// 895 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_delete_clause(yymsp[0].minor.yy132); - yy_destructor(47,&yymsp[-2].minor); - yy_destructor(27,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, isInitialized){ + + zval *model_name, *initialized, *lowercased; + zval *is_intitialized = NULL; + zval *r0 = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model_name); + + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(lowercased); + phalcon_fast_strtolower(lowercased, model_name); + + PHALCON_INIT_VAR(r0); + ZVAL_BOOL(r0, phalcon_array_isset(initialized, lowercased)); + PHALCON_CPY_WRT(is_intitialized, r0); + RETURN_NCTOR(is_intitialized); } -// 2113 "parser.c" - break; - case 81: -// 901 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_assoc_name(yymsp[-2].minor.yy132, yymsp[0].minor.yy0); - yy_destructor(31,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getLastInitialized){ + + + RETURN_MEMBER_QUICK(this_ptr, "_lastInitialized", 1491101038UL); } -// 2121 "parser.c" - break; - case 82: -// 905 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_assoc_name(yymsp[-1].minor.yy132, yymsp[0].minor.yy0); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, setConnectionService){ + + zval *model, *connection_service, *entity_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &connection_service); + + if (Z_TYPE_P(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A valid collection instance is required"); + return; + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_connectionServices"), entity_name, connection_service TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -// 2128 "parser.c" - break; - case 83: -// 909 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_assoc_name(yymsp[0].minor.yy132, NULL); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, useImplicitObjectIds){ + + zval *model, *use_implicit_object_ids, *entity_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &use_implicit_object_ids); + + if (Z_TYPE_P(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A valid collection instance is required"); + return; + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_implicitObjectsIds"), entity_name, use_implicit_object_ids TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -// 2135 "parser.c" - break; - case 85: -// 921 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; - yy_destructor(48,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, isUsingImplicitObjectIds){ + + zval *model, *entity_name, *implicit_objects_ids; + zval *implicit; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + if (Z_TYPE_P(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A valid collection instance is required"); + return; + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + PHALCON_OBS_VAR(implicit_objects_ids); + phalcon_read_property_this_quick(&implicit_objects_ids, this_ptr, SL("_implicitObjectsIds"), 1447589161UL, PH_NOISY_CC); + if (phalcon_array_isset(implicit_objects_ids, entity_name)) { + PHALCON_OBS_VAR(implicit); + phalcon_array_fetch(&implicit, implicit_objects_ids, entity_name, PH_NOISY); + RETURN_CCTOR(implicit); + } + + RETURN_MM_TRUE; } -// 2143 "parser.c" - break; - case 86: -// 927 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; - yy_destructor(49,&yymsp[-2].minor); - yy_destructor(50,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getConnection){ + + zval *model, *service = NULL, *connection_services; + zval *entity_name, *dependency_injector, *connection; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + if (Z_TYPE_P(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A valid collection instance is required"); + return; + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "mongo", 1); + + PHALCON_OBS_VAR(connection_services); + phalcon_read_property_this_quick(&connection_services, this_ptr, SL("_connectionServices"), 2904820280UL, PH_NOISY_CC); + if (Z_TYPE_P(connection_services) == IS_ARRAY) { + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + if (phalcon_array_isset(connection_services, entity_name)) { + PHALCON_OBS_NVAR(service); + phalcon_array_fetch(&service, connection_services, entity_name, PH_NOISY); + } + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); + return; + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_p1_key(connection, dependency_injector, "getshared", service, 1727570332UL); + if (Z_TYPE_P(connection) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid injected connection service"); + return; + } + + RETURN_CCTOR(connection); } -// 2152 "parser.c" - break; - case 89: -// 943 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_order_item(yymsp[0].minor.yy132, 0); -} -// 2159 "parser.c" - break; - case 90: -// 947 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_order_item(yymsp[-1].minor.yy132, PHQL_T_ASC); - yy_destructor(51,&yymsp[0].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, notifyEvent){ + + zval *event_name, *model, *status = NULL, *events_manager; + zval *fire_event_name = NULL, *custom_events_manager; + zval *entity_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &event_name, &model); + + PHALCON_INIT_VAR(status); + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_VAR(fire_event_name); + PHALCON_CONCAT_SV(fire_event_name, "collection:", event_name); + + phalcon_call_method_p2_key(status, events_manager, "fire", fire_event_name, model, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_CCTOR(status); + } + } + + PHALCON_OBS_VAR(custom_events_manager); + phalcon_read_property_this_quick(&custom_events_manager, this_ptr, SL("_customEventsManager"), 542727151UL, PH_NOISY_CC); + if (Z_TYPE_P(custom_events_manager) == IS_ARRAY) { + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(custom_events_manager, entity_name)) { + + PHALCON_INIT_NVAR(fire_event_name); + PHALCON_CONCAT_SV(fire_event_name, "collection:", event_name); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, custom_events_manager, "fire", fire_event_name, model, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_CCTOR(status); + } + } + } + + RETURN_CCTOR(status); } -// 2167 "parser.c" - break; - case 91: -// 951 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_order_item(yymsp[-1].minor.yy132, PHQL_T_DESC); - yy_destructor(52,&yymsp[0].minor); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Collection_ManagerInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Collection, ManagerInterface, mvc_collection_managerinterface, phalcon_mvc_collection_managerinterface_method_entry); + + return SUCCESS; } -// 2175 "parser.c" - break; - case 92: -// 957 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; - yy_destructor(53,&yymsp[-2].minor); - yy_destructor(50,&yymsp[-1].minor); + + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Collection){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc, Collection, mvc_collection, phalcon_mvc_collection_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_collection_ce, SL("_id"), ZEND_ACC_PUBLIC TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_ce, SL("_modelsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_ce, SL("_source"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_collection_ce, SL("_operationMade"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_ce, SL("_connection"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_ce, SL("_errorMessages"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_collection_ce, SL("_reserved"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_collection_ce, SL("_disableEvents"), 0, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + + zend_declare_class_constant_long(phalcon_mvc_collection_ce, SL("OP_NONE"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_collection_ce, SL("OP_CREATE"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_collection_ce, SL("OP_UPDATE"), 2 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_collection_ce, SL("OP_DELETE"), 3 TSRMLS_CC); + + zend_class_implements(phalcon_mvc_collection_ce TSRMLS_CC, 3, phalcon_mvc_collectioninterface_ce, phalcon_di_injectionawareinterface_ce, zend_ce_serializable); + + return SUCCESS; } -// 2184 "parser.c" - break; - case 96: -// 979 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; - yy_destructor(54,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, __construct){ + + zval *dependency_injector = NULL, *models_manager = NULL; + zval *service_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &dependency_injector, &models_manager); + + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); + } else { + PHALCON_SEPARATE_PARAM(dependency_injector); + } + + if (!models_manager) { + PHALCON_INIT_VAR(models_manager); + } else { + PHALCON_SEPARATE_PARAM(models_manager); + } + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_NVAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + } + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); + return; + } + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + + if (Z_TYPE_P(models_manager) != IS_OBJECT) { + + PHALCON_INIT_VAR(service_name); + ZVAL_STRING(service_name, "collectionManager", 1); + + PHALCON_INIT_NVAR(models_manager); + phalcon_call_method_p1_key(models_manager, dependency_injector, "getshared", service_name, 1727570332UL); + if (Z_TYPE_P(models_manager) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The injected service 'modelsManager' is not valid"); + return; + } + } + + phalcon_update_property_this_quick(this_ptr, SL("_modelsManager"), models_manager, 3699347875UL TSRMLS_CC); + + phalcon_call_method_p1_key(NULL, models_manager, "initialize", this_ptr, 2896075127UL); + + if (phalcon_method_quick_exists_ex(this_ptr, SS("onconstruct"), 564344039UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, this_ptr, "onconstruct", 564344039UL); + } + + PHALCON_MM_RESTORE(); } -// 2192 "parser.c" - break; - case 97: - case 100: -// 985 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_limit_clause(yymsp[0].minor.yy0, NULL); - yy_destructor(55,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, setId){ + + zval *id, *models_manager, *use_implicit_ids; + zval *mongo_id = NULL; + zend_class_entry *ce0; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &id); + + if (Z_TYPE_P(id) != IS_OBJECT) { + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(use_implicit_ids); + phalcon_call_method_p1_key(use_implicit_ids, models_manager, "isusingimplicitobjectids", this_ptr, 3521236505UL); + if (zend_is_true(use_implicit_ids)) { + ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + PHALCON_INIT_VAR(mongo_id); + object_init_ex(mongo_id, ce0); + if (phalcon_has_constructor(mongo_id TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, mongo_id, "__construct", id, 1107214344UL); + } + } else { + PHALCON_CPY_WRT(mongo_id, id); + } + } else { + PHALCON_CPY_WRT(mongo_id, id); + } + phalcon_update_property_this_quick(this_ptr, SL("_id"), mongo_id, 2090005265UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -// 2201 "parser.c" - break; - case 98: -// 989 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_limit_clause(yymsp[0].minor.yy0, yymsp[-2].minor.yy0); - yy_destructor(55,&yymsp[-3].minor); - yy_destructor(28,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, getId){ + + + RETURN_MEMBER_QUICK(this_ptr, "_id", 2090005265UL); } -// 2210 "parser.c" - break; - case 99: -// 993 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_limit_clause(yymsp[-2].minor.yy0, yymsp[0].minor.yy0); - yy_destructor(55,&yymsp[-3].minor); - yy_destructor(57,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + } -// 2219 "parser.c" - break; - case 101: -// 1005 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_MINUS, NULL, yymsp[0].minor.yy132); - yy_destructor(20,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -// 2227 "parser.c" - break; - case 102: -// 1009 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_SUB, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(20,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, setEventsManager){ + + zval *events_manager, *models_manager; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &events_manager); + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, models_manager, "setcustomeventsmanager", this_ptr, events_manager, 3062798396UL); + + PHALCON_MM_RESTORE(); } -// 2235 "parser.c" - break; - case 103: -// 1013 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_ADD, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(19,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, getEventsManager){ + + zval *models_manager; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, models_manager, "getcustomeventsmanager", this_ptr, 1410017072UL); + RETURN_MM(); } -// 2243 "parser.c" - break; - case 104: -// 1017 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_MUL, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(17,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, getModelsManager){ + + + RETURN_MEMBER_QUICK(this_ptr, "_modelsManager", 3699347875UL); } -// 2251 "parser.c" - break; - case 105: -// 1021 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_DIV, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(16,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, getReservedAttributes){ + + zval *reserved = NULL, *dummy; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(reserved); + phalcon_read_static_property(&reserved, SL("phalcon\\mvc\\collection"), SL("_reserved") TSRMLS_CC); + if (Z_TYPE_P(reserved) == IS_NULL) { + PHALCON_INIT_VAR(dummy); + ZVAL_BOOL(dummy, 1); + + PHALCON_INIT_NVAR(reserved); + array_init_size(reserved, 5); + phalcon_array_update_quick_string(&reserved, SS("_connection"), 3057302292UL, &dummy, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&reserved, SS("_dependencyInjector"), 765199457UL, &dummy, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&reserved, SS("_source"), 3355220565UL, &dummy, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&reserved, SS("_operationMade"), 3968152972UL, &dummy, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&reserved, SS("_errorMessages"), 1019066246UL, &dummy, PH_COPY | PH_SEPARATE); + phalcon_update_static_property(SL("phalcon\\mvc\\collection"), SL("_reserved"), reserved TSRMLS_CC); + } + + RETURN_CCTOR(reserved); } -// 2259 "parser.c" - break; - case 106: -// 1025 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_MOD, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(18,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, useImplicitObjectIds){ + + zval *use_implicit_object_ids, *models_manager; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &use_implicit_object_ids); + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, models_manager, "useimplicitobjectids", this_ptr, use_implicit_object_ids, 1206425092UL); + + PHALCON_MM_RESTORE(); } -// 2267 "parser.c" - break; - case 107: -// 1029 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_AND, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(9,&yymsp[-1].minor); + +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(); } -// 2275 "parser.c" - break; - case 108: -// 1033 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_OR, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(10,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, getSource){ + + zval *source = NULL, *class_name; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(source); + phalcon_read_property_this_quick(&source, this_ptr, SL("_source"), 3355220565UL, PH_NOISY_CC); + 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_CCTOR(source); } -// 2283 "parser.c" - break; - case 109: -// 1037 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_BITWISE_AND, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(13,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, setConnectionService){ + + zval *connection_service, *models_manager; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &connection_service); + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, models_manager, "setconnectionservice", this_ptr, connection_service, 4052304818UL); + RETURN_THIS(); } -// 2291 "parser.c" - break; - case 110: -// 1041 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_BITWISE_OR, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(14,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, getConnectionService){ + + zval *models_manager; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, models_manager, "getconnectionservice", this_ptr, 619546022UL); + RETURN_MM(); } -// 2299 "parser.c" - break; - case 111: -// 1045 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_BITWISE_XOR, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(15,&yymsp[-1].minor); + +static PHP_METHOD(Phalcon_Mvc_Collection, getConnection){ + + zval *connection = NULL, *models_manager; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(connection); + phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + if (Z_TYPE_P(connection) != IS_OBJECT) { + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(connection); + phalcon_call_method_p1_key(connection, models_manager, "getconnection", this_ptr, 2504689909UL); + phalcon_update_property_this_quick(this_ptr, SL("_connection"), connection, 3057302292UL TSRMLS_CC); + } + + RETURN_CCTOR(connection); } -// 2307 "parser.c" - break; - case 112: -// 1049 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_EQUALS, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(3,&yymsp[-1].minor); -} -// 2315 "parser.c" - break; - case 113: -// 1053 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_NOTEQUALS, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(4,&yymsp[-1].minor); -} -// 2323 "parser.c" - break; - case 114: -// 1057 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_LESS, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(5,&yymsp[-1].minor); -} -// 2331 "parser.c" - break; - case 115: -// 1061 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_GREATER, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(6,&yymsp[-1].minor); -} -// 2339 "parser.c" - break; - case 116: -// 1065 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_GREATEREQUAL, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(7,&yymsp[-1].minor); -} -// 2347 "parser.c" - break; - case 117: -// 1069 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_LESSEQUAL, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(8,&yymsp[-1].minor); -} -// 2355 "parser.c" - break; - case 118: -// 1073 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_LIKE, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(11,&yymsp[-1].minor); -} -// 2363 "parser.c" - break; - case 119: -// 1077 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_NLIKE, yymsp[-3].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(24,&yymsp[-2].minor); - yy_destructor(11,&yymsp[-1].minor); -} -// 2372 "parser.c" - break; - case 120: -// 1081 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_ILIKE, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(12,&yymsp[-1].minor); -} -// 2380 "parser.c" - break; - case 121: -// 1085 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_NILIKE, yymsp[-3].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(24,&yymsp[-2].minor); - yy_destructor(12,&yymsp[-1].minor); -} -// 2389 "parser.c" - break; - case 122: -// 1089 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_IN, yymsp[-4].minor.yy132, yymsp[-1].minor.yy132); - yy_destructor(22,&yymsp[-3].minor); - yy_destructor(43,&yymsp[-2].minor); - yy_destructor(44,&yymsp[0].minor); -} -// 2399 "parser.c" - break; - case 123: -// 1093 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_NOTIN, yymsp[-5].minor.yy132, yymsp[-1].minor.yy132); - yy_destructor(24,&yymsp[-4].minor); - yy_destructor(22,&yymsp[-3].minor); - yy_destructor(43,&yymsp[-2].minor); - yy_destructor(44,&yymsp[0].minor); -} -// 2410 "parser.c" - break; - case 124: -// 1097 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_AGAINST, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(1,&yymsp[-1].minor); -} -// 2418 "parser.c" - break; - case 125: -// 1101 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_CAST, yymsp[-3].minor.yy132, phql_ret_raw_qualified_name(yymsp[-1].minor.yy0, NULL)); - yy_destructor(58,&yymsp[-5].minor); - yy_destructor(43,&yymsp[-4].minor); - yy_destructor(31,&yymsp[-2].minor); - yy_destructor(44,&yymsp[0].minor); -} -// 2429 "parser.c" - break; - case 126: -// 1105 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_CONVERT, yymsp[-3].minor.yy132, phql_ret_raw_qualified_name(yymsp[-1].minor.yy0, NULL)); - yy_destructor(59,&yymsp[-5].minor); - yy_destructor(43,&yymsp[-4].minor); - yy_destructor(60,&yymsp[-2].minor); - yy_destructor(44,&yymsp[0].minor); -} -// 2440 "parser.c" - break; - case 128: -// 1115 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_func_call(yymsp[-3].minor.yy0, yymsp[-1].minor.yy132); - yy_destructor(43,&yymsp[-2].minor); - yy_destructor(44,&yymsp[0].minor); -} -// 2449 "parser.c" - break; - case 129: -// 1119 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_func_call(yymsp[-2].minor.yy0, NULL); - yy_destructor(43,&yymsp[-1].minor); - yy_destructor(44,&yymsp[0].minor); -} -// 2458 "parser.c" - break; - case 131: -// 1129 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_zval_list(yymsp[0].minor.yy132, NULL); -} -// 2465 "parser.c" - break; - case 134: -// 1143 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_ISNULL, yymsp[-2].minor.yy132, NULL); - yy_destructor(21,&yymsp[-1].minor); - yy_destructor(61,&yymsp[0].minor); -} -// 2474 "parser.c" - break; - case 135: -// 1147 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_ISNOTNULL, yymsp[-3].minor.yy132, NULL); - yy_destructor(21,&yymsp[-2].minor); - yy_destructor(24,&yymsp[-1].minor); - yy_destructor(61,&yymsp[0].minor); -} -// 2484 "parser.c" - break; - case 136: -// 1151 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_DISTINCT, NULL, yymsp[0].minor.yy132); - yy_destructor(23,&yymsp[-1].minor); -} -// 2492 "parser.c" - break; - case 137: -// 1155 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_BETWEEN, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); - yy_destructor(2,&yymsp[-1].minor); -} -// 2500 "parser.c" - break; - case 138: -// 1159 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_NOT, NULL, yymsp[0].minor.yy132); - yy_destructor(24,&yymsp[-1].minor); -} -// 2508 "parser.c" - break; - case 139: -// 1163 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_BITWISE_NOT, NULL, yymsp[0].minor.yy132); - yy_destructor(25,&yymsp[-1].minor); -} -// 2516 "parser.c" - break; - case 140: -// 1167 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_expr(PHQL_T_ENCLOSED, yymsp[-1].minor.yy132, NULL); - yy_destructor(43,&yymsp[-2].minor); - yy_destructor(44,&yymsp[0].minor); -} -// 2525 "parser.c" - break; - case 142: -// 1175 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_INTEGER, yymsp[0].minor.yy0); -} -// 2532 "parser.c" - break; - case 143: -// 1179 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_STRING, yymsp[0].minor.yy0); -} -// 2539 "parser.c" - break; - case 144: -// 1183 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_DOUBLE, yymsp[0].minor.yy0); -} -// 2546 "parser.c" - break; - case 145: -// 1187 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_NULL, NULL); - yy_destructor(61,&yymsp[0].minor); -} -// 2554 "parser.c" - break; - case 146: -// 1191 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_TRUE, NULL); - yy_destructor(64,&yymsp[0].minor); -} -// 2562 "parser.c" - break; - case 147: -// 1195 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_FALSE, NULL); - yy_destructor(65,&yymsp[0].minor); -} -// 2570 "parser.c" - break; - case 148: -// 1199 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_placeholder_zval(PHQL_T_NPLACEHOLDER, yymsp[0].minor.yy0); -} -// 2577 "parser.c" - break; - case 149: -// 1203 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_placeholder_zval(PHQL_T_SPLACEHOLDER, yymsp[0].minor.yy0); -} -// 2584 "parser.c" - break; - case 150: -// 1209 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_qualified_name(yymsp[-4].minor.yy0, yymsp[-2].minor.yy0, yymsp[0].minor.yy0); - yy_destructor(68,&yymsp[-3].minor); - yy_destructor(30,&yymsp[-1].minor); -} -// 2593 "parser.c" - break; - case 151: -// 1213 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_qualified_name(yymsp[-2].minor.yy0, NULL, yymsp[0].minor.yy0); - yy_destructor(68,&yymsp[-1].minor); -} -// 2601 "parser.c" - break; - case 152: -// 1217 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_qualified_name(NULL, yymsp[-2].minor.yy0, yymsp[0].minor.yy0); - yy_destructor(30,&yymsp[-1].minor); -} -// 2609 "parser.c" - break; - }; - yygoto = yyRuleInfo[yyruleno].lhs; - yysize = yyRuleInfo[yyruleno].nrhs; - yypParser->yyidx -= yysize; - yyact = yy_find_reduce_action(yypParser,yygoto); - if( yyact < YYNSTATE ){ - yy_shift(yypParser,yyact,yygoto,&yygotominor); - }else if( yyact == YYNSTATE + YYNRULE + 1 ){ - yy_accept(yypParser); - } + +static PHP_METHOD(Phalcon_Mvc_Collection, readAttribute){ + + zval *attribute, *attribute_value; + + 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_CC); + RETURN_CCTOR(attribute_value); + } + RETURN_MM_NULL(); } -static void yy_parse_failed( - yyParser *yypParser /* The parser */ -){ - phql_ARG_FETCH; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); - } -#endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will be executed whenever the - ** parser fails */ - phql_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} +static PHP_METHOD(Phalcon_Mvc_Collection, writeAttribute){ -static void yy_syntax_error( - yyParser *yypParser, /* The parser */ - int yymajor, /* The major type of the error token */ - YYMINORTYPE yyminor /* The minor type of the error token */ -){ - phql_ARG_FETCH; -#define TOKEN (yyminor.yy0) -// 446 "parser.lemon" + zval *attribute, *value; - if (status->scanner_state->start_length) { - { + phalcon_fetch_params(0, 2, 0, &attribute, &value); + + phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); + +} - char *token_name = NULL; - int token_found = 0; - unsigned int token_length; - const phql_token_names *tokens = phql_tokens; - int active_token = status->scanner_state->active_token; - int near_length = status->scanner_state->start_length; +static PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ - if (active_token) { + zval *collection, *document, *cloned_collection; + zval *value = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - do { - if (tokens->code == active_token) { - token_name = tokens->name; - token_length = tokens->length; - token_found = 1; - break; - } - ++tokens; - } while (tokens[0].code != 0); + 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) { + 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; + } + + 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_p2_key(NULL, cloned_collection, "writeattribute", key, value, 3716971876UL); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_CCTOR(cloned_collection); +} - if (!token_name) { - token_length = strlen("UNKNOWN"); - token_name = estrndup("UNKNOWN", token_length); - token_found = 0; - } +static PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ - status->syntax_error_len = 96 + status->token->len + token_length + near_length + status->phql_length;; - status->syntax_error = emalloc(sizeof(char) * status->syntax_error_len); + zval *params, *collection, *connection, *unique; + zval *source, *mongo_collection, *conditions = NULL; + zval *fields, *documents_cursor = NULL, *limit, *sort = NULL; + zval *base = NULL, *document = NULL, *collections, *documents_array; + zval *collection_cloned = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - if (near_length > 0) { - if (status->token->value) { - snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), near to '%s', when parsing: %s (%d)", token_name, status->token->value, status->scanner_state->start, status->phql, status->phql_length); - } else { - snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, near to '%s', when parsing: %s (%d)", token_name, status->scanner_state->start, status->phql, status->phql_length); - } - } else { - if (active_token != PHQL_T_IGNORE) { - if (status->token->value) { - snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), at the end of query, when parsing: %s (%d)", token_name, status->token->value, status->phql, status->phql_length); - } else { - snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, at the end of query, when parsing: %s (%d)", token_name, status->phql, status->phql_length); - } - } else { - snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected EOF, at the end of query"); - } - status->syntax_error[status->syntax_error_len - 1] = '\0'; - } + PHALCON_MM_GROW(); - if (!token_found) { - if (token_name) { - efree(token_name); - } - } + phalcon_fetch_params(1, 4, 0, ¶ms, &collection, &connection, &unique); + + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, collection, "getsource", 2025234358UL); + if (PHALCON_IS_EMPTY(source)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); + return; + } + + PHALCON_INIT_VAR(mongo_collection); + phalcon_call_method_p1_key(mongo_collection, connection, "selectcollection", source, 3563037297UL); + + if (phalcon_array_isset_long(params, 0)) { + PHALCON_OBS_VAR(conditions); + phalcon_array_fetch_long(&conditions, params, 0, PH_NOISY); + } else { + if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_NVAR(conditions); + phalcon_array_fetch_quick_string(&conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(conditions); + array_init(conditions); } + } + + 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_INIT_VAR(documents_cursor); + phalcon_call_method_p2_key(documents_cursor, mongo_collection, "find", conditions, fields, 259012646UL); } else { - status->syntax_error_len = strlen("Syntax error, unexpected EOF"); - status->syntax_error = estrndup("Syntax error, unexpected EOF", status->syntax_error_len); + PHALCON_INIT_NVAR(documents_cursor); + phalcon_call_method_p1_key(documents_cursor, mongo_collection, "find", conditions, 259012646UL); } - - status->status = PHQL_PARSING_FAILED; - -// 2718 "parser.c" - phql_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -static void yy_accept( - yyParser *yypParser /* The parser */ -){ - phql_ARG_FETCH; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); - } -#endif - while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); - /* Here code is inserted which will be executed whenever the - ** parser accepts */ - phql_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -/* The main parser program. -** The first argument is a pointer to a structure obtained from -** "phql_Alloc" which describes the current state of the parser. -** The second argument is the major token number. The third is -** the minor token. The fourth optional argument is whatever the -** user wants (and specified in the grammar) and is available for -** use by the action routines. -** -** Inputs: -**
    -**
  • A pointer to the parser (an opaque structure.) -**
  • The major token number. -**
  • The minor token number. -**
  • An option argument of a grammar-specified type. -**
-** -** Outputs: -** None. -*/ -static void phql_( - void *yyp, /* The parser */ - int yymajor, /* The major token code number */ - phql_TOKENTYPE yyminor /* The value for the token */ - phql_ARG_PDECL /* Optional %extra_argument parameter */ -){ - YYMINORTYPE yyminorunion; - int yyact; /* The parser action. */ - int yyendofinput; /* True if we are at the end of input */ - int yyerrorhit = 0; /* True if yymajor has invoked an error */ - yyParser *yypParser; /* The parser */ - - /* (re)initialize the parser, if necessary */ - yypParser = (yyParser*)yyp; - if( yypParser->yyidx<0 ){ - if( yymajor==0 ) return; - yypParser->yyidx = 0; - yypParser->yyerrcnt = -1; - yypParser->yystack[0].stateno = 0; - yypParser->yystack[0].major = 0; - } - yyminorunion.yy0 = yyminor; - yyendofinput = (yymajor==0); - phql_ARG_STORE; - -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); - } -#endif - - do{ - yyact = yy_find_shift_action(yypParser,yymajor); - if( yyactyyerrcnt--; - if( yyendofinput && yypParser->yyidx>=0 ){ - yymajor = 0; - }else{ - yymajor = YYNOCODE; - } - }else if( yyact < YYNSTATE + YYNRULE ){ - yy_reduce(yypParser,yyact-YYNSTATE); - }else if( yyact == YY_ERROR_ACTION ){ - int yymx; -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); - } -#endif -#ifdef YYERRORSYMBOL - /* A syntax error has occurred. - ** The response to an error depends upon whether or not the - ** grammar defines an error token "ERROR". - ** - ** This is what we do if the grammar does define ERROR: - ** - ** * Call the %syntax_error function. - ** - ** * Begin popping the stack until we enter a state where - ** it is legal to shift the error symbol, then shift - ** the error symbol. - ** - ** * Set the error count to three. - ** - ** * Begin accepting and shifting new tokens. No new error - ** processing will occur until three tokens have been - ** shifted successfully. - ** - */ - if( yypParser->yyerrcnt<0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); - } - yymx = yypParser->yystack[yypParser->yyidx].major; - if( yymx==YYERRORSYMBOL || yyerrorhit ){ -#ifndef NDEBUG - if( yyTraceFILE ){ - fprintf(yyTraceFILE,"%sDiscard input token %s\n", - yyTracePrompt,yyTokenName[yymajor]); - } -#endif - yy_destructor(yymajor,&yyminorunion); - yymajor = YYNOCODE; - }else{ - while( - yypParser->yyidx >= 0 && - yymx != YYERRORSYMBOL && - (yyact = yy_find_shift_action(yypParser,YYERRORSYMBOL)) >= YYNSTATE - ){ - yy_pop_parser_stack(yypParser); - } - if( yypParser->yyidx < 0 || yymajor==0 ){ - yy_destructor(yymajor,&yyminorunion); - yy_parse_failed(yypParser); - yymajor = YYNOCODE; - }else if( yymx!=YYERRORSYMBOL ){ - YYMINORTYPE u2; - u2.YYERRSYMDT = 0; - yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); - } - } - yypParser->yyerrcnt = 3; - yyerrorhit = 1; -#else /* YYERRORSYMBOL is not defined */ - /* This is what we do if the grammar does not define ERROR: - ** - ** * Report an error message, and throw away the input token. - ** - ** * If the input token is $, then fail the parse. - ** - ** As before, subsequent error messages are suppressed until - ** three input tokens have been successfully shifted. - */ - if( yypParser->yyerrcnt<=0 ){ - yy_syntax_error(yypParser,yymajor,yyminorunion); - } - yypParser->yyerrcnt = 3; - yy_destructor(yymajor,&yyminorunion); - if( yyendofinput ){ - yy_parse_failed(yypParser); - } - yymajor = YYNOCODE; -#endif - }else{ - yy_accept(yypParser); - yymajor = YYNOCODE; - } - }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); - return; -} - - -const phql_token_names phql_tokens[] = -{ - { SL("INTEGER"), PHQL_T_INTEGER }, - { SL("DOUBLE"), PHQL_T_DOUBLE }, - { SL("STRING"), PHQL_T_STRING }, - { SL("IDENTIFIER"), PHQL_T_IDENTIFIER }, - { SL("MINUS"), PHQL_T_MINUS }, - { SL("+"), PHQL_T_ADD }, - { SL("-"), PHQL_T_SUB }, - { SL("*"), PHQL_T_MUL }, - { SL("/"), PHQL_T_DIV }, - { SL("&"), PHQL_T_BITWISE_AND }, - { SL("|"), PHQL_T_BITWISE_OR }, - { SL("%%"), PHQL_T_MOD }, - { SL("AND"), PHQL_T_AND }, - { SL("OR"), PHQL_T_OR }, - { SL("LIKE"), PHQL_T_LIKE }, - { SL("ILIKE"), PHQL_T_ILIKE }, - { SL("DOT"), PHQL_T_DOT }, - { SL("COLON"), PHQL_T_COLON }, - { SL("COMMA"), PHQL_T_COMMA }, - { SL("EQUALS"), PHQL_T_EQUALS }, - { SL("NOT EQUALS"), PHQL_T_NOTEQUALS }, - { SL("NOT"), PHQL_T_NOT }, - { SL("<"), PHQL_T_LESS }, - { SL("<="), PHQL_T_LESSEQUAL }, - { SL(">"), PHQL_T_GREATER }, - { SL(">="), PHQL_T_GREATEREQUAL }, - { SL("("), PHQL_T_PARENTHESES_OPEN }, - { SL(")"), PHQL_T_PARENTHESES_CLOSE }, - { SL("NUMERIC PLACEHOLDER"), PHQL_T_NPLACEHOLDER }, - { SL("STRING PLACEHOLDER"), PHQL_T_SPLACEHOLDER }, - { SL("UPDATE"), PHQL_T_UPDATE }, - { SL("SET"), PHQL_T_SET }, - { SL("WHERE"), PHQL_T_WHERE }, - { SL("DELETE"), PHQL_T_DELETE }, - { SL("FROM"), PHQL_T_FROM }, - { SL("AS"), PHQL_T_AS }, - { SL("INSERT"), PHQL_T_INSERT }, - { SL("INTO"), PHQL_T_INTO }, - { SL("VALUES"), PHQL_T_VALUES }, - { SL("SELECT"), PHQL_T_SELECT }, - { SL("ORDER"), PHQL_T_ORDER }, - { SL("BY"), PHQL_T_BY }, - { SL("LIMIT"), PHQL_T_LIMIT }, - { SL("OFFSET"), PHQL_T_OFFSET }, - { SL("GROUP"), PHQL_T_GROUP }, - { SL("HAVING"), PHQL_T_HAVING }, - { SL("IN"), PHQL_T_IN }, - { SL("ON"), PHQL_T_ON }, - { SL("INNER"), PHQL_T_INNER }, - { SL("JOIN"), PHQL_T_JOIN }, - { SL("LEFT"), PHQL_T_LEFT }, - { SL("RIGHT"), PHQL_T_RIGHT }, - { SL("IS"), PHQL_T_IS }, - { SL("NULL"), PHQL_T_NULL }, - { SL("NOT IN"), PHQL_T_NOTIN }, - { SL("CROSS"), PHQL_T_CROSS }, - { SL("OUTER"), PHQL_T_OUTER }, - { SL("FULL"), PHQL_T_FULL }, - { SL("ASC"), PHQL_T_ASC }, - { SL("DESC"), PHQL_T_DESC }, - { SL("BETWEEN"), PHQL_T_BETWEEN }, - { SL("DISTINCT"), PHQL_T_DISTINCT }, - { SL("AGAINST"), PHQL_T_AGAINST }, - { SL("CAST"), PHQL_T_CAST }, - { SL("CONVERT"), PHQL_T_CONVERT }, - { SL("USING"), PHQL_T_USING }, - { NULL, 0, 0 } -}; - -static void *phql_wrapper_alloc(size_t bytes){ - return emalloc(bytes); -} - -static void phql_wrapper_free(void *pointer){ - efree(pointer); + + 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_p1_key(NULL, documents_cursor, "limit", limit, 192268420UL); + } + + 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_p1_key(NULL, documents_cursor, "sort", sort, 274650125UL); + } + + 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_p1_key(NULL, documents_cursor, "skip", sort, 274496444UL); + } + + 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_key(NULL, documents_cursor, "rewind", 1064078190UL); + + PHALCON_INIT_VAR(document); + phalcon_call_method_key(document, documents_cursor, "current", 431662984UL); + if (Z_TYPE_P(document) == IS_ARRAY) { + PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "cloneresult", base, document); + RETURN_MM(); + } + + RETURN_MM_FALSE; + } + + PHALCON_INIT_VAR(collections); + array_init(collections); + + PHALCON_INIT_VAR(documents_array); + phalcon_call_func_p1(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_INIT_NVAR(collection_cloned); + PHALCON_CALL_SELF_PARAMS_2(collection_cloned, this_ptr, "cloneresult", base, document); + phalcon_array_append(&collections, collection_cloned, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_CTOR(collections); } -static void phql_parse_with_token(void* phql_parser, int opcode, int parsercode, phql_scanner_token *token, phql_parser_status *parser_status){ - - phql_parser_token *pToken; - - pToken = emalloc(sizeof(phql_parser_token)); - pToken->opcode = opcode; - pToken->token = token->value; - pToken->token_len = token->len; - pToken->free_flag = 1; - phql_(phql_parser, parsercode, pToken, parser_status); - - token->value = NULL; - token->len = 0; -} +static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ -static void phql_scanner_error_msg(phql_parser_status *parser_status, zval **error_msg TSRMLS_DC){ + zval *params, *collection, *connection, *source; + zval *mongo_collection, *conditions = NULL, *simple = NULL; + zval *documents_cursor, *limit, *sort = NULL; - char *error = NULL, *error_part; - unsigned int length; - phql_scanner_state *state = parser_status->scanner_state; + PHALCON_MM_GROW(); - PHALCON_INIT_VAR(*error_msg); - if (state->start) { - length = 64 + state->start_length + parser_status->phql_length; - error = emalloc(sizeof(char) * length); - if (state->start_length > 16) { - error_part = estrndup(state->start, 16); - snprintf(error, length, "Scanning error before '%s...' when parsing: %s (%d)", error_part, parser_status->phql, parser_status->phql_length); - efree(error_part); + phalcon_fetch_params(1, 3, 0, ¶ms, &collection, &connection); + + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, collection, "getsource", 2025234358UL); + if (PHALCON_IS_EMPTY(source)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); + return; + } + + PHALCON_INIT_VAR(mongo_collection); + phalcon_call_method_p1_key(mongo_collection, connection, "selectcollection", source, 3563037297UL); + + if (phalcon_array_isset_long(params, 0)) { + PHALCON_OBS_VAR(conditions); + phalcon_array_fetch_long(&conditions, params, 0, PH_NOISY); + } else { + if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_NVAR(conditions); + phalcon_array_fetch_quick_string(&conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); } else { - snprintf(error, length, "Scanning error before '%s' when parsing: %s (%d)", state->start, parser_status->phql, parser_status->phql_length); + PHALCON_INIT_NVAR(conditions); + array_init(conditions); } - error[length - 1] = '\0'; - ZVAL_STRING(*error_msg, error, 1); + } + + PHALCON_INIT_VAR(simple); + ZVAL_BOOL(simple, 1); + if (phalcon_array_isset_quick_string(params, SS("limit"), 192268420UL)) { + ZVAL_BOOL(simple, 0); } else { - ZVAL_STRING(*error_msg, "Scanning error near to EOF", 1); + if (phalcon_array_isset_quick_string(params, SS("sort"), 274650125UL)) { + PHALCON_INIT_NVAR(simple); + ZVAL_BOOL(simple, 0); + } else { + if (phalcon_array_isset_quick_string(params, SS("skip"), 274496444UL)) { + PHALCON_INIT_NVAR(simple); + ZVAL_BOOL(simple, 0); + } + } } - - if (error) { - efree(error); + + if (PHALCON_IS_FALSE(simple)) { + + PHALCON_INIT_VAR(documents_cursor); + phalcon_call_method_p1_key(documents_cursor, mongo_collection, "find", conditions, 259012646UL); + + 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_p1_key(NULL, documents_cursor, "limit", limit, 192268420UL); + } + + 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_p1_key(NULL, documents_cursor, "sort", sort, 274650125UL); + } + + 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_p1_key(NULL, documents_cursor, "skip", sort, 274496444UL); + } + + phalcon_fast_count(return_value, documents_cursor TSRMLS_CC); + RETURN_MM(); } + + phalcon_call_method_p1_key(return_value, mongo_collection, "count", conditions, 4142425646UL); + RETURN_MM(); } -static int phql_parse_phql(zval *result, zval *phql TSRMLS_DC) { +static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ - zval *error_msg = NULL; + zval *dependency_injector, *disable_events; + zval *exists, *event_name = NULL, *status = NULL; - ZVAL_NULL(result); + PHALCON_MM_GROW(); - if (phql_internal_parse_phql(&result, Z_STRVAL_P(phql), Z_STRLEN_P(phql), &error_msg TSRMLS_CC) == FAILURE) { - phalcon_throw_exception_string(phalcon_mvc_model_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC); - return FAILURE; + 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_INIT_VAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + + if (!zend_is_true(exists)) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "beforeValidationOnCreate", 1); + } else { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "beforeValidationOnUpdate", 1); + } + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } } - - return SUCCESS; -} - -static int phql_internal_parse_phql(zval **result, char *phql, unsigned int phql_length, zval **error_msg TSRMLS_DC) { - - zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL; - phql_parser_status *parser_status = NULL; - int scanner_status, status = SUCCESS, error_length; - phql_scanner_state *state; - phql_scanner_token token; - unsigned long phql_key; - void* phql_parser; - char *error; - zval **temp_ast; - - if (!phql) { - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, "PHQL statement cannot be NULL", 1); - return FAILURE; + + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "validation", 1); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + if (!zend_is_true(disable_events)) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "onValidationFails", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + } + RETURN_MM_FALSE; } - - if (phalcon_globals_ptr->orm.cache_level >= 0) { - - phql_key = zend_inline_hash_func(phql, phql_length + 1); - - if (phalcon_globals_ptr->orm.parser_cache != NULL) { - if (zend_hash_index_find(phalcon_globals_ptr->orm.parser_cache, phql_key, (void**) &temp_ast) == SUCCESS) { - ZVAL_ZVAL(*result, *temp_ast, 1, 0); - Z_SET_REFCOUNT_P(*result, 1); - return SUCCESS; - } + + if (!zend_is_true(disable_events)) { + + if (!zend_is_true(exists)) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "afterValidationOnCreate", 1); + } else { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "afterValidationOnUpdate", 1); + } + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "afterValidation", 1); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "beforeSave", 1); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + + if (zend_is_true(exists)) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "beforeUpdate", 1); + } else { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "beforeCreate", 1); + } + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; } } + + RETURN_MM_TRUE; +} - phql_parser = phql_Alloc(phql_wrapper_alloc); +static PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ - parser_status = emalloc(sizeof(phql_parser_status)); - state = emalloc(sizeof(phql_scanner_state)); + zval *disable_events, *success, *exists, *event_name = NULL; - parser_status->status = PHQL_PARSING_OK; - parser_status->scanner_state = state; - parser_status->ret = NULL; - parser_status->syntax_error = NULL; - parser_status->token = &token; - parser_status->enable_literals = phalcon_globals_ptr->orm.enable_literals; - parser_status->phql = phql; - parser_status->phql_length = phql_length; + PHALCON_MM_GROW(); - state->active_token = 0; - state->start = phql; - state->start_length = 0; - state->end = state->start; - - token.value = NULL; - token.len = 0; + 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)) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "afterUpdate", 1); + } else { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "afterCreate", 1); + } + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "afterSave", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + } + + RETURN_CCTOR(success); + } + if (!zend_is_true(disable_events)) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "notSave", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + } + + phalcon_call_method_p1_key(NULL, this_ptr, "_canceloperation", disable_events, 1716493051UL); + RETURN_MM_FALSE; +} - while (0 <= (scanner_status = phql_get_token(state, &token))) { +static PHP_METHOD(Phalcon_Mvc_Collection, validate){ - /* Calculate the 'start' length */ - state->start_length = (phql + phql_length - state->start); + zval *validator, *status, *messages, *message = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - state->active_token = token.opcode; + PHALCON_MM_GROW(); - /* Parse the token found */ - switch (token.opcode) { + phalcon_fetch_params(1, 1, 0, &validator); + + if (Z_TYPE_P(validator) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Validator must be an Object"); + return; + } + + PHALCON_INIT_VAR(status); + phalcon_call_method_p1_key(status, validator, "validate", this_ptr, 2654098287UL); + if (PHALCON_IS_FALSE(status)) { + + PHALCON_INIT_VAR(messages); + phalcon_call_method_key(messages, validator, "getmessages", 4087333309UL); + + 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(); +} - case PHQL_T_IGNORE: - break; +static PHP_METHOD(Phalcon_Mvc_Collection, validationHasFailed){ - case PHQL_T_ADD: - phql_(phql_parser, PHQL_PLUS, NULL, parser_status); - break; - case PHQL_T_SUB: - phql_(phql_parser, PHQL_MINUS, NULL, parser_status); - break; - case PHQL_T_MUL: - phql_(phql_parser, PHQL_TIMES, NULL, parser_status); - break; - case PHQL_T_DIV: - phql_(phql_parser, PHQL_DIVIDE, NULL, parser_status); - break; - case PHQL_T_MOD: - phql_(phql_parser, PHQL_MOD, NULL, parser_status); - break; - case PHQL_T_AND: - phql_(phql_parser, PHQL_AND, NULL, parser_status); - break; - case PHQL_T_OR: - phql_(phql_parser, PHQL_OR, NULL, parser_status); - break; - case PHQL_T_EQUALS: - phql_(phql_parser, PHQL_EQUALS, NULL, parser_status); - break; - case PHQL_T_NOTEQUALS: - phql_(phql_parser, PHQL_NOTEQUALS, NULL, parser_status); - break; - case PHQL_T_LESS: - phql_(phql_parser, PHQL_LESS, NULL, parser_status); - break; - case PHQL_T_GREATER: - phql_(phql_parser, PHQL_GREATER, NULL, parser_status); - break; - case PHQL_T_GREATEREQUAL: - phql_(phql_parser, PHQL_GREATEREQUAL, NULL, parser_status); - break; - case PHQL_T_LESSEQUAL: - phql_(phql_parser, PHQL_LESSEQUAL, NULL, parser_status); - break; - case PHQL_T_LIKE: - phql_(phql_parser, PHQL_LIKE, NULL, parser_status); - break; - case PHQL_T_ILIKE: - phql_(phql_parser, PHQL_ILIKE, NULL, parser_status); - break; - case PHQL_T_NOT: - phql_(phql_parser, PHQL_NOT, NULL, parser_status); - break; - case PHQL_T_BITWISE_AND: - phql_(phql_parser, PHQL_BITWISE_AND, NULL, parser_status); - break; - case PHQL_T_BITWISE_OR: - phql_(phql_parser, PHQL_BITWISE_OR, NULL, parser_status); - break; - case PHQL_T_BITWISE_NOT: - phql_(phql_parser, PHQL_BITWISE_NOT, NULL, parser_status); - break; - case PHQL_T_BITWISE_XOR: - phql_(phql_parser, PHQL_BITWISE_XOR, NULL, parser_status); - break; - case PHQL_T_AGAINST: - phql_(phql_parser, PHQL_AGAINST, NULL, parser_status); - break; - case PHQL_T_DOT: - phql_(phql_parser, PHQL_DOT, NULL, parser_status); - break; - case PHQL_T_COLON: - phql_(phql_parser, PHQL_COLON, NULL, parser_status); - break; - case PHQL_T_COMMA: - phql_(phql_parser, PHQL_COMMA, NULL, parser_status); - break; + zval *error_messages; - case PHQL_T_PARENTHESES_OPEN: - phql_(phql_parser, PHQL_PARENTHESES_OPEN, NULL, parser_status); - break; - case PHQL_T_PARENTHESES_CLOSE: - phql_(phql_parser, PHQL_PARENTHESES_CLOSE, NULL, parser_status); - break; + PHALCON_MM_GROW(); - case PHQL_T_INTEGER: - if (parser_status->enable_literals) { - phql_parse_with_token(phql_parser, PHQL_T_INTEGER, PHQL_INTEGER, &token, parser_status); - } else { - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, "Literals are disabled in PHQL statements", 1); - parser_status->status = PHQL_PARSING_FAILED; - } - break; - case PHQL_T_DOUBLE: - if (parser_status->enable_literals) { - phql_parse_with_token(phql_parser, PHQL_T_DOUBLE, PHQL_DOUBLE, &token, parser_status); - } else { - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, "Literals are disabled in PHQL statements", 1); - parser_status->status = PHQL_PARSING_FAILED; - } - break; - case PHQL_T_STRING: - if (parser_status->enable_literals) { - phql_parse_with_token(phql_parser, PHQL_T_STRING, PHQL_STRING, &token, parser_status); - } else { - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, "Literals are disabled in PHQL statements", 1); - parser_status->status = PHQL_PARSING_FAILED; - } - break; - case PHQL_T_TRUE: - if (parser_status->enable_literals) { - phql_(phql_parser, PHQL_TRUE, NULL, parser_status); - } else { - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, "Literals are disabled in PHQL statements", 1); - parser_status->status = PHQL_PARSING_FAILED; - } - break; - case PHQL_T_FALSE: - if (parser_status->enable_literals) { - phql_(phql_parser, PHQL_FALSE, NULL, parser_status); - } else { - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, "Literals are disabled in PHQL statements", 1); - parser_status->status = PHQL_PARSING_FAILED; - } - break; + PHALCON_OBS_VAR(error_messages); + phalcon_read_property_this_quick(&error_messages, this_ptr, SL("_errorMessages"), 1019066246UL, PH_NOISY_CC); + if (Z_TYPE_P(error_messages) == IS_ARRAY) { + if (phalcon_fast_count_ev(error_messages TSRMLS_CC)) { + RETURN_MM_TRUE; + } + } + + RETURN_MM_FALSE; +} - case PHQL_T_IDENTIFIER: - phql_parse_with_token(phql_parser, PHQL_T_IDENTIFIER, PHQL_IDENTIFIER, &token, parser_status); - break; - case PHQL_T_NPLACEHOLDER: - phql_parse_with_token(phql_parser, PHQL_T_NPLACEHOLDER, PHQL_NPLACEHOLDER, &token, parser_status); - break; - case PHQL_T_SPLACEHOLDER: - phql_parse_with_token(phql_parser, PHQL_T_SPLACEHOLDER, PHQL_SPLACEHOLDER, &token, parser_status); - break; +static PHP_METHOD(Phalcon_Mvc_Collection, fireEvent){ - case PHQL_T_FROM: - phql_(phql_parser, PHQL_FROM, NULL, parser_status); - break; - case PHQL_T_UPDATE: - phql_(phql_parser, PHQL_UPDATE, NULL, parser_status); - break; - case PHQL_T_SET: - phql_(phql_parser, PHQL_SET, NULL, parser_status); - break; - case PHQL_T_WHERE: - phql_(phql_parser, PHQL_WHERE, NULL, parser_status); - break; - case PHQL_T_DELETE: - phql_(phql_parser, PHQL_DELETE, NULL, parser_status); - break; - case PHQL_T_INSERT: - phql_(phql_parser, PHQL_INSERT, NULL, parser_status); - break; - case PHQL_T_INTO: - phql_(phql_parser, PHQL_INTO, NULL, parser_status); - break; - case PHQL_T_VALUES: - phql_(phql_parser, PHQL_VALUES, NULL, parser_status); - break; - case PHQL_T_SELECT: - phql_(phql_parser, PHQL_SELECT, NULL, parser_status); - break; - case PHQL_T_AS: - phql_(phql_parser, PHQL_AS, NULL, parser_status); - break; - case PHQL_T_ORDER: - phql_(phql_parser, PHQL_ORDER, NULL, parser_status); - break; - case PHQL_T_BY: - phql_(phql_parser, PHQL_BY, NULL, parser_status); - break; - case PHQL_T_LIMIT: - phql_(phql_parser, PHQL_LIMIT, NULL, parser_status); - break; - case PHQL_T_OFFSET: - phql_(phql_parser, PHQL_OFFSET, NULL, parser_status); - break; - case PHQL_T_GROUP: - phql_(phql_parser, PHQL_GROUP, NULL, parser_status); - break; - case PHQL_T_HAVING: - phql_(phql_parser, PHQL_HAVING, NULL, parser_status); - break; - case PHQL_T_ASC: - phql_(phql_parser, PHQL_ASC, NULL, parser_status); - break; - case PHQL_T_DESC: - phql_(phql_parser, PHQL_DESC, NULL, parser_status); - break; - case PHQL_T_IN: - phql_(phql_parser, PHQL_IN, NULL, parser_status); - break; - case PHQL_T_ON: - phql_(phql_parser, PHQL_ON, NULL, parser_status); - break; - case PHQL_T_INNER: - phql_(phql_parser, PHQL_INNER, NULL, parser_status); - break; - case PHQL_T_JOIN: - phql_(phql_parser, PHQL_JOIN, NULL, parser_status); - break; - case PHQL_T_LEFT: - phql_(phql_parser, PHQL_LEFT, NULL, parser_status); - break; - case PHQL_T_RIGHT: - phql_(phql_parser, PHQL_RIGHT, NULL, parser_status); - break; - case PHQL_T_CROSS: - phql_(phql_parser, PHQL_CROSS, NULL, parser_status); - break; - case PHQL_T_FULL: - phql_(phql_parser, PHQL_FULL, NULL, parser_status); - break; - case PHQL_T_OUTER: - phql_(phql_parser, PHQL_OUTER, NULL, parser_status); - break; - case PHQL_T_IS: - phql_(phql_parser, PHQL_IS, NULL, parser_status); - break; - case PHQL_T_NULL: - phql_(phql_parser, PHQL_NULL, NULL, parser_status); - break; - case PHQL_T_BETWEEN: - phql_(phql_parser, PHQL_BETWEEN, NULL, parser_status); - break; - case PHQL_T_DISTINCT: - phql_(phql_parser, PHQL_DISTINCT, NULL, parser_status); - break; - case PHQL_T_CAST: - phql_(phql_parser, PHQL_CAST, NULL, parser_status); - break; - case PHQL_T_CONVERT: - phql_(phql_parser, PHQL_CONVERT, NULL, parser_status); - break; - case PHQL_T_USING: - phql_(phql_parser, PHQL_USING, NULL, parser_status); - break; - default: - parser_status->status = PHQL_PARSING_FAILED; - error_length = sizeof(char) * 32; - error = emalloc(error_length); - snprintf(error, error_length, "Scanner: Unknown opcode %c", token.opcode); - error[error_length - 1] = '\0'; - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, error, 1); - efree(error); - break; - } + zval *event_name, *models_manager; - if (parser_status->status != PHQL_PARSING_OK) { - status = FAILURE; - break; - } + PHALCON_MM_GROW(); - state->end = state->start; + phalcon_fetch_params(1, 1, 0, &event_name); + + if (phalcon_method_exists(this_ptr, event_name TSRMLS_CC) == SUCCESS) { + phalcon_call_method_zval_noret(this_ptr, event_name); } + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(return_value, models_manager, "notifyevent", event_name, this_ptr, 1223080128UL); + RETURN_MM(); +} - if (status != FAILURE) { - switch (scanner_status) { - case PHQL_SCANNER_RETCODE_ERR: - case PHQL_SCANNER_RETCODE_IMPOSSIBLE: - if (!*error_msg) { - if (!*error_msg) { - phql_scanner_error_msg(parser_status, error_msg TSRMLS_CC); - } - } - status = FAILURE; - break; - default: - phql_(phql_parser, 0, NULL, parser_status); - } - } +static PHP_METHOD(Phalcon_Mvc_Collection, fireEventCancel){ - state->active_token = 0; - state->start = NULL; + zval *event_name, *status = NULL, *models_manager; - if (parser_status->status != PHQL_PARSING_OK) { - status = FAILURE; - if (parser_status->syntax_error) { - if (!*error_msg) { - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, parser_status->syntax_error, 1); - } - efree(parser_status->syntax_error); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &event_name); + + if (phalcon_method_exists(this_ptr, event_name TSRMLS_CC) == SUCCESS) { + + PHALCON_INIT_VAR(status); + phalcon_call_method_zval(status, this_ptr, event_name); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; } } + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, models_manager, "notifyevent", event_name, this_ptr, 1223080128UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + + RETURN_MM_TRUE; +} - phql_Free(phql_parser, phql_wrapper_free); +static PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ - if (status != FAILURE) { - if (parser_status->status == PHQL_PARSING_OK) { - if (parser_status->ret) { + zval *disable_events, *operation_made, *event_name = NULL; - if (phalcon_globals_ptr->orm.cache_level >= 1) { - if (Z_TYPE_P(parser_status->ret) == IS_ARRAY) { - add_assoc_long(parser_status->ret, "id", phalcon_globals_ptr->orm.unique_cache_id++); - } - } + PHALCON_MM_GROW(); - ZVAL_ZVAL(*result, parser_status->ret, 0, 0); - ZVAL_NULL(parser_status->ret); - zval_ptr_dtor(&parser_status->ret); + phalcon_fetch_params(1, 1, 0, &disable_events); + + if (!zend_is_true(disable_events)) { + + PHALCON_OBS_VAR(operation_made); + phalcon_read_property_this_quick(&operation_made, this_ptr, SL("_operationMade"), 3968152972UL, PH_NOISY_CC); + if (PHALCON_IS_LONG(operation_made, 3)) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "notDeleted", 1); + } else { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "notSaved", 1); + } + + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + } + RETURN_MM_FALSE; +} - if (phalcon_globals_ptr->orm.cache_level >= 0) { +static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ - if (!phalcon_globals_ptr->orm.parser_cache) { - ALLOC_HASHTABLE(phalcon_globals_ptr->orm.parser_cache); - zend_hash_init(phalcon_globals_ptr->orm.parser_cache, 0, NULL, ZVAL_PTR_DTOR, 0); - } + zval *collection, *id, *mongo_id = NULL, *models_manager; + zval *use_implicit_ids, *parameters, *document_count; + zval *zero; + zend_class_entry *ce0; - Z_ADDREF_PP(result); + PHALCON_MM_GROW(); - zend_hash_index_update( - phalcon_globals_ptr->orm.parser_cache, - phql_key, - result, - sizeof(zval *), - NULL - ); + 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_quick(&id, this_ptr, SL("_id"), 2090005265UL, PH_NOISY_CC); + if (Z_TYPE_P(id) == IS_OBJECT) { + PHALCON_CPY_WRT(mongo_id, id); + } else { + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(use_implicit_ids); + phalcon_call_method_p1_key(use_implicit_ids, models_manager, "isusingimplicitobjectids", this_ptr, 3521236505UL); + if (zend_is_true(use_implicit_ids)) { + ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + PHALCON_INIT_NVAR(mongo_id); + object_init_ex(mongo_id, ce0); + if (phalcon_has_constructor(mongo_id TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, mongo_id, "__construct", id, 1107214344UL); } - + phalcon_update_property_this_quick(this_ptr, SL("_id"), mongo_id, 2090005265UL TSRMLS_CC); } else { - efree(parser_status->ret); + PHALCON_CPY_WRT(mongo_id, id); } } + + PHALCON_INIT_VAR(parameters); + array_init_size(parameters, 1); + phalcon_array_update_quick_string(¶meters, SS("_id"), 2090005265UL, &mongo_id, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(document_count); + phalcon_call_method_p1_key(document_count, collection, "count", parameters, 4142425646UL); + + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + is_smaller_function(return_value, zero, document_count TSRMLS_CC); + + RETURN_MM(); } - - efree(parser_status); - efree(state); - - return status; + RETURN_MM_FALSE; } +static PHP_METHOD(Phalcon_Mvc_Collection, getMessages){ + RETURN_MEMBER_QUICK(this_ptr, "_errorMessages", 1019066246UL); +} -#ifdef HAVE_CONFIG_H -#endif - - - - - +static PHP_METHOD(Phalcon_Mvc_Collection, appendMessage){ + zval *message, *type, *exception_message; -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query_Lang){ + PHALCON_MM_GROW(); - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\Query, Lang, mvc_model_query_lang, phalcon_mvc_model_query_lang_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - return SUCCESS; + phalcon_fetch_params(1, 1, 0, &message); + + if (Z_TYPE_P(message) != IS_OBJECT) { + PHALCON_INIT_VAR(type); + phalcon_call_func_p1(type, "gettype", message); + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Invalid message format '", type, "'"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Lang, parsePHQL){ +static PHP_METHOD(Phalcon_Mvc_Collection, save){ - zval *phql; + zval *dependency_injector, *source, *connection; + zval *collection, *exists, *empty_array, *disable_events; + zval *status = NULL, *data, *reserved, *properties, *value = NULL; + zval *key = NULL, *success = NULL, *options, *ok, *id; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &phql); - - if (Z_TYPE_P(phql) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "PHQL statement must be string"); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); return; } - if (phql_parse_phql(return_value, phql TSRMLS_CC) == FAILURE) { + + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); + if (PHALCON_IS_EMPTY(source)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); return; } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, this_ptr, "getconnection", 2504689909UL); + + PHALCON_INIT_VAR(collection); + phalcon_call_method_p1_key(collection, connection, "selectcollection", source, 3563037297UL); + + PHALCON_INIT_VAR(exists); + phalcon_call_method_p1_key(exists, this_ptr, "_exists", collection, 2792580580UL); + if (PHALCON_IS_FALSE(exists)) { + phalcon_update_property_long(this_ptr, SL("_operationMade"), 1 TSRMLS_CC); + } else { + phalcon_update_property_long(this_ptr, SL("_operationMade"), 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); + + PHALCON_OBS_VAR(disable_events); + phalcon_read_static_property(&disable_events, SL("phalcon\\mvc\\collection"), SL("_disableEvents") TSRMLS_CC); + + PHALCON_INIT_VAR(status); + phalcon_call_method_p3_key(status, this_ptr, "_presave", dependency_injector, disable_events, exists, 3296192410UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + + PHALCON_INIT_VAR(data); + array_init(data); + + PHALCON_INIT_VAR(reserved); + phalcon_call_method_key(reserved, this_ptr, "getreservedattributes", 3061016044UL); + + PHALCON_INIT_VAR(properties); + phalcon_call_func_p1(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 | PH_SEPARATE); + } + } else { + if (!phalcon_array_isset(reserved, key)) { + phalcon_array_update_zval(&data, key, &value, PH_COPY | PH_SEPARATE); + } + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(success); + ZVAL_BOOL(success, 0); + + PHALCON_INIT_VAR(options); + array_init_size(options, 1); + add_assoc_bool_ex(options, SS("safe"), 1); + + PHALCON_INIT_NVAR(status); + Z_SET_ISREF_P(options); + Z_ADDREF_P(options); + phalcon_call_method_p2_key(status, collection, "save", data, options, 274150868UL); + if (Z_REFCOUNT_P(options) > 1) { + Z_UNSET_ISREF_P(options); + Z_DELREF_P(options); + } + + if (Z_TYPE_P(status) == IS_ARRAY) { + 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 (PHALCON_IS_FALSE(exists)) { + if (phalcon_array_isset_quick_string(data, SS("_id"), 2090005265UL)) { + PHALCON_OBS_VAR(id); + phalcon_array_fetch_quick_string(&id, data, SS("_id"), 2090005265UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_id"), id, 2090005265UL TSRMLS_CC); + } + } + } + } + } else { + PHALCON_INIT_NVAR(success); + ZVAL_BOOL(success, 0); + } + + phalcon_call_method_p3_key(return_value, this_ptr, "_postsave", disable_events, success, exists, 3354288601UL); RETURN_MM(); } +static PHP_METHOD(Phalcon_Mvc_Collection, findById){ + zval *id, *class_name, *collection, *models_manager; + zval *use_implicit_ids, *mongo_id = NULL, *conditions; + zval *parameters; + zend_class_entry *ce0, *ce1; -/* Generated by re2c 0.13.5 on Sun Jun 23 22:30:45 2013 */ -// 1 "scanner.re" - + PHALCON_MM_GROW(); -#ifdef HAVE_CONFIG_H -#endif + 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_key(NULL, collection, "__construct", 1107214344UL); + } + + PHALCON_INIT_VAR(models_manager); + phalcon_call_method_key(models_manager, collection, "getmodelsmanager", 2387491844UL); + + PHALCON_INIT_VAR(use_implicit_ids); + phalcon_call_method_p1_key(use_implicit_ids, models_manager, "isusingimplicitobjectids", collection, 3521236505UL); + if (zend_is_true(use_implicit_ids)) { + ce1 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + PHALCON_INIT_VAR(mongo_id); + object_init_ex(mongo_id, ce1); + if (phalcon_has_constructor(mongo_id TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, mongo_id, "__construct", id, 1107214344UL); + } + } else { + PHALCON_CPY_WRT(mongo_id, id); + } + } else { + PHALCON_CPY_WRT(mongo_id, id); + } + + PHALCON_INIT_VAR(conditions); + array_init_size(conditions, 1); + phalcon_array_update_quick_string(&conditions, SS("_id"), 2090005265UL, &mongo_id, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(parameters); + array_init_size(parameters, 1); + phalcon_array_append(¶meters, conditions, PH_SEPARATE); + PHALCON_CALL_SELF_PARAMS_1(return_value, this_ptr, "findfirst", parameters); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Mvc_Collection, findFirst){ + zval *parameters = NULL, *class_name, *collection, *connection; + zval *unique; + zend_class_entry *ce0; -#define YYCTYPE unsigned char -#define YYCURSOR (s->start) -#define YYLIMIT (s->end) -#define YYMARKER q + PHALCON_MM_GROW(); -static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { + phalcon_fetch_params(1, 0, 1, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } + + if (Z_TYPE_P(parameters) != IS_NULL) { + 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_key(NULL, collection, "__construct", 1107214344UL); + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, collection, "getconnection", 2504689909UL); + + PHALCON_INIT_VAR(unique); + ZVAL_BOOL(unique, 1); + PHALCON_CALL_SELF_PARAMS_4(return_value, this_ptr, "_getresultset", parameters, collection, connection, unique); + RETURN_MM(); +} - char *q = YYCURSOR; - int status = PHQL_SCANNER_RETCODE_IMPOSSIBLE; +static PHP_METHOD(Phalcon_Mvc_Collection, find){ - while (PHQL_SCANNER_RETCODE_IMPOSSIBLE == status) { + zval *parameters = NULL, *class_name, *collection, *connection; + zval *unique; + zend_class_entry *ce0; - -// 45 "scanner.c" - { - YYCTYPE yych; - unsigned int yyaccept = 0; + PHALCON_MM_GROW(); - yych = *YYCURSOR; - switch (yych) { - case 0x00: goto yy68; - case '\t': - case '\n': - case '\r': - case ' ': goto yy66; - case '!': goto yy50; - case '"': goto yy29; - case '%': goto yy42; - case '&': goto yy62; - case '\'': goto yy30; - case '(': goto yy46; - case ')': goto yy48; - case '*': goto yy38; - case '+': goto yy34; - case ',': goto yy44; - case '-': goto yy36; - case '.': goto yy4; - case '/': goto yy40; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy2; - case ':': goto yy8; - case '<': goto yy52; - case '=': goto yy56; - case '>': goto yy54; - case '?': goto yy6; - case 'A': - case 'a': goto yy15; - case 'B': - case 'b': goto yy20; - case 'C': - case 'c': goto yy27; - case 'D': - case 'd': goto yy13; - case 'E': - case 'K': - case 'M': - case 'P': - case 'Q': - case 'X': - case 'Y': - case 'Z': - case '_': - case 'e': - case 'k': - case 'm': - case 'p': - case 'q': - case 'x': - case 'y': - case 'z': goto yy32; - case 'F': - case 'f': goto yy14; - case 'G': - case 'g': goto yy21; - case 'H': - case 'h': goto yy22; - case 'I': - case 'i': goto yy16; - case 'J': - case 'j': goto yy25; - case 'L': - case 'l': goto yy23; - case 'N': - case 'n': goto yy24; - case 'O': - case 'o': goto yy19; - case 'R': - case 'r': goto yy26; - case 'S': - case 's': goto yy12; - case 'T': - case 't': goto yy28; - case 'U': - case 'u': goto yy10; - case 'V': - case 'v': goto yy17; - case 'W': - case 'w': goto yy18; - case '[': goto yy33; - case '\\': goto yy31; - case '^': goto yy60; - case '|': goto yy64; - case '~': goto yy58; - default: goto yy70; - } -yy2: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '.': goto yy288; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy290; - default: goto yy3; - } -yy3: -// 46 "scanner.re" - { - token->opcode = PHQL_T_INTEGER; - token->value = estrndup(q, YYCURSOR - q); - token->len = YYCURSOR - q; - q = YYCURSOR; - return 0; + phalcon_fetch_params(1, 0, 1, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } + + if (Z_TYPE_P(parameters) != IS_NULL) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for find"); + return; } -// 170 "scanner.c" -yy4: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy285; - default: goto yy5; - } -yy5: -// 353 "scanner.re" - { - token->opcode = PHQL_T_DOT; - return 0; + } + + 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_key(NULL, collection, "__construct", 1107214344UL); + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, collection, "getconnection", 2504689909UL); + + PHALCON_INIT_VAR(unique); + ZVAL_BOOL(unique, 0); + PHALCON_CALL_SELF_PARAMS_4(return_value, this_ptr, "_getresultset", parameters, collection, connection, unique); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Collection, count){ + + zval *parameters = NULL, *class_name, *collection, *connection; + zend_class_entry *ce0; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } + + if (Z_TYPE_P(parameters) != IS_NULL) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for count"); + return; } -// 192 "scanner.c" -yy6: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy282; - default: goto yy7; - } -yy7: -// 448 "scanner.re" - { - status = PHQL_SCANNER_RETCODE_ERR; - break; + } + + 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_key(NULL, collection, "__construct", 1107214344UL); + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, collection, "getconnection", 2504689909UL); + PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_getgroupresultset", parameters, collection, connection); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Collection, aggregate){ + + zval *parameters, *class_name, *model, *connection; + zval *source, *collection; + zend_class_entry *ce0; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, ¶meters); + + if (Z_TYPE_P(parameters) != IS_NULL) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for aggregate"); + return; } -// 214 "scanner.c" -yy8: - yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); - switch (yych) { - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy278; - default: goto yy9; + } + + PHALCON_INIT_VAR(class_name); + phalcon_get_called_class(class_name TSRMLS_CC); + ce0 = phalcon_fetch_class(class_name TSRMLS_CC); + + PHALCON_INIT_VAR(model); + object_init_ex(model, ce0); + if (phalcon_has_constructor(model TSRMLS_CC)) { + phalcon_call_method_key(NULL, model, "__construct", 1107214344UL); + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, model, "getconnection", 2504689909UL); + + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); + if (PHALCON_IS_EMPTY(source)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); + return; + } + + PHALCON_INIT_VAR(collection); + phalcon_call_method_p1_key(collection, connection, "selectcollection", source, 3563037297UL); + phalcon_call_method_p1_key(return_value, collection, "aggregate", parameters, 3838056268UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Collection, summatory){ + + zval *field, *conditions = NULL, *finalize = NULL, *class_name; + zval *model, *connection, *source, *collection; + zval *keys, *empty_array, *initial, *reduce, *group; + zval *retval, *first_retval, *summatory; + zend_class_entry *ce0; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &field, &conditions, &finalize); + + if (!conditions) { + PHALCON_INIT_VAR(conditions); + } + + if (!finalize) { + PHALCON_INIT_VAR(finalize); + } + + 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(model); + object_init_ex(model, ce0); + if (phalcon_has_constructor(model TSRMLS_CC)) { + phalcon_call_method_key(NULL, model, "__construct", 1107214344UL); + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, model, "getconnection", 2504689909UL); + + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); + if (PHALCON_IS_EMPTY(source)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); + return; + } + + PHALCON_INIT_VAR(collection); + phalcon_call_method_p1_key(collection, connection, "selectcollection", source, 3563037297UL); + + 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_quick_string(&initial, SS("summatory"), 2358676118UL, &empty_array, PH_COPY | PH_SEPARATE); + + 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_INIT_VAR(group); + phalcon_call_method_p3_key(group, collection, "group", keys, initial, reduce, 7349554UL); + 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)) { + PHALCON_OBS_VAR(summatory); + phalcon_array_fetch_quick_string(&summatory, first_retval, SS("summatory"), 2358676118UL, PH_NOISY); + RETURN_CCTOR(summatory); } -yy9: -// 358 "scanner.re" - { - token->opcode = PHQL_T_COLON; - return 0; + + RETURN_CCTOR(first_retval); } -// 291 "scanner.c" -yy10: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case 'P': - case 'p': goto yy267; - case 'S': - case 's': goto yy268; - default: goto yy87; - } -yy11: -// 301 "scanner.re" - { - token->opcode = PHQL_T_IDENTIFIER; - if ((YYCURSOR - q) > 1) { - if (q[0] == '\\') { - token->value = estrndup(q + 1, YYCURSOR - q - 1); - token->len = YYCURSOR - q - 1; - } else { - token->value = estrndup(q, YYCURSOR - q); - token->len = YYCURSOR - q; - } - } else { - token->value = estrndup(q, YYCURSOR - q); - token->len = YYCURSOR - q; - } - q = YYCURSOR; - return 0; + + RETURN_CCTOR(retval); + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Collection, delete){ + + zval *disable_events, *event_name = NULL, *status = NULL, *id; + zval *connection, *source, *collection, *mongo_id = NULL; + zval *models_manager, *use_implicit_ids, *id_condition; + zval *success = NULL, *options, *ok; + zend_class_entry *ce0; + + PHALCON_MM_GROW(); + + if (!phalcon_isset_property(this_ptr, SS("_id") TSRMLS_CC)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The document cannot be deleted because it doesn't exist"); + return; + } + + PHALCON_OBS_VAR(disable_events); + phalcon_read_static_property(&disable_events, SL("phalcon\\mvc\\collection"), SL("_disableEvents") TSRMLS_CC); + if (!zend_is_true(disable_events)) { + + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "beforeDelete", 1); + + PHALCON_INIT_VAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; } -// 320 "scanner.c" -yy12: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy259; - default: goto yy87; - } -yy13: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy242; - case 'I': - case 'i': goto yy243; - default: goto yy87; - } -yy14: - yych = *++YYCURSOR; - switch (yych) { - case 'A': - case 'a': goto yy229; - case 'R': - case 'r': goto yy230; - case 'U': - case 'u': goto yy231; - default: goto yy87; - } -yy15: - yych = *++YYCURSOR; - switch (yych) { - case 'G': - case 'g': goto yy215; - case 'N': - case 'n': goto yy216; - case 'S': - case 's': goto yy217; - default: goto yy87; - } -yy16: - yych = *++YYCURSOR; - switch (yych) { - case 'L': - case 'l': goto yy194; - case 'N': - case 'n': goto yy195; - case 'S': - case 's': goto yy197; - default: goto yy87; - } -yy17: - yych = *++YYCURSOR; - switch (yych) { - case 'A': - case 'a': goto yy188; - default: goto yy87; - } -yy18: - yych = *++YYCURSOR; - switch (yych) { - case 'H': - case 'h': goto yy183; - default: goto yy87; - } -yy19: - yych = *++YYCURSOR; - switch (yych) { - case 'F': - case 'f': goto yy164; - case 'N': - case 'n': goto yy165; - case 'R': - case 'r': goto yy167; - case 'U': - case 'u': goto yy169; - default: goto yy87; + } + + PHALCON_OBS_VAR(id); + phalcon_read_property_this_quick(&id, this_ptr, SL("_id"), 2090005265UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, this_ptr, "getconnection", 2504689909UL); + + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); + if (PHALCON_IS_EMPTY(source)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); + return; + } + + PHALCON_INIT_VAR(collection); + phalcon_call_method_p1_key(collection, connection, "selectcollection", source, 3563037297UL); + if (Z_TYPE_P(id) == IS_OBJECT) { + PHALCON_CPY_WRT(mongo_id, id); + } else { + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(use_implicit_ids); + phalcon_call_method_p1_key(use_implicit_ids, models_manager, "isusingimplicitobjectids", this_ptr, 3521236505UL); + if (zend_is_true(use_implicit_ids)) { + ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + PHALCON_INIT_NVAR(mongo_id); + object_init_ex(mongo_id, ce0); + if (phalcon_has_constructor(mongo_id TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, mongo_id, "__construct", id, 1107214344UL); } -yy20: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy155; - case 'Y': - case 'y': goto yy156; - default: goto yy87; + } else { + PHALCON_CPY_WRT(mongo_id, id); + } + } + + PHALCON_INIT_VAR(id_condition); + array_init_size(id_condition, 1); + phalcon_array_update_quick_string(&id_condition, SS("_id"), 2090005265UL, &mongo_id, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(success); + ZVAL_BOOL(success, 0); + + PHALCON_INIT_VAR(options); + array_init_size(options, 1); + add_assoc_bool_ex(options, SS("safe"), 1); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, collection, "remove", id_condition, options, 1052443347UL); + 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); + ZVAL_STRING(event_name, "afterDelete", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); } -yy21: - yych = *++YYCURSOR; - switch (yych) { - case 'R': - case 'r': goto yy150; - default: goto yy87; + } + } else { + PHALCON_INIT_NVAR(success); + ZVAL_BOOL(success, 0); + } + + RETURN_NCTOR(success); +} + +static PHP_METHOD(Phalcon_Mvc_Collection, toArray){ + + zval *data, *reserved, *properties, *value = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(data); + array_init(data); + + PHALCON_INIT_VAR(reserved); + phalcon_call_method_key(reserved, this_ptr, "getreservedattributes", 3061016044UL); + + PHALCON_INIT_VAR(properties); + phalcon_call_func_p1(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 | PH_SEPARATE); } -yy22: - yych = *++YYCURSOR; - switch (yych) { - case 'A': - case 'a': goto yy144; - default: goto yy87; + } else { + if (!phalcon_array_isset(reserved, key)) { + phalcon_array_update_zval(&data, key, &value, PH_COPY | PH_SEPARATE); } -yy23: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy132; - case 'I': - case 'i': goto yy133; - default: goto yy87; + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_CTOR(data); +} + +static PHP_METHOD(Phalcon_Mvc_Collection, serialize){ + + zval *data; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(data); + phalcon_call_method_key(data, this_ptr, "toarray", 3566966151UL); + + phalcon_serialize(return_value, &data TSRMLS_CC); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Collection, unserialize){ + + zval *data, *attributes, *dependency_injector; + zval *service, *manager, *value = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + 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) { + + PHALCON_INIT_VAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ODM"); + return; } -yy24: - yych = *++YYCURSOR; - switch (yych) { - case 'O': - case 'o': goto yy125; - case 'U': - case 'u': goto yy126; - default: goto yy87; + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "collectionManager", 1); + + PHALCON_INIT_VAR(manager); + phalcon_call_method_p1_key(manager, dependency_injector, "getshared", service, 1727570332UL); + if (Z_TYPE_P(manager) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The injected service 'collectionManager' is not valid"); + return; } -yy25: - yych = *++YYCURSOR; - switch (yych) { - case 'O': - case 'o': goto yy121; - default: goto yy87; + + phalcon_update_property_this_quick(this_ptr, SL("_modelsManager"), manager, 3699347875UL 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); } -yy26: - yych = *++YYCURSOR; - switch (yych) { - case 'I': - case 'i': goto yy116; - default: goto yy87; - } -yy27: - yych = *++YYCURSOR; - switch (yych) { - case 'A': - case 'a': goto yy100; - case 'O': - case 'o': goto yy101; - case 'R': - case 'r': goto yy102; - default: goto yy87; - } -yy28: - yych = *++YYCURSOR; - switch (yych) { - case 'R': - case 'r': goto yy96; - default: goto yy87; - } -yy29: - yyaccept = 1; - yych = *(YYMARKER = ++YYCURSOR); - if (yych <= 0x00) goto yy7; - goto yy94; -yy30: - yyaccept = 1; - yych = *(YYMARKER = ++YYCURSOR); - if (yych <= 0x00) goto yy7; - goto yy89; -yy31: - yych = *++YYCURSOR; - switch (yych) { - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy7; - } -yy32: - yych = *++YYCURSOR; - goto yy87; -yy33: - yyaccept = 1; - yych = *(YYMARKER = ++YYCURSOR); - switch (yych) { - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy81; - default: goto yy7; - } -yy34: - ++YYCURSOR; -// 328 "scanner.re" - { - token->opcode = PHQL_T_ADD; - return 0; - } -// 608 "scanner.c" -yy36: - ++YYCURSOR; -// 333 "scanner.re" - { - token->opcode = PHQL_T_SUB; - return 0; - } -// 616 "scanner.c" -yy38: - ++YYCURSOR; -// 338 "scanner.re" - { - token->opcode = PHQL_T_MUL; - return 0; - } -// 624 "scanner.c" -yy40: - ++YYCURSOR; -// 343 "scanner.re" - { - token->opcode = PHQL_T_DIV; - return 0; - } -// 632 "scanner.c" -yy42: - ++YYCURSOR; -// 348 "scanner.re" - { - token->opcode = PHQL_T_MOD; - return 0; - } -// 640 "scanner.c" -yy44: - ++YYCURSOR; -// 363 "scanner.re" - { - token->opcode = PHQL_T_COMMA; - return 0; - } -// 648 "scanner.c" -yy46: - ++YYCURSOR; -// 368 "scanner.re" - { - token->opcode = PHQL_T_PARENTHESES_OPEN; - return 0; - } -// 656 "scanner.c" -yy48: - ++YYCURSOR; -// 373 "scanner.re" - { - token->opcode = PHQL_T_PARENTHESES_CLOSE; - return 0; + + RETURN_MM_NULL(); } -// 664 "scanner.c" -yy50: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '=': goto yy79; - default: goto yy51; - } -yy51: -// 413 "scanner.re" - { - token->opcode = PHQL_T_NOT; - return 0; + } + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid serialization data"); + return; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_CollectionInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, CollectionInterface, mvc_collectioninterface, phalcon_mvc_collectioninterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Controller){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, Controller, mvc_controller, "phalcon\\di\\injectable", phalcon_mvc_controller_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Controller, __construct){ + + + PHALCON_MM_GROW(); + + if (phalcon_method_quick_exists_ex(this_ptr, SS("onconstruct"), 564344039UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, this_ptr, "onconstruct", 564344039UL); + } + + PHALCON_MM_RESTORE(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_ControllerInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ControllerInterface, mvc_controllerinterface, NULL); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Dispatcher_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Dispatcher, Exception, mvc_dispatcher_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Dispatcher){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, Dispatcher, mvc_dispatcher, "phalcon\\dispatcher", phalcon_mvc_dispatcher_method_entry, 0); + + zend_declare_property_string(phalcon_mvc_dispatcher_ce, SL("_handlerSuffix"), "Controller", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_mvc_dispatcher_ce, SL("_defaultHandler"), "index", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_mvc_dispatcher_ce, SL("_defaultAction"), "index", ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_dispatcher_ce TSRMLS_CC, 1, phalcon_mvc_dispatcherinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Dispatcher, setControllerSuffix){ + + zval *controller_suffix; + + phalcon_fetch_params(0, 1, 0, &controller_suffix); + + phalcon_update_property_this_quick(this_ptr, SL("_handlerSuffix"), controller_suffix, 1659190583UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Dispatcher, setDefaultController){ + + zval *controller_name; + + phalcon_fetch_params(0, 1, 0, &controller_name); + + phalcon_update_property_this_quick(this_ptr, SL("_defaultHandler"), controller_name, 2940762855UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Dispatcher, setControllerName){ + + zval *controller_name; + + phalcon_fetch_params(0, 1, 0, &controller_name); + + phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), controller_name, 2743819555UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_handlerName", 2743819555UL); +} + +static PHP_METHOD(Phalcon_Mvc_Dispatcher, _throwDispatchException){ + + zval *message, *exception_code = NULL, *dependency_injector; + zval *exception_message, *exception = NULL, *service; + zval *response, *status_code, *status_message; + zval *events_manager, *event_name, *status; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &message, &exception_code); + + if (!exception_code) { + PHALCON_INIT_VAR(exception_code); + ZVAL_LONG(exception_code, 0); + } else { + PHALCON_SEPARATE_PARAM(exception_code); + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_NVAR(exception_code); + ZVAL_LONG(exception_code, 0); + + PHALCON_INIT_VAR(exception_message); + ZVAL_STRING(exception_message, "A dependency injection container is required to access the 'response' service", 1); + + PHALCON_INIT_VAR(exception); + object_init_ex(exception, phalcon_mvc_dispatcher_exception_ce); + phalcon_call_method_p2_key(NULL, exception, "__construct", exception_message, exception_code, 1107214344UL); + + phalcon_throw_exception(exception TSRMLS_CC); + return; + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "response", 1); + + PHALCON_INIT_VAR(response); + phalcon_call_method_p1_key(response, dependency_injector, "getshared", service, 1727570332UL); + + PHALCON_INIT_VAR(status_code); + ZVAL_LONG(status_code, 404); + + PHALCON_INIT_VAR(status_message); + ZVAL_STRING(status_message, "Not Found", 1); + phalcon_call_method_p2_key(NULL, response, "setstatuscode", status_code, status_message, 1498183248UL); + + PHALCON_INIT_NVAR(exception); + object_init_ex(exception, phalcon_mvc_dispatcher_exception_ce); + phalcon_call_method_p2_key(NULL, exception, "__construct", message, exception_code, 1107214344UL); + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "dispatch:beforeException", 1); + + PHALCON_INIT_VAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, exception, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; } -// 677 "scanner.c" -yy52: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '=': goto yy75; - case '>': goto yy77; - default: goto yy53; - } -yy53: -// 398 "scanner.re" - { - token->opcode = PHQL_T_LESS; - return 0; + } + + phalcon_throw_exception(exception TSRMLS_CC); + return; +} + +static PHP_METHOD(Phalcon_Mvc_Dispatcher, _handleException){ + + zval *exception, *events_manager, *event_name; + zval *status; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &exception); + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "dispatch:beforeException", 1); + + PHALCON_INIT_VAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, exception, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; } -// 691 "scanner.c" -yy54: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '=': goto yy73; - default: goto yy55; - } -yy55: -// 403 "scanner.re" - { - token->opcode = PHQL_T_GREATER; - return 0; - } -// 704 "scanner.c" -yy56: - ++YYCURSOR; -// 408 "scanner.re" - { - token->opcode = PHQL_T_EQUALS; - return 0; - } -// 712 "scanner.c" -yy58: - ++YYCURSOR; -// 418 "scanner.re" - { - token->opcode = PHQL_T_BITWISE_NOT; - return 0; - } -// 720 "scanner.c" -yy60: - ++YYCURSOR; -// 423 "scanner.re" - { - token->opcode = PHQL_T_BITWISE_XOR; - return 0; - } -// 728 "scanner.c" -yy62: - ++YYCURSOR; -// 428 "scanner.re" - { - token->opcode = PHQL_T_BITWISE_AND; - return 0; - } -// 736 "scanner.c" -yy64: - ++YYCURSOR; -// 433 "scanner.re" - { - token->opcode = PHQL_T_BITWISE_OR; - return 0; - } -// 744 "scanner.c" -yy66: - ++YYCURSOR; - yych = *YYCURSOR; - goto yy72; -yy67: -// 438 "scanner.re" - { - token->opcode = PHQL_T_IGNORE; - return 0; - } -// 755 "scanner.c" -yy68: - ++YYCURSOR; -// 443 "scanner.re" - { - status = PHQL_SCANNER_RETCODE_EOF; - break; - } -// 763 "scanner.c" -yy70: - yych = *++YYCURSOR; - goto yy7; -yy71: - ++YYCURSOR; - yych = *YYCURSOR; -yy72: - switch (yych) { - case '\t': - case '\n': - case '\r': - case ' ': goto yy71; - default: goto yy67; - } -yy73: - ++YYCURSOR; -// 393 "scanner.re" - { - token->opcode = PHQL_T_GREATEREQUAL; - return 0; - } -// 785 "scanner.c" -yy75: - ++YYCURSOR; -// 388 "scanner.re" - { - token->opcode = PHQL_T_LESSEQUAL; - return 0; - } -// 793 "scanner.c" -yy77: - ++YYCURSOR; -// 383 "scanner.re" - { - token->opcode = PHQL_T_NOTEQUALS; - return 0; - } -// 801 "scanner.c" -yy79: - ++YYCURSOR; -// 378 "scanner.re" - { - token->opcode = PHQL_T_NOTEQUALS; - return 0; + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerClass){ + + + PHALCON_MM_GROW(); + + phalcon_call_method_key(return_value, this_ptr, "gethandlername", 1725429572UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Dispatcher, getLastController){ + + + RETURN_MEMBER_QUICK(this_ptr, "_lastHandler", 1315517974UL); +} + +static PHP_METHOD(Phalcon_Mvc_Dispatcher, getActiveController){ + + + RETURN_MEMBER_QUICK(this_ptr, "_activeHandler", 2923197278UL); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_DispatcherInterface){ + + PHALCON_REGISTER_INTERFACE_EX(Phalcon\\Mvc, DispatcherInterface, mvc_dispatcherinterface, "phalcon\\dispatcherinterface", phalcon_mvc_dispatcherinterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_Collection){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Micro, Collection, mvc_micro_collection, phalcon_mvc_micro_collection_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_micro_collection_ce, SL("_prefix"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_collection_ce, SL("_lazy"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_collection_ce, SL("_handler"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_collection_ce, SL("_handlers"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_micro_collection_ce TSRMLS_CC, 1, phalcon_mvc_micro_collectioninterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, _addMap){ + + zval *method, *route_pattern, *handler, *handler_definition; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &method, &route_pattern, &handler); + + PHALCON_INIT_VAR(handler_definition); + array_init_size(handler_definition, 3); + phalcon_array_append(&handler_definition, method, PH_SEPARATE); + phalcon_array_append(&handler_definition, route_pattern, PH_SEPARATE); + phalcon_array_append(&handler_definition, handler, PH_SEPARATE); + phalcon_update_property_array_append(this_ptr, SL("_handlers"), handler_definition TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, setPrefix){ + + zval *prefix; + + phalcon_fetch_params(0, 1, 0, &prefix); + + phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, getPrefix){ + + + RETURN_MEMBER_QUICK(this_ptr, "_prefix", 3873791314UL); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, getHandlers){ + + + RETURN_MEMBER_QUICK(this_ptr, "_handlers", 2445210229UL); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, setHandler){ + + zval *handler, *lazy = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &handler, &lazy); + + if (!lazy) { + PHALCON_INIT_VAR(lazy); + ZVAL_BOOL(lazy, 0); + } + + phalcon_update_property_this_quick(this_ptr, SL("_handler"), handler, 1505752930UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_lazy"), lazy, 3981620804UL TSRMLS_CC); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, setLazy){ + + zval *lazy; + + phalcon_fetch_params(0, 1, 0, &lazy); + + phalcon_update_property_this_quick(this_ptr, SL("_lazy"), lazy, 3981620804UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, isLazy){ + + + RETURN_MEMBER_QUICK(this_ptr, "_lazy", 3981620804UL); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, getHandler){ + + + RETURN_MEMBER_QUICK(this_ptr, "_handler", 1505752930UL); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, map){ + + zval *route_pattern, *handler, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(method); + phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, get){ + + zval *route_pattern, *handler, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "GET", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, post){ + + zval *route_pattern, *handler, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "POST", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, put){ + + zval *route_pattern, *handler, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "PUT", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, patch){ + + zval *route_pattern, *handler, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "PATCH", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, head){ + + zval *route_pattern, *handler, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "HEAD", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, delete){ + + zval *route_pattern, *handler, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "DELETE", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, options){ + + zval *route_pattern, *handler, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "OPTIONS", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_CollectionInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Micro, CollectionInterface, mvc_micro_collectioninterface, phalcon_mvc_micro_collectioninterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Micro, Exception, mvc_micro_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_LazyLoader){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Micro, LazyLoader, mvc_micro_lazyloader, phalcon_mvc_micro_lazyloader_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_micro_lazyloader_ce, SL("_handler"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_lazyloader_ce, SL("_definition"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __construct){ + + zval *definition; + + phalcon_fetch_params(0, 1, 0, &definition); + + if (Z_TYPE_P(definition) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_micro_exception_ce, "Only strings can be lazy loaded"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_definition"), definition, 2496408365UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __call){ + + zval *method, *arguments, *handler = NULL, *definition; + zval *call_handler; + zend_class_entry *ce0; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &method, &arguments); + + PHALCON_OBS_VAR(handler); + phalcon_read_property_this_quick(&handler, this_ptr, SL("_handler"), 1505752930UL, PH_NOISY_CC); + if (Z_TYPE_P(handler) != IS_OBJECT) { + PHALCON_OBS_VAR(definition); + phalcon_read_property_this_quick(&definition, this_ptr, SL("_definition"), 2496408365UL, PH_NOISY_CC); + ce0 = phalcon_fetch_class(definition TSRMLS_CC); + + PHALCON_INIT_NVAR(handler); + object_init_ex(handler, ce0); + if (phalcon_has_constructor(handler TSRMLS_CC)) { + phalcon_call_method_key(NULL, handler, "__construct", 1107214344UL); } -// 809 "scanner.c" -yy81: - ++YYCURSOR; - yych = *YYCURSOR; - switch (yych) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy81; - case ']': goto yy84; - default: goto yy83; - } -yy83: - YYCURSOR = YYMARKER; - switch (yyaccept) { - case 0: goto yy9; - case 1: goto yy7; - } -yy84: - ++YYCURSOR; -// 320 "scanner.re" - { - token->opcode = PHQL_T_IDENTIFIER; - token->value = estrndup(q, YYCURSOR - q - 1); - token->len = YYCURSOR - q - 1; - q = YYCURSOR; - return 0; + phalcon_update_property_this_quick(this_ptr, SL("_handler"), handler, 1505752930UL TSRMLS_CC); + } + + PHALCON_INIT_VAR(call_handler); + array_init_size(call_handler, 2); + phalcon_array_append(&call_handler, handler, PH_SEPARATE); + phalcon_array_append(&call_handler, method, PH_SEPARATE); + + PHALCON_CALL_USER_FUNC_ARRAY(return_value, call_handler, arguments); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_MiddlewareInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Micro, MiddlewareInterface, mvc_micro_middlewareinterface, phalcon_mvc_micro_middlewareinterface_method_entry); + + return SUCCESS; +} + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Micro){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, Micro, mvc_micro, "phalcon\\di\\injectable", phalcon_mvc_micro_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_micro_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_ce, SL("_handlers"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_ce, SL("_router"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_ce, SL("_stopped"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_ce, SL("_notFoundHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_ce, SL("_activeHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_ce, SL("_beforeHandlers"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_ce, SL("_afterHandlers"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_ce, SL("_finishHandlers"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_micro_ce, SL("_returnedValue"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_micro_ce TSRMLS_CC, 1, zend_ce_arrayaccess); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Micro, __construct){ + + zval *dependency_injector = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &dependency_injector); + + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); + } + + if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + phalcon_call_method_p1_key(NULL, this_ptr, "setdi", dependency_injector, 461718238UL); + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, setDI){ + + zval *dependency_injector, *service, *exists; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &dependency_injector); + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "The dependency injector must be an object"); + return; + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "application", 1); + + PHALCON_INIT_VAR(exists); + phalcon_call_method_p1_key(exists, dependency_injector, "has", service, 2090320481UL); + if (!zend_is_true(exists)) { + phalcon_call_method_p2_key(NULL, dependency_injector, "set", service, this_ptr, 2090720177UL); + } + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, map){ + + zval *route_pattern, *handler, *router, *route; + zval *route_id; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(router); + phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + + PHALCON_INIT_VAR(route); + phalcon_call_method_p1_key(route, router, "add", route_pattern, 2090071694UL); + + PHALCON_INIT_VAR(route_id); + phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); + phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); + + RETURN_CCTOR(route); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, get){ + + zval *route_pattern, *handler, *router, *route; + zval *route_id; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(router); + phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + + PHALCON_INIT_VAR(route); + phalcon_call_method_p1_key(route, router, "addget", route_pattern, 522210158UL); + + PHALCON_INIT_VAR(route_id); + phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); + phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); + + RETURN_CCTOR(route); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, post){ + + zval *route_pattern, *handler, *router, *route; + zval *route_id; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(router); + phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + + PHALCON_INIT_VAR(route); + phalcon_call_method_p1_key(route, router, "addpost", route_pattern, 64101428UL); + + PHALCON_INIT_VAR(route_id); + phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); + phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); + + RETURN_CCTOR(route); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, put){ + + zval *route_pattern, *handler, *router, *route; + zval *route_id; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(router); + phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + + PHALCON_INIT_VAR(route); + phalcon_call_method_p1_key(route, router, "addput", route_pattern, 522551015UL); + + PHALCON_INIT_VAR(route_id); + phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); + phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); + + RETURN_CCTOR(route); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, patch){ + + zval *route_pattern, *handler, *router, *route; + zval *route_id; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(router); + phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + + PHALCON_INIT_VAR(route); + phalcon_call_method_p1_key(route, router, "addpatch", route_pattern, 2098765086UL); + + PHALCON_INIT_VAR(route_id); + phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); + phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); + + RETURN_CCTOR(route); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, head){ + + zval *route_pattern, *handler, *router, *route; + zval *route_id; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(router); + phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + + PHALCON_INIT_VAR(route); + phalcon_call_method_p1_key(route, router, "addhead", route_pattern, 54234560UL); + + PHALCON_INIT_VAR(route_id); + phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); + phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); + + RETURN_CCTOR(route); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, delete){ + + zval *route_pattern, *handler, *router, *route; + zval *route_id; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(router); + phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + + PHALCON_INIT_VAR(route); + phalcon_call_method_p1_key(route, router, "adddelete", route_pattern, 2369167137UL); + + PHALCON_INIT_VAR(route_id); + phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); + phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); + + RETURN_CCTOR(route); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, options){ + + zval *route_pattern, *handler, *router, *route; + zval *route_id; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + + PHALCON_INIT_VAR(router); + phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + + PHALCON_INIT_VAR(route); + phalcon_call_method_p1_key(route, router, "addoptions", route_pattern, 3163448186UL); + + PHALCON_INIT_VAR(route_id); + phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); + phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); + + RETURN_CCTOR(route); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, mount){ + + zval *collection, *main_handler, *handlers, *lazy; + zval *lazy_handler = NULL, *prefix, *handler = NULL, *methods = NULL; + zval *pattern = NULL, *sub_handler = NULL, *real_handler = NULL, *prefixed_pattern = NULL; + zval *route = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &collection); + + if (Z_TYPE_P(collection) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The collection is not valid"); + return; + } + + PHALCON_INIT_VAR(main_handler); + phalcon_call_method_key(main_handler, collection, "gethandler", 565881059UL); + if (PHALCON_IS_EMPTY(main_handler)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The collection requires a main handler"); + return; + } + + PHALCON_INIT_VAR(handlers); + phalcon_call_method_key(handlers, collection, "gethandlers", 1494209558UL); + if (!phalcon_fast_count_ev(handlers TSRMLS_CC)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "There are no handlers to mount"); + return; + } + + if (Z_TYPE_P(handlers) == IS_ARRAY) { + + PHALCON_INIT_VAR(lazy); + phalcon_call_method_key(lazy, collection, "islazy", 2860344993UL); + if (zend_is_true(lazy)) { + PHALCON_INIT_VAR(lazy_handler); + object_init_ex(lazy_handler, phalcon_mvc_micro_lazyloader_ce); + phalcon_call_method_p1_key(NULL, lazy_handler, "__construct", main_handler, 1107214344UL); + + } else { + PHALCON_CPY_WRT(lazy_handler, main_handler); } -// 897 "scanner.c" -yy86: - ++YYCURSOR; - yych = *YYCURSOR; -yy87: - switch (yych) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy11; + + PHALCON_INIT_VAR(prefix); + phalcon_call_method_key(prefix, collection, "getprefix", 2543805107UL); + + phalcon_is_iterable(handlers, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(handler); + + if (Z_TYPE_P(handler) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "One of the registered handlers is invalid"); + return; } -yy88: - ++YYCURSOR; - yych = *YYCURSOR; -yy89: - switch (yych) { - case 0x00: goto yy83; - case '\'': goto yy91; - case '\\': goto yy90; - default: goto yy88; + + PHALCON_OBS_NVAR(methods); + phalcon_array_fetch_long(&methods, handler, 0, PH_NOISY); + + PHALCON_OBS_NVAR(pattern); + phalcon_array_fetch_long(&pattern, handler, 1, PH_NOISY); + + PHALCON_OBS_NVAR(sub_handler); + phalcon_array_fetch_long(&sub_handler, handler, 2, PH_NOISY); + + PHALCON_INIT_NVAR(real_handler); + array_init_size(real_handler, 2); + phalcon_array_append(&real_handler, lazy_handler, PH_SEPARATE); + phalcon_array_append(&real_handler, sub_handler, PH_SEPARATE); + if (PHALCON_IS_NOT_EMPTY(prefix)) { + if (PHALCON_IS_STRING(pattern, "/")) { + PHALCON_CPY_WRT(prefixed_pattern, prefix); + } else { + PHALCON_INIT_NVAR(prefixed_pattern); + PHALCON_CONCAT_VV(prefixed_pattern, prefix, pattern); + } + } else { + PHALCON_CPY_WRT(prefixed_pattern, pattern); } -yy90: - ++YYCURSOR; - yych = *YYCURSOR; - switch (yych) { - case '\n': goto yy83; - default: goto yy88; + + PHALCON_INIT_NVAR(route); + phalcon_call_method_p2_key(route, this_ptr, "map", prefixed_pattern, real_handler, 2090500067UL); + if (zend_is_true(methods)) { + phalcon_call_method_p1_key(NULL, route, "via", methods, 2090831717UL); } -yy91: - ++YYCURSOR; -// 292 "scanner.re" - { - token->opcode = PHQL_T_STRING; - token->value = estrndup(q, YYCURSOR - q - 1); - token->len = YYCURSOR - q - 1; - q = YYCURSOR; - return 0; + + zend_hash_move_forward_ex(ah0, &hp0); } -// 996 "scanner.c" -yy93: - ++YYCURSOR; - yych = *YYCURSOR; -yy94: - switch (yych) { - case 0x00: goto yy83; - case '"': goto yy91; - case '\\': goto yy95; - default: goto yy93; - } -yy95: - ++YYCURSOR; - yych = *YYCURSOR; - switch (yych) { - case '\n': goto yy83; - default: goto yy93; + + } + + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, notFound){ + + zval *handler; + + phalcon_fetch_params(0, 1, 0, &handler); + + phalcon_update_property_this_quick(this_ptr, SL("_notFoundHandler"), handler, 2638317359UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, getRouter){ + + zval *router = NULL, *service_name, *remove; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(router); + phalcon_read_property_this_quick(&router, this_ptr, SL("_router"), 2063827077UL, PH_NOISY_CC); + if (Z_TYPE_P(router) != IS_OBJECT) { + PHALCON_INIT_VAR(service_name); + ZVAL_STRING(service_name, "router", 1); + + PHALCON_INIT_NVAR(router); + phalcon_call_method_p1_key(router, this_ptr, "getsharedservice", service_name, 3519183981UL); + + phalcon_call_method_key(NULL, router, "clear", 4138278668UL); + + PHALCON_INIT_VAR(remove); + ZVAL_BOOL(remove, 1); + + phalcon_call_method_p1_key(NULL, router, "removeextraslashes", remove, 2128043402UL); + + phalcon_update_property_this_quick(this_ptr, SL("_router"), router, 2063827077UL TSRMLS_CC); + } + + RETURN_CCTOR(router); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, setService){ + + zval *service_name, *definition, *shared = NULL, *dependency_injector = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 1, &service_name, &definition, &shared); + + if (!shared) { + PHALCON_INIT_VAR(shared); + ZVAL_BOOL(shared, 0); + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_NVAR(dependency_injector); + object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); + phalcon_call_method_key(NULL, dependency_injector, "__construct", 1107214344UL); + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + } + + phalcon_call_method_p3_key(return_value, dependency_injector, "set", service_name, definition, shared, 2090720177UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, hasService){ + + zval *service_name, *dependency_injector = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &service_name); + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_NVAR(dependency_injector); + object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); + phalcon_call_method_key(NULL, dependency_injector, "__construct", 1107214344UL); + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + } + + phalcon_call_method_p1_key(return_value, dependency_injector, "has", service_name, 2090320481UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, getService){ + + zval *service_name, *dependency_injector = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &service_name); + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_NVAR(dependency_injector); + object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); + phalcon_call_method_key(NULL, dependency_injector, "__construct", 1107214344UL); + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + } + + phalcon_call_method_p1_key(return_value, dependency_injector, "get", service_name, 2090288933UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, getSharedService){ + + zval *service_name, *dependency_injector = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &service_name); + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_NVAR(dependency_injector); + object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); + phalcon_call_method_key(NULL, dependency_injector, "__construct", 1107214344UL); + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + } + + phalcon_call_method_p1_key(return_value, dependency_injector, "getshared", service_name, 1727570332UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, handle){ + + zval *uri = NULL, *dependency_injector, *events_manager = NULL; + zval *event_name = NULL, *status = NULL, *service, *router, *matched_route; + zval *handlers, *route_id, *handler = NULL, *before_handlers; + zval *before = NULL, *is_middleware = NULL, *stopped = NULL, *params = NULL; + zval *returned_value = NULL, *after_handlers, *after = NULL; + zval *not_found_handler, *finish_handlers; + zval *finish = NULL, *returned_response; + HashTable *ah0, *ah1, *ah2; + HashPosition hp0, hp1, hp2; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &uri); + + if (!uri) { + PHALCON_INIT_VAR(uri); + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "A dependency injection container is required to access related dispatching services"); + return; + } + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "micro:beforeHandleRoute", 1); + + PHALCON_INIT_VAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "router", 1); + + PHALCON_INIT_VAR(router); + phalcon_call_method_p1_key(router, dependency_injector, "getshared", service, 1727570332UL); + + phalcon_call_method_p1_key(NULL, router, "handle", uri, 866903697UL); + + PHALCON_INIT_VAR(matched_route); + phalcon_call_method_key(matched_route, router, "getmatchedroute", 3985199242UL); + if (Z_TYPE_P(matched_route) == IS_OBJECT) { + + PHALCON_OBS_VAR(handlers); + phalcon_read_property_this_quick(&handlers, this_ptr, SL("_handlers"), 2445210229UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(route_id); + phalcon_call_method_key(route_id, matched_route, "getrouteid", 2741905729UL); + if (!phalcon_array_isset(handlers, route_id)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "Matched route doesn't have an associate handler"); + return; + } + + PHALCON_OBS_VAR(handler); + phalcon_array_fetch(&handler, handlers, route_id, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_activeHandler"), handler, 2923197278UL TSRMLS_CC); + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "micro:beforeExecuteRoute", 1); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } else { + PHALCON_OBS_NVAR(handler); + phalcon_read_property_this_quick(&handler, this_ptr, SL("_activeHandler"), 2923197278UL, PH_NOISY_CC); } -yy96: - yych = *++YYCURSOR; - switch (yych) { - case 'U': - case 'u': goto yy97; - default: goto yy87; + } + + PHALCON_OBS_VAR(before_handlers); + phalcon_read_property_this_quick(&before_handlers, this_ptr, SL("_beforeHandlers"), 1218553128UL, PH_NOISY_CC); + if (Z_TYPE_P(before_handlers) == IS_ARRAY) { + phalcon_update_property_bool(this_ptr, SL("_stopped"), 0 TSRMLS_CC); + + phalcon_is_iterable(before_handlers, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(before); + + if (Z_TYPE_P(before) == IS_OBJECT) { + + PHALCON_INIT_NVAR(is_middleware); + phalcon_instance_of(is_middleware, before, phalcon_mvc_micro_middlewareinterface_ce TSRMLS_CC); + if (PHALCON_IS_TRUE(is_middleware)) { + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, before, "call", this_ptr, 255165473UL); + + PHALCON_OBS_NVAR(stopped); + phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); + + if (zend_is_true(stopped)) { + break; + } + + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } + if (!phalcon_is_callable(before TSRMLS_CC)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The before handler is not callable"); + return; + } + + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC(status, before); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + + PHALCON_OBS_NVAR(stopped); + phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); + if (zend_is_true(stopped)) { + RETURN_CCTOR(status); + } + + zend_hash_move_forward_ex(ah0, &hp0); } -yy97: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy98; - default: goto yy87; + + } + + PHALCON_INIT_VAR(params); + phalcon_call_method_key(params, router, "getparams", 1893744905UL); + + PHALCON_INIT_VAR(returned_value); + PHALCON_CALL_USER_FUNC_ARRAY(returned_value, handler, params); + + phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), returned_value, 4143876906UL TSRMLS_CC); + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "micro:afterExecuteRoute", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } + + PHALCON_OBS_VAR(after_handlers); + phalcon_read_property_this_quick(&after_handlers, this_ptr, SL("_afterHandlers"), 687871879UL, PH_NOISY_CC); + if (Z_TYPE_P(after_handlers) == IS_ARRAY) { + phalcon_update_property_bool(this_ptr, SL("_stopped"), 0 TSRMLS_CC); + + phalcon_is_iterable(after_handlers, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(after); + + if (Z_TYPE_P(after) == IS_OBJECT) { + + PHALCON_INIT_NVAR(is_middleware); + phalcon_instance_of(is_middleware, after, phalcon_mvc_micro_middlewareinterface_ce TSRMLS_CC); + if (PHALCON_IS_TRUE(is_middleware)) { + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, after, "call", this_ptr, 255165473UL); + + PHALCON_OBS_NVAR(stopped); + phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); + + if (zend_is_true(stopped)) { + break; + } + + zend_hash_move_forward_ex(ah1, &hp1); + continue; + } + } + if (!phalcon_is_callable(after TSRMLS_CC)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "One of the 'after' handlers is not callable"); + return; + } + + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC(status, after); + + zend_hash_move_forward_ex(ah1, &hp1); } -yy98: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy99; + + } + } else { + PHALCON_OBS_NVAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "micro:beforeNotFound", 1); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; } -yy99: -// 281 "scanner.re" - { - token->opcode = PHQL_T_TRUE; - return 0; } -// 1103 "scanner.c" -yy100: - yych = *++YYCURSOR; - switch (yych) { - case 'S': - case 's': goto yy113; - default: goto yy87; + + PHALCON_OBS_VAR(not_found_handler); + phalcon_read_property_this_quick(¬_found_handler, this_ptr, SL("_notFoundHandler"), 2638317359UL, PH_NOISY_CC); + if (!phalcon_is_callable(not_found_handler TSRMLS_CC)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The Not-Found handler is not callable or is not defined"); + return; + } + + PHALCON_INIT_NVAR(returned_value); + PHALCON_CALL_USER_FUNC(returned_value, not_found_handler); + + phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), returned_value, 4143876906UL TSRMLS_CC); + + RETURN_CCTOR(returned_value); + } + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "micro:afterHandleRoute", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } + + PHALCON_OBS_VAR(finish_handlers); + phalcon_read_property_this_quick(&finish_handlers, this_ptr, SL("_finishHandlers"), 2843789078UL, PH_NOISY_CC); + if (Z_TYPE_P(finish_handlers) == IS_ARRAY) { + phalcon_update_property_bool(this_ptr, SL("_stopped"), 0 TSRMLS_CC); + + PHALCON_INIT_NVAR(params); + + phalcon_is_iterable(finish_handlers, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HVALUE(finish); + + if (Z_TYPE_P(finish) == IS_OBJECT) { + + PHALCON_INIT_NVAR(is_middleware); + phalcon_instance_of(is_middleware, finish, phalcon_mvc_micro_middlewareinterface_ce TSRMLS_CC); + if (PHALCON_IS_TRUE(is_middleware)) { + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, finish, "call", this_ptr, 255165473UL); + + PHALCON_OBS_NVAR(stopped); + phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); + + if (zend_is_true(stopped)) { + break; + } + + zend_hash_move_forward_ex(ah2, &hp2); + continue; + } } -yy101: - yych = *++YYCURSOR; - switch (yych) { - case 'N': - case 'n': goto yy107; - default: goto yy87; - } -yy102: - yych = *++YYCURSOR; - switch (yych) { - case 'O': - case 'o': goto yy103; - default: goto yy87; - } -yy103: - yych = *++YYCURSOR; - switch (yych) { - case 'S': - case 's': goto yy104; - default: goto yy87; + if (!phalcon_is_callable(finish TSRMLS_CC)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "One of finish handlers is not callable"); + return; } -yy104: - yych = *++YYCURSOR; - switch (yych) { - case 'S': - case 's': goto yy105; - default: goto yy87; + + if (Z_TYPE_P(params) == IS_NULL) { + PHALCON_INIT_NVAR(params); + array_init_size(params, 1); + phalcon_array_append(¶ms, this_ptr, PH_SEPARATE); } -yy105: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy106; + + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC_ARRAY(status, finish, params); + + PHALCON_OBS_NVAR(stopped); + phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); + + if (zend_is_true(stopped)) { + break; } -yy106: -// 231 "scanner.re" - { - token->opcode = PHQL_T_CROSS; - return 0; + + zend_hash_move_forward_ex(ah2, &hp2); } -// 1214 "scanner.c" -yy107: - yych = *++YYCURSOR; - switch (yych) { - case 'V': - case 'v': goto yy108; - default: goto yy87; - } -yy108: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy109; - default: goto yy87; - } -yy109: - yych = *++YYCURSOR; - switch (yych) { - case 'R': - case 'r': goto yy110; - default: goto yy87; + + } + + if (Z_TYPE_P(returned_value) == IS_OBJECT) { + + PHALCON_INIT_VAR(returned_response); + phalcon_instance_of(returned_response, returned_value, phalcon_http_responseinterface_ce TSRMLS_CC); + if (PHALCON_IS_TRUE(returned_response)) { + phalcon_call_method_key(NULL, returned_value, "send", 274285871UL); + } + } + + RETURN_CCTOR(returned_value); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, stop){ + + + phalcon_update_property_bool(this_ptr, SL("_stopped"), 1 TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Micro, setActiveHandler){ + + zval *active_handler; + + phalcon_fetch_params(0, 1, 0, &active_handler); + + phalcon_update_property_this_quick(this_ptr, SL("_activeHandler"), active_handler, 2923197278UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Micro, getActiveHandler){ + + + RETURN_MEMBER_QUICK(this_ptr, "_activeHandler", 2923197278UL); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, getReturnedValue){ + + + RETURN_MEMBER_QUICK(this_ptr, "_returnedValue", 4143876906UL); +} + + + + +static PHP_METHOD(Phalcon_Mvc_Micro, offsetUnset){ + + zval *alias; + + phalcon_fetch_params(0, 1, 0, &alias); + + RETURN_CCTORW(alias); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, before){ + + zval *handler; + + phalcon_fetch_params(0, 1, 0, &handler); + + phalcon_update_property_array_append(this_ptr, SL("_beforeHandlers"), handler TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, after){ + + zval *handler; + + phalcon_fetch_params(0, 1, 0, &handler); + + phalcon_update_property_array_append(this_ptr, SL("_afterHandlers"), handler TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, finish){ + + zval *handler; + + phalcon_fetch_params(0, 1, 0, &handler); + + phalcon_update_property_array_append(this_ptr, SL("_finishHandlers"), handler TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Micro, getHandlers){ + + + RETURN_MEMBER_QUICK(this_ptr, "_handlers", 2445210229UL); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Behavior_SoftDelete){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Behavior, SoftDelete, mvc_model_behavior_softdelete, "phalcon\\mvc\\model\\behavior", phalcon_mvc_model_behavior_softdelete_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_behavior_softdelete_ce TSRMLS_CC, 1, phalcon_mvc_model_behaviorinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Behavior_SoftDelete, notify){ + + zval *type, *model, *options, *skip, *value, *field, *actual_value; + zval *update_model, *status, *messages, *message = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &type, &model); + + if (PHALCON_IS_STRING(type, "beforeDelete")) { + + PHALCON_INIT_VAR(options); + phalcon_call_method_key(options, this_ptr, "getoptions", 680281137UL); + if (!phalcon_array_isset_quick_string(options, SS("value"), 574111618UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'value' is required"); + return; + } + + if (!phalcon_array_isset_quick_string(options, SS("field"), 4252138601UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'field' is required"); + return; + } + + PHALCON_INIT_VAR(skip); + ZVAL_BOOL(skip, 1); + + phalcon_call_method_p1_key(NULL, model, "skipoperation", skip, 1652216141UL); + + PHALCON_OBS_VAR(value); + phalcon_array_fetch_quick_string(&value, options, SS("value"), 574111618UL, PH_NOISY); + + PHALCON_OBS_VAR(field); + phalcon_array_fetch_quick_string(&field, options, SS("field"), 4252138601UL, PH_NOISY); + + PHALCON_INIT_VAR(actual_value); + phalcon_call_method_p1_key(actual_value, model, "readattribute", field, 95450773UL); + + if (!PHALCON_IS_EQUAL(actual_value, value)) { + + PHALCON_INIT_VAR(update_model); + if (phalcon_clone(update_model, model TSRMLS_CC) == FAILURE) { + return; } -yy110: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy111; - default: goto yy87; + phalcon_call_method_p2_key(NULL, update_model, "writeattribute", field, value, 3716971876UL); + + PHALCON_INIT_VAR(status); + phalcon_call_method_key(status, update_model, "save", 274150868UL); + if (!zend_is_true(status)) { + + PHALCON_INIT_VAR(messages); + phalcon_call_method_key(messages, update_model, "getmessages", 4087333309UL); + + 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_call_method_p1_key(NULL, model, "appendmessage", message, 2313005058UL); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_MM_FALSE; } -yy111: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy112; + + phalcon_call_method_p2_key(NULL, model, "writeattribute", field, value, 3716971876UL); + } + } + + PHALCON_MM_RESTORE(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Behavior_Timestampable){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Behavior, Timestampable, mvc_model_behavior_timestampable, "phalcon\\mvc\\model\\behavior", phalcon_mvc_model_behavior_timestampable_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_behavior_timestampable_ce TSRMLS_CC, 1, phalcon_mvc_model_behaviorinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Behavior_Timestampable, notify){ + + zval *type, *model, *take_action, *options, *timestamp = NULL; + zval *format, *generator, *field, *single_field = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &type, &model); + + PHALCON_INIT_VAR(take_action); + phalcon_call_method_p1_key(take_action, this_ptr, "musttakeaction", type, 4279140401UL); + if (PHALCON_IS_NOT_TRUE(take_action)) { + RETURN_MM_NULL(); + } + + PHALCON_INIT_VAR(options); + phalcon_call_method_p1_key(options, this_ptr, "getoptions", type, 680281137UL); + if (Z_TYPE_P(options) == IS_ARRAY) { + + if (!phalcon_array_isset_quick_string(options, SS("field"), 4252138601UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'field' is required"); + return; + } + + PHALCON_INIT_VAR(timestamp); + if (phalcon_array_isset_quick_string(options, SS("format"), 3131886190UL)) { + PHALCON_OBS_VAR(format); + phalcon_array_fetch_quick_string(&format, options, SS("format"), 3131886190UL, PH_NOISY); + + phalcon_call_func_p1(timestamp, "date", format); + } else { + if (phalcon_array_isset_quick_string(options, SS("generator"), 3205705004UL)) { + + PHALCON_OBS_VAR(generator); + phalcon_array_fetch_quick_string(&generator, options, SS("generator"), 3205705004UL, PH_NOISY); + if (Z_TYPE_P(generator) == IS_OBJECT) { + if (phalcon_is_instance_of(generator, SL("Closure") TSRMLS_CC)) { + PHALCON_INIT_NVAR(timestamp); + PHALCON_CALL_USER_FUNC(timestamp, generator); + } + } } -yy112: -// 271 "scanner.re" - { - token->opcode = PHQL_T_CONVERT; - return 0; } -// 1318 "scanner.c" -yy113: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy114; - default: goto yy87; + + if (Z_TYPE_P(timestamp) == IS_NULL) { + PHALCON_INIT_NVAR(timestamp); + ZVAL_LONG(timestamp, (long) time(NULL)); + } + + PHALCON_OBS_VAR(field); + phalcon_array_fetch_quick_string(&field, options, SS("field"), 4252138601UL, PH_NOISY); + + if (unlikely(Z_TYPE_P(field) == IS_ARRAY)) { + + phalcon_is_iterable(field, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(single_field); + + phalcon_call_method_p2_key(NULL, model, "writeattribute", single_field, timestamp, 3716971876UL); + + zend_hash_move_forward_ex(ah0, &hp0); } -yy114: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy115; - } -yy115: -// 266 "scanner.re" - { - token->opcode = PHQL_T_CAST; - return 0; - } -// 1401 "scanner.c" -yy116: - yych = *++YYCURSOR; - switch (yych) { - case 'G': - case 'g': goto yy117; - default: goto yy87; - } -yy117: - yych = *++YYCURSOR; - switch (yych) { - case 'H': - case 'h': goto yy118; - default: goto yy87; - } -yy118: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy119; - default: goto yy87; - } -yy119: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy120; - } -yy120: -// 226 "scanner.re" - { - token->opcode = PHQL_T_RIGHT; - return 0; - } -// 1498 "scanner.c" -yy121: - yych = *++YYCURSOR; - switch (yych) { - case 'I': - case 'i': goto yy122; - default: goto yy87; - } -yy122: - yych = *++YYCURSOR; - switch (yych) { - case 'N': - case 'n': goto yy123; - default: goto yy87; - } -yy123: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy124; - } -yy124: -// 211 "scanner.re" - { - token->opcode = PHQL_T_JOIN; - return 0; - } -// 1588 "scanner.c" -yy125: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy130; - default: goto yy87; - } -yy126: - yych = *++YYCURSOR; - switch (yych) { - case 'L': - case 'l': goto yy127; - default: goto yy87; - } -yy127: - yych = *++YYCURSOR; - switch (yych) { - case 'L': - case 'l': goto yy128; - default: goto yy87; - } -yy128: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy129; - } -yy129: -// 251 "scanner.re" - { - token->opcode = PHQL_T_NULL; - return 0; + + } else { + phalcon_call_method_p2_key(NULL, model, "writeattribute", field, timestamp, 3716971876UL); } -// 1685 "scanner.c" -yy130: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy131; - } -yy131: -// 171 "scanner.re" - { - token->opcode = PHQL_T_NOT; - return 0; + } + + PHALCON_MM_RESTORE(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Behavior){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Behavior, mvc_model_behavior, phalcon_mvc_model_behavior_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_property_null(phalcon_mvc_model_behavior_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Behavior, __construct){ + + zval *options = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } + + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Behavior, mustTakeAction){ + + zval *event_name, *options; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &event_name); + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (phalcon_array_isset(options, event_name)) { + RETURN_MM_TRUE; + } + + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Behavior, getOptions){ + + zval *event_name = NULL, *options, *event_options; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &event_name); + + if (!event_name) { + PHALCON_INIT_VAR(event_name); + } + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (Z_TYPE_P(event_name) != IS_NULL) { + if (phalcon_array_isset(options, event_name)) { + PHALCON_OBS_VAR(event_options); + phalcon_array_fetch(&event_options, options, event_name, PH_NOISY); + RETURN_CCTOR(event_options); } -// 1761 "scanner.c" -yy132: - yych = *++YYCURSOR; - switch (yych) { - case 'F': - case 'f': goto yy141; - default: goto yy87; - } -yy133: - yych = *++YYCURSOR; - switch (yych) { - case 'K': - case 'k': goto yy135; - case 'M': - case 'm': goto yy134; - default: goto yy87; - } -yy134: - yych = *++YYCURSOR; - switch (yych) { - case 'I': - case 'i': goto yy138; - default: goto yy87; - } -yy135: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy136; - default: goto yy87; - } -yy136: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy137; - } -yy137: -// 186 "scanner.re" - { - token->opcode = PHQL_T_LIKE; - return 0; + RETURN_MM_NULL(); + } + + RETURN_CCTOR(options); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Behavior, notify){ + + zval *type, *model; + + phalcon_fetch_params(0, 2, 0, &type, &model); + + RETURN_NULL(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Behavior, missingMethod){ + + zval *model, *method, *arguments = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 1, &model, &method, &arguments); + + if (!arguments) { + PHALCON_INIT_VAR(arguments); + } + + RETURN_MM_NULL(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_BehaviorInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, BehaviorInterface, mvc_model_behaviorinterface, phalcon_mvc_model_behaviorinterface_method_entry); + + return SUCCESS; +} + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Criteria){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Criteria, mvc_model_criteria, phalcon_mvc_model_criteria_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_model_criteria_ce, SL("_model"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_criteria_ce, SL("_params"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_model_criteria_ce, SL("_hiddenParamNumber"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_criteria_ce TSRMLS_CC, 2, phalcon_mvc_model_criteriainterface_ce, phalcon_di_injectionawareinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Dependency Injector is invalid"); + return; + } + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("di"), dependency_injector TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getDI){ + + zval *params, *dependency_injector; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("di"), 193489362UL)) { + PHALCON_OBS_VAR(dependency_injector); + phalcon_array_fetch_quick_string(&dependency_injector, params, SS("di"), 193489362UL, PH_NOISY); + RETURN_CCTOR(dependency_injector); + } + + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, setModelName){ + + zval *model_name; + + phalcon_fetch_params(0, 1, 0, &model_name); + + if (Z_TYPE_P(model_name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Model name must be string"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_model"), model_name, 2599397109UL TSRMLS_CC); + + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getModelName){ + + zval *model; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(model); + phalcon_read_property_this_quick(&model, this_ptr, SL("_model"), 2599397109UL, PH_NOISY_CC); + RETURN_CCTOR(model); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, bind){ + + zval *bind_params; + + phalcon_fetch_params(0, 1, 0, &bind_params); + + if (Z_TYPE_P(bind_params) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Bound parameters must be an Array"); + return; + } + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bind"), bind_params TSRMLS_CC); + + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, bindTypes){ + + zval *bind_types; + + phalcon_fetch_params(0, 1, 0, &bind_types); + + if (Z_TYPE_P(bind_types) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Bind types parameters must be an Array"); + return; + } + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bindTypes"), bind_types TSRMLS_CC); + + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, columns){ + + zval *columns; + + phalcon_fetch_params(0, 1, 0, &columns); + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("columns"), columns TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, join){ + + zval *model, *conditions = NULL, *alias = NULL, *type = NULL, *join, *params; + zval *current_joins, *merged_joins = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 3, &model, &conditions, &alias, &type); + + if (!conditions) { + PHALCON_INIT_VAR(conditions); + } + + if (!alias) { + PHALCON_INIT_VAR(alias); + } + + if (!type) { + PHALCON_INIT_VAR(type); + } + + PHALCON_INIT_VAR(join); + array_init_size(join, 4); + phalcon_array_append(&join, model, PH_SEPARATE); + phalcon_array_append(&join, conditions, PH_SEPARATE); + phalcon_array_append(&join, alias, PH_SEPARATE); + phalcon_array_append(&join, type, PH_SEPARATE); + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("joins"), 120974824UL)) { + + PHALCON_OBS_VAR(current_joins); + phalcon_array_fetch_quick_string(¤t_joins, params, SS("joins"), 120974824UL, PH_NOISY); + if (Z_TYPE_P(current_joins) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_joins); + phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_joins, join); } -// 1867 "scanner.c" -yy138: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy139; - default: goto yy87; - } -yy139: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy140; - } -yy140: -// 161 "scanner.re" - { - token->opcode = PHQL_T_LIMIT; - return 0; + } else { + PHALCON_INIT_NVAR(merged_joins); + array_init_size(merged_joins, 1); + phalcon_array_append(&merged_joins, join, PH_SEPARATE); + } + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); + + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, innerJoin){ + + zval *model, *conditions = NULL, *alias = NULL, *type, *join, *params; + zval *current_joins, *merged_joins = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); + + if (!conditions) { + PHALCON_INIT_VAR(conditions); + } + + if (!alias) { + PHALCON_INIT_VAR(alias); + } + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "INNER", 1); + + PHALCON_INIT_VAR(join); + array_init_size(join, 4); + phalcon_array_append(&join, model, PH_SEPARATE); + phalcon_array_append(&join, conditions, PH_SEPARATE); + phalcon_array_append(&join, alias, PH_SEPARATE); + phalcon_array_append(&join, type, PH_SEPARATE); + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("joins"), 120974824UL)) { + + PHALCON_OBS_VAR(current_joins); + phalcon_array_fetch_quick_string(¤t_joins, params, SS("joins"), 120974824UL, PH_NOISY); + if (Z_TYPE_P(current_joins) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_joins); + phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_joins, join); } -// 1950 "scanner.c" -yy141: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy142; - default: goto yy87; - } -yy142: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy143; - } -yy143: -// 221 "scanner.re" - { - token->opcode = PHQL_T_LEFT; - return 0; + } else { + PHALCON_INIT_NVAR(merged_joins); + array_init_size(merged_joins, 1); + phalcon_array_append(&merged_joins, join, PH_SEPARATE); + } + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); + + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, leftJoin){ + + zval *model, *conditions = NULL, *alias = NULL, *type, *join, *params; + zval *current_joins, *merged_joins = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); + + if (!conditions) { + PHALCON_INIT_VAR(conditions); + } + + if (!alias) { + PHALCON_INIT_VAR(alias); + } + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "LEFT", 1); + + PHALCON_INIT_VAR(join); + array_init_size(join, 4); + phalcon_array_append(&join, model, PH_SEPARATE); + phalcon_array_append(&join, conditions, PH_SEPARATE); + phalcon_array_append(&join, alias, PH_SEPARATE); + phalcon_array_append(&join, type, PH_SEPARATE); + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("joins"), 120974824UL)) { + + PHALCON_OBS_VAR(current_joins); + phalcon_array_fetch_quick_string(¤t_joins, params, SS("joins"), 120974824UL, PH_NOISY); + if (Z_TYPE_P(current_joins) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_joins); + phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_joins, join); } -// 2033 "scanner.c" -yy144: - yych = *++YYCURSOR; - switch (yych) { - case 'V': - case 'v': goto yy145; - default: goto yy87; - } -yy145: - yych = *++YYCURSOR; - switch (yych) { - case 'I': - case 'i': goto yy146; - default: goto yy87; - } -yy146: - yych = *++YYCURSOR; - switch (yych) { - case 'N': - case 'n': goto yy147; - default: goto yy87; - } -yy147: - yych = *++YYCURSOR; - switch (yych) { - case 'G': - case 'g': goto yy148; - default: goto yy87; - } -yy148: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy149; - } -yy149: -// 156 "scanner.re" - { - token->opcode = PHQL_T_HAVING; - return 0; + } else { + PHALCON_INIT_NVAR(merged_joins); + array_init_size(merged_joins, 1); + phalcon_array_append(&merged_joins, join, PH_SEPARATE); + } + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); + + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, rightJoin){ + + zval *model, *conditions = NULL, *alias = NULL, *type, *join, *params; + zval *current_joins, *merged_joins = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); + + if (!conditions) { + PHALCON_INIT_VAR(conditions); + } + + if (!alias) { + PHALCON_INIT_VAR(alias); + } + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "RIGHT", 1); + + PHALCON_INIT_VAR(join); + array_init_size(join, 4); + phalcon_array_append(&join, model, PH_SEPARATE); + phalcon_array_append(&join, conditions, PH_SEPARATE); + phalcon_array_append(&join, alias, PH_SEPARATE); + phalcon_array_append(&join, type, PH_SEPARATE); + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("joins"), 120974824UL)) { + + PHALCON_OBS_VAR(current_joins); + phalcon_array_fetch_quick_string(¤t_joins, params, SS("joins"), 120974824UL, PH_NOISY); + if (Z_TYPE_P(current_joins) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_joins); + phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_joins, join); } -// 2137 "scanner.c" -yy150: - yych = *++YYCURSOR; - switch (yych) { - case 'O': - case 'o': goto yy151; - default: goto yy87; - } -yy151: - yych = *++YYCURSOR; - switch (yych) { - case 'U': - case 'u': goto yy152; - default: goto yy87; - } -yy152: - yych = *++YYCURSOR; - switch (yych) { - case 'P': - case 'p': goto yy153; - default: goto yy87; - } -yy153: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy154; - } -yy154: -// 151 "scanner.re" - { - token->opcode = PHQL_T_GROUP; - return 0; + } else { + PHALCON_INIT_NVAR(merged_joins); + array_init_size(merged_joins, 1); + phalcon_array_append(&merged_joins, join, PH_SEPARATE); + } + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); + + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, where){ + + zval *conditions, *bind_params = NULL, *bind_types = NULL; + zval *params = NULL, *current_bind_params, *merged_params = NULL; + zval *current_bind_types, *merged_params_types = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); + + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); + } + + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } + + if (Z_TYPE_P(conditions) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Conditions must be string"); + return; + } + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("conditions"), conditions TSRMLS_CC); + + if (Z_TYPE_P(bind_params) == IS_ARRAY) { + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { + PHALCON_OBS_VAR(current_bind_params); + phalcon_array_fetch_quick_string(¤t_bind_params, params, SS("bind"), 254268962UL, PH_NOISY); + + PHALCON_INIT_VAR(merged_params); + phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_params, bind_params); } -// 2234 "scanner.c" -yy155: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy158; - default: goto yy87; - } -yy156: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy157; - } -yy157: -// 136 "scanner.re" - { - token->opcode = PHQL_T_BY; - return 0; + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bind"), merged_params TSRMLS_CC); + } + + if (Z_TYPE_P(bind_types) == IS_ARRAY) { + + PHALCON_OBS_NVAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { + PHALCON_OBS_VAR(current_bind_types); + phalcon_array_fetch_quick_string(¤t_bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); + + PHALCON_INIT_VAR(merged_params_types); + phalcon_fast_array_merge(merged_params_types, ¤t_bind_types, &bind_types TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_params_types, bind_types); } -// 2317 "scanner.c" -yy158: - yych = *++YYCURSOR; - switch (yych) { - case 'W': - case 'w': goto yy159; - default: goto yy87; - } -yy159: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy160; - default: goto yy87; - } -yy160: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy161; - default: goto yy87; - } -yy161: - yych = *++YYCURSOR; - switch (yych) { - case 'N': - case 'n': goto yy162; - default: goto yy87; - } -yy162: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy163; - } -yy163: -// 261 "scanner.re" - { - token->opcode = PHQL_T_BETWEEN; - return 0; + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bindTypes"), merged_params_types TSRMLS_CC); + } + + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, addWhere){ + + zval *conditions, *bind_params = NULL, *bind_types = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); + + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); + } + + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } + + phalcon_call_method_p3_key(NULL, this_ptr, "andwhere", conditions, bind_params, bind_types, 3363158931UL); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, andWhere){ + + zval *conditions, *bind_params = NULL, *bind_types = NULL; + zval *params = NULL, *current_conditions, *new_conditions = NULL; + zval *current_bind_params, *merged_params = NULL; + zval *current_bind_types, *merged_params_types = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); + + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); + } + + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } + + if (Z_TYPE_P(conditions) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Conditions must be string"); + return; + } + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_VAR(current_conditions); + phalcon_array_fetch_quick_string(¤t_conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); + + PHALCON_INIT_VAR(new_conditions); + PHALCON_CONCAT_SVSVS(new_conditions, "(", current_conditions, ") AND (", conditions, ")"); + } else { + PHALCON_CPY_WRT(new_conditions, conditions); + } + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("conditions"), new_conditions TSRMLS_CC); + + if (Z_TYPE_P(bind_params) == IS_ARRAY) { + + PHALCON_OBS_NVAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { + PHALCON_OBS_VAR(current_bind_params); + phalcon_array_fetch_quick_string(¤t_bind_params, params, SS("bind"), 254268962UL, PH_NOISY); + + PHALCON_INIT_VAR(merged_params); + phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_params, bind_params); } -// 2421 "scanner.c" -yy164: - yych = *++YYCURSOR; - switch (yych) { - case 'F': - case 'f': goto yy178; - default: goto yy87; - } -yy165: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy166; - } -yy166: -// 206 "scanner.re" - { - token->opcode = PHQL_T_ON; - return 0; + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bind"), merged_params TSRMLS_CC); + } + + if (Z_TYPE_P(bind_types) == IS_ARRAY) { + + PHALCON_OBS_NVAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { + PHALCON_OBS_VAR(current_bind_types); + phalcon_array_fetch_quick_string(¤t_bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); + + PHALCON_INIT_VAR(merged_params_types); + phalcon_fast_array_merge(merged_params_types, ¤t_bind_types, &bind_types TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_params_types, bind_types); } -// 2504 "scanner.c" -yy167: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - case 'D': - case 'd': goto yy174; - default: goto yy168; - } -yy168: -// 181 "scanner.re" - { - token->opcode = PHQL_T_OR; - return 0; + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bindTypes"), merged_params_types TSRMLS_CC); + } + + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, orWhere){ + + zval *conditions, *bind_params = NULL, *bind_types = NULL; + zval *params = NULL, *current_conditions, *new_conditions = NULL; + zval *current_bind_params, *merged_params = NULL; + zval *current_bind_types, *merged_params_types = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); + + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); + } + + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } + + if (Z_TYPE_P(conditions) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Conditions must be string"); + return; + } + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_VAR(current_conditions); + phalcon_array_fetch_quick_string(¤t_conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); + + PHALCON_INIT_VAR(new_conditions); + PHALCON_CONCAT_SVSVS(new_conditions, "(", current_conditions, ") OR (", conditions, ")"); + } else { + PHALCON_CPY_WRT(new_conditions, conditions); + } + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("conditions"), new_conditions TSRMLS_CC); + + if (Z_TYPE_P(bind_params) == IS_ARRAY) { + + PHALCON_OBS_NVAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { + PHALCON_OBS_VAR(current_bind_params); + phalcon_array_fetch_quick_string(¤t_bind_params, params, SS("bind"), 254268962UL, PH_NOISY); + + PHALCON_INIT_VAR(merged_params); + phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_params, bind_params); } -// 2580 "scanner.c" -yy169: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy170; - default: goto yy87; - } -yy170: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy171; - default: goto yy87; - } -yy171: - yych = *++YYCURSOR; - switch (yych) { - case 'R': - case 'r': goto yy172; - default: goto yy87; - } -yy172: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy173; - } -yy173: -// 236 "scanner.re" - { - token->opcode = PHQL_T_OUTER; - return 0; + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bind"), merged_params TSRMLS_CC); + } + + if (Z_TYPE_P(bind_types) == IS_ARRAY) { + + PHALCON_OBS_NVAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { + PHALCON_OBS_VAR(current_bind_types); + phalcon_array_fetch_quick_string(¤t_bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); + + PHALCON_INIT_VAR(merged_params_types); + phalcon_fast_array_merge(merged_params_types, ¤t_bind_types, &bind_types TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_params_types, bind_types); } -// 2677 "scanner.c" -yy174: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy175; - default: goto yy87; - } -yy175: - yych = *++YYCURSOR; - switch (yych) { - case 'R': - case 'r': goto yy176; - default: goto yy87; - } -yy176: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy177; - } -yy177: -// 131 "scanner.re" - { - token->opcode = PHQL_T_ORDER; - return 0; + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bindTypes"), merged_params_types TSRMLS_CC); + } + + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, betweenWhere){ + + zval *expr, *minimum, *maximum, *hidden_param, *one; + zval *next_hidden_param, *minimum_key, *maximum_key; + zval *conditions, *bind_params; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &expr, &minimum, &maximum); + + PHALCON_OBS_VAR(hidden_param); + phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + + PHALCON_INIT_VAR(next_hidden_param); + phalcon_add_function(next_hidden_param, hidden_param, one TSRMLS_CC); + + PHALCON_INIT_VAR(minimum_key); + PHALCON_CONCAT_SV(minimum_key, "phb", hidden_param); + + PHALCON_INIT_VAR(maximum_key); + PHALCON_CONCAT_SV(maximum_key, "phb", next_hidden_param); + + PHALCON_INIT_VAR(conditions); + PHALCON_CONCAT_VSVSVS(conditions, expr, " BETWEEN :", minimum_key, ": AND :", maximum_key, ":"); + + PHALCON_INIT_VAR(bind_params); + array_init_size(bind_params, 2); + phalcon_array_update_zval(&bind_params, minimum_key, &minimum, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&bind_params, maximum_key, &maximum, PH_COPY | PH_SEPARATE); + + phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); + PHALCON_SEPARATE(next_hidden_param); + phalcon_increment(next_hidden_param); + phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), next_hidden_param, 3119958698UL TSRMLS_CC); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, notBetweenWhere){ + + zval *expr, *minimum, *maximum, *hidden_param, *one; + zval *next_hidden_param, *minimum_key, *maximum_key; + zval *conditions, *bind_params; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &expr, &minimum, &maximum); + + PHALCON_OBS_VAR(hidden_param); + phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + + PHALCON_INIT_VAR(next_hidden_param); + phalcon_add_function(next_hidden_param, hidden_param, one TSRMLS_CC); + + PHALCON_INIT_VAR(minimum_key); + PHALCON_CONCAT_SV(minimum_key, "phb", hidden_param); + + PHALCON_INIT_VAR(maximum_key); + PHALCON_CONCAT_SV(maximum_key, "phb", next_hidden_param); + + PHALCON_INIT_VAR(conditions); + PHALCON_CONCAT_VSVSVS(conditions, expr, " NOT BETWEEN :", minimum_key, ": AND :", maximum_key, ":"); + + PHALCON_INIT_VAR(bind_params); + array_init_size(bind_params, 2); + phalcon_array_update_zval(&bind_params, minimum_key, &minimum, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&bind_params, maximum_key, &maximum, PH_COPY | PH_SEPARATE); + + phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); + PHALCON_SEPARATE(next_hidden_param); + phalcon_increment(next_hidden_param); + phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), next_hidden_param, 3119958698UL TSRMLS_CC); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, inWhere){ + + zval *expr, *values, *hidden_param, *bind_params; + zval *bind_keys, *value = NULL, *key = NULL, *query_key = NULL, *joined_keys; + zval *conditions; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &expr, &values); + + if (Z_TYPE_P(values) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Values must be an array"); + return; + } + + PHALCON_OBS_VAR(hidden_param); + phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(bind_params); + array_init(bind_params); + + PHALCON_INIT_VAR(bind_keys); + array_init(bind_keys); + + phalcon_is_iterable(values, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(value); + + PHALCON_INIT_NVAR(key); + PHALCON_CONCAT_SV(key, "phi", hidden_param); + + PHALCON_INIT_NVAR(query_key); + PHALCON_CONCAT_SVS(query_key, ":", key, ":"); + phalcon_array_append(&bind_keys, query_key, PH_SEPARATE); + phalcon_array_update_zval(&bind_params, key, &value, PH_COPY | PH_SEPARATE); + PHALCON_SEPARATE(hidden_param); + phalcon_increment(hidden_param); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(joined_keys); + phalcon_fast_join_str(joined_keys, SL(", "), bind_keys TSRMLS_CC); + + PHALCON_INIT_VAR(conditions); + PHALCON_CONCAT_VSVS(conditions, expr, " IN (", joined_keys, ")"); + + phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); + phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), hidden_param, 3119958698UL TSRMLS_CC); + + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, notInWhere){ + + zval *expr, *values, *hidden_param, *bind_params; + zval *bind_keys, *value = NULL, *key = NULL, *query_key = NULL, *joined_keys; + zval *conditions; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &expr, &values); + + if (Z_TYPE_P(values) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Values must be an array"); + return; + } + + PHALCON_OBS_VAR(hidden_param); + phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(bind_params); + array_init(bind_params); + + PHALCON_INIT_VAR(bind_keys); + array_init(bind_keys); + + phalcon_is_iterable(values, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(value); + + PHALCON_INIT_NVAR(key); + PHALCON_CONCAT_SV(key, "phi", hidden_param); + + PHALCON_INIT_NVAR(query_key); + PHALCON_CONCAT_SVS(query_key, ":", key, ":"); + phalcon_array_append(&bind_keys, query_key, PH_SEPARATE); + phalcon_array_update_zval(&bind_params, key, &value, PH_COPY | PH_SEPARATE); + PHALCON_SEPARATE(hidden_param); + phalcon_increment(hidden_param); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(joined_keys); + phalcon_fast_join_str(joined_keys, SL(", "), bind_keys TSRMLS_CC); + + PHALCON_INIT_VAR(conditions); + PHALCON_CONCAT_VSVS(conditions, expr, " NOT IN (", joined_keys, ")"); + + phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); + phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), hidden_param, 3119958698UL TSRMLS_CC); + + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, conditions){ + + zval *conditions; + + phalcon_fetch_params(0, 1, 0, &conditions); + + if (Z_TYPE_P(conditions) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Conditions must be string"); + return; + } + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("conditions"), conditions TSRMLS_CC); + + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, order){ + + zval *order_columns; + + phalcon_fetch_params(0, 1, 0, &order_columns); + + if (Z_TYPE_P(order_columns) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Order columns must be string"); + return; + } + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("order"), order_columns TSRMLS_CC); + + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, orderBy){ + + zval *order_columns; + + phalcon_fetch_params(0, 1, 0, &order_columns); + + if (Z_TYPE_P(order_columns) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Order columns must be string"); + return; + } + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("order"), order_columns TSRMLS_CC); + + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, limit){ + + zval *limit, *offset = NULL, *limit_clause; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &limit, &offset); + + if (!offset) { + PHALCON_INIT_VAR(offset); + } + + if (!phalcon_is_numeric(limit)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Rows limit parameter must be integer"); + return; + } + if (Z_TYPE_P(offset) == IS_NULL) { + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("limit"), limit TSRMLS_CC); + } else { + PHALCON_INIT_VAR(limit_clause); + array_init_size(limit_clause, 2); + phalcon_array_update_quick_string(&limit_clause, SS("number"), 807219790UL, &limit, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&limit_clause, SS("offset"), 1503966412UL, &offset, PH_COPY | PH_SEPARATE); + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("limit"), limit_clause TSRMLS_CC); + } + + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, forUpdate){ + + zval *for_update = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &for_update); + + if (!for_update) { + PHALCON_INIT_VAR(for_update); + ZVAL_BOOL(for_update, 1); + } + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("for_update"), for_update TSRMLS_CC); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, sharedLock){ + + zval *shared_lock = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &shared_lock); + + if (!shared_lock) { + PHALCON_INIT_VAR(shared_lock); + ZVAL_BOOL(shared_lock, 1); + } + + phalcon_update_property_array_string(this_ptr, SL("_params"), SS("shared_lock"), shared_lock TSRMLS_CC); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getWhere){ + + zval *params, *conditions; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_VAR(conditions); + phalcon_array_fetch_quick_string(&conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); + RETURN_CCTOR(conditions); + } + + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getColumns){ + + zval *params, *columns; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("columns"), 1041822630UL)) { + PHALCON_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, params, SS("columns"), 1041822630UL, PH_NOISY); + RETURN_CCTOR(columns); + } + + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getConditions){ + + zval *params, *conditions; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_VAR(conditions); + phalcon_array_fetch_quick_string(&conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); + RETURN_CCTOR(conditions); + } + + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getLimit){ + + zval *params, *conditions; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("limit"), 192268420UL)) { + PHALCON_OBS_VAR(conditions); + phalcon_array_fetch_quick_string(&conditions, params, SS("limit"), 192268420UL, PH_NOISY); + RETURN_CCTOR(conditions); + } + + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getOrder){ + + zval *params, *conditions; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(params, SS("order"), 320020033UL)) { + PHALCON_OBS_VAR(conditions); + phalcon_array_fetch_quick_string(&conditions, params, SS("order"), 320020033UL, PH_NOISY); + RETURN_CCTOR(conditions); + } + + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getParams){ + + + RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, fromInput){ + + zval *dependency_injector, *model_name, *data; + zval *conditions, *service, *meta_data, *model; + zval *data_types, *bind, *value = NULL, *field = NULL, *type = NULL, *condition = NULL; + zval *value_pattern = NULL, *join_conditions; + HashTable *ah0; + HashPosition hp0; + zval **hd; + zend_class_entry *ce0; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &dependency_injector, &model_name, &data); + + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Input data must be an Array"); + return; + } + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the ORM services"); + return; + } + + PHALCON_INIT_VAR(conditions); + array_init(conditions); + if (phalcon_fast_count_ev(data TSRMLS_CC)) { + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "modelsMetadata", 1); + + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_p1_key(meta_data, dependency_injector, "getshared", service, 1727570332UL); + ce0 = phalcon_fetch_class(model_name TSRMLS_CC); + + PHALCON_INIT_VAR(model); + object_init_ex(model, ce0); + if (phalcon_has_constructor(model TSRMLS_CC)) { + phalcon_call_method_key(NULL, model, "__construct", 1107214344UL); } -// 2767 "scanner.c" -yy178: - yych = *++YYCURSOR; - switch (yych) { - case 'S': - case 's': goto yy179; - default: goto yy87; - } -yy179: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy180; - default: goto yy87; - } -yy180: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy181; - default: goto yy87; - } -yy181: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy182; + + PHALCON_INIT_VAR(data_types); + phalcon_call_method_p1_key(data_types, meta_data, "getdatatypes", model, 562971380UL); + + PHALCON_INIT_VAR(bind); + array_init(bind); + + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(field, ah0, hp0); + PHALCON_GET_HVALUE(value); + + if (phalcon_array_isset(data_types, field)) { + if (Z_TYPE_P(value) != IS_NULL) { + if (!PHALCON_IS_STRING(value, "")) { + + PHALCON_OBS_NVAR(type); + phalcon_array_fetch(&type, data_types, field, PH_NOISY); + if (PHALCON_IS_LONG(type, 2)) { + PHALCON_INIT_NVAR(condition); + PHALCON_CONCAT_VSVS(condition, field, " LIKE :", field, ":"); + + PHALCON_INIT_NVAR(value_pattern); + PHALCON_CONCAT_SVS(value_pattern, "%", value, "%"); + phalcon_array_update_zval(&bind, field, &value_pattern, PH_COPY | PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(condition); + PHALCON_CONCAT_VSVS(condition, field, "=:", field, ":"); + phalcon_array_update_zval(&bind, field, &value, PH_COPY | PH_SEPARATE); + } + + phalcon_array_append(&conditions, condition, PH_SEPARATE); + } + } } -yy182: -// 166 "scanner.re" - { - token->opcode = PHQL_T_OFFSET; - return 0; + + zend_hash_move_forward_ex(ah0, &hp0); } -// 2864 "scanner.c" -yy183: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy184; - default: goto yy87; - } -yy184: - yych = *++YYCURSOR; - switch (yych) { - case 'R': - case 'r': goto yy185; - default: goto yy87; - } -yy185: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy186; - default: goto yy87; - } -yy186: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy187; + + } + + object_init_ex(return_value, phalcon_mvc_model_criteria_ce); + if (phalcon_fast_count_ev(conditions TSRMLS_CC)) { + PHALCON_INIT_VAR(join_conditions); + phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); + phalcon_call_method_p1_key(NULL, return_value, "where", join_conditions, 621293632UL); + phalcon_call_method_p1_key(NULL, return_value, "bind", bind, 254268962UL); + } + + phalcon_call_method_p1_key(NULL, return_value, "setmodelname", model_name, 3112384035UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Criteria, execute){ + + zval *model, *params, *resultset; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(model); + phalcon_read_property_this_quick(&model, this_ptr, SL("_model"), 2599397109UL, PH_NOISY_CC); + if (Z_TYPE_P(model) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Model name must be string"); + return; + } + + PHALCON_INIT_VAR(params); + phalcon_call_method_key(params, this_ptr, "getparams", 1893744905UL); + + PHALCON_INIT_VAR(resultset); + phalcon_call_zval_str_static_p1(resultset, model, "find", params); + + RETURN_CCTOR(resultset); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_CriteriaInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, CriteriaInterface, mvc_model_criteriainterface, phalcon_mvc_model_criteriainterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model, Exception, mvc_model_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Manager){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Manager, mvc_model_manager, phalcon_mvc_model_manager_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_customEventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_readConnectionServices"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_writeConnectionServices"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_aliases"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_hasMany"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_hasManySingle"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_hasOne"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_hasOneSingle"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_belongsTo"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_belongsToSingle"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_hasManyToMany"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_hasManyToManySingle"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_initialized"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_sources"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_schemas"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_behaviors"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_lastInitialized"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_lastQuery"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_reusable"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_keepSnapshots"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_dynamicUpdate"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_manager_ce, SL("_namespaceAliases"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_manager_ce TSRMLS_CC, 3, phalcon_mvc_model_managerinterface_ce, phalcon_di_injectionawareinterface_ce, phalcon_events_eventsawareinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setEventsManager){ + + zval *events_manager; + + phalcon_fetch_params(0, 1, 0, &events_manager); + + phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getEventsManager){ + + + RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setCustomEventsManager){ + + zval *model, *events_manager, *class_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &events_manager); + + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 1 TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_customEventsManager"), class_name, events_manager TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getCustomEventsManager){ + + zval *model, *custom_events_manager, *class_name; + zval *events_manager; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_OBS_VAR(custom_events_manager); + phalcon_read_property_this_quick(&custom_events_manager, this_ptr, SL("_customEventsManager"), 542727151UL, PH_NOISY_CC); + if (Z_TYPE_P(custom_events_manager) == IS_ARRAY) { + + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(custom_events_manager, class_name)) { + PHALCON_OBS_VAR(events_manager); + phalcon_array_fetch(&events_manager, custom_events_manager, class_name, PH_NOISY); + RETURN_CCTOR(events_manager); + } + } + + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, initialize){ + + zval *model, *class_name, *initialized, *events_manager; + zval *event_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 1 TSRMLS_CC); + + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); + + if (phalcon_array_isset(initialized, class_name)) { + RETURN_MM_FALSE; + } + + phalcon_update_property_array(this_ptr, SL("_initialized"), class_name, model TSRMLS_CC); + + if (phalcon_method_quick_exists_ex(model, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, model, "initialize", 2896075127UL); + } + + phalcon_update_property_this_quick(this_ptr, SL("_lastInitialized"), model, 1491101038UL TSRMLS_CC); + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "modelsManager:afterInitialize", 1); + phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, model, 259017035UL); + } + + RETURN_MM_TRUE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, isInitialized){ + + zval *model_name, *initialized, *lowercased; + zval *is_intitialized = NULL; + zval *r0 = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model_name); + + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(lowercased); + phalcon_fast_strtolower(lowercased, model_name); + + PHALCON_INIT_VAR(r0); + ZVAL_BOOL(r0, phalcon_array_isset(initialized, lowercased)); + PHALCON_CPY_WRT(is_intitialized, r0); + RETURN_NCTOR(is_intitialized); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getLastInitialized){ + + + RETURN_MEMBER_QUICK(this_ptr, "_lastInitialized", 1491101038UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, load){ + + zval *model_name, *new_instance = NULL, *initialized; + zval *lowercased, *model, *cloned, *dependency_injector; + zval *exception_message; + zend_class_entry *ce0; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &model_name, &new_instance); + + if (!new_instance) { + PHALCON_INIT_VAR(new_instance); + ZVAL_BOOL(new_instance, 0); + } + + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(lowercased); + phalcon_fast_strtolower(lowercased, model_name); + + if (phalcon_array_isset(initialized, lowercased)) { + + PHALCON_OBS_VAR(model); + phalcon_array_fetch(&model, initialized, lowercased, PH_NOISY); + if (zend_is_true(new_instance)) { + PHALCON_INIT_VAR(cloned); + if (phalcon_clone(cloned, model TSRMLS_CC) == FAILURE) { + return; } -yy187: -// 121 "scanner.re" - { - token->opcode = PHQL_T_WHERE; - return 0; + RETURN_CCTOR(cloned); } -// 2961 "scanner.c" -yy188: - yych = *++YYCURSOR; - switch (yych) { - case 'L': - case 'l': goto yy189; - default: goto yy87; - } -yy189: - yych = *++YYCURSOR; - switch (yych) { - case 'U': - case 'u': goto yy190; - default: goto yy87; - } -yy190: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy191; - default: goto yy87; - } -yy191: - yych = *++YYCURSOR; - switch (yych) { - case 'S': - case 's': goto yy192; - default: goto yy87; - } -yy192: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy193; - } -yy193: -// 116 "scanner.re" - { - token->opcode = PHQL_T_VALUES; - return 0; - } -// 3065 "scanner.c" -yy194: - yych = *++YYCURSOR; - switch (yych) { - case 'I': - case 'i': goto yy211; - default: goto yy87; - } -yy195: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'o': - case 'p': - case 'q': - case 'r': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - case 'N': - case 'n': goto yy201; - case 'S': - case 's': goto yy199; - case 'T': - case 't': goto yy200; - default: goto yy196; - } -yy196: -// 201 "scanner.re" - { - token->opcode = PHQL_T_IN; - return 0; + + RETURN_CCTOR(model); + } + + if (phalcon_class_exists(model_name, 1 TSRMLS_CC)) { + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + ce0 = phalcon_fetch_class(model_name TSRMLS_CC); + object_init_ex(return_value, ce0); + if (phalcon_has_constructor(return_value TSRMLS_CC)) { + phalcon_call_method_p2_key(NULL, return_value, "__construct", dependency_injector, this_ptr, 1107214344UL); } -// 3148 "scanner.c" -yy197: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy198; - } -yy198: -// 246 "scanner.re" - { - token->opcode = PHQL_T_IS; - return 0; + RETURN_MM(); + } + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Model '", model_name, "' could not be loaded"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setModelSource){ + + zval *model, *source, *entity_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &source); + + if (Z_TYPE_P(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Model is not an object"); + return; + } + if (Z_TYPE_P(source) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Source must be a string"); + return; + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_sources"), entity_name, source TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getModelSource){ + + zval *model, *entity_name, *sources, *source = NULL, *class_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + if (Z_TYPE_P(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Model is not an object"); + return; + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + PHALCON_OBS_VAR(sources); + phalcon_read_property_this_quick(&sources, this_ptr, SL("_sources"), 3348100040UL, PH_NOISY_CC); + if (Z_TYPE_P(sources) == IS_ARRAY) { + if (phalcon_array_isset(sources, entity_name)) { + PHALCON_OBS_VAR(source); + phalcon_array_fetch(&source, sources, entity_name, PH_NOISY); + RETURN_CCTOR(source); } -// 3224 "scanner.c" -yy199: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy207; - default: goto yy87; - } -yy200: - yych = *++YYCURSOR; - switch (yych) { - case 'O': - case 'o': goto yy205; - default: goto yy87; - } -yy201: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy202; - default: goto yy87; - } -yy202: - yych = *++YYCURSOR; - switch (yych) { - case 'R': - case 'r': goto yy203; - default: goto yy87; - } -yy203: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy204; - } -yy204: -// 216 "scanner.re" - { - token->opcode = PHQL_T_INNER; - return 0; + } + + PHALCON_INIT_VAR(class_name); + phalcon_get_class_ns(class_name, model, 0 TSRMLS_CC); + + PHALCON_INIT_NVAR(source); + phalcon_uncamelize(source, class_name); + phalcon_update_property_array(this_ptr, SL("_sources"), entity_name, source TSRMLS_CC); + + RETURN_CCTOR(source); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setModelSchema){ + + zval *model, *schema, *entity_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &schema); + + if (Z_TYPE_P(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Model is not an object"); + return; + } + if (Z_TYPE_P(schema) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Schema must be a string"); + return; + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_schemas"), entity_name, schema TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getModelSchema){ + + zval *model, *entity_name, *schemas, *schema; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + if (Z_TYPE_P(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Model is not an object"); + return; + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + PHALCON_OBS_VAR(schemas); + phalcon_read_property_this_quick(&schemas, this_ptr, SL("_schemas"), 211564232UL, PH_NOISY_CC); + if (Z_TYPE_P(schemas) == IS_ARRAY) { + if (phalcon_array_isset(schemas, entity_name)) { + PHALCON_OBS_VAR(schema); + phalcon_array_fetch(&schema, schemas, entity_name, PH_NOISY); + RETURN_CCTOR(schema); } -// 3328 "scanner.c" -yy205: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy206; - } -yy206: -// 111 "scanner.re" - { - token->opcode = PHQL_T_INTO; - return 0; + } + + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setConnectionService){ + + zval *model, *connection_service, *entity_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &connection_service); + + if (Z_TYPE_P(connection_service) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The connection service must be a string"); + return; + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_readConnectionServices"), entity_name, connection_service TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_writeConnectionServices"), entity_name, connection_service TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setWriteConnectionService){ + + zval *model, *connection_service, *entity_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &connection_service); + + if (Z_TYPE_P(connection_service) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The connection service must be a string"); + return; + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_writeConnectionServices"), entity_name, connection_service TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setReadConnectionService){ + + zval *model, *connection_service, *entity_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &connection_service); + + if (Z_TYPE_P(connection_service) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The connection service must be a string"); + return; + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_readConnectionServices"), entity_name, connection_service TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getWriteConnection){ + + zval *model, *service = NULL, *connection_services; + zval *entity_name, *dependency_injector, *connection; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "db", 1); + + PHALCON_OBS_VAR(connection_services); + phalcon_read_property_this_quick(&connection_services, this_ptr, SL("_writeConnectionServices"), 1867379683UL, PH_NOISY_CC); + if (Z_TYPE_P(connection_services) == IS_ARRAY) { + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + if (phalcon_array_isset(connection_services, entity_name)) { + PHALCON_OBS_NVAR(service); + phalcon_array_fetch(&service, connection_services, entity_name, PH_NOISY); } -// 3404 "scanner.c" -yy207: - yych = *++YYCURSOR; - switch (yych) { - case 'R': - case 'r': goto yy208; - default: goto yy87; - } -yy208: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy209; - default: goto yy87; - } -yy209: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy210; - } -yy210: -// 106 "scanner.re" - { - token->opcode = PHQL_T_INSERT; - return 0; + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); + return; + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_p1_key(connection, dependency_injector, "getshared", service, 1727570332UL); + if (Z_TYPE_P(connection) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid injected connection service"); + return; + } + + RETURN_CCTOR(connection); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getReadConnection){ + + zval *model, *service = NULL, *connection_services; + zval *entity_name, *dependency_injector, *connection; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "db", 1); + + PHALCON_OBS_VAR(connection_services); + phalcon_read_property_this_quick(&connection_services, this_ptr, SL("_readConnectionServices"), 679383124UL, PH_NOISY_CC); + if (Z_TYPE_P(connection_services) == IS_ARRAY) { + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + if (phalcon_array_isset(connection_services, entity_name)) { + PHALCON_OBS_NVAR(service); + phalcon_array_fetch(&service, connection_services, entity_name, PH_NOISY); } -// 3494 "scanner.c" -yy211: - yych = *++YYCURSOR; - switch (yych) { - case 'K': - case 'k': goto yy212; - default: goto yy87; - } -yy212: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy213; - default: goto yy87; - } -yy213: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy214; - } -yy214: -// 191 "scanner.re" - { - token->opcode = PHQL_T_ILIKE; - return 0; + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); + return; + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_p1_key(connection, dependency_injector, "getshared", service, 1727570332UL); + if (Z_TYPE_P(connection) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid injected connection service"); + return; + } + + RETURN_CCTOR(connection); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getReadConnectionService){ + + zval *model, *connection_services, *entity_name; + zval *connection; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_OBS_VAR(connection_services); + phalcon_read_property_this_quick(&connection_services, this_ptr, SL("_readConnectionServices"), 679383124UL, PH_NOISY_CC); + if (Z_TYPE_P(connection_services) == IS_ARRAY) { + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + if (phalcon_array_isset(connection_services, entity_name)) { + PHALCON_OBS_VAR(connection); + phalcon_array_fetch(&connection, connection_services, entity_name, PH_NOISY); + RETURN_CCTOR(connection); } -// 3584 "scanner.c" -yy215: - yych = *++YYCURSOR; - switch (yych) { - case 'A': - case 'a': goto yy223; - default: goto yy87; + } + + RETURN_MM_STRING("db", 1); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getWriteConnectionService){ + + zval *model, *connection_services, *entity_name; + zval *connection; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_OBS_VAR(connection_services); + phalcon_read_property_this_quick(&connection_services, this_ptr, SL("_writeConnectionServices"), 1867379683UL, PH_NOISY_CC); + if (Z_TYPE_P(connection_services) == IS_ARRAY) { + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + if (phalcon_array_isset(connection_services, entity_name)) { + PHALCON_OBS_VAR(connection); + phalcon_array_fetch(&connection, connection_services, entity_name, PH_NOISY); + RETURN_CCTOR(connection); + } + } + + RETURN_MM_STRING("db", 1); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, notifyEvent){ + + zval *event_name, *model, *status = NULL, *behaviors, *entity_name = NULL; + zval *models_behaviors, *behavior = NULL, *events_manager; + zval *fire_event_name = NULL, *custom_events_manager; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &event_name, &model); + + PHALCON_INIT_VAR(status); + + PHALCON_OBS_VAR(behaviors); + phalcon_read_property_this_quick(&behaviors, this_ptr, SL("_behaviors"), 712001671UL, PH_NOISY_CC); + if (Z_TYPE_P(behaviors) == IS_ARRAY) { + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(behaviors, entity_name)) { + + PHALCON_OBS_VAR(models_behaviors); + phalcon_array_fetch(&models_behaviors, behaviors, entity_name, PH_NOISY); + + phalcon_is_iterable(models_behaviors, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(behavior); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, behavior, "notify", event_name, model, 580961758UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_CCTOR(status); + } + + zend_hash_move_forward_ex(ah0, &hp0); } -yy216: - yych = *++YYCURSOR; - switch (yych) { - case 'D': - case 'd': goto yy221; - default: goto yy87; + + } + } + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_VAR(fire_event_name); + PHALCON_CONCAT_SV(fire_event_name, "model:", event_name); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", fire_event_name, model, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_CCTOR(status); + } + } + + PHALCON_OBS_VAR(custom_events_manager); + phalcon_read_property_this_quick(&custom_events_manager, this_ptr, SL("_customEventsManager"), 542727151UL, PH_NOISY_CC); + if (Z_TYPE_P(custom_events_manager) == IS_ARRAY) { + + PHALCON_INIT_NVAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(custom_events_manager, entity_name)) { + + PHALCON_INIT_NVAR(fire_event_name); + PHALCON_CONCAT_SV(fire_event_name, "model:", event_name); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, custom_events_manager, "fire", fire_event_name, model, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_CCTOR(status); } -yy217: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - case 'C': - case 'c': goto yy219; - default: goto yy218; - } -yy218: -// 101 "scanner.re" - { - token->opcode = PHQL_T_AS; - return 0; } -// 3674 "scanner.c" -yy219: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy220; + } + + RETURN_CCTOR(status); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, missingMethod){ + + zval *model, *event_name, *data, *behaviors, *entity_name; + zval *models_behaviors, *behavior = NULL, *result = NULL, *events_manager; + zval *fire_event_name; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &model, &event_name, &data); + + PHALCON_OBS_VAR(behaviors); + phalcon_read_property_this_quick(&behaviors, this_ptr, SL("_behaviors"), 712001671UL, PH_NOISY_CC); + if (Z_TYPE_P(behaviors) == IS_ARRAY) { + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(behaviors, entity_name)) { + + PHALCON_OBS_VAR(models_behaviors); + phalcon_array_fetch(&models_behaviors, behaviors, entity_name, PH_NOISY); + + phalcon_is_iterable(models_behaviors, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(behavior); + + PHALCON_INIT_NVAR(result); + phalcon_call_method_p3_key(result, behavior, "missingmethod", model, event_name, data, 965701664UL); + if (Z_TYPE_P(result) != IS_NULL) { + RETURN_CCTOR(result); + } + + zend_hash_move_forward_ex(ah0, &hp0); } -yy220: -// 141 "scanner.re" - { - token->opcode = PHQL_T_ASC; - return 0; + } -// 3750 "scanner.c" -yy221: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy222; - } -yy222: -// 176 "scanner.re" - { - token->opcode = PHQL_T_AND; - return 0; + } + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_VAR(fire_event_name); + PHALCON_CONCAT_SV(fire_event_name, "model:", event_name); + phalcon_call_method_p3_key(return_value, events_manager, "fire", fire_event_name, model, data, 259017035UL); + RETURN_MM(); + } + + RETURN_MM_NULL(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, addBehavior){ + + zval *model, *behavior, *entity_name, *behaviors; + zval *models_behaviors = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &behavior); + + if (Z_TYPE_P(behavior) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The behavior is invalid"); + return; + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + PHALCON_OBS_VAR(behaviors); + phalcon_read_property_this_quick(&behaviors, this_ptr, SL("_behaviors"), 712001671UL, PH_NOISY_CC); + if (phalcon_array_isset(behaviors, entity_name)) { + PHALCON_OBS_VAR(models_behaviors); + phalcon_array_fetch(&models_behaviors, behaviors, entity_name, PH_NOISY); + } else { + PHALCON_INIT_NVAR(models_behaviors); + array_init(models_behaviors); + } + + phalcon_array_append(&models_behaviors, behavior, PH_SEPARATE); + + phalcon_update_property_array(this_ptr, SL("_behaviors"), entity_name, models_behaviors TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, keepSnapshots){ + + zval *model, *keep_snapshots, *entity_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &keep_snapshots); + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_keepSnapshots"), entity_name, keep_snapshots TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, isKeepingSnapshots){ + + zval *model, *keep_snapshots, *entity_name, *is_keeping; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_OBS_VAR(keep_snapshots); + phalcon_read_property_this_quick(&keep_snapshots, this_ptr, SL("_keepSnapshots"), 2428293068UL, PH_NOISY_CC); + if (Z_TYPE_P(keep_snapshots) == IS_ARRAY) { + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(keep_snapshots, entity_name)) { + PHALCON_OBS_VAR(is_keeping); + phalcon_array_fetch(&is_keeping, keep_snapshots, entity_name, PH_NOISY); + RETURN_CCTOR(is_keeping); } -// 3826 "scanner.c" -yy223: - yych = *++YYCURSOR; - switch (yych) { - case 'I': - case 'i': goto yy224; - default: goto yy87; - } -yy224: - yych = *++YYCURSOR; - switch (yych) { - case 'N': - case 'n': goto yy225; - default: goto yy87; - } -yy225: - yych = *++YYCURSOR; - switch (yych) { - case 'S': - case 's': goto yy226; - default: goto yy87; - } -yy226: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy227; - default: goto yy87; - } -yy227: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy228; - } -yy228: -// 196 "scanner.re" - { - token->opcode = PHQL_T_AGAINST; - return 0; + } + + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, useDynamicUpdate){ + + zval *model, *dynamic_update, *entity_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &dynamic_update); + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_dynamicUpdate"), entity_name, dynamic_update TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_keepSnapshots"), entity_name, dynamic_update TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, isUsingDynamicUpdate){ + + zval *model, *dynamic_update, *entity_name, *is_using; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_OBS_VAR(dynamic_update); + phalcon_read_property_this_quick(&dynamic_update, this_ptr, SL("_dynamicUpdate"), 3808158412UL, PH_NOISY_CC); + if (Z_TYPE_P(dynamic_update) == IS_ARRAY) { + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(dynamic_update, entity_name)) { + PHALCON_OBS_VAR(is_using); + phalcon_array_fetch(&is_using, dynamic_update, entity_name, PH_NOISY); + RETURN_CCTOR(is_using); } -// 3930 "scanner.c" -yy229: - yych = *++YYCURSOR; - switch (yych) { - case 'L': - case 'l': goto yy238; - default: goto yy87; - } -yy230: - yych = *++YYCURSOR; - switch (yych) { - case 'O': - case 'o': goto yy235; - default: goto yy87; - } -yy231: - yych = *++YYCURSOR; - switch (yych) { - case 'L': - case 'l': goto yy232; - default: goto yy87; - } -yy232: - yych = *++YYCURSOR; - switch (yych) { - case 'L': - case 'l': goto yy233; - default: goto yy87; - } -yy233: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy234; - } -yy234: -// 241 "scanner.re" - { - token->opcode = PHQL_T_FULL; - return 0; + } + + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, addHasOne){ + + zval *model, *fields, *referenced_model, *referenced_fields; + zval *options = NULL, *entity_name, *referenced_entity; + zval *key_relation, *has_one, *relations = NULL, *number_fields; + zval *number_referenced, *type, *relation, *alias; + zval *lower_alias = NULL, *key_alias, *has_one_single; + zval *single_relations = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 4, 1, &model, &fields, &referenced_model, &referenced_fields, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + PHALCON_INIT_VAR(referenced_entity); + phalcon_fast_strtolower(referenced_entity, referenced_model); + + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", referenced_entity); + + PHALCON_OBS_VAR(has_one); + phalcon_read_property_this_quick(&has_one, this_ptr, SL("_hasOne"), 1482461634UL, PH_NOISY_CC); + if (!phalcon_array_isset(has_one, key_relation)) { + PHALCON_INIT_VAR(relations); + array_init(relations); + } else { + PHALCON_OBS_NVAR(relations); + phalcon_array_fetch(&relations, has_one, key_relation, PH_NOISY); + } + + if (Z_TYPE_P(referenced_fields) == IS_ARRAY) { + + PHALCON_INIT_VAR(number_fields); + phalcon_fast_count(number_fields, fields TSRMLS_CC); + + PHALCON_INIT_VAR(number_referenced); + phalcon_fast_count(number_referenced, referenced_fields TSRMLS_CC); + if (!PHALCON_IS_EQUAL(number_fields, number_referenced)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Number of referenced fields are not the same"); + return; } -// 4034 "scanner.c" -yy235: - yych = *++YYCURSOR; - switch (yych) { - case 'M': - case 'm': goto yy236; - default: goto yy87; - } -yy236: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy237; - } -yy237: -// 96 "scanner.re" - { - token->opcode = PHQL_T_FROM; - return 0; + } + + PHALCON_INIT_VAR(type); + ZVAL_LONG(type, 1); + + PHALCON_INIT_VAR(relation); + object_init_ex(relation, phalcon_mvc_model_relation_ce); + phalcon_call_method_p5_key(NULL, relation, "__construct", type, referenced_model, fields, referenced_fields, options, 1107214344UL); + + if (phalcon_array_isset_quick_string(options, SS("alias"), 4060151663UL)) { + PHALCON_OBS_VAR(alias); + phalcon_array_fetch_quick_string(&alias, options, SS("alias"), 4060151663UL, PH_NOISY); + + PHALCON_INIT_VAR(lower_alias); + phalcon_fast_strtolower(lower_alias, alias); + } else { + PHALCON_CPY_WRT(lower_alias, referenced_entity); + } + + phalcon_array_append(&relations, relation, PH_SEPARATE); + + PHALCON_INIT_VAR(key_alias); + PHALCON_CONCAT_VSV(key_alias, entity_name, "$", lower_alias); + phalcon_update_property_array(this_ptr, SL("_aliases"), key_alias, relation TSRMLS_CC); + + phalcon_update_property_array(this_ptr, SL("_hasOne"), key_relation, relations TSRMLS_CC); + + PHALCON_OBS_VAR(has_one_single); + phalcon_read_property_this_quick(&has_one_single, this_ptr, SL("_hasOneSingle"), 829919940UL, PH_NOISY_CC); + if (!phalcon_array_isset(has_one_single, entity_name)) { + PHALCON_INIT_VAR(single_relations); + array_init(single_relations); + } else { + PHALCON_OBS_NVAR(single_relations); + phalcon_array_fetch(&single_relations, has_one_single, entity_name, PH_NOISY); + } + + phalcon_array_append(&single_relations, relation, PH_SEPARATE); + + phalcon_update_property_array(this_ptr, SL("_hasOneSingle"), entity_name, single_relations TSRMLS_CC); + + RETURN_CTOR(relation); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, addBelongsTo){ + + zval *model, *fields, *referenced_model, *referenced_fields; + zval *options = NULL, *entity_name, *referenced_entity; + zval *key_relation, *belongs_to, *relations = NULL; + zval *number_fields, *number_referenced, *type; + zval *relation, *alias, *lower_alias = NULL, *key_alias; + zval *belongs_to_single, *single_relations = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 4, 1, &model, &fields, &referenced_model, &referenced_fields, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + PHALCON_INIT_VAR(referenced_entity); + phalcon_fast_strtolower(referenced_entity, referenced_model); + + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", referenced_entity); + + PHALCON_OBS_VAR(belongs_to); + phalcon_read_property_this_quick(&belongs_to, this_ptr, SL("_belongsTo"), 4267387377UL, PH_NOISY_CC); + if (!phalcon_array_isset(belongs_to, key_relation)) { + PHALCON_INIT_VAR(relations); + array_init(relations); + } else { + PHALCON_OBS_NVAR(relations); + phalcon_array_fetch(&relations, belongs_to, key_relation, PH_NOISY); + } + + if (Z_TYPE_P(referenced_fields) == IS_ARRAY) { + + PHALCON_INIT_VAR(number_fields); + phalcon_fast_count(number_fields, fields TSRMLS_CC); + + PHALCON_INIT_VAR(number_referenced); + phalcon_fast_count(number_referenced, referenced_fields TSRMLS_CC); + if (!PHALCON_IS_EQUAL(number_fields, number_referenced)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Number of referenced fields are not the same"); + return; } -// 4117 "scanner.c" -yy238: - yych = *++YYCURSOR; - switch (yych) { - case 'S': - case 's': goto yy239; - default: goto yy87; - } -yy239: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy240; - default: goto yy87; - } -yy240: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy241; - } -yy241: -// 286 "scanner.re" - { - token->opcode = PHQL_T_FALSE; - return 0; + } + + PHALCON_INIT_VAR(type); + ZVAL_LONG(type, 0); + + PHALCON_INIT_VAR(relation); + object_init_ex(relation, phalcon_mvc_model_relation_ce); + phalcon_call_method_p5_key(NULL, relation, "__construct", type, referenced_model, fields, referenced_fields, options, 1107214344UL); + + if (phalcon_array_isset_quick_string(options, SS("alias"), 4060151663UL)) { + PHALCON_OBS_VAR(alias); + phalcon_array_fetch_quick_string(&alias, options, SS("alias"), 4060151663UL, PH_NOISY); + + PHALCON_INIT_VAR(lower_alias); + phalcon_fast_strtolower(lower_alias, alias); + } else { + PHALCON_CPY_WRT(lower_alias, referenced_entity); + } + + phalcon_array_append(&relations, relation, PH_SEPARATE); + + PHALCON_INIT_VAR(key_alias); + PHALCON_CONCAT_VSV(key_alias, entity_name, "$", lower_alias); + phalcon_update_property_array(this_ptr, SL("_aliases"), key_alias, relation TSRMLS_CC); + + phalcon_update_property_array(this_ptr, SL("_belongsTo"), key_relation, relations TSRMLS_CC); + + PHALCON_OBS_VAR(belongs_to_single); + phalcon_read_property_this_quick(&belongs_to_single, this_ptr, SL("_belongsToSingle"), 2482590259UL, PH_NOISY_CC); + if (!phalcon_array_isset(belongs_to_single, entity_name)) { + PHALCON_INIT_VAR(single_relations); + array_init(single_relations); + } else { + PHALCON_OBS_NVAR(single_relations); + phalcon_array_fetch(&single_relations, belongs_to_single, entity_name, PH_NOISY); + } + + phalcon_array_append(&single_relations, relation, PH_SEPARATE); + + phalcon_update_property_array(this_ptr, SL("_belongsToSingle"), entity_name, single_relations TSRMLS_CC); + + RETURN_CTOR(relation); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, addHasMany){ + + zval *model, *fields, *referenced_model, *referenced_fields; + zval *options = NULL, *entity_name, *referenced_entity; + zval *key_relation, *has_many, *relations = NULL, *number_fields; + zval *number_referenced, *type, *relation, *alias; + zval *lower_alias = NULL, *key_alias, *has_many_single; + zval *single_relations = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 4, 1, &model, &fields, &referenced_model, &referenced_fields, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + PHALCON_INIT_VAR(referenced_entity); + phalcon_fast_strtolower(referenced_entity, referenced_model); + + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", referenced_entity); + + PHALCON_OBS_VAR(has_many); + phalcon_read_property_this_quick(&has_many, this_ptr, SL("_hasMany"), 1673768437UL, PH_NOISY_CC); + if (!phalcon_array_isset(has_many, key_relation)) { + PHALCON_INIT_VAR(relations); + array_init(relations); + } else { + PHALCON_OBS_NVAR(relations); + phalcon_array_fetch(&relations, has_many, key_relation, PH_NOISY); + } + + if (Z_TYPE_P(referenced_fields) == IS_ARRAY) { + + PHALCON_INIT_VAR(number_fields); + phalcon_fast_count(number_fields, fields TSRMLS_CC); + + PHALCON_INIT_VAR(number_referenced); + phalcon_fast_count(number_referenced, referenced_fields TSRMLS_CC); + if (!PHALCON_IS_EQUAL(number_fields, number_referenced)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Number of referenced fields are not the same"); + return; } -// 4207 "scanner.c" -yy242: - yych = *++YYCURSOR; - switch (yych) { - case 'L': - case 'l': goto yy251; - case 'S': - case 's': goto yy252; - default: goto yy87; - } -yy243: - yych = *++YYCURSOR; - switch (yych) { - case 'S': - case 's': goto yy244; - default: goto yy87; - } -yy244: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy245; - default: goto yy87; - } -yy245: - yych = *++YYCURSOR; - switch (yych) { - case 'I': - case 'i': goto yy246; - default: goto yy87; - } -yy246: - yych = *++YYCURSOR; - switch (yych) { - case 'N': - case 'n': goto yy247; - default: goto yy87; - } -yy247: - yych = *++YYCURSOR; - switch (yych) { - case 'C': - case 'c': goto yy248; - default: goto yy87; - } -yy248: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy249; - default: goto yy87; - } -yy249: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy250; - } -yy250: -// 256 "scanner.re" - { - token->opcode = PHQL_T_DISTINCT; - return 0; - } -// 4334 "scanner.c" -yy251: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy255; - default: goto yy87; - } -yy252: - yych = *++YYCURSOR; - switch (yych) { - case 'C': - case 'c': goto yy253; - default: goto yy87; - } -yy253: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy254; - } -yy254: -// 146 "scanner.re" - { - token->opcode = PHQL_T_DESC; - return 0; - } -// 4424 "scanner.c" -yy255: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy256; - default: goto yy87; - } -yy256: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy257; - default: goto yy87; - } -yy257: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy258; - } -yy258: -// 91 "scanner.re" - { - token->opcode = PHQL_T_DELETE; - return 0; + } + + PHALCON_INIT_VAR(type); + ZVAL_LONG(type, 2); + + PHALCON_INIT_VAR(relation); + object_init_ex(relation, phalcon_mvc_model_relation_ce); + phalcon_call_method_p5_key(NULL, relation, "__construct", type, referenced_model, fields, referenced_fields, options, 1107214344UL); + + if (phalcon_array_isset_quick_string(options, SS("alias"), 4060151663UL)) { + PHALCON_OBS_VAR(alias); + phalcon_array_fetch_quick_string(&alias, options, SS("alias"), 4060151663UL, PH_NOISY); + + PHALCON_INIT_VAR(lower_alias); + phalcon_fast_strtolower(lower_alias, alias); + } else { + PHALCON_CPY_WRT(lower_alias, referenced_entity); + } + + phalcon_array_append(&relations, relation, PH_SEPARATE); + + PHALCON_INIT_VAR(key_alias); + PHALCON_CONCAT_VSV(key_alias, entity_name, "$", lower_alias); + phalcon_update_property_array(this_ptr, SL("_aliases"), key_alias, relation TSRMLS_CC); + + phalcon_update_property_array(this_ptr, SL("_hasMany"), key_relation, relations TSRMLS_CC); + + PHALCON_OBS_VAR(has_many_single); + phalcon_read_property_this_quick(&has_many_single, this_ptr, SL("_hasManySingle"), 2728249655UL, PH_NOISY_CC); + if (!phalcon_array_isset(has_many_single, entity_name)) { + PHALCON_INIT_VAR(single_relations); + array_init(single_relations); + } else { + PHALCON_OBS_NVAR(single_relations); + phalcon_array_fetch(&single_relations, has_many_single, entity_name, PH_NOISY); + } + + phalcon_array_append(&single_relations, relation, PH_SEPARATE); + + phalcon_update_property_array(this_ptr, SL("_hasManySingle"), entity_name, single_relations TSRMLS_CC); + + RETURN_CTOR(relation); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, addHasManyToMany){ + + zval *model, *fields, *intermediate_model, *intermediate_fields; + zval *intermediate_referenced_fields, *referenced_model; + zval *referenced_fields, *options = NULL, *entity_name; + zval *intermediate_entity, *referenced_entity; + zval *key_relation, *has_many_to_many, *relations = NULL; + zval *number_fields = NULL, *number_referenced = NULL, *type; + zval *relation, *alias, *lower_alias = NULL, *key_alias; + zval *has_many_to_many_single, *single_relations = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 7, 1, &model, &fields, &intermediate_model, &intermediate_fields, &intermediate_referenced_fields, &referenced_model, &referenced_fields, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } + + PHALCON_INIT_VAR(entity_name); + phalcon_get_class(entity_name, model, 1 TSRMLS_CC); + + PHALCON_INIT_VAR(intermediate_entity); + phalcon_fast_strtolower(intermediate_entity, intermediate_model); + + PHALCON_INIT_VAR(referenced_entity); + phalcon_fast_strtolower(referenced_entity, referenced_model); + + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", referenced_entity); + + PHALCON_OBS_VAR(has_many_to_many); + phalcon_read_property_this_quick(&has_many_to_many, this_ptr, SL("_hasManyToMany"), 4215181805UL, PH_NOISY_CC); + if (!phalcon_array_isset(has_many_to_many, key_relation)) { + PHALCON_INIT_VAR(relations); + array_init(relations); + } else { + PHALCON_OBS_NVAR(relations); + phalcon_array_fetch(&relations, has_many_to_many, key_relation, PH_NOISY); + } + + if (Z_TYPE_P(intermediate_fields) == IS_ARRAY) { + + PHALCON_INIT_VAR(number_fields); + phalcon_fast_count(number_fields, fields TSRMLS_CC); + + PHALCON_INIT_VAR(number_referenced); + phalcon_fast_count(number_referenced, intermediate_fields TSRMLS_CC); + if (!PHALCON_IS_EQUAL(number_fields, number_referenced)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Number of referenced fields are not the same"); + return; } -// 4514 "scanner.c" -yy259: - yych = *++YYCURSOR; - switch (yych) { - case 'L': - case 'l': goto yy262; - case 'T': - case 't': goto yy260; - default: goto yy87; - } -yy260: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy261; - } -yy261: -// 86 "scanner.re" - { - token->opcode = PHQL_T_SET; - return 0; + } + + if (Z_TYPE_P(intermediate_referenced_fields) == IS_ARRAY) { + + PHALCON_INIT_NVAR(number_fields); + phalcon_fast_count(number_fields, fields TSRMLS_CC); + + PHALCON_INIT_NVAR(number_referenced); + phalcon_fast_count(number_referenced, intermediate_fields TSRMLS_CC); + if (!PHALCON_IS_EQUAL(number_fields, number_referenced)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Number of referenced fields are not the same"); + return; } -// 4599 "scanner.c" -yy262: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy263; - default: goto yy87; - } -yy263: - yych = *++YYCURSOR; - switch (yych) { - case 'C': - case 'c': goto yy264; - default: goto yy87; - } -yy264: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy265; - default: goto yy87; - } -yy265: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy266; - } -yy266: -// 126 "scanner.re" - { - token->opcode = PHQL_T_SELECT; - return 0; - } -// 4696 "scanner.c" -yy267: - yych = *++YYCURSOR; - switch (yych) { - case 'D': - case 'd': goto yy273; - default: goto yy87; - } -yy268: - yych = *++YYCURSOR; - switch (yych) { - case 'I': - case 'i': goto yy269; - default: goto yy87; - } -yy269: - yych = *++YYCURSOR; - switch (yych) { - case 'N': - case 'n': goto yy270; - default: goto yy87; - } -yy270: - yych = *++YYCURSOR; - switch (yych) { - case 'G': - case 'g': goto yy271; - default: goto yy87; - } -yy271: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy272; - } -yy272: -// 276 "scanner.re" - { - token->opcode = PHQL_T_USING; - return 0; - } -// 4800 "scanner.c" -yy273: - yych = *++YYCURSOR; - switch (yych) { - case 'A': - case 'a': goto yy274; - default: goto yy87; - } -yy274: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy275; - default: goto yy87; - } -yy275: - yych = *++YYCURSOR; - switch (yych) { - case 'E': - case 'e': goto yy276; - default: goto yy87; - } -yy276: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy86; - default: goto yy277; - } -yy277: -// 81 "scanner.re" - { - token->opcode = PHQL_T_UPDATE; - return 0; - } -// 4897 "scanner.c" -yy278: - ++YYCURSOR; - yych = *YYCURSOR; - switch (yych) { - case '-': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto yy278; - case ':': goto yy280; - default: goto yy83; - } -yy280: - ++YYCURSOR; -// 73 "scanner.re" - { - token->opcode = PHQL_T_SPLACEHOLDER; - token->value = estrndup(q, YYCURSOR - q - 1); - token->len = YYCURSOR - q - 1; - q = YYCURSOR; - return 0; - } -// 4979 "scanner.c" -yy282: - ++YYCURSOR; - yych = *YYCURSOR; - switch (yych) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy282; - default: goto yy284; - } -yy284: -// 64 "scanner.re" - { - token->opcode = PHQL_T_NPLACEHOLDER; - token->value = estrndup(q, YYCURSOR - q); - token->len = YYCURSOR - q; - q = YYCURSOR; - return 0; - } -// 5005 "scanner.c" -yy285: - ++YYCURSOR; - yych = *YYCURSOR; - switch (yych) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy285; - default: goto yy287; - } -yy287: -// 55 "scanner.re" - { - token->opcode = PHQL_T_DOUBLE; - token->value = estrndup(q, YYCURSOR - q); - token->len = YYCURSOR - q; - q = YYCURSOR; - return 0; - } -// 5031 "scanner.c" -yy288: - ++YYCURSOR; - yych = *YYCURSOR; - switch (yych) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy288; - default: goto yy287; - } -yy290: - ++YYCURSOR; - yych = *YYCURSOR; - switch (yych) { - case '.': goto yy288; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto yy290; - default: goto yy3; - } - } -// 453 "scanner.re" - } - - return status; + + PHALCON_INIT_VAR(type); + ZVAL_LONG(type, 4); + + PHALCON_INIT_VAR(relation); + object_init_ex(relation, phalcon_mvc_model_relation_ce); + phalcon_call_method_p5_key(NULL, relation, "__construct", type, referenced_model, fields, referenced_fields, options, 1107214344UL); + + phalcon_call_method_p3_key(NULL, relation, "setintermediaterelation", intermediate_fields, intermediate_model, intermediate_referenced_fields, 204485098UL); + + if (phalcon_array_isset_quick_string(options, SS("alias"), 4060151663UL)) { + PHALCON_OBS_VAR(alias); + phalcon_array_fetch_quick_string(&alias, options, SS("alias"), 4060151663UL, PH_NOISY); + + PHALCON_INIT_VAR(lower_alias); + phalcon_fast_strtolower(lower_alias, alias); + } else { + PHALCON_CPY_WRT(lower_alias, referenced_entity); + } + + phalcon_array_append(&relations, relation, PH_SEPARATE); + + PHALCON_INIT_VAR(key_alias); + PHALCON_CONCAT_VSV(key_alias, entity_name, "$", lower_alias); + phalcon_update_property_array(this_ptr, SL("_aliases"), key_alias, relation TSRMLS_CC); + + phalcon_update_property_array(this_ptr, SL("_hasManyToMany"), key_relation, relations TSRMLS_CC); + + PHALCON_OBS_VAR(has_many_to_many_single); + phalcon_read_property_this_quick(&has_many_to_many_single, this_ptr, SL("_hasManyToManySingle"), 3823224623UL, PH_NOISY_CC); + if (!phalcon_array_isset(has_many_to_many_single, entity_name)) { + PHALCON_INIT_VAR(single_relations); + array_init(single_relations); + } else { + PHALCON_OBS_NVAR(single_relations); + phalcon_array_fetch(&single_relations, has_many_to_many_single, entity_name, PH_NOISY); + } + + phalcon_array_append(&single_relations, relation, PH_SEPARATE); + + phalcon_update_property_array(this_ptr, SL("_hasManyToManySingle"), entity_name, single_relations TSRMLS_CC); + + RETURN_CTOR(relation); } +static PHP_METHOD(Phalcon_Mvc_Model_Manager, existsBelongsTo){ + zval *model_name, *model_relation, *initialized; + zval *entity_name, *entity_relation, *key_relation; + zval *belongs_to; + PHALCON_MM_GROW(); -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query_StatusInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model\\Query, StatusInterface, mvc_model_query_statusinterface, phalcon_mvc_model_query_statusinterface_method_entry); - - return SUCCESS; + phalcon_fetch_params(1, 2, 0, &model_name, &model_relation); + + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); + + PHALCON_INIT_VAR(entity_relation); + phalcon_fast_strtolower(entity_relation, model_relation); + + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", entity_relation); + + if (!phalcon_array_isset(initialized, entity_name)) { + phalcon_call_method_p1_key(NULL, this_ptr, "load", model_name, 266329637UL); + } + + PHALCON_OBS_VAR(belongs_to); + phalcon_read_property_this_quick(&belongs_to, this_ptr, SL("_belongsTo"), 4267387377UL, PH_NOISY_CC); + if (phalcon_array_isset(belongs_to, key_relation)) { + RETURN_MM_TRUE; + } + + RETURN_MM_FALSE; } +static PHP_METHOD(Phalcon_Mvc_Model_Manager, existsHasMany){ + zval *model_name, *model_relation, *initialized; + zval *entity_name, *entity_relation, *key_relation; + zval *has_many; + PHALCON_MM_GROW(); - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query_BuilderInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model\\Query, BuilderInterface, mvc_model_query_builderinterface, phalcon_mvc_model_query_builderinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query_Status){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\Query, Status, mvc_model_query_status, phalcon_mvc_model_query_status_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_model_query_status_ce, SL("_success"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_query_status_ce, SL("_model"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_query_status_ce TSRMLS_CC, 1, phalcon_mvc_model_query_statusinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query_Status, __construct){ - - zval *success, *model; - - phalcon_fetch_params(0, 2, 0, &success, &model); + phalcon_fetch_params(1, 2, 0, &model_name, &model_relation); - phalcon_update_property_this_quick(this_ptr, SL("_success"), success, 1784834493UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_model"), model, 2599397109UL TSRMLS_CC); + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query_Status, getModel){ - - - RETURN_MEMBER_QUICK(this_ptr, "_model", 2599397109UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query_Status, getMessages){ - - zval *model; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(model); - phalcon_read_property_this_quick(&model, this_ptr, SL("_model"), 2599397109UL, PH_NOISY_CC); - if (Z_TYPE_P(model) == IS_OBJECT) { - phalcon_call_method_key(return_value, model, "getmessages", 4087333309UL); - RETURN_MM(); - } + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); - RETURN_MM_EMPTY_ARRAY(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query_Status, success){ - - - RETURN_MEMBER_QUICK(this_ptr, "_success", 1784834493UL); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_BehaviorInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, BehaviorInterface, mvc_model_behaviorinterface, phalcon_mvc_model_behaviorinterface_method_entry); - - return SUCCESS; -} - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_ValidationFailed){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model, ValidationFailed, mvc_model_validationfailed, "phalcon\\mvc\\model\\exception", phalcon_mvc_model_validationfailed_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_model_validationfailed_ce, SL("_model"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_validationfailed_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_ValidationFailed, __construct){ - - zval *model, *validation_messages, *message; - zval *message_str = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &validation_messages); + PHALCON_INIT_VAR(entity_relation); + phalcon_fast_strtolower(entity_relation, model_relation); - if (phalcon_fast_count_ev(validation_messages TSRMLS_CC)) { - PHALCON_OBS_VAR(message); - phalcon_array_fetch_long(&message, validation_messages, 0, PH_NOISY); + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", entity_relation); - PHALCON_INIT_VAR(message_str); - phalcon_call_method_key(message_str, message, "getmessage", 4288675242UL); - } else { - PHALCON_INIT_NVAR(message_str); - ZVAL_STRING(message_str, "Validation failed", 1); + if (!phalcon_array_isset(initialized, entity_name)) { + phalcon_call_method_p1_key(NULL, this_ptr, "load", model_name, 266329637UL); } - phalcon_update_property_this_quick(this_ptr, SL("_model"), model, 2599397109UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_messages"), validation_messages, 743366684UL TSRMLS_CC); - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Mvc\\Model\\ValidationFailed", "__construct", message_str); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_ValidationFailed, getMessages){ - - - RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_ValidationFailed, getModel){ - - - RETURN_MEMBER_QUICK(this_ptr, "_model", 2599397109UL); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Message){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Message, mvc_model_message, phalcon_mvc_model_message_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_model_message_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_message_ce, SL("_message"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_message_ce, SL("_field"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_message_ce, SL("_model"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_message_ce TSRMLS_CC, 1, phalcon_mvc_model_messageinterface_ce); - - return SUCCESS; + PHALCON_OBS_VAR(has_many); + phalcon_read_property_this_quick(&has_many, this_ptr, SL("_hasMany"), 1673768437UL, PH_NOISY_CC); + if (phalcon_array_isset(has_many, key_relation)) { + RETURN_MM_TRUE; + } + + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Model_Message, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, existsHasOne){ - zval *message, *field = NULL, *type = NULL, *model = NULL; + zval *model_name, *model_relation, *initialized; + zval *entity_name, *entity_relation, *key_relation; + zval *has_one; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 3, &message, &field, &type, &model); + phalcon_fetch_params(1, 2, 0, &model_name, &model_relation); - if (!field) { - PHALCON_INIT_VAR(field); - } + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); - if (!type) { - PHALCON_INIT_VAR(type); - } + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); - if (!model) { - PHALCON_INIT_VAR(model); - } + PHALCON_INIT_VAR(entity_relation); + phalcon_fast_strtolower(entity_relation, model_relation); - phalcon_update_property_this_quick(this_ptr, SL("_message"), message, 933579817UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_field"), field, 2318377128UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - if (Z_TYPE_P(model) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_model"), model, 2599397109UL TSRMLS_CC); + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", entity_relation); + + if (!phalcon_array_isset(initialized, entity_name)) { + phalcon_call_method_p1_key(NULL, this_ptr, "load", model_name, 266329637UL); } - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, setType){ - - zval *type; - - phalcon_fetch_params(0, 1, 0, &type); + PHALCON_OBS_VAR(has_one); + phalcon_read_property_this_quick(&has_one, this_ptr, SL("_hasOne"), 1482461634UL, PH_NOISY_CC); + if (phalcon_array_isset(has_one, key_relation)) { + RETURN_MM_TRUE; + } - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - RETURN_THISW(); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Model_Message, getType){ - - - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); -} +static PHP_METHOD(Phalcon_Mvc_Model_Manager, existsHasManyToMany){ -static PHP_METHOD(Phalcon_Mvc_Model_Message, setMessage){ + zval *model_name, *model_relation, *initialized; + zval *entity_name, *entity_relation, *key_relation; + zval *has_many_to_many; - zval *message; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &message); + phalcon_fetch_params(1, 2, 0, &model_name, &model_relation); - phalcon_update_property_this_quick(this_ptr, SL("_message"), message, 933579817UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, getMessage){ - - - RETURN_MEMBER_QUICK(this_ptr, "_message", 933579817UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, setField){ - - zval *field; - - phalcon_fetch_params(0, 1, 0, &field); + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_field"), field, 2318377128UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, getField){ - - - RETURN_MEMBER_QUICK(this_ptr, "_field", 2318377128UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, setModel){ - - zval *model; - - phalcon_fetch_params(0, 1, 0, &model); + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); - phalcon_update_property_this_quick(this_ptr, SL("_model"), model, 2599397109UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, getModel){ - - - RETURN_MEMBER_QUICK(this_ptr, "_model", 2599397109UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, __toString){ - - - RETURN_MEMBER_QUICK(this_ptr, "_message", 933579817UL); + PHALCON_INIT_VAR(entity_relation); + phalcon_fast_strtolower(entity_relation, model_relation); + + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", entity_relation); + + if (!phalcon_array_isset(initialized, entity_name)) { + phalcon_call_method_p1_key(NULL, this_ptr, "load", model_name, 266329637UL); + } + + PHALCON_OBS_VAR(has_many_to_many); + phalcon_read_property_this_quick(&has_many_to_many, this_ptr, SL("_hasManyToMany"), 4215181805UL, PH_NOISY_CC); + if (phalcon_array_isset(has_many_to_many, key_relation)) { + RETURN_MM_TRUE; + } + + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Model_Message, __set_state){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getRelationByAlias){ - zval *message, *message_text, *field, *type; + zval *model_name, *alias, *aliases, *key_alias; + zval *key_lower, *relation; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 2, 0, &model_name, &alias); - PHALCON_OBS_VAR(message_text); - phalcon_array_fetch_quick_string(&message_text, message, SS("_message"), 933579817UL, PH_NOISY); + PHALCON_OBS_VAR(aliases); + phalcon_read_property_this_quick(&aliases, this_ptr, SL("_aliases"), 651658150UL, PH_NOISY_CC); + if (Z_TYPE_P(aliases) == IS_ARRAY) { - PHALCON_OBS_VAR(field); - phalcon_array_fetch_quick_string(&field, message, SS("_field"), 2318377128UL, PH_NOISY); + PHALCON_INIT_VAR(key_alias); + PHALCON_CONCAT_VSV(key_alias, model_name, "$", alias); - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, message, SS("_type"), 3991959110UL, PH_NOISY); - object_init_ex(return_value, phalcon_mvc_model_message_ce); - phalcon_call_method_p3_key(NULL, return_value, "__construct", message_text, field, type, 1107214344UL); + PHALCON_INIT_VAR(key_lower); + phalcon_fast_strtolower(key_lower, key_alias); + if (phalcon_array_isset(aliases, key_lower)) { + PHALCON_OBS_VAR(relation); + phalcon_array_fetch(&relation, aliases, key_lower, PH_NOISY); + RETURN_CCTOR(relation); + } + } - RETURN_MM(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaDataInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, MetaDataInterface, mvc_model_metadatainterface, phalcon_mvc_model_metadatainterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction_ManagerInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model\\Transaction, ManagerInterface, mvc_model_transaction_managerinterface, phalcon_mvc_model_transaction_managerinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction_Manager){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\Transaction, Manager, mvc_model_transaction_manager, phalcon_mvc_model_transaction_manager_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_model_transaction_manager_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_model_transaction_manager_ce, SL("_initialized"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_model_transaction_manager_ce, SL("_rollbackPendent"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_model_transaction_manager_ce, SL("_number"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_mvc_model_transaction_manager_ce, SL("_service"), "db", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_transaction_manager_ce, SL("_transactions"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_transaction_manager_ce TSRMLS_CC, 2, phalcon_mvc_model_transaction_managerinterface_ce, phalcon_di_injectionawareinterface_ce); - - return SUCCESS; + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getRelationRecords){ - zval *dependency_injector = NULL; + zval *relation, *method, *record, *parameters = NULL, *pre_conditions = NULL; + zval *placeholders = NULL, *referenced_model, *is_through; + zval *conditions = NULL, *intermediate_model, *intermediate_fields = NULL; + zval *fields = NULL, *value = NULL, *condition = NULL, *join_conditions; + zval *referenced_fields = NULL, *joined_join_conditions; + zval *joined_conditions = NULL, *builder, *query, *referenced_field = NULL; + zval *field = NULL, *ref_position = NULL, *dependency_injector; + zval *find_params, *find_arguments = NULL, *arguments; + zval *type, *retrieve_method = NULL, *reusable, *unique_key; + zval *records = NULL, *referenced_entity, *call_object; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &dependency_injector); + phalcon_fetch_params(1, 3, 1, &relation, &method, &record, ¶meters); - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); + if (!parameters) { + PHALCON_INIT_VAR(parameters); } else { - PHALCON_SEPARATE_PARAM(dependency_injector); + PHALCON_SEPARATE_PARAM(parameters); } - if (zend_is_true(dependency_injector)) { - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } else { - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_transaction_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); - return; - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); + PHALCON_INIT_VAR(pre_conditions); - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + if (Z_TYPE_P(parameters) == IS_ARRAY) { + if (phalcon_array_isset_long(parameters, 0)) { + PHALCON_OBS_NVAR(pre_conditions); + phalcon_array_fetch_long(&pre_conditions, parameters, 0, PH_NOISY); + phalcon_array_unset_long(¶meters, 0, PH_SEPARATE); + } else { + if (phalcon_array_isset_quick_string(parameters, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_NVAR(pre_conditions); + phalcon_array_fetch_quick_string(&pre_conditions, parameters, SS("conditions"), 1055696255UL, PH_NOISY); + phalcon_array_unset_string(¶meters, SS("conditions"), PH_SEPARATE); + } + } + } else { + if (Z_TYPE_P(parameters) == IS_STRING) { + PHALCON_CPY_WRT(pre_conditions, parameters); + } + } -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, setDbService){ - - zval *service; - - phalcon_fetch_params(0, 1, 0, &service); + if (Z_TYPE_P(parameters) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(parameters, SS("bind"), 254268962UL)) { + PHALCON_OBS_VAR(placeholders); + phalcon_array_fetch_quick_string(&placeholders, parameters, SS("bind"), 254268962UL, PH_NOISY); + phalcon_array_unset_string(¶meters, SS("bind"), PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(placeholders); + array_init(placeholders); + } + } else { + PHALCON_INIT_NVAR(placeholders); + array_init(placeholders); + } - phalcon_update_property_this_quick(this_ptr, SL("_service"), service, 3205872725UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, getDbService){ - - - RETURN_MEMBER_QUICK(this_ptr, "_service", 3205872725UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, setRollbackPendent){ - - zval *rollback_pendent; - - phalcon_fetch_params(0, 1, 0, &rollback_pendent); + PHALCON_INIT_VAR(referenced_model); + phalcon_call_method_key(referenced_model, relation, "getreferencedmodel", 478093161UL); - phalcon_update_property_this_quick(this_ptr, SL("_rollbackPendent"), rollback_pendent, 1836882012UL TSRMLS_CC); + PHALCON_INIT_VAR(is_through); + phalcon_call_method_key(is_through, relation, "isthrough", 2540564770UL); + if (zend_is_true(is_through)) { -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, getRollbackPendent){ - - - RETURN_MEMBER_QUICK(this_ptr, "_rollbackPendent", 1836882012UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, has){ - - zval *zero, *number; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); + PHALCON_INIT_VAR(conditions); + array_init(conditions); - PHALCON_OBS_VAR(number); - phalcon_read_property_this_quick(&number, this_ptr, SL("_number"), 1417600621UL, PH_NOISY_CC); - is_smaller_function(return_value, zero, number TSRMLS_CC); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, get){ - - zval *auto_begin = NULL, *initialized, *rollback_pendent = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &auto_begin); + PHALCON_INIT_VAR(intermediate_model); + phalcon_call_method_key(intermediate_model, relation, "getintermediatemodel", 851527441UL); - if (!auto_begin) { - PHALCON_INIT_VAR(auto_begin); - ZVAL_BOOL(auto_begin, 1); - } + PHALCON_INIT_VAR(intermediate_fields); + phalcon_call_method_key(intermediate_fields, relation, "getintermediatefields", 1646880791UL); - PHALCON_OBS_VAR(initialized); - phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); - if (zend_is_true(initialized)) { + PHALCON_INIT_VAR(fields); + phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); + if (Z_TYPE_P(fields) != IS_ARRAY) { + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", fields, 95450773UL); - PHALCON_OBS_VAR(rollback_pendent); - phalcon_read_property_this_quick(&rollback_pendent, this_ptr, SL("_rollbackPendent"), 1836882012UL, PH_NOISY_CC); - if (zend_is_true(rollback_pendent)) { - PHALCON_INIT_NVAR(rollback_pendent); - array_init_size(rollback_pendent, 2); - phalcon_array_append(&rollback_pendent, this_ptr, PH_SEPARATE); - add_next_index_stringl(rollback_pendent, SL("rollbackPendent"), 1); - phalcon_call_func_p1_noret("register_shutdown_function", rollback_pendent); + PHALCON_INIT_VAR(condition); + PHALCON_CONCAT_SVSVS(condition, "[", intermediate_model, "].[", intermediate_fields, "] = ?0"); + phalcon_array_append(&conditions, condition, PH_SEPARATE); + phalcon_array_append(&placeholders, value, PH_SEPARATE); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Not supported"); + return; } - phalcon_update_property_bool(this_ptr, SL("_initialized"), 1 TSRMLS_CC); - } - - phalcon_call_method_key(return_value, this_ptr, "getorcreatetransaction", 2952593376UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, getOrCreateTransaction){ - - zval *auto_begin = NULL, *dependency_injector, *number; - zval *transactions, *transaction = NULL, *false_value = NULL; - zval *service; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &auto_begin); - - if (!auto_begin) { - PHALCON_INIT_VAR(auto_begin); - ZVAL_BOOL(auto_begin, 1); - } - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_transaction_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); - return; - } + PHALCON_INIT_VAR(join_conditions); + array_init(join_conditions); - PHALCON_OBS_VAR(number); - phalcon_read_property_this_quick(&number, this_ptr, SL("_number"), 1417600621UL, PH_NOISY_CC); - if (zend_is_true(number)) { + PHALCON_INIT_NVAR(intermediate_fields); + phalcon_call_method_key(intermediate_fields, relation, "getintermediatereferencedfields", 3001626474UL); + if (Z_TYPE_P(intermediate_fields) != IS_ARRAY) { + PHALCON_INIT_VAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - PHALCON_OBS_VAR(transactions); - phalcon_read_property_this_quick(&transactions, this_ptr, SL("_transactions"), 3308612605UL, PH_NOISY_CC); - if (Z_TYPE_P(transactions) == IS_ARRAY) { + PHALCON_INIT_NVAR(condition); + PHALCON_CONCAT_SVSV(condition, "[", intermediate_model, "].[", intermediate_fields); + PHALCON_SCONCAT_SVSVS(condition, "] = [", referenced_model, "].[", referenced_fields, "]"); + phalcon_array_append(&join_conditions, condition, PH_SEPARATE); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Not supported"); + return; + } - phalcon_is_iterable(transactions, &ah0, &hp0, 0, 1); + PHALCON_INIT_VAR(joined_join_conditions); + phalcon_fast_join_str(joined_join_conditions, SL(" AND "), join_conditions TSRMLS_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (PHALCON_IS_NOT_EMPTY(pre_conditions)) { + phalcon_array_append(&conditions, pre_conditions, PH_SEPARATE); + } - PHALCON_GET_HVALUE(transaction); + PHALCON_INIT_VAR(joined_conditions); + phalcon_fast_join_str(joined_conditions, SL(" AND "), conditions TSRMLS_CC); - if (Z_TYPE_P(transaction) == IS_OBJECT) { - PHALCON_INIT_NVAR(false_value); - ZVAL_BOOL(false_value, 0); - phalcon_call_method_p1_key(NULL, transaction, "setisnewtransaction", false_value, 2346035325UL); - RETURN_CCTOR(transaction); - } + PHALCON_INIT_VAR(builder); + phalcon_call_method_p1_key(builder, this_ptr, "createbuilder", parameters, 2364485824UL); + phalcon_call_method_p1_key(NULL, builder, "from", referenced_model, 259337465UL); + phalcon_call_method_p2_key(NULL, builder, "innerjoin", intermediate_model, joined_join_conditions, 3760737553UL); + phalcon_call_method_p2_key(NULL, builder, "andwhere", joined_conditions, placeholders, 3363158931UL); - zend_hash_move_backwards_ex(ah0, &hp0); - } + PHALCON_INIT_VAR(query); + phalcon_call_method_key(query, builder, "getquery", 4154457883UL); - } + phalcon_call_method_key(return_value, query, "execute", 3117639032UL); + RETURN_MM(); } - PHALCON_OBS_VAR(service); - phalcon_read_property_this_quick(&service, this_ptr, SL("_service"), 3205872725UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(transaction); - object_init_ex(transaction, phalcon_mvc_model_transaction_ce); - phalcon_call_method_p3_key(NULL, transaction, "__construct", dependency_injector, auto_begin, service, 1107214344UL); + if (Z_TYPE_P(pre_conditions) != IS_NULL) { + PHALCON_INIT_NVAR(conditions); + array_init_size(conditions, 1); + phalcon_array_append(&conditions, pre_conditions, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(conditions); + array_init(conditions); + } - phalcon_call_method_p1_key(NULL, transaction, "settransactionmanager", this_ptr, 1385845106UL); - phalcon_update_property_array_append(this_ptr, SL("_transactions"), transaction TSRMLS_CC); - phalcon_property_incr(this_ptr, SL("_number") TSRMLS_CC); + PHALCON_INIT_NVAR(fields); + phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); + if (Z_TYPE_P(fields) != IS_ARRAY) { + PHALCON_INIT_NVAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", fields, 95450773UL); - RETURN_CTOR(transaction); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, rollbackPendent){ - - - PHALCON_MM_GROW(); - - phalcon_call_method_key(NULL, this_ptr, "rollback", 3199546639UL); + PHALCON_INIT_VAR(referenced_field); + phalcon_call_method_key(referenced_field, relation, "getreferencedfields", 2208451439UL); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, commit){ - - zval *transactions, *transaction = NULL, *connection = NULL; - zval *is_under_transaction = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(transactions); - phalcon_read_property_this_quick(&transactions, this_ptr, SL("_transactions"), 3308612605UL, PH_NOISY_CC); - if (Z_TYPE_P(transactions) == IS_ARRAY) { + PHALCON_INIT_NVAR(condition); + PHALCON_CONCAT_SVS(condition, "[", referenced_field, "] = ?0"); + phalcon_array_append(&conditions, condition, PH_SEPARATE); + phalcon_array_append(&placeholders, value, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - phalcon_is_iterable(transactions, &ah0, &hp0, 0, 0); + phalcon_is_iterable(fields, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_GET_HVALUE(transaction); + PHALCON_GET_HKEY(ref_position, ah0, hp0); + PHALCON_GET_HVALUE(field); - PHALCON_INIT_NVAR(connection); - phalcon_call_method_key(connection, transaction, "getconnection", 2504689909UL); + PHALCON_INIT_NVAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); - PHALCON_INIT_NVAR(is_under_transaction); - phalcon_call_method_key(is_under_transaction, connection, "isundertransaction", 4040888005UL); - if (zend_is_true(is_under_transaction)) { - phalcon_call_method_key(NULL, connection, "commit", 3546528686UL); - } + PHALCON_OBS_NVAR(referenced_field); + phalcon_array_fetch(&referenced_field, referenced_fields, ref_position, PH_NOISY); + + PHALCON_INIT_NVAR(condition); + PHALCON_CONCAT_SVSV(condition, "[", referenced_field, "] = ?", ref_position); + phalcon_array_append(&conditions, condition, PH_SEPARATE); + phalcon_array_append(&placeholders, value, PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); } } - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, rollback){ - - zval *collect = NULL, *transactions, *transaction = NULL, *connection = NULL; - zval *is_under_transaction = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &collect); + PHALCON_INIT_VAR(dependency_injector); + phalcon_call_method_key(dependency_injector, record, "getdi", 4287060818UL); - if (!collect) { - PHALCON_INIT_VAR(collect); - ZVAL_BOOL(collect, 1); + PHALCON_INIT_NVAR(joined_conditions); + phalcon_fast_join_str(joined_conditions, SL(" AND "), conditions TSRMLS_CC); + + PHALCON_INIT_VAR(find_params); + array_init_size(find_params, 3); + phalcon_array_append(&find_params, joined_conditions, PH_SEPARATE); + phalcon_array_update_quick_string(&find_params, SS("bind"), 254268962UL, &placeholders, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&find_params, SS("di"), 193489362UL, &dependency_injector, PH_COPY | PH_SEPARATE); + if (Z_TYPE_P(parameters) == IS_ARRAY) { + PHALCON_INIT_VAR(find_arguments); + phalcon_fast_array_merge(find_arguments, &find_params, ¶meters TSRMLS_CC); + } else { + PHALCON_CPY_WRT(find_arguments, find_params); } - PHALCON_OBS_VAR(transactions); - phalcon_read_property_this_quick(&transactions, this_ptr, SL("_transactions"), 3308612605UL, PH_NOISY_CC); - if (Z_TYPE_P(transactions) == IS_ARRAY) { + PHALCON_INIT_VAR(arguments); + array_init_size(arguments, 1); + phalcon_array_append(&arguments, find_arguments, PH_SEPARATE); - phalcon_is_iterable(transactions, &ah0, &hp0, 0, 0); + if (Z_TYPE_P(method) == IS_NULL) { + PHALCON_INIT_VAR(type); + phalcon_call_method_key(type, relation, "gettype", 4294422375UL); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + switch (phalcon_get_intval(type)) { - PHALCON_GET_HVALUE(transaction); + case 0: + PHALCON_INIT_VAR(retrieve_method); + ZVAL_STRING(retrieve_method, "findFirst", 1); + break; - PHALCON_INIT_NVAR(connection); - phalcon_call_method_key(connection, transaction, "getconnection", 2504689909UL); + case 1: + PHALCON_INIT_NVAR(retrieve_method); + ZVAL_STRING(retrieve_method, "findFirst", 1); + break; - PHALCON_INIT_NVAR(is_under_transaction); - phalcon_call_method_key(is_under_transaction, connection, "isundertransaction", 4040888005UL); - if (zend_is_true(is_under_transaction)) { - phalcon_call_method_key(NULL, connection, "rollback", 3199546639UL); - phalcon_call_method_key(NULL, connection, "close", 4138657211UL); - } + case 2: + PHALCON_INIT_NVAR(retrieve_method); + ZVAL_STRING(retrieve_method, "find", 1); + break; - if (zend_is_true(collect)) { - phalcon_call_method_p1_key(NULL, this_ptr, "_collecttransaction", transaction, 3516646160UL); - } + } + } else { + PHALCON_CPY_WRT(retrieve_method, method); + } - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_INIT_VAR(reusable); + phalcon_call_method_key(reusable, relation, "isreusable", 3326378900UL); + if (zend_is_true(reusable)) { + + PHALCON_INIT_VAR(unique_key); + phalcon_unique_key(unique_key, referenced_model, arguments TSRMLS_CC); + + PHALCON_INIT_VAR(records); + phalcon_call_method_p2_key(records, this_ptr, "getreusablerecords", referenced_model, unique_key, 840929610UL); + if (Z_TYPE_P(records) == IS_ARRAY || Z_TYPE_P(records) == IS_OBJECT) { + RETURN_CCTOR(records); } + } + + PHALCON_INIT_VAR(referenced_entity); + phalcon_call_method_p1_key(referenced_entity, this_ptr, "load", referenced_model, 266329637UL); + + PHALCON_INIT_VAR(call_object); + array_init_size(call_object, 2); + phalcon_array_append(&call_object, referenced_entity, PH_SEPARATE); + phalcon_array_append(&call_object, retrieve_method, PH_SEPARATE); + + PHALCON_INIT_NVAR(records); + PHALCON_CALL_USER_FUNC_ARRAY(records, call_object, arguments); + if (zend_is_true(reusable)) { + phalcon_call_method_p3_key(NULL, this_ptr, "setreusablerecords", referenced_model, unique_key, records, 2086427734UL); } - PHALCON_MM_RESTORE(); + RETURN_CCTOR(records); } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, notifyRollback){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getReusableRecords){ - zval *transaction; + zval *model_name, *key, *reusable, *records; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &transaction); + phalcon_fetch_params(1, 2, 0, &model_name, &key); - phalcon_call_method_p1_key(NULL, this_ptr, "_collecttransaction", transaction, 3516646160UL); + PHALCON_OBS_VAR(reusable); + phalcon_read_property_this_quick(&reusable, this_ptr, SL("_reusable"), 212790455UL, PH_NOISY_CC); + if (phalcon_array_isset(reusable, key)) { + PHALCON_OBS_VAR(records); + phalcon_array_fetch(&records, reusable, key, PH_NOISY); + RETURN_CCTOR(records); + } - PHALCON_MM_RESTORE(); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, notifyCommit){ - - zval *transaction; +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setReusableRecords){ - PHALCON_MM_GROW(); + zval *model_name, *key, *records; - phalcon_fetch_params(1, 1, 0, &transaction); + phalcon_fetch_params(0, 3, 0, &model_name, &key, &records); - phalcon_call_method_p1_key(NULL, this_ptr, "_collecttransaction", transaction, 3516646160UL); + phalcon_update_property_array(this_ptr, SL("_reusable"), key, records TSRMLS_CC); - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, _collectTransaction){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, clearReusableObjects){ - zval *transaction, *transactions, *new_transactions; - zval *managed_transaction = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + + phalcon_update_property_null(this_ptr, SL("_reusable") TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getBelongsToRecords){ + + zval *method, *model_name, *model_relation, *record; + zval *parameters = NULL, *belongs_to, *entity_name; + zval *entity_relation, *key_relation, *relations; + zval *relation; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &transaction); + phalcon_fetch_params(1, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); - PHALCON_OBS_VAR(transactions); - phalcon_read_property_this_quick(&transactions, this_ptr, SL("_transactions"), 3308612605UL, PH_NOISY_CC); - if (phalcon_fast_count_ev(transactions TSRMLS_CC)) { + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } - PHALCON_INIT_VAR(new_transactions); - array_init(new_transactions); + PHALCON_OBS_VAR(belongs_to); + phalcon_read_property_this_quick(&belongs_to, this_ptr, SL("_belongsTo"), 4267387377UL, PH_NOISY_CC); + if (Z_TYPE_P(belongs_to) == IS_ARRAY) { - phalcon_is_iterable(transactions, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(entity_relation); + phalcon_fast_strtolower(entity_relation, model_relation); - PHALCON_GET_HVALUE(managed_transaction); + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", entity_relation); + if (!phalcon_array_isset(belongs_to, key_relation)) { + RETURN_MM_FALSE; + } - if (PHALCON_IS_EQUAL(managed_transaction, transaction)) { - phalcon_array_append(&new_transactions, transaction, PH_SEPARATE); - phalcon_property_decr(this_ptr, SL("_number") TSRMLS_CC); - } + PHALCON_OBS_VAR(relations); + phalcon_array_fetch(&relations, belongs_to, key_relation, PH_NOISY); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_OBS_VAR(relation); + phalcon_array_fetch_long(&relation, relations, 0, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_transactions"), new_transactions, 3308612605UL TSRMLS_CC); + phalcon_call_method_p4_key(return_value, this_ptr, "getrelationrecords", relation, method, record, parameters, 4098322165UL); + RETURN_MM(); } - PHALCON_MM_RESTORE(); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, collectTransactions){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasManyRecords){ - zval *transactions, *managed_transaction = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *method, *model_name, *model_relation, *record; + zval *parameters = NULL, *has_many, *entity_name, *entity_relation; + zval *key_relation, *relations, *relation; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(transactions); - phalcon_read_property_this_quick(&transactions, this_ptr, SL("_transactions"), 3308612605UL, PH_NOISY_CC); - if (phalcon_fast_count_ev(transactions TSRMLS_CC)) { - - phalcon_is_iterable(transactions, &ah0, &hp0, 0, 0); + phalcon_fetch_params(1, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } - PHALCON_GET_HVALUE(managed_transaction); + PHALCON_OBS_VAR(has_many); + phalcon_read_property_this_quick(&has_many, this_ptr, SL("_hasMany"), 1673768437UL, PH_NOISY_CC); + if (Z_TYPE_P(has_many) == IS_ARRAY) { - phalcon_property_decr(this_ptr, SL("_number") TSRMLS_CC); + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_VAR(entity_relation); + phalcon_fast_strtolower(entity_relation, model_relation); - phalcon_update_property_null(this_ptr, SL("_transactions") TSRMLS_CC); + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", entity_relation); + if (!phalcon_array_isset(has_many, key_relation)) { + RETURN_MM_FALSE; + } + + PHALCON_OBS_VAR(relations); + phalcon_array_fetch(&relations, has_many, key_relation, PH_NOISY); + + PHALCON_OBS_VAR(relation); + phalcon_array_fetch_long(&relation, relations, 0, PH_NOISY); + + phalcon_call_method_p4_key(return_value, this_ptr, "getrelationrecords", relation, method, record, parameters, 4098322165UL); + RETURN_MM(); } - PHALCON_MM_RESTORE(); + RETURN_MM_FALSE; } +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasOneRecords){ + zval *method, *model_name, *model_relation, *record; + zval *parameters = NULL, *has_one, *entity_name, *entity_relation; + zval *key_relation, *relations, *relation; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } + + PHALCON_OBS_VAR(has_one); + phalcon_read_property_this_quick(&has_one, this_ptr, SL("_hasOne"), 1482461634UL, PH_NOISY_CC); + if (Z_TYPE_P(has_one) == IS_ARRAY) { + + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); + + PHALCON_INIT_VAR(entity_relation); + phalcon_fast_strtolower(entity_relation, model_relation); + + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", entity_relation); + if (!phalcon_array_isset(has_one, key_relation)) { + RETURN_MM_FALSE; + } + + PHALCON_OBS_VAR(relations); + phalcon_array_fetch(&relations, has_one, key_relation, PH_NOISY); + + PHALCON_OBS_VAR(relation); + phalcon_array_fetch_long(&relation, relations, 0, PH_NOISY); + + phalcon_call_method_p4_key(return_value, this_ptr, "getrelationrecords", relation, method, record, parameters, 4098322165UL); + RETURN_MM(); + } + + RETURN_MM_FALSE; +} -#ifdef HAVE_CONFIG_H -#endif - - - - - +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getBelongsTo){ -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction_Exception){ + zval *model, *belongs_to_single, *lower_name; + zval *relations; - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Transaction, Exception, mvc_model_transaction_exception, "phalcon\\mvc\\model\\exception", NULL, 0); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_OBS_VAR(belongs_to_single); + phalcon_read_property_this_quick(&belongs_to_single, this_ptr, SL("_belongsToSingle"), 2482590259UL, PH_NOISY_CC); + if (Z_TYPE_P(belongs_to_single) == IS_ARRAY) { + + PHALCON_INIT_VAR(lower_name); + phalcon_get_class(lower_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(belongs_to_single, lower_name)) { + PHALCON_OBS_VAR(relations); + phalcon_array_fetch(&relations, belongs_to_single, lower_name, PH_NOISY); + RETURN_CCTOR(relations); + } + } + + RETURN_MM_EMPTY_ARRAY(); } +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasMany){ + zval *model, *has_many_single, *lower_name, *relations; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_OBS_VAR(has_many_single); + phalcon_read_property_this_quick(&has_many_single, this_ptr, SL("_hasManySingle"), 2728249655UL, PH_NOISY_CC); + if (Z_TYPE_P(has_many_single) == IS_ARRAY) { + + PHALCON_INIT_VAR(lower_name); + phalcon_get_class(lower_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(has_many_single, lower_name)) { + PHALCON_OBS_VAR(relations); + phalcon_array_fetch(&relations, has_many_single, lower_name, PH_NOISY); + RETURN_CCTOR(relations); + } + } + + RETURN_MM_EMPTY_ARRAY(); +} -#ifdef HAVE_CONFIG_H -#endif - - - +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasOne){ + zval *model, *has_one_single, *lower_name, *relations; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_OBS_VAR(has_one_single); + phalcon_read_property_this_quick(&has_one_single, this_ptr, SL("_hasOneSingle"), 829919940UL, PH_NOISY_CC); + if (Z_TYPE_P(has_one_single) == IS_ARRAY) { + + PHALCON_INIT_VAR(lower_name); + phalcon_get_class(lower_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(has_one_single, lower_name)) { + PHALCON_OBS_VAR(relations); + phalcon_array_fetch(&relations, has_one_single, lower_name, PH_NOISY); + RETURN_CCTOR(relations); + } + } + + RETURN_MM_EMPTY_ARRAY(); +} -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction_Failed){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasManyToMany){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Transaction, Failed, mvc_model_transaction_failed, "phalcon\\mvc\\model\\transaction\\exception", phalcon_mvc_model_transaction_failed_method_entry, 0); + zval *model, *has_many_to_many_single, *lower_name; + zval *relations; - zend_declare_property_null(phalcon_mvc_model_transaction_failed_ce, SL("_record"), ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_OBS_VAR(has_many_to_many_single); + phalcon_read_property_this_quick(&has_many_to_many_single, this_ptr, SL("_hasManyToManySingle"), 3823224623UL, PH_NOISY_CC); + if (Z_TYPE_P(has_many_to_many_single) == IS_ARRAY) { + + PHALCON_INIT_VAR(lower_name); + phalcon_get_class(lower_name, model, 1 TSRMLS_CC); + if (phalcon_array_isset(has_many_to_many_single, lower_name)) { + PHALCON_OBS_VAR(relations); + phalcon_array_fetch(&relations, has_many_to_many_single, lower_name, PH_NOISY); + RETURN_CCTOR(relations); + } + } + + RETURN_MM_EMPTY_ARRAY(); } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Failed, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasOneAndHasMany){ - zval *message, *record; + zval *model, *has_one, *has_many; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &message, &record); + phalcon_fetch_params(1, 1, 0, &model); - phalcon_update_property_this_quick(this_ptr, SL("_record"), record, 1650960579UL TSRMLS_CC); - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Mvc\\Model\\Transaction\\Failed", "__construct", message); + PHALCON_INIT_VAR(has_one); + phalcon_call_method_p1_key(has_one, this_ptr, "gethasone", model, 153625411UL); - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(has_many); + phalcon_call_method_p1_key(has_many, this_ptr, "gethasmany", model, 771846038UL); + phalcon_fast_array_merge(return_value, &has_one, &has_many TSRMLS_CC); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Failed, getRecordMessages){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getRelations){ - zval *record = NULL, *messages; + zval *model_name, *entity_name, *all_relations; + zval *belongs_to, *relations = NULL, *relation = NULL, *has_many; + zval *has_one; + HashTable *ah0, *ah1, *ah2; + HashPosition hp0, hp1, hp2; + zval **hd; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(record); - phalcon_read_property_this_quick(&record, this_ptr, SL("_record"), 1650960579UL, PH_NOISY_CC); - if (Z_TYPE_P(record) != IS_NULL) { - PHALCON_INIT_NVAR(record); - phalcon_call_method_key(record, record, "getmessages", 4087333309UL); - RETURN_CCTOR(record); + phalcon_fetch_params(1, 1, 0, &model_name); + + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); + + PHALCON_INIT_VAR(all_relations); + array_init(all_relations); + + PHALCON_OBS_VAR(belongs_to); + phalcon_read_property_this_quick(&belongs_to, this_ptr, SL("_belongsToSingle"), 2482590259UL, PH_NOISY_CC); + if (Z_TYPE_P(belongs_to) == IS_ARRAY) { + if (phalcon_array_isset(belongs_to, entity_name)) { + + PHALCON_OBS_VAR(relations); + phalcon_array_fetch(&relations, belongs_to, entity_name, PH_NOISY); + + phalcon_is_iterable(relations, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(relation); + + phalcon_array_append(&all_relations, relation, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } } - PHALCON_INIT_VAR(messages); - phalcon_call_method_key(messages, this_ptr, "getmessage", 4288675242UL); + PHALCON_OBS_VAR(has_many); + phalcon_read_property_this_quick(&has_many, this_ptr, SL("_hasManySingle"), 2728249655UL, PH_NOISY_CC); + if (Z_TYPE_P(has_many) == IS_ARRAY) { + if (phalcon_array_isset(has_many, entity_name)) { - RETURN_CCTOR(messages); + PHALCON_OBS_NVAR(relations); + phalcon_array_fetch(&relations, has_many, entity_name, PH_NOISY); + + phalcon_is_iterable(relations, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(relation); + + phalcon_array_append(&all_relations, relation, PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); + } + + } + } + + PHALCON_OBS_VAR(has_one); + phalcon_read_property_this_quick(&has_one, this_ptr, SL("_hasOneSingle"), 829919940UL, PH_NOISY_CC); + if (Z_TYPE_P(has_one) == IS_ARRAY) { + if (phalcon_array_isset(has_one, entity_name)) { + + PHALCON_OBS_NVAR(relations); + phalcon_array_fetch(&relations, has_one, entity_name, PH_NOISY); + + phalcon_is_iterable(relations, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HVALUE(relation); + + phalcon_array_append(&all_relations, relation, PH_SEPARATE); + + zend_hash_move_forward_ex(ah2, &hp2); + } + + } + } + + RETURN_CTOR(all_relations); } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Failed, getRecord){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getRelationsBetween){ + zval *first, *second, *first_name, *second_name; + zval *key_relation, *belongs_to, *relations = NULL; + zval *has_many, *has_one; - RETURN_MEMBER_QUICK(this_ptr, "_record", 1650960579UL); -} + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 2, 0, &first, &second); + + PHALCON_INIT_VAR(first_name); + phalcon_fast_strtolower(first_name, first); + + PHALCON_INIT_VAR(second_name); + phalcon_fast_strtolower(second_name, second); + + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, first_name, "$", second_name); + + PHALCON_OBS_VAR(belongs_to); + phalcon_read_property_this_quick(&belongs_to, this_ptr, SL("_belongsTo"), 4267387377UL, PH_NOISY_CC); + if (Z_TYPE_P(belongs_to) == IS_ARRAY) { + if (phalcon_array_isset(belongs_to, key_relation)) { + PHALCON_OBS_VAR(relations); + phalcon_array_fetch(&relations, belongs_to, key_relation, PH_NOISY); + RETURN_CCTOR(relations); + } + } + + PHALCON_OBS_VAR(has_many); + phalcon_read_property_this_quick(&has_many, this_ptr, SL("_hasMany"), 1673768437UL, PH_NOISY_CC); + if (Z_TYPE_P(has_many) == IS_ARRAY) { + if (phalcon_array_isset(has_many, key_relation)) { + PHALCON_OBS_NVAR(relations); + phalcon_array_fetch(&relations, has_many, key_relation, PH_NOISY); + RETURN_CCTOR(relations); + } + } + + PHALCON_OBS_VAR(has_one); + phalcon_read_property_this_quick(&has_one, this_ptr, SL("_hasOne"), 1482461634UL, PH_NOISY_CC); + if (Z_TYPE_P(has_one) == IS_ARRAY) { + if (phalcon_array_isset(has_one, key_relation)) { + PHALCON_OBS_NVAR(relations); + phalcon_array_fetch(&relations, has_one, key_relation, PH_NOISY); + RETURN_CCTOR(relations); + } + } + + RETURN_MM_FALSE; +} +static PHP_METHOD(Phalcon_Mvc_Model_Manager, createQuery){ + zval *phql, *dependency_injector, *query; + PHALCON_MM_GROW(); -#ifdef HAVE_CONFIG_H -#endif + phalcon_fetch_params(1, 1, 0, &phql); + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injection object is required to access ORM services"); + return; + } + + PHALCON_INIT_VAR(query); + object_init_ex(query, phalcon_mvc_model_query_ce); + phalcon_call_method_p1_key(NULL, query, "__construct", phql, 1107214344UL); + + phalcon_call_method_p1_key(NULL, query, "setdi", dependency_injector, 461718238UL); + phalcon_update_property_this_quick(this_ptr, SL("_lastQuery"), query, 148087694UL TSRMLS_CC); + + RETURN_CTOR(query); +} +static PHP_METHOD(Phalcon_Mvc_Model_Manager, executeQuery){ + zval *phql, *placeholders = NULL, *dependency_injector; + zval *query; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 1, &phql, &placeholders); + + if (!placeholders) { + PHALCON_INIT_VAR(placeholders); + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injection object is required to access ORM services"); + return; + } + + PHALCON_INIT_VAR(query); + object_init_ex(query, phalcon_mvc_model_query_ce); + phalcon_call_method_p1_key(NULL, query, "__construct", phql, 1107214344UL); + + phalcon_call_method_p1_key(NULL, query, "setdi", dependency_injector, 461718238UL); + phalcon_update_property_this_quick(this_ptr, SL("_lastQuery"), query, 148087694UL TSRMLS_CC); + + phalcon_call_method_p1_key(return_value, query, "execute", placeholders, 3117639032UL); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Mvc_Model_Manager, createBuilder){ + zval *params = NULL, *dependency_injector; -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Files){ + PHALCON_MM_GROW(); - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\MetaData, Files, mvc_model_metadata_files, "phalcon\\mvc\\model\\metadata", phalcon_mvc_model_metadata_files_method_entry, 0); + phalcon_fetch_params(1, 0, 1, ¶ms); + + if (!params) { + PHALCON_INIT_VAR(params); + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injection object is required to access ORM services"); + return; + } + + object_init_ex(return_value, phalcon_mvc_model_query_builder_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", params, dependency_injector, 1107214344UL); + + RETURN_MM(); +} - zend_declare_property_string(phalcon_mvc_model_metadata_files_ce, SL("_metaDataDir"), "./", ZEND_ACC_PROTECTED TSRMLS_CC); +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getLastQuery){ - zend_class_implements(phalcon_mvc_model_metadata_files_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_lastQuery", 148087694UL); } -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, __construct){ - - zval *options = NULL, *meta_data_dir, *empty_array; +static PHP_METHOD(Phalcon_Mvc_Model_Manager, registerNamespaceAlias){ - PHALCON_MM_GROW(); + zval *alias, *namespace; - phalcon_fetch_params(1, 0, 1, &options); + phalcon_fetch_params(0, 2, 0, &alias, &namespace); - if (!options) { - PHALCON_INIT_VAR(options); + if (Z_TYPE_P(alias) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The namespace alias must be a string"); + return; } - - if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(options, SS("metaDataDir"), 3349936037UL)) { - PHALCON_OBS_VAR(meta_data_dir); - phalcon_array_fetch_quick_string(&meta_data_dir, options, SS("metaDataDir"), 3349936037UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_metaDataDir"), meta_data_dir, 1346965284UL TSRMLS_CC); - } + if (Z_TYPE_P(namespace) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The namespace must be a string"); + return; } - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_namespaceAliases"), alias, namespace TSRMLS_CC); - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, read){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getNamespaceAlias){ - zval *key, *separator, *meta_data_dir, *virtual_key; - zval *path, *data; + zval *alias, *namespace_aliases, *namespace; + zval *exception_message; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &key); - - PHALCON_INIT_VAR(separator); - ZVAL_STRING(separator, "_", 1); - - PHALCON_OBS_VAR(meta_data_dir); - phalcon_read_property_this_quick(&meta_data_dir, this_ptr, SL("_metaDataDir"), 1346965284UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(virtual_key); - phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); - - PHALCON_INIT_VAR(path); - PHALCON_CONCAT_VVS(path, meta_data_dir, virtual_key, ".php"); + phalcon_fetch_params(1, 1, 0, &alias); - if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_VAR(data); - if (phalcon_require_ret(data, path TSRMLS_CC) == FAILURE) { - return; - } - RETURN_CCTOR(data); + PHALCON_OBS_VAR(namespace_aliases); + phalcon_read_property_this_quick(&namespace_aliases, this_ptr, SL("_namespaceAliases"), 3928808595UL, PH_NOISY_CC); + if (phalcon_array_isset(namespace_aliases, alias)) { + PHALCON_OBS_VAR(namespace); + phalcon_array_fetch(&namespace, namespace_aliases, alias, PH_NOISY); + RETURN_CCTOR(namespace); } - RETURN_MM_NULL(); + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Namespace alias '", alias, "' is not registered"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, write){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getNamespaceAliases){ + + + RETURN_MEMBER_QUICK(this_ptr, "_namespaceAliases", 3928808595UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, __destruct){ - zval *key, *data, *separator, *meta_data_dir, *virtual_key; - zval *path, *to_string, *export, *php_export, *status; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &key, &data); - - PHALCON_INIT_VAR(separator); - ZVAL_STRING(separator, "_", 1); - - PHALCON_OBS_VAR(meta_data_dir); - phalcon_read_property_this_quick(&meta_data_dir, this_ptr, SL("_metaDataDir"), 1346965284UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(virtual_key); - phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); - - PHALCON_INIT_VAR(path); - PHALCON_CONCAT_VVS(path, meta_data_dir, virtual_key, ".php"); - - PHALCON_INIT_VAR(to_string); - ZVAL_BOOL(to_string, 1); - - PHALCON_INIT_VAR(export); - phalcon_call_func_p2(export, "var_export", data, to_string); - - PHALCON_INIT_VAR(php_export); - PHALCON_CONCAT_SVS(php_export, " +// 38 "parser.lemon" #ifdef HAVE_CONFIG_H @@ -57137,4147 +56554,3317 @@ static PHP_METHOD(Phalcon_Mvc_Model_Manager, __destruct){ -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MessageInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, MessageInterface, mvc_model_messageinterface, phalcon_mvc_model_messageinterface_method_entry); +static zval *phql_ret_literal_zval(int type, phql_parser_token *T) +{ + zval *ret; - return SUCCESS; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", type); + if (T) { + add_assoc_stringl(ret, "value", T->token, T->token_len, 0); + efree(T); + } + + return ret; } +static zval *phql_ret_placeholder_zval(int type, phql_parser_token *T) +{ + zval *ret; + MAKE_STD_ZVAL(ret); + array_init_size(ret, 2); + add_assoc_long(ret, "type", type); + add_assoc_stringl(ret, "value", T->token, T->token_len, 0); + efree(T); + return ret; +} +static zval *phql_ret_qualified_name(phql_parser_token *A, phql_parser_token *B, phql_parser_token *C) +{ + zval *ret; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHQL_T_QUALIFIED); + if (A != NULL) { + add_assoc_stringl(ret, "ns-alias", A->token, A->token_len, 0); + efree(A); + } + if (B != NULL) { + add_assoc_stringl(ret, "domain", B->token, B->token_len, 0); + efree(B); + } + add_assoc_stringl(ret, "name", C->token, C->token_len, 0); + efree(C); + return ret; +} +static zval *phql_ret_raw_qualified_name(phql_parser_token *A, phql_parser_token *B) +{ + zval *ret; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHQL_T_RAW_QUALIFIED); + if (B != NULL) { + add_assoc_stringl(ret, "domain", A->token, A->token_len, 0); + add_assoc_stringl(ret, "name", B->token, B->token_len, 0); + efree(B); + } else { + add_assoc_stringl(ret, "name", A->token, A->token_len, 0); + } + efree(A); -#ifdef HAVE_CONFIG_H -#endif + return ret; +} +static zval *phql_ret_select_statement(zval *S, zval *W, zval *O, zval *G, zval *H, zval *L) +{ + zval *ret; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHQL_T_SELECT); + add_assoc_zval(ret, "select", S); + if (W != NULL) { + add_assoc_zval(ret, "where", W); + } + if (O != NULL) { + add_assoc_zval(ret, "orderBy", O); + } + if (G != NULL) { + add_assoc_zval(ret, "groupBy", G); + } + if (H != NULL) { + add_assoc_zval(ret, "having", H); + } + if (L != NULL) { + add_assoc_zval(ret, "limit", L); + } + return ret; +} +static zval *phql_ret_select_clause(zval *columns, zval *tables, zval *join_list) +{ + zval *ret; -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction){ + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_zval(ret, "columns", columns); + add_assoc_zval(ret, "tables", tables); + if (join_list) { + add_assoc_zval(ret, "joins", join_list); + } - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Transaction, mvc_model_transaction, phalcon_mvc_model_transaction_method_entry, 0); + return ret; +} - zend_declare_property_null(phalcon_mvc_model_transaction_ce, SL("_connection"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_model_transaction_ce, SL("_activeTransaction"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_model_transaction_ce, SL("_isNewTransaction"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_model_transaction_ce, SL("_rollbackOnAbort"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_transaction_ce, SL("_manager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_transaction_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_transaction_ce, SL("_rollbackRecord"), ZEND_ACC_PROTECTED TSRMLS_CC); +static zval *phql_ret_order_item(zval *column, int sort){ - zend_class_implements(phalcon_mvc_model_transaction_ce TSRMLS_CC, 1, phalcon_mvc_model_transactioninterface_ce); + zval *ret; - return SUCCESS; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_zval(ret, "column", column); + if (sort != 0 ) { + add_assoc_long(ret, "sort", sort); + } + + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, __construct){ +static zval *phql_ret_limit_clause(phql_parser_token *L, phql_parser_token *O) +{ + zval *ret; - zval *dependency_injector, *auto_begin = NULL, *service = NULL; - zval *connection; + MAKE_STD_ZVAL(ret); + array_init(ret); - PHALCON_MM_GROW(); + add_assoc_stringl(ret, "number", L->token, L->token_len, 0); + efree(L); - phalcon_fetch_params(1, 1, 2, &dependency_injector, &auto_begin, &service); - - if (!auto_begin) { - PHALCON_INIT_VAR(auto_begin); - ZVAL_BOOL(auto_begin, 0); - } - - if (!service) { - PHALCON_INIT_VAR(service); - } else { - PHALCON_SEPARATE_PARAM(service); - } - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_transaction_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); - return; - } - if (Z_TYPE_P(service) != IS_STRING) { - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "db", 1); - } - - PHALCON_INIT_VAR(connection); - phalcon_call_method_p1_key(connection, dependency_injector, "get", service, 2090288933UL); - phalcon_update_property_this_quick(this_ptr, SL("_connection"), connection, 3057302292UL TSRMLS_CC); - if (zend_is_true(auto_begin)) { - phalcon_call_method_key(NULL, connection, "begin", 4090922282UL); + if (O != NULL) { + add_assoc_stringl(ret, "offset", O->token, O->token_len, 0); + efree(O); } - - PHALCON_MM_RESTORE(); + + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setTransactionManager){ +static zval *phql_ret_insert_statement(zval *Q, zval *F, zval *V) +{ + zval *ret; - zval *manager; + MAKE_STD_ZVAL(ret); + array_init(ret); - phalcon_fetch_params(0, 1, 0, &manager); - - if (Z_TYPE_P(manager) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_transaction_exception_ce, "Manager must be an Object"); - return; + add_assoc_long(ret, "type", PHQL_T_INSERT); + add_assoc_zval(ret, "qualifiedName", Q); + if (F != NULL) { + add_assoc_zval(ret, "fields", F); } - phalcon_update_property_this_quick(this_ptr, SL("_manager"), manager, 4140832863UL TSRMLS_CC); - + add_assoc_zval(ret, "values", V); + + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, begin){ +static zval *phql_ret_update_statement(zval *U, zval *W, zval *L) +{ + zval *ret; - zval *connection; + MAKE_STD_ZVAL(ret); + array_init(ret); - PHALCON_MM_GROW(); + add_assoc_long(ret, "type", PHQL_T_UPDATE); + add_assoc_zval(ret, "update", U); + if (W != NULL) { + add_assoc_zval(ret, "where", W); + } + if (L != NULL) { + add_assoc_zval(ret, "limit", L); + } - PHALCON_OBS_VAR(connection); - phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); - phalcon_call_method_key(return_value, connection, "begin", 4090922282UL); - RETURN_MM(); + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, commit){ +static zval *phql_ret_update_clause(zval *tables, zval *values) +{ + zval *ret; - zval *manager, *call_object, *arguments, *connection; + MAKE_STD_ZVAL(ret); + array_init_size(ret, 2); + add_assoc_zval(ret, "tables", tables); + add_assoc_zval(ret, "values", values); - PHALCON_MM_GROW(); + return ret; +} - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - if (Z_TYPE_P(manager) == IS_OBJECT) { - PHALCON_INIT_VAR(call_object); - array_init_size(call_object, 2); - phalcon_array_append(&call_object, manager, PH_SEPARATE); - add_next_index_stringl(call_object, SL("notifyCommit"), 1); - - PHALCON_INIT_VAR(arguments); - array_init_size(arguments, 1); - phalcon_array_append(&arguments, this_ptr, PH_SEPARATE); - phalcon_call_func_p2_noret("call_user_func_array", call_object, arguments); - } - - PHALCON_OBS_VAR(connection); - phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); - phalcon_call_method_key(return_value, connection, "commit", 3546528686UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, rollback){ +static zval *phql_ret_update_item(zval *column, zval *expr) +{ - zval *rollback_message = NULL, *rollback_record = NULL; - zval *manager, *call_object, *arguments, *connection; - zval *success; - zval *i0 = NULL; + zval *ret; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init_size(ret, 2); + add_assoc_zval(ret, "column", column); + add_assoc_zval(ret, "expr", expr); - phalcon_fetch_params(1, 0, 2, &rollback_message, &rollback_record); - - if (!rollback_message) { - PHALCON_INIT_VAR(rollback_message); - } else { - PHALCON_SEPARATE_PARAM(rollback_message); - } - - if (!rollback_record) { - PHALCON_INIT_VAR(rollback_record); - } else { - PHALCON_SEPARATE_PARAM(rollback_record); - } - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - if (Z_TYPE_P(manager) == IS_OBJECT) { - PHALCON_INIT_VAR(call_object); - array_init_size(call_object, 2); - phalcon_array_append(&call_object, manager, PH_SEPARATE); - add_next_index_stringl(call_object, SL("notifyRollback"), 1); - - PHALCON_INIT_VAR(arguments); - array_init_size(arguments, 1); - phalcon_array_append(&arguments, this_ptr, PH_SEPARATE); - phalcon_call_func_p2_noret("call_user_func_array", call_object, arguments); - } - - PHALCON_OBS_VAR(connection); - phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(success); - phalcon_call_method_key(success, connection, "rollback", 3199546639UL); - if (zend_is_true(success)) { - if (!zend_is_true(rollback_message)) { - PHALCON_INIT_NVAR(rollback_message); - ZVAL_STRING(rollback_message, "Transaction aborted", 1); - } - if (Z_TYPE_P(rollback_record) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_rollbackRecord"), rollback_record, 3406866061UL TSRMLS_CC); - } - - PHALCON_OBS_NVAR(rollback_record); - phalcon_read_property_this_quick(&rollback_record, this_ptr, SL("_rollbackRecord"), 3406866061UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(i0); - object_init_ex(i0, phalcon_mvc_model_transaction_failed_ce); - phalcon_call_method_p2_key(NULL, i0, "__construct", rollback_message, rollback_record, 1107214344UL); - - phalcon_throw_exception(i0 TSRMLS_CC); - return; - } - - PHALCON_MM_RESTORE(); + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, getConnection){ - - zval *rollback_on_abort, *was_aborted, *message; - zval *connection; +static zval *phql_ret_delete_statement(zval *D, zval *W, zval *L) +{ + zval *ret; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init(ret); - PHALCON_OBS_VAR(rollback_on_abort); - phalcon_read_property_this_quick(&rollback_on_abort, this_ptr, SL("_rollbackOnAbort"), 3438288323UL, PH_NOISY_CC); - if (zend_is_true(rollback_on_abort)) { - - PHALCON_INIT_VAR(was_aborted); - phalcon_call_func(was_aborted, "connection_aborted"); - if (zend_is_true(was_aborted)) { - PHALCON_INIT_VAR(message); - ZVAL_STRING(message, "The request was aborted", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "rollback", message, 3199546639UL); - } + add_assoc_long(ret, "type", PHQL_T_DELETE); + add_assoc_zval(ret, "delete", D); + if (W != NULL) { + add_assoc_zval(ret, "where", W); + } + if (L != NULL) { + add_assoc_zval(ret, "limit", L); } - - PHALCON_OBS_VAR(connection); - phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); - - RETURN_CCTOR(connection); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setIsNewTransaction){ - - zval *is_new; - - phalcon_fetch_params(0, 1, 0, &is_new); - - phalcon_update_property_this_quick(this_ptr, SL("_isNewTransaction"), is_new, 3116442896UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setRollbackOnAbort){ - - zval *rollback_on_abort; - phalcon_fetch_params(0, 1, 0, &rollback_on_abort); - - phalcon_update_property_this_quick(this_ptr, SL("_rollbackOnAbort"), rollback_on_abort, 3438288323UL TSRMLS_CC); - + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, isManaged){ - - zval *manager; - zval *r0 = NULL; +static zval *phql_ret_delete_clause(zval *tables) +{ + zval *ret; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init_size(ret, 1); + add_assoc_zval(ret, "tables", tables); - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - - PHALCON_ALLOC_ZVAL_MM(r0); - boolean_not_function(r0, manager TSRMLS_CC); - RETURN_NCTOR(r0); + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, getMessages){ +static zval *phql_ret_zval_list(zval *list_left, zval *right_list) +{ + zval *ret; + HashPosition pos; + HashTable *list; - RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); -} + MAKE_STD_ZVAL(ret); + array_init(ret); -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, isValid){ + list = Z_ARRVAL_P(list_left); + if (zend_hash_index_exists(list, 0)) { + zend_hash_internal_pointer_reset_ex(list, &pos); + for (;; zend_hash_move_forward_ex(list, &pos)) { - zval *connection; + zval ** item; - PHALCON_MM_GROW(); + if (zend_hash_get_current_data_ex(list, (void**)&item, &pos) == FAILURE) { + break; + } - PHALCON_OBS_VAR(connection); - phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); - phalcon_call_method_key(return_value, connection, "isundertransaction", 4040888005UL); - RETURN_MM(); -} + Z_ADDREF_PP(item); + add_next_index_zval(ret, *item); -static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setRollbackedRecord){ + } + zval_ptr_dtor(&list_left); + } else { + add_next_index_zval(ret, list_left); + } - zval *record; + if (right_list) { + add_next_index_zval(ret, right_list); + } - phalcon_fetch_params(0, 1, 0, &record); - - phalcon_update_property_this_quick(this_ptr, SL("_rollbackRecord"), record, 3406866061UL TSRMLS_CC); - + return ret; } +static zval *phql_ret_column_item(int type, zval *column, phql_parser_token *identifier_column, phql_parser_token *alias) +{ + zval *ret; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", type); + if (column) { + add_assoc_zval(ret, "column", column); + } + if (identifier_column) { + add_assoc_stringl(ret, "column", identifier_column->token, identifier_column->token_len, 0); + efree(identifier_column); + } + if (alias) { + add_assoc_stringl(ret, "alias", alias->token, alias->token_len, 0); + efree(alias); + } + return ret; +} -#ifdef HAVE_CONFIG_H -#endif - - - - - - +static zval *phql_ret_assoc_name(zval *qualified_name, phql_parser_token *alias) +{ -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Row){ + zval *ret; - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Row, mvc_model_row, phalcon_mvc_model_row_method_entry, 0); + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_zval(ret, "qualifiedName", qualified_name); + if (alias) { + add_assoc_stringl(ret, "alias", alias->token, alias->token_len, 0); + efree(alias); + } - zend_class_implements(phalcon_mvc_model_row_ce TSRMLS_CC, 2, zend_ce_arrayaccess, phalcon_mvc_model_resultinterface_ce); + return ret; - return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Model_Row, setDirtyState){ +static zval *phql_ret_join_type(int type) +{ + zval *ret; - zval *dirty_state; + MAKE_STD_ZVAL(ret); + ZVAL_LONG(ret, type); - phalcon_fetch_params(0, 1, 0, &dirty_state); - - RETURN_FALSE; + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model_Row, offsetExists){ - - zval *index; - - phalcon_fetch_params(0, 1, 0, &index); - - if (phalcon_isset_property_zval(this_ptr, index TSRMLS_CC)) { - RETURN_TRUE; - } - RETURN_FALSE; -} +static zval *phql_ret_join_item(zval *type, zval *qualified, zval *alias, zval *conditions) +{ -static PHP_METHOD(Phalcon_Mvc_Model_Row, offsetGet){ + zval *ret; - zval *index, *value; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_zval(ret, "type", type); - PHALCON_MM_GROW(); + if (qualified) { + add_assoc_zval(ret, "qualified", qualified); + } - phalcon_fetch_params(1, 1, 0, &index); - - if (phalcon_isset_property_zval(this_ptr, index TSRMLS_CC)) { - PHALCON_OBS_VAR(value); - phalcon_read_property_zval(&value, this_ptr, index, PH_NOISY_CC); - RETURN_CCTOR(value); + if (alias) { + add_assoc_zval(ret, "alias", alias); } - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The index does not exist in the row"); - return; -} -static PHP_METHOD(Phalcon_Mvc_Model_Row, offsetSet){ + if (conditions) { + add_assoc_zval(ret, "conditions", conditions); + } - zval *index, *value; + return ret; - phalcon_fetch_params(0, 2, 0, &index, &value); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Row is an immutable ArrayAccess object"); - return; } -static PHP_METHOD(Phalcon_Mvc_Model_Row, offsetUnset){ +static zval *phql_ret_expr(int type, zval *left, zval *right) +{ + zval *ret; - zval *offset; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", type); + if (left) { + add_assoc_zval(ret, "left", left); + } + if (right) { + add_assoc_zval(ret, "right", right); + } - phalcon_fetch_params(0, 1, 0, &offset); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Row is an immutable ArrayAccess object"); - return; + return ret; } +static zval *phql_ret_func_call(phql_parser_token *name, zval *arguments) +{ + zval *ret; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHQL_T_FCALL); + add_assoc_stringl(ret, "name", name->token, name->token_len, 0); + efree(name); + if (arguments) { + add_assoc_zval(ret, "arguments", arguments); + } -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_ResultInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, ResultInterface, mvc_model_resultinterface, phalcon_mvc_model_resultinterface_method_entry); - - return SUCCESS; + return ret; } - - - - -#ifdef HAVE_CONFIG_H +// 416 "parser.c" +/* Next is all token values, in a form suitable for use by makeheaders. +** This section will be null unless lemon is run with the -m switch. +*/ +/* Make sure the INTERFACE macro is defined. +*/ +#ifndef INTERFACE +# define INTERFACE 1 #endif +/* The next thing included is series of defines which control +** various aspects of the generated parser. +** YYCODETYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 terminals +** and nonterminals. "int" is used otherwise. +** YYNOCODE is a number of type YYCODETYPE which corresponds +** to no legal terminal or nonterminal number. This +** number is used to fill in empty slots of the hash +** table. +** YYFALLBACK If defined, this indicates that one or more tokens +** have fall-back values which should be used if the +** original value of the token will not parse. +** YYACTIONTYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 rules and +** states combined. "int" is used otherwise. +** phql_TOKENTYPE is the data type used for minor tokens given +** directly to the parser from the tokenizer. +** YYMINORTYPE is the data type used for all minor tokens. +** This is typically a union of many types, one of +** which is phql_TOKENTYPE. The entry in the union +** for base tokens is called "yy0". +** YYSTACKDEPTH is the maximum depth of the parser's stack. +** phql_ARG_SDECL A static variable declaration for the %extra_argument +** phql_ARG_PDECL A parameter declaration for the %extra_argument +** phql_ARG_STORE Code to store %extra_argument into yypParser +** phql_ARG_FETCH Code to extract %extra_argument from yypParser +** YYNSTATE the combined number of states. +** YYNRULE the number of rules in the grammar +** YYERRORSYMBOL is the code number of the error symbol. If not +** defined, then do no error processing. +*/ +#define YYCODETYPE unsigned char +#define YYNOCODE 114 +#define YYACTIONTYPE unsigned short int +#define phql_TOKENTYPE phql_parser_token* +typedef union { + phql_TOKENTYPE yy0; + zval* yy132; + int yy227; +} YYMINORTYPE; +#define YYSTACKDEPTH 100 +#define phql_ARG_SDECL phql_parser_status *status; +#define phql_ARG_PDECL ,phql_parser_status *status +#define phql_ARG_FETCH phql_parser_status *status = yypParser->status +#define phql_ARG_STORE yypParser->status = status +#define YYNSTATE 263 +#define YYNRULE 154 +#define YYERRORSYMBOL 69 +#define YYERRSYMDT yy227 +#define YY_NO_ACTION (YYNSTATE+YYNRULE+2) +#define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1) +#define YY_ERROR_ACTION (YYNSTATE+YYNRULE) +/* Next are that tables used to determine what action to take based on the +** current state and lookahead token. These tables are used to implement +** functions that take a state number and lookahead value and return an +** action integer. +** +** Suppose the action integer is N. Then the action is determined as +** follows +** +** 0 <= N < YYNSTATE Shift N. That is, push the lookahead +** token onto the stack and goto state N. +** +** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE. +** +** N == YYNSTATE+YYNRULE A syntax error has occurred. +** +** N == YYNSTATE+YYNRULE+1 The parser accepts its input. +** +** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused +** slots in the yy_action[] table. +** +** The action table is constructed as a single large table named yy_action[]. +** Given state S and lookahead X, the action is computed as +** +** yy_action[ yy_shift_ofst[S] + X ] +** +** If the index value yy_shift_ofst[S]+X is out of range or if the value +** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S] +** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table +** and that yy_default[S] should be used instead. +** +** The formula above is for computing the action when the lookahead is +** a terminal symbol. If the lookahead is a non-terminal (as occurs after +** a reduce action) then the yy_reduce_ofst[] array is used in place of +** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of +** YY_SHIFT_USE_DFLT. +** +** The following are the tables generated in this section: +** +** yy_action[] A single table containing all actions. +** yy_lookahead[] A table containing the lookahead for each entry in +** yy_action. Used to detect hash collisions. +** yy_shift_ofst[] For each state, the offset into yy_action for +** shifting terminals. +** yy_reduce_ofst[] For each state, the offset into yy_action for +** shifting non-terminals after a reduce. +** yy_default[] Default action for each state. +*/ +static YYACTIONTYPE yy_action[] = { + /* 0 */ 72, 78, 50, 52, 54, 56, 58, 60, 40, 42, + /* 10 */ 62, 67, 44, 46, 48, 36, 34, 38, 32, 29, + /* 20 */ 74, 69, 69, 64, 64, 72, 78, 50, 52, 54, + /* 30 */ 56, 58, 60, 40, 42, 62, 67, 44, 46, 48, + /* 40 */ 36, 34, 38, 32, 29, 74, 69, 263, 64, 18, + /* 50 */ 27, 28, 20, 215, 203, 213, 201, 72, 78, 50, + /* 60 */ 52, 54, 56, 58, 60, 40, 42, 62, 67, 44, + /* 70 */ 46, 48, 36, 34, 38, 32, 29, 74, 69, 264, + /* 80 */ 64, 32, 29, 74, 69, 155, 64, 83, 157, 72, + /* 90 */ 78, 50, 52, 54, 56, 58, 60, 40, 42, 62, + /* 100 */ 67, 44, 46, 48, 36, 34, 38, 32, 29, 74, + /* 110 */ 69, 265, 64, 240, 72, 78, 50, 52, 54, 56, + /* 120 */ 58, 60, 40, 42, 62, 67, 44, 46, 48, 36, + /* 130 */ 34, 38, 32, 29, 74, 69, 244, 64, 44, 46, + /* 140 */ 48, 36, 34, 38, 32, 29, 74, 69, 89, 64, + /* 150 */ 36, 34, 38, 32, 29, 74, 69, 108, 64, 72, + /* 160 */ 78, 50, 52, 54, 56, 58, 60, 40, 42, 62, + /* 170 */ 67, 44, 46, 48, 36, 34, 38, 32, 29, 74, + /* 180 */ 69, 266, 64, 50, 52, 54, 56, 58, 60, 40, + /* 190 */ 42, 62, 67, 44, 46, 48, 36, 34, 38, 32, + /* 200 */ 29, 74, 69, 99, 64, 136, 30, 17, 138, 100, + /* 210 */ 102, 104, 198, 65, 128, 93, 181, 182, 184, 186, + /* 220 */ 99, 190, 194, 30, 130, 267, 100, 102, 104, 106, + /* 230 */ 118, 257, 93, 181, 182, 184, 186, 9, 190, 194, + /* 240 */ 8, 16, 110, 141, 80, 86, 106, 113, 111, 112, + /* 250 */ 114, 115, 116, 117, 259, 26, 7, 149, 151, 110, + /* 260 */ 159, 80, 86, 277, 113, 111, 112, 114, 115, 116, + /* 270 */ 117, 208, 109, 162, 30, 23, 135, 100, 102, 104, + /* 280 */ 92, 71, 152, 209, 154, 158, 30, 217, 97, 100, + /* 290 */ 102, 104, 245, 270, 260, 93, 166, 106, 109, 170, + /* 300 */ 204, 168, 169, 361, 96, 126, 92, 119, 11, 106, + /* 310 */ 110, 179, 80, 86, 13, 113, 111, 112, 114, 115, + /* 320 */ 116, 117, 110, 15, 80, 86, 268, 113, 111, 112, + /* 330 */ 114, 115, 116, 117, 40, 42, 62, 67, 44, 46, + /* 340 */ 48, 36, 34, 38, 32, 29, 74, 69, 10, 64, + /* 350 */ 62, 67, 44, 46, 48, 36, 34, 38, 32, 29, + /* 360 */ 74, 69, 76, 64, 362, 71, 418, 1, 2, 3, + /* 370 */ 4, 5, 6, 19, 160, 21, 167, 168, 169, 142, + /* 380 */ 269, 10, 109, 285, 199, 71, 207, 212, 200, 95, + /* 390 */ 92, 119, 271, 164, 206, 239, 147, 226, 22, 75, + /* 400 */ 179, 256, 109, 163, 109, 222, 216, 212, 227, 132, + /* 410 */ 92, 119, 92, 109, 109, 286, 272, 226, 144, 148, + /* 420 */ 226, 92, 92, 26, 109, 233, 71, 229, 227, 21, + /* 430 */ 238, 225, 92, 142, 109, 10, 147, 109, 254, 360, + /* 440 */ 109, 21, 92, 109, 25, 92, 139, 10, 92, 124, + /* 450 */ 97, 92, 98, 109, 165, 109, 253, 279, 205, 146, + /* 460 */ 24, 92, 200, 92, 21, 21, 127, 12, 134, 139, + /* 470 */ 10, 10, 31, 33, 179, 74, 69, 35, 64, 124, + /* 480 */ 171, 175, 37, 39, 41, 109, 70, 120, 43, 109, + /* 490 */ 109, 275, 94, 92, 109, 45, 14, 92, 92, 109, + /* 500 */ 109, 109, 92, 64, 47, 109, 49, 92, 92, 92, + /* 510 */ 51, 53, 109, 92, 246, 55, 57, 120, 200, 77, + /* 520 */ 92, 109, 59, 109, 81, 211, 61, 109, 109, 92, + /* 530 */ 179, 92, 109, 109, 84, 92, 92, 125, 63, 109, + /* 540 */ 92, 92, 66, 109, 97, 68, 10, 92, 73, 79, + /* 550 */ 87, 92, 82, 288, 88, 109, 220, 228, 101, 109, + /* 560 */ 133, 103, 109, 92, 105, 109, 109, 92, 330, 109, + /* 570 */ 92, 109, 210, 92, 92, 109, 107, 92, 109, 92, + /* 580 */ 129, 109, 140, 92, 339, 94, 92, 161, 178, 92, + /* 590 */ 176, 273, 174, 109, 248, 255, 251, 109, 173, 109, + /* 600 */ 280, 92, 21, 281, 109, 92, 282, 92, 10, 109, + /* 610 */ 120, 262, 92, 224, 187, 200, 160, 92, 188, 219, + /* 620 */ 191, 195, 235, 242, 192, 196, 224, 179, 331, 223, + /* 630 */ 340, 179, 160, 250, 251, 122, 85, 90, 230, 242, + /* 640 */ 91, 121, 234, 123, 125, 131, 10, 137, 274, 278, + /* 650 */ 276, 143, 145, 150, 283, 10, 153, 284, 10, 156, + /* 660 */ 290, 10, 289, 287, 291, 180, 173, 172, 177, 312, + /* 670 */ 183, 313, 314, 185, 315, 316, 189, 221, 218, 193, + /* 680 */ 317, 318, 319, 242, 322, 242, 323, 197, 320, 333, + /* 690 */ 202, 236, 363, 332, 214, 237, 342, 241, 231, 249, + /* 700 */ 341, 232, 252, 261, 258, 269, 269, 269, 269, 269, + /* 710 */ 269, 269, 269, 269, 247, 269, 269, 269, 269, 269, + /* 720 */ 269, 269, 269, 243, +}; +static YYCODETYPE yy_lookahead[] = { + /* 0 */ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + /* 10 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + /* 20 */ 21, 22, 22, 24, 24, 1, 2, 3, 4, 5, + /* 30 */ 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + /* 40 */ 16, 17, 18, 19, 20, 21, 22, 0, 24, 78, + /* 50 */ 51, 52, 81, 29, 29, 31, 31, 1, 2, 3, + /* 60 */ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + /* 70 */ 14, 15, 16, 17, 18, 19, 20, 21, 22, 0, + /* 80 */ 24, 19, 20, 21, 22, 78, 24, 31, 81, 1, + /* 90 */ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + /* 100 */ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + /* 110 */ 22, 0, 24, 77, 1, 2, 3, 4, 5, 6, + /* 120 */ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + /* 130 */ 17, 18, 19, 20, 21, 22, 100, 24, 13, 14, + /* 140 */ 15, 16, 17, 18, 19, 20, 21, 22, 60, 24, + /* 150 */ 16, 17, 18, 19, 20, 21, 22, 44, 24, 1, + /* 160 */ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, + /* 170 */ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + /* 180 */ 22, 0, 24, 3, 4, 5, 6, 7, 8, 9, + /* 190 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + /* 200 */ 20, 21, 22, 17, 24, 78, 20, 80, 81, 23, + /* 210 */ 24, 25, 28, 11, 12, 29, 32, 33, 34, 35, + /* 220 */ 17, 37, 38, 20, 22, 0, 23, 24, 25, 43, + /* 230 */ 44, 77, 29, 32, 33, 34, 35, 81, 37, 38, + /* 240 */ 78, 79, 56, 81, 58, 59, 43, 61, 62, 63, + /* 250 */ 64, 65, 66, 67, 100, 86, 77, 78, 79, 56, + /* 260 */ 81, 58, 59, 0, 61, 62, 63, 64, 65, 66, + /* 270 */ 67, 17, 103, 26, 20, 106, 107, 23, 24, 25, + /* 280 */ 111, 86, 78, 29, 80, 81, 20, 40, 28, 23, + /* 290 */ 24, 25, 45, 0, 47, 29, 84, 43, 103, 91, + /* 300 */ 88, 89, 90, 0, 44, 110, 111, 112, 56, 43, + /* 310 */ 56, 103, 58, 59, 56, 61, 62, 63, 64, 65, + /* 320 */ 66, 67, 56, 56, 58, 59, 0, 61, 62, 63, + /* 330 */ 64, 65, 66, 67, 9, 10, 11, 12, 13, 14, + /* 340 */ 15, 16, 17, 18, 19, 20, 21, 22, 55, 24, + /* 350 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + /* 360 */ 21, 22, 24, 24, 0, 86, 70, 71, 72, 73, + /* 370 */ 74, 75, 76, 81, 48, 49, 88, 89, 90, 53, + /* 380 */ 0, 55, 103, 0, 87, 86, 85, 86, 91, 110, + /* 390 */ 111, 112, 0, 27, 28, 99, 86, 86, 50, 61, + /* 400 */ 103, 105, 103, 82, 103, 94, 85, 86, 97, 110, + /* 410 */ 111, 112, 111, 103, 103, 0, 0, 86, 108, 109, + /* 420 */ 86, 111, 111, 86, 103, 94, 86, 95, 97, 49, + /* 430 */ 98, 97, 111, 53, 103, 55, 86, 103, 86, 0, + /* 440 */ 103, 49, 111, 103, 107, 111, 54, 55, 111, 30, + /* 450 */ 28, 111, 112, 103, 83, 103, 104, 0, 87, 109, + /* 460 */ 28, 111, 91, 111, 49, 49, 44, 28, 86, 54, + /* 470 */ 55, 55, 86, 86, 103, 21, 22, 86, 24, 30, + /* 480 */ 92, 93, 86, 86, 86, 103, 43, 68, 86, 103, + /* 490 */ 103, 0, 43, 111, 103, 86, 57, 111, 111, 103, + /* 500 */ 103, 103, 111, 24, 86, 103, 86, 111, 111, 111, + /* 510 */ 86, 86, 103, 111, 87, 86, 86, 68, 91, 61, + /* 520 */ 111, 103, 86, 103, 43, 17, 86, 103, 103, 111, + /* 530 */ 103, 111, 103, 103, 29, 111, 111, 29, 86, 103, + /* 540 */ 111, 111, 86, 103, 28, 86, 55, 111, 86, 86, + /* 550 */ 43, 111, 86, 0, 86, 103, 42, 43, 86, 103, + /* 560 */ 44, 86, 103, 111, 86, 103, 103, 111, 0, 103, + /* 570 */ 111, 103, 30, 111, 111, 103, 86, 111, 103, 111, + /* 580 */ 86, 103, 86, 111, 0, 43, 111, 86, 29, 111, + /* 590 */ 31, 0, 86, 103, 101, 102, 103, 103, 39, 103, + /* 600 */ 0, 111, 49, 0, 103, 111, 0, 111, 55, 103, + /* 610 */ 68, 87, 111, 28, 32, 91, 48, 111, 36, 91, + /* 620 */ 32, 32, 28, 55, 36, 36, 28, 103, 0, 44, + /* 630 */ 0, 103, 48, 102, 103, 30, 44, 29, 44, 55, + /* 640 */ 44, 29, 44, 29, 29, 43, 55, 81, 0, 0, + /* 650 */ 0, 50, 28, 81, 0, 55, 81, 0, 55, 81, + /* 660 */ 0, 55, 0, 0, 0, 29, 39, 93, 29, 29, + /* 670 */ 32, 29, 29, 32, 29, 29, 32, 43, 41, 32, + /* 680 */ 29, 29, 29, 55, 0, 55, 0, 32, 29, 0, + /* 690 */ 29, 98, 0, 0, 29, 29, 0, 100, 42, 28, + /* 700 */ 0, 43, 3, 27, 100, 113, 113, 113, 113, 113, + /* 710 */ 113, 113, 113, 113, 46, 113, 113, 113, 113, 113, + /* 720 */ 113, 113, 113, 56, +}; +#define YY_SHIFT_USE_DFLT (-2) +static short yy_shift_ofst[] = { + /* 0 */ 247, 47, 79, 111, 181, 225, 326, 380, 293, 263, + /* 10 */ 252, 439, 258, 303, 267, 364, 392, 416, 491, 383, + /* 20 */ 457, 348, 266, 432, 266, -2, -1, -2, -2, 266, + /* 30 */ 266, 454, 266, 454, 266, 62, 266, 62, 266, 62, + /* 40 */ 266, 339, 266, 339, 266, 134, 266, 134, 266, 134, + /* 50 */ 266, 325, 266, 325, 266, 325, 266, 325, 266, 325, + /* 60 */ 266, 325, 266, 125, 202, 266, 479, 266, 125, 443, + /* 70 */ 203, 158, 266, 158, 338, -2, 458, -2, 266, 180, + /* 80 */ 481, 266, 56, 505, 592, -2, 507, 266, 88, 608, + /* 90 */ 596, -2, -2, 449, 186, 260, -2, 203, -2, -2, + /* 100 */ 266, 0, 266, 479, 266, 479, 266, 113, -2, -2, + /* 110 */ -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + /* 120 */ 612, 605, 614, -2, 615, -2, 422, -2, 266, 479, + /* 130 */ 602, 203, 516, -2, 454, -2, 591, 648, 649, 266, + /* 140 */ 158, 650, 601, 266, 624, 266, -2, 158, -2, 600, + /* 150 */ 654, 415, 603, 657, 553, 606, 660, 662, 663, 664, + /* 160 */ 266, 158, 254, 366, 636, 184, 201, -2, -2, 636, + /* 170 */ 559, 627, -2, 266, 158, -2, 639, -2, -2, -2, + /* 180 */ 419, 640, 638, 642, 641, 643, 582, 645, 644, 646, + /* 190 */ 588, 651, 647, 652, 589, 653, 655, 659, 636, -2, + /* 200 */ 25, 661, -2, -2, -2, -2, 254, -2, -2, 542, + /* 210 */ 508, -2, 24, 665, -2, -2, -2, 637, 636, 514, + /* 220 */ 634, 266, 585, 684, 266, -2, 158, -2, 666, 594, + /* 230 */ 656, 658, 266, 598, 686, 666, -2, -2, -2, 568, + /* 240 */ 628, 689, 667, 692, 693, 636, 668, 636, 671, 636, + /* 250 */ -2, 699, 266, -2, 158, -2, 584, 630, 696, 700, + /* 260 */ 676, 636, -2, +}; +#define YY_REDUCE_USE_DFLT (-30) +static short yy_reduce_ofst[] = { + /* 0 */ 296, -30, -30, -30, -30, -30, 179, 162, 156, -30, + /* 10 */ -30, -30, -30, -30, -30, -30, 127, -29, 292, -30, + /* 20 */ -30, -30, 169, -30, 337, -30, -30, -30, -30, 382, + /* 30 */ 386, -30, 387, -30, 391, -30, 396, -30, 397, -30, + /* 40 */ 398, -30, 402, -30, 409, -30, 418, -30, 420, -30, + /* 50 */ 424, -30, 425, -30, 429, -30, 430, -30, 436, -30, + /* 60 */ 440, -30, 452, -30, -30, 456, -30, 459, -30, -30, + /* 70 */ 195, -30, 462, -30, -30, -30, -30, -30, 463, -30, + /* 80 */ -30, 466, -30, -30, -30, -30, -30, 468, -30, -30, + /* 90 */ -30, -30, -30, -30, 279, -30, -30, 340, -30, -30, + /* 100 */ 472, -30, 475, -30, 478, -30, 490, -30, -30, -30, + /* 110 */ -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, + /* 120 */ -30, -30, -30, -30, -30, -30, -30, -30, 494, -30, + /* 130 */ -30, 299, -30, -30, -30, -30, 566, -30, -30, 496, + /* 140 */ -30, -30, -30, 310, -30, 350, -30, -30, -30, 572, + /* 150 */ -30, 204, 575, -30, 7, 578, -30, -30, -30, -30, + /* 160 */ 501, -30, 321, -30, 371, 212, 288, -30, -30, 208, + /* 170 */ 388, 574, -30, 506, -30, -30, -30, -30, -30, -30, + /* 180 */ -30, -30, -30, -30, -30, -30, -30, -30, -30, -30, + /* 190 */ -30, -30, -30, -30, -30, -30, -30, -30, 297, -30, + /* 200 */ -30, -30, -30, -30, -30, -30, 301, -30, -30, -30, + /* 210 */ -30, -30, -30, -30, -30, -30, -30, -30, 528, -30, + /* 220 */ -30, 311, -30, -30, 334, -30, -30, -30, 332, -30, + /* 230 */ -30, -30, 331, -30, -30, 593, -30, -30, -30, 36, + /* 240 */ 597, -30, -30, -30, -30, 427, -30, 493, -30, 531, + /* 250 */ -30, -30, 352, -30, -30, -30, 154, 604, -30, -30, + /* 260 */ -30, 524, -30, +}; +static YYACTIONTYPE yy_default[] = { + /* 0 */ 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, + /* 10 */ 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, + /* 20 */ 417, 417, 417, 349, 417, 350, 352, 353, 354, 417, + /* 30 */ 417, 364, 417, 366, 417, 367, 417, 368, 417, 369, + /* 40 */ 417, 370, 417, 371, 417, 372, 417, 373, 417, 374, + /* 50 */ 417, 375, 417, 376, 417, 377, 417, 378, 417, 379, + /* 60 */ 417, 380, 417, 381, 417, 417, 382, 417, 383, 417, + /* 70 */ 417, 396, 417, 387, 417, 397, 417, 398, 417, 400, + /* 80 */ 417, 417, 417, 417, 417, 388, 417, 417, 417, 417, + /* 90 */ 417, 389, 390, 416, 417, 417, 391, 417, 393, 395, + /* 100 */ 417, 399, 417, 401, 417, 402, 417, 417, 403, 404, + /* 110 */ 405, 406, 407, 408, 409, 410, 411, 412, 392, 394, + /* 120 */ 417, 414, 417, 413, 417, 415, 417, 385, 417, 384, + /* 130 */ 417, 417, 417, 386, 365, 351, 417, 417, 417, 417, + /* 140 */ 359, 417, 417, 417, 355, 417, 356, 358, 357, 417, + /* 150 */ 417, 417, 417, 417, 417, 417, 417, 417, 417, 417, + /* 160 */ 417, 348, 417, 417, 417, 292, 293, 303, 305, 417, + /* 170 */ 306, 307, 309, 417, 321, 308, 417, 310, 311, 347, + /* 180 */ 416, 417, 417, 417, 417, 417, 417, 417, 417, 417, + /* 190 */ 417, 417, 417, 417, 417, 417, 417, 417, 417, 301, + /* 200 */ 346, 417, 344, 345, 304, 302, 417, 294, 296, 416, + /* 210 */ 417, 297, 300, 417, 298, 299, 295, 417, 417, 417, + /* 220 */ 417, 417, 417, 417, 417, 324, 326, 325, 417, 417, + /* 230 */ 417, 417, 417, 417, 417, 417, 327, 329, 328, 417, + /* 240 */ 417, 417, 417, 417, 417, 417, 417, 417, 334, 417, + /* 250 */ 335, 417, 417, 337, 338, 336, 417, 417, 417, 417, + /* 260 */ 417, 417, 343, +}; +#define YY_SZ_ACTTAB (sizeof(yy_action)/sizeof(yy_action[0])) +/* The next table maps tokens into fallback tokens. If a construct +** like the following: +** +** %fallback ID X Y Z. +** +** appears in the grammer, then ID becomes a fallback token for X, Y, +** and Z. Whenever one of the tokens X, Y, or Z is input to the parser +** but it does not parse, the type of the token is changed to ID and +** the parse is retried before an error is thrown. +*/ +#ifdef YYFALLBACK +static const YYCODETYPE yyFallback[] = { +}; +#endif /* YYFALLBACK */ +/* The following structure represents a single element of the +** parser's stack. Information stored includes: +** +** + The state number for the parser at this level of the stack. +** +** + The value of the token stored at this level of the stack. +** (In other words, the "major" token.) +** +** + The semantic value stored at this level of the stack. This is +** the information used by the action routines in the grammar. +** It is sometimes called the "minor" token. +*/ +struct yyStackEntry { + int stateno; /* The state-number */ + int major; /* The major token value. This is the code + ** number for the token at this stack level */ + YYMINORTYPE minor; /* The user-supplied minor token value. This + ** is the value of the token */ +}; +typedef struct yyStackEntry yyStackEntry; +/* The state of the parser is completely contained in an instance of +** the following structure */ +struct yyParser { + int yyidx; /* Index of top element in stack */ + int yyerrcnt; /* Shifts left before out of the error */ + phql_ARG_SDECL /* A place to hold %extra_argument */ + yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */ +}; +typedef struct yyParser yyParser; +#ifndef NDEBUG +#include +static FILE *yyTraceFILE = 0; +static char *yyTracePrompt = 0; +#endif /* NDEBUG */ - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Uniqueness){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Uniqueness, mvc_model_validator_uniqueness, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_uniqueness_method_entry, 0); - - zend_class_implements(phalcon_mvc_model_validator_uniqueness_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Validator_Uniqueness, validate){ - - zval *record, *option = NULL, *field, *dependency_injector; - zval *service, *meta_data, *bind_types, *bind_data_types; - zval *column_map = NULL, *conditions, *bind_params; - zval *number = NULL, *compose_field = NULL, *column_field = NULL; - zval *exception_message = NULL, *value = NULL, *compose_condition = NULL; - zval *bind_type = NULL, *condition = NULL, *operation_made; - zval *primary_fields, *primary_field = NULL, *attribute_field = NULL; - zval *join_conditions, *params, *class_name; - zval *message = NULL, *join_fields, *type; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &record); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "field", 1); - - PHALCON_INIT_VAR(field); - phalcon_call_method_p1_key(field, this_ptr, "getoption", option, 1191969182UL); - - PHALCON_INIT_VAR(dependency_injector); - phalcon_call_method_key(dependency_injector, record, "getdi", 4287060818UL); - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "modelsMetadata", 1); - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_p1_key(meta_data, dependency_injector, "getshared", service, 1727570332UL); - - PHALCON_INIT_VAR(bind_types); - array_init(bind_types); - - PHALCON_INIT_VAR(bind_data_types); - phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", record, 448815543UL); - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getreversecolumnmap", record, 817005101UL); - } else { - PHALCON_INIT_NVAR(column_map); - } - - PHALCON_INIT_VAR(conditions); - array_init(conditions); - - PHALCON_INIT_VAR(bind_params); - array_init(bind_params); - - PHALCON_INIT_VAR(number); - ZVAL_LONG(number, 0); - if (Z_TYPE_P(field) == IS_ARRAY) { - - phalcon_is_iterable(field, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(compose_field); - - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, compose_field)) { - PHALCON_OBS_NVAR(column_field); - phalcon_array_fetch(&column_field, column_map, compose_field, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", compose_field, "\" isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(column_field, compose_field); - } - - if (!phalcon_array_isset(bind_data_types, column_field)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", column_field, "\" isn't part of the table columns"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_INIT_NVAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", compose_field, 95450773UL); - - PHALCON_INIT_NVAR(compose_condition); - PHALCON_CONCAT_SVSV(compose_condition, "[", compose_field, "] = ?", number); - phalcon_array_append(&conditions, compose_condition, PH_SEPARATE); - phalcon_array_append(&bind_params, value, PH_SEPARATE); - - PHALCON_OBS_NVAR(bind_type); - phalcon_array_fetch(&bind_type, bind_data_types, column_field, PH_NOISY); - phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); - PHALCON_SEPARATE(number); - phalcon_increment(number); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } else { - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, field)) { - PHALCON_OBS_NVAR(column_field); - phalcon_array_fetch(&column_field, column_map, field, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", field, "\" isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(column_field, field); - } - - if (!phalcon_array_isset(bind_data_types, column_field)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", column_field, "\" isn't part of the table columns"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_INIT_NVAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); - - PHALCON_INIT_VAR(condition); - PHALCON_CONCAT_SVS(condition, "[", field, "] = ?0"); - phalcon_array_append(&conditions, condition, PH_SEPARATE); - phalcon_array_append(&bind_params, value, PH_SEPARATE); - - PHALCON_OBS_NVAR(bind_type); - phalcon_array_fetch(&bind_type, bind_data_types, column_field, PH_NOISY); - phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); - PHALCON_SEPARATE(number); - phalcon_increment(number); - } - - PHALCON_INIT_VAR(operation_made); - phalcon_call_method_key(operation_made, record, "getoperationmade", 408703981UL); - if (PHALCON_IS_LONG(operation_made, 2)) { - - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_NVAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", record, 213063537UL); - } else { - PHALCON_INIT_NVAR(column_map); - } - - PHALCON_INIT_VAR(primary_fields); - phalcon_call_method_p1_key(primary_fields, meta_data, "getprimarykeyattributes", record, 692945721UL); - - phalcon_is_iterable(primary_fields, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(primary_field); - - if (!phalcon_array_isset(bind_data_types, primary_field)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", primary_field, "\" isn't part of the table columns"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, primary_field)) { - PHALCON_OBS_NVAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, primary_field, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", primary_field, "\" isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(attribute_field, primary_field); - } - - PHALCON_INIT_NVAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", primary_field, 95450773UL); - - PHALCON_INIT_NVAR(condition); - PHALCON_CONCAT_SVSV(condition, "[", attribute_field, "] <> ?", number); - phalcon_array_append(&conditions, condition, PH_SEPARATE); - phalcon_array_append(&bind_params, value, PH_SEPARATE); - - PHALCON_OBS_NVAR(bind_type); - phalcon_array_fetch(&bind_type, bind_data_types, primary_field, PH_NOISY); - phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); - PHALCON_SEPARATE(number); - phalcon_increment(number); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - } - - PHALCON_INIT_VAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - - PHALCON_INIT_VAR(params); - array_init(params); - phalcon_array_update_quick_string(¶ms, SS("di"), 193489362UL, &dependency_injector, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(¶ms, SS("conditions"), 1055696255UL, &join_conditions, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(¶ms, SS("bind"), 254268962UL, &bind_params, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(¶ms, SS("bindTypes"), 3951758359UL, &bind_types, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, record, 0 TSRMLS_CC); - - phalcon_call_zval_str_static_p1(number, class_name, "count", params); - if (!PHALCON_IS_LONG(number, 0)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message); - phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message)) { - if (Z_TYPE_P(field) == IS_ARRAY) { - PHALCON_INIT_VAR(join_fields); - phalcon_fast_join_str(join_fields, SL(", "), field TSRMLS_CC); - - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_SVS(message, "Value of fields: '", join_fields, "' are already present in another record"); - } else { - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_SVS(message, "Value of field: '", field, "' is already present in another record"); - } - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Unique", 1); - phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field, type, 2313005058UL); - RETURN_MM_FALSE; - } - - RETURN_MM_TRUE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_PresenceOf){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, PresenceOf, mvc_model_validator_presenceof, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_presenceof_method_entry, 0); - - zend_class_implements(phalcon_mvc_model_validator_presenceof_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - - return SUCCESS; +#ifndef NDEBUG +static void phql_Trace(FILE *TraceFILE, char *zTracePrompt){ + yyTraceFILE = TraceFILE; + yyTracePrompt = zTracePrompt; + if( yyTraceFILE==0 ) yyTracePrompt = 0; + else if( yyTracePrompt==0 ) yyTraceFILE = 0; } +#endif /* NDEBUG */ -static PHP_METHOD(Phalcon_Mvc_Model_Validator_PresenceOf, validate){ - - zval *record, *option = NULL, *field_name, *value, *message = NULL; - zval *type; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &record); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "field", 1); - - PHALCON_INIT_VAR(field_name); - phalcon_call_method_p1_key(field_name, this_ptr, "getoption", option, 1191969182UL); - if (Z_TYPE_P(field_name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); - return; - } - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); - if (PHALCON_IS_EMPTY(value)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message); - phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message)) { - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_SVS(message, "'", field_name, "' is required"); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "PresenceOf", 1); - phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field_name, type, 2313005058UL); - RETURN_MM_FALSE; - } - - RETURN_MM_TRUE; -} - - - +#ifndef NDEBUG +/* For tracing shifts, the names of all terminals and nonterminals +** are required. The following table supplies these names */ +static const char *yyTokenName[] = { + "$", "AGAINST", "BETWEEN", "EQUALS", + "NOTEQUALS", "LESS", "GREATER", "GREATEREQUAL", + "LESSEQUAL", "AND", "OR", "LIKE", + "ILIKE", "BITWISE_AND", "BITWISE_OR", "BITWISE_XOR", + "DIVIDE", "TIMES", "MOD", "PLUS", + "MINUS", "IS", "IN", "DISTINCT", + "NOT", "BITWISE_NOT", "SELECT", "FROM", + "COMMA", "IDENTIFIER", "DOT", "AS", + "JOIN", "INNER", "CROSS", "LEFT", + "OUTER", "RIGHT", "FULL", "ON", + "INSERT", "INTO", "VALUES", "PARENTHESES_OPEN", + "PARENTHESES_CLOSE", "UPDATE", "SET", "DELETE", + "WHERE", "ORDER", "BY", "ASC", + "DESC", "GROUP", "HAVING", "LIMIT", + "INTEGER", "OFFSET", "CAST", "CONVERT", + "USING", "NULL", "STRING", "DOUBLE", + "TRUE", "FALSE", "NPLACEHOLDER", "SPLACEHOLDER", + "COLON", "error", "program", "query_language", + "select_statement", "insert_statement", "update_statement", "delete_statement", + "select_clause", "where_clause", "order_clause", "group_clause", + "having_clause", "select_limit_clause", "column_list", "associated_name_list", + "join_list", "column_item", "expr", "associated_name", + "join_item", "join_clause", "join_type", "aliased_or_qualified_name", + "join_associated_name", "join_conditions", "values_list", "field_list", + "value_list", "value_item", "field_item", "update_clause", + "limit_clause", "update_item_list", "update_item", "qualified_name", + "new_value", "delete_clause", "order_list", "order_item", + "group_list", "group_item", "argument_list", "function_call", + "argument_item", +}; +#endif /* NDEBUG */ +#ifndef NDEBUG +/* For tracing reduce actions, the names of all rules are required. +*/ +static const char *yyRuleName[] = { + /* 0 */ "program ::= query_language", + /* 1 */ "query_language ::= select_statement", + /* 2 */ "query_language ::= insert_statement", + /* 3 */ "query_language ::= update_statement", + /* 4 */ "query_language ::= delete_statement", + /* 5 */ "select_statement ::= select_clause", + /* 6 */ "select_statement ::= select_clause where_clause", + /* 7 */ "select_statement ::= select_clause where_clause order_clause", + /* 8 */ "select_statement ::= select_clause where_clause group_clause", + /* 9 */ "select_statement ::= select_clause where_clause group_clause having_clause", + /* 10 */ "select_statement ::= select_clause where_clause group_clause order_clause", + /* 11 */ "select_statement ::= select_clause where_clause group_clause order_clause select_limit_clause", + /* 12 */ "select_statement ::= select_clause where_clause group_clause having_clause order_clause", + /* 13 */ "select_statement ::= select_clause where_clause select_limit_clause", + /* 14 */ "select_statement ::= select_clause where_clause order_clause select_limit_clause", + /* 15 */ "select_statement ::= select_clause where_clause group_clause select_limit_clause", + /* 16 */ "select_statement ::= select_clause where_clause group_clause having_clause select_limit_clause", + /* 17 */ "select_statement ::= select_clause order_clause", + /* 18 */ "select_statement ::= select_clause group_clause order_clause", + /* 19 */ "select_statement ::= select_clause group_clause having_clause order_clause", + /* 20 */ "select_statement ::= select_clause order_clause select_limit_clause", + /* 21 */ "select_statement ::= select_clause group_clause order_clause select_limit_clause", + /* 22 */ "select_statement ::= select_clause where_clause group_clause having_clause order_clause select_limit_clause", + /* 23 */ "select_statement ::= select_clause group_clause", + /* 24 */ "select_statement ::= select_clause group_clause select_limit_clause", + /* 25 */ "select_statement ::= select_clause group_clause having_clause", + /* 26 */ "select_statement ::= select_clause group_clause having_clause select_limit_clause", + /* 27 */ "select_statement ::= select_clause group_clause having_clause order_clause select_limit_clause", + /* 28 */ "select_statement ::= select_clause select_limit_clause", + /* 29 */ "select_clause ::= SELECT column_list FROM associated_name_list", + /* 30 */ "select_clause ::= SELECT column_list FROM associated_name_list join_list", + /* 31 */ "column_list ::= column_list COMMA column_item", + /* 32 */ "column_list ::= column_item", + /* 33 */ "column_item ::= TIMES", + /* 34 */ "column_item ::= IDENTIFIER DOT TIMES", + /* 35 */ "column_item ::= expr AS IDENTIFIER", + /* 36 */ "column_item ::= expr IDENTIFIER", + /* 37 */ "column_item ::= expr", + /* 38 */ "associated_name_list ::= associated_name_list COMMA associated_name", + /* 39 */ "associated_name_list ::= associated_name", + /* 40 */ "join_list ::= join_list join_item", + /* 41 */ "join_list ::= join_item", + /* 42 */ "join_item ::= join_clause", + /* 43 */ "join_clause ::= join_type aliased_or_qualified_name", + /* 44 */ "join_clause ::= join_type aliased_or_qualified_name join_associated_name", + /* 45 */ "join_clause ::= join_type aliased_or_qualified_name join_conditions", + /* 46 */ "join_clause ::= join_type aliased_or_qualified_name join_associated_name join_conditions", + /* 47 */ "join_associated_name ::= AS IDENTIFIER", + /* 48 */ "join_associated_name ::= IDENTIFIER", + /* 49 */ "join_type ::= JOIN", + /* 50 */ "join_type ::= INNER JOIN", + /* 51 */ "join_type ::= CROSS JOIN", + /* 52 */ "join_type ::= LEFT JOIN", + /* 53 */ "join_type ::= LEFT OUTER JOIN", + /* 54 */ "join_type ::= RIGHT JOIN", + /* 55 */ "join_type ::= RIGHT OUTER JOIN", + /* 56 */ "join_type ::= FULL JOIN", + /* 57 */ "join_type ::= FULL OUTER JOIN", + /* 58 */ "join_conditions ::= ON expr", + /* 59 */ "insert_statement ::= INSERT INTO aliased_or_qualified_name VALUES PARENTHESES_OPEN values_list PARENTHESES_CLOSE", + /* 60 */ "insert_statement ::= INSERT INTO aliased_or_qualified_name PARENTHESES_OPEN field_list PARENTHESES_CLOSE VALUES PARENTHESES_OPEN values_list PARENTHESES_CLOSE", + /* 61 */ "values_list ::= values_list COMMA value_item", + /* 62 */ "values_list ::= value_item", + /* 63 */ "value_item ::= expr", + /* 64 */ "field_list ::= field_list COMMA field_item", + /* 65 */ "field_list ::= field_item", + /* 66 */ "field_item ::= IDENTIFIER", + /* 67 */ "update_statement ::= update_clause", + /* 68 */ "update_statement ::= update_clause where_clause", + /* 69 */ "update_statement ::= update_clause limit_clause", + /* 70 */ "update_statement ::= update_clause where_clause limit_clause", + /* 71 */ "update_clause ::= UPDATE associated_name SET update_item_list", + /* 72 */ "update_item_list ::= update_item_list COMMA update_item", + /* 73 */ "update_item_list ::= update_item", + /* 74 */ "update_item ::= qualified_name EQUALS new_value", + /* 75 */ "new_value ::= expr", + /* 76 */ "delete_statement ::= delete_clause", + /* 77 */ "delete_statement ::= delete_clause where_clause", + /* 78 */ "delete_statement ::= delete_clause limit_clause", + /* 79 */ "delete_statement ::= delete_clause where_clause limit_clause", + /* 80 */ "delete_clause ::= DELETE FROM associated_name", + /* 81 */ "associated_name ::= aliased_or_qualified_name AS IDENTIFIER", + /* 82 */ "associated_name ::= aliased_or_qualified_name IDENTIFIER", + /* 83 */ "associated_name ::= aliased_or_qualified_name", + /* 84 */ "aliased_or_qualified_name ::= qualified_name", + /* 85 */ "where_clause ::= WHERE expr", + /* 86 */ "order_clause ::= ORDER BY order_list", + /* 87 */ "order_list ::= order_list COMMA order_item", + /* 88 */ "order_list ::= order_item", + /* 89 */ "order_item ::= expr", + /* 90 */ "order_item ::= expr ASC", + /* 91 */ "order_item ::= expr DESC", + /* 92 */ "group_clause ::= GROUP BY group_list", + /* 93 */ "group_list ::= group_list COMMA group_item", + /* 94 */ "group_list ::= group_item", + /* 95 */ "group_item ::= expr", + /* 96 */ "having_clause ::= HAVING expr", + /* 97 */ "select_limit_clause ::= LIMIT INTEGER", + /* 98 */ "select_limit_clause ::= LIMIT INTEGER COMMA INTEGER", + /* 99 */ "select_limit_clause ::= LIMIT INTEGER OFFSET INTEGER", + /* 100 */ "limit_clause ::= LIMIT INTEGER", + /* 101 */ "expr ::= MINUS expr", + /* 102 */ "expr ::= expr MINUS expr", + /* 103 */ "expr ::= expr PLUS expr", + /* 104 */ "expr ::= expr TIMES expr", + /* 105 */ "expr ::= expr DIVIDE expr", + /* 106 */ "expr ::= expr MOD expr", + /* 107 */ "expr ::= expr AND expr", + /* 108 */ "expr ::= expr OR expr", + /* 109 */ "expr ::= expr BITWISE_AND expr", + /* 110 */ "expr ::= expr BITWISE_OR expr", + /* 111 */ "expr ::= expr BITWISE_XOR expr", + /* 112 */ "expr ::= expr EQUALS expr", + /* 113 */ "expr ::= expr NOTEQUALS expr", + /* 114 */ "expr ::= expr LESS expr", + /* 115 */ "expr ::= expr GREATER expr", + /* 116 */ "expr ::= expr GREATEREQUAL expr", + /* 117 */ "expr ::= expr LESSEQUAL expr", + /* 118 */ "expr ::= expr LIKE expr", + /* 119 */ "expr ::= expr NOT LIKE expr", + /* 120 */ "expr ::= expr ILIKE expr", + /* 121 */ "expr ::= expr NOT ILIKE expr", + /* 122 */ "expr ::= expr IN PARENTHESES_OPEN argument_list PARENTHESES_CLOSE", + /* 123 */ "expr ::= expr NOT IN PARENTHESES_OPEN argument_list PARENTHESES_CLOSE", + /* 124 */ "expr ::= expr AGAINST expr", + /* 125 */ "expr ::= CAST PARENTHESES_OPEN expr AS IDENTIFIER PARENTHESES_CLOSE", + /* 126 */ "expr ::= CONVERT PARENTHESES_OPEN expr USING IDENTIFIER PARENTHESES_CLOSE", + /* 127 */ "expr ::= function_call", + /* 128 */ "function_call ::= IDENTIFIER PARENTHESES_OPEN argument_list PARENTHESES_CLOSE", + /* 129 */ "function_call ::= IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE", + /* 130 */ "argument_list ::= argument_list COMMA argument_item", + /* 131 */ "argument_list ::= argument_item", + /* 132 */ "argument_item ::= TIMES", + /* 133 */ "argument_item ::= expr", + /* 134 */ "expr ::= expr IS NULL", + /* 135 */ "expr ::= expr IS NOT NULL", + /* 136 */ "expr ::= DISTINCT expr", + /* 137 */ "expr ::= expr BETWEEN expr", + /* 138 */ "expr ::= NOT expr", + /* 139 */ "expr ::= BITWISE_NOT expr", + /* 140 */ "expr ::= PARENTHESES_OPEN expr PARENTHESES_CLOSE", + /* 141 */ "expr ::= qualified_name", + /* 142 */ "expr ::= INTEGER", + /* 143 */ "expr ::= STRING", + /* 144 */ "expr ::= DOUBLE", + /* 145 */ "expr ::= NULL", + /* 146 */ "expr ::= TRUE", + /* 147 */ "expr ::= FALSE", + /* 148 */ "expr ::= NPLACEHOLDER", + /* 149 */ "expr ::= SPLACEHOLDER", + /* 150 */ "qualified_name ::= IDENTIFIER COLON IDENTIFIER DOT IDENTIFIER", + /* 151 */ "qualified_name ::= IDENTIFIER COLON IDENTIFIER", + /* 152 */ "qualified_name ::= IDENTIFIER DOT IDENTIFIER", + /* 153 */ "qualified_name ::= IDENTIFIER", +}; +#endif /* NDEBUG */ -#ifdef HAVE_CONFIG_H +const char *phql_TokenName(int tokenType){ +#ifndef NDEBUG + if( tokenType>0 && tokenType<(sizeof(yyTokenName)/sizeof(yyTokenName[0])) ){ + return yyTokenName[tokenType]; + }else{ + return "Unknown"; + } +#else + return ""; #endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Numericality){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Numericality, mvc_model_validator_numericality, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_numericality_method_entry, 0); - - zend_class_implements(phalcon_mvc_model_validator_numericality_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - - return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Model_Validator_Numericality, validate){ - - zval *record, *option = NULL, *field, *value, *message = NULL, *type; - - PHALCON_MM_GROW(); +void *phql_Alloc(void *(*mallocProc)(size_t)){ + yyParser *pParser; + pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); + if( pParser ){ + pParser->yyidx = -1; + } + return pParser; +} - phalcon_fetch_params(1, 1, 0, &record); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "field", 1); - - PHALCON_INIT_VAR(field); - phalcon_call_method_p1_key(field, this_ptr, "getoption", option, 1191969182UL); - if (Z_TYPE_P(field) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); - return; - } - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); - - if (!phalcon_is_numeric(value)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message); - phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message)) { - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_SVS(message, "Value of field '", field, "' must be numeric"); +/* The following function deletes the value associated with a +** symbol. The symbol can be either a terminal or nonterminal. +** "yymajor" is the symbol code, and "yypminor" is a pointer to +** the value. +*/ +static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){ + switch( yymajor ){ + /* Here is inserted the actions which take place when a + ** terminal or non-terminal is destroyed. This can happen + ** when the symbol is popped from the stack during a + ** reduce or during error processing or when a parser is + ** being destroyed before it is finished parsing. + ** + ** Note: during a reduce, the only symbols destroyed are those + ** which appear on the RHS of the rule, but which are not used + ** inside the C code. + */ + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 26: + case 27: + case 28: + case 29: + case 30: + case 31: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + case 38: + case 39: + case 40: + case 41: + case 42: + case 43: + case 44: + case 45: + case 46: + case 47: + case 48: + case 49: + case 50: + case 51: + case 52: + case 53: + case 54: + case 55: + case 56: + case 57: + case 58: + case 59: + case 60: + case 61: + case 62: + case 63: + case 64: + case 65: + case 66: + case 67: + case 68: +// 513 "parser.lemon" +{ + if ((yypminor->yy0)) { + if ((yypminor->yy0)->free_flag) { + efree((yypminor->yy0)->token); } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Numericality", 1); - phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field, type, 2313005058UL); - RETURN_MM_FALSE; + efree((yypminor->yy0)); } - - RETURN_MM_TRUE; +} +// 1181 "parser.c" + break; + case 71: + case 72: + case 73: + case 74: + case 75: + case 76: + case 77: + case 78: + case 79: + case 80: + case 81: + case 82: + case 83: + case 84: + case 85: + case 86: + case 87: + case 88: + case 89: + case 90: + case 91: + case 92: + case 93: + case 95: + case 96: + case 98: + case 99: + case 100: + case 101: + case 102: + case 103: + case 105: + case 106: + case 107: + case 108: + case 109: + case 110: + case 111: + case 112: +// 526 "parser.lemon" +{ zval_ptr_dtor(&(yypminor->yy132)); } +// 1224 "parser.c" + break; + default: break; /* If no destructor action specified: do nothing */ + } } +static int yy_pop_parser_stack(yyParser *pParser){ + YYCODETYPE yymajor; + yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; - - - -#ifdef HAVE_CONFIG_H + if( pParser->yyidx<0 ) return 0; +#ifndef NDEBUG + if( yyTraceFILE && pParser->yyidx>=0 ){ + fprintf(yyTraceFILE,"%sPopping %s\n", + yyTracePrompt, + yyTokenName[yytos->major]); + } #endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Url){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Url, mvc_model_validator_url, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_url_method_entry, 0); - - zend_class_implements(phalcon_mvc_model_validator_url_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - - return SUCCESS; + yymajor = yytos->major; + yy_destructor( yymajor, &yytos->minor); + pParser->yyidx--; + return yymajor; } -static PHP_METHOD(Phalcon_Mvc_Model_Validator_Url, validate){ - - zval *record, *option = NULL, *field, *value, *flag, *is_valid; - zval *message = NULL, *type; - - PHALCON_MM_GROW(); +static void phql_Free( + void *p, /* The parser to be deleted */ + void (*freeProc)(void*) /* Function used to reclaim memory */ +){ + yyParser *pParser = (yyParser*)p; + if( pParser==0 ) return; + while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser); + (*freeProc)((void*)pParser); +} - phalcon_fetch_params(1, 1, 0, &record); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "field", 1); - - PHALCON_INIT_VAR(field); - phalcon_call_method_p1_key(field, this_ptr, "getoption", option, 1191969182UL); - if (Z_TYPE_P(field) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); - return; - } - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); - - PHALCON_INIT_VAR(flag); - ZVAL_LONG(flag, 273); - - PHALCON_INIT_VAR(is_valid); - phalcon_call_func_p2(is_valid, "filter_var", value, flag); - if (!zend_is_true(is_valid)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message); - phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message)) { - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_SVS(message, "'", field, "' does not have a valid url format"); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Url", 1); - phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field, type, 2313005058UL); - RETURN_MM_FALSE; - } - - RETURN_MM_TRUE; -} - - - - - -#ifdef HAVE_CONFIG_H +static int yy_find_shift_action( + yyParser *pParser, /* The parser */ + int iLookAhead /* The look-ahead token */ +){ + int i; + int stateno = pParser->yystack[pParser->yyidx].stateno; + + /* if( pParser->yyidx<0 ) return YY_NO_ACTION; */ + i = yy_shift_ofst[stateno]; + if( i==YY_SHIFT_USE_DFLT ){ + return yy_default[stateno]; + } + if( iLookAhead==YYNOCODE ){ + return YY_NO_ACTION; + } + i += iLookAhead; + if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ +#ifdef YYFALLBACK + int iFallback; /* Fallback token */ + if( iLookAhead %s\n", + yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]); + } #endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Regex){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Regex, mvc_model_validator_regex, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_regex_method_entry, 0); - - zend_class_implements(phalcon_mvc_model_validator_regex_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - - return SUCCESS; + return yy_find_shift_action(pParser, iFallback); + } +#endif + return yy_default[stateno]; + }else{ + return yy_action[i]; + } } -static PHP_METHOD(Phalcon_Mvc_Model_Validator_Regex, validate){ - - zval *record, *option = NULL, *field_name, *is_set, *value; - zval *failed = NULL, *matches, *pattern, *match_pattern; - zval *match_zero, *message = NULL, *type; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &record); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "field", 1); - - PHALCON_INIT_VAR(field_name); - phalcon_call_method_p1_key(field_name, this_ptr, "getoption", option, 1191969182UL); - if (Z_TYPE_P(field_name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); - return; - } - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "pattern", 1); - - PHALCON_INIT_VAR(is_set); - phalcon_call_method_p1_key(is_set, this_ptr, "issetoption", option, 2532732262UL); - if (!zend_is_true(is_set)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Validator requires a perl-compatible regex pattern"); - return; - } - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); - - PHALCON_INIT_VAR(failed); - ZVAL_BOOL(failed, 0); - - PHALCON_INIT_VAR(matches); - - PHALCON_INIT_VAR(pattern); - phalcon_call_method_p1_key(pattern, this_ptr, "getoption", option, 1191969182UL); - - PHALCON_INIT_VAR(match_pattern); - phalcon_preg_match(match_pattern, pattern, value, matches TSRMLS_CC); - - if (zend_is_true(match_pattern)) { - PHALCON_OBS_VAR(match_zero); - phalcon_array_fetch_long(&match_zero, matches, 0, PH_NOISY); - - is_not_equal_function(failed, match_zero, value TSRMLS_CC); - } else { - PHALCON_INIT_NVAR(failed); - ZVAL_BOOL(failed, 1); - } - - if (PHALCON_IS_TRUE(failed)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message); - phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message)) { - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_SVS(message, "Value of field '", field_name, "' doesn't match regular expression"); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Regex", 1); - phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field_name, type, 2313005058UL); - RETURN_MM_FALSE; - } - - RETURN_MM_TRUE; +static int yy_find_reduce_action( + yyParser *pParser, /* The parser */ + int iLookAhead /* The look-ahead token */ +){ + int i; + int stateno = pParser->yystack[pParser->yyidx].stateno; + + i = yy_reduce_ofst[stateno]; + if( i==YY_REDUCE_USE_DFLT ){ + return yy_default[stateno]; + } + if( iLookAhead==YYNOCODE ){ + return YY_NO_ACTION; + } + i += iLookAhead; + if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){ + return yy_default[stateno]; + }else{ + return yy_action[i]; + } } - - - - -#ifdef HAVE_CONFIG_H +static void yy_shift( + yyParser *yypParser, /* The parser to be shifted */ + int yyNewState, /* The new state to shift in */ + int yyMajor, /* The major token to shift in */ + YYMINORTYPE *yypMinor /* Pointer ot the minor token to shift in */ +){ + yyStackEntry *yytos; + yypParser->yyidx++; + if( yypParser->yyidx>=YYSTACKDEPTH ){ + phql_ARG_FETCH; + yypParser->yyidx--; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); + } +#endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will execute if the parser + ** stack every overflows */ + phql_ARG_STORE; /* Suppress warning about unused %extra_argument var */ + return; + } + yytos = &yypParser->yystack[yypParser->yyidx]; + yytos->stateno = yyNewState; + yytos->major = yyMajor; + yytos->minor = *yypMinor; +#ifndef NDEBUG + if( yyTraceFILE && yypParser->yyidx>0 ){ + int i; + fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState); + fprintf(yyTraceFILE,"%sStack:",yyTracePrompt); + for(i=1; i<=yypParser->yyidx; i++) + fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]); + fprintf(yyTraceFILE,"\n"); + } #endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_StringLength){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, StringLength, mvc_model_validator_stringlength, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_stringlength_method_entry, 0); - - zend_class_implements(phalcon_mvc_model_validator_stringlength_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Validator_StringLength, validate){ - - zval *record, *option = NULL, *field, *is_set_min, *is_set_max; - zval *value, *length = NULL, *invalid_maximum = NULL, *invalid_minimum = NULL; - zval *maximum, *message = NULL, *type = NULL, *minimum; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &record); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "field", 1); - - PHALCON_INIT_VAR(field); - phalcon_call_method_p1_key(field, this_ptr, "getoption", option, 1191969182UL); - if (Z_TYPE_P(field) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); - return; - } - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "min", 1); - - PHALCON_INIT_VAR(is_set_min); - phalcon_call_method_p1_key(is_set_min, this_ptr, "issetoption", option, 2532732262UL); - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "max", 1); - - PHALCON_INIT_VAR(is_set_max); - phalcon_call_method_p1_key(is_set_max, this_ptr, "issetoption", option, 2532732262UL); - if (!zend_is_true(is_set_min)) { - if (!zend_is_true(is_set_max)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A minimum or maximum must be set"); - return; - } - } - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); - - if (phalcon_function_quick_exists_ex(SS("mb_strlen"), 3716840971UL TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_VAR(length); - phalcon_call_func_p1(length, "mb_strlen", value); - } else { - PHALCON_INIT_NVAR(length); - phalcon_fast_strlen(length, value); - } - - PHALCON_INIT_VAR(invalid_maximum); - ZVAL_BOOL(invalid_maximum, 0); - - PHALCON_INIT_VAR(invalid_minimum); - ZVAL_BOOL(invalid_minimum, 0); - - if (zend_is_true(is_set_max)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "max", 1); - - PHALCON_INIT_VAR(maximum); - phalcon_call_method_p1_key(maximum, this_ptr, "getoption", option, 1191969182UL); - - is_smaller_function(invalid_maximum, maximum, length TSRMLS_CC); - if (PHALCON_IS_TRUE(invalid_maximum)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "messageMaximum", 1); - - PHALCON_INIT_VAR(message); - phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message)) { - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_SVSVS(message, "Value of field '", field, "' exceeds the maximum ", maximum, " characters"); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "TooLong", 1); - phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field, type, 2313005058UL); - RETURN_MM_FALSE; - } - } - - if (zend_is_true(is_set_min)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "min", 1); - - PHALCON_INIT_VAR(minimum); - phalcon_call_method_p1_key(minimum, this_ptr, "getoption", option, 1191969182UL); - - is_smaller_function(invalid_minimum, length, minimum TSRMLS_CC); - if (PHALCON_IS_TRUE(invalid_minimum)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "messageMinimum", 1); - - PHALCON_INIT_NVAR(message); - phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message)) { - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_SVSVS(message, "Value of field '", field, "' is less than the minimum ", minimum, " characters"); - } - - PHALCON_INIT_NVAR(type); - ZVAL_STRING(type, "TooShort", 1); - phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field, type, 2313005058UL); - RETURN_MM_FALSE; - } - } - - RETURN_MM_TRUE; } +/* The following table contains information about every rule that +** is used during the reduce. +*/ +static struct { + YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ + unsigned char nrhs; /* Number of right-hand side symbols in the rule */ +} yyRuleInfo[] = { + { 70, 1 }, + { 71, 1 }, + { 71, 1 }, + { 71, 1 }, + { 71, 1 }, + { 72, 1 }, + { 72, 2 }, + { 72, 3 }, + { 72, 3 }, + { 72, 4 }, + { 72, 4 }, + { 72, 5 }, + { 72, 5 }, + { 72, 3 }, + { 72, 4 }, + { 72, 4 }, + { 72, 5 }, + { 72, 2 }, + { 72, 3 }, + { 72, 4 }, + { 72, 3 }, + { 72, 4 }, + { 72, 6 }, + { 72, 2 }, + { 72, 3 }, + { 72, 3 }, + { 72, 4 }, + { 72, 5 }, + { 72, 2 }, + { 76, 4 }, + { 76, 5 }, + { 82, 3 }, + { 82, 1 }, + { 85, 1 }, + { 85, 3 }, + { 85, 3 }, + { 85, 2 }, + { 85, 1 }, + { 83, 3 }, + { 83, 1 }, + { 84, 2 }, + { 84, 1 }, + { 88, 1 }, + { 89, 2 }, + { 89, 3 }, + { 89, 3 }, + { 89, 4 }, + { 92, 2 }, + { 92, 1 }, + { 90, 1 }, + { 90, 2 }, + { 90, 2 }, + { 90, 2 }, + { 90, 3 }, + { 90, 2 }, + { 90, 3 }, + { 90, 2 }, + { 90, 3 }, + { 93, 2 }, + { 73, 7 }, + { 73, 10 }, + { 94, 3 }, + { 94, 1 }, + { 97, 1 }, + { 95, 3 }, + { 95, 1 }, + { 98, 1 }, + { 74, 1 }, + { 74, 2 }, + { 74, 2 }, + { 74, 3 }, + { 99, 4 }, + { 101, 3 }, + { 101, 1 }, + { 102, 3 }, + { 104, 1 }, + { 75, 1 }, + { 75, 2 }, + { 75, 2 }, + { 75, 3 }, + { 105, 3 }, + { 87, 3 }, + { 87, 2 }, + { 87, 1 }, + { 91, 1 }, + { 77, 2 }, + { 78, 3 }, + { 106, 3 }, + { 106, 1 }, + { 107, 1 }, + { 107, 2 }, + { 107, 2 }, + { 79, 3 }, + { 108, 3 }, + { 108, 1 }, + { 109, 1 }, + { 80, 2 }, + { 81, 2 }, + { 81, 4 }, + { 81, 4 }, + { 100, 2 }, + { 86, 2 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 3 }, + { 86, 4 }, + { 86, 3 }, + { 86, 4 }, + { 86, 5 }, + { 86, 6 }, + { 86, 3 }, + { 86, 6 }, + { 86, 6 }, + { 86, 1 }, + { 111, 4 }, + { 111, 3 }, + { 110, 3 }, + { 110, 1 }, + { 112, 1 }, + { 112, 1 }, + { 86, 3 }, + { 86, 4 }, + { 86, 2 }, + { 86, 3 }, + { 86, 2 }, + { 86, 2 }, + { 86, 3 }, + { 86, 1 }, + { 86, 1 }, + { 86, 1 }, + { 86, 1 }, + { 86, 1 }, + { 86, 1 }, + { 86, 1 }, + { 86, 1 }, + { 86, 1 }, + { 103, 5 }, + { 103, 3 }, + { 103, 3 }, + { 103, 1 }, +}; +static void yy_accept(yyParser*); /* Forward Declaration */ +static void yy_reduce( + yyParser *yypParser, /* The parser */ + int yyruleno /* Number of the rule by which to reduce */ +){ + int yygoto; /* The next state */ + int yyact; /* The next action */ + YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ + yyStackEntry *yymsp; /* The top of the parser's stack */ + int yysize; /* Amount to pop the stack */ + phql_ARG_FETCH; + yymsp = &yypParser->yystack[yypParser->yyidx]; +#ifndef NDEBUG + if( yyTraceFILE && yyruleno>=0 + && yyruleno + ** { ... } // User supplied code + ** // + ** break; + */ + case 0: +// 522 "parser.lemon" +{ + status->ret = yymsp[0].minor.yy132; } - -static PHP_METHOD(Phalcon_Mvc_Model_Validator_Email, validate){ - - zval *record, *option = NULL, *field_name, *regs, *invalid = NULL; - zval *value, *pattern, *match_pattern, *match_zero; - zval *message = NULL, *type; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &record); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "field", 1); - - PHALCON_INIT_VAR(field_name); - phalcon_call_method_p1_key(field_name, this_ptr, "getoption", option, 1191969182UL); - if (Z_TYPE_P(field_name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); - return; - } - - PHALCON_INIT_VAR(regs); - - PHALCON_INIT_VAR(invalid); - ZVAL_BOOL(invalid, 0); - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); - - PHALCON_INIT_VAR(pattern); - ZVAL_STRING(pattern, "/^[a-zA-Z0-9\\-_\\.\\+]+@[a-zA-Z0-9_\\-]+(\\.[a-zA-Z0-9_\\-]+)*$/", 1); - - PHALCON_INIT_VAR(match_pattern); - phalcon_preg_match(match_pattern, pattern, value, regs TSRMLS_CC); - - if (zend_is_true(match_pattern)) { - PHALCON_OBS_VAR(match_zero); - phalcon_array_fetch_long(&match_zero, regs, 0, PH_NOISY); - - is_not_equal_function(invalid, match_zero, value TSRMLS_CC); - } else { - PHALCON_INIT_NVAR(invalid); - ZVAL_BOOL(invalid, 1); - } - - if (PHALCON_IS_TRUE(invalid)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message); - phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message)) { - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_SVS(message, "Value of field '", field_name, "' must have a valid e-mail format"); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Email", 1); - phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field_name, type, 2313005058UL); - RETURN_MM_FALSE; - } - - RETURN_MM_TRUE; +// 1595 "parser.c" + break; + case 1: + case 2: + case 3: + case 4: + case 32: + case 39: + case 41: + case 42: + case 62: + case 63: + case 65: + case 73: + case 75: + case 84: + case 88: + case 94: + case 95: + case 127: + case 133: + case 141: +// 528 "parser.lemon" +{ + yygotominor.yy132 = yymsp[0].minor.yy132; } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Exclusionin){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Exclusionin, mvc_model_validator_exclusionin, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_exclusionin_method_entry, 0); - - zend_class_implements(phalcon_mvc_model_validator_exclusionin_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - - return SUCCESS; +// 1621 "parser.c" + break; + case 5: +// 546 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[0].minor.yy132, NULL, NULL, NULL, NULL, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Validator_Exclusionin, validate){ - - zval *record, *option = NULL, *field_name, *is_set, *domain; - zval *value, *message = NULL, *joined_domain, *type; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &record); - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "field", 1); - - PHALCON_INIT_VAR(field_name); - phalcon_call_method_p1_key(field_name, this_ptr, "getoption", option, 1191969182UL); - if (Z_TYPE_P(field_name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); - return; - } - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "domain", 1); - - PHALCON_INIT_VAR(is_set); - phalcon_call_method_p1_key(is_set, this_ptr, "issetoption", option, 2532732262UL); - if (PHALCON_IS_FALSE(is_set)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'domain' is required for this validator"); - return; - } - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "domain", 1); - - PHALCON_INIT_VAR(domain); - phalcon_call_method_p1_key(domain, this_ptr, "getoption", option, 1191969182UL); - if (Z_TYPE_P(domain) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Option 'domain' must be an array"); - return; - } - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); - - if (phalcon_fast_in_array(value, domain TSRMLS_CC)) { - - PHALCON_INIT_NVAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message); - phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message)) { - PHALCON_INIT_VAR(joined_domain); - phalcon_fast_join_str(joined_domain, SL(", "), domain TSRMLS_CC); - - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_SVSV(message, "Value of field '", field_name, "' must not be part of list: ", joined_domain); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Exclusion", 1); - phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field_name, type, 2313005058UL); - RETURN_MM_FALSE; - } - - RETURN_MM_TRUE; +// 1628 "parser.c" + break; + case 6: +// 550 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL, NULL, NULL, NULL); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Inclusionin){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Inclusionin, mvc_model_validator_inclusionin, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_inclusionin_method_entry, 0); - - zend_class_implements(phalcon_mvc_model_validator_inclusionin_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - - return SUCCESS; +// 1635 "parser.c" + break; + case 7: +// 554 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL, NULL, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Validator_Inclusionin, validate){ - - zval *record, *field = NULL, *field_name, *is_set, *domain; - zval *value, *option, *message = NULL, *joined_domain; - zval *type; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &record); - - PHALCON_INIT_VAR(field); - ZVAL_STRING(field, "field", 1); - - PHALCON_INIT_VAR(field_name); - phalcon_call_method_p1_key(field_name, this_ptr, "getoption", field, 1191969182UL); - if (Z_TYPE_P(field_name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); - return; - } - - PHALCON_INIT_NVAR(field); - ZVAL_STRING(field, "domain", 1); - - PHALCON_INIT_VAR(is_set); - phalcon_call_method_p1_key(is_set, this_ptr, "issetoption", field, 2532732262UL); - if (PHALCON_IS_FALSE(is_set)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'domain' is required for this validator"); - return; - } - - PHALCON_INIT_NVAR(field); - ZVAL_STRING(field, "domain", 1); - - PHALCON_INIT_VAR(domain); - phalcon_call_method_p1_key(domain, this_ptr, "getoption", field, 1191969182UL); - if (Z_TYPE_P(domain) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Option 'domain' must be an array"); - return; - } - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); - - if (!phalcon_fast_in_array(value, domain TSRMLS_CC)) { - - PHALCON_INIT_VAR(option); - ZVAL_STRING(option, "message", 1); - - PHALCON_INIT_VAR(message); - phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); - if (!zend_is_true(message)) { - PHALCON_INIT_VAR(joined_domain); - phalcon_fast_join_str(joined_domain, SL(", "), domain TSRMLS_CC); - - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_SVSV(message, "Value of field '", field_name, "' must be part of list: ", joined_domain); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "Inclusion", 1); - phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field_name, type, 2313005058UL); - RETURN_MM_FALSE; - } - - RETURN_MM_TRUE; +// 1642 "parser.c" + break; + case 8: +// 558 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132, NULL, NULL); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Relation){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Relation, mvc_model_relation, phalcon_mvc_model_relation_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_referencedModel"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_fields"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_referencedFields"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_intermediateModel"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_intermediateFields"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_intermediateReferencedFields"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("BELONGS_TO"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("HAS_ONE"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("HAS_MANY"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("HAS_ONE_THROUGH"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("HAS_MANY_THROUGH"), 4 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("NO_ACTION"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("ACTION_RESTRICT"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("ACTION_CASCADE"), 2 TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_relation_ce TSRMLS_CC, 1, phalcon_mvc_model_relationinterface_ce); - - return SUCCESS; +// 1649 "parser.c" + break; + case 9: +// 562 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, NULL, yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, __construct){ - - zval *type, *referenced_model, *fields, *referenced_fields; - zval *options = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 4, 1, &type, &referenced_model, &fields, &referenced_fields, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_referencedModel"), referenced_model, 4077480136UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_fields"), fields, 3492004987UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_referencedFields"), referenced_fields, 729137326UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); +// 1656 "parser.c" + break; + case 10: +// 566 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, yymsp[0].minor.yy132, yymsp[-1].minor.yy132, NULL, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, setIntermediateRelation){ - - zval *intermediate_fields, *intermediate_model; - zval *intermediate_referenced_fields; - - phalcon_fetch_params(0, 3, 0, &intermediate_fields, &intermediate_model, &intermediate_referenced_fields); - - phalcon_update_property_this_quick(this_ptr, SL("_intermediateFields"), intermediate_fields, 1022734614UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_intermediateModel"), intermediate_model, 312011824UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_intermediateReferencedFields"), intermediate_referenced_fields, 3351276297UL TSRMLS_CC); - +// 1663 "parser.c" + break; + case 11: +// 570 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-4].minor.yy132, yymsp[-3].minor.yy132, yymsp[-1].minor.yy132, yymsp[-2].minor.yy132, NULL, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, getType){ - - - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); +// 1670 "parser.c" + break; + case 12: +// 574 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-4].minor.yy132, yymsp[-3].minor.yy132, yymsp[0].minor.yy132, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, getReferencedModel){ - - - RETURN_MEMBER_QUICK(this_ptr, "_referencedModel", 4077480136UL); +// 1677 "parser.c" + break; + case 13: +// 578 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL, NULL, NULL, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, getFields){ - - - RETURN_MEMBER_QUICK(this_ptr, "_fields", 3492004987UL); +// 1684 "parser.c" + break; + case 14: +// 582 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL, NULL, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, getReferencedFields){ - - - RETURN_MEMBER_QUICK(this_ptr, "_referencedFields", 729137326UL); +// 1691 "parser.c" + break; + case 15: +// 586 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, NULL, yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, getOptions){ - - - RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); +// 1698 "parser.c" + break; + case 16: +// 590 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-4].minor.yy132, yymsp[-3].minor.yy132, NULL, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, isForeignKey){ - - zval *options; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(options, SS("foreignKey"), 1865016664UL)) { - RETURN_MM_TRUE; - } - } - - RETURN_MM_FALSE; +// 1705 "parser.c" + break; + case 17: +// 594 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132, NULL, NULL, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, getForeignKey){ - - zval *options, *foreign_key; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(options, SS("foreignKey"), 1865016664UL)) { - - PHALCON_OBS_VAR(foreign_key); - phalcon_array_fetch_quick_string(&foreign_key, options, SS("foreignKey"), 1865016664UL, PH_NOISY); - if (zend_is_true(foreign_key)) { - RETURN_CCTOR(foreign_key); - } - } - } - - RETURN_MM_FALSE; +// 1712 "parser.c" + break; + case 18: +// 598 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, NULL, yymsp[0].minor.yy132, yymsp[-1].minor.yy132, NULL, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, isThrough){ - - zval *type; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(type); - phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); - if (PHALCON_IS_LONG(type, 3)) { - RETURN_MM_TRUE; - } else { - if (PHALCON_IS_LONG(type, 4)) { - RETURN_MM_TRUE; - } - } - - RETURN_MM_FALSE; +// 1719 "parser.c" + break; + case 19: +// 602 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, NULL, yymsp[0].minor.yy132, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, isReusable){ - - zval *options, *reusable; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(options, SS("reusable"), 1227996376UL)) { - PHALCON_OBS_VAR(reusable); - phalcon_array_fetch_quick_string(&reusable, options, SS("reusable"), 1227996376UL, PH_NOISY); - RETURN_CCTOR(reusable); - } - } - - RETURN_MM_FALSE; +// 1726 "parser.c" + break; + case 20: +// 606 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, NULL, yymsp[-1].minor.yy132, NULL, NULL, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, getIntermediateFields){ - - - RETURN_MEMBER_QUICK(this_ptr, "_intermediateFields", 1022734614UL); +// 1733 "parser.c" + break; + case 21: +// 610 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, NULL, yymsp[-1].minor.yy132, yymsp[-2].minor.yy132, NULL, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, getIntermediateModel){ - - - RETURN_MEMBER_QUICK(this_ptr, "_intermediateModel", 312011824UL); +// 1740 "parser.c" + break; + case 22: +// 614 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-5].minor.yy132, yymsp[-4].minor.yy132, yymsp[-1].minor.yy132, yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Relation, getIntermediateReferencedFields){ - - - RETURN_MEMBER_QUICK(this_ptr, "_intermediateReferencedFields", 3351276297UL); +// 1747 "parser.c" + break; + case 23: +// 618 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-1].minor.yy132, NULL, NULL, yymsp[0].minor.yy132, NULL, NULL); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model, Exception, mvc_model_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; +// 1754 "parser.c" + break; + case 24: +// 622 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, NULL, NULL, yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Criteria){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Criteria, mvc_model_criteria, phalcon_mvc_model_criteria_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_model_criteria_ce, SL("_model"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_criteria_ce, SL("_params"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_model_criteria_ce, SL("_hiddenParamNumber"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_criteria_ce TSRMLS_CC, 2, phalcon_mvc_model_criteriainterface_ce, phalcon_di_injectionawareinterface_ce); - - return SUCCESS; +// 1761 "parser.c" + break; + case 25: +// 626 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-2].minor.yy132, NULL, NULL, yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Dependency Injector is invalid"); - return; - } - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("di"), dependency_injector TSRMLS_CC); - +// 1768 "parser.c" + break; + case 26: +// 630 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-3].minor.yy132, NULL, NULL, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getDI){ - - zval *params, *dependency_injector; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("di"), 193489362UL)) { - PHALCON_OBS_VAR(dependency_injector); - phalcon_array_fetch_quick_string(&dependency_injector, params, SS("di"), 193489362UL, PH_NOISY); - RETURN_CCTOR(dependency_injector); - } - - RETURN_MM_NULL(); +// 1775 "parser.c" + break; + case 27: +// 634 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-4].minor.yy132, NULL, yymsp[-1].minor.yy132, yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, setModelName){ - - zval *model_name; - - phalcon_fetch_params(0, 1, 0, &model_name); - - if (Z_TYPE_P(model_name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Model name must be string"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_model"), model_name, 2599397109UL TSRMLS_CC); - - RETURN_THISW(); +// 1782 "parser.c" + break; + case 28: +// 638 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[-1].minor.yy132, NULL, NULL, NULL, NULL, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getModelName){ - - zval *model; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(model); - phalcon_read_property_this_quick(&model, this_ptr, SL("_model"), 2599397109UL, PH_NOISY_CC); - RETURN_CCTOR(model); +// 1789 "parser.c" + break; + case 29: +// 644 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_clause(yymsp[-2].minor.yy132, yymsp[0].minor.yy132, NULL); + yy_destructor(26,&yymsp[-3].minor); + yy_destructor(27,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, bind){ - - zval *bind_params; - - phalcon_fetch_params(0, 1, 0, &bind_params); - - if (Z_TYPE_P(bind_params) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Bound parameters must be an Array"); - return; - } - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bind"), bind_params TSRMLS_CC); - - RETURN_THISW(); +// 1798 "parser.c" + break; + case 30: +// 648 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_clause(yymsp[-3].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(26,&yymsp[-4].minor); + yy_destructor(27,&yymsp[-2].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, bindTypes){ - - zval *bind_types; - - phalcon_fetch_params(0, 1, 0, &bind_types); - - if (Z_TYPE_P(bind_types) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Bind types parameters must be an Array"); - return; - } - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bindTypes"), bind_types TSRMLS_CC); - - RETURN_THISW(); +// 1807 "parser.c" + break; + case 31: + case 38: + case 61: + case 64: + case 72: + case 87: + case 93: + case 130: +// 654 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_zval_list(yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(28,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, columns){ - - zval *columns; - - phalcon_fetch_params(0, 1, 0, &columns); - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("columns"), columns TSRMLS_CC); - RETURN_THISW(); +// 1822 "parser.c" + break; + case 33: + case 132: +// 664 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_column_item(PHQL_T_ALL, NULL, NULL, NULL); + yy_destructor(17,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, join){ - - zval *model, *conditions = NULL, *alias = NULL, *type = NULL, *join, *params; - zval *current_joins, *merged_joins = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 3, &model, &conditions, &alias, &type); - - if (!conditions) { - PHALCON_INIT_VAR(conditions); - } - - if (!alias) { - PHALCON_INIT_VAR(alias); - } - - if (!type) { - PHALCON_INIT_VAR(type); - } - - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("joins"), 120974824UL)) { - - PHALCON_OBS_VAR(current_joins); - phalcon_array_fetch_quick_string(¤t_joins, params, SS("joins"), 120974824UL, PH_NOISY); - if (Z_TYPE_P(current_joins) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_joins); - phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_joins, join); - } - } else { - PHALCON_INIT_NVAR(merged_joins); - array_init_size(merged_joins, 1); - phalcon_array_append(&merged_joins, join, PH_SEPARATE); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); - - RETURN_THIS(); +// 1831 "parser.c" + break; + case 34: +// 668 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_column_item(PHQL_T_DOMAINALL, NULL, yymsp[-2].minor.yy0, NULL); + yy_destructor(30,&yymsp[-1].minor); + yy_destructor(17,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, innerJoin){ - - zval *model, *conditions = NULL, *alias = NULL, *type, *join, *params; - zval *current_joins, *merged_joins = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); - - if (!conditions) { - PHALCON_INIT_VAR(conditions); - } - - if (!alias) { - PHALCON_INIT_VAR(alias); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "INNER", 1); - - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("joins"), 120974824UL)) { - - PHALCON_OBS_VAR(current_joins); - phalcon_array_fetch_quick_string(¤t_joins, params, SS("joins"), 120974824UL, PH_NOISY); - if (Z_TYPE_P(current_joins) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_joins); - phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_joins, join); - } - } else { - PHALCON_INIT_NVAR(merged_joins); - array_init_size(merged_joins, 1); - phalcon_array_append(&merged_joins, join, PH_SEPARATE); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); - - RETURN_THIS(); +// 1840 "parser.c" + break; + case 35: +// 672 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_column_item(PHQL_T_EXPR, yymsp[-2].minor.yy132, NULL, yymsp[0].minor.yy0); + yy_destructor(31,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, leftJoin){ - - zval *model, *conditions = NULL, *alias = NULL, *type, *join, *params; - zval *current_joins, *merged_joins = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); - - if (!conditions) { - PHALCON_INIT_VAR(conditions); - } - - if (!alias) { - PHALCON_INIT_VAR(alias); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "LEFT", 1); - - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("joins"), 120974824UL)) { - - PHALCON_OBS_VAR(current_joins); - phalcon_array_fetch_quick_string(¤t_joins, params, SS("joins"), 120974824UL, PH_NOISY); - if (Z_TYPE_P(current_joins) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_joins); - phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_joins, join); - } - } else { - PHALCON_INIT_NVAR(merged_joins); - array_init_size(merged_joins, 1); - phalcon_array_append(&merged_joins, join, PH_SEPARATE); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); - - RETURN_THIS(); +// 1848 "parser.c" + break; + case 36: +// 676 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_column_item(PHQL_T_EXPR, yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy0); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, rightJoin){ - - zval *model, *conditions = NULL, *alias = NULL, *type, *join, *params; - zval *current_joins, *merged_joins = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); - - if (!conditions) { - PHALCON_INIT_VAR(conditions); - } - - if (!alias) { - PHALCON_INIT_VAR(alias); - } - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "RIGHT", 1); - - PHALCON_INIT_VAR(join); - array_init_size(join, 4); - phalcon_array_append(&join, model, PH_SEPARATE); - phalcon_array_append(&join, conditions, PH_SEPARATE); - phalcon_array_append(&join, alias, PH_SEPARATE); - phalcon_array_append(&join, type, PH_SEPARATE); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("joins"), 120974824UL)) { - - PHALCON_OBS_VAR(current_joins); - phalcon_array_fetch_quick_string(¤t_joins, params, SS("joins"), 120974824UL, PH_NOISY); - if (Z_TYPE_P(current_joins) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_joins); - phalcon_fast_array_merge(merged_joins, ¤t_joins, &join TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_joins, join); - } - } else { - PHALCON_INIT_NVAR(merged_joins); - array_init_size(merged_joins, 1); - phalcon_array_append(&merged_joins, join, PH_SEPARATE); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("joins"), merged_joins TSRMLS_CC); - - RETURN_THIS(); +// 1855 "parser.c" + break; + case 37: +// 680 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_column_item(PHQL_T_EXPR, yymsp[0].minor.yy132, NULL, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, where){ - - zval *conditions, *bind_params = NULL, *bind_types = NULL; - zval *params = NULL, *current_bind_params, *merged_params = NULL; - zval *current_bind_types, *merged_params_types = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } - - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } - - if (Z_TYPE_P(conditions) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Conditions must be string"); - return; - } - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("conditions"), conditions TSRMLS_CC); - - if (Z_TYPE_P(bind_params) == IS_ARRAY) { - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { - PHALCON_OBS_VAR(current_bind_params); - phalcon_array_fetch_quick_string(¤t_bind_params, params, SS("bind"), 254268962UL, PH_NOISY); - - PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params, bind_params); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bind"), merged_params TSRMLS_CC); - } - - if (Z_TYPE_P(bind_types) == IS_ARRAY) { - - PHALCON_OBS_NVAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { - PHALCON_OBS_VAR(current_bind_types); - phalcon_array_fetch_quick_string(¤t_bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); - - PHALCON_INIT_VAR(merged_params_types); - phalcon_fast_array_merge(merged_params_types, ¤t_bind_types, &bind_types TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params_types, bind_types); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bindTypes"), merged_params_types TSRMLS_CC); - } - - RETURN_THIS(); +// 1862 "parser.c" + break; + case 40: +// 696 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_zval_list(yymsp[-1].minor.yy132, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, addWhere){ - - zval *conditions, *bind_params = NULL, *bind_types = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } - - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } - - phalcon_call_method_p3_key(NULL, this_ptr, "andwhere", conditions, bind_params, bind_types, 3363158931UL); - RETURN_THIS(); +// 1869 "parser.c" + break; + case 43: +// 713 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_item(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, andWhere){ - - zval *conditions, *bind_params = NULL, *bind_types = NULL; - zval *params = NULL, *current_conditions, *new_conditions = NULL; - zval *current_bind_params, *merged_params = NULL; - zval *current_bind_types, *merged_params_types = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } - - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } - - if (Z_TYPE_P(conditions) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Conditions must be string"); - return; - } - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { - PHALCON_OBS_VAR(current_conditions); - phalcon_array_fetch_quick_string(¤t_conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); - - PHALCON_INIT_VAR(new_conditions); - PHALCON_CONCAT_SVSVS(new_conditions, "(", current_conditions, ") AND (", conditions, ")"); - } else { - PHALCON_CPY_WRT(new_conditions, conditions); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("conditions"), new_conditions TSRMLS_CC); - - if (Z_TYPE_P(bind_params) == IS_ARRAY) { - - PHALCON_OBS_NVAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { - PHALCON_OBS_VAR(current_bind_params); - phalcon_array_fetch_quick_string(¤t_bind_params, params, SS("bind"), 254268962UL, PH_NOISY); - - PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params, bind_params); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bind"), merged_params TSRMLS_CC); - } - - if (Z_TYPE_P(bind_types) == IS_ARRAY) { - - PHALCON_OBS_NVAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { - PHALCON_OBS_VAR(current_bind_types); - phalcon_array_fetch_quick_string(¤t_bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); - - PHALCON_INIT_VAR(merged_params_types); - phalcon_fast_array_merge(merged_params_types, ¤t_bind_types, &bind_types TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params_types, bind_types); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bindTypes"), merged_params_types TSRMLS_CC); - } - - RETURN_THIS(); +// 1876 "parser.c" + break; + case 44: +// 718 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_item(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, orWhere){ - - zval *conditions, *bind_params = NULL, *bind_types = NULL; - zval *params = NULL, *current_conditions, *new_conditions = NULL; - zval *current_bind_params, *merged_params = NULL; - zval *current_bind_types, *merged_params_types = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &conditions, &bind_params, &bind_types); - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } - - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } - - if (Z_TYPE_P(conditions) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Conditions must be string"); - return; - } - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { - PHALCON_OBS_VAR(current_conditions); - phalcon_array_fetch_quick_string(¤t_conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); - - PHALCON_INIT_VAR(new_conditions); - PHALCON_CONCAT_SVSVS(new_conditions, "(", current_conditions, ") OR (", conditions, ")"); - } else { - PHALCON_CPY_WRT(new_conditions, conditions); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("conditions"), new_conditions TSRMLS_CC); - - if (Z_TYPE_P(bind_params) == IS_ARRAY) { - - PHALCON_OBS_NVAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { - PHALCON_OBS_VAR(current_bind_params); - phalcon_array_fetch_quick_string(¤t_bind_params, params, SS("bind"), 254268962UL, PH_NOISY); - - PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params, bind_params); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bind"), merged_params TSRMLS_CC); - } - - if (Z_TYPE_P(bind_types) == IS_ARRAY) { - - PHALCON_OBS_NVAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { - PHALCON_OBS_VAR(current_bind_types); - phalcon_array_fetch_quick_string(¤t_bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); - - PHALCON_INIT_VAR(merged_params_types); - phalcon_fast_array_merge(merged_params_types, ¤t_bind_types, &bind_types TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params_types, bind_types); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("bindTypes"), merged_params_types TSRMLS_CC); - } - - RETURN_THIS(); +// 1883 "parser.c" + break; + case 45: +// 723 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_item(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, betweenWhere){ - - zval *expr, *minimum, *maximum, *hidden_param, *one; - zval *next_hidden_param, *minimum_key, *maximum_key; - zval *conditions, *bind_params; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &expr, &minimum, &maximum); - - PHALCON_OBS_VAR(hidden_param); - phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - PHALCON_INIT_VAR(next_hidden_param); - phalcon_add_function(next_hidden_param, hidden_param, one TSRMLS_CC); - - PHALCON_INIT_VAR(minimum_key); - PHALCON_CONCAT_SV(minimum_key, "phb", hidden_param); - - PHALCON_INIT_VAR(maximum_key); - PHALCON_CONCAT_SV(maximum_key, "phb", next_hidden_param); - - PHALCON_INIT_VAR(conditions); - PHALCON_CONCAT_VSVSVS(conditions, expr, " BETWEEN :", minimum_key, ": AND :", maximum_key, ":"); - - PHALCON_INIT_VAR(bind_params); - array_init_size(bind_params, 2); - phalcon_array_update_zval(&bind_params, minimum_key, &minimum, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&bind_params, maximum_key, &maximum, PH_COPY | PH_SEPARATE); - - phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); - PHALCON_SEPARATE(next_hidden_param); - phalcon_increment(next_hidden_param); - phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), next_hidden_param, 3119958698UL TSRMLS_CC); - RETURN_THIS(); +// 1890 "parser.c" + break; + case 46: +// 728 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_item(yymsp[-3].minor.yy132, yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, notBetweenWhere){ - - zval *expr, *minimum, *maximum, *hidden_param, *one; - zval *next_hidden_param, *minimum_key, *maximum_key; - zval *conditions, *bind_params; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &expr, &minimum, &maximum); - - PHALCON_OBS_VAR(hidden_param); - phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - PHALCON_INIT_VAR(next_hidden_param); - phalcon_add_function(next_hidden_param, hidden_param, one TSRMLS_CC); - - PHALCON_INIT_VAR(minimum_key); - PHALCON_CONCAT_SV(minimum_key, "phb", hidden_param); - - PHALCON_INIT_VAR(maximum_key); - PHALCON_CONCAT_SV(maximum_key, "phb", next_hidden_param); - - PHALCON_INIT_VAR(conditions); - PHALCON_CONCAT_VSVSVS(conditions, expr, " NOT BETWEEN :", minimum_key, ": AND :", maximum_key, ":"); - - PHALCON_INIT_VAR(bind_params); - array_init_size(bind_params, 2); - phalcon_array_update_zval(&bind_params, minimum_key, &minimum, PH_COPY | PH_SEPARATE); - phalcon_array_update_zval(&bind_params, maximum_key, &maximum, PH_COPY | PH_SEPARATE); - - phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); - PHALCON_SEPARATE(next_hidden_param); - phalcon_increment(next_hidden_param); - phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), next_hidden_param, 3119958698UL TSRMLS_CC); - RETURN_THIS(); +// 1897 "parser.c" + break; + case 47: +// 734 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_qualified_name(NULL, NULL, yymsp[0].minor.yy0); + yy_destructor(31,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, inWhere){ - - zval *expr, *values, *hidden_param, *bind_params; - zval *bind_keys, *value = NULL, *key = NULL, *query_key = NULL, *joined_keys; - zval *conditions; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &expr, &values); - - if (Z_TYPE_P(values) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Values must be an array"); - return; - } - - PHALCON_OBS_VAR(hidden_param); - phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(bind_params); - array_init(bind_params); - - PHALCON_INIT_VAR(bind_keys); - array_init(bind_keys); - - phalcon_is_iterable(values, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(value); - - PHALCON_INIT_NVAR(key); - PHALCON_CONCAT_SV(key, "phi", hidden_param); - - PHALCON_INIT_NVAR(query_key); - PHALCON_CONCAT_SVS(query_key, ":", key, ":"); - phalcon_array_append(&bind_keys, query_key, PH_SEPARATE); - phalcon_array_update_zval(&bind_params, key, &value, PH_COPY | PH_SEPARATE); - PHALCON_SEPARATE(hidden_param); - phalcon_increment(hidden_param); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(joined_keys); - phalcon_fast_join_str(joined_keys, SL(", "), bind_keys TSRMLS_CC); - - PHALCON_INIT_VAR(conditions); - PHALCON_CONCAT_VSVS(conditions, expr, " IN (", joined_keys, ")"); - - phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); - phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), hidden_param, 3119958698UL TSRMLS_CC); - - RETURN_THIS(); +// 1905 "parser.c" + break; + case 48: + case 66: + case 153: +// 738 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_qualified_name(NULL, NULL, yymsp[0].minor.yy0); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, notInWhere){ - - zval *expr, *values, *hidden_param, *bind_params; - zval *bind_keys, *value = NULL, *key = NULL, *query_key = NULL, *joined_keys; - zval *conditions; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &expr, &values); - - if (Z_TYPE_P(values) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Values must be an array"); - return; - } - - PHALCON_OBS_VAR(hidden_param); - phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(bind_params); - array_init(bind_params); - - PHALCON_INIT_VAR(bind_keys); - array_init(bind_keys); - - phalcon_is_iterable(values, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(value); - - PHALCON_INIT_NVAR(key); - PHALCON_CONCAT_SV(key, "phi", hidden_param); - - PHALCON_INIT_NVAR(query_key); - PHALCON_CONCAT_SVS(query_key, ":", key, ":"); - phalcon_array_append(&bind_keys, query_key, PH_SEPARATE); - phalcon_array_update_zval(&bind_params, key, &value, PH_COPY | PH_SEPARATE); - PHALCON_SEPARATE(hidden_param); - phalcon_increment(hidden_param); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(joined_keys); - phalcon_fast_join_str(joined_keys, SL(", "), bind_keys TSRMLS_CC); - - PHALCON_INIT_VAR(conditions); - PHALCON_CONCAT_VSVS(conditions, expr, " NOT IN (", joined_keys, ")"); - - phalcon_call_method_p2_key(NULL, this_ptr, "andwhere", conditions, bind_params, 3363158931UL); - phalcon_update_property_this_quick(this_ptr, SL("_hiddenParamNumber"), hidden_param, 3119958698UL TSRMLS_CC); - - RETURN_THIS(); +// 1914 "parser.c" + break; + case 49: +// 744 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_type(PHQL_T_INNERJOIN); + yy_destructor(32,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, conditions){ - - zval *conditions; - - phalcon_fetch_params(0, 1, 0, &conditions); - - if (Z_TYPE_P(conditions) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Conditions must be string"); - return; - } - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("conditions"), conditions TSRMLS_CC); - - RETURN_THISW(); +// 1922 "parser.c" + break; + case 50: +// 748 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_type(PHQL_T_INNERJOIN); + yy_destructor(33,&yymsp[-1].minor); + yy_destructor(32,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, order){ - - zval *order_columns; - - phalcon_fetch_params(0, 1, 0, &order_columns); - - if (Z_TYPE_P(order_columns) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Order columns must be string"); - return; - } - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("order"), order_columns TSRMLS_CC); - - RETURN_THISW(); +// 1931 "parser.c" + break; + case 51: +// 752 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_type(PHQL_T_CROSSJOIN); + yy_destructor(34,&yymsp[-1].minor); + yy_destructor(32,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, orderBy){ - - zval *order_columns; - - phalcon_fetch_params(0, 1, 0, &order_columns); - - if (Z_TYPE_P(order_columns) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Order columns must be string"); - return; - } - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("order"), order_columns TSRMLS_CC); - - RETURN_THISW(); +// 1940 "parser.c" + break; + case 52: +// 756 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_type(PHQL_T_LEFTJOIN); + yy_destructor(35,&yymsp[-1].minor); + yy_destructor(32,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, limit){ - - zval *limit, *offset = NULL, *limit_clause; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &limit, &offset); - - if (!offset) { - PHALCON_INIT_VAR(offset); - } - - if (!phalcon_is_numeric(limit)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Rows limit parameter must be integer"); - return; - } - if (Z_TYPE_P(offset) == IS_NULL) { - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("limit"), limit TSRMLS_CC); - } else { - PHALCON_INIT_VAR(limit_clause); - array_init_size(limit_clause, 2); - phalcon_array_update_quick_string(&limit_clause, SS("number"), 807219790UL, &limit, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&limit_clause, SS("offset"), 1503966412UL, &offset, PH_COPY | PH_SEPARATE); - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("limit"), limit_clause TSRMLS_CC); - } - - RETURN_THIS(); +// 1949 "parser.c" + break; + case 53: +// 760 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_type(PHQL_T_LEFTJOIN); + yy_destructor(35,&yymsp[-2].minor); + yy_destructor(36,&yymsp[-1].minor); + yy_destructor(32,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, forUpdate){ - - zval *for_update = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &for_update); - - if (!for_update) { - PHALCON_INIT_VAR(for_update); - ZVAL_BOOL(for_update, 1); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("for_update"), for_update TSRMLS_CC); - RETURN_THIS(); +// 1959 "parser.c" + break; + case 54: +// 764 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_type(PHQL_T_RIGHTJOIN); + yy_destructor(37,&yymsp[-1].minor); + yy_destructor(32,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, sharedLock){ - - zval *shared_lock = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &shared_lock); - - if (!shared_lock) { - PHALCON_INIT_VAR(shared_lock); - ZVAL_BOOL(shared_lock, 1); - } - - phalcon_update_property_array_string(this_ptr, SL("_params"), SS("shared_lock"), shared_lock TSRMLS_CC); - RETURN_THIS(); +// 1968 "parser.c" + break; + case 55: +// 768 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_type(PHQL_T_RIGHTJOIN); + yy_destructor(37,&yymsp[-2].minor); + yy_destructor(36,&yymsp[-1].minor); + yy_destructor(32,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getWhere){ - - zval *params, *conditions; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_quick_string(&conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); - RETURN_CCTOR(conditions); - } - - RETURN_MM_NULL(); +// 1978 "parser.c" + break; + case 56: +// 772 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_type(PHQL_T_FULLJOIN); + yy_destructor(38,&yymsp[-1].minor); + yy_destructor(32,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getColumns){ - - zval *params, *columns; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("columns"), 1041822630UL)) { - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, params, SS("columns"), 1041822630UL, PH_NOISY); - RETURN_CCTOR(columns); - } - - RETURN_MM_NULL(); +// 1987 "parser.c" + break; + case 57: +// 776 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_type(PHQL_T_FULLJOIN); + yy_destructor(38,&yymsp[-2].minor); + yy_destructor(36,&yymsp[-1].minor); + yy_destructor(32,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getConditions){ - - zval *params, *conditions; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_quick_string(&conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); - RETURN_CCTOR(conditions); - } - - RETURN_MM_NULL(); +// 1997 "parser.c" + break; + case 58: +// 782 "parser.lemon" +{ + yygotominor.yy132 = yymsp[0].minor.yy132; + yy_destructor(39,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getLimit){ - - zval *params, *conditions; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("limit"), 192268420UL)) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_quick_string(&conditions, params, SS("limit"), 192268420UL, PH_NOISY); - RETURN_CCTOR(conditions); - } - - RETURN_MM_NULL(); +// 2005 "parser.c" + break; + case 59: +// 789 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_insert_statement(yymsp[-4].minor.yy132, NULL, yymsp[-1].minor.yy132); + yy_destructor(40,&yymsp[-6].minor); + yy_destructor(41,&yymsp[-5].minor); + yy_destructor(42,&yymsp[-3].minor); + yy_destructor(43,&yymsp[-2].minor); + yy_destructor(44,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getOrder){ - - zval *params, *conditions; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_params"), 3223731112UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(params, SS("order"), 320020033UL)) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_quick_string(&conditions, params, SS("order"), 320020033UL, PH_NOISY); - RETURN_CCTOR(conditions); - } - - RETURN_MM_NULL(); +// 2017 "parser.c" + break; + case 60: +// 793 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_insert_statement(yymsp[-7].minor.yy132, yymsp[-5].minor.yy132, yymsp[-1].minor.yy132); + yy_destructor(40,&yymsp[-9].minor); + yy_destructor(41,&yymsp[-8].minor); + yy_destructor(43,&yymsp[-6].minor); + yy_destructor(44,&yymsp[-4].minor); + yy_destructor(42,&yymsp[-3].minor); + yy_destructor(43,&yymsp[-2].minor); + yy_destructor(44,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, getParams){ - - - RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); +// 2031 "parser.c" + break; + case 67: +// 831 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_update_statement(yymsp[0].minor.yy132, NULL, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, fromInput){ - - zval *dependency_injector, *model_name, *data; - zval *conditions, *service, *meta_data, *model; - zval *data_types, *bind, *value = NULL, *field = NULL, *type = NULL, *condition = NULL; - zval *value_pattern = NULL, *join_conditions; - HashTable *ah0; - HashPosition hp0; - zval **hd; - zend_class_entry *ce0; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &dependency_injector, &model_name, &data); - - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Input data must be an Array"); - return; - } - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the ORM services"); - return; - } - - PHALCON_INIT_VAR(conditions); - array_init(conditions); - if (phalcon_fast_count_ev(data TSRMLS_CC)) { - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "modelsMetadata", 1); - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_p1_key(meta_data, dependency_injector, "getshared", service, 1727570332UL); - ce0 = phalcon_fetch_class(model_name TSRMLS_CC); - - PHALCON_INIT_VAR(model); - object_init_ex(model, ce0); - if (phalcon_has_constructor(model TSRMLS_CC)) { - phalcon_call_method_key(NULL, model, "__construct", 1107214344UL); - } - - PHALCON_INIT_VAR(data_types); - phalcon_call_method_p1_key(data_types, meta_data, "getdatatypes", model, 562971380UL); - - PHALCON_INIT_VAR(bind); - array_init(bind); - - phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(field, ah0, hp0); - PHALCON_GET_HVALUE(value); - - if (phalcon_array_isset(data_types, field)) { - if (Z_TYPE_P(value) != IS_NULL) { - if (!PHALCON_IS_STRING(value, "")) { - - PHALCON_OBS_NVAR(type); - phalcon_array_fetch(&type, data_types, field, PH_NOISY); - if (PHALCON_IS_LONG(type, 2)) { - PHALCON_INIT_NVAR(condition); - PHALCON_CONCAT_VSVS(condition, field, " LIKE :", field, ":"); - - PHALCON_INIT_NVAR(value_pattern); - PHALCON_CONCAT_SVS(value_pattern, "%", value, "%"); - phalcon_array_update_zval(&bind, field, &value_pattern, PH_COPY | PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(condition); - PHALCON_CONCAT_VSVS(condition, field, "=:", field, ":"); - phalcon_array_update_zval(&bind, field, &value, PH_COPY | PH_SEPARATE); - } - - phalcon_array_append(&conditions, condition, PH_SEPARATE); - } - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - object_init_ex(return_value, phalcon_mvc_model_criteria_ce); - if (phalcon_fast_count_ev(conditions TSRMLS_CC)) { - PHALCON_INIT_VAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - phalcon_call_method_p1_key(NULL, return_value, "where", join_conditions, 621293632UL); - phalcon_call_method_p1_key(NULL, return_value, "bind", bind, 254268962UL); - } - - phalcon_call_method_p1_key(NULL, return_value, "setmodelname", model_name, 3112384035UL); - RETURN_MM(); +// 2038 "parser.c" + break; + case 68: +// 835 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_update_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_Criteria, execute){ - - zval *model, *params, *resultset; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(model); - phalcon_read_property_this_quick(&model, this_ptr, SL("_model"), 2599397109UL, PH_NOISY_CC); - if (Z_TYPE_P(model) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Model name must be string"); - return; - } - - PHALCON_INIT_VAR(params); - phalcon_call_method_key(params, this_ptr, "getparams", 1893744905UL); - - PHALCON_INIT_VAR(resultset); - phalcon_call_zval_str_static_p1(resultset, model, "find", params); - - RETURN_CCTOR(resultset); +// 2045 "parser.c" + break; + case 69: +// 839 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_update_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, MetaData, mvc_model_metadata, phalcon_mvc_model_metadata_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - zend_declare_property_null(phalcon_mvc_model_metadata_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_metadata_ce, SL("_strategy"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_metadata_ce, SL("_metaData"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_metadata_ce, SL("_columnMap"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_ATTRIBUTES"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_PRIMARY_KEY"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_NON_PRIMARY_KEY"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_NOT_NULL"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_DATA_TYPES"), 4 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_DATA_TYPES_NUMERIC"), 5 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_DATE_AT"), 6 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_DATE_IN"), 7 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_IDENTITY_COLUMN"), 8 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_DATA_TYPES_BIND"), 9 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_AUTOMATIC_DEFAULT_INSERT"), 10 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_AUTOMATIC_DEFAULT_UPDATE"), 11 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_COLUMN_MAP"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_metadata_ce, SL("MODELS_REVERSE_COLUMN_MAP"), 1 TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_metadata_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); - - return SUCCESS; +// 2052 "parser.c" + break; + case 70: +// 843 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_update_statement(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, _initialize){ - - zval *model, *key, *table, *schema, *strategy = NULL, *class_name; - zval *meta_data = NULL, *prefix_key = NULL, *data = NULL, *model_metadata = NULL; - zval *exception_message, *dependency_injector = NULL; - zval *key_name, *column_map = NULL, *model_column_map; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 4, 0, &model, &key, &table, &schema); - - PHALCON_INIT_VAR(strategy); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, model, 0 TSRMLS_CC); - if (Z_TYPE_P(key) != IS_NULL) { - - PHALCON_OBS_VAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - if (!phalcon_array_isset(meta_data, key)) { - - PHALCON_INIT_VAR(prefix_key); - PHALCON_CONCAT_SV(prefix_key, "meta-", key); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p1_key(data, this_ptr, "read", prefix_key, 273085793UL); - if (Z_TYPE_P(data) != IS_NULL) { - if (Z_TYPE_P(meta_data) != IS_ARRAY) { - PHALCON_INIT_NVAR(meta_data); - array_init(meta_data); - } - phalcon_array_update_zval(&meta_data, key, &data, PH_COPY | PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), meta_data, 1295805989UL TSRMLS_CC); - } else { - if (phalcon_method_quick_exists_ex(model, SS("metadata"), 2348961382UL TSRMLS_CC) == SUCCESS) { - - PHALCON_INIT_VAR(model_metadata); - phalcon_call_method_key(model_metadata, model, "metadata", 2348961382UL); - if (Z_TYPE_P(model_metadata) != IS_ARRAY) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Invalid meta-data for model ", class_name); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - - phalcon_call_method_key(strategy, this_ptr, "getstrategy", 281381624UL); - - PHALCON_INIT_NVAR(model_metadata); - phalcon_call_method_p2_key(model_metadata, strategy, "getmetadata", model, dependency_injector, 382754790UL); - } - - phalcon_update_property_array(this_ptr, SL("_metaData"), key, model_metadata TSRMLS_CC); - - phalcon_call_method_p2_key(NULL, this_ptr, "write", prefix_key, model_metadata, 633298768UL); - } - } - } - - if (!PHALCON_GLOBAL(orm).column_renaming) { - RETURN_MM_NULL(); - } - - PHALCON_INIT_VAR(key_name); - phalcon_fast_strtolower(key_name, class_name); - - PHALCON_OBS_VAR(column_map); - phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); - if (phalcon_array_isset(column_map, key_name)) { - RETURN_MM_NULL(); - } - - if (Z_TYPE_P(column_map) != IS_ARRAY) { - PHALCON_INIT_NVAR(column_map); - array_init(column_map); - } - - PHALCON_INIT_NVAR(prefix_key); - PHALCON_CONCAT_SV(prefix_key, "map-", key_name); - - PHALCON_INIT_NVAR(data); - phalcon_call_method_p1_key(data, this_ptr, "read", prefix_key, 273085793UL); - if (Z_TYPE_P(data) != IS_NULL) { - phalcon_array_update_zval(&column_map, key_name, &data, PH_COPY | PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_columnMap"), column_map, 1530164624UL TSRMLS_CC); - RETURN_MM_NULL(); - } - - if (Z_TYPE_P(strategy) != IS_OBJECT) { - PHALCON_OBS_NVAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(strategy); - phalcon_call_method_key(strategy, this_ptr, "getstrategy", 281381624UL); - } - - PHALCON_INIT_VAR(model_column_map); - phalcon_call_method_p2_key(model_column_map, strategy, "getcolumnmaps", model, dependency_injector, 2736133220UL); - - phalcon_update_property_array(this_ptr, SL("_columnMap"), key_name, model_column_map TSRMLS_CC); - - phalcon_call_method_p2_key(NULL, this_ptr, "write", prefix_key, model_column_map, 633298768UL); - - PHALCON_MM_RESTORE(); +// 2059 "parser.c" + break; + case 71: +// 849 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_update_clause(yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(45,&yymsp[-3].minor); + yy_destructor(46,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - +// 2068 "parser.c" + break; + case 74: +// 865 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_update_item(yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(3,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +// 2076 "parser.c" + break; + case 76: +// 877 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_delete_statement(yymsp[0].minor.yy132, NULL, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, setStrategy){ - - zval *strategy; - - phalcon_fetch_params(0, 1, 0, &strategy); - - if (Z_TYPE_P(strategy) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The meta-data extraction strategy is not valid"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_strategy"), strategy, 1232382295UL TSRMLS_CC); - +// 2083 "parser.c" + break; + case 77: +// 881 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_delete_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getStrategy){ - - zval *strategy = NULL; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(strategy); - phalcon_read_property_this_quick(&strategy, this_ptr, SL("_strategy"), 1232382295UL, PH_NOISY_CC); - if (Z_TYPE_P(strategy) == IS_NULL) { - PHALCON_INIT_NVAR(strategy); - object_init_ex(strategy, phalcon_mvc_model_metadata_strategy_introspection_ce); - phalcon_update_property_this_quick(this_ptr, SL("_strategy"), strategy, 1232382295UL TSRMLS_CC); - } - - RETURN_CCTOR(strategy); +// 2090 "parser.c" + break; + case 78: +// 885 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_delete_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, readMetaData){ - - zval *model, *table, *schema, *class_name, *key, *meta_data = NULL; - zval *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - if (Z_TYPE_P(model) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A model instance is required to retrieve the meta-data"); - return; - } - - PHALCON_INIT_VAR(table); - phalcon_call_method_key(table, model, "getsource", 2025234358UL); - - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, model, 1 TSRMLS_CC); - - PHALCON_INIT_VAR(key); - PHALCON_CONCAT_VSVV(key, class_name, "-", schema, table); - - PHALCON_OBS_VAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - if (!phalcon_array_isset(meta_data, key)) { - phalcon_call_method_p4_key(NULL, this_ptr, "_initialize", model, key, table, schema, 1143422230UL); - - PHALCON_OBS_NVAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - } - - PHALCON_OBS_VAR(data); - phalcon_array_fetch(&data, meta_data, key, PH_NOISY); - - RETURN_CCTOR(data); +// 2097 "parser.c" + break; + case 79: +// 889 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_delete_statement(yymsp[-2].minor.yy132, yymsp[-1].minor.yy132, yymsp[0].minor.yy132); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, readMetaDataIndex){ - - zval *model, *index, *table, *schema, *class_name; - zval *key, *meta_data = NULL, *meta_data_index, *attributes; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &index); - - if (Z_TYPE_P(model) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A model instance is required to retrieve the meta-data"); - return; - } - if (Z_TYPE_P(index) != IS_LONG) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Index must be a valid integer constant"); - return; - } - - PHALCON_INIT_VAR(table); - phalcon_call_method_key(table, model, "getsource", 2025234358UL); - - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, model, 1 TSRMLS_CC); - - PHALCON_INIT_VAR(key); - PHALCON_CONCAT_VSVV(key, class_name, "-", schema, table); - - PHALCON_OBS_VAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - if (!phalcon_array_isset(meta_data, key)) { - phalcon_call_method_p4_key(NULL, this_ptr, "_initialize", model, key, table, schema, 1143422230UL); - - PHALCON_OBS_NVAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - } - - PHALCON_OBS_VAR(meta_data_index); - phalcon_array_fetch(&meta_data_index, meta_data, key, PH_NOISY); - - PHALCON_OBS_VAR(attributes); - phalcon_array_fetch(&attributes, meta_data_index, index, PH_NOISY); - - RETURN_CCTOR(attributes); +// 2104 "parser.c" + break; + case 80: +// 895 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_delete_clause(yymsp[0].minor.yy132); + yy_destructor(47,&yymsp[-2].minor); + yy_destructor(27,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, writeMetaDataIndex){ - - zval *model, *index, *data, *table, *schema, *class_name; - zval *key, *meta_data = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &model, &index, &data); - - if (Z_TYPE_P(model) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A model instance is required to retrieve the meta-data"); - return; - } - if (Z_TYPE_P(index) != IS_LONG) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Index must be a valid integer constant"); - return; - } - - if (Z_TYPE_P(data) != IS_ARRAY) { - if (Z_TYPE_P(data) != IS_STRING) { - if (Z_TYPE_P(data) != IS_BOOL) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid data for index"); - return; - } - } - } - - PHALCON_INIT_VAR(table); - phalcon_call_method_key(table, model, "getsource", 2025234358UL); - - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, model, 1 TSRMLS_CC); - - PHALCON_INIT_VAR(key); - PHALCON_CONCAT_VSVV(key, class_name, "-", schema, table); - - PHALCON_OBS_VAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - if (!phalcon_array_isset(meta_data, key)) { - phalcon_call_method_p4_key(NULL, this_ptr, "_initialize", model, key, table, schema, 1143422230UL); - - PHALCON_OBS_NVAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - } - - phalcon_array_update_multi_2(&meta_data, key, index, &data, 0); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), meta_data, 1295805989UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); +// 2113 "parser.c" + break; + case 81: +// 901 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_assoc_name(yymsp[-2].minor.yy132, yymsp[0].minor.yy0); + yy_destructor(31,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, readColumnMap){ - - zval *model, *key_name, *column_map = NULL, *null_value; - zval *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - if (Z_TYPE_P(model) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A model instance is required to retrieve the meta-data"); - return; - } - - PHALCON_INIT_VAR(key_name); - phalcon_get_class(key_name, model, 1 TSRMLS_CC); - - PHALCON_OBS_VAR(column_map); - phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); - if (!phalcon_array_isset(column_map, key_name)) { - PHALCON_INIT_VAR(null_value); - phalcon_call_method_p4_key(NULL, this_ptr, "_initialize", model, null_value, null_value, null_value, 1143422230UL); - - PHALCON_OBS_NVAR(column_map); - phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); - } - - PHALCON_OBS_VAR(data); - phalcon_array_fetch(&data, column_map, key_name, PH_NOISY); - - RETURN_CCTOR(data); +// 2121 "parser.c" + break; + case 82: +// 905 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_assoc_name(yymsp[-1].minor.yy132, yymsp[0].minor.yy0); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, readColumnMapIndex){ - - zval *model, *index, *key_name, *column_map = NULL, *null_value; - zval *column_map_model, *attributes; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &index); - - if (Z_TYPE_P(model) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A model instance is required to retrieve the meta-data"); - return; - } - if (Z_TYPE_P(index) != IS_LONG) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Index must be a valid integer constant"); - return; - } - - PHALCON_INIT_VAR(key_name); - phalcon_get_class(key_name, model, 1 TSRMLS_CC); - - PHALCON_OBS_VAR(column_map); - phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); - if (!phalcon_array_isset(column_map, key_name)) { - PHALCON_INIT_VAR(null_value); - phalcon_call_method_p4_key(NULL, this_ptr, "_initialize", model, null_value, null_value, null_value, 1143422230UL); - - PHALCON_OBS_NVAR(column_map); - phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); - } - - PHALCON_OBS_VAR(column_map_model); - phalcon_array_fetch(&column_map_model, column_map, key_name, PH_NOISY); - - PHALCON_OBS_VAR(attributes); - phalcon_array_fetch(&attributes, column_map_model, index, PH_NOISY); - - RETURN_CCTOR(attributes); +// 2128 "parser.c" + break; + case 83: +// 909 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_assoc_name(yymsp[0].minor.yy132, NULL); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getAttributes){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 0); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readmetadataindex", model, index, 3936023514UL); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupted"); - return; - } - - RETURN_CCTOR(data); +// 2135 "parser.c" + break; + case 85: +// 921 "parser.lemon" +{ + yygotominor.yy132 = yymsp[0].minor.yy132; + yy_destructor(48,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getPrimaryKeyAttributes){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 1); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readmetadataindex", model, index, 3936023514UL); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupt"); - return; - } - - RETURN_CCTOR(data); +// 2143 "parser.c" + break; + case 86: +// 927 "parser.lemon" +{ + yygotominor.yy132 = yymsp[0].minor.yy132; + yy_destructor(49,&yymsp[-2].minor); + yy_destructor(50,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getNonPrimaryKeyAttributes){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 2); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readmetadataindex", model, index, 3936023514UL); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupt"); - return; - } - - RETURN_CCTOR(data); +// 2152 "parser.c" + break; + case 89: +// 943 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_order_item(yymsp[0].minor.yy132, 0); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getNotNullAttributes){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 3); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readmetadataindex", model, index, 3936023514UL); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupt"); - return; - } - - RETURN_CCTOR(data); +// 2159 "parser.c" + break; + case 90: +// 947 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_order_item(yymsp[-1].minor.yy132, PHQL_T_ASC); + yy_destructor(51,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getDataTypes){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 4); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readmetadataindex", model, index, 3936023514UL); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupt"); - return; - } - - RETURN_CCTOR(data); +// 2167 "parser.c" + break; + case 91: +// 951 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_order_item(yymsp[-1].minor.yy132, PHQL_T_DESC); + yy_destructor(52,&yymsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getDataTypesNumeric){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 5); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readmetadataindex", model, index, 3936023514UL); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupt"); - return; - } - - RETURN_CCTOR(data); +// 2175 "parser.c" + break; + case 92: +// 957 "parser.lemon" +{ + yygotominor.yy132 = yymsp[0].minor.yy132; + yy_destructor(53,&yymsp[-2].minor); + yy_destructor(50,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getIdentityField){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 8); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readmetadataindex", model, index, 3936023514UL); - RETURN_CCTOR(data); +// 2184 "parser.c" + break; + case 96: +// 979 "parser.lemon" +{ + yygotominor.yy132 = yymsp[0].minor.yy132; + yy_destructor(54,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getBindTypes){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 9); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readmetadataindex", model, index, 3936023514UL); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupt"); - return; - } - - RETURN_CCTOR(data); +// 2192 "parser.c" + break; + case 97: + case 100: +// 985 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_limit_clause(yymsp[0].minor.yy0, NULL); + yy_destructor(55,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getAutomaticCreateAttributes){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 10); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readmetadataindex", model, index, 3936023514UL); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupt"); - return; - } - - RETURN_CCTOR(data); +// 2201 "parser.c" + break; + case 98: +// 989 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_limit_clause(yymsp[0].minor.yy0, yymsp[-2].minor.yy0); + yy_destructor(55,&yymsp[-3].minor); + yy_destructor(28,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getAutomaticUpdateAttributes){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 11); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readmetadataindex", model, index, 3936023514UL); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupt"); - return; - } - - RETURN_CCTOR(data); +// 2210 "parser.c" + break; + case 99: +// 993 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_limit_clause(yymsp[-2].minor.yy0, yymsp[0].minor.yy0); + yy_destructor(55,&yymsp[-3].minor); + yy_destructor(57,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, setAutomaticCreateAttributes){ - - zval *model, *attributes, *create_index; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &attributes); - - PHALCON_INIT_VAR(create_index); - ZVAL_LONG(create_index, 10); - phalcon_call_method_p3_key(NULL, this_ptr, "writemetadataindex", model, create_index, attributes, 3417033257UL); - - PHALCON_MM_RESTORE(); +// 2219 "parser.c" + break; + case 101: +// 1005 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_MINUS, NULL, yymsp[0].minor.yy132); + yy_destructor(20,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, setAutomaticUpdateAttributes){ - - zval *model, *attributes, *create_index; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &attributes); - - PHALCON_INIT_VAR(create_index); - ZVAL_LONG(create_index, 11); - phalcon_call_method_p3_key(NULL, this_ptr, "writemetadataindex", model, create_index, attributes, 3417033257UL); - - PHALCON_MM_RESTORE(); +// 2227 "parser.c" + break; + case 102: +// 1009 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_SUB, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(20,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getColumnMap){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 0); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readcolumnmapindex", model, index, 1258492357UL); - if (Z_TYPE_P(data) != IS_NULL) { - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupt"); - return; - } - } - - RETURN_CCTOR(data); +// 2235 "parser.c" + break; + case 103: +// 1013 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_ADD, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(19,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getReverseColumnMap){ - - zval *model, *index, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(index); - ZVAL_LONG(index, 1); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p2_key(data, this_ptr, "readcolumnmapindex", model, index, 1258492357UL); - if (Z_TYPE_P(data) != IS_NULL) { - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The meta-data is invalid or is corrupt"); - return; - } - } - - RETURN_CCTOR(data); +// 2243 "parser.c" + break; + case 104: +// 1017 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_MUL, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(17,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, hasAttribute){ - - zval *model, *attribute, *column_map, *meta_data; - zval *data_types; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &attribute); - - if (Z_TYPE_P(attribute) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Attribute must be a string"); - return; - } - - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, this_ptr, "getreversecolumnmap", model, 817005101UL); - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, attribute)) { - RETURN_MM_TRUE; - } - } else { - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_p1_key(meta_data, this_ptr, "readmetadata", model, 3413674530UL); - - PHALCON_OBS_VAR(data_types); - phalcon_array_fetch_long(&data_types, meta_data, 4, PH_NOISY); - if (phalcon_array_isset(data_types, attribute)) { - RETURN_MM_TRUE; - } - } - - RETURN_MM_FALSE; +// 2251 "parser.c" + break; + case 105: +// 1021 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_DIV, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(16,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, isEmpty){ - - zval *meta_data; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - if (phalcon_fast_count_ev(meta_data TSRMLS_CC)) { - RETURN_MM_FALSE; - } - - RETURN_MM_TRUE; +// 2259 "parser.c" + break; + case 106: +// 1025 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_MOD, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(18,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, reset){ - - zval *empty_array; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_columnMap"), empty_array, 1530164624UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); +// 2267 "parser.c" + break; + case 107: +// 1029 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_AND, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(9,&yymsp[-1].minor); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Resultset_Complex){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Resultset, Complex, mvc_model_resultset_complex, "phalcon\\mvc\\model\\resultset", phalcon_mvc_model_resultset_complex_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_model_resultset_complex_ce, SL("_columnTypes"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_resultset_complex_ce TSRMLS_CC, 1, phalcon_mvc_model_resultsetinterface_ce); - - return SUCCESS; +// 2275 "parser.c" + break; + case 108: +// 1033 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_OR, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(10,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, __construct){ - - zval *columns_types, *result, *cache = NULL, *fetch_assoc; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &columns_types, &result, &cache); - - if (!cache) { - PHALCON_INIT_VAR(cache); - } - - phalcon_update_property_this_quick(this_ptr, SL("_columnTypes"), columns_types, 204488327UL TSRMLS_CC); - - phalcon_update_property_this_quick(this_ptr, SL("_result"), result, 1670144931UL TSRMLS_CC); - - if (Z_TYPE_P(cache) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); - } - - phalcon_update_property_long(this_ptr, SL("_type"), 1 TSRMLS_CC); - - if (Z_TYPE_P(result) == IS_OBJECT) { - PHALCON_INIT_VAR(fetch_assoc); - ZVAL_LONG(fetch_assoc, 1); - phalcon_call_method_p1_key(NULL, result, "setfetchmode", fetch_assoc, 824603840UL); - } - - PHALCON_MM_RESTORE(); +// 2283 "parser.c" + break; + case 109: +// 1037 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_BITWISE_AND, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(13,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, valid){ - - zval *type = NULL, *result, *row = NULL, *rows, *hydrate_mode, *underscore; - zval *empty_str, *active_row = NULL, *columns_types; - zval *dirty_state, *column = NULL, *alias = NULL, *source = NULL, *attributes = NULL; - zval *column_map = NULL, *row_model = NULL, *attribute = NULL, *column_alias = NULL; - zval *column_value = NULL, *keep_snapshots = NULL, *instance = NULL; - zval *value = NULL, *sql_alias = NULL, *n_alias = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(type); - phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); - if (zend_is_true(type)) { - - PHALCON_OBS_VAR(result); - phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); - if (PHALCON_IS_NOT_FALSE(result)) { - PHALCON_INIT_VAR(row); - phalcon_call_method_p1_key(row, result, "fetch", result, 4247924303UL); - } else { - PHALCON_INIT_NVAR(row); - ZVAL_BOOL(row, 0); - } - } else { - PHALCON_OBS_VAR(rows); - phalcon_read_property_this_quick(&rows, this_ptr, SL("_rows"), 3989235983UL, PH_NOISY_CC); - if (Z_TYPE_P(rows) == IS_ARRAY) { - - PHALCON_INIT_NVAR(row); - phalcon_array_get_current(row, rows); - if (Z_TYPE_P(row) == IS_OBJECT) { - phalcon_array_next(rows); - } - } else { - PHALCON_INIT_NVAR(row); - ZVAL_BOOL(row, 0); - } - } - - if (Z_TYPE_P(row) == IS_ARRAY || Z_TYPE_P(row) == IS_OBJECT) { - - if (zend_is_true(type)) { - - PHALCON_OBS_VAR(hydrate_mode); - phalcon_read_property_this_quick(&hydrate_mode, this_ptr, SL("_hydrateMode"), 2551752186UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(underscore); - ZVAL_STRING(underscore, "_", 1); - - PHALCON_INIT_VAR(empty_str); - ZVAL_STRING(empty_str, "", 1); - - - switch (phalcon_get_intval(hydrate_mode)) { - - case 0: - PHALCON_INIT_VAR(active_row); - object_init_ex(active_row, phalcon_mvc_model_row_ce); - break; - - case 1: - PHALCON_INIT_NVAR(active_row); - array_init(active_row); - break; - - case 2: - PHALCON_INIT_NVAR(active_row); - object_init(active_row); - break; - - } - - PHALCON_OBS_VAR(columns_types); - phalcon_read_property_this_quick(&columns_types, this_ptr, SL("_columnTypes"), 204488327UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(dirty_state); - ZVAL_LONG(dirty_state, 0); - - phalcon_is_iterable(columns_types, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(alias, ah0, hp0); - PHALCON_GET_HVALUE(column); - - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, column, SS("type"), 276192743UL, PH_NOISY); - if (PHALCON_IS_STRING(type, "object")) { - - PHALCON_OBS_NVAR(source); - phalcon_array_fetch_quick_string(&source, column, SS("column"), 3545634419UL, PH_NOISY); - - PHALCON_OBS_NVAR(attributes); - phalcon_array_fetch_quick_string(&attributes, column, SS("attributes"), 3318431052UL, PH_NOISY); - - PHALCON_OBS_NVAR(column_map); - phalcon_array_fetch_quick_string(&column_map, column, SS("columnMap"), 672221649UL, PH_NOISY); - - PHALCON_INIT_NVAR(row_model); - array_init(row_model); - - phalcon_is_iterable(attributes, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(attribute); - - PHALCON_INIT_NVAR(column_alias); - PHALCON_CONCAT_VVVV(column_alias, underscore, source, underscore, attribute); - - PHALCON_OBS_NVAR(column_value); - phalcon_array_fetch(&column_value, row, column_alias, PH_NOISY); - phalcon_array_update_zval(&row_model, attribute, &column_value, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - - switch (phalcon_get_intval(hydrate_mode)) { - - case 0: - if (phalcon_array_isset_quick_string(column, SS("keepSnapshots"), 1820056717UL)) { - PHALCON_OBS_NVAR(keep_snapshots); - phalcon_array_fetch_quick_string(&keep_snapshots, column, SS("keepSnapshots"), 1820056717UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(keep_snapshots); - ZVAL_BOOL(keep_snapshots, 0); - } - - PHALCON_OBS_NVAR(instance); - phalcon_array_fetch_quick_string(&instance, column, SS("instance"), 3884539162UL, PH_NOISY); - - PHALCON_INIT_NVAR(value); - PHALCON_CALL_STATIC_PARAMS_5(value, "phalcon\\mvc\\model", "cloneresultmap", instance, row_model, column_map, dirty_state, keep_snapshots); - break; - - default: - PHALCON_INIT_NVAR(value); - PHALCON_CALL_STATIC_PARAMS_3(value, "phalcon\\mvc\\model", "cloneresultmaphydrate", row_model, column_map, hydrate_mode); - break; - - } - - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_quick_string(&attribute, column, SS("balias"), 1705826801UL, PH_NOISY); - } else { - if (phalcon_array_isset_quick_string(column, SS("sqlAlias"), 2820722015UL)) { - PHALCON_OBS_NVAR(sql_alias); - phalcon_array_fetch_quick_string(&sql_alias, column, SS("sqlAlias"), 2820722015UL, PH_NOISY); - - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, row, sql_alias, PH_NOISY); - } else { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, row, alias, PH_NOISY); - } - - if (phalcon_array_isset_quick_string(column, SS("balias"), 1705826801UL)) { - PHALCON_CPY_WRT(attribute, alias); - } else { - PHALCON_INIT_NVAR(n_alias); - phalcon_fast_str_replace(n_alias, underscore, empty_str, alias); - PHALCON_CPY_WRT(attribute, n_alias); - } - } - - - switch (phalcon_get_intval(hydrate_mode)) { - - case 1: - phalcon_array_update_zval(&active_row, attribute, &value, PH_COPY | PH_SEPARATE); - break; - - default: - phalcon_update_property_zval_zval(active_row, attribute, value TSRMLS_CC); - break; - - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - phalcon_update_property_this_quick(this_ptr, SL("_activeRow"), active_row, 3086770360UL TSRMLS_CC); - } else { - phalcon_update_property_this_quick(this_ptr, SL("_activeRow"), row, 3086770360UL TSRMLS_CC); - } - RETURN_MM_TRUE; - } - - phalcon_update_property_bool(this_ptr, SL("_activeRow"), 0 TSRMLS_CC); - RETURN_MM_FALSE; +// 2291 "parser.c" + break; + case 110: +// 1041 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_BITWISE_OR, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(14,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, toArray){ - - zval *records, *valid = NULL, *current = NULL; - zval *r0 = NULL; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(records); - array_init(records); - phalcon_call_method_key(NULL, this_ptr, "rewind", 1064078190UL); - - while (1) { - - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, this_ptr, "valid", 574098517UL); - PHALCON_CPY_WRT(valid, r0); - if (PHALCON_IS_NOT_FALSE(valid)) { - } else { - break; - } - - PHALCON_INIT_NVAR(current); - phalcon_call_method_key(current, this_ptr, "current", 431662984UL); - phalcon_array_append(&records, current, PH_SEPARATE); - phalcon_call_method_key(NULL, this_ptr, "next", 268367684UL); - } - - RETURN_CTOR(records); +// 2299 "parser.c" + break; + case 111: +// 1045 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_BITWISE_XOR, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(15,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, serialize){ - - zval *records, *cache, *column_types, *hydrate_mode; - zval *data, *serialized; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(records); - phalcon_call_method_key(records, this_ptr, "toarray", 3566966151UL); - - PHALCON_OBS_VAR(cache); - phalcon_read_property_this_quick(&cache, this_ptr, SL("_cache"), 2191407384UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(column_types); - phalcon_read_property_this_quick(&column_types, this_ptr, SL("_columnTypes"), 204488327UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(hydrate_mode); - phalcon_read_property_this_quick(&hydrate_mode, this_ptr, SL("_hydrateMode"), 2551752186UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(data); - array_init_size(data, 4); - phalcon_array_update_quick_string(&data, SS("cache"), 4125168857UL, &cache, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("rows"), 273469616UL, &records, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("columnTypes"), 2207459080UL, &column_types, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("hydrateMode"), 259755643UL, &hydrate_mode, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(serialized); - phalcon_serialize(serialized, &data TSRMLS_CC); - - if (Z_TYPE_P(serialized) != IS_STRING) { - RETURN_MM_NULL(); - } - - RETURN_CTOR(serialized); +// 2307 "parser.c" + break; + case 112: +// 1049 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_EQUALS, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(3,&yymsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, unserialize){ - - zval *data, *resultset, *rows, *cache, *column_types; - zval *hydrate_mode; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &data); - - phalcon_update_property_long(this_ptr, SL("_type"), 0 TSRMLS_CC); - - PHALCON_INIT_VAR(resultset); - phalcon_unserialize(resultset, data TSRMLS_CC); - if (Z_TYPE_P(resultset) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid serialization data"); - return; - } - - PHALCON_OBS_VAR(rows); - phalcon_array_fetch_quick_string(&rows, resultset, SS("rows"), 273469616UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_rows"), rows, 3989235983UL TSRMLS_CC); - - PHALCON_OBS_VAR(cache); - phalcon_array_fetch_quick_string(&cache, resultset, SS("cache"), 4125168857UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); - - PHALCON_OBS_VAR(column_types); - phalcon_array_fetch_quick_string(&column_types, resultset, SS("columnTypes"), 2207459080UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_columnTypes"), column_types, 204488327UL TSRMLS_CC); - - PHALCON_OBS_VAR(hydrate_mode); - phalcon_array_fetch_quick_string(&hydrate_mode, resultset, SS("hydrateMode"), 259755643UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_hydrateMode"), hydrate_mode, 2551752186UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); +// 2315 "parser.c" + break; + case 113: +// 1053 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_NOTEQUALS, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(4,&yymsp[-1].minor); +} +// 2323 "parser.c" + break; + case 114: +// 1057 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_LESS, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(5,&yymsp[-1].minor); +} +// 2331 "parser.c" + break; + case 115: +// 1061 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_GREATER, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(6,&yymsp[-1].minor); +} +// 2339 "parser.c" + break; + case 116: +// 1065 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_GREATEREQUAL, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(7,&yymsp[-1].minor); +} +// 2347 "parser.c" + break; + case 117: +// 1069 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_LESSEQUAL, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(8,&yymsp[-1].minor); +} +// 2355 "parser.c" + break; + case 118: +// 1073 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_LIKE, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(11,&yymsp[-1].minor); +} +// 2363 "parser.c" + break; + case 119: +// 1077 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_NLIKE, yymsp[-3].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(24,&yymsp[-2].minor); + yy_destructor(11,&yymsp[-1].minor); +} +// 2372 "parser.c" + break; + case 120: +// 1081 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_ILIKE, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(12,&yymsp[-1].minor); +} +// 2380 "parser.c" + break; + case 121: +// 1085 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_NILIKE, yymsp[-3].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(24,&yymsp[-2].minor); + yy_destructor(12,&yymsp[-1].minor); +} +// 2389 "parser.c" + break; + case 122: +// 1089 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_IN, yymsp[-4].minor.yy132, yymsp[-1].minor.yy132); + yy_destructor(22,&yymsp[-3].minor); + yy_destructor(43,&yymsp[-2].minor); + yy_destructor(44,&yymsp[0].minor); +} +// 2399 "parser.c" + break; + case 123: +// 1093 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_NOTIN, yymsp[-5].minor.yy132, yymsp[-1].minor.yy132); + yy_destructor(24,&yymsp[-4].minor); + yy_destructor(22,&yymsp[-3].minor); + yy_destructor(43,&yymsp[-2].minor); + yy_destructor(44,&yymsp[0].minor); +} +// 2410 "parser.c" + break; + case 124: +// 1097 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_AGAINST, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(1,&yymsp[-1].minor); +} +// 2418 "parser.c" + break; + case 125: +// 1101 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_CAST, yymsp[-3].minor.yy132, phql_ret_raw_qualified_name(yymsp[-1].minor.yy0, NULL)); + yy_destructor(58,&yymsp[-5].minor); + yy_destructor(43,&yymsp[-4].minor); + yy_destructor(31,&yymsp[-2].minor); + yy_destructor(44,&yymsp[0].minor); +} +// 2429 "parser.c" + break; + case 126: +// 1105 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_CONVERT, yymsp[-3].minor.yy132, phql_ret_raw_qualified_name(yymsp[-1].minor.yy0, NULL)); + yy_destructor(59,&yymsp[-5].minor); + yy_destructor(43,&yymsp[-4].minor); + yy_destructor(60,&yymsp[-2].minor); + yy_destructor(44,&yymsp[0].minor); +} +// 2440 "parser.c" + break; + case 128: +// 1115 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_func_call(yymsp[-3].minor.yy0, yymsp[-1].minor.yy132); + yy_destructor(43,&yymsp[-2].minor); + yy_destructor(44,&yymsp[0].minor); +} +// 2449 "parser.c" + break; + case 129: +// 1119 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_func_call(yymsp[-2].minor.yy0, NULL); + yy_destructor(43,&yymsp[-1].minor); + yy_destructor(44,&yymsp[0].minor); +} +// 2458 "parser.c" + break; + case 131: +// 1129 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_zval_list(yymsp[0].minor.yy132, NULL); +} +// 2465 "parser.c" + break; + case 134: +// 1143 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_ISNULL, yymsp[-2].minor.yy132, NULL); + yy_destructor(21,&yymsp[-1].minor); + yy_destructor(61,&yymsp[0].minor); +} +// 2474 "parser.c" + break; + case 135: +// 1147 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_ISNOTNULL, yymsp[-3].minor.yy132, NULL); + yy_destructor(21,&yymsp[-2].minor); + yy_destructor(24,&yymsp[-1].minor); + yy_destructor(61,&yymsp[0].minor); +} +// 2484 "parser.c" + break; + case 136: +// 1151 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_DISTINCT, NULL, yymsp[0].minor.yy132); + yy_destructor(23,&yymsp[-1].minor); +} +// 2492 "parser.c" + break; + case 137: +// 1155 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_BETWEEN, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(2,&yymsp[-1].minor); +} +// 2500 "parser.c" + break; + case 138: +// 1159 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_NOT, NULL, yymsp[0].minor.yy132); + yy_destructor(24,&yymsp[-1].minor); +} +// 2508 "parser.c" + break; + case 139: +// 1163 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_BITWISE_NOT, NULL, yymsp[0].minor.yy132); + yy_destructor(25,&yymsp[-1].minor); +} +// 2516 "parser.c" + break; + case 140: +// 1167 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_expr(PHQL_T_ENCLOSED, yymsp[-1].minor.yy132, NULL); + yy_destructor(43,&yymsp[-2].minor); + yy_destructor(44,&yymsp[0].minor); +} +// 2525 "parser.c" + break; + case 142: +// 1175 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_INTEGER, yymsp[0].minor.yy0); +} +// 2532 "parser.c" + break; + case 143: +// 1179 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_STRING, yymsp[0].minor.yy0); +} +// 2539 "parser.c" + break; + case 144: +// 1183 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_DOUBLE, yymsp[0].minor.yy0); +} +// 2546 "parser.c" + break; + case 145: +// 1187 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_NULL, NULL); + yy_destructor(61,&yymsp[0].minor); +} +// 2554 "parser.c" + break; + case 146: +// 1191 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_TRUE, NULL); + yy_destructor(64,&yymsp[0].minor); +} +// 2562 "parser.c" + break; + case 147: +// 1195 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_FALSE, NULL); + yy_destructor(65,&yymsp[0].minor); +} +// 2570 "parser.c" + break; + case 148: +// 1199 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_placeholder_zval(PHQL_T_NPLACEHOLDER, yymsp[0].minor.yy0); +} +// 2577 "parser.c" + break; + case 149: +// 1203 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_placeholder_zval(PHQL_T_SPLACEHOLDER, yymsp[0].minor.yy0); +} +// 2584 "parser.c" + break; + case 150: +// 1209 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_qualified_name(yymsp[-4].minor.yy0, yymsp[-2].minor.yy0, yymsp[0].minor.yy0); + yy_destructor(68,&yymsp[-3].minor); + yy_destructor(30,&yymsp[-1].minor); +} +// 2593 "parser.c" + break; + case 151: +// 1213 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_qualified_name(yymsp[-2].minor.yy0, NULL, yymsp[0].minor.yy0); + yy_destructor(68,&yymsp[-1].minor); +} +// 2601 "parser.c" + break; + case 152: +// 1217 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_qualified_name(NULL, yymsp[-2].minor.yy0, yymsp[0].minor.yy0); + yy_destructor(30,&yymsp[-1].minor); +} +// 2609 "parser.c" + break; + }; + yygoto = yyRuleInfo[yyruleno].lhs; + yysize = yyRuleInfo[yyruleno].nrhs; + yypParser->yyidx -= yysize; + yyact = yy_find_reduce_action(yypParser,yygoto); + if( yyact < YYNSTATE ){ + yy_shift(yypParser,yyact,yygoto,&yygotominor); + }else if( yyact == YYNSTATE + YYNRULE + 1 ){ + yy_accept(yypParser); + } } - - - -#ifdef HAVE_CONFIG_H +static void yy_parse_failed( + yyParser *yypParser /* The parser */ +){ + phql_ARG_FETCH; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); + } #endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will be executed whenever the + ** parser fails */ + phql_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} +static void yy_syntax_error( + yyParser *yypParser, /* The parser */ + int yymajor, /* The major type of the error token */ + YYMINORTYPE yyminor /* The minor type of the error token */ +){ + phql_ARG_FETCH; +#define TOKEN (yyminor.yy0) +// 446 "parser.lemon" + if (status->scanner_state->start_length) { + { + char *token_name = NULL; + int token_found = 0; + unsigned int token_length; + const phql_token_names *tokens = phql_tokens; + int active_token = status->scanner_state->active_token; + int near_length = status->scanner_state->start_length; + if (active_token) { + do { + if (tokens->code == active_token) { + token_name = tokens->name; + token_length = tokens->length; + token_found = 1; + break; + } + ++tokens; + } while (tokens[0].code != 0); + } -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Resultset_Simple){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Resultset, Simple, mvc_model_resultset_simple, "phalcon\\mvc\\model\\resultset", phalcon_mvc_model_resultset_simple_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_model_resultset_simple_ce, SL("_model"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_resultset_simple_ce, SL("_columnMap"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_model_resultset_simple_ce, SL("_keepSnapshots"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_resultset_simple_ce TSRMLS_CC, 5, zend_ce_iterator, spl_ce_SeekableIterator, spl_ce_Countable, zend_ce_arrayaccess, zend_ce_serializable); + if (!token_name) { + token_length = strlen("UNKNOWN"); + token_name = estrndup("UNKNOWN", token_length); + token_found = 0; + } - return SUCCESS; -} + status->syntax_error_len = 96 + status->token->len + token_length + near_length + status->phql_length;; + status->syntax_error = emalloc(sizeof(char) * status->syntax_error_len); -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, __construct){ - - zval *column_map, *model, *result, *cache = NULL, *keep_snapshots = NULL; - zval *fetch_assoc, *limit, *row_count, *big_resultset; - - PHALCON_MM_GROW(); + if (near_length > 0) { + if (status->token->value) { + snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), near to '%s', when parsing: %s (%d)", token_name, status->token->value, status->scanner_state->start, status->phql, status->phql_length); + } else { + snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, near to '%s', when parsing: %s (%d)", token_name, status->scanner_state->start, status->phql, status->phql_length); + } + } else { + if (active_token != PHQL_T_IGNORE) { + if (status->token->value) { + snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s(%s), at the end of query, when parsing: %s (%d)", token_name, status->token->value, status->phql, status->phql_length); + } else { + snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected token %s, at the end of query, when parsing: %s (%d)", token_name, status->phql, status->phql_length); + } + } else { + snprintf(status->syntax_error, status->syntax_error_len, "Syntax error, unexpected EOF, at the end of query"); + } + status->syntax_error[status->syntax_error_len - 1] = '\0'; + } - phalcon_fetch_params(1, 3, 2, &column_map, &model, &result, &cache, &keep_snapshots); - - if (!cache) { - PHALCON_INIT_VAR(cache); - } - - if (!keep_snapshots) { - PHALCON_INIT_VAR(keep_snapshots); - } - - phalcon_update_property_this_quick(this_ptr, SL("_model"), model, 2599397109UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_result"), result, 1670144931UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_columnMap"), column_map, 1530164624UL TSRMLS_CC); - if (Z_TYPE_P(result) != IS_OBJECT) { - RETURN_MM_NULL(); - } - - PHALCON_INIT_VAR(fetch_assoc); - ZVAL_LONG(fetch_assoc, 1); - phalcon_call_method_p1_key(NULL, result, "setfetchmode", fetch_assoc, 824603840UL); - - PHALCON_INIT_VAR(limit); - ZVAL_LONG(limit, 32); - - PHALCON_INIT_VAR(row_count); - phalcon_call_method_key(row_count, result, "numrows", 887792640UL); - - PHALCON_INIT_VAR(big_resultset); - is_smaller_function(big_resultset, limit, row_count TSRMLS_CC); - if (PHALCON_IS_TRUE(big_resultset)) { - phalcon_update_property_long(this_ptr, SL("_type"), 1 TSRMLS_CC); + if (!token_found) { + if (token_name) { + efree(token_name); + } + } + } } else { - phalcon_update_property_long(this_ptr, SL("_type"), 0 TSRMLS_CC); + status->syntax_error_len = strlen("Syntax error, unexpected EOF"); + status->syntax_error = estrndup("Syntax error, unexpected EOF", status->syntax_error_len); } - - phalcon_update_property_this_quick(this_ptr, SL("_count"), row_count, 2208664173UL TSRMLS_CC); - - phalcon_update_property_this_quick(this_ptr, SL("_keepSnapshots"), keep_snapshots, 2428293068UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); + + status->status = PHQL_PARSING_FAILED; + +// 2718 "parser.c" + phql_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, valid){ +static void yy_accept( + yyParser *yypParser /* The parser */ +){ + phql_ARG_FETCH; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); + } +#endif + while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser); + /* Here code is inserted which will be executed whenever the + ** parser accepts */ + phql_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ +} - zval *type, *result = NULL, *row = NULL, *rows = NULL, *dirty_state, *hydrate_mode; - zval *keep_snapshots, *column_map, *model, *active_row = NULL; +/* The main parser program. +** The first argument is a pointer to a structure obtained from +** "phql_Alloc" which describes the current state of the parser. +** The second argument is the major token number. The third is +** the minor token. The fourth optional argument is whatever the +** user wants (and specified in the grammar) and is available for +** use by the action routines. +** +** Inputs: +**
    +**
  • A pointer to the parser (an opaque structure.) +**
  • The major token number. +**
  • The minor token number. +**
  • An option argument of a grammar-specified type. +**
+** +** Outputs: +** None. +*/ +static void phql_( + void *yyp, /* The parser */ + int yymajor, /* The major token code number */ + phql_TOKENTYPE yyminor /* The value for the token */ + phql_ARG_PDECL /* Optional %extra_argument parameter */ +){ + YYMINORTYPE yyminorunion; + int yyact; /* The parser action. */ + int yyendofinput; /* True if we are at the end of input */ + int yyerrorhit = 0; /* True if yymajor has invoked an error */ + yyParser *yypParser; /* The parser */ - PHALCON_MM_GROW(); + /* (re)initialize the parser, if necessary */ + yypParser = (yyParser*)yyp; + if( yypParser->yyidx<0 ){ + if( yymajor==0 ) return; + yypParser->yyidx = 0; + yypParser->yyerrcnt = -1; + yypParser->yystack[0].stateno = 0; + yypParser->yystack[0].major = 0; + } + yyminorunion.yy0 = yyminor; + yyendofinput = (yymajor==0); + phql_ARG_STORE; - PHALCON_OBS_VAR(type); - phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); - if (zend_is_true(type)) { - - PHALCON_OBS_VAR(result); - phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); - if (Z_TYPE_P(result) == IS_OBJECT) { - PHALCON_INIT_VAR(row); - phalcon_call_method_p1_key(row, result, "fetch", result, 4247924303UL); +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]); + } +#endif + + do{ + yyact = yy_find_shift_action(yypParser,yymajor); + if( yyactyyerrcnt--; + if( yyendofinput && yypParser->yyidx>=0 ){ + yymajor = 0; + }else{ + yymajor = YYNOCODE; + } + }else if( yyact < YYNSTATE + YYNRULE ){ + yy_reduce(yypParser,yyact-YYNSTATE); + }else if( yyact == YY_ERROR_ACTION ){ + int yymx; +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt); + } +#endif +#ifdef YYERRORSYMBOL + /* A syntax error has occurred. + ** The response to an error depends upon whether or not the + ** grammar defines an error token "ERROR". + ** + ** This is what we do if the grammar does define ERROR: + ** + ** * Call the %syntax_error function. + ** + ** * Begin popping the stack until we enter a state where + ** it is legal to shift the error symbol, then shift + ** the error symbol. + ** + ** * Set the error count to three. + ** + ** * Begin accepting and shifting new tokens. No new error + ** processing will occur until three tokens have been + ** shifted successfully. + ** + */ + if( yypParser->yyerrcnt<0 ){ + yy_syntax_error(yypParser,yymajor,yyminorunion); + } + yymx = yypParser->yystack[yypParser->yyidx].major; + if( yymx==YYERRORSYMBOL || yyerrorhit ){ +#ifndef NDEBUG + if( yyTraceFILE ){ + fprintf(yyTraceFILE,"%sDiscard input token %s\n", + yyTracePrompt,yyTokenName[yymajor]); + } +#endif + yy_destructor(yymajor,&yyminorunion); + yymajor = YYNOCODE; + }else{ + while( + yypParser->yyidx >= 0 && + yymx != YYERRORSYMBOL && + (yyact = yy_find_shift_action(yypParser,YYERRORSYMBOL)) >= YYNSTATE + ){ + yy_pop_parser_stack(yypParser); + } + if( yypParser->yyidx < 0 || yymajor==0 ){ + yy_destructor(yymajor,&yyminorunion); + yy_parse_failed(yypParser); + yymajor = YYNOCODE; + }else if( yymx!=YYERRORSYMBOL ){ + YYMINORTYPE u2; + u2.YYERRSYMDT = 0; + yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2); + } + } + yypParser->yyerrcnt = 3; + yyerrorhit = 1; +#else /* YYERRORSYMBOL is not defined */ + /* This is what we do if the grammar does not define ERROR: + ** + ** * Report an error message, and throw away the input token. + ** + ** * If the input token is $, then fail the parse. + ** + ** As before, subsequent error messages are suppressed until + ** three input tokens have been successfully shifted. + */ + if( yypParser->yyerrcnt<=0 ){ + yy_syntax_error(yypParser,yymajor,yyminorunion); + } + yypParser->yyerrcnt = 3; + yy_destructor(yymajor,&yyminorunion); + if( yyendofinput ){ + yy_parse_failed(yypParser); + } + yymajor = YYNOCODE; +#endif + }else{ + yy_accept(yypParser); + yymajor = YYNOCODE; + } + }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 ); + return; +} + + +const phql_token_names phql_tokens[] = +{ + { SL("INTEGER"), PHQL_T_INTEGER }, + { SL("DOUBLE"), PHQL_T_DOUBLE }, + { SL("STRING"), PHQL_T_STRING }, + { SL("IDENTIFIER"), PHQL_T_IDENTIFIER }, + { SL("MINUS"), PHQL_T_MINUS }, + { SL("+"), PHQL_T_ADD }, + { SL("-"), PHQL_T_SUB }, + { SL("*"), PHQL_T_MUL }, + { SL("/"), PHQL_T_DIV }, + { SL("&"), PHQL_T_BITWISE_AND }, + { SL("|"), PHQL_T_BITWISE_OR }, + { SL("%%"), PHQL_T_MOD }, + { SL("AND"), PHQL_T_AND }, + { SL("OR"), PHQL_T_OR }, + { SL("LIKE"), PHQL_T_LIKE }, + { SL("ILIKE"), PHQL_T_ILIKE }, + { SL("DOT"), PHQL_T_DOT }, + { SL("COLON"), PHQL_T_COLON }, + { SL("COMMA"), PHQL_T_COMMA }, + { SL("EQUALS"), PHQL_T_EQUALS }, + { SL("NOT EQUALS"), PHQL_T_NOTEQUALS }, + { SL("NOT"), PHQL_T_NOT }, + { SL("<"), PHQL_T_LESS }, + { SL("<="), PHQL_T_LESSEQUAL }, + { SL(">"), PHQL_T_GREATER }, + { SL(">="), PHQL_T_GREATEREQUAL }, + { SL("("), PHQL_T_PARENTHESES_OPEN }, + { SL(")"), PHQL_T_PARENTHESES_CLOSE }, + { SL("NUMERIC PLACEHOLDER"), PHQL_T_NPLACEHOLDER }, + { SL("STRING PLACEHOLDER"), PHQL_T_SPLACEHOLDER }, + { SL("UPDATE"), PHQL_T_UPDATE }, + { SL("SET"), PHQL_T_SET }, + { SL("WHERE"), PHQL_T_WHERE }, + { SL("DELETE"), PHQL_T_DELETE }, + { SL("FROM"), PHQL_T_FROM }, + { SL("AS"), PHQL_T_AS }, + { SL("INSERT"), PHQL_T_INSERT }, + { SL("INTO"), PHQL_T_INTO }, + { SL("VALUES"), PHQL_T_VALUES }, + { SL("SELECT"), PHQL_T_SELECT }, + { SL("ORDER"), PHQL_T_ORDER }, + { SL("BY"), PHQL_T_BY }, + { SL("LIMIT"), PHQL_T_LIMIT }, + { SL("OFFSET"), PHQL_T_OFFSET }, + { SL("GROUP"), PHQL_T_GROUP }, + { SL("HAVING"), PHQL_T_HAVING }, + { SL("IN"), PHQL_T_IN }, + { SL("ON"), PHQL_T_ON }, + { SL("INNER"), PHQL_T_INNER }, + { SL("JOIN"), PHQL_T_JOIN }, + { SL("LEFT"), PHQL_T_LEFT }, + { SL("RIGHT"), PHQL_T_RIGHT }, + { SL("IS"), PHQL_T_IS }, + { SL("NULL"), PHQL_T_NULL }, + { SL("NOT IN"), PHQL_T_NOTIN }, + { SL("CROSS"), PHQL_T_CROSS }, + { SL("OUTER"), PHQL_T_OUTER }, + { SL("FULL"), PHQL_T_FULL }, + { SL("ASC"), PHQL_T_ASC }, + { SL("DESC"), PHQL_T_DESC }, + { SL("BETWEEN"), PHQL_T_BETWEEN }, + { SL("DISTINCT"), PHQL_T_DISTINCT }, + { SL("AGAINST"), PHQL_T_AGAINST }, + { SL("CAST"), PHQL_T_CAST }, + { SL("CONVERT"), PHQL_T_CONVERT }, + { SL("USING"), PHQL_T_USING }, + { NULL, 0, 0 } +}; + +static void *phql_wrapper_alloc(size_t bytes){ + return emalloc(bytes); +} + +static void phql_wrapper_free(void *pointer){ + efree(pointer); +} + +static void phql_parse_with_token(void* phql_parser, int opcode, int parsercode, phql_scanner_token *token, phql_parser_status *parser_status){ + + phql_parser_token *pToken; + + pToken = emalloc(sizeof(phql_parser_token)); + pToken->opcode = opcode; + pToken->token = token->value; + pToken->token_len = token->len; + pToken->free_flag = 1; + phql_(phql_parser, parsercode, pToken, parser_status); + + token->value = NULL; + token->len = 0; +} + +static void phql_scanner_error_msg(phql_parser_status *parser_status, zval **error_msg TSRMLS_DC){ + + char *error = NULL, *error_part; + unsigned int length; + phql_scanner_state *state = parser_status->scanner_state; + + PHALCON_INIT_VAR(*error_msg); + if (state->start) { + length = 64 + state->start_length + parser_status->phql_length; + error = emalloc(sizeof(char) * length); + if (state->start_length > 16) { + error_part = estrndup(state->start, 16); + snprintf(error, length, "Scanning error before '%s...' when parsing: %s (%d)", error_part, parser_status->phql, parser_status->phql_length); + efree(error_part); } else { - PHALCON_INIT_NVAR(row); - ZVAL_BOOL(row, 0); + snprintf(error, length, "Scanning error before '%s' when parsing: %s (%d)", state->start, parser_status->phql, parser_status->phql_length); } + error[length - 1] = '\0'; + ZVAL_STRING(*error_msg, error, 1); } else { - PHALCON_OBS_VAR(rows); - phalcon_read_property_this_quick(&rows, this_ptr, SL("_rows"), 3989235983UL, PH_NOISY_CC); - if (Z_TYPE_P(rows) != IS_ARRAY) { - - PHALCON_OBS_NVAR(result); - phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); - if (Z_TYPE_P(result) == IS_OBJECT) { - PHALCON_INIT_NVAR(rows); - phalcon_call_method_key(rows, result, "fetchall", 1636682248UL); - phalcon_update_property_this_quick(this_ptr, SL("_rows"), rows, 3989235983UL TSRMLS_CC); - } - } - - if (Z_TYPE_P(rows) == IS_ARRAY) { - - PHALCON_INIT_NVAR(row); - phalcon_array_get_current(row, rows); - if (PHALCON_IS_NOT_FALSE(row)) { - phalcon_array_next(rows); - } - } else { - PHALCON_INIT_NVAR(row); - ZVAL_BOOL(row, 0); - } - } - - if (Z_TYPE_P(row) != IS_ARRAY) { - phalcon_update_property_bool(this_ptr, SL("_activeRow"), 0 TSRMLS_CC); - RETURN_MM_FALSE; + ZVAL_STRING(*error_msg, "Scanning error near to EOF", 1); } - - PHALCON_INIT_VAR(dirty_state); - ZVAL_LONG(dirty_state, 0); - - PHALCON_OBS_VAR(hydrate_mode); - phalcon_read_property_this_quick(&hydrate_mode, this_ptr, SL("_hydrateMode"), 2551752186UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(keep_snapshots); - phalcon_read_property_this_quick(&keep_snapshots, this_ptr, SL("_keepSnapshots"), 2428293068UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(column_map); - phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); - - - switch (phalcon_get_intval(hydrate_mode)) { - - case 0: - PHALCON_OBS_VAR(model); - phalcon_read_property_this_quick(&model, this_ptr, SL("_model"), 2599397109UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(active_row); - PHALCON_CALL_STATIC_PARAMS_5(active_row, "phalcon\\mvc\\model", "cloneresultmap", model, row, column_map, dirty_state, keep_snapshots); - break; - - default: - PHALCON_INIT_NVAR(active_row); - PHALCON_CALL_STATIC_PARAMS_3(active_row, "phalcon\\mvc\\model", "cloneresultmaphydrate", row, column_map, hydrate_mode); - break; - + + if (error) { + efree(error); } - phalcon_update_property_this_quick(this_ptr, SL("_activeRow"), active_row, 3086770360UL TSRMLS_CC); - RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, toArray){ +static int phql_parse_phql(zval *result, zval *phql TSRMLS_DC) { - zval *rename_columns = NULL, *type, *result = NULL, *active_row = NULL; - zval *records = NULL, *row_count, *column_map, *renamed_records; - zval *record = NULL, *renamed = NULL, *value = NULL, *key = NULL, *exception_message = NULL; - zval *renamed_key = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; + zval *error_msg = NULL; - PHALCON_MM_GROW(); + ZVAL_NULL(result); - phalcon_fetch_params(1, 0, 1, &rename_columns); - - if (!rename_columns) { - PHALCON_INIT_VAR(rename_columns); - ZVAL_BOOL(rename_columns, 1); + if (phql_internal_parse_phql(&result, Z_STRVAL_P(phql), Z_STRLEN_P(phql), &error_msg TSRMLS_CC) == FAILURE) { + phalcon_throw_exception_string(phalcon_mvc_model_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC); + return FAILURE; } - - PHALCON_OBS_VAR(type); - phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); - if (zend_is_true(type)) { - - PHALCON_OBS_VAR(result); - phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); - if (Z_TYPE_P(result) == IS_OBJECT) { - - PHALCON_OBS_VAR(active_row); - phalcon_read_property_this_quick(&active_row, this_ptr, SL("_activeRow"), 3086770360UL, PH_NOISY_CC); - - if (Z_TYPE_P(active_row) != IS_NULL) { - phalcon_call_method_key(NULL, result, "execute", 3117639032UL); + + return SUCCESS; +} + +static int phql_internal_parse_phql(zval **result, char *phql, unsigned int phql_length, zval **error_msg TSRMLS_DC) { + + zend_phalcon_globals *phalcon_globals_ptr = PHALCON_VGLOBAL; + phql_parser_status *parser_status = NULL; + int scanner_status, status = SUCCESS, error_length; + phql_scanner_state *state; + phql_scanner_token token; + unsigned long phql_key; + void* phql_parser; + char *error; + zval **temp_ast; + + if (!phql) { + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, "PHQL statement cannot be NULL", 1); + return FAILURE; + } + + if (phalcon_globals_ptr->orm.cache_level >= 0) { + + phql_key = zend_inline_hash_func(phql, phql_length + 1); + + if (phalcon_globals_ptr->orm.parser_cache != NULL) { + if (zend_hash_index_find(phalcon_globals_ptr->orm.parser_cache, phql_key, (void**) &temp_ast) == SUCCESS) { + ZVAL_ZVAL(*result, *temp_ast, 1, 0); + Z_SET_REFCOUNT_P(*result, 1); + return SUCCESS; } - - PHALCON_INIT_VAR(records); - phalcon_call_method_key(records, result, "fetchall", 1636682248UL); - } else { - PHALCON_INIT_NVAR(records); - array_init(records); } - } else { - PHALCON_OBS_NVAR(records); - phalcon_read_property_this_quick(&records, this_ptr, SL("_rows"), 3989235983UL, PH_NOISY_CC); - if (Z_TYPE_P(records) != IS_ARRAY) { - - PHALCON_OBS_NVAR(result); - phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); - if (Z_TYPE_P(result) == IS_OBJECT) { - - PHALCON_OBS_NVAR(active_row); - phalcon_read_property_this_quick(&active_row, this_ptr, SL("_activeRow"), 3086770360UL, PH_NOISY_CC); - - if (Z_TYPE_P(active_row) != IS_NULL) { - phalcon_call_method_key(NULL, result, "execute", 3117639032UL); - } - - PHALCON_INIT_NVAR(records); - phalcon_call_method_key(records, result, "fetchall", 1636682248UL); - phalcon_update_property_this_quick(this_ptr, SL("_rows"), records, 3989235983UL TSRMLS_CC); - - PHALCON_INIT_VAR(row_count); - phalcon_fast_count(row_count, records TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_count"), row_count, 2208664173UL TSRMLS_CC); - } - } - } - - if (zend_is_true(rename_columns)) { - - PHALCON_OBS_VAR(column_map); - phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); - if (Z_TYPE_P(column_map) != IS_ARRAY) { - RETURN_CCTOR(records); - } - - PHALCON_INIT_VAR(renamed_records); - array_init(renamed_records); - if (Z_TYPE_P(records) == IS_ARRAY) { - - phalcon_is_iterable(records, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(record); - - PHALCON_INIT_NVAR(renamed); - array_init(renamed); - - phalcon_is_iterable(record, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HKEY(key, ah1, hp1); - PHALCON_GET_HVALUE(value); - - if (!phalcon_array_isset(column_map, key)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", key, "' is not part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_NVAR(renamed_key); - phalcon_array_fetch(&renamed_key, column_map, key, PH_NOISY); - - phalcon_array_update_zval(&renamed, renamed_key, &value, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - phalcon_array_append(&renamed_records, renamed, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - RETURN_CTOR(renamed_records); } - - RETURN_CCTOR(records); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, serialize){ - zval *rename_columns, *records, *model, *cache; - zval *column_map, *hydrate_mode, *data; + phql_parser = phql_Alloc(phql_wrapper_alloc); - PHALCON_MM_GROW(); + parser_status = emalloc(sizeof(phql_parser_status)); + state = emalloc(sizeof(phql_scanner_state)); - PHALCON_INIT_VAR(rename_columns); - ZVAL_BOOL(rename_columns, 0); - - PHALCON_INIT_VAR(records); - phalcon_call_method_p1_key(records, this_ptr, "toarray", rename_columns, 3566966151UL); - - PHALCON_OBS_VAR(model); - phalcon_read_property_this_quick(&model, this_ptr, SL("_model"), 2599397109UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(cache); - phalcon_read_property_this_quick(&cache, this_ptr, SL("_cache"), 2191407384UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(column_map); - phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(hydrate_mode); - phalcon_read_property_this_quick(&hydrate_mode, this_ptr, SL("_hydrateMode"), 2551752186UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(data); - array_init_size(data, 5); - phalcon_array_update_quick_string(&data, SS("model"), 238191286UL, &model, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("cache"), 4125168857UL, &cache, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("rows"), 273469616UL, &records, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("columnMap"), 672221649UL, &column_map, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("hydrateMode"), 259755643UL, &hydrate_mode, PH_COPY | PH_SEPARATE); - - phalcon_update_property_bool(this_ptr, SL("_activeRow"), 0 TSRMLS_CC); - - phalcon_serialize(return_value, &data TSRMLS_CC); - RETURN_MM(); -} + parser_status->status = PHQL_PARSING_OK; + parser_status->scanner_state = state; + parser_status->ret = NULL; + parser_status->syntax_error = NULL; + parser_status->token = &token; + parser_status->enable_literals = phalcon_globals_ptr->orm.enable_literals; + parser_status->phql = phql; + parser_status->phql_length = phql_length; -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, unserialize){ + state->active_token = 0; + state->start = phql; + state->start_length = 0; + state->end = state->start; - zval *data, *resultset, *model, *rows, *cache, *column_map; - zval *hydrate_mode; + token.value = NULL; + token.len = 0; - PHALCON_MM_GROW(); + while (0 <= (scanner_status = phql_get_token(state, &token))) { - phalcon_fetch_params(1, 1, 0, &data); - - phalcon_update_property_long(this_ptr, SL("_type"), 0 TSRMLS_CC); - - PHALCON_INIT_VAR(resultset); - phalcon_unserialize(resultset, data TSRMLS_CC); - if (Z_TYPE_P(resultset) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid serialization data"); - return; - } - - PHALCON_OBS_VAR(model); - phalcon_array_fetch_quick_string(&model, resultset, SS("model"), 238191286UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_model"), model, 2599397109UL TSRMLS_CC); - - PHALCON_OBS_VAR(rows); - phalcon_array_fetch_quick_string(&rows, resultset, SS("rows"), 273469616UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_rows"), rows, 3989235983UL TSRMLS_CC); - - PHALCON_OBS_VAR(cache); - phalcon_array_fetch_quick_string(&cache, resultset, SS("cache"), 4125168857UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); - - PHALCON_OBS_VAR(column_map); - phalcon_array_fetch_quick_string(&column_map, resultset, SS("columnMap"), 672221649UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_columnMap"), column_map, 1530164624UL TSRMLS_CC); - - PHALCON_OBS_VAR(hydrate_mode); - phalcon_array_fetch_quick_string(&hydrate_mode, resultset, SS("hydrateMode"), 259755643UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_hydrateMode"), hydrate_mode, 2551752186UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} + /* Calculate the 'start' length */ + state->start_length = (phql + phql_length - state->start); + state->active_token = token.opcode; + /* Parse the token found */ + switch (token.opcode) { + case PHQL_T_IGNORE: + break; + case PHQL_T_ADD: + phql_(phql_parser, PHQL_PLUS, NULL, parser_status); + break; + case PHQL_T_SUB: + phql_(phql_parser, PHQL_MINUS, NULL, parser_status); + break; + case PHQL_T_MUL: + phql_(phql_parser, PHQL_TIMES, NULL, parser_status); + break; + case PHQL_T_DIV: + phql_(phql_parser, PHQL_DIVIDE, NULL, parser_status); + break; + case PHQL_T_MOD: + phql_(phql_parser, PHQL_MOD, NULL, parser_status); + break; + case PHQL_T_AND: + phql_(phql_parser, PHQL_AND, NULL, parser_status); + break; + case PHQL_T_OR: + phql_(phql_parser, PHQL_OR, NULL, parser_status); + break; + case PHQL_T_EQUALS: + phql_(phql_parser, PHQL_EQUALS, NULL, parser_status); + break; + case PHQL_T_NOTEQUALS: + phql_(phql_parser, PHQL_NOTEQUALS, NULL, parser_status); + break; + case PHQL_T_LESS: + phql_(phql_parser, PHQL_LESS, NULL, parser_status); + break; + case PHQL_T_GREATER: + phql_(phql_parser, PHQL_GREATER, NULL, parser_status); + break; + case PHQL_T_GREATEREQUAL: + phql_(phql_parser, PHQL_GREATEREQUAL, NULL, parser_status); + break; + case PHQL_T_LESSEQUAL: + phql_(phql_parser, PHQL_LESSEQUAL, NULL, parser_status); + break; + case PHQL_T_LIKE: + phql_(phql_parser, PHQL_LIKE, NULL, parser_status); + break; + case PHQL_T_ILIKE: + phql_(phql_parser, PHQL_ILIKE, NULL, parser_status); + break; + case PHQL_T_NOT: + phql_(phql_parser, PHQL_NOT, NULL, parser_status); + break; + case PHQL_T_BITWISE_AND: + phql_(phql_parser, PHQL_BITWISE_AND, NULL, parser_status); + break; + case PHQL_T_BITWISE_OR: + phql_(phql_parser, PHQL_BITWISE_OR, NULL, parser_status); + break; + case PHQL_T_BITWISE_NOT: + phql_(phql_parser, PHQL_BITWISE_NOT, NULL, parser_status); + break; + case PHQL_T_BITWISE_XOR: + phql_(phql_parser, PHQL_BITWISE_XOR, NULL, parser_status); + break; + case PHQL_T_AGAINST: + phql_(phql_parser, PHQL_AGAINST, NULL, parser_status); + break; + case PHQL_T_DOT: + phql_(phql_parser, PHQL_DOT, NULL, parser_status); + break; + case PHQL_T_COLON: + phql_(phql_parser, PHQL_COLON, NULL, parser_status); + break; + case PHQL_T_COMMA: + phql_(phql_parser, PHQL_COMMA, NULL, parser_status); + break; -#ifdef HAVE_CONFIG_H -#endif + case PHQL_T_PARENTHESES_OPEN: + phql_(phql_parser, PHQL_PARENTHESES_OPEN, NULL, parser_status); + break; + case PHQL_T_PARENTHESES_CLOSE: + phql_(phql_parser, PHQL_PARENTHESES_CLOSE, NULL, parser_status); + break; + case PHQL_T_INTEGER: + if (parser_status->enable_literals) { + phql_parse_with_token(phql_parser, PHQL_T_INTEGER, PHQL_INTEGER, &token, parser_status); + } else { + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, "Literals are disabled in PHQL statements", 1); + parser_status->status = PHQL_PARSING_FAILED; + } + break; + case PHQL_T_DOUBLE: + if (parser_status->enable_literals) { + phql_parse_with_token(phql_parser, PHQL_T_DOUBLE, PHQL_DOUBLE, &token, parser_status); + } else { + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, "Literals are disabled in PHQL statements", 1); + parser_status->status = PHQL_PARSING_FAILED; + } + break; + case PHQL_T_STRING: + if (parser_status->enable_literals) { + phql_parse_with_token(phql_parser, PHQL_T_STRING, PHQL_STRING, &token, parser_status); + } else { + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, "Literals are disabled in PHQL statements", 1); + parser_status->status = PHQL_PARSING_FAILED; + } + break; + case PHQL_T_TRUE: + if (parser_status->enable_literals) { + phql_(phql_parser, PHQL_TRUE, NULL, parser_status); + } else { + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, "Literals are disabled in PHQL statements", 1); + parser_status->status = PHQL_PARSING_FAILED; + } + break; + case PHQL_T_FALSE: + if (parser_status->enable_literals) { + phql_(phql_parser, PHQL_FALSE, NULL, parser_status); + } else { + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, "Literals are disabled in PHQL statements", 1); + parser_status->status = PHQL_PARSING_FAILED; + } + break; + case PHQL_T_IDENTIFIER: + phql_parse_with_token(phql_parser, PHQL_T_IDENTIFIER, PHQL_IDENTIFIER, &token, parser_status); + break; + case PHQL_T_NPLACEHOLDER: + phql_parse_with_token(phql_parser, PHQL_T_NPLACEHOLDER, PHQL_NPLACEHOLDER, &token, parser_status); + break; + case PHQL_T_SPLACEHOLDER: + phql_parse_with_token(phql_parser, PHQL_T_SPLACEHOLDER, PHQL_SPLACEHOLDER, &token, parser_status); + break; -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_RelationInterface){ + case PHQL_T_FROM: + phql_(phql_parser, PHQL_FROM, NULL, parser_status); + break; + case PHQL_T_UPDATE: + phql_(phql_parser, PHQL_UPDATE, NULL, parser_status); + break; + case PHQL_T_SET: + phql_(phql_parser, PHQL_SET, NULL, parser_status); + break; + case PHQL_T_WHERE: + phql_(phql_parser, PHQL_WHERE, NULL, parser_status); + break; + case PHQL_T_DELETE: + phql_(phql_parser, PHQL_DELETE, NULL, parser_status); + break; + case PHQL_T_INSERT: + phql_(phql_parser, PHQL_INSERT, NULL, parser_status); + break; + case PHQL_T_INTO: + phql_(phql_parser, PHQL_INTO, NULL, parser_status); + break; + case PHQL_T_VALUES: + phql_(phql_parser, PHQL_VALUES, NULL, parser_status); + break; + case PHQL_T_SELECT: + phql_(phql_parser, PHQL_SELECT, NULL, parser_status); + break; + case PHQL_T_AS: + phql_(phql_parser, PHQL_AS, NULL, parser_status); + break; + case PHQL_T_ORDER: + phql_(phql_parser, PHQL_ORDER, NULL, parser_status); + break; + case PHQL_T_BY: + phql_(phql_parser, PHQL_BY, NULL, parser_status); + break; + case PHQL_T_LIMIT: + phql_(phql_parser, PHQL_LIMIT, NULL, parser_status); + break; + case PHQL_T_OFFSET: + phql_(phql_parser, PHQL_OFFSET, NULL, parser_status); + break; + case PHQL_T_GROUP: + phql_(phql_parser, PHQL_GROUP, NULL, parser_status); + break; + case PHQL_T_HAVING: + phql_(phql_parser, PHQL_HAVING, NULL, parser_status); + break; + case PHQL_T_ASC: + phql_(phql_parser, PHQL_ASC, NULL, parser_status); + break; + case PHQL_T_DESC: + phql_(phql_parser, PHQL_DESC, NULL, parser_status); + break; + case PHQL_T_IN: + phql_(phql_parser, PHQL_IN, NULL, parser_status); + break; + case PHQL_T_ON: + phql_(phql_parser, PHQL_ON, NULL, parser_status); + break; + case PHQL_T_INNER: + phql_(phql_parser, PHQL_INNER, NULL, parser_status); + break; + case PHQL_T_JOIN: + phql_(phql_parser, PHQL_JOIN, NULL, parser_status); + break; + case PHQL_T_LEFT: + phql_(phql_parser, PHQL_LEFT, NULL, parser_status); + break; + case PHQL_T_RIGHT: + phql_(phql_parser, PHQL_RIGHT, NULL, parser_status); + break; + case PHQL_T_CROSS: + phql_(phql_parser, PHQL_CROSS, NULL, parser_status); + break; + case PHQL_T_FULL: + phql_(phql_parser, PHQL_FULL, NULL, parser_status); + break; + case PHQL_T_OUTER: + phql_(phql_parser, PHQL_OUTER, NULL, parser_status); + break; + case PHQL_T_IS: + phql_(phql_parser, PHQL_IS, NULL, parser_status); + break; + case PHQL_T_NULL: + phql_(phql_parser, PHQL_NULL, NULL, parser_status); + break; + case PHQL_T_BETWEEN: + phql_(phql_parser, PHQL_BETWEEN, NULL, parser_status); + break; + case PHQL_T_DISTINCT: + phql_(phql_parser, PHQL_DISTINCT, NULL, parser_status); + break; + case PHQL_T_CAST: + phql_(phql_parser, PHQL_CAST, NULL, parser_status); + break; + case PHQL_T_CONVERT: + phql_(phql_parser, PHQL_CONVERT, NULL, parser_status); + break; + case PHQL_T_USING: + phql_(phql_parser, PHQL_USING, NULL, parser_status); + break; + default: + parser_status->status = PHQL_PARSING_FAILED; + error_length = sizeof(char) * 32; + error = emalloc(error_length); + snprintf(error, error_length, "Scanner: Unknown opcode %c", token.opcode); + error[error_length - 1] = '\0'; + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, error, 1); + efree(error); + break; + } - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, RelationInterface, mvc_model_relationinterface, phalcon_mvc_model_relationinterface_method_entry); + if (parser_status->status != PHQL_PARSING_OK) { + status = FAILURE; + break; + } - return SUCCESS; -} + state->end = state->start; + } + if (status != FAILURE) { + switch (scanner_status) { + case PHQL_SCANNER_RETCODE_ERR: + case PHQL_SCANNER_RETCODE_IMPOSSIBLE: + if (!*error_msg) { + if (!*error_msg) { + phql_scanner_error_msg(parser_status, error_msg TSRMLS_CC); + } + } + status = FAILURE; + break; + default: + phql_(phql_parser, 0, NULL, parser_status); + } + } + state->active_token = 0; + state->start = NULL; + if (parser_status->status != PHQL_PARSING_OK) { + status = FAILURE; + if (parser_status->syntax_error) { + if (!*error_msg) { + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, parser_status->syntax_error, 1); + } + efree(parser_status->syntax_error); + } + } + phql_Free(phql_parser, phql_wrapper_free); + if (status != FAILURE) { + if (parser_status->status == PHQL_PARSING_OK) { + if (parser_status->ret) { + if (phalcon_globals_ptr->orm.cache_level >= 1) { + if (Z_TYPE_P(parser_status->ret) == IS_ARRAY) { + add_assoc_long(parser_status->ret, "id", phalcon_globals_ptr->orm.unique_cache_id++); + } + } + ZVAL_ZVAL(*result, parser_status->ret, 0, 0); + ZVAL_NULL(parser_status->ret); + zval_ptr_dtor(&parser_status->ret); + if (phalcon_globals_ptr->orm.cache_level >= 0) { + if (!phalcon_globals_ptr->orm.parser_cache) { + ALLOC_HASHTABLE(phalcon_globals_ptr->orm.parser_cache); + zend_hash_init(phalcon_globals_ptr->orm.parser_cache, 0, NULL, ZVAL_PTR_DTOR, 0); + } + Z_ADDREF_PP(result); + zend_hash_index_update( + phalcon_globals_ptr->orm.parser_cache, + phql_key, + result, + sizeof(zval *), + NULL + ); + } + } else { + efree(parser_status->ret); + } + } + } + efree(parser_status); + efree(state); + return status; +} +/* Generated by re2c 0.13.5 on Sun Jun 23 22:30:45 2013 */ +// 1 "scanner.re" #ifdef HAVE_CONFIG_H @@ -61285,8772 +59872,4501 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_RelationInterface){ -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_ResultsetInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, ResultsetInterface, mvc_model_resultsetinterface, phalcon_mvc_model_resultsetinterface_method_entry); - - return SUCCESS; -} - - - - - +#define YYCTYPE unsigned char +#define YYCURSOR (s->start) +#define YYLIMIT (s->end) +#define YYMARKER q +static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { + char *q = YYCURSOR; + int status = PHQL_SCANNER_RETCODE_IMPOSSIBLE; + while (PHQL_SCANNER_RETCODE_IMPOSSIBLE == status) { + +// 45 "scanner.c" + { + YYCTYPE yych; + unsigned int yyaccept = 0; - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_User_Plugin){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Plugin, mvc_user_plugin, "phalcon\\di\\injectable", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_User_Module){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Module, mvc_user_module, "phalcon\\di\\injectable", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_User_Component){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Component, mvc_user_component, "phalcon\\di\\injectable", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Router){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc, Router, mvc_router, phalcon_mvc_router_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_router_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_uriSource"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_namespace"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_module"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_controller"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_action"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_params"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_routes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_matchedRoute"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_matches"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_router_ce, SL("_wasMatched"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_defaultNamespace"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_defaultModule"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_defaultController"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_defaultAction"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_defaultParams"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_removeExtraSlashes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_ce, SL("_notFoundPaths"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_declare_class_constant_long(phalcon_mvc_router_ce, SL("URI_SOURCE_GET_URL"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_router_ce, SL("URI_SOURCE_SERVER_REQUEST_URI"), 1 TSRMLS_CC); - - zend_class_implements(phalcon_mvc_router_ce TSRMLS_CC, 2, phalcon_mvc_routerinterface_ce, phalcon_di_injectionawareinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Router, __construct){ - - zval *default_routes = NULL, *routes, *paths = NULL, *action_pattern; - zval *route = NULL, *params_pattern, *params; - - PHALCON_MM_GROW(); - - phalcon_update_property_empty_array(phalcon_mvc_router_ce, this_ptr, SL("_defaultParams") TSRMLS_CC); - - phalcon_fetch_params(1, 0, 1, &default_routes); - - if (!default_routes) { - PHALCON_INIT_VAR(default_routes); - ZVAL_BOOL(default_routes, 1); - } - - PHALCON_INIT_VAR(routes); - array_init(routes); - if (PHALCON_IS_TRUE(default_routes)) { - PHALCON_INIT_VAR(paths); - array_init_size(paths, 1); - add_assoc_long_ex(paths, SS("controller"), 1); - - PHALCON_INIT_VAR(action_pattern); - ZVAL_STRING(action_pattern, "#^/([a-zA-Z0-9\\_\\-]+)[/]{0,1}$#", 1); - - PHALCON_INIT_VAR(route); - object_init_ex(route, phalcon_mvc_router_route_ce); - phalcon_call_method_p2_key(NULL, route, "__construct", action_pattern, paths, 1107214344UL); - - phalcon_array_append(&routes, route, PH_SEPARATE); - - PHALCON_INIT_NVAR(paths); - array_init_size(paths, 3); - add_assoc_long_ex(paths, SS("controller"), 1); - add_assoc_long_ex(paths, SS("action"), 2); - add_assoc_long_ex(paths, SS("params"), 3); - - PHALCON_INIT_VAR(params_pattern); - ZVAL_STRING(params_pattern, "#^/([a-zA-Z0-9\\_\\-]+)/([a-zA-Z0-9\\.\\_]+)(/.*)*$#", 1); - - PHALCON_INIT_NVAR(route); - object_init_ex(route, phalcon_mvc_router_route_ce); - phalcon_call_method_p2_key(NULL, route, "__construct", params_pattern, paths, 1107214344UL); - - phalcon_array_append(&routes, route, PH_SEPARATE); - } - - PHALCON_INIT_VAR(params); - array_init(params); - phalcon_update_property_this_quick(this_ptr, SL("_params"), params, 3223731112UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_routes"), routes, 2063827110UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Router, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router, getRewriteUri){ - - zval *uri_source, *_GET, *url = NULL, *_SERVER, *url_parts; - zval *real_uri; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(uri_source); - phalcon_read_property_this_quick(&uri_source, this_ptr, SL("_uriSource"), 144947845UL, PH_NOISY_CC); - - if (!zend_is_true(uri_source)) { - phalcon_get_global(&_GET, SS("_GET") TSRMLS_CC); - if (phalcon_array_isset_quick_string(_GET, SS("_url"), 251147063UL)) { - - PHALCON_OBS_VAR(url); - phalcon_array_fetch_quick_string(&url, _GET, SS("_url"), 251147063UL, PH_NOISY); - if (PHALCON_IS_NOT_EMPTY(url)) { - RETURN_CCTOR(url); + yych = *YYCURSOR; + switch (yych) { + case 0x00: goto yy68; + case '\t': + case '\n': + case '\r': + case ' ': goto yy66; + case '!': goto yy50; + case '"': goto yy29; + case '%': goto yy42; + case '&': goto yy62; + case '\'': goto yy30; + case '(': goto yy46; + case ')': goto yy48; + case '*': goto yy38; + case '+': goto yy34; + case ',': goto yy44; + case '-': goto yy36; + case '.': goto yy4; + case '/': goto yy40; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy2; + case ':': goto yy8; + case '<': goto yy52; + case '=': goto yy56; + case '>': goto yy54; + case '?': goto yy6; + case 'A': + case 'a': goto yy15; + case 'B': + case 'b': goto yy20; + case 'C': + case 'c': goto yy27; + case 'D': + case 'd': goto yy13; + case 'E': + case 'K': + case 'M': + case 'P': + case 'Q': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'e': + case 'k': + case 'm': + case 'p': + case 'q': + case 'x': + case 'y': + case 'z': goto yy32; + case 'F': + case 'f': goto yy14; + case 'G': + case 'g': goto yy21; + case 'H': + case 'h': goto yy22; + case 'I': + case 'i': goto yy16; + case 'J': + case 'j': goto yy25; + case 'L': + case 'l': goto yy23; + case 'N': + case 'n': goto yy24; + case 'O': + case 'o': goto yy19; + case 'R': + case 'r': goto yy26; + case 'S': + case 's': goto yy12; + case 'T': + case 't': goto yy28; + case 'U': + case 'u': goto yy10; + case 'V': + case 'v': goto yy17; + case 'W': + case 'w': goto yy18; + case '[': goto yy33; + case '\\': goto yy31; + case '^': goto yy60; + case '|': goto yy64; + case '~': goto yy58; + default: goto yy70; + } +yy2: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '.': goto yy288; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy290; + default: goto yy3; } +yy3: +// 46 "scanner.re" + { + token->opcode = PHQL_T_INTEGER; + token->value = estrndup(q, YYCURSOR - q); + token->len = YYCURSOR - q; + q = YYCURSOR; + return 0; } - } else { - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - if (phalcon_array_isset_quick_string(_SERVER, SS("REQUEST_URI"), 1526037309UL)) { - - PHALCON_OBS_NVAR(url); - phalcon_array_fetch_quick_string(&url, _SERVER, SS("REQUEST_URI"), 1526037309UL, PH_NOISY); - - PHALCON_INIT_VAR(url_parts); - phalcon_fast_explode_str(url_parts, SL("?"), url); - - PHALCON_OBS_VAR(real_uri); - phalcon_array_fetch_long(&real_uri, url_parts, 0, PH_NOISY); - if (PHALCON_IS_NOT_EMPTY(real_uri)) { - RETURN_CCTOR(real_uri); +// 170 "scanner.c" +yy4: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy285; + default: goto yy5; } +yy5: +// 353 "scanner.re" + { + token->opcode = PHQL_T_DOT; + return 0; } - } - - RETURN_MM_STRING("/", 1); -} - -static PHP_METHOD(Phalcon_Mvc_Router, setUriSource){ - - zval *uri_source; - - phalcon_fetch_params(0, 1, 0, &uri_source); - - phalcon_update_property_this_quick(this_ptr, SL("_uriSource"), uri_source, 144947845UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, removeExtraSlashes){ - - zval *remove; - - phalcon_fetch_params(0, 1, 0, &remove); - - phalcon_update_property_this_quick(this_ptr, SL("_removeExtraSlashes"), remove, 1065444329UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, setDefaultNamespace){ - - zval *namespace_name; - - phalcon_fetch_params(0, 1, 0, &namespace_name); - - phalcon_update_property_this_quick(this_ptr, SL("_defaultNamespace"), namespace_name, 761145590UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, setDefaultModule){ - - zval *module_name; - - phalcon_fetch_params(0, 1, 0, &module_name); - - phalcon_update_property_this_quick(this_ptr, SL("_defaultModule"), module_name, 3959488399UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, setDefaultController){ - - zval *controller_name; - - phalcon_fetch_params(0, 1, 0, &controller_name); - - phalcon_update_property_this_quick(this_ptr, SL("_defaultController"), controller_name, 1418722861UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, setDefaultAction){ - - zval *action_name; - - phalcon_fetch_params(0, 1, 0, &action_name); - - phalcon_update_property_this_quick(this_ptr, SL("_defaultAction"), action_name, 895696999UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, setDefaults){ - - zval *defaults, *namespace_name, *module_name; - zval *controller_name, *action_name, *params; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &defaults); - - if (Z_TYPE_P(defaults) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "Defaults must be an array"); - return; - } - - if (phalcon_array_isset_quick_string(defaults, SS("namespace"), 545490034UL)) { - PHALCON_OBS_VAR(namespace_name); - phalcon_array_fetch_quick_string(&namespace_name, defaults, SS("namespace"), 545490034UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_defaultNamespace"), namespace_name, 761145590UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(defaults, SS("module"), 3565923467UL)) { - PHALCON_OBS_VAR(module_name); - phalcon_array_fetch_quick_string(&module_name, defaults, SS("module"), 3565923467UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_defaultModule"), module_name, 3959488399UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(defaults, SS("controller"), 2892024105UL)) { - PHALCON_OBS_VAR(controller_name); - phalcon_array_fetch_quick_string(&controller_name, defaults, SS("controller"), 2892024105UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_defaultController"), controller_name, 1418722861UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(defaults, SS("action"), 502132067UL)) { - PHALCON_OBS_VAR(action_name); - phalcon_array_fetch_quick_string(&action_name, defaults, SS("action"), 502132067UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_defaultAction"), action_name, 895696999UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(defaults, SS("params"), 2613350281UL)) { - PHALCON_OBS_VAR(params); - phalcon_array_fetch_quick_string(¶ms, defaults, SS("params"), 2613350281UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_defaultParams"), params, 3006915213UL TSRMLS_CC); - } - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, handle){ - - zval *uri = NULL, *real_uri = NULL, *remove_extra_slashes; - zval *handled_uri = NULL, *request = NULL, *current_host_name = NULL; - zval *route_found = NULL, *parts = NULL, *params = NULL, *matches, *routes; - zval *route = NULL, *methods = NULL, *dependency_injector = NULL; - zval *service = NULL, *match_method = NULL, *hostname = NULL, *regex_host_name = NULL; - zval *matched = NULL, *pattern = NULL, *before_match = NULL, *before_match_params = NULL; - zval *paths = NULL, *converters = NULL, *position = NULL, *part = NULL, *match_position = NULL; - zval *parameters = NULL, *converter = NULL, *converted_part = NULL; - zval *not_found_paths, *namespace, *default_namespace = NULL; - zval *module, *default_module = NULL, *controller, *default_controller = NULL; - zval *action, *default_action = NULL, *params_str, *str_params; - zval *slash, *params_merge = NULL, *default_params; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &uri); - - if (!uri) { - PHALCON_INIT_VAR(uri); - } - - if (!zend_is_true(uri)) { - PHALCON_INIT_VAR(real_uri); - phalcon_call_method_key(real_uri, this_ptr, "getrewriteuri", 1631494103UL); - } else { - PHALCON_CPY_WRT(real_uri, uri); - } - - PHALCON_OBS_VAR(remove_extra_slashes); - phalcon_read_property_this_quick(&remove_extra_slashes, this_ptr, SL("_removeExtraSlashes"), 1065444329UL, PH_NOISY_CC); - if (zend_is_true(remove_extra_slashes)) { - PHALCON_INIT_VAR(handled_uri); - phalcon_remove_extra_slashes(handled_uri, real_uri); - } else { - PHALCON_CPY_WRT(handled_uri, real_uri); - } - - PHALCON_INIT_VAR(request); - - PHALCON_INIT_VAR(current_host_name); - - PHALCON_INIT_VAR(route_found); - ZVAL_BOOL(route_found, 0); - - PHALCON_INIT_VAR(parts); - array_init(parts); - - PHALCON_INIT_VAR(params); - array_init(params); - - PHALCON_INIT_VAR(matches); - phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 0 TSRMLS_CC); - phalcon_update_property_null(this_ptr, SL("_matchedRoute") TSRMLS_CC); - - PHALCON_OBS_VAR(routes); - phalcon_read_property_this_quick(&routes, this_ptr, SL("_routes"), 2063827110UL, PH_NOISY_CC); - - phalcon_is_iterable(routes, &ah0, &hp0, 0, 1); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(route); - - PHALCON_INIT_NVAR(methods); - phalcon_call_method_key(methods, route, "gethttpmethods", 3411360217UL); - if (Z_TYPE_P(methods) != IS_NULL) { - - if (Z_TYPE_P(request) == IS_NULL) { - - PHALCON_OBS_NVAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "A dependency injection container is required to access the 'request' service"); - return; - } - - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "request", 1); - - PHALCON_INIT_NVAR(request); - phalcon_call_method_p1_key(request, dependency_injector, "getshared", service, 1727570332UL); - } - - PHALCON_INIT_NVAR(match_method); - phalcon_call_method_p1_key(match_method, request, "ismethod", methods, 2504815042UL); - if (PHALCON_IS_FALSE(match_method)) { - zend_hash_move_backwards_ex(ah0, &hp0); - continue; +// 192 "scanner.c" +yy6: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy282; + default: goto yy7; } +yy7: +// 448 "scanner.re" + { + status = PHQL_SCANNER_RETCODE_ERR; + break; } - - PHALCON_INIT_NVAR(hostname); - phalcon_call_method_key(hostname, route, "gethostname", 3942718116UL); - if (Z_TYPE_P(hostname) != IS_NULL) { - - if (Z_TYPE_P(request) == IS_NULL) { - - PHALCON_OBS_NVAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "A dependency injection container is required to access the 'request' service"); - return; - } - - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "request", 1); - - PHALCON_INIT_NVAR(request); - phalcon_call_method_p1_key(request, dependency_injector, "getshared", service, 1727570332UL); - } - - if (Z_TYPE_P(current_host_name) == IS_NULL) { - PHALCON_INIT_NVAR(current_host_name); - phalcon_call_method_key(current_host_name, request, "gethttphost", 3414889219UL); +// 214 "scanner.c" +yy8: + yyaccept = 0; + yych = *(YYMARKER = ++YYCURSOR); + switch (yych) { + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy278; + default: goto yy9; } - - if (Z_TYPE_P(current_host_name) == IS_NULL) { - zend_hash_move_backwards_ex(ah0, &hp0); - continue; +yy9: +// 358 "scanner.re" + { + token->opcode = PHQL_T_COLON; + return 0; + } +// 291 "scanner.c" +yy10: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case 'P': + case 'p': goto yy267; + case 'S': + case 's': goto yy268; + default: goto yy87; } - - PHALCON_INIT_NVAR(matched); - if (phalcon_memnstr_str(hostname, SL("("))) { - if (!phalcon_memnstr_str(hostname, SL("#"))) { - PHALCON_INIT_NVAR(regex_host_name); - PHALCON_CONCAT_SVS(regex_host_name, "#^", hostname, "$#"); +yy11: +// 301 "scanner.re" + { + token->opcode = PHQL_T_IDENTIFIER; + if ((YYCURSOR - q) > 1) { + if (q[0] == '\\') { + token->value = estrndup(q + 1, YYCURSOR - q - 1); + token->len = YYCURSOR - q - 1; } else { - PHALCON_CPY_WRT(regex_host_name, hostname); + token->value = estrndup(q, YYCURSOR - q); + token->len = YYCURSOR - q; } - - phalcon_preg_match(matched, regex_host_name, current_host_name, NULL TSRMLS_CC); } else { - is_equal_function(matched, current_host_name, hostname TSRMLS_CC); - } - - if (!zend_is_true(matched)) { - zend_hash_move_backwards_ex(ah0, &hp0); - continue; + token->value = estrndup(q, YYCURSOR - q); + token->len = YYCURSOR - q; } + q = YYCURSOR; + return 0; } - - PHALCON_INIT_NVAR(pattern); - phalcon_call_method_key(pattern, route, "getcompiledpattern", 1538259504UL); - - PHALCON_INIT_NVAR(route_found); - if (phalcon_memnstr_str(pattern, SL("^"))) { - phalcon_preg_match(route_found, pattern, handled_uri, matches TSRMLS_CC); - } else { - is_equal_function(route_found, pattern, handled_uri TSRMLS_CC); - } - - if (zend_is_true(route_found)) { - - PHALCON_INIT_NVAR(before_match); - phalcon_call_method_key(before_match, route, "getbeforematch", 3030065829UL); - if (Z_TYPE_P(before_match) != IS_NULL) { - - if (!phalcon_is_callable(before_match TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "Before-Match callback is not callable in matched route"); - return; - } - - PHALCON_INIT_NVAR(before_match_params); - array_init_size(before_match_params, 3); - phalcon_array_append(&before_match_params, handled_uri, PH_SEPARATE); - phalcon_array_append(&before_match_params, route, PH_SEPARATE); - phalcon_array_append(&before_match_params, this_ptr, PH_SEPARATE); - - PHALCON_INIT_NVAR(route_found); - PHALCON_CALL_USER_FUNC_ARRAY(route_found, before_match, params); +// 320 "scanner.c" +yy12: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy259; + default: goto yy87; } - } - - if (zend_is_true(route_found)) { - - PHALCON_INIT_NVAR(paths); - phalcon_call_method_key(paths, route, "getpaths", 4092132037UL); - PHALCON_CPY_WRT(parts, paths); - - if (Z_TYPE_P(matches) == IS_ARRAY) { - - PHALCON_INIT_NVAR(converters); - phalcon_call_method_key(converters, route, "getconverters", 441740624UL); - - phalcon_is_iterable(paths, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HKEY(part, ah1, hp1); - PHALCON_GET_HVALUE(position); - - if (phalcon_array_isset(matches, position)) { - - PHALCON_OBS_NVAR(match_position); - phalcon_array_fetch(&match_position, matches, position, PH_NOISY); - - if (Z_TYPE_P(converters) == IS_ARRAY) { - if (phalcon_array_isset(converters, part)) { - PHALCON_INIT_NVAR(parameters); - array_init_size(parameters, 1); - phalcon_array_append(¶meters, match_position, PH_SEPARATE); - - PHALCON_OBS_NVAR(converter); - phalcon_array_fetch(&converter, converters, part, PH_NOISY); - - PHALCON_INIT_NVAR(converted_part); - PHALCON_CALL_USER_FUNC_ARRAY(converted_part, converter, parameters); - phalcon_array_update_zval(&parts, part, &converted_part, PH_COPY | PH_SEPARATE); - zend_hash_move_forward_ex(ah1, &hp1); - continue; - } - } - - phalcon_array_update_zval(&parts, part, &match_position, PH_COPY | PH_SEPARATE); - } else { - if (Z_TYPE_P(converters) == IS_ARRAY) { - if (phalcon_array_isset(converters, part)) { - PHALCON_INIT_NVAR(parameters); - array_init_size(parameters, 1); - phalcon_array_append(¶meters, position, PH_SEPARATE); - - PHALCON_OBS_NVAR(converter); - phalcon_array_fetch(&converter, converters, part, PH_NOISY); - - PHALCON_INIT_NVAR(converted_part); - PHALCON_CALL_USER_FUNC_ARRAY(converted_part, converter, parameters); - phalcon_array_update_zval(&parts, part, &converted_part, PH_COPY | PH_SEPARATE); - } - } - } - - zend_hash_move_forward_ex(ah1, &hp1); - } - - phalcon_update_property_this_quick(this_ptr, SL("_matches"), matches, 83085737UL TSRMLS_CC); +yy13: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy242; + case 'I': + case 'i': goto yy243; + default: goto yy87; } - - phalcon_update_property_this_quick(this_ptr, SL("_matchedRoute"), route, 3232330313UL TSRMLS_CC); - break; - } - - zend_hash_move_backwards_ex(ah0, &hp0); - } - - if (zend_is_true(route_found)) { - phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 1 TSRMLS_CC); - } else { - phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 0 TSRMLS_CC); - } - - if (!zend_is_true(route_found)) { - - PHALCON_OBS_VAR(not_found_paths); - phalcon_read_property_this_quick(¬_found_paths, this_ptr, SL("_notFoundPaths"), 189519377UL, PH_NOISY_CC); - if (Z_TYPE_P(not_found_paths) != IS_NULL) { - PHALCON_CPY_WRT(parts, not_found_paths); - - PHALCON_INIT_NVAR(route_found); - ZVAL_BOOL(route_found, 1); - } - } - - if (zend_is_true(route_found)) { - - if (phalcon_array_isset_quick_string(parts, SS("namespace"), 545490034UL)) { - - PHALCON_OBS_VAR(namespace); - phalcon_array_fetch_quick_string(&namespace, parts, SS("namespace"), 545490034UL, PH_NOISY); - if (!phalcon_is_numeric(namespace)) { - phalcon_update_property_this_quick(this_ptr, SL("_namespace"), namespace, 1403433009UL TSRMLS_CC); +yy14: + yych = *++YYCURSOR; + switch (yych) { + case 'A': + case 'a': goto yy229; + case 'R': + case 'r': goto yy230; + case 'U': + case 'u': goto yy231; + default: goto yy87; } - - phalcon_array_unset_string(&parts, SS("namespace"), PH_SEPARATE); - } else { - PHALCON_OBS_VAR(default_namespace); - phalcon_read_property_this_quick(&default_namespace, this_ptr, SL("_defaultNamespace"), 761145590UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_namespace"), default_namespace, 1403433009UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(parts, SS("module"), 3565923467UL)) { - - PHALCON_OBS_VAR(module); - phalcon_array_fetch_quick_string(&module, parts, SS("module"), 3565923467UL, PH_NOISY); - if (!phalcon_is_numeric(module)) { - phalcon_update_property_this_quick(this_ptr, SL("_module"), module, 4176304298UL TSRMLS_CC); +yy15: + yych = *++YYCURSOR; + switch (yych) { + case 'G': + case 'g': goto yy215; + case 'N': + case 'n': goto yy216; + case 'S': + case 's': goto yy217; + default: goto yy87; } - - phalcon_array_unset_string(&parts, SS("module"), PH_SEPARATE); - } else { - PHALCON_OBS_VAR(default_module); - phalcon_read_property_this_quick(&default_module, this_ptr, SL("_defaultModule"), 3959488399UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_module"), default_module, 4176304298UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(parts, SS("controller"), 2892024105UL)) { - - PHALCON_OBS_VAR(controller); - phalcon_array_fetch_quick_string(&controller, parts, SS("controller"), 2892024105UL, PH_NOISY); - if (!phalcon_is_numeric(controller)) { - phalcon_update_property_this_quick(this_ptr, SL("_controller"), controller, 1139371208UL TSRMLS_CC); +yy16: + yych = *++YYCURSOR; + switch (yych) { + case 'L': + case 'l': goto yy194; + case 'N': + case 'n': goto yy195; + case 'S': + case 's': goto yy197; + default: goto yy87; } - - phalcon_array_unset_string(&parts, SS("controller"), PH_SEPARATE); - } else { - PHALCON_OBS_VAR(default_controller); - phalcon_read_property_this_quick(&default_controller, this_ptr, SL("_defaultController"), 1418722861UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_controller"), default_controller, 1139371208UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(parts, SS("action"), 502132067UL)) { - - PHALCON_OBS_VAR(action); - phalcon_array_fetch_quick_string(&action, parts, SS("action"), 502132067UL, PH_NOISY); - if (!phalcon_is_numeric(action)) { - phalcon_update_property_this_quick(this_ptr, SL("_action"), action, 1112512898UL TSRMLS_CC); +yy17: + yych = *++YYCURSOR; + switch (yych) { + case 'A': + case 'a': goto yy188; + default: goto yy87; } - - phalcon_array_unset_string(&parts, SS("action"), PH_SEPARATE); - } else { - PHALCON_OBS_VAR(default_action); - phalcon_read_property_this_quick(&default_action, this_ptr, SL("_defaultAction"), 895696999UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_action"), default_action, 1112512898UL TSRMLS_CC); - } - - if (phalcon_array_isset_quick_string(parts, SS("params"), 2613350281UL)) { - - PHALCON_OBS_VAR(params_str); - phalcon_array_fetch_quick_string(¶ms_str, parts, SS("params"), 2613350281UL, PH_NOISY); - - PHALCON_INIT_VAR(str_params); - phalcon_substr(str_params, params_str, 1, 0); - if (zend_is_true(str_params)) { - PHALCON_INIT_VAR(slash); - ZVAL_STRING(slash, "/", 1); - - PHALCON_INIT_NVAR(params); - phalcon_fast_explode(params, slash, str_params); +yy18: + yych = *++YYCURSOR; + switch (yych) { + case 'H': + case 'h': goto yy183; + default: goto yy87; } - - phalcon_array_unset_string(&parts, SS("params"), PH_SEPARATE); - } - - if (phalcon_fast_count_ev(params TSRMLS_CC)) { - PHALCON_INIT_VAR(params_merge); - phalcon_fast_array_merge(params_merge, ¶ms, &parts TSRMLS_CC); - } else { - PHALCON_CPY_WRT(params_merge, parts); - } - - phalcon_update_property_this_quick(this_ptr, SL("_params"), params_merge, 3223731112UL TSRMLS_CC); - } else { - PHALCON_OBS_NVAR(default_namespace); - phalcon_read_property_this_quick(&default_namespace, this_ptr, SL("_defaultNamespace"), 761145590UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_namespace"), default_namespace, 1403433009UL TSRMLS_CC); - - PHALCON_OBS_NVAR(default_module); - phalcon_read_property_this_quick(&default_module, this_ptr, SL("_defaultModule"), 3959488399UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_module"), default_module, 4176304298UL TSRMLS_CC); - - PHALCON_OBS_NVAR(default_controller); - phalcon_read_property_this_quick(&default_controller, this_ptr, SL("_defaultController"), 1418722861UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_controller"), default_controller, 1139371208UL TSRMLS_CC); - - PHALCON_OBS_NVAR(default_action); - phalcon_read_property_this_quick(&default_action, this_ptr, SL("_defaultAction"), 895696999UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_action"), default_action, 1112512898UL TSRMLS_CC); - - PHALCON_OBS_VAR(default_params); - phalcon_read_property_this_quick(&default_params, this_ptr, SL("_defaultParams"), 3006915213UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_params"), default_params, 3223731112UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, add){ - - zval *pattern, *paths = NULL, *http_methods = NULL, *route; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - if (!http_methods) { - PHALCON_INIT_VAR(http_methods); - } - - PHALCON_INIT_VAR(route); - object_init_ex(route, phalcon_mvc_router_route_ce); - phalcon_call_method_p3_key(NULL, route, "__construct", pattern, paths, http_methods, 1107214344UL); - - phalcon_update_property_array_append(this_ptr, SL("_routes"), route TSRMLS_CC); - RETURN_CTOR(route); -} - -static PHP_METHOD(Phalcon_Mvc_Router, addGet){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "GET", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, addPost){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "POST", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, addPut){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "PUT", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, addPatch){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "PATCH", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, addDelete){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "DELETE", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, addOptions){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "OPTIONS", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, addHead){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "HEAD", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, mount){ - - zval *group, *group_routes, *before_match, *route = NULL; - zval *hostname, *routes, *new_routes; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &group); - - if (Z_TYPE_P(group) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The group of routes is not valid"); - return; - } - - PHALCON_INIT_VAR(group_routes); - phalcon_call_method_key(group_routes, group, "getroutes", 733840903UL); - if (!phalcon_fast_count_ev(group_routes TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The group of routes does not contain any routes"); - return; - } - - PHALCON_INIT_VAR(before_match); - phalcon_call_method_key(before_match, group, "getbeforematch", 3030065829UL); - if (Z_TYPE_P(before_match) != IS_NULL) { - - phalcon_is_iterable(group_routes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(route); - - phalcon_call_method_p1_key(NULL, route, "beforematch", before_match, 1794408741UL); - - zend_hash_move_forward_ex(ah0, &hp0); +yy19: + yych = *++YYCURSOR; + switch (yych) { + case 'F': + case 'f': goto yy164; + case 'N': + case 'n': goto yy165; + case 'R': + case 'r': goto yy167; + case 'U': + case 'u': goto yy169; + default: goto yy87; + } +yy20: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy155; + case 'Y': + case 'y': goto yy156; + default: goto yy87; + } +yy21: + yych = *++YYCURSOR; + switch (yych) { + case 'R': + case 'r': goto yy150; + default: goto yy87; + } +yy22: + yych = *++YYCURSOR; + switch (yych) { + case 'A': + case 'a': goto yy144; + default: goto yy87; + } +yy23: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy132; + case 'I': + case 'i': goto yy133; + default: goto yy87; + } +yy24: + yych = *++YYCURSOR; + switch (yych) { + case 'O': + case 'o': goto yy125; + case 'U': + case 'u': goto yy126; + default: goto yy87; + } +yy25: + yych = *++YYCURSOR; + switch (yych) { + case 'O': + case 'o': goto yy121; + default: goto yy87; + } +yy26: + yych = *++YYCURSOR; + switch (yych) { + case 'I': + case 'i': goto yy116; + default: goto yy87; + } +yy27: + yych = *++YYCURSOR; + switch (yych) { + case 'A': + case 'a': goto yy100; + case 'O': + case 'o': goto yy101; + case 'R': + case 'r': goto yy102; + default: goto yy87; + } +yy28: + yych = *++YYCURSOR; + switch (yych) { + case 'R': + case 'r': goto yy96; + default: goto yy87; + } +yy29: + yyaccept = 1; + yych = *(YYMARKER = ++YYCURSOR); + if (yych <= 0x00) goto yy7; + goto yy94; +yy30: + yyaccept = 1; + yych = *(YYMARKER = ++YYCURSOR); + if (yych <= 0x00) goto yy7; + goto yy89; +yy31: + yych = *++YYCURSOR; + switch (yych) { + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy7; + } +yy32: + yych = *++YYCURSOR; + goto yy87; +yy33: + yyaccept = 1; + yych = *(YYMARKER = ++YYCURSOR); + switch (yych) { + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy81; + default: goto yy7; + } +yy34: + ++YYCURSOR; +// 328 "scanner.re" + { + token->opcode = PHQL_T_ADD; + return 0; } - - } - - PHALCON_INIT_VAR(hostname); - phalcon_call_method_key(hostname, group, "gethostname", 3942718116UL); - if (Z_TYPE_P(hostname) != IS_NULL) { - - phalcon_is_iterable(group_routes, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(route); - - phalcon_call_method_p1_key(NULL, route, "sethostname", hostname, 912882480UL); - - zend_hash_move_forward_ex(ah1, &hp1); +// 608 "scanner.c" +yy36: + ++YYCURSOR; +// 333 "scanner.re" + { + token->opcode = PHQL_T_SUB; + return 0; } - - } - - PHALCON_OBS_VAR(routes); - phalcon_read_property_this_quick(&routes, this_ptr, SL("_routes"), 2063827110UL, PH_NOISY_CC); - if (Z_TYPE_P(routes) == IS_ARRAY) { - PHALCON_INIT_VAR(new_routes); - phalcon_fast_array_merge(new_routes, &routes, &group_routes TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_routes"), new_routes, 2063827110UL TSRMLS_CC); - } else { - phalcon_update_property_this_quick(this_ptr, SL("_routes"), group_routes, 2063827110UL TSRMLS_CC); - } - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, notFound){ - - zval *paths; - - phalcon_fetch_params(0, 1, 0, &paths); - - if (Z_TYPE_P(paths) != IS_ARRAY) { - if (Z_TYPE_P(paths) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_router_exception_ce, "The not-found paths must be an array or string"); - return; +// 616 "scanner.c" +yy38: + ++YYCURSOR; +// 338 "scanner.re" + { + token->opcode = PHQL_T_MUL; + return 0; } - } - phalcon_update_property_this_quick(this_ptr, SL("_notFoundPaths"), paths, 189519377UL TSRMLS_CC); - - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, clear){ - - zval *empty_routes; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(empty_routes); - array_init(empty_routes); - phalcon_update_property_this_quick(this_ptr, SL("_routes"), empty_routes, 2063827110UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Router, getNamespaceName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_namespace", 1403433009UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router, getModuleName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_module", 4176304298UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router, getControllerName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_controller", 1139371208UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router, getActionName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_action", 1112512898UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router, getParams){ - - - RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router, getMatchedRoute){ - - - RETURN_MEMBER_QUICK(this_ptr, "_matchedRoute", 3232330313UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router, getMatches){ - - - RETURN_MEMBER_QUICK(this_ptr, "_matches", 83085737UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router, wasMatched){ - - - RETURN_MEMBER_QUICK(this_ptr, "_wasMatched", 2908823365UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router, getRoutes){ - - - RETURN_MEMBER_QUICK(this_ptr, "_routes", 2063827110UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router, getRouteById){ - - zval *id, *routes, *route = NULL, *route_id = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &id); - - PHALCON_OBS_VAR(routes); - phalcon_read_property_this_quick(&routes, this_ptr, SL("_routes"), 2063827110UL, PH_NOISY_CC); - - phalcon_is_iterable(routes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(route); - - PHALCON_INIT_NVAR(route_id); - phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); - if (PHALCON_IS_EQUAL(route_id, id)) { - RETURN_CCTOR(route); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Router, getRouteByName){ - - zval *name, *routes, *route = NULL, *route_name = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(routes); - phalcon_read_property_this_quick(&routes, this_ptr, SL("_routes"), 2063827110UL, PH_NOISY_CC); - - phalcon_is_iterable(routes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(route); - - PHALCON_INIT_NVAR(route_name); - phalcon_call_method_key(route_name, route, "getname", 4286441094UL); - if (PHALCON_IS_EQUAL(route_name, name)) { - RETURN_CCTOR(route); +// 624 "scanner.c" +yy40: + ++YYCURSOR; +// 343 "scanner.re" + { + token->opcode = PHQL_T_DIV; + return 0; } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_MM_FALSE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Group){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Router, Group, mvc_router_group, phalcon_mvc_router_group_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_router_group_ce, SL("_prefix"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_group_ce, SL("_hostname"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_group_ce, SL("_paths"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_group_ce, SL("_routes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_group_ce, SL("_beforeMatch"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, __construct){ - - zval *paths = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - if (Z_TYPE_P(paths) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_paths"), paths, 2700778884UL TSRMLS_CC); - } else { - if (Z_TYPE_P(paths) == IS_STRING) { - phalcon_update_property_this_quick(this_ptr, SL("_paths"), paths, 2700778884UL TSRMLS_CC); +// 632 "scanner.c" +yy42: + ++YYCURSOR; +// 348 "scanner.re" + { + token->opcode = PHQL_T_MOD; + return 0; } - } - if (phalcon_method_quick_exists_ex(this_ptr, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_p1_key(NULL, this_ptr, "initialize", paths, 2896075127UL); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, setHostname){ - - zval *hostname; - - phalcon_fetch_params(0, 1, 0, &hostname); - - phalcon_update_property_this_quick(this_ptr, SL("_hostname"), hostname, 598751491UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, getHostname){ - - - RETURN_MEMBER_QUICK(this_ptr, "_hostname", 598751491UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, setPrefix){ - - zval *prefix; - - phalcon_fetch_params(0, 1, 0, &prefix); - - phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, getPrefix){ - - - RETURN_MEMBER_QUICK(this_ptr, "_prefix", 3873791314UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, beforeMatch){ - - zval *before_match; - - phalcon_fetch_params(0, 1, 0, &before_match); - - phalcon_update_property_this_quick(this_ptr, SL("_beforeMatch"), before_match, 2834072708UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, getBeforeMatch){ - - - RETURN_MEMBER_QUICK(this_ptr, "_beforeMatch", 2834072708UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, setPaths){ - - zval *paths; - - phalcon_fetch_params(0, 1, 0, &paths); - - phalcon_update_property_this_quick(this_ptr, SL("_paths"), paths, 2700778884UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, getPaths){ - - - RETURN_MEMBER_QUICK(this_ptr, "_paths", 2700778884UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, getRoutes){ - - - RETURN_MEMBER_QUICK(this_ptr, "_routes", 2063827110UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, _addRoute){ - - zval *pattern, *paths = NULL, *http_methods = NULL, *prefix, *prefix_pattern; - zval *default_paths, *merged_paths = NULL, *route; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - if (!http_methods) { - PHALCON_INIT_VAR(http_methods); - } - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefix_pattern); - PHALCON_CONCAT_VV(prefix_pattern, prefix, pattern); - - PHALCON_OBS_VAR(default_paths); - phalcon_read_property_this_quick(&default_paths, this_ptr, SL("_paths"), 2700778884UL, PH_NOISY_CC); - - if (Z_TYPE_P(default_paths) == IS_ARRAY) { - if (Z_TYPE_P(paths) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_paths); - phalcon_fast_array_merge(merged_paths, &default_paths, &paths TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_paths, default_paths); +// 640 "scanner.c" +yy44: + ++YYCURSOR; +// 363 "scanner.re" + { + token->opcode = PHQL_T_COMMA; + return 0; } - } else { - PHALCON_CPY_WRT(merged_paths, paths); - } - - PHALCON_INIT_VAR(route); - object_init_ex(route, phalcon_mvc_router_route_ce); - phalcon_call_method_p3_key(NULL, route, "__construct", prefix_pattern, merged_paths, http_methods, 1107214344UL); - - phalcon_update_property_array_append(this_ptr, SL("_routes"), route TSRMLS_CC); - - RETURN_CTOR(route); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, add){ - - zval *pattern, *paths = NULL, *http_methods = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - if (!http_methods) { - PHALCON_INIT_VAR(http_methods); - } - - phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, http_methods, 1178487196UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, addGet){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "GET", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, addPost){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "POST", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, addPut){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "PUT", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, addPatch){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "PATCH", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, addDelete){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "DELETE", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, addOptions){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "OPTIONS", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, addHead){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "HEAD", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, clear){ - - zval *empty_routes; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(empty_routes); - array_init(empty_routes); - phalcon_update_property_this_quick(this_ptr, SL("_routes"), empty_routes, 2063827110UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Route){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Router, Route, mvc_router_route, phalcon_mvc_router_route_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_pattern"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_compiledPattern"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_paths"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_methods"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_hostname"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_converters"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_id"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_beforeMatch"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_uniqueId"), ZEND_ACC_STATIC|ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_router_route_ce TSRMLS_CC, 1, phalcon_mvc_router_routeinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, __construct){ - - zval *pattern, *paths = NULL, *http_methods = NULL, *unique_id = NULL; - zval *route_id = NULL, *one, *next_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - if (!http_methods) { - PHALCON_INIT_VAR(http_methods); - } - - phalcon_call_method_p2_key(NULL, this_ptr, "reconfigure", pattern, paths, 18237790UL); - - phalcon_update_property_this_quick(this_ptr, SL("_methods"), http_methods, 960170392UL TSRMLS_CC); - - PHALCON_OBS_VAR(unique_id); - phalcon_read_static_property(&unique_id, SL("phalcon\\mvc\\router\\route"), SL("_uniqueId") TSRMLS_CC); - if (Z_TYPE_P(unique_id) == IS_NULL) { - PHALCON_INIT_NVAR(unique_id); - ZVAL_LONG(unique_id, 0); - } - - PHALCON_CPY_WRT(route_id, unique_id); - phalcon_update_property_this_quick(this_ptr, SL("_id"), route_id, 2090005265UL TSRMLS_CC); - - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - PHALCON_INIT_VAR(next_id); - phalcon_add_function(next_id, unique_id, one TSRMLS_CC); - phalcon_update_static_property(SL("phalcon\\mvc\\router\\route"), SL("_uniqueId"), next_id TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, compilePattern){ - - zval *pattern, *compiled_pattern = NULL, *id_pattern; - zval *wildcard = NULL, *pattern_copy = NULL, *params_pattern; - zval *int_pattern; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &pattern); - - PHALCON_CPY_WRT(compiled_pattern, pattern); - - if (phalcon_memnstr_str(pattern, SL(":"))) { - - PHALCON_INIT_VAR(id_pattern); - ZVAL_STRING(id_pattern, "/([a-zA-Z0-9\\_\\-]+)", 1); - - if (phalcon_memnstr_str(pattern, SL("/:module"))) { - PHALCON_INIT_VAR(wildcard); - ZVAL_STRING(wildcard, "/:module", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); - - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); +// 648 "scanner.c" +yy46: + ++YYCURSOR; +// 368 "scanner.re" + { + token->opcode = PHQL_T_PARENTHESES_OPEN; + return 0; } - - if (phalcon_memnstr_str(pattern, SL("/:controller"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:controller", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); - - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); +// 656 "scanner.c" +yy48: + ++YYCURSOR; +// 373 "scanner.re" + { + token->opcode = PHQL_T_PARENTHESES_CLOSE; + return 0; } - - if (phalcon_memnstr_str(pattern, SL("/:namespace"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:namespace", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); - - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); +// 664 "scanner.c" +yy50: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '=': goto yy79; + default: goto yy51; + } +yy51: +// 413 "scanner.re" + { + token->opcode = PHQL_T_NOT; + return 0; } - - if (phalcon_memnstr_str(pattern, SL("/:action"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:action", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); - - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); +// 677 "scanner.c" +yy52: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '=': goto yy75; + case '>': goto yy77; + default: goto yy53; + } +yy53: +// 398 "scanner.re" + { + token->opcode = PHQL_T_LESS; + return 0; } - - if (phalcon_memnstr_str(pattern, SL("/:params"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:params", 1); - - PHALCON_INIT_VAR(params_pattern); - ZVAL_STRING(params_pattern, "(/.*)*", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); - - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, params_pattern, pattern_copy); +// 691 "scanner.c" +yy54: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '=': goto yy73; + default: goto yy55; + } +yy55: +// 403 "scanner.re" + { + token->opcode = PHQL_T_GREATER; + return 0; } - - if (phalcon_memnstr_str(pattern, SL("/:int"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:int", 1); - - PHALCON_INIT_VAR(int_pattern); - ZVAL_STRING(int_pattern, "/([0-9]+)", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); - - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, int_pattern, pattern_copy); +// 704 "scanner.c" +yy56: + ++YYCURSOR; +// 408 "scanner.re" + { + token->opcode = PHQL_T_EQUALS; + return 0; } - } - - if (phalcon_memnstr_str(compiled_pattern, SL("("))) { - PHALCON_CONCAT_SVS(return_value, "#^", compiled_pattern, "$#"); - RETURN_MM(); - } - - if (phalcon_memnstr_str(compiled_pattern, SL("["))) { - PHALCON_CONCAT_SVS(return_value, "#^", compiled_pattern, "$#"); - RETURN_MM(); - } - - RETURN_CCTOR(compiled_pattern); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, via){ - - zval *http_methods; - - phalcon_fetch_params(0, 1, 0, &http_methods); - - phalcon_update_property_this_quick(this_ptr, SL("_methods"), http_methods, 960170392UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, reConfigure){ - - zval *pattern, *paths = NULL, *module_name = NULL, *controller_name = NULL; - zval *action_name = NULL, *parts, *number_parts, *route_paths = NULL; - zval *real_class_name = NULL, *namespace_name, *lower_name; - zval *pcre_pattern = NULL, *compiled_pattern = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); - - if (!paths) { - PHALCON_INIT_VAR(paths); - } - - if (Z_TYPE_P(pattern) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The pattern must be string"); - return; - } - if (Z_TYPE_P(paths) != IS_NULL) { - if (Z_TYPE_P(paths) == IS_STRING) { - - PHALCON_INIT_VAR(module_name); - - PHALCON_INIT_VAR(controller_name); - - PHALCON_INIT_VAR(action_name); - - PHALCON_INIT_VAR(parts); - phalcon_fast_explode_str(parts, SL("::"), paths); - - PHALCON_INIT_VAR(number_parts); - phalcon_fast_count(number_parts, parts TSRMLS_CC); - - - switch (phalcon_get_intval(number_parts)) { - - case 3: - PHALCON_OBS_NVAR(module_name); - phalcon_array_fetch_long(&module_name, parts, 0, PH_NOISY); - - PHALCON_OBS_NVAR(controller_name); - phalcon_array_fetch_long(&controller_name, parts, 1, PH_NOISY); - - PHALCON_OBS_NVAR(action_name); - phalcon_array_fetch_long(&action_name, parts, 2, PH_NOISY); - break; - - case 2: - PHALCON_OBS_NVAR(controller_name); - phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); - - PHALCON_OBS_NVAR(action_name); - phalcon_array_fetch_long(&action_name, parts, 1, PH_NOISY); - break; - - case 1: - PHALCON_OBS_NVAR(controller_name); - phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); - break; - - } - - PHALCON_INIT_VAR(route_paths); - array_init(route_paths); - - if (Z_TYPE_P(module_name) != IS_NULL) { - phalcon_array_update_quick_string(&route_paths, SS("module"), 3565923467UL, &module_name, PH_COPY | PH_SEPARATE); +// 712 "scanner.c" +yy58: + ++YYCURSOR; +// 418 "scanner.re" + { + token->opcode = PHQL_T_BITWISE_NOT; + return 0; + } +// 720 "scanner.c" +yy60: + ++YYCURSOR; +// 423 "scanner.re" + { + token->opcode = PHQL_T_BITWISE_XOR; + return 0; + } +// 728 "scanner.c" +yy62: + ++YYCURSOR; +// 428 "scanner.re" + { + token->opcode = PHQL_T_BITWISE_AND; + return 0; + } +// 736 "scanner.c" +yy64: + ++YYCURSOR; +// 433 "scanner.re" + { + token->opcode = PHQL_T_BITWISE_OR; + return 0; + } +// 744 "scanner.c" +yy66: + ++YYCURSOR; + yych = *YYCURSOR; + goto yy72; +yy67: +// 438 "scanner.re" + { + token->opcode = PHQL_T_IGNORE; + return 0; + } +// 755 "scanner.c" +yy68: + ++YYCURSOR; +// 443 "scanner.re" + { + status = PHQL_SCANNER_RETCODE_EOF; + break; + } +// 763 "scanner.c" +yy70: + yych = *++YYCURSOR; + goto yy7; +yy71: + ++YYCURSOR; + yych = *YYCURSOR; +yy72: + switch (yych) { + case '\t': + case '\n': + case '\r': + case ' ': goto yy71; + default: goto yy67; } - - if (Z_TYPE_P(controller_name) != IS_NULL) { - - if (phalcon_memnstr_str(controller_name, SL("\\"))) { - - PHALCON_INIT_VAR(real_class_name); - phalcon_get_class_ns(real_class_name, controller_name, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(namespace_name); - phalcon_get_ns_class(namespace_name, controller_name, 0 TSRMLS_CC); - - if (zend_is_true(namespace_name)) { - phalcon_array_update_quick_string(&route_paths, SS("namespace"), 545490034UL, &namespace_name, PH_COPY | PH_SEPARATE); - } - } else { - PHALCON_CPY_WRT(real_class_name, controller_name); - } - - PHALCON_INIT_VAR(lower_name); - phalcon_uncamelize(lower_name, real_class_name); - - phalcon_array_update_quick_string(&route_paths, SS("controller"), 2892024105UL, &lower_name, PH_COPY | PH_SEPARATE); +yy73: + ++YYCURSOR; +// 393 "scanner.re" + { + token->opcode = PHQL_T_GREATEREQUAL; + return 0; + } +// 785 "scanner.c" +yy75: + ++YYCURSOR; +// 388 "scanner.re" + { + token->opcode = PHQL_T_LESSEQUAL; + return 0; + } +// 793 "scanner.c" +yy77: + ++YYCURSOR; +// 383 "scanner.re" + { + token->opcode = PHQL_T_NOTEQUALS; + return 0; + } +// 801 "scanner.c" +yy79: + ++YYCURSOR; +// 378 "scanner.re" + { + token->opcode = PHQL_T_NOTEQUALS; + return 0; + } +// 809 "scanner.c" +yy81: + ++YYCURSOR; + yych = *YYCURSOR; + switch (yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy81; + case ']': goto yy84; + default: goto yy83; } - - if (Z_TYPE_P(action_name) != IS_NULL) { - phalcon_array_update_quick_string(&route_paths, SS("action"), 502132067UL, &action_name, PH_COPY | PH_SEPARATE); +yy83: + YYCURSOR = YYMARKER; + switch (yyaccept) { + case 0: goto yy9; + case 1: goto yy7; } - } else { - PHALCON_CPY_WRT(route_paths, paths); +yy84: + ++YYCURSOR; +// 320 "scanner.re" + { + token->opcode = PHQL_T_IDENTIFIER; + token->value = estrndup(q, YYCURSOR - q - 1); + token->len = YYCURSOR - q - 1; + q = YYCURSOR; + return 0; } - } else { - PHALCON_INIT_NVAR(route_paths); - array_init(route_paths); - } - - if (Z_TYPE_P(route_paths) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The route contains invalid paths"); - return; - } - - if (!phalcon_start_with_str(pattern, SL("#"))) { - if (phalcon_memnstr_str(pattern, SL("{"))) { - PHALCON_INIT_VAR(pcre_pattern); - phalcon_extract_named_params(pcre_pattern, pattern, route_paths); - } else { - PHALCON_CPY_WRT(pcre_pattern, pattern); +// 897 "scanner.c" +yy86: + ++YYCURSOR; + yych = *YYCURSOR; +yy87: + switch (yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy11; + } +yy88: + ++YYCURSOR; + yych = *YYCURSOR; +yy89: + switch (yych) { + case 0x00: goto yy83; + case '\'': goto yy91; + case '\\': goto yy90; + default: goto yy88; + } +yy90: + ++YYCURSOR; + yych = *YYCURSOR; + switch (yych) { + case '\n': goto yy83; + default: goto yy88; + } +yy91: + ++YYCURSOR; +// 292 "scanner.re" + { + token->opcode = PHQL_T_STRING; + token->value = estrndup(q, YYCURSOR - q - 1); + token->len = YYCURSOR - q - 1; + q = YYCURSOR; + return 0; } - - PHALCON_INIT_VAR(compiled_pattern); - phalcon_call_method_p1_key(compiled_pattern, this_ptr, "compilepattern", pcre_pattern, 2680336012UL); - } else { - PHALCON_CPY_WRT(compiled_pattern, pattern); - } - - phalcon_update_property_this_quick(this_ptr, SL("_pattern"), pattern, 3404429922UL TSRMLS_CC); - - phalcon_update_property_this_quick(this_ptr, SL("_compiledPattern"), compiled_pattern, 4104436623UL TSRMLS_CC); - - phalcon_update_property_this_quick(this_ptr, SL("_paths"), route_paths, 2700778884UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, setName){ - - zval *name; - - phalcon_fetch_params(0, 1, 0, &name); - - phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, beforeMatch){ - - zval *callback; - - phalcon_fetch_params(0, 1, 0, &callback); - - phalcon_update_property_this_quick(this_ptr, SL("_beforeMatch"), callback, 2834072708UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getBeforeMatch){ - - - RETURN_MEMBER_QUICK(this_ptr, "_beforeMatch", 2834072708UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getRouteId){ - - - RETURN_MEMBER_QUICK(this_ptr, "_id", 2090005265UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getPattern){ - - - RETURN_MEMBER_QUICK(this_ptr, "_pattern", 3404429922UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getCompiledPattern){ - - - RETURN_MEMBER_QUICK(this_ptr, "_compiledPattern", 4104436623UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getPaths){ - - - RETURN_MEMBER_QUICK(this_ptr, "_paths", 2700778884UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getReversedPaths){ - - zval *reversed, *paths, *position = NULL, *path = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(reversed); - array_init(reversed); - - PHALCON_OBS_VAR(paths); - phalcon_read_property_this_quick(&paths, this_ptr, SL("_paths"), 2700778884UL, PH_NOISY_CC); - - phalcon_is_iterable(paths, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(path, ah0, hp0); - PHALCON_GET_HVALUE(position); - - phalcon_array_update_zval(&reversed, position, &path, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CTOR(reversed); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, setHttpMethods){ - - zval *http_methods; - - phalcon_fetch_params(0, 1, 0, &http_methods); - - phalcon_update_property_this_quick(this_ptr, SL("_methods"), http_methods, 960170392UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getHttpMethods){ - - - RETURN_MEMBER_QUICK(this_ptr, "_methods", 960170392UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, setHostname){ - - zval *hostname; - - phalcon_fetch_params(0, 1, 0, &hostname); - - phalcon_update_property_this_quick(this_ptr, SL("_hostname"), hostname, 598751491UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getHostname){ - - - RETURN_MEMBER_QUICK(this_ptr, "_hostname", 598751491UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, convert){ - - zval *name, *converter; - - phalcon_fetch_params(0, 2, 0, &name, &converter); - - phalcon_update_property_array(this_ptr, SL("_converters"), name, converter TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getConverters){ - - - RETURN_MEMBER_QUICK(this_ptr, "_converters", 994353007UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, reset){ - - zval *zero; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - phalcon_update_static_property(SL("phalcon\\mvc\\router\\route"), SL("_uniqueId"), zero TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Router, Exception, mvc_router_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Router_RouteInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Router, RouteInterface, mvc_router_routeinterface, phalcon_mvc_router_routeinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Annotations){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Router, Annotations, mvc_router_annotations, "phalcon\\mvc\\router", phalcon_mvc_router_annotations_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_router_annotations_ce, SL("_handlers"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_router_annotations_ce, SL("_processed"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_mvc_router_annotations_ce, SL("_controllerSuffix"), "Controller", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_mvc_router_annotations_ce, SL("_actionSuffix"), "Action", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_router_annotations_ce, SL("_routePrefix"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, addResource){ - - zval *handler, *prefix = NULL, *scope; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &handler, &prefix); - - if (!prefix) { - PHALCON_INIT_VAR(prefix); - } - - if (Z_TYPE_P(handler) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The handler must be a class name"); - return; - } - - PHALCON_INIT_VAR(scope); - array_init_size(scope, 2); - phalcon_array_append(&scope, prefix, PH_SEPARATE); - phalcon_array_append(&scope, handler, PH_SEPARATE); - phalcon_update_property_array_append(this_ptr, SL("_handlers"), scope TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_processed"), 0 TSRMLS_CC); - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, addModuleResource){ - - zval *module, *handler, *prefix = NULL, *scope; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &module, &handler, &prefix); - - if (!prefix) { - PHALCON_INIT_VAR(prefix); - } - - if (Z_TYPE_P(module) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The module is not a valid string"); - return; - } - if (Z_TYPE_P(handler) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The handler must be a class name"); - return; - } - - PHALCON_INIT_VAR(scope); - array_init_size(scope, 3); - phalcon_array_append(&scope, prefix, PH_SEPARATE); - phalcon_array_append(&scope, handler, PH_SEPARATE); - phalcon_array_append(&scope, module, PH_SEPARATE); - phalcon_update_property_array_append(this_ptr, SL("_handlers"), scope TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_processed"), 0 TSRMLS_CC); - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, handle){ - - zval *uri = NULL, *real_uri = NULL, *processed, *annotations_service = NULL; - zval *handlers, *controller_suffix, *scope = NULL, *prefix = NULL; - zval *dependency_injector = NULL, *service = NULL, *handler = NULL; - zval *controller_name = NULL, *lower_controller_name = NULL; - zval *namespace_name = NULL, *module_name = NULL, *sufixed = NULL; - zval *handler_annotations = NULL, *class_annotations = NULL; - zval *annotations = NULL, *annotation = NULL, *method_annotations = NULL; - zval *lowercased = NULL, *collection = NULL, *method = NULL; - HashTable *ah0, *ah1, *ah2, *ah3; - HashPosition hp0, hp1, hp2, hp3; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &uri); - - if (!uri) { - PHALCON_INIT_VAR(uri); - } - - if (!zend_is_true(uri)) { - PHALCON_INIT_VAR(real_uri); - phalcon_call_method_key(real_uri, this_ptr, "getrewriteuri", 1631494103UL); - } else { - PHALCON_CPY_WRT(real_uri, uri); - } - - PHALCON_OBS_VAR(processed); - phalcon_read_property_this_quick(&processed, this_ptr, SL("_processed"), 908491692UL, PH_NOISY_CC); - if (!zend_is_true(processed)) { - - PHALCON_INIT_VAR(annotations_service); - - PHALCON_OBS_VAR(handlers); - phalcon_read_property_this_quick(&handlers, this_ptr, SL("_handlers"), 2445210229UL, PH_NOISY_CC); - if (Z_TYPE_P(handlers) == IS_ARRAY) { - - PHALCON_OBS_VAR(controller_suffix); - phalcon_read_property_this_quick(&controller_suffix, this_ptr, SL("_controllerSuffix"), 2437326621UL, PH_NOISY_CC); - - phalcon_is_iterable(handlers, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(scope); - - if (Z_TYPE_P(scope) == IS_ARRAY) { - - PHALCON_OBS_NVAR(prefix); - phalcon_array_fetch_long(&prefix, scope, 0, PH_NOISY); - if (Z_TYPE_P(prefix) == IS_STRING) { - if (!phalcon_start_with(real_uri, prefix, NULL)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - - if (Z_TYPE_P(annotations_service) != IS_OBJECT) { - - PHALCON_OBS_NVAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "A dependency injection container is required to access the 'annotations' service"); - return; - } - - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "annotations", 1); - - PHALCON_INIT_NVAR(annotations_service); - phalcon_call_method_p1_key(annotations_service, dependency_injector, "getshared", service, 1727570332UL); - } - - PHALCON_OBS_NVAR(handler); - phalcon_array_fetch_long(&handler, scope, 1, PH_NOISY); - if (phalcon_memnstr_str(handler, SL("\\"))) { - PHALCON_INIT_NVAR(controller_name); - phalcon_get_class_ns(controller_name, handler, 0 TSRMLS_CC); - - PHALCON_INIT_NVAR(lower_controller_name); - phalcon_uncamelize(lower_controller_name, controller_name); - - PHALCON_INIT_NVAR(namespace_name); - phalcon_get_ns_class(namespace_name, handler, 0 TSRMLS_CC); - } else { - PHALCON_CPY_WRT(controller_name, handler); - - PHALCON_INIT_NVAR(lower_controller_name); - phalcon_uncamelize(lower_controller_name, controller_name); - - PHALCON_INIT_NVAR(namespace_name); - } - - phalcon_update_property_null(this_ptr, SL("_routePrefix") TSRMLS_CC); - - if (phalcon_array_isset_long(scope, 2)) { - PHALCON_OBS_NVAR(module_name); - phalcon_array_fetch_long(&module_name, scope, 2, PH_NOISY); - } else { - PHALCON_INIT_NVAR(module_name); - } - - PHALCON_INIT_NVAR(sufixed); - PHALCON_CONCAT_VV(sufixed, handler, controller_suffix); - - PHALCON_INIT_NVAR(handler_annotations); - phalcon_call_method_p1_key(handler_annotations, annotations_service, "get", sufixed, 2090288933UL); - - PHALCON_INIT_NVAR(class_annotations); - phalcon_call_method_key(class_annotations, handler_annotations, "getclassannotations", 3984548329UL); - if (Z_TYPE_P(class_annotations) == IS_OBJECT) { - - PHALCON_INIT_NVAR(annotations); - phalcon_call_method_key(annotations, class_annotations, "getannotations", 163297043UL); - if (Z_TYPE_P(annotations) == IS_ARRAY) { - - phalcon_is_iterable(annotations, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(annotation); - - phalcon_call_method_p2_key(NULL, this_ptr, "processcontrollerannotation", controller_name, annotation, 1441174403UL); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - } - } - - PHALCON_INIT_NVAR(method_annotations); - phalcon_call_method_key(method_annotations, handler_annotations, "getmethodsannotations", 2860599943UL); - if (Z_TYPE_P(method_annotations) == IS_ARRAY) { - - PHALCON_INIT_NVAR(lowercased); - phalcon_uncamelize(lowercased, handler); - - phalcon_is_iterable(method_annotations, &ah2, &hp2, 0, 0); - - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - - PHALCON_GET_HKEY(method, ah2, hp2); - PHALCON_GET_HVALUE(collection); - - if (Z_TYPE_P(collection) == IS_OBJECT) { - - PHALCON_INIT_NVAR(annotations); - phalcon_call_method_key(annotations, collection, "getannotations", 163297043UL); - - phalcon_is_iterable(annotations, &ah3, &hp3, 0, 0); - - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - - PHALCON_GET_HVALUE(annotation); - - phalcon_call_method_p5_key(NULL, this_ptr, "processactionannotation", module_name, namespace_name, lower_controller_name, method, annotation, 3018293437UL); - - zend_hash_move_forward_ex(ah3, &hp3); - } - - } - - zend_hash_move_forward_ex(ah2, &hp2); - } - - } - } - - zend_hash_move_forward_ex(ah0, &hp0); +// 996 "scanner.c" +yy93: + ++YYCURSOR; + yych = *YYCURSOR; +yy94: + switch (yych) { + case 0x00: goto yy83; + case '"': goto yy91; + case '\\': goto yy95; + default: goto yy93; } - - } - - phalcon_update_property_bool(this_ptr, SL("_processed"), 1 TSRMLS_CC); - } - - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Mvc\\Router\\Annotations", "handle", real_uri); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, processControllerAnnotation){ - - zval *handler, *annotation, *name, *position, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &handler, &annotation); - - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, annotation, "getname", 4286441094UL); - - if (PHALCON_IS_STRING(name, "RoutePrefix")) { - PHALCON_INIT_VAR(position); - ZVAL_LONG(position, 0); - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, annotation, "getargument", position, 3874091272UL); - phalcon_update_property_this_quick(this_ptr, SL("_routePrefix"), value, 2004814177UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, processActionAnnotation){ - - zval *module, *namespace, *controller, *action; - zval *annotation, *is_route = NULL, *methods = NULL, *name, *action_suffix; - zval *empty_str, *real_action_name, *action_name; - zval *route_prefix, *parameter = NULL, *paths = NULL, *position; - zval *value, *uri = NULL, *route, *converts = NULL, *convert = NULL, *param = NULL; - zval *conversor_param = NULL, *route_name; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 5, 0, &module, &namespace, &controller, &action, &annotation); - - PHALCON_INIT_VAR(is_route); - ZVAL_BOOL(is_route, 0); - - PHALCON_INIT_VAR(methods); - - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, annotation, "getname", 4286441094UL); - - if (PHALCON_IS_STRING(name, "Route")) { - ZVAL_BOOL(is_route, 1); - } else { - if (PHALCON_IS_STRING(name, "Get")) { - PHALCON_INIT_NVAR(is_route); - ZVAL_BOOL(is_route, 1); - - ZVAL_STRING(methods, "GET", 1); - } else { - if (PHALCON_IS_STRING(name, "Post")) { - PHALCON_INIT_NVAR(is_route); - ZVAL_BOOL(is_route, 1); - - PHALCON_INIT_NVAR(methods); - ZVAL_STRING(methods, "POST", 1); - } else { - if (PHALCON_IS_STRING(name, "Put")) { - PHALCON_INIT_NVAR(is_route); - ZVAL_BOOL(is_route, 1); - - PHALCON_INIT_NVAR(methods); - ZVAL_STRING(methods, "PUT", 1); - } else { - if (PHALCON_IS_STRING(name, "Options")) { - PHALCON_INIT_NVAR(is_route); - ZVAL_BOOL(is_route, 1); - - PHALCON_INIT_NVAR(methods); - ZVAL_STRING(methods, "OPTIONS", 1); - } - } +yy95: + ++YYCURSOR; + yych = *YYCURSOR; + switch (yych) { + case '\n': goto yy83; + default: goto yy93; } - } - } - - if (PHALCON_IS_TRUE(is_route)) { - - PHALCON_OBS_VAR(action_suffix); - phalcon_read_property_this_quick(&action_suffix, this_ptr, SL("_actionSuffix"), 879621975UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(empty_str); - ZVAL_STRING(empty_str, "", 1); - - PHALCON_INIT_VAR(real_action_name); - phalcon_fast_str_replace(real_action_name, action_suffix, empty_str, action); - - PHALCON_INIT_VAR(action_name); - phalcon_fast_strtolower(action_name, real_action_name); - - PHALCON_OBS_VAR(route_prefix); - phalcon_read_property_this_quick(&route_prefix, this_ptr, SL("_routePrefix"), 2004814177UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(parameter); - ZVAL_STRING(parameter, "paths", 1); - - PHALCON_INIT_VAR(paths); - phalcon_call_method_p1_key(paths, annotation, "getnamedparameter", parameter, 3202516043UL); - if (Z_TYPE_P(paths) != IS_ARRAY) { - PHALCON_INIT_NVAR(paths); - array_init(paths); - } - - if (Z_TYPE_P(module) == IS_STRING) { - phalcon_array_update_quick_string(&paths, SS("module"), 3565923467UL, &module, PH_COPY | PH_SEPARATE); - } - - if (Z_TYPE_P(namespace) == IS_STRING) { - phalcon_array_update_quick_string(&paths, SS("namespace"), 545490034UL, &namespace, PH_COPY | PH_SEPARATE); - } - - phalcon_array_update_quick_string(&paths, SS("controller"), 2892024105UL, &controller, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&paths, SS("action"), 502132067UL, &action_name, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(position); - ZVAL_LONG(position, 0); - - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, annotation, "getargument", position, 3874091272UL); - - if (Z_TYPE_P(value) != IS_NULL) { - if (!PHALCON_IS_STRING(value, "/")) { - PHALCON_INIT_VAR(uri); - PHALCON_CONCAT_VV(uri, route_prefix, value); - } else { - PHALCON_CPY_WRT(uri, route_prefix); +yy96: + yych = *++YYCURSOR; + switch (yych) { + case 'U': + case 'u': goto yy97; + default: goto yy87; } - } else { - PHALCON_INIT_NVAR(uri); - PHALCON_CONCAT_VV(uri, route_prefix, action_name); - } - - PHALCON_INIT_VAR(route); - phalcon_call_method_p2_key(route, this_ptr, "add", uri, paths, 2090071694UL); - if (Z_TYPE_P(methods) == IS_NULL) { - - PHALCON_INIT_NVAR(parameter); - ZVAL_STRING(parameter, "methods", 1); - - PHALCON_INIT_NVAR(methods); - phalcon_call_method_p1_key(methods, annotation, "getnamedparameter", parameter, 3202516043UL); - if (Z_TYPE_P(methods) == IS_ARRAY) { - phalcon_call_method_p1_key(NULL, route, "via", methods, 2090831717UL); - } else { - if (Z_TYPE_P(methods) == IS_STRING) { - phalcon_call_method_p1_key(NULL, route, "via", methods, 2090831717UL); - } +yy97: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy98; + default: goto yy87; } - } else { - phalcon_call_method_p1_key(NULL, route, "via", methods, 2090831717UL); - } - - PHALCON_INIT_NVAR(parameter); - ZVAL_STRING(parameter, "converts", 1); - - PHALCON_INIT_VAR(converts); - phalcon_call_method_p1_key(converts, annotation, "getnamedparameter", parameter, 3202516043UL); - if (Z_TYPE_P(converts) == IS_ARRAY) { - - phalcon_is_iterable(converts, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(param, ah0, hp0); - PHALCON_GET_HVALUE(convert); - - phalcon_call_method_p2_key(NULL, route, "convert", param, convert, 1120996230UL); - - zend_hash_move_forward_ex(ah0, &hp0); +yy98: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy99; } - +yy99: +// 281 "scanner.re" + { + token->opcode = PHQL_T_TRUE; + return 0; } - - PHALCON_INIT_NVAR(parameter); - ZVAL_STRING(parameter, "conversors", 1); - - PHALCON_INIT_NVAR(converts); - phalcon_call_method_p1_key(converts, annotation, "getnamedparameter", parameter, 3202516043UL); - if (Z_TYPE_P(converts) == IS_ARRAY) { - - phalcon_is_iterable(converts, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HKEY(conversor_param, ah1, hp1); - PHALCON_GET_HVALUE(convert); - - phalcon_call_method_p2_key(NULL, route, "convert", conversor_param, convert, 1120996230UL); - - zend_hash_move_forward_ex(ah1, &hp1); +// 1103 "scanner.c" +yy100: + yych = *++YYCURSOR; + switch (yych) { + case 'S': + case 's': goto yy113; + default: goto yy87; } - +yy101: + yych = *++YYCURSOR; + switch (yych) { + case 'N': + case 'n': goto yy107; + default: goto yy87; + } +yy102: + yych = *++YYCURSOR; + switch (yych) { + case 'O': + case 'o': goto yy103; + default: goto yy87; + } +yy103: + yych = *++YYCURSOR; + switch (yych) { + case 'S': + case 's': goto yy104; + default: goto yy87; + } +yy104: + yych = *++YYCURSOR; + switch (yych) { + case 'S': + case 's': goto yy105; + default: goto yy87; + } +yy105: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy106; + } +yy106: +// 231 "scanner.re" + { + token->opcode = PHQL_T_CROSS; + return 0; } - - PHALCON_INIT_NVAR(parameter); - ZVAL_STRING(parameter, "name", 1); - - PHALCON_INIT_VAR(route_name); - phalcon_call_method_p1_key(route_name, annotation, "getnamedparameter", parameter, 3202516043UL); - if (Z_TYPE_P(route_name) == IS_STRING) { - phalcon_call_method_p1_key(NULL, route, "setname", route_name, 311681298UL); +// 1214 "scanner.c" +yy107: + yych = *++YYCURSOR; + switch (yych) { + case 'V': + case 'v': goto yy108; + default: goto yy87; + } +yy108: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy109; + default: goto yy87; + } +yy109: + yych = *++YYCURSOR; + switch (yych) { + case 'R': + case 'r': goto yy110; + default: goto yy87; + } +yy110: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy111; + default: goto yy87; + } +yy111: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy112; + } +yy112: +// 271 "scanner.re" + { + token->opcode = PHQL_T_CONVERT; + return 0; } - - RETURN_MM_TRUE; - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, setControllerSuffix){ - - zval *controller_suffix; - - phalcon_fetch_params(0, 1, 0, &controller_suffix); - - phalcon_update_property_this_quick(this_ptr, SL("_controllerSuffix"), controller_suffix, 2437326621UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, setActionSuffix){ - - zval *action_suffix; - - phalcon_fetch_params(0, 1, 0, &action_suffix); - - phalcon_update_property_this_quick(this_ptr, SL("_actionSuffix"), action_suffix, 879621975UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, getResources){ - - - RETURN_MEMBER_QUICK(this_ptr, "_handlers", 2445210229UL); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Application){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, Application, mvc_application, "phalcon\\di\\injectable", phalcon_mvc_application_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_application_ce, SL("_defaultModule"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_application_ce, SL("_modules"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_application_ce, SL("_moduleObject"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_application_ce, SL("_implicitView"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Application, __construct){ - - zval *dependency_injector = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &dependency_injector); - - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } - - if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Application, useImplicitView){ - - zval *implicit_view; - - phalcon_fetch_params(0, 1, 0, &implicit_view); - - phalcon_update_property_this_quick(this_ptr, SL("_implicitView"), implicit_view, 1205999546UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Application, registerModules){ - - zval *modules, *merge = NULL, *registered_modules, *merged_modules = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &modules, &merge); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } - - if (Z_TYPE_P(modules) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "Modules must be an Array"); - return; - } - if (PHALCON_IS_FALSE(merge)) { - phalcon_update_property_this_quick(this_ptr, SL("_modules"), modules, 379092157UL TSRMLS_CC); - } else { - PHALCON_OBS_VAR(registered_modules); - phalcon_read_property_this_quick(®istered_modules, this_ptr, SL("_modules"), 379092157UL, PH_NOISY_CC); - if (Z_TYPE_P(registered_modules) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_modules); - phalcon_fast_array_merge(merged_modules, ®istered_modules, &modules TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_modules, modules); - } - - phalcon_update_property_this_quick(this_ptr, SL("_modules"), merged_modules, 379092157UL TSRMLS_CC); - } - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Application, getModules){ - - - RETURN_MEMBER_QUICK(this_ptr, "_modules", 379092157UL); -} - -static PHP_METHOD(Phalcon_Mvc_Application, setDefaultModule){ - - zval *default_module; - - phalcon_fetch_params(0, 1, 0, &default_module); - - phalcon_update_property_this_quick(this_ptr, SL("_defaultModule"), default_module, 3959488399UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Application, getDefaultModule){ - - - RETURN_MEMBER_QUICK(this_ptr, "_defaultModule", 3959488399UL); -} - -static PHP_METHOD(Phalcon_Mvc_Application, handle){ - - zval *uri = NULL, *dependency_injector, *events_manager; - zval *event_name = NULL, *status = NULL, *service = NULL, *router, *module_name = NULL; - zval *module_object = NULL, *modules, *exception_msg = NULL; - zval *module, *class_name = NULL, *path, *module_params; - zval *implicit_view, *view, *namespace_name; - zval *controller_name = NULL, *action_name = NULL, *params = NULL; - zval *dispatcher, *controller, *returned_response = NULL; - zval *possible_response, *render_status = NULL, *response = NULL; - zval *content; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &uri); - - if (!uri) { - PHALCON_INIT_VAR(uri); - } - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "A dependency injection object is required to access internal services"); - return; - } - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "application:boot", 1); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "router", 1); - - PHALCON_INIT_VAR(router); - phalcon_call_method_p1_key(router, dependency_injector, "getshared", service, 1727570332UL); - - phalcon_call_method_p1_key(NULL, router, "handle", uri, 866903697UL); - - PHALCON_INIT_VAR(module_name); - phalcon_call_method_key(module_name, router, "getmodulename", 3538616428UL); - - if (!zend_is_true(module_name)) { - PHALCON_OBS_NVAR(module_name); - phalcon_read_property_this_quick(&module_name, this_ptr, SL("_defaultModule"), 3959488399UL, PH_NOISY_CC); - } - - PHALCON_INIT_VAR(module_object); - - if (zend_is_true(module_name)) { - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "application:beforeStartModule", 1); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, module_name, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; +// 1318 "scanner.c" +yy113: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy114; + default: goto yy87; } - } - - PHALCON_OBS_VAR(modules); - phalcon_read_property_this_quick(&modules, this_ptr, SL("_modules"), 379092157UL, PH_NOISY_CC); - if (!phalcon_array_isset(modules, module_name)) { - PHALCON_INIT_VAR(exception_msg); - PHALCON_CONCAT_SVS(exception_msg, "Module '", module_name, "' isn't registered in the application container"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_application_exception_ce, exception_msg); - return; - } - - PHALCON_OBS_VAR(module); - phalcon_array_fetch(&module, modules, module_name, PH_NOISY); - if (Z_TYPE_P(module) != IS_ARRAY) { - if (Z_TYPE_P(module) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "Invalid module definition"); - return; +yy114: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy115; } +yy115: +// 266 "scanner.re" + { + token->opcode = PHQL_T_CAST; + return 0; } - - if (Z_TYPE_P(module) == IS_ARRAY) { - - if (phalcon_array_isset_quick_string(module, SS("className"), 362439804UL)) { - PHALCON_OBS_VAR(class_name); - phalcon_array_fetch_quick_string(&class_name, module, SS("className"), 362439804UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(class_name); - ZVAL_STRING(class_name, "Module", 1); +// 1401 "scanner.c" +yy116: + yych = *++YYCURSOR; + switch (yych) { + case 'G': + case 'g': goto yy117; + default: goto yy87; } - - if (phalcon_array_isset_quick_string(module, SS("path"), 270591026UL)) { - - PHALCON_OBS_VAR(path); - phalcon_array_fetch_quick_string(&path, module, SS("path"), 270591026UL, PH_NOISY); - if (!phalcon_class_exists(class_name, 0 TSRMLS_CC)) { - if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { - if (phalcon_require(path TSRMLS_CC) == FAILURE) { - return; - } - } else { - PHALCON_INIT_NVAR(exception_msg); - PHALCON_CONCAT_SVS(exception_msg, "Module definition path '", path, "' doesn't exist"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_application_exception_ce, exception_msg); - return; - } - } +yy117: + yych = *++YYCURSOR; + switch (yych) { + case 'H': + case 'h': goto yy118; + default: goto yy87; } - - phalcon_call_method_p1_key(module_object, dependency_injector, "get", class_name, 2090288933UL); - - phalcon_call_method_p1_key(NULL, module_object, "registerautoloaders", dependency_injector, 1488981101UL); - phalcon_call_method_p1_key(NULL, module_object, "registerservices", dependency_injector, 3636598030UL); - } else { - if (phalcon_is_instance_of(module, SL("Closure") TSRMLS_CC)) { - PHALCON_INIT_VAR(module_params); - array_init_size(module_params, 1); - phalcon_array_append(&module_params, dependency_injector, PH_SEPARATE); - - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC_ARRAY(status, module, module_params); - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "Invalid module definition"); - return; +yy118: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy119; + default: goto yy87; + } +yy119: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy120; } +yy120: +// 226 "scanner.re" + { + token->opcode = PHQL_T_RIGHT; + return 0; } - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_moduleObject"), module_object, 121977121UL TSRMLS_CC); - - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "application:afterStartModule", 1); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, module_name, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; +// 1498 "scanner.c" +yy121: + yych = *++YYCURSOR; + switch (yych) { + case 'I': + case 'i': goto yy122; + default: goto yy87; + } +yy122: + yych = *++YYCURSOR; + switch (yych) { + case 'N': + case 'n': goto yy123; + default: goto yy87; + } +yy123: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy124; } +yy124: +// 211 "scanner.re" + { + token->opcode = PHQL_T_JOIN; + return 0; } - } - - PHALCON_OBS_VAR(implicit_view); - phalcon_read_property_this_quick(&implicit_view, this_ptr, SL("_implicitView"), 1205999546UL, PH_NOISY_CC); - if (PHALCON_IS_TRUE(implicit_view)) { - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "view", 1); - - PHALCON_INIT_VAR(view); - phalcon_call_method_p1_key(view, dependency_injector, "getshared", service, 1727570332UL); - } - - PHALCON_INIT_NVAR(module_name); - phalcon_call_method_key(module_name, router, "getmodulename", 3538616428UL); - - PHALCON_INIT_VAR(namespace_name); - phalcon_call_method_key(namespace_name, router, "getnamespacename", 1552352211UL); - - PHALCON_INIT_VAR(controller_name); - phalcon_call_method_key(controller_name, router, "getcontrollername", 620100618UL); - - PHALCON_INIT_VAR(action_name); - phalcon_call_method_key(action_name, router, "getactionname", 2461134148UL); - - PHALCON_INIT_VAR(params); - phalcon_call_method_key(params, router, "getparams", 1893744905UL); - - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "dispatcher", 1); - - PHALCON_INIT_VAR(dispatcher); - phalcon_call_method_p1_key(dispatcher, dependency_injector, "getshared", service, 1727570332UL); - - phalcon_call_method_p1_key(NULL, dispatcher, "setmodulename", module_name, 2582492152UL); - phalcon_call_method_p1_key(NULL, dispatcher, "setnamespacename", namespace_name, 1052613599UL); - phalcon_call_method_p1_key(NULL, dispatcher, "setcontrollername", controller_name, 1308595606UL); - phalcon_call_method_p1_key(NULL, dispatcher, "setactionname", action_name, 1505009872UL); - phalcon_call_method_p1_key(NULL, dispatcher, "setparams", params, 2707361429UL); - - if (PHALCON_IS_TRUE(implicit_view)) { - phalcon_call_method_key(NULL, view, "start", 478839859UL); - } - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "application:beforeHandleRequest", 1); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, dispatcher, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; +// 1588 "scanner.c" +yy125: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy130; + default: goto yy87; + } +yy126: + yych = *++YYCURSOR; + switch (yych) { + case 'L': + case 'l': goto yy127; + default: goto yy87; + } +yy127: + yych = *++YYCURSOR; + switch (yych) { + case 'L': + case 'l': goto yy128; + default: goto yy87; + } +yy128: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy129; + } +yy129: +// 251 "scanner.re" + { + token->opcode = PHQL_T_NULL; + return 0; } - } - - PHALCON_INIT_VAR(controller); - phalcon_call_method_key(controller, dispatcher, "dispatch", 4202735573UL); - - PHALCON_INIT_VAR(returned_response); - ZVAL_BOOL(returned_response, 0); - - PHALCON_INIT_VAR(possible_response); - phalcon_call_method_key(possible_response, dispatcher, "getreturnedvalue", 1798811019UL); - if (Z_TYPE_P(possible_response) == IS_OBJECT) { - phalcon_instance_of(returned_response, possible_response, phalcon_http_responseinterface_ce TSRMLS_CC); - } - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "application:afterHandleRequest", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, controller, 259017035UL); - } - - if (PHALCON_IS_FALSE(returned_response)) { - if (PHALCON_IS_TRUE(implicit_view)) { - - if (Z_TYPE_P(controller) == IS_OBJECT) { - - PHALCON_INIT_VAR(render_status); - ZVAL_BOOL(render_status, 1); - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "application:viewRender", 1); - - phalcon_call_method_p3_key(render_status, events_manager, "fire", event_name, this_ptr, view, 259017035UL); - } - - if (PHALCON_IS_NOT_FALSE(render_status)) { - PHALCON_INIT_NVAR(controller_name); - phalcon_call_method_key(controller_name, dispatcher, "getcontrollername", 620100618UL); - - PHALCON_INIT_NVAR(action_name); - phalcon_call_method_key(action_name, dispatcher, "getactionname", 2461134148UL); - - PHALCON_INIT_NVAR(params); - phalcon_call_method_key(params, dispatcher, "getparams", 1893744905UL); - - phalcon_call_method_p3_key(NULL, view, "render", controller_name, action_name, params, 1053215877UL); - } +// 1685 "scanner.c" +yy130: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy131; } +yy131: +// 171 "scanner.re" + { + token->opcode = PHQL_T_NOT; + return 0; } - } - - if (PHALCON_IS_TRUE(implicit_view)) { - phalcon_call_method_key(NULL, view, "finish", 2892205606UL); - } - - if (PHALCON_IS_FALSE(returned_response)) { - - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "response", 1); - - PHALCON_INIT_VAR(response); - phalcon_call_method_p1_key(response, dependency_injector, "getshared", service, 1727570332UL); - if (PHALCON_IS_TRUE(implicit_view)) { - PHALCON_INIT_VAR(content); - phalcon_call_method_key(content, view, "getcontent", 3141446400UL); - phalcon_call_method_p1_key(NULL, response, "setcontent", content, 4220987916UL); +// 1761 "scanner.c" +yy132: + yych = *++YYCURSOR; + switch (yych) { + case 'F': + case 'f': goto yy141; + default: goto yy87; + } +yy133: + yych = *++YYCURSOR; + switch (yych) { + case 'K': + case 'k': goto yy135; + case 'M': + case 'm': goto yy134; + default: goto yy87; + } +yy134: + yych = *++YYCURSOR; + switch (yych) { + case 'I': + case 'i': goto yy138; + default: goto yy87; + } +yy135: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy136; + default: goto yy87; + } +yy136: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy137; + } +yy137: +// 186 "scanner.re" + { + token->opcode = PHQL_T_LIKE; + return 0; } - } else { - PHALCON_CPY_WRT(response, possible_response); - } - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "application:beforeSendResponse", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, response, 259017035UL); - } - - phalcon_call_method_key(NULL, response, "sendheaders", 1941404491UL); - - phalcon_call_method_key(NULL, response, "sendcookies", 4183658748UL); - - - RETURN_CCTOR(response); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Micro){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, Micro, mvc_micro, "phalcon\\di\\injectable", phalcon_mvc_micro_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_micro_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_ce, SL("_handlers"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_ce, SL("_router"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_ce, SL("_stopped"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_ce, SL("_notFoundHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_ce, SL("_activeHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_ce, SL("_beforeHandlers"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_ce, SL("_afterHandlers"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_ce, SL("_finishHandlers"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_ce, SL("_returnedValue"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_micro_ce TSRMLS_CC, 1, zend_ce_arrayaccess); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Micro, __construct){ - - zval *dependency_injector = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &dependency_injector); - - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } - - if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { - phalcon_call_method_p1_key(NULL, this_ptr, "setdi", dependency_injector, 461718238UL); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, setDI){ - - zval *dependency_injector, *service, *exists; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "The dependency injector must be an object"); - return; - } - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "application", 1); - - PHALCON_INIT_VAR(exists); - phalcon_call_method_p1_key(exists, dependency_injector, "has", service, 2090320481UL); - if (!zend_is_true(exists)) { - phalcon_call_method_p2_key(NULL, dependency_injector, "set", service, this_ptr, 2090720177UL); - } - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, map){ - - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); - - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "add", route_pattern, 2090071694UL); - - PHALCON_INIT_VAR(route_id); - phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - RETURN_CCTOR(route); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, get){ - - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); - - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addget", route_pattern, 522210158UL); - - PHALCON_INIT_VAR(route_id); - phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - RETURN_CCTOR(route); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, post){ - - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); - - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addpost", route_pattern, 64101428UL); - - PHALCON_INIT_VAR(route_id); - phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - RETURN_CCTOR(route); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, put){ - - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); - - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addput", route_pattern, 522551015UL); - - PHALCON_INIT_VAR(route_id); - phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - RETURN_CCTOR(route); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, patch){ - - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); - - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addpatch", route_pattern, 2098765086UL); - - PHALCON_INIT_VAR(route_id); - phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - RETURN_CCTOR(route); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, head){ - - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); - - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addhead", route_pattern, 54234560UL); - - PHALCON_INIT_VAR(route_id); - phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - RETURN_CCTOR(route); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, delete){ - - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); - - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "adddelete", route_pattern, 2369167137UL); - - PHALCON_INIT_VAR(route_id); - phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - RETURN_CCTOR(route); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, options){ - - zval *route_pattern, *handler, *router, *route; - zval *route_id; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); - - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addoptions", route_pattern, 3163448186UL); - - PHALCON_INIT_VAR(route_id); - phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); - - RETURN_CCTOR(route); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, mount){ - - zval *collection, *main_handler, *handlers, *lazy; - zval *lazy_handler = NULL, *prefix, *handler = NULL, *methods = NULL; - zval *pattern = NULL, *sub_handler = NULL, *real_handler = NULL, *prefixed_pattern = NULL; - zval *route = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &collection); - - if (Z_TYPE_P(collection) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The collection is not valid"); - return; - } - - PHALCON_INIT_VAR(main_handler); - phalcon_call_method_key(main_handler, collection, "gethandler", 565881059UL); - if (PHALCON_IS_EMPTY(main_handler)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The collection requires a main handler"); - return; - } - - PHALCON_INIT_VAR(handlers); - phalcon_call_method_key(handlers, collection, "gethandlers", 1494209558UL); - if (!phalcon_fast_count_ev(handlers TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "There are no handlers to mount"); - return; - } - - if (Z_TYPE_P(handlers) == IS_ARRAY) { - - PHALCON_INIT_VAR(lazy); - phalcon_call_method_key(lazy, collection, "islazy", 2860344993UL); - if (zend_is_true(lazy)) { - PHALCON_INIT_VAR(lazy_handler); - object_init_ex(lazy_handler, phalcon_mvc_micro_lazyloader_ce); - phalcon_call_method_p1_key(NULL, lazy_handler, "__construct", main_handler, 1107214344UL); - - } else { - PHALCON_CPY_WRT(lazy_handler, main_handler); +// 1867 "scanner.c" +yy138: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy139; + default: goto yy87; + } +yy139: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy140; + } +yy140: +// 161 "scanner.re" + { + token->opcode = PHQL_T_LIMIT; + return 0; } - - PHALCON_INIT_VAR(prefix); - phalcon_call_method_key(prefix, collection, "getprefix", 2543805107UL); - - phalcon_is_iterable(handlers, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(handler); - - if (Z_TYPE_P(handler) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "One of the registered handlers is invalid"); - return; +// 1950 "scanner.c" +yy141: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy142; + default: goto yy87; } - - PHALCON_OBS_NVAR(methods); - phalcon_array_fetch_long(&methods, handler, 0, PH_NOISY); - - PHALCON_OBS_NVAR(pattern); - phalcon_array_fetch_long(&pattern, handler, 1, PH_NOISY); - - PHALCON_OBS_NVAR(sub_handler); - phalcon_array_fetch_long(&sub_handler, handler, 2, PH_NOISY); - - PHALCON_INIT_NVAR(real_handler); - array_init_size(real_handler, 2); - phalcon_array_append(&real_handler, lazy_handler, PH_SEPARATE); - phalcon_array_append(&real_handler, sub_handler, PH_SEPARATE); - if (PHALCON_IS_NOT_EMPTY(prefix)) { - if (PHALCON_IS_STRING(pattern, "/")) { - PHALCON_CPY_WRT(prefixed_pattern, prefix); - } else { - PHALCON_INIT_NVAR(prefixed_pattern); - PHALCON_CONCAT_VV(prefixed_pattern, prefix, pattern); - } - } else { - PHALCON_CPY_WRT(prefixed_pattern, pattern); +yy142: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy143; } - - PHALCON_INIT_NVAR(route); - phalcon_call_method_p2_key(route, this_ptr, "map", prefixed_pattern, real_handler, 2090500067UL); - if (zend_is_true(methods)) { - phalcon_call_method_p1_key(NULL, route, "via", methods, 2090831717UL); +yy143: +// 221 "scanner.re" + { + token->opcode = PHQL_T_LEFT; + return 0; + } +// 2033 "scanner.c" +yy144: + yych = *++YYCURSOR; + switch (yych) { + case 'V': + case 'v': goto yy145; + default: goto yy87; } - - zend_hash_move_forward_ex(ah0, &hp0); +yy145: + yych = *++YYCURSOR; + switch (yych) { + case 'I': + case 'i': goto yy146; + default: goto yy87; + } +yy146: + yych = *++YYCURSOR; + switch (yych) { + case 'N': + case 'n': goto yy147; + default: goto yy87; + } +yy147: + yych = *++YYCURSOR; + switch (yych) { + case 'G': + case 'g': goto yy148; + default: goto yy87; + } +yy148: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy149; + } +yy149: +// 156 "scanner.re" + { + token->opcode = PHQL_T_HAVING; + return 0; } - - } - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, notFound){ - - zval *handler; - - phalcon_fetch_params(0, 1, 0, &handler); - - phalcon_update_property_this_quick(this_ptr, SL("_notFoundHandler"), handler, 2638317359UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, getRouter){ - - zval *router = NULL, *service_name, *remove; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(router); - phalcon_read_property_this_quick(&router, this_ptr, SL("_router"), 2063827077UL, PH_NOISY_CC); - if (Z_TYPE_P(router) != IS_OBJECT) { - PHALCON_INIT_VAR(service_name); - ZVAL_STRING(service_name, "router", 1); - - PHALCON_INIT_NVAR(router); - phalcon_call_method_p1_key(router, this_ptr, "getsharedservice", service_name, 3519183981UL); - - phalcon_call_method_key(NULL, router, "clear", 4138278668UL); - - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 1); - - phalcon_call_method_p1_key(NULL, router, "removeextraslashes", remove, 2128043402UL); - - phalcon_update_property_this_quick(this_ptr, SL("_router"), router, 2063827077UL TSRMLS_CC); - } - - RETURN_CCTOR(router); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, setService){ - - zval *service_name, *definition, *shared = NULL, *dependency_injector = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &service_name, &definition, &shared); - - if (!shared) { - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 0); - } - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); - phalcon_call_method_key(NULL, dependency_injector, "__construct", 1107214344UL); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } - - phalcon_call_method_p3_key(return_value, dependency_injector, "set", service_name, definition, shared, 2090720177UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, hasService){ - - zval *service_name, *dependency_injector = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &service_name); - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); - phalcon_call_method_key(NULL, dependency_injector, "__construct", 1107214344UL); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } - - phalcon_call_method_p1_key(return_value, dependency_injector, "has", service_name, 2090320481UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, getService){ - - zval *service_name, *dependency_injector = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &service_name); - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); - phalcon_call_method_key(NULL, dependency_injector, "__construct", 1107214344UL); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } - - phalcon_call_method_p1_key(return_value, dependency_injector, "get", service_name, 2090288933UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, getSharedService){ - - zval *service_name, *dependency_injector = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &service_name); - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); - phalcon_call_method_key(NULL, dependency_injector, "__construct", 1107214344UL); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } - - phalcon_call_method_p1_key(return_value, dependency_injector, "getshared", service_name, 1727570332UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, handle){ - - zval *uri = NULL, *dependency_injector, *events_manager = NULL; - zval *event_name = NULL, *status = NULL, *service, *router, *matched_route; - zval *handlers, *route_id, *handler = NULL, *before_handlers; - zval *before = NULL, *is_middleware = NULL, *stopped = NULL, *params = NULL; - zval *returned_value = NULL, *after_handlers, *after = NULL; - zval *not_found_handler, *finish_handlers; - zval *finish = NULL, *returned_response; - HashTable *ah0, *ah1, *ah2; - HashPosition hp0, hp1, hp2; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &uri); - - if (!uri) { - PHALCON_INIT_VAR(uri); - } - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "A dependency injection container is required to access related dispatching services"); - return; - } - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "micro:beforeHandleRoute", 1); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "router", 1); - - PHALCON_INIT_VAR(router); - phalcon_call_method_p1_key(router, dependency_injector, "getshared", service, 1727570332UL); - - phalcon_call_method_p1_key(NULL, router, "handle", uri, 866903697UL); - - PHALCON_INIT_VAR(matched_route); - phalcon_call_method_key(matched_route, router, "getmatchedroute", 3985199242UL); - if (Z_TYPE_P(matched_route) == IS_OBJECT) { - - PHALCON_OBS_VAR(handlers); - phalcon_read_property_this_quick(&handlers, this_ptr, SL("_handlers"), 2445210229UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(route_id); - phalcon_call_method_key(route_id, matched_route, "getrouteid", 2741905729UL); - if (!phalcon_array_isset(handlers, route_id)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "Matched route doesn't have an associate handler"); - return; - } - - PHALCON_OBS_VAR(handler); - phalcon_array_fetch(&handler, handlers, route_id, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_activeHandler"), handler, 2923197278UL TSRMLS_CC); - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "micro:beforeExecuteRoute", 1); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } else { - PHALCON_OBS_NVAR(handler); - phalcon_read_property_this_quick(&handler, this_ptr, SL("_activeHandler"), 2923197278UL, PH_NOISY_CC); +// 2137 "scanner.c" +yy150: + yych = *++YYCURSOR; + switch (yych) { + case 'O': + case 'o': goto yy151; + default: goto yy87; } - } - - PHALCON_OBS_VAR(before_handlers); - phalcon_read_property_this_quick(&before_handlers, this_ptr, SL("_beforeHandlers"), 1218553128UL, PH_NOISY_CC); - if (Z_TYPE_P(before_handlers) == IS_ARRAY) { - phalcon_update_property_bool(this_ptr, SL("_stopped"), 0 TSRMLS_CC); - - phalcon_is_iterable(before_handlers, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(before); - - if (Z_TYPE_P(before) == IS_OBJECT) { - - PHALCON_INIT_NVAR(is_middleware); - phalcon_instance_of(is_middleware, before, phalcon_mvc_micro_middlewareinterface_ce TSRMLS_CC); - if (PHALCON_IS_TRUE(is_middleware)) { - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, before, "call", this_ptr, 255165473UL); - - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); - - if (zend_is_true(stopped)) { - break; - } - - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - if (!phalcon_is_callable(before TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The before handler is not callable"); - return; - } - - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC(status, before); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); - if (zend_is_true(stopped)) { - RETURN_CCTOR(status); - } - - zend_hash_move_forward_ex(ah0, &hp0); +yy151: + yych = *++YYCURSOR; + switch (yych) { + case 'U': + case 'u': goto yy152; + default: goto yy87; } - - } - - PHALCON_INIT_VAR(params); - phalcon_call_method_key(params, router, "getparams", 1893744905UL); - - PHALCON_INIT_VAR(returned_value); - PHALCON_CALL_USER_FUNC_ARRAY(returned_value, handler, params); - - phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), returned_value, 4143876906UL TSRMLS_CC); - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "micro:afterExecuteRoute", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); - } - - PHALCON_OBS_VAR(after_handlers); - phalcon_read_property_this_quick(&after_handlers, this_ptr, SL("_afterHandlers"), 687871879UL, PH_NOISY_CC); - if (Z_TYPE_P(after_handlers) == IS_ARRAY) { - phalcon_update_property_bool(this_ptr, SL("_stopped"), 0 TSRMLS_CC); - - phalcon_is_iterable(after_handlers, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(after); - - if (Z_TYPE_P(after) == IS_OBJECT) { - - PHALCON_INIT_NVAR(is_middleware); - phalcon_instance_of(is_middleware, after, phalcon_mvc_micro_middlewareinterface_ce TSRMLS_CC); - if (PHALCON_IS_TRUE(is_middleware)) { - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, after, "call", this_ptr, 255165473UL); - - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); - - if (zend_is_true(stopped)) { - break; - } - - zend_hash_move_forward_ex(ah1, &hp1); - continue; - } - } - if (!phalcon_is_callable(after TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "One of the 'after' handlers is not callable"); - return; - } - - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC(status, after); - - zend_hash_move_forward_ex(ah1, &hp1); +yy152: + yych = *++YYCURSOR; + switch (yych) { + case 'P': + case 'p': goto yy153; + default: goto yy87; } - - } - } else { - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "micro:beforeNotFound", 1); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; +yy153: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy154; } +yy154: +// 151 "scanner.re" + { + token->opcode = PHQL_T_GROUP; + return 0; } - - PHALCON_OBS_VAR(not_found_handler); - phalcon_read_property_this_quick(¬_found_handler, this_ptr, SL("_notFoundHandler"), 2638317359UL, PH_NOISY_CC); - if (!phalcon_is_callable(not_found_handler TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The Not-Found handler is not callable or is not defined"); - return; - } - - PHALCON_INIT_NVAR(returned_value); - PHALCON_CALL_USER_FUNC(returned_value, not_found_handler); - - phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), returned_value, 4143876906UL TSRMLS_CC); - - RETURN_CCTOR(returned_value); - } - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "micro:afterHandleRoute", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); - } - - PHALCON_OBS_VAR(finish_handlers); - phalcon_read_property_this_quick(&finish_handlers, this_ptr, SL("_finishHandlers"), 2843789078UL, PH_NOISY_CC); - if (Z_TYPE_P(finish_handlers) == IS_ARRAY) { - phalcon_update_property_bool(this_ptr, SL("_stopped"), 0 TSRMLS_CC); - - PHALCON_INIT_NVAR(params); - - phalcon_is_iterable(finish_handlers, &ah2, &hp2, 0, 0); - - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - - PHALCON_GET_HVALUE(finish); - - if (Z_TYPE_P(finish) == IS_OBJECT) { - - PHALCON_INIT_NVAR(is_middleware); - phalcon_instance_of(is_middleware, finish, phalcon_mvc_micro_middlewareinterface_ce TSRMLS_CC); - if (PHALCON_IS_TRUE(is_middleware)) { - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, finish, "call", this_ptr, 255165473UL); - - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); - - if (zend_is_true(stopped)) { - break; - } - - zend_hash_move_forward_ex(ah2, &hp2); - continue; - } - } - if (!phalcon_is_callable(finish TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "One of finish handlers is not callable"); - return; - } - - if (Z_TYPE_P(params) == IS_NULL) { - PHALCON_INIT_NVAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, this_ptr, PH_SEPARATE); - } - - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC_ARRAY(status, finish, params); - - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); - - if (zend_is_true(stopped)) { - break; +// 2234 "scanner.c" +yy155: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy158; + default: goto yy87; } - - zend_hash_move_forward_ex(ah2, &hp2); - } - - } - - if (Z_TYPE_P(returned_value) == IS_OBJECT) { - - PHALCON_INIT_VAR(returned_response); - phalcon_instance_of(returned_response, returned_value, phalcon_http_responseinterface_ce TSRMLS_CC); - if (PHALCON_IS_TRUE(returned_response)) { - phalcon_call_method_key(NULL, returned_value, "send", 274285871UL); +yy156: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy157; + } +yy157: +// 136 "scanner.re" + { + token->opcode = PHQL_T_BY; + return 0; } - } - - RETURN_CCTOR(returned_value); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, stop){ - - - phalcon_update_property_bool(this_ptr, SL("_stopped"), 1 TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Micro, setActiveHandler){ - - zval *active_handler; - - phalcon_fetch_params(0, 1, 0, &active_handler); - - phalcon_update_property_this_quick(this_ptr, SL("_activeHandler"), active_handler, 2923197278UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Micro, getActiveHandler){ - - - RETURN_MEMBER_QUICK(this_ptr, "_activeHandler", 2923197278UL); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, getReturnedValue){ - - - RETURN_MEMBER_QUICK(this_ptr, "_returnedValue", 4143876906UL); -} - - - - -static PHP_METHOD(Phalcon_Mvc_Micro, offsetUnset){ - - zval *alias; - - phalcon_fetch_params(0, 1, 0, &alias); - - RETURN_CCTORW(alias); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, before){ - - zval *handler; - - phalcon_fetch_params(0, 1, 0, &handler); - - phalcon_update_property_array_append(this_ptr, SL("_beforeHandlers"), handler TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, after){ - - zval *handler; - - phalcon_fetch_params(0, 1, 0, &handler); - - phalcon_update_property_array_append(this_ptr, SL("_afterHandlers"), handler TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, finish){ - - zval *handler; - - phalcon_fetch_params(0, 1, 0, &handler); - - phalcon_update_property_array_append(this_ptr, SL("_finishHandlers"), handler TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, getHandlers){ - - - RETURN_MEMBER_QUICK(this_ptr, "_handlers", 2445210229UL); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_ModuleDefinitionInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ModuleDefinitionInterface, mvc_moduledefinitioninterface, phalcon_mvc_moduledefinitioninterface_method_entry); - - return SUCCESS; -} - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Collection_Document){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Collection, Document, mvc_collection_document, phalcon_mvc_collection_document_method_entry, 0); - - zend_class_implements(phalcon_mvc_collection_document_ce TSRMLS_CC, 1, zend_ce_arrayaccess); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetExists){ - - zval *index; - - phalcon_fetch_params(0, 1, 0, &index); - - if (phalcon_isset_property_zval(this_ptr, index TSRMLS_CC)) { - RETURN_TRUE; - } - RETURN_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetGet){ - - zval *index, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &index); - - if (phalcon_isset_property_zval(this_ptr, index TSRMLS_CC)) { - PHALCON_OBS_VAR(value); - phalcon_read_property_zval(&value, this_ptr, index, PH_NOISY_CC); - RETURN_CCTOR(value); - } - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The index does not exist in the row"); - return; -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetSet){ - - zval *index, *value; - - phalcon_fetch_params(0, 2, 0, &index, &value); - - phalcon_update_property_zval_zval(this_ptr, index, value TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetUnset){ - - zval *offset; - - phalcon_fetch_params(0, 1, 0, &offset); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_collection_exception_ce, "The index does not exist in the row"); - return; -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Document, readAttribute){ - - zval *attribute, *attribute_value; - - 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_CC); - RETURN_CCTOR(attribute_value); - } - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Document, writeAttribute){ - - zval *attribute, *value; - - phalcon_fetch_params(0, 2, 0, &attribute, &value); - - phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Collection_ManagerInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Collection, ManagerInterface, mvc_collection_managerinterface, phalcon_mvc_collection_managerinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Collection_Manager){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Collection, Manager, mvc_collection_manager, phalcon_mvc_collection_manager_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_initialized"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_lastInitialized"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_customEventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_connectionServices"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_manager_ce, SL("_implicitObjectsIds"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_collection_manager_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_events_eventsawareinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, setEventsManager){ - - zval *events_manager; - - phalcon_fetch_params(0, 1, 0, &events_manager); - - phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getEventsManager){ - - - RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, setCustomEventsManager){ - - zval *model, *events_manager, *class_name; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &events_manager); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, model, 1 TSRMLS_CC); - phalcon_update_property_array(this_ptr, SL("_customEventsManager"), class_name, events_manager TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getCustomEventsManager){ - - zval *model, *custom_events_manager, *class_name; - zval *events_manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_OBS_VAR(custom_events_manager); - phalcon_read_property_this_quick(&custom_events_manager, this_ptr, SL("_customEventsManager"), 542727151UL, PH_NOISY_CC); - if (Z_TYPE_P(custom_events_manager) == IS_ARRAY) { - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, model, 1 TSRMLS_CC); - if (phalcon_array_isset(custom_events_manager, class_name)) { - PHALCON_OBS_VAR(events_manager); - phalcon_array_fetch(&events_manager, custom_events_manager, class_name, PH_NOISY); - RETURN_CCTOR(events_manager); +// 2317 "scanner.c" +yy158: + yych = *++YYCURSOR; + switch (yych) { + case 'W': + case 'w': goto yy159; + default: goto yy87; + } +yy159: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy160; + default: goto yy87; + } +yy160: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy161; + default: goto yy87; + } +yy161: + yych = *++YYCURSOR; + switch (yych) { + case 'N': + case 'n': goto yy162; + default: goto yy87; + } +yy162: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy163; + } +yy163: +// 261 "scanner.re" + { + token->opcode = PHQL_T_BETWEEN; + return 0; } - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, initialize){ - - zval *model, *class_name, *initialized, *events_manager; - zval *event_name; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, model, 1 TSRMLS_CC); - - PHALCON_OBS_VAR(initialized); - phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); - - if (!phalcon_array_isset(initialized, class_name)) { - - if (phalcon_method_quick_exists_ex(model, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, model, "initialize", 2896075127UL); - } - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "collectionManager:afterInitialize", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); - } - - phalcon_update_property_array(this_ptr, SL("_initialized"), class_name, model TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_lastInitialized"), model, 1491101038UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, isInitialized){ - - zval *model_name, *initialized, *lowercased; - zval *is_intitialized = NULL; - zval *r0 = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model_name); - - PHALCON_OBS_VAR(initialized); - phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(lowercased); - phalcon_fast_strtolower(lowercased, model_name); - - PHALCON_INIT_VAR(r0); - ZVAL_BOOL(r0, phalcon_array_isset(initialized, lowercased)); - PHALCON_CPY_WRT(is_intitialized, r0); - RETURN_NCTOR(is_intitialized); -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getLastInitialized){ - - - RETURN_MEMBER_QUICK(this_ptr, "_lastInitialized", 1491101038UL); -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, setConnectionService){ - - zval *model, *connection_service, *entity_name; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &connection_service); - - if (Z_TYPE_P(model) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A valid collection instance is required"); - return; - } - - PHALCON_INIT_VAR(entity_name); - phalcon_get_class(entity_name, model, 1 TSRMLS_CC); - phalcon_update_property_array(this_ptr, SL("_connectionServices"), entity_name, connection_service TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, useImplicitObjectIds){ - - zval *model, *use_implicit_object_ids, *entity_name; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &use_implicit_object_ids); - - if (Z_TYPE_P(model) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A valid collection instance is required"); - return; - } - - PHALCON_INIT_VAR(entity_name); - phalcon_get_class(entity_name, model, 1 TSRMLS_CC); - phalcon_update_property_array(this_ptr, SL("_implicitObjectsIds"), entity_name, use_implicit_object_ids TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, isUsingImplicitObjectIds){ - - zval *model, *entity_name, *implicit_objects_ids; - zval *implicit; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - if (Z_TYPE_P(model) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A valid collection instance is required"); - return; - } - - PHALCON_INIT_VAR(entity_name); - phalcon_get_class(entity_name, model, 1 TSRMLS_CC); - - PHALCON_OBS_VAR(implicit_objects_ids); - phalcon_read_property_this_quick(&implicit_objects_ids, this_ptr, SL("_implicitObjectsIds"), 1447589161UL, PH_NOISY_CC); - if (phalcon_array_isset(implicit_objects_ids, entity_name)) { - PHALCON_OBS_VAR(implicit); - phalcon_array_fetch(&implicit, implicit_objects_ids, entity_name, PH_NOISY); - RETURN_CCTOR(implicit); - } - - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getConnection){ - - zval *model, *service = NULL, *connection_services; - zval *entity_name, *dependency_injector, *connection; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - if (Z_TYPE_P(model) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A valid collection instance is required"); - return; - } - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "mongo", 1); - - PHALCON_OBS_VAR(connection_services); - phalcon_read_property_this_quick(&connection_services, this_ptr, SL("_connectionServices"), 2904820280UL, PH_NOISY_CC); - if (Z_TYPE_P(connection_services) == IS_ARRAY) { - - PHALCON_INIT_VAR(entity_name); - phalcon_get_class(entity_name, model, 1 TSRMLS_CC); - - if (phalcon_array_isset(connection_services, entity_name)) { - PHALCON_OBS_NVAR(service); - phalcon_array_fetch(&service, connection_services, entity_name, PH_NOISY); +// 2421 "scanner.c" +yy164: + yych = *++YYCURSOR; + switch (yych) { + case 'F': + case 'f': goto yy178; + default: goto yy87; + } +yy165: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy166; + } +yy166: +// 206 "scanner.re" + { + token->opcode = PHQL_T_ON; + return 0; } - } - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); - return; - } - - PHALCON_INIT_VAR(connection); - phalcon_call_method_p1_key(connection, dependency_injector, "getshared", service, 1727570332UL); - if (Z_TYPE_P(connection) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid injected connection service"); - return; - } - - RETURN_CCTOR(connection); -} - -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, notifyEvent){ - - zval *event_name, *model, *status = NULL, *events_manager; - zval *fire_event_name = NULL, *custom_events_manager; - zval *entity_name; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &event_name, &model); - - PHALCON_INIT_VAR(status); - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_VAR(fire_event_name); - PHALCON_CONCAT_SV(fire_event_name, "collection:", event_name); - - phalcon_call_method_p2_key(status, events_manager, "fire", fire_event_name, model, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_CCTOR(status); +// 2504 "scanner.c" +yy167: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + case 'D': + case 'd': goto yy174; + default: goto yy168; + } +yy168: +// 181 "scanner.re" + { + token->opcode = PHQL_T_OR; + return 0; } - } - - PHALCON_OBS_VAR(custom_events_manager); - phalcon_read_property_this_quick(&custom_events_manager, this_ptr, SL("_customEventsManager"), 542727151UL, PH_NOISY_CC); - if (Z_TYPE_P(custom_events_manager) == IS_ARRAY) { - - PHALCON_INIT_VAR(entity_name); - phalcon_get_class(entity_name, model, 1 TSRMLS_CC); - if (phalcon_array_isset(custom_events_manager, entity_name)) { - - PHALCON_INIT_NVAR(fire_event_name); - PHALCON_CONCAT_SV(fire_event_name, "collection:", event_name); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, custom_events_manager, "fire", fire_event_name, model, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_CCTOR(status); +// 2580 "scanner.c" +yy169: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy170; + default: goto yy87; + } +yy170: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy171; + default: goto yy87; + } +yy171: + yych = *++YYCURSOR; + switch (yych) { + case 'R': + case 'r': goto yy172; + default: goto yy87; + } +yy172: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy173; } +yy173: +// 236 "scanner.re" + { + token->opcode = PHQL_T_OUTER; + return 0; } - } - - RETURN_CCTOR(status); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Collection_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Collection, Exception, mvc_collection_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Dispatcher){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, Dispatcher, mvc_dispatcher, "phalcon\\dispatcher", phalcon_mvc_dispatcher_method_entry, 0); - - zend_declare_property_string(phalcon_mvc_dispatcher_ce, SL("_handlerSuffix"), "Controller", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_mvc_dispatcher_ce, SL("_defaultHandler"), "index", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_mvc_dispatcher_ce, SL("_defaultAction"), "index", ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_dispatcher_ce TSRMLS_CC, 1, phalcon_mvc_dispatcherinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Dispatcher, setControllerSuffix){ - - zval *controller_suffix; - - phalcon_fetch_params(0, 1, 0, &controller_suffix); - - phalcon_update_property_this_quick(this_ptr, SL("_handlerSuffix"), controller_suffix, 1659190583UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Dispatcher, setDefaultController){ - - zval *controller_name; - - phalcon_fetch_params(0, 1, 0, &controller_name); - - phalcon_update_property_this_quick(this_ptr, SL("_defaultHandler"), controller_name, 2940762855UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Dispatcher, setControllerName){ - - zval *controller_name; - - phalcon_fetch_params(0, 1, 0, &controller_name); - - phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), controller_name, 2743819555UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_handlerName", 2743819555UL); -} - -static PHP_METHOD(Phalcon_Mvc_Dispatcher, _throwDispatchException){ - - zval *message, *exception_code = NULL, *dependency_injector; - zval *exception_message, *exception = NULL, *service; - zval *response, *status_code, *status_message; - zval *events_manager, *event_name, *status; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &message, &exception_code); - - if (!exception_code) { - PHALCON_INIT_VAR(exception_code); - ZVAL_LONG(exception_code, 0); - } else { - PHALCON_SEPARATE_PARAM(exception_code); - } - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(exception_code); - ZVAL_LONG(exception_code, 0); - - PHALCON_INIT_VAR(exception_message); - ZVAL_STRING(exception_message, "A dependency injection container is required to access the 'response' service", 1); - - PHALCON_INIT_VAR(exception); - object_init_ex(exception, phalcon_mvc_dispatcher_exception_ce); - phalcon_call_method_p2_key(NULL, exception, "__construct", exception_message, exception_code, 1107214344UL); - - phalcon_throw_exception(exception TSRMLS_CC); - return; - } - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "response", 1); - - PHALCON_INIT_VAR(response); - phalcon_call_method_p1_key(response, dependency_injector, "getshared", service, 1727570332UL); - - PHALCON_INIT_VAR(status_code); - ZVAL_LONG(status_code, 404); - - PHALCON_INIT_VAR(status_message); - ZVAL_STRING(status_message, "Not Found", 1); - phalcon_call_method_p2_key(NULL, response, "setstatuscode", status_code, status_message, 1498183248UL); - - PHALCON_INIT_NVAR(exception); - object_init_ex(exception, phalcon_mvc_dispatcher_exception_ce); - phalcon_call_method_p2_key(NULL, exception, "__construct", message, exception_code, 1107214344UL); - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "dispatch:beforeException", 1); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, exception, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } - - phalcon_throw_exception(exception TSRMLS_CC); - return; -} - -static PHP_METHOD(Phalcon_Mvc_Dispatcher, _handleException){ - - zval *exception, *events_manager, *event_name; - zval *status; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &exception); - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "dispatch:beforeException", 1); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, exception, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerClass){ - - - PHALCON_MM_GROW(); - - phalcon_call_method_key(return_value, this_ptr, "gethandlername", 1725429572UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Dispatcher, getLastController){ - - - RETURN_MEMBER_QUICK(this_ptr, "_lastHandler", 1315517974UL); -} - -static PHP_METHOD(Phalcon_Mvc_Dispatcher, getActiveController){ - - - RETURN_MEMBER_QUICK(this_ptr, "_activeHandler", 2923197278UL); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_View_Engine_Php){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View\\Engine, Php, mvc_view_engine_php, "phalcon\\mvc\\view\\engine", phalcon_mvc_view_engine_php_method_entry, 0); - - zend_class_implements(phalcon_mvc_view_engine_php_ce TSRMLS_CC, 1, phalcon_mvc_view_engineinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Php, render){ - - zval *path, *params, *must_clean = NULL, *value = NULL, *key = NULL, *contents; - zval *view; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &path, ¶ms, &must_clean); - - if (!must_clean) { - PHALCON_INIT_VAR(must_clean); - ZVAL_BOOL(must_clean, 0); - } - - if (PHALCON_IS_TRUE(must_clean)) { - phalcon_ob_clean(TSRMLS_C); - } - - if (Z_TYPE_P(params) == IS_ARRAY) { - - phalcon_is_iterable(params, &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_set_symbol(key, value TSRMLS_CC) == FAILURE){ - return; +// 2677 "scanner.c" +yy174: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy175; + default: goto yy87; } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - if (phalcon_require(path TSRMLS_CC) == FAILURE) { - return; - } - if (PHALCON_IS_TRUE(must_clean)) { - PHALCON_INIT_VAR(contents); - phalcon_ob_get_contents(contents TSRMLS_CC); - - PHALCON_OBS_VAR(view); - phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); - phalcon_call_method_p1_key(NULL, view, "setcontent", contents, 4220987916UL); - } - - PHALCON_MM_RESTORE(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_View_Engine_Volt){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View\\Engine, Volt, mvc_view_engine_volt, "phalcon\\mvc\\view\\engine", phalcon_mvc_view_engine_volt_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_view_engine_volt_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_ce, SL("_compiler"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_view_engine_volt_ce TSRMLS_CC, 1, phalcon_mvc_view_engineinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, setOptions){ - - zval *options; - - phalcon_fetch_params(0, 1, 0, &options); - - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Options parameter must be an array"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, getOptions){ - - - RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, getCompiler){ - - zval *compiler = NULL, *view, *options, *dependency_injector; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(compiler); - phalcon_read_property_this_quick(&compiler, this_ptr, SL("_compiler"), 96166463UL, PH_NOISY_CC); - if (Z_TYPE_P(compiler) != IS_OBJECT) { - - PHALCON_OBS_VAR(view); - phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(compiler); - object_init_ex(compiler, phalcon_mvc_view_engine_volt_compiler_ce); - phalcon_call_method_p1_key(NULL, compiler, "__construct", view, 1107214344UL); - - if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { - phalcon_call_method_p1_key(NULL, compiler, "setdi", dependency_injector, 461718238UL); - } - - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_call_method_p1_key(NULL, compiler, "setoptions", options, 1759822653UL); - } - - phalcon_update_property_this_quick(this_ptr, SL("_compiler"), compiler, 96166463UL TSRMLS_CC); - } - - RETURN_CCTOR(compiler); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, render){ - - zval *template_path, *params, *must_clean = NULL, *compiler; - zval *compiled_template_path, *value = NULL, *key = NULL, *contents; - zval *view; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &template_path, ¶ms, &must_clean); - - if (!must_clean) { - PHALCON_INIT_VAR(must_clean); - ZVAL_BOOL(must_clean, 0); - } - - if (PHALCON_IS_TRUE(must_clean)) { - phalcon_ob_clean(TSRMLS_C); - } - - PHALCON_INIT_VAR(compiler); - phalcon_call_method_key(compiler, this_ptr, "getcompiler", 3440133088UL); - phalcon_call_method_p1_key(NULL, compiler, "compile", template_path, 1074882030UL); - - PHALCON_INIT_VAR(compiled_template_path); - phalcon_call_method_key(compiled_template_path, compiler, "getcompiledtemplatepath", 652904091UL); - - if (Z_TYPE_P(params) == IS_ARRAY) { - - phalcon_is_iterable(params, &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_set_symbol(key, value TSRMLS_CC) == FAILURE){ - return; +yy175: + yych = *++YYCURSOR; + switch (yych) { + case 'R': + case 'r': goto yy176; + default: goto yy87; } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - if (phalcon_require(compiled_template_path TSRMLS_CC) == FAILURE) { - return; - } - if (PHALCON_IS_TRUE(must_clean)) { - PHALCON_INIT_VAR(contents); - phalcon_ob_get_contents(contents TSRMLS_CC); - - PHALCON_OBS_VAR(view); - phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); - phalcon_call_method_p1_key(NULL, view, "setcontent", contents, 4220987916UL); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, length){ - - zval *item, *length = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &item); - - PHALCON_INIT_VAR(length); - ZVAL_LONG(length, 0); - if (Z_TYPE_P(item) == IS_OBJECT) { - phalcon_fast_count(length, item TSRMLS_CC); - } else { - if (Z_TYPE_P(item) == IS_ARRAY) { - PHALCON_INIT_NVAR(length); - phalcon_fast_count(length, item TSRMLS_CC); - } else { - if (phalcon_function_quick_exists_ex(SS("mb_strlen"), 3716840971UL TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_NVAR(length); - phalcon_call_func_p1(length, "mb_strlen", item); - } else { - PHALCON_INIT_NVAR(length); - phalcon_fast_strlen(length, item); +yy176: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy177; } +yy177: +// 131 "scanner.re" + { + token->opcode = PHQL_T_ORDER; + return 0; } - } - - RETURN_CCTOR(length); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, isIncluded){ - - zval *needle, *haystack; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &needle, &haystack); - - if (Z_TYPE_P(haystack) == IS_ARRAY) { - phalcon_call_func_p2(return_value, "in_array", needle, haystack); - RETURN_MM(); - } - if (Z_TYPE_P(haystack) == IS_STRING) { - if (phalcon_function_quick_exists_ex(SS("mb_strpos"), 3716995774UL TSRMLS_CC) == SUCCESS) { - phalcon_call_func_p2(return_value, "mb_strpos", haystack, needle); - RETURN_MM(); - } - phalcon_fast_strpos(return_value, haystack, needle); - RETURN_MM(); - } - - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Invalid haystack"); - return; -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, convertEncoding){ - - zval *text, *from, *to; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &text, &from, &to); - - if (PHALCON_IS_STRING(from, "latin1")) { - if (PHALCON_IS_STRING(to, "utf8")) { - phalcon_call_func_p1(return_value, "utf8_encode", text); - RETURN_MM(); - } - } - - if (PHALCON_IS_STRING(to, "latin1")) { - if (PHALCON_IS_STRING(from, "utf8")) { - phalcon_call_func_p1(return_value, "utf8_decode", text); - RETURN_MM(); +// 2767 "scanner.c" +yy178: + yych = *++YYCURSOR; + switch (yych) { + case 'S': + case 's': goto yy179; + default: goto yy87; + } +yy179: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy180; + default: goto yy87; + } +yy180: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy181; + default: goto yy87; + } +yy181: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy182; + } +yy182: +// 166 "scanner.re" + { + token->opcode = PHQL_T_OFFSET; + return 0; } - } - - if (phalcon_function_quick_exists_ex(SS("mb_convert_encoding"), 2165643194UL TSRMLS_CC) == SUCCESS) { - phalcon_call_func_p3(return_value, "mb_convert_encoding", text, from, to); - RETURN_MM(); - } - - if (phalcon_function_quick_exists_ex(SS("iconv"), 67824100UL TSRMLS_CC) == SUCCESS) { - phalcon_call_func_p3(return_value, "iconv", from, to, text); - RETURN_MM(); - } - - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Any of 'mbstring' or 'iconv' is required to perform the charset conversion"); - return; -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, slice){ - - zval *value, *start, *end = NULL, *slice, *length = NULL, *position; - zval *current = NULL, *one, *range; - zval *r0 = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &value, &start, &end); - - if (!end) { - PHALCON_INIT_VAR(end); - } - - if (Z_TYPE_P(value) == IS_OBJECT) { - - PHALCON_INIT_VAR(slice); - array_init(slice); - if (Z_TYPE_P(end) == IS_NULL) { - PHALCON_INIT_VAR(length); - phalcon_fast_count(length, value TSRMLS_CC); - } else { - PHALCON_CPY_WRT(length, end); +// 2864 "scanner.c" +yy183: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy184; + default: goto yy87; + } +yy184: + yych = *++YYCURSOR; + switch (yych) { + case 'R': + case 'r': goto yy185; + default: goto yy87; + } +yy185: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy186; + default: goto yy87; + } +yy186: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy187; + } +yy187: +// 121 "scanner.re" + { + token->opcode = PHQL_T_WHERE; + return 0; } - - PHALCON_INIT_VAR(position); - ZVAL_LONG(position, 0); - phalcon_call_method_key(NULL, value, "rewind", 1064078190UL); - - while (1) { - - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, value, "valid", 574098517UL); - if (zend_is_true(r0)) { - } else { - break; +// 2961 "scanner.c" +yy188: + yych = *++YYCURSOR; + switch (yych) { + case 'L': + case 'l': goto yy189; + default: goto yy87; } - - if (PHALCON_GE(position, start)) { - if (PHALCON_LE(position, length)) { - PHALCON_INIT_NVAR(current); - phalcon_call_method_key(current, value, "current", 431662984UL); - phalcon_array_append(&slice, current, PH_SEPARATE); - } +yy189: + yych = *++YYCURSOR; + switch (yych) { + case 'U': + case 'u': goto yy190; + default: goto yy87; } - phalcon_call_method_key(NULL, value, "next", 268367684UL); - PHALCON_SEPARATE(position); - phalcon_increment(position); +yy190: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy191; + default: goto yy87; + } +yy191: + yych = *++YYCURSOR; + switch (yych) { + case 'S': + case 's': goto yy192; + default: goto yy87; + } +yy192: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy193; + } +yy193: +// 116 "scanner.re" + { + token->opcode = PHQL_T_VALUES; + return 0; } - - RETURN_CTOR(slice); - } - - if (Z_TYPE_P(end) != IS_NULL) { - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - PHALCON_INIT_VAR(range); - sub_function(range, end, start TSRMLS_CC); - - PHALCON_INIT_NVAR(length); - phalcon_add_function(length, range, one TSRMLS_CC); - } else { - PHALCON_INIT_NVAR(length); - } - - if (Z_TYPE_P(value) == IS_ARRAY) { - phalcon_call_func_p3(return_value, "array_slice", value, start, length); - RETURN_MM(); - } - - if (phalcon_function_quick_exists_ex(SS("mb_substr"), 3737269654UL TSRMLS_CC) == SUCCESS) { - if (Z_TYPE_P(length) != IS_NULL) { - phalcon_call_func_p3(return_value, "mb_substr", value, start, length); - RETURN_MM(); +// 3065 "scanner.c" +yy194: + yych = *++YYCURSOR; + switch (yych) { + case 'I': + case 'i': goto yy211; + default: goto yy87; + } +yy195: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'o': + case 'p': + case 'q': + case 'r': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + case 'N': + case 'n': goto yy201; + case 'S': + case 's': goto yy199; + case 'T': + case 't': goto yy200; + default: goto yy196; + } +yy196: +// 201 "scanner.re" + { + token->opcode = PHQL_T_IN; + return 0; } - phalcon_call_func_p2(return_value, "mb_substr", value, start); - RETURN_MM(); - } - - if (Z_TYPE_P(length) != IS_NULL) { - phalcon_call_func_p3(return_value, "substr", value, start, length); - RETURN_MM(); - } - - phalcon_call_func_p2(return_value, "substr", value, start); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, sort){ - - zval *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &value); - - Z_SET_ISREF_P(value); - phalcon_call_func_p1_noret("asort", value); - Z_UNSET_ISREF_P(value); - RETURN_CCTOR(value); -} - - - -/* Driver template for the LEMON parser generator. -** The author disclaims copyright to this source code. -*/ -/* First off, code is include which follows the "include" declaration -** in the input file. */ -#include -// 42 "parser.lemon" - - -#ifdef HAVE_CONFIG_H -#endif - - - - - -static zval *phvolt_ret_literal_zval(int type, phvolt_parser_token *T, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", type); - if (T) { - add_assoc_stringl(ret, "value", T->token, T->token_len, 0); - efree(T); - } - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_if_statement(zval *expr, zval *true_statements, zval *false_statements, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", PHVOLT_T_IF); - add_assoc_zval(ret, "expr", expr); - - if (true_statements) { - add_assoc_zval(ret, "true_statements", true_statements); - } - if (false_statements) { - add_assoc_zval(ret, "false_statements", false_statements); - } - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_elseif_statement(zval *expr, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", PHVOLT_T_ELSEIF); - add_assoc_zval(ret, "expr", expr); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_elsefor_statement(phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", PHVOLT_T_ELSEFOR); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_for_statement(phvolt_parser_token *variable, phvolt_parser_token *key, zval *expr, zval *if_expr, zval *block_statements, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", PHVOLT_T_FOR); - - add_assoc_stringl(ret, "variable", variable->token, variable->token_len, 0); - efree(variable); - - if (key) { - add_assoc_stringl(ret, "key", key->token, key->token_len, 0); - efree(key); - } - - add_assoc_zval(ret, "expr", expr); - - if (if_expr) { - add_assoc_zval(ret, "if_expr", if_expr); - } - - add_assoc_zval(ret, "block_statements", block_statements); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_cache_statement(zval *expr, phvolt_parser_token *lifetime, zval *block_statements, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - - add_assoc_long(ret, "type", PHVOLT_T_CACHE); - add_assoc_zval(ret, "expr", expr); - - if (lifetime) { - add_assoc_stringl(ret, "lifetime", lifetime->token, lifetime->token_len, 0); - efree(lifetime); - } - add_assoc_zval(ret, "block_statements", block_statements); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_set_statement(zval *assignments) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 2); - add_assoc_long(ret, "type", PHVOLT_T_SET); - - add_assoc_zval(ret, "assignments", assignments); - - return ret; -} - -static zval *phvolt_ret_set_assignment(phvolt_parser_token *variable, int operator, zval *expr, phvolt_scanner_state *state) -{ - - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 5); - - add_assoc_stringl(ret, "variable", variable->token, variable->token_len, 0); - efree(variable); - - add_assoc_long(ret, "op", operator); - - add_assoc_zval(ret, "expr", expr); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_echo_statement(zval *expr, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 4); - add_assoc_long(ret, "type", PHVOLT_T_ECHO); - add_assoc_zval(ret, "expr", expr); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_block_statement(phvolt_parser_token *name, zval *block_statements, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - - add_assoc_long(ret, "type", PHVOLT_T_BLOCK); - - add_assoc_stringl(ret, "name", name->token, name->token_len, 0); - efree(name); - - if (block_statements) { - add_assoc_zval(ret, "block_statements", block_statements); - } - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_macro_statement(phvolt_parser_token *macro_name, zval *parameters, zval *block_statements, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", PHVOLT_T_MACRO); - - add_assoc_stringl(ret, "name", macro_name->token, macro_name->token_len, 0); - efree(macro_name); - - if (parameters) { - add_assoc_zval(ret, "parameters", parameters); - } - - if (block_statements) { - add_assoc_zval(ret, "block_statements", block_statements); - } - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_macro_parameter(phvolt_parser_token *variable, zval *default_value, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 5); - - add_assoc_stringl(ret, "variable", variable->token, variable->token_len, 0); - efree(variable); - - if (default_value) { - add_assoc_zval(ret, "default", default_value); - } - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_extends_statement(phvolt_parser_token *P, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 4); - - add_assoc_long(ret, "type", PHVOLT_T_EXTENDS); - add_assoc_stringl(ret, "path", P->token, P->token_len, 0); - efree(P); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_include_statement(zval *path, zval *params, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 4); - - add_assoc_long(ret, "type", PHVOLT_T_INCLUDE); - - add_assoc_zval(ret, "path", path); - if (params) { - add_assoc_zval(ret, "params", params); - } - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_do_statement(zval *expr, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 4); - - add_assoc_long(ret, "type", PHVOLT_T_DO); - - add_assoc_zval(ret, "expr", expr); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_return_statement(zval *expr, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 4); - - add_assoc_long(ret, "type", PHVOLT_T_RETURN); - - add_assoc_zval(ret, "expr", expr); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_autoescape_statement(int enable, zval *block_statements, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 5); - - add_assoc_long(ret, "type", PHVOLT_T_AUTOESCAPE); - add_assoc_long(ret, "enable", enable); - add_assoc_zval(ret, "block_statements", block_statements); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_empty_statement(phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 3); - add_assoc_long(ret, "type", PHVOLT_T_EMPTY); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_break_statement(phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 3); - add_assoc_long(ret, "type", PHVOLT_T_BREAK); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_continue_statement(phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 3); - add_assoc_long(ret, "type", PHVOLT_T_CONTINUE); - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_zval_list(zval *list_left, zval *right_list) -{ - - zval *ret; - HashPosition pos; - HashTable *list; - - MAKE_STD_ZVAL(ret); - array_init(ret); - - if (list_left) { - - list = Z_ARRVAL_P(list_left); - if (zend_hash_index_exists(list, 0)) { - zend_hash_internal_pointer_reset_ex(list, &pos); - for (;; zend_hash_move_forward_ex(list, &pos)) { - - zval ** item; - - if (zend_hash_get_current_data_ex(list, (void**) &item, &pos) == FAILURE) { - break; - } - - Z_ADDREF_PP(item); - add_next_index_zval(ret, *item); - +// 3148 "scanner.c" +yy197: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy198; } - zval_ptr_dtor(&list_left); - } else { - add_next_index_zval(ret, list_left); +yy198: +// 246 "scanner.re" + { + token->opcode = PHQL_T_IS; + return 0; } - } - - add_next_index_zval(ret, right_list); - - return ret; -} - -static zval *phvolt_ret_named_item(phvolt_parser_token *name, zval *expr, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_zval(ret, "expr", expr); - if (name != NULL) { - add_assoc_stringl(ret, "name", name->token, name->token_len, 0); - efree(name); - } - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_expr(int type, zval *left, zval *right, zval *ternary, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", type); - - if (ternary) { - add_assoc_zval(ret, "ternary", ternary); - } - - if (left) { - add_assoc_zval(ret, "left", left); - } - - if (right) { - add_assoc_zval(ret, "right", right); - } - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_slice(zval *left, zval *start, zval *end, phvolt_scanner_state *state) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", PHVOLT_T_SLICE); - add_assoc_zval(ret, "left", left); - - if (start != NULL) { - add_assoc_zval(ret, "start", start); - } - - if (end != NULL) { - add_assoc_zval(ret, "end", end); - } - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_func_call(zval *expr, zval *arguments, phvolt_scanner_state *state) -{ - - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", PHVOLT_T_FCALL); - add_assoc_zval(ret, "name", expr); - - if (arguments) { - add_assoc_zval(ret, "arguments", arguments); - } - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - -static zval *phvolt_ret_macro_call_statement(zval *expr, zval *arguments, zval *caller, phvolt_scanner_state *state) -{ - - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", PHVOLT_T_CALL); - add_assoc_zval(ret, "name", expr); - - if (arguments) { - add_assoc_zval(ret, "arguments", arguments); - } - - if (caller) { - add_assoc_zval(ret, "caller", caller); - } - - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); - - return ret; -} - - -// 571 "parser.c" -/* Next is all token values, in a form suitable for use by makeheaders. -** This section will be null unless lemon is run with the -m switch. -*/ -/* Make sure the INTERFACE macro is defined. -*/ -#ifndef INTERFACE -# define INTERFACE 1 -#endif -/* The next thing included is series of defines which control -** various aspects of the generated parser. -** KKCODETYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 terminals -** and nonterminals. "int" is used otherwise. -** KKNOCODE is a number of type KKCODETYPE which corresponds -** to no legal terminal or nonterminal number. This -** number is used to fill in empty slots of the hash -** table. -** KKFALLBACK If defined, this indicates that one or more tokens -** have fall-back values which should be used if the -** original value of the token will not parse. -** KKACTIONTYPE is the data type used for storing terminal -** and nonterminal numbers. "unsigned char" is -** used if there are fewer than 250 rules and -** states combined. "int" is used otherwise. -** phvolt_KTOKENTYPE is the data type used for minor tokens given -** directly to the parser from the tokenizer. -** KKMINORTYPE is the data type used for all minor tokens. -** This is typically a union of many types, one of -** which is phvolt_KTOKENTYPE. The entry in the union -** for base tokens is called "kk0". -** KKSTACKDEPTH is the maximum depth of the parser's stack. -** phvolt_ARG_SDECL A static variable declaration for the %extra_argument -** phvolt_ARG_PDECL A parameter declaration for the %extra_argument -** phvolt_ARG_STORE Code to store %extra_argument into kkpParser -** phvolt_ARG_FETCH Code to extract %extra_argument from kkpParser -** KKNSTATE the combined number of states. -** KKNRULE the number of rules in the grammar -** KKERRORSYMBOL is the code number of the error symbol. If not -** defined, then do no error processing. -*/ -#define KKCODETYPE unsigned char -#define KKNOCODE 114 -#define KKACTIONTYPE unsigned short int -#define phvolt_KTOKENTYPE phvolt_parser_token* -typedef union { - phvolt_KTOKENTYPE kk0; - zval* kk132; - int kk227; -} KKMINORTYPE; -#define KKSTACKDEPTH 100 -#define phvolt_ARG_SDECL phvolt_parser_status *status; -#define phvolt_ARG_PDECL ,phvolt_parser_status *status -#define phvolt_ARG_FETCH phvolt_parser_status *status = kkpParser->status -#define phvolt_ARG_STORE kkpParser->status = status -#define KKNSTATE 322 -#define KKNRULE 133 -#define KKERRORSYMBOL 77 -#define KKERRSYMDT kk227 -#define KK_NO_ACTION (KKNSTATE+KKNRULE+2) -#define KK_ACCEPT_ACTION (KKNSTATE+KKNRULE+1) -#define KK_ERROR_ACTION (KKNSTATE+KKNRULE) - -/* Next are that tables used to determine what action to take based on the -** current state and lookahead token. These tables are used to implement -** functions that take a state number and lookahead value and return an -** action integer. -** -** Suppose the action integer is N. Then the action is determined as -** follows -** -** 0 <= N < KKNSTATE Shift N. That is, push the lookahead -** token onto the stack and goto state N. -** -** KKNSTATE <= N < KKNSTATE+KKNRULE Reduce by rule N-KKNSTATE. -** -** N == KKNSTATE+KKNRULE A syntax error has occurred. -** -** N == KKNSTATE+KKNRULE+1 The parser accepts its input. -** -** N == KKNSTATE+KKNRULE+2 No such action. Denotes unused -** slots in the kk_action[] table. -** -** The action table is constructed as a single large table named kk_action[]. -** Given state S and lookahead X, the action is computed as -** -** kk_action[ kk_shift_ofst[S] + X ] -** -** If the index value kk_shift_ofst[S]+X is out of range or if the value -** kk_lookahead[kk_shift_ofst[S]+X] is not equal to X or if kk_shift_ofst[S] -** is equal to KK_SHIFT_USE_DFLT, it means that the action is not in the table -** and that kk_default[S] should be used instead. -** -** The formula above is for computing the action when the lookahead is -** a terminal symbol. If the lookahead is a non-terminal (as occurs after -** a reduce action) then the kk_reduce_ofst[] array is used in place of -** the kk_shift_ofst[] array and KK_REDUCE_USE_DFLT is used in place of -** KK_SHIFT_USE_DFLT. -** -** The following are the tables generated in this section: -** -** kk_action[] A single table containing all actions. -** kk_lookahead[] A table containing the lookahead for each entry in -** kk_action. Used to detect hash collisions. -** kk_shift_ofst[] For each state, the offset into kk_action for -** shifting terminals. -** kk_reduce_ofst[] For each state, the offset into kk_action for -** shifting non-terminals after a reduce. -** kk_default[] Default action for each state. -*/ -static KKACTIONTYPE kk_action[] = { - /* 0 */ 82, 92, 23, 60, 52, 54, 64, 62, 66, 72, - /* 10 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, - /* 20 */ 56, 89, 58, 84, 87, 88, 96, 80, 288, 162, - /* 30 */ 82, 92, 128, 60, 52, 54, 64, 62, 66, 72, - /* 40 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, - /* 50 */ 56, 89, 58, 84, 87, 88, 96, 80, 244, 213, - /* 60 */ 48, 46, 50, 43, 40, 56, 89, 58, 84, 87, - /* 70 */ 88, 96, 80, 247, 295, 160, 255, 127, 168, 183, - /* 80 */ 82, 92, 170, 60, 52, 54, 64, 62, 66, 72, - /* 90 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, - /* 100 */ 56, 89, 58, 84, 87, 88, 96, 80, 322, 223, - /* 110 */ 82, 92, 169, 60, 52, 54, 64, 62, 66, 72, - /* 120 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, - /* 130 */ 56, 89, 58, 84, 87, 88, 96, 80, 304, 299, - /* 140 */ 82, 92, 224, 60, 52, 54, 64, 62, 66, 72, - /* 150 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, - /* 160 */ 56, 89, 58, 84, 87, 88, 96, 80, 30, 26, - /* 170 */ 82, 92, 32, 60, 52, 54, 64, 62, 66, 72, - /* 180 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, - /* 190 */ 56, 89, 58, 84, 87, 88, 96, 80, 108, 39, - /* 200 */ 82, 92, 108, 60, 52, 54, 64, 62, 66, 72, - /* 210 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, - /* 220 */ 56, 89, 58, 84, 87, 88, 96, 80, 82, 92, - /* 230 */ 94, 60, 52, 54, 64, 62, 66, 72, 74, 76, - /* 240 */ 78, 68, 70, 48, 46, 50, 43, 40, 56, 89, - /* 250 */ 58, 84, 87, 88, 96, 80, 43, 40, 56, 89, - /* 260 */ 58, 84, 87, 88, 96, 80, 84, 87, 88, 96, - /* 270 */ 80, 91, 112, 128, 107, 82, 92, 276, 60, 52, - /* 280 */ 54, 64, 62, 66, 72, 74, 76, 78, 68, 70, - /* 290 */ 48, 46, 50, 43, 40, 56, 89, 58, 84, 87, - /* 300 */ 88, 96, 80, 89, 58, 84, 87, 88, 96, 80, - /* 310 */ 281, 282, 283, 284, 285, 286, 269, 287, 197, 102, - /* 320 */ 234, 249, 270, 82, 92, 36, 60, 52, 54, 64, - /* 330 */ 62, 66, 72, 74, 76, 78, 68, 70, 48, 46, - /* 340 */ 50, 43, 40, 56, 89, 58, 84, 87, 88, 96, - /* 350 */ 80, 85, 226, 82, 92, 136, 60, 52, 54, 64, - /* 360 */ 62, 66, 72, 74, 76, 78, 68, 70, 48, 46, - /* 370 */ 50, 43, 40, 56, 89, 58, 84, 87, 88, 96, - /* 380 */ 80, 115, 229, 82, 92, 137, 60, 52, 54, 64, - /* 390 */ 62, 66, 72, 74, 76, 78, 68, 70, 48, 46, - /* 400 */ 50, 43, 40, 56, 89, 58, 84, 87, 88, 96, - /* 410 */ 80, 131, 232, 82, 92, 435, 60, 52, 54, 64, - /* 420 */ 62, 66, 72, 74, 76, 78, 68, 70, 48, 46, - /* 430 */ 50, 43, 40, 56, 89, 58, 84, 87, 88, 96, - /* 440 */ 80, 92, 436, 60, 52, 54, 64, 62, 66, 72, - /* 450 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, - /* 460 */ 56, 89, 58, 84, 87, 88, 96, 80, 246, 141, - /* 470 */ 143, 144, 82, 92, 157, 60, 52, 54, 64, 62, - /* 480 */ 66, 72, 74, 76, 78, 68, 70, 48, 46, 50, - /* 490 */ 43, 40, 56, 89, 58, 84, 87, 88, 96, 80, - /* 500 */ 435, 290, 82, 92, 159, 60, 52, 54, 64, 62, - /* 510 */ 66, 72, 74, 76, 78, 68, 70, 48, 46, 50, - /* 520 */ 43, 40, 56, 89, 58, 84, 87, 88, 96, 80, - /* 530 */ 436, 306, 82, 92, 166, 60, 52, 54, 64, 62, - /* 540 */ 66, 72, 74, 76, 78, 68, 70, 48, 46, 50, - /* 550 */ 43, 40, 56, 89, 58, 84, 87, 88, 96, 80, - /* 560 */ 82, 92, 172, 60, 52, 54, 64, 62, 66, 72, - /* 570 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, - /* 580 */ 56, 89, 58, 84, 87, 88, 195, 80, 60, 52, - /* 590 */ 54, 64, 62, 66, 72, 74, 76, 78, 68, 70, - /* 600 */ 48, 46, 50, 43, 40, 56, 89, 58, 84, 87, - /* 610 */ 88, 96, 80, 52, 54, 64, 62, 66, 72, 74, - /* 620 */ 76, 78, 68, 70, 48, 46, 50, 43, 40, 56, - /* 630 */ 89, 58, 84, 87, 88, 96, 80, 456, 1, 2, - /* 640 */ 248, 4, 5, 6, 7, 8, 9, 10, 11, 12, - /* 650 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - /* 660 */ 64, 62, 66, 72, 74, 76, 78, 68, 70, 48, - /* 670 */ 46, 50, 43, 40, 56, 89, 58, 84, 87, 88, - /* 680 */ 96, 80, 27, 248, 4, 5, 6, 7, 8, 9, - /* 690 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - /* 700 */ 20, 21, 22, 33, 248, 4, 5, 6, 7, 8, - /* 710 */ 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - /* 720 */ 19, 20, 21, 22, 163, 248, 4, 5, 6, 7, - /* 730 */ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - /* 740 */ 18, 19, 20, 21, 22, 189, 248, 4, 5, 6, - /* 750 */ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - /* 760 */ 17, 18, 19, 20, 21, 22, 199, 248, 4, 5, - /* 770 */ 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - /* 780 */ 16, 17, 18, 19, 20, 21, 22, 207, 248, 4, - /* 790 */ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - /* 800 */ 15, 16, 17, 18, 19, 20, 21, 22, 214, 248, - /* 810 */ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - /* 820 */ 14, 15, 16, 17, 18, 19, 20, 21, 22, 236, - /* 830 */ 248, 4, 5, 6, 7, 8, 9, 10, 11, 12, - /* 840 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - /* 850 */ 251, 248, 4, 5, 6, 7, 8, 9, 10, 11, - /* 860 */ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, - /* 870 */ 22, 257, 248, 4, 5, 6, 7, 8, 9, 10, - /* 880 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - /* 890 */ 21, 22, 272, 248, 4, 5, 6, 7, 8, 9, - /* 900 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - /* 910 */ 20, 21, 22, 291, 248, 4, 5, 6, 7, 8, - /* 920 */ 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - /* 930 */ 19, 20, 21, 22, 300, 248, 4, 5, 6, 7, - /* 940 */ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - /* 950 */ 18, 19, 20, 21, 22, 307, 248, 4, 5, 6, - /* 960 */ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - /* 970 */ 17, 18, 19, 20, 21, 22, 3, 4, 5, 6, - /* 980 */ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - /* 990 */ 17, 18, 19, 20, 21, 22, 24, 203, 29, 31, - /* 1000 */ 37, 156, 158, 323, 23, 167, 171, 185, 25, 90, - /* 1010 */ 139, 184, 173, 175, 177, 179, 181, 140, 117, 117, - /* 1020 */ 193, 138, 186, 188, 204, 278, 211, 192, 218, 221, - /* 1030 */ 198, 227, 230, 233, 187, 240, 242, 24, 203, 315, - /* 1040 */ 317, 37, 156, 158, 97, 314, 167, 38, 202, 104, - /* 1050 */ 126, 28, 184, 104, 117, 134, 106, 117, 113, 117, - /* 1060 */ 244, 193, 125, 117, 205, 204, 266, 211, 206, 218, - /* 1070 */ 221, 219, 227, 230, 233, 247, 240, 242, 24, 203, - /* 1080 */ 35, 104, 37, 156, 158, 155, 97, 167, 111, 97, - /* 1090 */ 113, 117, 196, 184, 139, 117, 117, 134, 210, 117, - /* 1100 */ 129, 244, 193, 217, 220, 138, 204, 244, 211, 235, - /* 1110 */ 218, 221, 311, 227, 230, 233, 247, 240, 242, 24, - /* 1120 */ 203, 42, 247, 37, 156, 158, 154, 165, 167, 239, - /* 1130 */ 142, 117, 241, 243, 184, 45, 117, 250, 47, 267, - /* 1140 */ 49, 254, 256, 193, 260, 117, 263, 204, 117, 211, - /* 1150 */ 117, 218, 221, 34, 227, 230, 233, 164, 240, 242, - /* 1160 */ 24, 203, 51, 53, 37, 156, 158, 265, 244, 167, - /* 1170 */ 268, 55, 117, 117, 271, 184, 57, 191, 275, 190, - /* 1180 */ 279, 117, 280, 247, 193, 278, 117, 277, 204, 297, - /* 1190 */ 211, 294, 218, 221, 59, 227, 230, 233, 200, 240, - /* 1200 */ 242, 24, 203, 296, 117, 37, 156, 158, 61, 244, - /* 1210 */ 167, 303, 310, 244, 313, 316, 184, 63, 117, 318, - /* 1220 */ 319, 320, 65, 321, 247, 193, 201, 117, 247, 204, - /* 1230 */ 261, 211, 117, 218, 221, 244, 227, 230, 233, 208, - /* 1240 */ 240, 242, 24, 203, 248, 67, 37, 156, 158, 69, - /* 1250 */ 247, 167, 71, 248, 244, 117, 215, 184, 73, 117, - /* 1260 */ 248, 248, 117, 75, 248, 248, 193, 248, 117, 247, - /* 1270 */ 204, 209, 211, 117, 218, 221, 237, 227, 230, 233, - /* 1280 */ 252, 240, 242, 24, 203, 248, 244, 37, 156, 158, - /* 1290 */ 77, 248, 167, 248, 79, 244, 81, 258, 184, 83, - /* 1300 */ 117, 247, 248, 248, 117, 248, 117, 193, 248, 117, - /* 1310 */ 247, 204, 244, 211, 216, 218, 221, 273, 227, 230, - /* 1320 */ 233, 292, 240, 242, 24, 203, 248, 247, 37, 156, - /* 1330 */ 158, 86, 244, 167, 93, 95, 244, 248, 301, 184, - /* 1340 */ 99, 117, 248, 248, 117, 117, 248, 247, 193, 248, - /* 1350 */ 117, 247, 204, 244, 211, 248, 218, 221, 308, 227, - /* 1360 */ 230, 233, 238, 240, 242, 24, 203, 248, 247, 37, - /* 1370 */ 156, 158, 101, 244, 167, 116, 248, 244, 248, 248, - /* 1380 */ 184, 132, 117, 248, 248, 117, 151, 248, 247, 193, - /* 1390 */ 248, 117, 247, 204, 244, 211, 117, 218, 221, 248, - /* 1400 */ 227, 230, 233, 253, 240, 242, 24, 203, 153, 247, - /* 1410 */ 37, 156, 158, 161, 244, 167, 174, 248, 117, 248, - /* 1420 */ 248, 184, 176, 117, 248, 178, 117, 248, 248, 247, - /* 1430 */ 193, 248, 117, 248, 204, 117, 211, 259, 218, 221, - /* 1440 */ 180, 227, 230, 233, 248, 240, 242, 24, 203, 182, - /* 1450 */ 117, 37, 156, 158, 194, 212, 167, 248, 248, 117, - /* 1460 */ 222, 248, 184, 225, 117, 117, 248, 248, 228, 248, - /* 1470 */ 117, 193, 248, 117, 248, 204, 262, 211, 117, 218, - /* 1480 */ 221, 248, 227, 230, 233, 248, 240, 242, 24, 203, - /* 1490 */ 231, 245, 37, 156, 158, 248, 289, 167, 298, 305, - /* 1500 */ 117, 117, 248, 184, 248, 274, 117, 248, 117, 117, - /* 1510 */ 248, 248, 193, 248, 248, 248, 204, 248, 211, 248, - /* 1520 */ 218, 221, 248, 227, 230, 233, 248, 240, 242, 24, - /* 1530 */ 203, 248, 248, 37, 156, 158, 248, 293, 167, 248, - /* 1540 */ 248, 248, 248, 248, 184, 248, 248, 248, 248, 248, - /* 1550 */ 248, 248, 248, 193, 248, 248, 248, 204, 248, 211, - /* 1560 */ 248, 218, 221, 248, 227, 230, 233, 248, 240, 242, - /* 1570 */ 24, 203, 248, 248, 37, 156, 158, 248, 302, 167, - /* 1580 */ 248, 248, 248, 248, 248, 184, 248, 248, 248, 248, - /* 1590 */ 248, 248, 248, 248, 193, 248, 248, 248, 204, 248, - /* 1600 */ 211, 248, 218, 221, 248, 227, 230, 233, 248, 240, - /* 1610 */ 242, 24, 203, 248, 248, 37, 156, 158, 248, 309, - /* 1620 */ 167, 248, 248, 248, 248, 248, 184, 248, 248, 248, - /* 1630 */ 248, 248, 248, 248, 248, 193, 248, 248, 248, 204, - /* 1640 */ 248, 211, 248, 218, 221, 248, 227, 230, 233, 248, - /* 1650 */ 240, 242, 24, 203, 312, 248, 37, 156, 158, 248, - /* 1660 */ 248, 167, 248, 248, 248, 248, 248, 184, 248, 248, - /* 1670 */ 248, 248, 248, 248, 248, 248, 193, 248, 248, 248, - /* 1680 */ 204, 248, 211, 248, 218, 221, 248, 227, 230, 233, - /* 1690 */ 248, 240, 242, 24, 203, 248, 248, 37, 156, 158, - /* 1700 */ 248, 248, 167, 248, 248, 248, 248, 248, 184, 248, - /* 1710 */ 248, 248, 248, 248, 248, 248, 248, 193, 248, 248, - /* 1720 */ 248, 204, 248, 211, 248, 218, 221, 248, 227, 230, - /* 1730 */ 233, 248, 240, 242, 248, 248, 248, 152, 248, 44, - /* 1740 */ 41, 248, 103, 248, 98, 248, 248, 100, 248, 248, - /* 1750 */ 248, 248, 248, 248, 248, 248, 118, 248, 248, 248, - /* 1760 */ 248, 248, 248, 248, 248, 248, 248, 119, 120, 121, - /* 1770 */ 122, 123, 124, 248, 248, 150, 248, 248, 44, 41, - /* 1780 */ 248, 103, 248, 98, 248, 248, 100, 248, 248, 248, - /* 1790 */ 248, 248, 248, 109, 248, 118, 248, 44, 41, 248, - /* 1800 */ 103, 248, 147, 248, 248, 100, 119, 120, 121, 122, - /* 1810 */ 123, 124, 248, 248, 118, 248, 248, 135, 248, 248, - /* 1820 */ 248, 248, 248, 248, 248, 119, 120, 121, 122, 123, - /* 1830 */ 124, 248, 109, 44, 41, 248, 103, 248, 98, 248, - /* 1840 */ 248, 100, 248, 248, 248, 248, 248, 248, 248, 149, - /* 1850 */ 146, 109, 44, 41, 248, 103, 248, 98, 248, 248, - /* 1860 */ 100, 145, 120, 121, 122, 123, 124, 248, 248, 118, - /* 1870 */ 248, 44, 41, 248, 103, 248, 98, 248, 133, 100, - /* 1880 */ 119, 130, 121, 122, 123, 124, 248, 109, 118, 248, - /* 1890 */ 248, 248, 248, 248, 248, 248, 248, 248, 248, 119, - /* 1900 */ 114, 121, 122, 123, 124, 248, 109, 248, 248, 44, - /* 1910 */ 41, 248, 103, 248, 98, 248, 248, 100, 248, 248, - /* 1920 */ 248, 248, 248, 248, 105, 109, 118, 248, 44, 41, - /* 1930 */ 248, 103, 248, 98, 248, 248, 100, 119, 114, 121, - /* 1940 */ 122, 123, 124, 248, 248, 118, 248, 248, 248, 248, - /* 1950 */ 248, 248, 248, 248, 248, 248, 119, 120, 121, 122, - /* 1960 */ 123, 124, 248, 109, 110, 248, 248, 44, 41, 248, - /* 1970 */ 103, 248, 98, 248, 248, 100, 248, 248, 248, 248, - /* 1980 */ 148, 248, 109, 248, 118, 248, 44, 41, 248, 103, - /* 1990 */ 248, 98, 248, 264, 100, 119, 130, 121, 122, 123, - /* 2000 */ 124, 248, 248, 118, 248, 248, 248, 248, 248, 248, - /* 2010 */ 248, 248, 248, 248, 119, 120, 121, 122, 123, 124, - /* 2020 */ 248, 109, 44, 41, 248, 103, 248, 98, 248, 248, - /* 2030 */ 100, 248, 248, 248, 248, 248, 248, 248, 248, 118, - /* 2040 */ 109, 44, 41, 248, 103, 248, 98, 248, 248, 100, - /* 2050 */ 119, 114, 121, 122, 123, 124, 248, 248, 118, 248, - /* 2060 */ 248, 248, 248, 248, 248, 248, 248, 248, 248, 119, - /* 2070 */ 130, 121, 122, 123, 124, 248, 109, 248, 248, 248, - /* 2080 */ 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, - /* 2090 */ 248, 248, 248, 248, 248, 109, -}; -static KKCODETYPE kk_lookahead[] = { - /* 0 */ 3, 4, 1, 6, 7, 8, 9, 10, 11, 12, - /* 10 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - /* 20 */ 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - /* 30 */ 3, 4, 2, 6, 7, 8, 9, 10, 11, 12, - /* 40 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - /* 50 */ 23, 24, 25, 26, 27, 28, 29, 30, 57, 32, - /* 60 */ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, - /* 70 */ 28, 29, 30, 72, 2, 3, 49, 47, 102, 103, - /* 80 */ 3, 4, 2, 6, 7, 8, 9, 10, 11, 12, - /* 90 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - /* 100 */ 23, 24, 25, 26, 27, 28, 29, 30, 0, 32, - /* 110 */ 3, 4, 32, 6, 7, 8, 9, 10, 11, 12, - /* 120 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - /* 130 */ 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - /* 140 */ 3, 4, 65, 6, 7, 8, 9, 10, 11, 12, - /* 150 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - /* 160 */ 23, 24, 25, 26, 27, 28, 29, 30, 32, 32, - /* 170 */ 3, 4, 32, 6, 7, 8, 9, 10, 11, 12, - /* 180 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - /* 190 */ 23, 24, 25, 26, 27, 28, 29, 30, 2, 32, - /* 200 */ 3, 4, 2, 6, 7, 8, 9, 10, 11, 12, - /* 210 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - /* 220 */ 23, 24, 25, 26, 27, 28, 29, 30, 3, 4, - /* 230 */ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - /* 240 */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - /* 250 */ 25, 26, 27, 28, 29, 30, 21, 22, 23, 24, - /* 260 */ 25, 26, 27, 28, 29, 30, 26, 27, 28, 29, - /* 270 */ 30, 74, 76, 2, 74, 3, 4, 2, 6, 7, - /* 280 */ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - /* 290 */ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, - /* 300 */ 28, 29, 30, 24, 25, 26, 27, 28, 29, 30, - /* 310 */ 49, 50, 51, 52, 53, 54, 104, 105, 47, 47, - /* 320 */ 53, 54, 47, 3, 4, 32, 6, 7, 8, 9, - /* 330 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - /* 340 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - /* 350 */ 30, 3, 32, 3, 4, 109, 6, 7, 8, 9, - /* 360 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - /* 370 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - /* 380 */ 30, 5, 32, 3, 4, 74, 6, 7, 8, 9, - /* 390 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - /* 400 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - /* 410 */ 30, 5, 32, 3, 4, 74, 6, 7, 8, 9, - /* 420 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, - /* 430 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, - /* 440 */ 30, 4, 74, 6, 7, 8, 9, 10, 11, 12, - /* 450 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - /* 460 */ 23, 24, 25, 26, 27, 28, 29, 30, 58, 5, - /* 470 */ 109, 74, 3, 4, 32, 6, 7, 8, 9, 10, - /* 480 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - /* 490 */ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - /* 500 */ 5, 32, 3, 4, 38, 6, 7, 8, 9, 10, - /* 510 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - /* 520 */ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - /* 530 */ 5, 32, 3, 4, 32, 6, 7, 8, 9, 10, - /* 540 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, - /* 550 */ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, - /* 560 */ 3, 4, 38, 6, 7, 8, 9, 10, 11, 12, - /* 570 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, - /* 580 */ 23, 24, 25, 26, 27, 28, 29, 30, 6, 7, - /* 590 */ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - /* 600 */ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, - /* 610 */ 28, 29, 30, 7, 8, 9, 10, 11, 12, 13, - /* 620 */ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, - /* 630 */ 24, 25, 26, 27, 28, 29, 30, 78, 79, 80, - /* 640 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, - /* 650 */ 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, - /* 660 */ 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, - /* 670 */ 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, - /* 680 */ 29, 30, 80, 81, 82, 83, 84, 85, 86, 87, - /* 690 */ 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, - /* 700 */ 98, 99, 100, 80, 81, 82, 83, 84, 85, 86, - /* 710 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, - /* 720 */ 97, 98, 99, 100, 80, 81, 82, 83, 84, 85, - /* 730 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - /* 740 */ 96, 97, 98, 99, 100, 80, 81, 82, 83, 84, - /* 750 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, - /* 760 */ 95, 96, 97, 98, 99, 100, 80, 81, 82, 83, - /* 770 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, - /* 780 */ 94, 95, 96, 97, 98, 99, 100, 80, 81, 82, - /* 790 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - /* 800 */ 93, 94, 95, 96, 97, 98, 99, 100, 80, 81, - /* 810 */ 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, - /* 820 */ 92, 93, 94, 95, 96, 97, 98, 99, 100, 80, - /* 830 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, - /* 840 */ 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, - /* 850 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, - /* 860 */ 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, - /* 870 */ 100, 80, 81, 82, 83, 84, 85, 86, 87, 88, - /* 880 */ 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, - /* 890 */ 99, 100, 80, 81, 82, 83, 84, 85, 86, 87, - /* 900 */ 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, - /* 910 */ 98, 99, 100, 80, 81, 82, 83, 84, 85, 86, - /* 920 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, - /* 930 */ 97, 98, 99, 100, 80, 81, 82, 83, 84, 85, - /* 940 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - /* 950 */ 96, 97, 98, 99, 100, 80, 81, 82, 83, 84, - /* 960 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, - /* 970 */ 95, 96, 97, 98, 99, 100, 81, 82, 83, 84, - /* 980 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, - /* 990 */ 95, 96, 97, 98, 99, 100, 31, 32, 33, 34, - /* 1000 */ 35, 36, 37, 0, 1, 40, 103, 38, 101, 101, - /* 1010 */ 38, 46, 41, 42, 43, 44, 45, 109, 111, 111, - /* 1020 */ 55, 49, 29, 32, 59, 38, 61, 32, 63, 64, - /* 1030 */ 32, 66, 67, 68, 47, 70, 71, 31, 32, 33, - /* 1040 */ 34, 35, 36, 37, 101, 1, 40, 101, 32, 101, - /* 1050 */ 107, 1, 46, 101, 111, 112, 108, 111, 110, 111, - /* 1060 */ 57, 55, 110, 111, 38, 59, 1, 61, 32, 63, - /* 1070 */ 64, 50, 66, 67, 68, 72, 70, 71, 31, 32, - /* 1080 */ 33, 101, 35, 36, 37, 101, 101, 40, 108, 101, - /* 1090 */ 110, 111, 107, 46, 38, 111, 111, 112, 32, 111, - /* 1100 */ 112, 57, 55, 32, 32, 49, 59, 57, 61, 32, - /* 1110 */ 63, 64, 1, 66, 67, 68, 72, 70, 71, 31, - /* 1120 */ 32, 101, 72, 35, 36, 37, 101, 39, 40, 32, - /* 1130 */ 74, 111, 32, 32, 46, 101, 111, 32, 101, 56, - /* 1140 */ 101, 32, 32, 55, 32, 111, 32, 59, 111, 61, - /* 1150 */ 111, 63, 64, 1, 66, 67, 68, 1, 70, 71, - /* 1160 */ 31, 32, 101, 101, 35, 36, 37, 32, 57, 40, - /* 1170 */ 32, 101, 111, 111, 32, 46, 101, 48, 32, 1, - /* 1180 */ 41, 111, 106, 72, 55, 38, 111, 105, 59, 3, - /* 1190 */ 61, 32, 63, 64, 101, 66, 67, 68, 1, 70, - /* 1200 */ 71, 31, 32, 38, 111, 35, 36, 37, 101, 57, - /* 1210 */ 40, 32, 32, 57, 32, 32, 46, 101, 111, 32, - /* 1220 */ 1, 33, 101, 32, 72, 55, 56, 111, 72, 59, - /* 1230 */ 1, 61, 111, 63, 64, 57, 66, 67, 68, 1, - /* 1240 */ 70, 71, 31, 32, 113, 101, 35, 36, 37, 101, - /* 1250 */ 72, 40, 101, 113, 57, 111, 1, 46, 101, 111, - /* 1260 */ 113, 113, 111, 101, 113, 113, 55, 113, 111, 72, - /* 1270 */ 59, 60, 61, 111, 63, 64, 1, 66, 67, 68, - /* 1280 */ 1, 70, 71, 31, 32, 113, 57, 35, 36, 37, - /* 1290 */ 101, 113, 40, 113, 101, 57, 101, 1, 46, 101, - /* 1300 */ 111, 72, 113, 113, 111, 113, 111, 55, 113, 111, - /* 1310 */ 72, 59, 57, 61, 62, 63, 64, 1, 66, 67, - /* 1320 */ 68, 1, 70, 71, 31, 32, 113, 72, 35, 36, - /* 1330 */ 37, 101, 57, 40, 101, 101, 57, 113, 1, 46, - /* 1340 */ 101, 111, 113, 113, 111, 111, 113, 72, 55, 113, - /* 1350 */ 111, 72, 59, 57, 61, 113, 63, 64, 1, 66, - /* 1360 */ 67, 68, 69, 70, 71, 31, 32, 113, 72, 35, - /* 1370 */ 36, 37, 101, 57, 40, 101, 113, 57, 113, 113, - /* 1380 */ 46, 101, 111, 113, 113, 111, 101, 113, 72, 55, - /* 1390 */ 113, 111, 72, 59, 57, 61, 111, 63, 64, 113, - /* 1400 */ 66, 67, 68, 69, 70, 71, 31, 32, 101, 72, - /* 1410 */ 35, 36, 37, 101, 57, 40, 101, 113, 111, 113, - /* 1420 */ 113, 46, 101, 111, 113, 101, 111, 113, 113, 72, - /* 1430 */ 55, 113, 111, 113, 59, 111, 61, 62, 63, 64, - /* 1440 */ 101, 66, 67, 68, 113, 70, 71, 31, 32, 101, - /* 1450 */ 111, 35, 36, 37, 101, 101, 40, 113, 113, 111, - /* 1460 */ 101, 113, 46, 101, 111, 111, 113, 113, 101, 113, - /* 1470 */ 111, 55, 113, 111, 113, 59, 60, 61, 111, 63, - /* 1480 */ 64, 113, 66, 67, 68, 113, 70, 71, 31, 32, - /* 1490 */ 101, 101, 35, 36, 37, 113, 101, 40, 101, 101, - /* 1500 */ 111, 111, 113, 46, 113, 48, 111, 113, 111, 111, - /* 1510 */ 113, 113, 55, 113, 113, 113, 59, 113, 61, 113, - /* 1520 */ 63, 64, 113, 66, 67, 68, 113, 70, 71, 31, - /* 1530 */ 32, 113, 113, 35, 36, 37, 113, 39, 40, 113, - /* 1540 */ 113, 113, 113, 113, 46, 113, 113, 113, 113, 113, - /* 1550 */ 113, 113, 113, 55, 113, 113, 113, 59, 113, 61, - /* 1560 */ 113, 63, 64, 113, 66, 67, 68, 113, 70, 71, - /* 1570 */ 31, 32, 113, 113, 35, 36, 37, 113, 39, 40, - /* 1580 */ 113, 113, 113, 113, 113, 46, 113, 113, 113, 113, - /* 1590 */ 113, 113, 113, 113, 55, 113, 113, 113, 59, 113, - /* 1600 */ 61, 113, 63, 64, 113, 66, 67, 68, 113, 70, - /* 1610 */ 71, 31, 32, 113, 113, 35, 36, 37, 113, 39, - /* 1620 */ 40, 113, 113, 113, 113, 113, 46, 113, 113, 113, - /* 1630 */ 113, 113, 113, 113, 113, 55, 113, 113, 113, 59, - /* 1640 */ 113, 61, 113, 63, 64, 113, 66, 67, 68, 113, - /* 1650 */ 70, 71, 31, 32, 33, 113, 35, 36, 37, 113, - /* 1660 */ 113, 40, 113, 113, 113, 113, 113, 46, 113, 113, - /* 1670 */ 113, 113, 113, 113, 113, 113, 55, 113, 113, 113, - /* 1680 */ 59, 113, 61, 113, 63, 64, 113, 66, 67, 68, - /* 1690 */ 113, 70, 71, 31, 32, 113, 113, 35, 36, 37, - /* 1700 */ 113, 113, 40, 113, 113, 113, 113, 113, 46, 113, - /* 1710 */ 113, 113, 113, 113, 113, 113, 113, 55, 113, 113, - /* 1720 */ 113, 59, 113, 61, 113, 63, 64, 113, 66, 67, - /* 1730 */ 68, 113, 70, 71, 113, 113, 113, 19, 113, 21, - /* 1740 */ 22, 113, 24, 113, 26, 113, 113, 29, 113, 113, - /* 1750 */ 113, 113, 113, 113, 113, 113, 38, 113, 113, 113, - /* 1760 */ 113, 113, 113, 113, 113, 113, 113, 49, 50, 51, - /* 1770 */ 52, 53, 54, 113, 113, 18, 113, 113, 21, 22, - /* 1780 */ 113, 24, 113, 26, 113, 113, 29, 113, 113, 113, - /* 1790 */ 113, 113, 113, 75, 113, 38, 113, 21, 22, 113, - /* 1800 */ 24, 113, 26, 113, 113, 29, 49, 50, 51, 52, - /* 1810 */ 53, 54, 113, 113, 38, 113, 113, 5, 113, 113, - /* 1820 */ 113, 113, 113, 113, 113, 49, 50, 51, 52, 53, - /* 1830 */ 54, 113, 75, 21, 22, 113, 24, 113, 26, 113, - /* 1840 */ 113, 29, 113, 113, 113, 113, 113, 113, 113, 73, - /* 1850 */ 38, 75, 21, 22, 113, 24, 113, 26, 113, 113, - /* 1860 */ 29, 49, 50, 51, 52, 53, 54, 113, 113, 38, - /* 1870 */ 113, 21, 22, 113, 24, 113, 26, 113, 47, 29, - /* 1880 */ 49, 50, 51, 52, 53, 54, 113, 75, 38, 113, - /* 1890 */ 113, 113, 113, 113, 113, 113, 113, 113, 113, 49, - /* 1900 */ 50, 51, 52, 53, 54, 113, 75, 113, 113, 21, - /* 1910 */ 22, 113, 24, 113, 26, 113, 113, 29, 113, 113, - /* 1920 */ 113, 113, 113, 113, 74, 75, 38, 113, 21, 22, - /* 1930 */ 113, 24, 113, 26, 113, 113, 29, 49, 50, 51, - /* 1940 */ 52, 53, 54, 113, 113, 38, 113, 113, 113, 113, - /* 1950 */ 113, 113, 113, 113, 113, 113, 49, 50, 51, 52, - /* 1960 */ 53, 54, 113, 75, 76, 113, 113, 21, 22, 113, - /* 1970 */ 24, 113, 26, 113, 113, 29, 113, 113, 113, 113, - /* 1980 */ 73, 113, 75, 113, 38, 113, 21, 22, 113, 24, - /* 1990 */ 113, 26, 113, 47, 29, 49, 50, 51, 52, 53, - /* 2000 */ 54, 113, 113, 38, 113, 113, 113, 113, 113, 113, - /* 2010 */ 113, 113, 113, 113, 49, 50, 51, 52, 53, 54, - /* 2020 */ 113, 75, 21, 22, 113, 24, 113, 26, 113, 113, - /* 2030 */ 29, 113, 113, 113, 113, 113, 113, 113, 113, 38, - /* 2040 */ 75, 21, 22, 113, 24, 113, 26, 113, 113, 29, - /* 2050 */ 49, 50, 51, 52, 53, 54, 113, 113, 38, 113, - /* 2060 */ 113, 113, 113, 113, 113, 113, 113, 113, 113, 49, - /* 2070 */ 50, 51, 52, 53, 54, 113, 75, 113, 113, 113, - /* 2080 */ 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, - /* 2090 */ 113, 113, 113, 113, 113, 75, -}; -#define KK_SHIFT_USE_DFLT (-4) -static short kk_shift_ofst[] = { - /* 0 */ 1, 108, 1003, -4, -4, -4, -4, -4, -4, -4, - /* 10 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, - /* 20 */ -4, -4, -4, 1662, 1965, 137, 1044, 1050, 965, 136, - /* 30 */ -4, 140, 1111, 1152, 1047, 293, -4, 1965, 167, -4, - /* 40 */ 1965, 1965, 279, 1965, 1965, 279, 1718, 235, 1757, 235, - /* 50 */ 1965, 235, 1965, 651, 1965, 651, 1965, 279, 1965, 240, - /* 60 */ 1965, 606, 1965, 42, 1776, 42, 1965, 42, 1965, 42, - /* 70 */ 1965, 42, 1965, 42, 1965, 42, 1965, 42, 1965, 42, - /* 80 */ 1965, -4, 1965, 437, 348, 1965, 240, -4, -4, 1812, - /* 90 */ 197, -4, 1965, 225, 1965, 582, 1831, 529, 1965, 240, - /* 100 */ 1965, 272, -4, 1850, 529, -4, 200, -4, 2001, 1888, - /* 110 */ -4, 196, -4, -4, 376, 1965, 529, -4, -4, -4, - /* 120 */ -4, -4, -4, -4, -4, -4, 30, -4, 2020, -4, - /* 130 */ 406, 1965, 529, -4, -4, 972, 311, -4, 341, 368, - /* 140 */ 464, 1056, -4, 397, -4, 495, 525, 1907, -4, -4, - /* 150 */ 1965, 235, 1965, 235, 279, 279, 442, -4, 466, 72, - /* 160 */ 1965, -3, 1, 1156, 1088, 502, -4, 524, 80, -4, - /* 170 */ 524, -4, 971, 1965, 529, 1965, 529, 1965, 529, 1965, - /* 180 */ 529, 1965, 529, -4, 969, 993, 987, 991, 1, 1178, - /* 190 */ 1129, 995, -4, 1965, 557, 1946, 271, 998, 1, 1197, - /* 200 */ 1170, 1016, -4, -4, 1026, 1036, 1229, 1238, 1211, 1066, - /* 210 */ -4, 1965, 27, 1, 1255, 1252, 1071, -4, 1021, 1072, - /* 220 */ -4, 1965, 77, -4, 1965, 320, -4, 1965, 350, -4, - /* 230 */ 1965, 380, -4, 267, 1077, 1, 1275, 1293, 1097, -4, - /* 240 */ 1100, -4, 1101, -4, 1965, 410, -4, -4, -4, 1105, - /* 250 */ 1, 1279, 1334, 1109, -4, 1110, 1, 1296, 1375, 1112, - /* 260 */ -4, 1416, 1114, -4, 1135, 1065, 1083, 1138, -4, 275, - /* 270 */ 1142, 1, 1316, 1457, 1146, -4, 1147, -4, 1139, 261, - /* 280 */ -4, -4, -4, -4, -4, -4, -4, -4, 1965, 469, - /* 290 */ 1, 1320, 1498, 1159, -4, 1165, 1186, 1965, 107, 1, - /* 300 */ 1337, 1539, 1179, -4, 1965, 499, 1, 1357, 1580, 1180, - /* 310 */ -4, 1621, 1182, -4, 1006, 1183, -4, 1187, 1219, 1188, - /* 320 */ 1191, -4, -}; -#define KK_REDUCE_USE_DFLT (-25) -static short kk_reduce_ofst[] = { - /* 0 */ 559, -25, 895, -25, -25, -25, -25, -25, -25, -25, - /* 10 */ -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, - /* 20 */ -25, -25, -25, -25, 907, -25, 602, 895, -25, -25, - /* 30 */ -25, -25, 623, 895, -25, -25, -25, 946, -25, -25, - /* 40 */ 984, 1020, -25, 1025, 1034, -25, 1037, -25, 1039, -25, - /* 50 */ 1061, -25, 1062, -25, 1070, -25, 1075, -25, 1093, -25, - /* 60 */ 1107, -25, 1116, -25, 1121, -25, 1144, -25, 1148, -25, - /* 70 */ 1151, -25, 1157, -25, 1162, -25, 1189, -25, 1193, -25, - /* 80 */ 1195, -25, 1198, -25, -25, 1230, -25, -25, -25, 908, - /* 90 */ -25, -25, 1233, -25, 1234, -25, 943, -25, 1239, -25, - /* 100 */ 1271, -25, -25, 948, -25, -25, -25, -25, 952, 980, - /* 110 */ -25, -25, -25, -25, -25, 1274, -25, -25, -25, -25, - /* 120 */ -25, -25, -25, -25, -25, -25, -25, -25, 988, -25, - /* 130 */ -25, 1280, -25, -25, -25, 246, -25, -25, -25, -25, - /* 140 */ -25, 361, -25, -25, -25, -25, -25, 1239, -25, -25, - /* 150 */ 1285, -25, 1307, -25, -25, -25, -25, -25, -25, -25, - /* 160 */ 1312, -25, 644, 895, -25, -25, -25, -24, -25, -25, - /* 170 */ 903, -25, -25, 1315, -25, 1321, -25, 1324, -25, 1339, - /* 180 */ -25, 1348, -25, -25, -25, -25, 212, -25, 665, 895, - /* 190 */ -25, -25, -25, 1353, -25, 985, -25, -25, 686, 895, - /* 200 */ -25, -25, -25, -25, -25, -25, 707, 895, -25, -25, - /* 210 */ -25, 1354, -25, 728, 895, -25, -25, -25, -25, -25, - /* 220 */ -25, 1359, -25, -25, 1362, -25, -25, 1367, -25, -25, - /* 230 */ 1389, -25, -25, -25, -25, 749, 895, -25, -25, -25, - /* 240 */ -25, -25, -25, -25, 1390, -25, -25, -25, -25, -25, - /* 250 */ 770, 895, -25, -25, -25, -25, 791, 895, -25, -25, - /* 260 */ -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, - /* 270 */ -25, 812, 895, -25, -25, -25, 1082, -25, -25, 1076, - /* 280 */ -25, -25, -25, -25, -25, -25, -25, -25, 1395, -25, - /* 290 */ 833, 895, -25, -25, -25, -25, -25, 1397, -25, 854, - /* 300 */ 895, -25, -25, -25, 1398, -25, 875, 895, -25, -25, - /* 310 */ -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, - /* 320 */ -25, -25, -}; -static KKACTIONTYPE kk_default[] = { - /* 0 */ 455, 455, 455, 324, 326, 327, 328, 329, 330, 331, - /* 10 */ 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, - /* 20 */ 342, 343, 344, 455, 455, 455, 455, 455, 455, 455, - /* 30 */ 345, 455, 455, 455, 455, 455, 347, 455, 455, 350, - /* 40 */ 455, 455, 394, 455, 455, 395, 455, 398, 455, 400, - /* 50 */ 455, 402, 455, 403, 455, 404, 455, 405, 455, 406, - /* 60 */ 455, 407, 455, 408, 455, 411, 455, 412, 455, 413, - /* 70 */ 455, 414, 455, 415, 455, 416, 455, 417, 455, 418, - /* 80 */ 455, 419, 455, 420, 455, 455, 421, 423, 424, 455, - /* 90 */ 455, 430, 455, 455, 455, 431, 455, 446, 455, 422, - /* 100 */ 455, 455, 425, 455, 440, 426, 455, 427, 455, 455, - /* 110 */ 428, 455, 429, 438, 450, 455, 439, 441, 448, 449, - /* 120 */ 450, 451, 452, 453, 454, 437, 455, 442, 455, 444, - /* 130 */ 450, 455, 447, 443, 445, 455, 455, 432, 455, 455, - /* 140 */ 455, 455, 433, 455, 434, 449, 448, 455, 409, 410, - /* 150 */ 455, 401, 455, 399, 397, 396, 455, 351, 455, 455, - /* 160 */ 455, 455, 455, 455, 455, 455, 352, 455, 455, 356, - /* 170 */ 455, 357, 455, 455, 359, 455, 360, 455, 361, 455, - /* 180 */ 362, 455, 363, 358, 455, 455, 455, 455, 455, 455, - /* 190 */ 455, 455, 364, 455, 455, 455, 455, 442, 455, 455, - /* 200 */ 455, 455, 376, 378, 455, 455, 455, 455, 455, 455, - /* 210 */ 380, 455, 455, 455, 455, 455, 455, 382, 455, 455, - /* 220 */ 384, 455, 455, 385, 455, 455, 386, 455, 455, 387, - /* 230 */ 455, 455, 388, 455, 455, 455, 455, 455, 455, 389, - /* 240 */ 455, 391, 455, 392, 455, 455, 379, 393, 325, 455, - /* 250 */ 455, 455, 455, 455, 390, 455, 455, 455, 455, 455, - /* 260 */ 383, 455, 455, 381, 443, 455, 455, 455, 377, 455, - /* 270 */ 455, 455, 455, 455, 455, 365, 455, 366, 368, 455, - /* 280 */ 369, 370, 371, 372, 373, 374, 375, 367, 455, 455, - /* 290 */ 455, 455, 455, 455, 353, 455, 455, 455, 455, 455, - /* 300 */ 455, 455, 455, 354, 455, 455, 455, 455, 455, 455, - /* 310 */ 355, 455, 455, 348, 455, 455, 346, 455, 455, 455, - /* 320 */ 455, 349, -}; -#define KK_SZ_ACTTAB (sizeof(kk_action)/sizeof(kk_action[0])) - -/* The next table maps tokens into fallback tokens. If a construct -** like the following: -** -** %fallback ID X Y Z. -** -** appears in the grammer, then ID becomes a fallback token for X, Y, -** and Z. Whenever one of the tokens X, Y, or Z is input to the parser -** but it does not parse, the type of the token is changed to ID and -** the parse is retried before an error is thrown. -*/ -#ifdef KKFALLBACK -static const KKCODETYPE kkFallback[] = { -}; -#endif /* KKFALLBACK */ - -/* The following structure represents a single element of the -** parser's stack. Information stored includes: -** -** + The state number for the parser at this level of the stack. -** -** + The value of the token stored at this level of the stack. -** (In other words, the "major" token.) -** -** + The semantic value stored at this level of the stack. This is -** the information used by the action routines in the grammar. -** It is sometimes called the "minor" token. -*/ -struct kkStackEntry { - int stateno; /* The state-number */ - int major; /* The major token value. This is the code - ** number for the token at this stack level */ - KKMINORTYPE minor; /* The user-supplied minor token value. This - ** is the value of the token */ -}; -typedef struct kkStackEntry kkStackEntry; - -/* The state of the parser is completely contained in an instance of -** the following structure */ -struct kkParser { - int kkidx; /* Index of top element in stack */ - int kkerrcnt; /* Shifts left before out of the error */ - phvolt_ARG_SDECL /* A place to hold %extra_argument */ - kkStackEntry kkstack[KKSTACKDEPTH]; /* The parser's stack */ -}; -typedef struct kkParser kkParser; - -#ifndef NDEBUG -#include -static FILE *kkTraceFILE = 0; -static char *kkTracePrompt = 0; -#endif /* NDEBUG */ - -#ifndef NDEBUG -static void phvolt_Trace(FILE *TraceFILE, char *zTracePrompt){ - kkTraceFILE = TraceFILE; - kkTracePrompt = zTracePrompt; - if( kkTraceFILE==0 ) kkTracePrompt = 0; - else if( kkTracePrompt==0 ) kkTraceFILE = 0; -} -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* For tracing shifts, the names of all terminals and nonterminals -** are required. The following table supplies these names */ -static const char *kkTokenName[] = { - "$", "OPEN_DELIMITER", "COMMA", "IN", - "QUESTION", "COLON", "RANGE", "AND", - "OR", "IS", "EQUALS", "NOTEQUALS", - "LESS", "GREATER", "GREATEREQUAL", "LESSEQUAL", - "IDENTICAL", "NOTIDENTICAL", "DIVIDE", "TIMES", - "MOD", "PLUS", "MINUS", "CONCAT", - "SBRACKET_OPEN", "PIPE", "NOT", "INCR", - "DECR", "PARENTHESES_OPEN", "DOT", "IF", - "CLOSE_DELIMITER", "ENDIF", "ELSE", "ELSEIF", - "ELSEFOR", "FOR", "IDENTIFIER", "ENDFOR", - "SET", "ASSIGN", "ADD_ASSIGN", "SUB_ASSIGN", - "MUL_ASSIGN", "DIV_ASSIGN", "MACRO", "PARENTHESES_CLOSE", - "ENDMACRO", "INTEGER", "STRING", "DOUBLE", - "NULL", "FALSE", "TRUE", "CALL", - "ENDCALL", "OPEN_EDELIMITER", "CLOSE_EDELIMITER", "BLOCK", - "ENDBLOCK", "CACHE", "ENDCACHE", "EXTENDS", - "INCLUDE", "WITH", "DO", "RETURN", - "AUTOESCAPE", "ENDAUTOESCAPE", "BREAK", "CONTINUE", - "RAW_FRAGMENT", "DEFINED", "SBRACKET_CLOSE", "CBRACKET_OPEN", - "CBRACKET_CLOSE", "error", "program", "volt_language", - "statement_list", "statement", "raw_fragment", "if_statement", - "elseif_statement", "elsefor_statement", "for_statement", "set_statement", - "echo_statement", "block_statement", "cache_statement", "extends_statement", - "include_statement", "do_statement", "return_statement", "autoescape_statement", - "break_statement", "continue_statement", "macro_statement", "empty_statement", - "macro_call_statement", "expr", "set_assignments", "set_assignment", - "macro_parameters", "macro_parameter", "macro_parameter_default", "argument_list", - "array_list", "slice_offset", "array_item", "function_call", - "argument_item", -}; -#endif /* NDEBUG */ - -#ifndef NDEBUG -/* For tracing reduce actions, the names of all rules are required. -*/ -static const char *kkRuleName[] = { - /* 0 */ "program ::= volt_language", - /* 1 */ "volt_language ::= statement_list", - /* 2 */ "statement_list ::= statement_list statement", - /* 3 */ "statement_list ::= statement", - /* 4 */ "statement ::= raw_fragment", - /* 5 */ "statement ::= if_statement", - /* 6 */ "statement ::= elseif_statement", - /* 7 */ "statement ::= elsefor_statement", - /* 8 */ "statement ::= for_statement", - /* 9 */ "statement ::= set_statement", - /* 10 */ "statement ::= echo_statement", - /* 11 */ "statement ::= block_statement", - /* 12 */ "statement ::= cache_statement", - /* 13 */ "statement ::= extends_statement", - /* 14 */ "statement ::= include_statement", - /* 15 */ "statement ::= do_statement", - /* 16 */ "statement ::= return_statement", - /* 17 */ "statement ::= autoescape_statement", - /* 18 */ "statement ::= break_statement", - /* 19 */ "statement ::= continue_statement", - /* 20 */ "statement ::= macro_statement", - /* 21 */ "statement ::= empty_statement", - /* 22 */ "statement ::= macro_call_statement", - /* 23 */ "if_statement ::= OPEN_DELIMITER IF expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDIF CLOSE_DELIMITER", - /* 24 */ "if_statement ::= OPEN_DELIMITER IF expr CLOSE_DELIMITER OPEN_DELIMITER ENDIF CLOSE_DELIMITER", - /* 25 */ "if_statement ::= OPEN_DELIMITER IF expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ELSE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDIF CLOSE_DELIMITER", - /* 26 */ "if_statement ::= OPEN_DELIMITER IF expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ELSE CLOSE_DELIMITER OPEN_DELIMITER ENDIF CLOSE_DELIMITER", - /* 27 */ "if_statement ::= OPEN_DELIMITER IF expr CLOSE_DELIMITER OPEN_DELIMITER ELSE CLOSE_DELIMITER OPEN_DELIMITER ENDIF CLOSE_DELIMITER", - /* 28 */ "elseif_statement ::= OPEN_DELIMITER ELSEIF expr CLOSE_DELIMITER", - /* 29 */ "elsefor_statement ::= OPEN_DELIMITER ELSEFOR CLOSE_DELIMITER", - /* 30 */ "for_statement ::= OPEN_DELIMITER FOR IDENTIFIER IN expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDFOR CLOSE_DELIMITER", - /* 31 */ "for_statement ::= OPEN_DELIMITER FOR IDENTIFIER IN expr IF expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDFOR CLOSE_DELIMITER", - /* 32 */ "for_statement ::= OPEN_DELIMITER FOR IDENTIFIER COMMA IDENTIFIER IN expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDFOR CLOSE_DELIMITER", - /* 33 */ "for_statement ::= OPEN_DELIMITER FOR IDENTIFIER COMMA IDENTIFIER IN expr IF expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDFOR CLOSE_DELIMITER", - /* 34 */ "set_statement ::= OPEN_DELIMITER SET set_assignments CLOSE_DELIMITER", - /* 35 */ "set_assignments ::= set_assignments COMMA set_assignment", - /* 36 */ "set_assignments ::= set_assignment", - /* 37 */ "set_assignment ::= IDENTIFIER ASSIGN expr", - /* 38 */ "set_assignment ::= IDENTIFIER ADD_ASSIGN expr", - /* 39 */ "set_assignment ::= IDENTIFIER SUB_ASSIGN expr", - /* 40 */ "set_assignment ::= IDENTIFIER MUL_ASSIGN expr", - /* 41 */ "set_assignment ::= IDENTIFIER DIV_ASSIGN expr", - /* 42 */ "macro_statement ::= OPEN_DELIMITER MACRO IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDMACRO CLOSE_DELIMITER", - /* 43 */ "macro_statement ::= OPEN_DELIMITER MACRO IDENTIFIER PARENTHESES_OPEN macro_parameters PARENTHESES_CLOSE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDMACRO CLOSE_DELIMITER", - /* 44 */ "macro_parameters ::= macro_parameters COMMA macro_parameter", - /* 45 */ "macro_parameters ::= macro_parameter", - /* 46 */ "macro_parameter ::= IDENTIFIER", - /* 47 */ "macro_parameter ::= IDENTIFIER ASSIGN macro_parameter_default", - /* 48 */ "macro_parameter_default ::= INTEGER", - /* 49 */ "macro_parameter_default ::= STRING", - /* 50 */ "macro_parameter_default ::= DOUBLE", - /* 51 */ "macro_parameter_default ::= NULL", - /* 52 */ "macro_parameter_default ::= FALSE", - /* 53 */ "macro_parameter_default ::= TRUE", - /* 54 */ "macro_call_statement ::= OPEN_DELIMITER CALL expr PARENTHESES_OPEN argument_list PARENTHESES_CLOSE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDCALL CLOSE_DELIMITER", - /* 55 */ "macro_call_statement ::= OPEN_DELIMITER CALL expr PARENTHESES_OPEN PARENTHESES_CLOSE CLOSE_DELIMITER OPEN_DELIMITER ENDCALL CLOSE_DELIMITER", - /* 56 */ "empty_statement ::= OPEN_DELIMITER CLOSE_DELIMITER", - /* 57 */ "echo_statement ::= OPEN_EDELIMITER expr CLOSE_EDELIMITER", - /* 58 */ "block_statement ::= OPEN_DELIMITER BLOCK IDENTIFIER CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDBLOCK CLOSE_DELIMITER", - /* 59 */ "block_statement ::= OPEN_DELIMITER BLOCK IDENTIFIER CLOSE_DELIMITER OPEN_DELIMITER ENDBLOCK CLOSE_DELIMITER", - /* 60 */ "cache_statement ::= OPEN_DELIMITER CACHE expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDCACHE CLOSE_DELIMITER", - /* 61 */ "cache_statement ::= OPEN_DELIMITER CACHE expr INTEGER CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDCACHE CLOSE_DELIMITER", - /* 62 */ "extends_statement ::= OPEN_DELIMITER EXTENDS STRING CLOSE_DELIMITER", - /* 63 */ "include_statement ::= OPEN_DELIMITER INCLUDE expr CLOSE_DELIMITER", - /* 64 */ "include_statement ::= OPEN_DELIMITER INCLUDE expr WITH expr CLOSE_DELIMITER", - /* 65 */ "do_statement ::= OPEN_DELIMITER DO expr CLOSE_DELIMITER", - /* 66 */ "return_statement ::= OPEN_DELIMITER RETURN expr CLOSE_DELIMITER", - /* 67 */ "autoescape_statement ::= OPEN_DELIMITER AUTOESCAPE FALSE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDAUTOESCAPE CLOSE_DELIMITER", - /* 68 */ "autoescape_statement ::= OPEN_DELIMITER AUTOESCAPE TRUE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDAUTOESCAPE CLOSE_DELIMITER", - /* 69 */ "break_statement ::= OPEN_DELIMITER BREAK CLOSE_DELIMITER", - /* 70 */ "continue_statement ::= OPEN_DELIMITER CONTINUE CLOSE_DELIMITER", - /* 71 */ "raw_fragment ::= RAW_FRAGMENT", - /* 72 */ "expr ::= MINUS expr", - /* 73 */ "expr ::= PLUS expr", - /* 74 */ "expr ::= expr MINUS expr", - /* 75 */ "expr ::= expr PLUS expr", - /* 76 */ "expr ::= expr TIMES expr", - /* 77 */ "expr ::= expr TIMES TIMES expr", - /* 78 */ "expr ::= expr DIVIDE expr", - /* 79 */ "expr ::= expr DIVIDE DIVIDE expr", - /* 80 */ "expr ::= expr MOD expr", - /* 81 */ "expr ::= expr AND expr", - /* 82 */ "expr ::= expr OR expr", - /* 83 */ "expr ::= expr CONCAT expr", - /* 84 */ "expr ::= expr PIPE expr", - /* 85 */ "expr ::= expr RANGE expr", - /* 86 */ "expr ::= expr EQUALS expr", - /* 87 */ "expr ::= expr IS NOT DEFINED", - /* 88 */ "expr ::= expr IS DEFINED", - /* 89 */ "expr ::= expr IS expr", - /* 90 */ "expr ::= expr NOTEQUALS expr", - /* 91 */ "expr ::= expr IDENTICAL expr", - /* 92 */ "expr ::= expr NOTIDENTICAL expr", - /* 93 */ "expr ::= expr LESS expr", - /* 94 */ "expr ::= expr GREATER expr", - /* 95 */ "expr ::= expr GREATEREQUAL expr", - /* 96 */ "expr ::= expr LESSEQUAL expr", - /* 97 */ "expr ::= expr DOT expr", - /* 98 */ "expr ::= expr IN expr", - /* 99 */ "expr ::= expr NOT IN expr", - /* 100 */ "expr ::= NOT expr", - /* 101 */ "expr ::= expr INCR", - /* 102 */ "expr ::= expr DECR", - /* 103 */ "expr ::= PARENTHESES_OPEN expr PARENTHESES_CLOSE", - /* 104 */ "expr ::= SBRACKET_OPEN SBRACKET_CLOSE", - /* 105 */ "expr ::= SBRACKET_OPEN array_list SBRACKET_CLOSE", - /* 106 */ "expr ::= CBRACKET_OPEN CBRACKET_CLOSE", - /* 107 */ "expr ::= CBRACKET_OPEN array_list CBRACKET_CLOSE", - /* 108 */ "expr ::= expr SBRACKET_OPEN expr SBRACKET_CLOSE", - /* 109 */ "expr ::= expr QUESTION expr COLON expr", - /* 110 */ "expr ::= expr SBRACKET_OPEN COLON slice_offset SBRACKET_CLOSE", - /* 111 */ "expr ::= expr SBRACKET_OPEN slice_offset COLON SBRACKET_CLOSE", - /* 112 */ "expr ::= expr SBRACKET_OPEN slice_offset COLON slice_offset SBRACKET_CLOSE", - /* 113 */ "slice_offset ::= INTEGER", - /* 114 */ "slice_offset ::= IDENTIFIER", - /* 115 */ "array_list ::= array_list COMMA array_item", - /* 116 */ "array_list ::= array_item", - /* 117 */ "array_item ::= STRING COLON expr", - /* 118 */ "array_item ::= expr", - /* 119 */ "expr ::= function_call", - /* 120 */ "function_call ::= expr PARENTHESES_OPEN argument_list PARENTHESES_CLOSE", - /* 121 */ "function_call ::= expr PARENTHESES_OPEN PARENTHESES_CLOSE", - /* 122 */ "argument_list ::= argument_list COMMA argument_item", - /* 123 */ "argument_list ::= argument_item", - /* 124 */ "argument_item ::= expr", - /* 125 */ "argument_item ::= STRING COLON expr", - /* 126 */ "expr ::= IDENTIFIER", - /* 127 */ "expr ::= INTEGER", - /* 128 */ "expr ::= STRING", - /* 129 */ "expr ::= DOUBLE", - /* 130 */ "expr ::= NULL", - /* 131 */ "expr ::= FALSE", - /* 132 */ "expr ::= TRUE", -}; -#endif /* NDEBUG */ - -const char *phvolt_TokenName(int tokenType){ -#ifndef NDEBUG - if( tokenType>0 && tokenType<(sizeof(kkTokenName)/sizeof(kkTokenName[0])) ){ - return kkTokenName[tokenType]; - }else{ - return "Unknown"; - } -#else - return ""; -#endif -} - -void *phvolt_Alloc(void *(*mallocProc)(size_t)){ - kkParser *pParser; - pParser = (kkParser*)(*mallocProc)( (size_t)sizeof(kkParser) ); - if( pParser ){ - pParser->kkidx = -1; - } - return pParser; -} - -/* The following function deletes the value associated with a -** symbol. The symbol can be either a terminal or nonterminal. -** "kkmajor" is the symbol code, and "kkpminor" is a pointer to -** the value. -*/ -static void kk_destructor(KKCODETYPE kkmajor, KKMINORTYPE *kkpminor){ - switch( kkmajor ){ - /* Here is inserted the actions which take place when a - ** terminal or non-terminal is destroyed. This can happen - ** when the symbol is popped from the stack during a - ** reduce or during error processing or when a parser is - ** being destroyed before it is finished parsing. - ** - ** Note: during a reduce, the only symbols destroyed are those - ** which appear on the RHS of the rule, but which are not used - ** inside the C code. - */ - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - case 18: - case 19: - case 20: - case 21: - case 22: - case 23: - case 24: - case 25: - case 26: - case 27: - case 28: - case 29: - case 30: - case 31: - case 32: - case 33: - case 34: - case 35: - case 36: - case 37: - case 38: - case 39: - case 40: - case 41: - case 42: - case 43: - case 44: - case 45: - case 46: - case 47: - case 48: - case 49: - case 50: - case 51: - case 52: - case 53: - case 54: - case 55: - case 56: - case 57: - case 58: - case 59: - case 60: - case 61: - case 62: - case 63: - case 64: - case 65: - case 66: - case 67: - case 68: - case 69: - case 70: - case 71: - case 72: - case 73: - case 74: - case 75: - case 76: -// 703 "parser.lemon" -{ - if ((kkpminor->kk0)) { - if ((kkpminor->kk0)->free_flag) { - efree((kkpminor->kk0)->token); - } - efree((kkpminor->kk0)); - } -} -// 1615 "parser.c" - break; - case 80: - case 81: - case 82: - case 83: - case 84: - case 85: - case 86: - case 87: - case 88: - case 89: - case 90: - case 91: - case 92: - case 93: - case 94: - case 95: - case 96: - case 97: - case 98: - case 99: - case 100: - case 101: - case 102: - case 103: - case 104: - case 105: - case 107: - case 108: - case 109: - case 110: - case 111: - case 112: -// 720 "parser.lemon" -{ zval_ptr_dtor(&(kkpminor->kk132)); } -// 1651 "parser.c" - break; - default: break; /* If no destructor action specified: do nothing */ - } -} - -static int kk_pop_parser_stack(kkParser *pParser){ - KKCODETYPE kkmajor; - kkStackEntry *kktos = &pParser->kkstack[pParser->kkidx]; - - if( pParser->kkidx<0 ) return 0; -#ifndef NDEBUG - if( kkTraceFILE && pParser->kkidx>=0 ){ - fprintf(kkTraceFILE,"%sPopping %s\n", - kkTracePrompt, - kkTokenName[kktos->major]); - } -#endif - kkmajor = kktos->major; - kk_destructor( kkmajor, &kktos->minor); - pParser->kkidx--; - return kkmajor; -} - -static void phvolt_Free( - void *p, /* The parser to be deleted */ - void (*freeProc)(void*) /* Function used to reclaim memory */ -){ - kkParser *pParser = (kkParser*)p; - if( pParser==0 ) return; - while( pParser->kkidx>=0 ) kk_pop_parser_stack(pParser); - (*freeProc)((void*)pParser); -} - -static int kk_find_shift_action( - kkParser *pParser, /* The parser */ - int iLookAhead /* The look-ahead token */ -){ - int i; - int stateno = pParser->kkstack[pParser->kkidx].stateno; - - /* if( pParser->kkidx<0 ) return KK_NO_ACTION; */ - i = kk_shift_ofst[stateno]; - if( i==KK_SHIFT_USE_DFLT ){ - return kk_default[stateno]; - } - if( iLookAhead==KKNOCODE ){ - return KK_NO_ACTION; - } - i += iLookAhead; - if( i<0 || i>=KK_SZ_ACTTAB || kk_lookahead[i]!=iLookAhead ){ -#ifdef KKFALLBACK - int iFallback; /* Fallback token */ - if( iLookAhead %s\n", - kkTracePrompt, kkTokenName[iLookAhead], kkTokenName[iFallback]); - } -#endif - return kk_find_shift_action(pParser, iFallback); - } -#endif - return kk_default[stateno]; - }else{ - return kk_action[i]; - } -} - -static int kk_find_reduce_action( - kkParser *pParser, /* The parser */ - int iLookAhead /* The look-ahead token */ -){ - int i; - int stateno = pParser->kkstack[pParser->kkidx].stateno; - - i = kk_reduce_ofst[stateno]; - if( i==KK_REDUCE_USE_DFLT ){ - return kk_default[stateno]; - } - if( iLookAhead==KKNOCODE ){ - return KK_NO_ACTION; - } - i += iLookAhead; - if( i<0 || i>=KK_SZ_ACTTAB || kk_lookahead[i]!=iLookAhead ){ - return kk_default[stateno]; - }else{ - return kk_action[i]; - } -} - -static void kk_shift( - kkParser *kkpParser, /* The parser to be shifted */ - int kkNewState, /* The new state to shift in */ - int kkMajor, /* The major token to shift in */ - KKMINORTYPE *kkpMinor /* Pointer ot the minor token to shift in */ -){ - kkStackEntry *kktos; - kkpParser->kkidx++; - if( kkpParser->kkidx>=KKSTACKDEPTH ){ - phvolt_ARG_FETCH; - kkpParser->kkidx--; -#ifndef NDEBUG - if( kkTraceFILE ){ - fprintf(kkTraceFILE,"%sStack Overflow!\n",kkTracePrompt); - } -#endif - while( kkpParser->kkidx>=0 ) kk_pop_parser_stack(kkpParser); - /* Here code is inserted which will execute if the parser - ** stack every overflows */ - phvolt_ARG_STORE; /* Suppress warning about unused %extra_argument var */ - return; - } - kktos = &kkpParser->kkstack[kkpParser->kkidx]; - kktos->stateno = kkNewState; - kktos->major = kkMajor; - kktos->minor = *kkpMinor; -#ifndef NDEBUG - if( kkTraceFILE && kkpParser->kkidx>0 ){ - int i; - fprintf(kkTraceFILE,"%sShift %d\n",kkTracePrompt,kkNewState); - fprintf(kkTraceFILE,"%sStack:",kkTracePrompt); - for(i=1; i<=kkpParser->kkidx; i++) - fprintf(kkTraceFILE," %s",kkTokenName[kkpParser->kkstack[i].major]); - fprintf(kkTraceFILE,"\n"); - } -#endif -} - -/* The following table contains information about every rule that -** is used during the reduce. -*/ -static struct { - KKCODETYPE lhs; /* Symbol on the left-hand side of the rule */ - unsigned char nrhs; /* Number of right-hand side symbols in the rule */ -} kkRuleInfo[] = { - { 78, 1 }, - { 79, 1 }, - { 80, 2 }, - { 80, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 81, 1 }, - { 83, 8 }, - { 83, 7 }, - { 83, 12 }, - { 83, 11 }, - { 83, 10 }, - { 84, 4 }, - { 85, 3 }, - { 86, 10 }, - { 86, 12 }, - { 86, 12 }, - { 86, 14 }, - { 87, 4 }, - { 102, 3 }, - { 102, 1 }, - { 103, 3 }, - { 103, 3 }, - { 103, 3 }, - { 103, 3 }, - { 103, 3 }, - { 98, 10 }, - { 98, 11 }, - { 104, 3 }, - { 104, 1 }, - { 105, 1 }, - { 105, 3 }, - { 106, 1 }, - { 106, 1 }, - { 106, 1 }, - { 106, 1 }, - { 106, 1 }, - { 106, 1 }, - { 100, 11 }, - { 100, 9 }, - { 99, 2 }, - { 88, 3 }, - { 89, 8 }, - { 89, 7 }, - { 90, 8 }, - { 90, 9 }, - { 91, 4 }, - { 92, 4 }, - { 92, 6 }, - { 93, 4 }, - { 94, 4 }, - { 95, 8 }, - { 95, 8 }, - { 96, 3 }, - { 97, 3 }, - { 82, 1 }, - { 101, 2 }, - { 101, 2 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 4 }, - { 101, 3 }, - { 101, 4 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 4 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 3 }, - { 101, 4 }, - { 101, 2 }, - { 101, 2 }, - { 101, 2 }, - { 101, 3 }, - { 101, 2 }, - { 101, 3 }, - { 101, 2 }, - { 101, 3 }, - { 101, 4 }, - { 101, 5 }, - { 101, 5 }, - { 101, 5 }, - { 101, 6 }, - { 109, 1 }, - { 109, 1 }, - { 108, 3 }, - { 108, 1 }, - { 110, 3 }, - { 110, 1 }, - { 101, 1 }, - { 111, 4 }, - { 111, 3 }, - { 107, 3 }, - { 107, 1 }, - { 112, 1 }, - { 112, 3 }, - { 101, 1 }, - { 101, 1 }, - { 101, 1 }, - { 101, 1 }, - { 101, 1 }, - { 101, 1 }, - { 101, 1 }, -}; - -static void kk_accept(kkParser*); /* Forward Declaration */ - -static void kk_reduce( - kkParser *kkpParser, /* The parser */ - int kkruleno /* Number of the rule by which to reduce */ -){ - int kkgoto; /* The next state */ - int kkact; /* The next action */ - KKMINORTYPE kkgotominor; /* The LHS of the rule reduced */ - kkStackEntry *kkmsp; /* The top of the parser's stack */ - int kksize; /* Amount to pop the stack */ - phvolt_ARG_FETCH; - kkmsp = &kkpParser->kkstack[kkpParser->kkidx]; -#ifndef NDEBUG - if( kkTraceFILE && kkruleno>=0 - && kkruleno - ** { ... } // User supplied code - ** // - ** break; - */ - case 0: -// 712 "parser.lemon" -{ - status->ret = kkmsp[0].minor.kk132; -} -// 2001 "parser.c" - break; - case 1: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - case 18: - case 19: - case 20: - case 21: - case 22: - case 119: -// 716 "parser.lemon" -{ - kkgotominor.kk132 = kkmsp[0].minor.kk132; -} -// 2028 "parser.c" - break; - case 2: -// 722 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_zval_list(kkmsp[-1].minor.kk132, kkmsp[0].minor.kk132); -} -// 2035 "parser.c" - break; - case 3: - case 36: - case 45: - case 116: - case 123: -// 726 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_zval_list(NULL, kkmsp[0].minor.kk132); -} -// 2046 "parser.c" - break; - case 23: -// 810 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_if_statement(kkmsp[-5].minor.kk132, kkmsp[-3].minor.kk132, NULL, status->scanner_state); - kk_destructor(1,&kkmsp[-7].minor); - kk_destructor(31,&kkmsp[-6].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(33,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2059 "parser.c" - break; - case 24: -// 814 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_if_statement(kkmsp[-4].minor.kk132, NULL, NULL, status->scanner_state); - kk_destructor(1,&kkmsp[-6].minor); - kk_destructor(31,&kkmsp[-5].minor); - kk_destructor(32,&kkmsp[-3].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(33,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2072 "parser.c" - break; - case 25: -// 818 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_if_statement(kkmsp[-9].minor.kk132, kkmsp[-7].minor.kk132, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-11].minor); - kk_destructor(31,&kkmsp[-10].minor); - kk_destructor(32,&kkmsp[-8].minor); - kk_destructor(1,&kkmsp[-6].minor); - kk_destructor(34,&kkmsp[-5].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(33,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2088 "parser.c" - break; - case 26: -// 822 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_if_statement(kkmsp[-8].minor.kk132, kkmsp[-6].minor.kk132, NULL, status->scanner_state); - kk_destructor(1,&kkmsp[-10].minor); - kk_destructor(31,&kkmsp[-9].minor); - kk_destructor(32,&kkmsp[-7].minor); - kk_destructor(1,&kkmsp[-5].minor); - kk_destructor(34,&kkmsp[-4].minor); - kk_destructor(32,&kkmsp[-3].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(33,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2104 "parser.c" - break; - case 27: -// 826 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_if_statement(kkmsp[-7].minor.kk132, NULL, NULL, status->scanner_state); - kk_destructor(1,&kkmsp[-9].minor); - kk_destructor(31,&kkmsp[-8].minor); - kk_destructor(32,&kkmsp[-6].minor); - kk_destructor(1,&kkmsp[-5].minor); - kk_destructor(34,&kkmsp[-4].minor); - kk_destructor(32,&kkmsp[-3].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(33,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2120 "parser.c" - break; - case 28: -// 832 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_elseif_statement(kkmsp[-1].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-3].minor); - kk_destructor(35,&kkmsp[-2].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2130 "parser.c" - break; - case 29: -// 838 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_elsefor_statement(status->scanner_state); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(36,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2140 "parser.c" - break; - case 30: -// 844 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_for_statement(kkmsp[-7].minor.kk0, NULL, kkmsp[-5].minor.kk132, NULL, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-9].minor); - kk_destructor(37,&kkmsp[-8].minor); - kk_destructor(3,&kkmsp[-6].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(39,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2154 "parser.c" - break; - case 31: -// 848 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_for_statement(kkmsp[-9].minor.kk0, NULL, kkmsp[-7].minor.kk132, kkmsp[-5].minor.kk132, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-11].minor); - kk_destructor(37,&kkmsp[-10].minor); - kk_destructor(3,&kkmsp[-8].minor); - kk_destructor(31,&kkmsp[-6].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(39,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2169 "parser.c" - break; - case 32: -// 852 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_for_statement(kkmsp[-7].minor.kk0, kkmsp[-9].minor.kk0, kkmsp[-5].minor.kk132, NULL, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-11].minor); - kk_destructor(37,&kkmsp[-10].minor); - kk_destructor(2,&kkmsp[-8].minor); - kk_destructor(3,&kkmsp[-6].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(39,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2184 "parser.c" - break; - case 33: -// 856 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_for_statement(kkmsp[-9].minor.kk0, kkmsp[-11].minor.kk0, kkmsp[-7].minor.kk132, kkmsp[-5].minor.kk132, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-13].minor); - kk_destructor(37,&kkmsp[-12].minor); - kk_destructor(2,&kkmsp[-10].minor); - kk_destructor(3,&kkmsp[-8].minor); - kk_destructor(31,&kkmsp[-6].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(39,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2200 "parser.c" - break; - case 34: -// 862 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_set_statement(kkmsp[-1].minor.kk132); - kk_destructor(1,&kkmsp[-3].minor); - kk_destructor(40,&kkmsp[-2].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2210 "parser.c" - break; - case 35: - case 44: - case 115: - case 122: -// 868 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_zval_list(kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132); - kk_destructor(2,&kkmsp[-1].minor); -} -// 2221 "parser.c" - break; - case 37: -// 878 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_set_assignment(kkmsp[-2].minor.kk0, PHVOLT_T_ASSIGN, kkmsp[0].minor.kk132, status->scanner_state); - kk_destructor(41,&kkmsp[-1].minor); -} -// 2229 "parser.c" - break; - case 38: -// 882 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_set_assignment(kkmsp[-2].minor.kk0, PHVOLT_T_ADD_ASSIGN, kkmsp[0].minor.kk132, status->scanner_state); - kk_destructor(42,&kkmsp[-1].minor); -} -// 2237 "parser.c" - break; - case 39: -// 886 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_set_assignment(kkmsp[-2].minor.kk0, PHVOLT_T_SUB_ASSIGN, kkmsp[0].minor.kk132, status->scanner_state); - kk_destructor(43,&kkmsp[-1].minor); -} -// 2245 "parser.c" - break; - case 40: -// 890 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_set_assignment(kkmsp[-2].minor.kk0, PHVOLT_T_MUL_ASSIGN, kkmsp[0].minor.kk132, status->scanner_state); - kk_destructor(44,&kkmsp[-1].minor); -} -// 2253 "parser.c" - break; - case 41: -// 894 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_set_assignment(kkmsp[-2].minor.kk0, PHVOLT_T_DIV_ASSIGN, kkmsp[0].minor.kk132, status->scanner_state); - kk_destructor(45,&kkmsp[-1].minor); -} -// 2261 "parser.c" - break; - case 42: -// 900 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_macro_statement(kkmsp[-7].minor.kk0, NULL, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-9].minor); - kk_destructor(46,&kkmsp[-8].minor); - kk_destructor(29,&kkmsp[-6].minor); - kk_destructor(47,&kkmsp[-5].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(48,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2276 "parser.c" - break; - case 43: -// 904 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_macro_statement(kkmsp[-8].minor.kk0, kkmsp[-6].minor.kk132, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-10].minor); - kk_destructor(46,&kkmsp[-9].minor); - kk_destructor(29,&kkmsp[-7].minor); - kk_destructor(47,&kkmsp[-5].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(48,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2291 "parser.c" - break; - case 46: -// 920 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_macro_parameter(kkmsp[0].minor.kk0, NULL, status->scanner_state); -} -// 2298 "parser.c" - break; - case 47: -// 924 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_macro_parameter(kkmsp[-2].minor.kk0, kkmsp[0].minor.kk132, status->scanner_state); - kk_destructor(41,&kkmsp[-1].minor); -} -// 2306 "parser.c" - break; - case 48: - case 113: - case 127: -// 928 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_INTEGER, kkmsp[0].minor.kk0, status->scanner_state); -} -// 2315 "parser.c" - break; - case 49: - case 128: -// 932 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_STRING, kkmsp[0].minor.kk0, status->scanner_state); -} -// 2323 "parser.c" - break; - case 50: - case 129: -// 936 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_DOUBLE, kkmsp[0].minor.kk0, status->scanner_state); -} -// 2331 "parser.c" - break; - case 51: - case 130: -// 940 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_NULL, NULL, status->scanner_state); - kk_destructor(52,&kkmsp[0].minor); -} -// 2340 "parser.c" - break; - case 52: - case 131: -// 944 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_FALSE, NULL, status->scanner_state); - kk_destructor(53,&kkmsp[0].minor); -} -// 2349 "parser.c" - break; - case 53: - case 132: -// 948 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_TRUE, NULL, status->scanner_state); - kk_destructor(54,&kkmsp[0].minor); -} -// 2358 "parser.c" - break; - case 54: -// 954 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_macro_call_statement(kkmsp[-8].minor.kk132, kkmsp[-6].minor.kk132, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-10].minor); - kk_destructor(55,&kkmsp[-9].minor); - kk_destructor(29,&kkmsp[-7].minor); - kk_destructor(47,&kkmsp[-5].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(56,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2373 "parser.c" - break; - case 55: -// 958 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_macro_call_statement(kkmsp[-6].minor.kk132, NULL, NULL, status->scanner_state); - kk_destructor(1,&kkmsp[-8].minor); - kk_destructor(55,&kkmsp[-7].minor); - kk_destructor(29,&kkmsp[-5].minor); - kk_destructor(47,&kkmsp[-4].minor); - kk_destructor(32,&kkmsp[-3].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(56,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2388 "parser.c" - break; - case 56: -// 964 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_empty_statement(status->scanner_state); - kk_destructor(1,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2397 "parser.c" - break; - case 57: -// 970 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_echo_statement(kkmsp[-1].minor.kk132, status->scanner_state); - kk_destructor(57,&kkmsp[-2].minor); - kk_destructor(58,&kkmsp[0].minor); -} -// 2406 "parser.c" - break; - case 58: -// 976 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_block_statement(kkmsp[-5].minor.kk0, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-7].minor); - kk_destructor(59,&kkmsp[-6].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(60,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2419 "parser.c" - break; - case 59: -// 980 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_block_statement(kkmsp[-4].minor.kk0, NULL, status->scanner_state); - kk_destructor(1,&kkmsp[-6].minor); - kk_destructor(59,&kkmsp[-5].minor); - kk_destructor(32,&kkmsp[-3].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(60,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2432 "parser.c" - break; - case 60: -// 986 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_cache_statement(kkmsp[-5].minor.kk132, NULL, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-7].minor); - kk_destructor(61,&kkmsp[-6].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(62,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2445 "parser.c" - break; - case 61: -// 990 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_cache_statement(kkmsp[-6].minor.kk132, kkmsp[-5].minor.kk0, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-8].minor); - kk_destructor(61,&kkmsp[-7].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(62,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2458 "parser.c" - break; - case 62: -// 996 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_extends_statement(kkmsp[-1].minor.kk0, status->scanner_state); - kk_destructor(1,&kkmsp[-3].minor); - kk_destructor(63,&kkmsp[-2].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2468 "parser.c" - break; - case 63: -// 1002 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_include_statement(kkmsp[-1].minor.kk132, NULL, status->scanner_state); - kk_destructor(1,&kkmsp[-3].minor); - kk_destructor(64,&kkmsp[-2].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2478 "parser.c" - break; - case 64: -// 1006 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_include_statement(kkmsp[-3].minor.kk132, kkmsp[-1].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-5].minor); - kk_destructor(64,&kkmsp[-4].minor); - kk_destructor(65,&kkmsp[-2].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2489 "parser.c" - break; - case 65: -// 1012 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_do_statement(kkmsp[-1].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-3].minor); - kk_destructor(66,&kkmsp[-2].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2499 "parser.c" - break; - case 66: -// 1018 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_return_statement(kkmsp[-1].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-3].minor); - kk_destructor(67,&kkmsp[-2].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2509 "parser.c" - break; - case 67: -// 1024 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_autoescape_statement(0, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-7].minor); - kk_destructor(68,&kkmsp[-6].minor); - kk_destructor(53,&kkmsp[-5].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(69,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2523 "parser.c" - break; - case 68: -// 1028 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_autoescape_statement(1, kkmsp[-3].minor.kk132, status->scanner_state); - kk_destructor(1,&kkmsp[-7].minor); - kk_destructor(68,&kkmsp[-6].minor); - kk_destructor(54,&kkmsp[-5].minor); - kk_destructor(32,&kkmsp[-4].minor); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(69,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2537 "parser.c" - break; - case 69: -// 1034 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_break_statement(status->scanner_state); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(70,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2547 "parser.c" - break; - case 70: -// 1040 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_continue_statement(status->scanner_state); - kk_destructor(1,&kkmsp[-2].minor); - kk_destructor(71,&kkmsp[-1].minor); - kk_destructor(32,&kkmsp[0].minor); -} -// 2557 "parser.c" - break; - case 71: -// 1046 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_RAW_FRAGMENT, kkmsp[0].minor.kk0, status->scanner_state); -} -// 2564 "parser.c" - break; - case 72: -// 1052 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_MINUS, NULL, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(22,&kkmsp[-1].minor); -} -// 2572 "parser.c" - break; - case 73: -// 1056 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_PLUS, NULL, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(21,&kkmsp[-1].minor); -} -// 2580 "parser.c" - break; - case 74: -// 1060 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_SUB, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(22,&kkmsp[-1].minor); -} -// 2588 "parser.c" - break; - case 75: -// 1064 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ADD, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(21,&kkmsp[-1].minor); -} -// 2596 "parser.c" - break; - case 76: -// 1068 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_MUL, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(19,&kkmsp[-1].minor); -} -// 2604 "parser.c" - break; - case 77: -// 1072 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_POW, kkmsp[-3].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(19,&kkmsp[-2].minor); - kk_destructor(19,&kkmsp[-1].minor); -} -// 2613 "parser.c" - break; - case 78: -// 1076 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_DIV, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(18,&kkmsp[-1].minor); -} -// 2621 "parser.c" - break; - case 79: -// 1080 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_MOD, kkmsp[-3].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(18,&kkmsp[-2].minor); - kk_destructor(18,&kkmsp[-1].minor); -} -// 2630 "parser.c" - break; - case 80: -// 1084 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_MOD, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(20,&kkmsp[-1].minor); -} -// 2638 "parser.c" - break; - case 81: -// 1088 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_AND, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(7,&kkmsp[-1].minor); -} -// 2646 "parser.c" - break; - case 82: -// 1092 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_OR, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(8,&kkmsp[-1].minor); -} -// 2654 "parser.c" - break; - case 83: -// 1096 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_CONCAT, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(23,&kkmsp[-1].minor); -} -// 2662 "parser.c" - break; - case 84: -// 1100 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_PIPE, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(25,&kkmsp[-1].minor); -} -// 2670 "parser.c" - break; - case 85: -// 1104 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_RANGE, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(6,&kkmsp[-1].minor); -} -// 2678 "parser.c" - break; - case 86: -// 1108 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_EQUALS, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(10,&kkmsp[-1].minor); -} -// 2686 "parser.c" - break; - case 87: -// 1112 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_NOT_ISSET, kkmsp[-3].minor.kk132, NULL, NULL, status->scanner_state); - kk_destructor(9,&kkmsp[-2].minor); - kk_destructor(26,&kkmsp[-1].minor); - kk_destructor(73,&kkmsp[0].minor); -} -// 2696 "parser.c" - break; - case 88: -// 1116 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ISSET, kkmsp[-2].minor.kk132, NULL, NULL, status->scanner_state); - kk_destructor(9,&kkmsp[-1].minor); - kk_destructor(73,&kkmsp[0].minor); -} -// 2705 "parser.c" - break; - case 89: -// 1120 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_IS, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(9,&kkmsp[-1].minor); -} -// 2713 "parser.c" - break; - case 90: -// 1124 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_NOTEQUALS, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(11,&kkmsp[-1].minor); -} -// 2721 "parser.c" - break; - case 91: -// 1128 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_IDENTICAL, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(16,&kkmsp[-1].minor); -} -// 2729 "parser.c" - break; - case 92: -// 1132 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_NOTIDENTICAL, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(17,&kkmsp[-1].minor); -} -// 2737 "parser.c" - break; - case 93: -// 1136 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_LESS, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(12,&kkmsp[-1].minor); -} -// 2745 "parser.c" - break; - case 94: -// 1140 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_GREATER, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(13,&kkmsp[-1].minor); -} -// 2753 "parser.c" - break; - case 95: -// 1144 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_GREATEREQUAL, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(14,&kkmsp[-1].minor); -} -// 2761 "parser.c" - break; - case 96: -// 1148 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_LESSEQUAL, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(15,&kkmsp[-1].minor); -} -// 2769 "parser.c" - break; - case 97: -// 1152 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_DOT, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(30,&kkmsp[-1].minor); -} -// 2777 "parser.c" - break; - case 98: -// 1156 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_IN, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(3,&kkmsp[-1].minor); -} -// 2785 "parser.c" - break; - case 99: -// 1160 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_NOT_IN, kkmsp[-3].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(26,&kkmsp[-2].minor); - kk_destructor(3,&kkmsp[-1].minor); -} -// 2794 "parser.c" - break; - case 100: -// 1164 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_NOT, NULL, kkmsp[0].minor.kk132, NULL, status->scanner_state); - kk_destructor(26,&kkmsp[-1].minor); -} -// 2802 "parser.c" - break; - case 101: -// 1168 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_INCR, kkmsp[-1].minor.kk132, NULL, NULL, status->scanner_state); - kk_destructor(27,&kkmsp[0].minor); -} -// 2810 "parser.c" - break; - case 102: -// 1172 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_DECR, kkmsp[-1].minor.kk132, NULL, NULL, status->scanner_state); - kk_destructor(28,&kkmsp[0].minor); -} -// 2818 "parser.c" - break; - case 103: -// 1176 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ENCLOSED, kkmsp[-1].minor.kk132, NULL, NULL, status->scanner_state); - kk_destructor(29,&kkmsp[-2].minor); - kk_destructor(47,&kkmsp[0].minor); -} -// 2827 "parser.c" - break; - case 104: -// 1180 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ARRAY, NULL, NULL, NULL, status->scanner_state); - kk_destructor(24,&kkmsp[-1].minor); - kk_destructor(74,&kkmsp[0].minor); -} -// 2836 "parser.c" - break; - case 105: -// 1184 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ARRAY, kkmsp[-1].minor.kk132, NULL, NULL, status->scanner_state); - kk_destructor(24,&kkmsp[-2].minor); - kk_destructor(74,&kkmsp[0].minor); -} -// 2845 "parser.c" - break; - case 106: -// 1188 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ARRAY, NULL, NULL, NULL, status->scanner_state); - kk_destructor(75,&kkmsp[-1].minor); - kk_destructor(76,&kkmsp[0].minor); -} -// 2854 "parser.c" - break; - case 107: -// 1192 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ARRAY, kkmsp[-1].minor.kk132, NULL, NULL, status->scanner_state); - kk_destructor(75,&kkmsp[-2].minor); - kk_destructor(76,&kkmsp[0].minor); -} -// 2863 "parser.c" - break; - case 108: -// 1196 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ARRAYACCESS, kkmsp[-3].minor.kk132, kkmsp[-1].minor.kk132, NULL, status->scanner_state); - kk_destructor(24,&kkmsp[-2].minor); - kk_destructor(74,&kkmsp[0].minor); -} -// 2872 "parser.c" - break; - case 109: -// 1200 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_TERNARY, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, kkmsp[-4].minor.kk132, status->scanner_state); - kk_destructor(4,&kkmsp[-3].minor); - kk_destructor(5,&kkmsp[-1].minor); -} -// 2881 "parser.c" - break; - case 110: -// 1204 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_slice(kkmsp[-4].minor.kk132, NULL, kkmsp[-1].minor.kk132, status->scanner_state); - kk_destructor(24,&kkmsp[-3].minor); - kk_destructor(5,&kkmsp[-2].minor); - kk_destructor(74,&kkmsp[0].minor); -} -// 2891 "parser.c" - break; - case 111: -// 1208 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_slice(kkmsp[-4].minor.kk132, kkmsp[-2].minor.kk132, NULL, status->scanner_state); - kk_destructor(24,&kkmsp[-3].minor); - kk_destructor(5,&kkmsp[-1].minor); - kk_destructor(74,&kkmsp[0].minor); -} -// 2901 "parser.c" - break; - case 112: -// 1212 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_slice(kkmsp[-5].minor.kk132, kkmsp[-3].minor.kk132, kkmsp[-1].minor.kk132, status->scanner_state); - kk_destructor(24,&kkmsp[-4].minor); - kk_destructor(5,&kkmsp[-2].minor); - kk_destructor(74,&kkmsp[0].minor); -} -// 2911 "parser.c" - break; - case 114: - case 126: -// 1222 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_IDENTIFIER, kkmsp[0].minor.kk0, status->scanner_state); -} -// 2919 "parser.c" - break; - case 117: - case 125: -// 1238 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_named_item(kkmsp[-2].minor.kk0, kkmsp[0].minor.kk132, status->scanner_state); - kk_destructor(5,&kkmsp[-1].minor); -} -// 2928 "parser.c" - break; - case 118: - case 124: -// 1242 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_named_item(NULL, kkmsp[0].minor.kk132, status->scanner_state); -} -// 2936 "parser.c" - break; - case 120: -// 1252 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_func_call(kkmsp[-3].minor.kk132, kkmsp[-1].minor.kk132, status->scanner_state); - kk_destructor(29,&kkmsp[-2].minor); - kk_destructor(47,&kkmsp[0].minor); -} -// 2945 "parser.c" - break; - case 121: -// 1256 "parser.lemon" -{ - kkgotominor.kk132 = phvolt_ret_func_call(kkmsp[-2].minor.kk132, NULL, status->scanner_state); - kk_destructor(29,&kkmsp[-1].minor); - kk_destructor(47,&kkmsp[0].minor); -} -// 2954 "parser.c" - break; - }; - kkgoto = kkRuleInfo[kkruleno].lhs; - kksize = kkRuleInfo[kkruleno].nrhs; - kkpParser->kkidx -= kksize; - kkact = kk_find_reduce_action(kkpParser,kkgoto); - if( kkact < KKNSTATE ){ - kk_shift(kkpParser,kkact,kkgoto,&kkgotominor); - }else if( kkact == KKNSTATE + KKNRULE + 1 ){ - kk_accept(kkpParser); - } -} - -static void kk_parse_failed( - kkParser *kkpParser /* The parser */ -){ - phvolt_ARG_FETCH; -#ifndef NDEBUG - if( kkTraceFILE ){ - fprintf(kkTraceFILE,"%sFail!\n",kkTracePrompt); - } -#endif - while( kkpParser->kkidx>=0 ) kk_pop_parser_stack(kkpParser); - /* Here code is inserted which will be executed whenever the - ** parser fails */ - phvolt_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -static void kk_syntax_error( - kkParser *kkpParser, /* The parser */ - int kkmajor, /* The major type of the error token */ - KKMINORTYPE kkminor /* The minor type of the error token */ -){ - phvolt_ARG_FETCH; -#define KTOKEN (kkminor.kk0) -// 605 "parser.lemon" - - { - - smart_str error_str = {0}; - - char *token_name = NULL; - const phvolt_token_names *tokens = phvolt_tokens; - int token_len = 0; - int active_token = status->scanner_state->active_token; - - if (status->scanner_state->start_length) { - - if (active_token) { - - do { - if (tokens->code == active_token) { - token_name = tokens->name; - token_len = tokens->len; - break; - } - ++tokens; - } while (tokens[0].code != 0); - +// 3224 "scanner.c" +yy199: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy207; + default: goto yy87; } - - smart_str_appendl(&error_str, "Syntax error, unexpected token ", sizeof("Syntax error, unexpected token ") - 1); - if (!token_name) { - smart_str_appendl(&error_str, "UNKNOWN", sizeof("UNKNOWN") - 1); - } else { - smart_str_appendl(&error_str, token_name, token_len); +yy200: + yych = *++YYCURSOR; + switch (yych) { + case 'O': + case 'o': goto yy205; + default: goto yy87; } - if (status->token->value) { - smart_str_appendc(&error_str, '('); - smart_str_appendl(&error_str, status->token->value, status->token->len); - smart_str_appendc(&error_str, ')'); +yy201: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy202; + default: goto yy87; + } +yy202: + yych = *++YYCURSOR; + switch (yych) { + case 'R': + case 'r': goto yy203; + default: goto yy87; + } +yy203: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy204; + } +yy204: +// 216 "scanner.re" + { + token->opcode = PHQL_T_INNER; + return 0; + } +// 3328 "scanner.c" +yy205: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy206; + } +yy206: +// 111 "scanner.re" + { + token->opcode = PHQL_T_INTO; + return 0; + } +// 3404 "scanner.c" +yy207: + yych = *++YYCURSOR; + switch (yych) { + case 'R': + case 'r': goto yy208; + default: goto yy87; + } +yy208: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy209; + default: goto yy87; + } +yy209: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy210; } - smart_str_appendl(&error_str, " in ", sizeof(" in ") - 1); - smart_str_appendl(&error_str, Z_STRVAL_P(status->scanner_state->active_file), Z_STRLEN_P(status->scanner_state->active_file)); - smart_str_appendl(&error_str, " on line ", sizeof(" on line ") - 1); +yy210: +// 106 "scanner.re" { - char stmp[MAX_LENGTH_OF_LONG + 1]; - int str_len; - str_len = slprintf(stmp, sizeof(stmp), "%ld", status->scanner_state->active_line); - smart_str_appendl(&error_str, stmp, str_len); + token->opcode = PHQL_T_INSERT; + return 0; + } +// 3494 "scanner.c" +yy211: + yych = *++YYCURSOR; + switch (yych) { + case 'K': + case 'k': goto yy212; + default: goto yy87; } - - } else { - - smart_str_appendl(&error_str, "Syntax error, unexpected EOF in ", sizeof("Syntax error, unexpected EOF in ") - 1); - smart_str_appendl(&error_str, Z_STRVAL_P(status->scanner_state->active_file), Z_STRLEN_P(status->scanner_state->active_file)); - - /* Report unclosed 'if' blocks */ - if ((status->scanner_state->if_level + status->scanner_state->old_if_level) > 0) { - if ((status->scanner_state->if_level + status->scanner_state->old_if_level) == 1) { - smart_str_appendl(&error_str, ", there is one 'if' block without close", sizeof(", there is one 'if' block without close") - 1); - } else { - smart_str_appendl(&error_str, ", there are ", sizeof(", there are ") - 1); - { - char stmp[MAX_LENGTH_OF_LONG + 1]; - int str_len; - str_len = slprintf(stmp, sizeof(stmp), "%ld", status->scanner_state->if_level + status->scanner_state->old_if_level); - smart_str_appendl(&error_str, stmp, str_len); - } - smart_str_appendl(&error_str, " 'if' blocks without close", sizeof(" 'if' blocks without close") - 1); - } +yy212: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy213; + default: goto yy87; } - - /* Report unclosed 'for' blocks */ - if (status->scanner_state->for_level > 0) { - if (status->scanner_state->for_level == 1) { - smart_str_appendl(&error_str, ", there is one 'for' block without close", sizeof(", there is one 'for' block without close") - 1); - } else { - smart_str_appendl(&error_str, ", there are ", sizeof(", there are ") - 1); - { - char stmp[MAX_LENGTH_OF_LONG + 1]; - int str_len; - str_len = slprintf(stmp, sizeof(stmp), "%ld", status->scanner_state->if_level); - smart_str_appendl(&error_str, stmp, str_len); - } - smart_str_appendl(&error_str, " 'for' blocks without close", sizeof(" 'for' blocks without close") - 1); - } +yy213: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy214; } +yy214: +// 191 "scanner.re" + { + token->opcode = PHQL_T_ILIKE; + return 0; } - - smart_str_0(&error_str); - - if (error_str.len) { - status->syntax_error = error_str.c; - status->syntax_error_len = error_str.len; - } else { - status->syntax_error = NULL; - } - - } - - status->status = PHVOLT_PARSING_FAILED; - -// 3094 "parser.c" - phvolt_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -static void kk_accept( - kkParser *kkpParser /* The parser */ -){ - phvolt_ARG_FETCH; -#ifndef NDEBUG - if( kkTraceFILE ){ - fprintf(kkTraceFILE,"%sAccept!\n",kkTracePrompt); - } -#endif - while( kkpParser->kkidx>=0 ) kk_pop_parser_stack(kkpParser); - /* Here code is inserted which will be executed whenever the - ** parser accepts */ - phvolt_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} - -/* The main parser program. -** The first argument is a pointer to a structure obtained from -** "phvolt_Alloc" which describes the current state of the parser. -** The second argument is the major token number. The third is -** the minor token. The fourth optional argument is whatever the -** user wants (and specified in the grammar) and is available for -** use by the action routines. -** -** Inputs: -**
    -**
  • A pointer to the parser (an opaque structure.) -**
  • The major token number. -**
  • The minor token number. -**
  • An option argument of a grammar-specified type. -**
-** -** Outputs: -** None. -*/ -static void phvolt_( - void *kkp, /* The parser */ - int kkmajor, /* The major token code number */ - phvolt_KTOKENTYPE kkminor /* The value for the token */ - phvolt_ARG_PDECL /* Optional %extra_argument parameter */ -){ - KKMINORTYPE kkminorunion; - int kkact; /* The parser action. */ - int kkendofinput; /* True if we are at the end of input */ - int kkerrorhit = 0; /* True if kkmajor has invoked an error */ - kkParser *kkpParser; /* The parser */ - - /* (re)initialize the parser, if necessary */ - kkpParser = (kkParser*)kkp; - if( kkpParser->kkidx<0 ){ - if( kkmajor==0 ) return; - kkpParser->kkidx = 0; - kkpParser->kkerrcnt = -1; - kkpParser->kkstack[0].stateno = 0; - kkpParser->kkstack[0].major = 0; - } - kkminorunion.kk0 = kkminor; - kkendofinput = (kkmajor==0); - phvolt_ARG_STORE; - -#ifndef NDEBUG - if( kkTraceFILE ){ - fprintf(kkTraceFILE,"%sInput %s\n",kkTracePrompt,kkTokenName[kkmajor]); - } -#endif - - do{ - kkact = kk_find_shift_action(kkpParser,kkmajor); - if( kkactkkerrcnt--; - if( kkendofinput && kkpParser->kkidx>=0 ){ - kkmajor = 0; - }else{ - kkmajor = KKNOCODE; - } - }else if( kkact < KKNSTATE + KKNRULE ){ - kk_reduce(kkpParser,kkact-KKNSTATE); - }else if( kkact == KK_ERROR_ACTION ){ - int kkmx; -#ifndef NDEBUG - if( kkTraceFILE ){ - fprintf(kkTraceFILE,"%sSyntax Error!\n",kkTracePrompt); - } -#endif -#ifdef KKERRORSYMBOL - /* A syntax error has occurred. - ** The response to an error depends upon whether or not the - ** grammar defines an error token "ERROR". - ** - ** This is what we do if the grammar does define ERROR: - ** - ** * Call the %syntax_error function. - ** - ** * Begin popping the stack until we enter a state where - ** it is legal to shift the error symbol, then shift - ** the error symbol. - ** - ** * Set the error count to three. - ** - ** * Begin accepting and shifting new tokens. No new error - ** processing will occur until three tokens have been - ** shifted successfully. - ** - */ - if( kkpParser->kkerrcnt<0 ){ - kk_syntax_error(kkpParser,kkmajor,kkminorunion); - } - kkmx = kkpParser->kkstack[kkpParser->kkidx].major; - if( kkmx==KKERRORSYMBOL || kkerrorhit ){ -#ifndef NDEBUG - if( kkTraceFILE ){ - fprintf(kkTraceFILE,"%sDiscard input token %s\n", - kkTracePrompt,kkTokenName[kkmajor]); - } -#endif - kk_destructor(kkmajor,&kkminorunion); - kkmajor = KKNOCODE; - }else{ - while( - kkpParser->kkidx >= 0 && - kkmx != KKERRORSYMBOL && - (kkact = kk_find_shift_action(kkpParser,KKERRORSYMBOL)) >= KKNSTATE - ){ - kk_pop_parser_stack(kkpParser); - } - if( kkpParser->kkidx < 0 || kkmajor==0 ){ - kk_destructor(kkmajor,&kkminorunion); - kk_parse_failed(kkpParser); - kkmajor = KKNOCODE; - }else if( kkmx!=KKERRORSYMBOL ){ - KKMINORTYPE u2; - u2.KKERRSYMDT = 0; - kk_shift(kkpParser,kkact,KKERRORSYMBOL,&u2); - } - } - kkpParser->kkerrcnt = 3; - kkerrorhit = 1; -#else /* KKERRORSYMBOL is not defined */ - /* This is what we do if the grammar does not define ERROR: - ** - ** * Report an error message, and throw away the input token. - ** - ** * If the input token is $, then fail the parse. - ** - ** As before, subsequent error messages are suppressed until - ** three input tokens have been successfully shifted. - */ - if( kkpParser->kkerrcnt<=0 ){ - kk_syntax_error(kkpParser,kkmajor,kkminorunion); - } - kkpParser->kkerrcnt = 3; - kk_destructor(kkmajor,&kkminorunion); - if( kkendofinput ){ - kk_parse_failed(kkpParser); - } - kkmajor = KKNOCODE; -#endif - }else{ - kk_accept(kkpParser); - kkmajor = KKNOCODE; - } - }while( kkmajor!=KKNOCODE && kkpParser->kkidx>=0 ); - return; -} - - -const phvolt_token_names phvolt_tokens[] = -{ - { SL("INTEGER"), PHVOLT_T_INTEGER }, - { SL("DOUBLE"), PHVOLT_T_DOUBLE }, - { SL("STRING"), PHVOLT_T_STRING }, - { SL("IDENTIFIER"), PHVOLT_T_IDENTIFIER }, - { SL("MINUS"), PHVOLT_T_MINUS }, - { SL("+"), PHVOLT_T_ADD }, - { SL("-"), PHVOLT_T_SUB }, - { SL("*"), PHVOLT_T_MUL }, - { SL("/"), PHVOLT_T_DIV }, - { SL("%%"), PHVOLT_T_MOD }, - { SL("!"), PHVOLT_T_NOT }, - { SL("~"), PHVOLT_T_CONCAT }, - { SL("AND"), PHVOLT_T_AND }, - { SL("OR"), PHVOLT_T_OR }, - { SL("DOT"), PHVOLT_T_DOT }, - { SL("COMMA"), PHVOLT_T_COMMA }, - { SL("EQUALS"), PHVOLT_T_EQUALS }, - { SL("NOT EQUALS"), PHVOLT_T_NOTEQUALS }, - { SL("IDENTICAL"), PHVOLT_T_IDENTICAL }, - { SL("NOT IDENTICAL"), PHVOLT_T_NOTIDENTICAL }, - { SL("NOT"), PHVOLT_T_NOT }, - { SL("RANGE"), PHVOLT_T_RANGE }, - { SL("COLON"), PHVOLT_T_COLON }, - { SL("QUESTION MARK"), PHVOLT_T_QUESTION }, - { SL("<"), PHVOLT_T_LESS }, - { SL("<="), PHVOLT_T_LESSEQUAL }, - { SL(">"), PHVOLT_T_GREATER }, - { SL(">="), PHVOLT_T_GREATEREQUAL }, - { SL("("), PHVOLT_T_PARENTHESES_OPEN }, - { SL(")"), PHVOLT_T_PARENTHESES_CLOSE }, - { SL("["), PHVOLT_T_SBRACKET_OPEN }, - { SL("]"), PHVOLT_T_SBRACKET_CLOSE }, - { SL("{"), PHVOLT_T_CBRACKET_OPEN }, - { SL("}"), PHVOLT_T_CBRACKET_CLOSE }, - { SL("{%"), PHVOLT_T_OPEN_DELIMITER }, - { SL("%}"), PHVOLT_T_CLOSE_DELIMITER }, - { SL("{{"), PHVOLT_T_OPEN_EDELIMITER }, - { SL("}}"), PHVOLT_T_CLOSE_EDELIMITER }, - { SL("IF"), PHVOLT_T_IF }, - { SL("ELSE"), PHVOLT_T_ELSE }, - { SL("ELSEIF"), PHVOLT_T_ELSEIF }, - { SL("ELSEFOR"), PHVOLT_T_ELSEFOR }, - { SL("ENDIF"), PHVOLT_T_ENDIF }, - { SL("FOR"), PHVOLT_T_FOR }, - { SL("IN"), PHVOLT_T_IN }, - { SL("ENDFOR"), PHVOLT_T_ENDFOR }, - { SL("SET"), PHVOLT_T_SET }, - { SL("ASSIGN"), PHVOLT_T_ASSIGN }, - { SL("+="), PHVOLT_T_ADD_ASSIGN }, - { SL("-="), PHVOLT_T_SUB_ASSIGN }, - { SL("*="), PHVOLT_T_MUL_ASSIGN }, - { SL("/="), PHVOLT_T_DIV_ASSIGN }, - { SL("++"), PHVOLT_T_INCR }, - { SL("--"), PHVOLT_T_DECR }, - { SL("BLOCK"), PHVOLT_T_BLOCK }, - { SL("ENDBLOCK"), PHVOLT_T_ENDBLOCK }, - { SL("CACHE"), PHVOLT_T_CACHE }, - { SL("ENDCACHE"), PHVOLT_T_ENDCACHE }, - { SL("EXTENDS"), PHVOLT_T_EXTENDS }, - { SL("IS"), PHVOLT_T_IS }, - { SL("DEFINED"), PHVOLT_T_DEFINED }, - { SL("INCLUDE"), PHVOLT_T_INCLUDE }, - { SL("DO"), PHVOLT_T_DO }, - { SL("WHITESPACE"), PHVOLT_T_IGNORE }, - { SL("AUTOESCAPE"), PHVOLT_T_AUTOESCAPE }, - { SL("ENDAUTOESCAPE"), PHVOLT_T_ENDAUTOESCAPE }, - { SL("CONTINUE"), PHVOLT_T_CONTINUE }, - { SL("BREAK"), PHVOLT_T_BREAK }, - { SL("WITH"), PHVOLT_T_WITH }, - { SL("RETURN"), PHVOLT_T_RETURN }, - { NULL, 0, 0 } -}; - -static void *phvolt_wrapper_alloc(size_t bytes){ - return emalloc(bytes); -} - -static void phvolt_wrapper_free(void *pointer){ - efree(pointer); -} - -static void phvolt_parse_with_token(void* phvolt_parser, int opcode, int parsercode, phvolt_scanner_token *token, phvolt_parser_status *parser_status){ - - phvolt_parser_token *pToken; - - pToken = emalloc(sizeof(phvolt_parser_token)); - pToken->opcode = opcode; - pToken->token = token->value; - pToken->token_len = token->len; - pToken->free_flag = 1; - - phvolt_(phvolt_parser, parsercode, pToken, parser_status); - - token->value = NULL; - token->len = 0; -} - -static void phvolt_create_error_msg(phvolt_parser_status *parser_status, char *message){ - - unsigned int length = (128 + Z_STRLEN_P(parser_status->scanner_state->active_file)); - char *str = emalloc(sizeof(char) * length); - - snprintf(str, length, "%s in %s on line %d", message, Z_STRVAL_P(parser_status->scanner_state->active_file), parser_status->scanner_state->active_line); - str[length - 1] = '\0'; - - parser_status->syntax_error = estrndup(str, strlen(str)); - efree(str); -} - -static void phvolt_scanner_error_msg(phvolt_parser_status *parser_status, zval **error_msg TSRMLS_DC){ - - char *error, *error_part; - int length; - phvolt_scanner_state *state = parser_status->scanner_state; - - PHALCON_INIT_VAR(*error_msg); - if (state->start) { - error = emalloc(sizeof(char) * 72 + state->start_length + Z_STRLEN_P(state->active_file)); - if (state->start_length > 16) { - length = 72 + Z_STRLEN_P(state->active_file); - error_part = estrndup(state->start, 16); - snprintf(error, length, "Scanning error before '%s...' in %s on line %d", error_part, Z_STRVAL_P(state->active_file), state->active_line); - error[length - 1] = '\0'; - } else { - length = 48 + state->start_length + Z_STRLEN_P(state->active_file); - snprintf(error, length, "Scanning error before '%s' in %s on line %d", state->start, Z_STRVAL_P(state->active_file), state->active_line); - } - } else { - error = emalloc(sizeof(char) * (32 + Z_STRLEN_P(state->active_file))); - length = 32 + Z_STRLEN_P(state->active_file); - snprintf(error, length, "Scanning error near to EOF in %s", Z_STRVAL_P(state->active_file)); - } - - error[length - 1] = '\0'; - ZVAL_STRING(*error_msg, error, 1); - efree(error); -} - -static int phvolt_parse_view(zval *result, zval *view_code, zval *template_path TSRMLS_DC){ - - zval *error_msg = NULL; - - ZVAL_NULL(result); - - if (Z_TYPE_P(view_code) != IS_STRING) { - phalcon_throw_exception_string(phalcon_mvc_view_exception_ce, SL("View code must be a string"), 1 TSRMLS_CC); - return FAILURE; - } - - if (phvolt_internal_parse_view(&result, view_code, template_path, &error_msg TSRMLS_CC) == FAILURE) { - phalcon_throw_exception_string(phalcon_mvc_view_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC); - return FAILURE; - } - - return SUCCESS; -} - -static int phvolt_is_blank_string(phvolt_scanner_token *token){ - - char *marker = token->value; - unsigned int ch, i; - - for (i = 0; i < token->len; i++) { - ch = *marker; - if (ch != ' ' && ch != '\t' && ch != '\n' && ch != '\r' && ch != 11) { +// 3584 "scanner.c" +yy215: + yych = *++YYCURSOR; + switch (yych) { + case 'A': + case 'a': goto yy223; + default: goto yy87; + } +yy216: + yych = *++YYCURSOR; + switch (yych) { + case 'D': + case 'd': goto yy221; + default: goto yy87; + } +yy217: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + case 'C': + case 'c': goto yy219; + default: goto yy218; + } +yy218: +// 101 "scanner.re" + { + token->opcode = PHQL_T_AS; return 0; } - marker++; - } - - return 1; -} - -static int phvolt_internal_parse_view(zval **result, zval *view_code, zval *template_path, zval **error_msg TSRMLS_DC) { - - char *error; - phvolt_scanner_state *state; - phvolt_scanner_token token; - int scanner_status, status = SUCCESS; - phvolt_parser_status *parser_status = NULL; - void* phvolt_parser; - - /** Check if the view has code */ - if (!Z_STRVAL_P(view_code)) { - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, "View code cannot be null", 1); - return FAILURE; - } - - if (!Z_STRLEN_P(view_code)) { - array_init(*result); - return SUCCESS; - } - - /** Start the reentrant parser */ - phvolt_parser = phvolt_Alloc(phvolt_wrapper_alloc); - - parser_status = emalloc(sizeof(phvolt_parser_status)); - state = emalloc(sizeof(phvolt_scanner_state)); - - parser_status->status = PHVOLT_PARSING_OK; - parser_status->scanner_state = state; - parser_status->ret = NULL; - parser_status->token = &token; - parser_status->syntax_error = NULL; - - /** Initialize the scanner state */ - state->active_token = 0; - state->start = Z_STRVAL_P(view_code); - state->mode = PHVOLT_MODE_RAW; - state->raw_buffer = emalloc(sizeof(char) * PHVOLT_RAW_BUFFER_SIZE); - state->raw_buffer_size = PHVOLT_RAW_BUFFER_SIZE; - state->raw_buffer_cursor = 0; - state->active_file = template_path; - state->active_line = 1; - state->statement_position = 0; - state->extends_mode = 0; - state->block_level = 0; - state->macro_level = 0; - state->start_length = 0; - state->old_if_level = 0; - state->if_level = 0; - state->for_level = 0; - state->whitespace_control = 0; - - state->end = state->start; - - token.value = NULL; - token.len = 0; - - while (0 <= (scanner_status = phvolt_get_token(state, &token))) { - - state->active_token = token.opcode; - - state->start_length = (Z_STRVAL_P(view_code) + Z_STRLEN_P(view_code) - state->start); - - switch (token.opcode) { - - case PHVOLT_T_IGNORE: - break; - - case PHVOLT_T_ADD: - phvolt_(phvolt_parser, PHVOLT_PLUS, NULL, parser_status); - break; - case PHVOLT_T_SUB: - phvolt_(phvolt_parser, PHVOLT_MINUS, NULL, parser_status); - break; - case PHVOLT_T_MUL: - phvolt_(phvolt_parser, PHVOLT_TIMES, NULL, parser_status); - break; - case PHVOLT_T_DIV: - phvolt_(phvolt_parser, PHVOLT_DIVIDE, NULL, parser_status); - break; - case PHVOLT_T_MOD: - phvolt_(phvolt_parser, PHVOLT_MOD, NULL, parser_status); - break; - case PHVOLT_T_AND: - phvolt_(phvolt_parser, PHVOLT_AND, NULL, parser_status); - break; - case PHVOLT_T_OR: - phvolt_(phvolt_parser, PHVOLT_OR, NULL, parser_status); - break; - case PHVOLT_T_IS: - phvolt_(phvolt_parser, PHVOLT_IS, NULL, parser_status); - break; - case PHVOLT_T_EQUALS: - phvolt_(phvolt_parser, PHVOLT_EQUALS, NULL, parser_status); - break; - case PHVOLT_T_NOTEQUALS: - phvolt_(phvolt_parser, PHVOLT_NOTEQUALS, NULL, parser_status); - break; - case PHVOLT_T_LESS: - phvolt_(phvolt_parser, PHVOLT_LESS, NULL, parser_status); - break; - case PHVOLT_T_GREATER: - phvolt_(phvolt_parser, PHVOLT_GREATER, NULL, parser_status); - break; - case PHVOLT_T_GREATEREQUAL: - phvolt_(phvolt_parser, PHVOLT_GREATEREQUAL, NULL, parser_status); - break; - case PHVOLT_T_LESSEQUAL: - phvolt_(phvolt_parser, PHVOLT_LESSEQUAL, NULL, parser_status); - break; - case PHVOLT_T_IDENTICAL: - phvolt_(phvolt_parser, PHVOLT_IDENTICAL, NULL, parser_status); - break; - case PHVOLT_T_NOTIDENTICAL: - phvolt_(phvolt_parser, PHVOLT_NOTIDENTICAL, NULL, parser_status); - break; - case PHVOLT_T_NOT: - phvolt_(phvolt_parser, PHVOLT_NOT, NULL, parser_status); - break; - case PHVOLT_T_DOT: - phvolt_(phvolt_parser, PHVOLT_DOT, NULL, parser_status); - break; - case PHVOLT_T_CONCAT: - phvolt_(phvolt_parser, PHVOLT_CONCAT, NULL, parser_status); - break; - case PHVOLT_T_RANGE: - phvolt_(phvolt_parser, PHVOLT_RANGE, NULL, parser_status); - break; - case PHVOLT_T_PIPE: - phvolt_(phvolt_parser, PHVOLT_PIPE, NULL, parser_status); - break; - case PHVOLT_T_COMMA: - phvolt_(phvolt_parser, PHVOLT_COMMA, NULL, parser_status); - break; - case PHVOLT_T_COLON: - phvolt_(phvolt_parser, PHVOLT_COLON, NULL, parser_status); - break; - case PHVOLT_T_QUESTION: - phvolt_(phvolt_parser, PHVOLT_QUESTION, NULL, parser_status); - break; - - case PHVOLT_T_PARENTHESES_OPEN: - phvolt_(phvolt_parser, PHVOLT_PARENTHESES_OPEN, NULL, parser_status); - break; - case PHVOLT_T_PARENTHESES_CLOSE: - phvolt_(phvolt_parser, PHVOLT_PARENTHESES_CLOSE, NULL, parser_status); - break; - case PHVOLT_T_SBRACKET_OPEN: - phvolt_(phvolt_parser, PHVOLT_SBRACKET_OPEN, NULL, parser_status); - break; - case PHVOLT_T_SBRACKET_CLOSE: - phvolt_(phvolt_parser, PHVOLT_SBRACKET_CLOSE, NULL, parser_status); - break; - case PHVOLT_T_CBRACKET_OPEN: - phvolt_(phvolt_parser, PHVOLT_CBRACKET_OPEN, NULL, parser_status); - break; - case PHVOLT_T_CBRACKET_CLOSE: - phvolt_(phvolt_parser, PHVOLT_CBRACKET_CLOSE, NULL, parser_status); - break; - - case PHVOLT_T_OPEN_DELIMITER: - phvolt_(phvolt_parser, PHVOLT_OPEN_DELIMITER, NULL, parser_status); - break; - case PHVOLT_T_CLOSE_DELIMITER: - phvolt_(phvolt_parser, PHVOLT_CLOSE_DELIMITER, NULL, parser_status); - break; - - case PHVOLT_T_OPEN_EDELIMITER: - if (state->extends_mode == 1 && state->block_level == 0) { - phvolt_create_error_msg(parser_status, "Child templates only may contain blocks"); - parser_status->status = PHVOLT_PARSING_FAILED; - break; - } - phvolt_(phvolt_parser, PHVOLT_OPEN_EDELIMITER, NULL, parser_status); - break; - case PHVOLT_T_CLOSE_EDELIMITER: - phvolt_(phvolt_parser, PHVOLT_CLOSE_EDELIMITER, NULL, parser_status); - break; - - case PHVOLT_T_NULL: - phvolt_(phvolt_parser, PHVOLT_NULL, NULL, parser_status); - break; - case PHVOLT_T_TRUE: - phvolt_(phvolt_parser, PHVOLT_TRUE, NULL, parser_status); - break; - case PHVOLT_T_FALSE: - phvolt_(phvolt_parser, PHVOLT_FALSE, NULL, parser_status); - break; - - case PHVOLT_T_INTEGER: - phvolt_parse_with_token(phvolt_parser, PHVOLT_T_INTEGER, PHVOLT_INTEGER, &token, parser_status); - break; - case PHVOLT_T_DOUBLE: - phvolt_parse_with_token(phvolt_parser, PHVOLT_T_DOUBLE, PHVOLT_DOUBLE, &token, parser_status); - break; - case PHVOLT_T_STRING: - phvolt_parse_with_token(phvolt_parser, PHVOLT_T_STRING, PHVOLT_STRING, &token, parser_status); - break; - case PHVOLT_T_IDENTIFIER: - phvolt_parse_with_token(phvolt_parser, PHVOLT_T_IDENTIFIER, PHVOLT_IDENTIFIER, &token, parser_status); - break; - - case PHVOLT_T_IF: - if (state->extends_mode == 1 && state->block_level == 0){ - phvolt_create_error_msg(parser_status, "Child templates only may contain blocks"); - parser_status->status = PHVOLT_PARSING_FAILED; - break; - } else { - state->if_level++; - state->block_level++; - } - phvolt_(phvolt_parser, PHVOLT_IF, NULL, parser_status); - break; - - case PHVOLT_T_ELSE: - if (state->if_level == 0 && state->for_level > 0) { - phvolt_(phvolt_parser, PHVOLT_ELSEFOR, NULL, parser_status); - } else { - phvolt_(phvolt_parser, PHVOLT_ELSE, NULL, parser_status); - } - break; - - case PHVOLT_T_ELSEFOR: - phvolt_(phvolt_parser, PHVOLT_ELSEFOR, NULL, parser_status); - break; - - case PHVOLT_T_ELSEIF: - if (state->if_level == 0) { - phvolt_create_error_msg(parser_status, "Unexpected ENDIF"); - parser_status->status = PHVOLT_PARSING_FAILED; - break; - } - phvolt_(phvolt_parser, PHVOLT_ELSEIF, NULL, parser_status); - break; - - case PHVOLT_T_ENDIF: - state->block_level--; - state->if_level--; - phvolt_(phvolt_parser, PHVOLT_ENDIF, NULL, parser_status); - break; - - case PHVOLT_T_FOR: - if (state->extends_mode == 1 && state->block_level == 0){ - phvolt_create_error_msg(parser_status, "Child templates only may contain blocks"); - parser_status->status = PHVOLT_PARSING_FAILED; - break; - } else { - state->old_if_level = state->if_level; - state->if_level = 0; - state->for_level++; - state->block_level++; - } - phvolt_(phvolt_parser, PHVOLT_FOR, NULL, parser_status); - break; - - case PHVOLT_T_IN: - phvolt_(phvolt_parser, PHVOLT_IN, NULL, parser_status); - break; - - case PHVOLT_T_ENDFOR: - state->block_level--; - state->for_level--; - state->if_level = state->old_if_level; - phvolt_(phvolt_parser, PHVOLT_ENDFOR, NULL, parser_status); - break; - - case PHVOLT_T_RAW_FRAGMENT: - if (token.len > 0) { - if (state->extends_mode == 1 && state->block_level == 0){ - if (!phvolt_is_blank_string(&token)) { - phvolt_create_error_msg(parser_status, "Child templates only may contain blocks"); - parser_status->status = PHVOLT_PARSING_FAILED; - } - efree(token.value); - break; - } else { - if (!phvolt_is_blank_string(&token)) { - state->statement_position++; - } - } - phvolt_parse_with_token(phvolt_parser, PHVOLT_T_RAW_FRAGMENT, PHVOLT_RAW_FRAGMENT, &token, parser_status); - } else { - efree(token.value); - } - break; - - case PHVOLT_T_SET: - if (state->extends_mode == 1 && state->block_level == 0){ - phvolt_create_error_msg(parser_status, "Child templates only may contain blocks"); - parser_status->status = PHVOLT_PARSING_FAILED; - break; - } - phvolt_(phvolt_parser, PHVOLT_SET, NULL, parser_status); - break; - case PHVOLT_T_ASSIGN: - phvolt_(phvolt_parser, PHVOLT_ASSIGN, NULL, parser_status); - break; - case PHVOLT_T_ADD_ASSIGN: - phvolt_(phvolt_parser, PHVOLT_ADD_ASSIGN, NULL, parser_status); - break; - case PHVOLT_T_SUB_ASSIGN: - phvolt_(phvolt_parser, PHVOLT_SUB_ASSIGN, NULL, parser_status); - break; - case PHVOLT_T_MUL_ASSIGN: - phvolt_(phvolt_parser, PHVOLT_MUL_ASSIGN, NULL, parser_status); - break; - case PHVOLT_T_DIV_ASSIGN: - phvolt_(phvolt_parser, PHVOLT_DIV_ASSIGN, NULL, parser_status); - break; - - case PHVOLT_T_INCR: - phvolt_(phvolt_parser, PHVOLT_INCR, NULL, parser_status); - break; - case PHVOLT_T_DECR: - phvolt_(phvolt_parser, PHVOLT_DECR, NULL, parser_status); - break; - - case PHVOLT_T_BLOCK: - if (state->block_level > 0) { - phvolt_create_error_msg(parser_status, "Embedding blocks into other blocks is not supported"); - parser_status->status = PHVOLT_PARSING_FAILED; - break; - } else { - state->block_level++; - } - phvolt_(phvolt_parser, PHVOLT_BLOCK, NULL, parser_status); - break; - case PHVOLT_T_ENDBLOCK: - state->block_level--; - phvolt_(phvolt_parser, PHVOLT_ENDBLOCK, NULL, parser_status); - break; - - case PHVOLT_T_MACRO: - if (state->macro_level > 0) { - phvolt_create_error_msg(parser_status, "Embedding macros into other macros is not allowed"); - parser_status->status = PHVOLT_PARSING_FAILED; - break; - } else { - state->macro_level++; - } - phvolt_(phvolt_parser, PHVOLT_MACRO, NULL, parser_status); - break; - case PHVOLT_T_ENDMACRO: - state->macro_level--; - phvolt_(phvolt_parser, PHVOLT_ENDMACRO, NULL, parser_status); - break; - - case PHVOLT_T_CALL: - phvolt_(phvolt_parser, PHVOLT_CALL, NULL, parser_status); - break; - case PHVOLT_T_ENDCALL: - phvolt_(phvolt_parser, PHVOLT_ENDCALL, NULL, parser_status); - break; - - case PHVOLT_T_CACHE: - phvolt_(phvolt_parser, PHVOLT_CACHE, NULL, parser_status); - break; - case PHVOLT_T_ENDCACHE: - phvolt_(phvolt_parser, PHVOLT_ENDCACHE, NULL, parser_status); - break; - - case PHVOLT_T_INCLUDE: - phvolt_(phvolt_parser, PHVOLT_INCLUDE, NULL, parser_status); - break; - - case PHVOLT_T_WITH: - phvolt_(phvolt_parser, PHVOLT_WITH, NULL, parser_status); - break; - - case PHVOLT_T_DEFINED: - phvolt_(phvolt_parser, PHVOLT_DEFINED, NULL, parser_status); - break; - - case PHVOLT_T_DO: - phvolt_(phvolt_parser, PHVOLT_DO, NULL, parser_status); - break; - case PHVOLT_T_RETURN: - phvolt_(phvolt_parser, PHVOLT_RETURN, NULL, parser_status); - break; - - case PHVOLT_T_AUTOESCAPE: - phvolt_(phvolt_parser, PHVOLT_AUTOESCAPE, NULL, parser_status); - break; - - case PHVOLT_T_ENDAUTOESCAPE: - phvolt_(phvolt_parser, PHVOLT_ENDAUTOESCAPE, NULL, parser_status); - break; - - case PHVOLT_T_BREAK: - phvolt_(phvolt_parser, PHVOLT_BREAK, NULL, parser_status); - break; - - case PHVOLT_T_CONTINUE: - phvolt_(phvolt_parser, PHVOLT_CONTINUE, NULL, parser_status); - break; - - case PHVOLT_T_EXTENDS: - if (state->statement_position != 1) { - phvolt_create_error_msg(parser_status, "Extends statement must be placed at the first line in the template"); - parser_status->status = PHVOLT_PARSING_FAILED; - break; - } else { - state->extends_mode = 1; - } - phvolt_(phvolt_parser, PHVOLT_EXTENDS, NULL, parser_status); - break; - - default: - parser_status->status = PHVOLT_PARSING_FAILED; - if (!*error_msg) { - error = emalloc(sizeof(char) * (48 + Z_STRLEN_P(state->active_file))); - snprintf(error, 48 + Z_STRLEN_P(state->active_file) + state->active_line, "Scanner: unknown opcode %d on in %s line %d", token.opcode, Z_STRVAL_P(state->active_file), state->active_line); - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, error, 1); - efree(error); - } - break; +// 3674 "scanner.c" +yy219: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy220; + } +yy220: +// 141 "scanner.re" + { + token->opcode = PHQL_T_ASC; + return 0; } - - if (parser_status->status != PHVOLT_PARSING_OK) { - status = FAILURE; - break; +// 3750 "scanner.c" +yy221: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy222; + } +yy222: +// 176 "scanner.re" + { + token->opcode = PHQL_T_AND; + return 0; } - - state->end = state->start; - } - - if (status != FAILURE) { - switch (scanner_status) { - case PHVOLT_SCANNER_RETCODE_ERR: - case PHVOLT_SCANNER_RETCODE_IMPOSSIBLE: - if (!*error_msg) { - phvolt_scanner_error_msg(parser_status, error_msg TSRMLS_CC); - } - status = FAILURE; - break; - default: - phvolt_(phvolt_parser, 0, NULL, parser_status); +// 3826 "scanner.c" +yy223: + yych = *++YYCURSOR; + switch (yych) { + case 'I': + case 'i': goto yy224; + default: goto yy87; + } +yy224: + yych = *++YYCURSOR; + switch (yych) { + case 'N': + case 'n': goto yy225; + default: goto yy87; + } +yy225: + yych = *++YYCURSOR; + switch (yych) { + case 'S': + case 's': goto yy226; + default: goto yy87; + } +yy226: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy227; + default: goto yy87; + } +yy227: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy228; + } +yy228: +// 196 "scanner.re" + { + token->opcode = PHQL_T_AGAINST; + return 0; } - } - - state->active_token = 0; - state->start = NULL; - efree(state->raw_buffer); - - if (parser_status->status != PHVOLT_PARSING_OK) { - status = FAILURE; - if (parser_status->syntax_error) { - if (!*error_msg) { - PHALCON_INIT_VAR(*error_msg); - ZVAL_STRING(*error_msg, parser_status->syntax_error, 1); +// 3930 "scanner.c" +yy229: + yych = *++YYCURSOR; + switch (yych) { + case 'L': + case 'l': goto yy238; + default: goto yy87; + } +yy230: + yych = *++YYCURSOR; + switch (yych) { + case 'O': + case 'o': goto yy235; + default: goto yy87; + } +yy231: + yych = *++YYCURSOR; + switch (yych) { + case 'L': + case 'l': goto yy232; + default: goto yy87; + } +yy232: + yych = *++YYCURSOR; + switch (yych) { + case 'L': + case 'l': goto yy233; + default: goto yy87; + } +yy233: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy234; + } +yy234: +// 241 "scanner.re" + { + token->opcode = PHQL_T_FULL; + return 0; + } +// 4034 "scanner.c" +yy235: + yych = *++YYCURSOR; + switch (yych) { + case 'M': + case 'm': goto yy236; + default: goto yy87; + } +yy236: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy237; + } +yy237: +// 96 "scanner.re" + { + token->opcode = PHQL_T_FROM; + return 0; + } +// 4117 "scanner.c" +yy238: + yych = *++YYCURSOR; + switch (yych) { + case 'S': + case 's': goto yy239; + default: goto yy87; + } +yy239: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy240; + default: goto yy87; + } +yy240: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy241; } - efree(parser_status->syntax_error); +yy241: +// 286 "scanner.re" + { + token->opcode = PHQL_T_FALSE; + return 0; } - } - - phvolt_Free(phvolt_parser, phvolt_wrapper_free); - - if (status != FAILURE) { - if (parser_status->status == PHVOLT_PARSING_OK) { - if (parser_status->ret) { - ZVAL_ZVAL(*result, parser_status->ret, 0, 0); - ZVAL_NULL(parser_status->ret); - zval_ptr_dtor(&parser_status->ret); - } else { - array_init(*result); +// 4207 "scanner.c" +yy242: + yych = *++YYCURSOR; + switch (yych) { + case 'L': + case 'l': goto yy251; + case 'S': + case 's': goto yy252; + default: goto yy87; } - } - } - - efree(parser_status); - efree(state); - - return status; -} - - -/* Generated by re2c 0.13.5 on Fri Jun 28 19:17:30 2013 */ -// 1 "scanner.re" - - -#ifdef HAVE_CONFIG_H -#endif - - - -#define KKCTYPE unsigned char -#define KKCURSOR (s->start) -#define KKLIMIT (s->end) -#define KKMARKER q - -static void phvolt_rtrim(phvolt_scanner_token *token) { - - char *cursor, *removed_str; - unsigned int i; - unsigned char ch; - - if (token->len > 0) { - - cursor = token->value; - cursor += (token->len - 1); - for (i = token->len; i > 0; i--) { - ch = (*cursor); - if (ch == '\t' || ch == '\n' || ch == '\r' || ch == ' ' || ch == '\v') { - cursor--; - continue; +yy243: + yych = *++YYCURSOR; + switch (yych) { + case 'S': + case 's': goto yy244; + default: goto yy87; } - break; - } - - removed_str = emalloc(i + 1); - memcpy(removed_str, token->value, i); - removed_str[i] = '\0'; - - efree(token->value); - token->value = removed_str; - token->len = i; - } - -} - -static void phvolt_ltrim(phvolt_scanner_token *token) { - - char *cursor, *removed_str; - unsigned int i; - unsigned char ch; - - if (token->len > 0) { - - cursor = token->value; - for (i = 0; i < token->len; i++) { - ch = (*cursor); - if (ch == '\t' || ch == '\n' || ch == '\r' || ch == ' ' || ch == '\v') { - cursor++; - continue; +yy244: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy245; + default: goto yy87; } - break; +yy245: + yych = *++YYCURSOR; + switch (yych) { + case 'I': + case 'i': goto yy246; + default: goto yy87; + } +yy246: + yych = *++YYCURSOR; + switch (yych) { + case 'N': + case 'n': goto yy247; + default: goto yy87; + } +yy247: + yych = *++YYCURSOR; + switch (yych) { + case 'C': + case 'c': goto yy248; + default: goto yy87; + } +yy248: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy249; + default: goto yy87; + } +yy249: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy250; + } +yy250: +// 256 "scanner.re" + { + token->opcode = PHQL_T_DISTINCT; + return 0; } - - removed_str = emalloc(token->len - i + 1); - memcpy(removed_str, token->value + i, token->len - i); - removed_str[token->len - i] = '\0'; - - efree(token->value); - token->value = removed_str; - token->len = token->len - i; - } - -} - -static int phvolt_get_token(phvolt_scanner_state *s, phvolt_scanner_token *token) { - - unsigned char next, double_next; - char *q = KKCURSOR, *start = KKCURSOR; - int status = PHVOLT_SCANNER_RETCODE_IMPOSSIBLE; - - while (PHVOLT_SCANNER_RETCODE_IMPOSSIBLE == status) { - - if (s->mode == PHVOLT_MODE_RAW || s->mode == PHVOLT_MODE_COMMENT) { - - next = '\0'; - double_next = '\0'; - - if (*KKCURSOR == '\n') { - s->active_line++; +// 4334 "scanner.c" +yy251: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy255; + default: goto yy87; } - - if (*KKCURSOR != '\0') { - next = *(KKCURSOR + 1); - if (next != '\0') { - double_next = *(KKCURSOR + 2); - } +yy252: + yych = *++YYCURSOR; + switch (yych) { + case 'C': + case 'c': goto yy253; + default: goto yy87; } - - if (*KKCURSOR == '\0' || (*KKCURSOR == '{' && (next == '%' || next == '{' || next == '#'))) { - - if (next != '#') { - - s->mode = PHVOLT_MODE_CODE; - - if (s->raw_buffer_cursor > 0) { - - token->opcode = PHVOLT_T_RAW_FRAGMENT; - token->value = emalloc(sizeof(char) * s->raw_buffer_cursor + 1); - memcpy(token->value, s->raw_buffer, s->raw_buffer_cursor); - token->value[s->raw_buffer_cursor] = 0; - token->len = s->raw_buffer_cursor; - - if (s->whitespace_control == 1) { - phvolt_ltrim(token); - s->whitespace_control = 0; - } - - if (double_next == '-') { - phvolt_rtrim(token); - } - - s->raw_buffer_cursor = 0; - q = KKCURSOR; - } else { - token->opcode = PHVOLT_T_IGNORE; - } - - } else { - - while ((next = *(++KKCURSOR))) { - if (next == '#' && *(KKCURSOR + 1) == '}') { - KKCURSOR+=2; - token->opcode = PHVOLT_T_IGNORE; - return 0; - } else { - if (next == '\n') { - s->active_line++; - } - } - } - - return PHVOLT_SCANNER_RETCODE_EOF; - } - - return 0; - - } else { - - if (s->raw_buffer_cursor == s->raw_buffer_size) { - s->raw_buffer_size += PHVOLT_RAW_BUFFER_SIZE; - s->raw_buffer = erealloc(s->raw_buffer, s->raw_buffer_size); - } - - memcpy(s->raw_buffer+s->raw_buffer_cursor, KKCURSOR, 1); - s->raw_buffer_cursor++; - - ++KKCURSOR; +yy253: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy254; } - - } else { - - -// 184 "scanner.c" - { - KKCTYPE kkch; - unsigned int kkaccept = 0; - - kkch = *KKCURSOR; - switch (kkch) { - case 0x00: goto kk70; - case '\t': - case '\r': - case ' ': goto kk66; - case '\n': goto kk68; - case '!': goto kk58; - case '"': goto kk27; - case '%': goto kk21; - case '\'': goto kk29; - case '(': goto kk44; - case ')': goto kk46; - case '*': goto kk34; - case '+': goto kk32; - case ',': goto kk42; - case '-': goto kk23; - case '.': goto kk40; - case '/': goto kk36; +yy254: +// 146 "scanner.re" + { + token->opcode = PHQL_T_DESC; + return 0; + } +// 4424 "scanner.c" +yy255: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy256; + default: goto yy87; + } +yy256: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy257; + default: goto yy87; + } +yy257: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy258; + } +yy258: +// 91 "scanner.re" + { + token->opcode = PHQL_T_DELETE; + return 0; + } +// 4514 "scanner.c" +yy259: + yych = *++YYCURSOR; + switch (yych) { + case 'L': + case 'l': goto yy262; + case 'T': + case 't': goto yy260; + default: goto yy87; + } +yy260: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { case '0': case '1': case '2': @@ -70060,292 +64376,383 @@ static int phvolt_get_token(phvolt_scanner_state *s, phvolt_scanner_token *token case '6': case '7': case '8': - case '9': goto kk2; - case ':': goto kk62; - case '<': goto kk52; - case '=': goto kk54; - case '>': goto kk56; - case '?': goto kk64; + case '9': case 'A': - case 'a': goto kk11; case 'B': - case 'b': goto kk13; case 'C': - case 'c': goto kk15; case 'D': - case 'd': goto kk18; case 'E': - case 'e': goto kk6; case 'F': - case 'f': goto kk7; case 'G': case 'H': + case 'I': case 'J': case 'K': case 'L': + case 'M': + case 'N': + case 'O': case 'P': case 'Q': + case 'R': + case 'S': + case 'T': case 'U': case 'V': + case 'W': case 'X': case 'Y': case 'Z': + case '\\': case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': case 'g': case 'h': + case 'i': case 'j': case 'k': case 'l': + case 'm': + case 'n': + case 'o': case 'p': case 'q': + case 'r': + case 's': + case 't': case 'u': case 'v': + case 'w': case 'x': case 'y': - case 'z': goto kk31; + case 'z': goto yy86; + default: goto yy261; + } +yy261: +// 86 "scanner.re" + { + token->opcode = PHQL_T_SET; + return 0; + } +// 4599 "scanner.c" +yy262: + yych = *++YYCURSOR; + switch (yych) { + case 'E': + case 'e': goto yy263; + default: goto yy87; + } +yy263: + yych = *++YYCURSOR; + switch (yych) { + case 'C': + case 'c': goto yy264; + default: goto yy87; + } +yy264: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy265; + default: goto yy87; + } +yy265: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': case 'I': - case 'i': goto kk4; + case 'J': + case 'K': + case 'L': case 'M': - case 'm': goto kk14; case 'N': - case 'n': goto kk9; case 'O': - case 'o': goto kk12; + case 'P': + case 'Q': case 'R': - case 'r': goto kk17; case 'S': - case 's': goto kk8; case 'T': - case 't': goto kk10; + case 'U': + case 'V': case 'W': - case 'w': goto kk16; - case '[': goto kk48; - case '\\': goto kk30; - case ']': goto kk50; - case '{': goto kk19; - case '|': goto kk60; - case '}': goto kk25; - case '~': goto kk38; - default: goto kk72; + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy266; } -kk2: - kkaccept = 0; - kkch = *(KKMARKER = ++KKCURSOR); - goto kk292; -kk3: -// 185 "scanner.re" +yy266: +// 126 "scanner.re" { - token->opcode = PHVOLT_T_INTEGER; - token->value = estrndup(start, KKCURSOR - start); - token->len = KKCURSOR - start; - q = KKCURSOR; + token->opcode = PHQL_T_SELECT; return 0; } -// 298 "scanner.c" -kk4: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case 'F': - case 'f': goto kk278; - case 'N': - case 'n': goto kk280; - case 'S': - case 's': goto kk282; - default: goto kk100; +// 4696 "scanner.c" +yy267: + yych = *++YYCURSOR; + switch (yych) { + case 'D': + case 'd': goto yy273; + default: goto yy87; } -kk5: -// 450 "scanner.re" - { - token->opcode = PHVOLT_T_IDENTIFIER; - token->value = estrndup(start, KKCURSOR - start); - token->len = KKCURSOR - start; - q = KKCURSOR; - return 0; - } -// 319 "scanner.c" -kk6: - kkch = *++KKCURSOR; - switch (kkch) { - case 'L': - case 'l': goto kk219; +yy268: + yych = *++YYCURSOR; + switch (yych) { + case 'I': + case 'i': goto yy269; + default: goto yy87; + } +yy269: + yych = *++YYCURSOR; + switch (yych) { case 'N': - case 'n': goto kk220; - case 'X': - case 'x': goto kk221; - default: goto kk100; + case 'n': goto yy270; + default: goto yy87; } -kk7: - kkch = *++KKCURSOR; - switch (kkch) { - case 'A': - case 'a': goto kk211; - case 'O': - case 'o': goto kk212; - default: goto kk100; +yy270: + yych = *++YYCURSOR; + switch (yych) { + case 'G': + case 'g': goto yy271; + default: goto yy87; } -kk8: - kkch = *++KKCURSOR; - switch (kkch) { +yy271: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': case 'E': - case 'e': goto kk208; - default: goto kk100; - } -kk9: - kkch = *++KKCURSOR; - switch (kkch) { + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': case 'O': - case 'o': goto kk201; - case 'U': - case 'u': goto kk202; - default: goto kk100; - } -kk10: - kkch = *++KKCURSOR; - switch (kkch) { + case 'P': + case 'Q': case 'R': - case 'r': goto kk197; - default: goto kk100; - } -kk11: - kkch = *++KKCURSOR; - switch (kkch) { - case 'N': - case 'n': goto kk184; + case 'S': + case 'T': case 'U': - case 'u': goto kk185; - default: goto kk100; - } -kk12: - kkch = *++KKCURSOR; - switch (kkch) { - case 'R': - case 'r': goto kk182; - default: goto kk100; - } -kk13: - kkch = *++KKCURSOR; - switch (kkch) { - case 'L': - case 'l': goto kk172; - case 'R': - case 'r': goto kk173; - default: goto kk100; - } -kk14: - kkch = *++KKCURSOR; - switch (kkch) { - case 'A': - case 'a': goto kk167; - default: goto kk100; + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy272; } -kk15: - kkch = *++KKCURSOR; - switch (kkch) { +yy272: +// 276 "scanner.re" + { + token->opcode = PHQL_T_USING; + return 0; + } +// 4800 "scanner.c" +yy273: + yych = *++YYCURSOR; + switch (yych) { case 'A': - case 'a': goto kk151; - case 'O': - case 'o': goto kk152; - default: goto kk100; + case 'a': goto yy274; + default: goto yy87; } -kk16: - kkch = *++KKCURSOR; - switch (kkch) { - case 'I': - case 'i': goto kk147; - default: goto kk100; +yy274: + yych = *++YYCURSOR; + switch (yych) { + case 'T': + case 't': goto yy275; + default: goto yy87; } -kk17: - kkch = *++KKCURSOR; - switch (kkch) { +yy275: + yych = *++YYCURSOR; + switch (yych) { case 'E': - case 'e': goto kk141; - default: goto kk100; + case 'e': goto yy276; + default: goto yy87; } -kk18: - kkch = *++KKCURSOR; - switch (kkch) { +yy276: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': case 'E': - case 'e': goto kk132; + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': case 'O': - case 'o': goto kk133; - default: goto kk100; - } -kk19: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '%': goto kk126; - case '{': goto kk124; - default: goto kk20; - } -kk20: -// 533 "scanner.re" - { - token->opcode = PHVOLT_T_CBRACKET_OPEN; - return 0; - } -// 440 "scanner.c" -kk21: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '}': goto kk122; - default: goto kk22; - } -kk22: -// 478 "scanner.re" - { - token->opcode = PHVOLT_T_MOD; - return 0; - } -// 453 "scanner.c" -kk23: - kkaccept = 1; - kkch = *(KKMARKER = ++KKCURSOR); - switch (kkch) { - case '%': goto kk117; - case '-': goto kk114; - case '=': goto kk112; - case '}': goto kk116; - default: goto kk24; - } -kk24: -// 463 "scanner.re" - { - token->opcode = PHVOLT_T_SUB; - return 0; - } -// 470 "scanner.c" -kk25: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '}': goto kk110; - default: goto kk26; + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto yy86; + default: goto yy277; } -kk26: -// 538 "scanner.re" +yy277: +// 81 "scanner.re" { - token->opcode = PHVOLT_T_CBRACKET_CLOSE; + token->opcode = PHQL_T_UPDATE; return 0; } -// 483 "scanner.c" -kk27: - kkaccept = 2; - kkch = *(KKMARKER = ++KKCURSOR); - if (kkch >= 0x01) goto kk108; -kk28: -// 649 "scanner.re" - { - status = PHVOLT_SCANNER_RETCODE_ERR; - break; - } -// 494 "scanner.c" -kk29: - kkaccept = 2; - kkch = *(KKMARKER = ++KKCURSOR); - if (kkch <= 0x00) goto kk28; - goto kk102; -kk30: - kkch = *++KKCURSOR; - switch (kkch) { +// 4897 "scanner.c" +yy278: + ++YYCURSOR; + yych = *YYCURSOR; + switch (yych) { + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': case 'A': case 'B': case 'C': @@ -70398,8259 +64805,12626 @@ static int phvolt_get_token(phvolt_scanner_state *s, phvolt_scanner_token *token case 'w': case 'x': case 'y': - case 'z': goto kk99; - default: goto kk28; + case 'z': goto yy278; + case ':': goto yy280; + default: goto yy83; } -kk31: - kkch = *++KKCURSOR; - goto kk100; -kk32: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '+': goto kk97; - case '=': goto kk95; - default: goto kk33; +yy280: + ++YYCURSOR; +// 73 "scanner.re" + { + token->opcode = PHQL_T_SPLACEHOLDER; + token->value = estrndup(q, YYCURSOR - q - 1); + token->len = YYCURSOR - q - 1; + q = YYCURSOR; + return 0; + } +// 4979 "scanner.c" +yy282: + ++YYCURSOR; + yych = *YYCURSOR; + switch (yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy282; + default: goto yy284; + } +yy284: +// 64 "scanner.re" + { + token->opcode = PHQL_T_NPLACEHOLDER; + token->value = estrndup(q, YYCURSOR - q); + token->len = YYCURSOR - q; + q = YYCURSOR; + return 0; + } +// 5005 "scanner.c" +yy285: + ++YYCURSOR; + yych = *YYCURSOR; + switch (yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy285; + default: goto yy287; + } +yy287: +// 55 "scanner.re" + { + token->opcode = PHQL_T_DOUBLE; + token->value = estrndup(q, YYCURSOR - q); + token->len = YYCURSOR - q; + q = YYCURSOR; + return 0; + } +// 5031 "scanner.c" +yy288: + ++YYCURSOR; + yych = *YYCURSOR; + switch (yych) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy288; + default: goto yy287; + } +yy290: + ++YYCURSOR; + yych = *YYCURSOR; + switch (yych) { + case '.': goto yy288; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto yy290; + default: goto yy3; + } + } +// 453 "scanner.re" + + } + + return status; +} + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query_Status){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\Query, Status, mvc_model_query_status, phalcon_mvc_model_query_status_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_model_query_status_ce, SL("_success"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_status_ce, SL("_model"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_query_status_ce TSRMLS_CC, 1, phalcon_mvc_model_query_statusinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query_Status, __construct){ + + zval *success, *model; + + phalcon_fetch_params(0, 2, 0, &success, &model); + + phalcon_update_property_this_quick(this_ptr, SL("_success"), success, 1784834493UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_model"), model, 2599397109UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query_Status, getModel){ + + + RETURN_MEMBER_QUICK(this_ptr, "_model", 2599397109UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query_Status, getMessages){ + + zval *model; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(model); + phalcon_read_property_this_quick(&model, this_ptr, SL("_model"), 2599397109UL, PH_NOISY_CC); + if (Z_TYPE_P(model) == IS_OBJECT) { + phalcon_call_method_key(return_value, model, "getmessages", 4087333309UL); + RETURN_MM(); + } + + RETURN_MM_EMPTY_ARRAY(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query_Status, success){ + + + RETURN_MEMBER_QUICK(this_ptr, "_success", 1784834493UL); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query_StatusInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model\\Query, StatusInterface, mvc_model_query_statusinterface, phalcon_mvc_model_query_statusinterface_method_entry); + + return SUCCESS; +} + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Query, mvc_model_query, phalcon_mvc_model_query_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_manager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_metaData"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_phql"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_ast"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_intermediate"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_models"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_sqlAliases"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_sqlAliasesModels"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_sqlModelsAliases"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_sqlAliasesModelsInstances"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_sqlColumnAliases"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_modelsInstances"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_cache"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_cacheOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_uniqueRow"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_bindParams"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_bindTypes"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_query_ce, SL("_irPhqlCache"), ZEND_ACC_STATIC|ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_declare_class_constant_long(phalcon_mvc_model_query_ce, SL("TYPE_SELECT"), 309 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_query_ce, SL("TYPE_INSERT"), 306 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_query_ce, SL("TYPE_UPDATE"), 300 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_query_ce, SL("TYPE_DELETE"), 303 TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_query_ce TSRMLS_CC, 2, phalcon_mvc_model_queryinterface_ce, phalcon_di_injectionawareinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, __construct){ + + zval *phql = NULL, *dependency_injector = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &phql, &dependency_injector); + + if (!phql) { + PHALCON_INIT_VAR(phql); + } + + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); + } + + if (Z_TYPE_P(phql) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_phql"), phql, 3986605817UL TSRMLS_CC); + } + if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + phalcon_call_method_p1_key(NULL, this_ptr, "setdi", dependency_injector, 461718238UL); + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, setDI){ + + zval *dependency_injector, *service = NULL, *manager; + zval *meta_data; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &dependency_injector); + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the ORM services"); + return; + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "modelsManager", 1); + + PHALCON_INIT_VAR(manager); + phalcon_call_method_p1_key(manager, dependency_injector, "getshared", service, 1727570332UL); + if (Z_TYPE_P(manager) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Injected service 'modelsManager' is invalid"); + return; + } + + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "modelsMetadata", 1); + + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_p1_key(meta_data, dependency_injector, "getshared", service, 1727570332UL); + if (Z_TYPE_P(meta_data) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Injected service 'modelsMetadata' is invalid"); + return; + } + + phalcon_update_property_this_quick(this_ptr, SL("_manager"), manager, 4140832863UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_metaData"), meta_data, 1295805989UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, setUniqueRow){ + + zval *unique_row; + + phalcon_fetch_params(0, 1, 0, &unique_row); + + phalcon_update_property_this_quick(this_ptr, SL("_uniqueRow"), unique_row, 1221667347UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, getUniqueRow){ + + + RETURN_MEMBER_QUICK(this_ptr, "_uniqueRow", 1221667347UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getQualified){ + + zval *expr, *column_name, *sql_column_aliases; + zval *source_column = NULL, *meta_data, *column_domain; + zval *sql_aliases, *phql = NULL, *exception_message = NULL; + zval *source = NULL, *sql_aliases_models_instances; + zval *model = NULL, *column_map = NULL, *real_column_name = NULL; + zval *number, *has_model = NULL, *models_instances; + zval *has_attribute = NULL, *models, *class_name; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &expr); + + PHALCON_OBS_VAR(column_name); + phalcon_array_fetch_quick_string(&column_name, expr, SS("name"), 268211462UL, PH_NOISY); + + PHALCON_OBS_VAR(sql_column_aliases); + phalcon_read_property_this_quick(&sql_column_aliases, this_ptr, SL("_sqlColumnAliases"), 3031417188UL, PH_NOISY_CC); + + if (phalcon_array_isset(sql_column_aliases, column_name)) { + PHALCON_INIT_VAR(source_column); + array_init_size(source_column, 2); + add_assoc_stringl_ex(source_column, SS("type"), SL("qualified"), 1); + phalcon_array_update_quick_string(&source_column, SS("name"), 268211462UL, &column_name, PH_COPY | PH_SEPARATE); + RETURN_CTOR(source_column); + } + + PHALCON_OBS_VAR(meta_data); + phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); + + if (phalcon_array_isset_quick_string(expr, SS("domain"), 542597917UL)) { + + PHALCON_OBS_VAR(column_domain); + phalcon_array_fetch_quick_string(&column_domain, expr, SS("domain"), 542597917UL, PH_NOISY); + + PHALCON_OBS_VAR(sql_aliases); + phalcon_read_property_this_quick(&sql_aliases, this_ptr, SL("_sqlAliases"), 3407085878UL, PH_NOISY_CC); + + if (!phalcon_array_isset(sql_aliases, column_domain)) { + PHALCON_OBS_VAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "Unknown model or alias '", column_domain, "' (1), when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_VAR(source); + phalcon_array_fetch(&source, sql_aliases, column_domain, PH_NOISY); + + if (PHALCON_GLOBAL(orm).column_renaming) { + + PHALCON_OBS_VAR(sql_aliases_models_instances); + phalcon_read_property_this_quick(&sql_aliases_models_instances, this_ptr, SL("_sqlAliasesModelsInstances"), 3347052930UL, PH_NOISY_CC); + + if (!phalcon_array_isset(sql_aliases_models_instances, column_domain)) { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "There is no model related to model or alias '", column_domain, "', when executing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_VAR(model); + phalcon_array_fetch(&model, sql_aliases_models_instances, column_domain, PH_NOISY); + + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getreversecolumnmap", model, 817005101UL); + } else { + PHALCON_INIT_NVAR(column_map); + } + + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, column_name)) { + PHALCON_OBS_VAR(real_column_name); + phalcon_array_fetch(&real_column_name, column_map, column_name, PH_NOISY); + } else { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVSV(exception_message, "Column '", column_name, "' doesn't belong to the model or alias '", column_domain, "', when executing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } else { + PHALCON_CPY_WRT(real_column_name, column_name); + } + } else { + PHALCON_INIT_VAR(number); + ZVAL_LONG(number, 0); + + PHALCON_INIT_VAR(has_model); + ZVAL_BOOL(has_model, 0); + + PHALCON_OBS_VAR(models_instances); + phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); + + phalcon_is_iterable(models_instances, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(model); + + PHALCON_INIT_NVAR(has_attribute); + phalcon_call_method_p2_key(has_attribute, meta_data, "hasattribute", model, column_name, 3258442645UL); + if (zend_is_true(has_attribute)) { + PHALCON_SEPARATE(number); + phalcon_increment(number); + if (PHALCON_GT_LONG(number, 1)) { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "The column '", column_name, "' is ambiguous, when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_CPY_WRT(has_model, model); } -kk33: -// 458 "scanner.re" - { - token->opcode = PHVOLT_T_ADD; - return 0; + + zend_hash_move_forward_ex(ah0, &hp0); } -// 574 "scanner.c" -kk34: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '=': goto kk93; - default: goto kk35; + + if (PHALCON_IS_FALSE(has_model)) { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "Column '", column_name, "' doesn't belong to any of the selected models (1), when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_VAR(models); + phalcon_read_property_this_quick(&models, this_ptr, SL("_models"), 4175729768UL, PH_NOISY_CC); + if (Z_TYPE_P(models) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The models list was not loaded correctly"); + return; + } + + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, has_model, 0 TSRMLS_CC); + if (phalcon_array_isset(models, class_name)) { + PHALCON_OBS_NVAR(source); + phalcon_array_fetch(&source, models, class_name, PH_NOISY); + } else { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "Column '", column_name, "' doesn't belong to any of the selected models (2), when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_NVAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getreversecolumnmap", has_model, 817005101UL); + } else { + PHALCON_INIT_NVAR(column_map); + } + + if (Z_TYPE_P(column_map) == IS_ARRAY) { + + if (phalcon_array_isset(column_map, column_name)) { + PHALCON_OBS_NVAR(real_column_name); + phalcon_array_fetch(&real_column_name, column_map, column_name, PH_NOISY); + } else { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "Column '", column_name, "' doesn't belong to any of the selected models (3), when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -kk35: -// 468 "scanner.re" - { - token->opcode = PHVOLT_T_MUL; - return 0; + } else { + PHALCON_CPY_WRT(real_column_name, column_name); } -// 587 "scanner.c" -kk36: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '=': goto kk91; - default: goto kk37; + } + + PHALCON_INIT_NVAR(source_column); + array_init_size(source_column, 4); + add_assoc_stringl_ex(source_column, SS("type"), SL("qualified"), 1); + phalcon_array_update_quick_string(&source_column, SS("domain"), 542597917UL, &source, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&source_column, SS("name"), 268211462UL, &real_column_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&source_column, SS("balias"), 1705826801UL, &column_name, PH_COPY | PH_SEPARATE); + + RETURN_CTOR(source_column); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getCallArgument){ + + zval *argument, *argument_type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &argument); + + PHALCON_OBS_VAR(argument_type); + phalcon_array_fetch_quick_string(&argument_type, argument, SS("type"), 276192743UL, PH_NOISY); + if (PHALCON_IS_LONG(argument_type, 352)) { + array_init_size(return_value, 1); + add_assoc_stringl_ex(return_value, SS("type"), SL("all"), 1); + RETURN_MM(); + } + + phalcon_call_method_p1_key(return_value, this_ptr, "_getexpression", argument, 2816780276UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getFunctionCall){ + + zval *expr, *name, *arguments, *function_args = NULL, *argument = NULL; + zval *argument_expr = NULL, *function_call = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &expr); + + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, expr, SS("name"), 268211462UL, PH_NOISY); + if (phalcon_array_isset_quick_string(expr, SS("arguments"), 3751272283UL)) { + + PHALCON_OBS_VAR(arguments); + phalcon_array_fetch_quick_string(&arguments, expr, SS("arguments"), 3751272283UL, PH_NOISY); + if (phalcon_array_isset_long(arguments, 0)) { + + PHALCON_INIT_VAR(function_args); + array_init(function_args); + + phalcon_is_iterable(arguments, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(argument); + + PHALCON_INIT_NVAR(argument_expr); + phalcon_call_method_p1_key(argument_expr, this_ptr, "_getcallargument", argument, 3276339843UL); + phalcon_array_append(&function_args, argument_expr, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } -kk37: -// 473 "scanner.re" - { - token->opcode = PHVOLT_T_DIV; - return 0; + + } else { + PHALCON_INIT_NVAR(argument_expr); + phalcon_call_method_p1_key(argument_expr, this_ptr, "_getcallargument", arguments, 3276339843UL); + + PHALCON_INIT_NVAR(function_args); + array_init_size(function_args, 1); + phalcon_array_append(&function_args, argument_expr, PH_SEPARATE); } -// 600 "scanner.c" -kk38: - ++KKCURSOR; -// 493 "scanner.re" - { - token->opcode = PHVOLT_T_CONCAT; - return 0; + + PHALCON_INIT_VAR(function_call); + array_init_size(function_call, 3); + add_assoc_stringl_ex(function_call, SS("type"), SL("functionCall"), 1); + phalcon_array_update_quick_string(&function_call, SS("name"), 268211462UL, &name, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&function_call, SS("arguments"), 3751272283UL, &function_args, PH_COPY | PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(function_call); + array_init_size(function_call, 2); + add_assoc_stringl_ex(function_call, SS("type"), SL("functionCall"), 1); + phalcon_array_update_quick_string(&function_call, SS("name"), 268211462UL, &name, PH_COPY | PH_SEPARATE); + } + + RETURN_CTOR(function_call); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getExpression){ + + zval *expr, *quoting = NULL, *temp_not_quoting, *expr_left; + zval *left, *expr_right, *right, *expr_type, *expr_return = NULL; + zval *expr_value = NULL, *value = NULL, *escaped_value = NULL, *question_mark; + zval *double_colon, *placeholder = NULL, *expression_message; + zval *expression, *list_items, *expr_list_item = NULL; + zval *expr_item = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &expr, "ing); + + if (!quoting) { + PHALCON_INIT_VAR(quoting); + ZVAL_BOOL(quoting, 1); + } + + if (phalcon_array_isset_quick_string(expr, SS("type"), 276192743UL)) { + + PHALCON_INIT_VAR(temp_not_quoting); + ZVAL_BOOL(temp_not_quoting, 1); + + if (phalcon_array_isset_quick_string(expr, SS("left"), 265976240UL)) { + PHALCON_OBS_VAR(expr_left); + phalcon_array_fetch_quick_string(&expr_left, expr, SS("left"), 265976240UL, PH_NOISY); + + PHALCON_INIT_VAR(left); + phalcon_call_method_p2_key(left, this_ptr, "_getexpression", expr_left, temp_not_quoting, 2816780276UL); } -// 608 "scanner.c" -kk40: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '.': goto kk89; - default: goto kk41; - } -kk41: -// 503 "scanner.re" - { - token->opcode = PHVOLT_T_DOT; - return 0; + + if (phalcon_array_isset_quick_string(expr, SS("right"), 426864067UL)) { + PHALCON_OBS_VAR(expr_right); + phalcon_array_fetch_quick_string(&expr_right, expr, SS("right"), 426864067UL, PH_NOISY); + + PHALCON_INIT_VAR(right); + phalcon_call_method_p2_key(right, this_ptr, "_getexpression", expr_right, temp_not_quoting, 2816780276UL); + } + + PHALCON_OBS_VAR(expr_type); + phalcon_array_fetch_quick_string(&expr_type, expr, SS("type"), 276192743UL, PH_NOISY); + + switch (phalcon_get_intval(expr_type)) { + + case 60: + PHALCON_INIT_VAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("<"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 61: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("="), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 62: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL(">"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 270: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("<>"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 271: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("<="), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 272: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL(">="), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 266: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("AND"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 267: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("OR"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 355: + PHALCON_INIT_NVAR(expr_return); + phalcon_call_method_p1_key(expr_return, this_ptr, "_getqualified", expr, 3068781464UL); + break; + + case 359: + PHALCON_INIT_NVAR(expr_return); + phalcon_call_method_p1_key(expr_return, this_ptr, "_getaliased", expr, 2254100183UL); + break; + + case 43: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("+"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 45: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("-"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 42: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("*"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 47: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("/"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 37: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("%"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 38: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("&"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 124: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("|"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 356: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 2); + add_assoc_stringl_ex(expr_return, SS("type"), SL("parentheses"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + break; + + case 367: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 3); + add_assoc_stringl_ex(expr_return, SS("type"), SL("unary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("-"), 1); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 258: + PHALCON_OBS_VAR(expr_value); + phalcon_array_fetch_quick_string(&expr_value, expr, SS("value"), 574111618UL, PH_NOISY); + + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 2); + add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); + phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &expr_value, PH_COPY | PH_SEPARATE); + break; + + case 259: + PHALCON_OBS_NVAR(expr_value); + phalcon_array_fetch_quick_string(&expr_value, expr, SS("value"), 574111618UL, PH_NOISY); + + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 2); + add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); + phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &expr_value, PH_COPY | PH_SEPARATE); + break; + + case 333: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 2); + add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); + add_assoc_stringl_ex(expr_return, SS("value"), SL("TRUE"), 1); + break; + + case 334: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 2); + add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); + add_assoc_stringl_ex(expr_return, SS("value"), SL("FALSE"), 1); + break; + + case 260: + PHALCON_OBS_VAR(value); + phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); + if (PHALCON_IS_TRUE(quoting)) { + + if (phalcon_memnstr_str(value, SL("'"))) { + PHALCON_INIT_VAR(escaped_value); + phalcon_orm_singlequotes(escaped_value, value TSRMLS_CC); + } else { + PHALCON_CPY_WRT(escaped_value, value); + } + + PHALCON_INIT_NVAR(expr_value); + PHALCON_CONCAT_SVS(expr_value, "'", escaped_value, "'"); + } else { + PHALCON_CPY_WRT(expr_value, value); + } + + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 2); + add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); + phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &expr_value, PH_COPY | PH_SEPARATE); + break; + + case 273: + PHALCON_OBS_NVAR(value); + phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); + + PHALCON_INIT_VAR(question_mark); + ZVAL_STRING(question_mark, "?", 1); + + PHALCON_INIT_VAR(double_colon); + ZVAL_STRING(double_colon, ":", 1); + + PHALCON_INIT_VAR(placeholder); + phalcon_fast_str_replace(placeholder, question_mark, double_colon, value); + + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 2); + add_assoc_stringl_ex(expr_return, SS("type"), SL("placeholder"), 1); + phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &placeholder, PH_COPY | PH_SEPARATE); + break; + + case 274: + PHALCON_OBS_NVAR(value); + phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); + + PHALCON_INIT_NVAR(placeholder); + PHALCON_CONCAT_SV(placeholder, ":", value); + + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 2); + add_assoc_stringl_ex(expr_return, SS("type"), SL("placeholder"), 1); + phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &placeholder, PH_COPY | PH_SEPARATE); + break; + + case 322: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 2); + add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); + add_assoc_stringl_ex(expr_return, SS("value"), SL("NULL"), 1); + break; + + case 268: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("LIKE"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 351: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("NOT LIKE"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 275: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("ILIKE"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 357: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("NOT ILIKE"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 33: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 3); + add_assoc_stringl_ex(expr_return, SS("type"), SL("unary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("NOT "), 1); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 365: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 3); + add_assoc_stringl_ex(expr_return, SS("type"), SL("unary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL(" IS NULL"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + break; + + case 366: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 3); + add_assoc_stringl_ex(expr_return, SS("type"), SL("unary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL(" IS NOT NULL"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + break; + + case 315: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("IN"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 323: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("NOT IN"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 330: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 3); + add_assoc_stringl_ex(expr_return, SS("type"), SL("unary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("DISTINCT "), 1); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 331: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("BETWEEN"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 276: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 4); + add_assoc_stringl_ex(expr_return, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(expr_return, SS("op"), SL("AGAINST"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 332: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 3); + add_assoc_stringl_ex(expr_return, SS("type"), SL("cast"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 335: + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 3); + add_assoc_stringl_ex(expr_return, SS("type"), SL("convert"), 1); + phalcon_array_update_quick_string(&expr_return, SS("left"), 265976240UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&expr_return, SS("right"), 426864067UL, &right, PH_COPY | PH_SEPARATE); + break; + + case 358: + PHALCON_OBS_NVAR(value); + phalcon_array_fetch_quick_string(&value, expr, SS("name"), 268211462UL, PH_NOISY); + + PHALCON_INIT_NVAR(expr_return); + array_init_size(expr_return, 2); + add_assoc_stringl_ex(expr_return, SS("type"), SL("literal"), 1); + phalcon_array_update_quick_string(&expr_return, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); + break; + + case 350: + PHALCON_INIT_NVAR(expr_return); + phalcon_call_method_p1_key(expr_return, this_ptr, "_getfunctioncall", expr, 410399654UL); + break; + + default: + PHALCON_INIT_VAR(expression_message); + PHALCON_CONCAT_SV(expression_message, "Unknown expression type ", expr_type); + + PHALCON_INIT_VAR(expression); + object_init_ex(expression, phalcon_mvc_model_exception_ce); + phalcon_call_method_p1_key(NULL, expression, "__construct", expression_message, 1107214344UL); + + phalcon_throw_exception(expression TSRMLS_CC); + return; + } -// 621 "scanner.c" -kk42: - ++KKCURSOR; -// 508 "scanner.re" - { - token->opcode = PHVOLT_T_COMMA; - return 0; + + RETURN_CCTOR(expr_return); + } + + if (phalcon_array_isset_quick_string(expr, SS("domain"), 542597917UL)) { + phalcon_call_method_p1_key(return_value, this_ptr, "_getqualified", expr, 3068781464UL); + RETURN_MM(); + } + + if (phalcon_array_isset_long(expr, 0)) { + + PHALCON_INIT_VAR(list_items); + array_init(list_items); + + phalcon_is_iterable(expr, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(expr_list_item); + + PHALCON_INIT_NVAR(expr_item); + phalcon_call_method_p1_key(expr_item, this_ptr, "_getexpression", expr_list_item, 2816780276UL); + phalcon_array_append(&list_items, expr_item, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } -// 629 "scanner.c" -kk44: - ++KKCURSOR; -// 513 "scanner.re" - { - token->opcode = PHVOLT_T_PARENTHESES_OPEN; - return 0; + + array_init_size(return_value, 2); + add_assoc_stringl_ex(return_value, SS("type"), SL("list"), 1); + phalcon_array_append(&return_value, list_items, PH_SEPARATE); + + RETURN_MM(); + } + + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Unknown expression"); + return; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getSelectColumn){ + + zval *column, *sql_columns, *column_type, *models; + zval *source = NULL, *model_name = NULL, *sql_column = NULL, *sql_aliases; + zval *column_domain, *phql, *exception_message = NULL; + zval *sql_column_alias = NULL, *sql_aliases_models; + zval *sql_models_aliases, *best_alias, *prepared_alias = NULL; + zval *column_data, *sql_expr_column, *balias; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &column); + + if (!phalcon_array_isset_quick_string(column, SS("type"), 276192743UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); + return; + } + + PHALCON_INIT_VAR(sql_columns); + array_init(sql_columns); + + PHALCON_OBS_VAR(column_type); + phalcon_array_fetch_quick_string(&column_type, column, SS("type"), 276192743UL, PH_NOISY); + if (PHALCON_IS_LONG(column_type, 352)) { + + PHALCON_OBS_VAR(models); + phalcon_read_property_this_quick(&models, this_ptr, SL("_models"), 4175729768UL, PH_NOISY_CC); + + phalcon_is_iterable(models, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(model_name, ah0, hp0); + PHALCON_GET_HVALUE(source); + + PHALCON_INIT_NVAR(sql_column); + array_init_size(sql_column, 3); + add_assoc_stringl_ex(sql_column, SS("type"), SL("object"), 1); + phalcon_array_update_quick_string(&sql_column, SS("model"), 238191286UL, &model_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_column, SS("column"), 3545634419UL, &source, PH_COPY | PH_SEPARATE); + phalcon_array_append(&sql_columns, sql_column, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } -// 637 "scanner.c" -kk46: - ++KKCURSOR; -// 518 "scanner.re" - { - token->opcode = PHVOLT_T_PARENTHESES_CLOSE; - return 0; + + RETURN_CTOR(sql_columns); + } + + if (!phalcon_array_isset_quick_string(column, SS("column"), 3545634419UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); + return; + } + + if (PHALCON_IS_LONG(column_type, 353)) { + + PHALCON_OBS_VAR(sql_aliases); + phalcon_read_property_this_quick(&sql_aliases, this_ptr, SL("_sqlAliases"), 3407085878UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(column_domain); + phalcon_array_fetch_quick_string(&column_domain, column, SS("column"), 3545634419UL, PH_NOISY); + if (!phalcon_array_isset(sql_aliases, column_domain)) { + PHALCON_OBS_VAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "Unknown model or alias '", column_domain, "' (2), when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -// 645 "scanner.c" -kk48: - ++KKCURSOR; -// 523 "scanner.re" - { - token->opcode = PHVOLT_T_SBRACKET_OPEN; - return 0; + + PHALCON_OBS_VAR(source); + phalcon_array_fetch(&source, sql_aliases, column_domain, PH_NOISY); + PHALCON_CPY_WRT(sql_column_alias, source); + + PHALCON_OBS_VAR(sql_aliases_models); + phalcon_read_property_this_quick(&sql_aliases_models, this_ptr, SL("_sqlAliasesModels"), 848643194UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch(&model_name, sql_aliases_models, column_domain, PH_NOISY); + + PHALCON_OBS_VAR(sql_models_aliases); + phalcon_read_property_this_quick(&sql_models_aliases, this_ptr, SL("_sqlModelsAliases"), 1781491322UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(best_alias); + phalcon_array_fetch(&best_alias, sql_models_aliases, model_name, PH_NOISY); + + if (PHALCON_IS_EQUAL(best_alias, model_name)) { + PHALCON_INIT_VAR(prepared_alias); + phalcon_lcfirst(prepared_alias, model_name); + } else { + PHALCON_CPY_WRT(prepared_alias, best_alias); } -// 653 "scanner.c" -kk50: - ++KKCURSOR; -// 528 "scanner.re" - { - token->opcode = PHVOLT_T_SBRACKET_CLOSE; - return 0; + + PHALCON_INIT_NVAR(sql_column); + array_init_size(sql_column, 4); + add_assoc_stringl_ex(sql_column, SS("type"), SL("object"), 1); + phalcon_array_update_quick_string(&sql_column, SS("model"), 238191286UL, &model_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_column, SS("column"), 3545634419UL, &sql_column_alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_column, SS("balias"), 1705826801UL, &prepared_alias, PH_COPY | PH_SEPARATE); + phalcon_array_append(&sql_columns, sql_column, PH_SEPARATE); + + RETURN_CTOR(sql_columns); + } + + if (PHALCON_IS_LONG(column_type, 354)) { + + PHALCON_INIT_NVAR(sql_column); + array_init_size(sql_column, 1); + add_assoc_stringl_ex(sql_column, SS("type"), SL("scalar"), 1); + + PHALCON_OBS_VAR(column_data); + phalcon_array_fetch_quick_string(&column_data, column, SS("column"), 3545634419UL, PH_NOISY); + + PHALCON_INIT_VAR(sql_expr_column); + phalcon_call_method_p1_key(sql_expr_column, this_ptr, "_getexpression", column_data, 2816780276UL); + + if (phalcon_array_isset_quick_string(sql_expr_column, SS("balias"), 1705826801UL)) { + PHALCON_OBS_VAR(balias); + phalcon_array_fetch_quick_string(&balias, sql_expr_column, SS("balias"), 1705826801UL, PH_NOISY); + phalcon_array_update_quick_string(&sql_column, SS("balias"), 1705826801UL, &balias, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_column, SS("sqlAlias"), 2820722015UL, &balias, PH_COPY | PH_SEPARATE); } -// 661 "scanner.c" -kk52: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '=': goto kk87; - case '>': goto kk85; - default: goto kk53; - } -kk53: -// 608 "scanner.re" - { - token->opcode = PHVOLT_T_LESS; - return 0; + + phalcon_array_update_quick_string(&sql_column, SS("column"), 3545634419UL, &sql_expr_column, PH_COPY | PH_SEPARATE); + phalcon_array_append(&sql_columns, sql_column, PH_SEPARATE); + + RETURN_CTOR(sql_columns); + } + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Unknown type of column ", column_type); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getTable){ + + zval *manager, *qualified_name, *model_name; + zval *model, *source, *schema, *complete_source; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &manager, &qualified_name); + + if (phalcon_array_isset_quick_string(qualified_name, SS("name"), 268211462UL)) { + + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); + + PHALCON_INIT_VAR(model); + phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); + + PHALCON_INIT_VAR(schema); + phalcon_call_method_key(schema, model, "getschema", 1539736246UL); + if (zend_is_true(schema)) { + PHALCON_INIT_VAR(complete_source); + array_init_size(complete_source, 2); + phalcon_array_append(&complete_source, schema, PH_SEPARATE); + phalcon_array_append(&complete_source, source, PH_SEPARATE); + RETURN_CTOR(complete_source); } -// 675 "scanner.c" -kk54: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '=': goto kk81; - default: goto kk55; - } -kk55: -// 548 "scanner.re" - { - token->opcode = PHVOLT_T_ASSIGN; - return 0; + + RETURN_CCTOR(source); + } + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); + return; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getJoin){ + + zval *manager, *join, *qualified, *qualified_type; + zval *model_name, *model, *source, *schema, *data; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &manager, &join); + + if (phalcon_array_isset_quick_string(join, SS("qualified"), 907647673UL)) { + + PHALCON_OBS_VAR(qualified); + phalcon_array_fetch_quick_string(&qualified, join, SS("qualified"), 907647673UL, PH_NOISY); + + PHALCON_OBS_VAR(qualified_type); + phalcon_array_fetch_quick_string(&qualified_type, qualified, SS("type"), 276192743UL, PH_NOISY); + if (PHALCON_IS_LONG(qualified_type, 355)) { + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch_quick_string(&model_name, qualified, SS("name"), 268211462UL, PH_NOISY); + + PHALCON_INIT_VAR(model); + phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); + + PHALCON_INIT_VAR(schema); + phalcon_call_method_key(schema, model, "getschema", 1539736246UL); + + PHALCON_INIT_VAR(data); + array_init_size(data, 4); + phalcon_array_update_quick_string(&data, SS("schema"), 2259341622UL, &schema, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("source"), 2744839734UL, &source, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("modelName"), 440103543UL, &model_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("model"), 238191286UL, &model, PH_COPY | PH_SEPARATE); + RETURN_CTOR(data); } -// 688 "scanner.c" -kk56: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '=': goto kk79; - default: goto kk57; + } + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); + return; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getJoinType){ + + zval *join, *type, *join_type = NULL, *phql, *exception_message; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &join); + + if (!phalcon_array_isset_quick_string(join, SS("type"), 276192743UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); + return; + } + + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, join, SS("type"), 276192743UL, PH_NOISY); + + switch (phalcon_get_intval(type)) { + + case 360: + PHALCON_INIT_VAR(join_type); + ZVAL_STRING(join_type, "INNER", 1); + break; + + case 361: + PHALCON_INIT_NVAR(join_type); + ZVAL_STRING(join_type, "LEFT", 1); + break; + + case 362: + PHALCON_INIT_NVAR(join_type); + ZVAL_STRING(join_type, "RIGHT", 1); + break; + + case 363: + PHALCON_INIT_NVAR(join_type); + ZVAL_STRING(join_type, "CROSS", 1); + break; + + case 364: + PHALCON_INIT_NVAR(join_type); + ZVAL_STRING(join_type, "FULL OUTER", 1); + break; + + default: + PHALCON_OBS_VAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "Unknown join type ", type, ", when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + + } + + RETURN_CTOR(join_type); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getSingleJoin){ + + zval *join_type, *join_source, *model_alias; + zval *join_alias, *relation, *fields, *referenced_fields; + zval *left = NULL, *left_expr = NULL, *right = NULL, *right_expr = NULL, *sql_join_condition; + zval *sql_join_conditions, *sql_join_partial_conditions; + zval *field = NULL, *position = NULL, *phql = NULL, *exception_message = NULL; + zval *referenced_field = NULL, *sql_equals_join_condition = NULL; + zval *sql_joins; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 5, 0, &join_type, &join_source, &model_alias, &join_alias, &relation); + + PHALCON_INIT_VAR(fields); + phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); + + PHALCON_INIT_VAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); + if (Z_TYPE_P(fields) != IS_ARRAY) { + PHALCON_INIT_VAR(left); + array_init_size(left, 3); + add_assoc_long_ex(left, SS("type"), 355); + phalcon_array_update_quick_string(&left, SS("domain"), 542597917UL, &model_alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&left, SS("name"), 268211462UL, &fields, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(left_expr); + phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); + + PHALCON_INIT_VAR(right); + array_init_size(right, 3); + add_assoc_stringl_ex(right, SS("type"), SL("qualified"), 1); + phalcon_array_update_quick_string(&right, SS("domain"), 542597917UL, &join_alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&right, SS("name"), 268211462UL, &referenced_fields, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(right_expr); + phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); + + PHALCON_INIT_VAR(sql_join_condition); + array_init_size(sql_join_condition, 4); + add_assoc_stringl_ex(sql_join_condition, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(sql_join_condition, SS("op"), SL("="), 1); + phalcon_array_update_quick_string(&sql_join_condition, SS("left"), 265976240UL, &left_expr, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_join_condition, SS("right"), 426864067UL, &right_expr, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(sql_join_conditions); + array_init_size(sql_join_conditions, 1); + phalcon_array_append(&sql_join_conditions, sql_join_condition, PH_SEPARATE); + } else { + PHALCON_INIT_VAR(sql_join_partial_conditions); + array_init(sql_join_partial_conditions); + + phalcon_is_iterable(fields, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(position, ah0, hp0); + PHALCON_GET_HVALUE(field); + + if (!phalcon_array_isset(referenced_fields, position)) { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "The number of fields must be equal to the number of referenced fields in join ", model_alias, "-", join_alias); + PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -kk57: -// 613 "scanner.re" - { - token->opcode = PHVOLT_T_GREATER; - return 0; + + PHALCON_OBS_NVAR(referenced_field); + phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); + + PHALCON_INIT_NVAR(left); + array_init_size(left, 3); + add_assoc_long_ex(left, SS("type"), 355); + phalcon_array_update_quick_string(&left, SS("domain"), 542597917UL, &model_alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&left, SS("name"), 268211462UL, &field, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(left_expr); + phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); + + PHALCON_INIT_NVAR(right); + array_init_size(right, 3); + add_assoc_stringl_ex(right, SS("type"), SL("qualified"), 1); + phalcon_array_update_quick_string(&right, SS("domain"), 542597917UL, &join_alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&right, SS("name"), 268211462UL, &referenced_field, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(right_expr); + phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); + + PHALCON_INIT_NVAR(sql_equals_join_condition); + array_init_size(sql_equals_join_condition, 4); + add_assoc_stringl_ex(sql_equals_join_condition, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(sql_equals_join_condition, SS("op"), SL("="), 1); + phalcon_array_update_quick_string(&sql_equals_join_condition, SS("left"), 265976240UL, &left_expr, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_equals_join_condition, SS("right"), 426864067UL, &right_expr, PH_COPY | PH_SEPARATE); + phalcon_array_append(&sql_join_partial_conditions, sql_equals_join_condition, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } -// 701 "scanner.c" -kk58: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '=': goto kk75; - default: goto kk59; + + } + + PHALCON_INIT_VAR(sql_joins); + array_init_size(sql_joins, 3); + phalcon_array_update_quick_string(&sql_joins, SS("type"), 276192743UL, &join_type, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_joins, SS("source"), 2744839734UL, &join_source, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_joins, SS("conditions"), 1055696255UL, &sql_join_conditions, PH_COPY | PH_SEPARATE); + + RETURN_CTOR(sql_joins); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getMultiJoin){ + + zval *join_type, *join_source, *model_alias; + zval *join_alias, *relation, *sql_joins, *fields; + zval *referenced_fields, *intermediate_model_name; + zval *manager, *intermediate_model, *intermediate_source; + zval *intermediate_schema, *intermediate_full_source; + zval *intermediate_fields, *intermediate_referenced_fields; + zval *referenced_model_name, *field = NULL, *position = NULL; + zval *phql = NULL, *exception_message = NULL, *intermediate_field = NULL; + zval *left = NULL, *left_expr = NULL, *right = NULL, *right_expr = NULL, *sql_equals_join_condition = NULL; + zval *sql_join_condition_first, *sql_join_conditions_first; + zval *sql_join_first, *sql_join_condition_second; + zval *sql_join_conditions_second, *sql_join_second; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 5, 0, &join_type, &join_source, &model_alias, &join_alias, &relation); + + PHALCON_INIT_VAR(sql_joins); + array_init(sql_joins); + + PHALCON_INIT_VAR(fields); + phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); + + PHALCON_INIT_VAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); + + PHALCON_INIT_VAR(intermediate_model_name); + phalcon_call_method_key(intermediate_model_name, relation, "getintermediatemodel", 851527441UL); + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(intermediate_model); + phalcon_call_method_p1_key(intermediate_model, manager, "load", intermediate_model_name, 266329637UL); + + PHALCON_INIT_VAR(intermediate_source); + phalcon_call_method_key(intermediate_source, intermediate_model, "getsource", 2025234358UL); + + PHALCON_INIT_VAR(intermediate_schema); + phalcon_call_method_key(intermediate_schema, intermediate_model, "getschema", 1539736246UL); + + PHALCON_INIT_VAR(intermediate_full_source); + array_init_size(intermediate_full_source, 2); + phalcon_array_append(&intermediate_full_source, intermediate_schema, PH_SEPARATE); + phalcon_array_append(&intermediate_full_source, intermediate_source, PH_SEPARATE); + + phalcon_update_property_array(this_ptr, SL("_sqlAliases"), intermediate_model_name, intermediate_source TSRMLS_CC); + + phalcon_update_property_array(this_ptr, SL("_sqlAliasesModelsInstances"), intermediate_model_name, intermediate_model TSRMLS_CC); + + PHALCON_INIT_VAR(intermediate_fields); + phalcon_call_method_key(intermediate_fields, relation, "getintermediatefields", 1646880791UL); + + PHALCON_INIT_VAR(intermediate_referenced_fields); + phalcon_call_method_key(intermediate_referenced_fields, relation, "getintermediatereferencedfields", 3001626474UL); + + PHALCON_INIT_VAR(referenced_model_name); + phalcon_call_method_key(referenced_model_name, relation, "getreferencedmodel", 478093161UL); + if (Z_TYPE_P(fields) == IS_ARRAY) { + + phalcon_is_iterable(fields, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(position, ah0, hp0); + PHALCON_GET_HVALUE(field); + + if (!phalcon_array_isset(referenced_fields, position)) { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "The number of fields must be equal to the number of referenced fields in join ", model_alias, "-", join_alias); + PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -kk59: -// 603 "scanner.re" - { - token->opcode = PHVOLT_T_NOT; - return 0; - } -// 714 "scanner.c" -kk60: - ++KKCURSOR; -// 618 "scanner.re" - { - token->opcode = PHVOLT_T_PIPE; - return 0; - } -// 722 "scanner.c" -kk62: - ++KKCURSOR; -// 623 "scanner.re" - { - token->opcode = PHVOLT_T_COLON; - return 0; - } -// 730 "scanner.c" -kk64: - ++KKCURSOR; -// 628 "scanner.re" - { - token->opcode = PHVOLT_T_QUESTION; - return 0; - } -// 738 "scanner.c" -kk66: - ++KKCURSOR; - kkch = *KKCURSOR; - goto kk74; -kk67: -// 633 "scanner.re" - { - token->opcode = PHVOLT_T_IGNORE; - return 0; - } -// 749 "scanner.c" -kk68: - ++KKCURSOR; -// 638 "scanner.re" - { - s->active_line++; - token->opcode = PHVOLT_T_IGNORE; - return 0; - } -// 758 "scanner.c" -kk70: - ++KKCURSOR; -// 644 "scanner.re" - { - status = PHVOLT_SCANNER_RETCODE_EOF; - break; + + PHALCON_OBS_NVAR(intermediate_field); + phalcon_array_fetch(&intermediate_field, intermediate_fields, position, PH_NOISY); + + PHALCON_INIT_NVAR(left); + array_init_size(left, 3); + add_assoc_long_ex(left, SS("type"), 355); + phalcon_array_update_quick_string(&left, SS("domain"), 542597917UL, &model_alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&left, SS("name"), 268211462UL, &field, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(left_expr); + phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); + + PHALCON_INIT_NVAR(right); + array_init_size(right, 3); + add_assoc_stringl_ex(right, SS("type"), SL("qualified"), 1); + phalcon_array_update_quick_string(&right, SS("domain"), 542597917UL, &join_alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&right, SS("name"), 268211462UL, &referenced_fields, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(right_expr); + phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); + + PHALCON_INIT_NVAR(sql_equals_join_condition); + array_init_size(sql_equals_join_condition, 4); + add_assoc_stringl_ex(sql_equals_join_condition, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(sql_equals_join_condition, SS("op"), SL("="), 1); + phalcon_array_update_quick_string(&sql_equals_join_condition, SS("left"), 265976240UL, &left_expr, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_equals_join_condition, SS("right"), 426864067UL, &right_expr, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } -// 766 "scanner.c" -kk72: - kkch = *++KKCURSOR; - goto kk28; -kk73: - ++KKCURSOR; - kkch = *KKCURSOR; -kk74: - switch (kkch) { - case '\t': - case '\r': - case ' ': goto kk73; - default: goto kk67; + + } else { + PHALCON_INIT_NVAR(left); + array_init_size(left, 3); + add_assoc_long_ex(left, SS("type"), 355); + phalcon_array_update_quick_string(&left, SS("domain"), 542597917UL, &model_alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&left, SS("name"), 268211462UL, &fields, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(left_expr); + phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); + + PHALCON_INIT_NVAR(right); + array_init_size(right, 3); + add_assoc_stringl_ex(right, SS("type"), SL("qualified"), 1); + phalcon_array_update_quick_string(&right, SS("domain"), 542597917UL, &intermediate_model_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&right, SS("name"), 268211462UL, &intermediate_fields, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(right_expr); + phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); + + PHALCON_INIT_VAR(sql_join_condition_first); + array_init_size(sql_join_condition_first, 4); + add_assoc_stringl_ex(sql_join_condition_first, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(sql_join_condition_first, SS("op"), SL("="), 1); + phalcon_array_update_quick_string(&sql_join_condition_first, SS("left"), 265976240UL, &left_expr, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_join_condition_first, SS("right"), 426864067UL, &right_expr, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(sql_join_conditions_first); + array_init_size(sql_join_conditions_first, 1); + phalcon_array_append(&sql_join_conditions_first, sql_join_condition_first, PH_SEPARATE); + + PHALCON_INIT_VAR(sql_join_first); + array_init_size(sql_join_first, 3); + phalcon_array_update_quick_string(&sql_join_first, SS("type"), 276192743UL, &join_type, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_join_first, SS("source"), 2744839734UL, &intermediate_source, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_join_first, SS("conditions"), 1055696255UL, &sql_join_conditions_first, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(left); + array_init_size(left, 3); + add_assoc_long_ex(left, SS("type"), 355); + phalcon_array_update_quick_string(&left, SS("domain"), 542597917UL, &intermediate_model_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&left, SS("name"), 268211462UL, &intermediate_referenced_fields, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(left_expr); + phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); + + PHALCON_INIT_NVAR(right); + array_init_size(right, 3); + add_assoc_stringl_ex(right, SS("type"), SL("qualified"), 1); + phalcon_array_update_quick_string(&right, SS("domain"), 542597917UL, &referenced_model_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&right, SS("name"), 268211462UL, &referenced_fields, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(right_expr); + phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); + + PHALCON_INIT_VAR(sql_join_condition_second); + array_init_size(sql_join_condition_second, 4); + add_assoc_stringl_ex(sql_join_condition_second, SS("type"), SL("binary-op"), 1); + add_assoc_stringl_ex(sql_join_condition_second, SS("op"), SL("="), 1); + phalcon_array_update_quick_string(&sql_join_condition_second, SS("left"), 265976240UL, &left_expr, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_join_condition_second, SS("right"), 426864067UL, &right_expr, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(sql_join_conditions_second); + array_init_size(sql_join_conditions_second, 1); + phalcon_array_append(&sql_join_conditions_second, sql_join_condition_second, PH_SEPARATE); + + PHALCON_INIT_VAR(sql_join_second); + array_init_size(sql_join_second, 3); + phalcon_array_update_quick_string(&sql_join_second, SS("type"), 276192743UL, &join_type, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_join_second, SS("source"), 2744839734UL, &join_source, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_join_second, SS("conditions"), 1055696255UL, &sql_join_conditions_second, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&sql_joins, 0, &sql_join_first, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&sql_joins, 1, &sql_join_second, PH_COPY | PH_SEPARATE); + } + + RETURN_CTOR(sql_joins); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getJoins){ + + zval *select, *models, *sql_aliases, *sql_aliases_models; + zval *sql_models_aliases, *sql_aliases_models_instances; + zval *models_instances, *from_models = NULL, *sql_joins = NULL; + zval *join_models, *join_sources, *join_types; + zval *join_pre_condition, *join_prepared; + zval *manager = NULL, *joins, *select_joins = NULL, *join_item = NULL; + zval *join_data = NULL, *source = NULL, *schema = NULL, *model = NULL, *model_name = NULL; + zval *complete_source = NULL, *join_type = NULL, *alias_expr = NULL; + zval *alias = NULL, *phql = NULL, *exception_message = NULL, *join_alias_name = NULL; + zval *join_expr = NULL, *pre_condition = NULL, *from_model_name = NULL; + zval *join_model = NULL, *join_alias = NULL, *join_source = NULL; + zval *model_name_alias = NULL, *relation = NULL, *relations = NULL; + zval *number_relations = NULL, *model_alias = NULL, *is_through = NULL; + zval *sql_join = NULL, *new_sql_joins = NULL, *sql_join_conditions = NULL; + HashTable *ah0, *ah1, *ah2, *ah3; + HashPosition hp0, hp1, hp2, hp3; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &select); + + PHALCON_OBS_VAR(models); + phalcon_read_property_this_quick(&models, this_ptr, SL("_models"), 4175729768UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(sql_aliases); + phalcon_read_property_this_quick(&sql_aliases, this_ptr, SL("_sqlAliases"), 3407085878UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(sql_aliases_models); + phalcon_read_property_this_quick(&sql_aliases_models, this_ptr, SL("_sqlAliasesModels"), 848643194UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(sql_models_aliases); + phalcon_read_property_this_quick(&sql_models_aliases, this_ptr, SL("_sqlModelsAliases"), 1781491322UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(sql_aliases_models_instances); + phalcon_read_property_this_quick(&sql_aliases_models_instances, this_ptr, SL("_sqlAliasesModelsInstances"), 3347052930UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(models_instances); + phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); + PHALCON_CPY_WRT(from_models, models); + + PHALCON_INIT_VAR(sql_joins); + array_init(sql_joins); + + PHALCON_INIT_VAR(join_models); + array_init(join_models); + + PHALCON_INIT_VAR(join_sources); + array_init(join_sources); + + PHALCON_INIT_VAR(join_types); + array_init(join_types); + + PHALCON_INIT_VAR(join_pre_condition); + array_init(join_pre_condition); + + PHALCON_INIT_VAR(join_prepared); + array_init(join_prepared); + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(joins); + phalcon_array_fetch_quick_string(&joins, select, SS("joins"), 120974824UL, PH_NOISY); + if (!phalcon_array_isset_long(joins, 0)) { + PHALCON_INIT_VAR(select_joins); + array_init_size(select_joins, 1); + phalcon_array_append(&select_joins, joins, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(select_joins, joins); + } + + phalcon_is_iterable(select_joins, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(join_item); + + PHALCON_INIT_NVAR(join_data); + phalcon_call_method_p2_key(join_data, this_ptr, "_getjoin", manager, join_item, 2949927412UL); + + PHALCON_OBS_NVAR(source); + phalcon_array_fetch_quick_string(&source, join_data, SS("source"), 2744839734UL, PH_NOISY); + + PHALCON_OBS_NVAR(schema); + phalcon_array_fetch_quick_string(&schema, join_data, SS("schema"), 2259341622UL, PH_NOISY); + + PHALCON_OBS_NVAR(model); + phalcon_array_fetch_quick_string(&model, join_data, SS("model"), 238191286UL, PH_NOISY); + + PHALCON_OBS_NVAR(model_name); + phalcon_array_fetch_quick_string(&model_name, join_data, SS("modelName"), 440103543UL, PH_NOISY); + + PHALCON_INIT_NVAR(complete_source); + array_init_size(complete_source, 2); + phalcon_array_append(&complete_source, source, PH_SEPARATE); + phalcon_array_append(&complete_source, schema, PH_SEPARATE); + + PHALCON_INIT_NVAR(join_type); + phalcon_call_method_p1_key(join_type, this_ptr, "_getjointype", join_item, 1296796086UL); + + if (phalcon_array_isset_quick_string(join_item, SS("alias"), 4060151663UL)) { + + PHALCON_OBS_NVAR(alias_expr); + phalcon_array_fetch_quick_string(&alias_expr, join_item, SS("alias"), 4060151663UL, PH_NOISY); + + PHALCON_OBS_NVAR(alias); + phalcon_array_fetch_quick_string(&alias, alias_expr, SS("name"), 268211462UL, PH_NOISY); + + if (phalcon_array_isset(join_models, alias)) { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Cannot use '", alias, "' as join alias because it was already used"); + PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -kk75: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '=': goto kk77; - default: goto kk76; + + phalcon_array_append(&complete_source, alias, PH_SEPARATE); + + phalcon_array_update_zval(&join_types, alias, &join_type, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&sql_aliases, alias, &alias, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&join_models, alias, &model_name, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&sql_models_aliases, model_name, &alias, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&sql_aliases_models, alias, &model_name, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&sql_aliases_models_instances, alias, &model, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&models, model_name, &alias, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&join_sources, alias, &complete_source, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&join_prepared, alias, &join_item, PH_COPY | PH_SEPARATE); + } else { + if (phalcon_array_isset(join_models, model_name)) { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Cannot use '", model_name, "' as join alias because it was already used"); + PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -kk76: -// 583 "scanner.re" - { - token->opcode = PHVOLT_T_NOTEQUALS; - return 0; - } -// 792 "scanner.c" -kk77: - ++KKCURSOR; -// 598 "scanner.re" - { - token->opcode = PHVOLT_T_NOTIDENTICAL; - return 0; + + phalcon_array_update_zval(&join_types, model_name, &join_type, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&sql_aliases, model_name, &source, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&join_models, model_name, &source, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&sql_models_aliases, model_name, &model_name, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&sql_aliases_models, model_name, &model_name, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&sql_aliases_models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&models, model_name, &source, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&join_sources, model_name, &complete_source, PH_COPY | PH_SEPARATE); + + phalcon_array_update_zval(&join_prepared, model_name, &join_item, PH_COPY | PH_SEPARATE); } -// 800 "scanner.c" -kk79: - ++KKCURSOR; -// 573 "scanner.re" - { - token->opcode = PHVOLT_T_GREATEREQUAL; - return 0; + + phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_update_property_this_quick(this_ptr, SL("_models"), models, 4175729768UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlAliases"), sql_aliases, 3407085878UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModels"), sql_aliases_models, 848643194UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlModelsAliases"), sql_models_aliases, 1781491322UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModelsInstances"), sql_aliases_models_instances, 3347052930UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_modelsInstances"), models_instances, 457905456UL TSRMLS_CC); + + phalcon_is_iterable(join_prepared, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HKEY(join_alias_name, ah1, hp1); + PHALCON_GET_HVALUE(join_item); + + if (phalcon_array_isset_quick_string(join_item, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_NVAR(join_expr); + phalcon_array_fetch_quick_string(&join_expr, join_item, SS("conditions"), 1055696255UL, PH_NOISY); + + PHALCON_INIT_NVAR(pre_condition); + phalcon_call_method_p1_key(pre_condition, this_ptr, "_getexpression", join_expr, 2816780276UL); + phalcon_array_update_zval(&join_pre_condition, join_alias_name, &pre_condition, PH_COPY | PH_SEPARATE); } -// 808 "scanner.c" -kk81: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '=': goto kk83; - default: goto kk82; + + zend_hash_move_forward_ex(ah1, &hp1); + } + + PHALCON_OBS_NVAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + phalcon_is_iterable(from_models, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HKEY(from_model_name, ah2, hp2); + PHALCON_GET_HVALUE(source); + + phalcon_is_iterable(join_models, &ah3, &hp3, 0, 0); + + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { + + PHALCON_GET_HKEY(join_alias, ah3, hp3); + PHALCON_GET_HVALUE(join_model); + + PHALCON_OBS_NVAR(join_source); + phalcon_array_fetch(&join_source, join_sources, join_alias, PH_NOISY); + + PHALCON_OBS_NVAR(join_type); + phalcon_array_fetch(&join_type, join_types, join_alias, PH_NOISY); + + if (!phalcon_array_isset(join_pre_condition, join_alias)) { + + PHALCON_OBS_NVAR(model_name_alias); + phalcon_array_fetch(&model_name_alias, sql_aliases_models, join_alias, PH_NOISY); + + PHALCON_INIT_NVAR(relation); + phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", from_model_name, model_name_alias, 785467656UL); + if (PHALCON_IS_FALSE(relation)) { + + PHALCON_INIT_NVAR(relations); + phalcon_call_method_p2_key(relations, manager, "getrelationsbetween", from_model_name, model_name_alias, 3538247200UL); + if (Z_TYPE_P(relations) == IS_ARRAY) { + + PHALCON_INIT_NVAR(number_relations); + phalcon_fast_count(number_relations, relations TSRMLS_CC); + if (!PHALCON_IS_LONG(number_relations, 1)) { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVS(exception_message, "There is more than one relation between models '", model_name, "' and '", join_model, "\", the join must be done using an alias"); + PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_NVAR(relation); + phalcon_array_fetch_long(&relation, relations, 0, PH_NOISY); + } + } + + if (Z_TYPE_P(relation) == IS_OBJECT) { + + PHALCON_OBS_NVAR(model_alias); + phalcon_array_fetch(&model_alias, sql_models_aliases, from_model_name, PH_NOISY); + + PHALCON_INIT_NVAR(is_through); + phalcon_call_method_key(is_through, relation, "isthrough", 2540564770UL); + if (!zend_is_true(is_through)) { + PHALCON_INIT_NVAR(sql_join); + phalcon_call_method_p5(sql_join, this_ptr, "_getsinglejoin", join_type, join_source, model_alias, join_alias, relation); + } else { + PHALCON_INIT_NVAR(sql_join); + phalcon_call_method_p5(sql_join, this_ptr, "_getmultijoin", join_type, join_source, model_alias, join_alias, relation); + } + + if (phalcon_array_isset_long(sql_join, 0)) { + PHALCON_INIT_NVAR(new_sql_joins); + phalcon_fast_array_merge(new_sql_joins, &sql_joins, &sql_join TSRMLS_CC); + PHALCON_CPY_WRT(sql_joins, new_sql_joins); + } else { + phalcon_array_append(&sql_joins, sql_join, PH_SEPARATE); + } + } else { + PHALCON_INIT_NVAR(sql_join_conditions); + array_init(sql_join_conditions); + + PHALCON_INIT_NVAR(sql_join); + array_init_size(sql_join, 3); + phalcon_array_update_quick_string(&sql_join, SS("type"), 276192743UL, &join_type, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_join, SS("source"), 2744839734UL, &join_source, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_join, SS("conditions"), 1055696255UL, &sql_join_conditions, PH_COPY | PH_SEPARATE); + phalcon_array_append(&sql_joins, sql_join, PH_SEPARATE); + } + } else { + PHALCON_OBS_NVAR(pre_condition); + phalcon_array_fetch(&pre_condition, join_pre_condition, join_alias, PH_NOISY); + + PHALCON_INIT_NVAR(sql_join_conditions); + array_init_size(sql_join_conditions, 1); + phalcon_array_append(&sql_join_conditions, pre_condition, PH_SEPARATE); + + PHALCON_INIT_NVAR(sql_join); + array_init_size(sql_join, 3); + phalcon_array_update_quick_string(&sql_join, SS("type"), 276192743UL, &join_type, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_join, SS("source"), 2744839734UL, &join_source, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_join, SS("conditions"), 1055696255UL, &sql_join_conditions, PH_COPY | PH_SEPARATE); + phalcon_array_append(&sql_joins, sql_join, PH_SEPARATE); } -kk82: -// 578 "scanner.re" - { - token->opcode = PHVOLT_T_EQUALS; - return 0; - } -// 821 "scanner.c" -kk83: - ++KKCURSOR; -// 593 "scanner.re" - { - token->opcode = PHVOLT_T_IDENTICAL; - return 0; - } -// 829 "scanner.c" -kk85: - ++KKCURSOR; -// 588 "scanner.re" - { - token->opcode = PHVOLT_T_NOTEQUALS; - return 0; - } -// 837 "scanner.c" -kk87: - ++KKCURSOR; -// 543 "scanner.re" - { - token->opcode = PHVOLT_T_LESSEQUAL; - return 0; - } -// 845 "scanner.c" -kk89: - ++KKCURSOR; -// 498 "scanner.re" - { - token->opcode = PHVOLT_T_RANGE; - return 0; - } -// 853 "scanner.c" -kk91: - ++KKCURSOR; -// 568 "scanner.re" - { - token->opcode = PHVOLT_T_DIV_ASSIGN; - return 0; - } -// 861 "scanner.c" -kk93: - ++KKCURSOR; -// 563 "scanner.re" - { - token->opcode = PHVOLT_T_MUL_ASSIGN; - return 0; - } -// 869 "scanner.c" -kk95: - ++KKCURSOR; -// 553 "scanner.re" - { - token->opcode = PHVOLT_T_ADD_ASSIGN; - return 0; - } -// 877 "scanner.c" -kk97: - ++KKCURSOR; -// 483 "scanner.re" - { - token->opcode = PHVOLT_T_INCR; - return 0; + + zend_hash_move_forward_ex(ah3, &hp3); } -// 885 "scanner.c" -kk99: - ++KKCURSOR; - kkch = *KKCURSOR; -kk100: - switch (kkch) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk5; - } -kk101: - ++KKCURSOR; - kkch = *KKCURSOR; -kk102: - switch (kkch) { - case 0x00: goto kk103; - case '\'': goto kk105; - case '\\': goto kk104; - default: goto kk101; - } -kk103: - KKCURSOR = KKMARKER; - switch (kkaccept) { - case 0: goto kk3; - case 1: goto kk24; - case 2: goto kk28; - } -kk104: - ++KKCURSOR; - kkch = *KKCURSOR; - switch (kkch) { - case '\n': goto kk103; - default: goto kk101; + + zend_hash_move_forward_ex(ah2, &hp2); + } + + RETURN_CCTOR(sql_joins); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getOrderClause){ + + zval *order, *order_columns = NULL, *order_parts, *order_item = NULL; + zval *order_column = NULL, *order_part_expr = NULL, *order_sort = NULL; + zval *order_part_sort = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &order); + + if (!phalcon_array_isset_long(order, 0)) { + PHALCON_INIT_VAR(order_columns); + array_init_size(order_columns, 1); + phalcon_array_append(&order_columns, order, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(order_columns, order); + } + + PHALCON_INIT_VAR(order_parts); + array_init(order_parts); + + phalcon_is_iterable(order_columns, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(order_item); + + PHALCON_OBS_NVAR(order_column); + phalcon_array_fetch_quick_string(&order_column, order_item, SS("column"), 3545634419UL, PH_NOISY); + + PHALCON_INIT_NVAR(order_part_expr); + phalcon_call_method_p1_key(order_part_expr, this_ptr, "_getexpression", order_column, 2816780276UL); + + if (phalcon_array_isset_quick_string(order_item, SS("sort"), 274650125UL)) { + + PHALCON_OBS_NVAR(order_sort); + phalcon_array_fetch_quick_string(&order_sort, order_item, SS("sort"), 274650125UL, PH_NOISY); + if (PHALCON_IS_LONG(order_sort, 327)) { + PHALCON_INIT_NVAR(order_part_sort); + array_init_size(order_part_sort, 2); + phalcon_array_append(&order_part_sort, order_part_expr, PH_SEPARATE); + add_next_index_stringl(order_part_sort, SL("ASC"), 1); + } else { + PHALCON_INIT_NVAR(order_part_sort); + array_init_size(order_part_sort, 2); + phalcon_array_append(&order_part_sort, order_part_expr, PH_SEPARATE); + add_next_index_stringl(order_part_sort, SL("DESC"), 1); } -kk105: - ++KKCURSOR; -// 441 "scanner.re" - { - token->opcode = PHVOLT_T_STRING; - token->value = estrndup(q, KKCURSOR - q - 1); - token->len = KKCURSOR - q - 1; - q = KKCURSOR; - return 0; + } else { + PHALCON_INIT_NVAR(order_part_sort); + array_init_size(order_part_sort, 1); + phalcon_array_append(&order_part_sort, order_part_expr, PH_SEPARATE); } -// 991 "scanner.c" -kk107: - ++KKCURSOR; - kkch = *KKCURSOR; -kk108: - switch (kkch) { - case 0x00: goto kk103; - case '"': goto kk105; - case '\\': goto kk109; - default: goto kk107; - } -kk109: - ++KKCURSOR; - kkch = *KKCURSOR; - switch (kkch) { - case '\n': goto kk103; - default: goto kk107; - } -kk110: - ++KKCURSOR; -// 420 "scanner.re" - { - s->mode = PHVOLT_MODE_RAW; - token->opcode = PHVOLT_T_CLOSE_EDELIMITER; - return 0; + + phalcon_array_append(&order_parts, order_part_sort, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_CTOR(order_parts); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getGroupClause){ + + zval *group, *group_parts = NULL, *group_item = NULL, *group_part_expr = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &group); + + if (phalcon_array_isset_long(group, 0)) { + + PHALCON_INIT_VAR(group_parts); + array_init(group_parts); + + phalcon_is_iterable(group, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(group_item); + + PHALCON_INIT_NVAR(group_part_expr); + phalcon_call_method_p1_key(group_part_expr, this_ptr, "_getexpression", group_item, 2816780276UL); + phalcon_array_append(&group_parts, group_part_expr, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } -// 1017 "scanner.c" -kk112: - ++KKCURSOR; -// 558 "scanner.re" - { - token->opcode = PHVOLT_T_SUB_ASSIGN; - return 0; + + } else { + PHALCON_INIT_NVAR(group_part_expr); + phalcon_call_method_p1_key(group_part_expr, this_ptr, "_getexpression", group, 2816780276UL); + + PHALCON_INIT_NVAR(group_parts); + array_init_size(group_parts, 1); + phalcon_array_append(&group_parts, group_part_expr, PH_SEPARATE); + } + + RETURN_CTOR(group_parts); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareSelect){ + + zval *ast, *select, *sql_models, *sql_tables, *sql_aliases; + zval *sql_columns, *sql_aliases_models, *sql_models_aliases; + zval *sql_aliases_models_instances, *models; + zval *models_instances, *tables, *selected_models = NULL; + zval *manager, *meta_data, *selected_model = NULL, *qualified_name = NULL; + zval *model_name = NULL, *ns_alias = NULL, *real_namespace = NULL; + zval *real_model_name = NULL, *model = NULL, *schema = NULL, *source = NULL; + zval *complete_source = NULL, *alias = NULL, *phql = NULL, *exception_message = NULL; + zval *joins, *sql_joins = NULL, *columns, *select_columns = NULL; + zval *position, *sql_column_aliases, *column = NULL; + zval *sql_column_group = NULL, *sql_column = NULL, *type = NULL, *sql_select; + zval *where, *where_expr, *group_by, *sql_group; + zval *having, *having_expr, *order, *sql_order; + zval *limit; + HashTable *ah0, *ah1, *ah2; + HashPosition hp0, hp1, hp2; + zval **hd; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(ast); + phalcon_read_property_this_quick(&ast, this_ptr, SL("_ast"), 250429676UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(select); + phalcon_array_fetch_quick_string(&select, ast, SS("select"), 2342345829UL, PH_NOISY); + if (!phalcon_array_isset_quick_string(select, SS("tables"), 3465666720UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); + return; + } + + if (!phalcon_array_isset_quick_string(select, SS("columns"), 1041822630UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); + return; + } + + PHALCON_INIT_VAR(sql_models); + array_init(sql_models); + + PHALCON_INIT_VAR(sql_tables); + array_init(sql_tables); + + PHALCON_INIT_VAR(sql_aliases); + array_init(sql_aliases); + + PHALCON_INIT_VAR(sql_columns); + array_init(sql_columns); + + PHALCON_INIT_VAR(sql_aliases_models); + array_init(sql_aliases_models); + + PHALCON_INIT_VAR(sql_models_aliases); + array_init(sql_models_aliases); + + PHALCON_INIT_VAR(sql_aliases_models_instances); + array_init(sql_aliases_models_instances); + + PHALCON_INIT_VAR(models); + array_init(models); + + PHALCON_INIT_VAR(models_instances); + array_init(models_instances); + + PHALCON_OBS_VAR(tables); + phalcon_array_fetch_quick_string(&tables, select, SS("tables"), 3465666720UL, PH_NOISY); + if (!phalcon_array_isset_long(tables, 0)) { + PHALCON_INIT_VAR(selected_models); + array_init_size(selected_models, 1); + phalcon_array_append(&selected_models, tables, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(selected_models, tables); + } + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(meta_data); + phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); + + phalcon_is_iterable(selected_models, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(selected_model); + + PHALCON_OBS_NVAR(qualified_name); + phalcon_array_fetch_quick_string(&qualified_name, selected_model, SS("qualifiedName"), 2418332666UL, PH_NOISY); + + PHALCON_OBS_NVAR(model_name); + phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); + + if (phalcon_array_isset_quick_string(qualified_name, SS("ns-alias"), 2470863549UL)) { + PHALCON_OBS_NVAR(ns_alias); + phalcon_array_fetch_quick_string(&ns_alias, qualified_name, SS("ns-alias"), 2470863549UL, PH_NOISY); + + PHALCON_INIT_NVAR(real_namespace); + phalcon_call_method_p1_key(real_namespace, manager, "getnamespacealias", ns_alias, 3487123420UL); + + PHALCON_INIT_NVAR(real_model_name); + PHALCON_CONCAT_VSV(real_model_name, real_namespace, "\\", model_name); + } else { + PHALCON_CPY_WRT(real_model_name, model_name); } -// 1025 "scanner.c" -kk114: - ++KKCURSOR; -// 488 "scanner.re" - { - token->opcode = PHVOLT_T_DECR; - return 0; + + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", real_model_name, 266329637UL); + + PHALCON_INIT_NVAR(schema); + phalcon_call_method_key(schema, model, "getschema", 1539736246UL); + + PHALCON_INIT_NVAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); + + if (zend_is_true(schema)) { + PHALCON_INIT_NVAR(complete_source); + array_init_size(complete_source, 2); + phalcon_array_append(&complete_source, source, PH_SEPARATE); + phalcon_array_append(&complete_source, schema, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(complete_source, source); } -// 1033 "scanner.c" -kk116: - kkch = *++KKCURSOR; - switch (kkch) { - case '}': goto kk120; - default: goto kk103; + + if (phalcon_array_isset_quick_string(selected_model, SS("alias"), 4060151663UL)) { + + PHALCON_OBS_NVAR(alias); + phalcon_array_fetch_quick_string(&alias, selected_model, SS("alias"), 4060151663UL, PH_NOISY); + + if (phalcon_array_isset(sql_aliases, alias)) { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Alias \"", alias, " is already used"); + PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -kk117: - kkch = *++KKCURSOR; - switch (kkch) { - case '}': goto kk118; - default: goto kk103; + + phalcon_array_update_zval(&sql_aliases, alias, &alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&sql_aliases_models, alias, &model_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&sql_models_aliases, model_name, &alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&sql_aliases_models_instances, alias, &model, PH_COPY | PH_SEPARATE); + + if (Z_TYPE_P(complete_source) == IS_ARRAY) { + phalcon_array_append(&complete_source, alias, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(complete_source); + array_init_size(complete_source, 3); + phalcon_array_append(&complete_source, source, PH_SEPARATE); + add_next_index_null(complete_source); + phalcon_array_append(&complete_source, alias, PH_SEPARATE); } -kk118: - ++KKCURSOR; -// 406 "scanner.re" - { - s->mode = PHVOLT_MODE_RAW; - s->whitespace_control = 1; - token->opcode = PHVOLT_T_CLOSE_DELIMITER; - return 0; - } -// 1055 "scanner.c" -kk120: - ++KKCURSOR; -// 433 "scanner.re" - { - s->mode = PHVOLT_MODE_RAW; - s->whitespace_control = 1; - token->opcode = PHVOLT_T_CLOSE_EDELIMITER; - return 0; + + phalcon_array_update_zval(&models, model_name, &alias, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_zval(&sql_aliases, model_name, &source, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&sql_aliases_models, model_name, &model_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&sql_models_aliases, model_name, &model_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&sql_aliases_models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&models, model_name, &source, PH_COPY | PH_SEPARATE); } -// 1065 "scanner.c" -kk122: - ++KKCURSOR; -// 394 "scanner.re" - { - s->mode = PHVOLT_MODE_RAW; - token->opcode = PHVOLT_T_CLOSE_DELIMITER; - return 0; + + phalcon_array_append(&sql_models, model_name, PH_SEPARATE); + phalcon_array_append(&sql_tables, complete_source, PH_SEPARATE); + phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_update_property_this_quick(this_ptr, SL("_models"), models, 4175729768UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_modelsInstances"), models_instances, 457905456UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlAliases"), sql_aliases, 3407085878UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModels"), sql_aliases_models, 848643194UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlModelsAliases"), sql_models_aliases, 1781491322UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModelsInstances"), sql_aliases_models_instances, 3347052930UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_modelsInstances"), models_instances, 457905456UL TSRMLS_CC); + + if (phalcon_array_isset_quick_string(select, SS("joins"), 120974824UL)) { + + PHALCON_OBS_VAR(joins); + phalcon_array_fetch_quick_string(&joins, select, SS("joins"), 120974824UL, PH_NOISY); + if (phalcon_fast_count_ev(joins TSRMLS_CC)) { + PHALCON_INIT_VAR(sql_joins); + phalcon_call_method_p1_key(sql_joins, this_ptr, "_getjoins", select, 2858327879UL); + } else { + PHALCON_INIT_NVAR(sql_joins); + array_init(sql_joins); } -// 1074 "scanner.c" -kk124: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '-': goto kk130; - default: goto kk125; + } else { + PHALCON_INIT_NVAR(sql_joins); + array_init(sql_joins); + } + + PHALCON_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, select, SS("columns"), 1041822630UL, PH_NOISY); + if (!phalcon_array_isset_long(columns, 0)) { + PHALCON_INIT_VAR(select_columns); + array_init_size(select_columns, 1); + phalcon_array_append(&select_columns, columns, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(select_columns, columns); + } + + PHALCON_INIT_VAR(position); + ZVAL_LONG(position, 0); + + PHALCON_INIT_VAR(sql_column_aliases); + array_init(sql_column_aliases); + + phalcon_is_iterable(select_columns, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(column); + + PHALCON_INIT_NVAR(sql_column_group); + phalcon_call_method_p1_key(sql_column_group, this_ptr, "_getselectcolumn", column, 3762838962UL); + + phalcon_is_iterable(sql_column_group, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HVALUE(sql_column); + + if (phalcon_array_isset_quick_string(column, SS("alias"), 4060151663UL)) { + PHALCON_OBS_NVAR(alias); + phalcon_array_fetch_quick_string(&alias, column, SS("alias"), 4060151663UL, PH_NOISY); + + phalcon_array_update_quick_string(&sql_column, SS("balias"), 1705826801UL, &alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_column, SS("sqlAlias"), 2820722015UL, &alias, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&sql_columns, alias, &sql_column, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval_bool(&sql_column_aliases, alias, 1, PH_SEPARATE); + } else { + if (phalcon_array_isset_quick_string(sql_column, SS("balias"), 1705826801UL)) { + PHALCON_OBS_NVAR(alias); + phalcon_array_fetch_quick_string(&alias, sql_column, SS("balias"), 1705826801UL, PH_NOISY); + phalcon_array_update_zval(&sql_columns, alias, &sql_column, PH_COPY | PH_SEPARATE); + } else { + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, sql_column, SS("type"), 276192743UL, PH_NOISY); + if (PHALCON_IS_STRING(type, "scalar")) { + PHALCON_INIT_NVAR(alias); + PHALCON_CONCAT_SV(alias, "_", position); + phalcon_array_update_zval(&sql_columns, alias, &sql_column, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_append(&sql_columns, sql_column, PH_SEPARATE); + } + } } -kk125: -// 413 "scanner.re" - { - s->whitespace_control = 0; - s->statement_position++; - token->opcode = PHVOLT_T_OPEN_EDELIMITER; - return 0; + PHALCON_SEPARATE(position); + phalcon_increment(position); + + zend_hash_move_forward_ex(ah2, &hp2); } -// 1089 "scanner.c" -kk126: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '-': goto kk128; - default: goto kk127; + + zend_hash_move_forward_ex(ah1, &hp1); + } + + phalcon_update_property_this_quick(this_ptr, SL("_sqlColumnAliases"), sql_column_aliases, 3031417188UL TSRMLS_CC); + + PHALCON_INIT_VAR(sql_select); + array_init_size(sql_select, 3); + phalcon_array_update_quick_string(&sql_select, SS("models"), 3565348937UL, &sql_models, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_select, SS("tables"), 3465666720UL, &sql_tables, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_select, SS("columns"), 1041822630UL, &sql_columns, PH_COPY | PH_SEPARATE); + if (phalcon_fast_count_ev(sql_joins TSRMLS_CC)) { + phalcon_array_update_quick_string(&sql_select, SS("joins"), 120974824UL, &sql_joins, PH_COPY | PH_SEPARATE); + } + + if (phalcon_array_isset_quick_string(ast, SS("where"), 621293632UL)) { + PHALCON_OBS_VAR(where); + phalcon_array_fetch_quick_string(&where, ast, SS("where"), 621293632UL, PH_NOISY); + + PHALCON_INIT_VAR(where_expr); + phalcon_call_method_p1_key(where_expr, this_ptr, "_getexpression", where, 2816780276UL); + phalcon_array_update_quick_string(&sql_select, SS("where"), 621293632UL, &where_expr, PH_COPY | PH_SEPARATE); + } + + if (phalcon_array_isset_quick_string(ast, SS("groupBy"), 3708772877UL)) { + PHALCON_OBS_VAR(group_by); + phalcon_array_fetch_quick_string(&group_by, ast, SS("groupBy"), 3708772877UL, PH_NOISY); + + PHALCON_INIT_VAR(sql_group); + phalcon_call_method_p1_key(sql_group, this_ptr, "_getgroupclause", group_by, 2246953294UL); + phalcon_array_update_quick_string(&sql_select, SS("group"), 7349554UL, &sql_group, PH_COPY | PH_SEPARATE); + } + + if (phalcon_array_isset_quick_string(ast, SS("having"), 876572994UL)) { + PHALCON_OBS_VAR(having); + phalcon_array_fetch_quick_string(&having, ast, SS("having"), 876572994UL, PH_NOISY); + + PHALCON_INIT_VAR(having_expr); + phalcon_call_method_p1_key(having_expr, this_ptr, "_getexpression", having, 2816780276UL); + phalcon_array_update_quick_string(&sql_select, SS("having"), 876572994UL, &having_expr, PH_COPY | PH_SEPARATE); + } + + if (phalcon_array_isset_quick_string(ast, SS("orderBy"), 609540828UL)) { + PHALCON_OBS_VAR(order); + phalcon_array_fetch_quick_string(&order, ast, SS("orderBy"), 609540828UL, PH_NOISY); + + PHALCON_INIT_VAR(sql_order); + phalcon_call_method_p1_key(sql_order, this_ptr, "_getorderclause", order, 1909526941UL); + phalcon_array_update_quick_string(&sql_select, SS("order"), 320020033UL, &sql_order, PH_COPY | PH_SEPARATE); + } + + if (phalcon_array_isset_quick_string(ast, SS("limit"), 192268420UL)) { + PHALCON_OBS_VAR(limit); + phalcon_array_fetch_quick_string(&limit, ast, SS("limit"), 192268420UL, PH_NOISY); + phalcon_array_update_quick_string(&sql_select, SS("limit"), 192268420UL, &limit, PH_COPY | PH_SEPARATE); + } + + RETURN_CTOR(sql_select); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareInsert){ + + zval *ast, *qualified_name, *manager, *model_name; + zval *model, *source = NULL, *schema, *sql_aliases, *not_quoting; + zval *expr_values, *values, *expr_value = NULL, *expr_insert = NULL; + zval *expr_type = NULL, *value = NULL, *sql_insert, *meta_data; + zval *sql_fields, *fields, *field = NULL, *name = NULL, *has_attribute = NULL; + zval *phql = NULL, *exception_message = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(ast); + phalcon_read_property_this_quick(&ast, this_ptr, SL("_ast"), 250429676UL, PH_NOISY_CC); + if (!phalcon_array_isset_quick_string(ast, SS("qualifiedName"), 2418332666UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted INSERT AST"); + return; + } + + if (!phalcon_array_isset_quick_string(ast, SS("values"), 1765818005UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted INSERT AST"); + return; + } + + PHALCON_OBS_VAR(qualified_name); + phalcon_array_fetch_quick_string(&qualified_name, ast, SS("qualifiedName"), 2418332666UL, PH_NOISY); + + if (!phalcon_array_isset_quick_string(qualified_name, SS("name"), 268211462UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted INSERT AST"); + return; + } + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); + + PHALCON_INIT_VAR(model); + phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); + + PHALCON_INIT_VAR(schema); + phalcon_call_method_key(schema, model, "getschema", 1539736246UL); + if (zend_is_true(schema)) { + PHALCON_INIT_NVAR(source); + array_init_size(source, 2); + phalcon_array_append(&source, schema, PH_SEPARATE); + phalcon_array_append(&source, source, PH_SEPARATE); + } + + PHALCON_INIT_VAR(sql_aliases); + array_init(sql_aliases); + + PHALCON_INIT_VAR(not_quoting); + ZVAL_BOOL(not_quoting, 0); + + PHALCON_INIT_VAR(expr_values); + array_init(expr_values); + + PHALCON_OBS_VAR(values); + phalcon_array_fetch_quick_string(&values, ast, SS("values"), 1765818005UL, PH_NOISY); + + phalcon_is_iterable(values, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(expr_value); + + PHALCON_INIT_NVAR(expr_insert); + phalcon_call_method_p2_key(expr_insert, this_ptr, "_getexpression", expr_value, not_quoting, 2816780276UL); + + PHALCON_OBS_NVAR(expr_type); + phalcon_array_fetch_quick_string(&expr_type, expr_value, SS("type"), 276192743UL, PH_NOISY); + + PHALCON_INIT_NVAR(value); + array_init_size(value, 2); + phalcon_array_update_quick_string(&value, SS("type"), 276192743UL, &expr_type, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&value, SS("value"), 574111618UL, &expr_insert, PH_COPY | PH_SEPARATE); + phalcon_array_append(&expr_values, value, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(sql_insert); + array_init(sql_insert); + phalcon_array_update_quick_string(&sql_insert, SS("model"), 238191286UL, &model_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_insert, SS("table"), 495471661UL, &source, PH_COPY | PH_SEPARATE); + + PHALCON_OBS_VAR(meta_data); + phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(ast, SS("fields"), 2881624156UL)) { + + PHALCON_INIT_VAR(sql_fields); + array_init(sql_fields); + + PHALCON_OBS_VAR(fields); + phalcon_array_fetch_quick_string(&fields, ast, SS("fields"), 2881624156UL, PH_NOISY); + + phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(field); + + PHALCON_OBS_NVAR(name); + phalcon_array_fetch_quick_string(&name, field, SS("name"), 268211462UL, PH_NOISY); + + PHALCON_INIT_NVAR(has_attribute); + phalcon_call_method_p2_key(has_attribute, meta_data, "hasattribute", model, name, 3258442645UL); + if (!zend_is_true(has_attribute)) { + PHALCON_OBS_NVAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVS(exception_message, "The model '", model_name, "' doesn't have the attribute '", name, "'"); + PHALCON_SCONCAT_SV(exception_message, ", when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -kk127: -// 388 "scanner.re" - { - s->whitespace_control = 0; - token->opcode = PHVOLT_T_OPEN_DELIMITER; - return 0; + + phalcon_array_append(&sql_fields, name, PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); + } + + phalcon_array_update_quick_string(&sql_insert, SS("fields"), 2881624156UL, &sql_fields, PH_COPY | PH_SEPARATE); + } + + phalcon_array_update_quick_string(&sql_insert, SS("values"), 1765818005UL, &expr_values, PH_COPY | PH_SEPARATE); + + RETURN_CTOR(sql_insert); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareUpdate){ + + zval *ast, *update, *models, *models_instances; + zval *sql_tables, *sql_models, *sql_aliases; + zval *sql_aliases_models_instances, *tables; + zval *update_tables = NULL, *manager, *table = NULL, *qualified_name = NULL; + zval *model_name = NULL, *ns_alias = NULL, *real_namespace = NULL; + zval *real_model_name = NULL, *model = NULL, *source = NULL, *schema = NULL; + zval *complete_source = NULL, *alias = NULL, *sql_fields, *sql_values; + zval *values, *update_values = NULL, *not_quoting = NULL, *update_value = NULL; + zval *column = NULL, *sql_column = NULL, *expr_column = NULL, *expr_value = NULL; + zval *type = NULL, *value = NULL, *sql_update, *where, *where_expr; + zval *limit; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(ast); + phalcon_read_property_this_quick(&ast, this_ptr, SL("_ast"), 250429676UL, PH_NOISY_CC); + if (!phalcon_array_isset_quick_string(ast, SS("update"), 1051190696UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted UPDATE AST"); + return; + } + + PHALCON_OBS_VAR(update); + phalcon_array_fetch_quick_string(&update, ast, SS("update"), 1051190696UL, PH_NOISY); + if (!phalcon_array_isset_quick_string(update, SS("tables"), 3465666720UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted UPDATE AST"); + return; + } + + if (!phalcon_array_isset_quick_string(update, SS("values"), 1765818005UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted UPDATE AST"); + return; + } + + PHALCON_INIT_VAR(models); + array_init(models); + + PHALCON_INIT_VAR(models_instances); + array_init(models_instances); + + PHALCON_INIT_VAR(sql_tables); + array_init(sql_tables); + + PHALCON_INIT_VAR(sql_models); + array_init(sql_models); + + PHALCON_INIT_VAR(sql_aliases); + array_init(sql_aliases); + + PHALCON_INIT_VAR(sql_aliases_models_instances); + array_init(sql_aliases_models_instances); + + PHALCON_OBS_VAR(tables); + phalcon_array_fetch_quick_string(&tables, update, SS("tables"), 3465666720UL, PH_NOISY); + if (!phalcon_array_isset_long(tables, 0)) { + PHALCON_INIT_VAR(update_tables); + array_init_size(update_tables, 1); + phalcon_array_append(&update_tables, tables, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(update_tables, tables); + } + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + phalcon_is_iterable(update_tables, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(table); + + PHALCON_OBS_NVAR(qualified_name); + phalcon_array_fetch_quick_string(&qualified_name, table, SS("qualifiedName"), 2418332666UL, PH_NOISY); + + PHALCON_OBS_NVAR(model_name); + phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); + + if (phalcon_array_isset_quick_string(qualified_name, SS("ns-alias"), 2470863549UL)) { + PHALCON_OBS_NVAR(ns_alias); + phalcon_array_fetch_quick_string(&ns_alias, qualified_name, SS("ns-alias"), 2470863549UL, PH_NOISY); + + PHALCON_INIT_NVAR(real_namespace); + phalcon_call_method_p1_key(real_namespace, manager, "getnamespacealias", ns_alias, 3487123420UL); + + PHALCON_INIT_NVAR(real_model_name); + PHALCON_CONCAT_VSV(real_model_name, real_namespace, "\\", model_name); + } else { + PHALCON_CPY_WRT(real_model_name, model_name); } -// 1103 "scanner.c" -kk128: - ++KKCURSOR; -// 400 "scanner.re" - { - s->whitespace_control = 0; - token->opcode = PHVOLT_T_OPEN_DELIMITER; - return 0; + + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", real_model_name, 266329637UL); + + PHALCON_INIT_NVAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); + + PHALCON_INIT_NVAR(schema); + phalcon_call_method_key(schema, model, "getschema", 1539736246UL); + + if (zend_is_true(schema)) { + PHALCON_INIT_NVAR(complete_source); + array_init_size(complete_source, 2); + phalcon_array_append(&complete_source, source, PH_SEPARATE); + phalcon_array_append(&complete_source, schema, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(complete_source); + array_init_size(complete_source, 2); + phalcon_array_append(&complete_source, source, PH_SEPARATE); + add_next_index_null(complete_source); } -// 1112 "scanner.c" -kk130: - ++KKCURSOR; -// 426 "scanner.re" - { - s->whitespace_control = 0; - s->statement_position++; - token->opcode = PHVOLT_T_OPEN_EDELIMITER; - return 0; + + if (phalcon_array_isset_quick_string(table, SS("alias"), 4060151663UL)) { + PHALCON_OBS_NVAR(alias); + phalcon_array_fetch_quick_string(&alias, table, SS("alias"), 4060151663UL, PH_NOISY); + phalcon_array_update_zval(&sql_aliases, alias, &alias, PH_COPY | PH_SEPARATE); + phalcon_array_append(&complete_source, alias, PH_SEPARATE); + phalcon_array_append(&sql_tables, complete_source, PH_SEPARATE); + phalcon_array_update_zval(&sql_aliases_models_instances, alias, &model, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&models, alias, &model_name, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_zval(&sql_aliases, model_name, &source, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&sql_aliases_models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + phalcon_array_append(&sql_tables, source, PH_SEPARATE); + phalcon_array_update_zval(&models, model_name, &source, PH_COPY | PH_SEPARATE); } -// 1122 "scanner.c" -kk132: - kkch = *++KKCURSOR; - switch (kkch) { - case 'F': - case 'f': goto kk135; - default: goto kk100; - } -kk133: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk134; - } -kk134: -// 358 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_DO; - return 0; + + phalcon_array_append(&sql_models, model_name, PH_SEPARATE); + phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_update_property_this_quick(this_ptr, SL("_models"), models, 4175729768UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_modelsInstances"), models_instances, 457905456UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlAliases"), sql_aliases, 3407085878UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModelsInstances"), sql_aliases_models_instances, 3347052930UL TSRMLS_CC); + + PHALCON_INIT_VAR(sql_fields); + array_init(sql_fields); + + PHALCON_INIT_VAR(sql_values); + array_init(sql_values); + + PHALCON_OBS_VAR(values); + phalcon_array_fetch_quick_string(&values, update, SS("values"), 1765818005UL, PH_NOISY); + if (!phalcon_array_isset_long(values, 0)) { + PHALCON_INIT_VAR(update_values); + array_init_size(update_values, 1); + phalcon_array_append(&update_values, values, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(update_values, values); + } + + PHALCON_INIT_VAR(not_quoting); + ZVAL_BOOL(not_quoting, 0); + + phalcon_is_iterable(update_values, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(update_value); + + PHALCON_OBS_NVAR(column); + phalcon_array_fetch_quick_string(&column, update_value, SS("column"), 3545634419UL, PH_NOISY); + + PHALCON_INIT_NVAR(sql_column); + phalcon_call_method_p2_key(sql_column, this_ptr, "_getexpression", column, not_quoting, 2816780276UL); + phalcon_array_append(&sql_fields, sql_column, PH_SEPARATE); + + PHALCON_OBS_NVAR(expr_column); + phalcon_array_fetch_quick_string(&expr_column, update_value, SS("expr"), 258368420UL, PH_NOISY); + + PHALCON_INIT_NVAR(expr_value); + phalcon_call_method_p2_key(expr_value, this_ptr, "_getexpression", expr_column, not_quoting, 2816780276UL); + + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, expr_column, SS("type"), 276192743UL, PH_NOISY); + + PHALCON_INIT_NVAR(value); + array_init_size(value, 2); + phalcon_array_update_quick_string(&value, SS("type"), 276192743UL, &type, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&value, SS("value"), 574111618UL, &expr_value, PH_COPY | PH_SEPARATE); + phalcon_array_append(&sql_values, value, PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); + } + + PHALCON_INIT_VAR(sql_update); + array_init(sql_update); + phalcon_array_update_quick_string(&sql_update, SS("tables"), 3465666720UL, &sql_tables, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_update, SS("models"), 3565348937UL, &sql_models, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_update, SS("fields"), 2881624156UL, &sql_fields, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_update, SS("values"), 1765818005UL, &sql_values, PH_COPY | PH_SEPARATE); + if (phalcon_array_isset_quick_string(ast, SS("where"), 621293632UL)) { + ZVAL_BOOL(not_quoting, 1); + + PHALCON_OBS_VAR(where); + phalcon_array_fetch_quick_string(&where, ast, SS("where"), 621293632UL, PH_NOISY); + + PHALCON_INIT_VAR(where_expr); + phalcon_call_method_p2_key(where_expr, this_ptr, "_getexpression", where, not_quoting, 2816780276UL); + phalcon_array_update_quick_string(&sql_update, SS("where"), 621293632UL, &where_expr, PH_COPY | PH_SEPARATE); + } + + if (phalcon_array_isset_quick_string(ast, SS("limit"), 192268420UL)) { + PHALCON_OBS_VAR(limit); + phalcon_array_fetch_quick_string(&limit, ast, SS("limit"), 192268420UL, PH_NOISY); + phalcon_array_update_quick_string(&sql_update, SS("limit"), 192268420UL, &limit, PH_COPY | PH_SEPARATE); + } + + RETURN_CTOR(sql_update); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareDelete){ + + zval *ast, *delete, *models, *models_instances; + zval *sql_tables, *sql_models, *sql_aliases; + zval *sql_aliases_models_instances, *tables; + zval *delete_tables = NULL, *manager, *table = NULL, *qualified_name = NULL; + zval *model_name = NULL, *ns_alias = NULL, *real_namespace = NULL; + zval *real_model_name = NULL, *model = NULL, *source = NULL, *schema = NULL; + zval *complete_source = NULL, *alias = NULL, *sql_delete, *not_quoting; + zval *where, *where_expr, *limit; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(ast); + phalcon_read_property_this_quick(&ast, this_ptr, SL("_ast"), 250429676UL, PH_NOISY_CC); + if (!phalcon_array_isset_quick_string(ast, SS("delete"), 150213496UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted DELETE AST"); + return; + } + + PHALCON_OBS_VAR(delete); + phalcon_array_fetch_quick_string(&delete, ast, SS("delete"), 150213496UL, PH_NOISY); + if (!phalcon_array_isset_quick_string(delete, SS("tables"), 3465666720UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted DELETE AST"); + return; + } + + PHALCON_INIT_VAR(models); + array_init(models); + + PHALCON_INIT_VAR(models_instances); + array_init(models_instances); + + PHALCON_INIT_VAR(sql_tables); + array_init(sql_tables); + + PHALCON_INIT_VAR(sql_models); + array_init(sql_models); + + PHALCON_INIT_VAR(sql_aliases); + array_init(sql_aliases); + + PHALCON_INIT_VAR(sql_aliases_models_instances); + array_init(sql_aliases_models_instances); + + PHALCON_OBS_VAR(tables); + phalcon_array_fetch_quick_string(&tables, delete, SS("tables"), 3465666720UL, PH_NOISY); + if (!phalcon_array_isset_long(tables, 0)) { + PHALCON_INIT_VAR(delete_tables); + array_init_size(delete_tables, 1); + phalcon_array_append(&delete_tables, tables, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(delete_tables, tables); + } + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + phalcon_is_iterable(delete_tables, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(table); + + PHALCON_OBS_NVAR(qualified_name); + phalcon_array_fetch_quick_string(&qualified_name, table, SS("qualifiedName"), 2418332666UL, PH_NOISY); + + PHALCON_OBS_NVAR(model_name); + phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); + + if (phalcon_array_isset_quick_string(qualified_name, SS("ns-alias"), 2470863549UL)) { + PHALCON_OBS_NVAR(ns_alias); + phalcon_array_fetch_quick_string(&ns_alias, qualified_name, SS("ns-alias"), 2470863549UL, PH_NOISY); + + PHALCON_INIT_NVAR(real_namespace); + phalcon_call_method_p1_key(real_namespace, manager, "getnamespacealias", ns_alias, 3487123420UL); + + PHALCON_INIT_NVAR(real_model_name); + PHALCON_CONCAT_VSV(real_model_name, real_namespace, "\\", model_name); + } else { + PHALCON_CPY_WRT(real_model_name, model_name); } -// 1206 "scanner.c" -kk135: - kkch = *++KKCURSOR; - switch (kkch) { - case 'I': - case 'i': goto kk136; - default: goto kk100; - } -kk136: - kkch = *++KKCURSOR; - switch (kkch) { - case 'N': - case 'n': goto kk137; - default: goto kk100; - } -kk137: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk138; - default: goto kk100; - } -kk138: - kkch = *++KKCURSOR; - switch (kkch) { - case 'D': - case 'd': goto kk139; - default: goto kk100; - } -kk139: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk140; - } -kk140: -// 335 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_DEFINED; - return 0; + + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", real_model_name, 266329637UL); + + PHALCON_INIT_NVAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); + + PHALCON_INIT_NVAR(schema); + phalcon_call_method_key(schema, model, "getschema", 1539736246UL); + if (zend_is_true(schema)) { + PHALCON_INIT_NVAR(complete_source); + array_init_size(complete_source, 2); + phalcon_array_append(&complete_source, source, PH_SEPARATE); + phalcon_array_append(&complete_source, schema, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(complete_source); + array_init_size(complete_source, 2); + phalcon_array_append(&complete_source, source, PH_SEPARATE); + add_next_index_null(complete_source); } -// 1311 "scanner.c" -kk141: - kkch = *++KKCURSOR; - switch (kkch) { - case 'T': - case 't': goto kk142; - default: goto kk100; + + if (phalcon_array_isset_quick_string(table, SS("alias"), 4060151663UL)) { + PHALCON_OBS_NVAR(alias); + phalcon_array_fetch_quick_string(&alias, table, SS("alias"), 4060151663UL, PH_NOISY); + phalcon_array_update_zval(&sql_aliases, alias, &alias, PH_COPY | PH_SEPARATE); + phalcon_array_append(&complete_source, alias, PH_SEPARATE); + phalcon_array_append(&sql_tables, complete_source, PH_SEPARATE); + phalcon_array_update_zval(&sql_aliases_models_instances, alias, &model, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&models, alias, &model_name, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_zval(&sql_aliases, model_name, &source, PH_COPY | PH_SEPARATE); + phalcon_array_update_zval(&sql_aliases_models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + phalcon_array_append(&sql_tables, source, PH_SEPARATE); + phalcon_array_update_zval(&models, model_name, &source, PH_COPY | PH_SEPARATE); + } + + phalcon_array_append(&sql_models, model_name, PH_SEPARATE); + phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_update_property_this_quick(this_ptr, SL("_models"), models, 4175729768UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_modelsInstances"), models_instances, 457905456UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlAliases"), sql_aliases, 3407085878UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_sqlAliasesModelsInstances"), sql_aliases_models_instances, 3347052930UL TSRMLS_CC); + + PHALCON_INIT_VAR(sql_delete); + array_init(sql_delete); + phalcon_array_update_quick_string(&sql_delete, SS("tables"), 3465666720UL, &sql_tables, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&sql_delete, SS("models"), 3565348937UL, &sql_models, PH_COPY | PH_SEPARATE); + if (phalcon_array_isset_quick_string(ast, SS("where"), 621293632UL)) { + PHALCON_INIT_VAR(not_quoting); + ZVAL_BOOL(not_quoting, 1); + + PHALCON_OBS_VAR(where); + phalcon_array_fetch_quick_string(&where, ast, SS("where"), 621293632UL, PH_NOISY); + + PHALCON_INIT_VAR(where_expr); + phalcon_call_method_p2_key(where_expr, this_ptr, "_getexpression", where, not_quoting, 2816780276UL); + phalcon_array_update_quick_string(&sql_delete, SS("where"), 621293632UL, &where_expr, PH_COPY | PH_SEPARATE); + } + + if (phalcon_array_isset_quick_string(ast, SS("limit"), 192268420UL)) { + PHALCON_OBS_VAR(limit); + phalcon_array_fetch_quick_string(&limit, ast, SS("limit"), 192268420UL, PH_NOISY); + phalcon_array_update_quick_string(&sql_delete, SS("limit"), 192268420UL, &limit, PH_COPY | PH_SEPARATE); + } + + RETURN_CTOR(sql_delete); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, parse){ + + zval *intermediate, *phql, *ast, *ir_phql = NULL, *ir_phql_cache = NULL; + zval *unique_id = NULL, *type = NULL, *exception_message; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(intermediate); + phalcon_read_property_this_quick(&intermediate, this_ptr, SL("_intermediate"), 1829292799UL, PH_NOISY_CC); + if (Z_TYPE_P(intermediate) == IS_ARRAY) { + RETURN_CCTOR(intermediate); + } + + PHALCON_OBS_VAR(phql); + phalcon_read_property_this_quick(&phql, this_ptr, SL("_phql"), 3986605817UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(ast); + if (phql_parse_phql(ast, phql TSRMLS_CC) == FAILURE) { + return; + } + + PHALCON_INIT_VAR(ir_phql); + + PHALCON_INIT_VAR(ir_phql_cache); + + PHALCON_INIT_VAR(unique_id); + + if (Z_TYPE_P(ast) == IS_ARRAY) { + + if (phalcon_array_isset_quick_string(ast, SS("id"), 193494642UL)) { + + PHALCON_OBS_NVAR(unique_id); + phalcon_array_fetch_quick_string(&unique_id, ast, SS("id"), 193494642UL, PH_NOISY); + + PHALCON_OBS_NVAR(ir_phql_cache); + phalcon_read_static_property(&ir_phql_cache, SL("phalcon\\mvc\\model\\query"), SL("_irPhqlCache") TSRMLS_CC); + if (phalcon_array_isset(ir_phql_cache, unique_id)) { + + PHALCON_OBS_NVAR(ir_phql); + phalcon_array_fetch(&ir_phql, ir_phql_cache, unique_id, PH_NOISY); + if (Z_TYPE_P(ir_phql) == IS_ARRAY) { + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, ast, SS("type"), 276192743UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); + RETURN_CCTOR(ir_phql); + } } -kk142: - kkch = *++KKCURSOR; - switch (kkch) { - case 'U': - case 'u': goto kk143; - default: goto kk100; + } + + if (phalcon_array_isset_quick_string(ast, SS("type"), 276192743UL)) { + phalcon_update_property_this_quick(this_ptr, SL("_ast"), ast, 250429676UL TSRMLS_CC); + + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, ast, SS("type"), 276192743UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); + + switch (phalcon_get_intval(type)) { + + case 309: + PHALCON_INIT_NVAR(ir_phql); + phalcon_call_method_key(ir_phql, this_ptr, "_prepareselect", 1122471507UL); + break; + + case 306: + PHALCON_INIT_NVAR(ir_phql); + phalcon_call_method_key(ir_phql, this_ptr, "_prepareinsert", 1453230024UL); + break; + + case 300: + PHALCON_INIT_NVAR(ir_phql); + phalcon_call_method_key(ir_phql, this_ptr, "_prepareupdate", 4126283670UL); + break; + + case 303: + PHALCON_INIT_NVAR(ir_phql); + phalcon_call_method_key(ir_phql, this_ptr, "_preparedelete", 3225306470UL); + break; + + default: + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "Unknown statement ", type, ", when preparing: ", phql); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } -kk143: - kkch = *++KKCURSOR; - switch (kkch) { - case 'R': - case 'r': goto kk144; - default: goto kk100; + } + } + + if (Z_TYPE_P(ir_phql) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted AST"); + return; + } + + if (Z_TYPE_P(unique_id) == IS_LONG) { + if (Z_TYPE_P(ir_phql_cache) != IS_ARRAY) { + PHALCON_INIT_NVAR(ir_phql_cache); + array_init(ir_phql_cache); + } + phalcon_array_update_zval(&ir_phql_cache, unique_id, &ir_phql, PH_COPY | PH_SEPARATE); + phalcon_update_static_property(SL("phalcon\\mvc\\model\\query"), SL("_irPhqlCache"), ir_phql_cache TSRMLS_CC); + } + + phalcon_update_property_this_quick(this_ptr, SL("_intermediate"), ir_phql, 1829292799UL TSRMLS_CC); + + RETURN_CCTOR(ir_phql); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, cache){ + + zval *cache_options; + + phalcon_fetch_params(0, 1, 0, &cache_options); + + phalcon_update_property_this_quick(this_ptr, SL("_cacheOptions"), cache_options, 528255652UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, getCacheOptions){ + + + RETURN_MEMBER_QUICK(this_ptr, "_cacheOptions", 528255652UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, getCache){ + + + RETURN_MEMBER_QUICK(this_ptr, "_cache", 2191407384UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _executeSelect){ + + zval *intermediate, *bind_params, *bind_types; + zval *manager, *models_instances = NULL, *models, *number_models; + zval *model_name = NULL, *model = NULL, *connection = NULL, *connections; + zval *type = NULL, *connection_types = NULL, *columns, *have_objects = NULL; + zval *have_scalars = NULL, *is_complex = NULL, *number_objects; + zval *column = NULL, *column_type = NULL, *is_simple_std = NULL, *select_columns; + zval *simple_column_map = NULL, *meta_data, *znull; + zval *alias_copy = NULL, *sql_column = NULL, *instance = NULL, *attributes = NULL; + zval *column_map = NULL, *attribute = NULL, *hidden_alias = NULL; + zval *column_alias = NULL, *is_keeping_snapshots = NULL; + zval *sql_alias = NULL, *dialect, *sql_select, *processed = NULL; + zval *value = NULL, *wildcard = NULL, *string_wildcard = NULL, *processed_types = NULL; + zval *type_wildcard = NULL, *result, *count, *result_data = NULL; + zval *cache, *result_object = NULL, *resultset = NULL; + HashTable *ah0, *ah1, *ah2, *ah3, *ah4, *ah5, *ah6; + HashPosition hp0, hp1, hp2, hp3, hp4, hp5, hp6; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &intermediate, &bind_params, &bind_types); + + PHALCON_SEPARATE_PARAM(intermediate); + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(models_instances); + phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); + if (Z_TYPE_P(models_instances) != IS_ARRAY) { + PHALCON_INIT_NVAR(models_instances); + array_init(models_instances); + } + + PHALCON_OBS_VAR(models); + phalcon_array_fetch_quick_string(&models, intermediate, SS("models"), 3565348937UL, PH_NOISY); + + PHALCON_INIT_VAR(number_models); + phalcon_fast_count(number_models, models TSRMLS_CC); + if (PHALCON_IS_LONG(number_models, 1)) { + + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); + if (!phalcon_array_isset(models_instances, model_name)) { + PHALCON_INIT_VAR(model); + phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + } else { + PHALCON_OBS_NVAR(model); + phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); + } + + if (phalcon_method_quick_exists_ex(model, SS("selectreadconnection"), 2893916401UL TSRMLS_CC) == SUCCESS) { + + PHALCON_INIT_VAR(connection); + phalcon_call_method_p3_key(connection, model, "selectreadconnection", intermediate, bind_params, bind_types, 2893916401UL); + if (Z_TYPE_P(connection) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "'selectReadConnection' didn't returned a valid connection"); + return; } -kk144: - kkch = *++KKCURSOR; - switch (kkch) { - case 'N': - case 'n': goto kk145; - default: goto kk100; + } else { + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, model, "getreadconnection", 488334257UL); + } + } else { + PHALCON_INIT_VAR(connections); + array_init(connections); + + phalcon_is_iterable(models, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(model_name); + + if (!phalcon_array_isset(models_instances, model_name)) { + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); + } else { + PHALCON_OBS_NVAR(model); + phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); } -kk145: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk146; + + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, model, "getreadconnection", 488334257UL); + + PHALCON_INIT_NVAR(type); + phalcon_call_method_key(type, connection, "gettype", 4294422375UL); + + phalcon_array_update_zval_bool(&connections, type, 1, PH_SEPARATE); + + PHALCON_INIT_NVAR(connection_types); + phalcon_fast_count(connection_types, connections TSRMLS_CC); + + if (PHALCON_IS_LONG(connection_types, 2)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Cannot use models of different database systems in the same query"); + return; } -kk146: -// 312 "scanner.re" - { - token->opcode = PHVOLT_T_RETURN; - return 0; + + zend_hash_move_forward_ex(ah0, &hp0); } -// 1415 "scanner.c" -kk147: - kkch = *++KKCURSOR; - switch (kkch) { - case 'T': - case 't': goto kk148; - default: goto kk100; - } -kk148: - kkch = *++KKCURSOR; - switch (kkch) { - case 'H': - case 'h': goto kk149; - default: goto kk100; + + } + + PHALCON_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, intermediate, SS("columns"), 1041822630UL, PH_NOISY); + + PHALCON_INIT_VAR(have_objects); + ZVAL_BOOL(have_objects, 0); + + PHALCON_INIT_VAR(have_scalars); + ZVAL_BOOL(have_scalars, 0); + + PHALCON_INIT_VAR(is_complex); + ZVAL_BOOL(is_complex, 0); + + PHALCON_INIT_VAR(number_objects); + ZVAL_LONG(number_objects, 0); + + phalcon_is_iterable(columns, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(column); + + PHALCON_OBS_NVAR(column_type); + phalcon_array_fetch_quick_string(&column_type, column, SS("type"), 276192743UL, PH_NOISY); + if (PHALCON_IS_STRING(column_type, "scalar")) { + if (!phalcon_array_isset_quick_string(column, SS("balias"), 1705826801UL)) { + PHALCON_INIT_NVAR(is_complex); + ZVAL_BOOL(is_complex, 1); } -kk149: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk150; + + PHALCON_INIT_NVAR(have_scalars); + ZVAL_BOOL(have_scalars, 1); + } else { + PHALCON_INIT_NVAR(have_objects); + ZVAL_BOOL(have_objects, 1); + PHALCON_SEPARATE(number_objects); + phalcon_increment(number_objects); + } + + zend_hash_move_forward_ex(ah1, &hp1); + } + + if (PHALCON_IS_FALSE(is_complex)) { + if (PHALCON_IS_TRUE(have_objects)) { + if (PHALCON_IS_TRUE(have_scalars)) { + PHALCON_INIT_NVAR(is_complex); + ZVAL_BOOL(is_complex, 1); + } else { + if (PHALCON_IS_LONG(number_objects, 1)) { + PHALCON_INIT_VAR(is_simple_std); + ZVAL_BOOL(is_simple_std, 0); + } else { + PHALCON_INIT_NVAR(is_complex); + ZVAL_BOOL(is_complex, 1); + } } -kk150: -// 307 "scanner.re" - { - token->opcode = PHVOLT_T_WITH; - return 0; + } else { + PHALCON_INIT_NVAR(is_simple_std); + ZVAL_BOOL(is_simple_std, 1); } -// 1505 "scanner.c" -kk151: - kkch = *++KKCURSOR; - switch (kkch) { - case 'C': - case 'c': goto kk161; - case 'L': - case 'l': goto kk160; - default: goto kk100; - } -kk152: - kkch = *++KKCURSOR; - switch (kkch) { - case 'N': - case 'n': goto kk153; - default: goto kk100; - } -kk153: - kkch = *++KKCURSOR; - switch (kkch) { - case 'T': - case 't': goto kk154; - default: goto kk100; + } + + PHALCON_INIT_VAR(select_columns); + array_init(select_columns); + + PHALCON_INIT_VAR(simple_column_map); + array_init(simple_column_map); + + PHALCON_OBS_VAR(meta_data); + phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(znull); + + phalcon_is_iterable(columns, &ah2, &hp2, 1, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HMKEY(alias_copy, ah2, hp2); + PHALCON_GET_HVALUE(column); + + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, column, SS("type"), 276192743UL, PH_NOISY); + + PHALCON_OBS_NVAR(sql_column); + phalcon_array_fetch_quick_string(&sql_column, column, SS("column"), 3545634419UL, PH_NOISY); + + if (PHALCON_IS_STRING(type, "object")) { + + PHALCON_OBS_NVAR(model_name); + phalcon_array_fetch_quick_string(&model_name, column, SS("model"), 238191286UL, PH_NOISY); + + if (phalcon_array_isset(models_instances, model_name)) { + PHALCON_OBS_NVAR(instance); + phalcon_array_fetch(&instance, models_instances, model_name, PH_NOISY); + } else { + PHALCON_INIT_NVAR(instance); + phalcon_call_method_p1_key(instance, manager, "load", model_name, 266329637UL); + phalcon_array_update_zval(&models_instances, model_name, &instance, PH_COPY | PH_SEPARATE); } -kk154: - kkch = *++KKCURSOR; - switch (kkch) { - case 'I': - case 'i': goto kk155; - default: goto kk100; + + PHALCON_INIT_NVAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", instance, 1013165772UL); + if (PHALCON_IS_TRUE(is_complex)) { + + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_NVAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", instance, 213063537UL); + } else { + PHALCON_CPY_WRT(column_map, znull); + } + + phalcon_is_iterable(attributes, &ah3, &hp3, 0, 0); + + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { + + PHALCON_GET_HVALUE(attribute); + + PHALCON_INIT_NVAR(hidden_alias); + PHALCON_CONCAT_SVSV(hidden_alias, "_", sql_column, "_", attribute); + + PHALCON_INIT_NVAR(column_alias); + array_init_size(column_alias, 3); + phalcon_array_append(&column_alias, attribute, PH_SEPARATE); + phalcon_array_append(&column_alias, sql_column, PH_SEPARATE); + phalcon_array_append(&column_alias, hidden_alias, PH_SEPARATE); + phalcon_array_append(&select_columns, column_alias, PH_SEPARATE); + + zend_hash_move_forward_ex(ah3, &hp3); + } + + phalcon_array_update_string_multi_2(&columns, alias_copy, SL("instance"), &instance, 0); + phalcon_array_update_string_multi_2(&columns, alias_copy, SL("attributes"), &attributes, 0); + phalcon_array_update_string_multi_2(&columns, alias_copy, SL("columnMap"), &column_map, 0); + + PHALCON_INIT_NVAR(is_keeping_snapshots); + phalcon_call_method_p1_key(is_keeping_snapshots, manager, "iskeepingsnapshots", instance, 2646609383UL); + if (zend_is_true(is_keeping_snapshots)) { + phalcon_array_update_string_multi_2(&columns, alias_copy, SL("keepSnapshots"), &is_keeping_snapshots, 0); + } + } else { + phalcon_is_iterable(attributes, &ah4, &hp4, 0, 0); + + while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { + + PHALCON_GET_HVALUE(attribute); + + PHALCON_INIT_NVAR(column_alias); + array_init_size(column_alias, 2); + phalcon_array_append(&column_alias, attribute, PH_SEPARATE); + phalcon_array_append(&column_alias, sql_column, PH_SEPARATE); + phalcon_array_append(&select_columns, column_alias, PH_SEPARATE); + + zend_hash_move_forward_ex(ah4, &hp4); + } + } -kk155: - kkch = *++KKCURSOR; - switch (kkch) { - case 'N': - case 'n': goto kk156; - default: goto kk100; + } else { + if (Z_TYPE_P(alias_copy) == IS_LONG) { + PHALCON_INIT_NVAR(column_alias); + array_init_size(column_alias, 2); + phalcon_array_append(&column_alias, sql_column, PH_SEPARATE); + phalcon_array_append(&column_alias, znull, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(column_alias); + array_init_size(column_alias, 3); + phalcon_array_append(&column_alias, sql_column, PH_SEPARATE); + phalcon_array_append(&column_alias, znull, PH_SEPARATE); + phalcon_array_append(&column_alias, alias_copy, PH_SEPARATE); } -kk156: - kkch = *++KKCURSOR; - switch (kkch) { - case 'U': - case 'u': goto kk157; - default: goto kk100; + phalcon_array_append(&select_columns, column_alias, PH_SEPARATE); + } + + if (PHALCON_IS_FALSE(is_complex)) { + if (PHALCON_IS_TRUE(is_simple_std)) { + if (phalcon_array_isset_quick_string(column, SS("sqlAlias"), 2820722015UL)) { + PHALCON_OBS_NVAR(sql_alias); + phalcon_array_fetch_quick_string(&sql_alias, column, SS("sqlAlias"), 2820722015UL, PH_NOISY); + phalcon_array_update_zval(&simple_column_map, sql_alias, &alias_copy, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_zval(&simple_column_map, alias_copy, &alias_copy, PH_COPY | PH_SEPARATE); + } } -kk157: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk158; - default: goto kk100; + } + + zend_hash_move_forward_ex(ah2, &hp2); + } + zend_hash_destroy(ah2); + efree(ah2); + + phalcon_array_update_quick_string(&intermediate, SS("columns"), 1041822630UL, &select_columns, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(dialect); + phalcon_call_method_key(dialect, connection, "getdialect", 3133083739UL); + + PHALCON_INIT_VAR(sql_select); + phalcon_call_method_p1_key(sql_select, dialect, "select", intermediate, 2342345829UL); + + if (Z_TYPE_P(bind_params) == IS_ARRAY) { + + PHALCON_INIT_VAR(processed); + array_init(processed); + + phalcon_is_iterable(bind_params, &ah5, &hp5, 0, 0); + + while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { + + PHALCON_GET_HKEY(wildcard, ah5, hp5); + PHALCON_GET_HVALUE(value); + + if (Z_TYPE_P(wildcard) == IS_LONG) { + PHALCON_INIT_NVAR(string_wildcard); + PHALCON_CONCAT_SV(string_wildcard, ":", wildcard); + phalcon_array_update_zval(&processed, string_wildcard, &value, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_zval(&processed, wildcard, &value, PH_COPY | PH_SEPARATE); } -kk158: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk159; + + zend_hash_move_forward_ex(ah5, &hp5); + } + + } else { + PHALCON_CPY_WRT(processed, bind_params); + } + + if (Z_TYPE_P(bind_types) == IS_ARRAY) { + + PHALCON_INIT_VAR(processed_types); + array_init(processed_types); + + phalcon_is_iterable(bind_types, &ah6, &hp6, 0, 0); + + while (zend_hash_get_current_data_ex(ah6, (void**) &hd, &hp6) == SUCCESS) { + + PHALCON_GET_HKEY(type_wildcard, ah6, hp6); + PHALCON_GET_HVALUE(value); + + if (Z_TYPE_P(type_wildcard) == IS_LONG) { + PHALCON_INIT_NVAR(string_wildcard); + PHALCON_CONCAT_SV(string_wildcard, ":", type_wildcard); + phalcon_array_update_zval(&processed_types, string_wildcard, &value, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_zval(&processed_types, type_wildcard, &value, PH_COPY | PH_SEPARATE); } -kk159: -// 376 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_CONTINUE; - return 0; + + zend_hash_move_forward_ex(ah6, &hp6); + } + + } else { + PHALCON_CPY_WRT(processed_types, bind_types); + } + + PHALCON_INIT_VAR(result); + phalcon_call_method_p3_key(result, connection, "query", sql_select, processed, processed_types, 401898907UL); + + PHALCON_INIT_VAR(count); + phalcon_call_method_p1_key(count, result, "numrows", result, 887792640UL); + if (zend_is_true(count)) { + PHALCON_CPY_WRT(result_data, result); + } else { + PHALCON_INIT_NVAR(result_data); + ZVAL_BOOL(result_data, 0); + } + + PHALCON_OBS_VAR(cache); + phalcon_read_property_this_quick(&cache, this_ptr, SL("_cache"), 2191407384UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(is_complex)) { + + if (PHALCON_IS_TRUE(is_simple_std)) { + PHALCON_INIT_VAR(result_object); + object_init_ex(result_object, phalcon_mvc_model_row_ce); + + PHALCON_INIT_NVAR(is_keeping_snapshots); + ZVAL_BOOL(is_keeping_snapshots, 0); + } else { + PHALCON_CPY_WRT(result_object, model); + + PHALCON_INIT_NVAR(simple_column_map); + phalcon_call_method_p1_key(simple_column_map, meta_data, "getcolumnmap", model, 213063537UL); + + PHALCON_INIT_NVAR(is_keeping_snapshots); + phalcon_call_method_p1_key(is_keeping_snapshots, manager, "iskeepingsnapshots", model, 2646609383UL); + } + + PHALCON_INIT_VAR(resultset); + object_init_ex(resultset, phalcon_mvc_model_resultset_simple_ce); + phalcon_call_method_p5_key(NULL, resultset, "__construct", simple_column_map, result_object, result_data, cache, is_keeping_snapshots, 1107214344UL); + + RETURN_CTOR(resultset); + } + + PHALCON_INIT_NVAR(resultset); + object_init_ex(resultset, phalcon_mvc_model_resultset_complex_ce); + phalcon_call_method_p3_key(NULL, resultset, "__construct", columns, result_data, cache, 1107214344UL); + + RETURN_CTOR(resultset); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _executeInsert){ + + zval *intermediate, *bind_params, *bind_types; + zval *model_name, *manager, *models_instances; + zval *model = NULL, *connection, *meta_data, *attributes; + zval *automatic_fields = NULL, *fields = NULL, *column_map = NULL; + zval *values, *number_fields, *number_values; + zval *dialect, *double_colon, *empty_string; + zval *null_value, *not_exists, *insert_values; + zval *value = NULL, *number = NULL, *type = NULL, *expr_value = NULL, *insert_value = NULL; + zval *insert_expr = NULL, *wildcard = NULL, *exception_message = NULL; + zval *field_name = NULL, *attribute_name = NULL, *base_model; + zval *insert_model, *success; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &intermediate, &bind_params, &bind_types); + + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch_quick_string(&model_name, intermediate, SS("model"), 238191286UL, PH_NOISY); + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(models_instances); + phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); + if (phalcon_array_isset(models_instances, model_name)) { + PHALCON_OBS_VAR(model); + phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); + } else { + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); + + PHALCON_OBS_VAR(meta_data); + phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", model, 1013165772UL); + + PHALCON_INIT_VAR(automatic_fields); + ZVAL_BOOL(automatic_fields, 0); + + if (phalcon_array_isset_quick_string(intermediate, SS("fields"), 2881624156UL)) { + PHALCON_OBS_VAR(fields); + phalcon_array_fetch_quick_string(&fields, intermediate, SS("fields"), 2881624156UL, PH_NOISY); + } else { + ZVAL_BOOL(automatic_fields, 1); + PHALCON_CPY_WRT(fields, attributes); + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", model, 213063537UL); + } else { + PHALCON_INIT_NVAR(column_map); + } + } + + PHALCON_OBS_VAR(values); + phalcon_array_fetch_quick_string(&values, intermediate, SS("values"), 1765818005UL, PH_NOISY); + + PHALCON_INIT_VAR(number_fields); + phalcon_fast_count(number_fields, fields TSRMLS_CC); + + PHALCON_INIT_VAR(number_values); + phalcon_fast_count(number_values, values TSRMLS_CC); + + if (!PHALCON_IS_EQUAL(number_fields, number_values)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The column count does not match the values count"); + return; + } + + PHALCON_INIT_VAR(dialect); + phalcon_call_method_key(dialect, connection, "getdialect", 3133083739UL); + + PHALCON_INIT_VAR(double_colon); + ZVAL_STRING(double_colon, ":", 1); + + PHALCON_INIT_VAR(empty_string); + ZVAL_STRING(empty_string, "", 1); + + PHALCON_INIT_VAR(null_value); + + PHALCON_INIT_VAR(not_exists); + ZVAL_BOOL(not_exists, 0); + + PHALCON_INIT_VAR(insert_values); + array_init(insert_values); + + phalcon_is_iterable(values, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(number, ah0, hp0); + PHALCON_GET_HVALUE(value); + + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, value, SS("type"), 276192743UL, PH_NOISY); + + PHALCON_OBS_NVAR(expr_value); + phalcon_array_fetch_quick_string(&expr_value, value, SS("value"), 574111618UL, PH_NOISY); + + switch (phalcon_get_intval(type)) { + + case 260: + PHALCON_INIT_NVAR(insert_value); + phalcon_call_method_p1_key(insert_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; + + case 258: + PHALCON_INIT_NVAR(insert_value); + phalcon_call_method_p1_key(insert_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; + + case 259: + PHALCON_INIT_NVAR(insert_value); + phalcon_call_method_p1_key(insert_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; + + case 322: + PHALCON_CPY_WRT(insert_value, null_value); + break; + + case 273: + if (Z_TYPE_P(bind_params) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Bound parameter cannot be replaced because placeholders is not an array"); + return; + } + + PHALCON_INIT_NVAR(insert_expr); + phalcon_call_method_p1_key(insert_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); + + PHALCON_INIT_NVAR(wildcard); + phalcon_fast_str_replace(wildcard, double_colon, empty_string, insert_expr); + if (!phalcon_array_isset(bind_params, wildcard)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Bound parameter '", wildcard, "' cannot be replaced because it isn't in the placeholders list"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_NVAR(insert_value); + phalcon_array_fetch(&insert_value, bind_params, wildcard, PH_NOISY); + break; + + case 274: + if (Z_TYPE_P(bind_params) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Bound parameter cannot be replaced because placeholders is not an array"); + return; + } + + PHALCON_INIT_NVAR(insert_expr); + phalcon_call_method_p1_key(insert_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); + + PHALCON_INIT_NVAR(wildcard); + phalcon_fast_str_replace(wildcard, double_colon, empty_string, insert_expr); + if (!phalcon_array_isset(bind_params, wildcard)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Bound parameter '", wildcard, "' cannot be replaced because it's not in the placeholders list"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_NVAR(insert_value); + phalcon_array_fetch(&insert_value, bind_params, wildcard, PH_NOISY); + break; + + default: + PHALCON_INIT_NVAR(insert_expr); + phalcon_call_method_p1_key(insert_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); + + PHALCON_INIT_NVAR(insert_value); + object_init_ex(insert_value, phalcon_db_rawvalue_ce); + phalcon_call_method_p1_key(NULL, insert_value, "__construct", insert_expr, 1107214344UL); + + break; + } -// 1633 "scanner.c" -kk160: - kkch = *++KKCURSOR; - switch (kkch) { - case 'L': - case 'l': goto kk165; - default: goto kk100; - } -kk161: - kkch = *++KKCURSOR; - switch (kkch) { - case 'H': - case 'h': goto kk162; - default: goto kk100; - } -kk162: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk163; - default: goto kk100; - } -kk163: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk164; + + PHALCON_OBS_NVAR(field_name); + phalcon_array_fetch(&field_name, fields, number, PH_NOISY); + + if (PHALCON_IS_TRUE(automatic_fields)) { + + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, field_name)) { + PHALCON_OBS_NVAR(attribute_name); + phalcon_array_fetch(&attribute_name, column_map, field_name, PH_NOISY); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", field_name, "\" isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } else { + PHALCON_CPY_WRT(attribute_name, field_name); } -kk164: -// 347 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_CACHE; - return 0; + } else { + PHALCON_CPY_WRT(attribute_name, field_name); } -// 1731 "scanner.c" -kk165: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk166; - } -kk166: -// 296 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_CALL; - return 0; + + phalcon_array_update_zval(&insert_values, attribute_name, &insert_value, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(base_model); + phalcon_call_method_p1_key(base_model, manager, "load", model_name, 266329637UL); + + PHALCON_INIT_VAR(insert_model); + if (phalcon_clone(insert_model, base_model TSRMLS_CC) == FAILURE) { + return; + } + + PHALCON_INIT_VAR(success); + phalcon_call_method_p1_key(success, insert_model, "create", insert_values, 3654027737UL); + + object_init_ex(return_value, phalcon_mvc_model_query_status_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", success, insert_model, 1107214344UL); + + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getRelatedRecords){ + + zval *model, *intermediate, *bind_params, *bind_types; + zval *selected_tables, *selected_models, *source; + zval *model_name, *select_column, *selected_columns; + zval *select_ir, *where_conditions, *limit_conditions; + zval *type_select, *dependency_injector, *query; + zval *records; + zval *a0 = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 4, 0, &model, &intermediate, &bind_params, &bind_types); + + PHALCON_OBS_VAR(selected_tables); + phalcon_array_fetch_quick_string(&selected_tables, intermediate, SS("tables"), 3465666720UL, PH_NOISY); + + PHALCON_OBS_VAR(selected_models); + phalcon_array_fetch_quick_string(&selected_models, intermediate, SS("models"), 3565348937UL, PH_NOISY); + + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); + + PHALCON_INIT_VAR(model_name); + phalcon_get_class(model_name, model, 0 TSRMLS_CC); + + PHALCON_INIT_VAR(select_column); + array_init_size(select_column, 1); + + PHALCON_INIT_VAR(a0); + array_init_size(a0, 3); + add_assoc_stringl_ex(a0, SS("type"), SL("object"), 1); + phalcon_array_update_quick_string(&a0, SS("model"), 238191286UL, &model_name, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&a0, SS("column"), 3545634419UL, &source, PH_COPY | PH_SEPARATE); + phalcon_array_append(&select_column, a0, PH_SEPARATE); + + PHALCON_INIT_VAR(selected_columns); + array_init_size(selected_columns, 1); + phalcon_array_append(&selected_columns, select_column, PH_SEPARATE); + + PHALCON_INIT_VAR(select_ir); + array_init_size(select_ir, 3); + phalcon_array_update_quick_string(&select_ir, SS("columns"), 1041822630UL, &select_column, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&select_ir, SS("models"), 3565348937UL, &selected_models, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&select_ir, SS("tables"), 3465666720UL, &selected_tables, PH_COPY | PH_SEPARATE); + + if (phalcon_array_isset_quick_string(intermediate, SS("where"), 621293632UL)) { + PHALCON_OBS_VAR(where_conditions); + phalcon_array_fetch_quick_string(&where_conditions, intermediate, SS("where"), 621293632UL, PH_NOISY); + phalcon_array_update_quick_string(&select_ir, SS("where"), 621293632UL, &where_conditions, PH_COPY | PH_SEPARATE); + } + + if (phalcon_array_isset_quick_string(intermediate, SS("limit"), 192268420UL)) { + PHALCON_OBS_VAR(limit_conditions); + phalcon_array_fetch_quick_string(&limit_conditions, intermediate, SS("limit"), 192268420UL, PH_NOISY); + phalcon_array_update_quick_string(&select_ir, SS("limit"), 192268420UL, &limit_conditions, PH_COPY | PH_SEPARATE); + } + + PHALCON_INIT_VAR(type_select); + ZVAL_LONG(type_select, 309); + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(query); + object_init_ex(query, phalcon_mvc_model_query_ce); + phalcon_call_method_key(NULL, query, "__construct", 1107214344UL); + + phalcon_call_method_p1_key(NULL, query, "setdi", dependency_injector, 461718238UL); + phalcon_call_method_p1_key(NULL, query, "settype", type_select, 319662579UL); + phalcon_call_method_p1_key(NULL, query, "setintermediate", select_ir, 3787545516UL); + + PHALCON_INIT_VAR(records); + phalcon_call_method_p2_key(records, query, "execute", bind_params, bind_types, 3117639032UL); + + RETURN_CCTOR(records); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _executeUpdate){ + + zval *intermediate, *bind_params, *bind_types; + zval *models, *model_name, *models_instances; + zval *model = NULL, *manager, *connection = NULL, *dialect, *double_colon; + zval *empty_string, *fields, *values, *update_values; + zval *select_bind_params = NULL, *select_bind_types = NULL; + zval *null_value, *field = NULL, *number = NULL, *field_name = NULL; + zval *value = NULL, *type = NULL, *expr_value = NULL, *update_value = NULL; + zval *update_expr = NULL, *wildcard = NULL, *exception_message = NULL; + zval *records, *success = NULL, *record = NULL; + zval *r0 = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &intermediate, &bind_params, &bind_types); + + PHALCON_OBS_VAR(models); + phalcon_array_fetch_quick_string(&models, intermediate, SS("models"), 3565348937UL, PH_NOISY); + if (phalcon_array_isset_long(models, 1)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Updating several models at the same time is still not supported"); + return; + } + + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); + + PHALCON_OBS_VAR(models_instances); + phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); + if (phalcon_array_isset(models_instances, model_name)) { + PHALCON_OBS_VAR(model); + phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); + } else { + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); + + PHALCON_INIT_VAR(dialect); + phalcon_call_method_key(dialect, connection, "getdialect", 3133083739UL); + + PHALCON_INIT_VAR(double_colon); + ZVAL_STRING(double_colon, ":", 1); + + PHALCON_INIT_VAR(empty_string); + ZVAL_STRING(empty_string, "", 1); + + PHALCON_OBS_VAR(fields); + phalcon_array_fetch_quick_string(&fields, intermediate, SS("fields"), 2881624156UL, PH_NOISY); + + PHALCON_OBS_VAR(values); + phalcon_array_fetch_quick_string(&values, intermediate, SS("values"), 1765818005UL, PH_NOISY); + + PHALCON_INIT_VAR(update_values); + array_init(update_values); + + PHALCON_CPY_WRT(select_bind_params, bind_params); + PHALCON_CPY_WRT(select_bind_types, bind_types); + + PHALCON_INIT_VAR(null_value); + + phalcon_is_iterable(fields, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(number, ah0, hp0); + PHALCON_GET_HVALUE(field); + + PHALCON_OBS_NVAR(field_name); + phalcon_array_fetch_quick_string(&field_name, field, SS("name"), 268211462UL, PH_NOISY); + + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, values, number, PH_NOISY); + + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, value, SS("type"), 276192743UL, PH_NOISY); + + PHALCON_OBS_NVAR(expr_value); + phalcon_array_fetch_quick_string(&expr_value, value, SS("value"), 574111618UL, PH_NOISY); + + switch (phalcon_get_intval(type)) { + + case 260: + PHALCON_INIT_NVAR(update_value); + phalcon_call_method_p1_key(update_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; + + case 258: + PHALCON_INIT_NVAR(update_value); + phalcon_call_method_p1_key(update_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; + + case 259: + PHALCON_INIT_NVAR(update_value); + phalcon_call_method_p1_key(update_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; + + case 322: + PHALCON_CPY_WRT(update_value, null_value); + break; + + case 273: + if (Z_TYPE_P(bind_params) == IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Bound parameter cannot be replaced because placeholders is not an array"); + return; + } + + PHALCON_INIT_NVAR(update_expr); + phalcon_call_method_p1_key(update_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); + + PHALCON_INIT_NVAR(wildcard); + phalcon_fast_str_replace(wildcard, double_colon, empty_string, update_expr); + if (phalcon_array_isset(bind_params, wildcard)) { + PHALCON_OBS_NVAR(update_value); + phalcon_array_fetch(&update_value, bind_params, wildcard, PH_NOISY); + phalcon_array_unset(&select_bind_params, wildcard, PH_SEPARATE); + phalcon_array_unset(&select_bind_types, wildcard, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Bound parameter '", wildcard, "' cannot be replaced because it's not in the placeholders list"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + break; + + case 274: + if (Z_TYPE_P(bind_params) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Bound parameter cannot be replaced because placeholders is not an array"); + return; + } + + PHALCON_INIT_NVAR(update_expr); + phalcon_call_method_p1_key(update_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); + + PHALCON_INIT_NVAR(wildcard); + phalcon_fast_str_replace(wildcard, double_colon, empty_string, update_expr); + if (phalcon_array_isset(bind_params, wildcard)) { + PHALCON_OBS_NVAR(update_value); + phalcon_array_fetch(&update_value, bind_params, wildcard, PH_NOISY); + phalcon_array_unset(&select_bind_params, wildcard, PH_SEPARATE); + phalcon_array_unset(&select_bind_types, wildcard, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Bound parameter '", wildcard, "' cannot be replaced because it's not in the placeholders list"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + break; + + default: + PHALCON_INIT_NVAR(update_expr); + phalcon_call_method_p1_key(update_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); + + PHALCON_INIT_NVAR(update_value); + object_init_ex(update_value, phalcon_db_rawvalue_ce); + phalcon_call_method_p1_key(NULL, update_value, "__construct", update_expr, 1107214344UL); + + break; + + } + phalcon_array_update_zval(&update_values, field_name, &update_value, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(records); + phalcon_call_method_p4_key(records, this_ptr, "_getrelatedrecords", model, intermediate, select_bind_params, select_bind_types, 1071693079UL); + + if (!phalcon_fast_count_ev(records TSRMLS_CC)) { + PHALCON_INIT_VAR(success); + ZVAL_BOOL(success, 1); + object_init_ex(return_value, phalcon_mvc_model_query_status_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", success, null_value, 1107214344UL); + + RETURN_MM(); + } + + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); + + phalcon_call_method_key(NULL, connection, "begin", 4090922282UL); + phalcon_call_method_key(NULL, records, "rewind", 1064078190UL); + + while (1) { + + PHALCON_INIT_NVAR(r0); + phalcon_call_method_key(r0, records, "valid", 574098517UL); + if (PHALCON_IS_NOT_FALSE(r0)) { + } else { + break; } -// 1808 "scanner.c" -kk167: - kkch = *++KKCURSOR; - switch (kkch) { - case 'C': - case 'c': goto kk168; - default: goto kk100; - } -kk168: - kkch = *++KKCURSOR; - switch (kkch) { - case 'R': - case 'r': goto kk169; - default: goto kk100; - } -kk169: - kkch = *++KKCURSOR; - switch (kkch) { - case 'O': - case 'o': goto kk170; - default: goto kk100; - } -kk170: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk171; - } -kk171: -// 285 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_MACRO; - return 0; + + PHALCON_INIT_NVAR(record); + phalcon_call_method_key(record, records, "current", 431662984UL); + + PHALCON_INIT_NVAR(success); + phalcon_call_method_p1_key(success, record, "update", update_values, 1051190696UL); + if (!zend_is_true(success)) { + phalcon_call_method_key(NULL, connection, "rollback", 3199546639UL); + object_init_ex(return_value, phalcon_mvc_model_query_status_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", success, record, 1107214344UL); + + RETURN_MM(); } -// 1906 "scanner.c" -kk172: - kkch = *++KKCURSOR; - switch (kkch) { - case 'O': - case 'o': goto kk178; - default: goto kk100; - } -kk173: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk174; - default: goto kk100; - } -kk174: - kkch = *++KKCURSOR; - switch (kkch) { - case 'A': - case 'a': goto kk175; - default: goto kk100; - } -kk175: - kkch = *++KKCURSOR; - switch (kkch) { - case 'K': - case 'k': goto kk176; - default: goto kk100; - } -kk176: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk177; - } -kk177: -// 382 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_BREAK; - return 0; + + phalcon_call_method_key(NULL, records, "next", 268367684UL); + } + + phalcon_call_method_key(NULL, connection, "commit", 3546528686UL); + + PHALCON_INIT_NVAR(success); + ZVAL_BOOL(success, 1); + object_init_ex(return_value, phalcon_mvc_model_query_status_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", success, null_value, 1107214344UL); + + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, _executeDelete){ + + zval *intermediate, *bind_params, *bind_types; + zval *models, *model_name, *models_instances; + zval *model = NULL, *manager, *records, *success = NULL, *null_value = NULL; + zval *connection, *record = NULL; + zval *r0 = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &intermediate, &bind_params, &bind_types); + + PHALCON_OBS_VAR(models); + phalcon_array_fetch_quick_string(&models, intermediate, SS("models"), 3565348937UL, PH_NOISY); + if (phalcon_array_isset_long(models, 1)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Delete from several models at the same time is still not supported"); + return; + } + + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); + + PHALCON_OBS_VAR(models_instances); + phalcon_read_property_this_quick(&models_instances, this_ptr, SL("_modelsInstances"), 457905456UL, PH_NOISY_CC); + if (phalcon_array_isset(models_instances, model_name)) { + PHALCON_OBS_VAR(model); + phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); + } else { + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + } + + PHALCON_INIT_VAR(records); + phalcon_call_method_p4_key(records, this_ptr, "_getrelatedrecords", model, intermediate, bind_params, bind_types, 1071693079UL); + + if (!phalcon_fast_count_ev(records TSRMLS_CC)) { + PHALCON_INIT_VAR(success); + ZVAL_BOOL(success, 1); + + PHALCON_INIT_VAR(null_value); + object_init_ex(return_value, phalcon_mvc_model_query_status_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", success, null_value, 1107214344UL); + + RETURN_MM(); + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); + + phalcon_call_method_key(NULL, connection, "begin", 4090922282UL); + phalcon_call_method_key(NULL, records, "rewind", 1064078190UL); + + while (1) { + + PHALCON_INIT_NVAR(r0); + phalcon_call_method_key(r0, records, "valid", 574098517UL); + if (PHALCON_IS_NOT_FALSE(r0)) { + } else { + break; } -// 2011 "scanner.c" -kk178: - kkch = *++KKCURSOR; - switch (kkch) { - case 'C': - case 'c': goto kk179; - default: goto kk100; - } -kk179: - kkch = *++KKCURSOR; - switch (kkch) { - case 'K': - case 'k': goto kk180; - default: goto kk100; - } -kk180: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk181; - } -kk181: -// 274 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_BLOCK; - return 0; + + PHALCON_INIT_NVAR(record); + phalcon_call_method_key(record, records, "current", 431662984UL); + + PHALCON_INIT_NVAR(success); + phalcon_call_method_key(success, record, "delete", 150213496UL); + if (!zend_is_true(success)) { + phalcon_call_method_key(NULL, connection, "rollback", 3199546639UL); + object_init_ex(return_value, phalcon_mvc_model_query_status_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", success, record, 1107214344UL); + + RETURN_MM(); } -// 2102 "scanner.c" -kk182: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk183; - } -kk183: -// 269 "scanner.re" - { - token->opcode = PHVOLT_T_OR; - return 0; + + phalcon_call_method_key(NULL, records, "next", 268367684UL); + } + + phalcon_call_method_key(NULL, connection, "commit", 3546528686UL); + + PHALCON_INIT_NVAR(success); + ZVAL_BOOL(success, 1); + + PHALCON_INIT_NVAR(null_value); + ZVAL_BOOL(null_value, 1); + + object_init_ex(return_value, phalcon_mvc_model_query_status_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", success, null_value, 1107214344UL); + + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, execute){ + + zval *bind_params = NULL, *bind_types = NULL, *unique_row; + zval *cache_options, *key, *lifetime = NULL, *cache_service = NULL; + zval *dependency_injector, *cache, *result = NULL, *is_fresh; + zval *prepared_result = NULL, *intermediate, *default_bind_params; + zval *merged_params = NULL, *default_bind_types; + zval *merged_types = NULL, *type, *exception_message; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &bind_params, &bind_types); + + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); + } + + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } + + PHALCON_OBS_VAR(unique_row); + phalcon_read_property_this_quick(&unique_row, this_ptr, SL("_uniqueRow"), 1221667347UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(cache_options); + phalcon_read_property_this_quick(&cache_options, this_ptr, SL("_cacheOptions"), 528255652UL, PH_NOISY_CC); + if (Z_TYPE_P(cache_options) != IS_NULL) { + if (Z_TYPE_P(cache_options) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid caching options"); + return; } -// 2178 "scanner.c" -kk184: - kkch = *++KKCURSOR; - switch (kkch) { - case 'D': - case 'd': goto kk195; - default: goto kk100; - } -kk185: - kkch = *++KKCURSOR; - switch (kkch) { - case 'T': - case 't': goto kk186; - default: goto kk100; - } -kk186: - kkch = *++KKCURSOR; - switch (kkch) { - case 'O': - case 'o': goto kk187; - default: goto kk100; - } -kk187: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk188; - default: goto kk100; - } -kk188: - kkch = *++KKCURSOR; - switch (kkch) { - case 'S': - case 's': goto kk189; - default: goto kk100; - } -kk189: - kkch = *++KKCURSOR; - switch (kkch) { - case 'C': - case 'c': goto kk190; - default: goto kk100; - } -kk190: - kkch = *++KKCURSOR; - switch (kkch) { - case 'A': - case 'a': goto kk191; - default: goto kk100; - } -kk191: - kkch = *++KKCURSOR; - switch (kkch) { - case 'P': - case 'p': goto kk192; - default: goto kk100; - } -kk192: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk193; - default: goto kk100; + + if (phalcon_array_isset_quick_string(cache_options, SS("key"), 2090432846UL)) { + PHALCON_OBS_VAR(key); + phalcon_array_fetch_quick_string(&key, cache_options, SS("key"), 2090432846UL, PH_NOISY); + } else { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A cache key must be provided to identify the cached resultset in the cache backend"); + return; + } + + if (phalcon_array_isset_quick_string(cache_options, SS("lifetime"), 2639810228UL)) { + PHALCON_OBS_VAR(lifetime); + phalcon_array_fetch_quick_string(&lifetime, cache_options, SS("lifetime"), 2639810228UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(lifetime); + ZVAL_LONG(lifetime, 3600); + } + + if (phalcon_array_isset_quick_string(cache_options, SS("service"), 243174486UL)) { + PHALCON_OBS_VAR(cache_service); + phalcon_array_fetch_quick_string(&cache_service, cache_options, SS("service"), 243174486UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(cache_service); + ZVAL_STRING(cache_service, "modelsCache", 1); + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(cache); + phalcon_call_method_p1_key(cache, dependency_injector, "getshared", cache_service, 1727570332UL); + if (Z_TYPE_P(cache) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The cache service must be an object"); + return; + } + + PHALCON_INIT_VAR(result); + phalcon_call_method_p2_key(result, cache, "get", key, lifetime, 2090288933UL); + if (Z_TYPE_P(result) != IS_NULL) { + if (Z_TYPE_P(result) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The cache didn't return a valid resultset"); + return; } -kk193: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk194; + + PHALCON_INIT_VAR(is_fresh); + ZVAL_BOOL(is_fresh, 0); + phalcon_call_method_p1_key(NULL, result, "setisfresh", is_fresh, 2789062661UL); + + if (zend_is_true(unique_row)) { + PHALCON_INIT_VAR(prepared_result); + phalcon_call_method_key(prepared_result, result, "getfirst", 3710205613UL); + } else { + PHALCON_CPY_WRT(prepared_result, result); } -kk194: -// 364 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_AUTOESCAPE; - return 0; + + RETURN_CCTOR(prepared_result); + } + + phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); + } + + PHALCON_INIT_VAR(intermediate); + phalcon_call_method_key(intermediate, this_ptr, "parse", 339512704UL); + + PHALCON_OBS_VAR(default_bind_params); + phalcon_read_property_this_quick(&default_bind_params, this_ptr, SL("_bindParams"), 2293392709UL, PH_NOISY_CC); + if (Z_TYPE_P(default_bind_params) == IS_ARRAY) { + if (Z_TYPE_P(bind_params) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_params); + phalcon_fast_array_merge(merged_params, &default_bind_params, &bind_params TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_params, default_bind_params); + } + } else { + PHALCON_CPY_WRT(merged_params, bind_params); + } + + PHALCON_OBS_VAR(default_bind_types); + phalcon_read_property_this_quick(&default_bind_types, this_ptr, SL("_bindTypes"), 514734038UL, PH_NOISY_CC); + if (Z_TYPE_P(default_bind_types) == IS_ARRAY) { + if (Z_TYPE_P(bind_types) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_types); + phalcon_fast_array_merge(merged_types, &default_bind_types, &bind_types TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_types, default_bind_types); + } + } else { + PHALCON_CPY_WRT(merged_types, bind_types); + } + + PHALCON_OBS_VAR(type); + phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); + + switch (phalcon_get_intval(type)) { + + case 309: + PHALCON_INIT_NVAR(result); + phalcon_call_method_p3_key(result, this_ptr, "_executeselect", intermediate, merged_params, merged_types, 125194679UL); + break; + + case 306: + PHALCON_INIT_NVAR(result); + phalcon_call_method_p3_key(result, this_ptr, "_executeinsert", intermediate, merged_params, merged_types, 455953196UL); + break; + + case 300: + PHALCON_INIT_NVAR(result); + phalcon_call_method_p3_key(result, this_ptr, "_executeupdate", intermediate, merged_params, merged_types, 3129006842UL); + break; + + case 303: + PHALCON_INIT_NVAR(result); + phalcon_call_method_p3_key(result, this_ptr, "_executedelete", intermediate, merged_params, merged_types, 2228029642UL); + break; + + default: + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Unknown statement ", type); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + + } + + if (Z_TYPE_P(cache_options) != IS_NULL) { + + if (!PHALCON_IS_LONG(type, 309)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Only PHQL statements that return resultsets can be cached"); + return; + } + phalcon_call_method_p3_key(NULL, cache, "save", key, result, lifetime, 274150868UL); + } + + if (zend_is_true(unique_row)) { + PHALCON_INIT_NVAR(prepared_result); + phalcon_call_method_key(prepared_result, result, "getfirst", 3710205613UL); + } else { + PHALCON_CPY_WRT(prepared_result, result); + } + + RETURN_CCTOR(prepared_result); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, getSingleResult){ + + zval *bind_params = NULL, *bind_types = NULL, *unique_row; + zval *result = NULL, *first_result; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &bind_params, &bind_types); + + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); + } + + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } + + PHALCON_OBS_VAR(unique_row); + phalcon_read_property_this_quick(&unique_row, this_ptr, SL("_uniqueRow"), 1221667347UL, PH_NOISY_CC); + + if (zend_is_true(unique_row)) { + PHALCON_INIT_VAR(result); + phalcon_call_method_p2_key(result, this_ptr, "execute", bind_params, bind_types, 3117639032UL); + RETURN_CCTOR(result); + } + + PHALCON_INIT_NVAR(result); + phalcon_call_method_p2_key(result, this_ptr, "execute", bind_params, bind_types, 3117639032UL); + + PHALCON_INIT_VAR(first_result); + phalcon_call_method_key(first_result, result, "getfirst", 3710205613UL); + + RETURN_CCTOR(result); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, setType){ + + zval *type; + + phalcon_fetch_params(0, 1, 0, &type); + + phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, getType){ + + + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, setBindParams){ + + zval *bind_params; + + phalcon_fetch_params(0, 1, 0, &bind_params); + + if (Z_TYPE_P(bind_params) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Bind parameters must be an array"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_bindParams"), bind_params, 2293392709UL TSRMLS_CC); + + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, getBindParams){ + + + RETURN_MEMBER_QUICK(this_ptr, "_bindParams", 2293392709UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, setBindTypes){ + + zval *bind_types; + + phalcon_fetch_params(0, 1, 0, &bind_types); + + if (Z_TYPE_P(bind_types) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Bind types must be an array"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_bindTypes"), bind_types, 514734038UL TSRMLS_CC); + + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, getBindTypes){ + + + RETURN_MEMBER_QUICK(this_ptr, "_bindTypes", 514734038UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, setIntermediate){ + + zval *intermediate; + + phalcon_fetch_params(0, 1, 0, &intermediate); + + phalcon_update_property_this_quick(this_ptr, SL("_intermediate"), intermediate, 1829292799UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, getIntermediate){ + + + RETURN_MEMBER_QUICK(this_ptr, "_intermediate", 1829292799UL); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_QueryInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, QueryInterface, mvc_model_queryinterface, phalcon_mvc_model_queryinterface_method_entry); + + return SUCCESS; +} + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Relation){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Relation, mvc_model_relation, phalcon_mvc_model_relation_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_referencedModel"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_fields"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_referencedFields"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_intermediateModel"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_intermediateFields"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_intermediateReferencedFields"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_relation_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("BELONGS_TO"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("HAS_ONE"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("HAS_MANY"), 2 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("HAS_ONE_THROUGH"), 3 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("HAS_MANY_THROUGH"), 4 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("NO_ACTION"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("ACTION_RESTRICT"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_relation_ce, SL("ACTION_CASCADE"), 2 TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_relation_ce TSRMLS_CC, 1, phalcon_mvc_model_relationinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, __construct){ + + zval *type, *referenced_model, *fields, *referenced_fields; + zval *options = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 4, 1, &type, &referenced_model, &fields, &referenced_fields, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } + + phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_referencedModel"), referenced_model, 4077480136UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_fields"), fields, 3492004987UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_referencedFields"), referenced_fields, 729137326UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, setIntermediateRelation){ + + zval *intermediate_fields, *intermediate_model; + zval *intermediate_referenced_fields; + + phalcon_fetch_params(0, 3, 0, &intermediate_fields, &intermediate_model, &intermediate_referenced_fields); + + phalcon_update_property_this_quick(this_ptr, SL("_intermediateFields"), intermediate_fields, 1022734614UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_intermediateModel"), intermediate_model, 312011824UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_intermediateReferencedFields"), intermediate_referenced_fields, 3351276297UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, getType){ + + + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, getReferencedModel){ + + + RETURN_MEMBER_QUICK(this_ptr, "_referencedModel", 4077480136UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, getFields){ + + + RETURN_MEMBER_QUICK(this_ptr, "_fields", 3492004987UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, getReferencedFields){ + + + RETURN_MEMBER_QUICK(this_ptr, "_referencedFields", 729137326UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, getOptions){ + + + RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, isForeignKey){ + + zval *options; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (Z_TYPE_P(options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(options, SS("foreignKey"), 1865016664UL)) { + RETURN_MM_TRUE; } -// 2318 "scanner.c" -kk195: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk196; + } + + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, getForeignKey){ + + zval *options, *foreign_key; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (Z_TYPE_P(options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(options, SS("foreignKey"), 1865016664UL)) { + + PHALCON_OBS_VAR(foreign_key); + phalcon_array_fetch_quick_string(&foreign_key, options, SS("foreignKey"), 1865016664UL, PH_NOISY); + if (zend_is_true(foreign_key)) { + RETURN_CCTOR(foreign_key); } -kk196: -// 264 "scanner.re" - { - token->opcode = PHVOLT_T_AND; - return 0; } -// 2394 "scanner.c" -kk197: - kkch = *++KKCURSOR; - switch (kkch) { - case 'U': - case 'u': goto kk198; - default: goto kk100; - } -kk198: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk199; - default: goto kk100; - } -kk199: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk200; - } -kk200: -// 259 "scanner.re" - { - token->opcode = PHVOLT_T_TRUE; - return 0; + } + + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, isThrough){ + + zval *type; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(type); + phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); + if (PHALCON_IS_LONG(type, 3)) { + RETURN_MM_TRUE; + } else { + if (PHALCON_IS_LONG(type, 4)) { + RETURN_MM_TRUE; } -// 2484 "scanner.c" -kk201: - kkch = *++KKCURSOR; - switch (kkch) { - case 'T': - case 't': goto kk206; - default: goto kk100; - } -kk202: - kkch = *++KKCURSOR; - switch (kkch) { - case 'L': - case 'l': goto kk203; - default: goto kk100; - } -kk203: - kkch = *++KKCURSOR; - switch (kkch) { - case 'L': - case 'l': goto kk204; - default: goto kk100; - } -kk204: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk205; - } -kk205: -// 249 "scanner.re" - { - token->opcode = PHVOLT_T_NULL; - return 0; + } + + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, isReusable){ + + zval *options, *reusable; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (Z_TYPE_P(options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(options, SS("reusable"), 1227996376UL)) { + PHALCON_OBS_VAR(reusable); + phalcon_array_fetch_quick_string(&reusable, options, SS("reusable"), 1227996376UL, PH_NOISY); + RETURN_CCTOR(reusable); } -// 2581 "scanner.c" -kk206: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk207; - } -kk207: -// 329 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_NOT; - return 0; + } + + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, getIntermediateFields){ + + + RETURN_MEMBER_QUICK(this_ptr, "_intermediateFields", 1022734614UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, getIntermediateModel){ + + + RETURN_MEMBER_QUICK(this_ptr, "_intermediateModel", 312011824UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Relation, getIntermediateReferencedFields){ + + + RETURN_MEMBER_QUICK(this_ptr, "_intermediateReferencedFields", 3351276297UL); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_RelationInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, RelationInterface, mvc_model_relationinterface, phalcon_mvc_model_relationinterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_ResultInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, ResultInterface, mvc_model_resultinterface, phalcon_mvc_model_resultinterface_method_entry); + + return SUCCESS; +} + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Resultset_Complex){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Resultset, Complex, mvc_model_resultset_complex, "phalcon\\mvc\\model\\resultset", phalcon_mvc_model_resultset_complex_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_model_resultset_complex_ce, SL("_columnTypes"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_resultset_complex_ce TSRMLS_CC, 1, phalcon_mvc_model_resultsetinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, __construct){ + + zval *columns_types, *result, *cache = NULL, *fetch_assoc; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 1, &columns_types, &result, &cache); + + if (!cache) { + PHALCON_INIT_VAR(cache); + } + + phalcon_update_property_this_quick(this_ptr, SL("_columnTypes"), columns_types, 204488327UL TSRMLS_CC); + + phalcon_update_property_this_quick(this_ptr, SL("_result"), result, 1670144931UL TSRMLS_CC); + + if (Z_TYPE_P(cache) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); + } + + phalcon_update_property_long(this_ptr, SL("_type"), 1 TSRMLS_CC); + + if (Z_TYPE_P(result) == IS_OBJECT) { + PHALCON_INIT_VAR(fetch_assoc); + ZVAL_LONG(fetch_assoc, 1); + phalcon_call_method_p1_key(NULL, result, "setfetchmode", fetch_assoc, 824603840UL); + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, valid){ + + zval *type = NULL, *result, *row = NULL, *rows, *hydrate_mode, *underscore; + zval *empty_str, *active_row = NULL, *columns_types; + zval *dirty_state, *column = NULL, *alias = NULL, *source = NULL, *attributes = NULL; + zval *column_map = NULL, *row_model = NULL, *attribute = NULL, *column_alias = NULL; + zval *column_value = NULL, *keep_snapshots = NULL, *instance = NULL; + zval *value = NULL, *sql_alias = NULL, *n_alias = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(type); + phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); + if (zend_is_true(type)) { + + PHALCON_OBS_VAR(result); + phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); + if (PHALCON_IS_NOT_FALSE(result)) { + PHALCON_INIT_VAR(row); + phalcon_call_method_p1_key(row, result, "fetch", result, 4247924303UL); + } else { + PHALCON_INIT_NVAR(row); + ZVAL_BOOL(row, 0); } -// 2658 "scanner.c" -kk208: - kkch = *++KKCURSOR; - switch (kkch) { - case 'T': - case 't': goto kk209; - default: goto kk100; - } -kk209: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk210; + } else { + PHALCON_OBS_VAR(rows); + phalcon_read_property_this_quick(&rows, this_ptr, SL("_rows"), 3989235983UL, PH_NOISY_CC); + if (Z_TYPE_P(rows) == IS_ARRAY) { + + PHALCON_INIT_NVAR(row); + phalcon_array_get_current(row, rows); + if (Z_TYPE_P(row) == IS_OBJECT) { + phalcon_array_next(rows); } -kk210: -// 244 "scanner.re" - { - token->opcode = PHVOLT_T_SET; - return 0; + } else { + PHALCON_INIT_NVAR(row); + ZVAL_BOOL(row, 0); } -// 2741 "scanner.c" -kk211: - kkch = *++KKCURSOR; - switch (kkch) { - case 'L': - case 'l': goto kk215; - default: goto kk100; - } -kk212: - kkch = *++KKCURSOR; - switch (kkch) { - case 'R': - case 'r': goto kk213; - default: goto kk100; + } + + if (Z_TYPE_P(row) == IS_ARRAY || Z_TYPE_P(row) == IS_OBJECT) { + + if (zend_is_true(type)) { + + PHALCON_OBS_VAR(hydrate_mode); + phalcon_read_property_this_quick(&hydrate_mode, this_ptr, SL("_hydrateMode"), 2551752186UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(underscore); + ZVAL_STRING(underscore, "_", 1); + + PHALCON_INIT_VAR(empty_str); + ZVAL_STRING(empty_str, "", 1); + + + switch (phalcon_get_intval(hydrate_mode)) { + + case 0: + PHALCON_INIT_VAR(active_row); + object_init_ex(active_row, phalcon_mvc_model_row_ce); + break; + + case 1: + PHALCON_INIT_NVAR(active_row); + array_init(active_row); + break; + + case 2: + PHALCON_INIT_NVAR(active_row); + object_init(active_row); + break; + } -kk213: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk214; + + PHALCON_OBS_VAR(columns_types); + phalcon_read_property_this_quick(&columns_types, this_ptr, SL("_columnTypes"), 204488327UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(dirty_state); + ZVAL_LONG(dirty_state, 0); + + phalcon_is_iterable(columns_types, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(alias, ah0, hp0); + PHALCON_GET_HVALUE(column); + + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, column, SS("type"), 276192743UL, PH_NOISY); + if (PHALCON_IS_STRING(type, "object")) { + + PHALCON_OBS_NVAR(source); + phalcon_array_fetch_quick_string(&source, column, SS("column"), 3545634419UL, PH_NOISY); + + PHALCON_OBS_NVAR(attributes); + phalcon_array_fetch_quick_string(&attributes, column, SS("attributes"), 3318431052UL, PH_NOISY); + + PHALCON_OBS_NVAR(column_map); + phalcon_array_fetch_quick_string(&column_map, column, SS("columnMap"), 672221649UL, PH_NOISY); + + PHALCON_INIT_NVAR(row_model); + array_init(row_model); + + phalcon_is_iterable(attributes, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(attribute); + + PHALCON_INIT_NVAR(column_alias); + PHALCON_CONCAT_VVVV(column_alias, underscore, source, underscore, attribute); + + PHALCON_OBS_NVAR(column_value); + phalcon_array_fetch(&column_value, row, column_alias, PH_NOISY); + phalcon_array_update_zval(&row_model, attribute, &column_value, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); + } + + + switch (phalcon_get_intval(hydrate_mode)) { + + case 0: + if (phalcon_array_isset_quick_string(column, SS("keepSnapshots"), 1820056717UL)) { + PHALCON_OBS_NVAR(keep_snapshots); + phalcon_array_fetch_quick_string(&keep_snapshots, column, SS("keepSnapshots"), 1820056717UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(keep_snapshots); + ZVAL_BOOL(keep_snapshots, 0); + } + + PHALCON_OBS_NVAR(instance); + phalcon_array_fetch_quick_string(&instance, column, SS("instance"), 3884539162UL, PH_NOISY); + + PHALCON_INIT_NVAR(value); + PHALCON_CALL_STATIC_PARAMS_5(value, "phalcon\\mvc\\model", "cloneresultmap", instance, row_model, column_map, dirty_state, keep_snapshots); + break; + + default: + PHALCON_INIT_NVAR(value); + PHALCON_CALL_STATIC_PARAMS_3(value, "phalcon\\mvc\\model", "cloneresultmaphydrate", row_model, column_map, hydrate_mode); + break; + + } + + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_quick_string(&attribute, column, SS("balias"), 1705826801UL, PH_NOISY); + } else { + if (phalcon_array_isset_quick_string(column, SS("sqlAlias"), 2820722015UL)) { + PHALCON_OBS_NVAR(sql_alias); + phalcon_array_fetch_quick_string(&sql_alias, column, SS("sqlAlias"), 2820722015UL, PH_NOISY); + + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, row, sql_alias, PH_NOISY); + } else { + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, row, alias, PH_NOISY); + } + + if (phalcon_array_isset_quick_string(column, SS("balias"), 1705826801UL)) { + PHALCON_CPY_WRT(attribute, alias); + } else { + PHALCON_INIT_NVAR(n_alias); + phalcon_fast_str_replace(n_alias, underscore, empty_str, alias); + PHALCON_CPY_WRT(attribute, n_alias); + } + } + + + switch (phalcon_get_intval(hydrate_mode)) { + + case 1: + phalcon_array_update_zval(&active_row, attribute, &value, PH_COPY | PH_SEPARATE); + break; + + default: + phalcon_update_property_zval_zval(active_row, attribute, value TSRMLS_CC); + break; + + } + + zend_hash_move_forward_ex(ah0, &hp0); } -kk214: -// 228 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_FOR; - return 0; + + phalcon_update_property_this_quick(this_ptr, SL("_activeRow"), active_row, 3086770360UL TSRMLS_CC); + } else { + phalcon_update_property_this_quick(this_ptr, SL("_activeRow"), row, 3086770360UL TSRMLS_CC); + } + RETURN_MM_TRUE; + } + + phalcon_update_property_bool(this_ptr, SL("_activeRow"), 0 TSRMLS_CC); + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, toArray){ + + zval *records, *valid = NULL, *current = NULL; + zval *r0 = NULL; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(records); + array_init(records); + phalcon_call_method_key(NULL, this_ptr, "rewind", 1064078190UL); + + while (1) { + + PHALCON_INIT_NVAR(r0); + phalcon_call_method_key(r0, this_ptr, "valid", 574098517UL); + PHALCON_CPY_WRT(valid, r0); + if (PHALCON_IS_NOT_FALSE(valid)) { + } else { + break; + } + + PHALCON_INIT_NVAR(current); + phalcon_call_method_key(current, this_ptr, "current", 431662984UL); + phalcon_array_append(&records, current, PH_SEPARATE); + phalcon_call_method_key(NULL, this_ptr, "next", 268367684UL); + } + + RETURN_CTOR(records); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, serialize){ + + zval *records, *cache, *column_types, *hydrate_mode; + zval *data, *serialized; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(records); + phalcon_call_method_key(records, this_ptr, "toarray", 3566966151UL); + + PHALCON_OBS_VAR(cache); + phalcon_read_property_this_quick(&cache, this_ptr, SL("_cache"), 2191407384UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(column_types); + phalcon_read_property_this_quick(&column_types, this_ptr, SL("_columnTypes"), 204488327UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(hydrate_mode); + phalcon_read_property_this_quick(&hydrate_mode, this_ptr, SL("_hydrateMode"), 2551752186UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(data); + array_init_size(data, 4); + phalcon_array_update_quick_string(&data, SS("cache"), 4125168857UL, &cache, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("rows"), 273469616UL, &records, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("columnTypes"), 2207459080UL, &column_types, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("hydrateMode"), 259755643UL, &hydrate_mode, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(serialized); + phalcon_serialize(serialized, &data TSRMLS_CC); + + if (Z_TYPE_P(serialized) != IS_STRING) { + RETURN_MM_NULL(); + } + + RETURN_CTOR(serialized); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, unserialize){ + + zval *data, *resultset, *rows, *cache, *column_types; + zval *hydrate_mode; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &data); + + phalcon_update_property_long(this_ptr, SL("_type"), 0 TSRMLS_CC); + + PHALCON_INIT_VAR(resultset); + phalcon_unserialize(resultset, data TSRMLS_CC); + if (Z_TYPE_P(resultset) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid serialization data"); + return; + } + + PHALCON_OBS_VAR(rows); + phalcon_array_fetch_quick_string(&rows, resultset, SS("rows"), 273469616UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_rows"), rows, 3989235983UL TSRMLS_CC); + + PHALCON_OBS_VAR(cache); + phalcon_array_fetch_quick_string(&cache, resultset, SS("cache"), 4125168857UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); + + PHALCON_OBS_VAR(column_types); + phalcon_array_fetch_quick_string(&column_types, resultset, SS("columnTypes"), 2207459080UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_columnTypes"), column_types, 204488327UL TSRMLS_CC); + + PHALCON_OBS_VAR(hydrate_mode); + phalcon_array_fetch_quick_string(&hydrate_mode, resultset, SS("hydrateMode"), 259755643UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_hydrateMode"), hydrate_mode, 2551752186UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Resultset_Simple){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Resultset, Simple, mvc_model_resultset_simple, "phalcon\\mvc\\model\\resultset", phalcon_mvc_model_resultset_simple_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_model_resultset_simple_ce, SL("_model"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_resultset_simple_ce, SL("_columnMap"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_model_resultset_simple_ce, SL("_keepSnapshots"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_resultset_simple_ce TSRMLS_CC, 5, zend_ce_iterator, spl_ce_SeekableIterator, spl_ce_Countable, zend_ce_arrayaccess, zend_ce_serializable); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, __construct){ + + zval *column_map, *model, *result, *cache = NULL, *keep_snapshots = NULL; + zval *fetch_assoc, *limit, *row_count, *big_resultset; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 2, &column_map, &model, &result, &cache, &keep_snapshots); + + if (!cache) { + PHALCON_INIT_VAR(cache); + } + + if (!keep_snapshots) { + PHALCON_INIT_VAR(keep_snapshots); + } + + phalcon_update_property_this_quick(this_ptr, SL("_model"), model, 2599397109UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_result"), result, 1670144931UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_columnMap"), column_map, 1530164624UL TSRMLS_CC); + if (Z_TYPE_P(result) != IS_OBJECT) { + RETURN_MM_NULL(); + } + + PHALCON_INIT_VAR(fetch_assoc); + ZVAL_LONG(fetch_assoc, 1); + phalcon_call_method_p1_key(NULL, result, "setfetchmode", fetch_assoc, 824603840UL); + + PHALCON_INIT_VAR(limit); + ZVAL_LONG(limit, 32); + + PHALCON_INIT_VAR(row_count); + phalcon_call_method_key(row_count, result, "numrows", 887792640UL); + + PHALCON_INIT_VAR(big_resultset); + is_smaller_function(big_resultset, limit, row_count TSRMLS_CC); + if (PHALCON_IS_TRUE(big_resultset)) { + phalcon_update_property_long(this_ptr, SL("_type"), 1 TSRMLS_CC); + } else { + phalcon_update_property_long(this_ptr, SL("_type"), 0 TSRMLS_CC); + } + + phalcon_update_property_this_quick(this_ptr, SL("_count"), row_count, 2208664173UL TSRMLS_CC); + + phalcon_update_property_this_quick(this_ptr, SL("_keepSnapshots"), keep_snapshots, 2428293068UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, valid){ + + zval *type, *result = NULL, *row = NULL, *rows = NULL, *dirty_state, *hydrate_mode; + zval *keep_snapshots, *column_map, *model, *active_row = NULL; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(type); + phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); + if (zend_is_true(type)) { + + PHALCON_OBS_VAR(result); + phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); + if (Z_TYPE_P(result) == IS_OBJECT) { + PHALCON_INIT_VAR(row); + phalcon_call_method_p1_key(row, result, "fetch", result, 4247924303UL); + } else { + PHALCON_INIT_NVAR(row); + ZVAL_BOOL(row, 0); } -// 2832 "scanner.c" -kk215: - kkch = *++KKCURSOR; - switch (kkch) { - case 'S': - case 's': goto kk216; - default: goto kk100; - } -kk216: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk217; - default: goto kk100; - } -kk217: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk218; + } else { + PHALCON_OBS_VAR(rows); + phalcon_read_property_this_quick(&rows, this_ptr, SL("_rows"), 3989235983UL, PH_NOISY_CC); + if (Z_TYPE_P(rows) != IS_ARRAY) { + + PHALCON_OBS_NVAR(result); + phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); + if (Z_TYPE_P(result) == IS_OBJECT) { + PHALCON_INIT_NVAR(rows); + phalcon_call_method_key(rows, result, "fetchall", 1636682248UL); + phalcon_update_property_this_quick(this_ptr, SL("_rows"), rows, 3989235983UL TSRMLS_CC); } -kk218: -// 254 "scanner.re" - { - token->opcode = PHVOLT_T_FALSE; - return 0; } -// 2922 "scanner.c" -kk219: - kkch = *++KKCURSOR; - switch (kkch) { - case 'S': - case 's': goto kk268; - default: goto kk100; - } -kk220: - kkch = *++KKCURSOR; - switch (kkch) { - case 'D': - case 'd': goto kk228; - default: goto kk100; - } -kk221: - kkch = *++KKCURSOR; - switch (kkch) { - case 'T': - case 't': goto kk222; - default: goto kk100; - } -kk222: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk223; - default: goto kk100; + + if (Z_TYPE_P(rows) == IS_ARRAY) { + + PHALCON_INIT_NVAR(row); + phalcon_array_get_current(row, rows); + if (PHALCON_IS_NOT_FALSE(row)) { + phalcon_array_next(rows); } -kk223: - kkch = *++KKCURSOR; - switch (kkch) { - case 'N': - case 'n': goto kk224; - default: goto kk100; + } else { + PHALCON_INIT_NVAR(row); + ZVAL_BOOL(row, 0); + } + } + + if (Z_TYPE_P(row) != IS_ARRAY) { + phalcon_update_property_bool(this_ptr, SL("_activeRow"), 0 TSRMLS_CC); + RETURN_MM_FALSE; + } + + PHALCON_INIT_VAR(dirty_state); + ZVAL_LONG(dirty_state, 0); + + PHALCON_OBS_VAR(hydrate_mode); + phalcon_read_property_this_quick(&hydrate_mode, this_ptr, SL("_hydrateMode"), 2551752186UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(keep_snapshots); + phalcon_read_property_this_quick(&keep_snapshots, this_ptr, SL("_keepSnapshots"), 2428293068UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(column_map); + phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); + + + switch (phalcon_get_intval(hydrate_mode)) { + + case 0: + PHALCON_OBS_VAR(model); + phalcon_read_property_this_quick(&model, this_ptr, SL("_model"), 2599397109UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(active_row); + PHALCON_CALL_STATIC_PARAMS_5(active_row, "phalcon\\mvc\\model", "cloneresultmap", model, row, column_map, dirty_state, keep_snapshots); + break; + + default: + PHALCON_INIT_NVAR(active_row); + PHALCON_CALL_STATIC_PARAMS_3(active_row, "phalcon\\mvc\\model", "cloneresultmaphydrate", row, column_map, hydrate_mode); + break; + + } + phalcon_update_property_this_quick(this_ptr, SL("_activeRow"), active_row, 3086770360UL TSRMLS_CC); + RETURN_MM_TRUE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, toArray){ + + zval *rename_columns = NULL, *type, *result = NULL, *active_row = NULL; + zval *records = NULL, *row_count, *column_map, *renamed_records; + zval *record = NULL, *renamed = NULL, *value = NULL, *key = NULL, *exception_message = NULL; + zval *renamed_key = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &rename_columns); + + if (!rename_columns) { + PHALCON_INIT_VAR(rename_columns); + ZVAL_BOOL(rename_columns, 1); + } + + PHALCON_OBS_VAR(type); + phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); + if (zend_is_true(type)) { + + PHALCON_OBS_VAR(result); + phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); + if (Z_TYPE_P(result) == IS_OBJECT) { + + PHALCON_OBS_VAR(active_row); + phalcon_read_property_this_quick(&active_row, this_ptr, SL("_activeRow"), 3086770360UL, PH_NOISY_CC); + + if (Z_TYPE_P(active_row) != IS_NULL) { + phalcon_call_method_key(NULL, result, "execute", 3117639032UL); } -kk224: - kkch = *++KKCURSOR; - switch (kkch) { - case 'D': - case 'd': goto kk225; - default: goto kk100; + + PHALCON_INIT_VAR(records); + phalcon_call_method_key(records, result, "fetchall", 1636682248UL); + } else { + PHALCON_INIT_NVAR(records); + array_init(records); + } + } else { + PHALCON_OBS_NVAR(records); + phalcon_read_property_this_quick(&records, this_ptr, SL("_rows"), 3989235983UL, PH_NOISY_CC); + if (Z_TYPE_P(records) != IS_ARRAY) { + + PHALCON_OBS_NVAR(result); + phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); + if (Z_TYPE_P(result) == IS_OBJECT) { + + PHALCON_OBS_NVAR(active_row); + phalcon_read_property_this_quick(&active_row, this_ptr, SL("_activeRow"), 3086770360UL, PH_NOISY_CC); + + if (Z_TYPE_P(active_row) != IS_NULL) { + phalcon_call_method_key(NULL, result, "execute", 3117639032UL); + } + + PHALCON_INIT_NVAR(records); + phalcon_call_method_key(records, result, "fetchall", 1636682248UL); + phalcon_update_property_this_quick(this_ptr, SL("_rows"), records, 3989235983UL TSRMLS_CC); + + PHALCON_INIT_VAR(row_count); + phalcon_fast_count(row_count, records TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_count"), row_count, 2208664173UL TSRMLS_CC); } -kk225: - kkch = *++KKCURSOR; - switch (kkch) { - case 'S': - case 's': goto kk226; - default: goto kk100; + } + } + + if (zend_is_true(rename_columns)) { + + PHALCON_OBS_VAR(column_map); + phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); + if (Z_TYPE_P(column_map) != IS_ARRAY) { + RETURN_CCTOR(records); + } + + PHALCON_INIT_VAR(renamed_records); + array_init(renamed_records); + if (Z_TYPE_P(records) == IS_ARRAY) { + + phalcon_is_iterable(records, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(record); + + PHALCON_INIT_NVAR(renamed); + array_init(renamed); + + phalcon_is_iterable(record, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HKEY(key, ah1, hp1); + PHALCON_GET_HVALUE(value); + + if (!phalcon_array_isset(column_map, key)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", key, "' is not part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_NVAR(renamed_key); + phalcon_array_fetch(&renamed_key, column_map, key, PH_NOISY); + + phalcon_array_update_zval(&renamed, renamed_key, &value, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); + } + + phalcon_array_append(&renamed_records, renamed, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } -kk226: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk227; + + } + + RETURN_CTOR(renamed_records); + } + + RETURN_CCTOR(records); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, serialize){ + + zval *rename_columns, *records, *model, *cache; + zval *column_map, *hydrate_mode, *data; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(rename_columns); + ZVAL_BOOL(rename_columns, 0); + + PHALCON_INIT_VAR(records); + phalcon_call_method_p1_key(records, this_ptr, "toarray", rename_columns, 3566966151UL); + + PHALCON_OBS_VAR(model); + phalcon_read_property_this_quick(&model, this_ptr, SL("_model"), 2599397109UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(cache); + phalcon_read_property_this_quick(&cache, this_ptr, SL("_cache"), 2191407384UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(column_map); + phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(hydrate_mode); + phalcon_read_property_this_quick(&hydrate_mode, this_ptr, SL("_hydrateMode"), 2551752186UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(data); + array_init_size(data, 5); + phalcon_array_update_quick_string(&data, SS("model"), 238191286UL, &model, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("cache"), 4125168857UL, &cache, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("rows"), 273469616UL, &records, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("columnMap"), 672221649UL, &column_map, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&data, SS("hydrateMode"), 259755643UL, &hydrate_mode, PH_COPY | PH_SEPARATE); + + phalcon_update_property_bool(this_ptr, SL("_activeRow"), 0 TSRMLS_CC); + + phalcon_serialize(return_value, &data TSRMLS_CC); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, unserialize){ + + zval *data, *resultset, *model, *rows, *cache, *column_map; + zval *hydrate_mode; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &data); + + phalcon_update_property_long(this_ptr, SL("_type"), 0 TSRMLS_CC); + + PHALCON_INIT_VAR(resultset); + phalcon_unserialize(resultset, data TSRMLS_CC); + if (Z_TYPE_P(resultset) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid serialization data"); + return; + } + + PHALCON_OBS_VAR(model); + phalcon_array_fetch_quick_string(&model, resultset, SS("model"), 238191286UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_model"), model, 2599397109UL TSRMLS_CC); + + PHALCON_OBS_VAR(rows); + phalcon_array_fetch_quick_string(&rows, resultset, SS("rows"), 273469616UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_rows"), rows, 3989235983UL TSRMLS_CC); + + PHALCON_OBS_VAR(cache); + phalcon_array_fetch_quick_string(&cache, resultset, SS("cache"), 4125168857UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); + + PHALCON_OBS_VAR(column_map); + phalcon_array_fetch_quick_string(&column_map, resultset, SS("columnMap"), 672221649UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_columnMap"), column_map, 1530164624UL TSRMLS_CC); + + PHALCON_OBS_VAR(hydrate_mode); + phalcon_array_fetch_quick_string(&hydrate_mode, resultset, SS("hydrateMode"), 259755643UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_hydrateMode"), hydrate_mode, 2551752186UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Resultset){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Resultset, mvc_model_resultset, phalcon_mvc_model_resultset_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_property_long(phalcon_mvc_model_resultset_ce, SL("_type"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_result"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_cache"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_model_resultset_ce, SL("_isFresh"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_model_resultset_ce, SL("_pointer"), -1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_count"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_activeRow"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_rows"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_resultset_ce, SL("_errorMessages"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_model_resultset_ce, SL("_hydrateMode"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_declare_class_constant_long(phalcon_mvc_model_resultset_ce, SL("TYPE_RESULT_FULL"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_resultset_ce, SL("TYPE_RESULT_PARTIAL"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_resultset_ce, SL("HYDRATE_RECORDS"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_resultset_ce, SL("HYDRATE_OBJECTS"), 2 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_resultset_ce, SL("HYDRATE_ARRAYS"), 1 TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_resultset_ce TSRMLS_CC, 6, phalcon_mvc_model_resultsetinterface_ce, zend_ce_iterator, spl_ce_SeekableIterator, spl_ce_Countable, zend_ce_arrayaccess, zend_ce_serializable); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, next){ + + + phalcon_property_incr(this_ptr, SL("_pointer") TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, key){ + + + RETURN_MEMBER_QUICK(this_ptr, "_pointer", 3868032485UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, rewind){ + + zval *type, *result = NULL, *active_row, *zero, *rows = NULL; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(type); + phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); + if (zend_is_true(type)) { + + PHALCON_OBS_VAR(result); + phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); + if (PHALCON_IS_NOT_FALSE(result)) { + + PHALCON_OBS_VAR(active_row); + phalcon_read_property_this_quick(&active_row, this_ptr, SL("_activeRow"), 3086770360UL, PH_NOISY_CC); + if (Z_TYPE_P(active_row) != IS_NULL) { + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + phalcon_call_method_p1_key(NULL, result, "dataseek", zero, 3282855015UL); } -kk227: -// 317 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_EXTENDS; - return 0; } -// 3048 "scanner.c" -kk228: - kkch = *++KKCURSOR; - switch (kkch) { - case 'A': - case 'a': goto kk229; - case 'B': - case 'b': goto kk230; - case 'C': - case 'c': goto kk231; - case 'F': - case 'f': goto kk232; - case 'I': - case 'i': goto kk233; - case 'M': - case 'm': goto kk234; - default: goto kk100; - } -kk229: - kkch = *++KKCURSOR; - switch (kkch) { - case 'U': - case 'u': goto kk258; - default: goto kk100; - } -kk230: - kkch = *++KKCURSOR; - switch (kkch) { - case 'L': - case 'l': goto kk253; - default: goto kk100; + } else { + PHALCON_OBS_VAR(rows); + phalcon_read_property_this_quick(&rows, this_ptr, SL("_rows"), 3989235983UL, PH_NOISY_CC); + if (Z_TYPE_P(rows) == IS_NULL) { + + PHALCON_OBS_NVAR(result); + phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); + if (Z_TYPE_P(result) == IS_OBJECT) { + PHALCON_INIT_NVAR(rows); + phalcon_call_method_key(rows, result, "fetchall", 1636682248UL); + phalcon_update_property_this_quick(this_ptr, SL("_rows"), rows, 3989235983UL TSRMLS_CC); } -kk231: - kkch = *++KKCURSOR; - switch (kkch) { - case 'A': - case 'a': goto kk245; - default: goto kk100; + } + + if (Z_TYPE_P(rows) == IS_ARRAY) { + Z_SET_ISREF_P(rows); + phalcon_call_func_p1_noret("reset", rows); + Z_UNSET_ISREF_P(rows); + } + } + + phalcon_update_property_long(this_ptr, SL("_pointer"), 0 TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, seek){ + + long i; + zval *type, *result, *rows, *position; + zval *pointer, *is_different; + HashTable *ah0; + + PHALCON_MM_GROW(); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &position) == FAILURE) { + PHALCON_MM_RESTORE(); + RETURN_NULL(); + } + + PHALCON_OBS_VAR(pointer); + phalcon_read_property(&pointer, this_ptr, SL("_pointer"), PH_NOISY_CC); + + PHALCON_INIT_VAR(is_different); + is_not_equal_function(is_different, pointer, position TSRMLS_CC); + if (PHALCON_IS_TRUE(is_different)) { + + PHALCON_OBS_VAR(type); + phalcon_read_property(&type, this_ptr, SL("_type"), PH_NOISY_CC); + if (zend_is_true(type)) { + + PHALCON_OBS_VAR(result); + phalcon_read_property(&result, this_ptr, SL("_result"), PH_NOISY_CC); + phalcon_call_method_p1_key(NULL, result, "dataseek", position, 3282855015UL); + + } else { + + PHALCON_OBS_VAR(rows); + phalcon_read_property(&rows, this_ptr, SL("_rows"), PH_NOISY_CC); + + if (Z_TYPE_P(rows) == IS_NULL) { + PHALCON_OBS_VAR(result); + phalcon_read_property(&result, this_ptr, SL("_result"), PH_NOISY_CC); + if (PHALCON_IS_NOT_FALSE(result)) { + PHALCON_INIT_NVAR(rows); + phalcon_call_method_key(rows, result, "fetchall", 1636682248UL); + phalcon_update_property_zval(this_ptr, SL("_rows"), rows TSRMLS_CC); + } } -kk232: - kkch = *++KKCURSOR; - switch (kkch) { - case 'O': - case 'o': goto kk242; - default: goto kk100; + + convert_to_long(position); + + if(Z_TYPE_P(rows) == IS_ARRAY){ + + ah0 = Z_ARRVAL_P(rows); + zend_hash_internal_pointer_reset(ah0); + + i = 0; + while (1) { + + if (i >= Z_LVAL_P(position)) { + break; + } + + zend_hash_move_forward(ah0); + i++; + } } -kk233: - kkch = *++KKCURSOR; - switch (kkch) { - case 'F': - case 'f': goto kk240; - default: goto kk100; + + phalcon_update_property_zval(this_ptr, SL("_pointer"), position TSRMLS_CC); + } + } + + PHALCON_MM_RESTORE();} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, count){ + + zval *count = NULL, *type, *result = NULL, *number_rows, *rows = NULL; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(count); + phalcon_read_property_this_quick(&count, this_ptr, SL("_count"), 2208664173UL, PH_NOISY_CC); + + if (Z_TYPE_P(count) == IS_NULL) { + + PHALCON_INIT_NVAR(count); + ZVAL_LONG(count, 0); + + PHALCON_OBS_VAR(type); + phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); + if (zend_is_true(type)) { + + PHALCON_OBS_VAR(result); + phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); + if (PHALCON_IS_NOT_FALSE(result)) { + PHALCON_INIT_VAR(number_rows); + phalcon_call_method_key(number_rows, result, "numrows", 887792640UL); + + PHALCON_INIT_NVAR(count); + ZVAL_LONG(count, phalcon_get_intval(number_rows)); } -kk234: - kkch = *++KKCURSOR; - switch (kkch) { - case 'A': - case 'a': goto kk235; - default: goto kk100; + } else { + PHALCON_OBS_VAR(rows); + phalcon_read_property_this_quick(&rows, this_ptr, SL("_rows"), 3989235983UL, PH_NOISY_CC); + if (Z_TYPE_P(rows) == IS_NULL) { + + PHALCON_OBS_NVAR(result); + phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); + if (Z_TYPE_P(result) == IS_OBJECT) { + PHALCON_INIT_NVAR(rows); + phalcon_call_method_key(rows, result, "fetchall", 1636682248UL); + phalcon_update_property_this_quick(this_ptr, SL("_rows"), rows, 3989235983UL TSRMLS_CC); + } } -kk235: - kkch = *++KKCURSOR; - switch (kkch) { - case 'C': - case 'c': goto kk236; - default: goto kk100; + + PHALCON_INIT_NVAR(count); + phalcon_fast_count(count, rows TSRMLS_CC); + } + + phalcon_update_property_this_quick(this_ptr, SL("_count"), count, 2208664173UL TSRMLS_CC); + } + + RETURN_CCTOR(count); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetExists){ + + zval *index, *count; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &index); + + PHALCON_INIT_VAR(count); + phalcon_call_method_key(count, this_ptr, "count", 4142425646UL); + is_smaller_function(return_value, index, count TSRMLS_CC); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetGet){ + + zval *index, *count, *pointer, *valid; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &index); + + PHALCON_INIT_VAR(count); + phalcon_call_method_key(count, this_ptr, "count", 4142425646UL); + if (PHALCON_LT(index, count)) { + + PHALCON_OBS_VAR(pointer); + phalcon_read_property_this_quick(&pointer, this_ptr, SL("_pointer"), 3868032485UL, PH_NOISY_CC); + if (PHALCON_IS_EQUAL(pointer, index)) { + phalcon_call_method_key(return_value, this_ptr, "current", 431662984UL); + RETURN_MM(); + } + + phalcon_call_method_p1_key(NULL, this_ptr, "seek", index, 274276301UL); + + PHALCON_INIT_VAR(valid); + phalcon_call_method_key(valid, this_ptr, "valid", 574098517UL); + if (PHALCON_IS_NOT_FALSE(valid)) { + phalcon_call_method_key(return_value, this_ptr, "current", 431662984UL); + RETURN_MM(); + } + + RETURN_MM_FALSE; + } + + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The index does not exist in the cursor"); + return; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetSet){ + + zval *index, *value; + + phalcon_fetch_params(0, 2, 0, &index, &value); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Cursor is an immutable ArrayAccess object"); + return; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetUnset){ + + zval *offset; + + phalcon_fetch_params(0, 1, 0, &offset); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Cursor is an immutable ArrayAccess object"); + return; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getType){ + + + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getFirst){ + + zval *pointer, *valid; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(pointer); + phalcon_read_property_this_quick(&pointer, this_ptr, SL("_pointer"), 3868032485UL, PH_NOISY_CC); + if (PHALCON_IS_LONG(pointer, 0)) { + phalcon_call_method_key(return_value, this_ptr, "current", 431662984UL); + RETURN_MM(); + } + + phalcon_call_method_key(NULL, this_ptr, "rewind", 1064078190UL); + + PHALCON_INIT_VAR(valid); + phalcon_call_method_key(valid, this_ptr, "valid", 574098517UL); + if (PHALCON_IS_NOT_FALSE(valid)) { + phalcon_call_method_key(return_value, this_ptr, "current", 431662984UL); + RETURN_MM(); + } + + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getLast){ + + zval *one, *count, *pre_count, *valid; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + + PHALCON_INIT_VAR(count); + phalcon_call_method_key(count, this_ptr, "count", 4142425646UL); + + PHALCON_INIT_VAR(pre_count); + sub_function(pre_count, count, one TSRMLS_CC); + phalcon_call_method_p1_key(NULL, this_ptr, "seek", pre_count, 274276301UL); + + PHALCON_INIT_VAR(valid); + phalcon_call_method_key(valid, this_ptr, "valid", 574098517UL); + if (PHALCON_IS_NOT_FALSE(valid)) { + phalcon_call_method_key(return_value, this_ptr, "current", 431662984UL); + RETURN_MM(); + } + + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, setIsFresh){ + + zval *is_fresh; + + phalcon_fetch_params(0, 1, 0, &is_fresh); + + phalcon_update_property_this_quick(this_ptr, SL("_isFresh"), is_fresh, 1397060440UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, isFresh){ + + + RETURN_MEMBER_QUICK(this_ptr, "_isFresh", 1397060440UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, setHydrateMode){ + + zval *hydrate_mode; + + phalcon_fetch_params(0, 1, 0, &hydrate_mode); + + phalcon_update_property_this_quick(this_ptr, SL("_hydrateMode"), hydrate_mode, 2551752186UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getHydrateMode){ + + + RETURN_MEMBER_QUICK(this_ptr, "_hydrateMode", 2551752186UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getCache){ + + + RETURN_MEMBER_QUICK(this_ptr, "_cache", 2191407384UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, current){ + + + RETURN_MEMBER_QUICK(this_ptr, "_activeRow", 3086770360UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getMessages){ + + + RETURN_MEMBER_QUICK(this_ptr, "_errorMessages", 1019066246UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, delete){ + + zval *condition_callback = NULL, *transaction = NULL, *record = NULL; + zval *connection = NULL, *parameters = NULL, *status = NULL, *messages = NULL; + zval *r0 = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &condition_callback); + + if (!condition_callback) { + PHALCON_INIT_VAR(condition_callback); + } + + PHALCON_INIT_VAR(transaction); + ZVAL_BOOL(transaction, 0); + phalcon_call_method_key(NULL, this_ptr, "rewind", 1064078190UL); + + while (1) { + + PHALCON_INIT_NVAR(r0); + phalcon_call_method_key(r0, this_ptr, "valid", 574098517UL); + if (zend_is_true(r0)) { + } else { + break; + } + + PHALCON_INIT_NVAR(record); + phalcon_call_method_key(record, this_ptr, "current", 431662984UL); + if (PHALCON_IS_FALSE(transaction)) { + + if (phalcon_method_quick_exists_ex(record, SS("getwriteconnection"), 4280185952UL TSRMLS_CC) == FAILURE) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The returned record is not valid"); + return; } -kk236: - kkch = *++KKCURSOR; - switch (kkch) { - case 'R': - case 'r': goto kk237; - default: goto kk100; + + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, record, "getwriteconnection", 4280185952UL); + phalcon_call_method_key(NULL, connection, "begin", 4090922282UL); + + PHALCON_INIT_NVAR(transaction); + ZVAL_BOOL(transaction, 1); + } + + if (Z_TYPE_P(condition_callback) == IS_OBJECT) { + + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 1); + phalcon_array_append(¶meters, record, PH_SEPARATE); + + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC_ARRAY(status, condition_callback, parameters); + if (PHALCON_IS_FALSE(status)) { + continue; } -kk237: - kkch = *++KKCURSOR; - switch (kkch) { - case 'O': - case 'o': goto kk238; - default: goto kk100; + } + + PHALCON_INIT_NVAR(status); + phalcon_call_method_key(status, record, "delete", 150213496UL); + if (!zend_is_true(status)) { + PHALCON_INIT_NVAR(messages); + phalcon_call_method_key(messages, record, "getmessages", 4087333309UL); + phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), messages, 1019066246UL TSRMLS_CC); + + phalcon_call_method_key(NULL, connection, "rollback", 3199546639UL); + + PHALCON_INIT_NVAR(transaction); + ZVAL_BOOL(transaction, 0); + break; + } + + phalcon_call_method_key(NULL, this_ptr, "next", 268367684UL); + } + + if (PHALCON_IS_TRUE(transaction)) { + phalcon_call_method_key(NULL, connection, "commit", 3546528686UL); + } + + RETURN_MM_TRUE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, filter){ + + zval *filter, *records, *parameters, *record = NULL, *processed_record = NULL; + zval *r0 = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &filter); + + PHALCON_INIT_VAR(records); + array_init(records); + phalcon_call_method_key(NULL, this_ptr, "rewind", 1064078190UL); + + PHALCON_INIT_VAR(parameters); + array_init(parameters); + + while (1) { + + PHALCON_INIT_NVAR(r0); + phalcon_call_method_key(r0, this_ptr, "valid", 574098517UL); + if (zend_is_true(r0)) { + } else { + break; + } + + PHALCON_INIT_NVAR(record); + phalcon_call_method_key(record, this_ptr, "current", 431662984UL); + phalcon_array_update_long(¶meters, 0, &record, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_NVAR(processed_record); + PHALCON_CALL_USER_FUNC_ARRAY(processed_record, filter, parameters); + + if (Z_TYPE_P(processed_record) != IS_OBJECT) { + if (Z_TYPE_P(processed_record) != IS_ARRAY) { + continue; } -kk238: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk239; + } + + phalcon_array_append(&records, processed_record, PH_SEPARATE); + phalcon_call_method_key(NULL, this_ptr, "next", 268367684UL); + } + + RETURN_CTOR(records); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_ResultsetInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, ResultsetInterface, mvc_model_resultsetinterface, phalcon_mvc_model_resultsetinterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Row){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Row, mvc_model_row, phalcon_mvc_model_row_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_row_ce TSRMLS_CC, 2, zend_ce_arrayaccess, phalcon_mvc_model_resultinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Row, setDirtyState){ + + zval *dirty_state; + + phalcon_fetch_params(0, 1, 0, &dirty_state); + + RETURN_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Row, offsetExists){ + + zval *index; + + phalcon_fetch_params(0, 1, 0, &index); + + if (phalcon_isset_property_zval(this_ptr, index TSRMLS_CC)) { + RETURN_TRUE; + } + RETURN_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Row, offsetGet){ + + zval *index, *value; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &index); + + if (phalcon_isset_property_zval(this_ptr, index TSRMLS_CC)) { + PHALCON_OBS_VAR(value); + phalcon_read_property_zval(&value, this_ptr, index, PH_NOISY_CC); + RETURN_CCTOR(value); + } + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The index does not exist in the row"); + return; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Row, offsetSet){ + + zval *index, *value; + + phalcon_fetch_params(0, 2, 0, &index, &value); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Row is an immutable ArrayAccess object"); + return; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Row, offsetUnset){ + + zval *offset; + + phalcon_fetch_params(0, 1, 0, &offset); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Row is an immutable ArrayAccess object"); + return; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Transaction, Exception, mvc_model_transaction_exception, "phalcon\\mvc\\model\\exception", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction_Failed){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Transaction, Failed, mvc_model_transaction_failed, "phalcon\\mvc\\model\\transaction\\exception", phalcon_mvc_model_transaction_failed_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_model_transaction_failed_ce, SL("_record"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Failed, __construct){ + + zval *message, *record; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &message, &record); + + phalcon_update_property_this_quick(this_ptr, SL("_record"), record, 1650960579UL TSRMLS_CC); + PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Mvc\\Model\\Transaction\\Failed", "__construct", message); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Failed, getRecordMessages){ + + zval *record = NULL, *messages; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(record); + phalcon_read_property_this_quick(&record, this_ptr, SL("_record"), 1650960579UL, PH_NOISY_CC); + if (Z_TYPE_P(record) != IS_NULL) { + PHALCON_INIT_NVAR(record); + phalcon_call_method_key(record, record, "getmessages", 4087333309UL); + RETURN_CCTOR(record); + } + + PHALCON_INIT_VAR(messages); + phalcon_call_method_key(messages, this_ptr, "getmessage", 4288675242UL); + + RETURN_CCTOR(messages); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Failed, getRecord){ + + + RETURN_MEMBER_QUICK(this_ptr, "_record", 1650960579UL); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction_Manager){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\Transaction, Manager, mvc_model_transaction_manager, phalcon_mvc_model_transaction_manager_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_model_transaction_manager_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_model_transaction_manager_ce, SL("_initialized"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_model_transaction_manager_ce, SL("_rollbackPendent"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_model_transaction_manager_ce, SL("_number"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_mvc_model_transaction_manager_ce, SL("_service"), "db", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_transaction_manager_ce, SL("_transactions"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_transaction_manager_ce TSRMLS_CC, 2, phalcon_mvc_model_transaction_managerinterface_ce, phalcon_di_injectionawareinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, __construct){ + + zval *dependency_injector = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &dependency_injector); + + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); + } else { + PHALCON_SEPARATE_PARAM(dependency_injector); + } + + if (zend_is_true(dependency_injector)) { + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + } else { + PHALCON_INIT_NVAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + } + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_transaction_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); + return; + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, setDbService){ + + zval *service; + + phalcon_fetch_params(0, 1, 0, &service); + + phalcon_update_property_this_quick(this_ptr, SL("_service"), service, 3205872725UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, getDbService){ + + + RETURN_MEMBER_QUICK(this_ptr, "_service", 3205872725UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, setRollbackPendent){ + + zval *rollback_pendent; + + phalcon_fetch_params(0, 1, 0, &rollback_pendent); + + phalcon_update_property_this_quick(this_ptr, SL("_rollbackPendent"), rollback_pendent, 1836882012UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, getRollbackPendent){ + + + RETURN_MEMBER_QUICK(this_ptr, "_rollbackPendent", 1836882012UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, has){ + + zval *zero, *number; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + + PHALCON_OBS_VAR(number); + phalcon_read_property_this_quick(&number, this_ptr, SL("_number"), 1417600621UL, PH_NOISY_CC); + is_smaller_function(return_value, zero, number TSRMLS_CC); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, get){ + + zval *auto_begin = NULL, *initialized, *rollback_pendent = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &auto_begin); + + if (!auto_begin) { + PHALCON_INIT_VAR(auto_begin); + ZVAL_BOOL(auto_begin, 1); + } + + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); + if (zend_is_true(initialized)) { + + PHALCON_OBS_VAR(rollback_pendent); + phalcon_read_property_this_quick(&rollback_pendent, this_ptr, SL("_rollbackPendent"), 1836882012UL, PH_NOISY_CC); + if (zend_is_true(rollback_pendent)) { + PHALCON_INIT_NVAR(rollback_pendent); + array_init_size(rollback_pendent, 2); + phalcon_array_append(&rollback_pendent, this_ptr, PH_SEPARATE); + add_next_index_stringl(rollback_pendent, SL("rollbackPendent"), 1); + phalcon_call_func_p1_noret("register_shutdown_function", rollback_pendent); + } + + phalcon_update_property_bool(this_ptr, SL("_initialized"), 1 TSRMLS_CC); + } + + phalcon_call_method_key(return_value, this_ptr, "getorcreatetransaction", 2952593376UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, getOrCreateTransaction){ + + zval *auto_begin = NULL, *dependency_injector, *number; + zval *transactions, *transaction = NULL, *false_value = NULL; + zval *service; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &auto_begin); + + if (!auto_begin) { + PHALCON_INIT_VAR(auto_begin); + ZVAL_BOOL(auto_begin, 1); + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_transaction_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); + return; + } + + PHALCON_OBS_VAR(number); + phalcon_read_property_this_quick(&number, this_ptr, SL("_number"), 1417600621UL, PH_NOISY_CC); + if (zend_is_true(number)) { + + PHALCON_OBS_VAR(transactions); + phalcon_read_property_this_quick(&transactions, this_ptr, SL("_transactions"), 3308612605UL, PH_NOISY_CC); + if (Z_TYPE_P(transactions) == IS_ARRAY) { + + phalcon_is_iterable(transactions, &ah0, &hp0, 0, 1); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(transaction); + + if (Z_TYPE_P(transaction) == IS_OBJECT) { + PHALCON_INIT_NVAR(false_value); + ZVAL_BOOL(false_value, 0); + phalcon_call_method_p1_key(NULL, transaction, "setisnewtransaction", false_value, 2346035325UL); + RETURN_CCTOR(transaction); + } + + zend_hash_move_backwards_ex(ah0, &hp0); } -kk239: -// 291 "scanner.re" - { - token->opcode = PHVOLT_T_ENDMACRO; - return 0; + } -// 3204 "scanner.c" -kk240: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk241; + } + + PHALCON_OBS_VAR(service); + phalcon_read_property_this_quick(&service, this_ptr, SL("_service"), 3205872725UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(transaction); + object_init_ex(transaction, phalcon_mvc_model_transaction_ce); + phalcon_call_method_p3_key(NULL, transaction, "__construct", dependency_injector, auto_begin, service, 1107214344UL); + + phalcon_call_method_p1_key(NULL, transaction, "settransactionmanager", this_ptr, 1385845106UL); + phalcon_update_property_array_append(this_ptr, SL("_transactions"), transaction TSRMLS_CC); + phalcon_property_incr(this_ptr, SL("_number") TSRMLS_CC); + + RETURN_CTOR(transaction); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, rollbackPendent){ + + + PHALCON_MM_GROW(); + + phalcon_call_method_key(NULL, this_ptr, "rollback", 3199546639UL); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, commit){ + + zval *transactions, *transaction = NULL, *connection = NULL; + zval *is_under_transaction = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(transactions); + phalcon_read_property_this_quick(&transactions, this_ptr, SL("_transactions"), 3308612605UL, PH_NOISY_CC); + if (Z_TYPE_P(transactions) == IS_ARRAY) { + + phalcon_is_iterable(transactions, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(transaction); + + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, transaction, "getconnection", 2504689909UL); + + PHALCON_INIT_NVAR(is_under_transaction); + phalcon_call_method_key(is_under_transaction, connection, "isundertransaction", 4040888005UL); + if (zend_is_true(is_under_transaction)) { + phalcon_call_method_key(NULL, connection, "commit", 3546528686UL); } -kk241: -// 223 "scanner.re" - { - token->opcode = PHVOLT_T_ENDIF; - return 0; + + zend_hash_move_forward_ex(ah0, &hp0); } -// 3280 "scanner.c" -kk242: - kkch = *++KKCURSOR; - switch (kkch) { - case 'R': - case 'r': goto kk243; - default: goto kk100; + + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, rollback){ + + zval *collect = NULL, *transactions, *transaction = NULL, *connection = NULL; + zval *is_under_transaction = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &collect); + + if (!collect) { + PHALCON_INIT_VAR(collect); + ZVAL_BOOL(collect, 1); + } + + PHALCON_OBS_VAR(transactions); + phalcon_read_property_this_quick(&transactions, this_ptr, SL("_transactions"), 3308612605UL, PH_NOISY_CC); + if (Z_TYPE_P(transactions) == IS_ARRAY) { + + phalcon_is_iterable(transactions, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(transaction); + + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, transaction, "getconnection", 2504689909UL); + + PHALCON_INIT_NVAR(is_under_transaction); + phalcon_call_method_key(is_under_transaction, connection, "isundertransaction", 4040888005UL); + if (zend_is_true(is_under_transaction)) { + phalcon_call_method_key(NULL, connection, "rollback", 3199546639UL); + phalcon_call_method_key(NULL, connection, "close", 4138657211UL); } -kk243: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk244; + + if (zend_is_true(collect)) { + phalcon_call_method_p1_key(NULL, this_ptr, "_collecttransaction", transaction, 3516646160UL); } -kk244: -// 234 "scanner.re" - { - token->opcode = PHVOLT_T_ENDFOR; - return 0; + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, notifyRollback){ + + zval *transaction; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &transaction); + + phalcon_call_method_p1_key(NULL, this_ptr, "_collecttransaction", transaction, 3516646160UL); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, notifyCommit){ + + zval *transaction; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &transaction); + + phalcon_call_method_p1_key(NULL, this_ptr, "_collecttransaction", transaction, 3516646160UL); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, _collectTransaction){ + + zval *transaction, *transactions, *new_transactions; + zval *managed_transaction = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &transaction); + + PHALCON_OBS_VAR(transactions); + phalcon_read_property_this_quick(&transactions, this_ptr, SL("_transactions"), 3308612605UL, PH_NOISY_CC); + if (phalcon_fast_count_ev(transactions TSRMLS_CC)) { + + PHALCON_INIT_VAR(new_transactions); + array_init(new_transactions); + + phalcon_is_iterable(transactions, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(managed_transaction); + + if (PHALCON_IS_EQUAL(managed_transaction, transaction)) { + phalcon_array_append(&new_transactions, transaction, PH_SEPARATE); + phalcon_property_decr(this_ptr, SL("_number") TSRMLS_CC); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_update_property_this_quick(this_ptr, SL("_transactions"), new_transactions, 3308612605UL TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, collectTransactions){ + + zval *transactions, *managed_transaction = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(transactions); + phalcon_read_property_this_quick(&transactions, this_ptr, SL("_transactions"), 3308612605UL, PH_NOISY_CC); + if (phalcon_fast_count_ev(transactions TSRMLS_CC)) { + + phalcon_is_iterable(transactions, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(managed_transaction); + + phalcon_property_decr(this_ptr, SL("_number") TSRMLS_CC); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_update_property_null(this_ptr, SL("_transactions") TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction_ManagerInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model\\Transaction, ManagerInterface, mvc_model_transaction_managerinterface, phalcon_mvc_model_transaction_managerinterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Transaction, mvc_model_transaction, phalcon_mvc_model_transaction_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_model_transaction_ce, SL("_connection"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_model_transaction_ce, SL("_activeTransaction"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_model_transaction_ce, SL("_isNewTransaction"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_model_transaction_ce, SL("_rollbackOnAbort"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_transaction_ce, SL("_manager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_transaction_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_transaction_ce, SL("_rollbackRecord"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_transaction_ce TSRMLS_CC, 1, phalcon_mvc_model_transactioninterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, __construct){ + + zval *dependency_injector, *auto_begin = NULL, *service = NULL; + zval *connection; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &dependency_injector, &auto_begin, &service); + + if (!auto_begin) { + PHALCON_INIT_VAR(auto_begin); + ZVAL_BOOL(auto_begin, 0); + } + + if (!service) { + PHALCON_INIT_VAR(service); + } else { + PHALCON_SEPARATE_PARAM(service); + } + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_transaction_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); + return; + } + if (Z_TYPE_P(service) != IS_STRING) { + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "db", 1); + } + + PHALCON_INIT_VAR(connection); + phalcon_call_method_p1_key(connection, dependency_injector, "get", service, 2090288933UL); + phalcon_update_property_this_quick(this_ptr, SL("_connection"), connection, 3057302292UL TSRMLS_CC); + if (zend_is_true(auto_begin)) { + phalcon_call_method_key(NULL, connection, "begin", 4090922282UL); + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setTransactionManager){ + + zval *manager; + + phalcon_fetch_params(0, 1, 0, &manager); + + if (Z_TYPE_P(manager) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_transaction_exception_ce, "Manager must be an Object"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_manager"), manager, 4140832863UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, begin){ + + zval *connection; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(connection); + phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + phalcon_call_method_key(return_value, connection, "begin", 4090922282UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, commit){ + + zval *manager, *call_object, *arguments, *connection; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + if (Z_TYPE_P(manager) == IS_OBJECT) { + PHALCON_INIT_VAR(call_object); + array_init_size(call_object, 2); + phalcon_array_append(&call_object, manager, PH_SEPARATE); + add_next_index_stringl(call_object, SL("notifyCommit"), 1); + + PHALCON_INIT_VAR(arguments); + array_init_size(arguments, 1); + phalcon_array_append(&arguments, this_ptr, PH_SEPARATE); + phalcon_call_func_p2_noret("call_user_func_array", call_object, arguments); + } + + PHALCON_OBS_VAR(connection); + phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + phalcon_call_method_key(return_value, connection, "commit", 3546528686UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, rollback){ + + zval *rollback_message = NULL, *rollback_record = NULL; + zval *manager, *call_object, *arguments, *connection; + zval *success; + zval *i0 = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &rollback_message, &rollback_record); + + if (!rollback_message) { + PHALCON_INIT_VAR(rollback_message); + } else { + PHALCON_SEPARATE_PARAM(rollback_message); + } + + if (!rollback_record) { + PHALCON_INIT_VAR(rollback_record); + } else { + PHALCON_SEPARATE_PARAM(rollback_record); + } + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + if (Z_TYPE_P(manager) == IS_OBJECT) { + PHALCON_INIT_VAR(call_object); + array_init_size(call_object, 2); + phalcon_array_append(&call_object, manager, PH_SEPARATE); + add_next_index_stringl(call_object, SL("notifyRollback"), 1); + + PHALCON_INIT_VAR(arguments); + array_init_size(arguments, 1); + phalcon_array_append(&arguments, this_ptr, PH_SEPARATE); + phalcon_call_func_p2_noret("call_user_func_array", call_object, arguments); + } + + PHALCON_OBS_VAR(connection); + phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(success); + phalcon_call_method_key(success, connection, "rollback", 3199546639UL); + if (zend_is_true(success)) { + if (!zend_is_true(rollback_message)) { + PHALCON_INIT_NVAR(rollback_message); + ZVAL_STRING(rollback_message, "Transaction aborted", 1); } -// 3363 "scanner.c" -kk245: - kkch = *++KKCURSOR; - switch (kkch) { - case 'C': - case 'c': goto kk246; - case 'L': - case 'l': goto kk247; - default: goto kk100; - } -kk246: - kkch = *++KKCURSOR; - switch (kkch) { - case 'H': - case 'h': goto kk250; - default: goto kk100; - } -kk247: - kkch = *++KKCURSOR; - switch (kkch) { - case 'L': - case 'l': goto kk248; - default: goto kk100; - } -kk248: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk249; - } -kk249: -// 302 "scanner.re" - { - token->opcode = PHVOLT_T_ENDCALL; - return 0; + if (Z_TYPE_P(rollback_record) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_rollbackRecord"), rollback_record, 3406866061UL TSRMLS_CC); } -// 3462 "scanner.c" -kk250: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk251; - default: goto kk100; - } -kk251: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk252; - } -kk252: -// 353 "scanner.re" - { - token->opcode = PHVOLT_T_ENDCACHE; - return 0; + + PHALCON_OBS_NVAR(rollback_record); + phalcon_read_property_this_quick(&rollback_record, this_ptr, SL("_rollbackRecord"), 3406866061UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(i0); + object_init_ex(i0, phalcon_mvc_model_transaction_failed_ce); + phalcon_call_method_p2_key(NULL, i0, "__construct", rollback_message, rollback_record, 1107214344UL); + + phalcon_throw_exception(i0 TSRMLS_CC); + return; + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, getConnection){ + + zval *rollback_on_abort, *was_aborted, *message; + zval *connection; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(rollback_on_abort); + phalcon_read_property_this_quick(&rollback_on_abort, this_ptr, SL("_rollbackOnAbort"), 3438288323UL, PH_NOISY_CC); + if (zend_is_true(rollback_on_abort)) { + + PHALCON_INIT_VAR(was_aborted); + phalcon_call_func(was_aborted, "connection_aborted"); + if (zend_is_true(was_aborted)) { + PHALCON_INIT_VAR(message); + ZVAL_STRING(message, "The request was aborted", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "rollback", message, 3199546639UL); } -// 3545 "scanner.c" -kk253: - kkch = *++KKCURSOR; - switch (kkch) { - case 'O': - case 'o': goto kk254; - default: goto kk100; - } -kk254: - kkch = *++KKCURSOR; - switch (kkch) { - case 'C': - case 'c': goto kk255; - default: goto kk100; - } -kk255: - kkch = *++KKCURSOR; - switch (kkch) { - case 'K': - case 'k': goto kk256; - default: goto kk100; - } -kk256: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk257; - } -kk257: -// 280 "scanner.re" - { - token->opcode = PHVOLT_T_ENDBLOCK; - return 0; + } + + PHALCON_OBS_VAR(connection); + phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + + RETURN_CCTOR(connection); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setIsNewTransaction){ + + zval *is_new; + + phalcon_fetch_params(0, 1, 0, &is_new); + + phalcon_update_property_this_quick(this_ptr, SL("_isNewTransaction"), is_new, 3116442896UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setRollbackOnAbort){ + + zval *rollback_on_abort; + + phalcon_fetch_params(0, 1, 0, &rollback_on_abort); + + phalcon_update_property_this_quick(this_ptr, SL("_rollbackOnAbort"), rollback_on_abort, 3438288323UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, isManaged){ + + zval *manager; + zval *r0 = NULL; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); + + PHALCON_ALLOC_ZVAL_MM(r0); + boolean_not_function(r0, manager TSRMLS_CC); + RETURN_NCTOR(r0); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, getMessages){ + + + RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, isValid){ + + zval *connection; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(connection); + phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + phalcon_call_method_key(return_value, connection, "isundertransaction", 4040888005UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setRollbackedRecord){ + + zval *record; + + phalcon_fetch_params(0, 1, 0, &record); + + phalcon_update_property_this_quick(this_ptr, SL("_rollbackRecord"), record, 3406866061UL TSRMLS_CC); + +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_TransactionInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, TransactionInterface, mvc_model_transactioninterface, phalcon_mvc_model_transactioninterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_ValidationFailed){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model, ValidationFailed, mvc_model_validationfailed, "phalcon\\mvc\\model\\exception", phalcon_mvc_model_validationfailed_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_model_validationfailed_ce, SL("_model"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_validationfailed_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_ValidationFailed, __construct){ + + zval *model, *validation_messages, *message; + zval *message_str = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &validation_messages); + + if (phalcon_fast_count_ev(validation_messages TSRMLS_CC)) { + PHALCON_OBS_VAR(message); + phalcon_array_fetch_long(&message, validation_messages, 0, PH_NOISY); + + PHALCON_INIT_VAR(message_str); + phalcon_call_method_key(message_str, message, "getmessage", 4288675242UL); + } else { + PHALCON_INIT_NVAR(message_str); + ZVAL_STRING(message_str, "Validation failed", 1); + } + phalcon_update_property_this_quick(this_ptr, SL("_model"), model, 2599397109UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_messages"), validation_messages, 743366684UL TSRMLS_CC); + PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Mvc\\Model\\ValidationFailed", "__construct", message_str); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_ValidationFailed, getMessages){ + + + RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_ValidationFailed, getModel){ + + + RETURN_MEMBER_QUICK(this_ptr, "_model", 2599397109UL); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Email){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Email, mvc_model_validator_email, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_email_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_validator_email_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Email, validate){ + + zval *record, *option = NULL, *field_name, *regs, *invalid = NULL; + zval *value, *pattern, *match_pattern, *match_zero; + zval *message = NULL, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &record); + + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); + + PHALCON_INIT_VAR(field_name); + phalcon_call_method_p1_key(field_name, this_ptr, "getoption", option, 1191969182UL); + if (Z_TYPE_P(field_name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); + return; + } + + PHALCON_INIT_VAR(regs); + + PHALCON_INIT_VAR(invalid); + ZVAL_BOOL(invalid, 0); + + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); + + PHALCON_INIT_VAR(pattern); + ZVAL_STRING(pattern, "/^[a-zA-Z0-9\\-_\\.\\+]+@[a-zA-Z0-9_\\-]+(\\.[a-zA-Z0-9_\\-]+)*$/", 1); + + PHALCON_INIT_VAR(match_pattern); + phalcon_preg_match(match_pattern, pattern, value, regs TSRMLS_CC); + + if (zend_is_true(match_pattern)) { + PHALCON_OBS_VAR(match_zero); + phalcon_array_fetch_long(&match_zero, regs, 0, PH_NOISY); + + is_not_equal_function(invalid, match_zero, value TSRMLS_CC); + } else { + PHALCON_INIT_NVAR(invalid); + ZVAL_BOOL(invalid, 1); + } + + if (PHALCON_IS_TRUE(invalid)) { + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "message", 1); + + PHALCON_INIT_VAR(message); + phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); + if (!zend_is_true(message)) { + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVS(message, "Value of field '", field_name, "' must have a valid e-mail format"); } -// 3642 "scanner.c" -kk258: - kkch = *++KKCURSOR; - switch (kkch) { - case 'T': - case 't': goto kk259; - default: goto kk100; - } -kk259: - kkch = *++KKCURSOR; - switch (kkch) { - case 'O': - case 'o': goto kk260; - default: goto kk100; - } -kk260: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk261; - default: goto kk100; - } -kk261: - kkch = *++KKCURSOR; - switch (kkch) { - case 'S': - case 's': goto kk262; - default: goto kk100; - } -kk262: - kkch = *++KKCURSOR; - switch (kkch) { - case 'C': - case 'c': goto kk263; - default: goto kk100; - } -kk263: - kkch = *++KKCURSOR; - switch (kkch) { - case 'A': - case 'a': goto kk264; - default: goto kk100; - } -kk264: - kkch = *++KKCURSOR; - switch (kkch) { - case 'P': - case 'p': goto kk265; - default: goto kk100; - } -kk265: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk266; - default: goto kk100; - } -kk266: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk267; - } -kk267: -// 370 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_ENDAUTOESCAPE; - return 0; + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "Email", 1); + phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field_name, type, 2313005058UL); + RETURN_MM_FALSE; + } + + RETURN_MM_TRUE; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Exclusionin){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Exclusionin, mvc_model_validator_exclusionin, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_exclusionin_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_validator_exclusionin_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Exclusionin, validate){ + + zval *record, *option = NULL, *field_name, *is_set, *domain; + zval *value, *message = NULL, *joined_domain, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &record); + + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); + + PHALCON_INIT_VAR(field_name); + phalcon_call_method_p1_key(field_name, this_ptr, "getoption", option, 1191969182UL); + if (Z_TYPE_P(field_name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); + return; + } + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "domain", 1); + + PHALCON_INIT_VAR(is_set); + phalcon_call_method_p1_key(is_set, this_ptr, "issetoption", option, 2532732262UL); + if (PHALCON_IS_FALSE(is_set)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'domain' is required for this validator"); + return; + } + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "domain", 1); + + PHALCON_INIT_VAR(domain); + phalcon_call_method_p1_key(domain, this_ptr, "getoption", option, 1191969182UL); + if (Z_TYPE_P(domain) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Option 'domain' must be an array"); + return; + } + + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); + + if (phalcon_fast_in_array(value, domain TSRMLS_CC)) { + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "message", 1); + + PHALCON_INIT_VAR(message); + phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); + if (!zend_is_true(message)) { + PHALCON_INIT_VAR(joined_domain); + phalcon_fast_join_str(joined_domain, SL(", "), domain TSRMLS_CC); + + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVSV(message, "Value of field '", field_name, "' must not be part of list: ", joined_domain); } -// 3775 "scanner.c" -kk268: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk269; - default: goto kk100; - } -kk269: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'G': - case 'H': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'g': - case 'h': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - case 'F': - case 'f': goto kk271; - case 'I': - case 'i': goto kk272; - default: goto kk270; - } -kk270: -// 208 "scanner.re" - { - token->opcode = PHVOLT_T_ELSE; - return 0; + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "Exclusion", 1); + phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field_name, type, 2313005058UL); + RETURN_MM_FALSE; + } + + RETURN_MM_TRUE; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Inclusionin){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Inclusionin, mvc_model_validator_inclusionin, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_inclusionin_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_validator_inclusionin_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Inclusionin, validate){ + + zval *record, *field = NULL, *field_name, *is_set, *domain; + zval *value, *option, *message = NULL, *joined_domain; + zval *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &record); + + PHALCON_INIT_VAR(field); + ZVAL_STRING(field, "field", 1); + + PHALCON_INIT_VAR(field_name); + phalcon_call_method_p1_key(field_name, this_ptr, "getoption", field, 1191969182UL); + if (Z_TYPE_P(field_name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); + return; + } + + PHALCON_INIT_NVAR(field); + ZVAL_STRING(field, "domain", 1); + + PHALCON_INIT_VAR(is_set); + phalcon_call_method_p1_key(is_set, this_ptr, "issetoption", field, 2532732262UL); + if (PHALCON_IS_FALSE(is_set)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'domain' is required for this validator"); + return; + } + + PHALCON_INIT_NVAR(field); + ZVAL_STRING(field, "domain", 1); + + PHALCON_INIT_VAR(domain); + phalcon_call_method_p1_key(domain, this_ptr, "getoption", field, 1191969182UL); + if (Z_TYPE_P(domain) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Option 'domain' must be an array"); + return; + } + + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); + + if (!phalcon_fast_in_array(value, domain TSRMLS_CC)) { + + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "message", 1); + + PHALCON_INIT_VAR(message); + phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); + if (!zend_is_true(message)) { + PHALCON_INIT_VAR(joined_domain); + phalcon_fast_join_str(joined_domain, SL(", "), domain TSRMLS_CC); + + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVSV(message, "Value of field '", field_name, "' must be part of list: ", joined_domain); } -// 3858 "scanner.c" -kk271: - kkch = *++KKCURSOR; - switch (kkch) { - case 'O': - case 'o': goto kk275; - default: goto kk100; - } -kk272: - kkch = *++KKCURSOR; - switch (kkch) { - case 'F': - case 'f': goto kk273; - default: goto kk100; - } -kk273: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk274; - } -kk274: -// 218 "scanner.re" - { - token->opcode = PHVOLT_T_ELSEIF; - return 0; + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "Inclusion", 1); + phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field_name, type, 2313005058UL); + RETURN_MM_FALSE; + } + + RETURN_MM_TRUE; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Numericality){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Numericality, mvc_model_validator_numericality, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_numericality_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_validator_numericality_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Numericality, validate){ + + zval *record, *option = NULL, *field, *value, *message = NULL, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &record); + + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); + + PHALCON_INIT_VAR(field); + phalcon_call_method_p1_key(field, this_ptr, "getoption", option, 1191969182UL); + if (Z_TYPE_P(field) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); + return; + } + + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); + + if (!phalcon_is_numeric(value)) { + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "message", 1); + + PHALCON_INIT_VAR(message); + phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); + if (!zend_is_true(message)) { + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVS(message, "Value of field '", field, "' must be numeric"); } -// 3948 "scanner.c" -kk275: - kkch = *++KKCURSOR; - switch (kkch) { - case 'R': - case 'r': goto kk276; - default: goto kk100; - } -kk276: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk277; - } -kk277: -// 213 "scanner.re" - { - token->opcode = PHVOLT_T_ELSEFOR; - return 0; + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "Numericality", 1); + phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field, type, 2313005058UL); + RETURN_MM_FALSE; + } + + RETURN_MM_TRUE; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_PresenceOf){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, PresenceOf, mvc_model_validator_presenceof, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_presenceof_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_validator_presenceof_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator_PresenceOf, validate){ + + zval *record, *option = NULL, *field_name, *value, *message = NULL; + zval *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &record); + + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); + + PHALCON_INIT_VAR(field_name); + phalcon_call_method_p1_key(field_name, this_ptr, "getoption", option, 1191969182UL); + if (Z_TYPE_P(field_name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); + return; + } + + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); + if (PHALCON_IS_EMPTY(value)) { + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "message", 1); + + PHALCON_INIT_VAR(message); + phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); + if (!zend_is_true(message)) { + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVS(message, "'", field_name, "' is required"); } -// 4031 "scanner.c" -kk278: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk279; - } -kk279: -// 202 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_IF; - return 0; + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "PresenceOf", 1); + phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field_name, type, 2313005058UL); + RETURN_MM_FALSE; + } + + RETURN_MM_TRUE; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Regex){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Regex, mvc_model_validator_regex, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_regex_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_validator_regex_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Regex, validate){ + + zval *record, *option = NULL, *field_name, *is_set, *value; + zval *failed = NULL, *matches, *pattern, *match_pattern; + zval *match_zero, *message = NULL, *type; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &record); + + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); + + PHALCON_INIT_VAR(field_name); + phalcon_call_method_p1_key(field_name, this_ptr, "getoption", option, 1191969182UL); + if (Z_TYPE_P(field_name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); + return; + } + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "pattern", 1); + + PHALCON_INIT_VAR(is_set); + phalcon_call_method_p1_key(is_set, this_ptr, "issetoption", option, 2532732262UL); + if (!zend_is_true(is_set)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Validator requires a perl-compatible regex pattern"); + return; + } + + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); + + PHALCON_INIT_VAR(failed); + ZVAL_BOOL(failed, 0); + + PHALCON_INIT_VAR(matches); + + PHALCON_INIT_VAR(pattern); + phalcon_call_method_p1_key(pattern, this_ptr, "getoption", option, 1191969182UL); + + PHALCON_INIT_VAR(match_pattern); + phalcon_preg_match(match_pattern, pattern, value, matches TSRMLS_CC); + + if (zend_is_true(match_pattern)) { + PHALCON_OBS_VAR(match_zero); + phalcon_array_fetch_long(&match_zero, matches, 0, PH_NOISY); + + is_not_equal_function(failed, match_zero, value TSRMLS_CC); + } else { + PHALCON_INIT_NVAR(failed); + ZVAL_BOOL(failed, 1); + } + + if (PHALCON_IS_TRUE(failed)) { + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "message", 1); + + PHALCON_INIT_VAR(message); + phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); + if (!zend_is_true(message)) { + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVS(message, "Value of field '", field_name, "' doesn't match regular expression"); + } + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "Regex", 1); + phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field_name, type, 2313005058UL); + RETURN_MM_FALSE; + } + + RETURN_MM_TRUE; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_StringLength){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, StringLength, mvc_model_validator_stringlength, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_stringlength_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_validator_stringlength_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator_StringLength, validate){ + + zval *record, *option = NULL, *field, *is_set_min, *is_set_max; + zval *value, *length = NULL, *invalid_maximum = NULL, *invalid_minimum = NULL; + zval *maximum, *message = NULL, *type = NULL, *minimum; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &record); + + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); + + PHALCON_INIT_VAR(field); + phalcon_call_method_p1_key(field, this_ptr, "getoption", option, 1191969182UL); + if (Z_TYPE_P(field) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); + return; + } + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "min", 1); + + PHALCON_INIT_VAR(is_set_min); + phalcon_call_method_p1_key(is_set_min, this_ptr, "issetoption", option, 2532732262UL); + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "max", 1); + + PHALCON_INIT_VAR(is_set_max); + phalcon_call_method_p1_key(is_set_max, this_ptr, "issetoption", option, 2532732262UL); + if (!zend_is_true(is_set_min)) { + if (!zend_is_true(is_set_max)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A minimum or maximum must be set"); + return; } -// 4108 "scanner.c" -kk280: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - case 'C': - case 'c': goto kk284; - default: goto kk281; + } + + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); + + if (phalcon_function_quick_exists_ex(SS("mb_strlen"), 3716840971UL TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_VAR(length); + phalcon_call_func_p1(length, "mb_strlen", value); + } else { + PHALCON_INIT_NVAR(length); + phalcon_fast_strlen(length, value); + } + + PHALCON_INIT_VAR(invalid_maximum); + ZVAL_BOOL(invalid_maximum, 0); + + PHALCON_INIT_VAR(invalid_minimum); + ZVAL_BOOL(invalid_minimum, 0); + + if (zend_is_true(is_set_max)) { + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "max", 1); + + PHALCON_INIT_VAR(maximum); + phalcon_call_method_p1_key(maximum, this_ptr, "getoption", option, 1191969182UL); + + is_smaller_function(invalid_maximum, maximum, length TSRMLS_CC); + if (PHALCON_IS_TRUE(invalid_maximum)) { + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "messageMaximum", 1); + + PHALCON_INIT_VAR(message); + phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); + if (!zend_is_true(message)) { + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVSVS(message, "Value of field '", field, "' exceeds the maximum ", maximum, " characters"); } -kk281: -// 239 "scanner.re" - { - token->opcode = PHVOLT_T_IN; - return 0; + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "TooLong", 1); + phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field, type, 2313005058UL); + RETURN_MM_FALSE; } -// 4184 "scanner.c" -kk282: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk283; + } + + if (zend_is_true(is_set_min)) { + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "min", 1); + + PHALCON_INIT_VAR(minimum); + phalcon_call_method_p1_key(minimum, this_ptr, "getoption", option, 1191969182UL); + + is_smaller_function(invalid_minimum, length, minimum TSRMLS_CC); + if (PHALCON_IS_TRUE(invalid_minimum)) { + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "messageMinimum", 1); + + PHALCON_INIT_NVAR(message); + phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); + if (!zend_is_true(message)) { + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVSVS(message, "Value of field '", field, "' is less than the minimum ", minimum, " characters"); } -kk283: -// 323 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_IS; - return 0; + + PHALCON_INIT_NVAR(type); + ZVAL_STRING(type, "TooShort", 1); + phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field, type, 2313005058UL); + RETURN_MM_FALSE; } -// 4261 "scanner.c" -kk284: - kkch = *++KKCURSOR; - switch (kkch) { - case 'L': - case 'l': goto kk285; - default: goto kk100; - } -kk285: - kkch = *++KKCURSOR; - switch (kkch) { - case 'U': - case 'u': goto kk286; - default: goto kk100; - } -kk286: - kkch = *++KKCURSOR; - switch (kkch) { - case 'D': - case 'd': goto kk287; - default: goto kk100; + } + + RETURN_MM_TRUE; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Uniqueness){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Uniqueness, mvc_model_validator_uniqueness, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_uniqueness_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_validator_uniqueness_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Uniqueness, validate){ + + zval *record, *option = NULL, *field, *dependency_injector; + zval *service, *meta_data, *bind_types, *bind_data_types; + zval *column_map = NULL, *conditions, *bind_params; + zval *number = NULL, *compose_field = NULL, *column_field = NULL; + zval *exception_message = NULL, *value = NULL, *compose_condition = NULL; + zval *bind_type = NULL, *condition = NULL, *operation_made; + zval *primary_fields, *primary_field = NULL, *attribute_field = NULL; + zval *join_conditions, *params, *class_name; + zval *message = NULL, *join_fields, *type; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &record); + + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); + + PHALCON_INIT_VAR(field); + phalcon_call_method_p1_key(field, this_ptr, "getoption", option, 1191969182UL); + + PHALCON_INIT_VAR(dependency_injector); + phalcon_call_method_key(dependency_injector, record, "getdi", 4287060818UL); + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "modelsMetadata", 1); + + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_p1_key(meta_data, dependency_injector, "getshared", service, 1727570332UL); + + PHALCON_INIT_VAR(bind_types); + array_init(bind_types); + + PHALCON_INIT_VAR(bind_data_types); + phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", record, 448815543UL); + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getreversecolumnmap", record, 817005101UL); + } else { + PHALCON_INIT_NVAR(column_map); + } + + PHALCON_INIT_VAR(conditions); + array_init(conditions); + + PHALCON_INIT_VAR(bind_params); + array_init(bind_params); + + PHALCON_INIT_VAR(number); + ZVAL_LONG(number, 0); + if (Z_TYPE_P(field) == IS_ARRAY) { + + phalcon_is_iterable(field, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(compose_field); + + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, compose_field)) { + PHALCON_OBS_NVAR(column_field); + phalcon_array_fetch(&column_field, column_map, compose_field, PH_NOISY); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", compose_field, "\" isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } else { + PHALCON_CPY_WRT(column_field, compose_field); } -kk287: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk288; - default: goto kk100; + + if (!phalcon_array_isset(bind_data_types, column_field)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", column_field, "\" isn't part of the table columns"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -kk288: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case '\\': - case '_': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': goto kk99; - default: goto kk289; + + PHALCON_INIT_NVAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", compose_field, 95450773UL); + + PHALCON_INIT_NVAR(compose_condition); + PHALCON_CONCAT_SVSV(compose_condition, "[", compose_field, "] = ?", number); + phalcon_array_append(&conditions, compose_condition, PH_SEPARATE); + phalcon_array_append(&bind_params, value, PH_SEPARATE); + + PHALCON_OBS_NVAR(bind_type); + phalcon_array_fetch(&bind_type, bind_data_types, column_field, PH_NOISY); + phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); + PHALCON_SEPARATE(number); + phalcon_increment(number); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } else { + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, field)) { + PHALCON_OBS_NVAR(column_field); + phalcon_array_fetch(&column_field, column_map, field, PH_NOISY); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", field, "\" isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -kk289: -// 341 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_INCLUDE; - return 0; + } else { + PHALCON_CPY_WRT(column_field, field); + } + + if (!phalcon_array_isset(bind_data_types, column_field)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", column_field, "\" isn't part of the table columns"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_INIT_NVAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); + + PHALCON_INIT_VAR(condition); + PHALCON_CONCAT_SVS(condition, "[", field, "] = ?0"); + phalcon_array_append(&conditions, condition, PH_SEPARATE); + phalcon_array_append(&bind_params, value, PH_SEPARATE); + + PHALCON_OBS_NVAR(bind_type); + phalcon_array_fetch(&bind_type, bind_data_types, column_field, PH_NOISY); + phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); + PHALCON_SEPARATE(number); + phalcon_increment(number); + } + + PHALCON_INIT_VAR(operation_made); + phalcon_call_method_key(operation_made, record, "getoperationmade", 408703981UL); + if (PHALCON_IS_LONG(operation_made, 2)) { + + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_NVAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", record, 213063537UL); + } else { + PHALCON_INIT_NVAR(column_map); } -// 4366 "scanner.c" -kk290: - kkch = *++KKCURSOR; - switch (kkch) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto kk293; - default: goto kk103; - } -kk291: - kkaccept = 0; - KKMARKER = ++KKCURSOR; - kkch = *KKCURSOR; -kk292: - switch (kkch) { - case '.': goto kk290; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto kk291; - default: goto kk3; + + PHALCON_INIT_VAR(primary_fields); + phalcon_call_method_p1_key(primary_fields, meta_data, "getprimarykeyattributes", record, 692945721UL); + + phalcon_is_iterable(primary_fields, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(primary_field); + + if (!phalcon_array_isset(bind_data_types, primary_field)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", primary_field, "\" isn't part of the table columns"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -kk293: - ++KKCURSOR; - kkch = *KKCURSOR; - switch (kkch) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': goto kk293; - default: goto kk295; + + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, primary_field)) { + PHALCON_OBS_NVAR(attribute_field); + phalcon_array_fetch(&attribute_field, column_map, primary_field, PH_NOISY); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", primary_field, "\" isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } else { + PHALCON_CPY_WRT(attribute_field, primary_field); } -kk295: -// 194 "scanner.re" - { - token->opcode = PHVOLT_T_DOUBLE; - token->value = estrndup(start, KKCURSOR - start); - token->len = KKCURSOR - start; - q = KKCURSOR; - return 0; + + PHALCON_INIT_NVAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", primary_field, 95450773UL); + + PHALCON_INIT_NVAR(condition); + PHALCON_CONCAT_SVSV(condition, "[", attribute_field, "] <> ?", number); + phalcon_array_append(&conditions, condition, PH_SEPARATE); + phalcon_array_append(&bind_params, value, PH_SEPARATE); + + PHALCON_OBS_NVAR(bind_type); + phalcon_array_fetch(&bind_type, bind_data_types, primary_field, PH_NOISY); + phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); + PHALCON_SEPARATE(number); + phalcon_increment(number); + + zend_hash_move_forward_ex(ah1, &hp1); } -// 4426 "scanner.c" + + } + + PHALCON_INIT_VAR(join_conditions); + phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); + + PHALCON_INIT_VAR(params); + array_init(params); + phalcon_array_update_quick_string(¶ms, SS("di"), 193489362UL, &dependency_injector, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(¶ms, SS("conditions"), 1055696255UL, &join_conditions, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(¶ms, SS("bind"), 254268962UL, &bind_params, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(¶ms, SS("bindTypes"), 3951758359UL, &bind_types, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, record, 0 TSRMLS_CC); + + phalcon_call_zval_str_static_p1(number, class_name, "count", params); + if (!PHALCON_IS_LONG(number, 0)) { + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "message", 1); + + PHALCON_INIT_VAR(message); + phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); + if (!zend_is_true(message)) { + if (Z_TYPE_P(field) == IS_ARRAY) { + PHALCON_INIT_VAR(join_fields); + phalcon_fast_join_str(join_fields, SL(", "), field TSRMLS_CC); + + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVS(message, "Value of fields: '", join_fields, "' are already present in another record"); + } else { + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVS(message, "Value of field: '", field, "' is already present in another record"); + } } -// 654 "scanner.re" + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "Unique", 1); + phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field, type, 2313005058UL); + RETURN_MM_FALSE; + } + + RETURN_MM_TRUE; +} + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Url){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Validator, Url, mvc_model_validator_url, "phalcon\\mvc\\model\\validator", phalcon_mvc_model_validator_url_method_entry, 0); + + zend_class_implements(phalcon_mvc_model_validator_url_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Url, validate){ + + zval *record, *option = NULL, *field, *value, *flag, *is_valid; + zval *message = NULL, *type; + + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &record); + + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); + + PHALCON_INIT_VAR(field); + phalcon_call_method_p1_key(field, this_ptr, "getoption", option, 1191969182UL); + if (Z_TYPE_P(field) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Field name must be a string"); + return; + } + + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); + + PHALCON_INIT_VAR(flag); + ZVAL_LONG(flag, 273); + + PHALCON_INIT_VAR(is_valid); + phalcon_call_func_p2(is_valid, "filter_var", value, flag); + if (!zend_is_true(is_valid)) { + + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "message", 1); + + PHALCON_INIT_VAR(message); + phalcon_call_method_p1_key(message, this_ptr, "getoption", option, 1191969182UL); + if (!zend_is_true(message)) { + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVS(message, "'", field, "' does not have a valid url format"); } + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "Url", 1); + phalcon_call_method_p3_key(NULL, this_ptr, "appendmessage", message, field, type, 2313005058UL); + RETURN_MM_FALSE; } + + RETURN_MM_TRUE; +} - return status; + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Validator, mvc_model_validator, phalcon_mvc_model_validator_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_property_null(phalcon_mvc_model_validator_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_validator_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator, __construct){ + + zval *options; + + phalcon_fetch_params(0, 1, 0, &options); + + if (Z_TYPE_P(options) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "$options argument must be an Array"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator, appendMessage){ + + zval *message, *field = NULL, *type = NULL, *class_name, *suffix; + zval *empty_string, *model_message; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &message, &field, &type); + + if (!field) { + PHALCON_INIT_VAR(field); + } + + if (!type) { + PHALCON_INIT_VAR(type); + } else { + PHALCON_SEPARATE_PARAM(type); + } + + if (!zend_is_true(type)) { + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); + + PHALCON_INIT_VAR(suffix); + ZVAL_STRING(suffix, "Validator", 1); + + PHALCON_INIT_VAR(empty_string); + ZVAL_STRING(empty_string, "", 1); + + PHALCON_INIT_NVAR(type); + phalcon_fast_str_replace(type, suffix, empty_string, class_name); + } + + PHALCON_INIT_VAR(model_message); + object_init_ex(model_message, phalcon_mvc_model_message_ce); + phalcon_call_method_p3_key(NULL, model_message, "__construct", message, field, type, 1107214344UL); + + phalcon_update_property_array_append(this_ptr, SL("_messages"), model_message TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator, getMessages){ + + + RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator, getOptions){ + + + RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator, getOption){ + + zval *option, *options, *value; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &option); + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (phalcon_array_isset(options, option)) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, options, option, PH_NOISY); + RETURN_CCTOR(value); + } + + RETURN_MM_EMPTY_STRING(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Validator, isSetOption){ + + zval *option, *options, *is_set = NULL; + zval *r0 = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &option); + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(r0); + ZVAL_BOOL(r0, phalcon_array_isset(options, option)); + PHALCON_CPY_WRT(is_set, r0); + RETURN_NCTOR(is_set); } + #ifdef HAVE_CONFIG_H #endif +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_ValidatorInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, ValidatorInterface, mvc_model_validatorinterface, phalcon_mvc_model_validatorinterface_method_entry); + + return SUCCESS; +} -PHALCON_INIT_CLASS(Phalcon_Mvc_View_Engine_Volt_Compiler){ - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\View\\Engine\\Volt, Compiler, mvc_view_engine_volt_compiler, phalcon_mvc_view_engine_volt_compiler_method_entry, 0); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_view"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_arrayHelpers"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_level"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_foreachLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_blockLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_exprLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_view_engine_volt_compiler_ce, SL("_extended"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_view_engine_volt_compiler_ce, SL("_autoescape"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_extendedBlocks"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_currentBlock"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_blocks"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_forElsePointers"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_loopPointers"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_extensions"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_functions"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_macros"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_prefix"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_currentPath"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_compiledTemplatePath"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_mvc_view_engine_volt_compiler_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc, Model, mvc_model, phalcon_mvc_model_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_property_null(phalcon_mvc_model_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_ce, SL("_modelsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_ce, SL("_modelsMetaData"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_ce, SL("_errorMessages"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_model_ce, SL("_operationMade"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_model_ce, SL("_dirtyState"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_ce, SL("_transaction"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_ce, SL("_uniqueKey"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_ce, SL("_uniqueParams"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_ce, SL("_uniqueTypes"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_ce, SL("_skipped"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_ce, SL("_related"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_model_ce, SL("_snapshot"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("OP_NONE"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("OP_CREATE"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("OP_UPDATE"), 2 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("OP_DELETE"), 3 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("DIRTY_STATE_PERSISTENT"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("DIRTY_STATE_TRANSIENT"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("DIRTY_STATE_DETACHED"), 2 TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_ce TSRMLS_CC, 4, phalcon_mvc_modelinterface_ce, phalcon_mvc_model_resultinterface_ce, phalcon_di_injectionawareinterface_ce, zend_ce_serializable); return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model, __construct){ - zval *view = NULL; + zval *dependency_injector = NULL, *models_manager = NULL; + zval *service_name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &view); + phalcon_fetch_params(1, 0, 2, &dependency_injector, &models_manager); - if (!view) { - PHALCON_INIT_VAR(view); + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); + } else { + PHALCON_SEPARATE_PARAM(dependency_injector); } - if (Z_TYPE_P(view) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_view"), view, 3993744575UL TSRMLS_CC); + if (!models_manager) { + PHALCON_INIT_VAR(models_manager); + } else { + PHALCON_SEPARATE_PARAM(models_manager); + } + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_NVAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + } + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); + return; + } + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + + if (Z_TYPE_P(models_manager) != IS_OBJECT) { + + PHALCON_INIT_VAR(service_name); + ZVAL_STRING(service_name, "modelsManager", 1); + + PHALCON_INIT_NVAR(models_manager); + phalcon_call_method_p1_key(models_manager, dependency_injector, "getshared", service_name, 1727570332UL); + if (Z_TYPE_P(models_manager) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The injected service 'modelsManager' is not valid"); + return; + } + } + + phalcon_update_property_this_quick(this_ptr, SL("_modelsManager"), models_manager, 3699347875UL TSRMLS_CC); + + phalcon_call_method_p1_key(NULL, models_manager, "initialize", this_ptr, 2896075127UL); + + if (phalcon_method_quick_exists_ex(this_ptr, SS("onconstruct"), 564344039UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, this_ptr, "onconstruct", 564344039UL); } PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setDI){ +static PHP_METHOD(Phalcon_Mvc_Model, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Model, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model, setEventsManager){ + + zval *events_manager, *models_manager; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &events_manager); + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, models_manager, "setcustomeventsmanager", this_ptr, events_manager, 3062798396UL); + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, getEventsManager){ + + zval *models_manager; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, models_manager, "getcustomeventsmanager", this_ptr, 1410017072UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, getModelsMetaData){ + + zval *meta_data = NULL, *dependency_injector, *service; - zval *dependency_injector; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &dependency_injector); + PHALCON_OBS_VAR(meta_data); + phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_modelsMetaData"), 3906670569UL, PH_NOISY_CC); + if (Z_TYPE_P(meta_data) != IS_OBJECT) { - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Dependency Injector is invalid"); - return; + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); + return; + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "modelsMetadata", 1); + + PHALCON_INIT_NVAR(meta_data); + phalcon_call_method_p1_key(meta_data, dependency_injector, "getshared", service, 1727570332UL); + if (Z_TYPE_P(meta_data) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The injected service 'modelsMetadata' is not valid"); + return; + } + + phalcon_update_property_this_quick(this_ptr, SL("_modelsMetaData"), meta_data, 3906670569UL TSRMLS_CC); } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + RETURN_CCTOR(meta_data); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getDI){ +static PHP_METHOD(Phalcon_Mvc_Model, getModelsManager){ - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); + RETURN_MEMBER_QUICK(this_ptr, "_modelsManager", 3699347875UL); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setOptions){ +static PHP_METHOD(Phalcon_Mvc_Model, setTransaction){ - zval *options; + zval *transaction; - phalcon_fetch_params(0, 1, 0, &options); + phalcon_fetch_params(0, 1, 0, &transaction); - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Options must be an array"); - return; + if (Z_TYPE_P(transaction) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_transaction"), transaction, 1141465066UL TSRMLS_CC); + RETURN_THISW(); } - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Transaction should be an object"); + return; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setOption){ +static PHP_METHOD(Phalcon_Mvc_Model, setSource){ - zval *option, *value; + zval *source, *models_manager; - phalcon_fetch_params(0, 2, 0, &option, &value); - - phalcon_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &source); + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, models_manager, "setmodelsource", this_ptr, source, 3377351315UL); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getOption){ +static PHP_METHOD(Phalcon_Mvc_Model, getSource){ - zval *option, *options, *value; + zval *models_manager; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &option); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (phalcon_array_isset(options, option)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, options, option, PH_NOISY); - RETURN_CCTOR(value); - } + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, models_manager, "getmodelsource", this_ptr, 569714055UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, setSchema){ + + zval *schema, *models_manager; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &schema); - RETURN_MM_NULL(); + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, models_manager, "setmodelschema", this_ptr, schema, 2891853203UL); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getOptions){ +static PHP_METHOD(Phalcon_Mvc_Model, getSchema){ + + zval *models_manager; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, models_manager, "getmodelschema", this_ptr, 84215943UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, fireExtensionEvent){ +static PHP_METHOD(Phalcon_Mvc_Model, setConnectionService){ - zval *name, *arguments = NULL, *extensions, *extension = NULL; - zval *call_object = NULL, *status = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *connection_service, *models_manager; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, &arguments); - - if (!arguments) { - PHALCON_INIT_VAR(arguments); - } - - PHALCON_OBS_VAR(extensions); - phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); - if (Z_TYPE_P(extensions) == IS_ARRAY) { - - phalcon_is_iterable(extensions, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(extension); - - if (phalcon_method_exists(extension, name TSRMLS_CC) == SUCCESS) { - - PHALCON_INIT_NVAR(call_object); - array_init_size(call_object, 2); - phalcon_array_append(&call_object, extension, PH_SEPARATE); - phalcon_array_append(&call_object, name, PH_SEPARATE); - if (Z_TYPE_P(arguments) == IS_ARRAY) { - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC_ARRAY(status, call_object, arguments); - } else { - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC(status, call_object); - } - - if (Z_TYPE_P(status) == IS_STRING) { - RETURN_CCTOR(status); - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } + phalcon_fetch_params(1, 1, 0, &connection_service); - PHALCON_MM_RESTORE(); + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, models_manager, "setconnectionservice", this_ptr, connection_service, 4052304818UL); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addExtension){ +static PHP_METHOD(Phalcon_Mvc_Model, setReadConnectionService){ - zval *extension; + zval *connection_service, *models_manager; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &extension); - - if (Z_TYPE_P(extension) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The extension is not valid"); - return; - } - - if (phalcon_method_quick_exists_ex(extension, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_p1_key(NULL, extension, "initialize", this_ptr, 2896075127UL); - } - - phalcon_update_property_array_append(this_ptr, SL("_extensions"), extension TSRMLS_CC); + phalcon_fetch_params(1, 1, 0, &connection_service); + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, models_manager, "setreadconnectionservice", this_ptr, connection_service, 1669421294UL); RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getExtensions){ +static PHP_METHOD(Phalcon_Mvc_Model, setWriteConnectionService){ + zval *connection_service, *models_manager; - RETURN_MEMBER_QUICK(this_ptr, "_extensions", 726159316UL); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &connection_service); + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, models_manager, "setwriteconnectionservice", this_ptr, connection_service, 1190096957UL); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addFunction){ +static PHP_METHOD(Phalcon_Mvc_Model, getReadConnectionService){ - zval *name, *definition; + zval *models_manager; - phalcon_fetch_params(0, 2, 0, &name, &definition); - - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "The function name must be a string"); - return; - } - phalcon_update_property_array(this_ptr, SL("_functions"), name, definition TSRMLS_CC); - - RETURN_THISW(); + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, models_manager, "getreadconnectionservice", this_ptr, 1381856482UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getFunctions){ +static PHP_METHOD(Phalcon_Mvc_Model, getWriteConnectionService){ + zval *models_manager; - RETURN_MEMBER_QUICK(this_ptr, "_functions", 2704716189UL); + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, models_manager, "getwriteconnectionservice", this_ptr, 290392753UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addFilter){ +static PHP_METHOD(Phalcon_Mvc_Model, setDirtyState){ - zval *name, *definition; + zval *dirty_state; - phalcon_fetch_params(0, 2, 0, &name, &definition); - - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "The function name must be a string"); - return; - } - phalcon_update_property_array(this_ptr, SL("_filters"), name, definition TSRMLS_CC); + phalcon_fetch_params(0, 1, 0, &dirty_state); + phalcon_update_property_this_quick(this_ptr, SL("_dirtyState"), dirty_state, 1560981745UL TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getFilters){ +static PHP_METHOD(Phalcon_Mvc_Model, getDirtyState){ - RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL); + RETURN_MEMBER_QUICK(this_ptr, "_dirtyState", 1560981745UL); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setUniquePrefix){ +static PHP_METHOD(Phalcon_Mvc_Model, getReadConnection){ - zval *prefix; + zval *models_manager; - phalcon_fetch_params(0, 1, 0, &prefix); - - phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); - RETURN_THISW(); + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, models_manager, "getreadconnection", this_ptr, 488334257UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getUniquePrefix){ +static PHP_METHOD(Phalcon_Mvc_Model, getWriteConnection){ - zval *prefix = NULL, *current_path, *parameters, *calculated_prefix; + zval *transaction, *models_manager; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - if (!zend_is_true(prefix)) { - PHALCON_OBS_VAR(current_path); - phalcon_read_property_this_quick(¤t_path, this_ptr, SL("_currentPath"), 3436123892UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(prefix); - phalcon_unique_path_key(prefix, current_path TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); - } - - if (Z_TYPE_P(prefix) == IS_OBJECT) { - if (phalcon_is_instance_of(prefix, SL("Closure") TSRMLS_CC)) { - PHALCON_INIT_VAR(parameters); - array_init_size(parameters, 1); - phalcon_array_append(¶meters, this_ptr, PH_SEPARATE); - - PHALCON_INIT_VAR(calculated_prefix); - phalcon_call_func_p2(calculated_prefix, "call_user_func_array", prefix, parameters); - phalcon_update_property_this_quick(this_ptr, SL("_prefix"), calculated_prefix, 3873791314UL TSRMLS_CC); - PHALCON_CPY_WRT(prefix, calculated_prefix); - } - } - - if (Z_TYPE_P(prefix) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The unique compilation prefix is invalid"); - return; + PHALCON_OBS_VAR(transaction); + phalcon_read_property_this_quick(&transaction, this_ptr, SL("_transaction"), 1141465066UL, PH_NOISY_CC); + if (Z_TYPE_P(transaction) == IS_OBJECT) { + phalcon_call_method_key(return_value, transaction, "getconnection", 2504689909UL); + RETURN_MM(); } - RETURN_CCTOR(prefix); + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p1_key(return_value, models_manager, "getwriteconnection", this_ptr, 4280185952UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, attributeReader){ +static PHP_METHOD(Phalcon_Mvc_Model, assign){ - zval *expr, *expr_code, *loop_context, *left, *left_type; - zval *variable, *level, *prefix, *dependency_injector; - zval *is_service, *left_code, *right, *right_type; - zval *member, *right_code; + zval *data, *column_map = NULL, *value = NULL, *key = NULL, *attribute = NULL; + zval *exception_message = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &expr); - - PHALCON_INIT_VAR(expr_code); + phalcon_fetch_params(1, 1, 1, &data, &column_map); - PHALCON_INIT_VAR(loop_context); + if (!column_map) { + PHALCON_INIT_VAR(column_map); + } - PHALCON_OBS_VAR(left); - phalcon_array_fetch_quick_string(&left, expr, SS("left"), 265976240UL, PH_NOISY); + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data to dump in the object must be an Array"); + return; + } - PHALCON_OBS_VAR(left_type); - phalcon_array_fetch_quick_string(&left_type, left, SS("type"), 276192743UL, PH_NOISY); - if (PHALCON_IS_LONG(left_type, 265)) { + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - PHALCON_OBS_VAR(variable); - phalcon_array_fetch_quick_string(&variable, left, SS("value"), 574111618UL, PH_NOISY); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (PHALCON_IS_STRING(variable, "loop")) { - PHALCON_OBS_VAR(level); - phalcon_read_property_this_quick(&level, this_ptr, SL("_foreachLevel"), 1560648116UL, PH_NOISY_CC); + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - PHALCON_INIT_VAR(prefix); - phalcon_call_method_key(prefix, this_ptr, "getuniqueprefix", 3888429962UL); - PHALCON_SCONCAT_SVVS(expr_code, "$", prefix, level, "loop"); - phalcon_update_property_array(this_ptr, SL("_loopPointers"), level, level TSRMLS_CC); - } else { - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + if (Z_TYPE_P(column_map) == IS_ARRAY) { - PHALCON_INIT_VAR(is_service); - phalcon_call_method_p1_key(is_service, dependency_injector, "has", variable, 2090320481UL); - if (zend_is_true(is_service)) { - PHALCON_SCONCAT_SV(expr_code, "$this->", variable); - } else { - PHALCON_SCONCAT_SV(expr_code, "$", variable); - } - } else { - PHALCON_SCONCAT_SV(expr_code, "$", variable); - } - } - } else { - PHALCON_INIT_VAR(left_code); - phalcon_call_method_p1_key(left_code, this_ptr, "expression", left, 218841909UL); - if (!PHALCON_IS_LONG(left_type, 46)) { - if (!PHALCON_IS_LONG(left_type, 350)) { - PHALCON_SCONCAT_SVS(expr_code, "(", left_code, ")"); + if (phalcon_array_isset(column_map, key)) { + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch(&attribute, column_map, key, PH_NOISY); + phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); } else { - phalcon_concat_self(&expr_code, left_code TSRMLS_CC); + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column \"", key, "\" doesn't make part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } } else { - phalcon_concat_self(&expr_code, left_code TSRMLS_CC); + phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); } - } - - phalcon_concat_self_str(&expr_code, SL("->") TSRMLS_CC); - - PHALCON_OBS_VAR(right); - phalcon_array_fetch_quick_string(&right, expr, SS("right"), 426864067UL, PH_NOISY); - PHALCON_OBS_VAR(right_type); - phalcon_array_fetch_quick_string(&right_type, right, SS("type"), 276192743UL, PH_NOISY); - if (PHALCON_IS_LONG(right_type, 265)) { - PHALCON_OBS_VAR(member); - phalcon_array_fetch_quick_string(&member, right, SS("value"), 574111618UL, PH_NOISY); - phalcon_concat_self(&expr_code, member TSRMLS_CC); - } else { - PHALCON_INIT_VAR(right_code); - phalcon_call_method_p1_key(right_code, this_ptr, "expression", right, 218841909UL); - phalcon_concat_self(&expr_code, right_code TSRMLS_CC); + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CCTOR(expr_code); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall){ +static PHP_METHOD(Phalcon_Mvc_Model, cloneResultMap){ - zval *expr, *code = NULL, *func_arguments = NULL, *arguments = NULL; - zval *name_expr, *name_type, *name = NULL, *extensions; - zval *event, *fire_arguments, *functions, *definition; - zval *parameters, *line = NULL, *file = NULL, *exception_message = NULL; - zval *macros, *extended_blocks, *current_block; - zval *expr_level, *block, *escaped_code = NULL, *camelized; - zval *method, *class_name, *array_helpers = NULL; + zval *base, *data, *column_map, *dirty_state = NULL, *keep_snapshots = NULL; + zval *object, *value = NULL, *key = NULL, *attribute = NULL, *exception_message = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &expr); - - if (Z_TYPE_P(expr) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted function call"); - return; - } - - PHALCON_INIT_VAR(code); - - PHALCON_INIT_VAR(func_arguments); - if (phalcon_array_isset_quick_string(expr, SS("arguments"), 3751272283UL)) { - PHALCON_OBS_NVAR(func_arguments); - phalcon_array_fetch_quick_string(&func_arguments, expr, SS("arguments"), 3751272283UL, PH_NOISY); - - PHALCON_INIT_VAR(arguments); - phalcon_call_method_p1_key(arguments, this_ptr, "expression", func_arguments, 218841909UL); - } else { - PHALCON_INIT_NVAR(arguments); - ZVAL_STRING(arguments, "", 1); - } - - PHALCON_OBS_VAR(name_expr); - phalcon_array_fetch_quick_string(&name_expr, expr, SS("name"), 268211462UL, PH_NOISY); - - PHALCON_OBS_VAR(name_type); - phalcon_array_fetch_quick_string(&name_type, name_expr, SS("type"), 276192743UL, PH_NOISY); - - if (PHALCON_IS_LONG(name_type, 265)) { - - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, name_expr, SS("value"), 574111618UL, PH_NOISY); - - PHALCON_OBS_VAR(extensions); - phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); - if (Z_TYPE_P(extensions) == IS_ARRAY) { - - PHALCON_INIT_VAR(event); - ZVAL_STRING(event, "compileFunction", 1); - - PHALCON_INIT_VAR(fire_arguments); - array_init_size(fire_arguments, 3); - phalcon_array_append(&fire_arguments, name, PH_SEPARATE); - phalcon_array_append(&fire_arguments, arguments, PH_SEPARATE); - phalcon_array_append(&fire_arguments, func_arguments, PH_SEPARATE); - - phalcon_call_method_p2_key(code, this_ptr, "fireextensionevent", event, fire_arguments, 1575031978UL); - if (Z_TYPE_P(code) == IS_STRING) { - RETURN_CCTOR(code); - } - } - - PHALCON_OBS_VAR(functions); - phalcon_read_property_this_quick(&functions, this_ptr, SL("_functions"), 2704716189UL, PH_NOISY_CC); - if (Z_TYPE_P(functions) == IS_ARRAY) { - if (phalcon_array_isset(functions, name)) { - - PHALCON_OBS_VAR(definition); - phalcon_array_fetch(&definition, functions, name, PH_NOISY); - - if (Z_TYPE_P(definition) == IS_STRING) { - PHALCON_CONCAT_VSVS(return_value, definition, "(", arguments, ")"); - RETURN_MM(); - } - - if (Z_TYPE_P(definition) == IS_OBJECT) { - if (phalcon_is_instance_of(definition, SL("Closure") TSRMLS_CC)) { - PHALCON_INIT_VAR(parameters); - array_init_size(parameters, 2); - phalcon_array_append(¶meters, arguments, PH_SEPARATE); - phalcon_array_append(¶meters, func_arguments, PH_SEPARATE); - phalcon_call_func_p2(return_value, "call_user_func_array", definition, parameters); - RETURN_MM(); - } - } - - PHALCON_OBS_VAR(line); - phalcon_array_fetch_quick_string(&line, expr, SS("line"), 266128205UL, PH_NOISY); - - PHALCON_OBS_VAR(file); - phalcon_array_fetch_quick_string(&file, expr, SS("file"), 259010501UL, PH_NOISY); - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVSVSV(exception_message, "Invalid definition for user function '", name, "' in ", file, " on line ", line); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; - } - } - - PHALCON_OBS_VAR(macros); - phalcon_read_property_this_quick(¯os, this_ptr, SL("_macros"), 3627118793UL, PH_NOISY_CC); - - if (phalcon_array_isset(macros, name)) { - PHALCON_CONCAT_SVSVS(return_value, "vmacro_", name, "(array(", arguments, "))"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "get_content")) { - RETURN_MM_STRING("$this->getContent()", 1); - } - - if (PHALCON_IS_STRING(name, "content")) { - RETURN_MM_STRING("$this->getContent()", 1); - } + phalcon_fetch_params(1, 3, 2, &base, &data, &column_map, &dirty_state, &keep_snapshots); - if (PHALCON_IS_STRING(name, "partial")) { - PHALCON_CONCAT_SVS(return_value, "$this->partial(", arguments, ")"); - RETURN_MM(); - } + if (!dirty_state) { + PHALCON_INIT_VAR(dirty_state); + ZVAL_LONG(dirty_state, 0); + } - if (PHALCON_IS_STRING(name, "super")) { + if (!keep_snapshots) { + PHALCON_INIT_VAR(keep_snapshots); + } - PHALCON_OBS_VAR(extended_blocks); - phalcon_read_property_this_quick(&extended_blocks, this_ptr, SL("_extendedBlocks"), 3140083987UL, PH_NOISY_CC); - if (Z_TYPE_P(extended_blocks) == IS_ARRAY) { + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data to dump in the object must be an Array"); + return; + } - PHALCON_OBS_VAR(current_block); - phalcon_read_property_this_quick(¤t_block, this_ptr, SL("_currentBlock"), 1187906770UL, PH_NOISY_CC); - if (phalcon_array_isset(extended_blocks, current_block)) { + PHALCON_INIT_VAR(object); + if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { + return; + } - PHALCON_OBS_VAR(expr_level); - phalcon_read_property_this_quick(&expr_level, this_ptr, SL("_exprLevel"), 4164657371UL, PH_NOISY_CC); + phalcon_call_method_p1_key(NULL, object, "setdirtystate", dirty_state, 1304577662UL); - PHALCON_OBS_VAR(block); - phalcon_array_fetch(&block, extended_blocks, current_block, PH_NOISY); - if (Z_TYPE_P(block) == IS_ARRAY) { + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(code); - phalcon_call_method_p1_key(code, this_ptr, "_statementlistorextends", block, 2351303889UL); - if (PHALCON_IS_LONG(expr_level, 1)) { - PHALCON_CPY_WRT(escaped_code, code); - } else { - PHALCON_INIT_NVAR(escaped_code); - phalcon_call_func_p1(escaped_code, "addslashes", code); - } - } else { - if (PHALCON_IS_LONG(expr_level, 1)) { - PHALCON_CPY_WRT(escaped_code, block); - } else { - PHALCON_INIT_NVAR(escaped_code); - phalcon_call_func_p1(escaped_code, "addslashes", block); - } - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (PHALCON_IS_LONG(expr_level, 1)) { - RETURN_CCTOR(escaped_code); - } + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - PHALCON_CONCAT_SVS(return_value, "'", escaped_code, "'"); + if (Z_TYPE_P(key) == IS_STRING) { - RETURN_MM(); + if (Z_TYPE_P(column_map) == IS_ARRAY) { + + if (phalcon_array_isset(column_map, key)) { + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch(&attribute, column_map, key, PH_NOISY); + phalcon_update_property_zval_zval(object, attribute, value TSRMLS_CC); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column \"", key, "\" doesn't make part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } + } else { + phalcon_update_property_zval_zval(object, key, value TSRMLS_CC); } - - RETURN_MM_STRING("''", 1); } - PHALCON_INIT_VAR(camelized); - phalcon_camelize(camelized, name); - - PHALCON_INIT_VAR(method); - phalcon_lcfirst(method, camelized); - - PHALCON_INIT_VAR(class_name); - ZVAL_STRING(class_name, "Phalcon\\Tag", 1); - - if (phalcon_method_exists(class_name, method TSRMLS_CC) == SUCCESS) { + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_OBS_VAR(array_helpers); - phalcon_read_property_this_quick(&array_helpers, this_ptr, SL("_arrayHelpers"), 3087512406UL, PH_NOISY_CC); - if (Z_TYPE_P(array_helpers) != IS_ARRAY) { - PHALCON_INIT_NVAR(array_helpers); - array_init_size(array_helpers, 15); - 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); - add_assoc_bool_ex(array_helpers, SS("select"), 1); - add_assoc_bool_ex(array_helpers, SS("select_static"), 1); - add_assoc_bool_ex(array_helpers, SS("submit_button"), 1); - add_assoc_bool_ex(array_helpers, SS("radio_field"), 1); - add_assoc_bool_ex(array_helpers, SS("check_field"), 1); - add_assoc_bool_ex(array_helpers, SS("file_field"), 1); - add_assoc_bool_ex(array_helpers, SS("hidden_field"), 1); - add_assoc_bool_ex(array_helpers, SS("password_field"), 1); - add_assoc_bool_ex(array_helpers, SS("text_area"), 1); - add_assoc_bool_ex(array_helpers, SS("text_field"), 1); - add_assoc_bool_ex(array_helpers, SS("date_field"), 1); - add_assoc_bool_ex(array_helpers, SS("numeric_field"), 1); - phalcon_update_property_this_quick(this_ptr, SL("_arrayHelpers"), array_helpers, 3087512406UL TSRMLS_CC); - } + if (zend_is_true(keep_snapshots)) { + phalcon_call_method_p2_key(NULL, object, "setsnapshotdata", data, column_map, 1073494651UL); + } - if (phalcon_array_isset(array_helpers, name)) { - PHALCON_CONCAT_SVSVS(return_value, "Phalcon\\Tag::", method, "(array(", arguments, "))"); - RETURN_MM(); - } + if (phalcon_method_quick_exists_ex(object, SS("afterfetch"), 1256108385UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, object, "afterfetch", 1256108385UL); + } - PHALCON_CONCAT_SVSVS(return_value, "Phalcon\\Tag::", method, "(", arguments, ")"); + RETURN_CCTOR(object); +} + +static PHP_METHOD(Phalcon_Mvc_Model, cloneResultMapHydrate){ + + zval *data, *column_map, *hydration_mode, *hydrate = NULL; + zval *value = NULL, *key = NULL, *exception_message = NULL, *attribute = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &data, &column_map, &hydration_mode); - RETURN_MM(); - } + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data to hidrate must be an Array"); + return; + } - if (PHALCON_IS_STRING(name, "url")) { - PHALCON_CONCAT_SVS(return_value, "$this->url->get(", arguments, ")"); - RETURN_MM(); + if (Z_TYPE_P(column_map) != IS_ARRAY) { + if (PHALCON_IS_LONG(hydration_mode, 1)) { + RETURN_CCTOR(data); } + } - if (PHALCON_IS_STRING(name, "static_url")) { - PHALCON_CONCAT_SVS(return_value, "$this->url->getStatic(", arguments, ")"); - RETURN_MM(); - } + if (PHALCON_IS_LONG(hydration_mode, 1)) { + PHALCON_INIT_VAR(hydrate); + array_init(hydrate); + } else { + PHALCON_INIT_NVAR(hydrate); + object_init(hydrate); + } - if (PHALCON_IS_STRING(name, "date")) { - PHALCON_CONCAT_SVS(return_value, "date(", arguments, ")"); - RETURN_MM(); - } + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - if (PHALCON_IS_STRING(name, "time")) { - PHALCON_INIT_NVAR(code); - ZVAL_STRING(code, "time()", 1); - RETURN_CCTOR(code); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (PHALCON_IS_STRING(name, "dump")) { - PHALCON_CONCAT_SVS(return_value, "var_dump(", arguments, ")"); - RETURN_MM(); - } + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - if (PHALCON_IS_STRING(name, "version")) { - RETURN_MM_STRING("Phalcon\\Version::get()", 1); - } + if (Z_TYPE_P(key) == IS_STRING) { + if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (PHALCON_IS_STRING(name, "version_id")) { - RETURN_MM_STRING("Phalcon\\Version::getId()", 1); - } + if (!phalcon_array_isset(column_map, key)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column \"", key, "\" doesn't make part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } - if (PHALCON_IS_STRING(name, "constant")) { - PHALCON_CONCAT_SVS(return_value, "constant(", arguments, ")"); - RETURN_MM(); + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch(&attribute, column_map, key, PH_NOISY); + if (PHALCON_IS_LONG(hydration_mode, 1)) { + phalcon_array_update_zval(&hydrate, attribute, &value, PH_COPY | PH_SEPARATE); + } else { + phalcon_update_property_zval_zval(hydrate, attribute, value TSRMLS_CC); + } + } else { + if (PHALCON_IS_LONG(hydration_mode, 1)) { + phalcon_array_update_zval(&hydrate, key, &value, PH_COPY | PH_SEPARATE); + } else { + phalcon_update_property_zval_zval(hydrate, key, value TSRMLS_CC); + } + } } - PHALCON_OBS_NVAR(line); - phalcon_array_fetch_quick_string(&line, expr, SS("line"), 266128205UL, PH_NOISY); - - PHALCON_OBS_NVAR(file); - phalcon_array_fetch_quick_string(&file, expr, SS("file"), 259010501UL, PH_NOISY); - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVSV(exception_message, "Undefined function '", name, "' in ", file, " on line ", line); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; + zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_INIT_NVAR(name); - phalcon_call_method_p1_key(name, this_ptr, "expression", name_expr, 218841909UL); - PHALCON_CONCAT_VSVS(return_value, name, "(", arguments, ")"); - - RETURN_MM(); + RETURN_CCTOR(hydrate); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, resolveTest){ +static PHP_METHOD(Phalcon_Mvc_Model, cloneResult){ - zval *test, *left, *type, *name = NULL, *test_name, *test_arguments = NULL; - zval *arguments = NULL, *right_code; + zval *base, *data, *dirty_state = NULL, *object, *value = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &test, &left); + phalcon_fetch_params(1, 2, 1, &base, &data, &dirty_state); - if (Z_TYPE_P(test) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted test"); + if (!dirty_state) { + PHALCON_INIT_VAR(dirty_state); + ZVAL_LONG(dirty_state, 0); + } + + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data to dump in the object must be an Array"); return; } - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, test, SS("type"), 276192743UL, PH_NOISY); + PHALCON_INIT_VAR(object); + if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { + return; + } - if (PHALCON_IS_LONG(type, 265)) { + phalcon_call_method_p1_key(NULL, object, "setdirtystate", dirty_state, 1304577662UL); - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, test, SS("value"), 574111618UL, PH_NOISY); + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - if (PHALCON_IS_STRING(name, "empty")) { - PHALCON_CONCAT_SVS(return_value, "empty(", left, ")"); - RETURN_MM(); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (PHALCON_IS_STRING(name, "even")) { - PHALCON_CONCAT_SVS(return_value, "(((", left, ") % 2) == 0)"); - RETURN_MM(); - } + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - if (PHALCON_IS_STRING(name, "odd")) { - PHALCON_CONCAT_SVS(return_value, "(((", left, ") % 2) != 0)"); - RETURN_MM(); + if (Z_TYPE_P(key) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid key in array data provided to dumpResult()"); + return; } + phalcon_update_property_zval_zval(object, key, value TSRMLS_CC); - if (PHALCON_IS_STRING(name, "numeric")) { - PHALCON_CONCAT_SVS(return_value, "is_numeric(", left, ")"); - RETURN_MM(); - } + zend_hash_move_forward_ex(ah0, &hp0); + } - if (PHALCON_IS_STRING(name, "scalar")) { - PHALCON_CONCAT_SVS(return_value, "is_scalar(", left, ")"); - RETURN_MM(); - } + if (phalcon_method_quick_exists_ex(object, SS("afterfetch"), 1256108385UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, object, "afterfetch", 1256108385UL); + } - if (PHALCON_IS_STRING(name, "iterable")) { - PHALCON_CONCAT_SVSVS(return_value, "(is_array(", left, ") || (", left, ") instanceof Traversable)"); - RETURN_MM(); - } + RETURN_CCTOR(object); +} + +static PHP_METHOD(Phalcon_Mvc_Model, find){ + + zval *parameters = NULL, *model_name, *params = NULL, *builder; + zval *query, *bind_params = NULL, *bind_types = NULL, *cache; + zval *resultset, *hydration; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); } - if (PHALCON_IS_LONG(type, 350)) { + PHALCON_INIT_VAR(model_name); + phalcon_get_called_class(model_name TSRMLS_CC); + if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_OBS_VAR(test_name); - phalcon_array_fetch_quick_string(&test_name, test, SS("name"), 268211462UL, PH_NOISY); - if (phalcon_array_isset_quick_string(test_name, SS("value"), 574111618UL)) { + PHALCON_INIT_VAR(params); + array_init(params); + if (Z_TYPE_P(parameters) != IS_NULL) { + phalcon_array_append(¶ms, parameters, PH_SEPARATE); + } + } else { + PHALCON_CPY_WRT(params, parameters); + } - PHALCON_OBS_NVAR(name); - phalcon_array_fetch_quick_string(&name, test_name, SS("value"), 574111618UL, PH_NOISY); - if (PHALCON_IS_STRING(name, "divisibleby")) { - PHALCON_OBS_VAR(test_arguments); - phalcon_array_fetch_quick_string(&test_arguments, test, SS("arguments"), 3751272283UL, PH_NOISY); + PHALCON_INIT_VAR(builder); + object_init_ex(builder, phalcon_mvc_model_query_builder_ce); + phalcon_call_method_p1_key(NULL, builder, "__construct", params, 1107214344UL); - PHALCON_INIT_VAR(arguments); - phalcon_call_method_p1_key(arguments, this_ptr, "expression", test_arguments, 218841909UL); - PHALCON_CONCAT_SVSVS(return_value, "(((", left, ") % (", arguments, ")) == 0)"); - RETURN_MM(); - } + phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - if (PHALCON_IS_STRING(name, "sameas")) { - PHALCON_OBS_NVAR(test_arguments); - phalcon_array_fetch_quick_string(&test_arguments, test, SS("arguments"), 3751272283UL, PH_NOISY); + PHALCON_INIT_VAR(query); + phalcon_call_method_key(query, builder, "getquery", 4154457883UL); - PHALCON_INIT_NVAR(arguments); - phalcon_call_method_p1_key(arguments, this_ptr, "expression", test_arguments, 218841909UL); - PHALCON_CONCAT_SVSVS(return_value, "(", left, ") === (", arguments, ")"); - RETURN_MM(); - } + PHALCON_INIT_VAR(bind_params); - if (PHALCON_IS_STRING(name, "type")) { - PHALCON_OBS_NVAR(test_arguments); - phalcon_array_fetch_quick_string(&test_arguments, test, SS("arguments"), 3751272283UL, PH_NOISY); + PHALCON_INIT_VAR(bind_types); - PHALCON_INIT_NVAR(arguments); - phalcon_call_method_p1_key(arguments, this_ptr, "expression", test_arguments, 218841909UL); - PHALCON_CONCAT_SVSVS(return_value, "gettype(", left, ") === (", arguments, ")"); - RETURN_MM(); - } + if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { + + PHALCON_OBS_NVAR(bind_params); + phalcon_array_fetch_quick_string(&bind_params, params, SS("bind"), 254268962UL, PH_NOISY); + if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { + PHALCON_OBS_NVAR(bind_types); + phalcon_array_fetch_quick_string(&bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); } } - PHALCON_INIT_VAR(right_code); - phalcon_call_method_p1_key(right_code, this_ptr, "expression", test, 218841909UL); - PHALCON_CONCAT_VSV(return_value, left, " == ", right_code); + if (phalcon_array_isset_quick_string(params, SS("cache"), 4125168857UL)) { + PHALCON_OBS_VAR(cache); + phalcon_array_fetch_quick_string(&cache, params, SS("cache"), 4125168857UL, PH_NOISY); + phalcon_call_method_p1_key(NULL, query, "cache", cache, 4125168857UL); + } - RETURN_MM(); + PHALCON_INIT_VAR(resultset); + phalcon_call_method_p2_key(resultset, query, "execute", bind_params, bind_types, 3117639032UL); + + if (Z_TYPE_P(resultset) == IS_OBJECT) { + if (phalcon_array_isset_quick_string(params, SS("hydration"), 1688432023UL)) { + PHALCON_OBS_VAR(hydration); + phalcon_array_fetch_quick_string(&hydration, params, SS("hydration"), 1688432023UL, PH_NOISY); + phalcon_call_method_p1_key(NULL, resultset, "sethydratemode", hydration, 46032167UL); + } + } + + RETURN_CCTOR(resultset); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, resolveFilter){ +static PHP_METHOD(Phalcon_Mvc_Model, findFirst){ - zval *filter, *left, *code = NULL, *type, *name = NULL, *function_name; - zval *line = NULL, *file = NULL, *exception_message = NULL, *func_arguments = NULL; - zval *arguments = NULL, *resolved_expr, *resolved_param; - zval *extensions, *event, *fire_arguments, *filters; - zval *definition, *parameters; + zval *parameters = NULL, *model_name, *params = NULL, *builder; + zval *one, *query, *bind_params = NULL, *bind_types = NULL, *cache; + zval *unique; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &filter, &left); + phalcon_fetch_params(1, 0, 1, ¶meters); - if (Z_TYPE_P(filter) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted filter"); - return; + if (!parameters) { + PHALCON_INIT_VAR(parameters); } - PHALCON_INIT_VAR(code); - - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, filter, SS("type"), 276192743UL, PH_NOISY); + PHALCON_INIT_VAR(model_name); + phalcon_get_called_class(model_name TSRMLS_CC); + if (Z_TYPE_P(parameters) != IS_ARRAY) { - if (PHALCON_IS_LONG(type, 265)) { - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, filter, SS("value"), 574111618UL, PH_NOISY); + PHALCON_INIT_VAR(params); + array_init(params); + if (Z_TYPE_P(parameters) != IS_NULL) { + phalcon_array_append(¶ms, parameters, PH_SEPARATE); + } } else { - if (PHALCON_IS_LONG(type, 350)) { - PHALCON_OBS_VAR(function_name); - phalcon_array_fetch_quick_string(&function_name, filter, SS("name"), 268211462UL, PH_NOISY); + PHALCON_CPY_WRT(params, parameters); + } - PHALCON_OBS_NVAR(name); - phalcon_array_fetch_quick_string(&name, function_name, SS("value"), 574111618UL, PH_NOISY); - } else { - PHALCON_OBS_VAR(line); - phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); + PHALCON_INIT_VAR(builder); + object_init_ex(builder, phalcon_mvc_model_query_builder_ce); + phalcon_call_method_p1_key(NULL, builder, "__construct", params, 1107214344UL); - PHALCON_OBS_VAR(file); - phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); + phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Unknown filter type in ", file, " on line ", line); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + phalcon_call_method_p1_key(NULL, builder, "limit", one, 192268420UL); + + PHALCON_INIT_VAR(query); + phalcon_call_method_key(query, builder, "getquery", 4154457883UL); + + PHALCON_INIT_VAR(bind_params); + + PHALCON_INIT_VAR(bind_types); + if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { + + PHALCON_OBS_NVAR(bind_params); + phalcon_array_fetch_quick_string(&bind_params, params, SS("bind"), 254268962UL, PH_NOISY); + if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { + PHALCON_OBS_NVAR(bind_types); + phalcon_array_fetch_quick_string(&bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); } } - PHALCON_INIT_VAR(func_arguments); + if (phalcon_array_isset_quick_string(params, SS("cache"), 4125168857UL)) { + PHALCON_OBS_VAR(cache); + phalcon_array_fetch_quick_string(&cache, params, SS("cache"), 4125168857UL, PH_NOISY); + phalcon_call_method_p1_key(NULL, query, "cache", cache, 4125168857UL); + } - PHALCON_INIT_VAR(arguments); + PHALCON_INIT_VAR(unique); + ZVAL_BOOL(unique, 1); - if (phalcon_array_isset_quick_string(filter, SS("arguments"), 3751272283UL)) { + phalcon_call_method_p1_key(NULL, query, "setuniquerow", unique, 2999205376UL); - PHALCON_OBS_NVAR(file); - phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); + phalcon_call_method_p2_key(return_value, query, "execute", bind_params, bind_types, 3117639032UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, query){ + + zval *dependency_injector = NULL, *model_name, *criteria; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &dependency_injector); - PHALCON_OBS_NVAR(line); - phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); + } else { + PHALCON_SEPARATE_PARAM(dependency_injector); + } - PHALCON_OBS_NVAR(func_arguments); - phalcon_array_fetch_quick_string(&func_arguments, filter, SS("arguments"), 3751272283UL, PH_NOISY); + PHALCON_INIT_VAR(model_name); + phalcon_get_called_class(model_name TSRMLS_CC); - if (!PHALCON_IS_STRING(name, "default")) { - PHALCON_INIT_VAR(resolved_expr); - array_init_size(resolved_expr, 4); - add_assoc_long_ex(resolved_expr, SS("type"), 364); - phalcon_array_update_quick_string(&resolved_expr, SS("value"), 574111618UL, &left, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&resolved_expr, SS("file"), 259010501UL, &file, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&resolved_expr, SS("line"), 266128205UL, &line, PH_COPY | PH_SEPARATE); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_NVAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + } - PHALCON_INIT_VAR(resolved_param); - array_init_size(resolved_param, 3); - phalcon_array_update_quick_string(&resolved_param, SS("expr"), 258368420UL, &resolved_expr, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&resolved_param, SS("file"), 259010501UL, &file, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&resolved_param, SS("line"), 266128205UL, &line, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(criteria); + object_init_ex(criteria, phalcon_mvc_model_criteria_ce); + phalcon_call_method_p1_key(NULL, criteria, "setdi", dependency_injector, 461718238UL); + phalcon_call_method_p1_key(NULL, criteria, "setmodelname", model_name, 3112384035UL); - phalcon_array_unshift(func_arguments, resolved_param); - } + RETURN_CTOR(criteria); +} + +static PHP_METHOD(Phalcon_Mvc_Model, _exists){ + + zval *meta_data, *connection, *table = NULL, *unique_params = NULL; + zval *unique_types = NULL, *unique_key = NULL, *primary_keys; + zval *bind_data_types, *number_primary, *column_map = NULL; + zval *null_value, *number_empty, *where_pk, *field = NULL; + zval *attribute_field = NULL, *exception_message = NULL; + zval *value = NULL, *escaped_field = NULL, *pk_condition = NULL, *type = NULL; + zval *join_where, *dirty_state, *schema, *source; + zval *escaped_table, *null_mode, *select, *num; + zval *row_count; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 1, &meta_data, &connection, &table); - phalcon_call_method_p1_key(arguments, this_ptr, "expression", func_arguments, 218841909UL); + if (!table) { + PHALCON_INIT_VAR(table); } else { - PHALCON_CPY_WRT(arguments, left); - } - - PHALCON_OBS_VAR(extensions); - phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); - if (Z_TYPE_P(extensions) == IS_ARRAY) { - - PHALCON_INIT_VAR(event); - ZVAL_STRING(event, "compileFilter", 1); - - PHALCON_INIT_VAR(fire_arguments); - array_init_size(fire_arguments, 3); - phalcon_array_append(&fire_arguments, name, PH_SEPARATE); - phalcon_array_append(&fire_arguments, arguments, PH_SEPARATE); - phalcon_array_append(&fire_arguments, func_arguments, PH_SEPARATE); - - phalcon_call_method_p2_key(code, this_ptr, "fireextensionevent", event, fire_arguments, 1575031978UL); - if (Z_TYPE_P(code) == IS_STRING) { - RETURN_CCTOR(code); - } + PHALCON_SEPARATE_PARAM(table); } - PHALCON_OBS_VAR(filters); - phalcon_read_property_this_quick(&filters, this_ptr, SL("_filters"), 3850488637UL, PH_NOISY_CC); - if (Z_TYPE_P(filters) == IS_ARRAY) { - if (phalcon_array_isset(filters, name)) { + PHALCON_INIT_VAR(unique_params); - PHALCON_OBS_VAR(definition); - phalcon_array_fetch(&definition, filters, name, PH_NOISY); + PHALCON_INIT_VAR(unique_types); - if (Z_TYPE_P(definition) == IS_STRING) { - PHALCON_CONCAT_VSVS(return_value, definition, "(", arguments, ")"); - RETURN_MM(); - } + PHALCON_OBS_VAR(unique_key); + phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); + if (Z_TYPE_P(unique_key) == IS_NULL) { - if (Z_TYPE_P(definition) == IS_OBJECT) { - if (phalcon_is_instance_of(definition, SL("Closure") TSRMLS_CC)) { - PHALCON_INIT_VAR(parameters); - array_init_size(parameters, 2); - phalcon_array_append(¶meters, arguments, PH_SEPARATE); - phalcon_array_append(¶meters, func_arguments, PH_SEPARATE); - phalcon_call_func_p2(return_value, "call_user_func_array", definition, parameters); - RETURN_MM(); - } - } + PHALCON_INIT_VAR(primary_keys); + phalcon_call_method_p1_key(primary_keys, meta_data, "getprimarykeyattributes", this_ptr, 692945721UL); - PHALCON_OBS_NVAR(line); - phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); + PHALCON_INIT_VAR(bind_data_types); + phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); - PHALCON_OBS_NVAR(file); - phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); + PHALCON_INIT_VAR(number_primary); + phalcon_fast_count(number_primary, primary_keys TSRMLS_CC); + if (!zend_is_true(number_primary)) { + RETURN_MM_FALSE; + } - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVSV(exception_message, "Invalid definition for user filter '", name, "' in ", file, " on line ", line); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); + } else { + PHALCON_INIT_NVAR(column_map); } - } - if (PHALCON_IS_STRING(name, "length")) { - PHALCON_CONCAT_SVS(return_value, "$this->length(", arguments, ")"); - RETURN_MM(); - } + PHALCON_INIT_VAR(null_value); - if (PHALCON_IS_STRING(name, "e")) { - PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtml(", arguments, ")"); - RETURN_MM(); - } + PHALCON_INIT_VAR(number_empty); + ZVAL_LONG(number_empty, 0); - if (PHALCON_IS_STRING(name, "escape")) { - PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtml(", arguments, ")"); - RETURN_MM(); - } + PHALCON_INIT_VAR(where_pk); + array_init(where_pk); - if (PHALCON_IS_STRING(name, "escape_css")) { - PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeCss(", arguments, ")"); - RETURN_MM(); - } + array_init(unique_params); - if (PHALCON_IS_STRING(name, "escape_js")) { - PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeJs(", arguments, ")"); - RETURN_MM(); - } + array_init(unique_types); - if (PHALCON_IS_STRING(name, "escape_attr")) { - PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtmlAttr(", arguments, ")"); - RETURN_MM(); - } + phalcon_is_iterable(primary_keys, &ah0, &hp0, 0, 0); - if (PHALCON_IS_STRING(name, "trim")) { - PHALCON_CONCAT_SVS(return_value, "trim(", arguments, ")"); - RETURN_MM(); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (PHALCON_IS_STRING(name, "left_trim")) { - PHALCON_CONCAT_SVS(return_value, "ltrim(", arguments, ")"); - RETURN_MM(); - } + PHALCON_GET_HVALUE(field); - if (PHALCON_IS_STRING(name, "right_trim")) { - PHALCON_CONCAT_SVS(return_value, "rtrim(", arguments, ")"); - RETURN_MM(); - } + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, field)) { + PHALCON_OBS_NVAR(attribute_field); + phalcon_array_fetch(&attribute_field, column_map, field, PH_NOISY); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } else { + PHALCON_CPY_WRT(attribute_field, field); + } - if (PHALCON_IS_STRING(name, "striptags")) { - PHALCON_CONCAT_SVS(return_value, "strip_tags(", arguments, ")"); - RETURN_MM(); - } + if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { - if (PHALCON_IS_STRING(name, "url_encode")) { - PHALCON_CONCAT_SVS(return_value, "urlencode(", arguments, ")"); - RETURN_MM(); - } + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); - if (PHALCON_IS_STRING(name, "slashes")) { - PHALCON_CONCAT_SVS(return_value, "addslashes(", arguments, ")"); - RETURN_MM(); - } + if (PHALCON_IS_EMPTY(value)) { + PHALCON_SEPARATE(number_empty); + phalcon_increment(number_empty); + } - if (PHALCON_IS_STRING(name, "stripslashes")) { - PHALCON_CONCAT_SVS(return_value, "stripslashes(", arguments, ")"); - RETURN_MM(); - } + phalcon_array_append(&unique_params, value, PH_SEPARATE); + } else { + phalcon_array_append(&unique_params, null_value, PH_SEPARATE); + PHALCON_SEPARATE(number_empty); + phalcon_increment(number_empty); + } - if (PHALCON_IS_STRING(name, "nl2br")) { - PHALCON_CONCAT_SVS(return_value, "nl2br(", arguments, ")"); - RETURN_MM(); - } + PHALCON_INIT_NVAR(escaped_field); + phalcon_call_method_p1_key(escaped_field, connection, "escapeidentifier", field, 585773337UL); - if (PHALCON_IS_STRING(name, "keys")) { - PHALCON_CONCAT_SVS(return_value, "array_keys(", arguments, ")"); - RETURN_MM(); - } + PHALCON_INIT_NVAR(pk_condition); + PHALCON_CONCAT_VS(pk_condition, escaped_field, " = ?"); + if (!phalcon_array_isset(bind_data_types, field)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the table columns"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } - if (PHALCON_IS_STRING(name, "join")) { - PHALCON_CONCAT_SVS(return_value, "join(", arguments, ")"); - RETURN_MM(); - } + PHALCON_OBS_NVAR(type); + phalcon_array_fetch(&type, bind_data_types, field, PH_NOISY); + phalcon_array_append(&unique_types, type, PH_SEPARATE); + phalcon_array_append(&where_pk, pk_condition, PH_SEPARATE); - if (PHALCON_IS_STRING(name, "lowercase")) { - PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::lower(", arguments, ")"); - RETURN_MM(); - } + zend_hash_move_forward_ex(ah0, &hp0); + } - if (PHALCON_IS_STRING(name, "lower")) { - PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::lower(", arguments, ")"); - RETURN_MM(); - } + if (PHALCON_IS_EQUAL(number_primary, number_empty)) { + RETURN_MM_FALSE; + } - if (PHALCON_IS_STRING(name, "uppercase")) { - PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::upper(", arguments, ")"); - RETURN_MM(); - } + PHALCON_INIT_VAR(join_where); + phalcon_fast_join_str(join_where, SL(" AND "), where_pk TSRMLS_CC); - if (PHALCON_IS_STRING(name, "upper")) { - PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::upper(", arguments, ")"); - RETURN_MM(); + phalcon_update_property_this_quick(this_ptr, SL("_uniqueKey"), join_where, 1221404964UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_uniqueParams"), unique_params, 1065564063UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_uniqueTypes"), unique_types, 3340838640UL TSRMLS_CC); + PHALCON_CPY_WRT(unique_key, join_where); } - if (PHALCON_IS_STRING(name, "capitalize")) { - PHALCON_CONCAT_SVS(return_value, "ucwords(", arguments, ")"); - RETURN_MM(); + PHALCON_OBS_VAR(dirty_state); + phalcon_read_property_this_quick(&dirty_state, this_ptr, SL("_dirtyState"), 1560981745UL, PH_NOISY_CC); + if (!zend_is_true(dirty_state)) { + RETURN_MM_TRUE; } - if (PHALCON_IS_STRING(name, "sort")) { - PHALCON_CONCAT_SVS(return_value, "$this->sort(", arguments, ")"); - RETURN_MM(); + if (Z_TYPE_P(unique_key) == IS_NULL) { + PHALCON_OBS_NVAR(unique_key); + phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); } - if (PHALCON_IS_STRING(name, "json_encode")) { - PHALCON_CONCAT_SVS(return_value, "json_encode(", arguments, ")"); - RETURN_MM(); + if (Z_TYPE_P(unique_params) == IS_NULL) { + PHALCON_OBS_NVAR(unique_params); + phalcon_read_property_this_quick(&unique_params, this_ptr, SL("_uniqueParams"), 1065564063UL, PH_NOISY_CC); } - if (PHALCON_IS_STRING(name, "json_decode")) { - PHALCON_CONCAT_SVS(return_value, "json_decode(", arguments, ")"); - RETURN_MM(); + if (Z_TYPE_P(unique_types) == IS_NULL) { + PHALCON_OBS_NVAR(unique_types); + phalcon_read_property_this_quick(&unique_types, this_ptr, SL("_uniqueTypes"), 3340838640UL, PH_NOISY_CC); } - if (PHALCON_IS_STRING(name, "format")) { - PHALCON_CONCAT_SVS(return_value, "sprintf(", arguments, ")"); - RETURN_MM(); - } + PHALCON_INIT_VAR(schema); + phalcon_call_method_key(schema, this_ptr, "getschema", 1539736246UL); - if (PHALCON_IS_STRING(name, "abs")) { - PHALCON_CONCAT_SVS(return_value, "abs(", arguments, ")"); - RETURN_MM(); + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); + if (zend_is_true(schema)) { + PHALCON_INIT_NVAR(table); + array_init_size(table, 2); + phalcon_array_append(&table, schema, PH_SEPARATE); + phalcon_array_append(&table, source, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(table, source); } - if (PHALCON_IS_STRING(name, "slice")) { - PHALCON_CONCAT_SVS(return_value, "$this->slice(", arguments, ")"); - RETURN_MM(); - } + PHALCON_INIT_VAR(escaped_table); + phalcon_call_method_p1_key(escaped_table, connection, "escapeidentifier", table, 585773337UL); - if (PHALCON_IS_STRING(name, "default")) { - PHALCON_CONCAT_SVSVSVS(return_value, "(empty(", left, ") ? (", arguments, ") : (", left, "))"); - RETURN_MM(); - } + PHALCON_INIT_VAR(null_mode); - if (PHALCON_IS_STRING(name, "convert_encoding")) { - PHALCON_CONCAT_SVS(return_value, "$this->convertEncoding(", arguments, ")"); - RETURN_MM(); - } + PHALCON_INIT_VAR(select); + PHALCON_CONCAT_SVSV(select, "SELECT COUNT(*) \"rowcount\" FROM ", escaped_table, " WHERE ", unique_key); - PHALCON_OBS_NVAR(line); - phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); + PHALCON_INIT_VAR(num); + phalcon_call_method_p4_key(num, connection, "fetchone", select, null_mode, unique_params, unique_types, 1637187313UL); - PHALCON_OBS_NVAR(file); - phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); + PHALCON_OBS_VAR(row_count); + phalcon_array_fetch_quick_string(&row_count, num, SS("rowcount"), 4184721862UL, PH_NOISY); + if (zend_is_true(row_count)) { + phalcon_update_property_long(this_ptr, SL("_dirtyState"), 0 TSRMLS_CC); + RETURN_MM_TRUE; + } else { + phalcon_update_property_long(this_ptr, SL("_dirtyState"), 1 TSRMLS_CC); + } - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVSV(exception_message, "Unknown filter \"", name, "\" in ", file, " on line ", line); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, expression){ +static PHP_METHOD(Phalcon_Mvc_Model, _groupResult){ - zval *expr, *expr_code = NULL, *extensions, *event = NULL, *fire_arguments = NULL; - zval *items = NULL, *single_expr = NULL, *single_expr_expr = NULL; - zval *single_expr_code = NULL, *name = NULL, *parameter = NULL, *type = NULL; - zval *left = NULL, *left_code = NULL, *right_code = NULL, *right = NULL, *value = NULL; - zval *single_quote = NULL, *escaped_quoute = NULL, *escaped_string = NULL; - zval *start = NULL, *start_code = NULL, *end = NULL, *end_code = NULL, *ternary = NULL; - zval *ternary_code = NULL, *line = NULL, *file = NULL, *exception_message = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *function, *alias, *parameters, *params = NULL, *group_column = NULL; + zval *distinct_column, *columns = NULL, *group_columns; + zval *model_name, *builder, *query, *bind_params = NULL; + zval *bind_types = NULL, *resultset, *cache, *number_rows; + zval *first_row, *value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &expr); + phalcon_fetch_params(1, 3, 0, &function, &alias, ¶meters); - if (Z_TYPE_P(expr) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted expression"); - return; + if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (Z_TYPE_P(parameters) != IS_NULL) { + PHALCON_INIT_VAR(params); + array_init_size(params, 1); + phalcon_array_append(¶ms, parameters, PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(params); + array_init(params); + } + } else { + PHALCON_CPY_WRT(params, parameters); + } + if (phalcon_array_isset_quick_string(params, SS("column"), 3545634419UL)) { + PHALCON_OBS_VAR(group_column); + phalcon_array_fetch_quick_string(&group_column, params, SS("column"), 3545634419UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(group_column); + ZVAL_STRING(group_column, "*", 1); } - PHALCON_INIT_VAR(expr_code); - phalcon_property_incr(this_ptr, SL("_exprLevel") TSRMLS_CC); - - PHALCON_OBS_VAR(extensions); - phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); - - while (1) { - - if (Z_TYPE_P(extensions) == IS_ARRAY) { - - PHALCON_INIT_NVAR(event); - ZVAL_STRING(event, "resolveExpression", 1); + if (phalcon_array_isset_quick_string(params, SS("distinct"), 73581991UL)) { + PHALCON_OBS_VAR(distinct_column); + phalcon_array_fetch_quick_string(&distinct_column, params, SS("distinct"), 73581991UL, PH_NOISY); - PHALCON_INIT_NVAR(fire_arguments); - array_init_size(fire_arguments, 1); - phalcon_array_append(&fire_arguments, expr, PH_SEPARATE); + PHALCON_INIT_VAR(columns); + PHALCON_CONCAT_VSVSV(columns, function, "(DISTINCT ", distinct_column, ") AS ", alias); + } else { + if (phalcon_array_isset_quick_string(params, SS("group"), 7349554UL)) { + PHALCON_OBS_VAR(group_columns); + phalcon_array_fetch_quick_string(&group_columns, params, SS("group"), 7349554UL, PH_NOISY); - PHALCON_INIT_NVAR(expr_code); - phalcon_call_method_p2_key(expr_code, this_ptr, "fireextensionevent", event, fire_arguments, 1575031978UL); - if (Z_TYPE_P(expr_code) == IS_STRING) { - break; - } + PHALCON_INIT_NVAR(columns); + PHALCON_CONCAT_VSVSVSV(columns, group_columns, ", ", function, "(", group_column, ") AS ", alias); + } else { + PHALCON_INIT_NVAR(columns); + PHALCON_CONCAT_VSVSV(columns, function, "(", group_column, ") AS ", alias); } - if (!phalcon_array_isset_quick_string(expr, SS("type"), 276192743UL)) { + } - PHALCON_INIT_NVAR(items); - array_init(items); + PHALCON_INIT_VAR(model_name); + phalcon_get_called_class(model_name TSRMLS_CC); - phalcon_is_iterable(expr, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(builder); + object_init_ex(builder, phalcon_mvc_model_query_builder_ce); + phalcon_call_method_p1_key(NULL, builder, "__construct", params, 1107214344UL); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + phalcon_call_method_p1_key(NULL, builder, "columns", columns, 1041822630UL); + phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - PHALCON_GET_HVALUE(single_expr); + PHALCON_INIT_VAR(query); + phalcon_call_method_key(query, builder, "getquery", 4154457883UL); - PHALCON_OBS_NVAR(single_expr_expr); - phalcon_array_fetch_quick_string(&single_expr_expr, single_expr, SS("expr"), 258368420UL, PH_NOISY); + PHALCON_INIT_VAR(bind_params); - PHALCON_INIT_NVAR(single_expr_code); - phalcon_call_method_p1_key(single_expr_code, this_ptr, "expression", single_expr_expr, 218841909UL); - if (phalcon_array_isset_quick_string(single_expr, SS("name"), 268211462UL)) { - PHALCON_OBS_NVAR(name); - phalcon_array_fetch_quick_string(&name, single_expr, SS("name"), 268211462UL, PH_NOISY); + PHALCON_INIT_VAR(bind_types); + if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { - PHALCON_INIT_NVAR(parameter); - PHALCON_CONCAT_SVSV(parameter, "'", name, "' => ", single_expr_code); - phalcon_array_append(&items, parameter, PH_SEPARATE); - } else { - phalcon_array_append(&items, single_expr_code, PH_SEPARATE); - } + PHALCON_OBS_NVAR(bind_params); + phalcon_array_fetch_quick_string(&bind_params, params, SS("bind"), 254268962UL, PH_NOISY); + if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { + PHALCON_OBS_NVAR(bind_types); + phalcon_array_fetch_quick_string(&bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); + } + } - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_VAR(resultset); + phalcon_call_method_p2_key(resultset, query, "execute", bind_params, bind_types, 3117639032UL); - PHALCON_INIT_NVAR(expr_code); - phalcon_fast_join_str(expr_code, SL(", "), items TSRMLS_CC); - break; - } + if (phalcon_array_isset_quick_string(params, SS("cache"), 4125168857UL)) { + PHALCON_OBS_VAR(cache); + phalcon_array_fetch_quick_string(&cache, params, SS("cache"), 4125168857UL, PH_NOISY); + phalcon_call_method_p1_key(NULL, query, "cache", cache, 4125168857UL); + } - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, expr, SS("type"), 276192743UL, PH_NOISY); + if (phalcon_array_isset_quick_string(params, SS("group"), 7349554UL)) { + RETURN_CCTOR(resultset); + } - if (PHALCON_IS_LONG(type, 46)) { - PHALCON_INIT_NVAR(expr_code); - phalcon_call_method_p1_key(expr_code, this_ptr, "attributereader", expr, 3193180844UL); - break; - } + PHALCON_INIT_VAR(number_rows); + phalcon_fast_count(number_rows, resultset TSRMLS_CC); - if (phalcon_array_isset_quick_string(expr, SS("left"), 265976240UL)) { - PHALCON_OBS_NVAR(left); - phalcon_array_fetch_quick_string(&left, expr, SS("left"), 265976240UL, PH_NOISY); + PHALCON_INIT_VAR(first_row); + phalcon_call_method_key(first_row, resultset, "getfirst", 3710205613UL); - PHALCON_INIT_NVAR(left_code); - phalcon_call_method_p1_key(left_code, this_ptr, "expression", left, 218841909UL); - } + PHALCON_OBS_VAR(value); + phalcon_read_property_zval(&value, first_row, alias, PH_NOISY_CC); - if (PHALCON_IS_LONG(type, 311)) { - PHALCON_OBS_NVAR(right_code); - phalcon_array_fetch_quick_string(&right_code, expr, SS("right"), 426864067UL, PH_NOISY); + RETURN_CCTOR(value); +} + +static PHP_METHOD(Phalcon_Mvc_Model, count){ + + zval *parameters = NULL, *function, *alias; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, ¶meters); - PHALCON_INIT_NVAR(expr_code); - phalcon_call_method_p2_key(expr_code, this_ptr, "resolvetest", right_code, left_code, 812472805UL); - break; - } + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } - if (PHALCON_IS_LONG(type, 124)) { - PHALCON_OBS_NVAR(right_code); - phalcon_array_fetch_quick_string(&right_code, expr, SS("right"), 426864067UL, PH_NOISY); + PHALCON_INIT_VAR(function); + ZVAL_STRING(function, "COUNT", 1); - PHALCON_INIT_NVAR(expr_code); - phalcon_call_method_p2_key(expr_code, this_ptr, "resolvefilter", right_code, left_code, 3562260459UL); - break; - } + PHALCON_INIT_VAR(alias); + ZVAL_STRING(alias, "rowcount", 1); + PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, sum){ + + zval *parameters = NULL, *function, *alias; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, ¶meters); - if (phalcon_array_isset_quick_string(expr, SS("right"), 426864067UL)) { - PHALCON_OBS_NVAR(right); - phalcon_array_fetch_quick_string(&right, expr, SS("right"), 426864067UL, PH_NOISY); + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } - PHALCON_INIT_NVAR(right_code); - phalcon_call_method_p1_key(right_code, this_ptr, "expression", right, 218841909UL); - } + PHALCON_INIT_VAR(function); + ZVAL_STRING(function, "SUM", 1); + + PHALCON_INIT_VAR(alias); + ZVAL_STRING(alias, "sumatory", 1); + PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, maximum){ + + zval *parameters = NULL, *function, *alias; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, ¶meters); - PHALCON_INIT_NVAR(expr_code); + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } - switch (phalcon_get_intval(type)) { + PHALCON_INIT_VAR(function); + ZVAL_STRING(function, "MAX", 1); - case 33: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "!", right_code); - break; + PHALCON_INIT_VAR(alias); + ZVAL_STRING(alias, "maximum", 1); + PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, minimum){ + + zval *parameters = NULL, *function, *alias; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, ¶meters); - case 42: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " * ", right_code); - break; + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } - case 43: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " + ", right_code); - break; + PHALCON_INIT_VAR(function); + ZVAL_STRING(function, "MIN", 1); - case 45: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " - ", right_code); - break; + PHALCON_INIT_VAR(alias); + ZVAL_STRING(alias, "minimum", 1); + PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, average){ + + zval *parameters = NULL, *function, *alias; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, ¶meters); - case 47: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " / ", right_code); - break; + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } - case 37: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " % ", right_code); - break; + PHALCON_INIT_VAR(function); + ZVAL_STRING(function, "AVG", 1); - case 60: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " < ", right_code); - break; + PHALCON_INIT_VAR(alias); + ZVAL_STRING(alias, "average", 1); + PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, fireEvent){ + + zval *event_name, *models_manager; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &event_name); - case 61: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " > ", right_code); - break; + if (phalcon_method_exists(this_ptr, event_name TSRMLS_CC) == SUCCESS) { + phalcon_call_method_zval_noret(this_ptr, event_name); + } - case 62: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " > ", right_code); - break; + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - case 126: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " . ", right_code); - break; + phalcon_call_method_p2_key(return_value, models_manager, "notifyevent", event_name, this_ptr, 1223080128UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, fireEventCancel){ + + zval *event_name, *status = NULL, *models_manager; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &event_name); - case 278: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "pow(", left_code, ", ", right_code, ")"); - break; + if (phalcon_method_exists(this_ptr, event_name TSRMLS_CC) == SUCCESS) { - case 360: - if (phalcon_array_isset_quick_string(expr, SS("left"), 265976240UL)) { - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "array(", left_code, ")"); - } else { - PHALCON_INIT_NVAR(expr_code); - ZVAL_STRING(expr_code, "array()", 1); - } - break; + PHALCON_INIT_VAR(status); + phalcon_call_method_zval(status, this_ptr, event_name); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } - case 258: - PHALCON_OBS_NVAR(expr_code); - phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); - break; + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - case 259: - PHALCON_OBS_NVAR(expr_code); - phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); - break; + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, models_manager, "notifyevent", event_name, this_ptr, 1223080128UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } - case 260: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); + RETURN_MM_TRUE; +} + +static PHP_METHOD(Phalcon_Mvc_Model, _cancelOperation){ + + zval *operation_made, *event_name = NULL; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(operation_made); + phalcon_read_property_this_quick(&operation_made, this_ptr, SL("_operationMade"), 3968152972UL, PH_NOISY_CC); + if (PHALCON_IS_LONG(operation_made, 3)) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "notDeleted", 1); + } else { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "notSaved", 1); + } - PHALCON_INIT_NVAR(single_quote); - ZVAL_STRING(single_quote, "'", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - PHALCON_INIT_NVAR(escaped_quoute); - ZVAL_STRING(escaped_quoute, "\\'", 1); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, appendMessage){ + + zval *message, *type, *exception_message; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &message); - PHALCON_INIT_NVAR(escaped_string); - phalcon_fast_str_replace(escaped_string, single_quote, escaped_quoute, value); + if (Z_TYPE_P(message) != IS_OBJECT) { + PHALCON_INIT_VAR(type); + phalcon_call_func_p1(type, "gettype", message); - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "'", escaped_string, "'"); - break; + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Invalid message format '", type, "'"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - case 261: - PHALCON_INIT_NVAR(expr_code); - ZVAL_STRING(expr_code, "null", 1); - break; + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, validate){ + + zval *validator, *status, *messages, *message = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &validator); - case 262: - PHALCON_INIT_NVAR(expr_code); - ZVAL_STRING(expr_code, "false", 1); - break; + if (Z_TYPE_P(validator) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Validator must be an Object"); + return; + } - case 263: - PHALCON_INIT_NVAR(expr_code); - ZVAL_STRING(expr_code, "true", 1); - break; + PHALCON_INIT_VAR(status); + phalcon_call_method_p1_key(status, validator, "validate", this_ptr, 2654098287UL); + if (PHALCON_IS_FALSE(status)) { - case 265: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); + PHALCON_INIT_VAR(messages); + phalcon_call_method_key(messages, validator, "getmessages", 4087333309UL); - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "$", value); - break; + phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); - case 266: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " && ", right_code); - break; + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - case 267: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " || ", right_code); - break; + PHALCON_GET_HVALUE(message); - case 270: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " <= ", right_code); - break; + phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - case 271: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " >= ", right_code); - break; + zend_hash_move_forward_ex(ah0, &hp0); + } - case 272: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " == ", right_code); - break; + } - case 273: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " != ", right_code); - break; + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, validationHasFailed){ + + zval *error_messages; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(error_messages); + phalcon_read_property_this_quick(&error_messages, this_ptr, SL("_errorMessages"), 1019066246UL, PH_NOISY_CC); + if (Z_TYPE_P(error_messages) == IS_ARRAY) { + if (phalcon_fast_count_ev(error_messages TSRMLS_CC)) { + RETURN_MM_TRUE; + } + } - case 274: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " === ", right_code); - break; + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model, getMessages){ + + + RETURN_MEMBER_QUICK(this_ptr, "_errorMessages", 1019066246UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysRestrict){ + + zval *manager, *belongs_to, *error = NULL, *relation = NULL, *foreign_key = NULL; + zval *action = NULL, *relation_class = NULL, *referenced_model = NULL; + zval *conditions = NULL, *bind_params = NULL, *fields = NULL, *referenced_fields = NULL; + zval *field = NULL, *position = NULL, *value = NULL, *referenced_field = NULL; + zval *condition = NULL, *extra_conditions = NULL, *join_conditions = NULL; + zval *parameters = NULL, *rowcount = NULL, *user_message = NULL, *joined_fields = NULL; + zval *type = NULL, *message = NULL, *event_name; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - case 275: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " !== ", right_code); - break; + PHALCON_INIT_VAR(belongs_to); + phalcon_call_method_p1_key(belongs_to, manager, "getbelongsto", this_ptr, 2949171154UL); + if (phalcon_fast_count_ev(belongs_to TSRMLS_CC)) { - case 276: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "range(", left_code, ", ", right_code, ")"); - break; + PHALCON_INIT_VAR(error); + ZVAL_BOOL(error, 0); - case 350: - PHALCON_INIT_NVAR(expr_code); - phalcon_call_method_p1_key(expr_code, this_ptr, "functioncall", expr, 1638966055UL); - break; + phalcon_is_iterable(belongs_to, &ah0, &hp0, 0, 0); - case 356: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "(", left_code, ")"); - break; + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - case 361: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSVS(expr_code, left_code, "[", right_code, "]"); - break; + PHALCON_GET_HVALUE(relation); - case 365: - if (phalcon_array_isset_quick_string(expr, SS("start"), 478839859UL)) { - PHALCON_OBS_NVAR(start); - phalcon_array_fetch_quick_string(&start, expr, SS("start"), 478839859UL, PH_NOISY); + PHALCON_INIT_NVAR(foreign_key); + phalcon_call_method_key(foreign_key, relation, "getforeignkey", 3855868664UL); + if (PHALCON_IS_NOT_FALSE(foreign_key)) { - PHALCON_INIT_NVAR(start_code); - phalcon_call_method_p1_key(start_code, this_ptr, "expression", start, 218841909UL); - } else { - PHALCON_INIT_NVAR(start_code); - ZVAL_STRING(start_code, "null", 1); + PHALCON_INIT_NVAR(action); + ZVAL_LONG(action, 1); + + if (Z_TYPE_P(foreign_key) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(foreign_key, SS("action"), 502132067UL)) { + PHALCON_OBS_NVAR(action); + phalcon_array_fetch_quick_string(&action, foreign_key, SS("action"), 502132067UL, PH_NOISY); + } } - if (phalcon_array_isset_quick_string(expr, SS("end"), 2090226332UL)) { - PHALCON_OBS_NVAR(end); - phalcon_array_fetch_quick_string(&end, expr, SS("end"), 2090226332UL, PH_NOISY); + if (PHALCON_IS_LONG(action, 1)) { - PHALCON_INIT_NVAR(end_code); - phalcon_call_method_p1_key(end_code, this_ptr, "expression", end, 218841909UL); - } else { - PHALCON_INIT_NVAR(end_code); - ZVAL_STRING(end_code, "null", 1); - } + PHALCON_INIT_NVAR(relation_class); + phalcon_call_method_key(relation_class, relation, "getreferencedmodel", 478093161UL); - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVSVS(expr_code, "$this->slice(", left_code, ", ", start_code, ", ", end_code, ")"); - break; + PHALCON_INIT_NVAR(referenced_model); + phalcon_call_method_p1_key(referenced_model, manager, "load", relation_class, 266329637UL); - case 362: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "!isset(", left_code, ")"); - break; + PHALCON_INIT_NVAR(conditions); + array_init(conditions); - case 363: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "isset(", left_code, ")"); - break; + PHALCON_INIT_NVAR(bind_params); + array_init(bind_params); - case 309: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "$this->isIncluded(", left_code, ", ", right_code, ")"); - break; + PHALCON_INIT_NVAR(fields); + phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - case 369: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "!$this->isIncluded(", left_code, ", ", right_code, ")"); - break; + PHALCON_INIT_NVAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); + if (Z_TYPE_P(fields) == IS_ARRAY) { - case 366: - PHALCON_OBS_NVAR(ternary); - phalcon_array_fetch_quick_string(&ternary, expr, SS("ternary"), 4197153930UL, PH_NOISY); + phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); - PHALCON_INIT_NVAR(ternary_code); - phalcon_call_method_p1_key(ternary_code, this_ptr, "expression", ternary, 218841909UL); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVSVS(expr_code, "(", ternary_code, " ? ", left_code, " : ", right_code, ")"); - break; + PHALCON_GET_HKEY(position, ah1, hp1); + PHALCON_GET_HVALUE(field); - case 367: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "-", right_code); - break; + if (phalcon_isset_property_zval(this_ptr, field TSRMLS_CC)) { + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, field, PH_NOISY_CC); + } else { + PHALCON_INIT_NVAR(value); + } - case 368: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "+", right_code); - break; + PHALCON_OBS_NVAR(referenced_field); + phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - case 364: - PHALCON_OBS_NVAR(expr_code); - phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); - break; + PHALCON_INIT_NVAR(condition); + PHALCON_CONCAT_SVSV(condition, "[", referenced_field, "] = ?", position); + phalcon_array_append(&conditions, condition, PH_SEPARATE); + phalcon_array_append(&bind_params, value, PH_SEPARATE); - default: - PHALCON_OBS_NVAR(line); - phalcon_array_fetch_quick_string(&line, expr, SS("line"), 266128205UL, PH_NOISY); + zend_hash_move_forward_ex(ah1, &hp1); + } - PHALCON_OBS_NVAR(file); - phalcon_array_fetch_quick_string(&file, expr, SS("file"), 259010501UL, PH_NOISY); + } else { + if (phalcon_isset_property_zval(this_ptr, fields TSRMLS_CC)) { + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, fields, PH_NOISY_CC); + } else { + PHALCON_INIT_NVAR(value); + } - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVSV(exception_message, "Unknown expression ", type, " in ", file, " on line ", line); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; + PHALCON_INIT_NVAR(condition); + PHALCON_CONCAT_SVS(condition, "[", referenced_fields, "] = ?0"); + phalcon_array_append(&conditions, condition, PH_SEPARATE); + phalcon_array_append(&bind_params, value, PH_SEPARATE); + } - } - break; - } - phalcon_property_decr(this_ptr, SL("_exprLevel") TSRMLS_CC); + if (phalcon_array_isset_quick_string(foreign_key, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_NVAR(extra_conditions); + phalcon_array_fetch_quick_string(&extra_conditions, foreign_key, SS("conditions"), 1055696255UL, PH_NOISY); + phalcon_array_append(&conditions, extra_conditions, PH_SEPARATE); + } - RETURN_CCTOR(expr_code); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _statementListOrExtends){ - - zval *statements, *is_statement_list = NULL, *statement = NULL; - zval *code; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &statements); + PHALCON_INIT_NVAR(join_conditions); + phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - if (Z_TYPE_P(statements) != IS_ARRAY) { - RETURN_CCTOR(statements); - } + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 2); + phalcon_array_append(¶meters, join_conditions, PH_SEPARATE); + phalcon_array_update_quick_string(¶meters, SS("bind"), 254268962UL, &bind_params, PH_COPY | PH_SEPARATE); - PHALCON_INIT_VAR(is_statement_list); - ZVAL_BOOL(is_statement_list, 1); - if (!phalcon_array_isset_quick_string(statements, SS("type"), 276192743UL)) { + PHALCON_INIT_NVAR(rowcount); + phalcon_call_method_p1_key(rowcount, referenced_model, "count", parameters, 4142425646UL); + if (!zend_is_true(rowcount)) { + + if (phalcon_array_isset_quick_string(foreign_key, SS("message"), 2265848874UL)) { + PHALCON_OBS_NVAR(user_message); + phalcon_array_fetch_quick_string(&user_message, foreign_key, SS("message"), 2265848874UL, PH_NOISY); + } else { + if (Z_TYPE_P(fields) == IS_ARRAY) { + PHALCON_INIT_NVAR(joined_fields); + phalcon_fast_join_str(joined_fields, SL(", "), fields TSRMLS_CC); + + PHALCON_INIT_NVAR(user_message); + PHALCON_CONCAT_SVS(user_message, "Value of fields \"", joined_fields, "\" does not exist on referenced table"); + } else { + PHALCON_INIT_NVAR(user_message); + PHALCON_CONCAT_SVS(user_message, "Value of field \"", fields, "\" does not exist on referenced table"); + } + } - phalcon_is_iterable(statements, &ah0, &hp0, 0, 0); + PHALCON_INIT_NVAR(type); + ZVAL_STRING(type, "ConstraintViolation", 1); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_NVAR(message); + object_init_ex(message, phalcon_mvc_model_message_ce); + phalcon_call_method_p3_key(NULL, message, "__construct", user_message, fields, type, 1107214344UL); - PHALCON_GET_HVALUE(statement); + phalcon_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - if (Z_TYPE_P(statement) != IS_ARRAY) { - PHALCON_INIT_NVAR(is_statement_list); - ZVAL_BOOL(is_statement_list, 0); - break; + PHALCON_INIT_NVAR(error); + ZVAL_BOOL(error, 1); + break; + } + } } zend_hash_move_forward_ex(ah0, &hp0); } + if (PHALCON_IS_TRUE(error)) { + if (PHALCON_GLOBAL(orm).events) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "onValidationFails", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + phalcon_call_method_key(NULL, this_ptr, "_canceloperation", 1716493051UL); + } + RETURN_MM_FALSE; + } } - if (PHALCON_IS_TRUE(is_statement_list)) { - PHALCON_INIT_VAR(code); - phalcon_call_method_p1_key(code, this_ptr, "_statementlist", statements, 1357145205UL); - RETURN_CCTOR(code); - } - - - RETURN_CCTOR(statements); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileForeach){ +static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysReverseRestrict){ - zval *statement, *extends_mode = NULL, *compilation; - zval *prefix, *level, *prefix_level, *expr, *expr_code; - zval *block_statements, *for_else = NULL, *bstatement = NULL; - zval *type = NULL, *code, *loop_context, *iterator = NULL, *variable; - zval *key, *if_expr, *if_expr_code; - HashTable *ah0; - HashPosition hp0; + zval *manager, *relations, *error = NULL, *relation = NULL, *foreign_key = NULL; + zval *action = NULL, *relation_class = NULL, *referenced_model = NULL; + zval *fields = NULL, *referenced_fields = NULL, *conditions = NULL; + zval *bind_params = NULL, *field = NULL, *position = NULL, *value = NULL, *referenced_field = NULL; + zval *condition = NULL, *extra_conditions = NULL, *join_conditions = NULL; + zval *parameters = NULL, *rowcount = NULL, *user_message = NULL, *type = NULL; + zval *message = NULL, *event_name; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &statement, &extends_mode); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } + PHALCON_INIT_VAR(relations); + phalcon_call_method_p1_key(relations, manager, "gethasoneandhasmany", this_ptr, 775341383UL); + if (phalcon_fast_count_ev(relations TSRMLS_CC)) { - PHALCON_INIT_VAR(compilation); - ZVAL_STRING(compilation, "", 1); - phalcon_property_incr(this_ptr, SL("_foreachLevel") TSRMLS_CC); + PHALCON_INIT_VAR(error); + ZVAL_BOOL(error, 0); - PHALCON_INIT_VAR(prefix); - phalcon_call_method_key(prefix, this_ptr, "getuniqueprefix", 3888429962UL); + phalcon_is_iterable(relations, &ah0, &hp0, 0, 0); - PHALCON_OBS_VAR(level); - phalcon_read_property_this_quick(&level, this_ptr, SL("_foreachLevel"), 1560648116UL, PH_NOISY_CC); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(prefix_level); - PHALCON_CONCAT_VV(prefix_level, prefix, level); + PHALCON_GET_HVALUE(relation); - PHALCON_OBS_VAR(expr); - phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); + PHALCON_INIT_NVAR(foreign_key); + phalcon_call_method_key(foreign_key, relation, "getforeignkey", 3855868664UL); + if (PHALCON_IS_NOT_FALSE(foreign_key)) { - PHALCON_INIT_VAR(expr_code); - phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); + PHALCON_INIT_NVAR(action); + ZVAL_LONG(action, 1); - PHALCON_OBS_VAR(block_statements); - phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); + if (Z_TYPE_P(foreign_key) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(foreign_key, SS("action"), 502132067UL)) { + PHALCON_OBS_NVAR(action); + phalcon_array_fetch_quick_string(&action, foreign_key, SS("action"), 502132067UL, PH_NOISY); + } + } - PHALCON_INIT_VAR(for_else); - ZVAL_BOOL(for_else, 0); - if (Z_TYPE_P(block_statements) == IS_ARRAY) { + if (PHALCON_IS_LONG(action, 1)) { - phalcon_is_iterable(block_statements, &ah0, &hp0, 0, 0); + PHALCON_INIT_NVAR(relation_class); + phalcon_call_method_key(relation_class, relation, "getreferencedmodel", 478093161UL); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_NVAR(referenced_model); + phalcon_call_method_p1_key(referenced_model, manager, "load", relation_class, 266329637UL); - PHALCON_GET_HVALUE(bstatement); + PHALCON_INIT_NVAR(fields); + phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - if (Z_TYPE_P(bstatement) != IS_ARRAY) { - break; - } + PHALCON_INIT_NVAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - if (!phalcon_array_isset_quick_string(bstatement, SS("type"), 276192743UL)) { - break; - } + PHALCON_INIT_NVAR(conditions); + array_init(conditions); - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, bstatement, SS("type"), 276192743UL, PH_NOISY); - if (PHALCON_IS_LONG(type, 321)) { - PHALCON_SCONCAT_SVS(compilation, ""); - PHALCON_CPY_WRT(for_else, prefix_level); - phalcon_update_property_array(this_ptr, SL("_forElsePointers"), level, for_else TSRMLS_CC); - break; - } + PHALCON_INIT_NVAR(bind_params); + array_init(bind_params); + if (Z_TYPE_P(fields) == IS_ARRAY) { - zend_hash_move_forward_ex(ah0, &hp0); - } + phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); - } + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_INIT_VAR(code); - phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); + PHALCON_GET_HKEY(position, ah1, hp1); + PHALCON_GET_HVALUE(field); - PHALCON_OBS_VAR(loop_context); - phalcon_read_property_this_quick(&loop_context, this_ptr, SL("_loopPointers"), 3384827986UL, PH_NOISY_CC); + if (phalcon_isset_property_zval(this_ptr, field TSRMLS_CC)) { + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, field, PH_NOISY_CC); + } else { + PHALCON_INIT_NVAR(value); + } - if (phalcon_array_isset(loop_context, level)) { - PHALCON_SCONCAT_SVSVS(compilation, "length = count($", prefix_level, "iterator); "); - PHALCON_SCONCAT_SVS(compilation, "$", prefix_level, "loop->index = 1; "); - PHALCON_SCONCAT_SVS(compilation, "$", prefix_level, "loop->index0 = 1; "); - PHALCON_SCONCAT_SVSVS(compilation, "$", prefix_level, "loop->revindex = $", prefix_level, "loop->length; "); - PHALCON_SCONCAT_SVSVS(compilation, "$", prefix_level, "loop->revindex0 = $", prefix_level, "loop->length - 1; ?>"); + PHALCON_OBS_NVAR(referenced_field); + phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - PHALCON_INIT_VAR(iterator); - PHALCON_CONCAT_SVS(iterator, "$", prefix_level, "iterator"); - } else { - PHALCON_CPY_WRT(iterator, expr_code); - } + PHALCON_INIT_NVAR(condition); + PHALCON_CONCAT_SVSV(condition, "[", referenced_field, "] = ?", position); + phalcon_array_append(&conditions, condition, PH_SEPARATE); + phalcon_array_append(&bind_params, value, PH_SEPARATE); - PHALCON_OBS_VAR(variable); - phalcon_array_fetch_quick_string(&variable, statement, SS("variable"), 1809440971UL, PH_NOISY); + zend_hash_move_forward_ex(ah1, &hp1); + } - if (phalcon_array_isset_quick_string(statement, SS("key"), 2090432846UL)) { - PHALCON_OBS_VAR(key); - phalcon_array_fetch_quick_string(&key, statement, SS("key"), 2090432846UL, PH_NOISY); - PHALCON_SCONCAT_SVSVSVS(compilation, " $", variable, ") { "); - } else { - PHALCON_SCONCAT_SVSVS(compilation, ""); - } else { - phalcon_concat_self_str(&compilation, SL("?>") TSRMLS_CC); - } + if (phalcon_array_isset_quick_string(foreign_key, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_NVAR(extra_conditions); + phalcon_array_fetch_quick_string(&extra_conditions, foreign_key, SS("conditions"), 1055696255UL, PH_NOISY); + phalcon_array_append(&conditions, extra_conditions, PH_SEPARATE); + } - if (phalcon_array_isset(loop_context, level)) { - PHALCON_SCONCAT_SVSVS(compilation, "first = ($", prefix_level, "incr == 0); "); - PHALCON_SCONCAT_SVSVS(compilation, "$", prefix_level, "loop->index = $", prefix_level, "incr + 1; "); - PHALCON_SCONCAT_SVSVS(compilation, "$", prefix_level, "loop->index0 = $", prefix_level, "incr; "); - PHALCON_SCONCAT_SVSVSVS(compilation, "$", prefix_level, "loop->revindex = $", prefix_level, "loop->length - $", prefix_level, "incr; "); - PHALCON_SCONCAT_SVSVSVS(compilation, "$", prefix_level, "loop->revindex0 = $", prefix_level, "loop->length - ($", prefix_level, "incr + 1); "); - PHALCON_SCONCAT_SVSVSVS(compilation, "$", prefix_level, "loop->last = ($", prefix_level, "incr == ($", prefix_level, "loop->length - 1)); ?>"); - } + PHALCON_INIT_NVAR(join_conditions); + phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - if (Z_TYPE_P(for_else) == IS_STRING) { - PHALCON_SCONCAT_SVS(compilation, ""); - } + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 2); + phalcon_array_append(¶meters, join_conditions, PH_SEPARATE); + phalcon_array_update_quick_string(¶meters, SS("bind"), 254268962UL, &bind_params, PH_COPY | PH_SEPARATE); - phalcon_concat_self(&compilation, code TSRMLS_CC); - if (phalcon_array_isset_quick_string(statement, SS("if_expr"), 4083762802UL)) { - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - } + PHALCON_INIT_NVAR(rowcount); + phalcon_call_method_p1_key(rowcount, referenced_model, "count", parameters, 4142425646UL); + if (zend_is_true(rowcount)) { - if (Z_TYPE_P(for_else) == IS_STRING) { - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - } else { - if (phalcon_array_isset(loop_context, level)) { - PHALCON_SCONCAT_SVS(compilation, ""); - } else { - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - } - } + if (phalcon_array_isset_quick_string(foreign_key, SS("message"), 2265848874UL)) { + PHALCON_OBS_NVAR(user_message); + phalcon_array_fetch_quick_string(&user_message, foreign_key, SS("message"), 2265848874UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(user_message); + PHALCON_CONCAT_SV(user_message, "Record is referenced by model ", relation_class); + } - phalcon_property_decr(this_ptr, SL("_foreachLevel") TSRMLS_CC); + PHALCON_INIT_NVAR(type); + ZVAL_STRING(type, "ConstraintViolation", 1); - RETURN_CTOR(compilation); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileForElse){ - - zval *level, *for_else_pointers, *prefix, *loop_context; - zval *compilation = NULL; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(level); - phalcon_read_property_this_quick(&level, this_ptr, SL("_foreachLevel"), 1560648116UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(message); + object_init_ex(message, phalcon_mvc_model_message_ce); + phalcon_call_method_p3_key(NULL, message, "__construct", user_message, fields, type, 1107214344UL); - PHALCON_OBS_VAR(for_else_pointers); - phalcon_read_property_this_quick(&for_else_pointers, this_ptr, SL("_forElsePointers"), 17082280UL, PH_NOISY_CC); - if (phalcon_array_isset(for_else_pointers, level)) { + phalcon_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - PHALCON_OBS_VAR(prefix); - phalcon_array_fetch(&prefix, for_else_pointers, level, PH_NOISY); + PHALCON_INIT_NVAR(error); + ZVAL_BOOL(error, 1); + break; + } + } + } - PHALCON_OBS_VAR(loop_context); - phalcon_read_property_this_quick(&loop_context, this_ptr, SL("_loopPointers"), 3384827986UL, PH_NOISY_CC); - if (phalcon_array_isset(loop_context, level)) { - PHALCON_INIT_VAR(compilation); - PHALCON_CONCAT_SVSVS(compilation, ""); - } else { - PHALCON_INIT_NVAR(compilation); - PHALCON_CONCAT_SVS(compilation, ""); + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CTOR(compilation); + if (PHALCON_IS_TRUE(error)) { + if (PHALCON_GLOBAL(orm).events) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "onValidationFails", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + phalcon_call_method_key(NULL, this_ptr, "_canceloperation", 1716493051UL); + } + RETURN_MM_FALSE; + } } - PHALCON_MM_RESTORE(); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileIf){ +static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysReverseCascade){ - zval *statement, *extends_mode = NULL, *compilation; - zval *expr, *expr_code, *block_statements = NULL, *code = NULL; + zval *manager, *relations, *relation = NULL, *foreign_key = NULL; + zval *action = NULL, *relation_class = NULL, *referenced_model = NULL; + zval *fields = NULL, *referenced_fields = NULL, *conditions = NULL; + zval *bind_params = NULL, *field = NULL, *position = NULL, *value = NULL, *referenced_field = NULL; + zval *condition = NULL, *extra_conditions = NULL, *join_conditions = NULL; + zval *parameters = NULL, *resulset = NULL, *status = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &statement, &extends_mode); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - PHALCON_INIT_VAR(compilation); - - if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } - - PHALCON_OBS_VAR(expr); - phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); - - PHALCON_INIT_VAR(expr_code); - phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); - - PHALCON_SCONCAT_SVS(compilation, ""); - PHALCON_OBS_VAR(block_statements); - phalcon_array_fetch_quick_string(&block_statements, statement, SS("true_statements"), 3718314604UL, PH_NOISY); - - PHALCON_INIT_VAR(code); - phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); - phalcon_concat_self(&compilation, code TSRMLS_CC); + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(statement, SS("false_statements"), 3888255479UL)) { - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); + PHALCON_INIT_VAR(relations); + phalcon_call_method_p1_key(relations, manager, "gethasoneandhasmany", this_ptr, 775341383UL); + if (phalcon_fast_count_ev(relations TSRMLS_CC)) { - PHALCON_OBS_NVAR(block_statements); - phalcon_array_fetch_quick_string(&block_statements, statement, SS("false_statements"), 3888255479UL, PH_NOISY); + phalcon_is_iterable(relations, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(code); - phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); - phalcon_concat_self(&compilation, code TSRMLS_CC); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); + PHALCON_GET_HVALUE(relation); - RETURN_CCTOR(compilation); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileElseIf){ - - zval *statement, *expr, *expr_code; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &statement); + PHALCON_INIT_NVAR(foreign_key); + phalcon_call_method_key(foreign_key, relation, "getforeignkey", 3855868664UL); + if (PHALCON_IS_NOT_FALSE(foreign_key)) { - if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } + PHALCON_INIT_NVAR(action); + ZVAL_LONG(action, 0); - PHALCON_OBS_VAR(expr); - phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); + if (Z_TYPE_P(foreign_key) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(foreign_key, SS("action"), 502132067UL)) { + PHALCON_OBS_NVAR(action); + phalcon_array_fetch_quick_string(&action, foreign_key, SS("action"), 502132067UL, PH_NOISY); + } + } - PHALCON_INIT_VAR(expr_code); - phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); + if (PHALCON_IS_LONG(action, 2)) { - PHALCON_CONCAT_SVS(return_value, ""); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileCache){ - - zval *statement, *extends_mode = NULL, *compilation; - zval *expr, *expr_code, *lifetime = NULL, *block_statements; - zval *code; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &statement, &extends_mode); + PHALCON_INIT_NVAR(relation_class); + phalcon_call_method_key(relation_class, relation, "getreferencedmodel", 478093161UL); - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } + PHALCON_INIT_NVAR(referenced_model); + phalcon_call_method_p1_key(referenced_model, manager, "load", relation_class, 266329637UL); - if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } + PHALCON_INIT_NVAR(fields); + phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - PHALCON_INIT_VAR(compilation); + PHALCON_INIT_NVAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - PHALCON_OBS_VAR(expr); - phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); + PHALCON_INIT_NVAR(conditions); + array_init(conditions); - PHALCON_INIT_VAR(expr_code); - phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); + PHALCON_INIT_NVAR(bind_params); + array_init(bind_params); + if (Z_TYPE_P(fields) == IS_ARRAY) { - PHALCON_SCONCAT_SVS(compilation, "di->get('viewCache'); "); - if (phalcon_array_isset_quick_string(statement, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_VAR(lifetime); - phalcon_array_fetch_quick_string(&lifetime, statement, SS("lifetime"), 2639810228UL, PH_NOISY); - PHALCON_SCONCAT_SVS(compilation, "$_cacheKey[", expr_code, "]"); - PHALCON_SCONCAT_SVSVSVS(compilation, " = $_cache[", expr_code, "]->start(", expr_code, ", ", lifetime, "); "); - } else { - PHALCON_SCONCAT_SVSVSVS(compilation, "$_cacheKey[", expr_code, "] = $_cache[", expr_code, "]->start(", expr_code, "); "); - } + phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); - PHALCON_SCONCAT_SVS(compilation, "if ($_cacheKey[", expr_code, "] === null) { ?>"); - PHALCON_OBS_VAR(block_statements); - phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_INIT_VAR(code); - phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); - phalcon_concat_self(&compilation, code TSRMLS_CC); + PHALCON_GET_HKEY(position, ah1, hp1); + PHALCON_GET_HVALUE(field); - if (phalcon_array_isset_quick_string(statement, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_NVAR(lifetime); - phalcon_array_fetch_quick_string(&lifetime, statement, SS("lifetime"), 2639810228UL, PH_NOISY); - PHALCON_SCONCAT_SVSVSVS(compilation, "save(", expr_code, ", null, ", lifetime, "); "); - PHALCON_SCONCAT_SVS(compilation, "} else { echo $_cacheKey[", expr_code, "]; } ?>"); - } else { - PHALCON_SCONCAT_SVSVSVS(compilation, "save(", expr_code, "); } else { echo $_cacheKey[", expr_code, "]; } ?>"); - } + if (phalcon_isset_property_zval(this_ptr, field TSRMLS_CC)) { + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, field, PH_NOISY_CC); + } else { + PHALCON_INIT_NVAR(value); + } - RETURN_CCTOR(compilation); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileEcho){ - - zval *statement, *compilation, *expr, *expr_code; - zval *expr_type, *name, *name_type, *name_value; - zval *autoescape; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &statement); + PHALCON_OBS_NVAR(referenced_field); + phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } + PHALCON_INIT_NVAR(condition); + PHALCON_CONCAT_SVSV(condition, "[", referenced_field, "] = ?", position); + phalcon_array_append(&conditions, condition, PH_SEPARATE); + phalcon_array_append(&bind_params, value, PH_SEPARATE); - PHALCON_INIT_VAR(compilation); + zend_hash_move_forward_ex(ah1, &hp1); + } - PHALCON_OBS_VAR(expr); - phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); + } else { + if (phalcon_isset_property_zval(this_ptr, fields TSRMLS_CC)) { + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, fields, PH_NOISY_CC); + } else { + PHALCON_INIT_NVAR(value); + } - PHALCON_INIT_VAR(expr_code); - phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); + PHALCON_INIT_NVAR(condition); + PHALCON_CONCAT_SVS(condition, "[", referenced_fields, "] = ?0"); + phalcon_array_append(&conditions, condition, PH_SEPARATE); + phalcon_array_append(&bind_params, value, PH_SEPARATE); + } - PHALCON_OBS_VAR(expr_type); - phalcon_array_fetch_quick_string(&expr_type, expr, SS("type"), 276192743UL, PH_NOISY); - if (PHALCON_IS_LONG(expr_type, 350)) { + if (phalcon_array_isset_quick_string(foreign_key, SS("conditions"), 1055696255UL)) { + PHALCON_OBS_NVAR(extra_conditions); + phalcon_array_fetch_quick_string(&extra_conditions, foreign_key, SS("conditions"), 1055696255UL, PH_NOISY); + phalcon_array_append(&conditions, extra_conditions, PH_SEPARATE); + } - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, expr, SS("name"), 268211462UL, PH_NOISY); + PHALCON_INIT_NVAR(join_conditions); + phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - PHALCON_OBS_VAR(name_type); - phalcon_array_fetch_quick_string(&name_type, name, SS("type"), 276192743UL, PH_NOISY); - if (PHALCON_IS_LONG(name_type, 265)) { + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 2); + phalcon_array_append(¶meters, join_conditions, PH_SEPARATE); + phalcon_array_update_quick_string(¶meters, SS("bind"), 254268962UL, &bind_params, PH_COPY | PH_SEPARATE); - PHALCON_OBS_VAR(name_value); - phalcon_array_fetch_quick_string(&name_value, name, SS("value"), 574111618UL, PH_NOISY); + PHALCON_INIT_NVAR(resulset); + phalcon_call_method_p1_key(resulset, referenced_model, "find", parameters, 259012646UL); - if (PHALCON_IS_STRING(name_value, "super")) { - RETURN_CCTOR(expr_code); + PHALCON_INIT_NVAR(status); + phalcon_call_method_key(status, resulset, "delete", 150213496UL); + + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } } + + zend_hash_move_forward_ex(ah0, &hp0); } - } - PHALCON_OBS_VAR(autoescape); - phalcon_read_property_this_quick(&autoescape, this_ptr, SL("_autoescape"), 2399648718UL, PH_NOISY_CC); - if (zend_is_true(autoescape)) { - PHALCON_SCONCAT_SVS(compilation, "escaper->escapeHtml(", expr_code, "); ?>"); - } else { - PHALCON_SCONCAT_SVS(compilation, ""); } - RETURN_CCTOR(compilation); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileInclude){ +static PHP_METHOD(Phalcon_Mvc_Model, _preSave){ - zval *statement, *path_expr, *expr_type, *path = NULL; - zval *view, *views_dir, *final_path = NULL, *extended; - zval *sub_compiler, *compilation = NULL, *compiled_path; - zval *expr_params, *params; + zval *meta_data, *exists, *identity_field, *event_name = NULL; + zval *status = NULL, *not_null, *data_type_numeric; + zval *column_map = NULL, *automatic_attributes = NULL, *error = NULL; + zval *null_value, *field = NULL, *is_null = NULL, *attribute_field = NULL; + zval *exception_message = NULL, *value = NULL, *message = NULL, *type = NULL; + zval *model_message = NULL, *skipped; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &statement); + phalcon_fetch_params(1, 3, 0, &meta_data, &exists, &identity_field); - if (!phalcon_array_isset_quick_string(statement, SS("path"), 270591026UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } + if (PHALCON_GLOBAL(orm).events) { - PHALCON_OBS_VAR(path_expr); - phalcon_array_fetch_quick_string(&path_expr, statement, SS("path"), 270591026UL, PH_NOISY); + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "beforeValidation", 1); - PHALCON_OBS_VAR(expr_type); - phalcon_array_fetch_quick_string(&expr_type, path_expr, SS("type"), 276192743UL, PH_NOISY); + PHALCON_INIT_VAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } - if (PHALCON_IS_LONG(expr_type, 260)) { + if (!zend_is_true(exists)) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "beforeValidationOnCreate", 1); + } else { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "beforeValidationOnUpdate", 1); + } - if (!phalcon_array_isset_quick_string(statement, SS("params"), 2613350281UL)) { + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } - PHALCON_OBS_VAR(path); - phalcon_array_fetch_quick_string(&path, path_expr, SS("value"), 574111618UL, PH_NOISY); + if (PHALCON_GLOBAL(orm).virtual_foreign_keys) { - PHALCON_OBS_VAR(view); - phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); - if (Z_TYPE_P(view) == IS_OBJECT) { - PHALCON_INIT_VAR(views_dir); - phalcon_call_method_key(views_dir, view, "getviewsdir", 2448458514UL); + PHALCON_INIT_NVAR(status); + phalcon_call_method_key(status, this_ptr, "_checkforeignkeysrestrict", 3705233048UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } - PHALCON_INIT_VAR(final_path); - PHALCON_CONCAT_VV(final_path, views_dir, path); + if (PHALCON_GLOBAL(orm).not_null_validations) { + + PHALCON_INIT_VAR(not_null); + phalcon_call_method_p1_key(not_null, meta_data, "getnotnullattributes", this_ptr, 1717716120UL); + if (Z_TYPE_P(not_null) == IS_ARRAY) { + + PHALCON_INIT_VAR(data_type_numeric); + phalcon_call_method_p1_key(data_type_numeric, meta_data, "getdatatypesnumeric", this_ptr, 4122766183UL); + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); } else { - PHALCON_CPY_WRT(final_path, path); + PHALCON_INIT_NVAR(column_map); } - PHALCON_INIT_VAR(extended); - ZVAL_BOOL(extended, 0); - - PHALCON_INIT_VAR(sub_compiler); - if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { - return; + if (zend_is_true(exists)) { + PHALCON_INIT_VAR(automatic_attributes); + phalcon_call_method_p1_key(automatic_attributes, meta_data, "getautomaticupdateattributes", this_ptr, 2703790998UL); + } else { + PHALCON_INIT_NVAR(automatic_attributes); + phalcon_call_method_p1_key(automatic_attributes, meta_data, "getautomaticcreateattributes", this_ptr, 159934727UL); } - PHALCON_INIT_VAR(compilation); - phalcon_call_method_p2_key(compilation, sub_compiler, "compile", final_path, extended, 1074882030UL); + PHALCON_INIT_VAR(error); + ZVAL_BOOL(error, 0); - if (Z_TYPE_P(compilation) == IS_NULL) { - PHALCON_INIT_VAR(compiled_path); - phalcon_call_method_key(compiled_path, sub_compiler, "getcompiledtemplatepath", 652904091UL); + PHALCON_INIT_VAR(null_value); - PHALCON_INIT_NVAR(compilation); - phalcon_file_get_contents(compilation, compiled_path TSRMLS_CC); - } + phalcon_is_iterable(not_null, &ah0, &hp0, 0, 0); - RETURN_CCTOR(compilation); - } - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_NVAR(path); - phalcon_call_method_p1_key(path, this_ptr, "expression", path_expr, 218841909UL); - if (!phalcon_array_isset_quick_string(statement, SS("params"), 2613350281UL)) { - PHALCON_CONCAT_SVS(return_value, "partial(", path, "); ?>"); - RETURN_MM(); - } + PHALCON_GET_HVALUE(field); - PHALCON_OBS_VAR(expr_params); - phalcon_array_fetch_quick_string(&expr_params, statement, SS("params"), 2613350281UL, PH_NOISY); + if (!phalcon_array_isset(automatic_attributes, field)) { - PHALCON_INIT_VAR(params); - phalcon_call_method_p1_key(params, this_ptr, "expression", expr_params, 218841909UL); - PHALCON_CONCAT_SVSVS(return_value, "partial(", path, ", ", params, "); ?>"); + PHALCON_INIT_NVAR(is_null); + ZVAL_BOOL(is_null, 0); + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, field)) { + PHALCON_OBS_NVAR(attribute_field); + phalcon_array_fetch(&attribute_field, column_map, field, PH_NOISY); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } else { + PHALCON_CPY_WRT(attribute_field, field); + } - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileSet){ - - zval *statement, *compilation, *assignments; - zval *assignment = NULL, *expr = NULL, *expr_code = NULL, *variable = NULL; - zval *op = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &statement); + if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { - if (!phalcon_array_isset_quick_string(statement, SS("assignments"), 2364482705UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); - PHALCON_INIT_VAR(compilation); - ZVAL_STRING(compilation, "") TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_skipped"), 0 TSRMLS_CC); - RETURN_CTOR(compilation); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + + PHALCON_OBS_VAR(skipped); + phalcon_read_property_this_quick(&skipped, this_ptr, SL("_skipped"), 2005665588UL, PH_NOISY_CC); + if (PHALCON_IS_TRUE(skipped)) { + RETURN_MM_TRUE; + } + } + + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileDo){ +static PHP_METHOD(Phalcon_Mvc_Model, _postSave){ - zval *statement, *expr, *expr_code; + zval *success, *exists, *event_name = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &statement); - - if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } + phalcon_fetch_params(1, 2, 0, &success, &exists); - PHALCON_OBS_VAR(expr); - phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); + if (PHALCON_IS_TRUE(success)) { + if (zend_is_true(exists)) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "afterUpdate", 1); + } else { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "afterCreate", 1); + } + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - PHALCON_INIT_VAR(expr_code); - phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "afterSave", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - PHALCON_CONCAT_SVS(return_value, ""); + RETURN_CCTOR(success); + } - RETURN_MM(); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "notSave", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + phalcon_call_method_key(NULL, this_ptr, "_canceloperation", 1716493051UL); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileReturn){ +static PHP_METHOD(Phalcon_Mvc_Model, _doLowInsert){ - zval *statement, *expr, *expr_code; + zval *meta_data, *connection, *table, *identity_field; + zval *null_value, *bind_skip, *fields, *values; + zval *bind_types, *attributes, *bind_data_types; + zval *automatic_attributes, *column_map = NULL, *field = NULL; + zval *attribute_field = NULL, *exception_message = NULL; + zval *value = NULL, *bind_type = NULL, *default_value, *use_explicit_identity; + zval *success, *sequence_name = NULL, *support_sequences; + zval *source, *last_insert_id; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &statement); + phalcon_fetch_params(1, 4, 0, &meta_data, &connection, &table, &identity_field); - if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } + PHALCON_INIT_VAR(null_value); - PHALCON_OBS_VAR(expr); - phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); + PHALCON_INIT_VAR(bind_skip); + ZVAL_LONG(bind_skip, 1024); - PHALCON_INIT_VAR(expr_code); - phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); - PHALCON_CONCAT_SVS(return_value, ""); + PHALCON_INIT_VAR(fields); + array_init(fields); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileAutoEscape){ - - zval *statement, *extends_mode, *old_autoescape; - zval *autoescape, *block_statements, *compilation; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &statement, &extends_mode); + PHALCON_INIT_VAR(values); + array_init(values); - if (!phalcon_array_isset_quick_string(statement, SS("enable"), 1780738348UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; + PHALCON_INIT_VAR(bind_types); + array_init(bind_types); + + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); + + PHALCON_INIT_VAR(bind_data_types); + phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); + + PHALCON_INIT_VAR(automatic_attributes); + phalcon_call_method_p1_key(automatic_attributes, meta_data, "getautomaticcreateattributes", this_ptr, 159934727UL); + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); + } else { + PHALCON_INIT_NVAR(column_map); } - PHALCON_OBS_VAR(old_autoescape); - phalcon_read_property_this_quick(&old_autoescape, this_ptr, SL("_autoescape"), 2399648718UL, PH_NOISY_CC); + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - PHALCON_OBS_VAR(autoescape); - phalcon_array_fetch_quick_string(&autoescape, statement, SS("enable"), 1780738348UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_autoescape"), autoescape, 2399648718UL TSRMLS_CC); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_OBS_VAR(block_statements); - phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); + PHALCON_GET_HVALUE(field); - PHALCON_INIT_VAR(compilation); - phalcon_call_method_p2_key(compilation, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); - phalcon_update_property_this_quick(this_ptr, SL("_autoescape"), old_autoescape, 2399648718UL TSRMLS_CC); + if (!phalcon_array_isset(automatic_attributes, field)) { - RETURN_CCTOR(compilation); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileMacro){ - - zval *statement, *extends_mode, *name, *macros; - zval *exception_message, *code, *parameters; - zval *parameter = NULL, *position = NULL, *variable_name = NULL, *block_statements; - zval *block_code; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &statement, &extends_mode); + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, field)) { + PHALCON_OBS_NVAR(attribute_field); + phalcon_array_fetch(&attribute_field, column_map, field, PH_NOISY); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } else { + PHALCON_CPY_WRT(attribute_field, field); + } - if (!phalcon_array_isset_quick_string(statement, SS("name"), 268211462UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; + if (!PHALCON_IS_EQUAL(field, identity_field)) { + phalcon_array_append(&fields, field, PH_SEPARATE); + + if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { + + if (!phalcon_array_isset(bind_data_types, field)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' have not defined a bind data type"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); + phalcon_array_append(&values, value, PH_SEPARATE); + + PHALCON_OBS_NVAR(bind_type); + phalcon_array_fetch(&bind_type, bind_data_types, field, PH_NOISY); + phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); + } else { + phalcon_array_append(&values, null_value, PH_SEPARATE); + phalcon_array_append(&bind_types, bind_skip, PH_SEPARATE); + } + } + } + + zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, statement, SS("name"), 268211462UL, PH_NOISY); + if (PHALCON_IS_NOT_FALSE(identity_field)) { + + PHALCON_INIT_VAR(default_value); + phalcon_call_method_key(default_value, connection, "getdefaultidvalue", 2034022004UL); + + PHALCON_INIT_VAR(use_explicit_identity); + phalcon_call_method_key(use_explicit_identity, connection, "useexplicitidvalue", 3630963518UL); + if (zend_is_true(use_explicit_identity)) { + phalcon_array_append(&fields, identity_field, PH_SEPARATE); + } - PHALCON_OBS_VAR(macros); - phalcon_read_property_this_quick(¯os, this_ptr, SL("_macros"), 3627118793UL, PH_NOISY_CC); + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, identity_field)) { + PHALCON_OBS_NVAR(attribute_field); + phalcon_array_fetch(&attribute_field, column_map, identity_field, PH_NOISY); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Identity column '", identity_field, "' isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } else { + PHALCON_CPY_WRT(attribute_field, identity_field); + } - if (phalcon_array_isset(macros, name)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Macro \"", name, "\" is already defined"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; - } else { - phalcon_update_property_array(this_ptr, SL("_macros"), name, name TSRMLS_CC); - } + if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, ""); - } else { - PHALCON_SCONCAT_VS(code, name, "($__p) { "); + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); + if (PHALCON_IS_EMPTY(value)) { + if (zend_is_true(use_explicit_identity)) { + phalcon_array_append(&values, default_value, PH_SEPARATE); + phalcon_array_append(&bind_types, bind_skip, PH_SEPARATE); + } + } else { + if (!zend_is_true(use_explicit_identity)) { + phalcon_array_append(&fields, identity_field, PH_SEPARATE); + } - PHALCON_OBS_VAR(parameters); - phalcon_array_fetch_quick_string(¶meters, statement, SS("parameters"), 3941032889UL, PH_NOISY); + if (!phalcon_array_isset(bind_data_types, identity_field)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Identity column '", identity_field, "' isn't part of the table columns"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } - phalcon_is_iterable(parameters, &ah0, &hp0, 0, 0); + phalcon_array_append(&values, value, PH_SEPARATE); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_NVAR(bind_type); + phalcon_array_fetch(&bind_type, bind_data_types, identity_field, PH_NOISY); + phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); + } + } else { + if (zend_is_true(use_explicit_identity)) { + phalcon_array_append(&values, default_value, PH_SEPARATE); + phalcon_array_append(&bind_types, bind_skip, PH_SEPARATE); + } + } + } - PHALCON_GET_HKEY(position, ah0, hp0); - PHALCON_GET_HVALUE(parameter); + PHALCON_INIT_VAR(success); + phalcon_call_method_p4_key(success, connection, "insert", table, values, fields, bind_types, 2673104346UL); + if (PHALCON_IS_NOT_FALSE(identity_field)) { - PHALCON_OBS_NVAR(variable_name); - phalcon_array_fetch_quick_string(&variable_name, parameter, SS("variable"), 1809440971UL, PH_NOISY); - PHALCON_SCONCAT_SVS(code, "if (isset($__p[", position, "])) { "); - PHALCON_SCONCAT_SVSVS(code, "$", variable_name, " = $__p[", position, "];"); - phalcon_concat_self_str(&code, SL(" } else { ") TSRMLS_CC); - PHALCON_SCONCAT_SVS(code, "if (isset($__p['", variable_name, "'])) { "); - PHALCON_SCONCAT_SVSVS(code, "$", variable_name, " = $__p['", variable_name, "'];"); - phalcon_concat_self_str(&code, SL(" } else { ") TSRMLS_CC); - PHALCON_SCONCAT_SVSVS(code, " throw new \\Phalcon\\Mvc\\View\\Exception(\"Macro ", name, " was called without parameter: ", variable_name, "\"); "); - phalcon_concat_self_str(&code, SL(" } } ") TSRMLS_CC); + PHALCON_INIT_VAR(sequence_name); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_VAR(support_sequences); + phalcon_call_method_key(support_sequences, connection, "supportsequences", 875716110UL); + if (PHALCON_IS_TRUE(support_sequences)) { + if (phalcon_method_quick_exists_ex(this_ptr, SS("getsequencename"), 3416900031UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(sequence_name, this_ptr, "getsequencename", 3416900031UL); + } else { + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); - phalcon_concat_self_str(&code, SL(" ?>") TSRMLS_CC); - } + PHALCON_INIT_NVAR(sequence_name); + PHALCON_CONCAT_VSVS(sequence_name, source, "_", identity_field, "_seq"); + } + } - if (phalcon_array_isset_quick_string(statement, SS("block_statements"), 883954391UL)) { - PHALCON_OBS_VAR(block_statements); - phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); + PHALCON_INIT_VAR(last_insert_id); + phalcon_call_method_p1_key(last_insert_id, connection, "lastinsertid", sequence_name, 106913211UL); + phalcon_update_property_zval_zval(this_ptr, attribute_field, last_insert_id TSRMLS_CC); - PHALCON_INIT_VAR(block_code); - phalcon_call_method_p2_key(block_code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); - PHALCON_SCONCAT_VS(code, block_code, ""); - } else { - phalcon_concat_self_str(&code, SL("") TSRMLS_CC); + phalcon_update_property_null(this_ptr, SL("_uniqueParams") TSRMLS_CC); } - RETURN_CTOR(code); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileCall){ - - - + RETURN_CCTOR(success); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _statementList){ +static PHP_METHOD(Phalcon_Mvc_Model, _doLowUpdate){ - zval *statements, *extends_mode = NULL, *extended = NULL, *block_mode = NULL; - zval *compilation = NULL, *extensions, *statement = NULL, *line = NULL; - zval *file = NULL, *exception_message = NULL, *event = NULL, *fire_arguments = NULL; - zval *temp_compilation = NULL, *type = NULL, *block_name = NULL, *block_statements = NULL; - zval *blocks = NULL, *code = NULL, *path = NULL, *view = NULL, *views_dir = NULL, *final_path = NULL; - zval *sub_compiler = NULL, *compiled_path = NULL, *level; - HashTable *ah0; - HashPosition hp0; + zval *meta_data, *connection, *table, *null_value; + zval *bind_skip, *fields, *values, *bind_types; + zval *manager, *use_dynamic_update = NULL, *snapshot; + zval *bind_data_types, *non_primary, *automatic_attributes; + zval *column_map = NULL, *field = NULL, *exception_message = NULL; + zval *attribute_field = NULL, *value = NULL, *bind_type = NULL, *changed = NULL; + zval *snapshot_value = NULL, *unique_key, *unique_params = NULL; + zval *unique_types, *primary_keys, *conditions; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &statements, &extends_mode); + phalcon_fetch_params(1, 3, 0, &meta_data, &connection, &table); - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } + PHALCON_INIT_VAR(null_value); - if (!phalcon_fast_count_ev(statements TSRMLS_CC)) { - RETURN_MM_EMPTY_STRING(); - } + PHALCON_INIT_VAR(bind_skip); + ZVAL_LONG(bind_skip, 1024); - PHALCON_OBS_VAR(extended); - phalcon_read_property_this_quick(&extended, this_ptr, SL("_extended"), 1049215029UL, PH_NOISY_CC); + PHALCON_INIT_VAR(fields); + array_init(fields); - PHALCON_INIT_VAR(block_mode); - ZVAL_BOOL(block_mode, zend_is_true(extended) || zend_is_true(extends_mode)); - if (PHALCON_IS_TRUE(block_mode)) { - phalcon_property_incr(this_ptr, SL("_blockLevel") TSRMLS_CC); + PHALCON_INIT_VAR(values); + array_init(values); + + PHALCON_INIT_VAR(bind_types); + array_init(bind_types); + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(use_dynamic_update); + phalcon_call_method_p1_key(use_dynamic_update, manager, "isusingdynamicupdate", this_ptr, 2562260687UL); + if (zend_is_true(use_dynamic_update)) { + + PHALCON_OBS_VAR(snapshot); + phalcon_read_property_this_quick(&snapshot, this_ptr, SL("_snapshot"), 3325604532UL, PH_NOISY_CC); + if (Z_TYPE_P(snapshot) != IS_ARRAY) { + PHALCON_INIT_NVAR(use_dynamic_update); + ZVAL_BOOL(use_dynamic_update, 0); + } } - phalcon_property_incr(this_ptr, SL("_level") TSRMLS_CC); + PHALCON_INIT_VAR(bind_data_types); + phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); - PHALCON_INIT_VAR(compilation); + PHALCON_INIT_VAR(non_primary); + phalcon_call_method_p1_key(non_primary, meta_data, "getnonprimarykeyattributes", this_ptr, 1524832420UL); - PHALCON_OBS_VAR(extensions); - phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); + PHALCON_INIT_VAR(automatic_attributes); + phalcon_call_method_p1_key(automatic_attributes, meta_data, "getautomaticupdateattributes", this_ptr, 2703790998UL); + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); + } else { + PHALCON_INIT_NVAR(column_map); + } - phalcon_is_iterable(statements, &ah0, &hp0, 0, 0); + phalcon_is_iterable(non_primary, &ah0, &hp0, 0, 0); while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_GET_HVALUE(statement); + PHALCON_GET_HVALUE(field); - if (Z_TYPE_P(statement) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } + if (!phalcon_array_isset(automatic_attributes, field)) { - if (!phalcon_array_isset_quick_string(statement, SS("type"), 276192743UL)) { - PHALCON_OBS_NVAR(line); - phalcon_array_fetch_quick_string(&line, statement, SS("line"), 266128205UL, PH_NOISY); + if (!phalcon_array_isset(bind_data_types, field)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' have not defined a bind data type"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } - PHALCON_OBS_NVAR(file); - phalcon_array_fetch_quick_string(&file, statement, SS("file"), 259010501UL, PH_NOISY); + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, field)) { + PHALCON_OBS_NVAR(attribute_field); + phalcon_array_fetch(&attribute_field, column_map, field, PH_NOISY); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } else { + PHALCON_CPY_WRT(attribute_field, field); + } - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Invalid statement in ", file, " on line ", line); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; - } + if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { - if (Z_TYPE_P(extensions) == IS_ARRAY) { + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); - PHALCON_INIT_NVAR(event); - ZVAL_STRING(event, "compileStatement", 1); + if (!zend_is_true(use_dynamic_update)) { + phalcon_array_append(&fields, field, PH_SEPARATE); + phalcon_array_append(&values, value, PH_SEPARATE); - PHALCON_INIT_NVAR(fire_arguments); - array_init_size(fire_arguments, 1); - phalcon_array_append(&fire_arguments, statement, PH_SEPARATE); + PHALCON_OBS_NVAR(bind_type); + phalcon_array_fetch(&bind_type, bind_data_types, field, PH_NOISY); + phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); + } else { + if (!phalcon_array_isset(snapshot, attribute_field)) { + PHALCON_INIT_NVAR(changed); + ZVAL_BOOL(changed, 1); + } else { + PHALCON_OBS_NVAR(snapshot_value); + phalcon_array_fetch(&snapshot_value, snapshot, attribute_field, PH_NOISY); + if (!PHALCON_IS_EQUAL(value, snapshot_value)) { + PHALCON_INIT_NVAR(changed); + ZVAL_BOOL(changed, 1); + } else { + PHALCON_INIT_NVAR(changed); + ZVAL_BOOL(changed, 0); + } + } - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p2_key(temp_compilation, this_ptr, "fireextensionevent", event, fire_arguments, 1575031978UL); - if (Z_TYPE_P(temp_compilation) == IS_STRING) { - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - zend_hash_move_forward_ex(ah0, &hp0); - continue; + if (zend_is_true(changed)) { + phalcon_array_append(&fields, field, PH_SEPARATE); + phalcon_array_append(&values, value, PH_SEPARATE); + + PHALCON_OBS_NVAR(bind_type); + phalcon_array_fetch(&bind_type, bind_data_types, field, PH_NOISY); + phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); + } + } + } else { + phalcon_array_append(&fields, field, PH_SEPARATE); + phalcon_array_append(&values, null_value, PH_SEPARATE); + phalcon_array_append(&bind_types, bind_skip, PH_SEPARATE); } } - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, statement, SS("type"), 276192743UL, PH_NOISY); - + zend_hash_move_forward_ex(ah0, &hp0); + } - switch (phalcon_get_intval(type)) { + if (!phalcon_fast_count_ev(fields TSRMLS_CC)) { + RETURN_MM_TRUE; + } - case 357: - PHALCON_OBS_NVAR(temp_compilation); - phalcon_array_fetch_quick_string(&temp_compilation, statement, SS("value"), 574111618UL, PH_NOISY); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + PHALCON_OBS_VAR(unique_key); + phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); - case 300: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p2_key(temp_compilation, this_ptr, "compileif", statement, extends_mode, 2315543869UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + PHALCON_OBS_VAR(unique_params); + phalcon_read_property_this_quick(&unique_params, this_ptr, SL("_uniqueParams"), 1065564063UL, PH_NOISY_CC); - case 302: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p1_key(temp_compilation, this_ptr, "compileelseif", statement, 4134464646UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + PHALCON_OBS_VAR(unique_types); + phalcon_read_property_this_quick(&unique_types, this_ptr, SL("_uniqueTypes"), 3340838640UL, PH_NOISY_CC); - case 304: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p2_key(temp_compilation, this_ptr, "compileforeach", statement, extends_mode, 2502131046UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + if (Z_TYPE_P(unique_params) != IS_ARRAY) { - case 306: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p1_key(temp_compilation, this_ptr, "compileset", statement, 3398865754UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + PHALCON_INIT_NVAR(unique_params); + array_init(unique_params); - case 359: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p1_key(temp_compilation, this_ptr, "compileecho", statement, 476736013UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + PHALCON_INIT_VAR(primary_keys); + phalcon_call_method_p1_key(primary_keys, meta_data, "getprimarykeyattributes", this_ptr, 692945721UL); - case 307: - PHALCON_OBS_NVAR(block_name); - phalcon_array_fetch_quick_string(&block_name, statement, SS("name"), 268211462UL, PH_NOISY); - if (phalcon_array_isset_quick_string(statement, SS("block_statements"), 883954391UL)) { - PHALCON_OBS_NVAR(block_statements); - phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(block_statements); - } + if (!phalcon_fast_count_ev(primary_keys TSRMLS_CC)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A primary key must be defined in the model in order to perform the operation"); + return; + } - PHALCON_OBS_NVAR(blocks); - phalcon_read_property_this_quick(&blocks, this_ptr, SL("_blocks"), 2750049986UL, PH_NOISY_CC); - if (zend_is_true(block_mode)) { - if (Z_TYPE_P(blocks) != IS_ARRAY) { - PHALCON_INIT_NVAR(blocks); - array_init(blocks); - } + phalcon_is_iterable(primary_keys, &ah1, &hp1, 0, 0); - if (Z_TYPE_P(compilation) != IS_NULL) { - phalcon_array_append(&blocks, compilation, PH_SEPARATE); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_INIT_NVAR(compilation); - } + PHALCON_GET_HVALUE(field); - phalcon_array_update_zval(&blocks, block_name, &block_statements, PH_COPY | PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_blocks"), blocks, 2750049986UL TSRMLS_CC); + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, field)) { + PHALCON_OBS_NVAR(attribute_field); + phalcon_array_fetch(&attribute_field, column_map, field, PH_NOISY); } else { - if (Z_TYPE_P(block_statements) == IS_ARRAY) { - PHALCON_INIT_NVAR(code); - phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); - phalcon_concat_self(&compilation, code TSRMLS_CC); - } + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } + } else { + PHALCON_CPY_WRT(attribute_field, field); + } + 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_CC); + phalcon_array_append(&unique_params, value, PH_SEPARATE); + } else { + phalcon_array_append(&unique_params, null_value, PH_SEPARATE); + } - break; + zend_hash_move_forward_ex(ah1, &hp1); + } - case 310: - PHALCON_OBS_NVAR(path); - phalcon_array_fetch_quick_string(&path, statement, SS("path"), 270591026UL, PH_NOISY); + } - PHALCON_OBS_NVAR(view); - phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); - if (Z_TYPE_P(view) == IS_OBJECT) { - PHALCON_INIT_NVAR(views_dir); - phalcon_call_method_key(views_dir, view, "getviewsdir", 2448458514UL); + PHALCON_INIT_VAR(conditions); + array_init_size(conditions, 3); + phalcon_array_update_quick_string(&conditions, SS("conditions"), 1055696255UL, &unique_key, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&conditions, SS("bind"), 254268962UL, &unique_params, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&conditions, SS("bindTypes"), 3951758359UL, &unique_types, PH_COPY | PH_SEPARATE); - PHALCON_INIT_NVAR(final_path); - PHALCON_CONCAT_VV(final_path, views_dir, path); - } else { - PHALCON_CPY_WRT(final_path, path); - } + phalcon_call_method_p5(return_value, connection, "update", table, fields, values, conditions, bind_types); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, _preSaveRelatedRecords){ + + zval *connection, *related, *nesting, *class_name; + zval *manager, *record = NULL, *name = NULL, *relation = NULL, *type = NULL, *columns = NULL; + zval *referenced_model = NULL, *referenced_fields = NULL; + zval *status = NULL, *messages = NULL, *message = NULL, *referenced_value = NULL; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &connection, &related); - PHALCON_INIT_NVAR(extended); - ZVAL_BOOL(extended, 1); + PHALCON_INIT_VAR(nesting); + ZVAL_BOOL(nesting, 0); - PHALCON_INIT_NVAR(sub_compiler); - if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { - return; - } + phalcon_call_method_p1_key(NULL, connection, "begin", nesting, 4090922282UL); - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p2_key(temp_compilation, sub_compiler, "compile", final_path, extended, 1074882030UL); + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); - if (Z_TYPE_P(temp_compilation) == IS_NULL) { - PHALCON_INIT_NVAR(compiled_path); - phalcon_call_method_key(compiled_path, sub_compiler, "getcompiledtemplatepath", 652904091UL); + PHALCON_INIT_VAR(manager); + phalcon_call_method_key(manager, this_ptr, "getmodelsmanager", 2387491844UL); - PHALCON_INIT_NVAR(temp_compilation); - phalcon_file_get_contents(temp_compilation, compiled_path TSRMLS_CC); - } + phalcon_is_iterable(related, &ah0, &hp0, 0, 0); - phalcon_update_property_bool(this_ptr, SL("_extended"), 1 TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_extendedBlocks"), temp_compilation, 3140083987UL TSRMLS_CC); - PHALCON_CPY_WRT(block_mode, extended); - break; + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - case 313: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p1_key(temp_compilation, this_ptr, "compileinclude", statement, 3933930706UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + PHALCON_GET_HKEY(name, ah0, hp0); + PHALCON_GET_HVALUE(record); - case 314: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p2_key(temp_compilation, this_ptr, "compilecache", statement, extends_mode, 2766559938UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + PHALCON_INIT_NVAR(relation); + phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", class_name, name, 785467656UL); + if (Z_TYPE_P(relation) == IS_OBJECT) { - case 316: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p1_key(temp_compilation, this_ptr, "compiledo", statement, 2315538721UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + PHALCON_INIT_NVAR(type); + phalcon_call_method_key(type, relation, "gettype", 4294422375UL); - case 327: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p1_key(temp_compilation, this_ptr, "compilereturn", statement, 3471502286UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + if (PHALCON_IS_LONG(type, 0)) { - case 317: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p2_key(temp_compilation, this_ptr, "compileautoescape", statement, extends_mode, 3843651512UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + if (Z_TYPE_P(record) != IS_OBJECT) { + phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Only objects can be stored as part of belongs-to relations"); + return; + } - case 319: - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - break; + PHALCON_INIT_NVAR(columns); + phalcon_call_method_key(columns, relation, "getfields", 2162018780UL); - case 320: - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - break; + PHALCON_INIT_NVAR(referenced_model); + phalcon_call_method_key(referenced_model, relation, "getreferencedmodel", 478093161UL); - case 321: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_key(temp_compilation, this_ptr, "compileforelse", 2502543678UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + PHALCON_INIT_NVAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); + if (Z_TYPE_P(columns) == IS_ARRAY) { + phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Not implemented"); + return; + } - case 322: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p2_key(temp_compilation, this_ptr, "compilemacro", statement, extends_mode, 3157925088UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + PHALCON_INIT_NVAR(status); + phalcon_call_method_key(status, record, "save", 274150868UL); + if (!zend_is_true(status)) { - case 325: - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p2_key(temp_compilation, this_ptr, "compilecall", statement, extends_mode, 474296554UL); - phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); - break; + PHALCON_INIT_NVAR(messages); + phalcon_call_method_key(messages, record, "getmessages", 4087333309UL); - case 358: - break; + phalcon_is_iterable(messages, &ah1, &hp1, 0, 0); - default: - PHALCON_OBS_NVAR(line); - phalcon_array_fetch_quick_string(&line, statement, SS("line"), 266128205UL, PH_NOISY); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_OBS_NVAR(file); - phalcon_array_fetch_quick_string(&file, statement, SS("file"), 259010501UL, PH_NOISY); + PHALCON_GET_HVALUE(message); - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVSV(exception_message, "Unknown statement ", type, " in ", file, " on line ", line); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; + if (Z_TYPE_P(record) == IS_OBJECT) { + phalcon_call_method_p1_key(NULL, message, "setmodel", record, 1672695874UL); + } - } + phalcon_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - zend_hash_move_forward_ex(ah0, &hp0); - } + zend_hash_move_forward_ex(ah1, &hp1); + } - if (PHALCON_IS_TRUE(block_mode)) { + phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); + RETURN_MM_FALSE; + } - PHALCON_OBS_VAR(level); - phalcon_read_property_this_quick(&level, this_ptr, SL("_blockLevel"), 160754279UL, PH_NOISY_CC); - if (PHALCON_IS_LONG(level, 1)) { + PHALCON_INIT_NVAR(referenced_value); + phalcon_call_method_p1_key(referenced_value, record, "readattribute", referenced_fields, 95450773UL); - if (Z_TYPE_P(compilation) != IS_NULL) { - phalcon_update_property_array_append(this_ptr, SL("_blocks"), compilation TSRMLS_CC); + phalcon_update_property_zval_zval(this_ptr, columns, referenced_value TSRMLS_CC); } } - phalcon_property_decr(this_ptr, SL("_blockLevel") TSRMLS_CC); + zend_hash_move_forward_ex(ah0, &hp0); } - phalcon_property_decr(this_ptr, SL("_level") TSRMLS_CC); - - RETURN_CCTOR(compilation); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _compileSource){ +static PHP_METHOD(Phalcon_Mvc_Model, _postSaveRelatedRecords){ - zval *view_code, *extends_mode = NULL, *current_path; - zval *intermediate, *compilation, *extended; - zval *final_compilation = NULL, *blocks = NULL, *extended_blocks; - zval *block = NULL, *name = NULL, *local_block = NULL, *block_compilation = NULL; - HashTable *ah0; - HashPosition hp0; + zval *connection, *related, *nesting, *class_name; + zval *manager, *record = NULL, *name = NULL, *relation = NULL, *type = NULL, *columns = NULL; + zval *referenced_model = NULL, *referenced_fields = NULL; + zval *related_records = NULL, *exception_message = NULL; + zval *value = NULL, *is_through = NULL, *new_instance = NULL, *intermediate_model_name = NULL; + zval *intermediate_fields = NULL, *intermediate_referenced_fields = NULL; + zval *record_after = NULL, *intermediate_model = NULL, *intermediate_value = NULL; + zval *status = NULL, *messages = NULL, *message = NULL; + HashTable *ah0, *ah1, *ah2, *ah3; + HashPosition hp0, hp1, hp2, hp3; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &view_code, &extends_mode); + phalcon_fetch_params(1, 2, 0, &connection, &related); - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } + PHALCON_INIT_VAR(nesting); + ZVAL_BOOL(nesting, 0); - PHALCON_OBS_VAR(current_path); - phalcon_read_property_this_quick(¤t_path, this_ptr, SL("_currentPath"), 3436123892UL, PH_NOISY_CC); + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); - PHALCON_INIT_VAR(intermediate); - if (phvolt_parse_view(intermediate, view_code, current_path TSRMLS_CC) == FAILURE) { - return; - } + PHALCON_INIT_VAR(manager); + phalcon_call_method_key(manager, this_ptr, "getmodelsmanager", 2387491844UL); - if (Z_TYPE_P(intermediate) == IS_ARRAY) { + phalcon_is_iterable(related, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(compilation); - phalcon_call_method_p2_key(compilation, this_ptr, "_statementlist", intermediate, extends_mode, 1357145205UL); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_OBS_VAR(extended); - phalcon_read_property_this_quick(&extended, this_ptr, SL("_extended"), 1049215029UL, PH_NOISY_CC); - if (PHALCON_IS_TRUE(extended)) { + PHALCON_GET_HKEY(name, ah0, hp0); + PHALCON_GET_HVALUE(record); - if (PHALCON_IS_TRUE(extends_mode)) { - PHALCON_INIT_VAR(final_compilation); - array_init(final_compilation); - } else { - PHALCON_INIT_NVAR(final_compilation); - } + PHALCON_INIT_NVAR(relation); + phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", class_name, name, 785467656UL); + if (Z_TYPE_P(relation) == IS_OBJECT) { - PHALCON_OBS_VAR(blocks); - phalcon_read_property_this_quick(&blocks, this_ptr, SL("_blocks"), 2750049986UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(type); + phalcon_call_method_key(type, relation, "gettype", 4294422375UL); - PHALCON_OBS_VAR(extended_blocks); - phalcon_read_property_this_quick(&extended_blocks, this_ptr, SL("_extendedBlocks"), 3140083987UL, PH_NOISY_CC); + if (PHALCON_IS_LONG(type, 0)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } - phalcon_is_iterable(extended_blocks, &ah0, &hp0, 0, 0); + if (Z_TYPE_P(record) != IS_OBJECT) { + if (Z_TYPE_P(record) != IS_ARRAY) { + phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Only objects/arrays can be stored as part of has-many/has-one/has-many-to-many relations"); + return; + } + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_NVAR(columns); + phalcon_call_method_key(columns, relation, "getfields", 2162018780UL); - PHALCON_GET_HKEY(name, ah0, hp0); - PHALCON_GET_HVALUE(block); + PHALCON_INIT_NVAR(referenced_model); + phalcon_call_method_key(referenced_model, relation, "getreferencedmodel", 478093161UL); - if (Z_TYPE_P(name) == IS_STRING) { - if (Z_TYPE_P(block) == IS_ARRAY) { - if (phalcon_array_isset(blocks, name)) { - PHALCON_OBS_NVAR(local_block); - phalcon_array_fetch(&local_block, blocks, name, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_currentBlock"), name, 1187906770UL TSRMLS_CC); + PHALCON_INIT_NVAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); + if (Z_TYPE_P(columns) == IS_ARRAY) { + phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Not implemented"); + return; + } - PHALCON_INIT_NVAR(block_compilation); - phalcon_call_method_p1_key(block_compilation, this_ptr, "_statementlist", local_block, 1357145205UL); - } else { - PHALCON_INIT_NVAR(block_compilation); - phalcon_call_method_p1_key(block_compilation, this_ptr, "_statementlist", block, 1357145205UL); - } - } else { - if (phalcon_array_isset(blocks, name)) { - PHALCON_OBS_NVAR(local_block); - phalcon_array_fetch(&local_block, blocks, name, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_currentBlock"), name, 1187906770UL TSRMLS_CC); + if (Z_TYPE_P(record) == IS_OBJECT) { + PHALCON_INIT_NVAR(related_records); + array_init_size(related_records, 1); + phalcon_array_append(&related_records, record, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(related_records, record); + } - PHALCON_INIT_NVAR(block_compilation); - phalcon_call_method_p1_key(block_compilation, this_ptr, "_statementlist", local_block, 1357145205UL); - } else { - PHALCON_CPY_WRT(block_compilation, block); - } - } - if (PHALCON_IS_TRUE(extends_mode)) { - phalcon_array_update_zval(&final_compilation, name, &block_compilation, PH_COPY | PH_SEPARATE); - } else { - phalcon_concat_self(&final_compilation, block_compilation TSRMLS_CC); - } - } else { - if (PHALCON_IS_TRUE(extends_mode)) { - phalcon_array_append(&final_compilation, block, PH_SEPARATE); - } else { - phalcon_concat_self(&final_compilation, block TSRMLS_CC); - } - } + if (!phalcon_isset_property_zval(this_ptr, columns TSRMLS_CC)) { + phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "The column '", columns, "' needs to be present in the model"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } - RETURN_CCTOR(final_compilation); - } - - if (PHALCON_IS_TRUE(extends_mode)) { - PHALCON_OBS_NVAR(blocks); - phalcon_read_property_this_quick(&blocks, this_ptr, SL("_blocks"), 2750049986UL, PH_NOISY_CC); - RETURN_CCTOR(blocks); - } + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, columns, PH_NOISY_CC); - RETURN_CCTOR(compilation); - } + PHALCON_INIT_NVAR(is_through); + phalcon_call_method_key(is_through, relation, "isthrough", 2540564770UL); - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Invalid intermediate representation"); - return; -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileString){ - - zval *view_code, *extends_mode = NULL, *current_path; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &view_code, &extends_mode); + if (zend_is_true(is_through)) { + PHALCON_INIT_NVAR(new_instance); + ZVAL_BOOL(new_instance, 1); - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } + PHALCON_INIT_NVAR(intermediate_model_name); + phalcon_call_method_key(intermediate_model_name, relation, "getintermediatemodel", 851527441UL); - if (Z_TYPE_P(view_code) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The code must be string"); - return; - } + PHALCON_INIT_NVAR(intermediate_fields); + phalcon_call_method_key(intermediate_fields, relation, "getintermediatefields", 1646880791UL); - PHALCON_INIT_VAR(current_path); - ZVAL_STRING(current_path, "eval code", 1); - phalcon_update_property_this_quick(this_ptr, SL("_currentPath"), current_path, 3436123892UL TSRMLS_CC); - phalcon_call_method_p2_key(return_value, this_ptr, "_compilesource", view_code, extends_mode, 1468654718UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileFile){ - - zval *path, *compiled_path, *extends_mode = NULL, *exception_message = NULL; - zval *view_code, *compilation, *final_compilation = NULL; - zval *status; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &path, &compiled_path, &extends_mode); + PHALCON_INIT_NVAR(intermediate_referenced_fields); + phalcon_call_method_key(intermediate_referenced_fields, relation, "getintermediatereferencedfields", 3001626474UL); + } - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } + phalcon_is_iterable(related_records, &ah1, &hp1, 0, 0); - if (PHALCON_IS_EQUAL(path, compiled_path)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Template path and compilation template path cannot be the same"); - return; - } + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - if (phalcon_file_exists(path TSRMLS_CC) == FAILURE) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Template file ", path, " does not exist"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; - } + PHALCON_GET_HVALUE(record_after); - PHALCON_INIT_VAR(view_code); - phalcon_file_get_contents(view_code, path TSRMLS_CC); - if (PHALCON_IS_FALSE(view_code)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Template file ", path, " could not be opened"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; - } + if (!zend_is_true(is_through)) { + phalcon_call_method_p2_key(NULL, record_after, "writeattribute", referenced_fields, value, 3716971876UL); + } else { + PHALCON_INIT_NVAR(intermediate_model); + phalcon_call_method_p2_key(intermediate_model, manager, "load", intermediate_model_name, new_instance, 266329637UL); - phalcon_update_property_this_quick(this_ptr, SL("_currentPath"), path, 3436123892UL TSRMLS_CC); + phalcon_call_method_p2_key(NULL, intermediate_model, "writeattribute", intermediate_fields, value, 3716971876UL); - PHALCON_INIT_VAR(compilation); - phalcon_call_method_p2_key(compilation, this_ptr, "_compilesource", view_code, extends_mode, 1468654718UL); + PHALCON_OBS_NVAR(intermediate_value); + phalcon_read_property_zval(&intermediate_value, record_after, referenced_fields, PH_NOISY_CC); - if (Z_TYPE_P(compilation) == IS_ARRAY) { - PHALCON_INIT_VAR(final_compilation); - phalcon_serialize(final_compilation, &compilation TSRMLS_CC); - } else { - PHALCON_CPY_WRT(final_compilation, compilation); - } + phalcon_call_method_p2_key(NULL, intermediate_model, "writeattribute", intermediate_referenced_fields, intermediate_value, 3716971876UL); - PHALCON_INIT_VAR(status); - phalcon_file_put_contents(status, compiled_path, final_compilation TSRMLS_CC); - if (PHALCON_IS_FALSE(status)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Volt directory can't be written"); - return; - } + PHALCON_INIT_NVAR(status); + phalcon_call_method_key(status, intermediate_model, "save", 274150868UL); + if (!zend_is_true(status)) { - RETURN_CCTOR(compilation); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compile){ - - zval *template_path, *extends_mode = NULL, *zero, *znull; - zval *zfalse, *stat = NULL, *compile_always = NULL, *compiled_path = NULL; - zval *prefix = NULL, *compiled_separator = NULL, *compiled_extension = NULL; - zval *compilation = NULL, *options, *real_template_path; - zval *template_sep_path = NULL, *compiled_template_path = NULL; - zval *params, *real_compiled_path = NULL, *blocks_code; - zval *exception_message = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &template_path, &extends_mode); + PHALCON_INIT_NVAR(messages); + phalcon_call_method_key(messages, intermediate_model, "getmessages", 4087333309UL); - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } + phalcon_is_iterable(messages, &ah2, &hp2, 0, 0); - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - PHALCON_INIT_VAR(znull); + PHALCON_GET_HVALUE(message); - PHALCON_INIT_VAR(zfalse); - ZVAL_BOOL(zfalse, 0); + if (Z_TYPE_P(message) == IS_OBJECT) { + phalcon_call_method_p1_key(NULL, message, "setmodel", record, 1672695874UL); + } - phalcon_update_property_this_quick(this_ptr, SL("_extended"), zfalse, 1049215029UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_extendedBlocks"), zfalse, 3140083987UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_blocks"), znull, 2750049986UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_level"), zero, 2549049372UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_foreachLevel"), zero, 1560648116UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_blockLevel"), zero, 160754279UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_exprLevel"), zero, 4164657371UL TSRMLS_CC); + phalcon_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - PHALCON_INIT_VAR(stat); - ZVAL_BOOL(stat, 1); - PHALCON_CPY_WRT(compile_always, zfalse); + zend_hash_move_forward_ex(ah2, &hp2); + } - PHALCON_INIT_VAR(compiled_path); - ZVAL_STRING(compiled_path, "", 1); - PHALCON_CPY_WRT(prefix, znull); + phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); + RETURN_MM_FALSE; + } + } - PHALCON_INIT_VAR(compiled_separator); - ZVAL_STRING(compiled_separator, "%%", 1); + PHALCON_INIT_NVAR(status); + phalcon_call_method_key(status, record_after, "save", 274150868UL); + if (!zend_is_true(status)) { - PHALCON_INIT_VAR(compiled_extension); - ZVAL_STRING(compiled_extension, ".php", 1); - PHALCON_CPY_WRT(compilation, znull); + PHALCON_INIT_NVAR(messages); + phalcon_call_method_key(messages, record_after, "getmessages", 4087333309UL); - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (Z_TYPE_P(options) == IS_ARRAY) { + phalcon_is_iterable(messages, &ah3, &hp3, 0, 0); - if (phalcon_array_isset_quick_string(options, SS("compileAlways"), 595908511UL)) { + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - phalcon_array_fetch_quick_string(&compile_always, options, SS("compileAlways"), 595908511UL, PH_NOISY); - if (Z_TYPE_P(compile_always) != IS_BOOL) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compileAlways must be a bool value"); - return; - } - } + PHALCON_GET_HVALUE(message); - if (phalcon_array_isset_quick_string(options, SS("prefix"), 3263410483UL)) { + if (Z_TYPE_P(message) == IS_OBJECT) { + phalcon_call_method_p1_key(NULL, message, "setmodel", record, 1672695874UL); + } - phalcon_array_fetch_quick_string(&prefix, options, SS("prefix"), 3263410483UL, PH_NOISY); - if (Z_TYPE_P(prefix) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "prefix must be a string"); - return; - } - } + phalcon_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - if (phalcon_array_isset_quick_string(options, SS("compiledPath"), 2785475967UL)) { + zend_hash_move_forward_ex(ah3, &hp3); + } - PHALCON_OBS_NVAR(compiled_path); - phalcon_array_fetch_quick_string(&compiled_path, options, SS("compiledPath"), 2785475967UL, PH_NOISY); - if (Z_TYPE_P(compiled_path) != IS_STRING) { - if (Z_TYPE_P(compiled_path) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compiledPath must be a string or a closure"); - return; + phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); + RETURN_MM_FALSE; } + + zend_hash_move_forward_ex(ah1, &hp1); } - } - if (phalcon_array_isset_quick_string(options, SS("compiledSeparator"), 3462898403UL)) { + } else { + if (Z_TYPE_P(record) != IS_ARRAY) { + phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - PHALCON_OBS_NVAR(compiled_separator); - phalcon_array_fetch_quick_string(&compiled_separator, options, SS("compiledSeparator"), 3462898403UL, PH_NOISY); - if (Z_TYPE_P(compiled_separator) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compiledSeparator must be a string"); + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVS(exception_message, "There are no defined relations for the model \"", class_name, "\" using alias \"", name, "\""); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } } - if (phalcon_array_isset_quick_string(options, SS("compiledExtension"), 401304207UL)) { + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_OBS_NVAR(compiled_extension); - phalcon_array_fetch_quick_string(&compiled_extension, options, SS("compiledExtension"), 401304207UL, PH_NOISY); - if (Z_TYPE_P(compiled_extension) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compiledExtension must be a string"); - return; - } - } + phalcon_call_method_p1_key(NULL, connection, "commit", nesting, 3546528686UL); + RETURN_MM_TRUE; +} + +static PHP_METHOD(Phalcon_Mvc_Model, save){ + + zval *data = NULL, *white_list = NULL, *meta_data, *attributes = NULL; + zval *attribute = NULL, *value = NULL, *possible_setter = NULL, *write_connection; + zval *related, *status = NULL, *schema, *source, *table = NULL, *read_connection; + zval *exists, *error_messages = NULL, *identity_field; + zval *nesting = NULL, *exception, *success = NULL, *new_success = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &data, &white_list); - if (phalcon_array_isset_quick_string(options, SS("stat"), 274811297UL)) { - PHALCON_OBS_NVAR(stat); - phalcon_array_fetch_quick_string(&stat, options, SS("stat"), 274811297UL, PH_NOISY); - } + if (!data) { + PHALCON_INIT_VAR(data); } - if (Z_TYPE_P(compiled_path) == IS_STRING) { + if (!white_list) { + PHALCON_INIT_VAR(white_list); + } - if (PHALCON_IS_NOT_EMPTY(compiled_path)) { - PHALCON_INIT_VAR(real_template_path); - phalcon_call_func_p1(real_template_path, "realpath", template_path); + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - PHALCON_INIT_VAR(template_sep_path); - phalcon_prepare_virtual_path(template_sep_path, real_template_path, compiled_separator TSRMLS_CC); - } else { - PHALCON_CPY_WRT(template_sep_path, template_path); + if (Z_TYPE_P(data) != IS_NULL) { + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data passed to save() must be an array"); + return; } - if (PHALCON_IS_TRUE(extends_mode)) { - PHALCON_INIT_VAR(compiled_template_path); - PHALCON_CONCAT_VVVVSVV(compiled_template_path, compiled_path, prefix, template_sep_path, compiled_separator, "e", compiled_separator, compiled_extension); - } else { - PHALCON_INIT_NVAR(compiled_template_path); - PHALCON_CONCAT_VVVV(compiled_template_path, compiled_path, prefix, template_sep_path, compiled_extension); + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getcolumnmap", this_ptr, 213063537UL); + if (Z_TYPE_P(attributes) != IS_ARRAY) { + PHALCON_INIT_NVAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); } - } else { - if (Z_TYPE_P(compiled_path) == IS_OBJECT) { - if (phalcon_is_instance_of(compiled_path, SL("Closure") TSRMLS_CC)) { - PHALCON_INIT_VAR(params); - array_init_size(params, 3); - phalcon_array_append(¶ms, template_path, PH_SEPARATE); - phalcon_array_append(¶ms, options, PH_SEPARATE); - phalcon_array_append(¶ms, extends_mode, PH_SEPARATE); + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(compiled_template_path); - PHALCON_CALL_USER_FUNC_ARRAY(compiled_template_path, compiled_path, params); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (Z_TYPE_P(compiled_template_path) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compiledPath closure didn't return a valid string"); - return; + PHALCON_GET_HVALUE(attribute); + + if (phalcon_array_isset(data, attribute)) { + + if (Z_TYPE_P(white_list) == IS_ARRAY) { + if (!phalcon_fast_in_array(attribute, white_list TSRMLS_CC)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } + + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, data, attribute, PH_NOISY); + + PHALCON_INIT_NVAR(possible_setter); + PHALCON_CONCAT_SV(possible_setter, "set", attribute); + if (phalcon_method_exists(this_ptr, possible_setter TSRMLS_CC) == SUCCESS) { + phalcon_call_method_zval_p1_noret(this_ptr, possible_setter, value); + } else { + phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); } - } else { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compiledPath must be a string or a closure"); - return; } - } - } - PHALCON_CPY_WRT(real_compiled_path, compiled_template_path); - if (zend_is_true(compile_always)) { - PHALCON_INIT_NVAR(compilation); - phalcon_call_method_p3_key(compilation, this_ptr, "compilefile", template_path, real_compiled_path, extends_mode, 478141582UL); - } else { - if (PHALCON_IS_TRUE(stat)) { + zend_hash_move_forward_ex(ah0, &hp0); + } - if (phalcon_file_exists(compiled_template_path TSRMLS_CC) == SUCCESS) { + } - if (phalcon_compare_mtime(template_path, real_compiled_path TSRMLS_CC)) { - PHALCON_INIT_NVAR(compilation); - phalcon_call_method_p3_key(compilation, this_ptr, "compilefile", template_path, real_compiled_path, extends_mode, 478141582UL); - } else { - if (PHALCON_IS_TRUE(extends_mode)) { + PHALCON_INIT_VAR(write_connection); + phalcon_call_method_key(write_connection, this_ptr, "getwriteconnection", 4280185952UL); - PHALCON_INIT_VAR(blocks_code); - phalcon_file_get_contents(blocks_code, real_compiled_path TSRMLS_CC); - if (PHALCON_IS_FALSE(blocks_code)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Extends compilation file ", real_compiled_path, " could not be opened"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; - } + PHALCON_OBS_VAR(related); + phalcon_read_property_this_quick(&related, this_ptr, SL("_related"), 3277783461UL, PH_NOISY_CC); + if (Z_TYPE_P(related) == IS_ARRAY) { - if (zend_is_true(blocks_code)) { - PHALCON_INIT_NVAR(compilation); - phalcon_unserialize(compilation, blocks_code TSRMLS_CC); - } else { - PHALCON_INIT_NVAR(compilation); - array_init(compilation); - } - } - } - } else { - PHALCON_INIT_NVAR(compilation); - phalcon_call_method_p3_key(compilation, this_ptr, "compilefile", template_path, real_compiled_path, extends_mode, 478141582UL); - } - } else { - if (phalcon_file_exists(real_compiled_path TSRMLS_CC) == FAILURE) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Compiled template file ", real_compiled_path, " does not exist"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; - } + PHALCON_INIT_VAR(status); + phalcon_call_method_p2_key(status, this_ptr, "_presaverelatedrecords", write_connection, related, 2651327373UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; } } - phalcon_update_property_this_quick(this_ptr, SL("_compiledTemplatePath"), real_compiled_path, 2270620474UL TSRMLS_CC); - - RETURN_CCTOR(compilation); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getTemplatePath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_currentPath", 3436123892UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getCompiledTemplatePath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_compiledTemplatePath", 2270620474UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, parse){ - - zval *view_code, *current_path; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &view_code); + PHALCON_INIT_VAR(schema); + phalcon_call_method_key(schema, this_ptr, "getschema", 1539736246UL); - PHALCON_INIT_VAR(current_path); - ZVAL_STRING(current_path, "eval code", 1); - if (phvolt_parse_view(return_value, view_code, current_path TSRMLS_CC) == FAILURE) { - return; + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); + if (zend_is_true(schema)) { + PHALCON_INIT_VAR(table); + array_init_size(table, 2); + phalcon_array_append(&table, schema, PH_SEPARATE); + phalcon_array_append(&table, source, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(table, source); } - RETURN_MM(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_View_EngineInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\View, EngineInterface, mvc_view_engineinterface, phalcon_mvc_view_engineinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_View_Engine){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View, Engine, mvc_view_engine, "phalcon\\di\\injectable", phalcon_mvc_view_engine_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - zend_declare_property_null(phalcon_mvc_view_engine_ce, SL("_view"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine, __construct){ - - zval *view, *dependency_injector = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &view, &dependency_injector); - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); + PHALCON_INIT_VAR(read_connection); + phalcon_call_method_key(read_connection, this_ptr, "getreadconnection", 488334257UL); + + PHALCON_INIT_VAR(exists); + phalcon_call_method_p3_key(exists, this_ptr, "_exists", meta_data, read_connection, table, 2792580580UL); + if (zend_is_true(exists)) { + phalcon_update_property_long(this_ptr, SL("_operationMade"), 2 TSRMLS_CC); + } else { + phalcon_update_property_long(this_ptr, SL("_operationMade"), 1 TSRMLS_CC); } - phalcon_update_property_this_quick(this_ptr, SL("_view"), view, 3993744575UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + PHALCON_INIT_VAR(error_messages); + array_init(error_messages); + phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), error_messages, 1019066246UL TSRMLS_CC); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine, getContent){ - - zval *view; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(view); - phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); - phalcon_call_method_key(return_value, view, "getcontent", 3141446400UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine, partial){ - - zval *partial_path, *params = NULL, *view; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &partial_path, ¶ms); + PHALCON_INIT_VAR(identity_field); + phalcon_call_method_p1_key(identity_field, meta_data, "getidentityfield", this_ptr, 1208930067UL); - if (!params) { - PHALCON_INIT_VAR(params); - } + PHALCON_INIT_NVAR(status); + phalcon_call_method_p3_key(status, this_ptr, "_presave", meta_data, exists, identity_field, 3296192410UL); + if (PHALCON_IS_FALSE(status)) { - PHALCON_OBS_VAR(view); - phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); - phalcon_call_method_p2_key(return_value, view, "partial", partial_path, params, 363586066UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine, getView){ - - - RETURN_MEMBER_QUICK(this_ptr, "_view", 3993744575UL); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_View_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View, Exception, mvc_view_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_View_Simple){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View, Simple, mvc_view_simple, "phalcon\\di\\injectable", phalcon_mvc_view_simple_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_viewsDir"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_partialsDir"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_viewParams"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_view_simple_ce, SL("_engines"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_registeredEngines"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_activeRenderPath"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_content"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_view_simple_ce, SL("_cache"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_cacheOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, __construct){ - - zval *options = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); + if (Z_TYPE_P(related) == IS_ARRAY) { + PHALCON_INIT_VAR(nesting); + ZVAL_BOOL(nesting, 0); + phalcon_call_method_p1_key(NULL, write_connection, "rollback", nesting, 3199546639UL); + } - if (!options) { - PHALCON_INIT_VAR(options); + if (PHALCON_GLOBAL(orm).exception_on_failed_save) { + PHALCON_OBS_NVAR(error_messages); + phalcon_read_property_this_quick(&error_messages, this_ptr, SL("_errorMessages"), 1019066246UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(exception); + object_init_ex(exception, phalcon_mvc_model_validationfailed_ce); + phalcon_call_method_p2_key(NULL, exception, "__construct", this_ptr, error_messages, 1107214344UL); + + phalcon_throw_exception(exception TSRMLS_CC); + return; + } + + RETURN_MM_FALSE; } - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + if (zend_is_true(exists)) { + PHALCON_INIT_VAR(success); + phalcon_call_method_p3_key(success, this_ptr, "_dolowupdate", meta_data, write_connection, table, 393175884UL); + } else { + PHALCON_INIT_NVAR(success); + phalcon_call_method_p4_key(success, this_ptr, "_dolowinsert", meta_data, write_connection, table, identity_field, 2015089534UL); } - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, setViewsDir){ - - zval *views_dir; - - phalcon_fetch_params(0, 1, 0, &views_dir); + if (zend_is_true(success)) { + phalcon_update_property_long(this_ptr, SL("_dirtyState"), 0 TSRMLS_CC); + } - phalcon_update_property_this_quick(this_ptr, SL("_viewsDir"), views_dir, 3398309201UL TSRMLS_CC); + if (PHALCON_GLOBAL(orm).events) { + PHALCON_INIT_VAR(new_success); + phalcon_call_method_p2_key(new_success, this_ptr, "_postsave", success, exists, 3354288601UL); + } else { + PHALCON_CPY_WRT(new_success, success); + } -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, getViewsDir){ - - - RETURN_MEMBER_QUICK(this_ptr, "_viewsDir", 3398309201UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, registerEngines){ - - zval *engines; - - phalcon_fetch_params(0, 1, 0, &engines); + if (Z_TYPE_P(related) == IS_ARRAY) { - if (Z_TYPE_P(engines) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Engines to register must be an array"); - return; + if (PHALCON_IS_FALSE(new_success)) { + PHALCON_INIT_NVAR(nesting); + ZVAL_BOOL(nesting, 0); + phalcon_call_method_p1_key(NULL, write_connection, "rollback", nesting, 3199546639UL); + RETURN_MM_FALSE; + } + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, this_ptr, "_postsaverelatedrecords", write_connection, related, 2967472140UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } } - phalcon_update_property_this_quick(this_ptr, SL("_registeredEngines"), engines, 3326968731UL TSRMLS_CC); + RETURN_CCTOR(new_success); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, _loadTemplateEngines){ +static PHP_METHOD(Phalcon_Mvc_Model, create){ - zval *engines = NULL, *dependency_injector, *registered_engines; - zval *php_engine, *arguments, *engine_service = NULL; - zval *extension = NULL, *engine_object = NULL, *exception_message = NULL; + zval *data = NULL, *white_list = NULL, *meta_data, *column_map = NULL; + zval *attributes, *attribute = NULL, *attribute_field = NULL; + zval *exception_message = NULL, *value = NULL, *possible_setter = NULL; + zval *read_connection, *exists, *field, *type, *message; + zval *model_message, *messages; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(engines); - phalcon_read_property_this_quick(&engines, this_ptr, SL("_engines"), 1840711053UL, PH_NOISY_CC); - - if (PHALCON_IS_FALSE(engines)) { + phalcon_fetch_params(1, 0, 2, &data, &white_list); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (!data) { + PHALCON_INIT_VAR(data); + } - PHALCON_INIT_NVAR(engines); - array_init(engines); + if (!white_list) { + PHALCON_INIT_VAR(white_list); + } - PHALCON_OBS_VAR(registered_engines); - phalcon_read_property_this_quick(®istered_engines, this_ptr, SL("_registeredEngines"), 3326968731UL, PH_NOISY_CC); - if (Z_TYPE_P(registered_engines) != IS_ARRAY) { - PHALCON_INIT_VAR(php_engine); - object_init_ex(php_engine, phalcon_mvc_view_engine_php_ce); - phalcon_call_method_p2_key(NULL, php_engine, "__construct", this_ptr, dependency_injector, 1107214344UL); + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - phalcon_array_update_string(&engines, SL(".phtml"), &php_engine, PH_COPY | PH_SEPARATE); + if (Z_TYPE_P(data) != IS_NULL) { + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data passed to create() must be an array"); + return; + } + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); } else { - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "A dependency injector container is required to obtain the application services"); - return; - } - - PHALCON_INIT_VAR(arguments); - array_init_size(arguments, 2); - phalcon_array_append(&arguments, this_ptr, PH_SEPARATE); - phalcon_array_append(&arguments, dependency_injector, PH_SEPARATE); + PHALCON_INIT_NVAR(column_map); + } - phalcon_is_iterable(registered_engines, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - PHALCON_GET_HKEY(extension, ah0, hp0); - PHALCON_GET_HVALUE(engine_service); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (Z_TYPE_P(engine_service) == IS_OBJECT) { + PHALCON_GET_HVALUE(attribute); - if (phalcon_is_instance_of(engine_service, SL("Closure") TSRMLS_CC)) { - PHALCON_INIT_NVAR(engine_object); - PHALCON_CALL_USER_FUNC_ARRAY(engine_object, engine_service, arguments); - } else { - PHALCON_CPY_WRT(engine_object, engine_service); - } + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, attribute)) { + PHALCON_OBS_NVAR(attribute_field); + phalcon_array_fetch(&attribute_field, column_map, attribute, PH_NOISY); } else { - if (Z_TYPE_P(engine_service) == IS_STRING) { - PHALCON_INIT_NVAR(engine_object); - phalcon_call_method_p2_key(engine_object, dependency_injector, "getshared", engine_service, arguments, 1727570332UL); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Invalid template engine registration for extension: ", extension); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", attribute, "' isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } else { + PHALCON_CPY_WRT(attribute_field, attribute); + } + + if (phalcon_array_isset(data, attribute_field)) { + + if (Z_TYPE_P(white_list) == IS_ARRAY) { + if (!phalcon_fast_in_array(attribute_field, white_list TSRMLS_CC)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; } } - phalcon_array_update_zval(&engines, extension, &engine_object, PH_COPY | PH_SEPARATE); - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, data, attribute_field, PH_NOISY); + + PHALCON_INIT_NVAR(possible_setter); + PHALCON_CONCAT_SV(possible_setter, "set", attribute_field); + if (phalcon_method_exists(this_ptr, possible_setter TSRMLS_CC) == SUCCESS) { + phalcon_call_method_zval_p1_noret(this_ptr, possible_setter, value); + } else { + phalcon_update_property_zval_zval(this_ptr, attribute_field, value TSRMLS_CC); + } } + zend_hash_move_forward_ex(ah0, &hp0); } - phalcon_update_property_this_quick(this_ptr, SL("_engines"), engines, 1840711053UL TSRMLS_CC); - } else { - PHALCON_OBS_NVAR(engines); - phalcon_read_property_this_quick(&engines, this_ptr, SL("_engines"), 1840711053UL, PH_NOISY_CC); } - RETURN_CCTOR(engines); + PHALCON_INIT_VAR(read_connection); + phalcon_call_method_key(read_connection, this_ptr, "getreadconnection", 488334257UL); + + PHALCON_INIT_VAR(exists); + phalcon_call_method_p2_key(exists, this_ptr, "_exists", meta_data, read_connection, 2792580580UL); + + if (zend_is_true(exists)) { + PHALCON_INIT_VAR(field); + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "InvalidCreateAttempt", 1); + + PHALCON_INIT_VAR(message); + ZVAL_STRING(message, "Record cannot be created because it already exists", 1); + + PHALCON_INIT_VAR(model_message); + object_init_ex(model_message, phalcon_mvc_model_message_ce); + phalcon_call_method_p3_key(NULL, model_message, "__construct", message, field, type, 1107214344UL); + + PHALCON_INIT_VAR(messages); + array_init_size(messages, 1); + phalcon_array_append(&messages, model_message, PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), messages, 1019066246UL TSRMLS_CC); + RETURN_MM_FALSE; + } + + phalcon_call_method_key(return_value, this_ptr, "save", 274150868UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, _internalRender){ +static PHP_METHOD(Phalcon_Mvc_Model, update){ - zval *path, *params, *events_manager, *event_name = NULL; - zval *status = NULL, *not_exists = NULL, *must_clean, *views_dir; - zval *views_dir_path, *engines, *engine = NULL, *extension = NULL; - zval *view_engine_path = NULL, *exception_message; + zval *data = NULL, *white_list = NULL, *meta_data = NULL, *column_map = NULL; + zval *attributes, *attribute = NULL, *attribute_field = NULL; + zval *exception_message = NULL, *value = NULL, *possible_setter = NULL; + zval *dirty_state, *read_connection, *exists; + zval *field, *type, *message, *model_message, *messages; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &path, ¶ms); - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_activeRenderPath"), path, 1528023309UL TSRMLS_CC); - } - - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "view:beforeRender", 1); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_NULL(); - } + phalcon_fetch_params(1, 0, 2, &data, &white_list); + + if (!data) { + PHALCON_INIT_VAR(data); } - PHALCON_INIT_VAR(not_exists); - ZVAL_BOOL(not_exists, 1); + if (!white_list) { + PHALCON_INIT_VAR(white_list); + } - PHALCON_INIT_VAR(must_clean); - ZVAL_BOOL(must_clean, 1); + PHALCON_INIT_VAR(meta_data); - PHALCON_OBS_VAR(views_dir); - phalcon_read_property_this_quick(&views_dir, this_ptr, SL("_viewsDir"), 3398309201UL, PH_NOISY_CC); + if (Z_TYPE_P(data) != IS_NULL) { + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data passed to update() must be an array"); + return; + } - PHALCON_INIT_VAR(views_dir_path); - PHALCON_CONCAT_VV(views_dir_path, views_dir, path); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); + } else { + PHALCON_INIT_NVAR(column_map); + } - PHALCON_INIT_VAR(engines); - phalcon_call_method_key(engines, this_ptr, "_loadtemplateengines", 4149337481UL); + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); - phalcon_is_iterable(engines, &ah0, &hp0, 0, 0); + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_GET_HKEY(extension, ah0, hp0); - PHALCON_GET_HVALUE(engine); + PHALCON_GET_HVALUE(attribute); - PHALCON_INIT_NVAR(view_engine_path); - PHALCON_CONCAT_VV(view_engine_path, views_dir_path, extension); + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, attribute)) { + PHALCON_OBS_NVAR(attribute_field); + phalcon_array_fetch(&attribute_field, column_map, attribute, PH_NOISY); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", attribute, "' isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } else { + PHALCON_CPY_WRT(attribute_field, attribute); + } - if (phalcon_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { + if (phalcon_array_isset(data, attribute_field)) { - if (Z_TYPE_P(events_manager) == IS_OBJECT) { + if (Z_TYPE_P(white_list) == IS_ARRAY) { + if (!phalcon_fast_in_array(attribute_field, white_list TSRMLS_CC)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "view:beforeRenderView", 1); + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, data, attribute_field, PH_NOISY); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, view_engine_path, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; + PHALCON_INIT_NVAR(possible_setter); + PHALCON_CONCAT_SV(possible_setter, "set", attribute_field); + if (phalcon_method_exists(this_ptr, possible_setter TSRMLS_CC) == SUCCESS) { + phalcon_call_method_zval_p1_noret(this_ptr, possible_setter, value); + } else { + phalcon_update_property_zval_zval(this_ptr, attribute_field, value TSRMLS_CC); } } - phalcon_call_method_p3_key(NULL, engine, "render", view_engine_path, params, must_clean, 1053215877UL); - - PHALCON_INIT_NVAR(not_exists); - ZVAL_BOOL(not_exists, 0); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "view:afterRenderView", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); - } - break; + zend_hash_move_forward_ex(ah0, &hp0); } - zend_hash_move_forward_ex(ah0, &hp0); } - if (PHALCON_IS_TRUE(not_exists)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "View '", views_dir_path, "' was not found in the views directory"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; - } + PHALCON_OBS_VAR(dirty_state); + phalcon_read_property_this_quick(&dirty_state, this_ptr, SL("_dirtyState"), 1560981745UL, PH_NOISY_CC); + if (zend_is_true(dirty_state)) { + if (Z_TYPE_P(meta_data) == IS_NULL) { + PHALCON_INIT_NVAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); + } - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "view:afterRender", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + PHALCON_INIT_VAR(read_connection); + phalcon_call_method_key(read_connection, this_ptr, "getreadconnection", 488334257UL); + + PHALCON_INIT_VAR(exists); + phalcon_call_method_p2_key(exists, this_ptr, "_exists", meta_data, read_connection, 2792580580UL); + if (!zend_is_true(exists)) { + PHALCON_INIT_VAR(field); + + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "InvalidUpdateAttempt", 1); + + PHALCON_INIT_VAR(message); + ZVAL_STRING(message, "Record cannot be updated because it does not exist", 1); + + PHALCON_INIT_VAR(model_message); + object_init_ex(model_message, phalcon_mvc_model_message_ce); + phalcon_call_method_p3_key(NULL, model_message, "__construct", message, field, type, 1107214344UL); + + PHALCON_INIT_VAR(messages); + array_init_size(messages, 1); + phalcon_array_append(&messages, model_message, PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), messages, 1019066246UL TSRMLS_CC); + RETURN_MM_FALSE; + } } - PHALCON_MM_RESTORE(); + phalcon_call_method_key(return_value, this_ptr, "save", 274150868UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, render){ +static PHP_METHOD(Phalcon_Mvc_Model, delete){ - zval *path, *params = NULL, *cache, *is_started = NULL, *key = NULL, *lifetime = NULL; - zval *cache_options, *content = NULL, *view_params; - zval *merged_params = NULL, *is_fresh; + zval *meta_data, *write_connection, *empty_array; + zval *check_foreign_keys = NULL, *values, *bind_types; + zval *conditions, *primary_keys, *bind_data_types; + zval *column_map = NULL, *primary_key = NULL, *exception_message = NULL; + zval *attribute_field = NULL, *value = NULL, *escaped_field = NULL; + zval *primary_condition = NULL, *bind_type = NULL, *delete_conditions; + zval *event_name = NULL, *status, *skipped, *schema, *source; + zval *table = NULL, *success; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &path, ¶ms); - - if (!params) { - PHALCON_INIT_VAR(params); - } - - PHALCON_INIT_VAR(cache); - phalcon_call_method_key(cache, this_ptr, "getcache", 3582760537UL); - if (Z_TYPE_P(cache) == IS_OBJECT) { - - PHALCON_INIT_VAR(is_started); - phalcon_call_method_key(is_started, cache, "isstarted", 527759032UL); - if (PHALCON_IS_FALSE(is_started)) { - - PHALCON_INIT_VAR(key); + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - PHALCON_INIT_VAR(lifetime); + PHALCON_INIT_VAR(write_connection); + phalcon_call_method_key(write_connection, this_ptr, "getwriteconnection", 4280185952UL); - PHALCON_OBS_VAR(cache_options); - phalcon_read_property_this_quick(&cache_options, this_ptr, SL("_cacheOptions"), 528255652UL, PH_NOISY_CC); + phalcon_update_property_long(this_ptr, SL("_operationMade"), 3 TSRMLS_CC); - if (Z_TYPE_P(cache_options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(cache_options, SS("key"), 2090432846UL)) { - PHALCON_OBS_NVAR(key); - phalcon_array_fetch_quick_string(&key, cache_options, SS("key"), 2090432846UL, PH_NOISY); - } - if (phalcon_array_isset_quick_string(cache_options, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_NVAR(lifetime); - phalcon_array_fetch_quick_string(&lifetime, cache_options, SS("lifetime"), 2639810228UL, PH_NOISY); - } - } + PHALCON_INIT_VAR(empty_array); + array_init(empty_array); + phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), empty_array, 1019066246UL TSRMLS_CC); - if (Z_TYPE_P(key) == IS_NULL) { - PHALCON_INIT_NVAR(key); - phalcon_md5(key, path); - } + if (PHALCON_GLOBAL(orm).virtual_foreign_keys) { - PHALCON_INIT_VAR(content); - phalcon_call_method_p2_key(content, cache, "start", key, lifetime, 478839859UL); - if (Z_TYPE_P(content) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_content"), content, 4081318271UL TSRMLS_CC); - RETURN_CCTOR(content); - } + PHALCON_INIT_VAR(check_foreign_keys); + phalcon_call_method_key(check_foreign_keys, this_ptr, "_checkforeignkeysreverserestrict", 2200393844UL); + if (PHALCON_IS_FALSE(check_foreign_keys)) { + RETURN_MM_FALSE; } } - phalcon_create_symbol_table(TSRMLS_C); + PHALCON_INIT_VAR(values); + array_init(values); - phalcon_ob_start(TSRMLS_C); + PHALCON_INIT_VAR(bind_types); + array_init(bind_types); - PHALCON_OBS_VAR(view_params); - phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + PHALCON_INIT_VAR(conditions); + array_init(conditions); - if (Z_TYPE_P(params) == IS_ARRAY) { - if (Z_TYPE_P(view_params) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, &view_params, ¶ms TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params, params); - } + PHALCON_INIT_VAR(primary_keys); + phalcon_call_method_p1_key(primary_keys, meta_data, "getprimarykeyattributes", this_ptr, 692945721UL); + + PHALCON_INIT_VAR(bind_data_types); + phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); + if (PHALCON_GLOBAL(orm).column_renaming) { + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); } else { - PHALCON_CPY_WRT(merged_params, view_params); + PHALCON_INIT_NVAR(column_map); } - phalcon_call_method_p2_key(NULL, this_ptr, "_internalrender", path, merged_params, 608460065UL); + if (!phalcon_fast_count_ev(primary_keys TSRMLS_CC)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A primary key must be defined in the model in order to perform the operation"); + return; + } - if (Z_TYPE_P(cache) == IS_OBJECT) { + phalcon_is_iterable(primary_keys, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(is_started); - phalcon_call_method_key(is_started, cache, "isstarted", 527759032UL); - if (PHALCON_IS_TRUE(is_started)) { + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(is_fresh); - phalcon_call_method_key(is_fresh, cache, "isfresh", 3981662073UL); - if (PHALCON_IS_TRUE(is_fresh)) { - phalcon_call_method_key(NULL, cache, "save", 274150868UL); + PHALCON_GET_HVALUE(primary_key); + + if (!phalcon_array_isset(bind_data_types, primary_key)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", primary_key, "' have not defined a bind data type"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (phalcon_array_isset(column_map, primary_key)) { + PHALCON_OBS_NVAR(attribute_field); + phalcon_array_fetch(&attribute_field, column_map, primary_key, PH_NOISY); } else { - phalcon_call_method_key(NULL, cache, "stop", 274826411UL); + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column '", primary_key, "' isn't part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } } else { - phalcon_call_method_key(NULL, cache, "stop", 274826411UL); + PHALCON_CPY_WRT(attribute_field, primary_key); } - } - phalcon_ob_end_clean(TSRMLS_C); + if (!phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Cannot delete the record because the primary key attribute: '", attribute_field, "' wasn't set"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } - PHALCON_OBS_NVAR(content); - phalcon_read_property_this_quick(&content, this_ptr, SL("_content"), 4081318271UL, PH_NOISY_CC); + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); + phalcon_array_append(&values, value, PH_SEPARATE); - RETURN_CCTOR(content); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, partial){ - - zval *partial_path, *params = NULL, *view_params, *merged_params = NULL; - zval *content; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &partial_path, ¶ms); + PHALCON_INIT_NVAR(escaped_field); + phalcon_call_method_p1_key(escaped_field, write_connection, "escapeidentifier", primary_key, 585773337UL); - if (!params) { - PHALCON_INIT_VAR(params); - } + PHALCON_INIT_NVAR(primary_condition); + PHALCON_CONCAT_VS(primary_condition, escaped_field, " = ?"); + phalcon_array_append(&conditions, primary_condition, PH_SEPARATE); - phalcon_ob_start(TSRMLS_C); + PHALCON_OBS_NVAR(bind_type); + phalcon_array_fetch(&bind_type, bind_data_types, primary_key, PH_NOISY); + phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); - if (Z_TYPE_P(params) == IS_ARRAY) { + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_OBS_VAR(view_params); - phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + PHALCON_INIT_VAR(delete_conditions); + phalcon_fast_join_str(delete_conditions, SL(" AND "), conditions TSRMLS_CC); + if (PHALCON_GLOBAL(orm).events) { + phalcon_update_property_bool(this_ptr, SL("_skipped"), 0 TSRMLS_CC); - if (Z_TYPE_P(view_params) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, &view_params, ¶ms TSRMLS_CC); + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "beforeDelete", 1); + + PHALCON_INIT_VAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; } else { - PHALCON_CPY_WRT(merged_params, params); + PHALCON_OBS_VAR(skipped); + phalcon_read_property_this_quick(&skipped, this_ptr, SL("_skipped"), 2005665588UL, PH_NOISY_CC); + if (PHALCON_IS_TRUE(skipped)) { + RETURN_MM_TRUE; + } } + } - phalcon_create_symbol_table(TSRMLS_C); + PHALCON_INIT_VAR(schema); + phalcon_call_method_key(schema, this_ptr, "getschema", 1539736246UL); + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); + if (zend_is_true(schema)) { + PHALCON_INIT_VAR(table); + array_init_size(table, 2); + phalcon_array_append(&table, schema, PH_SEPARATE); + phalcon_array_append(&table, source, PH_SEPARATE); } else { - PHALCON_CPY_WRT(merged_params, params); + PHALCON_CPY_WRT(table, source); } - phalcon_call_method_p2_key(NULL, this_ptr, "_internalrender", partial_path, merged_params, 608460065UL); - - if (Z_TYPE_P(params) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), view_params, 1685283331UL TSRMLS_CC); - } + PHALCON_INIT_VAR(success); + phalcon_call_method_p4_key(success, write_connection, "delete", table, delete_conditions, values, bind_types, 150213496UL); - phalcon_ob_end_clean(TSRMLS_C); + if (PHALCON_GLOBAL(orm).virtual_foreign_keys) { - PHALCON_OBS_VAR(content); - phalcon_read_property_this_quick(&content, this_ptr, SL("_content"), 4081318271UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(check_foreign_keys); + phalcon_call_method_key(check_foreign_keys, this_ptr, "_checkforeignkeysreversecascade", 2711790920UL); + if (PHALCON_IS_FALSE(check_foreign_keys)) { + RETURN_MM_FALSE; + } + } - zend_print_zval(content, 0); + if (PHALCON_GLOBAL(orm).events) { + if (zend_is_true(success)) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "afterDelete", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + } + } - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, setCacheOptions){ - - zval *options; - - phalcon_fetch_params(0, 1, 0, &options); + phalcon_update_property_long(this_ptr, SL("_dirtyState"), 2 TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_cacheOptions"), options, 528255652UL TSRMLS_CC); - RETURN_THISW(); + RETURN_CCTOR(success); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, getCacheOptions){ +static PHP_METHOD(Phalcon_Mvc_Model, getOperationMade){ - RETURN_MEMBER_QUICK(this_ptr, "_cacheOptions", 528255652UL); + RETURN_MEMBER_QUICK(this_ptr, "_operationMade", 3968152972UL); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, _createCache){ +static PHP_METHOD(Phalcon_Mvc_Model, refresh){ - zval *dependency_injector, *cache_service = NULL; - zval *cache_options, *view_cache; + zval *dirty_state, *meta_data, *read_connection; + zval *schema, *source, *table = NULL, *unique_key = NULL, *exists; + zval *unique_params, *unique_types, *attributes; + zval *fields, *attribute = NULL, *field_item = NULL, *escaped_table; + zval *select, *dialect, *sql, *fetch_type, *row, *column_map; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "A dependency injector container is required to obtain the view cache services"); + PHALCON_OBS_VAR(dirty_state); + phalcon_read_property_this_quick(&dirty_state, this_ptr, SL("_dirtyState"), 1560981745UL, PH_NOISY_CC); + if (!PHALCON_IS_LONG(dirty_state, 0)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The record cannot be refreshed because it does not exist or is deleted"); return; } - PHALCON_INIT_VAR(cache_service); - ZVAL_STRING(cache_service, "viewCache", 1); + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - PHALCON_OBS_VAR(cache_options); - phalcon_read_property_this_quick(&cache_options, this_ptr, SL("_cacheOptions"), 528255652UL, PH_NOISY_CC); - if (Z_TYPE_P(cache_options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(cache_options, SS("service"), 243174486UL)) { - PHALCON_OBS_NVAR(cache_service); - phalcon_array_fetch_quick_string(&cache_service, cache_options, SS("service"), 243174486UL, PH_NOISY); + PHALCON_INIT_VAR(read_connection); + phalcon_call_method_key(read_connection, this_ptr, "getreadconnection", 488334257UL); + + PHALCON_INIT_VAR(schema); + phalcon_call_method_key(schema, this_ptr, "getschema", 1539736246UL); + + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); + if (zend_is_true(schema)) { + PHALCON_INIT_VAR(table); + array_init_size(table, 2); + phalcon_array_append(&table, schema, PH_SEPARATE); + phalcon_array_append(&table, source, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(table, source); + } + + PHALCON_OBS_VAR(unique_key); + phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); + if (!zend_is_true(unique_key)) { + + PHALCON_INIT_VAR(exists); + phalcon_call_method_p3_key(exists, this_ptr, "_exists", meta_data, read_connection, table, 2792580580UL); + if (!zend_is_true(exists)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The record cannot be refreshed because it does not exist or is deleted"); + return; } + + PHALCON_OBS_NVAR(unique_key); + phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); } - PHALCON_INIT_VAR(view_cache); - phalcon_call_method_p1_key(view_cache, dependency_injector, "getshared", cache_service, 1727570332UL); - if (Z_TYPE_P(view_cache) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The injected caching service is invalid"); + PHALCON_OBS_VAR(unique_params); + phalcon_read_property_this_quick(&unique_params, this_ptr, SL("_uniqueParams"), 1065564063UL, PH_NOISY_CC); + if (Z_TYPE_P(unique_params) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The record cannot be refreshed because it does not exist or is deleted"); return; } - RETURN_CCTOR(view_cache); + PHALCON_OBS_VAR(unique_types); + phalcon_read_property_this_quick(&unique_types, this_ptr, SL("_uniqueTypes"), 3340838640UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); + + PHALCON_INIT_VAR(fields); + array_init(fields); + + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(attribute); + + PHALCON_INIT_NVAR(field_item); + array_init_size(field_item, 1); + phalcon_array_append(&field_item, attribute, PH_SEPARATE); + phalcon_array_append(&fields, field_item, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(escaped_table); + phalcon_call_method_p1_key(escaped_table, read_connection, "escapeidentifier", table, 585773337UL); + + PHALCON_INIT_VAR(select); + array_init(select); + phalcon_array_update_quick_string(&select, SS("columns"), 1041822630UL, &fields, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&select, SS("tables"), 3465666720UL, &escaped_table, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&select, SS("where"), 621293632UL, &unique_key, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(dialect); + phalcon_call_method_key(dialect, read_connection, "getdialect", 3133083739UL); + + PHALCON_INIT_VAR(sql); + phalcon_call_method_p1_key(sql, dialect, "select", select, 2342345829UL); + + PHALCON_INIT_VAR(fetch_type); + ZVAL_LONG(fetch_type, 1); + + PHALCON_INIT_VAR(row); + phalcon_call_method_p4_key(row, read_connection, "fetchone", sql, fetch_type, unique_params, unique_types, 1637187313UL); + + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); + + if (Z_TYPE_P(row) == IS_ARRAY) { + phalcon_call_method_p2_key(NULL, this_ptr, "assign", row, column_map, 1127103722UL); + } + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, getCache){ - - zval *cache = NULL; +static PHP_METHOD(Phalcon_Mvc_Model, skipOperation){ - PHALCON_MM_GROW(); + zval *skip; - PHALCON_OBS_VAR(cache); - phalcon_read_property_this_quick(&cache, this_ptr, SL("_cache"), 2191407384UL, PH_NOISY_CC); - if (zend_is_true(cache)) { - if (Z_TYPE_P(cache) != IS_OBJECT) { - PHALCON_INIT_NVAR(cache); - phalcon_call_method_key(cache, this_ptr, "_createcache", 1216889100UL); - phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); - } - } + phalcon_fetch_params(0, 1, 0, &skip); + + phalcon_update_property_this_quick(this_ptr, SL("_skipped"), skip, 2005665588UL TSRMLS_CC); - RETURN_CCTOR(cache); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, cache){ +static PHP_METHOD(Phalcon_Mvc_Model, readAttribute){ - zval *options = NULL; + zval *attribute, *attribute_value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - ZVAL_BOOL(options, 1); - } + phalcon_fetch_params(1, 1, 0, &attribute); - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_update_property_bool(this_ptr, SL("_cache"), 1 TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_cacheOptions"), options, 528255652UL TSRMLS_CC); - } else { - if (zend_is_true(options)) { - phalcon_update_property_bool(this_ptr, SL("_cache"), 1 TSRMLS_CC); - } else { - phalcon_update_property_bool(this_ptr, SL("_cache"), 0 TSRMLS_CC); - } + 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_CC); + RETURN_CCTOR(attribute_value); } - - RETURN_THIS(); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, setParamToView){ +static PHP_METHOD(Phalcon_Mvc_Model, writeAttribute){ - zval *key, *value; + zval *attribute, *value; - phalcon_fetch_params(0, 2, 0, &key, &value); + phalcon_fetch_params(0, 2, 0, &attribute, &value); + + phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); - RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, setVars){ +static PHP_METHOD(Phalcon_Mvc_Model, skipAttributes){ - zval *params, *merge = NULL, *view_params, *merged_params = NULL; + zval *attributes, *null_value, *keys_attributes; + zval *attribute = NULL, *meta_data; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, ¶ms, &merge); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 1); - } + phalcon_fetch_params(1, 1, 0, &attributes); - if (Z_TYPE_P(params) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The render parameters must be an array"); + if (Z_TYPE_P(attributes) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Attributes must be an array"); return; } - if (zend_is_true(merge)) { - PHALCON_OBS_VAR(view_params); - phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); - if (Z_TYPE_P(view_params) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, &view_params, ¶ms TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_params, params); - } + PHALCON_INIT_VAR(null_value); - phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), merged_params, 1685283331UL TSRMLS_CC); - } else { - phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), params, 1685283331UL TSRMLS_CC); + PHALCON_INIT_VAR(keys_attributes); + array_init(keys_attributes); + + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(attribute); + + phalcon_array_update_zval(&keys_attributes, attribute, &null_value, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, setVar){ - - zval *key, *value; - - phalcon_fetch_params(0, 2, 0, &key, &value); + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); + phalcon_call_method_p2_key(NULL, meta_data, "setautomaticcreateattributes", this_ptr, keys_attributes, 316109587UL); + phalcon_call_method_p2_key(NULL, meta_data, "setautomaticupdateattributes", this_ptr, keys_attributes, 2859965858UL); - phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); - RETURN_THISW(); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, getVar){ +static PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnCreate){ - zval *key, *params, *value; + zval *attributes, *null_value, *keys_attributes; + zval *attribute = NULL, *meta_data; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &key); + phalcon_fetch_params(1, 1, 0, &attributes); - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); - if (phalcon_array_isset(params, key)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, params, key, PH_NOISY); - RETURN_CCTOR(value); + if (Z_TYPE_P(attributes) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Attributes must be an array"); + return; } - RETURN_MM_NULL(); + PHALCON_INIT_VAR(null_value); + + PHALCON_INIT_VAR(keys_attributes); + array_init(keys_attributes); + + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(attribute); + + phalcon_array_update_zval(&keys_attributes, attribute, &null_value, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); + phalcon_call_method_p2_key(NULL, meta_data, "setautomaticcreateattributes", this_ptr, keys_attributes, 316109587UL); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, getParamsToView){ - - - RETURN_MEMBER_QUICK(this_ptr, "_viewParams", 1685283331UL); -} +static PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnUpdate){ -static PHP_METHOD(Phalcon_Mvc_View_Simple, setContent){ + zval *attributes, *null_value, *keys_attributes; + zval *attribute = NULL, *meta_data; + HashTable *ah0; + HashPosition hp0; + zval **hd; - zval *content; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &content); + phalcon_fetch_params(1, 1, 0, &attributes); - if (Z_TYPE_P(content) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Content must be a string"); + if (Z_TYPE_P(attributes) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Attributes must be an array"); return; } - phalcon_update_property_this_quick(this_ptr, SL("_content"), content, 4081318271UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, getContent){ - - - RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); + PHALCON_INIT_VAR(null_value); + + PHALCON_INIT_VAR(keys_attributes); + array_init(keys_attributes); + + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(attribute); + + phalcon_array_update_zval(&keys_attributes, attribute, &null_value, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); + phalcon_call_method_p2_key(NULL, meta_data, "setautomaticupdateattributes", this_ptr, keys_attributes, 2859965858UL); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, getActiveRenderPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_activeRenderPath", 1528023309UL); -} +static PHP_METHOD(Phalcon_Mvc_Model, hasOne){ -static PHP_METHOD(Phalcon_Mvc_View_Simple, __set){ + zval *fields, *reference_model, *referenced_fields; + zval *options = NULL, *manager; - zval *key, *value; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 2, 0, &key, &value); + phalcon_fetch_params(1, 3, 1, &fields, &reference_model, &referenced_fields, &options); - phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); + if (!options) { + PHALCON_INIT_VAR(options); + } + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p5(return_value, manager, "addhasone", this_ptr, fields, reference_model, referenced_fields, options); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View_Simple, __get){ +static PHP_METHOD(Phalcon_Mvc_Model, belongsTo){ - zval *key, *params, *value; + zval *fields, *reference_model, *referenced_fields; + zval *options = NULL, *manager; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &key); + phalcon_fetch_params(1, 3, 1, &fields, &reference_model, &referenced_fields, &options); - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); - if (phalcon_array_isset(params, key)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, params, key, PH_NOISY); - RETURN_CCTOR(value); + if (!options) { + PHALCON_INIT_VAR(options); } - RETURN_MM_NULL(); + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p5(return_value, manager, "addbelongsto", this_ptr, fields, reference_model, referenced_fields, options); + RETURN_MM(); } +static PHP_METHOD(Phalcon_Mvc_Model, hasMany){ + zval *fields, *reference_model, *referenced_fields; + zval *options = NULL, *manager; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 3, 1, &fields, &reference_model, &referenced_fields, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p5(return_value, manager, "addhasmany", this_ptr, fields, reference_model, referenced_fields, options); + RETURN_MM(); +} -#ifdef HAVE_CONFIG_H -#endif +static PHP_METHOD(Phalcon_Mvc_Model, hasManyToMany){ + zval *fields, *intermediate_model, *intermediate_fields; + zval *intermediate_referenced_fields, *reference_model; + zval *referenced_fields, *options = NULL, *manager; + zval *p0[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 6, 1, &fields, &intermediate_model, &intermediate_fields, &intermediate_referenced_fields, &reference_model, &referenced_fields, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + + p0[0] = this_ptr; + p0[1] = fields; + p0[2] = intermediate_model; + p0[3] = intermediate_fields; + p0[4] = intermediate_referenced_fields; + p0[5] = reference_model; + p0[6] = referenced_fields; + p0[7] = options; + phalcon_call_method_pn(return_value, manager, "addhasmanytomany", 8, p0); + RETURN_MM(); +} +static PHP_METHOD(Phalcon_Mvc_Model, addBehavior){ + zval *behavior, *manager; + PHALCON_MM_GROW(); -PHALCON_INIT_CLASS(Phalcon_Mvc_Url){ + phalcon_fetch_params(1, 1, 0, &behavior); + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, manager, "addbehavior", this_ptr, behavior, 2404171070UL); + + PHALCON_MM_RESTORE(); +} - PHALCON_REGISTER_CLASS(Phalcon\\Mvc, Url, mvc_url, phalcon_mvc_url_method_entry, 0); +static PHP_METHOD(Phalcon_Mvc_Model, keepSnapshots){ - zend_declare_property_null(phalcon_mvc_url_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_url_ce, SL("_baseUri"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_url_ce, SL("_staticBaseUri"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_url_ce, SL("_basePath"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_url_ce, SL("_router"), ZEND_ACC_PROTECTED TSRMLS_CC); + zval *keep_snapshot, *manager; - zend_class_implements(phalcon_mvc_url_ce TSRMLS_CC, 2, phalcon_mvc_urlinterface_ce, phalcon_di_injectionawareinterface_ce); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 1, 0, &keep_snapshot); + + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, manager, "keepsnapshots", this_ptr, keep_snapshot, 3989700781UL); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Url, setDI){ +static PHP_METHOD(Phalcon_Mvc_Model, setSnapshotData){ - zval *dependency_injector; + zval *data, *column_map = NULL, *snapshot, *value = NULL, *key = NULL, *exception_message = NULL; + zval *attribute = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - phalcon_fetch_params(0, 1, 0, &dependency_injector); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &data, &column_map); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_url_exception_ce, "The dependency injector must be an Object"); + if (!column_map) { + PHALCON_INIT_VAR(column_map); + } + + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The snapshot data must be an array"); return; } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + if (Z_TYPE_P(column_map) == IS_ARRAY) { + + PHALCON_INIT_VAR(snapshot); + array_init(snapshot); + + 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 (Z_TYPE_P(key) != IS_STRING) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + + if (!phalcon_array_isset(column_map, key)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column \"", key, "\" doesn't make part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch(&attribute, column_map, key, PH_NOISY); + phalcon_array_update_zval(&snapshot, attribute, &value, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_update_property_this_quick(this_ptr, SL("_snapshot"), snapshot, 3325604532UL TSRMLS_CC); + RETURN_MM_NULL(); + } + + phalcon_update_property_this_quick(this_ptr, SL("_snapshot"), data, 3325604532UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Url, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -static PHP_METHOD(Phalcon_Mvc_Url, setBaseUri){ +static PHP_METHOD(Phalcon_Mvc_Model, hasSnapshotData){ - zval *base_uri, *static_base_uri; + zval *snapshot; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &base_uri); - - phalcon_update_property_this_quick(this_ptr, SL("_baseUri"), base_uri, 3689183023UL TSRMLS_CC); - - PHALCON_OBS_VAR(static_base_uri); - phalcon_read_property_this_quick(&static_base_uri, this_ptr, SL("_staticBaseUri"), 2610838775UL, PH_NOISY_CC); - if (Z_TYPE_P(static_base_uri) == IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_staticBaseUri"), base_uri, 2610838775UL TSRMLS_CC); + PHALCON_OBS_VAR(snapshot); + phalcon_read_property_this_quick(&snapshot, this_ptr, SL("_snapshot"), 3325604532UL, PH_NOISY_CC); + if (Z_TYPE_P(snapshot) == IS_ARRAY) { + RETURN_MM_TRUE; } - RETURN_THIS(); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Url, setStaticBaseUri){ +static PHP_METHOD(Phalcon_Mvc_Model, getSnapshotData){ - zval *static_base_uri; - phalcon_fetch_params(0, 1, 0, &static_base_uri); - - phalcon_update_property_this_quick(this_ptr, SL("_staticBaseUri"), static_base_uri, 2610838775UL TSRMLS_CC); - RETURN_THISW(); + RETURN_MEMBER_QUICK(this_ptr, "_snapshot", 3325604532UL); } -static PHP_METHOD(Phalcon_Mvc_Url, getBaseUri){ +static PHP_METHOD(Phalcon_Mvc_Model, hasChanged){ - zval *base_uri = NULL, *slash, *_SERVER, *php_self, *uri = NULL; + zval *field_name = NULL, *snapshot, *dirty_state, *meta_data; + zval *column_map, *attributes, *all_attributes = NULL; + zval *exception_message = NULL, *value = NULL, *original_value = NULL; + zval *type = NULL, *name = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(base_uri); - phalcon_read_property_this_quick(&base_uri, this_ptr, SL("_baseUri"), 3689183023UL, PH_NOISY_CC); - if (Z_TYPE_P(base_uri) == IS_NULL) { + phalcon_fetch_params(1, 0, 1, &field_name); - PHALCON_INIT_VAR(slash); - ZVAL_STRING(slash, "/", 1); - phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); - if (phalcon_array_isset_quick_string(_SERVER, SS("PHP_SELF"), 3176521366UL)) { - PHALCON_OBS_VAR(php_self); - phalcon_array_fetch_quick_string(&php_self, _SERVER, SS("PHP_SELF"), 3176521366UL, PH_NOISY); + if (!field_name) { + PHALCON_INIT_VAR(field_name); + } - PHALCON_INIT_VAR(uri); - phalcon_get_uri(uri, php_self); + PHALCON_OBS_VAR(snapshot); + phalcon_read_property_this_quick(&snapshot, this_ptr, SL("_snapshot"), 3325604532UL, PH_NOISY_CC); + if (Z_TYPE_P(snapshot) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The record doesn't have a valid data snapshot"); + return; + } + + if (Z_TYPE_P(field_name) != IS_STRING) { + if (Z_TYPE_P(field_name) != IS_NULL) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The field name must be string"); + return; + } + } + + PHALCON_OBS_VAR(dirty_state); + phalcon_read_property_this_quick(&dirty_state, this_ptr, SL("_dirtyState"), 1560981745UL, PH_NOISY_CC); + + if (!PHALCON_IS_LONG(dirty_state, 0)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Change checking cannot be performed because the object has not been persisted or is deleted"); + return; + } + + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); + + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getreversecolumnmap", this_ptr, 817005101UL); + + if (Z_TYPE_P(column_map) != IS_ARRAY) { + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getdatatypes", this_ptr, 562971380UL); + PHALCON_CPY_WRT(all_attributes, attributes); + } else { + PHALCON_CPY_WRT(all_attributes, column_map); + } + + if (Z_TYPE_P(field_name) == IS_STRING) { + + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (!phalcon_array_isset(column_map, field_name)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "The field '", field_name, "' is not part of the model"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } } else { - PHALCON_INIT_NVAR(uri); + if (!phalcon_array_isset(attributes, field_name)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "The field '", field_name, "' is not part of the model"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } + + if (!phalcon_isset_property_zval(this_ptr, field_name TSRMLS_CC)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "The field '", field_name, "' is not defined on the model"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + if (!phalcon_array_isset(snapshot, field_name)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "The field '", field_name, "' was not found in the snapshot"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_VAR(value); + phalcon_read_property_zval(&value, this_ptr, field_name, PH_NOISY_CC); + + PHALCON_OBS_VAR(original_value); + phalcon_array_fetch(&original_value, snapshot, field_name, PH_NOISY); + + if (PHALCON_IS_EQUAL(value, original_value)) { + RETURN_MM_FALSE; + } else { + RETURN_MM_TRUE; + } + } + + phalcon_is_iterable(all_attributes, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(name, ah0, hp0); + PHALCON_GET_HVALUE(type); + + if (!phalcon_array_isset(snapshot, name)) { + RETURN_MM_TRUE; + } + + if (!phalcon_isset_property_zval(this_ptr, name TSRMLS_CC)) { + RETURN_MM_TRUE; } - if (!zend_is_true(uri)) { - PHALCON_CPY_WRT(base_uri, slash); - } else { - PHALCON_INIT_NVAR(base_uri); - PHALCON_CONCAT_VVV(base_uri, slash, uri, slash); + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, name, PH_NOISY_CC); + + PHALCON_OBS_NVAR(original_value); + phalcon_array_fetch(&original_value, snapshot, name, PH_NOISY); + + if (!PHALCON_IS_EQUAL(value, original_value)) { + RETURN_MM_TRUE; } - phalcon_update_property_this_quick(this_ptr, SL("_baseUri"), base_uri, 3689183023UL TSRMLS_CC); + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CCTOR(base_uri); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Url, getStaticBaseUri){ +static PHP_METHOD(Phalcon_Mvc_Model, getChangedFields){ - zval *static_base_uri; + zval *snapshot, *dirty_state, *meta_data, *column_map; + zval *attributes, *all_attributes = NULL, *changed; + zval *type = NULL, *name = NULL, *value = NULL, *original_value = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(static_base_uri); - phalcon_read_property_this_quick(&static_base_uri, this_ptr, SL("_staticBaseUri"), 2610838775UL, PH_NOISY_CC); - if (Z_TYPE_P(static_base_uri) != IS_NULL) { - RETURN_CCTOR(static_base_uri); + PHALCON_OBS_VAR(snapshot); + phalcon_read_property_this_quick(&snapshot, this_ptr, SL("_snapshot"), 3325604532UL, PH_NOISY_CC); + if (Z_TYPE_P(snapshot) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The record doesn't have a valid data snapshot"); + return; } - phalcon_call_method_key(return_value, this_ptr, "getbaseuri", 2750461136UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Url, setBasePath){ - - zval *base_path; - - phalcon_fetch_params(0, 1, 0, &base_path); - - phalcon_update_property_this_quick(this_ptr, SL("_basePath"), base_path, 1477430348UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Url, getBasePath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_basePath", 1477430348UL); -} - -static PHP_METHOD(Phalcon_Mvc_Url, get){ - - zval *uri = NULL, *base_uri, *router = NULL, *dependency_injector; - zval *service, *route_name, *route, *exception_message; - zval *pattern, *paths, *processed_uri, *args = NULL, *query_string; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &uri, &args); + PHALCON_OBS_VAR(dirty_state); + phalcon_read_property_this_quick(&dirty_state, this_ptr, SL("_dirtyState"), 1560981745UL, PH_NOISY_CC); - if (!uri) { - PHALCON_INIT_VAR(uri); + if (!PHALCON_IS_LONG(dirty_state, 0)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Change checking cannot be performed because the object has not been persisted or is deleted"); + return; } - PHALCON_INIT_VAR(base_uri); - phalcon_call_method_key(base_uri, this_ptr, "getbaseuri", 2750461136UL); - if (Z_TYPE_P(uri) == IS_ARRAY) { - if (!phalcon_array_isset_quick_string(uri, SS("for"), 2090263820UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_url_exception_ce, "It's necessary to define the route name with the parameter \"for\""); - return; - } + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - PHALCON_OBS_VAR(router); - phalcon_read_property_this_quick(&router, this_ptr, SL("_router"), 2063827077UL, PH_NOISY_CC); + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getreversecolumnmap", this_ptr, 817005101UL); - if (Z_TYPE_P(router) != IS_OBJECT) { + if (Z_TYPE_P(column_map) != IS_ARRAY) { + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getdatatypes", this_ptr, 562971380UL); + PHALCON_CPY_WRT(all_attributes, attributes); + } else { + PHALCON_CPY_WRT(all_attributes, column_map); + } - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (!zend_is_true(dependency_injector)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_url_exception_ce, "A dependency injector container is required to obtain the \"url\" service"); - return; - } + PHALCON_INIT_VAR(changed); + array_init(changed); - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "router", 1); + phalcon_is_iterable(all_attributes, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(router); - phalcon_call_method_p1_key(router, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_property_this_quick(this_ptr, SL("_router"), router, 2063827077UL TSRMLS_CC); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_OBS_VAR(route_name); - phalcon_array_fetch_quick_string(&route_name, uri, SS("for"), 2090263820UL, PH_NOISY); + PHALCON_GET_HKEY(name, ah0, hp0); + PHALCON_GET_HVALUE(type); - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "getroutebyname", route_name, 3004506768UL); - if (Z_TYPE_P(route) != IS_OBJECT) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Cannot obtain a route using the name \"", route_name, "\""); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_url_exception_ce, exception_message); - return; + if (!phalcon_array_isset(snapshot, name)) { + phalcon_array_append(&changed, name, PH_SEPARATE); + zend_hash_move_forward_ex(ah0, &hp0); + continue; } - PHALCON_INIT_VAR(pattern); - phalcon_call_method_key(pattern, route, "getpattern", 2464558051UL); + if (!phalcon_isset_property_zval(this_ptr, name TSRMLS_CC)) { + phalcon_array_append(&changed, name, PH_SEPARATE); + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } - PHALCON_INIT_VAR(paths); - phalcon_call_method_key(paths, route, "getreversedpaths", 2949022469UL); + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, name, PH_NOISY_CC); - PHALCON_INIT_VAR(processed_uri); - phalcon_replace_paths(processed_uri, pattern, paths, uri TSRMLS_CC); - PHALCON_CONCAT_VV(return_value, base_uri, processed_uri); - } - else { - PHALCON_CONCAT_VV(return_value, base_uri, uri); - } + PHALCON_OBS_NVAR(original_value); + phalcon_array_fetch(&original_value, snapshot, name, PH_NOISY); - if (args) { - PHALCON_INIT_VAR(query_string); - phalcon_http_build_query(query_string, args, "&" TSRMLS_CC); - if (Z_TYPE_P(query_string) == IS_STRING && Z_STRLEN_P(query_string)) { - if (phalcon_memnstr_str(return_value, "?", 1)) { - PHALCON_SCONCAT_SV(return_value, "&", query_string); - } - else { - PHALCON_SCONCAT_SV(return_value, "?", query_string); - } + if (!PHALCON_IS_EQUAL(value, original_value)) { + phalcon_array_append(&changed, name, PH_SEPARATE); + zend_hash_move_forward_ex(ah0, &hp0); + continue; } + + zend_hash_move_forward_ex(ah0, &hp0); } - - RETURN_MM(); + + RETURN_CTOR(changed); } -static PHP_METHOD(Phalcon_Mvc_Url, getStatic){ +static PHP_METHOD(Phalcon_Mvc_Model, useDynamicUpdate){ - zval *uri = NULL, *static_base_uri, *base_uri; + zval *dynamic_update, *manager; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &uri); - - if (!uri) { - PHALCON_INIT_VAR(uri); - } - - PHALCON_OBS_VAR(static_base_uri); - phalcon_read_property_this_quick(&static_base_uri, this_ptr, SL("_staticBaseUri"), 2610838775UL, PH_NOISY_CC); - if (Z_TYPE_P(static_base_uri) != IS_NULL) { - PHALCON_CONCAT_VV(return_value, static_base_uri, uri); - RETURN_MM(); - } + phalcon_fetch_params(1, 1, 0, &dynamic_update); - PHALCON_INIT_VAR(base_uri); - phalcon_call_method_key(base_uri, this_ptr, "getbaseuri", 2750461136UL); - PHALCON_CONCAT_VV(return_value, base_uri, uri); + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, manager, "usedynamicupdate", this_ptr, dynamic_update, 3447359802UL); - RETURN_MM(); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Url, path){ +static PHP_METHOD(Phalcon_Mvc_Model, getRelated){ - zval *path = NULL, *base_path; + zval *alias, *arguments = NULL, *manager, *class_name; + zval *relation, *exception_message, *call_object; + zval *model_args; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &path); + phalcon_fetch_params(1, 1, 1, &alias, &arguments); - if (!path) { - PHALCON_INIT_VAR(path); + if (!arguments) { + PHALCON_INIT_VAR(arguments); } - PHALCON_OBS_VAR(base_path); - phalcon_read_property_this_quick(&base_path, this_ptr, SL("_basePath"), 1477430348UL, PH_NOISY_CC); - PHALCON_CONCAT_VV(return_value, base_path, path); - RETURN_MM(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_RouterInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, RouterInterface, mvc_routerinterface, phalcon_mvc_routerinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_LazyLoader){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Micro, LazyLoader, mvc_micro_lazyloader, phalcon_mvc_micro_lazyloader_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_micro_lazyloader_ce, SL("_handler"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_lazyloader_ce, SL("_definition"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __construct){ - - zval *definition; - - phalcon_fetch_params(0, 1, 0, &definition); + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - if (Z_TYPE_P(definition) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_micro_exception_ce, "Only strings can be lazy loaded"); + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); + + PHALCON_INIT_VAR(relation); + phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", class_name, alias, 785467656UL); + if (Z_TYPE_P(relation) != IS_OBJECT) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVSVS(exception_message, "There is no defined relations for the model \"", class_name, "\" using alias \"", alias, "\""); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); return; } - phalcon_update_property_this_quick(this_ptr, SL("_definition"), definition, 2496408365UL TSRMLS_CC); + PHALCON_INIT_VAR(call_object); + array_init_size(call_object, 2); + phalcon_array_append(&call_object, manager, PH_SEPARATE); + add_next_index_stringl(call_object, SL("getRelationRecords"), 1); + + PHALCON_INIT_VAR(model_args); + array_init_size(model_args, 4); + phalcon_array_append(&model_args, relation, PH_SEPARATE); + add_next_index_null(model_args); + phalcon_array_append(&model_args, this_ptr, PH_SEPARATE); + phalcon_array_append(&model_args, arguments, PH_SEPARATE); + PHALCON_CALL_USER_FUNC_ARRAY(return_value, call_object, model_args); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __call){ +static PHP_METHOD(Phalcon_Mvc_Model, _getRelatedRecords){ - zval *method, *arguments, *handler = NULL, *definition; - zval *call_handler; - zend_class_entry *ce0; + zval *model_name, *method, *arguments, *manager; + zval *relation = NULL, *query_method = NULL, *alias = NULL, *extra_args = NULL; + zval *call_args, *call_object; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &method, &arguments); + phalcon_fetch_params(1, 3, 0, &model_name, &method, &arguments); - PHALCON_OBS_VAR(handler); - phalcon_read_property_this_quick(&handler, this_ptr, SL("_handler"), 1505752930UL, PH_NOISY_CC); - if (Z_TYPE_P(handler) != IS_OBJECT) { - PHALCON_OBS_VAR(definition); - phalcon_read_property_this_quick(&definition, this_ptr, SL("_definition"), 2496408365UL, PH_NOISY_CC); - ce0 = phalcon_fetch_class(definition TSRMLS_CC); + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(handler); - object_init_ex(handler, ce0); - if (phalcon_has_constructor(handler TSRMLS_CC)) { - phalcon_call_method_key(NULL, handler, "__construct", 1107214344UL); + PHALCON_INIT_VAR(relation); + ZVAL_BOOL(relation, 0); + + PHALCON_INIT_VAR(query_method); + + if (phalcon_start_with_str(method, SL("get"))) { + PHALCON_INIT_VAR(alias); + phalcon_substr(alias, method, 3, 0); + + phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", model_name, alias, 785467656UL); + } + + if (Z_TYPE_P(relation) != IS_OBJECT) { + if (phalcon_start_with_str(method, SL("count"))) { + ZVAL_STRING(query_method, "count", 1); + + PHALCON_INIT_NVAR(alias); + phalcon_substr(alias, method, 5, 0); + + PHALCON_INIT_NVAR(relation); + phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", model_name, alias, 785467656UL); } - phalcon_update_property_this_quick(this_ptr, SL("_handler"), handler, 1505752930UL TSRMLS_CC); } - PHALCON_INIT_VAR(call_handler); - array_init_size(call_handler, 2); - phalcon_array_append(&call_handler, handler, PH_SEPARATE); - phalcon_array_append(&call_handler, method, PH_SEPARATE); + if (Z_TYPE_P(relation) == IS_OBJECT) { + if (phalcon_array_isset_long(arguments, 0)) { + PHALCON_OBS_VAR(extra_args); + phalcon_array_fetch_long(&extra_args, arguments, 0, PH_NOISY); + } else { + PHALCON_INIT_NVAR(extra_args); + } - PHALCON_CALL_USER_FUNC_ARRAY(return_value, call_handler, arguments); - RETURN_MM(); + PHALCON_INIT_VAR(call_args); + array_init_size(call_args, 4); + phalcon_array_append(&call_args, relation, PH_SEPARATE); + phalcon_array_append(&call_args, query_method, PH_SEPARATE); + phalcon_array_append(&call_args, this_ptr, PH_SEPARATE); + phalcon_array_append(&call_args, extra_args, PH_SEPARATE); + + PHALCON_INIT_VAR(call_object); + array_init_size(call_object, 2); + phalcon_array_append(&call_object, manager, PH_SEPARATE); + add_next_index_stringl(call_object, SL("getRelationRecords"), 1); + PHALCON_CALL_USER_FUNC_ARRAY(return_value, call_object, call_args); + RETURN_MM(); + } + + RETURN_MM_NULL(); } +static PHP_METHOD(Phalcon_Mvc_Model, __call){ + zval *method, *arguments = NULL, *model_name, *records; + zval *models_manager, *status, *exception_message; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_Collection){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Micro, Collection, mvc_micro_collection, phalcon_mvc_micro_collection_method_entry, 0); - - zend_declare_property_null(phalcon_mvc_micro_collection_ce, SL("_prefix"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_collection_ce, SL("_lazy"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_collection_ce, SL("_handler"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_micro_collection_ce, SL("_handlers"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_micro_collection_ce TSRMLS_CC, 1, phalcon_mvc_micro_collectioninterface_ce); - - return SUCCESS; + phalcon_fetch_params(1, 1, 1, &method, &arguments); + + if (!arguments) { + PHALCON_INIT_VAR(arguments); + array_init(arguments); + } + + PHALCON_INIT_VAR(model_name); + phalcon_get_class(model_name, this_ptr, 0 TSRMLS_CC); + + PHALCON_INIT_VAR(records); + phalcon_call_method_p3_key(records, this_ptr, "_getrelatedrecords", model_name, method, arguments, 1071693079UL); + if (Z_TYPE_P(records) != IS_NULL) { + RETURN_CCTOR(records); + } + + PHALCON_OBS_VAR(models_manager); + phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(status); + phalcon_call_method_p3_key(status, models_manager, "missingmethod", this_ptr, method, arguments, 965701664UL); + if (Z_TYPE_P(status) != IS_NULL) { + RETURN_CCTOR(status); + } + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVSVS(exception_message, "The method \"", method, "\" doesn't exist on model \"", model_name, "\""); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, _addMap){ +static PHP_METHOD(Phalcon_Mvc_Model, __callStatic){ - zval *method, *route_pattern, *handler, *handler_definition; + zval *method, *arguments = NULL, *extra_method = NULL, *type = NULL; + zval *model_name, *exception_message = NULL, *value; + zval *model, *meta_data, *attributes = NULL, *field = NULL, *extra_method_first; + zval *conditions, *bind_params, *parameters; + zend_class_entry *ce0; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &method, &route_pattern, &handler); + phalcon_fetch_params(1, 1, 1, &method, &arguments); + + if (!arguments) { + PHALCON_INIT_VAR(arguments); + } + + PHALCON_INIT_VAR(extra_method); + + if (phalcon_start_with_str(method, SL("findFirstBy"))) { + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "findFirst", 1); + + phalcon_substr(extra_method, method, 11, 0); + } + + if (Z_TYPE_P(extra_method) == IS_NULL) { + if (phalcon_start_with_str(method, SL("findBy"))) { + PHALCON_INIT_NVAR(type); + ZVAL_STRING(type, "find", 1); + + PHALCON_INIT_NVAR(extra_method); + phalcon_substr(extra_method, method, 6, 0); + } + } + + if (Z_TYPE_P(extra_method) == IS_NULL) { + if (phalcon_start_with_str(method, SL("countBy"))) { + PHALCON_INIT_NVAR(type); + ZVAL_STRING(type, "count", 1); + + PHALCON_INIT_NVAR(extra_method); + phalcon_substr(extra_method, method, 7, 0); + } + } + + PHALCON_INIT_VAR(model_name); + phalcon_get_called_class(model_name TSRMLS_CC); + if (!zend_is_true(extra_method)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVSVS(exception_message, "The static method \"", method, "\" doesn't exist on model \"", model_name, "\""); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + if (!phalcon_array_isset_long(arguments, 0)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "The static method \"", method, "\" requires one argument"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_VAR(value); + phalcon_array_fetch_long(&value, arguments, 0, PH_NOISY); + ce0 = phalcon_fetch_class(model_name TSRMLS_CC); + + PHALCON_INIT_VAR(model); + object_init_ex(model, ce0); + if (phalcon_has_constructor(model TSRMLS_CC)) { + phalcon_call_method_key(NULL, model, "__construct", 1107214344UL); + } + + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, model, "getmodelsmetadata", 3603043978UL); + + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getreversecolumnmap", model, 817005101UL); + if (Z_TYPE_P(attributes) != IS_ARRAY) { + PHALCON_INIT_NVAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getdatatypes", model, 562971380UL); + } + + if (phalcon_array_isset(attributes, extra_method)) { + PHALCON_CPY_WRT(field, extra_method); + } else { + PHALCON_INIT_VAR(extra_method_first); + phalcon_lcfirst(extra_method_first, extra_method); + if (phalcon_array_isset(attributes, extra_method_first)) { + PHALCON_CPY_WRT(field, extra_method_first); + } else { + PHALCON_INIT_NVAR(field); + phalcon_uncamelize(field, extra_method); + if (!phalcon_array_isset(attributes, field)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Cannot resolve attribute \"", extra_method, "' in the model"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + } + } - PHALCON_INIT_VAR(handler_definition); - array_init_size(handler_definition, 3); - phalcon_array_append(&handler_definition, method, PH_SEPARATE); - phalcon_array_append(&handler_definition, route_pattern, PH_SEPARATE); - phalcon_array_append(&handler_definition, handler, PH_SEPARATE); - phalcon_update_property_array_append(this_ptr, SL("_handlers"), handler_definition TSRMLS_CC); + PHALCON_INIT_VAR(conditions); + PHALCON_CONCAT_VS(conditions, field, " = ?0"); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, setPrefix){ - - zval *prefix; - - phalcon_fetch_params(0, 1, 0, &prefix); + PHALCON_INIT_VAR(bind_params); + array_init_size(bind_params, 1); + phalcon_array_append(&bind_params, value, PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, getPrefix){ - - - RETURN_MEMBER_QUICK(this_ptr, "_prefix", 3873791314UL); -} - -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, getHandlers){ - - - RETURN_MEMBER_QUICK(this_ptr, "_handlers", 2445210229UL); + PHALCON_INIT_VAR(parameters); + array_init_size(parameters, 2); + phalcon_array_update_quick_string(¶meters, SS("conditions"), 1055696255UL, &conditions, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(¶meters, SS("bind"), 254268962UL, &bind_params, PH_COPY | PH_SEPARATE); + + phalcon_call_zval_static_p1(return_value, model_name, type, parameters); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, setHandler){ +static PHP_METHOD(Phalcon_Mvc_Model, __set){ - zval *handler, *lazy = NULL; + zval *property, *value, *is_model, *lower_property = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &handler, &lazy); + phalcon_fetch_params(1, 2, 0, &property, &value); - if (!lazy) { - PHALCON_INIT_VAR(lazy); - ZVAL_BOOL(lazy, 0); + if (Z_TYPE_P(value) == IS_OBJECT) { + + PHALCON_INIT_VAR(is_model); + phalcon_instance_of(is_model, value, phalcon_mvc_modelinterface_ce TSRMLS_CC); + if (zend_is_true(is_model)) { + PHALCON_INIT_VAR(lower_property); + phalcon_fast_strtolower(lower_property, property); + phalcon_update_property_zval_zval(this_ptr, lower_property, value TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_related"), lower_property, value TSRMLS_CC); + phalcon_update_property_long(this_ptr, SL("_dirtyState"), 1 TSRMLS_CC); + RETURN_CCTOR(value); + } } - phalcon_update_property_this_quick(this_ptr, SL("_handler"), handler, 1505752930UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_lazy"), lazy, 3981620804UL TSRMLS_CC); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, setLazy){ - - zval *lazy; - - phalcon_fetch_params(0, 1, 0, &lazy); + if (Z_TYPE_P(value) == IS_ARRAY) { + PHALCON_INIT_NVAR(lower_property); + phalcon_fast_strtolower(lower_property, property); + phalcon_update_property_array(this_ptr, SL("_related"), lower_property, value TSRMLS_CC); + phalcon_update_property_long(this_ptr, SL("_dirtyState"), 1 TSRMLS_CC); + RETURN_CCTOR(value); + } - phalcon_update_property_this_quick(this_ptr, SL("_lazy"), lazy, 3981620804UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, isLazy){ - - - RETURN_MEMBER_QUICK(this_ptr, "_lazy", 3981620804UL); -} - -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, getHandler){ - - - RETURN_MEMBER_QUICK(this_ptr, "_handler", 1505752930UL); -} - -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, map){ - - zval *route_pattern, *handler, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + phalcon_update_property_zval_zval(this_ptr, property, value TSRMLS_CC); - PHALCON_INIT_VAR(method); - phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); - RETURN_MM(); + RETURN_CCTOR(value); } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, get){ +static PHP_METHOD(Phalcon_Mvc_Model, __get){ - zval *route_pattern, *handler, *method; + zval *property, *model_name, *manager, *lower_property; + zval *relation, *call_args, *call_object, *result; + zval *is_simple_model, *error_msg; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + phalcon_fetch_params(1, 1, 0, &property); - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "GET", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); - RETURN_MM(); + PHALCON_INIT_VAR(model_name); + phalcon_get_class(model_name, this_ptr, 0 TSRMLS_CC); + + PHALCON_INIT_VAR(manager); + phalcon_call_method_key(manager, this_ptr, "getmodelsmanager", 2387491844UL); + + PHALCON_INIT_VAR(lower_property); + phalcon_fast_strtolower(lower_property, property); + + PHALCON_INIT_VAR(relation); + phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", model_name, lower_property, 785467656UL); + if (Z_TYPE_P(relation) == IS_OBJECT) { + + PHALCON_INIT_VAR(call_args); + array_init_size(call_args, 4); + phalcon_array_append(&call_args, relation, PH_SEPARATE); + add_next_index_null(call_args); + phalcon_array_append(&call_args, this_ptr, PH_SEPARATE); + add_next_index_null(call_args); + + PHALCON_INIT_VAR(call_object); + array_init_size(call_object, 2); + phalcon_array_append(&call_object, manager, PH_SEPARATE); + add_next_index_stringl(call_object, SL("getRelationRecords"), 1); + + PHALCON_INIT_VAR(result); + PHALCON_CALL_USER_FUNC_ARRAY(result, call_object, call_args); + + if (Z_TYPE_P(result) == IS_OBJECT) { + + phalcon_update_property_zval_zval(this_ptr, lower_property, result TSRMLS_CC); + + PHALCON_INIT_VAR(is_simple_model); + phalcon_instance_of(is_simple_model, result, phalcon_mvc_modelinterface_ce TSRMLS_CC); + if (PHALCON_IS_TRUE(is_simple_model)) { + phalcon_update_property_array(this_ptr, SL("_related"), lower_property, result TSRMLS_CC); + } + } + + RETURN_CCTOR(result); + } + + PHALCON_INIT_VAR(error_msg); + PHALCON_CONCAT_SVSV(error_msg, "Access to undefined property ", model_name, "::", property); + phalcon_call_func_p1_noret("trigger_error", error_msg); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, post){ +static PHP_METHOD(Phalcon_Mvc_Model, __isset){ - zval *route_pattern, *handler, *method; + zval *property, *model_name, *manager, *relation; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + phalcon_fetch_params(1, 1, 0, &property); - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "POST", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); - RETURN_MM(); + PHALCON_INIT_VAR(model_name); + phalcon_get_class(model_name, this_ptr, 0 TSRMLS_CC); + + PHALCON_INIT_VAR(manager); + phalcon_call_method_key(manager, this_ptr, "getmodelsmanager", 2387491844UL); + + PHALCON_INIT_VAR(relation); + phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", model_name, property, 785467656UL); + if (Z_TYPE_P(relation) == IS_OBJECT) { + RETURN_MM_TRUE; + } + + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, put){ +static PHP_METHOD(Phalcon_Mvc_Model, serialize){ - zval *route_pattern, *handler, *method; + zval *meta_data, *attributes, *null_value, *data; + zval *attribute = NULL, *value = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "PUT", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); + + PHALCON_INIT_VAR(null_value); + + PHALCON_INIT_VAR(data); + array_init(data); + + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(attribute); + + if (phalcon_isset_property_zval(this_ptr, attribute TSRMLS_CC)) { + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, attribute, PH_NOISY_CC); + phalcon_array_update_zval(&data, attribute, &value, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_zval(&data, attribute, &null_value, PH_COPY | PH_SEPARATE); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + phalcon_serialize(return_value, &data TSRMLS_CC); RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, patch){ +static PHP_METHOD(Phalcon_Mvc_Model, unserialize){ - zval *route_pattern, *handler, *method; + zval *data, *attributes, *dependency_injector; + zval *service, *manager, *value = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + phalcon_fetch_params(1, 1, 0, &data); - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "PATCH", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); - RETURN_MM(); + if (Z_TYPE_P(data) == IS_STRING) { + + PHALCON_INIT_VAR(attributes); + phalcon_unserialize(attributes, data TSRMLS_CC); + if (Z_TYPE_P(attributes) == IS_ARRAY) { + + PHALCON_INIT_VAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); + return; + } + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "modelsManager", 1); + + PHALCON_INIT_VAR(manager); + phalcon_call_method_p1_key(manager, dependency_injector, "getshared", service, 1727570332UL); + if (Z_TYPE_P(manager) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The injected service 'modelsManager' is not valid"); + return; + } + + phalcon_update_property_this_quick(this_ptr, SL("_modelsManager"), manager, 3699347875UL TSRMLS_CC); + + phalcon_call_method_p1_key(NULL, manager, "initialize", this_ptr, 2896075127UL); + + 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(); + } + } + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid serialization data"); + return; } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, head){ +static PHP_METHOD(Phalcon_Mvc_Model, dump){ - zval *route_pattern, *handler, *method; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "HEAD", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); + phalcon_call_func_p1(return_value, "get_object_vars", this_ptr); RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, delete){ +static PHP_METHOD(Phalcon_Mvc_Model, toArray){ - zval *route_pattern, *handler, *method; + zval *meta_data, *data, *null_value, *attributes; + zval *column_map, *attribute = NULL, *exception_message = NULL; + zval *attribute_field = NULL, *value = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "DELETE", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); - RETURN_MM(); + PHALCON_INIT_VAR(data); + array_init(data); + + PHALCON_INIT_VAR(null_value); + + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); + + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); + + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(attribute); + + if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (!phalcon_array_isset(column_map, attribute)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Column \"", attribute, "\" doesn't make part of the column map"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } + + PHALCON_OBS_NVAR(attribute_field); + phalcon_array_fetch(&attribute_field, column_map, attribute, PH_NOISY); + } else { + PHALCON_CPY_WRT(attribute_field, attribute); + } + 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_CC); + phalcon_array_update_zval(&data, attribute_field, &value, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_zval(&data, attribute_field, &null_value, PH_COPY | PH_SEPARATE); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + RETURN_CTOR(data); } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, options){ +static PHP_METHOD(Phalcon_Mvc_Model, setup){ - zval *route_pattern, *handler, *method; + zval *options, *disable_events, *virtual_foreign_keys; + zval *column_renaming, *not_null_validations; + zval *exception_on_failed_save, *phql_literals; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + phalcon_fetch_params(1, 1, 0, &options); - PHALCON_INIT_VAR(method); - ZVAL_STRING(method, "OPTIONS", 1); - phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); - RETURN_MM(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Micro, Exception, mvc_micro_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_MiddlewareInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Micro, MiddlewareInterface, mvc_micro_middlewareinterface, phalcon_mvc_micro_middlewareinterface_method_entry); - - return SUCCESS; -} - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_CollectionInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Micro, CollectionInterface, mvc_micro_collectioninterface, phalcon_mvc_micro_collectioninterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_UrlInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, UrlInterface, mvc_urlinterface, phalcon_mvc_urlinterface_method_entry); - - return SUCCESS; -} - - - - - - + if (Z_TYPE_P(options) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Options must be an array"); + return; + } + + if (phalcon_array_isset_quick_string(options, SS("events"), 2099005594UL)) { + PHALCON_OBS_VAR(disable_events); + phalcon_array_fetch_quick_string(&disable_events, options, SS("events"), 2099005594UL, PH_NOISY); + PHALCON_GLOBAL(orm).events = zend_is_true(disable_events); + } + + if (phalcon_array_isset_quick_string(options, SS("virtualForeignKeys"), 3101162738UL)) { + PHALCON_OBS_VAR(virtual_foreign_keys); + phalcon_array_fetch_quick_string(&virtual_foreign_keys, options, SS("virtualForeignKeys"), 3101162738UL, PH_NOISY); + PHALCON_GLOBAL(orm).virtual_foreign_keys = zend_is_true(virtual_foreign_keys); + } + + if (phalcon_array_isset_quick_string(options, SS("columnRenaming"), 1384279140UL)) { + PHALCON_OBS_VAR(column_renaming); + phalcon_array_fetch_quick_string(&column_renaming, options, SS("columnRenaming"), 1384279140UL, PH_NOISY); + PHALCON_GLOBAL(orm).column_renaming = zend_is_true(column_renaming); + } + + if (phalcon_array_isset_quick_string(options, SS("notNullValidations"), 3404663535UL)) { + PHALCON_OBS_VAR(not_null_validations); + phalcon_array_fetch_quick_string(¬_null_validations, options, SS("notNullValidations"), 3404663535UL, PH_NOISY); + PHALCON_GLOBAL(orm).not_null_validations = zend_is_true(not_null_validations); + } + + if (phalcon_array_isset_quick_string(options, SS("exceptionOnFailedSave"), 2203913893UL)) { + PHALCON_OBS_VAR(exception_on_failed_save); + phalcon_array_fetch_quick_string(&exception_on_failed_save, options, SS("exceptionOnFailedSave"), 2203913893UL, PH_NOISY); + PHALCON_GLOBAL(orm).exception_on_failed_save = zend_is_true(exception_on_failed_save); + } + + if (phalcon_array_isset_quick_string(options, SS("phqlLiterals"), 3976399002UL)) { + PHALCON_OBS_VAR(phql_literals); + phalcon_array_fetch_quick_string(&phql_literals, options, SS("phqlLiterals"), 3976399002UL, PH_NOISY); + PHALCON_GLOBAL(orm).enable_literals = zend_is_true(phql_literals); + } + + PHALCON_MM_RESTORE(); +} @@ -78661,12 +77435,9 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_UrlInterface){ +PHALCON_INIT_CLASS(Phalcon_Mvc_ModelInterface){ - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Application_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Application, Exception, mvc_application_exception, "phalcon\\exception", NULL, 0); + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ModelInterface, mvc_modelinterface, phalcon_mvc_modelinterface_method_entry); return SUCCESS; } @@ -78675,1581 +77446,1381 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Application_Exception){ -#ifdef HAVE_CONFIG_H -#endif - -PHALCON_INIT_CLASS(Phalcon_Mvc_Collection){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc, Collection, mvc_collection, phalcon_mvc_collection_method_entry, 0); - zend_declare_property_null(phalcon_mvc_collection_ce, SL("_id"), ZEND_ACC_PUBLIC TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_ce, SL("_modelsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_ce, SL("_source"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_collection_ce, SL("_operationMade"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_ce, SL("_connection"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_ce, SL("_errorMessages"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_collection_ce, SL("_reserved"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_collection_ce, SL("_disableEvents"), 0, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_collection_ce, SL("OP_NONE"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_collection_ce, SL("OP_CREATE"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_collection_ce, SL("OP_UPDATE"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_collection_ce, SL("OP_DELETE"), 3 TSRMLS_CC); - zend_class_implements(phalcon_mvc_collection_ce TSRMLS_CC, 3, phalcon_mvc_collectioninterface_ce, phalcon_di_injectionawareinterface_ce, zend_ce_serializable); - return SUCCESS; -} -static PHP_METHOD(Phalcon_Mvc_Collection, __construct){ - zval *dependency_injector = NULL, *models_manager = NULL; - zval *service_name; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &dependency_injector, &models_manager); - - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } else { - PHALCON_SEPARATE_PARAM(dependency_injector); - } - - if (!models_manager) { - PHALCON_INIT_VAR(models_manager); - } else { - PHALCON_SEPARATE_PARAM(models_manager); - } - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - } - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); - return; - } - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - - if (Z_TYPE_P(models_manager) != IS_OBJECT) { - - PHALCON_INIT_VAR(service_name); - ZVAL_STRING(service_name, "collectionManager", 1); - - PHALCON_INIT_NVAR(models_manager); - phalcon_call_method_p1_key(models_manager, dependency_injector, "getshared", service_name, 1727570332UL); - if (Z_TYPE_P(models_manager) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The injected service 'modelsManager' is not valid"); - return; - } - } - - phalcon_update_property_this_quick(this_ptr, SL("_modelsManager"), models_manager, 3699347875UL TSRMLS_CC); - - phalcon_call_method_p1_key(NULL, models_manager, "initialize", this_ptr, 2896075127UL); - - if (phalcon_method_quick_exists_ex(this_ptr, SS("onconstruct"), 564344039UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, this_ptr, "onconstruct", 564344039UL); - } - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Mvc_Collection, setId){ - zval *id, *models_manager, *use_implicit_ids; - zval *mongo_id = NULL; - zend_class_entry *ce0; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &id); - - if (Z_TYPE_P(id) != IS_OBJECT) { - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(use_implicit_ids); - phalcon_call_method_p1_key(use_implicit_ids, models_manager, "isusingimplicitobjectids", this_ptr, 3521236505UL); - if (zend_is_true(use_implicit_ids)) { - ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - PHALCON_INIT_VAR(mongo_id); - object_init_ex(mongo_id, ce0); - if (phalcon_has_constructor(mongo_id TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, mongo_id, "__construct", id, 1107214344UL); - } - } else { - PHALCON_CPY_WRT(mongo_id, id); - } - } else { - PHALCON_CPY_WRT(mongo_id, id); - } - phalcon_update_property_this_quick(this_ptr, SL("_id"), mongo_id, 2090005265UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Mvc_Collection, getId){ - RETURN_MEMBER_QUICK(this_ptr, "_id", 2090005265UL); -} -static PHP_METHOD(Phalcon_Mvc_Collection, setDI){ - zval *dependency_injector; - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - -} -static PHP_METHOD(Phalcon_Mvc_Collection, getDI){ - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} -static PHP_METHOD(Phalcon_Mvc_Collection, setEventsManager){ - zval *events_manager, *models_manager; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &events_manager); - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, models_manager, "setcustomeventsmanager", this_ptr, events_manager, 3062798396UL); - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Mvc_Collection, getEventsManager){ - zval *models_manager; - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, models_manager, "getcustomeventsmanager", this_ptr, 1410017072UL); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Mvc_Collection, getModelsManager){ +#ifdef HAVE_CONFIG_H +#endif - RETURN_MEMBER_QUICK(this_ptr, "_modelsManager", 3699347875UL); -} -static PHP_METHOD(Phalcon_Mvc_Collection, getReservedAttributes){ - zval *reserved = NULL, *dummy; +PHALCON_INIT_CLASS(Phalcon_Mvc_ModuleDefinitionInterface){ - PHALCON_MM_GROW(); + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ModuleDefinitionInterface, mvc_moduledefinitioninterface, phalcon_mvc_moduledefinitioninterface_method_entry); - PHALCON_OBS_VAR(reserved); - phalcon_read_static_property(&reserved, SL("phalcon\\mvc\\collection"), SL("_reserved") TSRMLS_CC); - if (Z_TYPE_P(reserved) == IS_NULL) { - PHALCON_INIT_VAR(dummy); - ZVAL_BOOL(dummy, 1); - - PHALCON_INIT_NVAR(reserved); - array_init_size(reserved, 5); - phalcon_array_update_quick_string(&reserved, SS("_connection"), 3057302292UL, &dummy, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&reserved, SS("_dependencyInjector"), 765199457UL, &dummy, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&reserved, SS("_source"), 3355220565UL, &dummy, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&reserved, SS("_operationMade"), 3968152972UL, &dummy, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&reserved, SS("_errorMessages"), 1019066246UL, &dummy, PH_COPY | PH_SEPARATE); - phalcon_update_static_property(SL("phalcon\\mvc\\collection"), SL("_reserved"), reserved TSRMLS_CC); - } - - RETURN_CCTOR(reserved); + return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Collection, useImplicitObjectIds){ - - zval *use_implicit_object_ids, *models_manager; - - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &use_implicit_object_ids); - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, models_manager, "useimplicitobjectids", this_ptr, use_implicit_object_ids, 1206425092UL); - - PHALCON_MM_RESTORE(); -} -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(); -} -static PHP_METHOD(Phalcon_Mvc_Collection, getSource){ - zval *source = NULL, *class_name; +#ifdef HAVE_CONFIG_H +#endif - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(source); - phalcon_read_property_this_quick(&source, this_ptr, SL("_source"), 3355220565UL, PH_NOISY_CC); - 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_CCTOR(source); -} -static PHP_METHOD(Phalcon_Mvc_Collection, setConnectionService){ - zval *connection_service, *models_manager; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &connection_service); - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, models_manager, "setconnectionservice", this_ptr, connection_service, 4052304818UL); - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Mvc_Collection, getConnectionService){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Annotations){ - zval *models_manager; + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Router, Annotations, mvc_router_annotations, "phalcon\\mvc\\router", phalcon_mvc_router_annotations_method_entry, 0); - PHALCON_MM_GROW(); + zend_declare_property_null(phalcon_mvc_router_annotations_ce, SL("_handlers"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_router_annotations_ce, SL("_processed"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_mvc_router_annotations_ce, SL("_controllerSuffix"), "Controller", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_mvc_router_annotations_ce, SL("_actionSuffix"), "Action", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_annotations_ce, SL("_routePrefix"), ZEND_ACC_PROTECTED TSRMLS_CC); - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, models_manager, "getconnectionservice", this_ptr, 619546022UL); - RETURN_MM(); + return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Collection, getConnection){ +static PHP_METHOD(Phalcon_Mvc_Router_Annotations, addResource){ - zval *connection = NULL, *models_manager; + zval *handler, *prefix = NULL, *scope; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(connection); - phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); - if (Z_TYPE_P(connection) != IS_OBJECT) { - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 1, &handler, &prefix); - PHALCON_INIT_NVAR(connection); - phalcon_call_method_p1_key(connection, models_manager, "getconnection", this_ptr, 2504689909UL); - phalcon_update_property_this_quick(this_ptr, SL("_connection"), connection, 3057302292UL TSRMLS_CC); + if (!prefix) { + PHALCON_INIT_VAR(prefix); } - RETURN_CCTOR(connection); + if (Z_TYPE_P(handler) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The handler must be a class name"); + return; + } + + PHALCON_INIT_VAR(scope); + array_init_size(scope, 2); + phalcon_array_append(&scope, prefix, PH_SEPARATE); + phalcon_array_append(&scope, handler, PH_SEPARATE); + phalcon_update_property_array_append(this_ptr, SL("_handlers"), scope TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_processed"), 0 TSRMLS_CC); + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Collection, readAttribute){ +static PHP_METHOD(Phalcon_Mvc_Router_Annotations, addModuleResource){ - zval *attribute, *attribute_value; + zval *module, *handler, *prefix = NULL, *scope; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &attribute); + phalcon_fetch_params(1, 2, 1, &module, &handler, &prefix); - 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_CC); - RETURN_CCTOR(attribute_value); + if (!prefix) { + PHALCON_INIT_VAR(prefix); } - RETURN_MM_NULL(); -} - -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); + if (Z_TYPE_P(module) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The module is not a valid string"); + return; + } + if (Z_TYPE_P(handler) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The handler must be a class name"); + return; + } + + PHALCON_INIT_VAR(scope); + array_init_size(scope, 3); + phalcon_array_append(&scope, prefix, PH_SEPARATE); + phalcon_array_append(&scope, handler, PH_SEPARATE); + phalcon_array_append(&scope, module, PH_SEPARATE); + phalcon_update_property_array_append(this_ptr, SL("_handlers"), scope TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_processed"), 0 TSRMLS_CC); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ +static PHP_METHOD(Phalcon_Mvc_Router_Annotations, handle){ - zval *collection, *document, *cloned_collection; - zval *value = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; + zval *uri = NULL, *real_uri = NULL, *processed, *annotations_service = NULL; + zval *handlers, *controller_suffix, *scope = NULL, *prefix = NULL; + zval *dependency_injector = NULL, *service = NULL, *handler = NULL; + zval *controller_name = NULL, *lower_controller_name = NULL; + zval *namespace_name = NULL, *module_name = NULL, *sufixed = NULL; + zval *handler_annotations = NULL, *class_annotations = NULL; + zval *annotations = NULL, *annotation = NULL, *method_annotations = NULL; + zval *lowercased = NULL, *collection = NULL, *method = NULL; + HashTable *ah0, *ah1, *ah2, *ah3; + HashPosition hp0, hp1, hp2, hp3; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &collection, &document); + phalcon_fetch_params(1, 0, 1, &uri); - 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) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid document"); - return; + if (!uri) { + PHALCON_INIT_VAR(uri); } - PHALCON_INIT_VAR(cloned_collection); - if (phalcon_clone(cloned_collection, collection TSRMLS_CC) == FAILURE) { - return; + if (!zend_is_true(uri)) { + PHALCON_INIT_VAR(real_uri); + phalcon_call_method_key(real_uri, this_ptr, "getrewriteuri", 1631494103UL); + } else { + PHALCON_CPY_WRT(real_uri, uri); } - phalcon_is_iterable(document, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(processed); + phalcon_read_property_this_quick(&processed, this_ptr, SL("_processed"), 908491692UL, PH_NOISY_CC); + if (!zend_is_true(processed)) { - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(annotations_service); - PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + PHALCON_OBS_VAR(handlers); + phalcon_read_property_this_quick(&handlers, this_ptr, SL("_handlers"), 2445210229UL, PH_NOISY_CC); + if (Z_TYPE_P(handlers) == IS_ARRAY) { - phalcon_call_method_p2_key(NULL, cloned_collection, "writeattribute", key, value, 3716971876UL); + PHALCON_OBS_VAR(controller_suffix); + phalcon_read_property_this_quick(&controller_suffix, this_ptr, SL("_controllerSuffix"), 2437326621UL, PH_NOISY_CC); - zend_hash_move_forward_ex(ah0, &hp0); - } + phalcon_is_iterable(handlers, &ah0, &hp0, 0, 0); - RETURN_CCTOR(cloned_collection); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ - - zval *params, *collection, *connection, *unique; - zval *source, *mongo_collection, *conditions = NULL; - zval *fields, *documents_cursor = NULL, *limit, *sort = NULL; - zval *base = NULL, *document = NULL, *collections, *documents_array; - zval *collection_cloned = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 4, 0, ¶ms, &collection, &connection, &unique); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, collection, "getsource", 2025234358UL); - if (PHALCON_IS_EMPTY(source)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); - return; - } + PHALCON_GET_HVALUE(scope); - PHALCON_INIT_VAR(mongo_collection); - phalcon_call_method_p1_key(mongo_collection, connection, "selectcollection", source, 3563037297UL); + if (Z_TYPE_P(scope) == IS_ARRAY) { - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_long(&conditions, params, 0, PH_NOISY); - } else { - if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { - PHALCON_OBS_NVAR(conditions); - phalcon_array_fetch_quick_string(&conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(conditions); - array_init(conditions); - } - } + PHALCON_OBS_NVAR(prefix); + phalcon_array_fetch_long(&prefix, scope, 0, PH_NOISY); + if (Z_TYPE_P(prefix) == IS_STRING) { + if (!phalcon_start_with(real_uri, prefix, NULL)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } - 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); + if (Z_TYPE_P(annotations_service) != IS_OBJECT) { - PHALCON_INIT_VAR(documents_cursor); - phalcon_call_method_p2_key(documents_cursor, mongo_collection, "find", conditions, fields, 259012646UL); - } else { - PHALCON_INIT_NVAR(documents_cursor); - phalcon_call_method_p1_key(documents_cursor, mongo_collection, "find", conditions, 259012646UL); - } + PHALCON_OBS_NVAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "A dependency injection container is required to access the 'annotations' service"); + return; + } - 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_p1_key(NULL, documents_cursor, "limit", limit, 192268420UL); - } + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "annotations", 1); + + PHALCON_INIT_NVAR(annotations_service); + phalcon_call_method_p1_key(annotations_service, dependency_injector, "getshared", service, 1727570332UL); + } + + PHALCON_OBS_NVAR(handler); + phalcon_array_fetch_long(&handler, scope, 1, PH_NOISY); + if (phalcon_memnstr_str(handler, SL("\\"))) { + PHALCON_INIT_NVAR(controller_name); + phalcon_get_class_ns(controller_name, handler, 0 TSRMLS_CC); + + PHALCON_INIT_NVAR(lower_controller_name); + phalcon_uncamelize(lower_controller_name, controller_name); + + PHALCON_INIT_NVAR(namespace_name); + phalcon_get_ns_class(namespace_name, handler, 0 TSRMLS_CC); + } else { + PHALCON_CPY_WRT(controller_name, handler); + + PHALCON_INIT_NVAR(lower_controller_name); + phalcon_uncamelize(lower_controller_name, controller_name); + + PHALCON_INIT_NVAR(namespace_name); + } + + phalcon_update_property_null(this_ptr, SL("_routePrefix") TSRMLS_CC); + + if (phalcon_array_isset_long(scope, 2)) { + PHALCON_OBS_NVAR(module_name); + phalcon_array_fetch_long(&module_name, scope, 2, PH_NOISY); + } else { + PHALCON_INIT_NVAR(module_name); + } + + PHALCON_INIT_NVAR(sufixed); + PHALCON_CONCAT_VV(sufixed, handler, controller_suffix); + + PHALCON_INIT_NVAR(handler_annotations); + phalcon_call_method_p1_key(handler_annotations, annotations_service, "get", sufixed, 2090288933UL); + + PHALCON_INIT_NVAR(class_annotations); + phalcon_call_method_key(class_annotations, handler_annotations, "getclassannotations", 3984548329UL); + if (Z_TYPE_P(class_annotations) == IS_OBJECT) { + + PHALCON_INIT_NVAR(annotations); + phalcon_call_method_key(annotations, class_annotations, "getannotations", 163297043UL); + if (Z_TYPE_P(annotations) == IS_ARRAY) { + + phalcon_is_iterable(annotations, &ah1, &hp1, 0, 0); + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(annotation); + + phalcon_call_method_p2_key(NULL, this_ptr, "processcontrollerannotation", controller_name, annotation, 1441174403UL); + + zend_hash_move_forward_ex(ah1, &hp1); + } + + } + } + + PHALCON_INIT_NVAR(method_annotations); + phalcon_call_method_key(method_annotations, handler_annotations, "getmethodsannotations", 2860599943UL); + if (Z_TYPE_P(method_annotations) == IS_ARRAY) { + + PHALCON_INIT_NVAR(lowercased); + phalcon_uncamelize(lowercased, handler); + + phalcon_is_iterable(method_annotations, &ah2, &hp2, 0, 0); + + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + + PHALCON_GET_HKEY(method, ah2, hp2); + PHALCON_GET_HVALUE(collection); + + if (Z_TYPE_P(collection) == IS_OBJECT) { + + PHALCON_INIT_NVAR(annotations); + phalcon_call_method_key(annotations, collection, "getannotations", 163297043UL); + + phalcon_is_iterable(annotations, &ah3, &hp3, 0, 0); + + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - 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_p1_key(NULL, documents_cursor, "sort", sort, 274650125UL); - } + PHALCON_GET_HVALUE(annotation); - 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_p1_key(NULL, documents_cursor, "skip", sort, 274496444UL); - } + phalcon_call_method_p5_key(NULL, this_ptr, "processactionannotation", module_name, namespace_name, lower_controller_name, method, annotation, 3018293437UL); - 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); - } + zend_hash_move_forward_ex(ah3, &hp3); + } - if (PHALCON_IS_TRUE(unique)) { + } - phalcon_call_method_key(NULL, documents_cursor, "rewind", 1064078190UL); + zend_hash_move_forward_ex(ah2, &hp2); + } - PHALCON_INIT_VAR(document); - phalcon_call_method_key(document, documents_cursor, "current", 431662984UL); - if (Z_TYPE_P(document) == IS_ARRAY) { - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "cloneresult", base, document); - RETURN_MM(); - } + } + } - RETURN_MM_FALSE; - } + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_INIT_VAR(collections); - array_init(collections); + } - PHALCON_INIT_VAR(documents_array); - phalcon_call_func_p1(documents_array, "iterator_to_array", documents_cursor); + phalcon_update_property_bool(this_ptr, SL("_processed"), 1 TSRMLS_CC); + } - phalcon_is_iterable(documents_array, &ah0, &hp0, 0, 0); + PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Mvc\\Router\\Annotations", "handle", real_uri); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Annotations, processControllerAnnotation){ + + zval *handler, *annotation, *name, *position, *value; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &handler, &annotation); - PHALCON_GET_HVALUE(document); + PHALCON_INIT_VAR(name); + phalcon_call_method_key(name, annotation, "getname", 4286441094UL); - PHALCON_INIT_NVAR(collection_cloned); - PHALCON_CALL_SELF_PARAMS_2(collection_cloned, this_ptr, "cloneresult", base, document); - phalcon_array_append(&collections, collection_cloned, PH_SEPARATE); + if (PHALCON_IS_STRING(name, "RoutePrefix")) { + PHALCON_INIT_VAR(position); + ZVAL_LONG(position, 0); - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, annotation, "getargument", position, 3874091272UL); + phalcon_update_property_this_quick(this_ptr, SL("_routePrefix"), value, 2004814177UL TSRMLS_CC); } - RETURN_CTOR(collections); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ +static PHP_METHOD(Phalcon_Mvc_Router_Annotations, processActionAnnotation){ - zval *params, *collection, *connection, *source; - zval *mongo_collection, *conditions = NULL, *simple = NULL; - zval *documents_cursor, *limit, *sort = NULL; + zval *module, *namespace, *controller, *action; + zval *annotation, *is_route = NULL, *methods = NULL, *name, *action_suffix; + zval *empty_str, *real_action_name, *action_name; + zval *route_prefix, *parameter = NULL, *paths = NULL, *position; + zval *value, *uri = NULL, *route, *converts = NULL, *convert = NULL, *param = NULL; + zval *conversor_param = NULL, *route_name; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, ¶ms, &collection, &connection); + phalcon_fetch_params(1, 5, 0, &module, &namespace, &controller, &action, &annotation); - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, collection, "getsource", 2025234358UL); - if (PHALCON_IS_EMPTY(source)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); - return; - } + PHALCON_INIT_VAR(is_route); + ZVAL_BOOL(is_route, 0); - PHALCON_INIT_VAR(mongo_collection); - phalcon_call_method_p1_key(mongo_collection, connection, "selectcollection", source, 3563037297UL); + PHALCON_INIT_VAR(methods); - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_VAR(conditions); - phalcon_array_fetch_long(&conditions, params, 0, PH_NOISY); - } else { - if (phalcon_array_isset_quick_string(params, SS("conditions"), 1055696255UL)) { - PHALCON_OBS_NVAR(conditions); - phalcon_array_fetch_quick_string(&conditions, params, SS("conditions"), 1055696255UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(conditions); - array_init(conditions); - } - } + PHALCON_INIT_VAR(name); + phalcon_call_method_key(name, annotation, "getname", 4286441094UL); - PHALCON_INIT_VAR(simple); - ZVAL_BOOL(simple, 1); - if (phalcon_array_isset_quick_string(params, SS("limit"), 192268420UL)) { - ZVAL_BOOL(simple, 0); + if (PHALCON_IS_STRING(name, "Route")) { + ZVAL_BOOL(is_route, 1); } else { - if (phalcon_array_isset_quick_string(params, SS("sort"), 274650125UL)) { - PHALCON_INIT_NVAR(simple); - ZVAL_BOOL(simple, 0); + if (PHALCON_IS_STRING(name, "Get")) { + PHALCON_INIT_NVAR(is_route); + ZVAL_BOOL(is_route, 1); + + ZVAL_STRING(methods, "GET", 1); } else { - if (phalcon_array_isset_quick_string(params, SS("skip"), 274496444UL)) { - PHALCON_INIT_NVAR(simple); - ZVAL_BOOL(simple, 0); - } - } - } + if (PHALCON_IS_STRING(name, "Post")) { + PHALCON_INIT_NVAR(is_route); + ZVAL_BOOL(is_route, 1); - if (PHALCON_IS_FALSE(simple)) { + PHALCON_INIT_NVAR(methods); + ZVAL_STRING(methods, "POST", 1); + } else { + if (PHALCON_IS_STRING(name, "Put")) { + PHALCON_INIT_NVAR(is_route); + ZVAL_BOOL(is_route, 1); - PHALCON_INIT_VAR(documents_cursor); - phalcon_call_method_p1_key(documents_cursor, mongo_collection, "find", conditions, 259012646UL); + PHALCON_INIT_NVAR(methods); + ZVAL_STRING(methods, "PUT", 1); + } else { + if (PHALCON_IS_STRING(name, "Options")) { + PHALCON_INIT_NVAR(is_route); + ZVAL_BOOL(is_route, 1); - 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_p1_key(NULL, documents_cursor, "limit", limit, 192268420UL); + PHALCON_INIT_NVAR(methods); + ZVAL_STRING(methods, "OPTIONS", 1); + } + } + } } + } - 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_p1_key(NULL, documents_cursor, "sort", sort, 274650125UL); - } + if (PHALCON_IS_TRUE(is_route)) { - 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_p1_key(NULL, documents_cursor, "skip", sort, 274496444UL); - } + PHALCON_OBS_VAR(action_suffix); + phalcon_read_property_this_quick(&action_suffix, this_ptr, SL("_actionSuffix"), 879621975UL, PH_NOISY_CC); - phalcon_fast_count(return_value, documents_cursor TSRMLS_CC); - RETURN_MM(); - } + PHALCON_INIT_VAR(empty_str); + ZVAL_STRING(empty_str, "", 1); - phalcon_call_method_p1_key(return_value, mongo_collection, "count", conditions, 4142425646UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ - - zval *dependency_injector, *disable_events; - zval *exists, *event_name = NULL, *status = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &dependency_injector, &disable_events, &exists); + PHALCON_INIT_VAR(real_action_name); + phalcon_fast_str_replace(real_action_name, action_suffix, empty_str, action); - if (!zend_is_true(disable_events)) { + PHALCON_INIT_VAR(action_name); + phalcon_fast_strtolower(action_name, real_action_name); - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "beforeValidation", 1); + PHALCON_OBS_VAR(route_prefix); + phalcon_read_property_this_quick(&route_prefix, this_ptr, SL("_routePrefix"), 2004814177UL, PH_NOISY_CC); - PHALCON_INIT_VAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; + PHALCON_INIT_VAR(parameter); + ZVAL_STRING(parameter, "paths", 1); + + PHALCON_INIT_VAR(paths); + phalcon_call_method_p1_key(paths, annotation, "getnamedparameter", parameter, 3202516043UL); + if (Z_TYPE_P(paths) != IS_ARRAY) { + PHALCON_INIT_NVAR(paths); + array_init(paths); } - if (!zend_is_true(exists)) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "beforeValidationOnCreate", 1); - } else { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "beforeValidationOnUpdate", 1); + if (Z_TYPE_P(module) == IS_STRING) { + phalcon_array_update_quick_string(&paths, SS("module"), 3565923467UL, &module, PH_COPY | PH_SEPARATE); } - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; + if (Z_TYPE_P(namespace) == IS_STRING) { + phalcon_array_update_quick_string(&paths, SS("namespace"), 545490034UL, &namespace, PH_COPY | PH_SEPARATE); } - } - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "validation", 1); + phalcon_array_update_quick_string(&paths, SS("controller"), 2892024105UL, &controller, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&paths, SS("action"), 502132067UL, &action_name, PH_COPY | PH_SEPARATE); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - if (!zend_is_true(disable_events)) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "onValidationFails", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - } - RETURN_MM_FALSE; - } + PHALCON_INIT_VAR(position); + ZVAL_LONG(position, 0); - if (!zend_is_true(disable_events)) { + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, annotation, "getargument", position, 3874091272UL); - if (!zend_is_true(exists)) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "afterValidationOnCreate", 1); + if (Z_TYPE_P(value) != IS_NULL) { + if (!PHALCON_IS_STRING(value, "/")) { + PHALCON_INIT_VAR(uri); + PHALCON_CONCAT_VV(uri, route_prefix, value); + } else { + PHALCON_CPY_WRT(uri, route_prefix); + } } else { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "afterValidationOnUpdate", 1); + PHALCON_INIT_NVAR(uri); + PHALCON_CONCAT_VV(uri, route_prefix, action_name); } - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } + PHALCON_INIT_VAR(route); + phalcon_call_method_p2_key(route, this_ptr, "add", uri, paths, 2090071694UL); + if (Z_TYPE_P(methods) == IS_NULL) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "afterValidation", 1); + PHALCON_INIT_NVAR(parameter); + ZVAL_STRING(parameter, "methods", 1); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; + PHALCON_INIT_NVAR(methods); + phalcon_call_method_p1_key(methods, annotation, "getnamedparameter", parameter, 3202516043UL); + if (Z_TYPE_P(methods) == IS_ARRAY) { + phalcon_call_method_p1_key(NULL, route, "via", methods, 2090831717UL); + } else { + if (Z_TYPE_P(methods) == IS_STRING) { + phalcon_call_method_p1_key(NULL, route, "via", methods, 2090831717UL); + } + } + } else { + phalcon_call_method_p1_key(NULL, route, "via", methods, 2090831717UL); } - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "beforeSave", 1); + PHALCON_INIT_NVAR(parameter); + ZVAL_STRING(parameter, "converts", 1); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } + PHALCON_INIT_VAR(converts); + phalcon_call_method_p1_key(converts, annotation, "getnamedparameter", parameter, 3202516043UL); + if (Z_TYPE_P(converts) == IS_ARRAY) { - if (zend_is_true(exists)) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "beforeUpdate", 1); - } else { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "beforeCreate", 1); - } + phalcon_is_iterable(converts, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Mvc_Collection, _postSave){ - - zval *disable_events, *success, *exists, *event_name = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &disable_events, &success, &exists); + PHALCON_GET_HKEY(param, ah0, hp0); + PHALCON_GET_HVALUE(convert); - if (PHALCON_IS_TRUE(success)) { - if (!zend_is_true(disable_events)) { - if (PHALCON_IS_TRUE(exists)) { - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "afterUpdate", 1); - } else { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "afterCreate", 1); + phalcon_call_method_p2_key(NULL, route, "convert", param, convert, 1120996230UL); + + zend_hash_move_forward_ex(ah0, &hp0); } - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "afterSave", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); } - RETURN_CCTOR(success); - } - if (!zend_is_true(disable_events)) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "notSave", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - } + PHALCON_INIT_NVAR(parameter); + ZVAL_STRING(parameter, "conversors", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "_canceloperation", disable_events, 1716493051UL); - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Collection, validate){ - - zval *validator, *status, *messages, *message = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &validator); + PHALCON_INIT_NVAR(converts); + phalcon_call_method_p1_key(converts, annotation, "getnamedparameter", parameter, 3202516043UL); + if (Z_TYPE_P(converts) == IS_ARRAY) { - if (Z_TYPE_P(validator) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Validator must be an Object"); - return; - } + phalcon_is_iterable(converts, &ah1, &hp1, 0, 0); - PHALCON_INIT_VAR(status); - phalcon_call_method_p1_key(status, validator, "validate", this_ptr, 2654098287UL); - if (PHALCON_IS_FALSE(status)) { + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_INIT_VAR(messages); - phalcon_call_method_key(messages, validator, "getmessages", 4087333309UL); + PHALCON_GET_HKEY(conversor_param, ah1, hp1); + PHALCON_GET_HVALUE(convert); - phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); + phalcon_call_method_p2_key(NULL, route, "convert", conversor_param, convert, 1120996230UL); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + zend_hash_move_forward_ex(ah1, &hp1); + } - PHALCON_GET_HVALUE(message); + } - phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); + PHALCON_INIT_NVAR(parameter); + ZVAL_STRING(parameter, "name", 1); - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_INIT_VAR(route_name); + phalcon_call_method_p1_key(route_name, annotation, "getnamedparameter", parameter, 3202516043UL); + if (Z_TYPE_P(route_name) == IS_STRING) { + phalcon_call_method_p1_key(NULL, route, "setname", route_name, 311681298UL); } + RETURN_MM_TRUE; } PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Collection, validationHasFailed){ +static PHP_METHOD(Phalcon_Mvc_Router_Annotations, setControllerSuffix){ - zval *error_messages; + zval *controller_suffix; - PHALCON_MM_GROW(); + phalcon_fetch_params(0, 1, 0, &controller_suffix); + + phalcon_update_property_this_quick(this_ptr, SL("_controllerSuffix"), controller_suffix, 2437326621UL TSRMLS_CC); + +} - PHALCON_OBS_VAR(error_messages); - phalcon_read_property_this_quick(&error_messages, this_ptr, SL("_errorMessages"), 1019066246UL, PH_NOISY_CC); - if (Z_TYPE_P(error_messages) == IS_ARRAY) { - if (phalcon_fast_count_ev(error_messages TSRMLS_CC)) { - RETURN_MM_TRUE; - } - } +static PHP_METHOD(Phalcon_Mvc_Router_Annotations, setActionSuffix){ + + zval *action_suffix; + + phalcon_fetch_params(0, 1, 0, &action_suffix); + + phalcon_update_property_this_quick(this_ptr, SL("_actionSuffix"), action_suffix, 879621975UL TSRMLS_CC); - RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Collection, fireEvent){ +static PHP_METHOD(Phalcon_Mvc_Router_Annotations, getResources){ + + + RETURN_MEMBER_QUICK(this_ptr, "_handlers", 2445210229UL); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Router, Exception, mvc_router_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; +} - zval *event_name, *models_manager; + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Group){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Router, Group, mvc_router_group, phalcon_mvc_router_group_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_router_group_ce, SL("_prefix"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_group_ce, SL("_hostname"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_group_ce, SL("_paths"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_group_ce, SL("_routes"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_group_ce, SL("_beforeMatch"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Router_Group, __construct){ + + zval *paths = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &event_name); + phalcon_fetch_params(1, 0, 1, &paths); - if (phalcon_method_exists(this_ptr, event_name TSRMLS_CC) == SUCCESS) { - phalcon_call_method_zval_noret(this_ptr, event_name); + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(return_value, models_manager, "notifyevent", event_name, this_ptr, 1223080128UL); - RETURN_MM(); + if (Z_TYPE_P(paths) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_paths"), paths, 2700778884UL TSRMLS_CC); + } else { + if (Z_TYPE_P(paths) == IS_STRING) { + phalcon_update_property_this_quick(this_ptr, SL("_paths"), paths, 2700778884UL TSRMLS_CC); + } + } + if (phalcon_method_quick_exists_ex(this_ptr, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_p1_key(NULL, this_ptr, "initialize", paths, 2896075127UL); + } + + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Group, setHostname){ + + zval *hostname; + + phalcon_fetch_params(0, 1, 0, &hostname); + + phalcon_update_property_this_quick(this_ptr, SL("_hostname"), hostname, 598751491UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Collection, fireEventCancel){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, getHostname){ + + + RETURN_MEMBER_QUICK(this_ptr, "_hostname", 598751491UL); +} - zval *event_name, *status = NULL, *models_manager; +static PHP_METHOD(Phalcon_Mvc_Router_Group, setPrefix){ - PHALCON_MM_GROW(); + zval *prefix; - phalcon_fetch_params(1, 1, 0, &event_name); - - if (phalcon_method_exists(this_ptr, event_name TSRMLS_CC) == SUCCESS) { - - PHALCON_INIT_VAR(status); - phalcon_call_method_zval(status, this_ptr, event_name); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, models_manager, "notifyevent", event_name, this_ptr, 1223080128UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } + phalcon_fetch_params(0, 1, 0, &prefix); - RETURN_MM_TRUE; + phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, getPrefix){ - zval *disable_events, *operation_made, *event_name = NULL; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_prefix", 3873791314UL); +} - phalcon_fetch_params(1, 1, 0, &disable_events); - - if (!zend_is_true(disable_events)) { - - PHALCON_OBS_VAR(operation_made); - phalcon_read_property_this_quick(&operation_made, this_ptr, SL("_operationMade"), 3968152972UL, PH_NOISY_CC); - if (PHALCON_IS_LONG(operation_made, 3)) { - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "notDeleted", 1); - } else { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "notSaved", 1); - } +static PHP_METHOD(Phalcon_Mvc_Router_Group, beforeMatch){ + + zval *before_match; + + phalcon_fetch_params(0, 1, 0, &before_match); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - } - RETURN_MM_FALSE; + phalcon_update_property_this_quick(this_ptr, SL("_beforeMatch"), before_match, 2834072708UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, getBeforeMatch){ - zval *collection, *id, *mongo_id = NULL, *models_manager; - zval *use_implicit_ids, *parameters, *document_count; - zval *zero; - zend_class_entry *ce0; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_beforeMatch", 2834072708UL); +} - 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_quick(&id, this_ptr, SL("_id"), 2090005265UL, PH_NOISY_CC); - if (Z_TYPE_P(id) == IS_OBJECT) { - PHALCON_CPY_WRT(mongo_id, id); - } else { - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(use_implicit_ids); - phalcon_call_method_p1_key(use_implicit_ids, models_manager, "isusingimplicitobjectids", this_ptr, 3521236505UL); - if (zend_is_true(use_implicit_ids)) { - ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - PHALCON_INIT_NVAR(mongo_id); - object_init_ex(mongo_id, ce0); - if (phalcon_has_constructor(mongo_id TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, mongo_id, "__construct", id, 1107214344UL); - } - phalcon_update_property_this_quick(this_ptr, SL("_id"), mongo_id, 2090005265UL TSRMLS_CC); - } else { - PHALCON_CPY_WRT(mongo_id, id); - } - } - - PHALCON_INIT_VAR(parameters); - array_init_size(parameters, 1); - phalcon_array_update_quick_string(¶meters, SS("_id"), 2090005265UL, &mongo_id, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(document_count); - phalcon_call_method_p1_key(document_count, collection, "count", parameters, 4142425646UL); +static PHP_METHOD(Phalcon_Mvc_Router_Group, setPaths){ + + zval *paths; + + phalcon_fetch_params(0, 1, 0, &paths); - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - is_smaller_function(return_value, zero, document_count TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_paths"), paths, 2700778884UL TSRMLS_CC); - RETURN_MM(); - } - RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Collection, getMessages){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, getPaths){ - RETURN_MEMBER_QUICK(this_ptr, "_errorMessages", 1019066246UL); + RETURN_MEMBER_QUICK(this_ptr, "_paths", 2700778884UL); } -static PHP_METHOD(Phalcon_Mvc_Collection, appendMessage){ - - zval *message, *type, *exception_message; +static PHP_METHOD(Phalcon_Mvc_Router_Group, getRoutes){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); - - if (Z_TYPE_P(message) != IS_OBJECT) { - PHALCON_INIT_VAR(type); - phalcon_call_func_p1(type, "gettype", message); - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Invalid message format '", type, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - - PHALCON_MM_RESTORE(); + RETURN_MEMBER_QUICK(this_ptr, "_routes", 2063827110UL); } -static PHP_METHOD(Phalcon_Mvc_Collection, save){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, _addRoute){ - zval *dependency_injector, *source, *connection; - zval *collection, *exists, *empty_array, *disable_events; - zval *status = NULL, *data, *reserved, *properties, *value = NULL; - zval *key = NULL, *success = NULL, *options, *ok, *id; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *pattern, *paths = NULL, *http_methods = NULL, *prefix, *prefix_pattern; + zval *default_paths, *merged_paths = NULL, *route; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); - return; - } - - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); - if (PHALCON_IS_EMPTY(source)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); - return; - } - - PHALCON_INIT_VAR(connection); - phalcon_call_method_key(connection, this_ptr, "getconnection", 2504689909UL); - - PHALCON_INIT_VAR(collection); - phalcon_call_method_p1_key(collection, connection, "selectcollection", source, 3563037297UL); + phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); - PHALCON_INIT_VAR(exists); - phalcon_call_method_p1_key(exists, this_ptr, "_exists", collection, 2792580580UL); - if (PHALCON_IS_FALSE(exists)) { - phalcon_update_property_long(this_ptr, SL("_operationMade"), 1 TSRMLS_CC); - } else { - phalcon_update_property_long(this_ptr, SL("_operationMade"), 2 TSRMLS_CC); + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - - phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), empty_array, 1019066246UL TSRMLS_CC); - - PHALCON_OBS_VAR(disable_events); - phalcon_read_static_property(&disable_events, SL("phalcon\\mvc\\collection"), SL("_disableEvents") TSRMLS_CC); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p3_key(status, this_ptr, "_presave", dependency_injector, disable_events, exists, 3296192410UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; + if (!http_methods) { + PHALCON_INIT_VAR(http_methods); } - PHALCON_INIT_VAR(data); - array_init(data); - - PHALCON_INIT_VAR(reserved); - phalcon_call_method_key(reserved, this_ptr, "getreservedattributes", 3061016044UL); - - PHALCON_INIT_VAR(properties); - phalcon_call_func_p1(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_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + PHALCON_INIT_VAR(prefix_pattern); + PHALCON_CONCAT_VV(prefix_pattern, prefix, pattern); - if (PHALCON_IS_STRING(key, "_id")) { + PHALCON_OBS_VAR(default_paths); + phalcon_read_property_this_quick(&default_paths, this_ptr, SL("_paths"), 2700778884UL, PH_NOISY_CC); - if (Z_TYPE_P(value) != IS_NULL) { - phalcon_array_update_zval(&data, key, &value, PH_COPY | PH_SEPARATE); - } + if (Z_TYPE_P(default_paths) == IS_ARRAY) { + if (Z_TYPE_P(paths) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_paths); + phalcon_fast_array_merge(merged_paths, &default_paths, &paths TSRMLS_CC); } else { - if (!phalcon_array_isset(reserved, key)) { - phalcon_array_update_zval(&data, key, &value, PH_COPY | PH_SEPARATE); - } + PHALCON_CPY_WRT(merged_paths, default_paths); } - - zend_hash_move_forward_ex(ah0, &hp0); + } else { + PHALCON_CPY_WRT(merged_paths, paths); } - PHALCON_INIT_VAR(success); - ZVAL_BOOL(success, 0); + PHALCON_INIT_VAR(route); + object_init_ex(route, phalcon_mvc_router_route_ce); + phalcon_call_method_p3_key(NULL, route, "__construct", prefix_pattern, merged_paths, http_methods, 1107214344UL); - PHALCON_INIT_VAR(options); - array_init_size(options, 1); - add_assoc_bool_ex(options, SS("safe"), 1); + phalcon_update_property_array_append(this_ptr, SL("_routes"), route TSRMLS_CC); - PHALCON_INIT_NVAR(status); - Z_SET_ISREF_P(options); - Z_ADDREF_P(options); - phalcon_call_method_p2_key(status, collection, "save", data, options, 274150868UL); - if (Z_REFCOUNT_P(options) > 1) { - Z_UNSET_ISREF_P(options); - Z_DELREF_P(options); - } + RETURN_CTOR(route); +} - if (Z_TYPE_P(status) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(status, SS("ok"), 193501407UL)) { +static PHP_METHOD(Phalcon_Mvc_Router_Group, add){ + + zval *pattern, *paths = NULL, *http_methods = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); - PHALCON_OBS_VAR(ok); - phalcon_array_fetch_quick_string(&ok, status, SS("ok"), 193501407UL, PH_NOISY); - if (zend_is_true(ok)) { + if (!paths) { + PHALCON_INIT_VAR(paths); + } - ZVAL_BOOL(success, 1); - if (PHALCON_IS_FALSE(exists)) { - if (phalcon_array_isset_quick_string(data, SS("_id"), 2090005265UL)) { - PHALCON_OBS_VAR(id); - phalcon_array_fetch_quick_string(&id, data, SS("_id"), 2090005265UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_id"), id, 2090005265UL TSRMLS_CC); - } - } - } - } - } else { - PHALCON_INIT_NVAR(success); - ZVAL_BOOL(success, 0); + if (!http_methods) { + PHALCON_INIT_VAR(http_methods); } - phalcon_call_method_p3_key(return_value, this_ptr, "_postsave", disable_events, success, exists, 3354288601UL); + phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, http_methods, 1178487196UL); RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Collection, findById){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, addGet){ - zval *id, *class_name, *collection, *models_manager; - zval *use_implicit_ids, *mongo_id = NULL, *conditions; - zval *parameters; - zend_class_entry *ce0, *ce1; + zval *pattern, *paths = NULL, *method; 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_key(NULL, collection, "__construct", 1107214344UL); - } - - PHALCON_INIT_VAR(models_manager); - phalcon_call_method_key(models_manager, collection, "getmodelsmanager", 2387491844UL); + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - PHALCON_INIT_VAR(use_implicit_ids); - phalcon_call_method_p1_key(use_implicit_ids, models_manager, "isusingimplicitobjectids", collection, 3521236505UL); - if (zend_is_true(use_implicit_ids)) { - ce1 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - PHALCON_INIT_VAR(mongo_id); - object_init_ex(mongo_id, ce1); - if (phalcon_has_constructor(mongo_id TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, mongo_id, "__construct", id, 1107214344UL); - } - } else { - PHALCON_CPY_WRT(mongo_id, id); - } - } else { - PHALCON_CPY_WRT(mongo_id, id); + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_INIT_VAR(conditions); - array_init_size(conditions, 1); - phalcon_array_update_quick_string(&conditions, SS("_id"), 2090005265UL, &mongo_id, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(parameters); - array_init_size(parameters, 1); - phalcon_array_append(¶meters, conditions, PH_SEPARATE); - PHALCON_CALL_SELF_PARAMS_1(return_value, this_ptr, "findfirst", parameters); + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "GET", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Collection, findFirst){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, addPost){ - zval *parameters = NULL, *class_name, *collection, *connection; - zval *unique; - zend_class_entry *ce0; + zval *pattern, *paths = NULL, *method; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for findFirst"); - return; - } + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_INIT_VAR(class_name); - phalcon_get_called_class(class_name TSRMLS_CC); - ce0 = phalcon_fetch_class(class_name TSRMLS_CC); + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "POST", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Group, addPut){ + + zval *pattern, *paths = NULL, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - PHALCON_INIT_VAR(collection); - object_init_ex(collection, ce0); - if (phalcon_has_constructor(collection TSRMLS_CC)) { - phalcon_call_method_key(NULL, collection, "__construct", 1107214344UL); + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_INIT_VAR(connection); - phalcon_call_method_key(connection, collection, "getconnection", 2504689909UL); - - PHALCON_INIT_VAR(unique); - ZVAL_BOOL(unique, 1); - PHALCON_CALL_SELF_PARAMS_4(return_value, this_ptr, "_getresultset", parameters, collection, connection, unique); + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "PUT", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Collection, find){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, addPatch){ - zval *parameters = NULL, *class_name, *collection, *connection; - zval *unique; - zend_class_entry *ce0; + zval *pattern, *paths = NULL, *method; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for find"); - return; - } + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_INIT_VAR(class_name); - phalcon_get_called_class(class_name TSRMLS_CC); - ce0 = phalcon_fetch_class(class_name TSRMLS_CC); + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "PATCH", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Group, addDelete){ + + zval *pattern, *paths = NULL, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - PHALCON_INIT_VAR(collection); - object_init_ex(collection, ce0); - if (phalcon_has_constructor(collection TSRMLS_CC)) { - phalcon_call_method_key(NULL, collection, "__construct", 1107214344UL); + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_INIT_VAR(connection); - phalcon_call_method_key(connection, collection, "getconnection", 2504689909UL); - - PHALCON_INIT_VAR(unique); - ZVAL_BOOL(unique, 0); - PHALCON_CALL_SELF_PARAMS_4(return_value, this_ptr, "_getresultset", parameters, collection, connection, unique); + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "DELETE", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Collection, count){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, addOptions){ - zval *parameters = NULL, *class_name, *collection, *connection; - zend_class_entry *ce0; + zval *pattern, *paths = NULL, *method; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for count"); - return; - } + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_INIT_VAR(class_name); - phalcon_get_called_class(class_name TSRMLS_CC); - ce0 = phalcon_fetch_class(class_name TSRMLS_CC); + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "OPTIONS", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Group, addHead){ + + zval *pattern, *paths = NULL, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - PHALCON_INIT_VAR(collection); - object_init_ex(collection, ce0); - if (phalcon_has_constructor(collection TSRMLS_CC)) { - phalcon_call_method_key(NULL, collection, "__construct", 1107214344UL); + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_INIT_VAR(connection); - phalcon_call_method_key(connection, collection, "getconnection", 2504689909UL); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_getgroupresultset", parameters, collection, connection); + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "HEAD", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, method, 1178487196UL); RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Collection, aggregate){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, clear){ + + zval *empty_routes; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(empty_routes); + array_init(empty_routes); + phalcon_update_property_this_quick(this_ptr, SL("_routes"), empty_routes, 2063827110UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Route){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Router, Route, mvc_router_route, phalcon_mvc_router_route_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_pattern"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_compiledPattern"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_paths"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_methods"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_hostname"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_converters"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_id"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_beforeMatch"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_route_ce, SL("_uniqueId"), ZEND_ACC_STATIC|ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_router_route_ce TSRMLS_CC, 1, phalcon_mvc_router_routeinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Router_Route, __construct){ - zval *parameters, *class_name, *model, *connection; - zval *source, *collection; - zend_class_entry *ce0; + zval *pattern, *paths = NULL, *http_methods = NULL, *unique_id = NULL; + zval *route_id = NULL, *one, *next_id; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); + phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); - if (Z_TYPE_P(parameters) != IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Invalid parameters for aggregate"); - return; - } + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_INIT_VAR(class_name); - phalcon_get_called_class(class_name TSRMLS_CC); - ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - - PHALCON_INIT_VAR(model); - object_init_ex(model, ce0); - if (phalcon_has_constructor(model TSRMLS_CC)) { - phalcon_call_method_key(NULL, model, "__construct", 1107214344UL); + if (!http_methods) { + PHALCON_INIT_VAR(http_methods); } - PHALCON_INIT_VAR(connection); - phalcon_call_method_key(connection, model, "getconnection", 2504689909UL); + phalcon_call_method_p2_key(NULL, this_ptr, "reconfigure", pattern, paths, 18237790UL); - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, model, "getsource", 2025234358UL); - if (PHALCON_IS_EMPTY(source)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); - return; + phalcon_update_property_this_quick(this_ptr, SL("_methods"), http_methods, 960170392UL TSRMLS_CC); + + PHALCON_OBS_VAR(unique_id); + phalcon_read_static_property(&unique_id, SL("phalcon\\mvc\\router\\route"), SL("_uniqueId") TSRMLS_CC); + if (Z_TYPE_P(unique_id) == IS_NULL) { + PHALCON_INIT_NVAR(unique_id); + ZVAL_LONG(unique_id, 0); } - PHALCON_INIT_VAR(collection); - phalcon_call_method_p1_key(collection, connection, "selectcollection", source, 3563037297UL); - phalcon_call_method_p1_key(return_value, collection, "aggregate", parameters, 3838056268UL); - RETURN_MM(); + PHALCON_CPY_WRT(route_id, unique_id); + phalcon_update_property_this_quick(this_ptr, SL("_id"), route_id, 2090005265UL TSRMLS_CC); + + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + + PHALCON_INIT_VAR(next_id); + phalcon_add_function(next_id, unique_id, one TSRMLS_CC); + phalcon_update_static_property(SL("phalcon\\mvc\\router\\route"), SL("_uniqueId"), next_id TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Collection, summatory){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, compilePattern){ - zval *field, *conditions = NULL, *finalize = NULL, *class_name; - zval *model, *connection, *source, *collection; - zval *keys, *empty_array, *initial, *reduce, *group; - zval *retval, *first_retval, *summatory; - zend_class_entry *ce0; + zval *pattern, *compiled_pattern = NULL, *id_pattern; + zval *wildcard = NULL, *pattern_copy = NULL, *params_pattern; + zval *int_pattern; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &field, &conditions, &finalize); + phalcon_fetch_params(1, 1, 0, &pattern); - if (!conditions) { - PHALCON_INIT_VAR(conditions); - } + PHALCON_CPY_WRT(compiled_pattern, pattern); - if (!finalize) { - PHALCON_INIT_VAR(finalize); - } + if (phalcon_memnstr_str(pattern, SL(":"))) { - 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(id_pattern); + ZVAL_STRING(id_pattern, "/([a-zA-Z0-9\\_\\-]+)", 1); - PHALCON_INIT_VAR(class_name); - phalcon_get_called_class(class_name TSRMLS_CC); - ce0 = phalcon_fetch_class(class_name TSRMLS_CC); + if (phalcon_memnstr_str(pattern, SL("/:module"))) { + PHALCON_INIT_VAR(wildcard); + ZVAL_STRING(wildcard, "/:module", 1); + PHALCON_CPY_WRT(pattern_copy, compiled_pattern); - PHALCON_INIT_VAR(model); - object_init_ex(model, ce0); - if (phalcon_has_constructor(model TSRMLS_CC)) { - phalcon_call_method_key(NULL, model, "__construct", 1107214344UL); - } + PHALCON_INIT_NVAR(compiled_pattern); + phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); + } - PHALCON_INIT_VAR(connection); - phalcon_call_method_key(connection, model, "getconnection", 2504689909UL); + if (phalcon_memnstr_str(pattern, SL("/:controller"))) { + PHALCON_INIT_NVAR(wildcard); + ZVAL_STRING(wildcard, "/:controller", 1); + PHALCON_CPY_WRT(pattern_copy, compiled_pattern); - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, model, "getsource", 2025234358UL); - if (PHALCON_IS_EMPTY(source)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); - return; - } + PHALCON_INIT_NVAR(compiled_pattern); + phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); + } - PHALCON_INIT_VAR(collection); - phalcon_call_method_p1_key(collection, connection, "selectcollection", source, 3563037297UL); + if (phalcon_memnstr_str(pattern, SL("/:namespace"))) { + PHALCON_INIT_NVAR(wildcard); + ZVAL_STRING(wildcard, "/:namespace", 1); + PHALCON_CPY_WRT(pattern_copy, compiled_pattern); - PHALCON_INIT_VAR(keys); - array_init(keys); + PHALCON_INIT_NVAR(compiled_pattern); + phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); + } - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); + if (phalcon_memnstr_str(pattern, SL("/:action"))) { + PHALCON_INIT_NVAR(wildcard); + ZVAL_STRING(wildcard, "/:action", 1); + PHALCON_CPY_WRT(pattern_copy, compiled_pattern); - PHALCON_INIT_VAR(initial); - array_init_size(initial, 1); - phalcon_array_update_quick_string(&initial, SS("summatory"), 2358676118UL, &empty_array, PH_COPY | PH_SEPARATE); + PHALCON_INIT_NVAR(compiled_pattern); + phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_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_INIT_VAR(group); - phalcon_call_method_p3_key(group, collection, "group", keys, initial, reduce, 7349554UL); - if (phalcon_array_isset_quick_string(group, SS("retval"), 1060973715UL)) { + if (phalcon_memnstr_str(pattern, SL("/:params"))) { + PHALCON_INIT_NVAR(wildcard); + ZVAL_STRING(wildcard, "/:params", 1); - PHALCON_OBS_VAR(retval); - phalcon_array_fetch_quick_string(&retval, group, SS("retval"), 1060973715UL, PH_NOISY); - if (phalcon_array_isset_long(retval, 0)) { + PHALCON_INIT_VAR(params_pattern); + ZVAL_STRING(params_pattern, "(/.*)*", 1); + PHALCON_CPY_WRT(pattern_copy, compiled_pattern); - 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)) { - PHALCON_OBS_VAR(summatory); - phalcon_array_fetch_quick_string(&summatory, first_retval, SS("summatory"), 2358676118UL, PH_NOISY); - RETURN_CCTOR(summatory); - } + PHALCON_INIT_NVAR(compiled_pattern); + phalcon_fast_str_replace(compiled_pattern, wildcard, params_pattern, pattern_copy); + } - RETURN_CCTOR(first_retval); + if (phalcon_memnstr_str(pattern, SL("/:int"))) { + PHALCON_INIT_NVAR(wildcard); + ZVAL_STRING(wildcard, "/:int", 1); + + PHALCON_INIT_VAR(int_pattern); + ZVAL_STRING(int_pattern, "/([0-9]+)", 1); + PHALCON_CPY_WRT(pattern_copy, compiled_pattern); + + PHALCON_INIT_NVAR(compiled_pattern); + phalcon_fast_str_replace(compiled_pattern, wildcard, int_pattern, pattern_copy); } + } - RETURN_CCTOR(retval); + if (phalcon_memnstr_str(compiled_pattern, SL("("))) { + PHALCON_CONCAT_SVS(return_value, "#^", compiled_pattern, "$#"); + RETURN_MM(); } - PHALCON_MM_RESTORE(); + if (phalcon_memnstr_str(compiled_pattern, SL("["))) { + PHALCON_CONCAT_SVS(return_value, "#^", compiled_pattern, "$#"); + RETURN_MM(); + } + + RETURN_CCTOR(compiled_pattern); } -static PHP_METHOD(Phalcon_Mvc_Collection, delete){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, via){ - zval *disable_events, *event_name = NULL, *status = NULL, *id; - zval *connection, *source, *collection, *mongo_id = NULL; - zval *models_manager, *use_implicit_ids, *id_condition; - zval *success = NULL, *options, *ok; - zend_class_entry *ce0; + zval *http_methods; + + phalcon_fetch_params(0, 1, 0, &http_methods); + + phalcon_update_property_this_quick(this_ptr, SL("_methods"), http_methods, 960170392UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Route, reConfigure){ + + zval *pattern, *paths = NULL, *module_name = NULL, *controller_name = NULL; + zval *action_name = NULL, *parts, *number_parts, *route_paths = NULL; + zval *real_class_name = NULL, *namespace_name, *lower_name; + zval *pcre_pattern = NULL, *compiled_pattern = NULL; PHALCON_MM_GROW(); - if (!phalcon_isset_property(this_ptr, SS("_id") TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The document cannot be deleted because it doesn't exist"); + phalcon_fetch_params(1, 1, 1, &pattern, &paths); + + if (!paths) { + PHALCON_INIT_VAR(paths); + } + + if (Z_TYPE_P(pattern) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The pattern must be string"); return; } + if (Z_TYPE_P(paths) != IS_NULL) { + if (Z_TYPE_P(paths) == IS_STRING) { - PHALCON_OBS_VAR(disable_events); - phalcon_read_static_property(&disable_events, SL("phalcon\\mvc\\collection"), SL("_disableEvents") TSRMLS_CC); - if (!zend_is_true(disable_events)) { + PHALCON_INIT_VAR(module_name); - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "beforeDelete", 1); + PHALCON_INIT_VAR(controller_name); - PHALCON_INIT_VAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } + PHALCON_INIT_VAR(action_name); - PHALCON_OBS_VAR(id); - phalcon_read_property_this_quick(&id, this_ptr, SL("_id"), 2090005265UL, PH_NOISY_CC); + PHALCON_INIT_VAR(parts); + phalcon_fast_explode_str(parts, SL("::"), paths); - PHALCON_INIT_VAR(connection); - phalcon_call_method_key(connection, this_ptr, "getconnection", 2504689909UL); + PHALCON_INIT_VAR(number_parts); + phalcon_fast_count(number_parts, parts TSRMLS_CC); - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); - if (PHALCON_IS_EMPTY(source)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "Method getSource() returns empty string"); - return; - } - PHALCON_INIT_VAR(collection); - phalcon_call_method_p1_key(collection, connection, "selectcollection", source, 3563037297UL); - if (Z_TYPE_P(id) == IS_OBJECT) { - PHALCON_CPY_WRT(mongo_id, id); - } else { - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + switch (phalcon_get_intval(number_parts)) { - PHALCON_INIT_VAR(use_implicit_ids); - phalcon_call_method_p1_key(use_implicit_ids, models_manager, "isusingimplicitobjectids", this_ptr, 3521236505UL); - if (zend_is_true(use_implicit_ids)) { - ce0 = zend_fetch_class(SL("MongoId"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - PHALCON_INIT_NVAR(mongo_id); - object_init_ex(mongo_id, ce0); - if (phalcon_has_constructor(mongo_id TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, mongo_id, "__construct", id, 1107214344UL); - } - } else { - PHALCON_CPY_WRT(mongo_id, id); - } - } + case 3: + PHALCON_OBS_NVAR(module_name); + phalcon_array_fetch_long(&module_name, parts, 0, PH_NOISY); - PHALCON_INIT_VAR(id_condition); - array_init_size(id_condition, 1); - phalcon_array_update_quick_string(&id_condition, SS("_id"), 2090005265UL, &mongo_id, PH_COPY | PH_SEPARATE); + PHALCON_OBS_NVAR(controller_name); + phalcon_array_fetch_long(&controller_name, parts, 1, PH_NOISY); - PHALCON_INIT_VAR(success); - ZVAL_BOOL(success, 0); + PHALCON_OBS_NVAR(action_name); + phalcon_array_fetch_long(&action_name, parts, 2, PH_NOISY); + break; - PHALCON_INIT_VAR(options); - array_init_size(options, 1); - add_assoc_bool_ex(options, SS("safe"), 1); + case 2: + PHALCON_OBS_NVAR(controller_name); + phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, collection, "remove", id_condition, options, 1052443347UL); - if (Z_TYPE_P(status) != IS_ARRAY) { - RETURN_MM_FALSE; - } + PHALCON_OBS_NVAR(action_name); + phalcon_array_fetch_long(&action_name, parts, 1, PH_NOISY); + break; - if (phalcon_array_isset_quick_string(status, SS("ok"), 193501407UL)) { + case 1: + PHALCON_OBS_NVAR(controller_name); + phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); + break; - 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); - ZVAL_STRING(event_name, "afterDelete", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + PHALCON_INIT_VAR(route_paths); + array_init(route_paths); + + if (Z_TYPE_P(module_name) != IS_NULL) { + phalcon_array_update_quick_string(&route_paths, SS("module"), 3565923467UL, &module_name, PH_COPY | PH_SEPARATE); } - } - } else { - PHALCON_INIT_NVAR(success); - ZVAL_BOOL(success, 0); - } - RETURN_NCTOR(success); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, toArray){ - - zval *data, *reserved, *properties, *value = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(data); - array_init(data); + if (Z_TYPE_P(controller_name) != IS_NULL) { - PHALCON_INIT_VAR(reserved); - phalcon_call_method_key(reserved, this_ptr, "getreservedattributes", 3061016044UL); + if (phalcon_memnstr_str(controller_name, SL("\\"))) { - PHALCON_INIT_VAR(properties); - phalcon_call_func_p1(properties, "get_object_vars", this_ptr); + PHALCON_INIT_VAR(real_class_name); + phalcon_get_class_ns(real_class_name, controller_name, 0 TSRMLS_CC); - phalcon_is_iterable(properties, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(namespace_name); + phalcon_get_ns_class(namespace_name, controller_name, 0 TSRMLS_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (zend_is_true(namespace_name)) { + phalcon_array_update_quick_string(&route_paths, SS("namespace"), 545490034UL, &namespace_name, PH_COPY | PH_SEPARATE); + } + } else { + PHALCON_CPY_WRT(real_class_name, controller_name); + } - PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + PHALCON_INIT_VAR(lower_name); + phalcon_uncamelize(lower_name, real_class_name); - if (PHALCON_IS_STRING(key, "_id")) { + phalcon_array_update_quick_string(&route_paths, SS("controller"), 2892024105UL, &lower_name, PH_COPY | PH_SEPARATE); + } - if (Z_TYPE_P(value) != IS_NULL) { - phalcon_array_update_zval(&data, key, &value, PH_COPY | PH_SEPARATE); + if (Z_TYPE_P(action_name) != IS_NULL) { + phalcon_array_update_quick_string(&route_paths, SS("action"), 502132067UL, &action_name, PH_COPY | PH_SEPARATE); } } else { - if (!phalcon_array_isset(reserved, key)) { - phalcon_array_update_zval(&data, key, &value, PH_COPY | PH_SEPARATE); - } + PHALCON_CPY_WRT(route_paths, paths); } + } else { + PHALCON_INIT_NVAR(route_paths); + array_init(route_paths); + } - zend_hash_move_forward_ex(ah0, &hp0); + if (Z_TYPE_P(route_paths) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The route contains invalid paths"); + return; } - RETURN_CTOR(data); + if (!phalcon_start_with_str(pattern, SL("#"))) { + if (phalcon_memnstr_str(pattern, SL("{"))) { + PHALCON_INIT_VAR(pcre_pattern); + phalcon_extract_named_params(pcre_pattern, pattern, route_paths); + } else { + PHALCON_CPY_WRT(pcre_pattern, pattern); + } + + PHALCON_INIT_VAR(compiled_pattern); + phalcon_call_method_p1_key(compiled_pattern, this_ptr, "compilepattern", pcre_pattern, 2680336012UL); + } else { + PHALCON_CPY_WRT(compiled_pattern, pattern); + } + + phalcon_update_property_this_quick(this_ptr, SL("_pattern"), pattern, 3404429922UL TSRMLS_CC); + + phalcon_update_property_this_quick(this_ptr, SL("_compiledPattern"), compiled_pattern, 4104436623UL TSRMLS_CC); + + phalcon_update_property_this_quick(this_ptr, SL("_paths"), route_paths, 2700778884UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Collection, serialize){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, getName){ - zval *data; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); +} - PHALCON_INIT_VAR(data); - phalcon_call_method_key(data, this_ptr, "toarray", 3566966151UL); +static PHP_METHOD(Phalcon_Mvc_Router_Route, setName){ + + zval *name; + + phalcon_fetch_params(0, 1, 0, &name); - phalcon_serialize(return_value, &data TSRMLS_CC); - RETURN_MM(); + phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Collection, unserialize){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, beforeMatch){ - zval *data, *attributes, *dependency_injector; - zval *service, *manager, *value = NULL, *key = NULL; + zval *callback; + + phalcon_fetch_params(0, 1, 0, &callback); + + phalcon_update_property_this_quick(this_ptr, SL("_beforeMatch"), callback, 2834072708UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Route, getBeforeMatch){ + + + RETURN_MEMBER_QUICK(this_ptr, "_beforeMatch", 2834072708UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Route, getRouteId){ + + + RETURN_MEMBER_QUICK(this_ptr, "_id", 2090005265UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Route, getPattern){ + + + RETURN_MEMBER_QUICK(this_ptr, "_pattern", 3404429922UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Route, getCompiledPattern){ + + + RETURN_MEMBER_QUICK(this_ptr, "_compiledPattern", 4104436623UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Route, getPaths){ + + + RETURN_MEMBER_QUICK(this_ptr, "_paths", 2700778884UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router_Route, getReversedPaths){ + + zval *reversed, *paths, *position = NULL, *path = NULL; HashTable *ah0; HashPosition hp0; zval **hd; 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) { - - PHALCON_INIT_VAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_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_INIT_VAR(manager); - phalcon_call_method_p1_key(manager, dependency_injector, "getshared", service, 1727570332UL); - if (Z_TYPE_P(manager) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The injected service 'collectionManager' is not valid"); - return; - } - - phalcon_update_property_this_quick(this_ptr, SL("_modelsManager"), manager, 3699347875UL TSRMLS_CC); + PHALCON_INIT_VAR(reversed); + array_init(reversed); - phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(paths); + phalcon_read_property_this_quick(&paths, this_ptr, SL("_paths"), 2700778884UL, PH_NOISY_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + phalcon_is_iterable(paths, &ah0, &hp0, 0, 0); - PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); + PHALCON_GET_HKEY(path, ah0, hp0); + PHALCON_GET_HVALUE(position); - zend_hash_move_forward_ex(ah0, &hp0); - } + phalcon_array_update_zval(&reversed, position, &path, PH_COPY | PH_SEPARATE); - RETURN_MM_NULL(); - } + zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid serialization data"); - return; + + RETURN_CTOR(reversed); } +static PHP_METHOD(Phalcon_Mvc_Router_Route, setHttpMethods){ + zval *http_methods; + phalcon_fetch_params(0, 1, 0, &http_methods); + + phalcon_update_property_this_quick(this_ptr, SL("_methods"), http_methods, 960170392UL TSRMLS_CC); + RETURN_THISW(); +} - -#ifdef HAVE_CONFIG_H -#endif +static PHP_METHOD(Phalcon_Mvc_Router_Route, getHttpMethods){ + RETURN_MEMBER_QUICK(this_ptr, "_methods", 960170392UL); +} -PHALCON_INIT_CLASS(Phalcon_Mvc_ModelInterface){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, setHostname){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ModelInterface, mvc_modelinterface, phalcon_mvc_modelinterface_method_entry); + zval *hostname; - return SUCCESS; + phalcon_fetch_params(0, 1, 0, &hostname); + + phalcon_update_property_this_quick(this_ptr, SL("_hostname"), hostname, 598751491UL TSRMLS_CC); + RETURN_THISW(); } +static PHP_METHOD(Phalcon_Mvc_Router_Route, getHostname){ + RETURN_MEMBER_QUICK(this_ptr, "_hostname", 598751491UL); +} +static PHP_METHOD(Phalcon_Mvc_Router_Route, convert){ + zval *name, *converter; + phalcon_fetch_params(0, 2, 0, &name, &converter); + + phalcon_update_property_array(this_ptr, SL("_converters"), name, converter TSRMLS_CC); + RETURN_THISW(); +} +static PHP_METHOD(Phalcon_Mvc_Router_Route, getConverters){ + RETURN_MEMBER_QUICK(this_ptr, "_converters", 994353007UL); +} +static PHP_METHOD(Phalcon_Mvc_Router_Route, reset){ + zval *zero; + PHALCON_MM_GROW(); + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + phalcon_update_static_property(SL("phalcon\\mvc\\router\\route"), SL("_uniqueId"), zero TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} +#ifdef HAVE_CONFIG_H +#endif +PHALCON_INIT_CLASS(Phalcon_Mvc_Router_RouteInterface){ + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Router, RouteInterface, mvc_router_routeinterface, phalcon_mvc_router_routeinterface_method_entry); - + return SUCCESS; +} @@ -80277,7191 +78848,8227 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_ModelInterface){ -PHALCON_INIT_CLASS(Phalcon_Mvc_View){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Router){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, View, mvc_view, "phalcon\\di\\injectable", phalcon_mvc_view_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Mvc, Router, mvc_router, phalcon_mvc_router_method_entry, 0); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_mvc_view_ce, SL("_basePath"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_mvc_view_ce, SL("_content"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_view_ce, SL("_renderLevel"), 5, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_disabledLevels"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_viewParams"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_layout"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_mvc_view_ce, SL("_layoutsDir"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_mvc_view_ce, SL("_partialsDir"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_viewsDir"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_templatesBefore"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_templatesAfter"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_view_ce, SL("_engines"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_registeredEngines"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_mvc_view_ce, SL("_mainView"), "index", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_controllerName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_actionName"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_params"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_pickView"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_cache"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_view_ce, SL("_cacheLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_view_ce, SL("_activeRenderPath"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_mvc_view_ce, SL("_disabled"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_uriSource"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_namespace"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_module"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_controller"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_action"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_params"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_routes"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_matchedRoute"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_matches"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_router_ce, SL("_wasMatched"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_defaultNamespace"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_defaultModule"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_defaultController"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_defaultAction"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_defaultParams"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_removeExtraSlashes"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_router_ce, SL("_notFoundPaths"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_MAIN_LAYOUT"), 5 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_AFTER_TEMPLATE"), 4 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_LAYOUT"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_BEFORE_TEMPLATE"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_ACTION_VIEW"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_NO_RENDER"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_router_ce, SL("URI_SOURCE_GET_URL"), 0 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_router_ce, SL("URI_SOURCE_SERVER_REQUEST_URI"), 1 TSRMLS_CC); - zend_class_implements(phalcon_mvc_view_ce TSRMLS_CC, 1, phalcon_mvc_viewinterface_ce); + zend_class_implements(phalcon_mvc_router_ce TSRMLS_CC, 2, phalcon_mvc_routerinterface_ce, phalcon_di_injectionawareinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_View, __construct){ +static PHP_METHOD(Phalcon_Mvc_Router, __construct){ - zval *options = NULL; + zval *default_routes = NULL, *routes, *paths = NULL, *action_pattern; + zval *route = NULL, *params_pattern, *params; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &options); + phalcon_update_property_empty_array(phalcon_mvc_router_ce, this_ptr, SL("_defaultParams") TSRMLS_CC); - if (!options) { - PHALCON_INIT_VAR(options); + phalcon_fetch_params(1, 0, 1, &default_routes); + + if (!default_routes) { + PHALCON_INIT_VAR(default_routes); + ZVAL_BOOL(default_routes, 1); } - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + PHALCON_INIT_VAR(routes); + array_init(routes); + if (PHALCON_IS_TRUE(default_routes)) { + PHALCON_INIT_VAR(paths); + array_init_size(paths, 1); + add_assoc_long_ex(paths, SS("controller"), 1); + + PHALCON_INIT_VAR(action_pattern); + ZVAL_STRING(action_pattern, "#^/([a-zA-Z0-9\\_\\-]+)[/]{0,1}$#", 1); + + PHALCON_INIT_VAR(route); + object_init_ex(route, phalcon_mvc_router_route_ce); + phalcon_call_method_p2_key(NULL, route, "__construct", action_pattern, paths, 1107214344UL); + + phalcon_array_append(&routes, route, PH_SEPARATE); + + PHALCON_INIT_NVAR(paths); + array_init_size(paths, 3); + add_assoc_long_ex(paths, SS("controller"), 1); + add_assoc_long_ex(paths, SS("action"), 2); + add_assoc_long_ex(paths, SS("params"), 3); + + PHALCON_INIT_VAR(params_pattern); + ZVAL_STRING(params_pattern, "#^/([a-zA-Z0-9\\_\\-]+)/([a-zA-Z0-9\\.\\_]+)(/.*)*$#", 1); + + PHALCON_INIT_NVAR(route); + object_init_ex(route, phalcon_mvc_router_route_ce); + phalcon_call_method_p2_key(NULL, route, "__construct", params_pattern, paths, 1107214344UL); + + phalcon_array_append(&routes, route, PH_SEPARATE); } + PHALCON_INIT_VAR(params); + array_init(params); + phalcon_update_property_this_quick(this_ptr, SL("_params"), params, 3223731112UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_routes"), routes, 2063827110UL TSRMLS_CC); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_View, setViewsDir){ +static PHP_METHOD(Phalcon_Mvc_Router, setDI){ - zval *views_dir; + zval *dependency_injector; - phalcon_fetch_params(0, 1, 0, &views_dir); + phalcon_fetch_params(0, 1, 0, &dependency_injector); - if (Z_TYPE_P(views_dir) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "The views directory must be a string"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_viewsDir"), views_dir, 3398309201UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View, getViewsDir){ +static PHP_METHOD(Phalcon_Mvc_Router, getDI){ - RETURN_MEMBER_QUICK(this_ptr, "_viewsDir", 3398309201UL); + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -static PHP_METHOD(Phalcon_Mvc_View, setLayoutsDir){ - - zval *layouts_dir; - - phalcon_fetch_params(0, 1, 0, &layouts_dir); - - phalcon_update_property_this_quick(this_ptr, SL("_layoutsDir"), layouts_dir, 313056692UL TSRMLS_CC); - RETURN_THISW(); -} +static PHP_METHOD(Phalcon_Mvc_Router, getRewriteUri){ -static PHP_METHOD(Phalcon_Mvc_View, getLayoutsDir){ + zval *uri_source, *_GET, *url = NULL, *_SERVER, *url_parts; + zval *real_uri; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_layoutsDir", 313056692UL); + PHALCON_OBS_VAR(uri_source); + phalcon_read_property_this_quick(&uri_source, this_ptr, SL("_uriSource"), 144947845UL, PH_NOISY_CC); + + if (!zend_is_true(uri_source)) { + phalcon_get_global(&_GET, SS("_GET") TSRMLS_CC); + if (phalcon_array_isset_quick_string(_GET, SS("_url"), 251147063UL)) { + + PHALCON_OBS_VAR(url); + phalcon_array_fetch_quick_string(&url, _GET, SS("_url"), 251147063UL, PH_NOISY); + if (PHALCON_IS_NOT_EMPTY(url)) { + RETURN_CCTOR(url); + } + } + } else { + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + if (phalcon_array_isset_quick_string(_SERVER, SS("REQUEST_URI"), 1526037309UL)) { + + PHALCON_OBS_NVAR(url); + phalcon_array_fetch_quick_string(&url, _SERVER, SS("REQUEST_URI"), 1526037309UL, PH_NOISY); + + PHALCON_INIT_VAR(url_parts); + phalcon_fast_explode_str(url_parts, SL("?"), url); + + PHALCON_OBS_VAR(real_uri); + phalcon_array_fetch_long(&real_uri, url_parts, 0, PH_NOISY); + if (PHALCON_IS_NOT_EMPTY(real_uri)) { + RETURN_CCTOR(real_uri); + } + } + } + + RETURN_MM_STRING("/", 1); } -static PHP_METHOD(Phalcon_Mvc_View, setPartialsDir){ +static PHP_METHOD(Phalcon_Mvc_Router, setUriSource){ - zval *partials_dir; + zval *uri_source; - phalcon_fetch_params(0, 1, 0, &partials_dir); + phalcon_fetch_params(0, 1, 0, &uri_source); - phalcon_update_property_this_quick(this_ptr, SL("_partialsDir"), partials_dir, 2130168739UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_uriSource"), uri_source, 144947845UL TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View, getPartialsDir){ - - - RETURN_MEMBER_QUICK(this_ptr, "_partialsDir", 2130168739UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, setBasePath){ +static PHP_METHOD(Phalcon_Mvc_Router, removeExtraSlashes){ - zval *base_path; + zval *remove; - phalcon_fetch_params(0, 1, 0, &base_path); + phalcon_fetch_params(0, 1, 0, &remove); - phalcon_update_property_this_quick(this_ptr, SL("_basePath"), base_path, 1477430348UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_removeExtraSlashes"), remove, 1065444329UL TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View, setRenderLevel){ +static PHP_METHOD(Phalcon_Mvc_Router, setDefaultNamespace){ - zval *level; + zval *namespace_name; - phalcon_fetch_params(0, 1, 0, &level); + phalcon_fetch_params(0, 1, 0, &namespace_name); - phalcon_update_property_this_quick(this_ptr, SL("_renderLevel"), level, 3194989084UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_defaultNamespace"), namespace_name, 761145590UL TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View, disableLevel){ - - zval *level, *disabled; +static PHP_METHOD(Phalcon_Mvc_Router, setDefaultModule){ - PHALCON_MM_GROW(); + zval *module_name; - phalcon_fetch_params(1, 1, 0, &level); - - if (Z_TYPE_P(level) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_disabledLevels"), level, 1575004551UL TSRMLS_CC); - } else { - PHALCON_INIT_VAR(disabled); - ZVAL_BOOL(disabled, 1); - phalcon_update_property_array(this_ptr, SL("_disabledLevels"), level, disabled TSRMLS_CC); - } + phalcon_fetch_params(0, 1, 0, &module_name); - RETURN_THIS(); + phalcon_update_property_this_quick(this_ptr, SL("_defaultModule"), module_name, 3959488399UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View, setMainView){ +static PHP_METHOD(Phalcon_Mvc_Router, setDefaultController){ - zval *view_path; + zval *controller_name; - phalcon_fetch_params(0, 1, 0, &view_path); + phalcon_fetch_params(0, 1, 0, &controller_name); - phalcon_update_property_this_quick(this_ptr, SL("_mainView"), view_path, 1829858724UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_defaultController"), controller_name, 1418722861UL TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View, getMainView){ - - - RETURN_MEMBER_QUICK(this_ptr, "_mainView", 1829858724UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, setLayout){ +static PHP_METHOD(Phalcon_Mvc_Router, setDefaultAction){ - zval *layout; + zval *action_name; - phalcon_fetch_params(0, 1, 0, &layout); + phalcon_fetch_params(0, 1, 0, &action_name); - phalcon_update_property_this_quick(this_ptr, SL("_layout"), layout, 2361639842UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_defaultAction"), action_name, 895696999UL TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View, getLayout){ - - - RETURN_MEMBER_QUICK(this_ptr, "_layout", 2361639842UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, setTemplateBefore){ +static PHP_METHOD(Phalcon_Mvc_Router, setDefaults){ - zval *template_before, *array_template; + zval *defaults, *namespace_name, *module_name; + zval *controller_name, *action_name, *params; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &template_before); + phalcon_fetch_params(1, 1, 0, &defaults); - if (Z_TYPE_P(template_before) != IS_ARRAY) { - PHALCON_INIT_VAR(array_template); - array_init_size(array_template, 1); - phalcon_array_append(&array_template, template_before, PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_templatesBefore"), array_template, 3273177030UL TSRMLS_CC); - } else { - phalcon_update_property_this_quick(this_ptr, SL("_templatesBefore"), template_before, 3273177030UL TSRMLS_CC); + if (Z_TYPE_P(defaults) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "Defaults must be an array"); + return; + } + + if (phalcon_array_isset_quick_string(defaults, SS("namespace"), 545490034UL)) { + PHALCON_OBS_VAR(namespace_name); + phalcon_array_fetch_quick_string(&namespace_name, defaults, SS("namespace"), 545490034UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_defaultNamespace"), namespace_name, 761145590UL TSRMLS_CC); + } + + if (phalcon_array_isset_quick_string(defaults, SS("module"), 3565923467UL)) { + PHALCON_OBS_VAR(module_name); + phalcon_array_fetch_quick_string(&module_name, defaults, SS("module"), 3565923467UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_defaultModule"), module_name, 3959488399UL TSRMLS_CC); + } + + if (phalcon_array_isset_quick_string(defaults, SS("controller"), 2892024105UL)) { + PHALCON_OBS_VAR(controller_name); + phalcon_array_fetch_quick_string(&controller_name, defaults, SS("controller"), 2892024105UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_defaultController"), controller_name, 1418722861UL TSRMLS_CC); + } + + if (phalcon_array_isset_quick_string(defaults, SS("action"), 502132067UL)) { + PHALCON_OBS_VAR(action_name); + phalcon_array_fetch_quick_string(&action_name, defaults, SS("action"), 502132067UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_defaultAction"), action_name, 895696999UL TSRMLS_CC); + } + + if (phalcon_array_isset_quick_string(defaults, SS("params"), 2613350281UL)) { + PHALCON_OBS_VAR(params); + phalcon_array_fetch_quick_string(¶ms, defaults, SS("params"), 2613350281UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_defaultParams"), params, 3006915213UL TSRMLS_CC); } RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_View, cleanTemplateBefore){ - - - phalcon_update_property_null(this_ptr, SL("_templatesBefore") TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, setTemplateAfter){ +static PHP_METHOD(Phalcon_Mvc_Router, handle){ - zval *template_after, *array_template; + zval *uri = NULL, *real_uri = NULL, *remove_extra_slashes; + zval *handled_uri = NULL, *request = NULL, *current_host_name = NULL; + zval *route_found = NULL, *parts = NULL, *params = NULL, *matches, *routes; + zval *route = NULL, *methods = NULL, *dependency_injector = NULL; + zval *service = NULL, *match_method = NULL, *hostname = NULL, *regex_host_name = NULL; + zval *matched = NULL, *pattern = NULL, *before_match = NULL, *before_match_params = NULL; + zval *paths = NULL, *converters = NULL, *position = NULL, *part = NULL, *match_position = NULL; + zval *parameters = NULL, *converter = NULL, *converted_part = NULL; + zval *not_found_paths, *namespace, *default_namespace = NULL; + zval *module, *default_module = NULL, *controller, *default_controller = NULL; + zval *action, *default_action = NULL, *params_str, *str_params; + zval *slash, *params_merge = NULL, *default_params; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &template_after); + phalcon_fetch_params(1, 0, 1, &uri); - if (Z_TYPE_P(template_after) != IS_ARRAY) { - PHALCON_INIT_VAR(array_template); - array_init_size(array_template, 1); - phalcon_array_append(&array_template, template_after, PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_templatesAfter"), array_template, 3575793989UL TSRMLS_CC); + if (!uri) { + PHALCON_INIT_VAR(uri); + } + + if (!zend_is_true(uri)) { + PHALCON_INIT_VAR(real_uri); + phalcon_call_method_key(real_uri, this_ptr, "getrewriteuri", 1631494103UL); } else { - phalcon_update_property_this_quick(this_ptr, SL("_templatesAfter"), template_after, 3575793989UL TSRMLS_CC); + PHALCON_CPY_WRT(real_uri, uri); } - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_View, cleanTemplateAfter){ - - - phalcon_update_property_null(this_ptr, SL("_templatesAfter") TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, setParamToView){ - - zval *key, *value; - - phalcon_fetch_params(0, 2, 0, &key, &value); + PHALCON_OBS_VAR(remove_extra_slashes); + phalcon_read_property_this_quick(&remove_extra_slashes, this_ptr, SL("_removeExtraSlashes"), 1065444329UL, PH_NOISY_CC); + if (zend_is_true(remove_extra_slashes)) { + PHALCON_INIT_VAR(handled_uri); + phalcon_remove_extra_slashes(handled_uri, real_uri); + } else { + PHALCON_CPY_WRT(handled_uri, real_uri); + } - phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, setVars){ - - zval *params, *merge = NULL, *view_params, *merged_params = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, ¶ms, &merge); + PHALCON_INIT_VAR(request); + + PHALCON_INIT_VAR(current_host_name); + + PHALCON_INIT_VAR(route_found); + ZVAL_BOOL(route_found, 0); + + PHALCON_INIT_VAR(parts); + array_init(parts); + + PHALCON_INIT_VAR(params); + array_init(params); + + PHALCON_INIT_VAR(matches); + phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 0 TSRMLS_CC); + phalcon_update_property_null(this_ptr, SL("_matchedRoute") TSRMLS_CC); + + PHALCON_OBS_VAR(routes); + phalcon_read_property_this_quick(&routes, this_ptr, SL("_routes"), 2063827110UL, PH_NOISY_CC); + + phalcon_is_iterable(routes, &ah0, &hp0, 0, 1); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(route); + + PHALCON_INIT_NVAR(methods); + phalcon_call_method_key(methods, route, "gethttpmethods", 3411360217UL); + if (Z_TYPE_P(methods) != IS_NULL) { + + if (Z_TYPE_P(request) == IS_NULL) { + + PHALCON_OBS_NVAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "A dependency injection container is required to access the 'request' service"); + return; + } + + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "request", 1); + + PHALCON_INIT_NVAR(request); + phalcon_call_method_p1_key(request, dependency_injector, "getshared", service, 1727570332UL); + } + + PHALCON_INIT_NVAR(match_method); + phalcon_call_method_p1_key(match_method, request, "ismethod", methods, 2504815042UL); + if (PHALCON_IS_FALSE(match_method)) { + zend_hash_move_backwards_ex(ah0, &hp0); + continue; + } + } + + PHALCON_INIT_NVAR(hostname); + phalcon_call_method_key(hostname, route, "gethostname", 3942718116UL); + if (Z_TYPE_P(hostname) != IS_NULL) { + + if (Z_TYPE_P(request) == IS_NULL) { + + PHALCON_OBS_NVAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "A dependency injection container is required to access the 'request' service"); + return; + } + + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "request", 1); + + PHALCON_INIT_NVAR(request); + phalcon_call_method_p1_key(request, dependency_injector, "getshared", service, 1727570332UL); + } + + if (Z_TYPE_P(current_host_name) == IS_NULL) { + PHALCON_INIT_NVAR(current_host_name); + phalcon_call_method_key(current_host_name, request, "gethttphost", 3414889219UL); + } + + if (Z_TYPE_P(current_host_name) == IS_NULL) { + zend_hash_move_backwards_ex(ah0, &hp0); + continue; + } + + PHALCON_INIT_NVAR(matched); + if (phalcon_memnstr_str(hostname, SL("("))) { + if (!phalcon_memnstr_str(hostname, SL("#"))) { + PHALCON_INIT_NVAR(regex_host_name); + PHALCON_CONCAT_SVS(regex_host_name, "#^", hostname, "$#"); + } else { + PHALCON_CPY_WRT(regex_host_name, hostname); + } - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 1); - } + phalcon_preg_match(matched, regex_host_name, current_host_name, NULL TSRMLS_CC); + } else { + is_equal_function(matched, current_host_name, hostname TSRMLS_CC); + } - if (Z_TYPE_P(params) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The render parameters must be an array"); - return; - } - if (zend_is_true(merge)) { + if (!zend_is_true(matched)) { + zend_hash_move_backwards_ex(ah0, &hp0); + continue; + } + } - PHALCON_OBS_VAR(view_params); - phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); - if (Z_TYPE_P(view_params) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_params); - phalcon_fast_array_merge(merged_params, &view_params, ¶ms TSRMLS_CC); + PHALCON_INIT_NVAR(pattern); + phalcon_call_method_key(pattern, route, "getcompiledpattern", 1538259504UL); + + PHALCON_INIT_NVAR(route_found); + if (phalcon_memnstr_str(pattern, SL("^"))) { + phalcon_preg_match(route_found, pattern, handled_uri, matches TSRMLS_CC); } else { - PHALCON_CPY_WRT(merged_params, params); + is_equal_function(route_found, pattern, handled_uri TSRMLS_CC); } - phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), merged_params, 1685283331UL TSRMLS_CC); - } else { - phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), params, 1685283331UL TSRMLS_CC); - } + if (zend_is_true(route_found)) { - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_View, setVar){ - - zval *key, *value; - - phalcon_fetch_params(0, 2, 0, &key, &value); + PHALCON_INIT_NVAR(before_match); + phalcon_call_method_key(before_match, route, "getbeforematch", 3030065829UL); + if (Z_TYPE_P(before_match) != IS_NULL) { - phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, getVar){ - - zval *key, *params, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); + if (!phalcon_is_callable(before_match TSRMLS_CC)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "Before-Match callback is not callable in matched route"); + return; + } - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); - if (phalcon_array_isset(params, key)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, params, key, PH_NOISY); - RETURN_CCTOR(value); - } + PHALCON_INIT_NVAR(before_match_params); + array_init_size(before_match_params, 3); + phalcon_array_append(&before_match_params, handled_uri, PH_SEPARATE); + phalcon_array_append(&before_match_params, route, PH_SEPARATE); + phalcon_array_append(&before_match_params, this_ptr, PH_SEPARATE); - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_View, getParamsToView){ - - - RETURN_MEMBER_QUICK(this_ptr, "_viewParams", 1685283331UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, getControllerName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_controllerName", 3332183433UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, getActionName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_actionName", 2975797059UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, getParams){ - - - RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, start){ - - - PHALCON_MM_GROW(); - - phalcon_update_property_null(this_ptr, SL("_content") TSRMLS_CC); - phalcon_ob_start(TSRMLS_C); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_View, _loadTemplateEngines){ - - zval *engines = NULL, *dependency_injector, *registered_engines; - zval *php_engine, *arguments, *engine_service = NULL; - zval *extension = NULL, *engine_object = NULL, *exception_message = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(engines); - phalcon_read_property_this_quick(&engines, this_ptr, SL("_engines"), 1840711053UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(route_found); + PHALCON_CALL_USER_FUNC_ARRAY(route_found, before_match, params); + } + } - if (PHALCON_IS_FALSE(engines)) { + if (zend_is_true(route_found)) { - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(paths); + phalcon_call_method_key(paths, route, "getpaths", 4092132037UL); + PHALCON_CPY_WRT(parts, paths); - PHALCON_INIT_NVAR(engines); - array_init(engines); + if (Z_TYPE_P(matches) == IS_ARRAY) { - PHALCON_OBS_VAR(registered_engines); - phalcon_read_property_this_quick(®istered_engines, this_ptr, SL("_registeredEngines"), 3326968731UL, PH_NOISY_CC); - if (Z_TYPE_P(registered_engines) != IS_ARRAY) { - PHALCON_INIT_VAR(php_engine); - object_init_ex(php_engine, phalcon_mvc_view_engine_php_ce); - phalcon_call_method_p2_key(NULL, php_engine, "__construct", this_ptr, dependency_injector, 1107214344UL); + PHALCON_INIT_NVAR(converters); + phalcon_call_method_key(converters, route, "getconverters", 441740624UL); - phalcon_array_update_string(&engines, SL(".phtml"), &php_engine, PH_COPY | PH_SEPARATE); - } else { - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "A dependency injector container is required to obtain the application services"); - return; - } + phalcon_is_iterable(paths, &ah1, &hp1, 0, 0); - PHALCON_INIT_VAR(arguments); - array_init_size(arguments, 2); - phalcon_array_append(&arguments, this_ptr, PH_SEPARATE); - phalcon_array_append(&arguments, dependency_injector, PH_SEPARATE); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - phalcon_is_iterable(registered_engines, &ah0, &hp0, 0, 0); + PHALCON_GET_HKEY(part, ah1, hp1); + PHALCON_GET_HVALUE(position); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (phalcon_array_isset(matches, position)) { - PHALCON_GET_HKEY(extension, ah0, hp0); - PHALCON_GET_HVALUE(engine_service); + PHALCON_OBS_NVAR(match_position); + phalcon_array_fetch(&match_position, matches, position, PH_NOISY); - if (Z_TYPE_P(engine_service) == IS_OBJECT) { + if (Z_TYPE_P(converters) == IS_ARRAY) { + if (phalcon_array_isset(converters, part)) { + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 1); + phalcon_array_append(¶meters, match_position, PH_SEPARATE); - if (phalcon_is_instance_of(engine_service, SL("Closure") TSRMLS_CC)) { - PHALCON_INIT_NVAR(engine_object); - PHALCON_CALL_USER_FUNC_ARRAY(engine_object, engine_service, arguments); - } else { - PHALCON_CPY_WRT(engine_object, engine_service); - } - } else { - if (Z_TYPE_P(engine_service) == IS_STRING) { - PHALCON_INIT_NVAR(engine_object); - phalcon_call_method_p2_key(engine_object, dependency_injector, "getshared", engine_service, arguments, 1727570332UL); + PHALCON_OBS_NVAR(converter); + phalcon_array_fetch(&converter, converters, part, PH_NOISY); + + PHALCON_INIT_NVAR(converted_part); + PHALCON_CALL_USER_FUNC_ARRAY(converted_part, converter, parameters); + phalcon_array_update_zval(&parts, part, &converted_part, PH_COPY | PH_SEPARATE); + zend_hash_move_forward_ex(ah1, &hp1); + continue; + } + } + + phalcon_array_update_zval(&parts, part, &match_position, PH_COPY | PH_SEPARATE); } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "Invalid template engine registration for extension: ", extension); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; + if (Z_TYPE_P(converters) == IS_ARRAY) { + if (phalcon_array_isset(converters, part)) { + PHALCON_INIT_NVAR(parameters); + array_init_size(parameters, 1); + phalcon_array_append(¶meters, position, PH_SEPARATE); + + PHALCON_OBS_NVAR(converter); + phalcon_array_fetch(&converter, converters, part, PH_NOISY); + + PHALCON_INIT_NVAR(converted_part); + PHALCON_CALL_USER_FUNC_ARRAY(converted_part, converter, parameters); + phalcon_array_update_zval(&parts, part, &converted_part, PH_COPY | PH_SEPARATE); + } + } } + + zend_hash_move_forward_ex(ah1, &hp1); } - phalcon_array_update_zval(&engines, extension, &engine_object, PH_COPY | PH_SEPARATE); - zend_hash_move_forward_ex(ah0, &hp0); + phalcon_update_property_this_quick(this_ptr, SL("_matches"), matches, 83085737UL TSRMLS_CC); } + phalcon_update_property_this_quick(this_ptr, SL("_matchedRoute"), route, 3232330313UL TSRMLS_CC); + break; } - phalcon_update_property_this_quick(this_ptr, SL("_engines"), engines, 1840711053UL TSRMLS_CC); - } else { - PHALCON_OBS_NVAR(engines); - phalcon_read_property_this_quick(&engines, this_ptr, SL("_engines"), 1840711053UL, PH_NOISY_CC); + zend_hash_move_backwards_ex(ah0, &hp0); } - RETURN_CCTOR(engines); -} - -static PHP_METHOD(Phalcon_Mvc_View, _engineRender){ - - zval *engines, *view_path, *silence, *must_clean; - zval *cache, *not_exists = NULL, *views_dir, *base_path; - zval *views_dir_path, *render_level, *cache_level; - zval *is_started, *key = NULL, *lifetime = NULL, *view_options; - zval *cache_options, *cached_view, *is_fresh; - zval *view_params, *events_manager, *engine = NULL; - zval *extension = NULL, *view_engine_path = NULL, *event_name = NULL; - zval *status = NULL, *exception_message; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 5, 0, &engines, &view_path, &silence, &must_clean, &cache); + if (zend_is_true(route_found)) { + phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 1 TSRMLS_CC); + } else { + phalcon_update_property_bool(this_ptr, SL("_wasMatched"), 0 TSRMLS_CC); + } - PHALCON_INIT_VAR(not_exists); - ZVAL_BOOL(not_exists, 1); + if (!zend_is_true(route_found)) { - PHALCON_OBS_VAR(views_dir); - phalcon_read_property_this_quick(&views_dir, this_ptr, SL("_viewsDir"), 3398309201UL, PH_NOISY_CC); + PHALCON_OBS_VAR(not_found_paths); + phalcon_read_property_this_quick(¬_found_paths, this_ptr, SL("_notFoundPaths"), 189519377UL, PH_NOISY_CC); + if (Z_TYPE_P(not_found_paths) != IS_NULL) { + PHALCON_CPY_WRT(parts, not_found_paths); - PHALCON_OBS_VAR(base_path); - phalcon_read_property_this_quick(&base_path, this_ptr, SL("_basePath"), 1477430348UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(route_found); + ZVAL_BOOL(route_found, 1); + } + } - PHALCON_INIT_VAR(views_dir_path); - PHALCON_CONCAT_VVV(views_dir_path, base_path, views_dir, view_path); + if (zend_is_true(route_found)) { - if (Z_TYPE_P(cache) == IS_OBJECT) { + if (phalcon_array_isset_quick_string(parts, SS("namespace"), 545490034UL)) { - PHALCON_OBS_VAR(render_level); - phalcon_read_property_this_quick(&render_level, this_ptr, SL("_renderLevel"), 3194989084UL, PH_NOISY_CC); + PHALCON_OBS_VAR(namespace); + phalcon_array_fetch_quick_string(&namespace, parts, SS("namespace"), 545490034UL, PH_NOISY); + if (!phalcon_is_numeric(namespace)) { + phalcon_update_property_this_quick(this_ptr, SL("_namespace"), namespace, 1403433009UL TSRMLS_CC); + } - PHALCON_OBS_VAR(cache_level); - phalcon_read_property_this_quick(&cache_level, this_ptr, SL("_cacheLevel"), 3155415824UL, PH_NOISY_CC); - if (PHALCON_GE(render_level, cache_level)) { + phalcon_array_unset_string(&parts, SS("namespace"), PH_SEPARATE); + } else { + PHALCON_OBS_VAR(default_namespace); + phalcon_read_property_this_quick(&default_namespace, this_ptr, SL("_defaultNamespace"), 761145590UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_namespace"), default_namespace, 1403433009UL TSRMLS_CC); + } - PHALCON_INIT_VAR(is_started); - phalcon_call_method_key(is_started, cache, "isstarted", 527759032UL); - if (PHALCON_IS_FALSE(is_started)) { + if (phalcon_array_isset_quick_string(parts, SS("module"), 3565923467UL)) { - PHALCON_INIT_VAR(key); + PHALCON_OBS_VAR(module); + phalcon_array_fetch_quick_string(&module, parts, SS("module"), 3565923467UL, PH_NOISY); + if (!phalcon_is_numeric(module)) { + phalcon_update_property_this_quick(this_ptr, SL("_module"), module, 4176304298UL TSRMLS_CC); + } - PHALCON_INIT_VAR(lifetime); + phalcon_array_unset_string(&parts, SS("module"), PH_SEPARATE); + } else { + PHALCON_OBS_VAR(default_module); + phalcon_read_property_this_quick(&default_module, this_ptr, SL("_defaultModule"), 3959488399UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_module"), default_module, 4176304298UL TSRMLS_CC); + } - PHALCON_OBS_VAR(view_options); - phalcon_read_property_this_quick(&view_options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(parts, SS("controller"), 2892024105UL)) { - if (Z_TYPE_P(view_options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(view_options, SS("cache"), 4125168857UL)) { + PHALCON_OBS_VAR(controller); + phalcon_array_fetch_quick_string(&controller, parts, SS("controller"), 2892024105UL, PH_NOISY); + if (!phalcon_is_numeric(controller)) { + phalcon_update_property_this_quick(this_ptr, SL("_controller"), controller, 1139371208UL TSRMLS_CC); + } - PHALCON_OBS_VAR(cache_options); - phalcon_array_fetch_quick_string(&cache_options, view_options, SS("cache"), 4125168857UL, PH_NOISY); - if (Z_TYPE_P(cache_options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(cache_options, SS("key"), 2090432846UL)) { - PHALCON_OBS_NVAR(key); - phalcon_array_fetch_quick_string(&key, cache_options, SS("key"), 2090432846UL, PH_NOISY); - } - if (phalcon_array_isset_quick_string(cache_options, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_NVAR(lifetime); - phalcon_array_fetch_quick_string(&lifetime, cache_options, SS("lifetime"), 2639810228UL, PH_NOISY); - } - } - } - } + phalcon_array_unset_string(&parts, SS("controller"), PH_SEPARATE); + } else { + PHALCON_OBS_VAR(default_controller); + phalcon_read_property_this_quick(&default_controller, this_ptr, SL("_defaultController"), 1418722861UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_controller"), default_controller, 1139371208UL TSRMLS_CC); + } - if (Z_TYPE_P(key) == IS_NULL) { - PHALCON_INIT_NVAR(key); - phalcon_md5(key, view_path); - } + if (phalcon_array_isset_quick_string(parts, SS("action"), 502132067UL)) { - PHALCON_INIT_VAR(cached_view); - phalcon_call_method_p2_key(cached_view, cache, "start", key, lifetime, 478839859UL); - if (Z_TYPE_P(cached_view) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_content"), cached_view, 4081318271UL TSRMLS_CC); - RETURN_MM_NULL(); - } + PHALCON_OBS_VAR(action); + phalcon_array_fetch_quick_string(&action, parts, SS("action"), 502132067UL, PH_NOISY); + if (!phalcon_is_numeric(action)) { + phalcon_update_property_this_quick(this_ptr, SL("_action"), action, 1112512898UL TSRMLS_CC); } - PHALCON_INIT_VAR(is_fresh); - phalcon_call_method_key(is_fresh, cache, "isfresh", 3981662073UL); - if (!zend_is_true(is_fresh)) { - RETURN_MM_NULL(); + phalcon_array_unset_string(&parts, SS("action"), PH_SEPARATE); + } else { + PHALCON_OBS_VAR(default_action); + phalcon_read_property_this_quick(&default_action, this_ptr, SL("_defaultAction"), 895696999UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_action"), default_action, 1112512898UL TSRMLS_CC); + } + + if (phalcon_array_isset_quick_string(parts, SS("params"), 2613350281UL)) { + + PHALCON_OBS_VAR(params_str); + phalcon_array_fetch_quick_string(¶ms_str, parts, SS("params"), 2613350281UL, PH_NOISY); + + PHALCON_INIT_VAR(str_params); + phalcon_substr(str_params, params_str, 1, 0); + if (zend_is_true(str_params)) { + PHALCON_INIT_VAR(slash); + ZVAL_STRING(slash, "/", 1); + + PHALCON_INIT_NVAR(params); + phalcon_fast_explode(params, slash, str_params); } + + phalcon_array_unset_string(&parts, SS("params"), PH_SEPARATE); } - } - PHALCON_OBS_VAR(view_params); - phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + if (phalcon_fast_count_ev(params TSRMLS_CC)) { + PHALCON_INIT_VAR(params_merge); + phalcon_fast_array_merge(params_merge, ¶ms, &parts TSRMLS_CC); + } else { + PHALCON_CPY_WRT(params_merge, parts); + } - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_params"), params_merge, 3223731112UL TSRMLS_CC); + } else { + PHALCON_OBS_NVAR(default_namespace); + phalcon_read_property_this_quick(&default_namespace, this_ptr, SL("_defaultNamespace"), 761145590UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_namespace"), default_namespace, 1403433009UL TSRMLS_CC); - phalcon_is_iterable(engines, &ah0, &hp0, 0, 0); + PHALCON_OBS_NVAR(default_module); + phalcon_read_property_this_quick(&default_module, this_ptr, SL("_defaultModule"), 3959488399UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_module"), default_module, 4176304298UL TSRMLS_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_NVAR(default_controller); + phalcon_read_property_this_quick(&default_controller, this_ptr, SL("_defaultController"), 1418722861UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_controller"), default_controller, 1139371208UL TSRMLS_CC); - PHALCON_GET_HKEY(extension, ah0, hp0); - PHALCON_GET_HVALUE(engine); + PHALCON_OBS_NVAR(default_action); + phalcon_read_property_this_quick(&default_action, this_ptr, SL("_defaultAction"), 895696999UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_action"), default_action, 1112512898UL TSRMLS_CC); - PHALCON_INIT_NVAR(view_engine_path); - PHALCON_CONCAT_VV(view_engine_path, views_dir_path, extension); + PHALCON_OBS_VAR(default_params); + phalcon_read_property_this_quick(&default_params, this_ptr, SL("_defaultParams"), 3006915213UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_params"), default_params, 3223731112UL TSRMLS_CC); + } - if (phalcon_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Router, add){ + + zval *pattern, *paths = NULL, *http_methods = NULL, *route; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_activeRenderPath"), view_engine_path, 1528023309UL TSRMLS_CC); + if (!paths) { + PHALCON_INIT_VAR(paths); + } - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "view:beforeRenderView", 1); + if (!http_methods) { + PHALCON_INIT_VAR(http_methods); + } - PHALCON_INIT_NVAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, view_engine_path, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - phalcon_call_method_p3_key(NULL, engine, "render", view_engine_path, view_params, must_clean, 1053215877UL); + PHALCON_INIT_VAR(route); + object_init_ex(route, phalcon_mvc_router_route_ce); + phalcon_call_method_p3_key(NULL, route, "__construct", pattern, paths, http_methods, 1107214344UL); - PHALCON_INIT_NVAR(not_exists); - ZVAL_BOOL(not_exists, 0); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "view:afterRenderView", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); - } + phalcon_update_property_array_append(this_ptr, SL("_routes"), route TSRMLS_CC); + RETURN_CTOR(route); +} + +static PHP_METHOD(Phalcon_Mvc_Router, addGet){ + + zval *pattern, *paths = NULL, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - break; - } + if (!paths) { + PHALCON_INIT_VAR(paths); + } + + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "GET", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Router, addPost){ + + zval *pattern, *paths = NULL, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &pattern, &paths); + + if (!paths) { + PHALCON_INIT_VAR(paths); + } + + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "POST", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Router, addPut){ + + zval *pattern, *paths = NULL, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &pattern, &paths); + + if (!paths) { + PHALCON_INIT_VAR(paths); + } + + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "PUT", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Router, addPatch){ + + zval *pattern, *paths = NULL, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - zend_hash_move_forward_ex(ah0, &hp0); + if (!paths) { + PHALCON_INIT_VAR(paths); } - if (PHALCON_IS_TRUE(not_exists)) { + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "PATCH", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Router, addDelete){ + + zval *pattern, *paths = NULL, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_activeRenderPath"), view_engine_path, 1528023309UL TSRMLS_CC); + if (!paths) { + PHALCON_INIT_VAR(paths); + } - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "view:notFoundView", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); - } - if (!zend_is_true(silence)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "View '", views_dir_path, "' was not found in the views directory"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); - return; - } + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "DELETE", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Router, addOptions){ + + zval *pattern, *paths = NULL, *method; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &pattern, &paths); + + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "OPTIONS", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View, registerEngines){ +static PHP_METHOD(Phalcon_Mvc_Router, addHead){ - zval *engines; + zval *pattern, *paths = NULL, *method; - phalcon_fetch_params(0, 1, 0, &engines); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - if (Z_TYPE_P(engines) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Engines to register must be an array"); - return; + if (!paths) { + PHALCON_INIT_VAR(paths); } - phalcon_update_property_this_quick(this_ptr, SL("_registeredEngines"), engines, 3326968731UL TSRMLS_CC); - RETURN_THISW(); + PHALCON_INIT_VAR(method); + ZVAL_STRING(method, "HEAD", 1); + phalcon_call_method_p3_key(return_value, this_ptr, "add", pattern, paths, method, 2090071694UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View, render){ +static PHP_METHOD(Phalcon_Mvc_Router, mount){ - zval *controller_name, *action_name, *params = NULL; - zval *disabled, *contents = NULL, *layouts_dir = NULL, *layout; - zval *layout_name = NULL, *engines, *pick_view, *render_view = NULL; - zval *pick_view_action, *cache = NULL, *cache_level; - zval *events_manager, *event_name = NULL, *status, *must_clean; - zval *silence = NULL, *disabled_levels, *render_level; - zval *templates_before, *template_before = NULL; - zval *view_temp_path = NULL, *templates_after, *template_after = NULL; - zval *main_view, *is_started, *is_fresh; + zval *group, *group_routes, *before_match, *route = NULL; + zval *hostname, *routes, *new_routes; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &controller_name, &action_name, ¶ms); - - if (!params) { - PHALCON_INIT_VAR(params); - } - - PHALCON_OBS_VAR(disabled); - phalcon_read_property_this_quick(&disabled, this_ptr, SL("_disabled"), 2601399228UL, PH_NOISY_CC); - if (PHALCON_IS_NOT_FALSE(disabled)) { - PHALCON_INIT_VAR(contents); - phalcon_ob_get_contents(contents TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_content"), contents, 4081318271UL TSRMLS_CC); - RETURN_MM_FALSE; - } - - phalcon_update_property_this_quick(this_ptr, SL("_controllerName"), controller_name, 3332183433UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_actionName"), action_name, 2975797059UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_params"), params, 3223731112UL TSRMLS_CC); - - PHALCON_OBS_VAR(layouts_dir); - phalcon_read_property_this_quick(&layouts_dir, this_ptr, SL("_layoutsDir"), 313056692UL, PH_NOISY_CC); - if (!zend_is_true(layouts_dir)) { - PHALCON_INIT_NVAR(layouts_dir); - ZVAL_STRING(layouts_dir, "layouts/", 1); - } + phalcon_fetch_params(1, 1, 0, &group); - PHALCON_OBS_VAR(layout); - phalcon_read_property_this_quick(&layout, this_ptr, SL("_layout"), 2361639842UL, PH_NOISY_CC); - if (zend_is_true(layout)) { - PHALCON_CPY_WRT(layout_name, layout); - } else { - PHALCON_CPY_WRT(layout_name, controller_name); + if (Z_TYPE_P(group) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The group of routes is not valid"); + return; } - PHALCON_INIT_VAR(engines); - phalcon_call_method_key(engines, this_ptr, "_loadtemplateengines", 4149337481UL); - - PHALCON_OBS_VAR(pick_view); - phalcon_read_property_this_quick(&pick_view, this_ptr, SL("_pickView"), 1471709510UL, PH_NOISY_CC); - if (Z_TYPE_P(pick_view) == IS_NULL) { - PHALCON_INIT_VAR(render_view); - PHALCON_CONCAT_VSV(render_view, controller_name, "/", action_name); - } else { - PHALCON_OBS_NVAR(render_view); - phalcon_array_fetch_long(&render_view, pick_view, 0, PH_NOISY); - if (phalcon_array_isset_long(pick_view, 1)) { - PHALCON_OBS_VAR(pick_view_action); - phalcon_array_fetch_long(&pick_view_action, pick_view, 1, PH_NOISY); - PHALCON_CPY_WRT(layout_name, pick_view_action); - } + PHALCON_INIT_VAR(group_routes); + phalcon_call_method_key(group_routes, group, "getroutes", 733840903UL); + if (!phalcon_fast_count_ev(group_routes TSRMLS_CC)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The group of routes does not contain any routes"); + return; } - PHALCON_INIT_VAR(cache); - - PHALCON_OBS_VAR(cache_level); - phalcon_read_property_this_quick(&cache_level, this_ptr, SL("_cacheLevel"), 3155415824UL, PH_NOISY_CC); - if (zend_is_true(cache_level)) { - phalcon_call_method_key(cache, this_ptr, "getcache", 3582760537UL); - } + PHALCON_INIT_VAR(before_match); + phalcon_call_method_key(before_match, group, "getbeforematch", 3030065829UL); + if (Z_TYPE_P(before_match) != IS_NULL) { - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + phalcon_is_iterable(group_routes, &ah0, &hp0, 0, 0); - phalcon_create_symbol_table(TSRMLS_C); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_GET_HVALUE(route); - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "view:beforeRender", 1); + phalcon_call_method_p1_key(NULL, route, "beforematch", before_match, 1794408741UL); - PHALCON_INIT_VAR(status); - phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; + zend_hash_move_forward_ex(ah0, &hp0); } + } - PHALCON_INIT_NVAR(contents); - phalcon_ob_get_contents(contents TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_content"), contents, 4081318271UL TSRMLS_CC); + PHALCON_INIT_VAR(hostname); + phalcon_call_method_key(hostname, group, "gethostname", 3942718116UL); + if (Z_TYPE_P(hostname) != IS_NULL) { - PHALCON_INIT_VAR(must_clean); - ZVAL_BOOL(must_clean, 1); + phalcon_is_iterable(group_routes, &ah1, &hp1, 0, 0); - PHALCON_INIT_VAR(silence); - ZVAL_BOOL(silence, 1); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_OBS_VAR(disabled_levels); - phalcon_read_property_this_quick(&disabled_levels, this_ptr, SL("_disabledLevels"), 1575004551UL, PH_NOISY_CC); + PHALCON_GET_HVALUE(route); - PHALCON_OBS_VAR(render_level); - phalcon_read_property_this_quick(&render_level, this_ptr, SL("_renderLevel"), 3194989084UL, PH_NOISY_CC); - if (zend_is_true(render_level)) { + phalcon_call_method_p1_key(NULL, route, "sethostname", hostname, 912882480UL); - if (PHALCON_GE_LONG(render_level, 1)) { - if (!phalcon_array_isset_long(disabled_levels, 1)) { - phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, render_view, silence, must_clean, cache, 828860954UL); - } + zend_hash_move_forward_ex(ah1, &hp1); } - if (PHALCON_GE_LONG(render_level, 2)) { - if (!phalcon_array_isset_long(disabled_levels, 2)) { + } - PHALCON_OBS_VAR(templates_before); - phalcon_read_property_this_quick(&templates_before, this_ptr, SL("_templatesBefore"), 3273177030UL, PH_NOISY_CC); + PHALCON_OBS_VAR(routes); + phalcon_read_property_this_quick(&routes, this_ptr, SL("_routes"), 2063827110UL, PH_NOISY_CC); + if (Z_TYPE_P(routes) == IS_ARRAY) { + PHALCON_INIT_VAR(new_routes); + phalcon_fast_array_merge(new_routes, &routes, &group_routes TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_routes"), new_routes, 2063827110UL TSRMLS_CC); + } else { + phalcon_update_property_this_quick(this_ptr, SL("_routes"), group_routes, 2063827110UL TSRMLS_CC); + } - if (Z_TYPE_P(templates_before) == IS_ARRAY) { + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Router, notFound){ + + zval *paths; + + phalcon_fetch_params(0, 1, 0, &paths); - ZVAL_BOOL(silence, 0); + if (Z_TYPE_P(paths) != IS_ARRAY) { + if (Z_TYPE_P(paths) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_router_exception_ce, "The not-found paths must be an array or string"); + return; + } + } + phalcon_update_property_this_quick(this_ptr, SL("_notFoundPaths"), paths, 189519377UL TSRMLS_CC); - phalcon_is_iterable(templates_before, &ah0, &hp0, 0, 0); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Router, clear){ + + zval *empty_routes; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(empty_routes); + array_init(empty_routes); + phalcon_update_property_this_quick(this_ptr, SL("_routes"), empty_routes, 2063827110UL TSRMLS_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Router, getNamespaceName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_namespace", 1403433009UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router, getModuleName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_module", 4176304298UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router, getControllerName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_controller", 1139371208UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router, getActionName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_action", 1112512898UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router, getParams){ + + + RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router, getMatchedRoute){ + + + RETURN_MEMBER_QUICK(this_ptr, "_matchedRoute", 3232330313UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router, getMatches){ + + + RETURN_MEMBER_QUICK(this_ptr, "_matches", 83085737UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router, wasMatched){ + + + RETURN_MEMBER_QUICK(this_ptr, "_wasMatched", 2908823365UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router, getRoutes){ + + + RETURN_MEMBER_QUICK(this_ptr, "_routes", 2063827110UL); +} + +static PHP_METHOD(Phalcon_Mvc_Router, getRouteById){ + + zval *id, *routes, *route = NULL, *route_id = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &id); - PHALCON_GET_HVALUE(template_before); + PHALCON_OBS_VAR(routes); + phalcon_read_property_this_quick(&routes, this_ptr, SL("_routes"), 2063827110UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(view_temp_path); - PHALCON_CONCAT_VV(view_temp_path, layouts_dir, template_before); - phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache, 828860954UL); + phalcon_is_iterable(routes, &ah0, &hp0, 0, 0); - zend_hash_move_forward_ex(ah0, &hp0); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_NVAR(silence); - ZVAL_BOOL(silence, 1); - } - } - } + PHALCON_GET_HVALUE(route); - if (PHALCON_GE_LONG(render_level, 3)) { - if (!phalcon_array_isset_long(disabled_levels, 3)) { - PHALCON_INIT_NVAR(view_temp_path); - PHALCON_CONCAT_VV(view_temp_path, layouts_dir, layout_name); - phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache, 828860954UL); - } + PHALCON_INIT_NVAR(route_id); + phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); + if (PHALCON_IS_EQUAL(route_id, id)) { + RETURN_CCTOR(route); } - if (PHALCON_GE_LONG(render_level, 4)) { - if (!phalcon_array_isset_long(disabled_levels, 4)) { - - PHALCON_OBS_VAR(templates_after); - phalcon_read_property_this_quick(&templates_after, this_ptr, SL("_templatesAfter"), 3575793989UL, PH_NOISY_CC); - if (Z_TYPE_P(templates_after) == IS_ARRAY) { - - PHALCON_INIT_NVAR(silence); - ZVAL_BOOL(silence, 0); - - phalcon_is_iterable(templates_after, &ah1, &hp1, 0, 0); + zend_hash_move_forward_ex(ah0, &hp0); + } - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Router, getRouteByName){ + + zval *name, *routes, *route = NULL, *route_name = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &name); - PHALCON_GET_HVALUE(template_after); + PHALCON_OBS_VAR(routes); + phalcon_read_property_this_quick(&routes, this_ptr, SL("_routes"), 2063827110UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(view_temp_path); - PHALCON_CONCAT_VV(view_temp_path, layouts_dir, template_after); - phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache, 828860954UL); + phalcon_is_iterable(routes, &ah0, &hp0, 0, 0); - zend_hash_move_forward_ex(ah1, &hp1); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_NVAR(silence); - ZVAL_BOOL(silence, 1); - } - } - } + PHALCON_GET_HVALUE(route); - if (PHALCON_GE_LONG(render_level, 5)) { - if (!phalcon_array_isset_long(disabled_levels, 5)) { - PHALCON_OBS_VAR(main_view); - phalcon_read_property_this_quick(&main_view, this_ptr, SL("_mainView"), 1829858724UL, PH_NOISY_CC); - phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, main_view, silence, must_clean, cache, 828860954UL); - } + PHALCON_INIT_NVAR(route_name); + phalcon_call_method_key(route_name, route, "getname", 4286441094UL); + if (PHALCON_IS_EQUAL(route_name, name)) { + RETURN_CCTOR(route); } - if (Z_TYPE_P(cache) == IS_OBJECT) { + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_INIT_VAR(is_started); - phalcon_call_method_key(is_started, cache, "isstarted", 527759032UL); - if (PHALCON_IS_TRUE(is_started)) { + RETURN_MM_FALSE; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_RouterInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, RouterInterface, mvc_routerinterface, phalcon_mvc_routerinterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Url_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Url, Exception, mvc_url_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Url){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc, Url, mvc_url, phalcon_mvc_url_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_url_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_url_ce, SL("_baseUri"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_url_ce, SL("_staticBaseUri"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_url_ce, SL("_basePath"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_url_ce, SL("_router"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_url_ce TSRMLS_CC, 2, phalcon_mvc_urlinterface_ce, phalcon_di_injectionawareinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_Url, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); - PHALCON_INIT_VAR(is_fresh); - phalcon_call_method_key(is_fresh, cache, "isfresh", 3981662073UL); - if (PHALCON_IS_TRUE(is_fresh)) { - phalcon_call_method_key(NULL, cache, "save", 274150868UL); - } else { - phalcon_call_method_key(NULL, cache, "stop", 274826411UL); - } - } else { - phalcon_call_method_key(NULL, cache, "stop", 274826411UL); - } - } + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_url_exception_ce, "The dependency injector must be an Object"); + return; } + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Mvc_Url, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} + +static PHP_METHOD(Phalcon_Mvc_Url, setBaseUri){ + + zval *base_uri, *static_base_uri; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &base_uri); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "view:afterRender", 1); - phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + phalcon_update_property_this_quick(this_ptr, SL("_baseUri"), base_uri, 3689183023UL TSRMLS_CC); + + PHALCON_OBS_VAR(static_base_uri); + phalcon_read_property_this_quick(&static_base_uri, this_ptr, SL("_staticBaseUri"), 2610838775UL, PH_NOISY_CC); + if (Z_TYPE_P(static_base_uri) == IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_staticBaseUri"), base_uri, 2610838775UL TSRMLS_CC); } - RETURN_MM_NULL(); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_View, pick){ +static PHP_METHOD(Phalcon_Mvc_Url, setStaticBaseUri){ - zval *render_view, *pick_view = NULL, *layout = NULL, *parts; + zval *static_base_uri; + + phalcon_fetch_params(0, 1, 0, &static_base_uri); + + phalcon_update_property_this_quick(this_ptr, SL("_staticBaseUri"), static_base_uri, 2610838775UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Url, getBaseUri){ + + zval *base_uri = NULL, *slash, *_SERVER, *php_self, *uri = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &render_view); + PHALCON_OBS_VAR(base_uri); + phalcon_read_property_this_quick(&base_uri, this_ptr, SL("_baseUri"), 3689183023UL, PH_NOISY_CC); + if (Z_TYPE_P(base_uri) == IS_NULL) { - if (Z_TYPE_P(render_view) == IS_ARRAY) { - PHALCON_CPY_WRT(pick_view, render_view); - } else { - PHALCON_INIT_VAR(layout); - if (phalcon_memnstr_str(render_view, SL("/"))) { - PHALCON_INIT_VAR(parts); - phalcon_fast_explode_str(parts, SL("/"), render_view); + PHALCON_INIT_VAR(slash); + ZVAL_STRING(slash, "/", 1); + phalcon_get_global(&_SERVER, SS("_SERVER") TSRMLS_CC); + if (phalcon_array_isset_quick_string(_SERVER, SS("PHP_SELF"), 3176521366UL)) { + PHALCON_OBS_VAR(php_self); + phalcon_array_fetch_quick_string(&php_self, _SERVER, SS("PHP_SELF"), 3176521366UL, PH_NOISY); - PHALCON_OBS_NVAR(layout); - phalcon_array_fetch_long(&layout, parts, 0, PH_NOISY); + PHALCON_INIT_VAR(uri); + phalcon_get_uri(uri, php_self); + } else { + PHALCON_INIT_NVAR(uri); } - PHALCON_INIT_NVAR(pick_view); - array_init_size(pick_view, 1); - phalcon_array_append(&pick_view, render_view, PH_SEPARATE); - if (Z_TYPE_P(layout) != IS_NULL) { - phalcon_array_append(&pick_view, layout, PH_SEPARATE); + if (!zend_is_true(uri)) { + PHALCON_CPY_WRT(base_uri, slash); + } else { + PHALCON_INIT_NVAR(base_uri); + PHALCON_CONCAT_VVV(base_uri, slash, uri, slash); } + + phalcon_update_property_this_quick(this_ptr, SL("_baseUri"), base_uri, 3689183023UL TSRMLS_CC); } - phalcon_update_property_this_quick(this_ptr, SL("_pickView"), pick_view, 1471709510UL TSRMLS_CC); - RETURN_THIS(); + RETURN_CCTOR(base_uri); } -static PHP_METHOD(Phalcon_Mvc_View, partial){ +static PHP_METHOD(Phalcon_Mvc_Url, getStaticBaseUri){ - zval *partial_path, *params = NULL, *view_params, *new_params = NULL; - zval *zfalse, *partials_dir, *real_path, *engines; + zval *static_base_uri; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &partial_path, ¶ms); - - if (!params) { - PHALCON_INIT_VAR(params); + PHALCON_OBS_VAR(static_base_uri); + phalcon_read_property_this_quick(&static_base_uri, this_ptr, SL("_staticBaseUri"), 2610838775UL, PH_NOISY_CC); + if (Z_TYPE_P(static_base_uri) != IS_NULL) { + RETURN_CCTOR(static_base_uri); } - if (Z_TYPE_P(params) == IS_ARRAY) { + phalcon_call_method_key(return_value, this_ptr, "getbaseuri", 2750461136UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Url, setBasePath){ + + zval *base_path; + + phalcon_fetch_params(0, 1, 0, &base_path); - PHALCON_OBS_VAR(view_params); - phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + phalcon_update_property_this_quick(this_ptr, SL("_basePath"), base_path, 1477430348UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Mvc_Url, getBasePath){ + + + RETURN_MEMBER_QUICK(this_ptr, "_basePath", 1477430348UL); +} + +static PHP_METHOD(Phalcon_Mvc_Url, get){ + + zval *uri = NULL, *base_uri, *router = NULL, *dependency_injector; + zval *service, *route_name, *route, *exception_message; + zval *pattern, *paths, *processed_uri, *args = NULL, *query_string; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &uri, &args); - if (Z_TYPE_P(view_params) == IS_ARRAY) { - PHALCON_INIT_VAR(new_params); - phalcon_fast_array_merge(new_params, &view_params, ¶ms TSRMLS_CC); - } else { - PHALCON_CPY_WRT(new_params, params); + if (!uri) { + PHALCON_INIT_VAR(uri); + } + + PHALCON_INIT_VAR(base_uri); + phalcon_call_method_key(base_uri, this_ptr, "getbaseuri", 2750461136UL); + if (Z_TYPE_P(uri) == IS_ARRAY) { + if (!phalcon_array_isset_quick_string(uri, SS("for"), 2090263820UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_url_exception_ce, "It's necessary to define the route name with the parameter \"for\""); + return; } - phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), new_params, 1685283331UL TSRMLS_CC); + PHALCON_OBS_VAR(router); + phalcon_read_property_this_quick(&router, this_ptr, SL("_router"), 2063827077UL, PH_NOISY_CC); - phalcon_create_symbol_table(TSRMLS_C); + if (Z_TYPE_P(router) != IS_OBJECT) { - } + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (!zend_is_true(dependency_injector)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_url_exception_ce, "A dependency injector container is required to obtain the \"url\" service"); + return; + } - PHALCON_INIT_VAR(zfalse); - ZVAL_BOOL(zfalse, 0); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "router", 1); - PHALCON_OBS_VAR(partials_dir); - phalcon_read_property_this_quick(&partials_dir, this_ptr, SL("_partialsDir"), 2130168739UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(router); + phalcon_call_method_p1_key(router, dependency_injector, "getshared", service, 1727570332UL); + phalcon_update_property_this_quick(this_ptr, SL("_router"), router, 2063827077UL TSRMLS_CC); + } - PHALCON_INIT_VAR(real_path); - PHALCON_CONCAT_VV(real_path, partials_dir, partial_path); + PHALCON_OBS_VAR(route_name); + phalcon_array_fetch_quick_string(&route_name, uri, SS("for"), 2090263820UL, PH_NOISY); - PHALCON_INIT_VAR(engines); - phalcon_call_method_key(engines, this_ptr, "_loadtemplateengines", 4149337481UL); + PHALCON_INIT_VAR(route); + phalcon_call_method_p1_key(route, router, "getroutebyname", route_name, 3004506768UL); + if (Z_TYPE_P(route) != IS_OBJECT) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Cannot obtain a route using the name \"", route_name, "\""); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_url_exception_ce, exception_message); + return; + } - phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, real_path, zfalse, zfalse, zfalse, 828860954UL); + PHALCON_INIT_VAR(pattern); + phalcon_call_method_key(pattern, route, "getpattern", 2464558051UL); - if (Z_TYPE_P(params) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), view_params, 1685283331UL TSRMLS_CC); + PHALCON_INIT_VAR(paths); + phalcon_call_method_key(paths, route, "getreversedpaths", 2949022469UL); + + PHALCON_INIT_VAR(processed_uri); + phalcon_replace_paths(processed_uri, pattern, paths, uri TSRMLS_CC); + PHALCON_CONCAT_VV(return_value, base_uri, processed_uri); + } + else { + PHALCON_CONCAT_VV(return_value, base_uri, uri); } - PHALCON_MM_RESTORE(); + if (args) { + PHALCON_INIT_VAR(query_string); + phalcon_http_build_query(query_string, args, "&" TSRMLS_CC); + if (Z_TYPE_P(query_string) == IS_STRING && Z_STRLEN_P(query_string)) { + if (phalcon_memnstr_str(return_value, "?", 1)) { + PHALCON_SCONCAT_SV(return_value, "&", query_string); + } + else { + PHALCON_SCONCAT_SV(return_value, "?", query_string); + } + } + } + + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View, getRender){ +static PHP_METHOD(Phalcon_Mvc_Url, getStatic){ - zval *controller_name, *action_name, *params = NULL; - zval *config_callback = NULL, *view, *status, *content; + zval *uri = NULL, *static_base_uri, *base_uri; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 2, &controller_name, &action_name, ¶ms, &config_callback); + phalcon_fetch_params(1, 0, 1, &uri); - if (!params) { - PHALCON_INIT_VAR(params); - } else { - PHALCON_SEPARATE_PARAM(params); + if (!uri) { + PHALCON_INIT_VAR(uri); } - if (!config_callback) { - PHALCON_INIT_VAR(config_callback); + PHALCON_OBS_VAR(static_base_uri); + phalcon_read_property_this_quick(&static_base_uri, this_ptr, SL("_staticBaseUri"), 2610838775UL, PH_NOISY_CC); + if (Z_TYPE_P(static_base_uri) != IS_NULL) { + PHALCON_CONCAT_VV(return_value, static_base_uri, uri); + RETURN_MM(); } - PHALCON_INIT_VAR(view); - if (phalcon_clone(view, this_ptr TSRMLS_CC) == FAILURE) { - return; - } + PHALCON_INIT_VAR(base_uri); + phalcon_call_method_key(base_uri, this_ptr, "getbaseuri", 2750461136UL); + PHALCON_CONCAT_VV(return_value, base_uri, uri); - phalcon_call_method_key(NULL, view, "reset", 422548360UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Url, path){ + + zval *path = NULL, *base_path; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &path); - if (Z_TYPE_P(params) == IS_ARRAY) { - phalcon_call_method_p1_key(NULL, view, "setvars", params, 321174573UL); + if (!path) { + PHALCON_INIT_VAR(path); } - if (Z_TYPE_P(config_callback) == IS_OBJECT) { - PHALCON_INIT_NVAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, view, PH_SEPARATE); + PHALCON_OBS_VAR(base_path); + phalcon_read_property_this_quick(&base_path, this_ptr, SL("_basePath"), 1477430348UL, PH_NOISY_CC); + PHALCON_CONCAT_VV(return_value, base_path, path); + RETURN_MM(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_UrlInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, UrlInterface, mvc_urlinterface, phalcon_mvc_urlinterface_method_entry); + + return SUCCESS; +} + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_User_Component){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Component, mvc_user_component, "phalcon\\di\\injectable", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_User_Module){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Module, mvc_user_module, "phalcon\\di\\injectable", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_User_Plugin){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Plugin, mvc_user_plugin, "phalcon\\di\\injectable", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_View_Engine_Php){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View\\Engine, Php, mvc_view_engine_php, "phalcon\\mvc\\view\\engine", phalcon_mvc_view_engine_php_method_entry, 0); + + zend_class_implements(phalcon_mvc_view_engine_php_ce TSRMLS_CC, 1, phalcon_mvc_view_engineinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Php, render){ + + zval *path, *params, *must_clean = NULL, *value = NULL, *key = NULL, *contents; + zval *view; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 1, &path, ¶ms, &must_clean); - PHALCON_INIT_VAR(status); - PHALCON_CALL_USER_FUNC_ARRAY(status, config_callback, params); + if (!must_clean) { + PHALCON_INIT_VAR(must_clean); + ZVAL_BOOL(must_clean, 0); } - phalcon_call_method_key(NULL, view, "start", 478839859UL); + if (PHALCON_IS_TRUE(must_clean)) { + phalcon_ob_clean(TSRMLS_C); + } - phalcon_call_method_p2_key(NULL, view, "render", controller_name, action_name, 1053215877UL); + if (Z_TYPE_P(params) == IS_ARRAY) { - phalcon_ob_end_clean(TSRMLS_C); + phalcon_is_iterable(params, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(content); - phalcon_call_method_key(content, view, "getcontent", 3141446400UL); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - RETURN_CCTOR(content); + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); + + if (phalcon_set_symbol(key, value TSRMLS_CC) == FAILURE){ + return; + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } + + if (phalcon_require(path TSRMLS_CC) == FAILURE) { + return; + } + if (PHALCON_IS_TRUE(must_clean)) { + PHALCON_INIT_VAR(contents); + phalcon_ob_get_contents(contents TSRMLS_CC); + + PHALCON_OBS_VAR(view); + phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); + phalcon_call_method_p1_key(NULL, view, "setcontent", contents, 4220987916UL); + } + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_View, finish){ - PHALCON_MM_GROW(); - phalcon_ob_end_clean(TSRMLS_C); - RETURN_THIS(); + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_View_Engine_Volt_Compiler){ + + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\View\\Engine\\Volt, Compiler, mvc_view_engine_volt_compiler, phalcon_mvc_view_engine_volt_compiler_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_view"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_arrayHelpers"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_level"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_foreachLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_blockLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_view_engine_volt_compiler_ce, SL("_exprLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_view_engine_volt_compiler_ce, SL("_extended"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_view_engine_volt_compiler_ce, SL("_autoescape"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_extendedBlocks"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_currentBlock"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_blocks"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_forElsePointers"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_loopPointers"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_extensions"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_functions"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_macros"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_prefix"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_currentPath"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_compiler_ce, SL("_compiledTemplatePath"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_view_engine_volt_compiler_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_View, _createCache){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, __construct){ - zval *dependency_injector, *cache_service = NULL; - zval *view_options, *cache_options, *view_cache; + zval *view = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "A dependency injector container is required to obtain the view cache services"); - return; - } - - PHALCON_INIT_VAR(cache_service); - ZVAL_STRING(cache_service, "viewCache", 1); + phalcon_fetch_params(1, 0, 1, &view); - PHALCON_OBS_VAR(view_options); - phalcon_read_property_this_quick(&view_options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (Z_TYPE_P(view_options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(view_options, SS("cache"), 4125168857UL)) { + if (!view) { + PHALCON_INIT_VAR(view); + } - PHALCON_OBS_VAR(cache_options); - phalcon_array_fetch_quick_string(&cache_options, view_options, SS("cache"), 4125168857UL, PH_NOISY); - if (Z_TYPE_P(cache_options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(cache_options, SS("service"), 243174486UL)) { - PHALCON_OBS_NVAR(cache_service); - phalcon_array_fetch_quick_string(&cache_service, cache_options, SS("service"), 243174486UL, PH_NOISY); - } - } - } + if (Z_TYPE_P(view) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_view"), view, 3993744575UL TSRMLS_CC); } - PHALCON_INIT_VAR(view_cache); - phalcon_call_method_p1_key(view_cache, dependency_injector, "getshared", cache_service, 1727570332UL); - if (Z_TYPE_P(view_cache) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The injected caching service is invalid"); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Dependency Injector is invalid"); return; } + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - RETURN_CCTOR(view_cache); } -static PHP_METHOD(Phalcon_Mvc_View, isCaching){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setOptions){ + + zval *options; + + phalcon_fetch_params(0, 1, 0, &options); + + if (Z_TYPE_P(options) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Options must be an array"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + +} - zval *zero, *cache_level; +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setOption){ - PHALCON_MM_GROW(); + zval *option, *value; - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); + phalcon_fetch_params(0, 2, 0, &option, &value); + + phalcon_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC); - PHALCON_OBS_VAR(cache_level); - phalcon_read_property_this_quick(&cache_level, this_ptr, SL("_cacheLevel"), 3155415824UL, PH_NOISY_CC); - is_smaller_function(return_value, zero, cache_level TSRMLS_CC); - RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View, getCache){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getOption){ - zval *cache = NULL; + zval *option, *options, *value; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(cache); - phalcon_read_property_this_quick(&cache, this_ptr, SL("_cache"), 2191407384UL, PH_NOISY_CC); - if (zend_is_true(cache)) { - if (Z_TYPE_P(cache) != IS_OBJECT) { - PHALCON_INIT_NVAR(cache); - phalcon_call_method_key(cache, this_ptr, "_createcache", 1216889100UL); - phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); - } - } else { - PHALCON_INIT_NVAR(cache); - phalcon_call_method_key(cache, this_ptr, "_createcache", 1216889100UL); - phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); + phalcon_fetch_params(1, 1, 0, &option); + + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (phalcon_array_isset(options, option)) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, options, option, PH_NOISY); + RETURN_CCTOR(value); } - RETURN_CCTOR(cache); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Mvc_View, cache){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getOptions){ - zval *options = NULL, *view_options = NULL, *cache_options = NULL; - zval *value = NULL, *key = NULL, *cache_level; + + RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, fireExtensionEvent){ + + zval *name, *arguments = NULL, *extensions, *extension = NULL; + zval *call_object = NULL, *status = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &options); + phalcon_fetch_params(1, 1, 1, &name, &arguments); - if (!options) { - PHALCON_INIT_VAR(options); - ZVAL_BOOL(options, 1); + if (!arguments) { + PHALCON_INIT_VAR(arguments); } - if (Z_TYPE_P(options) == IS_ARRAY) { + PHALCON_OBS_VAR(extensions); + phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); + if (Z_TYPE_P(extensions) == IS_ARRAY) { - PHALCON_OBS_VAR(view_options); - phalcon_read_property_this_quick(&view_options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (Z_TYPE_P(view_options) != IS_ARRAY) { - PHALCON_INIT_NVAR(view_options); - array_init(view_options); - } + phalcon_is_iterable(extensions, &ah0, &hp0, 0, 0); - if (phalcon_array_isset_quick_string(view_options, SS("cache"), 4125168857UL)) { - PHALCON_OBS_VAR(cache_options); - phalcon_array_fetch_quick_string(&cache_options, view_options, SS("cache"), 4125168857UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(cache_options); - array_init(cache_options); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - phalcon_is_iterable(options, &ah0, &hp0, 0, 0); + PHALCON_GET_HVALUE(extension); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (phalcon_method_exists(extension, name TSRMLS_CC) == SUCCESS) { - PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + PHALCON_INIT_NVAR(call_object); + array_init_size(call_object, 2); + phalcon_array_append(&call_object, extension, PH_SEPARATE); + phalcon_array_append(&call_object, name, PH_SEPARATE); + if (Z_TYPE_P(arguments) == IS_ARRAY) { + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC_ARRAY(status, call_object, arguments); + } else { + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC(status, call_object); + } - phalcon_array_update_zval(&cache_options, key, &value, PH_COPY | PH_SEPARATE); + if (Z_TYPE_P(status) == IS_STRING) { + RETURN_CCTOR(status); + } + } zend_hash_move_forward_ex(ah0, &hp0); } - if (phalcon_array_isset_quick_string(cache_options, SS("level"), 187843549UL)) { - PHALCON_OBS_VAR(cache_level); - phalcon_array_fetch_quick_string(&cache_level, cache_options, SS("level"), 187843549UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_cacheLevel"), cache_level, 3155415824UL TSRMLS_CC); - } else { - phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 5 TSRMLS_CC); - } + } - phalcon_array_update_quick_string(&view_options, SS("cache"), 4125168857UL, &cache_options, PH_COPY | PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_options"), view_options, 1620153008UL TSRMLS_CC); - } else { - if (zend_is_true(options)) { - phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 5 TSRMLS_CC); - } else { - phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 0 TSRMLS_CC); - } + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addExtension){ + + zval *extension; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &extension); + + if (Z_TYPE_P(extension) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The extension is not valid"); + return; + } + + if (phalcon_method_quick_exists_ex(extension, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_p1_key(NULL, extension, "initialize", this_ptr, 2896075127UL); } + phalcon_update_property_array_append(this_ptr, SL("_extensions"), extension TSRMLS_CC); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Mvc_View, setContent){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getExtensions){ - zval *content; - phalcon_fetch_params(0, 1, 0, &content); + RETURN_MEMBER_QUICK(this_ptr, "_extensions", 726159316UL); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addFunction){ + + zval *name, *definition; + + phalcon_fetch_params(0, 2, 0, &name, &definition); - if (Z_TYPE_P(content) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Content must be a string"); + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "The function name must be a string"); return; } - phalcon_update_property_this_quick(this_ptr, SL("_content"), content, 4081318271UL TSRMLS_CC); + phalcon_update_property_array(this_ptr, SL("_functions"), name, definition TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View, getContent){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getFunctions){ - RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); + RETURN_MEMBER_QUICK(this_ptr, "_functions", 2704716189UL); } -static PHP_METHOD(Phalcon_Mvc_View, getActiveRenderPath){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addFilter){ + zval *name, *definition; - RETURN_MEMBER_QUICK(this_ptr, "_activeRenderPath", 1528023309UL); + phalcon_fetch_params(0, 2, 0, &name, &definition); + + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "The function name must be a string"); + return; + } + phalcon_update_property_array(this_ptr, SL("_filters"), name, definition TSRMLS_CC); + + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View, disable){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getFilters){ - phalcon_update_property_bool(this_ptr, SL("_disabled"), 1 TSRMLS_CC); - RETURN_THISW(); + RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL); } -static PHP_METHOD(Phalcon_Mvc_View, enable){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setUniquePrefix){ + zval *prefix; - phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); + phalcon_fetch_params(0, 1, 0, &prefix); + + phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_View, reset){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getUniquePrefix){ - zval *znull; + zval *prefix = NULL, *current_path, *parameters, *calculated_prefix; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(znull); - phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_engines"), 0 TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_cache"), znull, 2191407384UL TSRMLS_CC); - phalcon_update_property_long(this_ptr, SL("_renderLevel"), 5 TSRMLS_CC); - phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 0 TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_content"), znull, 4081318271UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_templatesBefore"), znull, 3273177030UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_templatesAfter"), znull, 3575793989UL TSRMLS_CC); - RETURN_THIS(); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + if (!zend_is_true(prefix)) { + PHALCON_OBS_VAR(current_path); + phalcon_read_property_this_quick(¤t_path, this_ptr, SL("_currentPath"), 3436123892UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(prefix); + phalcon_unique_path_key(prefix, current_path TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); + } + + if (Z_TYPE_P(prefix) == IS_OBJECT) { + if (phalcon_is_instance_of(prefix, SL("Closure") TSRMLS_CC)) { + PHALCON_INIT_VAR(parameters); + array_init_size(parameters, 1); + phalcon_array_append(¶meters, this_ptr, PH_SEPARATE); + + PHALCON_INIT_VAR(calculated_prefix); + phalcon_call_func_p2(calculated_prefix, "call_user_func_array", prefix, parameters); + phalcon_update_property_this_quick(this_ptr, SL("_prefix"), calculated_prefix, 3873791314UL TSRMLS_CC); + PHALCON_CPY_WRT(prefix, calculated_prefix); + } + } + + if (Z_TYPE_P(prefix) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The unique compilation prefix is invalid"); + return; + } + + RETURN_CCTOR(prefix); } -static PHP_METHOD(Phalcon_Mvc_View, __set){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, attributeReader){ - zval *key, *value; + zval *expr, *expr_code, *loop_context, *left, *left_type; + zval *variable, *level, *prefix, *dependency_injector; + zval *is_service, *left_code, *right, *right_type; + zval *member, *right_code; - phalcon_fetch_params(0, 2, 0, &key, &value); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &expr); + + PHALCON_INIT_VAR(expr_code); + + PHALCON_INIT_VAR(loop_context); + + PHALCON_OBS_VAR(left); + phalcon_array_fetch_quick_string(&left, expr, SS("left"), 265976240UL, PH_NOISY); + + PHALCON_OBS_VAR(left_type); + phalcon_array_fetch_quick_string(&left_type, left, SS("type"), 276192743UL, PH_NOISY); + if (PHALCON_IS_LONG(left_type, 265)) { + + PHALCON_OBS_VAR(variable); + phalcon_array_fetch_quick_string(&variable, left, SS("value"), 574111618UL, PH_NOISY); + + if (PHALCON_IS_STRING(variable, "loop")) { + PHALCON_OBS_VAR(level); + phalcon_read_property_this_quick(&level, this_ptr, SL("_foreachLevel"), 1560648116UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(prefix); + phalcon_call_method_key(prefix, this_ptr, "getuniqueprefix", 3888429962UL); + PHALCON_SCONCAT_SVVS(expr_code, "$", prefix, level, "loop"); + phalcon_update_property_array(this_ptr, SL("_loopPointers"), level, level TSRMLS_CC); + } else { + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + + PHALCON_INIT_VAR(is_service); + phalcon_call_method_p1_key(is_service, dependency_injector, "has", variable, 2090320481UL); + if (zend_is_true(is_service)) { + PHALCON_SCONCAT_SV(expr_code, "$this->", variable); + } else { + PHALCON_SCONCAT_SV(expr_code, "$", variable); + } + } else { + PHALCON_SCONCAT_SV(expr_code, "$", variable); + } + } + } else { + PHALCON_INIT_VAR(left_code); + phalcon_call_method_p1_key(left_code, this_ptr, "expression", left, 218841909UL); + if (!PHALCON_IS_LONG(left_type, 46)) { + if (!PHALCON_IS_LONG(left_type, 350)) { + PHALCON_SCONCAT_SVS(expr_code, "(", left_code, ")"); + } else { + phalcon_concat_self(&expr_code, left_code TSRMLS_CC); + } + } else { + phalcon_concat_self(&expr_code, left_code TSRMLS_CC); + } + } + + phalcon_concat_self_str(&expr_code, SL("->") TSRMLS_CC); + + PHALCON_OBS_VAR(right); + phalcon_array_fetch_quick_string(&right, expr, SS("right"), 426864067UL, PH_NOISY); + + PHALCON_OBS_VAR(right_type); + phalcon_array_fetch_quick_string(&right_type, right, SS("type"), 276192743UL, PH_NOISY); + if (PHALCON_IS_LONG(right_type, 265)) { + PHALCON_OBS_VAR(member); + phalcon_array_fetch_quick_string(&member, right, SS("value"), 574111618UL, PH_NOISY); + phalcon_concat_self(&expr_code, member TSRMLS_CC); + } else { + PHALCON_INIT_VAR(right_code); + phalcon_call_method_p1_key(right_code, this_ptr, "expression", right, 218841909UL); + phalcon_concat_self(&expr_code, right_code TSRMLS_CC); + } + + RETURN_CCTOR(expr_code); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall){ + + zval *expr, *code = NULL, *func_arguments = NULL, *arguments = NULL; + zval *name_expr, *name_type, *name = NULL, *extensions; + zval *event, *fire_arguments, *functions, *definition; + zval *parameters, *line = NULL, *file = NULL, *exception_message = NULL; + zval *macros, *extended_blocks, *current_block; + zval *expr_level, *block, *escaped_code = NULL, *camelized; + zval *method, *class_name, *array_helpers = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &expr); + + if (Z_TYPE_P(expr) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted function call"); + return; + } + + PHALCON_INIT_VAR(code); + + PHALCON_INIT_VAR(func_arguments); + if (phalcon_array_isset_quick_string(expr, SS("arguments"), 3751272283UL)) { + PHALCON_OBS_NVAR(func_arguments); + phalcon_array_fetch_quick_string(&func_arguments, expr, SS("arguments"), 3751272283UL, PH_NOISY); + + PHALCON_INIT_VAR(arguments); + phalcon_call_method_p1_key(arguments, this_ptr, "expression", func_arguments, 218841909UL); + } else { + PHALCON_INIT_NVAR(arguments); + ZVAL_STRING(arguments, "", 1); + } + + PHALCON_OBS_VAR(name_expr); + phalcon_array_fetch_quick_string(&name_expr, expr, SS("name"), 268211462UL, PH_NOISY); + + PHALCON_OBS_VAR(name_type); + phalcon_array_fetch_quick_string(&name_type, name_expr, SS("type"), 276192743UL, PH_NOISY); + + if (PHALCON_IS_LONG(name_type, 265)) { + + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, name_expr, SS("value"), 574111618UL, PH_NOISY); + + PHALCON_OBS_VAR(extensions); + phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); + if (Z_TYPE_P(extensions) == IS_ARRAY) { + + PHALCON_INIT_VAR(event); + ZVAL_STRING(event, "compileFunction", 1); + + PHALCON_INIT_VAR(fire_arguments); + array_init_size(fire_arguments, 3); + phalcon_array_append(&fire_arguments, name, PH_SEPARATE); + phalcon_array_append(&fire_arguments, arguments, PH_SEPARATE); + phalcon_array_append(&fire_arguments, func_arguments, PH_SEPARATE); + + phalcon_call_method_p2_key(code, this_ptr, "fireextensionevent", event, fire_arguments, 1575031978UL); + if (Z_TYPE_P(code) == IS_STRING) { + RETURN_CCTOR(code); + } + } + + PHALCON_OBS_VAR(functions); + phalcon_read_property_this_quick(&functions, this_ptr, SL("_functions"), 2704716189UL, PH_NOISY_CC); + if (Z_TYPE_P(functions) == IS_ARRAY) { + if (phalcon_array_isset(functions, name)) { + + PHALCON_OBS_VAR(definition); + phalcon_array_fetch(&definition, functions, name, PH_NOISY); + + if (Z_TYPE_P(definition) == IS_STRING) { + PHALCON_CONCAT_VSVS(return_value, definition, "(", arguments, ")"); + RETURN_MM(); + } + + if (Z_TYPE_P(definition) == IS_OBJECT) { + if (phalcon_is_instance_of(definition, SL("Closure") TSRMLS_CC)) { + PHALCON_INIT_VAR(parameters); + array_init_size(parameters, 2); + phalcon_array_append(¶meters, arguments, PH_SEPARATE); + phalcon_array_append(¶meters, func_arguments, PH_SEPARATE); + phalcon_call_func_p2(return_value, "call_user_func_array", definition, parameters); + RETURN_MM(); + } + } + + PHALCON_OBS_VAR(line); + phalcon_array_fetch_quick_string(&line, expr, SS("line"), 266128205UL, PH_NOISY); + + PHALCON_OBS_VAR(file); + phalcon_array_fetch_quick_string(&file, expr, SS("file"), 259010501UL, PH_NOISY); + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVSVSV(exception_message, "Invalid definition for user function '", name, "' in ", file, " on line ", line); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; + } + } + + PHALCON_OBS_VAR(macros); + phalcon_read_property_this_quick(¯os, this_ptr, SL("_macros"), 3627118793UL, PH_NOISY_CC); + + if (phalcon_array_isset(macros, name)) { + PHALCON_CONCAT_SVSVS(return_value, "vmacro_", name, "(array(", arguments, "))"); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(name, "get_content")) { + RETURN_MM_STRING("$this->getContent()", 1); + } + + if (PHALCON_IS_STRING(name, "content")) { + RETURN_MM_STRING("$this->getContent()", 1); + } + + if (PHALCON_IS_STRING(name, "partial")) { + PHALCON_CONCAT_SVS(return_value, "$this->partial(", arguments, ")"); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(name, "super")) { + + PHALCON_OBS_VAR(extended_blocks); + phalcon_read_property_this_quick(&extended_blocks, this_ptr, SL("_extendedBlocks"), 3140083987UL, PH_NOISY_CC); + if (Z_TYPE_P(extended_blocks) == IS_ARRAY) { + + PHALCON_OBS_VAR(current_block); + phalcon_read_property_this_quick(¤t_block, this_ptr, SL("_currentBlock"), 1187906770UL, PH_NOISY_CC); + if (phalcon_array_isset(extended_blocks, current_block)) { + + PHALCON_OBS_VAR(expr_level); + phalcon_read_property_this_quick(&expr_level, this_ptr, SL("_exprLevel"), 4164657371UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(block); + phalcon_array_fetch(&block, extended_blocks, current_block, PH_NOISY); + if (Z_TYPE_P(block) == IS_ARRAY) { + + PHALCON_INIT_NVAR(code); + phalcon_call_method_p1_key(code, this_ptr, "_statementlistorextends", block, 2351303889UL); + if (PHALCON_IS_LONG(expr_level, 1)) { + PHALCON_CPY_WRT(escaped_code, code); + } else { + PHALCON_INIT_NVAR(escaped_code); + phalcon_call_func_p1(escaped_code, "addslashes", code); + } + } else { + if (PHALCON_IS_LONG(expr_level, 1)) { + PHALCON_CPY_WRT(escaped_code, block); + } else { + PHALCON_INIT_NVAR(escaped_code); + phalcon_call_func_p1(escaped_code, "addslashes", block); + } + } + + if (PHALCON_IS_LONG(expr_level, 1)) { + RETURN_CCTOR(escaped_code); + } + + PHALCON_CONCAT_SVS(return_value, "'", escaped_code, "'"); + + RETURN_MM(); + } + } + + RETURN_MM_STRING("''", 1); + } + + PHALCON_INIT_VAR(camelized); + phalcon_camelize(camelized, name); + + PHALCON_INIT_VAR(method); + phalcon_lcfirst(method, camelized); + + PHALCON_INIT_VAR(class_name); + ZVAL_STRING(class_name, "Phalcon\\Tag", 1); + + if (phalcon_method_exists(class_name, method TSRMLS_CC) == SUCCESS) { + + PHALCON_OBS_VAR(array_helpers); + phalcon_read_property_this_quick(&array_helpers, this_ptr, SL("_arrayHelpers"), 3087512406UL, PH_NOISY_CC); + if (Z_TYPE_P(array_helpers) != IS_ARRAY) { + PHALCON_INIT_NVAR(array_helpers); + array_init_size(array_helpers, 15); + 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); + add_assoc_bool_ex(array_helpers, SS("select"), 1); + add_assoc_bool_ex(array_helpers, SS("select_static"), 1); + add_assoc_bool_ex(array_helpers, SS("submit_button"), 1); + add_assoc_bool_ex(array_helpers, SS("radio_field"), 1); + add_assoc_bool_ex(array_helpers, SS("check_field"), 1); + add_assoc_bool_ex(array_helpers, SS("file_field"), 1); + add_assoc_bool_ex(array_helpers, SS("hidden_field"), 1); + add_assoc_bool_ex(array_helpers, SS("password_field"), 1); + add_assoc_bool_ex(array_helpers, SS("text_area"), 1); + add_assoc_bool_ex(array_helpers, SS("text_field"), 1); + add_assoc_bool_ex(array_helpers, SS("date_field"), 1); + add_assoc_bool_ex(array_helpers, SS("numeric_field"), 1); + phalcon_update_property_this_quick(this_ptr, SL("_arrayHelpers"), array_helpers, 3087512406UL TSRMLS_CC); + } - phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); + if (phalcon_array_isset(array_helpers, name)) { + PHALCON_CONCAT_SVSVS(return_value, "Phalcon\\Tag::", method, "(array(", arguments, "))"); + RETURN_MM(); + } -} - -static PHP_METHOD(Phalcon_Mvc_View, __get){ - - zval *key, *params, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); + PHALCON_CONCAT_SVSVS(return_value, "Phalcon\\Tag::", method, "(", arguments, ")"); - PHALCON_OBS_VAR(params); - phalcon_read_property_this_quick(¶ms, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); - if (phalcon_array_isset(params, key)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, params, key, PH_NOISY); - RETURN_CCTOR(value); - } + RETURN_MM(); + } - RETURN_MM_NULL(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_CollectionInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, CollectionInterface, mvc_collectioninterface, phalcon_mvc_collectioninterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc, Model, mvc_model, phalcon_mvc_model_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - zend_declare_property_null(phalcon_mvc_model_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_ce, SL("_modelsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_ce, SL("_modelsMetaData"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_ce, SL("_errorMessages"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_model_ce, SL("_operationMade"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_model_ce, SL("_dirtyState"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_ce, SL("_transaction"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_ce, SL("_uniqueKey"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_ce, SL("_uniqueParams"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_ce, SL("_uniqueTypes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_ce, SL("_skipped"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_ce, SL("_related"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_mvc_model_ce, SL("_snapshot"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("OP_NONE"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("OP_CREATE"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("OP_UPDATE"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("OP_DELETE"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("DIRTY_STATE_PERSISTENT"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("DIRTY_STATE_TRANSIENT"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_mvc_model_ce, SL("DIRTY_STATE_DETACHED"), 2 TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_ce TSRMLS_CC, 4, phalcon_mvc_modelinterface_ce, phalcon_mvc_model_resultinterface_ce, phalcon_di_injectionawareinterface_ce, zend_ce_serializable); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model, __construct){ - - zval *dependency_injector = NULL, *models_manager = NULL; - zval *service_name; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &dependency_injector, &models_manager); + if (PHALCON_IS_STRING(name, "url")) { + PHALCON_CONCAT_SVS(return_value, "$this->url->get(", arguments, ")"); + RETURN_MM(); + } - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } else { - PHALCON_SEPARATE_PARAM(dependency_injector); - } + if (PHALCON_IS_STRING(name, "static_url")) { + PHALCON_CONCAT_SVS(return_value, "$this->url->getStatic(", arguments, ")"); + RETURN_MM(); + } - if (!models_manager) { - PHALCON_INIT_VAR(models_manager); - } else { - PHALCON_SEPARATE_PARAM(models_manager); - } + if (PHALCON_IS_STRING(name, "date")) { + PHALCON_CONCAT_SVS(return_value, "date(", arguments, ")"); + RETURN_MM(); + } - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - } - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); - return; - } + if (PHALCON_IS_STRING(name, "time")) { + PHALCON_INIT_NVAR(code); + ZVAL_STRING(code, "time()", 1); + RETURN_CCTOR(code); + } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + if (PHALCON_IS_STRING(name, "dump")) { + PHALCON_CONCAT_SVS(return_value, "var_dump(", arguments, ")"); + RETURN_MM(); + } - if (Z_TYPE_P(models_manager) != IS_OBJECT) { + if (PHALCON_IS_STRING(name, "version")) { + RETURN_MM_STRING("Phalcon\\Version::get()", 1); + } - PHALCON_INIT_VAR(service_name); - ZVAL_STRING(service_name, "modelsManager", 1); + if (PHALCON_IS_STRING(name, "version_id")) { + RETURN_MM_STRING("Phalcon\\Version::getId()", 1); + } - PHALCON_INIT_NVAR(models_manager); - phalcon_call_method_p1_key(models_manager, dependency_injector, "getshared", service_name, 1727570332UL); - if (Z_TYPE_P(models_manager) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The injected service 'modelsManager' is not valid"); - return; + if (PHALCON_IS_STRING(name, "constant")) { + PHALCON_CONCAT_SVS(return_value, "constant(", arguments, ")"); + RETURN_MM(); } - } - phalcon_update_property_this_quick(this_ptr, SL("_modelsManager"), models_manager, 3699347875UL TSRMLS_CC); + PHALCON_OBS_NVAR(line); + phalcon_array_fetch_quick_string(&line, expr, SS("line"), 266128205UL, PH_NOISY); - phalcon_call_method_p1_key(NULL, models_manager, "initialize", this_ptr, 2896075127UL); + PHALCON_OBS_NVAR(file); + phalcon_array_fetch_quick_string(&file, expr, SS("file"), 259010501UL, PH_NOISY); - if (phalcon_method_quick_exists_ex(this_ptr, SS("onconstruct"), 564344039UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, this_ptr, "onconstruct", 564344039UL); + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVSV(exception_message, "Undefined function '", name, "' in ", file, " on line ", line); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; } - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + PHALCON_INIT_NVAR(name); + phalcon_call_method_p1_key(name, this_ptr, "expression", name_expr, 218841909UL); + PHALCON_CONCAT_VSVS(return_value, name, "(", arguments, ")"); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Model, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model, setEventsManager){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, resolveTest){ - zval *events_manager, *models_manager; + zval *test, *left, *type, *name = NULL, *test_name, *test_arguments = NULL; + zval *arguments = NULL, *right_code; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &events_manager); + phalcon_fetch_params(1, 2, 0, &test, &left); - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, models_manager, "setcustomeventsmanager", this_ptr, events_manager, 3062798396UL); + if (Z_TYPE_P(test) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted test"); + return; + } - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getEventsManager){ - - zval *models_manager; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, models_manager, "getcustomeventsmanager", this_ptr, 1410017072UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getModelsMetaData){ - - zval *meta_data = NULL, *dependency_injector, *service; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(meta_data); - phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_modelsMetaData"), 3906670569UL, PH_NOISY_CC); - if (Z_TYPE_P(meta_data) != IS_OBJECT) { + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, test, SS("type"), 276192743UL, PH_NOISY); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); - return; + if (PHALCON_IS_LONG(type, 265)) { + + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, test, SS("value"), 574111618UL, PH_NOISY); + + if (PHALCON_IS_STRING(name, "empty")) { + PHALCON_CONCAT_SVS(return_value, "empty(", left, ")"); + RETURN_MM(); } - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "modelsMetadata", 1); + if (PHALCON_IS_STRING(name, "even")) { + PHALCON_CONCAT_SVS(return_value, "(((", left, ") % 2) == 0)"); + RETURN_MM(); + } - PHALCON_INIT_NVAR(meta_data); - phalcon_call_method_p1_key(meta_data, dependency_injector, "getshared", service, 1727570332UL); - if (Z_TYPE_P(meta_data) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The injected service 'modelsMetadata' is not valid"); - return; + if (PHALCON_IS_STRING(name, "odd")) { + PHALCON_CONCAT_SVS(return_value, "(((", left, ") % 2) != 0)"); + RETURN_MM(); } - phalcon_update_property_this_quick(this_ptr, SL("_modelsMetaData"), meta_data, 3906670569UL TSRMLS_CC); - } + if (PHALCON_IS_STRING(name, "numeric")) { + PHALCON_CONCAT_SVS(return_value, "is_numeric(", left, ")"); + RETURN_MM(); + } - RETURN_CCTOR(meta_data); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getModelsManager){ - - - RETURN_MEMBER_QUICK(this_ptr, "_modelsManager", 3699347875UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model, setTransaction){ - - zval *transaction; - - phalcon_fetch_params(0, 1, 0, &transaction); + if (PHALCON_IS_STRING(name, "scalar")) { + PHALCON_CONCAT_SVS(return_value, "is_scalar(", left, ")"); + RETURN_MM(); + } - if (Z_TYPE_P(transaction) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_transaction"), transaction, 1141465066UL TSRMLS_CC); - RETURN_THISW(); + if (PHALCON_IS_STRING(name, "iterable")) { + PHALCON_CONCAT_SVSVS(return_value, "(is_array(", left, ") || (", left, ") instanceof Traversable)"); + RETURN_MM(); + } } - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Transaction should be an object"); - return; -} - -static PHP_METHOD(Phalcon_Mvc_Model, setSource){ - - zval *source, *models_manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &source); - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, models_manager, "setmodelsource", this_ptr, source, 3377351315UL); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getSource){ - - zval *models_manager; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, models_manager, "getmodelsource", this_ptr, 569714055UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, setSchema){ - - zval *schema, *models_manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &schema); + if (PHALCON_IS_LONG(type, 350)) { - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, models_manager, "setmodelschema", this_ptr, schema, 2891853203UL); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getSchema){ - - zval *models_manager; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, models_manager, "getmodelschema", this_ptr, 84215943UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, setConnectionService){ - - zval *connection_service, *models_manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &connection_service); + PHALCON_OBS_VAR(test_name); + phalcon_array_fetch_quick_string(&test_name, test, SS("name"), 268211462UL, PH_NOISY); + if (phalcon_array_isset_quick_string(test_name, SS("value"), 574111618UL)) { - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, models_manager, "setconnectionservice", this_ptr, connection_service, 4052304818UL); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, setReadConnectionService){ - - zval *connection_service, *models_manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &connection_service); + PHALCON_OBS_NVAR(name); + phalcon_array_fetch_quick_string(&name, test_name, SS("value"), 574111618UL, PH_NOISY); + if (PHALCON_IS_STRING(name, "divisibleby")) { + PHALCON_OBS_VAR(test_arguments); + phalcon_array_fetch_quick_string(&test_arguments, test, SS("arguments"), 3751272283UL, PH_NOISY); - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, models_manager, "setreadconnectionservice", this_ptr, connection_service, 1669421294UL); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, setWriteConnectionService){ - - zval *connection_service, *models_manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &connection_service); + PHALCON_INIT_VAR(arguments); + phalcon_call_method_p1_key(arguments, this_ptr, "expression", test_arguments, 218841909UL); + PHALCON_CONCAT_SVSVS(return_value, "(((", left, ") % (", arguments, ")) == 0)"); + RETURN_MM(); + } - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, models_manager, "setwriteconnectionservice", this_ptr, connection_service, 1190096957UL); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getReadConnectionService){ - - zval *models_manager; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, models_manager, "getreadconnectionservice", this_ptr, 1381856482UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getWriteConnectionService){ - - zval *models_manager; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, models_manager, "getwriteconnectionservice", this_ptr, 290392753UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, setDirtyState){ - - zval *dirty_state; - - phalcon_fetch_params(0, 1, 0, &dirty_state); + if (PHALCON_IS_STRING(name, "sameas")) { + PHALCON_OBS_NVAR(test_arguments); + phalcon_array_fetch_quick_string(&test_arguments, test, SS("arguments"), 3751272283UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_dirtyState"), dirty_state, 1560981745UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getDirtyState){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dirtyState", 1560981745UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getReadConnection){ - - zval *models_manager; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, models_manager, "getreadconnection", this_ptr, 488334257UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getWriteConnection){ - - zval *transaction, *models_manager; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(transaction); - phalcon_read_property_this_quick(&transaction, this_ptr, SL("_transaction"), 1141465066UL, PH_NOISY_CC); - if (Z_TYPE_P(transaction) == IS_OBJECT) { - phalcon_call_method_key(return_value, transaction, "getconnection", 2504689909UL); - RETURN_MM(); + PHALCON_INIT_NVAR(arguments); + phalcon_call_method_p1_key(arguments, this_ptr, "expression", test_arguments, 218841909UL); + PHALCON_CONCAT_SVSVS(return_value, "(", left, ") === (", arguments, ")"); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(name, "type")) { + PHALCON_OBS_NVAR(test_arguments); + phalcon_array_fetch_quick_string(&test_arguments, test, SS("arguments"), 3751272283UL, PH_NOISY); + + PHALCON_INIT_NVAR(arguments); + phalcon_call_method_p1_key(arguments, this_ptr, "expression", test_arguments, 218841909UL); + PHALCON_CONCAT_SVSVS(return_value, "gettype(", left, ") === (", arguments, ")"); + RETURN_MM(); + } + } } - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, models_manager, "getwriteconnection", this_ptr, 4280185952UL); + PHALCON_INIT_VAR(right_code); + phalcon_call_method_p1_key(right_code, this_ptr, "expression", test, 218841909UL); + PHALCON_CONCAT_VSV(return_value, left, " == ", right_code); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Model, assign){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, resolveFilter){ - zval *data, *column_map = NULL, *value = NULL, *key = NULL, *attribute = NULL; - zval *exception_message = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *filter, *left, *code = NULL, *type, *name = NULL, *function_name; + zval *line = NULL, *file = NULL, *exception_message = NULL, *func_arguments = NULL; + zval *arguments = NULL, *resolved_expr, *resolved_param; + zval *extensions, *event, *fire_arguments, *filters; + zval *definition, *parameters; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &data, &column_map); - - if (!column_map) { - PHALCON_INIT_VAR(column_map); - } + phalcon_fetch_params(1, 2, 0, &filter, &left); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data to dump in the object must be an Array"); + if (Z_TYPE_P(filter) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted filter"); return; } - phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(code); - PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, filter, SS("type"), 276192743UL, PH_NOISY); - if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (PHALCON_IS_LONG(type, 265)) { + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, filter, SS("value"), 574111618UL, PH_NOISY); + } else { + if (PHALCON_IS_LONG(type, 350)) { + PHALCON_OBS_VAR(function_name); + phalcon_array_fetch_quick_string(&function_name, filter, SS("name"), 268211462UL, PH_NOISY); - if (phalcon_array_isset(column_map, key)) { - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch(&attribute, column_map, key, PH_NOISY); - phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column \"", key, "\" doesn't make part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + PHALCON_OBS_NVAR(name); + phalcon_array_fetch_quick_string(&name, function_name, SS("value"), 574111618UL, PH_NOISY); } else { - phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); - } + PHALCON_OBS_VAR(line); + phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_OBS_VAR(file); + phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "Unknown filter type in ", file, " on line ", line); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; + } } + PHALCON_INIT_VAR(func_arguments); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, cloneResultMap){ - - zval *base, *data, *column_map, *dirty_state = NULL, *keep_snapshots = NULL; - zval *object, *value = NULL, *key = NULL, *attribute = NULL, *exception_message = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 2, &base, &data, &column_map, &dirty_state, &keep_snapshots); + PHALCON_INIT_VAR(arguments); - if (!dirty_state) { - PHALCON_INIT_VAR(dirty_state); - ZVAL_LONG(dirty_state, 0); - } + if (phalcon_array_isset_quick_string(filter, SS("arguments"), 3751272283UL)) { - if (!keep_snapshots) { - PHALCON_INIT_VAR(keep_snapshots); - } + PHALCON_OBS_NVAR(file); + phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data to dump in the object must be an Array"); - return; - } + PHALCON_OBS_NVAR(line); + phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); - PHALCON_INIT_VAR(object); - if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { - return; + PHALCON_OBS_NVAR(func_arguments); + phalcon_array_fetch_quick_string(&func_arguments, filter, SS("arguments"), 3751272283UL, PH_NOISY); + + if (!PHALCON_IS_STRING(name, "default")) { + PHALCON_INIT_VAR(resolved_expr); + array_init_size(resolved_expr, 4); + add_assoc_long_ex(resolved_expr, SS("type"), 364); + phalcon_array_update_quick_string(&resolved_expr, SS("value"), 574111618UL, &left, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&resolved_expr, SS("file"), 259010501UL, &file, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&resolved_expr, SS("line"), 266128205UL, &line, PH_COPY | PH_SEPARATE); + + PHALCON_INIT_VAR(resolved_param); + array_init_size(resolved_param, 3); + phalcon_array_update_quick_string(&resolved_param, SS("expr"), 258368420UL, &resolved_expr, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&resolved_param, SS("file"), 259010501UL, &file, PH_COPY | PH_SEPARATE); + phalcon_array_update_quick_string(&resolved_param, SS("line"), 266128205UL, &line, PH_COPY | PH_SEPARATE); + + phalcon_array_unshift(func_arguments, resolved_param); + } + + phalcon_call_method_p1_key(arguments, this_ptr, "expression", func_arguments, 218841909UL); + } else { + PHALCON_CPY_WRT(arguments, left); } - phalcon_call_method_p1_key(NULL, object, "setdirtystate", dirty_state, 1304577662UL); + PHALCON_OBS_VAR(extensions); + phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); + if (Z_TYPE_P(extensions) == IS_ARRAY) { - phalcon_is_iterable(data, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(event); + ZVAL_STRING(event, "compileFilter", 1); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(fire_arguments); + array_init_size(fire_arguments, 3); + phalcon_array_append(&fire_arguments, name, PH_SEPARATE); + phalcon_array_append(&fire_arguments, arguments, PH_SEPARATE); + phalcon_array_append(&fire_arguments, func_arguments, PH_SEPARATE); - PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + phalcon_call_method_p2_key(code, this_ptr, "fireextensionevent", event, fire_arguments, 1575031978UL); + if (Z_TYPE_P(code) == IS_STRING) { + RETURN_CCTOR(code); + } + } - if (Z_TYPE_P(key) == IS_STRING) { + PHALCON_OBS_VAR(filters); + phalcon_read_property_this_quick(&filters, this_ptr, SL("_filters"), 3850488637UL, PH_NOISY_CC); + if (Z_TYPE_P(filters) == IS_ARRAY) { + if (phalcon_array_isset(filters, name)) { - if (Z_TYPE_P(column_map) == IS_ARRAY) { + PHALCON_OBS_VAR(definition); + phalcon_array_fetch(&definition, filters, name, PH_NOISY); - if (phalcon_array_isset(column_map, key)) { - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch(&attribute, column_map, key, PH_NOISY); - phalcon_update_property_zval_zval(object, attribute, value TSRMLS_CC); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column \"", key, "\" doesn't make part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; + if (Z_TYPE_P(definition) == IS_STRING) { + PHALCON_CONCAT_VSVS(return_value, definition, "(", arguments, ")"); + RETURN_MM(); + } + + if (Z_TYPE_P(definition) == IS_OBJECT) { + if (phalcon_is_instance_of(definition, SL("Closure") TSRMLS_CC)) { + PHALCON_INIT_VAR(parameters); + array_init_size(parameters, 2); + phalcon_array_append(¶meters, arguments, PH_SEPARATE); + phalcon_array_append(¶meters, func_arguments, PH_SEPARATE); + phalcon_call_func_p2(return_value, "call_user_func_array", definition, parameters); + RETURN_MM(); } - } else { - phalcon_update_property_zval_zval(object, key, value TSRMLS_CC); } + + PHALCON_OBS_NVAR(line); + phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); + + PHALCON_OBS_NVAR(file); + phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVSV(exception_message, "Invalid definition for user filter '", name, "' in ", file, " on line ", line); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; } + } - zend_hash_move_forward_ex(ah0, &hp0); + if (PHALCON_IS_STRING(name, "length")) { + PHALCON_CONCAT_SVS(return_value, "$this->length(", arguments, ")"); + RETURN_MM(); } - if (zend_is_true(keep_snapshots)) { - phalcon_call_method_p2_key(NULL, object, "setsnapshotdata", data, column_map, 1073494651UL); + if (PHALCON_IS_STRING(name, "e")) { + PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtml(", arguments, ")"); + RETURN_MM(); } - if (phalcon_method_quick_exists_ex(object, SS("afterfetch"), 1256108385UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, object, "afterfetch", 1256108385UL); + if (PHALCON_IS_STRING(name, "escape")) { + PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtml(", arguments, ")"); + RETURN_MM(); } - RETURN_CCTOR(object); -} - -static PHP_METHOD(Phalcon_Mvc_Model, cloneResultMapHydrate){ - - zval *data, *column_map, *hydration_mode, *hydrate = NULL; - zval *value = NULL, *key = NULL, *exception_message = NULL, *attribute = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &data, &column_map, &hydration_mode); + if (PHALCON_IS_STRING(name, "escape_css")) { + PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeCss(", arguments, ")"); + RETURN_MM(); + } - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data to hidrate must be an Array"); - return; + if (PHALCON_IS_STRING(name, "escape_js")) { + PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeJs(", arguments, ")"); + RETURN_MM(); } - if (Z_TYPE_P(column_map) != IS_ARRAY) { - if (PHALCON_IS_LONG(hydration_mode, 1)) { - RETURN_CCTOR(data); - } + if (PHALCON_IS_STRING(name, "escape_attr")) { + PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtmlAttr(", arguments, ")"); + RETURN_MM(); } - if (PHALCON_IS_LONG(hydration_mode, 1)) { - PHALCON_INIT_VAR(hydrate); - array_init(hydrate); - } else { - PHALCON_INIT_NVAR(hydrate); - object_init(hydrate); + if (PHALCON_IS_STRING(name, "trim")) { + PHALCON_CONCAT_SVS(return_value, "trim(", arguments, ")"); + RETURN_MM(); } - phalcon_is_iterable(data, &ah0, &hp0, 0, 0); + if (PHALCON_IS_STRING(name, "left_trim")) { + PHALCON_CONCAT_SVS(return_value, "ltrim(", arguments, ")"); + RETURN_MM(); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (PHALCON_IS_STRING(name, "right_trim")) { + PHALCON_CONCAT_SVS(return_value, "rtrim(", arguments, ")"); + RETURN_MM(); + } - PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + if (PHALCON_IS_STRING(name, "striptags")) { + PHALCON_CONCAT_SVS(return_value, "strip_tags(", arguments, ")"); + RETURN_MM(); + } - if (Z_TYPE_P(key) == IS_STRING) { - if (Z_TYPE_P(column_map) == IS_ARRAY) { + if (PHALCON_IS_STRING(name, "url_encode")) { + PHALCON_CONCAT_SVS(return_value, "urlencode(", arguments, ")"); + RETURN_MM(); + } - if (!phalcon_array_isset(column_map, key)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column \"", key, "\" doesn't make part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + if (PHALCON_IS_STRING(name, "slashes")) { + PHALCON_CONCAT_SVS(return_value, "addslashes(", arguments, ")"); + RETURN_MM(); + } - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch(&attribute, column_map, key, PH_NOISY); - if (PHALCON_IS_LONG(hydration_mode, 1)) { - phalcon_array_update_zval(&hydrate, attribute, &value, PH_COPY | PH_SEPARATE); - } else { - phalcon_update_property_zval_zval(hydrate, attribute, value TSRMLS_CC); - } - } else { - if (PHALCON_IS_LONG(hydration_mode, 1)) { - phalcon_array_update_zval(&hydrate, key, &value, PH_COPY | PH_SEPARATE); - } else { - phalcon_update_property_zval_zval(hydrate, key, value TSRMLS_CC); - } - } - } + if (PHALCON_IS_STRING(name, "stripslashes")) { + PHALCON_CONCAT_SVS(return_value, "stripslashes(", arguments, ")"); + RETURN_MM(); + } - zend_hash_move_forward_ex(ah0, &hp0); + if (PHALCON_IS_STRING(name, "nl2br")) { + PHALCON_CONCAT_SVS(return_value, "nl2br(", arguments, ")"); + RETURN_MM(); } - RETURN_CCTOR(hydrate); -} - -static PHP_METHOD(Phalcon_Mvc_Model, cloneResult){ - - zval *base, *data, *dirty_state = NULL, *object, *value = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &base, &data, &dirty_state); + if (PHALCON_IS_STRING(name, "keys")) { + PHALCON_CONCAT_SVS(return_value, "array_keys(", arguments, ")"); + RETURN_MM(); + } - if (!dirty_state) { - PHALCON_INIT_VAR(dirty_state); - ZVAL_LONG(dirty_state, 0); + if (PHALCON_IS_STRING(name, "join")) { + PHALCON_CONCAT_SVS(return_value, "join(", arguments, ")"); + RETURN_MM(); } - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data to dump in the object must be an Array"); - return; + if (PHALCON_IS_STRING(name, "lowercase")) { + PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::lower(", arguments, ")"); + RETURN_MM(); } - PHALCON_INIT_VAR(object); - if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { - return; + if (PHALCON_IS_STRING(name, "lower")) { + PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::lower(", arguments, ")"); + RETURN_MM(); } - phalcon_call_method_p1_key(NULL, object, "setdirtystate", dirty_state, 1304577662UL); + if (PHALCON_IS_STRING(name, "uppercase")) { + PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::upper(", arguments, ")"); + RETURN_MM(); + } - phalcon_is_iterable(data, &ah0, &hp0, 0, 0); + if (PHALCON_IS_STRING(name, "upper")) { + PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::upper(", arguments, ")"); + RETURN_MM(); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (PHALCON_IS_STRING(name, "capitalize")) { + PHALCON_CONCAT_SVS(return_value, "ucwords(", arguments, ")"); + RETURN_MM(); + } - PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + if (PHALCON_IS_STRING(name, "sort")) { + PHALCON_CONCAT_SVS(return_value, "$this->sort(", arguments, ")"); + RETURN_MM(); + } - if (Z_TYPE_P(key) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid key in array data provided to dumpResult()"); - return; - } - phalcon_update_property_zval_zval(object, key, value TSRMLS_CC); + if (PHALCON_IS_STRING(name, "json_encode")) { + PHALCON_CONCAT_SVS(return_value, "json_encode(", arguments, ")"); + RETURN_MM(); + } - zend_hash_move_forward_ex(ah0, &hp0); + if (PHALCON_IS_STRING(name, "json_decode")) { + PHALCON_CONCAT_SVS(return_value, "json_decode(", arguments, ")"); + RETURN_MM(); } - if (phalcon_method_quick_exists_ex(object, SS("afterfetch"), 1256108385UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, object, "afterfetch", 1256108385UL); + if (PHALCON_IS_STRING(name, "format")) { + PHALCON_CONCAT_SVS(return_value, "sprintf(", arguments, ")"); + RETURN_MM(); } - RETURN_CCTOR(object); + if (PHALCON_IS_STRING(name, "abs")) { + PHALCON_CONCAT_SVS(return_value, "abs(", arguments, ")"); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(name, "slice")) { + PHALCON_CONCAT_SVS(return_value, "$this->slice(", arguments, ")"); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(name, "default")) { + PHALCON_CONCAT_SVSVSVS(return_value, "(empty(", left, ") ? (", arguments, ") : (", left, "))"); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(name, "convert_encoding")) { + PHALCON_CONCAT_SVS(return_value, "$this->convertEncoding(", arguments, ")"); + RETURN_MM(); + } + + PHALCON_OBS_NVAR(line); + phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); + + PHALCON_OBS_NVAR(file); + phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVSV(exception_message, "Unknown filter \"", name, "\" in ", file, " on line ", line); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; } -static PHP_METHOD(Phalcon_Mvc_Model, find){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, expression){ - zval *parameters = NULL, *model_name, *params = NULL, *builder; - zval *query, *bind_params = NULL, *bind_types = NULL, *cache; - zval *resultset, *hydration; + zval *expr, *expr_code = NULL, *extensions, *event = NULL, *fire_arguments = NULL; + zval *items = NULL, *single_expr = NULL, *single_expr_expr = NULL; + zval *single_expr_code = NULL, *name = NULL, *parameter = NULL, *type = NULL; + zval *left = NULL, *left_code = NULL, *right_code = NULL, *right = NULL, *value = NULL; + zval *single_quote = NULL, *escaped_quoute = NULL, *escaped_string = NULL; + zval *start = NULL, *start_code = NULL, *end = NULL, *end_code = NULL, *ternary = NULL; + zval *ternary_code = NULL, *line = NULL, *file = NULL, *exception_message = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, ¶meters); + phalcon_fetch_params(1, 1, 0, &expr); - if (!parameters) { - PHALCON_INIT_VAR(parameters); + if (Z_TYPE_P(expr) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted expression"); + return; } - PHALCON_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); - if (Z_TYPE_P(parameters) != IS_ARRAY) { + PHALCON_INIT_VAR(expr_code); + phalcon_property_incr(this_ptr, SL("_exprLevel") TSRMLS_CC); - PHALCON_INIT_VAR(params); - array_init(params); - if (Z_TYPE_P(parameters) != IS_NULL) { - phalcon_array_append(¶ms, parameters, PH_SEPARATE); + PHALCON_OBS_VAR(extensions); + phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); + + while (1) { + + if (Z_TYPE_P(extensions) == IS_ARRAY) { + + PHALCON_INIT_NVAR(event); + ZVAL_STRING(event, "resolveExpression", 1); + + PHALCON_INIT_NVAR(fire_arguments); + array_init_size(fire_arguments, 1); + phalcon_array_append(&fire_arguments, expr, PH_SEPARATE); + + PHALCON_INIT_NVAR(expr_code); + phalcon_call_method_p2_key(expr_code, this_ptr, "fireextensionevent", event, fire_arguments, 1575031978UL); + if (Z_TYPE_P(expr_code) == IS_STRING) { + break; + } } - } else { - PHALCON_CPY_WRT(params, parameters); - } + if (!phalcon_array_isset_quick_string(expr, SS("type"), 276192743UL)) { - PHALCON_INIT_VAR(builder); - object_init_ex(builder, phalcon_mvc_model_query_builder_ce); - phalcon_call_method_p1_key(NULL, builder, "__construct", params, 1107214344UL); + PHALCON_INIT_NVAR(items); + array_init(items); - phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); + phalcon_is_iterable(expr, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(query); - phalcon_call_method_key(query, builder, "getquery", 4154457883UL); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(bind_params); + PHALCON_GET_HVALUE(single_expr); - PHALCON_INIT_VAR(bind_types); + PHALCON_OBS_NVAR(single_expr_expr); + phalcon_array_fetch_quick_string(&single_expr_expr, single_expr, SS("expr"), 258368420UL, PH_NOISY); - if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { + PHALCON_INIT_NVAR(single_expr_code); + phalcon_call_method_p1_key(single_expr_code, this_ptr, "expression", single_expr_expr, 218841909UL); + if (phalcon_array_isset_quick_string(single_expr, SS("name"), 268211462UL)) { + PHALCON_OBS_NVAR(name); + phalcon_array_fetch_quick_string(&name, single_expr, SS("name"), 268211462UL, PH_NOISY); - PHALCON_OBS_NVAR(bind_params); - phalcon_array_fetch_quick_string(&bind_params, params, SS("bind"), 254268962UL, PH_NOISY); - if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { - PHALCON_OBS_NVAR(bind_types); - phalcon_array_fetch_quick_string(&bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); + PHALCON_INIT_NVAR(parameter); + PHALCON_CONCAT_SVSV(parameter, "'", name, "' => ", single_expr_code); + phalcon_array_append(&items, parameter, PH_SEPARATE); + } else { + phalcon_array_append(&items, single_expr_code, PH_SEPARATE); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_INIT_NVAR(expr_code); + phalcon_fast_join_str(expr_code, SL(", "), items TSRMLS_CC); + break; } - } - if (phalcon_array_isset_quick_string(params, SS("cache"), 4125168857UL)) { - PHALCON_OBS_VAR(cache); - phalcon_array_fetch_quick_string(&cache, params, SS("cache"), 4125168857UL, PH_NOISY); - phalcon_call_method_p1_key(NULL, query, "cache", cache, 4125168857UL); - } + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, expr, SS("type"), 276192743UL, PH_NOISY); - PHALCON_INIT_VAR(resultset); - phalcon_call_method_p2_key(resultset, query, "execute", bind_params, bind_types, 3117639032UL); + if (PHALCON_IS_LONG(type, 46)) { + PHALCON_INIT_NVAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "attributereader", expr, 3193180844UL); + break; + } - if (Z_TYPE_P(resultset) == IS_OBJECT) { - if (phalcon_array_isset_quick_string(params, SS("hydration"), 1688432023UL)) { - PHALCON_OBS_VAR(hydration); - phalcon_array_fetch_quick_string(&hydration, params, SS("hydration"), 1688432023UL, PH_NOISY); - phalcon_call_method_p1_key(NULL, resultset, "sethydratemode", hydration, 46032167UL); + if (phalcon_array_isset_quick_string(expr, SS("left"), 265976240UL)) { + PHALCON_OBS_NVAR(left); + phalcon_array_fetch_quick_string(&left, expr, SS("left"), 265976240UL, PH_NOISY); + + PHALCON_INIT_NVAR(left_code); + phalcon_call_method_p1_key(left_code, this_ptr, "expression", left, 218841909UL); + } + + if (PHALCON_IS_LONG(type, 311)) { + PHALCON_OBS_NVAR(right_code); + phalcon_array_fetch_quick_string(&right_code, expr, SS("right"), 426864067UL, PH_NOISY); + + PHALCON_INIT_NVAR(expr_code); + phalcon_call_method_p2_key(expr_code, this_ptr, "resolvetest", right_code, left_code, 812472805UL); + break; } - } - RETURN_CCTOR(resultset); -} - -static PHP_METHOD(Phalcon_Mvc_Model, findFirst){ - - zval *parameters = NULL, *model_name, *params = NULL, *builder; - zval *one, *query, *bind_params = NULL, *bind_types = NULL, *cache; - zval *unique; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, ¶meters); + if (PHALCON_IS_LONG(type, 124)) { + PHALCON_OBS_NVAR(right_code); + phalcon_array_fetch_quick_string(&right_code, expr, SS("right"), 426864067UL, PH_NOISY); - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + PHALCON_INIT_NVAR(expr_code); + phalcon_call_method_p2_key(expr_code, this_ptr, "resolvefilter", right_code, left_code, 3562260459UL); + break; + } - PHALCON_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); - if (Z_TYPE_P(parameters) != IS_ARRAY) { + if (phalcon_array_isset_quick_string(expr, SS("right"), 426864067UL)) { + PHALCON_OBS_NVAR(right); + phalcon_array_fetch_quick_string(&right, expr, SS("right"), 426864067UL, PH_NOISY); - PHALCON_INIT_VAR(params); - array_init(params); - if (Z_TYPE_P(parameters) != IS_NULL) { - phalcon_array_append(¶ms, parameters, PH_SEPARATE); + PHALCON_INIT_NVAR(right_code); + phalcon_call_method_p1_key(right_code, this_ptr, "expression", right, 218841909UL); } - } else { - PHALCON_CPY_WRT(params, parameters); - } - PHALCON_INIT_VAR(builder); - object_init_ex(builder, phalcon_mvc_model_query_builder_ce); - phalcon_call_method_p1_key(NULL, builder, "__construct", params, 1107214344UL); + PHALCON_INIT_NVAR(expr_code); - phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); + switch (phalcon_get_intval(type)) { - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - phalcon_call_method_p1_key(NULL, builder, "limit", one, 192268420UL); + case 33: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SV(expr_code, "!", right_code); + break; - PHALCON_INIT_VAR(query); - phalcon_call_method_key(query, builder, "getquery", 4154457883UL); + case 42: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " * ", right_code); + break; - PHALCON_INIT_VAR(bind_params); + case 43: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " + ", right_code); + break; - PHALCON_INIT_VAR(bind_types); - if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { + case 45: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " - ", right_code); + break; - PHALCON_OBS_NVAR(bind_params); - phalcon_array_fetch_quick_string(&bind_params, params, SS("bind"), 254268962UL, PH_NOISY); - if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { - PHALCON_OBS_NVAR(bind_types); - phalcon_array_fetch_quick_string(&bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); - } - } + case 47: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " / ", right_code); + break; - if (phalcon_array_isset_quick_string(params, SS("cache"), 4125168857UL)) { - PHALCON_OBS_VAR(cache); - phalcon_array_fetch_quick_string(&cache, params, SS("cache"), 4125168857UL, PH_NOISY); - phalcon_call_method_p1_key(NULL, query, "cache", cache, 4125168857UL); - } + case 37: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " % ", right_code); + break; - PHALCON_INIT_VAR(unique); - ZVAL_BOOL(unique, 1); + case 60: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " < ", right_code); + break; - phalcon_call_method_p1_key(NULL, query, "setuniquerow", unique, 2999205376UL); + case 61: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " > ", right_code); + break; - phalcon_call_method_p2_key(return_value, query, "execute", bind_params, bind_types, 3117639032UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, query){ - - zval *dependency_injector = NULL, *model_name, *criteria; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &dependency_injector); + case 62: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " > ", right_code); + break; - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } else { - PHALCON_SEPARATE_PARAM(dependency_injector); - } + case 126: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " . ", right_code); + break; - PHALCON_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); + case 278: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVS(expr_code, "pow(", left_code, ", ", right_code, ")"); + break; - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - } + case 360: + if (phalcon_array_isset_quick_string(expr, SS("left"), 265976240UL)) { + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVS(expr_code, "array(", left_code, ")"); + } else { + PHALCON_INIT_NVAR(expr_code); + ZVAL_STRING(expr_code, "array()", 1); + } + break; - PHALCON_INIT_VAR(criteria); - object_init_ex(criteria, phalcon_mvc_model_criteria_ce); - phalcon_call_method_p1_key(NULL, criteria, "setdi", dependency_injector, 461718238UL); - phalcon_call_method_p1_key(NULL, criteria, "setmodelname", model_name, 3112384035UL); + case 258: + PHALCON_OBS_NVAR(expr_code); + phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); + break; - RETURN_CTOR(criteria); -} - -static PHP_METHOD(Phalcon_Mvc_Model, _exists){ - - zval *meta_data, *connection, *table = NULL, *unique_params = NULL; - zval *unique_types = NULL, *unique_key = NULL, *primary_keys; - zval *bind_data_types, *number_primary, *column_map = NULL; - zval *null_value, *number_empty, *where_pk, *field = NULL; - zval *attribute_field = NULL, *exception_message = NULL; - zval *value = NULL, *escaped_field = NULL, *pk_condition = NULL, *type = NULL; - zval *join_where, *dirty_state, *schema, *source; - zval *escaped_table, *null_mode, *select, *num; - zval *row_count; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &meta_data, &connection, &table); + case 259: + PHALCON_OBS_NVAR(expr_code); + phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); + break; - if (!table) { - PHALCON_INIT_VAR(table); - } else { - PHALCON_SEPARATE_PARAM(table); - } + case 260: + PHALCON_OBS_NVAR(value); + phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - PHALCON_INIT_VAR(unique_params); + PHALCON_INIT_NVAR(single_quote); + ZVAL_STRING(single_quote, "'", 1); - PHALCON_INIT_VAR(unique_types); + PHALCON_INIT_NVAR(escaped_quoute); + ZVAL_STRING(escaped_quoute, "\\'", 1); - PHALCON_OBS_VAR(unique_key); - phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); - if (Z_TYPE_P(unique_key) == IS_NULL) { + PHALCON_INIT_NVAR(escaped_string); + phalcon_fast_str_replace(escaped_string, single_quote, escaped_quoute, value); - PHALCON_INIT_VAR(primary_keys); - phalcon_call_method_p1_key(primary_keys, meta_data, "getprimarykeyattributes", this_ptr, 692945721UL); + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVS(expr_code, "'", escaped_string, "'"); + break; - PHALCON_INIT_VAR(bind_data_types); - phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); + case 261: + PHALCON_INIT_NVAR(expr_code); + ZVAL_STRING(expr_code, "null", 1); + break; - PHALCON_INIT_VAR(number_primary); - phalcon_fast_count(number_primary, primary_keys TSRMLS_CC); - if (!zend_is_true(number_primary)) { - RETURN_MM_FALSE; - } + case 262: + PHALCON_INIT_NVAR(expr_code); + ZVAL_STRING(expr_code, "false", 1); + break; - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); - } else { - PHALCON_INIT_NVAR(column_map); - } + case 263: + PHALCON_INIT_NVAR(expr_code); + ZVAL_STRING(expr_code, "true", 1); + break; - PHALCON_INIT_VAR(null_value); + case 265: + PHALCON_OBS_NVAR(value); + phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - PHALCON_INIT_VAR(number_empty); - ZVAL_LONG(number_empty, 0); + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SV(expr_code, "$", value); + break; - PHALCON_INIT_VAR(where_pk); - array_init(where_pk); + case 266: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " && ", right_code); + break; - array_init(unique_params); + case 267: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " || ", right_code); + break; - array_init(unique_types); + case 270: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " <= ", right_code); + break; - phalcon_is_iterable(primary_keys, &ah0, &hp0, 0, 0); + case 271: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " >= ", right_code); + break; - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + case 272: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " == ", right_code); + break; - PHALCON_GET_HVALUE(field); + case 273: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " != ", right_code); + break; - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, field)) { - PHALCON_OBS_NVAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, field, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(attribute_field, field); - } + case 274: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " === ", right_code); + break; - if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { + case 275: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " !== ", right_code); + break; - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); + case 276: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVS(expr_code, "range(", left_code, ", ", right_code, ")"); + break; - if (PHALCON_IS_EMPTY(value)) { - PHALCON_SEPARATE(number_empty); - phalcon_increment(number_empty); - } + case 350: + PHALCON_INIT_NVAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "functioncall", expr, 1638966055UL); + break; - phalcon_array_append(&unique_params, value, PH_SEPARATE); - } else { - phalcon_array_append(&unique_params, null_value, PH_SEPARATE); - PHALCON_SEPARATE(number_empty); - phalcon_increment(number_empty); - } + case 356: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVS(expr_code, "(", left_code, ")"); + break; - PHALCON_INIT_NVAR(escaped_field); - phalcon_call_method_p1_key(escaped_field, connection, "escapeidentifier", field, 585773337UL); + case 361: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSVS(expr_code, left_code, "[", right_code, "]"); + break; - PHALCON_INIT_NVAR(pk_condition); - PHALCON_CONCAT_VS(pk_condition, escaped_field, " = ?"); - if (!phalcon_array_isset(bind_data_types, field)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the table columns"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + case 365: + if (phalcon_array_isset_quick_string(expr, SS("start"), 478839859UL)) { + PHALCON_OBS_NVAR(start); + phalcon_array_fetch_quick_string(&start, expr, SS("start"), 478839859UL, PH_NOISY); - PHALCON_OBS_NVAR(type); - phalcon_array_fetch(&type, bind_data_types, field, PH_NOISY); - phalcon_array_append(&unique_types, type, PH_SEPARATE); - phalcon_array_append(&where_pk, pk_condition, PH_SEPARATE); + PHALCON_INIT_NVAR(start_code); + phalcon_call_method_p1_key(start_code, this_ptr, "expression", start, 218841909UL); + } else { + PHALCON_INIT_NVAR(start_code); + ZVAL_STRING(start_code, "null", 1); + } - zend_hash_move_forward_ex(ah0, &hp0); - } + if (phalcon_array_isset_quick_string(expr, SS("end"), 2090226332UL)) { + PHALCON_OBS_NVAR(end); + phalcon_array_fetch_quick_string(&end, expr, SS("end"), 2090226332UL, PH_NOISY); - if (PHALCON_IS_EQUAL(number_primary, number_empty)) { - RETURN_MM_FALSE; - } + PHALCON_INIT_NVAR(end_code); + phalcon_call_method_p1_key(end_code, this_ptr, "expression", end, 218841909UL); + } else { + PHALCON_INIT_NVAR(end_code); + ZVAL_STRING(end_code, "null", 1); + } - PHALCON_INIT_VAR(join_where); - phalcon_fast_join_str(join_where, SL(" AND "), where_pk TSRMLS_CC); + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVSVS(expr_code, "$this->slice(", left_code, ", ", start_code, ", ", end_code, ")"); + break; - phalcon_update_property_this_quick(this_ptr, SL("_uniqueKey"), join_where, 1221404964UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_uniqueParams"), unique_params, 1065564063UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_uniqueTypes"), unique_types, 3340838640UL TSRMLS_CC); - PHALCON_CPY_WRT(unique_key, join_where); - } + case 362: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVS(expr_code, "!isset(", left_code, ")"); + break; - PHALCON_OBS_VAR(dirty_state); - phalcon_read_property_this_quick(&dirty_state, this_ptr, SL("_dirtyState"), 1560981745UL, PH_NOISY_CC); - if (!zend_is_true(dirty_state)) { - RETURN_MM_TRUE; - } + case 363: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVS(expr_code, "isset(", left_code, ")"); + break; - if (Z_TYPE_P(unique_key) == IS_NULL) { - PHALCON_OBS_NVAR(unique_key); - phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); - } + case 309: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVS(expr_code, "$this->isIncluded(", left_code, ", ", right_code, ")"); + break; - if (Z_TYPE_P(unique_params) == IS_NULL) { - PHALCON_OBS_NVAR(unique_params); - phalcon_read_property_this_quick(&unique_params, this_ptr, SL("_uniqueParams"), 1065564063UL, PH_NOISY_CC); - } + case 369: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVS(expr_code, "!$this->isIncluded(", left_code, ", ", right_code, ")"); + break; - if (Z_TYPE_P(unique_types) == IS_NULL) { - PHALCON_OBS_NVAR(unique_types); - phalcon_read_property_this_quick(&unique_types, this_ptr, SL("_uniqueTypes"), 3340838640UL, PH_NOISY_CC); - } + case 366: + PHALCON_OBS_NVAR(ternary); + phalcon_array_fetch_quick_string(&ternary, expr, SS("ternary"), 4197153930UL, PH_NOISY); - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, this_ptr, "getschema", 1539736246UL); + PHALCON_INIT_NVAR(ternary_code); + phalcon_call_method_p1_key(ternary_code, this_ptr, "expression", ternary, 218841909UL); - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); - if (zend_is_true(schema)) { - PHALCON_INIT_NVAR(table); - array_init_size(table, 2); - phalcon_array_append(&table, schema, PH_SEPARATE); - phalcon_array_append(&table, source, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(table, source); - } + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVSVS(expr_code, "(", ternary_code, " ? ", left_code, " : ", right_code, ")"); + break; - PHALCON_INIT_VAR(escaped_table); - phalcon_call_method_p1_key(escaped_table, connection, "escapeidentifier", table, 585773337UL); + case 367: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SV(expr_code, "-", right_code); + break; - PHALCON_INIT_VAR(null_mode); + case 368: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SV(expr_code, "+", right_code); + break; - PHALCON_INIT_VAR(select); - PHALCON_CONCAT_SVSV(select, "SELECT COUNT(*) \"rowcount\" FROM ", escaped_table, " WHERE ", unique_key); + case 364: + PHALCON_OBS_NVAR(expr_code); + phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); + break; - PHALCON_INIT_VAR(num); - phalcon_call_method_p4_key(num, connection, "fetchone", select, null_mode, unique_params, unique_types, 1637187313UL); + default: + PHALCON_OBS_NVAR(line); + phalcon_array_fetch_quick_string(&line, expr, SS("line"), 266128205UL, PH_NOISY); - PHALCON_OBS_VAR(row_count); - phalcon_array_fetch_quick_string(&row_count, num, SS("rowcount"), 4184721862UL, PH_NOISY); - if (zend_is_true(row_count)) { - phalcon_update_property_long(this_ptr, SL("_dirtyState"), 0 TSRMLS_CC); - RETURN_MM_TRUE; - } else { - phalcon_update_property_long(this_ptr, SL("_dirtyState"), 1 TSRMLS_CC); + PHALCON_OBS_NVAR(file); + phalcon_array_fetch_quick_string(&file, expr, SS("file"), 259010501UL, PH_NOISY); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVSV(exception_message, "Unknown expression ", type, " in ", file, " on line ", line); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; + + } + break; } + phalcon_property_decr(this_ptr, SL("_exprLevel") TSRMLS_CC); - RETURN_MM_FALSE; + RETURN_CCTOR(expr_code); } -static PHP_METHOD(Phalcon_Mvc_Model, _groupResult){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _statementListOrExtends){ - zval *function, *alias, *parameters, *params = NULL, *group_column = NULL; - zval *distinct_column, *columns = NULL, *group_columns; - zval *model_name, *builder, *query, *bind_params = NULL; - zval *bind_types = NULL, *resultset, *cache, *number_rows; - zval *first_row, *value; + zval *statements, *is_statement_list = NULL, *statement = NULL; + zval *code; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &function, &alias, ¶meters); - - if (Z_TYPE_P(parameters) != IS_ARRAY) { - if (Z_TYPE_P(parameters) != IS_NULL) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(params); - array_init(params); - } - } else { - PHALCON_CPY_WRT(params, parameters); - } - if (phalcon_array_isset_quick_string(params, SS("column"), 3545634419UL)) { - PHALCON_OBS_VAR(group_column); - phalcon_array_fetch_quick_string(&group_column, params, SS("column"), 3545634419UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(group_column); - ZVAL_STRING(group_column, "*", 1); - } - - if (phalcon_array_isset_quick_string(params, SS("distinct"), 73581991UL)) { - PHALCON_OBS_VAR(distinct_column); - phalcon_array_fetch_quick_string(&distinct_column, params, SS("distinct"), 73581991UL, PH_NOISY); - - PHALCON_INIT_VAR(columns); - PHALCON_CONCAT_VSVSV(columns, function, "(DISTINCT ", distinct_column, ") AS ", alias); - } else { - if (phalcon_array_isset_quick_string(params, SS("group"), 7349554UL)) { - PHALCON_OBS_VAR(group_columns); - phalcon_array_fetch_quick_string(&group_columns, params, SS("group"), 7349554UL, PH_NOISY); - - PHALCON_INIT_NVAR(columns); - PHALCON_CONCAT_VSVSVSV(columns, group_columns, ", ", function, "(", group_column, ") AS ", alias); - } else { - PHALCON_INIT_NVAR(columns); - PHALCON_CONCAT_VSVSV(columns, function, "(", group_column, ") AS ", alias); - } - } + phalcon_fetch_params(1, 1, 0, &statements); - PHALCON_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); + if (Z_TYPE_P(statements) != IS_ARRAY) { + RETURN_CCTOR(statements); + } - PHALCON_INIT_VAR(builder); - object_init_ex(builder, phalcon_mvc_model_query_builder_ce); - phalcon_call_method_p1_key(NULL, builder, "__construct", params, 1107214344UL); + PHALCON_INIT_VAR(is_statement_list); + ZVAL_BOOL(is_statement_list, 1); + if (!phalcon_array_isset_quick_string(statements, SS("type"), 276192743UL)) { - phalcon_call_method_p1_key(NULL, builder, "columns", columns, 1041822630UL); - phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); + phalcon_is_iterable(statements, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(query); - phalcon_call_method_key(query, builder, "getquery", 4154457883UL); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(bind_params); + PHALCON_GET_HVALUE(statement); - PHALCON_INIT_VAR(bind_types); - if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { + if (Z_TYPE_P(statement) != IS_ARRAY) { + PHALCON_INIT_NVAR(is_statement_list); + ZVAL_BOOL(is_statement_list, 0); + break; + } - PHALCON_OBS_NVAR(bind_params); - phalcon_array_fetch_quick_string(&bind_params, params, SS("bind"), 254268962UL, PH_NOISY); - if (phalcon_array_isset_quick_string(params, SS("bindTypes"), 3951758359UL)) { - PHALCON_OBS_NVAR(bind_types); - phalcon_array_fetch_quick_string(&bind_types, params, SS("bindTypes"), 3951758359UL, PH_NOISY); + zend_hash_move_forward_ex(ah0, &hp0); } - } - - PHALCON_INIT_VAR(resultset); - phalcon_call_method_p2_key(resultset, query, "execute", bind_params, bind_types, 3117639032UL); - if (phalcon_array_isset_quick_string(params, SS("cache"), 4125168857UL)) { - PHALCON_OBS_VAR(cache); - phalcon_array_fetch_quick_string(&cache, params, SS("cache"), 4125168857UL, PH_NOISY); - phalcon_call_method_p1_key(NULL, query, "cache", cache, 4125168857UL); } - if (phalcon_array_isset_quick_string(params, SS("group"), 7349554UL)) { - RETURN_CCTOR(resultset); + if (PHALCON_IS_TRUE(is_statement_list)) { + PHALCON_INIT_VAR(code); + phalcon_call_method_p1_key(code, this_ptr, "_statementlist", statements, 1357145205UL); + RETURN_CCTOR(code); } - PHALCON_INIT_VAR(number_rows); - phalcon_fast_count(number_rows, resultset TSRMLS_CC); - - PHALCON_INIT_VAR(first_row); - phalcon_call_method_key(first_row, resultset, "getfirst", 3710205613UL); - - PHALCON_OBS_VAR(value); - phalcon_read_property_zval(&value, first_row, alias, PH_NOISY_CC); - RETURN_CCTOR(value); + RETURN_CCTOR(statements); } -static PHP_METHOD(Phalcon_Mvc_Model, count){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileForeach){ - zval *parameters = NULL, *function, *alias; + zval *statement, *extends_mode = NULL, *compilation; + zval *prefix, *level, *prefix_level, *expr, *expr_code; + zval *block_statements, *for_else = NULL, *bstatement = NULL; + zval *type = NULL, *code, *loop_context, *iterator = NULL, *variable; + zval *key, *if_expr, *if_expr_code; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, ¶meters); + phalcon_fetch_params(1, 1, 1, &statement, &extends_mode); - if (!parameters) { - PHALCON_INIT_VAR(parameters); + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); } - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "COUNT", 1); + if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; + } - PHALCON_INIT_VAR(alias); - ZVAL_STRING(alias, "rowcount", 1); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, sum){ - - zval *parameters = NULL, *function, *alias; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, ¶meters); + PHALCON_INIT_VAR(compilation); + ZVAL_STRING(compilation, "", 1); + phalcon_property_incr(this_ptr, SL("_foreachLevel") TSRMLS_CC); - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + PHALCON_INIT_VAR(prefix); + phalcon_call_method_key(prefix, this_ptr, "getuniqueprefix", 3888429962UL); - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "SUM", 1); + PHALCON_OBS_VAR(level); + phalcon_read_property_this_quick(&level, this_ptr, SL("_foreachLevel"), 1560648116UL, PH_NOISY_CC); - PHALCON_INIT_VAR(alias); - ZVAL_STRING(alias, "sumatory", 1); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, maximum){ - - zval *parameters = NULL, *function, *alias; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, ¶meters); + PHALCON_INIT_VAR(prefix_level); + PHALCON_CONCAT_VV(prefix_level, prefix, level); - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + PHALCON_OBS_VAR(expr); + phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "MAX", 1); + PHALCON_INIT_VAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); - PHALCON_INIT_VAR(alias); - ZVAL_STRING(alias, "maximum", 1); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, minimum){ - - zval *parameters = NULL, *function, *alias; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, ¶meters); + PHALCON_OBS_VAR(block_statements); + phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + PHALCON_INIT_VAR(for_else); + ZVAL_BOOL(for_else, 0); + if (Z_TYPE_P(block_statements) == IS_ARRAY) { - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "MIN", 1); + phalcon_is_iterable(block_statements, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(alias); - ZVAL_STRING(alias, "minimum", 1); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, average){ - - zval *parameters = NULL, *function, *alias; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, ¶meters); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(bstatement); + + if (Z_TYPE_P(bstatement) != IS_ARRAY) { + break; + } + + if (!phalcon_array_isset_quick_string(bstatement, SS("type"), 276192743UL)) { + break; + } + + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, bstatement, SS("type"), 276192743UL, PH_NOISY); + if (PHALCON_IS_LONG(type, 321)) { + PHALCON_SCONCAT_SVS(compilation, ""); + PHALCON_CPY_WRT(for_else, prefix_level); + phalcon_update_property_array(this_ptr, SL("_forElsePointers"), level, for_else TSRMLS_CC); + break; + } + + zend_hash_move_forward_ex(ah0, &hp0); + } - if (!parameters) { - PHALCON_INIT_VAR(parameters); } - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "AVG", 1); + PHALCON_INIT_VAR(code); + phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); - PHALCON_INIT_VAR(alias); - ZVAL_STRING(alias, "average", 1); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, fireEvent){ - - zval *event_name, *models_manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &event_name); + PHALCON_OBS_VAR(loop_context); + phalcon_read_property_this_quick(&loop_context, this_ptr, SL("_loopPointers"), 3384827986UL, PH_NOISY_CC); - if (phalcon_method_exists(this_ptr, event_name TSRMLS_CC) == SUCCESS) { - phalcon_call_method_zval_noret(this_ptr, event_name); + if (phalcon_array_isset(loop_context, level)) { + PHALCON_SCONCAT_SVSVS(compilation, "length = count($", prefix_level, "iterator); "); + PHALCON_SCONCAT_SVS(compilation, "$", prefix_level, "loop->index = 1; "); + PHALCON_SCONCAT_SVS(compilation, "$", prefix_level, "loop->index0 = 1; "); + PHALCON_SCONCAT_SVSVS(compilation, "$", prefix_level, "loop->revindex = $", prefix_level, "loop->length; "); + PHALCON_SCONCAT_SVSVS(compilation, "$", prefix_level, "loop->revindex0 = $", prefix_level, "loop->length - 1; ?>"); + + PHALCON_INIT_VAR(iterator); + PHALCON_CONCAT_SVS(iterator, "$", prefix_level, "iterator"); + } else { + PHALCON_CPY_WRT(iterator, expr_code); } - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + PHALCON_OBS_VAR(variable); + phalcon_array_fetch_quick_string(&variable, statement, SS("variable"), 1809440971UL, PH_NOISY); - phalcon_call_method_p2_key(return_value, models_manager, "notifyevent", event_name, this_ptr, 1223080128UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, fireEventCancel){ - - zval *event_name, *status = NULL, *models_manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &event_name); + if (phalcon_array_isset_quick_string(statement, SS("key"), 2090432846UL)) { + PHALCON_OBS_VAR(key); + phalcon_array_fetch_quick_string(&key, statement, SS("key"), 2090432846UL, PH_NOISY); + PHALCON_SCONCAT_SVSVSVS(compilation, " $", variable, ") { "); + } else { + PHALCON_SCONCAT_SVSVS(compilation, ""); + } else { + phalcon_concat_self_str(&compilation, SL("?>") TSRMLS_CC); } - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + if (phalcon_array_isset(loop_context, level)) { + PHALCON_SCONCAT_SVSVS(compilation, "first = ($", prefix_level, "incr == 0); "); + PHALCON_SCONCAT_SVSVS(compilation, "$", prefix_level, "loop->index = $", prefix_level, "incr + 1; "); + PHALCON_SCONCAT_SVSVS(compilation, "$", prefix_level, "loop->index0 = $", prefix_level, "incr; "); + PHALCON_SCONCAT_SVSVSVS(compilation, "$", prefix_level, "loop->revindex = $", prefix_level, "loop->length - $", prefix_level, "incr; "); + PHALCON_SCONCAT_SVSVSVS(compilation, "$", prefix_level, "loop->revindex0 = $", prefix_level, "loop->length - ($", prefix_level, "incr + 1); "); + PHALCON_SCONCAT_SVSVSVS(compilation, "$", prefix_level, "loop->last = ($", prefix_level, "incr == ($", prefix_level, "loop->length - 1)); ?>"); + } - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, models_manager, "notifyevent", event_name, this_ptr, 1223080128UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; + if (Z_TYPE_P(for_else) == IS_STRING) { + PHALCON_SCONCAT_SVS(compilation, ""); } - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Mvc_Model, _cancelOperation){ - - zval *operation_made, *event_name = NULL; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(operation_made); - phalcon_read_property_this_quick(&operation_made, this_ptr, SL("_operationMade"), 3968152972UL, PH_NOISY_CC); - if (PHALCON_IS_LONG(operation_made, 3)) { - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "notDeleted", 1); + phalcon_concat_self(&compilation, code TSRMLS_CC); + if (phalcon_array_isset_quick_string(statement, SS("if_expr"), 4083762802UL)) { + phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); + } + + if (Z_TYPE_P(for_else) == IS_STRING) { + phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); } else { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "notSaved", 1); + if (phalcon_array_isset(loop_context, level)) { + PHALCON_SCONCAT_SVS(compilation, ""); + } else { + phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); + } } - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + phalcon_property_decr(this_ptr, SL("_foreachLevel") TSRMLS_CC); - PHALCON_MM_RESTORE(); + RETURN_CTOR(compilation); } -static PHP_METHOD(Phalcon_Mvc_Model, appendMessage){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileForElse){ - zval *message, *type, *exception_message; + zval *level, *for_else_pointers, *prefix, *loop_context; + zval *compilation = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + PHALCON_OBS_VAR(level); + phalcon_read_property_this_quick(&level, this_ptr, SL("_foreachLevel"), 1560648116UL, PH_NOISY_CC); - if (Z_TYPE_P(message) != IS_OBJECT) { - PHALCON_INIT_VAR(type); - phalcon_call_func_p1(type, "gettype", message); + PHALCON_OBS_VAR(for_else_pointers); + phalcon_read_property_this_quick(&for_else_pointers, this_ptr, SL("_forElsePointers"), 17082280UL, PH_NOISY_CC); + if (phalcon_array_isset(for_else_pointers, level)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Invalid message format '", type, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; + PHALCON_OBS_VAR(prefix); + phalcon_array_fetch(&prefix, for_else_pointers, level, PH_NOISY); + + PHALCON_OBS_VAR(loop_context); + phalcon_read_property_this_quick(&loop_context, this_ptr, SL("_loopPointers"), 3384827986UL, PH_NOISY_CC); + if (phalcon_array_isset(loop_context, level)) { + PHALCON_INIT_VAR(compilation); + PHALCON_CONCAT_SVSVS(compilation, ""); + } else { + PHALCON_INIT_NVAR(compilation); + PHALCON_CONCAT_SVS(compilation, ""); + } + + RETURN_CTOR(compilation); } - phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - RETURN_THIS(); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Model, validate){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileIf){ - zval *validator, *status, *messages, *message = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *statement, *extends_mode = NULL, *compilation; + zval *expr, *expr_code, *block_statements = NULL, *code = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &validator); + phalcon_fetch_params(1, 1, 1, &statement, &extends_mode); - if (Z_TYPE_P(validator) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Validator must be an Object"); - return; + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); } - PHALCON_INIT_VAR(status); - phalcon_call_method_p1_key(status, validator, "validate", this_ptr, 2654098287UL); - if (PHALCON_IS_FALSE(status)) { + PHALCON_INIT_VAR(compilation); - PHALCON_INIT_VAR(messages); - phalcon_call_method_key(messages, validator, "getmessages", 4087333309UL); + if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; + } - phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(expr); + phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); - PHALCON_GET_HVALUE(message); + PHALCON_SCONCAT_SVS(compilation, ""); + PHALCON_OBS_VAR(block_statements); + phalcon_array_fetch_quick_string(&block_statements, statement, SS("true_statements"), 3718314604UL, PH_NOISY); - phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); + PHALCON_INIT_VAR(code); + phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); + phalcon_concat_self(&compilation, code TSRMLS_CC); - zend_hash_move_forward_ex(ah0, &hp0); - } + if (phalcon_array_isset_quick_string(statement, SS("false_statements"), 3888255479UL)) { + phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); + + PHALCON_OBS_NVAR(block_statements); + phalcon_array_fetch_quick_string(&block_statements, statement, SS("false_statements"), 3888255479UL, PH_NOISY); + PHALCON_INIT_NVAR(code); + phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); + phalcon_concat_self(&compilation, code TSRMLS_CC); } - RETURN_THIS(); + phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); + + RETURN_CCTOR(compilation); } -static PHP_METHOD(Phalcon_Mvc_Model, validationHasFailed){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileElseIf){ - zval *error_messages; + zval *statement, *expr, *expr_code; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(error_messages); - phalcon_read_property_this_quick(&error_messages, this_ptr, SL("_errorMessages"), 1019066246UL, PH_NOISY_CC); - if (Z_TYPE_P(error_messages) == IS_ARRAY) { - if (phalcon_fast_count_ev(error_messages TSRMLS_CC)) { - RETURN_MM_TRUE; - } + phalcon_fetch_params(1, 1, 0, &statement); + + if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; } - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Model, getMessages){ - - - RETURN_MEMBER_QUICK(this_ptr, "_errorMessages", 1019066246UL); + PHALCON_OBS_VAR(expr); + phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); + + PHALCON_INIT_VAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); + + PHALCON_CONCAT_SVS(return_value, ""); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysRestrict){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileCache){ - zval *manager, *belongs_to, *error = NULL, *relation = NULL, *foreign_key = NULL; - zval *action = NULL, *relation_class = NULL, *referenced_model = NULL; - zval *conditions = NULL, *bind_params = NULL, *fields = NULL, *referenced_fields = NULL; - zval *field = NULL, *position = NULL, *value = NULL, *referenced_field = NULL; - zval *condition = NULL, *extra_conditions = NULL, *join_conditions = NULL; - zval *parameters = NULL, *rowcount = NULL, *user_message = NULL, *joined_fields = NULL; - zval *type = NULL, *message = NULL, *event_name; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; + zval *statement, *extends_mode = NULL, *compilation; + zval *expr, *expr_code, *lifetime = NULL, *block_statements; + zval *code; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(belongs_to); - phalcon_call_method_p1_key(belongs_to, manager, "getbelongsto", this_ptr, 2949171154UL); - if (phalcon_fast_count_ev(belongs_to TSRMLS_CC)) { - - PHALCON_INIT_VAR(error); - ZVAL_BOOL(error, 0); - - phalcon_is_iterable(belongs_to, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(relation); - - PHALCON_INIT_NVAR(foreign_key); - phalcon_call_method_key(foreign_key, relation, "getforeignkey", 3855868664UL); - if (PHALCON_IS_NOT_FALSE(foreign_key)) { - - PHALCON_INIT_NVAR(action); - ZVAL_LONG(action, 1); - - if (Z_TYPE_P(foreign_key) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(foreign_key, SS("action"), 502132067UL)) { - PHALCON_OBS_NVAR(action); - phalcon_array_fetch_quick_string(&action, foreign_key, SS("action"), 502132067UL, PH_NOISY); - } - } - - if (PHALCON_IS_LONG(action, 1)) { - - PHALCON_INIT_NVAR(relation_class); - phalcon_call_method_key(relation_class, relation, "getreferencedmodel", 478093161UL); - - PHALCON_INIT_NVAR(referenced_model); - phalcon_call_method_p1_key(referenced_model, manager, "load", relation_class, 266329637UL); - - PHALCON_INIT_NVAR(conditions); - array_init(conditions); - - PHALCON_INIT_NVAR(bind_params); - array_init(bind_params); - - PHALCON_INIT_NVAR(fields); - phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - - PHALCON_INIT_NVAR(referenced_fields); - phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - if (Z_TYPE_P(fields) == IS_ARRAY) { - - phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + phalcon_fetch_params(1, 1, 1, &statement, &extends_mode); - PHALCON_GET_HKEY(position, ah1, hp1); - PHALCON_GET_HVALUE(field); + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); + } - if (phalcon_isset_property_zval(this_ptr, field TSRMLS_CC)) { - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, field, PH_NOISY_CC); - } else { - PHALCON_INIT_NVAR(value); - } + if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; + } - PHALCON_OBS_NVAR(referenced_field); - phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); + PHALCON_INIT_VAR(compilation); - PHALCON_INIT_NVAR(condition); - PHALCON_CONCAT_SVSV(condition, "[", referenced_field, "] = ?", position); - phalcon_array_append(&conditions, condition, PH_SEPARATE); - phalcon_array_append(&bind_params, value, PH_SEPARATE); + PHALCON_OBS_VAR(expr); + phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); - zend_hash_move_forward_ex(ah1, &hp1); - } + PHALCON_INIT_VAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); - } else { - if (phalcon_isset_property_zval(this_ptr, fields TSRMLS_CC)) { - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, fields, PH_NOISY_CC); - } else { - PHALCON_INIT_NVAR(value); - } + PHALCON_SCONCAT_SVS(compilation, "di->get('viewCache'); "); + if (phalcon_array_isset_quick_string(statement, SS("lifetime"), 2639810228UL)) { + PHALCON_OBS_VAR(lifetime); + phalcon_array_fetch_quick_string(&lifetime, statement, SS("lifetime"), 2639810228UL, PH_NOISY); + PHALCON_SCONCAT_SVS(compilation, "$_cacheKey[", expr_code, "]"); + PHALCON_SCONCAT_SVSVSVS(compilation, " = $_cache[", expr_code, "]->start(", expr_code, ", ", lifetime, "); "); + } else { + PHALCON_SCONCAT_SVSVSVS(compilation, "$_cacheKey[", expr_code, "] = $_cache[", expr_code, "]->start(", expr_code, "); "); + } - PHALCON_INIT_NVAR(condition); - PHALCON_CONCAT_SVS(condition, "[", referenced_fields, "] = ?0"); - phalcon_array_append(&conditions, condition, PH_SEPARATE); - phalcon_array_append(&bind_params, value, PH_SEPARATE); - } + PHALCON_SCONCAT_SVS(compilation, "if ($_cacheKey[", expr_code, "] === null) { ?>"); + PHALCON_OBS_VAR(block_statements); + phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); - if (phalcon_array_isset_quick_string(foreign_key, SS("conditions"), 1055696255UL)) { - PHALCON_OBS_NVAR(extra_conditions); - phalcon_array_fetch_quick_string(&extra_conditions, foreign_key, SS("conditions"), 1055696255UL, PH_NOISY); - phalcon_array_append(&conditions, extra_conditions, PH_SEPARATE); - } + PHALCON_INIT_VAR(code); + phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); + phalcon_concat_self(&compilation, code TSRMLS_CC); - PHALCON_INIT_NVAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); + if (phalcon_array_isset_quick_string(statement, SS("lifetime"), 2639810228UL)) { + PHALCON_OBS_NVAR(lifetime); + phalcon_array_fetch_quick_string(&lifetime, statement, SS("lifetime"), 2639810228UL, PH_NOISY); + PHALCON_SCONCAT_SVSVSVS(compilation, "save(", expr_code, ", null, ", lifetime, "); "); + PHALCON_SCONCAT_SVS(compilation, "} else { echo $_cacheKey[", expr_code, "]; } ?>"); + } else { + PHALCON_SCONCAT_SVSVSVS(compilation, "save(", expr_code, "); } else { echo $_cacheKey[", expr_code, "]; } ?>"); + } - PHALCON_INIT_NVAR(parameters); - array_init_size(parameters, 2); - phalcon_array_append(¶meters, join_conditions, PH_SEPARATE); - phalcon_array_update_quick_string(¶meters, SS("bind"), 254268962UL, &bind_params, PH_COPY | PH_SEPARATE); + RETURN_CCTOR(compilation); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileEcho){ + + zval *statement, *compilation, *expr, *expr_code; + zval *expr_type, *name, *name_type, *name_value; + zval *autoescape; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &statement); - PHALCON_INIT_NVAR(rowcount); - phalcon_call_method_p1_key(rowcount, referenced_model, "count", parameters, 4142425646UL); - if (!zend_is_true(rowcount)) { + if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; + } - if (phalcon_array_isset_quick_string(foreign_key, SS("message"), 2265848874UL)) { - PHALCON_OBS_NVAR(user_message); - phalcon_array_fetch_quick_string(&user_message, foreign_key, SS("message"), 2265848874UL, PH_NOISY); - } else { - if (Z_TYPE_P(fields) == IS_ARRAY) { - PHALCON_INIT_NVAR(joined_fields); - phalcon_fast_join_str(joined_fields, SL(", "), fields TSRMLS_CC); + PHALCON_INIT_VAR(compilation); - PHALCON_INIT_NVAR(user_message); - PHALCON_CONCAT_SVS(user_message, "Value of fields \"", joined_fields, "\" does not exist on referenced table"); - } else { - PHALCON_INIT_NVAR(user_message); - PHALCON_CONCAT_SVS(user_message, "Value of field \"", fields, "\" does not exist on referenced table"); - } - } + PHALCON_OBS_VAR(expr); + phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); - PHALCON_INIT_NVAR(type); - ZVAL_STRING(type, "ConstraintViolation", 1); + PHALCON_INIT_VAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); - PHALCON_INIT_NVAR(message); - object_init_ex(message, phalcon_mvc_model_message_ce); - phalcon_call_method_p3_key(NULL, message, "__construct", user_message, fields, type, 1107214344UL); + PHALCON_OBS_VAR(expr_type); + phalcon_array_fetch_quick_string(&expr_type, expr, SS("type"), 276192743UL, PH_NOISY); + if (PHALCON_IS_LONG(expr_type, 350)) { - phalcon_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, expr, SS("name"), 268211462UL, PH_NOISY); - PHALCON_INIT_NVAR(error); - ZVAL_BOOL(error, 1); - break; - } - } - } + PHALCON_OBS_VAR(name_type); + phalcon_array_fetch_quick_string(&name_type, name, SS("type"), 276192743UL, PH_NOISY); + if (PHALCON_IS_LONG(name_type, 265)) { - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_OBS_VAR(name_value); + phalcon_array_fetch_quick_string(&name_value, name, SS("value"), 574111618UL, PH_NOISY); - if (PHALCON_IS_TRUE(error)) { - if (PHALCON_GLOBAL(orm).events) { - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "onValidationFails", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - phalcon_call_method_key(NULL, this_ptr, "_canceloperation", 1716493051UL); + if (PHALCON_IS_STRING(name_value, "super")) { + RETURN_CCTOR(expr_code); } - RETURN_MM_FALSE; } } - RETURN_MM_TRUE; + PHALCON_OBS_VAR(autoescape); + phalcon_read_property_this_quick(&autoescape, this_ptr, SL("_autoescape"), 2399648718UL, PH_NOISY_CC); + if (zend_is_true(autoescape)) { + PHALCON_SCONCAT_SVS(compilation, "escaper->escapeHtml(", expr_code, "); ?>"); + } else { + PHALCON_SCONCAT_SVS(compilation, ""); + } + + RETURN_CCTOR(compilation); } -static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysReverseRestrict){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileInclude){ - zval *manager, *relations, *error = NULL, *relation = NULL, *foreign_key = NULL; - zval *action = NULL, *relation_class = NULL, *referenced_model = NULL; - zval *fields = NULL, *referenced_fields = NULL, *conditions = NULL; - zval *bind_params = NULL, *field = NULL, *position = NULL, *value = NULL, *referenced_field = NULL; - zval *condition = NULL, *extra_conditions = NULL, *join_conditions = NULL; - zval *parameters = NULL, *rowcount = NULL, *user_message = NULL, *type = NULL; - zval *message = NULL, *event_name; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; + zval *statement, *path_expr, *expr_type, *path = NULL; + zval *view, *views_dir, *final_path = NULL, *extended; + zval *sub_compiler, *compilation = NULL, *compiled_path; + zval *expr_params, *params; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 0, &statement); - PHALCON_INIT_VAR(relations); - phalcon_call_method_p1_key(relations, manager, "gethasoneandhasmany", this_ptr, 775341383UL); - if (phalcon_fast_count_ev(relations TSRMLS_CC)) { + if (!phalcon_array_isset_quick_string(statement, SS("path"), 270591026UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; + } - PHALCON_INIT_VAR(error); - ZVAL_BOOL(error, 0); + PHALCON_OBS_VAR(path_expr); + phalcon_array_fetch_quick_string(&path_expr, statement, SS("path"), 270591026UL, PH_NOISY); - phalcon_is_iterable(relations, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(expr_type); + phalcon_array_fetch_quick_string(&expr_type, path_expr, SS("type"), 276192743UL, PH_NOISY); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (PHALCON_IS_LONG(expr_type, 260)) { - PHALCON_GET_HVALUE(relation); + if (!phalcon_array_isset_quick_string(statement, SS("params"), 2613350281UL)) { - PHALCON_INIT_NVAR(foreign_key); - phalcon_call_method_key(foreign_key, relation, "getforeignkey", 3855868664UL); - if (PHALCON_IS_NOT_FALSE(foreign_key)) { + PHALCON_OBS_VAR(path); + phalcon_array_fetch_quick_string(&path, path_expr, SS("value"), 574111618UL, PH_NOISY); - PHALCON_INIT_NVAR(action); - ZVAL_LONG(action, 1); + PHALCON_OBS_VAR(view); + phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); + if (Z_TYPE_P(view) == IS_OBJECT) { + PHALCON_INIT_VAR(views_dir); + phalcon_call_method_key(views_dir, view, "getviewsdir", 2448458514UL); - if (Z_TYPE_P(foreign_key) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(foreign_key, SS("action"), 502132067UL)) { - PHALCON_OBS_NVAR(action); - phalcon_array_fetch_quick_string(&action, foreign_key, SS("action"), 502132067UL, PH_NOISY); - } - } + PHALCON_INIT_VAR(final_path); + PHALCON_CONCAT_VV(final_path, views_dir, path); + } else { + PHALCON_CPY_WRT(final_path, path); + } - if (PHALCON_IS_LONG(action, 1)) { + PHALCON_INIT_VAR(extended); + ZVAL_BOOL(extended, 0); - PHALCON_INIT_NVAR(relation_class); - phalcon_call_method_key(relation_class, relation, "getreferencedmodel", 478093161UL); + PHALCON_INIT_VAR(sub_compiler); + if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { + return; + } - PHALCON_INIT_NVAR(referenced_model); - phalcon_call_method_p1_key(referenced_model, manager, "load", relation_class, 266329637UL); + PHALCON_INIT_VAR(compilation); + phalcon_call_method_p2_key(compilation, sub_compiler, "compile", final_path, extended, 1074882030UL); - PHALCON_INIT_NVAR(fields); - phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); + if (Z_TYPE_P(compilation) == IS_NULL) { + PHALCON_INIT_VAR(compiled_path); + phalcon_call_method_key(compiled_path, sub_compiler, "getcompiledtemplatepath", 652904091UL); - PHALCON_INIT_NVAR(referenced_fields); - phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); + PHALCON_INIT_NVAR(compilation); + phalcon_file_get_contents(compilation, compiled_path TSRMLS_CC); + } - PHALCON_INIT_NVAR(conditions); - array_init(conditions); + RETURN_CCTOR(compilation); + } + } - PHALCON_INIT_NVAR(bind_params); - array_init(bind_params); - if (Z_TYPE_P(fields) == IS_ARRAY) { + PHALCON_INIT_NVAR(path); + phalcon_call_method_p1_key(path, this_ptr, "expression", path_expr, 218841909UL); + if (!phalcon_array_isset_quick_string(statement, SS("params"), 2613350281UL)) { + PHALCON_CONCAT_SVS(return_value, "partial(", path, "); ?>"); + RETURN_MM(); + } - phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); + PHALCON_OBS_VAR(expr_params); + phalcon_array_fetch_quick_string(&expr_params, statement, SS("params"), 2613350281UL, PH_NOISY); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + PHALCON_INIT_VAR(params); + phalcon_call_method_p1_key(params, this_ptr, "expression", expr_params, 218841909UL); + PHALCON_CONCAT_SVSVS(return_value, "partial(", path, ", ", params, "); ?>"); - PHALCON_GET_HKEY(position, ah1, hp1); - PHALCON_GET_HVALUE(field); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileSet){ + + zval *statement, *compilation, *assignments; + zval *assignment = NULL, *expr = NULL, *expr_code = NULL, *variable = NULL; + zval *op = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &statement); - if (phalcon_isset_property_zval(this_ptr, field TSRMLS_CC)) { - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, field, PH_NOISY_CC); - } else { - PHALCON_INIT_NVAR(value); - } + if (!phalcon_array_isset_quick_string(statement, SS("assignments"), 2364482705UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; + } - PHALCON_OBS_NVAR(referenced_field); - phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); + PHALCON_INIT_VAR(compilation); + ZVAL_STRING(compilation, "") TSRMLS_CC); + + RETURN_CTOR(compilation); } -static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysReverseCascade){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileDo){ - zval *manager, *relations, *relation = NULL, *foreign_key = NULL; - zval *action = NULL, *relation_class = NULL, *referenced_model = NULL; - zval *fields = NULL, *referenced_fields = NULL, *conditions = NULL; - zval *bind_params = NULL, *field = NULL, *position = NULL, *value = NULL, *referenced_field = NULL; - zval *condition = NULL, *extra_conditions = NULL, *join_conditions = NULL; - zval *parameters = NULL, *resulset = NULL, *status = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; + zval *statement, *expr, *expr_code; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(relations); - phalcon_call_method_p1_key(relations, manager, "gethasoneandhasmany", this_ptr, 775341383UL); - if (phalcon_fast_count_ev(relations TSRMLS_CC)) { - - phalcon_is_iterable(relations, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(relation); + phalcon_fetch_params(1, 1, 0, &statement); - PHALCON_INIT_NVAR(foreign_key); - phalcon_call_method_key(foreign_key, relation, "getforeignkey", 3855868664UL); - if (PHALCON_IS_NOT_FALSE(foreign_key)) { + if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; + } - PHALCON_INIT_NVAR(action); - ZVAL_LONG(action, 0); + PHALCON_OBS_VAR(expr); + phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); - if (Z_TYPE_P(foreign_key) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(foreign_key, SS("action"), 502132067UL)) { - PHALCON_OBS_NVAR(action); - phalcon_array_fetch_quick_string(&action, foreign_key, SS("action"), 502132067UL, PH_NOISY); - } - } + PHALCON_INIT_VAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); - if (PHALCON_IS_LONG(action, 2)) { + PHALCON_CONCAT_SVS(return_value, ""); - PHALCON_INIT_NVAR(relation_class); - phalcon_call_method_key(relation_class, relation, "getreferencedmodel", 478093161UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileReturn){ + + zval *statement, *expr, *expr_code; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &statement); - PHALCON_INIT_NVAR(referenced_model); - phalcon_call_method_p1_key(referenced_model, manager, "load", relation_class, 266329637UL); + if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; + } - PHALCON_INIT_NVAR(fields); - phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); + PHALCON_OBS_VAR(expr); + phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); - PHALCON_INIT_NVAR(referenced_fields); - phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); + PHALCON_INIT_VAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); + PHALCON_CONCAT_SVS(return_value, ""); - PHALCON_INIT_NVAR(conditions); - array_init(conditions); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileAutoEscape){ + + zval *statement, *extends_mode, *old_autoescape; + zval *autoescape, *block_statements, *compilation; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &statement, &extends_mode); - PHALCON_INIT_NVAR(bind_params); - array_init(bind_params); - if (Z_TYPE_P(fields) == IS_ARRAY) { + if (!phalcon_array_isset_quick_string(statement, SS("enable"), 1780738348UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; + } - phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); + PHALCON_OBS_VAR(old_autoescape); + phalcon_read_property_this_quick(&old_autoescape, this_ptr, SL("_autoescape"), 2399648718UL, PH_NOISY_CC); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + PHALCON_OBS_VAR(autoescape); + phalcon_array_fetch_quick_string(&autoescape, statement, SS("enable"), 1780738348UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_autoescape"), autoescape, 2399648718UL TSRMLS_CC); - PHALCON_GET_HKEY(position, ah1, hp1); - PHALCON_GET_HVALUE(field); + PHALCON_OBS_VAR(block_statements); + phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); - if (phalcon_isset_property_zval(this_ptr, field TSRMLS_CC)) { - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, field, PH_NOISY_CC); - } else { - PHALCON_INIT_NVAR(value); - } + PHALCON_INIT_VAR(compilation); + phalcon_call_method_p2_key(compilation, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); + phalcon_update_property_this_quick(this_ptr, SL("_autoescape"), old_autoescape, 2399648718UL TSRMLS_CC); - PHALCON_OBS_NVAR(referenced_field); - phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); + RETURN_CCTOR(compilation); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileMacro){ + + zval *statement, *extends_mode, *name, *macros; + zval *exception_message, *code, *parameters; + zval *parameter = NULL, *position = NULL, *variable_name = NULL, *block_statements; + zval *block_code; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &statement, &extends_mode); - PHALCON_INIT_NVAR(condition); - PHALCON_CONCAT_SVSV(condition, "[", referenced_field, "] = ?", position); - phalcon_array_append(&conditions, condition, PH_SEPARATE); - phalcon_array_append(&bind_params, value, PH_SEPARATE); + if (!phalcon_array_isset_quick_string(statement, SS("name"), 268211462UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; + } - zend_hash_move_forward_ex(ah1, &hp1); - } + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, statement, SS("name"), 268211462UL, PH_NOISY); - } else { - if (phalcon_isset_property_zval(this_ptr, fields TSRMLS_CC)) { - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, fields, PH_NOISY_CC); - } else { - PHALCON_INIT_NVAR(value); - } + PHALCON_OBS_VAR(macros); + phalcon_read_property_this_quick(¯os, this_ptr, SL("_macros"), 3627118793UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(condition); - PHALCON_CONCAT_SVS(condition, "[", referenced_fields, "] = ?0"); - phalcon_array_append(&conditions, condition, PH_SEPARATE); - phalcon_array_append(&bind_params, value, PH_SEPARATE); - } + if (phalcon_array_isset(macros, name)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Macro \"", name, "\" is already defined"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; + } else { + phalcon_update_property_array(this_ptr, SL("_macros"), name, name TSRMLS_CC); + } - if (phalcon_array_isset_quick_string(foreign_key, SS("conditions"), 1055696255UL)) { - PHALCON_OBS_NVAR(extra_conditions); - phalcon_array_fetch_quick_string(&extra_conditions, foreign_key, SS("conditions"), 1055696255UL, PH_NOISY); - phalcon_array_append(&conditions, extra_conditions, PH_SEPARATE); - } + PHALCON_INIT_VAR(code); + ZVAL_STRING(code, ""); + } else { + PHALCON_SCONCAT_VS(code, name, "($__p) { "); - PHALCON_INIT_NVAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); + PHALCON_OBS_VAR(parameters); + phalcon_array_fetch_quick_string(¶meters, statement, SS("parameters"), 3941032889UL, PH_NOISY); - PHALCON_INIT_NVAR(parameters); - array_init_size(parameters, 2); - phalcon_array_append(¶meters, join_conditions, PH_SEPARATE); - phalcon_array_update_quick_string(¶meters, SS("bind"), 254268962UL, &bind_params, PH_COPY | PH_SEPARATE); + phalcon_is_iterable(parameters, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(resulset); - phalcon_call_method_p1_key(resulset, referenced_model, "find", parameters, 259012646UL); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_NVAR(status); - phalcon_call_method_key(status, resulset, "delete", 150213496UL); + PHALCON_GET_HKEY(position, ah0, hp0); + PHALCON_GET_HVALUE(parameter); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } - } + PHALCON_OBS_NVAR(variable_name); + phalcon_array_fetch_quick_string(&variable_name, parameter, SS("variable"), 1809440971UL, PH_NOISY); + PHALCON_SCONCAT_SVS(code, "if (isset($__p[", position, "])) { "); + PHALCON_SCONCAT_SVSVS(code, "$", variable_name, " = $__p[", position, "];"); + phalcon_concat_self_str(&code, SL(" } else { ") TSRMLS_CC); + PHALCON_SCONCAT_SVS(code, "if (isset($__p['", variable_name, "'])) { "); + PHALCON_SCONCAT_SVSVS(code, "$", variable_name, " = $__p['", variable_name, "'];"); + phalcon_concat_self_str(&code, SL(" } else { ") TSRMLS_CC); + PHALCON_SCONCAT_SVSVS(code, " throw new \\Phalcon\\Mvc\\View\\Exception(\"Macro ", name, " was called without parameter: ", variable_name, "\"); "); + phalcon_concat_self_str(&code, SL(" } } ") TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); } + phalcon_concat_self_str(&code, SL(" ?>") TSRMLS_CC); } - RETURN_MM_TRUE; + if (phalcon_array_isset_quick_string(statement, SS("block_statements"), 883954391UL)) { + PHALCON_OBS_VAR(block_statements); + phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); + + PHALCON_INIT_VAR(block_code); + phalcon_call_method_p2_key(block_code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); + PHALCON_SCONCAT_VS(code, block_code, ""); + } else { + phalcon_concat_self_str(&code, SL("") TSRMLS_CC); + } + + RETURN_CTOR(code); } -static PHP_METHOD(Phalcon_Mvc_Model, _preSave){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileCall){ - zval *meta_data, *exists, *identity_field, *event_name = NULL; - zval *status = NULL, *not_null, *data_type_numeric; - zval *column_map = NULL, *automatic_attributes = NULL, *error = NULL; - zval *null_value, *field = NULL, *is_null = NULL, *attribute_field = NULL; - zval *exception_message = NULL, *value = NULL, *message = NULL, *type = NULL; - zval *model_message = NULL, *skipped; + + +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _statementList){ + + zval *statements, *extends_mode = NULL, *extended = NULL, *block_mode = NULL; + zval *compilation = NULL, *extensions, *statement = NULL, *line = NULL; + zval *file = NULL, *exception_message = NULL, *event = NULL, *fire_arguments = NULL; + zval *temp_compilation = NULL, *type = NULL, *block_name = NULL, *block_statements = NULL; + zval *blocks = NULL, *code = NULL, *path = NULL, *view = NULL, *views_dir = NULL, *final_path = NULL; + zval *sub_compiler = NULL, *compiled_path = NULL, *level; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &meta_data, &exists, &identity_field); + phalcon_fetch_params(1, 1, 1, &statements, &extends_mode); - if (PHALCON_GLOBAL(orm).events) { + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); + } - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "beforeValidation", 1); + if (!phalcon_fast_count_ev(statements TSRMLS_CC)) { + RETURN_MM_EMPTY_STRING(); + } - PHALCON_INIT_VAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } + PHALCON_OBS_VAR(extended); + phalcon_read_property_this_quick(&extended, this_ptr, SL("_extended"), 1049215029UL, PH_NOISY_CC); - if (!zend_is_true(exists)) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "beforeValidationOnCreate", 1); - } else { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "beforeValidationOnUpdate", 1); - } + PHALCON_INIT_VAR(block_mode); + ZVAL_BOOL(block_mode, zend_is_true(extended) || zend_is_true(extends_mode)); + if (PHALCON_IS_TRUE(block_mode)) { + phalcon_property_incr(this_ptr, SL("_blockLevel") TSRMLS_CC); + } - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; + phalcon_property_incr(this_ptr, SL("_level") TSRMLS_CC); + + PHALCON_INIT_VAR(compilation); + + PHALCON_OBS_VAR(extensions); + phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); + + phalcon_is_iterable(statements, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(statement); + + if (Z_TYPE_P(statement) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; } - } - if (PHALCON_GLOBAL(orm).virtual_foreign_keys) { + if (!phalcon_array_isset_quick_string(statement, SS("type"), 276192743UL)) { + PHALCON_OBS_NVAR(line); + phalcon_array_fetch_quick_string(&line, statement, SS("line"), 266128205UL, PH_NOISY); - PHALCON_INIT_NVAR(status); - phalcon_call_method_key(status, this_ptr, "_checkforeignkeysrestrict", 3705233048UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; + PHALCON_OBS_NVAR(file); + phalcon_array_fetch_quick_string(&file, statement, SS("file"), 259010501UL, PH_NOISY); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "Invalid statement in ", file, " on line ", line); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; } - } - if (PHALCON_GLOBAL(orm).not_null_validations) { + if (Z_TYPE_P(extensions) == IS_ARRAY) { - PHALCON_INIT_VAR(not_null); - phalcon_call_method_p1_key(not_null, meta_data, "getnotnullattributes", this_ptr, 1717716120UL); - if (Z_TYPE_P(not_null) == IS_ARRAY) { + PHALCON_INIT_NVAR(event); + ZVAL_STRING(event, "compileStatement", 1); - PHALCON_INIT_VAR(data_type_numeric); - phalcon_call_method_p1_key(data_type_numeric, meta_data, "getdatatypesnumeric", this_ptr, 4122766183UL); - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); - } else { - PHALCON_INIT_NVAR(column_map); - } + PHALCON_INIT_NVAR(fire_arguments); + array_init_size(fire_arguments, 1); + phalcon_array_append(&fire_arguments, statement, PH_SEPARATE); - if (zend_is_true(exists)) { - PHALCON_INIT_VAR(automatic_attributes); - phalcon_call_method_p1_key(automatic_attributes, meta_data, "getautomaticupdateattributes", this_ptr, 2703790998UL); - } else { - PHALCON_INIT_NVAR(automatic_attributes); - phalcon_call_method_p1_key(automatic_attributes, meta_data, "getautomaticcreateattributes", this_ptr, 159934727UL); + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p2_key(temp_compilation, this_ptr, "fireextensionevent", event, fire_arguments, 1575031978UL); + if (Z_TYPE_P(temp_compilation) == IS_STRING) { + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + zend_hash_move_forward_ex(ah0, &hp0); + continue; } + } - PHALCON_INIT_VAR(error); - ZVAL_BOOL(error, 0); + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, statement, SS("type"), 276192743UL, PH_NOISY); - PHALCON_INIT_VAR(null_value); - phalcon_is_iterable(not_null, &ah0, &hp0, 0, 0); + switch (phalcon_get_intval(type)) { - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + case 357: + PHALCON_OBS_NVAR(temp_compilation); + phalcon_array_fetch_quick_string(&temp_compilation, statement, SS("value"), 574111618UL, PH_NOISY); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; - PHALCON_GET_HVALUE(field); + case 300: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p2_key(temp_compilation, this_ptr, "compileif", statement, extends_mode, 2315543869UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; - if (!phalcon_array_isset(automatic_attributes, field)) { + case 302: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p1_key(temp_compilation, this_ptr, "compileelseif", statement, 4134464646UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; - PHALCON_INIT_NVAR(is_null); - ZVAL_BOOL(is_null, 0); - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, field)) { - PHALCON_OBS_NVAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, field, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(attribute_field, field); - } + case 304: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p2_key(temp_compilation, this_ptr, "compileforeach", statement, extends_mode, 2502131046UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; - if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { + case 306: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p1_key(temp_compilation, this_ptr, "compileset", statement, 3398865754UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); + case 359: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p1_key(temp_compilation, this_ptr, "compileecho", statement, 476736013UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; - if (Z_TYPE_P(value) != IS_OBJECT) { - if (!phalcon_array_isset(data_type_numeric, field)) { - if (PHALCON_IS_EMPTY(value)) { - PHALCON_INIT_NVAR(is_null); - ZVAL_BOOL(is_null, 1); - } - } else { - if (!phalcon_is_numeric(value)) { - PHALCON_INIT_NVAR(is_null); - ZVAL_BOOL(is_null, 1); - } - } - } - } else { - PHALCON_INIT_NVAR(is_null); - ZVAL_BOOL(is_null, 1); + case 307: + PHALCON_OBS_NVAR(block_name); + phalcon_array_fetch_quick_string(&block_name, statement, SS("name"), 268211462UL, PH_NOISY); + if (phalcon_array_isset_quick_string(statement, SS("block_statements"), 883954391UL)) { + PHALCON_OBS_NVAR(block_statements); + phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(block_statements); + } + + PHALCON_OBS_NVAR(blocks); + phalcon_read_property_this_quick(&blocks, this_ptr, SL("_blocks"), 2750049986UL, PH_NOISY_CC); + if (zend_is_true(block_mode)) { + if (Z_TYPE_P(blocks) != IS_ARRAY) { + PHALCON_INIT_NVAR(blocks); + array_init(blocks); } - if (PHALCON_IS_TRUE(is_null)) { - if (!zend_is_true(exists)) { + if (Z_TYPE_P(compilation) != IS_NULL) { + phalcon_array_append(&blocks, compilation, PH_SEPARATE); - if (PHALCON_IS_EQUAL(field, identity_field)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } + PHALCON_INIT_NVAR(compilation); + } - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_VS(message, attribute_field, " is required"); + phalcon_array_update_zval(&blocks, block_name, &block_statements, PH_COPY | PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_blocks"), blocks, 2750049986UL TSRMLS_CC); + } else { + if (Z_TYPE_P(block_statements) == IS_ARRAY) { + PHALCON_INIT_NVAR(code); + phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); + phalcon_concat_self(&compilation, code TSRMLS_CC); + } + } - PHALCON_INIT_NVAR(type); - ZVAL_STRING(type, "PresenceOf", 1); + break; - PHALCON_INIT_NVAR(model_message); - object_init_ex(model_message, phalcon_mvc_model_message_ce); - phalcon_call_method_p3_key(NULL, model_message, "__construct", message, attribute_field, type, 1107214344UL); + case 310: + PHALCON_OBS_NVAR(path); + phalcon_array_fetch_quick_string(&path, statement, SS("path"), 270591026UL, PH_NOISY); - phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), model_message TSRMLS_CC); + PHALCON_OBS_NVAR(view); + phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); + if (Z_TYPE_P(view) == IS_OBJECT) { + PHALCON_INIT_NVAR(views_dir); + phalcon_call_method_key(views_dir, view, "getviewsdir", 2448458514UL); - PHALCON_INIT_NVAR(error); - ZVAL_BOOL(error, 1); - } + PHALCON_INIT_NVAR(final_path); + PHALCON_CONCAT_VV(final_path, views_dir, path); + } else { + PHALCON_CPY_WRT(final_path, path); } - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_NVAR(extended); + ZVAL_BOOL(extended, 1); - if (PHALCON_IS_TRUE(error)) { - if (PHALCON_GLOBAL(orm).events) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "onValidationFails", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - phalcon_call_method_key(NULL, this_ptr, "_canceloperation", 1716493051UL); + PHALCON_INIT_NVAR(sub_compiler); + if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { + return; } - RETURN_MM_FALSE; - } - } - } - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "validation", 1); + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p2_key(temp_compilation, sub_compiler, "compile", final_path, extended, 1074882030UL); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - if (PHALCON_GLOBAL(orm).events) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "onValidationFails", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - } - RETURN_MM_FALSE; - } + if (Z_TYPE_P(temp_compilation) == IS_NULL) { + PHALCON_INIT_NVAR(compiled_path); + phalcon_call_method_key(compiled_path, sub_compiler, "getcompiledtemplatepath", 652904091UL); - if (PHALCON_GLOBAL(orm).events) { - if (!zend_is_true(exists)) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "afterValidationOnCreate", 1); - } else { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "afterValidationOnUpdate", 1); - } + PHALCON_INIT_NVAR(temp_compilation); + phalcon_file_get_contents(temp_compilation, compiled_path TSRMLS_CC); + } - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } + phalcon_update_property_bool(this_ptr, SL("_extended"), 1 TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_extendedBlocks"), temp_compilation, 3140083987UL TSRMLS_CC); + PHALCON_CPY_WRT(block_mode, extended); + break; - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "afterValidation", 1); + case 313: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p1_key(temp_compilation, this_ptr, "compileinclude", statement, 3933930706UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } + case 314: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p2_key(temp_compilation, this_ptr, "compilecache", statement, extends_mode, 2766559938UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "beforeSave", 1); + case 316: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p1_key(temp_compilation, this_ptr, "compiledo", statement, 2315538721UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } + case 327: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p1_key(temp_compilation, this_ptr, "compilereturn", statement, 3471502286UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; - if (zend_is_true(exists)) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "beforeUpdate", 1); - } else { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "beforeCreate", 1); - } + case 317: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p2_key(temp_compilation, this_ptr, "compileautoescape", statement, extends_mode, 3843651512UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; - phalcon_update_property_bool(this_ptr, SL("_skipped"), 0 TSRMLS_CC); + case 319: + phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); + break; - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } + case 320: + phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); + break; + + case 321: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_key(temp_compilation, this_ptr, "compileforelse", 2502543678UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; + + case 322: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p2_key(temp_compilation, this_ptr, "compilemacro", statement, extends_mode, 3157925088UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; + + case 325: + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p2_key(temp_compilation, this_ptr, "compilecall", statement, extends_mode, 474296554UL); + phalcon_concat_self(&compilation, temp_compilation TSRMLS_CC); + break; + + case 358: + break; + + default: + PHALCON_OBS_NVAR(line); + phalcon_array_fetch_quick_string(&line, statement, SS("line"), 266128205UL, PH_NOISY); + + PHALCON_OBS_NVAR(file); + phalcon_array_fetch_quick_string(&file, statement, SS("file"), 259010501UL, PH_NOISY); + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSVSV(exception_message, "Unknown statement ", type, " in ", file, " on line ", line); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; - PHALCON_OBS_VAR(skipped); - phalcon_read_property_this_quick(&skipped, this_ptr, SL("_skipped"), 2005665588UL, PH_NOISY_CC); - if (PHALCON_IS_TRUE(skipped)) { - RETURN_MM_TRUE; } + + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Mvc_Model, _postSave){ - - zval *success, *exists, *event_name = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &success, &exists); + if (PHALCON_IS_TRUE(block_mode)) { - if (PHALCON_IS_TRUE(success)) { - if (zend_is_true(exists)) { - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "afterUpdate", 1); - } else { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "afterCreate", 1); - } - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + PHALCON_OBS_VAR(level); + phalcon_read_property_this_quick(&level, this_ptr, SL("_blockLevel"), 160754279UL, PH_NOISY_CC); + if (PHALCON_IS_LONG(level, 1)) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "afterSave", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + if (Z_TYPE_P(compilation) != IS_NULL) { + phalcon_update_property_array_append(this_ptr, SL("_blocks"), compilation TSRMLS_CC); + } + } - RETURN_CCTOR(success); + phalcon_property_decr(this_ptr, SL("_blockLevel") TSRMLS_CC); } - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "notSave", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - phalcon_call_method_key(NULL, this_ptr, "_canceloperation", 1716493051UL); - RETURN_MM_FALSE; + phalcon_property_decr(this_ptr, SL("_level") TSRMLS_CC); + + RETURN_CCTOR(compilation); } -static PHP_METHOD(Phalcon_Mvc_Model, _doLowInsert){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _compileSource){ - zval *meta_data, *connection, *table, *identity_field; - zval *null_value, *bind_skip, *fields, *values; - zval *bind_types, *attributes, *bind_data_types; - zval *automatic_attributes, *column_map = NULL, *field = NULL; - zval *attribute_field = NULL, *exception_message = NULL; - zval *value = NULL, *bind_type = NULL, *default_value, *use_explicit_identity; - zval *success, *sequence_name = NULL, *support_sequences; - zval *source, *last_insert_id; + zval *view_code, *extends_mode = NULL, *current_path; + zval *intermediate, *compilation, *extended; + zval *final_compilation = NULL, *blocks = NULL, *extended_blocks; + zval *block = NULL, *name = NULL, *local_block = NULL, *block_compilation = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 4, 0, &meta_data, &connection, &table, &identity_field); - - PHALCON_INIT_VAR(null_value); + phalcon_fetch_params(1, 1, 1, &view_code, &extends_mode); - PHALCON_INIT_VAR(bind_skip); - ZVAL_LONG(bind_skip, 1024); + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); + } - PHALCON_INIT_VAR(fields); - array_init(fields); + PHALCON_OBS_VAR(current_path); + phalcon_read_property_this_quick(¤t_path, this_ptr, SL("_currentPath"), 3436123892UL, PH_NOISY_CC); - PHALCON_INIT_VAR(values); - array_init(values); + PHALCON_INIT_VAR(intermediate); + if (phvolt_parse_view(intermediate, view_code, current_path TSRMLS_CC) == FAILURE) { + return; + } - PHALCON_INIT_VAR(bind_types); - array_init(bind_types); + if (Z_TYPE_P(intermediate) == IS_ARRAY) { - PHALCON_INIT_VAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); + PHALCON_INIT_VAR(compilation); + phalcon_call_method_p2_key(compilation, this_ptr, "_statementlist", intermediate, extends_mode, 1357145205UL); - PHALCON_INIT_VAR(bind_data_types); - phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); + PHALCON_OBS_VAR(extended); + phalcon_read_property_this_quick(&extended, this_ptr, SL("_extended"), 1049215029UL, PH_NOISY_CC); + if (PHALCON_IS_TRUE(extended)) { - PHALCON_INIT_VAR(automatic_attributes); - phalcon_call_method_p1_key(automatic_attributes, meta_data, "getautomaticcreateattributes", this_ptr, 159934727UL); - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); - } else { - PHALCON_INIT_NVAR(column_map); - } + if (PHALCON_IS_TRUE(extends_mode)) { + PHALCON_INIT_VAR(final_compilation); + array_init(final_compilation); + } else { + PHALCON_INIT_NVAR(final_compilation); + } - phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(blocks); + phalcon_read_property_this_quick(&blocks, this_ptr, SL("_blocks"), 2750049986UL, PH_NOISY_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_VAR(extended_blocks); + phalcon_read_property_this_quick(&extended_blocks, this_ptr, SL("_extendedBlocks"), 3140083987UL, PH_NOISY_CC); - PHALCON_GET_HVALUE(field); + phalcon_is_iterable(extended_blocks, &ah0, &hp0, 0, 0); - if (!phalcon_array_isset(automatic_attributes, field)) { + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, field)) { - PHALCON_OBS_NVAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, field, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(attribute_field, field); - } + PHALCON_GET_HKEY(name, ah0, hp0); + PHALCON_GET_HVALUE(block); - if (!PHALCON_IS_EQUAL(field, identity_field)) { - phalcon_array_append(&fields, field, PH_SEPARATE); + if (Z_TYPE_P(name) == IS_STRING) { + if (Z_TYPE_P(block) == IS_ARRAY) { + if (phalcon_array_isset(blocks, name)) { + PHALCON_OBS_NVAR(local_block); + phalcon_array_fetch(&local_block, blocks, name, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_currentBlock"), name, 1187906770UL TSRMLS_CC); - if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { + PHALCON_INIT_NVAR(block_compilation); + phalcon_call_method_p1_key(block_compilation, this_ptr, "_statementlist", local_block, 1357145205UL); + } else { + PHALCON_INIT_NVAR(block_compilation); + phalcon_call_method_p1_key(block_compilation, this_ptr, "_statementlist", block, 1357145205UL); + } + } else { + if (phalcon_array_isset(blocks, name)) { + PHALCON_OBS_NVAR(local_block); + phalcon_array_fetch(&local_block, blocks, name, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_currentBlock"), name, 1187906770UL TSRMLS_CC); - if (!phalcon_array_isset(bind_data_types, field)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' have not defined a bind data type"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; + PHALCON_INIT_NVAR(block_compilation); + phalcon_call_method_p1_key(block_compilation, this_ptr, "_statementlist", local_block, 1357145205UL); + } else { + PHALCON_CPY_WRT(block_compilation, block); + } + } + if (PHALCON_IS_TRUE(extends_mode)) { + phalcon_array_update_zval(&final_compilation, name, &block_compilation, PH_COPY | PH_SEPARATE); + } else { + phalcon_concat_self(&final_compilation, block_compilation TSRMLS_CC); } - - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); - phalcon_array_append(&values, value, PH_SEPARATE); - - PHALCON_OBS_NVAR(bind_type); - phalcon_array_fetch(&bind_type, bind_data_types, field, PH_NOISY); - phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); } else { - phalcon_array_append(&values, null_value, PH_SEPARATE); - phalcon_array_append(&bind_types, bind_skip, PH_SEPARATE); + if (PHALCON_IS_TRUE(extends_mode)) { + phalcon_array_append(&final_compilation, block, PH_SEPARATE); + } else { + phalcon_concat_self(&final_compilation, block TSRMLS_CC); + } } - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - if (PHALCON_IS_NOT_FALSE(identity_field)) { - PHALCON_INIT_VAR(default_value); - phalcon_call_method_key(default_value, connection, "getdefaultidvalue", 2034022004UL); + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_INIT_VAR(use_explicit_identity); - phalcon_call_method_key(use_explicit_identity, connection, "useexplicitidvalue", 3630963518UL); - if (zend_is_true(use_explicit_identity)) { - phalcon_array_append(&fields, identity_field, PH_SEPARATE); + RETURN_CCTOR(final_compilation); } - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, identity_field)) { - PHALCON_OBS_NVAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, identity_field, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Identity column '", identity_field, "' isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(attribute_field, identity_field); + if (PHALCON_IS_TRUE(extends_mode)) { + PHALCON_OBS_NVAR(blocks); + phalcon_read_property_this_quick(&blocks, this_ptr, SL("_blocks"), 2750049986UL, PH_NOISY_CC); + RETURN_CCTOR(blocks); } - if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { + RETURN_CCTOR(compilation); + } - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); - if (PHALCON_IS_EMPTY(value)) { - if (zend_is_true(use_explicit_identity)) { - phalcon_array_append(&values, default_value, PH_SEPARATE); - phalcon_array_append(&bind_types, bind_skip, PH_SEPARATE); - } - } else { - if (!zend_is_true(use_explicit_identity)) { - phalcon_array_append(&fields, identity_field, PH_SEPARATE); - } + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Invalid intermediate representation"); + return; +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileString){ + + zval *view_code, *extends_mode = NULL, *current_path; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &view_code, &extends_mode); - if (!phalcon_array_isset(bind_data_types, identity_field)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Identity column '", identity_field, "' isn't part of the table columns"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); + } - phalcon_array_append(&values, value, PH_SEPARATE); + if (Z_TYPE_P(view_code) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The code must be string"); + return; + } - PHALCON_OBS_NVAR(bind_type); - phalcon_array_fetch(&bind_type, bind_data_types, identity_field, PH_NOISY); - phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); - } - } else { - if (zend_is_true(use_explicit_identity)) { - phalcon_array_append(&values, default_value, PH_SEPARATE); - phalcon_array_append(&bind_types, bind_skip, PH_SEPARATE); - } - } + PHALCON_INIT_VAR(current_path); + ZVAL_STRING(current_path, "eval code", 1); + phalcon_update_property_this_quick(this_ptr, SL("_currentPath"), current_path, 3436123892UL TSRMLS_CC); + phalcon_call_method_p2_key(return_value, this_ptr, "_compilesource", view_code, extends_mode, 1468654718UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileFile){ + + zval *path, *compiled_path, *extends_mode = NULL, *exception_message = NULL; + zval *view_code, *compilation, *final_compilation = NULL; + zval *status; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 1, &path, &compiled_path, &extends_mode); + + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); } - PHALCON_INIT_VAR(success); - phalcon_call_method_p4_key(success, connection, "insert", table, values, fields, bind_types, 2673104346UL); - if (PHALCON_IS_NOT_FALSE(identity_field)) { + if (PHALCON_IS_EQUAL(path, compiled_path)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Template path and compilation template path cannot be the same"); + return; + } - PHALCON_INIT_VAR(sequence_name); + if (phalcon_file_exists(path TSRMLS_CC) == FAILURE) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Template file ", path, " does not exist"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; + } - PHALCON_INIT_VAR(support_sequences); - phalcon_call_method_key(support_sequences, connection, "supportsequences", 875716110UL); - if (PHALCON_IS_TRUE(support_sequences)) { - if (phalcon_method_quick_exists_ex(this_ptr, SS("getsequencename"), 3416900031UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(sequence_name, this_ptr, "getsequencename", 3416900031UL); - } else { - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); + PHALCON_INIT_VAR(view_code); + phalcon_file_get_contents(view_code, path TSRMLS_CC); + if (PHALCON_IS_FALSE(view_code)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Template file ", path, " could not be opened"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; + } - PHALCON_INIT_NVAR(sequence_name); - PHALCON_CONCAT_VSVS(sequence_name, source, "_", identity_field, "_seq"); - } - } + phalcon_update_property_this_quick(this_ptr, SL("_currentPath"), path, 3436123892UL TSRMLS_CC); - PHALCON_INIT_VAR(last_insert_id); - phalcon_call_method_p1_key(last_insert_id, connection, "lastinsertid", sequence_name, 106913211UL); - phalcon_update_property_zval_zval(this_ptr, attribute_field, last_insert_id TSRMLS_CC); + PHALCON_INIT_VAR(compilation); + phalcon_call_method_p2_key(compilation, this_ptr, "_compilesource", view_code, extends_mode, 1468654718UL); - phalcon_update_property_null(this_ptr, SL("_uniqueParams") TSRMLS_CC); + if (Z_TYPE_P(compilation) == IS_ARRAY) { + PHALCON_INIT_VAR(final_compilation); + phalcon_serialize(final_compilation, &compilation TSRMLS_CC); + } else { + PHALCON_CPY_WRT(final_compilation, compilation); } - RETURN_CCTOR(success); + PHALCON_INIT_VAR(status); + phalcon_file_put_contents(status, compiled_path, final_compilation TSRMLS_CC); + if (PHALCON_IS_FALSE(status)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Volt directory can't be written"); + return; + } + + RETURN_CCTOR(compilation); } -static PHP_METHOD(Phalcon_Mvc_Model, _doLowUpdate){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compile){ - zval *meta_data, *connection, *table, *null_value; - zval *bind_skip, *fields, *values, *bind_types; - zval *manager, *use_dynamic_update = NULL, *snapshot; - zval *bind_data_types, *non_primary, *automatic_attributes; - zval *column_map = NULL, *field = NULL, *exception_message = NULL; - zval *attribute_field = NULL, *value = NULL, *bind_type = NULL, *changed = NULL; - zval *snapshot_value = NULL, *unique_key, *unique_params = NULL; - zval *unique_types, *primary_keys, *conditions; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; + zval *template_path, *extends_mode = NULL, *zero, *znull; + zval *zfalse, *stat = NULL, *compile_always = NULL, *compiled_path = NULL; + zval *prefix = NULL, *compiled_separator = NULL, *compiled_extension = NULL; + zval *compilation = NULL, *options, *real_template_path; + zval *template_sep_path = NULL, *compiled_template_path = NULL; + zval *params, *real_compiled_path = NULL, *blocks_code; + zval *exception_message = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &meta_data, &connection, &table); - - PHALCON_INIT_VAR(null_value); - - PHALCON_INIT_VAR(bind_skip); - ZVAL_LONG(bind_skip, 1024); + phalcon_fetch_params(1, 1, 1, &template_path, &extends_mode); - PHALCON_INIT_VAR(fields); - array_init(fields); + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); + } - PHALCON_INIT_VAR(values); - array_init(values); + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); - PHALCON_INIT_VAR(bind_types); - array_init(bind_types); + PHALCON_INIT_VAR(znull); - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); + PHALCON_INIT_VAR(zfalse); + ZVAL_BOOL(zfalse, 0); - PHALCON_INIT_VAR(use_dynamic_update); - phalcon_call_method_p1_key(use_dynamic_update, manager, "isusingdynamicupdate", this_ptr, 2562260687UL); - if (zend_is_true(use_dynamic_update)) { + phalcon_update_property_this_quick(this_ptr, SL("_extended"), zfalse, 1049215029UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_extendedBlocks"), zfalse, 3140083987UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_blocks"), znull, 2750049986UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_level"), zero, 2549049372UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_foreachLevel"), zero, 1560648116UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_blockLevel"), zero, 160754279UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_exprLevel"), zero, 4164657371UL TSRMLS_CC); - PHALCON_OBS_VAR(snapshot); - phalcon_read_property_this_quick(&snapshot, this_ptr, SL("_snapshot"), 3325604532UL, PH_NOISY_CC); - if (Z_TYPE_P(snapshot) != IS_ARRAY) { - PHALCON_INIT_NVAR(use_dynamic_update); - ZVAL_BOOL(use_dynamic_update, 0); - } - } + PHALCON_INIT_VAR(stat); + ZVAL_BOOL(stat, 1); + PHALCON_CPY_WRT(compile_always, zfalse); - PHALCON_INIT_VAR(bind_data_types); - phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); + PHALCON_INIT_VAR(compiled_path); + ZVAL_STRING(compiled_path, "", 1); + PHALCON_CPY_WRT(prefix, znull); - PHALCON_INIT_VAR(non_primary); - phalcon_call_method_p1_key(non_primary, meta_data, "getnonprimarykeyattributes", this_ptr, 1524832420UL); + PHALCON_INIT_VAR(compiled_separator); + ZVAL_STRING(compiled_separator, "%%", 1); - PHALCON_INIT_VAR(automatic_attributes); - phalcon_call_method_p1_key(automatic_attributes, meta_data, "getautomaticupdateattributes", this_ptr, 2703790998UL); - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); - } else { - PHALCON_INIT_NVAR(column_map); - } + PHALCON_INIT_VAR(compiled_extension); + ZVAL_STRING(compiled_extension, ".php", 1); + PHALCON_CPY_WRT(compilation, znull); - phalcon_is_iterable(non_primary, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (Z_TYPE_P(options) == IS_ARRAY) { - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (phalcon_array_isset_quick_string(options, SS("compileAlways"), 595908511UL)) { - PHALCON_GET_HVALUE(field); + phalcon_array_fetch_quick_string(&compile_always, options, SS("compileAlways"), 595908511UL, PH_NOISY); + if (Z_TYPE_P(compile_always) != IS_BOOL) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compileAlways must be a bool value"); + return; + } + } - if (!phalcon_array_isset(automatic_attributes, field)) { + if (phalcon_array_isset_quick_string(options, SS("prefix"), 3263410483UL)) { - if (!phalcon_array_isset(bind_data_types, field)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' have not defined a bind data type"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + phalcon_array_fetch_quick_string(&prefix, options, SS("prefix"), 3263410483UL, PH_NOISY); + if (Z_TYPE_P(prefix) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "prefix must be a string"); return; } + } - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, field)) { - PHALCON_OBS_NVAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, field, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + if (phalcon_array_isset_quick_string(options, SS("compiledPath"), 2785475967UL)) { + + PHALCON_OBS_NVAR(compiled_path); + phalcon_array_fetch_quick_string(&compiled_path, options, SS("compiledPath"), 2785475967UL, PH_NOISY); + if (Z_TYPE_P(compiled_path) != IS_STRING) { + if (Z_TYPE_P(compiled_path) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compiledPath must be a string or a closure"); return; } - } else { - PHALCON_CPY_WRT(attribute_field, field); } + } - if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { + if (phalcon_array_isset_quick_string(options, SS("compiledSeparator"), 3462898403UL)) { - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); + PHALCON_OBS_NVAR(compiled_separator); + phalcon_array_fetch_quick_string(&compiled_separator, options, SS("compiledSeparator"), 3462898403UL, PH_NOISY); + if (Z_TYPE_P(compiled_separator) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compiledSeparator must be a string"); + return; + } + } - if (!zend_is_true(use_dynamic_update)) { - phalcon_array_append(&fields, field, PH_SEPARATE); - phalcon_array_append(&values, value, PH_SEPARATE); + if (phalcon_array_isset_quick_string(options, SS("compiledExtension"), 401304207UL)) { - PHALCON_OBS_NVAR(bind_type); - phalcon_array_fetch(&bind_type, bind_data_types, field, PH_NOISY); - phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); - } else { - if (!phalcon_array_isset(snapshot, attribute_field)) { - PHALCON_INIT_NVAR(changed); - ZVAL_BOOL(changed, 1); - } else { - PHALCON_OBS_NVAR(snapshot_value); - phalcon_array_fetch(&snapshot_value, snapshot, attribute_field, PH_NOISY); - if (!PHALCON_IS_EQUAL(value, snapshot_value)) { - PHALCON_INIT_NVAR(changed); - ZVAL_BOOL(changed, 1); - } else { - PHALCON_INIT_NVAR(changed); - ZVAL_BOOL(changed, 0); - } - } + PHALCON_OBS_NVAR(compiled_extension); + phalcon_array_fetch_quick_string(&compiled_extension, options, SS("compiledExtension"), 401304207UL, PH_NOISY); + if (Z_TYPE_P(compiled_extension) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compiledExtension must be a string"); + return; + } + } - if (zend_is_true(changed)) { - phalcon_array_append(&fields, field, PH_SEPARATE); - phalcon_array_append(&values, value, PH_SEPARATE); + if (phalcon_array_isset_quick_string(options, SS("stat"), 274811297UL)) { + PHALCON_OBS_NVAR(stat); + phalcon_array_fetch_quick_string(&stat, options, SS("stat"), 274811297UL, PH_NOISY); + } + } + + if (Z_TYPE_P(compiled_path) == IS_STRING) { + + if (PHALCON_IS_NOT_EMPTY(compiled_path)) { + PHALCON_INIT_VAR(real_template_path); + phalcon_call_func_p1(real_template_path, "realpath", template_path); + + PHALCON_INIT_VAR(template_sep_path); + phalcon_prepare_virtual_path(template_sep_path, real_template_path, compiled_separator TSRMLS_CC); + } else { + PHALCON_CPY_WRT(template_sep_path, template_path); + } + + if (PHALCON_IS_TRUE(extends_mode)) { + PHALCON_INIT_VAR(compiled_template_path); + PHALCON_CONCAT_VVVVSVV(compiled_template_path, compiled_path, prefix, template_sep_path, compiled_separator, "e", compiled_separator, compiled_extension); + } else { + PHALCON_INIT_NVAR(compiled_template_path); + PHALCON_CONCAT_VVVV(compiled_template_path, compiled_path, prefix, template_sep_path, compiled_extension); + } + } else { + if (Z_TYPE_P(compiled_path) == IS_OBJECT) { + if (phalcon_is_instance_of(compiled_path, SL("Closure") TSRMLS_CC)) { + + PHALCON_INIT_VAR(params); + array_init_size(params, 3); + phalcon_array_append(¶ms, template_path, PH_SEPARATE); + phalcon_array_append(¶ms, options, PH_SEPARATE); + phalcon_array_append(¶ms, extends_mode, PH_SEPARATE); + + PHALCON_INIT_NVAR(compiled_template_path); + PHALCON_CALL_USER_FUNC_ARRAY(compiled_template_path, compiled_path, params); - PHALCON_OBS_NVAR(bind_type); - phalcon_array_fetch(&bind_type, bind_data_types, field, PH_NOISY); - phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); - } + if (Z_TYPE_P(compiled_template_path) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compiledPath closure didn't return a valid string"); + return; } } else { - phalcon_array_append(&fields, field, PH_SEPARATE); - phalcon_array_append(&values, null_value, PH_SEPARATE); - phalcon_array_append(&bind_types, bind_skip, PH_SEPARATE); + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compiledPath must be a string or a closure"); + return; } } - - zend_hash_move_forward_ex(ah0, &hp0); } - if (!phalcon_fast_count_ev(fields TSRMLS_CC)) { - RETURN_MM_TRUE; - } - - PHALCON_OBS_VAR(unique_key); - phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(unique_params); - phalcon_read_property_this_quick(&unique_params, this_ptr, SL("_uniqueParams"), 1065564063UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(unique_types); - phalcon_read_property_this_quick(&unique_types, this_ptr, SL("_uniqueTypes"), 3340838640UL, PH_NOISY_CC); - - if (Z_TYPE_P(unique_params) != IS_ARRAY) { - - PHALCON_INIT_NVAR(unique_params); - array_init(unique_params); - - PHALCON_INIT_VAR(primary_keys); - phalcon_call_method_p1_key(primary_keys, meta_data, "getprimarykeyattributes", this_ptr, 692945721UL); - - if (!phalcon_fast_count_ev(primary_keys TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A primary key must be defined in the model in order to perform the operation"); - return; - } + PHALCON_CPY_WRT(real_compiled_path, compiled_template_path); + if (zend_is_true(compile_always)) { + PHALCON_INIT_NVAR(compilation); + phalcon_call_method_p3_key(compilation, this_ptr, "compilefile", template_path, real_compiled_path, extends_mode, 478141582UL); + } else { + if (PHALCON_IS_TRUE(stat)) { - phalcon_is_iterable(primary_keys, &ah1, &hp1, 0, 0); + if (phalcon_file_exists(compiled_template_path TSRMLS_CC) == SUCCESS) { - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + if (phalcon_compare_mtime(template_path, real_compiled_path TSRMLS_CC)) { + PHALCON_INIT_NVAR(compilation); + phalcon_call_method_p3_key(compilation, this_ptr, "compilefile", template_path, real_compiled_path, extends_mode, 478141582UL); + } else { + if (PHALCON_IS_TRUE(extends_mode)) { - PHALCON_GET_HVALUE(field); + PHALCON_INIT_VAR(blocks_code); + phalcon_file_get_contents(blocks_code, real_compiled_path TSRMLS_CC); + if (PHALCON_IS_FALSE(blocks_code)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Extends compilation file ", real_compiled_path, " could not be opened"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; + } - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, field)) { - PHALCON_OBS_NVAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, field, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", field, "' isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; + if (zend_is_true(blocks_code)) { + PHALCON_INIT_NVAR(compilation); + phalcon_unserialize(compilation, blocks_code TSRMLS_CC); + } else { + PHALCON_INIT_NVAR(compilation); + array_init(compilation); + } + } } } else { - PHALCON_CPY_WRT(attribute_field, field); + PHALCON_INIT_NVAR(compilation); + phalcon_call_method_p3_key(compilation, this_ptr, "compilefile", template_path, real_compiled_path, extends_mode, 478141582UL); } - 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_CC); - phalcon_array_append(&unique_params, value, PH_SEPARATE); - } else { - phalcon_array_append(&unique_params, null_value, PH_SEPARATE); + } else { + if (phalcon_file_exists(real_compiled_path TSRMLS_CC) == FAILURE) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "Compiled template file ", real_compiled_path, " does not exist"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; } - - zend_hash_move_forward_ex(ah1, &hp1); } - } - PHALCON_INIT_VAR(conditions); - array_init_size(conditions, 3); - phalcon_array_update_quick_string(&conditions, SS("conditions"), 1055696255UL, &unique_key, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&conditions, SS("bind"), 254268962UL, &unique_params, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&conditions, SS("bindTypes"), 3951758359UL, &unique_types, PH_COPY | PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_compiledTemplatePath"), real_compiled_path, 2270620474UL TSRMLS_CC); - phalcon_call_method_p5(return_value, connection, "update", table, fields, values, conditions, bind_types); + RETURN_CCTOR(compilation); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getTemplatePath){ + + + RETURN_MEMBER_QUICK(this_ptr, "_currentPath", 3436123892UL); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getCompiledTemplatePath){ + + + RETURN_MEMBER_QUICK(this_ptr, "_compiledTemplatePath", 2270620474UL); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, parse){ + + zval *view_code, *current_path; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &view_code); + + PHALCON_INIT_VAR(current_path); + ZVAL_STRING(current_path, "eval code", 1); + if (phvolt_parse_view(return_value, view_code, current_path TSRMLS_CC) == FAILURE) { + return; + } RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_Model, _preSaveRelatedRecords){ - zval *connection, *related, *nesting, *class_name; - zval *manager, *record = NULL, *name = NULL, *relation = NULL, *type = NULL, *columns = NULL; - zval *referenced_model = NULL, *referenced_fields = NULL; - zval *status = NULL, *messages = NULL, *message = NULL, *referenced_value = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; - PHALCON_MM_GROW(); +/* Driver template for the LEMON parser generator. +** The author disclaims copyright to this source code. +*/ +/* First off, code is include which follows the "include" declaration +** in the input file. */ +#include +// 42 "parser.lemon" + + +#ifdef HAVE_CONFIG_H +#endif + + + + + +static zval *phvolt_ret_literal_zval(int type, phvolt_parser_token *T, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", type); + if (T) { + add_assoc_stringl(ret, "value", T->token, T->token_len, 0); + efree(T); + } + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_if_statement(zval *expr, zval *true_statements, zval *false_statements, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_IF); + add_assoc_zval(ret, "expr", expr); + + if (true_statements) { + add_assoc_zval(ret, "true_statements", true_statements); + } + if (false_statements) { + add_assoc_zval(ret, "false_statements", false_statements); + } + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_elseif_statement(zval *expr, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_ELSEIF); + add_assoc_zval(ret, "expr", expr); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_elsefor_statement(phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_ELSEFOR); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_for_statement(phvolt_parser_token *variable, phvolt_parser_token *key, zval *expr, zval *if_expr, zval *block_statements, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_FOR); + + add_assoc_stringl(ret, "variable", variable->token, variable->token_len, 0); + efree(variable); + + if (key) { + add_assoc_stringl(ret, "key", key->token, key->token_len, 0); + efree(key); + } + + add_assoc_zval(ret, "expr", expr); + + if (if_expr) { + add_assoc_zval(ret, "if_expr", if_expr); + } + + add_assoc_zval(ret, "block_statements", block_statements); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_cache_statement(zval *expr, phvolt_parser_token *lifetime, zval *block_statements, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init(ret); + + add_assoc_long(ret, "type", PHVOLT_T_CACHE); + add_assoc_zval(ret, "expr", expr); + + if (lifetime) { + add_assoc_stringl(ret, "lifetime", lifetime->token, lifetime->token_len, 0); + efree(lifetime); + } + add_assoc_zval(ret, "block_statements", block_statements); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_set_statement(zval *assignments) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 2); + add_assoc_long(ret, "type", PHVOLT_T_SET); + + add_assoc_zval(ret, "assignments", assignments); + + return ret; +} + +static zval *phvolt_ret_set_assignment(phvolt_parser_token *variable, int operator, zval *expr, phvolt_scanner_state *state) +{ + + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 5); + + add_assoc_stringl(ret, "variable", variable->token, variable->token_len, 0); + efree(variable); + + add_assoc_long(ret, "op", operator); + + add_assoc_zval(ret, "expr", expr); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_echo_statement(zval *expr, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 4); + add_assoc_long(ret, "type", PHVOLT_T_ECHO); + add_assoc_zval(ret, "expr", expr); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_block_statement(phvolt_parser_token *name, zval *block_statements, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init(ret); + + add_assoc_long(ret, "type", PHVOLT_T_BLOCK); + + add_assoc_stringl(ret, "name", name->token, name->token_len, 0); + efree(name); + + if (block_statements) { + add_assoc_zval(ret, "block_statements", block_statements); + } + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_macro_statement(phvolt_parser_token *macro_name, zval *parameters, zval *block_statements, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_MACRO); + + add_assoc_stringl(ret, "name", macro_name->token, macro_name->token_len, 0); + efree(macro_name); + + if (parameters) { + add_assoc_zval(ret, "parameters", parameters); + } + + if (block_statements) { + add_assoc_zval(ret, "block_statements", block_statements); + } + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_macro_parameter(phvolt_parser_token *variable, zval *default_value, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 5); + + add_assoc_stringl(ret, "variable", variable->token, variable->token_len, 0); + efree(variable); + + if (default_value) { + add_assoc_zval(ret, "default", default_value); + } + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_extends_statement(phvolt_parser_token *P, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 4); + + add_assoc_long(ret, "type", PHVOLT_T_EXTENDS); + add_assoc_stringl(ret, "path", P->token, P->token_len, 0); + efree(P); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_include_statement(zval *path, zval *params, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 4); + + add_assoc_long(ret, "type", PHVOLT_T_INCLUDE); + + add_assoc_zval(ret, "path", path); + if (params) { + add_assoc_zval(ret, "params", params); + } + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_do_statement(zval *expr, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 4); + + add_assoc_long(ret, "type", PHVOLT_T_DO); + + add_assoc_zval(ret, "expr", expr); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_return_statement(zval *expr, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 4); + + add_assoc_long(ret, "type", PHVOLT_T_RETURN); + + add_assoc_zval(ret, "expr", expr); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_autoescape_statement(int enable, zval *block_statements, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 5); + + add_assoc_long(ret, "type", PHVOLT_T_AUTOESCAPE); + add_assoc_long(ret, "enable", enable); + add_assoc_zval(ret, "block_statements", block_statements); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_empty_statement(phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 3); + add_assoc_long(ret, "type", PHVOLT_T_EMPTY); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_break_statement(phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 3); + add_assoc_long(ret, "type", PHVOLT_T_BREAK); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_continue_statement(phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 3); + add_assoc_long(ret, "type", PHVOLT_T_CONTINUE); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); - phalcon_fetch_params(1, 2, 0, &connection, &related); - - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 0); - - phalcon_call_method_p1_key(NULL, connection, "begin", nesting, 4090922282UL); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(manager); - phalcon_call_method_key(manager, this_ptr, "getmodelsmanager", 2387491844UL); - - phalcon_is_iterable(related, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(name, ah0, hp0); - PHALCON_GET_HVALUE(record); - - PHALCON_INIT_NVAR(relation); - phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", class_name, name, 785467656UL); - if (Z_TYPE_P(relation) == IS_OBJECT) { - - PHALCON_INIT_NVAR(type); - phalcon_call_method_key(type, relation, "gettype", 4294422375UL); - - if (PHALCON_IS_LONG(type, 0)) { - - if (Z_TYPE_P(record) != IS_OBJECT) { - phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Only objects can be stored as part of belongs-to relations"); - return; - } - - PHALCON_INIT_NVAR(columns); - phalcon_call_method_key(columns, relation, "getfields", 2162018780UL); - - PHALCON_INIT_NVAR(referenced_model); - phalcon_call_method_key(referenced_model, relation, "getreferencedmodel", 478093161UL); - - PHALCON_INIT_NVAR(referenced_fields); - phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - if (Z_TYPE_P(columns) == IS_ARRAY) { - phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Not implemented"); - return; - } - - PHALCON_INIT_NVAR(status); - phalcon_call_method_key(status, record, "save", 274150868UL); - if (!zend_is_true(status)) { - - PHALCON_INIT_NVAR(messages); - phalcon_call_method_key(messages, record, "getmessages", 4087333309UL); - - phalcon_is_iterable(messages, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(message); - - if (Z_TYPE_P(record) == IS_OBJECT) { - phalcon_call_method_p1_key(NULL, message, "setmodel", record, 1672695874UL); - } - - phalcon_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - RETURN_MM_FALSE; - } - - PHALCON_INIT_NVAR(referenced_value); - phalcon_call_method_p1_key(referenced_value, record, "readattribute", referenced_fields, 95450773UL); - - phalcon_update_property_zval_zval(this_ptr, columns, referenced_value TSRMLS_CC); - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_MM_TRUE; + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model, _postSaveRelatedRecords){ +static zval *phvolt_ret_zval_list(zval *list_left, zval *right_list) +{ - zval *connection, *related, *nesting, *class_name; - zval *manager, *record = NULL, *name = NULL, *relation = NULL, *type = NULL, *columns = NULL; - zval *referenced_model = NULL, *referenced_fields = NULL; - zval *related_records = NULL, *exception_message = NULL; - zval *value = NULL, *is_through = NULL, *new_instance = NULL, *intermediate_model_name = NULL; - zval *intermediate_fields = NULL, *intermediate_referenced_fields = NULL; - zval *record_after = NULL, *intermediate_model = NULL, *intermediate_value = NULL; - zval *status = NULL, *messages = NULL, *message = NULL; - HashTable *ah0, *ah1, *ah2, *ah3; - HashPosition hp0, hp1, hp2, hp3; - zval **hd; + zval *ret; + HashPosition pos; + HashTable *list; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init(ret); - phalcon_fetch_params(1, 2, 0, &connection, &related); - - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 0); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(manager); - phalcon_call_method_key(manager, this_ptr, "getmodelsmanager", 2387491844UL); - - phalcon_is_iterable(related, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(name, ah0, hp0); - PHALCON_GET_HVALUE(record); - - PHALCON_INIT_NVAR(relation); - phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", class_name, name, 785467656UL); - if (Z_TYPE_P(relation) == IS_OBJECT) { - - PHALCON_INIT_NVAR(type); - phalcon_call_method_key(type, relation, "gettype", 4294422375UL); - - if (PHALCON_IS_LONG(type, 0)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - - if (Z_TYPE_P(record) != IS_OBJECT) { - if (Z_TYPE_P(record) != IS_ARRAY) { - phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Only objects/arrays can be stored as part of has-many/has-one/has-many-to-many relations"); - return; - } - } - - PHALCON_INIT_NVAR(columns); - phalcon_call_method_key(columns, relation, "getfields", 2162018780UL); - - PHALCON_INIT_NVAR(referenced_model); - phalcon_call_method_key(referenced_model, relation, "getreferencedmodel", 478093161UL); - - PHALCON_INIT_NVAR(referenced_fields); - phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - if (Z_TYPE_P(columns) == IS_ARRAY) { - phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Not implemented"); - return; - } - - if (Z_TYPE_P(record) == IS_OBJECT) { - PHALCON_INIT_NVAR(related_records); - array_init_size(related_records, 1); - phalcon_array_append(&related_records, record, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(related_records, record); - } - - if (!phalcon_isset_property_zval(this_ptr, columns TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "The column '", columns, "' needs to be present in the model"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, columns, PH_NOISY_CC); - - PHALCON_INIT_NVAR(is_through); - phalcon_call_method_key(is_through, relation, "isthrough", 2540564770UL); - - if (zend_is_true(is_through)) { - PHALCON_INIT_NVAR(new_instance); - ZVAL_BOOL(new_instance, 1); - - PHALCON_INIT_NVAR(intermediate_model_name); - phalcon_call_method_key(intermediate_model_name, relation, "getintermediatemodel", 851527441UL); - - PHALCON_INIT_NVAR(intermediate_fields); - phalcon_call_method_key(intermediate_fields, relation, "getintermediatefields", 1646880791UL); - - PHALCON_INIT_NVAR(intermediate_referenced_fields); - phalcon_call_method_key(intermediate_referenced_fields, relation, "getintermediatereferencedfields", 3001626474UL); - } - - phalcon_is_iterable(related_records, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(record_after); - - if (!zend_is_true(is_through)) { - phalcon_call_method_p2_key(NULL, record_after, "writeattribute", referenced_fields, value, 3716971876UL); - } else { - PHALCON_INIT_NVAR(intermediate_model); - phalcon_call_method_p2_key(intermediate_model, manager, "load", intermediate_model_name, new_instance, 266329637UL); - - phalcon_call_method_p2_key(NULL, intermediate_model, "writeattribute", intermediate_fields, value, 3716971876UL); - - PHALCON_OBS_NVAR(intermediate_value); - phalcon_read_property_zval(&intermediate_value, record_after, referenced_fields, PH_NOISY_CC); - - phalcon_call_method_p2_key(NULL, intermediate_model, "writeattribute", intermediate_referenced_fields, intermediate_value, 3716971876UL); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_key(status, intermediate_model, "save", 274150868UL); - if (!zend_is_true(status)) { - - PHALCON_INIT_NVAR(messages); - phalcon_call_method_key(messages, intermediate_model, "getmessages", 4087333309UL); - - phalcon_is_iterable(messages, &ah2, &hp2, 0, 0); - - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - - PHALCON_GET_HVALUE(message); - - if (Z_TYPE_P(message) == IS_OBJECT) { - phalcon_call_method_p1_key(NULL, message, "setmodel", record, 1672695874UL); - } - - phalcon_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - - zend_hash_move_forward_ex(ah2, &hp2); - } - - phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - RETURN_MM_FALSE; - } - } - - PHALCON_INIT_NVAR(status); - phalcon_call_method_key(status, record_after, "save", 274150868UL); - if (!zend_is_true(status)) { - - PHALCON_INIT_NVAR(messages); - phalcon_call_method_key(messages, record_after, "getmessages", 4087333309UL); - - phalcon_is_iterable(messages, &ah3, &hp3, 0, 0); - - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - - PHALCON_GET_HVALUE(message); - - if (Z_TYPE_P(message) == IS_OBJECT) { - phalcon_call_method_p1_key(NULL, message, "setmodel", record, 1672695874UL); - } - - phalcon_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - - zend_hash_move_forward_ex(ah3, &hp3); - } - - phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - RETURN_MM_FALSE; + if (list_left) { + + list = Z_ARRVAL_P(list_left); + if (zend_hash_index_exists(list, 0)) { + zend_hash_internal_pointer_reset_ex(list, &pos); + for (;; zend_hash_move_forward_ex(list, &pos)) { + + zval ** item; + + if (zend_hash_get_current_data_ex(list, (void**) &item, &pos) == FAILURE) { + break; } - - zend_hash_move_forward_ex(ah1, &hp1); + + Z_ADDREF_PP(item); + add_next_index_zval(ret, *item); + } - + zval_ptr_dtor(&list_left); } else { - if (Z_TYPE_P(record) != IS_ARRAY) { - phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSVS(exception_message, "There are no defined relations for the model \"", class_name, "\" using alias \"", name, "\""); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } + add_next_index_zval(ret, list_left); } - - zend_hash_move_forward_ex(ah0, &hp0); } - - phalcon_call_method_p1_key(NULL, connection, "commit", nesting, 3546528686UL); - RETURN_MM_TRUE; -} -static PHP_METHOD(Phalcon_Mvc_Model, save){ + add_next_index_zval(ret, right_list); - zval *data = NULL, *white_list = NULL, *meta_data, *attributes = NULL; - zval *attribute = NULL, *value = NULL, *possible_setter = NULL, *write_connection; - zval *related, *status = NULL, *schema, *source, *table = NULL, *read_connection; - zval *exists, *error_messages = NULL, *identity_field; - zval *nesting = NULL, *exception, *success = NULL, *new_success = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + return ret; +} - PHALCON_MM_GROW(); +static zval *phvolt_ret_named_item(phvolt_parser_token *name, zval *expr, phvolt_scanner_state *state) +{ + zval *ret; - phalcon_fetch_params(1, 0, 2, &data, &white_list); - - if (!data) { - PHALCON_INIT_VAR(data); - } - - if (!white_list) { - PHALCON_INIT_VAR(white_list); - } - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - - if (Z_TYPE_P(data) != IS_NULL) { - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data passed to save() must be an array"); - return; - } - - PHALCON_INIT_VAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getcolumnmap", this_ptr, 213063537UL); - if (Z_TYPE_P(attributes) != IS_ARRAY) { - PHALCON_INIT_NVAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); - } - - phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(attribute); - - if (phalcon_array_isset(data, attribute)) { - - if (Z_TYPE_P(white_list) == IS_ARRAY) { - if (!phalcon_fast_in_array(attribute, white_list TSRMLS_CC)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, data, attribute, PH_NOISY); - - PHALCON_INIT_NVAR(possible_setter); - PHALCON_CONCAT_SV(possible_setter, "set", attribute); - if (phalcon_method_exists(this_ptr, possible_setter TSRMLS_CC) == SUCCESS) { - phalcon_call_method_zval_p1_noret(this_ptr, possible_setter, value); - } else { - phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - PHALCON_INIT_VAR(write_connection); - phalcon_call_method_key(write_connection, this_ptr, "getwriteconnection", 4280185952UL); - - PHALCON_OBS_VAR(related); - phalcon_read_property_this_quick(&related, this_ptr, SL("_related"), 3277783461UL, PH_NOISY_CC); - if (Z_TYPE_P(related) == IS_ARRAY) { - - PHALCON_INIT_VAR(status); - phalcon_call_method_p2_key(status, this_ptr, "_presaverelatedrecords", write_connection, related, 2651327373UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } - - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, this_ptr, "getschema", 1539736246UL); - - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); - if (zend_is_true(schema)) { - PHALCON_INIT_VAR(table); - array_init_size(table, 2); - phalcon_array_append(&table, schema, PH_SEPARATE); - phalcon_array_append(&table, source, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(table, source); - } - - PHALCON_INIT_VAR(read_connection); - phalcon_call_method_key(read_connection, this_ptr, "getreadconnection", 488334257UL); - - PHALCON_INIT_VAR(exists); - phalcon_call_method_p3_key(exists, this_ptr, "_exists", meta_data, read_connection, table, 2792580580UL); - if (zend_is_true(exists)) { - phalcon_update_property_long(this_ptr, SL("_operationMade"), 2 TSRMLS_CC); - } else { - phalcon_update_property_long(this_ptr, SL("_operationMade"), 1 TSRMLS_CC); - } - - PHALCON_INIT_VAR(error_messages); - array_init(error_messages); - phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), error_messages, 1019066246UL TSRMLS_CC); - - PHALCON_INIT_VAR(identity_field); - phalcon_call_method_p1_key(identity_field, meta_data, "getidentityfield", this_ptr, 1208930067UL); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p3_key(status, this_ptr, "_presave", meta_data, exists, identity_field, 3296192410UL); - if (PHALCON_IS_FALSE(status)) { - - if (Z_TYPE_P(related) == IS_ARRAY) { - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 0); - phalcon_call_method_p1_key(NULL, write_connection, "rollback", nesting, 3199546639UL); - } - - if (PHALCON_GLOBAL(orm).exception_on_failed_save) { - PHALCON_OBS_NVAR(error_messages); - phalcon_read_property_this_quick(&error_messages, this_ptr, SL("_errorMessages"), 1019066246UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(exception); - object_init_ex(exception, phalcon_mvc_model_validationfailed_ce); - phalcon_call_method_p2_key(NULL, exception, "__construct", this_ptr, error_messages, 1107214344UL); - - phalcon_throw_exception(exception TSRMLS_CC); - return; - } - - RETURN_MM_FALSE; - } - - if (zend_is_true(exists)) { - PHALCON_INIT_VAR(success); - phalcon_call_method_p3_key(success, this_ptr, "_dolowupdate", meta_data, write_connection, table, 393175884UL); - } else { - PHALCON_INIT_NVAR(success); - phalcon_call_method_p4_key(success, this_ptr, "_dolowinsert", meta_data, write_connection, table, identity_field, 2015089534UL); - } - - if (zend_is_true(success)) { - phalcon_update_property_long(this_ptr, SL("_dirtyState"), 0 TSRMLS_CC); - } - - if (PHALCON_GLOBAL(orm).events) { - PHALCON_INIT_VAR(new_success); - phalcon_call_method_p2_key(new_success, this_ptr, "_postsave", success, exists, 3354288601UL); - } else { - PHALCON_CPY_WRT(new_success, success); - } - - if (Z_TYPE_P(related) == IS_ARRAY) { - - if (PHALCON_IS_FALSE(new_success)) { - PHALCON_INIT_NVAR(nesting); - ZVAL_BOOL(nesting, 0); - phalcon_call_method_p1_key(NULL, write_connection, "rollback", nesting, 3199546639UL); - RETURN_MM_FALSE; - } - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, this_ptr, "_postsaverelatedrecords", write_connection, related, 2967472140UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_zval(ret, "expr", expr); + if (name != NULL) { + add_assoc_stringl(ret, "name", name->token, name->token_len, 0); + efree(name); } - - RETURN_CCTOR(new_success); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model, create){ +static zval *phvolt_ret_expr(int type, zval *left, zval *right, zval *ternary, phvolt_scanner_state *state) +{ + zval *ret; - zval *data = NULL, *white_list = NULL, *meta_data, *column_map = NULL; - zval *attributes, *attribute = NULL, *attribute_field = NULL; - zval *exception_message = NULL, *value = NULL, *possible_setter = NULL; - zval *read_connection, *exists, *field, *type, *message; - zval *model_message, *messages; - HashTable *ah0; - HashPosition hp0; - zval **hd; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", type); - PHALCON_MM_GROW(); + if (ternary) { + add_assoc_zval(ret, "ternary", ternary); + } - phalcon_fetch_params(1, 0, 2, &data, &white_list); - - if (!data) { - PHALCON_INIT_VAR(data); + if (left) { + add_assoc_zval(ret, "left", left); } - - if (!white_list) { - PHALCON_INIT_VAR(white_list); + + if (right) { + add_assoc_zval(ret, "right", right); } - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - - if (Z_TYPE_P(data) != IS_NULL) { - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data passed to create() must be an array"); - return; - } - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); - } else { - PHALCON_INIT_NVAR(column_map); - } - - PHALCON_INIT_VAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); - - phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(attribute); - - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, attribute)) { - PHALCON_OBS_NVAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, attribute, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", attribute, "' isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(attribute_field, attribute); - } - - if (phalcon_array_isset(data, attribute_field)) { - - if (Z_TYPE_P(white_list) == IS_ARRAY) { - if (!phalcon_fast_in_array(attribute_field, white_list TSRMLS_CC)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, data, attribute_field, PH_NOISY); - - PHALCON_INIT_NVAR(possible_setter); - PHALCON_CONCAT_SV(possible_setter, "set", attribute_field); - if (phalcon_method_exists(this_ptr, possible_setter TSRMLS_CC) == SUCCESS) { - phalcon_call_method_zval_p1_noret(this_ptr, possible_setter, value); - } else { - phalcon_update_property_zval_zval(this_ptr, attribute_field, value TSRMLS_CC); - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; +} + +static zval *phvolt_ret_slice(zval *left, zval *start, zval *end, phvolt_scanner_state *state) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_SLICE); + add_assoc_zval(ret, "left", left); + + if (start != NULL) { + add_assoc_zval(ret, "start", start); } - - PHALCON_INIT_VAR(read_connection); - phalcon_call_method_key(read_connection, this_ptr, "getreadconnection", 488334257UL); - - PHALCON_INIT_VAR(exists); - phalcon_call_method_p2_key(exists, this_ptr, "_exists", meta_data, read_connection, 2792580580UL); - - if (zend_is_true(exists)) { - PHALCON_INIT_VAR(field); - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "InvalidCreateAttempt", 1); - - PHALCON_INIT_VAR(message); - ZVAL_STRING(message, "Record cannot be created because it already exists", 1); - - PHALCON_INIT_VAR(model_message); - object_init_ex(model_message, phalcon_mvc_model_message_ce); - phalcon_call_method_p3_key(NULL, model_message, "__construct", message, field, type, 1107214344UL); - - PHALCON_INIT_VAR(messages); - array_init_size(messages, 1); - phalcon_array_append(&messages, model_message, PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), messages, 1019066246UL TSRMLS_CC); - RETURN_MM_FALSE; + + if (end != NULL) { + add_assoc_zval(ret, "end", end); } - - phalcon_call_method_key(return_value, this_ptr, "save", 274150868UL); - RETURN_MM(); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model, update){ +static zval *phvolt_ret_func_call(zval *expr, zval *arguments, phvolt_scanner_state *state) +{ - zval *data = NULL, *white_list = NULL, *meta_data = NULL, *column_map = NULL; - zval *attributes, *attribute = NULL, *attribute_field = NULL; - zval *exception_message = NULL, *value = NULL, *possible_setter = NULL; - zval *dirty_state, *read_connection, *exists; - zval *field, *type, *message, *model_message, *messages; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *ret; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_FCALL); + add_assoc_zval(ret, "name", expr); - phalcon_fetch_params(1, 0, 2, &data, &white_list); - - if (!data) { - PHALCON_INIT_VAR(data); - } - - if (!white_list) { - PHALCON_INIT_VAR(white_list); - } - - PHALCON_INIT_VAR(meta_data); - - if (Z_TYPE_P(data) != IS_NULL) { - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data passed to update() must be an array"); - return; - } - - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); - } else { - PHALCON_INIT_NVAR(column_map); - } - - PHALCON_INIT_VAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); - - phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(attribute); - - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, attribute)) { - PHALCON_OBS_NVAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, attribute, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", attribute, "' isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(attribute_field, attribute); - } - - if (phalcon_array_isset(data, attribute_field)) { - - if (Z_TYPE_P(white_list) == IS_ARRAY) { - if (!phalcon_fast_in_array(attribute_field, white_list TSRMLS_CC)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, data, attribute_field, PH_NOISY); - - PHALCON_INIT_NVAR(possible_setter); - PHALCON_CONCAT_SV(possible_setter, "set", attribute_field); - if (phalcon_method_exists(this_ptr, possible_setter TSRMLS_CC) == SUCCESS) { - phalcon_call_method_zval_p1_noret(this_ptr, possible_setter, value); - } else { - phalcon_update_property_zval_zval(this_ptr, attribute_field, value TSRMLS_CC); - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - PHALCON_OBS_VAR(dirty_state); - phalcon_read_property_this_quick(&dirty_state, this_ptr, SL("_dirtyState"), 1560981745UL, PH_NOISY_CC); - if (zend_is_true(dirty_state)) { - if (Z_TYPE_P(meta_data) == IS_NULL) { - PHALCON_INIT_NVAR(meta_data); - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - } - - PHALCON_INIT_VAR(read_connection); - phalcon_call_method_key(read_connection, this_ptr, "getreadconnection", 488334257UL); - - PHALCON_INIT_VAR(exists); - phalcon_call_method_p2_key(exists, this_ptr, "_exists", meta_data, read_connection, 2792580580UL); - if (!zend_is_true(exists)) { - PHALCON_INIT_VAR(field); - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "InvalidUpdateAttempt", 1); - - PHALCON_INIT_VAR(message); - ZVAL_STRING(message, "Record cannot be updated because it does not exist", 1); - - PHALCON_INIT_VAR(model_message); - object_init_ex(model_message, phalcon_mvc_model_message_ce); - phalcon_call_method_p3_key(NULL, model_message, "__construct", message, field, type, 1107214344UL); - - PHALCON_INIT_VAR(messages); - array_init_size(messages, 1); - phalcon_array_append(&messages, model_message, PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), messages, 1019066246UL TSRMLS_CC); - RETURN_MM_FALSE; - } + if (arguments) { + add_assoc_zval(ret, "arguments", arguments); } - - phalcon_call_method_key(return_value, this_ptr, "save", 274150868UL); - RETURN_MM(); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model, delete){ +static zval *phvolt_ret_macro_call_statement(zval *expr, zval *arguments, zval *caller, phvolt_scanner_state *state) +{ - zval *meta_data, *write_connection, *empty_array; - zval *check_foreign_keys = NULL, *values, *bind_types; - zval *conditions, *primary_keys, *bind_data_types; - zval *column_map = NULL, *primary_key = NULL, *exception_message = NULL; - zval *attribute_field = NULL, *value = NULL, *escaped_field = NULL; - zval *primary_condition = NULL, *bind_type = NULL, *delete_conditions; - zval *event_name = NULL, *status, *skipped, *schema, *source; - zval *table = NULL, *success; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *ret; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_CALL); + add_assoc_zval(ret, "name", expr); - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - - PHALCON_INIT_VAR(write_connection); - phalcon_call_method_key(write_connection, this_ptr, "getwriteconnection", 4280185952UL); - - phalcon_update_property_long(this_ptr, SL("_operationMade"), 3 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); - - if (PHALCON_GLOBAL(orm).virtual_foreign_keys) { - - PHALCON_INIT_VAR(check_foreign_keys); - phalcon_call_method_key(check_foreign_keys, this_ptr, "_checkforeignkeysreverserestrict", 2200393844UL); - if (PHALCON_IS_FALSE(check_foreign_keys)) { - RETURN_MM_FALSE; - } - } - - PHALCON_INIT_VAR(values); - array_init(values); - - PHALCON_INIT_VAR(bind_types); - array_init(bind_types); - - PHALCON_INIT_VAR(conditions); - array_init(conditions); - - PHALCON_INIT_VAR(primary_keys); - phalcon_call_method_p1_key(primary_keys, meta_data, "getprimarykeyattributes", this_ptr, 692945721UL); - - PHALCON_INIT_VAR(bind_data_types); - phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); - if (PHALCON_GLOBAL(orm).column_renaming) { - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); - } else { - PHALCON_INIT_NVAR(column_map); - } - - if (!phalcon_fast_count_ev(primary_keys TSRMLS_CC)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A primary key must be defined in the model in order to perform the operation"); - return; - } - - phalcon_is_iterable(primary_keys, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(primary_key); - - if (!phalcon_array_isset(bind_data_types, primary_key)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", primary_key, "' have not defined a bind data type"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (phalcon_array_isset(column_map, primary_key)) { - PHALCON_OBS_NVAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, primary_key, PH_NOISY); - } else { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column '", primary_key, "' isn't part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - PHALCON_CPY_WRT(attribute_field, primary_key); - } - - if (!phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Cannot delete the record because the primary key attribute: '", attribute_field, "' wasn't set"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); - phalcon_array_append(&values, value, PH_SEPARATE); - - PHALCON_INIT_NVAR(escaped_field); - phalcon_call_method_p1_key(escaped_field, write_connection, "escapeidentifier", primary_key, 585773337UL); - - PHALCON_INIT_NVAR(primary_condition); - PHALCON_CONCAT_VS(primary_condition, escaped_field, " = ?"); - phalcon_array_append(&conditions, primary_condition, PH_SEPARATE); - - PHALCON_OBS_NVAR(bind_type); - phalcon_array_fetch(&bind_type, bind_data_types, primary_key, PH_NOISY); - phalcon_array_append(&bind_types, bind_type, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(delete_conditions); - phalcon_fast_join_str(delete_conditions, SL(" AND "), conditions TSRMLS_CC); - if (PHALCON_GLOBAL(orm).events) { - phalcon_update_property_bool(this_ptr, SL("_skipped"), 0 TSRMLS_CC); - - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "beforeDelete", 1); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } else { - PHALCON_OBS_VAR(skipped); - phalcon_read_property_this_quick(&skipped, this_ptr, SL("_skipped"), 2005665588UL, PH_NOISY_CC); - if (PHALCON_IS_TRUE(skipped)) { - RETURN_MM_TRUE; - } - } - } - - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, this_ptr, "getschema", 1539736246UL); - - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); - if (zend_is_true(schema)) { - PHALCON_INIT_VAR(table); - array_init_size(table, 2); - phalcon_array_append(&table, schema, PH_SEPARATE); - phalcon_array_append(&table, source, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(table, source); - } - - PHALCON_INIT_VAR(success); - phalcon_call_method_p4_key(success, write_connection, "delete", table, delete_conditions, values, bind_types, 150213496UL); - - if (PHALCON_GLOBAL(orm).virtual_foreign_keys) { - - PHALCON_INIT_NVAR(check_foreign_keys); - phalcon_call_method_key(check_foreign_keys, this_ptr, "_checkforeignkeysreversecascade", 2711790920UL); - if (PHALCON_IS_FALSE(check_foreign_keys)) { - RETURN_MM_FALSE; - } + if (arguments) { + add_assoc_zval(ret, "arguments", arguments); } - - if (PHALCON_GLOBAL(orm).events) { - if (zend_is_true(success)) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "afterDelete", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - } + + if (caller) { + add_assoc_zval(ret, "caller", caller); } - - phalcon_update_property_long(this_ptr, SL("_dirtyState"), 2 TSRMLS_CC); - - RETURN_CCTOR(success); + + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); + + return ret; } -static PHP_METHOD(Phalcon_Mvc_Model, getOperationMade){ +// 571 "parser.c" +/* Next is all token values, in a form suitable for use by makeheaders. +** This section will be null unless lemon is run with the -m switch. +*/ +/* Make sure the INTERFACE macro is defined. +*/ +#ifndef INTERFACE +# define INTERFACE 1 +#endif +/* The next thing included is series of defines which control +** various aspects of the generated parser. +** KKCODETYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 terminals +** and nonterminals. "int" is used otherwise. +** KKNOCODE is a number of type KKCODETYPE which corresponds +** to no legal terminal or nonterminal number. This +** number is used to fill in empty slots of the hash +** table. +** KKFALLBACK If defined, this indicates that one or more tokens +** have fall-back values which should be used if the +** original value of the token will not parse. +** KKACTIONTYPE is the data type used for storing terminal +** and nonterminal numbers. "unsigned char" is +** used if there are fewer than 250 rules and +** states combined. "int" is used otherwise. +** phvolt_KTOKENTYPE is the data type used for minor tokens given +** directly to the parser from the tokenizer. +** KKMINORTYPE is the data type used for all minor tokens. +** This is typically a union of many types, one of +** which is phvolt_KTOKENTYPE. The entry in the union +** for base tokens is called "kk0". +** KKSTACKDEPTH is the maximum depth of the parser's stack. +** phvolt_ARG_SDECL A static variable declaration for the %extra_argument +** phvolt_ARG_PDECL A parameter declaration for the %extra_argument +** phvolt_ARG_STORE Code to store %extra_argument into kkpParser +** phvolt_ARG_FETCH Code to extract %extra_argument from kkpParser +** KKNSTATE the combined number of states. +** KKNRULE the number of rules in the grammar +** KKERRORSYMBOL is the code number of the error symbol. If not +** defined, then do no error processing. +*/ +#define KKCODETYPE unsigned char +#define KKNOCODE 114 +#define KKACTIONTYPE unsigned short int +#define phvolt_KTOKENTYPE phvolt_parser_token* +typedef union { + phvolt_KTOKENTYPE kk0; + zval* kk132; + int kk227; +} KKMINORTYPE; +#define KKSTACKDEPTH 100 +#define phvolt_ARG_SDECL phvolt_parser_status *status; +#define phvolt_ARG_PDECL ,phvolt_parser_status *status +#define phvolt_ARG_FETCH phvolt_parser_status *status = kkpParser->status +#define phvolt_ARG_STORE kkpParser->status = status +#define KKNSTATE 322 +#define KKNRULE 133 +#define KKERRORSYMBOL 77 +#define KKERRSYMDT kk227 +#define KK_NO_ACTION (KKNSTATE+KKNRULE+2) +#define KK_ACCEPT_ACTION (KKNSTATE+KKNRULE+1) +#define KK_ERROR_ACTION (KKNSTATE+KKNRULE) + +/* Next are that tables used to determine what action to take based on the +** current state and lookahead token. These tables are used to implement +** functions that take a state number and lookahead value and return an +** action integer. +** +** Suppose the action integer is N. Then the action is determined as +** follows +** +** 0 <= N < KKNSTATE Shift N. That is, push the lookahead +** token onto the stack and goto state N. +** +** KKNSTATE <= N < KKNSTATE+KKNRULE Reduce by rule N-KKNSTATE. +** +** N == KKNSTATE+KKNRULE A syntax error has occurred. +** +** N == KKNSTATE+KKNRULE+1 The parser accepts its input. +** +** N == KKNSTATE+KKNRULE+2 No such action. Denotes unused +** slots in the kk_action[] table. +** +** The action table is constructed as a single large table named kk_action[]. +** Given state S and lookahead X, the action is computed as +** +** kk_action[ kk_shift_ofst[S] + X ] +** +** If the index value kk_shift_ofst[S]+X is out of range or if the value +** kk_lookahead[kk_shift_ofst[S]+X] is not equal to X or if kk_shift_ofst[S] +** is equal to KK_SHIFT_USE_DFLT, it means that the action is not in the table +** and that kk_default[S] should be used instead. +** +** The formula above is for computing the action when the lookahead is +** a terminal symbol. If the lookahead is a non-terminal (as occurs after +** a reduce action) then the kk_reduce_ofst[] array is used in place of +** the kk_shift_ofst[] array and KK_REDUCE_USE_DFLT is used in place of +** KK_SHIFT_USE_DFLT. +** +** The following are the tables generated in this section: +** +** kk_action[] A single table containing all actions. +** kk_lookahead[] A table containing the lookahead for each entry in +** kk_action. Used to detect hash collisions. +** kk_shift_ofst[] For each state, the offset into kk_action for +** shifting terminals. +** kk_reduce_ofst[] For each state, the offset into kk_action for +** shifting non-terminals after a reduce. +** kk_default[] Default action for each state. +*/ +static KKACTIONTYPE kk_action[] = { + /* 0 */ 82, 92, 23, 60, 52, 54, 64, 62, 66, 72, + /* 10 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, + /* 20 */ 56, 89, 58, 84, 87, 88, 96, 80, 288, 162, + /* 30 */ 82, 92, 128, 60, 52, 54, 64, 62, 66, 72, + /* 40 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, + /* 50 */ 56, 89, 58, 84, 87, 88, 96, 80, 244, 213, + /* 60 */ 48, 46, 50, 43, 40, 56, 89, 58, 84, 87, + /* 70 */ 88, 96, 80, 247, 295, 160, 255, 127, 168, 183, + /* 80 */ 82, 92, 170, 60, 52, 54, 64, 62, 66, 72, + /* 90 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, + /* 100 */ 56, 89, 58, 84, 87, 88, 96, 80, 322, 223, + /* 110 */ 82, 92, 169, 60, 52, 54, 64, 62, 66, 72, + /* 120 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, + /* 130 */ 56, 89, 58, 84, 87, 88, 96, 80, 304, 299, + /* 140 */ 82, 92, 224, 60, 52, 54, 64, 62, 66, 72, + /* 150 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, + /* 160 */ 56, 89, 58, 84, 87, 88, 96, 80, 30, 26, + /* 170 */ 82, 92, 32, 60, 52, 54, 64, 62, 66, 72, + /* 180 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, + /* 190 */ 56, 89, 58, 84, 87, 88, 96, 80, 108, 39, + /* 200 */ 82, 92, 108, 60, 52, 54, 64, 62, 66, 72, + /* 210 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, + /* 220 */ 56, 89, 58, 84, 87, 88, 96, 80, 82, 92, + /* 230 */ 94, 60, 52, 54, 64, 62, 66, 72, 74, 76, + /* 240 */ 78, 68, 70, 48, 46, 50, 43, 40, 56, 89, + /* 250 */ 58, 84, 87, 88, 96, 80, 43, 40, 56, 89, + /* 260 */ 58, 84, 87, 88, 96, 80, 84, 87, 88, 96, + /* 270 */ 80, 91, 112, 128, 107, 82, 92, 276, 60, 52, + /* 280 */ 54, 64, 62, 66, 72, 74, 76, 78, 68, 70, + /* 290 */ 48, 46, 50, 43, 40, 56, 89, 58, 84, 87, + /* 300 */ 88, 96, 80, 89, 58, 84, 87, 88, 96, 80, + /* 310 */ 281, 282, 283, 284, 285, 286, 269, 287, 197, 102, + /* 320 */ 234, 249, 270, 82, 92, 36, 60, 52, 54, 64, + /* 330 */ 62, 66, 72, 74, 76, 78, 68, 70, 48, 46, + /* 340 */ 50, 43, 40, 56, 89, 58, 84, 87, 88, 96, + /* 350 */ 80, 85, 226, 82, 92, 136, 60, 52, 54, 64, + /* 360 */ 62, 66, 72, 74, 76, 78, 68, 70, 48, 46, + /* 370 */ 50, 43, 40, 56, 89, 58, 84, 87, 88, 96, + /* 380 */ 80, 115, 229, 82, 92, 137, 60, 52, 54, 64, + /* 390 */ 62, 66, 72, 74, 76, 78, 68, 70, 48, 46, + /* 400 */ 50, 43, 40, 56, 89, 58, 84, 87, 88, 96, + /* 410 */ 80, 131, 232, 82, 92, 435, 60, 52, 54, 64, + /* 420 */ 62, 66, 72, 74, 76, 78, 68, 70, 48, 46, + /* 430 */ 50, 43, 40, 56, 89, 58, 84, 87, 88, 96, + /* 440 */ 80, 92, 436, 60, 52, 54, 64, 62, 66, 72, + /* 450 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, + /* 460 */ 56, 89, 58, 84, 87, 88, 96, 80, 246, 141, + /* 470 */ 143, 144, 82, 92, 157, 60, 52, 54, 64, 62, + /* 480 */ 66, 72, 74, 76, 78, 68, 70, 48, 46, 50, + /* 490 */ 43, 40, 56, 89, 58, 84, 87, 88, 96, 80, + /* 500 */ 435, 290, 82, 92, 159, 60, 52, 54, 64, 62, + /* 510 */ 66, 72, 74, 76, 78, 68, 70, 48, 46, 50, + /* 520 */ 43, 40, 56, 89, 58, 84, 87, 88, 96, 80, + /* 530 */ 436, 306, 82, 92, 166, 60, 52, 54, 64, 62, + /* 540 */ 66, 72, 74, 76, 78, 68, 70, 48, 46, 50, + /* 550 */ 43, 40, 56, 89, 58, 84, 87, 88, 96, 80, + /* 560 */ 82, 92, 172, 60, 52, 54, 64, 62, 66, 72, + /* 570 */ 74, 76, 78, 68, 70, 48, 46, 50, 43, 40, + /* 580 */ 56, 89, 58, 84, 87, 88, 195, 80, 60, 52, + /* 590 */ 54, 64, 62, 66, 72, 74, 76, 78, 68, 70, + /* 600 */ 48, 46, 50, 43, 40, 56, 89, 58, 84, 87, + /* 610 */ 88, 96, 80, 52, 54, 64, 62, 66, 72, 74, + /* 620 */ 76, 78, 68, 70, 48, 46, 50, 43, 40, 56, + /* 630 */ 89, 58, 84, 87, 88, 96, 80, 456, 1, 2, + /* 640 */ 248, 4, 5, 6, 7, 8, 9, 10, 11, 12, + /* 650 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + /* 660 */ 64, 62, 66, 72, 74, 76, 78, 68, 70, 48, + /* 670 */ 46, 50, 43, 40, 56, 89, 58, 84, 87, 88, + /* 680 */ 96, 80, 27, 248, 4, 5, 6, 7, 8, 9, + /* 690 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + /* 700 */ 20, 21, 22, 33, 248, 4, 5, 6, 7, 8, + /* 710 */ 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + /* 720 */ 19, 20, 21, 22, 163, 248, 4, 5, 6, 7, + /* 730 */ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + /* 740 */ 18, 19, 20, 21, 22, 189, 248, 4, 5, 6, + /* 750 */ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + /* 760 */ 17, 18, 19, 20, 21, 22, 199, 248, 4, 5, + /* 770 */ 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + /* 780 */ 16, 17, 18, 19, 20, 21, 22, 207, 248, 4, + /* 790 */ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + /* 800 */ 15, 16, 17, 18, 19, 20, 21, 22, 214, 248, + /* 810 */ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, + /* 820 */ 14, 15, 16, 17, 18, 19, 20, 21, 22, 236, + /* 830 */ 248, 4, 5, 6, 7, 8, 9, 10, 11, 12, + /* 840 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + /* 850 */ 251, 248, 4, 5, 6, 7, 8, 9, 10, 11, + /* 860 */ 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + /* 870 */ 22, 257, 248, 4, 5, 6, 7, 8, 9, 10, + /* 880 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + /* 890 */ 21, 22, 272, 248, 4, 5, 6, 7, 8, 9, + /* 900 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + /* 910 */ 20, 21, 22, 291, 248, 4, 5, 6, 7, 8, + /* 920 */ 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + /* 930 */ 19, 20, 21, 22, 300, 248, 4, 5, 6, 7, + /* 940 */ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + /* 950 */ 18, 19, 20, 21, 22, 307, 248, 4, 5, 6, + /* 960 */ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + /* 970 */ 17, 18, 19, 20, 21, 22, 3, 4, 5, 6, + /* 980 */ 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + /* 990 */ 17, 18, 19, 20, 21, 22, 24, 203, 29, 31, + /* 1000 */ 37, 156, 158, 323, 23, 167, 171, 185, 25, 90, + /* 1010 */ 139, 184, 173, 175, 177, 179, 181, 140, 117, 117, + /* 1020 */ 193, 138, 186, 188, 204, 278, 211, 192, 218, 221, + /* 1030 */ 198, 227, 230, 233, 187, 240, 242, 24, 203, 315, + /* 1040 */ 317, 37, 156, 158, 97, 314, 167, 38, 202, 104, + /* 1050 */ 126, 28, 184, 104, 117, 134, 106, 117, 113, 117, + /* 1060 */ 244, 193, 125, 117, 205, 204, 266, 211, 206, 218, + /* 1070 */ 221, 219, 227, 230, 233, 247, 240, 242, 24, 203, + /* 1080 */ 35, 104, 37, 156, 158, 155, 97, 167, 111, 97, + /* 1090 */ 113, 117, 196, 184, 139, 117, 117, 134, 210, 117, + /* 1100 */ 129, 244, 193, 217, 220, 138, 204, 244, 211, 235, + /* 1110 */ 218, 221, 311, 227, 230, 233, 247, 240, 242, 24, + /* 1120 */ 203, 42, 247, 37, 156, 158, 154, 165, 167, 239, + /* 1130 */ 142, 117, 241, 243, 184, 45, 117, 250, 47, 267, + /* 1140 */ 49, 254, 256, 193, 260, 117, 263, 204, 117, 211, + /* 1150 */ 117, 218, 221, 34, 227, 230, 233, 164, 240, 242, + /* 1160 */ 24, 203, 51, 53, 37, 156, 158, 265, 244, 167, + /* 1170 */ 268, 55, 117, 117, 271, 184, 57, 191, 275, 190, + /* 1180 */ 279, 117, 280, 247, 193, 278, 117, 277, 204, 297, + /* 1190 */ 211, 294, 218, 221, 59, 227, 230, 233, 200, 240, + /* 1200 */ 242, 24, 203, 296, 117, 37, 156, 158, 61, 244, + /* 1210 */ 167, 303, 310, 244, 313, 316, 184, 63, 117, 318, + /* 1220 */ 319, 320, 65, 321, 247, 193, 201, 117, 247, 204, + /* 1230 */ 261, 211, 117, 218, 221, 244, 227, 230, 233, 208, + /* 1240 */ 240, 242, 24, 203, 248, 67, 37, 156, 158, 69, + /* 1250 */ 247, 167, 71, 248, 244, 117, 215, 184, 73, 117, + /* 1260 */ 248, 248, 117, 75, 248, 248, 193, 248, 117, 247, + /* 1270 */ 204, 209, 211, 117, 218, 221, 237, 227, 230, 233, + /* 1280 */ 252, 240, 242, 24, 203, 248, 244, 37, 156, 158, + /* 1290 */ 77, 248, 167, 248, 79, 244, 81, 258, 184, 83, + /* 1300 */ 117, 247, 248, 248, 117, 248, 117, 193, 248, 117, + /* 1310 */ 247, 204, 244, 211, 216, 218, 221, 273, 227, 230, + /* 1320 */ 233, 292, 240, 242, 24, 203, 248, 247, 37, 156, + /* 1330 */ 158, 86, 244, 167, 93, 95, 244, 248, 301, 184, + /* 1340 */ 99, 117, 248, 248, 117, 117, 248, 247, 193, 248, + /* 1350 */ 117, 247, 204, 244, 211, 248, 218, 221, 308, 227, + /* 1360 */ 230, 233, 238, 240, 242, 24, 203, 248, 247, 37, + /* 1370 */ 156, 158, 101, 244, 167, 116, 248, 244, 248, 248, + /* 1380 */ 184, 132, 117, 248, 248, 117, 151, 248, 247, 193, + /* 1390 */ 248, 117, 247, 204, 244, 211, 117, 218, 221, 248, + /* 1400 */ 227, 230, 233, 253, 240, 242, 24, 203, 153, 247, + /* 1410 */ 37, 156, 158, 161, 244, 167, 174, 248, 117, 248, + /* 1420 */ 248, 184, 176, 117, 248, 178, 117, 248, 248, 247, + /* 1430 */ 193, 248, 117, 248, 204, 117, 211, 259, 218, 221, + /* 1440 */ 180, 227, 230, 233, 248, 240, 242, 24, 203, 182, + /* 1450 */ 117, 37, 156, 158, 194, 212, 167, 248, 248, 117, + /* 1460 */ 222, 248, 184, 225, 117, 117, 248, 248, 228, 248, + /* 1470 */ 117, 193, 248, 117, 248, 204, 262, 211, 117, 218, + /* 1480 */ 221, 248, 227, 230, 233, 248, 240, 242, 24, 203, + /* 1490 */ 231, 245, 37, 156, 158, 248, 289, 167, 298, 305, + /* 1500 */ 117, 117, 248, 184, 248, 274, 117, 248, 117, 117, + /* 1510 */ 248, 248, 193, 248, 248, 248, 204, 248, 211, 248, + /* 1520 */ 218, 221, 248, 227, 230, 233, 248, 240, 242, 24, + /* 1530 */ 203, 248, 248, 37, 156, 158, 248, 293, 167, 248, + /* 1540 */ 248, 248, 248, 248, 184, 248, 248, 248, 248, 248, + /* 1550 */ 248, 248, 248, 193, 248, 248, 248, 204, 248, 211, + /* 1560 */ 248, 218, 221, 248, 227, 230, 233, 248, 240, 242, + /* 1570 */ 24, 203, 248, 248, 37, 156, 158, 248, 302, 167, + /* 1580 */ 248, 248, 248, 248, 248, 184, 248, 248, 248, 248, + /* 1590 */ 248, 248, 248, 248, 193, 248, 248, 248, 204, 248, + /* 1600 */ 211, 248, 218, 221, 248, 227, 230, 233, 248, 240, + /* 1610 */ 242, 24, 203, 248, 248, 37, 156, 158, 248, 309, + /* 1620 */ 167, 248, 248, 248, 248, 248, 184, 248, 248, 248, + /* 1630 */ 248, 248, 248, 248, 248, 193, 248, 248, 248, 204, + /* 1640 */ 248, 211, 248, 218, 221, 248, 227, 230, 233, 248, + /* 1650 */ 240, 242, 24, 203, 312, 248, 37, 156, 158, 248, + /* 1660 */ 248, 167, 248, 248, 248, 248, 248, 184, 248, 248, + /* 1670 */ 248, 248, 248, 248, 248, 248, 193, 248, 248, 248, + /* 1680 */ 204, 248, 211, 248, 218, 221, 248, 227, 230, 233, + /* 1690 */ 248, 240, 242, 24, 203, 248, 248, 37, 156, 158, + /* 1700 */ 248, 248, 167, 248, 248, 248, 248, 248, 184, 248, + /* 1710 */ 248, 248, 248, 248, 248, 248, 248, 193, 248, 248, + /* 1720 */ 248, 204, 248, 211, 248, 218, 221, 248, 227, 230, + /* 1730 */ 233, 248, 240, 242, 248, 248, 248, 152, 248, 44, + /* 1740 */ 41, 248, 103, 248, 98, 248, 248, 100, 248, 248, + /* 1750 */ 248, 248, 248, 248, 248, 248, 118, 248, 248, 248, + /* 1760 */ 248, 248, 248, 248, 248, 248, 248, 119, 120, 121, + /* 1770 */ 122, 123, 124, 248, 248, 150, 248, 248, 44, 41, + /* 1780 */ 248, 103, 248, 98, 248, 248, 100, 248, 248, 248, + /* 1790 */ 248, 248, 248, 109, 248, 118, 248, 44, 41, 248, + /* 1800 */ 103, 248, 147, 248, 248, 100, 119, 120, 121, 122, + /* 1810 */ 123, 124, 248, 248, 118, 248, 248, 135, 248, 248, + /* 1820 */ 248, 248, 248, 248, 248, 119, 120, 121, 122, 123, + /* 1830 */ 124, 248, 109, 44, 41, 248, 103, 248, 98, 248, + /* 1840 */ 248, 100, 248, 248, 248, 248, 248, 248, 248, 149, + /* 1850 */ 146, 109, 44, 41, 248, 103, 248, 98, 248, 248, + /* 1860 */ 100, 145, 120, 121, 122, 123, 124, 248, 248, 118, + /* 1870 */ 248, 44, 41, 248, 103, 248, 98, 248, 133, 100, + /* 1880 */ 119, 130, 121, 122, 123, 124, 248, 109, 118, 248, + /* 1890 */ 248, 248, 248, 248, 248, 248, 248, 248, 248, 119, + /* 1900 */ 114, 121, 122, 123, 124, 248, 109, 248, 248, 44, + /* 1910 */ 41, 248, 103, 248, 98, 248, 248, 100, 248, 248, + /* 1920 */ 248, 248, 248, 248, 105, 109, 118, 248, 44, 41, + /* 1930 */ 248, 103, 248, 98, 248, 248, 100, 119, 114, 121, + /* 1940 */ 122, 123, 124, 248, 248, 118, 248, 248, 248, 248, + /* 1950 */ 248, 248, 248, 248, 248, 248, 119, 120, 121, 122, + /* 1960 */ 123, 124, 248, 109, 110, 248, 248, 44, 41, 248, + /* 1970 */ 103, 248, 98, 248, 248, 100, 248, 248, 248, 248, + /* 1980 */ 148, 248, 109, 248, 118, 248, 44, 41, 248, 103, + /* 1990 */ 248, 98, 248, 264, 100, 119, 130, 121, 122, 123, + /* 2000 */ 124, 248, 248, 118, 248, 248, 248, 248, 248, 248, + /* 2010 */ 248, 248, 248, 248, 119, 120, 121, 122, 123, 124, + /* 2020 */ 248, 109, 44, 41, 248, 103, 248, 98, 248, 248, + /* 2030 */ 100, 248, 248, 248, 248, 248, 248, 248, 248, 118, + /* 2040 */ 109, 44, 41, 248, 103, 248, 98, 248, 248, 100, + /* 2050 */ 119, 114, 121, 122, 123, 124, 248, 248, 118, 248, + /* 2060 */ 248, 248, 248, 248, 248, 248, 248, 248, 248, 119, + /* 2070 */ 130, 121, 122, 123, 124, 248, 109, 248, 248, 248, + /* 2080 */ 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, + /* 2090 */ 248, 248, 248, 248, 248, 109, +}; +static KKCODETYPE kk_lookahead[] = { + /* 0 */ 3, 4, 1, 6, 7, 8, 9, 10, 11, 12, + /* 10 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + /* 20 */ 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + /* 30 */ 3, 4, 2, 6, 7, 8, 9, 10, 11, 12, + /* 40 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + /* 50 */ 23, 24, 25, 26, 27, 28, 29, 30, 57, 32, + /* 60 */ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + /* 70 */ 28, 29, 30, 72, 2, 3, 49, 47, 102, 103, + /* 80 */ 3, 4, 2, 6, 7, 8, 9, 10, 11, 12, + /* 90 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + /* 100 */ 23, 24, 25, 26, 27, 28, 29, 30, 0, 32, + /* 110 */ 3, 4, 32, 6, 7, 8, 9, 10, 11, 12, + /* 120 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + /* 130 */ 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, + /* 140 */ 3, 4, 65, 6, 7, 8, 9, 10, 11, 12, + /* 150 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + /* 160 */ 23, 24, 25, 26, 27, 28, 29, 30, 32, 32, + /* 170 */ 3, 4, 32, 6, 7, 8, 9, 10, 11, 12, + /* 180 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + /* 190 */ 23, 24, 25, 26, 27, 28, 29, 30, 2, 32, + /* 200 */ 3, 4, 2, 6, 7, 8, 9, 10, 11, 12, + /* 210 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + /* 220 */ 23, 24, 25, 26, 27, 28, 29, 30, 3, 4, + /* 230 */ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + /* 240 */ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + /* 250 */ 25, 26, 27, 28, 29, 30, 21, 22, 23, 24, + /* 260 */ 25, 26, 27, 28, 29, 30, 26, 27, 28, 29, + /* 270 */ 30, 74, 76, 2, 74, 3, 4, 2, 6, 7, + /* 280 */ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + /* 290 */ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + /* 300 */ 28, 29, 30, 24, 25, 26, 27, 28, 29, 30, + /* 310 */ 49, 50, 51, 52, 53, 54, 104, 105, 47, 47, + /* 320 */ 53, 54, 47, 3, 4, 32, 6, 7, 8, 9, + /* 330 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + /* 340 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + /* 350 */ 30, 3, 32, 3, 4, 109, 6, 7, 8, 9, + /* 360 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + /* 370 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + /* 380 */ 30, 5, 32, 3, 4, 74, 6, 7, 8, 9, + /* 390 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + /* 400 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + /* 410 */ 30, 5, 32, 3, 4, 74, 6, 7, 8, 9, + /* 420 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + /* 430 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + /* 440 */ 30, 4, 74, 6, 7, 8, 9, 10, 11, 12, + /* 450 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + /* 460 */ 23, 24, 25, 26, 27, 28, 29, 30, 58, 5, + /* 470 */ 109, 74, 3, 4, 32, 6, 7, 8, 9, 10, + /* 480 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + /* 490 */ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + /* 500 */ 5, 32, 3, 4, 38, 6, 7, 8, 9, 10, + /* 510 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + /* 520 */ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + /* 530 */ 5, 32, 3, 4, 32, 6, 7, 8, 9, 10, + /* 540 */ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, + /* 550 */ 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, + /* 560 */ 3, 4, 38, 6, 7, 8, 9, 10, 11, 12, + /* 570 */ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, + /* 580 */ 23, 24, 25, 26, 27, 28, 29, 30, 6, 7, + /* 590 */ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + /* 600 */ 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, + /* 610 */ 28, 29, 30, 7, 8, 9, 10, 11, 12, 13, + /* 620 */ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, + /* 630 */ 24, 25, 26, 27, 28, 29, 30, 78, 79, 80, + /* 640 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, + /* 650 */ 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, + /* 660 */ 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + /* 670 */ 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, + /* 680 */ 29, 30, 80, 81, 82, 83, 84, 85, 86, 87, + /* 690 */ 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, + /* 700 */ 98, 99, 100, 80, 81, 82, 83, 84, 85, 86, + /* 710 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, + /* 720 */ 97, 98, 99, 100, 80, 81, 82, 83, 84, 85, + /* 730 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + /* 740 */ 96, 97, 98, 99, 100, 80, 81, 82, 83, 84, + /* 750 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, + /* 760 */ 95, 96, 97, 98, 99, 100, 80, 81, 82, 83, + /* 770 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, + /* 780 */ 94, 95, 96, 97, 98, 99, 100, 80, 81, 82, + /* 790 */ 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, + /* 800 */ 93, 94, 95, 96, 97, 98, 99, 100, 80, 81, + /* 810 */ 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, + /* 820 */ 92, 93, 94, 95, 96, 97, 98, 99, 100, 80, + /* 830 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, + /* 840 */ 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, + /* 850 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, + /* 860 */ 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, + /* 870 */ 100, 80, 81, 82, 83, 84, 85, 86, 87, 88, + /* 880 */ 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, + /* 890 */ 99, 100, 80, 81, 82, 83, 84, 85, 86, 87, + /* 900 */ 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, + /* 910 */ 98, 99, 100, 80, 81, 82, 83, 84, 85, 86, + /* 920 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, + /* 930 */ 97, 98, 99, 100, 80, 81, 82, 83, 84, 85, + /* 940 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + /* 950 */ 96, 97, 98, 99, 100, 80, 81, 82, 83, 84, + /* 960 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, + /* 970 */ 95, 96, 97, 98, 99, 100, 81, 82, 83, 84, + /* 980 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, + /* 990 */ 95, 96, 97, 98, 99, 100, 31, 32, 33, 34, + /* 1000 */ 35, 36, 37, 0, 1, 40, 103, 38, 101, 101, + /* 1010 */ 38, 46, 41, 42, 43, 44, 45, 109, 111, 111, + /* 1020 */ 55, 49, 29, 32, 59, 38, 61, 32, 63, 64, + /* 1030 */ 32, 66, 67, 68, 47, 70, 71, 31, 32, 33, + /* 1040 */ 34, 35, 36, 37, 101, 1, 40, 101, 32, 101, + /* 1050 */ 107, 1, 46, 101, 111, 112, 108, 111, 110, 111, + /* 1060 */ 57, 55, 110, 111, 38, 59, 1, 61, 32, 63, + /* 1070 */ 64, 50, 66, 67, 68, 72, 70, 71, 31, 32, + /* 1080 */ 33, 101, 35, 36, 37, 101, 101, 40, 108, 101, + /* 1090 */ 110, 111, 107, 46, 38, 111, 111, 112, 32, 111, + /* 1100 */ 112, 57, 55, 32, 32, 49, 59, 57, 61, 32, + /* 1110 */ 63, 64, 1, 66, 67, 68, 72, 70, 71, 31, + /* 1120 */ 32, 101, 72, 35, 36, 37, 101, 39, 40, 32, + /* 1130 */ 74, 111, 32, 32, 46, 101, 111, 32, 101, 56, + /* 1140 */ 101, 32, 32, 55, 32, 111, 32, 59, 111, 61, + /* 1150 */ 111, 63, 64, 1, 66, 67, 68, 1, 70, 71, + /* 1160 */ 31, 32, 101, 101, 35, 36, 37, 32, 57, 40, + /* 1170 */ 32, 101, 111, 111, 32, 46, 101, 48, 32, 1, + /* 1180 */ 41, 111, 106, 72, 55, 38, 111, 105, 59, 3, + /* 1190 */ 61, 32, 63, 64, 101, 66, 67, 68, 1, 70, + /* 1200 */ 71, 31, 32, 38, 111, 35, 36, 37, 101, 57, + /* 1210 */ 40, 32, 32, 57, 32, 32, 46, 101, 111, 32, + /* 1220 */ 1, 33, 101, 32, 72, 55, 56, 111, 72, 59, + /* 1230 */ 1, 61, 111, 63, 64, 57, 66, 67, 68, 1, + /* 1240 */ 70, 71, 31, 32, 113, 101, 35, 36, 37, 101, + /* 1250 */ 72, 40, 101, 113, 57, 111, 1, 46, 101, 111, + /* 1260 */ 113, 113, 111, 101, 113, 113, 55, 113, 111, 72, + /* 1270 */ 59, 60, 61, 111, 63, 64, 1, 66, 67, 68, + /* 1280 */ 1, 70, 71, 31, 32, 113, 57, 35, 36, 37, + /* 1290 */ 101, 113, 40, 113, 101, 57, 101, 1, 46, 101, + /* 1300 */ 111, 72, 113, 113, 111, 113, 111, 55, 113, 111, + /* 1310 */ 72, 59, 57, 61, 62, 63, 64, 1, 66, 67, + /* 1320 */ 68, 1, 70, 71, 31, 32, 113, 72, 35, 36, + /* 1330 */ 37, 101, 57, 40, 101, 101, 57, 113, 1, 46, + /* 1340 */ 101, 111, 113, 113, 111, 111, 113, 72, 55, 113, + /* 1350 */ 111, 72, 59, 57, 61, 113, 63, 64, 1, 66, + /* 1360 */ 67, 68, 69, 70, 71, 31, 32, 113, 72, 35, + /* 1370 */ 36, 37, 101, 57, 40, 101, 113, 57, 113, 113, + /* 1380 */ 46, 101, 111, 113, 113, 111, 101, 113, 72, 55, + /* 1390 */ 113, 111, 72, 59, 57, 61, 111, 63, 64, 113, + /* 1400 */ 66, 67, 68, 69, 70, 71, 31, 32, 101, 72, + /* 1410 */ 35, 36, 37, 101, 57, 40, 101, 113, 111, 113, + /* 1420 */ 113, 46, 101, 111, 113, 101, 111, 113, 113, 72, + /* 1430 */ 55, 113, 111, 113, 59, 111, 61, 62, 63, 64, + /* 1440 */ 101, 66, 67, 68, 113, 70, 71, 31, 32, 101, + /* 1450 */ 111, 35, 36, 37, 101, 101, 40, 113, 113, 111, + /* 1460 */ 101, 113, 46, 101, 111, 111, 113, 113, 101, 113, + /* 1470 */ 111, 55, 113, 111, 113, 59, 60, 61, 111, 63, + /* 1480 */ 64, 113, 66, 67, 68, 113, 70, 71, 31, 32, + /* 1490 */ 101, 101, 35, 36, 37, 113, 101, 40, 101, 101, + /* 1500 */ 111, 111, 113, 46, 113, 48, 111, 113, 111, 111, + /* 1510 */ 113, 113, 55, 113, 113, 113, 59, 113, 61, 113, + /* 1520 */ 63, 64, 113, 66, 67, 68, 113, 70, 71, 31, + /* 1530 */ 32, 113, 113, 35, 36, 37, 113, 39, 40, 113, + /* 1540 */ 113, 113, 113, 113, 46, 113, 113, 113, 113, 113, + /* 1550 */ 113, 113, 113, 55, 113, 113, 113, 59, 113, 61, + /* 1560 */ 113, 63, 64, 113, 66, 67, 68, 113, 70, 71, + /* 1570 */ 31, 32, 113, 113, 35, 36, 37, 113, 39, 40, + /* 1580 */ 113, 113, 113, 113, 113, 46, 113, 113, 113, 113, + /* 1590 */ 113, 113, 113, 113, 55, 113, 113, 113, 59, 113, + /* 1600 */ 61, 113, 63, 64, 113, 66, 67, 68, 113, 70, + /* 1610 */ 71, 31, 32, 113, 113, 35, 36, 37, 113, 39, + /* 1620 */ 40, 113, 113, 113, 113, 113, 46, 113, 113, 113, + /* 1630 */ 113, 113, 113, 113, 113, 55, 113, 113, 113, 59, + /* 1640 */ 113, 61, 113, 63, 64, 113, 66, 67, 68, 113, + /* 1650 */ 70, 71, 31, 32, 33, 113, 35, 36, 37, 113, + /* 1660 */ 113, 40, 113, 113, 113, 113, 113, 46, 113, 113, + /* 1670 */ 113, 113, 113, 113, 113, 113, 55, 113, 113, 113, + /* 1680 */ 59, 113, 61, 113, 63, 64, 113, 66, 67, 68, + /* 1690 */ 113, 70, 71, 31, 32, 113, 113, 35, 36, 37, + /* 1700 */ 113, 113, 40, 113, 113, 113, 113, 113, 46, 113, + /* 1710 */ 113, 113, 113, 113, 113, 113, 113, 55, 113, 113, + /* 1720 */ 113, 59, 113, 61, 113, 63, 64, 113, 66, 67, + /* 1730 */ 68, 113, 70, 71, 113, 113, 113, 19, 113, 21, + /* 1740 */ 22, 113, 24, 113, 26, 113, 113, 29, 113, 113, + /* 1750 */ 113, 113, 113, 113, 113, 113, 38, 113, 113, 113, + /* 1760 */ 113, 113, 113, 113, 113, 113, 113, 49, 50, 51, + /* 1770 */ 52, 53, 54, 113, 113, 18, 113, 113, 21, 22, + /* 1780 */ 113, 24, 113, 26, 113, 113, 29, 113, 113, 113, + /* 1790 */ 113, 113, 113, 75, 113, 38, 113, 21, 22, 113, + /* 1800 */ 24, 113, 26, 113, 113, 29, 49, 50, 51, 52, + /* 1810 */ 53, 54, 113, 113, 38, 113, 113, 5, 113, 113, + /* 1820 */ 113, 113, 113, 113, 113, 49, 50, 51, 52, 53, + /* 1830 */ 54, 113, 75, 21, 22, 113, 24, 113, 26, 113, + /* 1840 */ 113, 29, 113, 113, 113, 113, 113, 113, 113, 73, + /* 1850 */ 38, 75, 21, 22, 113, 24, 113, 26, 113, 113, + /* 1860 */ 29, 49, 50, 51, 52, 53, 54, 113, 113, 38, + /* 1870 */ 113, 21, 22, 113, 24, 113, 26, 113, 47, 29, + /* 1880 */ 49, 50, 51, 52, 53, 54, 113, 75, 38, 113, + /* 1890 */ 113, 113, 113, 113, 113, 113, 113, 113, 113, 49, + /* 1900 */ 50, 51, 52, 53, 54, 113, 75, 113, 113, 21, + /* 1910 */ 22, 113, 24, 113, 26, 113, 113, 29, 113, 113, + /* 1920 */ 113, 113, 113, 113, 74, 75, 38, 113, 21, 22, + /* 1930 */ 113, 24, 113, 26, 113, 113, 29, 49, 50, 51, + /* 1940 */ 52, 53, 54, 113, 113, 38, 113, 113, 113, 113, + /* 1950 */ 113, 113, 113, 113, 113, 113, 49, 50, 51, 52, + /* 1960 */ 53, 54, 113, 75, 76, 113, 113, 21, 22, 113, + /* 1970 */ 24, 113, 26, 113, 113, 29, 113, 113, 113, 113, + /* 1980 */ 73, 113, 75, 113, 38, 113, 21, 22, 113, 24, + /* 1990 */ 113, 26, 113, 47, 29, 49, 50, 51, 52, 53, + /* 2000 */ 54, 113, 113, 38, 113, 113, 113, 113, 113, 113, + /* 2010 */ 113, 113, 113, 113, 49, 50, 51, 52, 53, 54, + /* 2020 */ 113, 75, 21, 22, 113, 24, 113, 26, 113, 113, + /* 2030 */ 29, 113, 113, 113, 113, 113, 113, 113, 113, 38, + /* 2040 */ 75, 21, 22, 113, 24, 113, 26, 113, 113, 29, + /* 2050 */ 49, 50, 51, 52, 53, 54, 113, 113, 38, 113, + /* 2060 */ 113, 113, 113, 113, 113, 113, 113, 113, 113, 49, + /* 2070 */ 50, 51, 52, 53, 54, 113, 75, 113, 113, 113, + /* 2080 */ 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, + /* 2090 */ 113, 113, 113, 113, 113, 75, +}; +#define KK_SHIFT_USE_DFLT (-4) +static short kk_shift_ofst[] = { + /* 0 */ 1, 108, 1003, -4, -4, -4, -4, -4, -4, -4, + /* 10 */ -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, + /* 20 */ -4, -4, -4, 1662, 1965, 137, 1044, 1050, 965, 136, + /* 30 */ -4, 140, 1111, 1152, 1047, 293, -4, 1965, 167, -4, + /* 40 */ 1965, 1965, 279, 1965, 1965, 279, 1718, 235, 1757, 235, + /* 50 */ 1965, 235, 1965, 651, 1965, 651, 1965, 279, 1965, 240, + /* 60 */ 1965, 606, 1965, 42, 1776, 42, 1965, 42, 1965, 42, + /* 70 */ 1965, 42, 1965, 42, 1965, 42, 1965, 42, 1965, 42, + /* 80 */ 1965, -4, 1965, 437, 348, 1965, 240, -4, -4, 1812, + /* 90 */ 197, -4, 1965, 225, 1965, 582, 1831, 529, 1965, 240, + /* 100 */ 1965, 272, -4, 1850, 529, -4, 200, -4, 2001, 1888, + /* 110 */ -4, 196, -4, -4, 376, 1965, 529, -4, -4, -4, + /* 120 */ -4, -4, -4, -4, -4, -4, 30, -4, 2020, -4, + /* 130 */ 406, 1965, 529, -4, -4, 972, 311, -4, 341, 368, + /* 140 */ 464, 1056, -4, 397, -4, 495, 525, 1907, -4, -4, + /* 150 */ 1965, 235, 1965, 235, 279, 279, 442, -4, 466, 72, + /* 160 */ 1965, -3, 1, 1156, 1088, 502, -4, 524, 80, -4, + /* 170 */ 524, -4, 971, 1965, 529, 1965, 529, 1965, 529, 1965, + /* 180 */ 529, 1965, 529, -4, 969, 993, 987, 991, 1, 1178, + /* 190 */ 1129, 995, -4, 1965, 557, 1946, 271, 998, 1, 1197, + /* 200 */ 1170, 1016, -4, -4, 1026, 1036, 1229, 1238, 1211, 1066, + /* 210 */ -4, 1965, 27, 1, 1255, 1252, 1071, -4, 1021, 1072, + /* 220 */ -4, 1965, 77, -4, 1965, 320, -4, 1965, 350, -4, + /* 230 */ 1965, 380, -4, 267, 1077, 1, 1275, 1293, 1097, -4, + /* 240 */ 1100, -4, 1101, -4, 1965, 410, -4, -4, -4, 1105, + /* 250 */ 1, 1279, 1334, 1109, -4, 1110, 1, 1296, 1375, 1112, + /* 260 */ -4, 1416, 1114, -4, 1135, 1065, 1083, 1138, -4, 275, + /* 270 */ 1142, 1, 1316, 1457, 1146, -4, 1147, -4, 1139, 261, + /* 280 */ -4, -4, -4, -4, -4, -4, -4, -4, 1965, 469, + /* 290 */ 1, 1320, 1498, 1159, -4, 1165, 1186, 1965, 107, 1, + /* 300 */ 1337, 1539, 1179, -4, 1965, 499, 1, 1357, 1580, 1180, + /* 310 */ -4, 1621, 1182, -4, 1006, 1183, -4, 1187, 1219, 1188, + /* 320 */ 1191, -4, +}; +#define KK_REDUCE_USE_DFLT (-25) +static short kk_reduce_ofst[] = { + /* 0 */ 559, -25, 895, -25, -25, -25, -25, -25, -25, -25, + /* 10 */ -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, + /* 20 */ -25, -25, -25, -25, 907, -25, 602, 895, -25, -25, + /* 30 */ -25, -25, 623, 895, -25, -25, -25, 946, -25, -25, + /* 40 */ 984, 1020, -25, 1025, 1034, -25, 1037, -25, 1039, -25, + /* 50 */ 1061, -25, 1062, -25, 1070, -25, 1075, -25, 1093, -25, + /* 60 */ 1107, -25, 1116, -25, 1121, -25, 1144, -25, 1148, -25, + /* 70 */ 1151, -25, 1157, -25, 1162, -25, 1189, -25, 1193, -25, + /* 80 */ 1195, -25, 1198, -25, -25, 1230, -25, -25, -25, 908, + /* 90 */ -25, -25, 1233, -25, 1234, -25, 943, -25, 1239, -25, + /* 100 */ 1271, -25, -25, 948, -25, -25, -25, -25, 952, 980, + /* 110 */ -25, -25, -25, -25, -25, 1274, -25, -25, -25, -25, + /* 120 */ -25, -25, -25, -25, -25, -25, -25, -25, 988, -25, + /* 130 */ -25, 1280, -25, -25, -25, 246, -25, -25, -25, -25, + /* 140 */ -25, 361, -25, -25, -25, -25, -25, 1239, -25, -25, + /* 150 */ 1285, -25, 1307, -25, -25, -25, -25, -25, -25, -25, + /* 160 */ 1312, -25, 644, 895, -25, -25, -25, -24, -25, -25, + /* 170 */ 903, -25, -25, 1315, -25, 1321, -25, 1324, -25, 1339, + /* 180 */ -25, 1348, -25, -25, -25, -25, 212, -25, 665, 895, + /* 190 */ -25, -25, -25, 1353, -25, 985, -25, -25, 686, 895, + /* 200 */ -25, -25, -25, -25, -25, -25, 707, 895, -25, -25, + /* 210 */ -25, 1354, -25, 728, 895, -25, -25, -25, -25, -25, + /* 220 */ -25, 1359, -25, -25, 1362, -25, -25, 1367, -25, -25, + /* 230 */ 1389, -25, -25, -25, -25, 749, 895, -25, -25, -25, + /* 240 */ -25, -25, -25, -25, 1390, -25, -25, -25, -25, -25, + /* 250 */ 770, 895, -25, -25, -25, -25, 791, 895, -25, -25, + /* 260 */ -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, + /* 270 */ -25, 812, 895, -25, -25, -25, 1082, -25, -25, 1076, + /* 280 */ -25, -25, -25, -25, -25, -25, -25, -25, 1395, -25, + /* 290 */ 833, 895, -25, -25, -25, -25, -25, 1397, -25, 854, + /* 300 */ 895, -25, -25, -25, 1398, -25, 875, 895, -25, -25, + /* 310 */ -25, -25, -25, -25, -25, -25, -25, -25, -25, -25, + /* 320 */ -25, -25, +}; +static KKACTIONTYPE kk_default[] = { + /* 0 */ 455, 455, 455, 324, 326, 327, 328, 329, 330, 331, + /* 10 */ 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, + /* 20 */ 342, 343, 344, 455, 455, 455, 455, 455, 455, 455, + /* 30 */ 345, 455, 455, 455, 455, 455, 347, 455, 455, 350, + /* 40 */ 455, 455, 394, 455, 455, 395, 455, 398, 455, 400, + /* 50 */ 455, 402, 455, 403, 455, 404, 455, 405, 455, 406, + /* 60 */ 455, 407, 455, 408, 455, 411, 455, 412, 455, 413, + /* 70 */ 455, 414, 455, 415, 455, 416, 455, 417, 455, 418, + /* 80 */ 455, 419, 455, 420, 455, 455, 421, 423, 424, 455, + /* 90 */ 455, 430, 455, 455, 455, 431, 455, 446, 455, 422, + /* 100 */ 455, 455, 425, 455, 440, 426, 455, 427, 455, 455, + /* 110 */ 428, 455, 429, 438, 450, 455, 439, 441, 448, 449, + /* 120 */ 450, 451, 452, 453, 454, 437, 455, 442, 455, 444, + /* 130 */ 450, 455, 447, 443, 445, 455, 455, 432, 455, 455, + /* 140 */ 455, 455, 433, 455, 434, 449, 448, 455, 409, 410, + /* 150 */ 455, 401, 455, 399, 397, 396, 455, 351, 455, 455, + /* 160 */ 455, 455, 455, 455, 455, 455, 352, 455, 455, 356, + /* 170 */ 455, 357, 455, 455, 359, 455, 360, 455, 361, 455, + /* 180 */ 362, 455, 363, 358, 455, 455, 455, 455, 455, 455, + /* 190 */ 455, 455, 364, 455, 455, 455, 455, 442, 455, 455, + /* 200 */ 455, 455, 376, 378, 455, 455, 455, 455, 455, 455, + /* 210 */ 380, 455, 455, 455, 455, 455, 455, 382, 455, 455, + /* 220 */ 384, 455, 455, 385, 455, 455, 386, 455, 455, 387, + /* 230 */ 455, 455, 388, 455, 455, 455, 455, 455, 455, 389, + /* 240 */ 455, 391, 455, 392, 455, 455, 379, 393, 325, 455, + /* 250 */ 455, 455, 455, 455, 390, 455, 455, 455, 455, 455, + /* 260 */ 383, 455, 455, 381, 443, 455, 455, 455, 377, 455, + /* 270 */ 455, 455, 455, 455, 455, 365, 455, 366, 368, 455, + /* 280 */ 369, 370, 371, 372, 373, 374, 375, 367, 455, 455, + /* 290 */ 455, 455, 455, 455, 353, 455, 455, 455, 455, 455, + /* 300 */ 455, 455, 455, 354, 455, 455, 455, 455, 455, 455, + /* 310 */ 355, 455, 455, 348, 455, 455, 346, 455, 455, 455, + /* 320 */ 455, 349, +}; +#define KK_SZ_ACTTAB (sizeof(kk_action)/sizeof(kk_action[0])) + +/* The next table maps tokens into fallback tokens. If a construct +** like the following: +** +** %fallback ID X Y Z. +** +** appears in the grammer, then ID becomes a fallback token for X, Y, +** and Z. Whenever one of the tokens X, Y, or Z is input to the parser +** but it does not parse, the type of the token is changed to ID and +** the parse is retried before an error is thrown. +*/ +#ifdef KKFALLBACK +static const KKCODETYPE kkFallback[] = { +}; +#endif /* KKFALLBACK */ + +/* The following structure represents a single element of the +** parser's stack. Information stored includes: +** +** + The state number for the parser at this level of the stack. +** +** + The value of the token stored at this level of the stack. +** (In other words, the "major" token.) +** +** + The semantic value stored at this level of the stack. This is +** the information used by the action routines in the grammar. +** It is sometimes called the "minor" token. +*/ +struct kkStackEntry { + int stateno; /* The state-number */ + int major; /* The major token value. This is the code + ** number for the token at this stack level */ + KKMINORTYPE minor; /* The user-supplied minor token value. This + ** is the value of the token */ +}; +typedef struct kkStackEntry kkStackEntry; + +/* The state of the parser is completely contained in an instance of +** the following structure */ +struct kkParser { + int kkidx; /* Index of top element in stack */ + int kkerrcnt; /* Shifts left before out of the error */ + phvolt_ARG_SDECL /* A place to hold %extra_argument */ + kkStackEntry kkstack[KKSTACKDEPTH]; /* The parser's stack */ +}; +typedef struct kkParser kkParser; + +#ifndef NDEBUG +#include +static FILE *kkTraceFILE = 0; +static char *kkTracePrompt = 0; +#endif /* NDEBUG */ - RETURN_MEMBER_QUICK(this_ptr, "_operationMade", 3968152972UL); +#ifndef NDEBUG +static void phvolt_Trace(FILE *TraceFILE, char *zTracePrompt){ + kkTraceFILE = TraceFILE; + kkTracePrompt = zTracePrompt; + if( kkTraceFILE==0 ) kkTracePrompt = 0; + else if( kkTracePrompt==0 ) kkTraceFILE = 0; } +#endif /* NDEBUG */ -static PHP_METHOD(Phalcon_Mvc_Model, refresh){ +#ifndef NDEBUG +/* For tracing shifts, the names of all terminals and nonterminals +** are required. The following table supplies these names */ +static const char *kkTokenName[] = { + "$", "OPEN_DELIMITER", "COMMA", "IN", + "QUESTION", "COLON", "RANGE", "AND", + "OR", "IS", "EQUALS", "NOTEQUALS", + "LESS", "GREATER", "GREATEREQUAL", "LESSEQUAL", + "IDENTICAL", "NOTIDENTICAL", "DIVIDE", "TIMES", + "MOD", "PLUS", "MINUS", "CONCAT", + "SBRACKET_OPEN", "PIPE", "NOT", "INCR", + "DECR", "PARENTHESES_OPEN", "DOT", "IF", + "CLOSE_DELIMITER", "ENDIF", "ELSE", "ELSEIF", + "ELSEFOR", "FOR", "IDENTIFIER", "ENDFOR", + "SET", "ASSIGN", "ADD_ASSIGN", "SUB_ASSIGN", + "MUL_ASSIGN", "DIV_ASSIGN", "MACRO", "PARENTHESES_CLOSE", + "ENDMACRO", "INTEGER", "STRING", "DOUBLE", + "NULL", "FALSE", "TRUE", "CALL", + "ENDCALL", "OPEN_EDELIMITER", "CLOSE_EDELIMITER", "BLOCK", + "ENDBLOCK", "CACHE", "ENDCACHE", "EXTENDS", + "INCLUDE", "WITH", "DO", "RETURN", + "AUTOESCAPE", "ENDAUTOESCAPE", "BREAK", "CONTINUE", + "RAW_FRAGMENT", "DEFINED", "SBRACKET_CLOSE", "CBRACKET_OPEN", + "CBRACKET_CLOSE", "error", "program", "volt_language", + "statement_list", "statement", "raw_fragment", "if_statement", + "elseif_statement", "elsefor_statement", "for_statement", "set_statement", + "echo_statement", "block_statement", "cache_statement", "extends_statement", + "include_statement", "do_statement", "return_statement", "autoescape_statement", + "break_statement", "continue_statement", "macro_statement", "empty_statement", + "macro_call_statement", "expr", "set_assignments", "set_assignment", + "macro_parameters", "macro_parameter", "macro_parameter_default", "argument_list", + "array_list", "slice_offset", "array_item", "function_call", + "argument_item", +}; +#endif /* NDEBUG */ - zval *dirty_state, *meta_data, *read_connection; - zval *schema, *source, *table = NULL, *unique_key = NULL, *exists; - zval *unique_params, *unique_types, *attributes; - zval *fields, *attribute = NULL, *field_item = NULL, *escaped_table; - zval *select, *dialect, *sql, *fetch_type, *row, *column_map; - HashTable *ah0; - HashPosition hp0; - zval **hd; +#ifndef NDEBUG +/* For tracing reduce actions, the names of all rules are required. +*/ +static const char *kkRuleName[] = { + /* 0 */ "program ::= volt_language", + /* 1 */ "volt_language ::= statement_list", + /* 2 */ "statement_list ::= statement_list statement", + /* 3 */ "statement_list ::= statement", + /* 4 */ "statement ::= raw_fragment", + /* 5 */ "statement ::= if_statement", + /* 6 */ "statement ::= elseif_statement", + /* 7 */ "statement ::= elsefor_statement", + /* 8 */ "statement ::= for_statement", + /* 9 */ "statement ::= set_statement", + /* 10 */ "statement ::= echo_statement", + /* 11 */ "statement ::= block_statement", + /* 12 */ "statement ::= cache_statement", + /* 13 */ "statement ::= extends_statement", + /* 14 */ "statement ::= include_statement", + /* 15 */ "statement ::= do_statement", + /* 16 */ "statement ::= return_statement", + /* 17 */ "statement ::= autoescape_statement", + /* 18 */ "statement ::= break_statement", + /* 19 */ "statement ::= continue_statement", + /* 20 */ "statement ::= macro_statement", + /* 21 */ "statement ::= empty_statement", + /* 22 */ "statement ::= macro_call_statement", + /* 23 */ "if_statement ::= OPEN_DELIMITER IF expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDIF CLOSE_DELIMITER", + /* 24 */ "if_statement ::= OPEN_DELIMITER IF expr CLOSE_DELIMITER OPEN_DELIMITER ENDIF CLOSE_DELIMITER", + /* 25 */ "if_statement ::= OPEN_DELIMITER IF expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ELSE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDIF CLOSE_DELIMITER", + /* 26 */ "if_statement ::= OPEN_DELIMITER IF expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ELSE CLOSE_DELIMITER OPEN_DELIMITER ENDIF CLOSE_DELIMITER", + /* 27 */ "if_statement ::= OPEN_DELIMITER IF expr CLOSE_DELIMITER OPEN_DELIMITER ELSE CLOSE_DELIMITER OPEN_DELIMITER ENDIF CLOSE_DELIMITER", + /* 28 */ "elseif_statement ::= OPEN_DELIMITER ELSEIF expr CLOSE_DELIMITER", + /* 29 */ "elsefor_statement ::= OPEN_DELIMITER ELSEFOR CLOSE_DELIMITER", + /* 30 */ "for_statement ::= OPEN_DELIMITER FOR IDENTIFIER IN expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDFOR CLOSE_DELIMITER", + /* 31 */ "for_statement ::= OPEN_DELIMITER FOR IDENTIFIER IN expr IF expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDFOR CLOSE_DELIMITER", + /* 32 */ "for_statement ::= OPEN_DELIMITER FOR IDENTIFIER COMMA IDENTIFIER IN expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDFOR CLOSE_DELIMITER", + /* 33 */ "for_statement ::= OPEN_DELIMITER FOR IDENTIFIER COMMA IDENTIFIER IN expr IF expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDFOR CLOSE_DELIMITER", + /* 34 */ "set_statement ::= OPEN_DELIMITER SET set_assignments CLOSE_DELIMITER", + /* 35 */ "set_assignments ::= set_assignments COMMA set_assignment", + /* 36 */ "set_assignments ::= set_assignment", + /* 37 */ "set_assignment ::= IDENTIFIER ASSIGN expr", + /* 38 */ "set_assignment ::= IDENTIFIER ADD_ASSIGN expr", + /* 39 */ "set_assignment ::= IDENTIFIER SUB_ASSIGN expr", + /* 40 */ "set_assignment ::= IDENTIFIER MUL_ASSIGN expr", + /* 41 */ "set_assignment ::= IDENTIFIER DIV_ASSIGN expr", + /* 42 */ "macro_statement ::= OPEN_DELIMITER MACRO IDENTIFIER PARENTHESES_OPEN PARENTHESES_CLOSE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDMACRO CLOSE_DELIMITER", + /* 43 */ "macro_statement ::= OPEN_DELIMITER MACRO IDENTIFIER PARENTHESES_OPEN macro_parameters PARENTHESES_CLOSE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDMACRO CLOSE_DELIMITER", + /* 44 */ "macro_parameters ::= macro_parameters COMMA macro_parameter", + /* 45 */ "macro_parameters ::= macro_parameter", + /* 46 */ "macro_parameter ::= IDENTIFIER", + /* 47 */ "macro_parameter ::= IDENTIFIER ASSIGN macro_parameter_default", + /* 48 */ "macro_parameter_default ::= INTEGER", + /* 49 */ "macro_parameter_default ::= STRING", + /* 50 */ "macro_parameter_default ::= DOUBLE", + /* 51 */ "macro_parameter_default ::= NULL", + /* 52 */ "macro_parameter_default ::= FALSE", + /* 53 */ "macro_parameter_default ::= TRUE", + /* 54 */ "macro_call_statement ::= OPEN_DELIMITER CALL expr PARENTHESES_OPEN argument_list PARENTHESES_CLOSE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDCALL CLOSE_DELIMITER", + /* 55 */ "macro_call_statement ::= OPEN_DELIMITER CALL expr PARENTHESES_OPEN PARENTHESES_CLOSE CLOSE_DELIMITER OPEN_DELIMITER ENDCALL CLOSE_DELIMITER", + /* 56 */ "empty_statement ::= OPEN_DELIMITER CLOSE_DELIMITER", + /* 57 */ "echo_statement ::= OPEN_EDELIMITER expr CLOSE_EDELIMITER", + /* 58 */ "block_statement ::= OPEN_DELIMITER BLOCK IDENTIFIER CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDBLOCK CLOSE_DELIMITER", + /* 59 */ "block_statement ::= OPEN_DELIMITER BLOCK IDENTIFIER CLOSE_DELIMITER OPEN_DELIMITER ENDBLOCK CLOSE_DELIMITER", + /* 60 */ "cache_statement ::= OPEN_DELIMITER CACHE expr CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDCACHE CLOSE_DELIMITER", + /* 61 */ "cache_statement ::= OPEN_DELIMITER CACHE expr INTEGER CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDCACHE CLOSE_DELIMITER", + /* 62 */ "extends_statement ::= OPEN_DELIMITER EXTENDS STRING CLOSE_DELIMITER", + /* 63 */ "include_statement ::= OPEN_DELIMITER INCLUDE expr CLOSE_DELIMITER", + /* 64 */ "include_statement ::= OPEN_DELIMITER INCLUDE expr WITH expr CLOSE_DELIMITER", + /* 65 */ "do_statement ::= OPEN_DELIMITER DO expr CLOSE_DELIMITER", + /* 66 */ "return_statement ::= OPEN_DELIMITER RETURN expr CLOSE_DELIMITER", + /* 67 */ "autoescape_statement ::= OPEN_DELIMITER AUTOESCAPE FALSE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDAUTOESCAPE CLOSE_DELIMITER", + /* 68 */ "autoescape_statement ::= OPEN_DELIMITER AUTOESCAPE TRUE CLOSE_DELIMITER statement_list OPEN_DELIMITER ENDAUTOESCAPE CLOSE_DELIMITER", + /* 69 */ "break_statement ::= OPEN_DELIMITER BREAK CLOSE_DELIMITER", + /* 70 */ "continue_statement ::= OPEN_DELIMITER CONTINUE CLOSE_DELIMITER", + /* 71 */ "raw_fragment ::= RAW_FRAGMENT", + /* 72 */ "expr ::= MINUS expr", + /* 73 */ "expr ::= PLUS expr", + /* 74 */ "expr ::= expr MINUS expr", + /* 75 */ "expr ::= expr PLUS expr", + /* 76 */ "expr ::= expr TIMES expr", + /* 77 */ "expr ::= expr TIMES TIMES expr", + /* 78 */ "expr ::= expr DIVIDE expr", + /* 79 */ "expr ::= expr DIVIDE DIVIDE expr", + /* 80 */ "expr ::= expr MOD expr", + /* 81 */ "expr ::= expr AND expr", + /* 82 */ "expr ::= expr OR expr", + /* 83 */ "expr ::= expr CONCAT expr", + /* 84 */ "expr ::= expr PIPE expr", + /* 85 */ "expr ::= expr RANGE expr", + /* 86 */ "expr ::= expr EQUALS expr", + /* 87 */ "expr ::= expr IS NOT DEFINED", + /* 88 */ "expr ::= expr IS DEFINED", + /* 89 */ "expr ::= expr IS expr", + /* 90 */ "expr ::= expr NOTEQUALS expr", + /* 91 */ "expr ::= expr IDENTICAL expr", + /* 92 */ "expr ::= expr NOTIDENTICAL expr", + /* 93 */ "expr ::= expr LESS expr", + /* 94 */ "expr ::= expr GREATER expr", + /* 95 */ "expr ::= expr GREATEREQUAL expr", + /* 96 */ "expr ::= expr LESSEQUAL expr", + /* 97 */ "expr ::= expr DOT expr", + /* 98 */ "expr ::= expr IN expr", + /* 99 */ "expr ::= expr NOT IN expr", + /* 100 */ "expr ::= NOT expr", + /* 101 */ "expr ::= expr INCR", + /* 102 */ "expr ::= expr DECR", + /* 103 */ "expr ::= PARENTHESES_OPEN expr PARENTHESES_CLOSE", + /* 104 */ "expr ::= SBRACKET_OPEN SBRACKET_CLOSE", + /* 105 */ "expr ::= SBRACKET_OPEN array_list SBRACKET_CLOSE", + /* 106 */ "expr ::= CBRACKET_OPEN CBRACKET_CLOSE", + /* 107 */ "expr ::= CBRACKET_OPEN array_list CBRACKET_CLOSE", + /* 108 */ "expr ::= expr SBRACKET_OPEN expr SBRACKET_CLOSE", + /* 109 */ "expr ::= expr QUESTION expr COLON expr", + /* 110 */ "expr ::= expr SBRACKET_OPEN COLON slice_offset SBRACKET_CLOSE", + /* 111 */ "expr ::= expr SBRACKET_OPEN slice_offset COLON SBRACKET_CLOSE", + /* 112 */ "expr ::= expr SBRACKET_OPEN slice_offset COLON slice_offset SBRACKET_CLOSE", + /* 113 */ "slice_offset ::= INTEGER", + /* 114 */ "slice_offset ::= IDENTIFIER", + /* 115 */ "array_list ::= array_list COMMA array_item", + /* 116 */ "array_list ::= array_item", + /* 117 */ "array_item ::= STRING COLON expr", + /* 118 */ "array_item ::= expr", + /* 119 */ "expr ::= function_call", + /* 120 */ "function_call ::= expr PARENTHESES_OPEN argument_list PARENTHESES_CLOSE", + /* 121 */ "function_call ::= expr PARENTHESES_OPEN PARENTHESES_CLOSE", + /* 122 */ "argument_list ::= argument_list COMMA argument_item", + /* 123 */ "argument_list ::= argument_item", + /* 124 */ "argument_item ::= expr", + /* 125 */ "argument_item ::= STRING COLON expr", + /* 126 */ "expr ::= IDENTIFIER", + /* 127 */ "expr ::= INTEGER", + /* 128 */ "expr ::= STRING", + /* 129 */ "expr ::= DOUBLE", + /* 130 */ "expr ::= NULL", + /* 131 */ "expr ::= FALSE", + /* 132 */ "expr ::= TRUE", +}; +#endif /* NDEBUG */ - PHALCON_MM_GROW(); +const char *phvolt_TokenName(int tokenType){ +#ifndef NDEBUG + if( tokenType>0 && tokenType<(sizeof(kkTokenName)/sizeof(kkTokenName[0])) ){ + return kkTokenName[tokenType]; + }else{ + return "Unknown"; + } +#else + return ""; +#endif +} - PHALCON_OBS_VAR(dirty_state); - phalcon_read_property_this_quick(&dirty_state, this_ptr, SL("_dirtyState"), 1560981745UL, PH_NOISY_CC); - if (!PHALCON_IS_LONG(dirty_state, 0)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The record cannot be refreshed because it does not exist or is deleted"); - return; - } - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - - PHALCON_INIT_VAR(read_connection); - phalcon_call_method_key(read_connection, this_ptr, "getreadconnection", 488334257UL); - - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, this_ptr, "getschema", 1539736246UL); - - PHALCON_INIT_VAR(source); - phalcon_call_method_key(source, this_ptr, "getsource", 2025234358UL); - if (zend_is_true(schema)) { - PHALCON_INIT_VAR(table); - array_init_size(table, 2); - phalcon_array_append(&table, schema, PH_SEPARATE); - phalcon_array_append(&table, source, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(table, source); - } - - PHALCON_OBS_VAR(unique_key); - phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); - if (!zend_is_true(unique_key)) { - - PHALCON_INIT_VAR(exists); - phalcon_call_method_p3_key(exists, this_ptr, "_exists", meta_data, read_connection, table, 2792580580UL); - if (!zend_is_true(exists)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The record cannot be refreshed because it does not exist or is deleted"); - return; - } - - PHALCON_OBS_NVAR(unique_key); - phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); - } - - PHALCON_OBS_VAR(unique_params); - phalcon_read_property_this_quick(&unique_params, this_ptr, SL("_uniqueParams"), 1065564063UL, PH_NOISY_CC); - if (Z_TYPE_P(unique_params) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The record cannot be refreshed because it does not exist or is deleted"); - return; - } - - PHALCON_OBS_VAR(unique_types); - phalcon_read_property_this_quick(&unique_types, this_ptr, SL("_uniqueTypes"), 3340838640UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); - - PHALCON_INIT_VAR(fields); - array_init(fields); - - phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(attribute); - - PHALCON_INIT_NVAR(field_item); - array_init_size(field_item, 1); - phalcon_array_append(&field_item, attribute, PH_SEPARATE); - phalcon_array_append(&fields, field_item, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(escaped_table); - phalcon_call_method_p1_key(escaped_table, read_connection, "escapeidentifier", table, 585773337UL); - - PHALCON_INIT_VAR(select); - array_init(select); - phalcon_array_update_quick_string(&select, SS("columns"), 1041822630UL, &fields, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&select, SS("tables"), 3465666720UL, &escaped_table, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&select, SS("where"), 621293632UL, &unique_key, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(dialect); - phalcon_call_method_key(dialect, read_connection, "getdialect", 3133083739UL); - - PHALCON_INIT_VAR(sql); - phalcon_call_method_p1_key(sql, dialect, "select", select, 2342345829UL); - - PHALCON_INIT_VAR(fetch_type); - ZVAL_LONG(fetch_type, 1); - - PHALCON_INIT_VAR(row); - phalcon_call_method_p4_key(row, read_connection, "fetchone", sql, fetch_type, unique_params, unique_types, 1637187313UL); - - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); - - if (Z_TYPE_P(row) == IS_ARRAY) { - phalcon_call_method_p2_key(NULL, this_ptr, "assign", row, column_map, 1127103722UL); +void *phvolt_Alloc(void *(*mallocProc)(size_t)){ + kkParser *pParser; + pParser = (kkParser*)(*mallocProc)( (size_t)sizeof(kkParser) ); + if( pParser ){ + pParser->kkidx = -1; + } + return pParser; +} + +/* The following function deletes the value associated with a +** symbol. The symbol can be either a terminal or nonterminal. +** "kkmajor" is the symbol code, and "kkpminor" is a pointer to +** the value. +*/ +static void kk_destructor(KKCODETYPE kkmajor, KKMINORTYPE *kkpminor){ + switch( kkmajor ){ + /* Here is inserted the actions which take place when a + ** terminal or non-terminal is destroyed. This can happen + ** when the symbol is popped from the stack during a + ** reduce or during error processing or when a parser is + ** being destroyed before it is finished parsing. + ** + ** Note: during a reduce, the only symbols destroyed are those + ** which appear on the RHS of the rule, but which are not used + ** inside the C code. + */ + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 26: + case 27: + case 28: + case 29: + case 30: + case 31: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + case 38: + case 39: + case 40: + case 41: + case 42: + case 43: + case 44: + case 45: + case 46: + case 47: + case 48: + case 49: + case 50: + case 51: + case 52: + case 53: + case 54: + case 55: + case 56: + case 57: + case 58: + case 59: + case 60: + case 61: + case 62: + case 63: + case 64: + case 65: + case 66: + case 67: + case 68: + case 69: + case 70: + case 71: + case 72: + case 73: + case 74: + case 75: + case 76: +// 703 "parser.lemon" +{ + if ((kkpminor->kk0)) { + if ((kkpminor->kk0)->free_flag) { + efree((kkpminor->kk0)->token); + } + efree((kkpminor->kk0)); } - - PHALCON_MM_RESTORE(); } - -static PHP_METHOD(Phalcon_Mvc_Model, skipOperation){ - - zval *skip; - - phalcon_fetch_params(0, 1, 0, &skip); - - phalcon_update_property_this_quick(this_ptr, SL("_skipped"), skip, 2005665588UL TSRMLS_CC); - +// 1615 "parser.c" + break; + case 80: + case 81: + case 82: + case 83: + case 84: + case 85: + case 86: + case 87: + case 88: + case 89: + case 90: + case 91: + case 92: + case 93: + case 94: + case 95: + case 96: + case 97: + case 98: + case 99: + case 100: + case 101: + case 102: + case 103: + case 104: + case 105: + case 107: + case 108: + case 109: + case 110: + case 111: + case 112: +// 720 "parser.lemon" +{ zval_ptr_dtor(&(kkpminor->kk132)); } +// 1651 "parser.c" + break; + default: break; /* If no destructor action specified: do nothing */ + } } -static PHP_METHOD(Phalcon_Mvc_Model, readAttribute){ - - zval *attribute, *attribute_value; - - PHALCON_MM_GROW(); +static int kk_pop_parser_stack(kkParser *pParser){ + KKCODETYPE kkmajor; + kkStackEntry *kktos = &pParser->kkstack[pParser->kkidx]; - 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_CC); - RETURN_CCTOR(attribute_value); - } - RETURN_MM_NULL(); + if( pParser->kkidx<0 ) return 0; +#ifndef NDEBUG + if( kkTraceFILE && pParser->kkidx>=0 ){ + fprintf(kkTraceFILE,"%sPopping %s\n", + kkTracePrompt, + kkTokenName[kktos->major]); + } +#endif + kkmajor = kktos->major; + kk_destructor( kkmajor, &kktos->minor); + pParser->kkidx--; + return kkmajor; } -static PHP_METHOD(Phalcon_Mvc_Model, writeAttribute){ - - zval *attribute, *value; - - phalcon_fetch_params(0, 2, 0, &attribute, &value); - - phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - +static void phvolt_Free( + void *p, /* The parser to be deleted */ + void (*freeProc)(void*) /* Function used to reclaim memory */ +){ + kkParser *pParser = (kkParser*)p; + if( pParser==0 ) return; + while( pParser->kkidx>=0 ) kk_pop_parser_stack(pParser); + (*freeProc)((void*)pParser); } -static PHP_METHOD(Phalcon_Mvc_Model, skipAttributes){ - - zval *attributes, *null_value, *keys_attributes; - zval *attribute = NULL, *meta_data; - HashTable *ah0; - HashPosition hp0; - zval **hd; +static int kk_find_shift_action( + kkParser *pParser, /* The parser */ + int iLookAhead /* The look-ahead token */ +){ + int i; + int stateno = pParser->kkstack[pParser->kkidx].stateno; + + /* if( pParser->kkidx<0 ) return KK_NO_ACTION; */ + i = kk_shift_ofst[stateno]; + if( i==KK_SHIFT_USE_DFLT ){ + return kk_default[stateno]; + } + if( iLookAhead==KKNOCODE ){ + return KK_NO_ACTION; + } + i += iLookAhead; + if( i<0 || i>=KK_SZ_ACTTAB || kk_lookahead[i]!=iLookAhead ){ +#ifdef KKFALLBACK + int iFallback; /* Fallback token */ + if( iLookAhead %s\n", + kkTracePrompt, kkTokenName[iLookAhead], kkTokenName[iFallback]); + } +#endif + return kk_find_shift_action(pParser, iFallback); + } +#endif + return kk_default[stateno]; + }else{ + return kk_action[i]; + } +} - PHALCON_MM_GROW(); +static int kk_find_reduce_action( + kkParser *pParser, /* The parser */ + int iLookAhead /* The look-ahead token */ +){ + int i; + int stateno = pParser->kkstack[pParser->kkidx].stateno; + + i = kk_reduce_ofst[stateno]; + if( i==KK_REDUCE_USE_DFLT ){ + return kk_default[stateno]; + } + if( iLookAhead==KKNOCODE ){ + return KK_NO_ACTION; + } + i += iLookAhead; + if( i<0 || i>=KK_SZ_ACTTAB || kk_lookahead[i]!=iLookAhead ){ + return kk_default[stateno]; + }else{ + return kk_action[i]; + } +} - phalcon_fetch_params(1, 1, 0, &attributes); - - if (Z_TYPE_P(attributes) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Attributes must be an array"); - return; - } - - PHALCON_INIT_VAR(null_value); - - PHALCON_INIT_VAR(keys_attributes); - array_init(keys_attributes); - - phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(attribute); - - phalcon_array_update_zval(&keys_attributes, attribute, &null_value, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - phalcon_call_method_p2_key(NULL, meta_data, "setautomaticcreateattributes", this_ptr, keys_attributes, 316109587UL); - phalcon_call_method_p2_key(NULL, meta_data, "setautomaticupdateattributes", this_ptr, keys_attributes, 2859965858UL); - - PHALCON_MM_RESTORE(); +static void kk_shift( + kkParser *kkpParser, /* The parser to be shifted */ + int kkNewState, /* The new state to shift in */ + int kkMajor, /* The major token to shift in */ + KKMINORTYPE *kkpMinor /* Pointer ot the minor token to shift in */ +){ + kkStackEntry *kktos; + kkpParser->kkidx++; + if( kkpParser->kkidx>=KKSTACKDEPTH ){ + phvolt_ARG_FETCH; + kkpParser->kkidx--; +#ifndef NDEBUG + if( kkTraceFILE ){ + fprintf(kkTraceFILE,"%sStack Overflow!\n",kkTracePrompt); + } +#endif + while( kkpParser->kkidx>=0 ) kk_pop_parser_stack(kkpParser); + /* Here code is inserted which will execute if the parser + ** stack every overflows */ + phvolt_ARG_STORE; /* Suppress warning about unused %extra_argument var */ + return; + } + kktos = &kkpParser->kkstack[kkpParser->kkidx]; + kktos->stateno = kkNewState; + kktos->major = kkMajor; + kktos->minor = *kkpMinor; +#ifndef NDEBUG + if( kkTraceFILE && kkpParser->kkidx>0 ){ + int i; + fprintf(kkTraceFILE,"%sShift %d\n",kkTracePrompt,kkNewState); + fprintf(kkTraceFILE,"%sStack:",kkTracePrompt); + for(i=1; i<=kkpParser->kkidx; i++) + fprintf(kkTraceFILE," %s",kkTokenName[kkpParser->kkstack[i].major]); + fprintf(kkTraceFILE,"\n"); + } +#endif } -static PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnCreate){ +/* The following table contains information about every rule that +** is used during the reduce. +*/ +static struct { + KKCODETYPE lhs; /* Symbol on the left-hand side of the rule */ + unsigned char nrhs; /* Number of right-hand side symbols in the rule */ +} kkRuleInfo[] = { + { 78, 1 }, + { 79, 1 }, + { 80, 2 }, + { 80, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 81, 1 }, + { 83, 8 }, + { 83, 7 }, + { 83, 12 }, + { 83, 11 }, + { 83, 10 }, + { 84, 4 }, + { 85, 3 }, + { 86, 10 }, + { 86, 12 }, + { 86, 12 }, + { 86, 14 }, + { 87, 4 }, + { 102, 3 }, + { 102, 1 }, + { 103, 3 }, + { 103, 3 }, + { 103, 3 }, + { 103, 3 }, + { 103, 3 }, + { 98, 10 }, + { 98, 11 }, + { 104, 3 }, + { 104, 1 }, + { 105, 1 }, + { 105, 3 }, + { 106, 1 }, + { 106, 1 }, + { 106, 1 }, + { 106, 1 }, + { 106, 1 }, + { 106, 1 }, + { 100, 11 }, + { 100, 9 }, + { 99, 2 }, + { 88, 3 }, + { 89, 8 }, + { 89, 7 }, + { 90, 8 }, + { 90, 9 }, + { 91, 4 }, + { 92, 4 }, + { 92, 6 }, + { 93, 4 }, + { 94, 4 }, + { 95, 8 }, + { 95, 8 }, + { 96, 3 }, + { 97, 3 }, + { 82, 1 }, + { 101, 2 }, + { 101, 2 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 4 }, + { 101, 3 }, + { 101, 4 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 4 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 3 }, + { 101, 4 }, + { 101, 2 }, + { 101, 2 }, + { 101, 2 }, + { 101, 3 }, + { 101, 2 }, + { 101, 3 }, + { 101, 2 }, + { 101, 3 }, + { 101, 4 }, + { 101, 5 }, + { 101, 5 }, + { 101, 5 }, + { 101, 6 }, + { 109, 1 }, + { 109, 1 }, + { 108, 3 }, + { 108, 1 }, + { 110, 3 }, + { 110, 1 }, + { 101, 1 }, + { 111, 4 }, + { 111, 3 }, + { 107, 3 }, + { 107, 1 }, + { 112, 1 }, + { 112, 3 }, + { 101, 1 }, + { 101, 1 }, + { 101, 1 }, + { 101, 1 }, + { 101, 1 }, + { 101, 1 }, + { 101, 1 }, +}; - zval *attributes, *null_value, *keys_attributes; - zval *attribute = NULL, *meta_data; - HashTable *ah0; - HashPosition hp0; - zval **hd; +static void kk_accept(kkParser*); /* Forward Declaration */ - PHALCON_MM_GROW(); +static void kk_reduce( + kkParser *kkpParser, /* The parser */ + int kkruleno /* Number of the rule by which to reduce */ +){ + int kkgoto; /* The next state */ + int kkact; /* The next action */ + KKMINORTYPE kkgotominor; /* The LHS of the rule reduced */ + kkStackEntry *kkmsp; /* The top of the parser's stack */ + int kksize; /* Amount to pop the stack */ + phvolt_ARG_FETCH; + kkmsp = &kkpParser->kkstack[kkpParser->kkidx]; +#ifndef NDEBUG + if( kkTraceFILE && kkruleno>=0 + && kkruleno + ** { ... } // User supplied code + ** // + ** break; + */ + case 0: +// 712 "parser.lemon" +{ + status->ret = kkmsp[0].minor.kk132; +} +// 2001 "parser.c" + break; + case 1: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + case 18: + case 19: + case 20: + case 21: + case 22: + case 119: +// 716 "parser.lemon" +{ + kkgotominor.kk132 = kkmsp[0].minor.kk132; +} +// 2028 "parser.c" + break; + case 2: +// 722 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_zval_list(kkmsp[-1].minor.kk132, kkmsp[0].minor.kk132); } - -static PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnUpdate){ - - zval *attributes, *null_value, *keys_attributes; - zval *attribute = NULL, *meta_data; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &attributes); - - if (Z_TYPE_P(attributes) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Attributes must be an array"); - return; - } - - PHALCON_INIT_VAR(null_value); - - PHALCON_INIT_VAR(keys_attributes); - array_init(keys_attributes); - - phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(attribute); - - phalcon_array_update_zval(&keys_attributes, attribute, &null_value, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - phalcon_call_method_p2_key(NULL, meta_data, "setautomaticupdateattributes", this_ptr, keys_attributes, 2859965858UL); - - PHALCON_MM_RESTORE(); +// 2035 "parser.c" + break; + case 3: + case 36: + case 45: + case 116: + case 123: +// 726 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_zval_list(NULL, kkmsp[0].minor.kk132); } - -static PHP_METHOD(Phalcon_Mvc_Model, hasOne){ - - zval *fields, *reference_model, *referenced_fields; - zval *options = NULL, *manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 1, &fields, &reference_model, &referenced_fields, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p5(return_value, manager, "addhasone", this_ptr, fields, reference_model, referenced_fields, options); - RETURN_MM(); +// 2046 "parser.c" + break; + case 23: +// 810 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_if_statement(kkmsp[-5].minor.kk132, kkmsp[-3].minor.kk132, NULL, status->scanner_state); + kk_destructor(1,&kkmsp[-7].minor); + kk_destructor(31,&kkmsp[-6].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(33,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, belongsTo){ - - zval *fields, *reference_model, *referenced_fields; - zval *options = NULL, *manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 1, &fields, &reference_model, &referenced_fields, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p5(return_value, manager, "addbelongsto", this_ptr, fields, reference_model, referenced_fields, options); - RETURN_MM(); +// 2059 "parser.c" + break; + case 24: +// 814 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_if_statement(kkmsp[-4].minor.kk132, NULL, NULL, status->scanner_state); + kk_destructor(1,&kkmsp[-6].minor); + kk_destructor(31,&kkmsp[-5].minor); + kk_destructor(32,&kkmsp[-3].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(33,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, hasMany){ - - zval *fields, *reference_model, *referenced_fields; - zval *options = NULL, *manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 1, &fields, &reference_model, &referenced_fields, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p5(return_value, manager, "addhasmany", this_ptr, fields, reference_model, referenced_fields, options); - RETURN_MM(); +// 2072 "parser.c" + break; + case 25: +// 818 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_if_statement(kkmsp[-9].minor.kk132, kkmsp[-7].minor.kk132, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-11].minor); + kk_destructor(31,&kkmsp[-10].minor); + kk_destructor(32,&kkmsp[-8].minor); + kk_destructor(1,&kkmsp[-6].minor); + kk_destructor(34,&kkmsp[-5].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(33,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, hasManyToMany){ - - zval *fields, *intermediate_model, *intermediate_fields; - zval *intermediate_referenced_fields, *reference_model; - zval *referenced_fields, *options = NULL, *manager; - zval *p0[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 6, 1, &fields, &intermediate_model, &intermediate_fields, &intermediate_referenced_fields, &reference_model, &referenced_fields, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - - p0[0] = this_ptr; - p0[1] = fields; - p0[2] = intermediate_model; - p0[3] = intermediate_fields; - p0[4] = intermediate_referenced_fields; - p0[5] = reference_model; - p0[6] = referenced_fields; - p0[7] = options; - phalcon_call_method_pn(return_value, manager, "addhasmanytomany", 8, p0); - RETURN_MM(); +// 2088 "parser.c" + break; + case 26: +// 822 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_if_statement(kkmsp[-8].minor.kk132, kkmsp[-6].minor.kk132, NULL, status->scanner_state); + kk_destructor(1,&kkmsp[-10].minor); + kk_destructor(31,&kkmsp[-9].minor); + kk_destructor(32,&kkmsp[-7].minor); + kk_destructor(1,&kkmsp[-5].minor); + kk_destructor(34,&kkmsp[-4].minor); + kk_destructor(32,&kkmsp[-3].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(33,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, addBehavior){ - - zval *behavior, *manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &behavior); - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, manager, "addbehavior", this_ptr, behavior, 2404171070UL); - - PHALCON_MM_RESTORE(); +// 2104 "parser.c" + break; + case 27: +// 826 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_if_statement(kkmsp[-7].minor.kk132, NULL, NULL, status->scanner_state); + kk_destructor(1,&kkmsp[-9].minor); + kk_destructor(31,&kkmsp[-8].minor); + kk_destructor(32,&kkmsp[-6].minor); + kk_destructor(1,&kkmsp[-5].minor); + kk_destructor(34,&kkmsp[-4].minor); + kk_destructor(32,&kkmsp[-3].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(33,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, keepSnapshots){ - - zval *keep_snapshot, *manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &keep_snapshot); - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, manager, "keepsnapshots", this_ptr, keep_snapshot, 3989700781UL); - - PHALCON_MM_RESTORE(); +// 2120 "parser.c" + break; + case 28: +// 832 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_elseif_statement(kkmsp[-1].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-3].minor); + kk_destructor(35,&kkmsp[-2].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, setSnapshotData){ - - zval *data, *column_map = NULL, *snapshot, *value = NULL, *key = NULL, *exception_message = NULL; - zval *attribute = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &data, &column_map); - - if (!column_map) { - PHALCON_INIT_VAR(column_map); - } - - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The snapshot data must be an array"); - return; - } - - if (Z_TYPE_P(column_map) == IS_ARRAY) { - - PHALCON_INIT_VAR(snapshot); - array_init(snapshot); - - 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 (Z_TYPE_P(key) != IS_STRING) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - - if (!phalcon_array_isset(column_map, key)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column \"", key, "\" doesn't make part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch(&attribute, column_map, key, PH_NOISY); - phalcon_array_update_zval(&snapshot, attribute, &value, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - phalcon_update_property_this_quick(this_ptr, SL("_snapshot"), snapshot, 3325604532UL TSRMLS_CC); - RETURN_MM_NULL(); - } - - phalcon_update_property_this_quick(this_ptr, SL("_snapshot"), data, 3325604532UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); +// 2130 "parser.c" + break; + case 29: +// 838 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_elsefor_statement(status->scanner_state); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(36,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, hasSnapshotData){ - - zval *snapshot; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(snapshot); - phalcon_read_property_this_quick(&snapshot, this_ptr, SL("_snapshot"), 3325604532UL, PH_NOISY_CC); - if (Z_TYPE_P(snapshot) == IS_ARRAY) { - RETURN_MM_TRUE; - } - - RETURN_MM_FALSE; +// 2140 "parser.c" + break; + case 30: +// 844 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_for_statement(kkmsp[-7].minor.kk0, NULL, kkmsp[-5].minor.kk132, NULL, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-9].minor); + kk_destructor(37,&kkmsp[-8].minor); + kk_destructor(3,&kkmsp[-6].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(39,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, getSnapshotData){ - - - RETURN_MEMBER_QUICK(this_ptr, "_snapshot", 3325604532UL); +// 2154 "parser.c" + break; + case 31: +// 848 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_for_statement(kkmsp[-9].minor.kk0, NULL, kkmsp[-7].minor.kk132, kkmsp[-5].minor.kk132, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-11].minor); + kk_destructor(37,&kkmsp[-10].minor); + kk_destructor(3,&kkmsp[-8].minor); + kk_destructor(31,&kkmsp[-6].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(39,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, hasChanged){ - - zval *field_name = NULL, *snapshot, *dirty_state, *meta_data; - zval *column_map, *attributes, *all_attributes = NULL; - zval *exception_message = NULL, *value = NULL, *original_value = NULL; - zval *type = NULL, *name = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &field_name); - - if (!field_name) { - PHALCON_INIT_VAR(field_name); - } - - PHALCON_OBS_VAR(snapshot); - phalcon_read_property_this_quick(&snapshot, this_ptr, SL("_snapshot"), 3325604532UL, PH_NOISY_CC); - if (Z_TYPE_P(snapshot) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The record doesn't have a valid data snapshot"); - return; - } - - if (Z_TYPE_P(field_name) != IS_STRING) { - if (Z_TYPE_P(field_name) != IS_NULL) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The field name must be string"); - return; - } - } - - PHALCON_OBS_VAR(dirty_state); - phalcon_read_property_this_quick(&dirty_state, this_ptr, SL("_dirtyState"), 1560981745UL, PH_NOISY_CC); - - if (!PHALCON_IS_LONG(dirty_state, 0)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Change checking cannot be performed because the object has not been persisted or is deleted"); - return; - } - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getreversecolumnmap", this_ptr, 817005101UL); - - if (Z_TYPE_P(column_map) != IS_ARRAY) { - PHALCON_INIT_VAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getdatatypes", this_ptr, 562971380UL); - PHALCON_CPY_WRT(all_attributes, attributes); - } else { - PHALCON_CPY_WRT(all_attributes, column_map); - } - - if (Z_TYPE_P(field_name) == IS_STRING) { - - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (!phalcon_array_isset(column_map, field_name)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "The field '", field_name, "' is not part of the model"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } else { - if (!phalcon_array_isset(attributes, field_name)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "The field '", field_name, "' is not part of the model"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } - - if (!phalcon_isset_property_zval(this_ptr, field_name TSRMLS_CC)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "The field '", field_name, "' is not defined on the model"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - if (!phalcon_array_isset(snapshot, field_name)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "The field '", field_name, "' was not found in the snapshot"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_VAR(value); - phalcon_read_property_zval(&value, this_ptr, field_name, PH_NOISY_CC); - - PHALCON_OBS_VAR(original_value); - phalcon_array_fetch(&original_value, snapshot, field_name, PH_NOISY); - - if (PHALCON_IS_EQUAL(value, original_value)) { - RETURN_MM_FALSE; - } else { - RETURN_MM_TRUE; - } - } - - phalcon_is_iterable(all_attributes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(name, ah0, hp0); - PHALCON_GET_HVALUE(type); - - if (!phalcon_array_isset(snapshot, name)) { - RETURN_MM_TRUE; - } - - if (!phalcon_isset_property_zval(this_ptr, name TSRMLS_CC)) { - RETURN_MM_TRUE; - } - - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, name, PH_NOISY_CC); - - PHALCON_OBS_NVAR(original_value); - phalcon_array_fetch(&original_value, snapshot, name, PH_NOISY); - - if (!PHALCON_IS_EQUAL(value, original_value)) { - RETURN_MM_TRUE; - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_MM_FALSE; +// 2169 "parser.c" + break; + case 32: +// 852 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_for_statement(kkmsp[-7].minor.kk0, kkmsp[-9].minor.kk0, kkmsp[-5].minor.kk132, NULL, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-11].minor); + kk_destructor(37,&kkmsp[-10].minor); + kk_destructor(2,&kkmsp[-8].minor); + kk_destructor(3,&kkmsp[-6].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(39,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); +} +// 2184 "parser.c" + break; + case 33: +// 856 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_for_statement(kkmsp[-9].minor.kk0, kkmsp[-11].minor.kk0, kkmsp[-7].minor.kk132, kkmsp[-5].minor.kk132, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-13].minor); + kk_destructor(37,&kkmsp[-12].minor); + kk_destructor(2,&kkmsp[-10].minor); + kk_destructor(3,&kkmsp[-8].minor); + kk_destructor(31,&kkmsp[-6].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(39,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, getChangedFields){ - - zval *snapshot, *dirty_state, *meta_data, *column_map; - zval *attributes, *all_attributes = NULL, *changed; - zval *type = NULL, *name = NULL, *value = NULL, *original_value = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(snapshot); - phalcon_read_property_this_quick(&snapshot, this_ptr, SL("_snapshot"), 3325604532UL, PH_NOISY_CC); - if (Z_TYPE_P(snapshot) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The record doesn't have a valid data snapshot"); - return; - } - - PHALCON_OBS_VAR(dirty_state); - phalcon_read_property_this_quick(&dirty_state, this_ptr, SL("_dirtyState"), 1560981745UL, PH_NOISY_CC); - - if (!PHALCON_IS_LONG(dirty_state, 0)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Change checking cannot be performed because the object has not been persisted or is deleted"); - return; - } - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getreversecolumnmap", this_ptr, 817005101UL); - - if (Z_TYPE_P(column_map) != IS_ARRAY) { - PHALCON_INIT_VAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getdatatypes", this_ptr, 562971380UL); - PHALCON_CPY_WRT(all_attributes, attributes); - } else { - PHALCON_CPY_WRT(all_attributes, column_map); - } - - PHALCON_INIT_VAR(changed); - array_init(changed); - - phalcon_is_iterable(all_attributes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(name, ah0, hp0); - PHALCON_GET_HVALUE(type); - - if (!phalcon_array_isset(snapshot, name)) { - phalcon_array_append(&changed, name, PH_SEPARATE); - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - - if (!phalcon_isset_property_zval(this_ptr, name TSRMLS_CC)) { - phalcon_array_append(&changed, name, PH_SEPARATE); - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, name, PH_NOISY_CC); - - PHALCON_OBS_NVAR(original_value); - phalcon_array_fetch(&original_value, snapshot, name, PH_NOISY); - - if (!PHALCON_IS_EQUAL(value, original_value)) { - phalcon_array_append(&changed, name, PH_SEPARATE); - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CTOR(changed); +// 2200 "parser.c" + break; + case 34: +// 862 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_set_statement(kkmsp[-1].minor.kk132); + kk_destructor(1,&kkmsp[-3].minor); + kk_destructor(40,&kkmsp[-2].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, useDynamicUpdate){ - - zval *dynamic_update, *manager; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &dynamic_update); - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, manager, "usedynamicupdate", this_ptr, dynamic_update, 3447359802UL); - - PHALCON_MM_RESTORE(); +// 2210 "parser.c" + break; + case 35: + case 44: + case 115: + case 122: +// 868 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_zval_list(kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132); + kk_destructor(2,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, getRelated){ - - zval *alias, *arguments = NULL, *manager, *class_name; - zval *relation, *exception_message, *call_object; - zval *model_args; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &alias, &arguments); - - if (!arguments) { - PHALCON_INIT_VAR(arguments); - } - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(relation); - phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", class_name, alias, 785467656UL); - if (Z_TYPE_P(relation) != IS_OBJECT) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVSVS(exception_message, "There is no defined relations for the model \"", class_name, "\" using alias \"", alias, "\""); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_INIT_VAR(call_object); - array_init_size(call_object, 2); - phalcon_array_append(&call_object, manager, PH_SEPARATE); - add_next_index_stringl(call_object, SL("getRelationRecords"), 1); - - PHALCON_INIT_VAR(model_args); - array_init_size(model_args, 4); - phalcon_array_append(&model_args, relation, PH_SEPARATE); - add_next_index_null(model_args); - phalcon_array_append(&model_args, this_ptr, PH_SEPARATE); - phalcon_array_append(&model_args, arguments, PH_SEPARATE); - PHALCON_CALL_USER_FUNC_ARRAY(return_value, call_object, model_args); - RETURN_MM(); +// 2221 "parser.c" + break; + case 37: +// 878 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_set_assignment(kkmsp[-2].minor.kk0, PHVOLT_T_ASSIGN, kkmsp[0].minor.kk132, status->scanner_state); + kk_destructor(41,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, _getRelatedRecords){ - - zval *model_name, *method, *arguments, *manager; - zval *relation = NULL, *query_method = NULL, *alias = NULL, *extra_args = NULL; - zval *call_args, *call_object; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &model_name, &method, &arguments); - - PHALCON_OBS_VAR(manager); - phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(relation); - ZVAL_BOOL(relation, 0); - - PHALCON_INIT_VAR(query_method); - - if (phalcon_start_with_str(method, SL("get"))) { - PHALCON_INIT_VAR(alias); - phalcon_substr(alias, method, 3, 0); - - phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", model_name, alias, 785467656UL); - } - - if (Z_TYPE_P(relation) != IS_OBJECT) { - if (phalcon_start_with_str(method, SL("count"))) { - ZVAL_STRING(query_method, "count", 1); - - PHALCON_INIT_NVAR(alias); - phalcon_substr(alias, method, 5, 0); - - PHALCON_INIT_NVAR(relation); - phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", model_name, alias, 785467656UL); - } - } - - if (Z_TYPE_P(relation) == IS_OBJECT) { - if (phalcon_array_isset_long(arguments, 0)) { - PHALCON_OBS_VAR(extra_args); - phalcon_array_fetch_long(&extra_args, arguments, 0, PH_NOISY); - } else { - PHALCON_INIT_NVAR(extra_args); - } - - PHALCON_INIT_VAR(call_args); - array_init_size(call_args, 4); - phalcon_array_append(&call_args, relation, PH_SEPARATE); - phalcon_array_append(&call_args, query_method, PH_SEPARATE); - phalcon_array_append(&call_args, this_ptr, PH_SEPARATE); - phalcon_array_append(&call_args, extra_args, PH_SEPARATE); - - PHALCON_INIT_VAR(call_object); - array_init_size(call_object, 2); - phalcon_array_append(&call_object, manager, PH_SEPARATE); - add_next_index_stringl(call_object, SL("getRelationRecords"), 1); - PHALCON_CALL_USER_FUNC_ARRAY(return_value, call_object, call_args); - RETURN_MM(); - } - - RETURN_MM_NULL(); +// 2229 "parser.c" + break; + case 38: +// 882 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_set_assignment(kkmsp[-2].minor.kk0, PHVOLT_T_ADD_ASSIGN, kkmsp[0].minor.kk132, status->scanner_state); + kk_destructor(42,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, __call){ - - zval *method, *arguments = NULL, *model_name, *records; - zval *models_manager, *status, *exception_message; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &method, &arguments); - - if (!arguments) { - PHALCON_INIT_VAR(arguments); - array_init(arguments); - } - - PHALCON_INIT_VAR(model_name); - phalcon_get_class(model_name, this_ptr, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(records); - phalcon_call_method_p3_key(records, this_ptr, "_getrelatedrecords", model_name, method, arguments, 1071693079UL); - if (Z_TYPE_P(records) != IS_NULL) { - RETURN_CCTOR(records); - } - - PHALCON_OBS_VAR(models_manager); - phalcon_read_property_this_quick(&models_manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p3_key(status, models_manager, "missingmethod", this_ptr, method, arguments, 965701664UL); - if (Z_TYPE_P(status) != IS_NULL) { - RETURN_CCTOR(status); - } - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVSVS(exception_message, "The method \"", method, "\" doesn't exist on model \"", model_name, "\""); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; +// 2237 "parser.c" + break; + case 39: +// 886 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_set_assignment(kkmsp[-2].minor.kk0, PHVOLT_T_SUB_ASSIGN, kkmsp[0].minor.kk132, status->scanner_state); + kk_destructor(43,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, __callStatic){ - - zval *method, *arguments = NULL, *extra_method = NULL, *type = NULL; - zval *model_name, *exception_message = NULL, *value; - zval *model, *meta_data, *attributes = NULL, *field = NULL, *extra_method_first; - zval *conditions, *bind_params, *parameters; - zend_class_entry *ce0; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &method, &arguments); - - if (!arguments) { - PHALCON_INIT_VAR(arguments); - } - - PHALCON_INIT_VAR(extra_method); - - if (phalcon_start_with_str(method, SL("findFirstBy"))) { - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "findFirst", 1); - - phalcon_substr(extra_method, method, 11, 0); - } - - if (Z_TYPE_P(extra_method) == IS_NULL) { - if (phalcon_start_with_str(method, SL("findBy"))) { - PHALCON_INIT_NVAR(type); - ZVAL_STRING(type, "find", 1); - - PHALCON_INIT_NVAR(extra_method); - phalcon_substr(extra_method, method, 6, 0); - } - } - - if (Z_TYPE_P(extra_method) == IS_NULL) { - if (phalcon_start_with_str(method, SL("countBy"))) { - PHALCON_INIT_NVAR(type); - ZVAL_STRING(type, "count", 1); - - PHALCON_INIT_NVAR(extra_method); - phalcon_substr(extra_method, method, 7, 0); - } - } - - PHALCON_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); - if (!zend_is_true(extra_method)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVSVS(exception_message, "The static method \"", method, "\" doesn't exist on model \"", model_name, "\""); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - if (!phalcon_array_isset_long(arguments, 0)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "The static method \"", method, "\" requires one argument"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_VAR(value); - phalcon_array_fetch_long(&value, arguments, 0, PH_NOISY); - ce0 = phalcon_fetch_class(model_name TSRMLS_CC); - - PHALCON_INIT_VAR(model); - object_init_ex(model, ce0); - if (phalcon_has_constructor(model TSRMLS_CC)) { - phalcon_call_method_key(NULL, model, "__construct", 1107214344UL); - } - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_key(meta_data, model, "getmodelsmetadata", 3603043978UL); - - PHALCON_INIT_VAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getreversecolumnmap", model, 817005101UL); - if (Z_TYPE_P(attributes) != IS_ARRAY) { - PHALCON_INIT_NVAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getdatatypes", model, 562971380UL); - } - - if (phalcon_array_isset(attributes, extra_method)) { - PHALCON_CPY_WRT(field, extra_method); - } else { - PHALCON_INIT_VAR(extra_method_first); - phalcon_lcfirst(extra_method_first, extra_method); - if (phalcon_array_isset(attributes, extra_method_first)) { - PHALCON_CPY_WRT(field, extra_method_first); - } else { - PHALCON_INIT_NVAR(field); - phalcon_uncamelize(field, extra_method); - if (!phalcon_array_isset(attributes, field)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Cannot resolve attribute \"", extra_method, "' in the model"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - } - } - - PHALCON_INIT_VAR(conditions); - PHALCON_CONCAT_VS(conditions, field, " = ?0"); - - PHALCON_INIT_VAR(bind_params); - array_init_size(bind_params, 1); - phalcon_array_append(&bind_params, value, PH_SEPARATE); - - PHALCON_INIT_VAR(parameters); - array_init_size(parameters, 2); - phalcon_array_update_quick_string(¶meters, SS("conditions"), 1055696255UL, &conditions, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(¶meters, SS("bind"), 254268962UL, &bind_params, PH_COPY | PH_SEPARATE); - - phalcon_call_zval_static_p1(return_value, model_name, type, parameters); - RETURN_MM(); +// 2245 "parser.c" + break; + case 40: +// 890 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_set_assignment(kkmsp[-2].minor.kk0, PHVOLT_T_MUL_ASSIGN, kkmsp[0].minor.kk132, status->scanner_state); + kk_destructor(44,&kkmsp[-1].minor); +} +// 2253 "parser.c" + break; + case 41: +// 894 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_set_assignment(kkmsp[-2].minor.kk0, PHVOLT_T_DIV_ASSIGN, kkmsp[0].minor.kk132, status->scanner_state); + kk_destructor(45,&kkmsp[-1].minor); +} +// 2261 "parser.c" + break; + case 42: +// 900 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_macro_statement(kkmsp[-7].minor.kk0, NULL, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-9].minor); + kk_destructor(46,&kkmsp[-8].minor); + kk_destructor(29,&kkmsp[-6].minor); + kk_destructor(47,&kkmsp[-5].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(48,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); +} +// 2276 "parser.c" + break; + case 43: +// 904 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_macro_statement(kkmsp[-8].minor.kk0, kkmsp[-6].minor.kk132, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-10].minor); + kk_destructor(46,&kkmsp[-9].minor); + kk_destructor(29,&kkmsp[-7].minor); + kk_destructor(47,&kkmsp[-5].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(48,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); +} +// 2291 "parser.c" + break; + case 46: +// 920 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_macro_parameter(kkmsp[0].minor.kk0, NULL, status->scanner_state); +} +// 2298 "parser.c" + break; + case 47: +// 924 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_macro_parameter(kkmsp[-2].minor.kk0, kkmsp[0].minor.kk132, status->scanner_state); + kk_destructor(41,&kkmsp[-1].minor); +} +// 2306 "parser.c" + break; + case 48: + case 113: + case 127: +// 928 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_INTEGER, kkmsp[0].minor.kk0, status->scanner_state); +} +// 2315 "parser.c" + break; + case 49: + case 128: +// 932 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_STRING, kkmsp[0].minor.kk0, status->scanner_state); +} +// 2323 "parser.c" + break; + case 50: + case 129: +// 936 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_DOUBLE, kkmsp[0].minor.kk0, status->scanner_state); +} +// 2331 "parser.c" + break; + case 51: + case 130: +// 940 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_NULL, NULL, status->scanner_state); + kk_destructor(52,&kkmsp[0].minor); +} +// 2340 "parser.c" + break; + case 52: + case 131: +// 944 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_FALSE, NULL, status->scanner_state); + kk_destructor(53,&kkmsp[0].minor); +} +// 2349 "parser.c" + break; + case 53: + case 132: +// 948 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_TRUE, NULL, status->scanner_state); + kk_destructor(54,&kkmsp[0].minor); +} +// 2358 "parser.c" + break; + case 54: +// 954 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_macro_call_statement(kkmsp[-8].minor.kk132, kkmsp[-6].minor.kk132, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-10].minor); + kk_destructor(55,&kkmsp[-9].minor); + kk_destructor(29,&kkmsp[-7].minor); + kk_destructor(47,&kkmsp[-5].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(56,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, __set){ - - zval *property, *value, *is_model, *lower_property = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &property, &value); - - if (Z_TYPE_P(value) == IS_OBJECT) { - - PHALCON_INIT_VAR(is_model); - phalcon_instance_of(is_model, value, phalcon_mvc_modelinterface_ce TSRMLS_CC); - if (zend_is_true(is_model)) { - PHALCON_INIT_VAR(lower_property); - phalcon_fast_strtolower(lower_property, property); - phalcon_update_property_zval_zval(this_ptr, lower_property, value TSRMLS_CC); - phalcon_update_property_array(this_ptr, SL("_related"), lower_property, value TSRMLS_CC); - phalcon_update_property_long(this_ptr, SL("_dirtyState"), 1 TSRMLS_CC); - RETURN_CCTOR(value); - } - } - - if (Z_TYPE_P(value) == IS_ARRAY) { - PHALCON_INIT_NVAR(lower_property); - phalcon_fast_strtolower(lower_property, property); - phalcon_update_property_array(this_ptr, SL("_related"), lower_property, value TSRMLS_CC); - phalcon_update_property_long(this_ptr, SL("_dirtyState"), 1 TSRMLS_CC); - RETURN_CCTOR(value); - } - - phalcon_update_property_zval_zval(this_ptr, property, value TSRMLS_CC); - - RETURN_CCTOR(value); +// 2373 "parser.c" + break; + case 55: +// 958 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_macro_call_statement(kkmsp[-6].minor.kk132, NULL, NULL, status->scanner_state); + kk_destructor(1,&kkmsp[-8].minor); + kk_destructor(55,&kkmsp[-7].minor); + kk_destructor(29,&kkmsp[-5].minor); + kk_destructor(47,&kkmsp[-4].minor); + kk_destructor(32,&kkmsp[-3].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(56,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, __get){ - - zval *property, *model_name, *manager, *lower_property; - zval *relation, *call_args, *call_object, *result; - zval *is_simple_model, *error_msg; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &property); - - PHALCON_INIT_VAR(model_name); - phalcon_get_class(model_name, this_ptr, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(manager); - phalcon_call_method_key(manager, this_ptr, "getmodelsmanager", 2387491844UL); - - PHALCON_INIT_VAR(lower_property); - phalcon_fast_strtolower(lower_property, property); - - PHALCON_INIT_VAR(relation); - phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", model_name, lower_property, 785467656UL); - if (Z_TYPE_P(relation) == IS_OBJECT) { - - PHALCON_INIT_VAR(call_args); - array_init_size(call_args, 4); - phalcon_array_append(&call_args, relation, PH_SEPARATE); - add_next_index_null(call_args); - phalcon_array_append(&call_args, this_ptr, PH_SEPARATE); - add_next_index_null(call_args); - - PHALCON_INIT_VAR(call_object); - array_init_size(call_object, 2); - phalcon_array_append(&call_object, manager, PH_SEPARATE); - add_next_index_stringl(call_object, SL("getRelationRecords"), 1); - - PHALCON_INIT_VAR(result); - PHALCON_CALL_USER_FUNC_ARRAY(result, call_object, call_args); - - if (Z_TYPE_P(result) == IS_OBJECT) { - - phalcon_update_property_zval_zval(this_ptr, lower_property, result TSRMLS_CC); - - PHALCON_INIT_VAR(is_simple_model); - phalcon_instance_of(is_simple_model, result, phalcon_mvc_modelinterface_ce TSRMLS_CC); - if (PHALCON_IS_TRUE(is_simple_model)) { - phalcon_update_property_array(this_ptr, SL("_related"), lower_property, result TSRMLS_CC); - } - } - - RETURN_CCTOR(result); - } - - PHALCON_INIT_VAR(error_msg); - PHALCON_CONCAT_SVSV(error_msg, "Access to undefined property ", model_name, "::", property); - phalcon_call_func_p1_noret("trigger_error", error_msg); - RETURN_MM_NULL(); +// 2388 "parser.c" + break; + case 56: +// 964 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_empty_statement(status->scanner_state); + kk_destructor(1,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, __isset){ - - zval *property, *model_name, *manager, *relation; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &property); - - PHALCON_INIT_VAR(model_name); - phalcon_get_class(model_name, this_ptr, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(manager); - phalcon_call_method_key(manager, this_ptr, "getmodelsmanager", 2387491844UL); - - PHALCON_INIT_VAR(relation); - phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", model_name, property, 785467656UL); - if (Z_TYPE_P(relation) == IS_OBJECT) { - RETURN_MM_TRUE; - } - - RETURN_MM_FALSE; +// 2397 "parser.c" + break; + case 57: +// 970 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_echo_statement(kkmsp[-1].minor.kk132, status->scanner_state); + kk_destructor(57,&kkmsp[-2].minor); + kk_destructor(58,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, serialize){ - - zval *meta_data, *attributes, *null_value, *data; - zval *attribute = NULL, *value = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - - PHALCON_INIT_VAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); - - PHALCON_INIT_VAR(null_value); - - PHALCON_INIT_VAR(data); - array_init(data); - - phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(attribute); - - if (phalcon_isset_property_zval(this_ptr, attribute TSRMLS_CC)) { - PHALCON_OBS_NVAR(value); - phalcon_read_property_zval(&value, this_ptr, attribute, PH_NOISY_CC); - phalcon_array_update_zval(&data, attribute, &value, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_zval(&data, attribute, &null_value, PH_COPY | PH_SEPARATE); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - phalcon_serialize(return_value, &data TSRMLS_CC); - RETURN_MM(); +// 2406 "parser.c" + break; + case 58: +// 976 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_block_statement(kkmsp[-5].minor.kk0, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-7].minor); + kk_destructor(59,&kkmsp[-6].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(60,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, unserialize){ - - zval *data, *attributes, *dependency_injector; - zval *service, *manager, *value = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - 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) { - - PHALCON_INIT_VAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); - return; - } - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "modelsManager", 1); - - PHALCON_INIT_VAR(manager); - phalcon_call_method_p1_key(manager, dependency_injector, "getshared", service, 1727570332UL); - if (Z_TYPE_P(manager) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The injected service 'modelsManager' is not valid"); - return; - } - - phalcon_update_property_this_quick(this_ptr, SL("_modelsManager"), manager, 3699347875UL TSRMLS_CC); - - phalcon_call_method_p1_key(NULL, manager, "initialize", this_ptr, 2896075127UL); - - 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(); - } - } - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Invalid serialization data"); - return; +// 2419 "parser.c" + break; + case 59: +// 980 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_block_statement(kkmsp[-4].minor.kk0, NULL, status->scanner_state); + kk_destructor(1,&kkmsp[-6].minor); + kk_destructor(59,&kkmsp[-5].minor); + kk_destructor(32,&kkmsp[-3].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(60,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, dump){ - - - PHALCON_MM_GROW(); - - phalcon_call_func_p1(return_value, "get_object_vars", this_ptr); - RETURN_MM(); +// 2432 "parser.c" + break; + case 60: +// 986 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_cache_statement(kkmsp[-5].minor.kk132, NULL, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-7].minor); + kk_destructor(61,&kkmsp[-6].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(62,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, toArray){ - - zval *meta_data, *data, *null_value, *attributes; - zval *column_map, *attribute = NULL, *exception_message = NULL; - zval *attribute_field = NULL, *value = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(meta_data); - phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - - PHALCON_INIT_VAR(data); - array_init(data); - - PHALCON_INIT_VAR(null_value); - - PHALCON_INIT_VAR(attributes); - phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); - - PHALCON_INIT_VAR(column_map); - phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); - - phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(attribute); - - if (Z_TYPE_P(column_map) == IS_ARRAY) { - if (!phalcon_array_isset(column_map, attribute)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Column \"", attribute, "\" doesn't make part of the column map"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_OBS_NVAR(attribute_field); - phalcon_array_fetch(&attribute_field, column_map, attribute, PH_NOISY); - } else { - PHALCON_CPY_WRT(attribute_field, attribute); - } - 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_CC); - phalcon_array_update_zval(&data, attribute_field, &value, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_zval(&data, attribute_field, &null_value, PH_COPY | PH_SEPARATE); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CTOR(data); +// 2445 "parser.c" + break; + case 61: +// 990 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_cache_statement(kkmsp[-6].minor.kk132, kkmsp[-5].minor.kk0, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-8].minor); + kk_destructor(61,&kkmsp[-7].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(62,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Mvc_Model, setup){ - - zval *options, *disable_events, *virtual_foreign_keys; - zval *column_renaming, *not_null_validations; - zval *exception_on_failed_save, *phql_literals; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &options); - - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Options must be an array"); - return; - } - - if (phalcon_array_isset_quick_string(options, SS("events"), 2099005594UL)) { - PHALCON_OBS_VAR(disable_events); - phalcon_array_fetch_quick_string(&disable_events, options, SS("events"), 2099005594UL, PH_NOISY); - PHALCON_GLOBAL(orm).events = zend_is_true(disable_events); - } - - if (phalcon_array_isset_quick_string(options, SS("virtualForeignKeys"), 3101162738UL)) { - PHALCON_OBS_VAR(virtual_foreign_keys); - phalcon_array_fetch_quick_string(&virtual_foreign_keys, options, SS("virtualForeignKeys"), 3101162738UL, PH_NOISY); - PHALCON_GLOBAL(orm).virtual_foreign_keys = zend_is_true(virtual_foreign_keys); - } - - if (phalcon_array_isset_quick_string(options, SS("columnRenaming"), 1384279140UL)) { - PHALCON_OBS_VAR(column_renaming); - phalcon_array_fetch_quick_string(&column_renaming, options, SS("columnRenaming"), 1384279140UL, PH_NOISY); - PHALCON_GLOBAL(orm).column_renaming = zend_is_true(column_renaming); - } - - if (phalcon_array_isset_quick_string(options, SS("notNullValidations"), 3404663535UL)) { - PHALCON_OBS_VAR(not_null_validations); - phalcon_array_fetch_quick_string(¬_null_validations, options, SS("notNullValidations"), 3404663535UL, PH_NOISY); - PHALCON_GLOBAL(orm).not_null_validations = zend_is_true(not_null_validations); - } - - if (phalcon_array_isset_quick_string(options, SS("exceptionOnFailedSave"), 2203913893UL)) { - PHALCON_OBS_VAR(exception_on_failed_save); - phalcon_array_fetch_quick_string(&exception_on_failed_save, options, SS("exceptionOnFailedSave"), 2203913893UL, PH_NOISY); - PHALCON_GLOBAL(orm).exception_on_failed_save = zend_is_true(exception_on_failed_save); - } - - if (phalcon_array_isset_quick_string(options, SS("phqlLiterals"), 3976399002UL)) { - PHALCON_OBS_VAR(phql_literals); - phalcon_array_fetch_quick_string(&phql_literals, options, SS("phqlLiterals"), 3976399002UL, PH_NOISY); - PHALCON_GLOBAL(orm).enable_literals = zend_is_true(phql_literals); - } - - PHALCON_MM_RESTORE(); +// 2458 "parser.c" + break; + case 62: +// 996 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_extends_statement(kkmsp[-1].minor.kk0, status->scanner_state); + kk_destructor(1,&kkmsp[-3].minor); + kk_destructor(63,&kkmsp[-2].minor); + kk_destructor(32,&kkmsp[0].minor); +} +// 2468 "parser.c" + break; + case 63: +// 1002 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_include_statement(kkmsp[-1].minor.kk132, NULL, status->scanner_state); + kk_destructor(1,&kkmsp[-3].minor); + kk_destructor(64,&kkmsp[-2].minor); + kk_destructor(32,&kkmsp[0].minor); +} +// 2478 "parser.c" + break; + case 64: +// 1006 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_include_statement(kkmsp[-3].minor.kk132, kkmsp[-1].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-5].minor); + kk_destructor(64,&kkmsp[-4].minor); + kk_destructor(65,&kkmsp[-2].minor); + kk_destructor(32,&kkmsp[0].minor); +} +// 2489 "parser.c" + break; + case 65: +// 1012 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_do_statement(kkmsp[-1].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-3].minor); + kk_destructor(66,&kkmsp[-2].minor); + kk_destructor(32,&kkmsp[0].minor); +} +// 2499 "parser.c" + break; + case 66: +// 1018 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_return_statement(kkmsp[-1].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-3].minor); + kk_destructor(67,&kkmsp[-2].minor); + kk_destructor(32,&kkmsp[0].minor); +} +// 2509 "parser.c" + break; + case 67: +// 1024 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_autoescape_statement(0, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-7].minor); + kk_destructor(68,&kkmsp[-6].minor); + kk_destructor(53,&kkmsp[-5].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(69,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); +} +// 2523 "parser.c" + break; + case 68: +// 1028 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_autoescape_statement(1, kkmsp[-3].minor.kk132, status->scanner_state); + kk_destructor(1,&kkmsp[-7].minor); + kk_destructor(68,&kkmsp[-6].minor); + kk_destructor(54,&kkmsp[-5].minor); + kk_destructor(32,&kkmsp[-4].minor); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(69,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); +} +// 2537 "parser.c" + break; + case 69: +// 1034 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_break_statement(status->scanner_state); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(70,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); +} +// 2547 "parser.c" + break; + case 70: +// 1040 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_continue_statement(status->scanner_state); + kk_destructor(1,&kkmsp[-2].minor); + kk_destructor(71,&kkmsp[-1].minor); + kk_destructor(32,&kkmsp[0].minor); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Dispatcher_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Dispatcher, Exception, mvc_dispatcher_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; +// 2557 "parser.c" + break; + case 71: +// 1046 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_RAW_FRAGMENT, kkmsp[0].minor.kk0, status->scanner_state); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_ControllerInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ControllerInterface, mvc_controllerinterface, NULL); - - return SUCCESS; +// 2564 "parser.c" + break; + case 72: +// 1052 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_MINUS, NULL, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(22,&kkmsp[-1].minor); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Cache_FrontendInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Cache, FrontendInterface, cache_frontendinterface, phalcon_cache_frontendinterface_method_entry); - - return SUCCESS; +// 2572 "parser.c" + break; + case 73: +// 1056 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_PLUS, NULL, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(21,&kkmsp[-1].minor); } - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Cache_Multiple){ - - PHALCON_REGISTER_CLASS(Phalcon\\Cache, Multiple, cache_multiple, phalcon_cache_multiple_method_entry, 0); - - zend_declare_property_null(phalcon_cache_multiple_ce, SL("_backends"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; +// 2580 "parser.c" + break; + case 74: +// 1060 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_SUB, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(22,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Multiple, __construct){ - - zval *backends = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &backends); - - if (!backends) { - PHALCON_INIT_VAR(backends); - } - - if (Z_TYPE_P(backends) != IS_NULL) { - if (Z_TYPE_P(backends) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backends must be an array"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_backends"), backends, 2548946143UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); +// 2588 "parser.c" + break; + case 75: +// 1064 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ADD, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(21,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Multiple, push){ - - zval *backend; - - phalcon_fetch_params(0, 1, 0, &backend); - - if (Z_TYPE_P(backend) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_cache_exception_ce, "The backend is not valid"); - return; - } - phalcon_update_property_array_append(this_ptr, SL("_backends"), backend TSRMLS_CC); - - RETURN_THISW(); +// 2596 "parser.c" + break; + case 76: +// 1068 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_MUL, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(19,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Multiple, get){ - - zval *key_name, *lifetime = NULL, *backends, *backend = NULL; - zval *content = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - PHALCON_OBS_VAR(backends); - phalcon_read_property_this_quick(&backends, this_ptr, SL("_backends"), 2548946143UL, PH_NOISY_CC); - - phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(backend); - - PHALCON_INIT_NVAR(content); - phalcon_call_method_p2_key(content, backend, "get", key_name, lifetime, 2090288933UL); - if (Z_TYPE_P(content) != IS_NULL) { - RETURN_CCTOR(content); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_MM_NULL(); +// 2604 "parser.c" + break; + case 77: +// 1072 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_POW, kkmsp[-3].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(19,&kkmsp[-2].minor); + kk_destructor(19,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Multiple, start){ - - zval *key_name, *lifetime = NULL, *backends, *backend = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - PHALCON_OBS_VAR(backends); - phalcon_read_property_this_quick(&backends, this_ptr, SL("_backends"), 2548946143UL, PH_NOISY_CC); - - phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(backend); - - phalcon_call_method_p2_key(NULL, backend, "start", key_name, lifetime, 478839859UL); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - - PHALCON_MM_RESTORE(); +// 2613 "parser.c" + break; + case 78: +// 1076 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_DIV, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(18,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Multiple, save){ - - zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; - zval *backends, *backend = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!content) { - PHALCON_INIT_VAR(content); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (!stop_buffer) { - PHALCON_INIT_VAR(stop_buffer); - ZVAL_BOOL(stop_buffer, 1); - } - - PHALCON_OBS_VAR(backends); - phalcon_read_property_this_quick(&backends, this_ptr, SL("_backends"), 2548946143UL, PH_NOISY_CC); - - phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(backend); - - phalcon_call_method_p4_key(NULL, backend, "save", key_name, content, lifetime, stop_buffer, 274150868UL); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - - PHALCON_MM_RESTORE(); +// 2621 "parser.c" + break; + case 79: +// 1080 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_MOD, kkmsp[-3].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(18,&kkmsp[-2].minor); + kk_destructor(18,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Multiple, delete){ - - zval *key_name, *backends, *backend = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key_name); - - PHALCON_OBS_VAR(backends); - phalcon_read_property_this_quick(&backends, this_ptr, SL("_backends"), 2548946143UL, PH_NOISY_CC); - - phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(backend); - - phalcon_call_method_p1_key(NULL, backend, "delete", key_name, 150213496UL); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - - PHALCON_MM_RESTORE(); +// 2630 "parser.c" + break; + case 80: +// 1084 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_MOD, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(20,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Multiple, exists){ - - zval *key_name = NULL, *lifetime = NULL, *backends, *backend = NULL; - zval *exists = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - PHALCON_OBS_VAR(backends); - phalcon_read_property_this_quick(&backends, this_ptr, SL("_backends"), 2548946143UL, PH_NOISY_CC); - - phalcon_is_iterable(backends, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(backend); - - PHALCON_INIT_NVAR(exists); - phalcon_call_method_p2_key(exists, backend, "exists", key_name, lifetime, 2182199749UL); - if (zend_is_true(exists)) { - RETURN_MM_TRUE; - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_MM_FALSE; +// 2638 "parser.c" + break; + case 81: +// 1088 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_AND, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(7,&kkmsp[-1].minor); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_Data){ - - PHALCON_REGISTER_CLASS(Phalcon\\Cache\\Frontend, Data, cache_frontend_data, phalcon_cache_frontend_data_method_entry, 0); - - zend_declare_property_null(phalcon_cache_frontend_data_ce, SL("_frontendOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_cache_frontend_data_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); - - return SUCCESS; +// 2646 "parser.c" + break; + case 82: +// 1092 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_OR, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(8,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Data, __construct){ - - zval *frontend_options = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &frontend_options); - - if (!frontend_options) { - PHALCON_INIT_VAR(frontend_options); - } - - phalcon_update_property_this_quick(this_ptr, SL("_frontendOptions"), frontend_options, 164501392UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); +// 2654 "parser.c" + break; + case 83: +// 1096 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_CONCAT, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(23,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Data, getLifetime){ - - zval *options, *lifetime; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_frontendOptions"), 164501392UL, PH_NOISY_CC); - if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_VAR(lifetime); - phalcon_array_fetch_quick_string(&lifetime, options, SS("lifetime"), 2639810228UL, PH_NOISY); - RETURN_CCTOR(lifetime); - } - } - - PHALCON_MM_RESTORE(); - RETURN_LONG(1); +// 2662 "parser.c" + break; + case 84: +// 1100 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_PIPE, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(25,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Data, isBuffering){ - - - RETURN_FALSE; +// 2670 "parser.c" + break; + case 85: +// 1104 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_RANGE, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(6,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Data, start){ - - - +// 2678 "parser.c" + break; + case 86: +// 1108 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_EQUALS, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(10,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Data, getContent){ - - - RETURN_NULL(); +// 2686 "parser.c" + break; + case 87: +// 1112 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_NOT_ISSET, kkmsp[-3].minor.kk132, NULL, NULL, status->scanner_state); + kk_destructor(9,&kkmsp[-2].minor); + kk_destructor(26,&kkmsp[-1].minor); + kk_destructor(73,&kkmsp[0].minor); +} +// 2696 "parser.c" + break; + case 88: +// 1116 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ISSET, kkmsp[-2].minor.kk132, NULL, NULL, status->scanner_state); + kk_destructor(9,&kkmsp[-1].minor); + kk_destructor(73,&kkmsp[0].minor); +} +// 2705 "parser.c" + break; + case 89: +// 1120 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_IS, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(9,&kkmsp[-1].minor); +} +// 2713 "parser.c" + break; + case 90: +// 1124 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_NOTEQUALS, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(11,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Data, stop){ - - - +// 2721 "parser.c" + break; + case 91: +// 1128 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_IDENTICAL, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(16,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Data, beforeStore){ - - zval *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &data); - - phalcon_serialize(return_value, &data TSRMLS_CC); - RETURN_MM(); +// 2729 "parser.c" + break; + case 92: +// 1132 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_NOTIDENTICAL, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(17,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Data, afterRetrieve){ - - zval *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &data); - - phalcon_unserialize(return_value, data TSRMLS_CC); - RETURN_MM(); +// 2737 "parser.c" + break; + case 93: +// 1136 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_LESS, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(12,&kkmsp[-1].minor); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_Json){ - - PHALCON_REGISTER_CLASS(Phalcon\\Cache\\Frontend, Json, cache_frontend_json, phalcon_cache_frontend_json_method_entry, 0); - - zend_declare_property_null(phalcon_cache_frontend_json_ce, SL("_frontendOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_cache_frontend_json_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); - - return SUCCESS; +// 2745 "parser.c" + break; + case 94: +// 1140 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_GREATER, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(13,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Json, __construct){ - - zval *frontend_options = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &frontend_options); - - if (!frontend_options) { - PHALCON_INIT_VAR(frontend_options); - } - - phalcon_update_property_this_quick(this_ptr, SL("_frontendOptions"), frontend_options, 164501392UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); +// 2753 "parser.c" + break; + case 95: +// 1144 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_GREATEREQUAL, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(14,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Json, getLifetime){ - - zval *options, *lifetime; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_frontendOptions"), 164501392UL, PH_NOISY_CC); - if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_VAR(lifetime); - phalcon_array_fetch_quick_string(&lifetime, options, SS("lifetime"), 2639810228UL, PH_NOISY); - RETURN_CCTOR(lifetime); - } - } - - PHALCON_MM_RESTORE(); - RETURN_LONG(1); +// 2761 "parser.c" + break; + case 96: +// 1148 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_LESSEQUAL, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(15,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Json, isBuffering){ - - - RETURN_FALSE; +// 2769 "parser.c" + break; + case 97: +// 1152 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_DOT, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(30,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Json, start){ - - - +// 2777 "parser.c" + break; + case 98: +// 1156 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_IN, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(3,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Json, getContent){ - - - RETURN_NULL(); +// 2785 "parser.c" + break; + case 99: +// 1160 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_NOT_IN, kkmsp[-3].minor.kk132, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(26,&kkmsp[-2].minor); + kk_destructor(3,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Json, stop){ - - - +// 2794 "parser.c" + break; + case 100: +// 1164 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_NOT, NULL, kkmsp[0].minor.kk132, NULL, status->scanner_state); + kk_destructor(26,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Json, beforeStore){ - - zval *data; - - phalcon_fetch_params(1, 1, 0, &data); - - phalcon_json_encode(return_value, data, 0 TSRMLS_CC); +// 2802 "parser.c" + break; + case 101: +// 1168 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_INCR, kkmsp[-1].minor.kk132, NULL, NULL, status->scanner_state); + kk_destructor(27,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Json, afterRetrieve){ - - zval *data; - - phalcon_fetch_params(1, 1, 0, &data); - - phalcon_json_decode(return_value, data, 0 TSRMLS_CC); +// 2810 "parser.c" + break; + case 102: +// 1172 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_DECR, kkmsp[-1].minor.kk132, NULL, NULL, status->scanner_state); + kk_destructor(28,&kkmsp[0].minor); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_Output){ - - PHALCON_REGISTER_CLASS(Phalcon\\Cache\\Frontend, Output, cache_frontend_output, phalcon_cache_frontend_output_method_entry, 0); - - zend_declare_property_bool(phalcon_cache_frontend_output_ce, SL("_buffering"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cache_frontend_output_ce, SL("_frontendOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_cache_frontend_output_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); - - return SUCCESS; +// 2818 "parser.c" + break; + case 103: +// 1176 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ENCLOSED, kkmsp[-1].minor.kk132, NULL, NULL, status->scanner_state); + kk_destructor(29,&kkmsp[-2].minor); + kk_destructor(47,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Output, __construct){ - - zval *frontend_options = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &frontend_options); - - if (!frontend_options) { - PHALCON_INIT_VAR(frontend_options); - } - - phalcon_update_property_this_quick(this_ptr, SL("_frontendOptions"), frontend_options, 164501392UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); +// 2827 "parser.c" + break; + case 104: +// 1180 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ARRAY, NULL, NULL, NULL, status->scanner_state); + kk_destructor(24,&kkmsp[-1].minor); + kk_destructor(74,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Output, getLifetime){ - - zval *options, *lifetime; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_frontendOptions"), 164501392UL, PH_NOISY_CC); - if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_VAR(lifetime); - phalcon_array_fetch_quick_string(&lifetime, options, SS("lifetime"), 2639810228UL, PH_NOISY); - RETURN_CCTOR(lifetime); - } - } - - PHALCON_MM_RESTORE(); - RETURN_LONG(1); +// 2836 "parser.c" + break; + case 105: +// 1184 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ARRAY, kkmsp[-1].minor.kk132, NULL, NULL, status->scanner_state); + kk_destructor(24,&kkmsp[-2].minor); + kk_destructor(74,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Output, isBuffering){ - - - RETURN_MEMBER_QUICK(this_ptr, "_buffering", 4086213532UL); +// 2845 "parser.c" + break; + case 106: +// 1188 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ARRAY, NULL, NULL, NULL, status->scanner_state); + kk_destructor(75,&kkmsp[-1].minor); + kk_destructor(76,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Output, start){ - - - PHALCON_MM_GROW(); - - phalcon_update_property_bool(this_ptr, SL("_buffering"), 1 TSRMLS_CC); - phalcon_ob_start(TSRMLS_C); - - PHALCON_MM_RESTORE(); +// 2854 "parser.c" + break; + case 107: +// 1192 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ARRAY, kkmsp[-1].minor.kk132, NULL, NULL, status->scanner_state); + kk_destructor(75,&kkmsp[-2].minor); + kk_destructor(76,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Output, getContent){ - - zval *buffering; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(buffering); - phalcon_read_property_this_quick(&buffering, this_ptr, SL("_buffering"), 4086213532UL, PH_NOISY_CC); - if (zend_is_true(buffering)) { - phalcon_ob_get_contents(return_value TSRMLS_CC); - RETURN_MM(); - } - - RETURN_MM_NULL(); +// 2863 "parser.c" + break; + case 108: +// 1196 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_ARRAYACCESS, kkmsp[-3].minor.kk132, kkmsp[-1].minor.kk132, NULL, status->scanner_state); + kk_destructor(24,&kkmsp[-2].minor); + kk_destructor(74,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Output, stop){ - - zval *buffering; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(buffering); - phalcon_read_property_this_quick(&buffering, this_ptr, SL("_buffering"), 4086213532UL, PH_NOISY_CC); - if (zend_is_true(buffering)) { - phalcon_ob_end_clean(TSRMLS_C); - } - - phalcon_update_property_bool(this_ptr, SL("_buffering"), 0 TSRMLS_CC); - - PHALCON_MM_RESTORE(); +// 2872 "parser.c" + break; + case 109: +// 1200 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_expr(PHVOLT_T_TERNARY, kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132, kkmsp[-4].minor.kk132, status->scanner_state); + kk_destructor(4,&kkmsp[-3].minor); + kk_destructor(5,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Output, beforeStore){ - - zval *data; - - phalcon_fetch_params(0, 1, 0, &data); - - RETURN_CCTORW(data); +// 2881 "parser.c" + break; + case 110: +// 1204 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_slice(kkmsp[-4].minor.kk132, NULL, kkmsp[-1].minor.kk132, status->scanner_state); + kk_destructor(24,&kkmsp[-3].minor); + kk_destructor(5,&kkmsp[-2].minor); + kk_destructor(74,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_Output, afterRetrieve){ - - zval *data; - - phalcon_fetch_params(0, 1, 0, &data); - - RETURN_CCTORW(data); +// 2891 "parser.c" + break; + case 111: +// 1208 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_slice(kkmsp[-4].minor.kk132, kkmsp[-2].minor.kk132, NULL, status->scanner_state); + kk_destructor(24,&kkmsp[-3].minor); + kk_destructor(5,&kkmsp[-1].minor); + kk_destructor(74,&kkmsp[0].minor); } - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_None){ - - PHALCON_REGISTER_CLASS(Phalcon\\Cache\\Frontend, None, cache_frontend_none, phalcon_cache_frontend_none_method_entry, 0); - - zend_class_implements(phalcon_cache_frontend_none_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); - - return SUCCESS; +// 2901 "parser.c" + break; + case 112: +// 1212 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_slice(kkmsp[-5].minor.kk132, kkmsp[-3].minor.kk132, kkmsp[-1].minor.kk132, status->scanner_state); + kk_destructor(24,&kkmsp[-4].minor); + kk_destructor(5,&kkmsp[-2].minor); + kk_destructor(74,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_None, getLifetime){ - - - RETURN_LONG(1); +// 2911 "parser.c" + break; + case 114: + case 126: +// 1222 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_IDENTIFIER, kkmsp[0].minor.kk0, status->scanner_state); } - -static PHP_METHOD(Phalcon_Cache_Frontend_None, isBuffering){ - - - RETURN_FALSE; +// 2919 "parser.c" + break; + case 117: + case 125: +// 1238 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_named_item(kkmsp[-2].minor.kk0, kkmsp[0].minor.kk132, status->scanner_state); + kk_destructor(5,&kkmsp[-1].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_None, start){ - - - +// 2928 "parser.c" + break; + case 118: + case 124: +// 1242 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_named_item(NULL, kkmsp[0].minor.kk132, status->scanner_state); } - -static PHP_METHOD(Phalcon_Cache_Frontend_None, getContent){ - - - +// 2936 "parser.c" + break; + case 120: +// 1252 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_func_call(kkmsp[-3].minor.kk132, kkmsp[-1].minor.kk132, status->scanner_state); + kk_destructor(29,&kkmsp[-2].minor); + kk_destructor(47,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_None, stop){ - - - +// 2945 "parser.c" + break; + case 121: +// 1256 "parser.lemon" +{ + kkgotominor.kk132 = phvolt_ret_func_call(kkmsp[-2].minor.kk132, NULL, status->scanner_state); + kk_destructor(29,&kkmsp[-1].minor); + kk_destructor(47,&kkmsp[0].minor); } - -static PHP_METHOD(Phalcon_Cache_Frontend_None, beforeStore){ - - zval *data; - - phalcon_fetch_params(0, 1, 0, &data); - - RETURN_CCTORW(data); +// 2954 "parser.c" + break; + }; + kkgoto = kkRuleInfo[kkruleno].lhs; + kksize = kkRuleInfo[kkruleno].nrhs; + kkpParser->kkidx -= kksize; + kkact = kk_find_reduce_action(kkpParser,kkgoto); + if( kkact < KKNSTATE ){ + kk_shift(kkpParser,kkact,kkgoto,&kkgotominor); + }else if( kkact == KKNSTATE + KKNRULE + 1 ){ + kk_accept(kkpParser); + } } -static PHP_METHOD(Phalcon_Cache_Frontend_None, afterRetrieve){ - - zval *data; - - phalcon_fetch_params(0, 1, 0, &data); - - RETURN_CCTORW(data); +static void kk_parse_failed( + kkParser *kkpParser /* The parser */ +){ + phvolt_ARG_FETCH; +#ifndef NDEBUG + if( kkTraceFILE ){ + fprintf(kkTraceFILE,"%sFail!\n",kkTracePrompt); + } +#endif + while( kkpParser->kkidx>=0 ) kk_pop_parser_stack(kkpParser); + /* Here code is inserted which will be executed whenever the + ** parser fails */ + phvolt_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ } +static void kk_syntax_error( + kkParser *kkpParser, /* The parser */ + int kkmajor, /* The major type of the error token */ + KKMINORTYPE kkminor /* The minor type of the error token */ +){ + phvolt_ARG_FETCH; +#define KTOKEN (kkminor.kk0) +// 605 "parser.lemon" + { + smart_str error_str = {0}; + char *token_name = NULL; + const phvolt_token_names *tokens = phvolt_tokens; + int token_len = 0; + int active_token = status->scanner_state->active_token; -#ifdef HAVE_CONFIG_H -#endif - + if (status->scanner_state->start_length) { + if (active_token) { + do { + if (tokens->code == active_token) { + token_name = tokens->name; + token_len = tokens->len; + break; + } + ++tokens; + } while (tokens[0].code != 0); + } + smart_str_appendl(&error_str, "Syntax error, unexpected token ", sizeof("Syntax error, unexpected token ") - 1); + if (!token_name) { + smart_str_appendl(&error_str, "UNKNOWN", sizeof("UNKNOWN") - 1); + } else { + smart_str_appendl(&error_str, token_name, token_len); + } + if (status->token->value) { + smart_str_appendc(&error_str, '('); + smart_str_appendl(&error_str, status->token->value, status->token->len); + smart_str_appendc(&error_str, ')'); + } + smart_str_appendl(&error_str, " in ", sizeof(" in ") - 1); + smart_str_appendl(&error_str, Z_STRVAL_P(status->scanner_state->active_file), Z_STRLEN_P(status->scanner_state->active_file)); + smart_str_appendl(&error_str, " on line ", sizeof(" on line ") - 1); + { + char stmp[MAX_LENGTH_OF_LONG + 1]; + int str_len; + str_len = slprintf(stmp, sizeof(stmp), "%ld", status->scanner_state->active_line); + smart_str_appendl(&error_str, stmp, str_len); + } + } else { -PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_Igbinary){ + smart_str_appendl(&error_str, "Syntax error, unexpected EOF in ", sizeof("Syntax error, unexpected EOF in ") - 1); + smart_str_appendl(&error_str, Z_STRVAL_P(status->scanner_state->active_file), Z_STRLEN_P(status->scanner_state->active_file)); - PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Frontend, Igbinary, cache_frontend_igbinary, "phalcon\\cache\\frontend\\data", phalcon_cache_frontend_igbinary_method_entry, 0); + /* Report unclosed 'if' blocks */ + if ((status->scanner_state->if_level + status->scanner_state->old_if_level) > 0) { + if ((status->scanner_state->if_level + status->scanner_state->old_if_level) == 1) { + smart_str_appendl(&error_str, ", there is one 'if' block without close", sizeof(", there is one 'if' block without close") - 1); + } else { + smart_str_appendl(&error_str, ", there are ", sizeof(", there are ") - 1); + { + char stmp[MAX_LENGTH_OF_LONG + 1]; + int str_len; + str_len = slprintf(stmp, sizeof(stmp), "%ld", status->scanner_state->if_level + status->scanner_state->old_if_level); + smart_str_appendl(&error_str, stmp, str_len); + } + smart_str_appendl(&error_str, " 'if' blocks without close", sizeof(" 'if' blocks without close") - 1); + } + } - zend_class_implements(phalcon_cache_frontend_igbinary_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); + /* Report unclosed 'for' blocks */ + if (status->scanner_state->for_level > 0) { + if (status->scanner_state->for_level == 1) { + smart_str_appendl(&error_str, ", there is one 'for' block without close", sizeof(", there is one 'for' block without close") - 1); + } else { + smart_str_appendl(&error_str, ", there are ", sizeof(", there are ") - 1); + { + char stmp[MAX_LENGTH_OF_LONG + 1]; + int str_len; + str_len = slprintf(stmp, sizeof(stmp), "%ld", status->scanner_state->if_level); + smart_str_appendl(&error_str, stmp, str_len); + } + smart_str_appendl(&error_str, " 'for' blocks without close", sizeof(" 'for' blocks without close") - 1); + } + } + } - return SUCCESS; -} + smart_str_0(&error_str); -static PHP_METHOD(Phalcon_Cache_Frontend_Igbinary, beforeStore){ + if (error_str.len) { + status->syntax_error = error_str.c; + status->syntax_error_len = error_str.len; + } else { + status->syntax_error = NULL; + } - zval *data; + } - PHALCON_MM_GROW(); + status->status = PHVOLT_PARSING_FAILED; - phalcon_fetch_params(1, 1, 0, &data); - - phalcon_call_func_p1(return_value, "igbinary_serialize", data); - RETURN_MM(); +// 3094 "parser.c" + phvolt_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ } -static PHP_METHOD(Phalcon_Cache_Frontend_Igbinary, afterRetrieve){ - - zval *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &data); - - phalcon_call_func_p1(return_value, "igbinary_unserialize", data); - RETURN_MM(); +static void kk_accept( + kkParser *kkpParser /* The parser */ +){ + phvolt_ARG_FETCH; +#ifndef NDEBUG + if( kkTraceFILE ){ + fprintf(kkTraceFILE,"%sAccept!\n",kkTracePrompt); + } +#endif + while( kkpParser->kkidx>=0 ) kk_pop_parser_stack(kkpParser); + /* Here code is inserted which will be executed whenever the + ** parser accepts */ + phvolt_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ } +/* The main parser program. +** The first argument is a pointer to a structure obtained from +** "phvolt_Alloc" which describes the current state of the parser. +** The second argument is the major token number. The third is +** the minor token. The fourth optional argument is whatever the +** user wants (and specified in the grammar) and is available for +** use by the action routines. +** +** Inputs: +**
    +**
  • A pointer to the parser (an opaque structure.) +**
  • The major token number. +**
  • The minor token number. +**
  • An option argument of a grammar-specified type. +**
+** +** Outputs: +** None. +*/ +static void phvolt_( + void *kkp, /* The parser */ + int kkmajor, /* The major token code number */ + phvolt_KTOKENTYPE kkminor /* The value for the token */ + phvolt_ARG_PDECL /* Optional %extra_argument parameter */ +){ + KKMINORTYPE kkminorunion; + int kkact; /* The parser action. */ + int kkendofinput; /* True if we are at the end of input */ + int kkerrorhit = 0; /* True if kkmajor has invoked an error */ + kkParser *kkpParser; /* The parser */ + /* (re)initialize the parser, if necessary */ + kkpParser = (kkParser*)kkp; + if( kkpParser->kkidx<0 ){ + if( kkmajor==0 ) return; + kkpParser->kkidx = 0; + kkpParser->kkerrcnt = -1; + kkpParser->kkstack[0].stateno = 0; + kkpParser->kkstack[0].major = 0; + } + kkminorunion.kk0 = kkminor; + kkendofinput = (kkmajor==0); + phvolt_ARG_STORE; - - -#ifdef HAVE_CONFIG_H +#ifndef NDEBUG + if( kkTraceFILE ){ + fprintf(kkTraceFILE,"%sInput %s\n",kkTracePrompt,kkTokenName[kkmajor]); + } #endif + do{ + kkact = kk_find_shift_action(kkpParser,kkmajor); + if( kkactkkerrcnt--; + if( kkendofinput && kkpParser->kkidx>=0 ){ + kkmajor = 0; + }else{ + kkmajor = KKNOCODE; + } + }else if( kkact < KKNSTATE + KKNRULE ){ + kk_reduce(kkpParser,kkact-KKNSTATE); + }else if( kkact == KK_ERROR_ACTION ){ + int kkmx; +#ifndef NDEBUG + if( kkTraceFILE ){ + fprintf(kkTraceFILE,"%sSyntax Error!\n",kkTracePrompt); + } +#endif +#ifdef KKERRORSYMBOL + /* A syntax error has occurred. + ** The response to an error depends upon whether or not the + ** grammar defines an error token "ERROR". + ** + ** This is what we do if the grammar does define ERROR: + ** + ** * Call the %syntax_error function. + ** + ** * Begin popping the stack until we enter a state where + ** it is legal to shift the error symbol, then shift + ** the error symbol. + ** + ** * Set the error count to three. + ** + ** * Begin accepting and shifting new tokens. No new error + ** processing will occur until three tokens have been + ** shifted successfully. + ** + */ + if( kkpParser->kkerrcnt<0 ){ + kk_syntax_error(kkpParser,kkmajor,kkminorunion); + } + kkmx = kkpParser->kkstack[kkpParser->kkidx].major; + if( kkmx==KKERRORSYMBOL || kkerrorhit ){ +#ifndef NDEBUG + if( kkTraceFILE ){ + fprintf(kkTraceFILE,"%sDiscard input token %s\n", + kkTracePrompt,kkTokenName[kkmajor]); + } +#endif + kk_destructor(kkmajor,&kkminorunion); + kkmajor = KKNOCODE; + }else{ + while( + kkpParser->kkidx >= 0 && + kkmx != KKERRORSYMBOL && + (kkact = kk_find_shift_action(kkpParser,KKERRORSYMBOL)) >= KKNSTATE + ){ + kk_pop_parser_stack(kkpParser); + } + if( kkpParser->kkidx < 0 || kkmajor==0 ){ + kk_destructor(kkmajor,&kkminorunion); + kk_parse_failed(kkpParser); + kkmajor = KKNOCODE; + }else if( kkmx!=KKERRORSYMBOL ){ + KKMINORTYPE u2; + u2.KKERRSYMDT = 0; + kk_shift(kkpParser,kkact,KKERRORSYMBOL,&u2); + } + } + kkpParser->kkerrcnt = 3; + kkerrorhit = 1; +#else /* KKERRORSYMBOL is not defined */ + /* This is what we do if the grammar does not define ERROR: + ** + ** * Report an error message, and throw away the input token. + ** + ** * If the input token is $, then fail the parse. + ** + ** As before, subsequent error messages are suppressed until + ** three input tokens have been successfully shifted. + */ + if( kkpParser->kkerrcnt<=0 ){ + kk_syntax_error(kkpParser,kkmajor,kkminorunion); + } + kkpParser->kkerrcnt = 3; + kk_destructor(kkmajor,&kkminorunion); + if( kkendofinput ){ + kk_parse_failed(kkpParser); + } + kkmajor = KKNOCODE; +#endif + }else{ + kk_accept(kkpParser); + kkmajor = KKNOCODE; + } + }while( kkmajor!=KKNOCODE && kkpParser->kkidx>=0 ); + return; +} +const phvolt_token_names phvolt_tokens[] = +{ + { SL("INTEGER"), PHVOLT_T_INTEGER }, + { SL("DOUBLE"), PHVOLT_T_DOUBLE }, + { SL("STRING"), PHVOLT_T_STRING }, + { SL("IDENTIFIER"), PHVOLT_T_IDENTIFIER }, + { SL("MINUS"), PHVOLT_T_MINUS }, + { SL("+"), PHVOLT_T_ADD }, + { SL("-"), PHVOLT_T_SUB }, + { SL("*"), PHVOLT_T_MUL }, + { SL("/"), PHVOLT_T_DIV }, + { SL("%%"), PHVOLT_T_MOD }, + { SL("!"), PHVOLT_T_NOT }, + { SL("~"), PHVOLT_T_CONCAT }, + { SL("AND"), PHVOLT_T_AND }, + { SL("OR"), PHVOLT_T_OR }, + { SL("DOT"), PHVOLT_T_DOT }, + { SL("COMMA"), PHVOLT_T_COMMA }, + { SL("EQUALS"), PHVOLT_T_EQUALS }, + { SL("NOT EQUALS"), PHVOLT_T_NOTEQUALS }, + { SL("IDENTICAL"), PHVOLT_T_IDENTICAL }, + { SL("NOT IDENTICAL"), PHVOLT_T_NOTIDENTICAL }, + { SL("NOT"), PHVOLT_T_NOT }, + { SL("RANGE"), PHVOLT_T_RANGE }, + { SL("COLON"), PHVOLT_T_COLON }, + { SL("QUESTION MARK"), PHVOLT_T_QUESTION }, + { SL("<"), PHVOLT_T_LESS }, + { SL("<="), PHVOLT_T_LESSEQUAL }, + { SL(">"), PHVOLT_T_GREATER }, + { SL(">="), PHVOLT_T_GREATEREQUAL }, + { SL("("), PHVOLT_T_PARENTHESES_OPEN }, + { SL(")"), PHVOLT_T_PARENTHESES_CLOSE }, + { SL("["), PHVOLT_T_SBRACKET_OPEN }, + { SL("]"), PHVOLT_T_SBRACKET_CLOSE }, + { SL("{"), PHVOLT_T_CBRACKET_OPEN }, + { SL("}"), PHVOLT_T_CBRACKET_CLOSE }, + { SL("{%"), PHVOLT_T_OPEN_DELIMITER }, + { SL("%}"), PHVOLT_T_CLOSE_DELIMITER }, + { SL("{{"), PHVOLT_T_OPEN_EDELIMITER }, + { SL("}}"), PHVOLT_T_CLOSE_EDELIMITER }, + { SL("IF"), PHVOLT_T_IF }, + { SL("ELSE"), PHVOLT_T_ELSE }, + { SL("ELSEIF"), PHVOLT_T_ELSEIF }, + { SL("ELSEFOR"), PHVOLT_T_ELSEFOR }, + { SL("ENDIF"), PHVOLT_T_ENDIF }, + { SL("FOR"), PHVOLT_T_FOR }, + { SL("IN"), PHVOLT_T_IN }, + { SL("ENDFOR"), PHVOLT_T_ENDFOR }, + { SL("SET"), PHVOLT_T_SET }, + { SL("ASSIGN"), PHVOLT_T_ASSIGN }, + { SL("+="), PHVOLT_T_ADD_ASSIGN }, + { SL("-="), PHVOLT_T_SUB_ASSIGN }, + { SL("*="), PHVOLT_T_MUL_ASSIGN }, + { SL("/="), PHVOLT_T_DIV_ASSIGN }, + { SL("++"), PHVOLT_T_INCR }, + { SL("--"), PHVOLT_T_DECR }, + { SL("BLOCK"), PHVOLT_T_BLOCK }, + { SL("ENDBLOCK"), PHVOLT_T_ENDBLOCK }, + { SL("CACHE"), PHVOLT_T_CACHE }, + { SL("ENDCACHE"), PHVOLT_T_ENDCACHE }, + { SL("EXTENDS"), PHVOLT_T_EXTENDS }, + { SL("IS"), PHVOLT_T_IS }, + { SL("DEFINED"), PHVOLT_T_DEFINED }, + { SL("INCLUDE"), PHVOLT_T_INCLUDE }, + { SL("DO"), PHVOLT_T_DO }, + { SL("WHITESPACE"), PHVOLT_T_IGNORE }, + { SL("AUTOESCAPE"), PHVOLT_T_AUTOESCAPE }, + { SL("ENDAUTOESCAPE"), PHVOLT_T_ENDAUTOESCAPE }, + { SL("CONTINUE"), PHVOLT_T_CONTINUE }, + { SL("BREAK"), PHVOLT_T_BREAK }, + { SL("WITH"), PHVOLT_T_WITH }, + { SL("RETURN"), PHVOLT_T_RETURN }, + { NULL, 0, 0 } +}; +static void *phvolt_wrapper_alloc(size_t bytes){ + return emalloc(bytes); +} +static void phvolt_wrapper_free(void *pointer){ + efree(pointer); +} +static void phvolt_parse_with_token(void* phvolt_parser, int opcode, int parsercode, phvolt_scanner_token *token, phvolt_parser_status *parser_status){ -PHALCON_INIT_CLASS(Phalcon_Cache_Frontend_Base64){ - - PHALCON_REGISTER_CLASS(Phalcon\\Cache\\Frontend, Base64, cache_frontend_base64, phalcon_cache_frontend_base64_method_entry, 0); + phvolt_parser_token *pToken; - zend_declare_property_null(phalcon_cache_frontend_base64_ce, SL("_frontendOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); + pToken = emalloc(sizeof(phvolt_parser_token)); + pToken->opcode = opcode; + pToken->token = token->value; + pToken->token_len = token->len; + pToken->free_flag = 1; - zend_class_implements(phalcon_cache_frontend_base64_ce TSRMLS_CC, 1, phalcon_cache_frontendinterface_ce); + phvolt_(phvolt_parser, parsercode, pToken, parser_status); - return SUCCESS; + token->value = NULL; + token->len = 0; } -static PHP_METHOD(Phalcon_Cache_Frontend_Base64, __construct){ +static void phvolt_create_error_msg(phvolt_parser_status *parser_status, char *message){ - zval *frontend_options = NULL; + unsigned int length = (128 + Z_STRLEN_P(parser_status->scanner_state->active_file)); + char *str = emalloc(sizeof(char) * length); - PHALCON_MM_GROW(); + snprintf(str, length, "%s in %s on line %d", message, Z_STRVAL_P(parser_status->scanner_state->active_file), parser_status->scanner_state->active_line); + str[length - 1] = '\0'; - phalcon_fetch_params(1, 0, 1, &frontend_options); - - if (!frontend_options) { - PHALCON_INIT_VAR(frontend_options); - } - - phalcon_update_property_this_quick(this_ptr, SL("_frontendOptions"), frontend_options, 164501392UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); + parser_status->syntax_error = estrndup(str, strlen(str)); + efree(str); } -static PHP_METHOD(Phalcon_Cache_Frontend_Base64, getLifetime){ - - zval *options, *lifetime; +static void phvolt_scanner_error_msg(phvolt_parser_status *parser_status, zval **error_msg TSRMLS_DC){ - PHALCON_MM_GROW(); + char *error, *error_part; + int length; + phvolt_scanner_state *state = parser_status->scanner_state; - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_frontendOptions"), 164501392UL, PH_NOISY_CC); - if (Z_TYPE_P(options) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_VAR(lifetime); - phalcon_array_fetch_quick_string(&lifetime, options, SS("lifetime"), 2639810228UL, PH_NOISY); - RETURN_CCTOR(lifetime); + PHALCON_INIT_VAR(*error_msg); + if (state->start) { + error = emalloc(sizeof(char) * 72 + state->start_length + Z_STRLEN_P(state->active_file)); + if (state->start_length > 16) { + length = 72 + Z_STRLEN_P(state->active_file); + error_part = estrndup(state->start, 16); + snprintf(error, length, "Scanning error before '%s...' in %s on line %d", error_part, Z_STRVAL_P(state->active_file), state->active_line); + error[length - 1] = '\0'; + } else { + length = 48 + state->start_length + Z_STRLEN_P(state->active_file); + snprintf(error, length, "Scanning error before '%s' in %s on line %d", state->start, Z_STRVAL_P(state->active_file), state->active_line); } + } else { + error = emalloc(sizeof(char) * (32 + Z_STRLEN_P(state->active_file))); + length = 32 + Z_STRLEN_P(state->active_file); + snprintf(error, length, "Scanning error near to EOF in %s", Z_STRVAL_P(state->active_file)); } - - PHALCON_MM_RESTORE(); - RETURN_LONG(1); -} - -static PHP_METHOD(Phalcon_Cache_Frontend_Base64, isBuffering){ - - - RETURN_FALSE; -} - -static PHP_METHOD(Phalcon_Cache_Frontend_Base64, start){ - - - -} -static PHP_METHOD(Phalcon_Cache_Frontend_Base64, getContent){ - - - RETURN_NULL(); + error[length - 1] = '\0'; + ZVAL_STRING(*error_msg, error, 1); + efree(error); } -static PHP_METHOD(Phalcon_Cache_Frontend_Base64, stop){ - +static int phvolt_parse_view(zval *result, zval *view_code, zval *template_path TSRMLS_DC){ - -} + zval *error_msg = NULL; -static PHP_METHOD(Phalcon_Cache_Frontend_Base64, beforeStore){ + ZVAL_NULL(result); - zval *data; + if (Z_TYPE_P(view_code) != IS_STRING) { + phalcon_throw_exception_string(phalcon_mvc_view_exception_ce, SL("View code must be a string"), 1 TSRMLS_CC); + return FAILURE; + } - PHALCON_MM_GROW(); + if (phvolt_internal_parse_view(&result, view_code, template_path, &error_msg TSRMLS_CC) == FAILURE) { + phalcon_throw_exception_string(phalcon_mvc_view_exception_ce, Z_STRVAL_P(error_msg), Z_STRLEN_P(error_msg), 1 TSRMLS_CC); + return FAILURE; + } - phalcon_fetch_params(1, 1, 0, &data); - - phalcon_base64_encode(return_value, data); - RETURN_MM(); + return SUCCESS; } -static PHP_METHOD(Phalcon_Cache_Frontend_Base64, afterRetrieve){ - - zval *data; - - PHALCON_MM_GROW(); +static int phvolt_is_blank_string(phvolt_scanner_token *token){ - phalcon_fetch_params(1, 1, 0, &data); - - phalcon_base64_decode(return_value, data); - RETURN_MM(); -} + char *marker = token->value; + unsigned int ch, i; + for (i = 0; i < token->len; i++) { + ch = *marker; + if (ch != ' ' && ch != '\t' && ch != '\n' && ch != '\r' && ch != 11) { + return 0; + } + marker++; + } + return 1; +} +static int phvolt_internal_parse_view(zval **result, zval *view_code, zval *template_path, zval **error_msg TSRMLS_DC) { + char *error; + phvolt_scanner_state *state; + phvolt_scanner_token token; + int scanner_status, status = SUCCESS; + phvolt_parser_status *parser_status = NULL; + void* phvolt_parser; -#ifdef HAVE_CONFIG_H -#endif + /** Check if the view has code */ + if (!Z_STRVAL_P(view_code)) { + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, "View code cannot be null", 1); + return FAILURE; + } + if (!Z_STRLEN_P(view_code)) { + array_init(*result); + return SUCCESS; + } + /** Start the reentrant parser */ + phvolt_parser = phvolt_Alloc(phvolt_wrapper_alloc); + parser_status = emalloc(sizeof(phvolt_parser_status)); + state = emalloc(sizeof(phvolt_scanner_state)); + parser_status->status = PHVOLT_PARSING_OK; + parser_status->scanner_state = state; + parser_status->ret = NULL; + parser_status->token = &token; + parser_status->syntax_error = NULL; + /** Initialize the scanner state */ + state->active_token = 0; + state->start = Z_STRVAL_P(view_code); + state->mode = PHVOLT_MODE_RAW; + state->raw_buffer = emalloc(sizeof(char) * PHVOLT_RAW_BUFFER_SIZE); + state->raw_buffer_size = PHVOLT_RAW_BUFFER_SIZE; + state->raw_buffer_cursor = 0; + state->active_file = template_path; + state->active_line = 1; + state->statement_position = 0; + state->extends_mode = 0; + state->block_level = 0; + state->macro_level = 0; + state->start_length = 0; + state->old_if_level = 0; + state->if_level = 0; + state->for_level = 0; + state->whitespace_control = 0; + state->end = state->start; -PHALCON_INIT_CLASS(Phalcon_Cache_Backend_Memcache){ + token.value = NULL; + token.len = 0; - PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, Memcache, cache_backend_memcache, "phalcon\\cache\\backend", phalcon_cache_backend_memcache_method_entry, 0); + while (0 <= (scanner_status = phvolt_get_token(state, &token))) { - zend_declare_property_null(phalcon_cache_backend_memcache_ce, SL("_memcache"), ZEND_ACC_PROTECTED TSRMLS_CC); + state->active_token = token.opcode; - zend_class_implements(phalcon_cache_backend_memcache_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); + state->start_length = (Z_STRVAL_P(view_code) + Z_STRLEN_P(view_code) - state->start); - return SUCCESS; -} + switch (token.opcode) { -static PHP_METHOD(Phalcon_Cache_Backend_Memcache, __construct){ + case PHVOLT_T_IGNORE: + break; - zval *frontend, *options = NULL; + case PHVOLT_T_ADD: + phvolt_(phvolt_parser, PHVOLT_PLUS, NULL, parser_status); + break; + case PHVOLT_T_SUB: + phvolt_(phvolt_parser, PHVOLT_MINUS, NULL, parser_status); + break; + case PHVOLT_T_MUL: + phvolt_(phvolt_parser, PHVOLT_TIMES, NULL, parser_status); + break; + case PHVOLT_T_DIV: + phvolt_(phvolt_parser, PHVOLT_DIVIDE, NULL, parser_status); + break; + case PHVOLT_T_MOD: + phvolt_(phvolt_parser, PHVOLT_MOD, NULL, parser_status); + break; + case PHVOLT_T_AND: + phvolt_(phvolt_parser, PHVOLT_AND, NULL, parser_status); + break; + case PHVOLT_T_OR: + phvolt_(phvolt_parser, PHVOLT_OR, NULL, parser_status); + break; + case PHVOLT_T_IS: + phvolt_(phvolt_parser, PHVOLT_IS, NULL, parser_status); + break; + case PHVOLT_T_EQUALS: + phvolt_(phvolt_parser, PHVOLT_EQUALS, NULL, parser_status); + break; + case PHVOLT_T_NOTEQUALS: + phvolt_(phvolt_parser, PHVOLT_NOTEQUALS, NULL, parser_status); + break; + case PHVOLT_T_LESS: + phvolt_(phvolt_parser, PHVOLT_LESS, NULL, parser_status); + break; + case PHVOLT_T_GREATER: + phvolt_(phvolt_parser, PHVOLT_GREATER, NULL, parser_status); + break; + case PHVOLT_T_GREATEREQUAL: + phvolt_(phvolt_parser, PHVOLT_GREATEREQUAL, NULL, parser_status); + break; + case PHVOLT_T_LESSEQUAL: + phvolt_(phvolt_parser, PHVOLT_LESSEQUAL, NULL, parser_status); + break; + case PHVOLT_T_IDENTICAL: + phvolt_(phvolt_parser, PHVOLT_IDENTICAL, NULL, parser_status); + break; + case PHVOLT_T_NOTIDENTICAL: + phvolt_(phvolt_parser, PHVOLT_NOTIDENTICAL, NULL, parser_status); + break; + case PHVOLT_T_NOT: + phvolt_(phvolt_parser, PHVOLT_NOT, NULL, parser_status); + break; + case PHVOLT_T_DOT: + phvolt_(phvolt_parser, PHVOLT_DOT, NULL, parser_status); + break; + case PHVOLT_T_CONCAT: + phvolt_(phvolt_parser, PHVOLT_CONCAT, NULL, parser_status); + break; + case PHVOLT_T_RANGE: + phvolt_(phvolt_parser, PHVOLT_RANGE, NULL, parser_status); + break; + case PHVOLT_T_PIPE: + phvolt_(phvolt_parser, PHVOLT_PIPE, NULL, parser_status); + break; + case PHVOLT_T_COMMA: + phvolt_(phvolt_parser, PHVOLT_COMMA, NULL, parser_status); + break; + case PHVOLT_T_COLON: + phvolt_(phvolt_parser, PHVOLT_COLON, NULL, parser_status); + break; + case PHVOLT_T_QUESTION: + phvolt_(phvolt_parser, PHVOLT_QUESTION, NULL, parser_status); + break; - PHALCON_MM_GROW(); + case PHVOLT_T_PARENTHESES_OPEN: + phvolt_(phvolt_parser, PHVOLT_PARENTHESES_OPEN, NULL, parser_status); + break; + case PHVOLT_T_PARENTHESES_CLOSE: + phvolt_(phvolt_parser, PHVOLT_PARENTHESES_CLOSE, NULL, parser_status); + break; + case PHVOLT_T_SBRACKET_OPEN: + phvolt_(phvolt_parser, PHVOLT_SBRACKET_OPEN, NULL, parser_status); + break; + case PHVOLT_T_SBRACKET_CLOSE: + phvolt_(phvolt_parser, PHVOLT_SBRACKET_CLOSE, NULL, parser_status); + break; + case PHVOLT_T_CBRACKET_OPEN: + phvolt_(phvolt_parser, PHVOLT_CBRACKET_OPEN, NULL, parser_status); + break; + case PHVOLT_T_CBRACKET_CLOSE: + phvolt_(phvolt_parser, PHVOLT_CBRACKET_CLOSE, NULL, parser_status); + break; - phalcon_fetch_params(1, 1, 1, &frontend, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } else { - PHALCON_SEPARATE_PARAM(options); - } - - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_INIT_NVAR(options); - array_init(options); - } - if (!phalcon_array_isset_quick_string(options, SS("host"), 261606083UL)) { - phalcon_array_update_string_string(&options, SL("host"), SL("127.0.0.1"), PH_SEPARATE); - } - - if (!phalcon_array_isset_quick_string(options, SS("port"), 271092362UL)) { - phalcon_array_update_string_string(&options, SL("port"), SL("11211"), PH_SEPARATE); - } - - if (!phalcon_array_isset_quick_string(options, SS("persistent"), 2222052598UL)) { - phalcon_array_update_string_bool(&options, SL("persistent"), 0, PH_SEPARATE); - } - - if (!phalcon_array_isset_quick_string(options, SS("statsKey"), 2508919229UL)) { - phalcon_array_update_string_string(&options, SL("statsKey"), SL("_PHCM"), PH_SEPARATE); - } - - PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\Memcache", "__construct", frontend, options); - - PHALCON_MM_RESTORE(); -} + case PHVOLT_T_OPEN_DELIMITER: + phvolt_(phvolt_parser, PHVOLT_OPEN_DELIMITER, NULL, parser_status); + break; + case PHVOLT_T_CLOSE_DELIMITER: + phvolt_(phvolt_parser, PHVOLT_CLOSE_DELIMITER, NULL, parser_status); + break; -static PHP_METHOD(Phalcon_Cache_Backend_Memcache, _connect){ + case PHVOLT_T_OPEN_EDELIMITER: + if (state->extends_mode == 1 && state->block_level == 0) { + phvolt_create_error_msg(parser_status, "Child templates only may contain blocks"); + parser_status->status = PHVOLT_PARSING_FAILED; + break; + } + phvolt_(phvolt_parser, PHVOLT_OPEN_EDELIMITER, NULL, parser_status); + break; + case PHVOLT_T_CLOSE_EDELIMITER: + phvolt_(phvolt_parser, PHVOLT_CLOSE_EDELIMITER, NULL, parser_status); + break; - zval *options, *memcache, *host, *port, *persistent; - zval *success; - zend_class_entry *ce0; + case PHVOLT_T_NULL: + phvolt_(phvolt_parser, PHVOLT_NULL, NULL, parser_status); + break; + case PHVOLT_T_TRUE: + phvolt_(phvolt_parser, PHVOLT_TRUE, NULL, parser_status); + break; + case PHVOLT_T_FALSE: + phvolt_(phvolt_parser, PHVOLT_FALSE, NULL, parser_status); + break; - PHALCON_MM_GROW(); + case PHVOLT_T_INTEGER: + phvolt_parse_with_token(phvolt_parser, PHVOLT_T_INTEGER, PHVOLT_INTEGER, &token, parser_status); + break; + case PHVOLT_T_DOUBLE: + phvolt_parse_with_token(phvolt_parser, PHVOLT_T_DOUBLE, PHVOLT_DOUBLE, &token, parser_status); + break; + case PHVOLT_T_STRING: + phvolt_parse_with_token(phvolt_parser, PHVOLT_T_STRING, PHVOLT_STRING, &token, parser_status); + break; + case PHVOLT_T_IDENTIFIER: + phvolt_parse_with_token(phvolt_parser, PHVOLT_T_IDENTIFIER, PHVOLT_IDENTIFIER, &token, parser_status); + break; - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - ce0 = zend_fetch_class(SL("Memcache"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - - PHALCON_INIT_VAR(memcache); - object_init_ex(memcache, ce0); - if (phalcon_has_constructor(memcache TSRMLS_CC)) { - phalcon_call_method_key(NULL, memcache, "__construct", 1107214344UL); - } - - PHALCON_OBS_VAR(host); - phalcon_array_fetch_quick_string(&host, options, SS("host"), 261606083UL, PH_NOISY); - - PHALCON_OBS_VAR(port); - phalcon_array_fetch_quick_string(&port, options, SS("port"), 271092362UL, PH_NOISY); - - PHALCON_OBS_VAR(persistent); - phalcon_array_fetch_quick_string(&persistent, options, SS("persistent"), 2222052598UL, PH_NOISY); + case PHVOLT_T_IF: + if (state->extends_mode == 1 && state->block_level == 0){ + phvolt_create_error_msg(parser_status, "Child templates only may contain blocks"); + parser_status->status = PHVOLT_PARSING_FAILED; + break; + } else { + state->if_level++; + state->block_level++; + } + phvolt_(phvolt_parser, PHVOLT_IF, NULL, parser_status); + break; - PHALCON_INIT_VAR(success); - if (zend_is_true(persistent)) { - phalcon_call_method_p2_key(success, memcache, "pconnect", host, port, 2937764031UL); - } else { - phalcon_call_method_p2_key(success, memcache, "connect", host, port, 1111492527UL); - } - - if (!zend_is_true(success)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cannot connect to Memcached server"); - return; - } - - phalcon_update_property_this_quick(this_ptr, SL("_memcache"), memcache, 958186231UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} + case PHVOLT_T_ELSE: + if (state->if_level == 0 && state->for_level > 0) { + phvolt_(phvolt_parser, PHVOLT_ELSEFOR, NULL, parser_status); + } else { + phvolt_(phvolt_parser, PHVOLT_ELSE, NULL, parser_status); + } + break; -static PHP_METHOD(Phalcon_Cache_Backend_Memcache, get){ + case PHVOLT_T_ELSEFOR: + phvolt_(phvolt_parser, PHVOLT_ELSEFOR, NULL, parser_status); + break; - zval *key_name, *lifetime = NULL, *memcache = NULL, *frontend; - zval *prefix, *prefixed_key, *cached_content; + case PHVOLT_T_ELSEIF: + if (state->if_level == 0) { + phvolt_create_error_msg(parser_status, "Unexpected ENDIF"); + parser_status->status = PHVOLT_PARSING_FAILED; + break; + } + phvolt_(phvolt_parser, PHVOLT_ELSEIF, NULL, parser_status); + break; - PHALCON_MM_GROW(); + case PHVOLT_T_ENDIF: + state->block_level--; + state->if_level--; + phvolt_(phvolt_parser, PHVOLT_ENDIF, NULL, parser_status); + break; - phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - PHALCON_OBS_VAR(memcache); - phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); - if (Z_TYPE_P(memcache) != IS_OBJECT) { - phalcon_call_method_key(NULL, this_ptr, "_connect", 4074190766UL); - - PHALCON_OBS_NVAR(memcache); - phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); - } - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); - phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), prefixed_key, 394299009UL TSRMLS_CC); - - PHALCON_INIT_VAR(cached_content); - phalcon_call_method_p1_key(cached_content, memcache, "get", prefixed_key, 2090288933UL); - if (PHALCON_IS_FALSE(cached_content)) { - RETURN_MM_NULL(); - } - - phalcon_call_method_p1_key(return_value, frontend, "afterretrieve", cached_content, 3229641981UL); - RETURN_MM(); -} + case PHVOLT_T_FOR: + if (state->extends_mode == 1 && state->block_level == 0){ + phvolt_create_error_msg(parser_status, "Child templates only may contain blocks"); + parser_status->status = PHVOLT_PARSING_FAILED; + break; + } else { + state->old_if_level = state->if_level; + state->if_level = 0; + state->for_level++; + state->block_level++; + } + phvolt_(phvolt_parser, PHVOLT_FOR, NULL, parser_status); + break; -static PHP_METHOD(Phalcon_Cache_Backend_Memcache, save){ + case PHVOLT_T_IN: + phvolt_(phvolt_parser, PHVOLT_IN, NULL, parser_status); + break; - zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; - zval *last_key = NULL, *prefix, *frontend, *memcache = NULL, *cached_content = NULL; - zval *prepared_content, *ttl = NULL, *flags, *success; - zval *options, *special_key, *keys = NULL, *is_buffering; + case PHVOLT_T_ENDFOR: + state->block_level--; + state->for_level--; + state->if_level = state->old_if_level; + phvolt_(phvolt_parser, PHVOLT_ENDFOR, NULL, parser_status); + break; - PHALCON_MM_GROW(); + case PHVOLT_T_RAW_FRAGMENT: + if (token.len > 0) { + if (state->extends_mode == 1 && state->block_level == 0){ + if (!phvolt_is_blank_string(&token)) { + phvolt_create_error_msg(parser_status, "Child templates only may contain blocks"); + parser_status->status = PHVOLT_PARSING_FAILED; + } + efree(token.value); + break; + } else { + if (!phvolt_is_blank_string(&token)) { + state->statement_position++; + } + } + phvolt_parse_with_token(phvolt_parser, PHVOLT_T_RAW_FRAGMENT, PHVOLT_RAW_FRAGMENT, &token, parser_status); + } else { + efree(token.value); + } + break; - phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!content) { - PHALCON_INIT_VAR(content); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (!stop_buffer) { - PHALCON_INIT_VAR(stop_buffer); - ZVAL_BOOL(stop_buffer, 1); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_VV(last_key, prefix, key_name); - } - if (!zend_is_true(last_key)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); - return; - } - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(memcache); - phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); - if (Z_TYPE_P(memcache) != IS_OBJECT) { - phalcon_call_method_key(NULL, this_ptr, "_connect", 4074190766UL); - - PHALCON_OBS_NVAR(memcache); - phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); - } - - if (Z_TYPE_P(content) == IS_NULL) { - PHALCON_INIT_VAR(cached_content); - phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); - } else { - PHALCON_CPY_WRT(cached_content, content); - } - - PHALCON_INIT_VAR(prepared_content); - phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); - if (Z_TYPE_P(lifetime) == IS_NULL) { - PHALCON_INIT_VAR(ttl); - phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); - } else { - PHALCON_CPY_WRT(ttl, lifetime); - } - - PHALCON_INIT_VAR(flags); - ZVAL_LONG(flags, 0); - - PHALCON_INIT_VAR(success); - phalcon_call_method_p4_key(success, memcache, "set", last_key, prepared_content, flags, ttl, 2090720177UL); - if (!zend_is_true(success)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Failed storing data in memcached"); - return; - } - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(special_key); - phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); - - PHALCON_INIT_VAR(keys); - phalcon_call_method_p1_key(keys, memcache, "get", special_key, 2090288933UL); - if (Z_TYPE_P(keys) != IS_ARRAY) { - PHALCON_INIT_NVAR(keys); - array_init(keys); - } - - if (!phalcon_array_isset(keys, last_key)) { - phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); - phalcon_call_method_p2_key(NULL, memcache, "set", special_key, keys, 2090720177UL); - } - - PHALCON_INIT_VAR(is_buffering); - phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); - if (PHALCON_IS_TRUE(stop_buffer)) { - phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); - } - - if (PHALCON_IS_TRUE(is_buffering)) { - zend_print_zval(cached_content, 0); - } - - phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} + case PHVOLT_T_SET: + if (state->extends_mode == 1 && state->block_level == 0){ + phvolt_create_error_msg(parser_status, "Child templates only may contain blocks"); + parser_status->status = PHVOLT_PARSING_FAILED; + break; + } + phvolt_(phvolt_parser, PHVOLT_SET, NULL, parser_status); + break; + case PHVOLT_T_ASSIGN: + phvolt_(phvolt_parser, PHVOLT_ASSIGN, NULL, parser_status); + break; + case PHVOLT_T_ADD_ASSIGN: + phvolt_(phvolt_parser, PHVOLT_ADD_ASSIGN, NULL, parser_status); + break; + case PHVOLT_T_SUB_ASSIGN: + phvolt_(phvolt_parser, PHVOLT_SUB_ASSIGN, NULL, parser_status); + break; + case PHVOLT_T_MUL_ASSIGN: + phvolt_(phvolt_parser, PHVOLT_MUL_ASSIGN, NULL, parser_status); + break; + case PHVOLT_T_DIV_ASSIGN: + phvolt_(phvolt_parser, PHVOLT_DIV_ASSIGN, NULL, parser_status); + break; -static PHP_METHOD(Phalcon_Cache_Backend_Memcache, delete){ + case PHVOLT_T_INCR: + phvolt_(phvolt_parser, PHVOLT_INCR, NULL, parser_status); + break; + case PHVOLT_T_DECR: + phvolt_(phvolt_parser, PHVOLT_DECR, NULL, parser_status); + break; - zval *key_name, *memcache = NULL, *prefix, *prefixed_key; - zval *options, *special_key, *keys; + case PHVOLT_T_BLOCK: + if (state->block_level > 0) { + phvolt_create_error_msg(parser_status, "Embedding blocks into other blocks is not supported"); + parser_status->status = PHVOLT_PARSING_FAILED; + break; + } else { + state->block_level++; + } + phvolt_(phvolt_parser, PHVOLT_BLOCK, NULL, parser_status); + break; + case PHVOLT_T_ENDBLOCK: + state->block_level--; + phvolt_(phvolt_parser, PHVOLT_ENDBLOCK, NULL, parser_status); + break; - PHALCON_MM_GROW(); + case PHVOLT_T_MACRO: + if (state->macro_level > 0) { + phvolt_create_error_msg(parser_status, "Embedding macros into other macros is not allowed"); + parser_status->status = PHVOLT_PARSING_FAILED; + break; + } else { + state->macro_level++; + } + phvolt_(phvolt_parser, PHVOLT_MACRO, NULL, parser_status); + break; + case PHVOLT_T_ENDMACRO: + state->macro_level--; + phvolt_(phvolt_parser, PHVOLT_ENDMACRO, NULL, parser_status); + break; - phalcon_fetch_params(1, 1, 0, &key_name); - - PHALCON_OBS_VAR(memcache); - phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); - if (Z_TYPE_P(memcache) != IS_OBJECT) { - phalcon_call_method_key(NULL, this_ptr, "_connect", 4074190766UL); - - PHALCON_OBS_NVAR(memcache); - phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); - } - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(special_key); - phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); - - PHALCON_INIT_VAR(keys); - phalcon_call_method_p1_key(keys, memcache, "get", special_key, 2090288933UL); - if (Z_TYPE_P(keys) == IS_ARRAY) { - phalcon_array_unset(&keys, prefixed_key, PH_SEPARATE); - phalcon_call_method_p2_key(NULL, memcache, "set", special_key, keys, 2090720177UL); - } - - phalcon_call_method_p1_key(return_value, memcache, "delete", prefixed_key, 150213496UL); - RETURN_MM(); -} + case PHVOLT_T_CALL: + phvolt_(phvolt_parser, PHVOLT_CALL, NULL, parser_status); + break; + case PHVOLT_T_ENDCALL: + phvolt_(phvolt_parser, PHVOLT_ENDCALL, NULL, parser_status); + break; -static PHP_METHOD(Phalcon_Cache_Backend_Memcache, queryKeys){ + case PHVOLT_T_CACHE: + phvolt_(phvolt_parser, PHVOLT_CACHE, NULL, parser_status); + break; + case PHVOLT_T_ENDCACHE: + phvolt_(phvolt_parser, PHVOLT_ENDCACHE, NULL, parser_status); + break; - zval *prefix = NULL, *memcache = NULL, *options, *special_key; - zval *keys, *prefixed_keys, *ttl = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + case PHVOLT_T_INCLUDE: + phvolt_(phvolt_parser, PHVOLT_INCLUDE, NULL, parser_status); + break; - PHALCON_MM_GROW(); + case PHVOLT_T_WITH: + phvolt_(phvolt_parser, PHVOLT_WITH, NULL, parser_status); + break; - phalcon_fetch_params(1, 0, 1, &prefix); - - if (!prefix) { - PHALCON_INIT_VAR(prefix); - } - - PHALCON_OBS_VAR(memcache); - phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); - if (Z_TYPE_P(memcache) != IS_OBJECT) { - phalcon_call_method_key(NULL, this_ptr, "_connect", 4074190766UL); - - PHALCON_OBS_NVAR(memcache); - phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); + case PHVOLT_T_DEFINED: + phvolt_(phvolt_parser, PHVOLT_DEFINED, NULL, parser_status); + break; + + case PHVOLT_T_DO: + phvolt_(phvolt_parser, PHVOLT_DO, NULL, parser_status); + break; + case PHVOLT_T_RETURN: + phvolt_(phvolt_parser, PHVOLT_RETURN, NULL, parser_status); + break; + + case PHVOLT_T_AUTOESCAPE: + phvolt_(phvolt_parser, PHVOLT_AUTOESCAPE, NULL, parser_status); + break; + + case PHVOLT_T_ENDAUTOESCAPE: + phvolt_(phvolt_parser, PHVOLT_ENDAUTOESCAPE, NULL, parser_status); + break; + + case PHVOLT_T_BREAK: + phvolt_(phvolt_parser, PHVOLT_BREAK, NULL, parser_status); + break; + + case PHVOLT_T_CONTINUE: + phvolt_(phvolt_parser, PHVOLT_CONTINUE, NULL, parser_status); + break; + + case PHVOLT_T_EXTENDS: + if (state->statement_position != 1) { + phvolt_create_error_msg(parser_status, "Extends statement must be placed at the first line in the template"); + parser_status->status = PHVOLT_PARSING_FAILED; + break; + } else { + state->extends_mode = 1; + } + phvolt_(phvolt_parser, PHVOLT_EXTENDS, NULL, parser_status); + break; + + default: + parser_status->status = PHVOLT_PARSING_FAILED; + if (!*error_msg) { + error = emalloc(sizeof(char) * (48 + Z_STRLEN_P(state->active_file))); + snprintf(error, 48 + Z_STRLEN_P(state->active_file) + state->active_line, "Scanner: unknown opcode %d on in %s line %d", token.opcode, Z_STRVAL_P(state->active_file), state->active_line); + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, error, 1); + efree(error); + } + break; + } + + if (parser_status->status != PHVOLT_PARSING_OK) { + status = FAILURE; + break; + } + + state->end = state->start; } - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(special_key); - phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); - - PHALCON_INIT_VAR(keys); - phalcon_call_method_p1_key(keys, memcache, "get", special_key, 2090288933UL); - if (Z_TYPE_P(keys) == IS_ARRAY) { - - PHALCON_INIT_VAR(prefixed_keys); - array_init(prefixed_keys); - - phalcon_is_iterable(keys, &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(ttl); - - if (zend_is_true(prefix)) { - if (!phalcon_start_with(key, prefix, NULL)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; + + if (status != FAILURE) { + switch (scanner_status) { + case PHVOLT_SCANNER_RETCODE_ERR: + case PHVOLT_SCANNER_RETCODE_IMPOSSIBLE: + if (!*error_msg) { + phvolt_scanner_error_msg(parser_status, error_msg TSRMLS_CC); } - } - phalcon_array_append(&prefixed_keys, key, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); + status = FAILURE; + break; + default: + phvolt_(phvolt_parser, 0, NULL, parser_status); } - - RETURN_CTOR(prefixed_keys); } - - RETURN_MM_EMPTY_ARRAY(); -} -static PHP_METHOD(Phalcon_Cache_Backend_Memcache, exists){ + state->active_token = 0; + state->start = NULL; + efree(state->raw_buffer); - zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *memcache = NULL; - zval *cache_exists; + if (parser_status->status != PHVOLT_PARSING_OK) { + status = FAILURE; + if (parser_status->syntax_error) { + if (!*error_msg) { + PHALCON_INIT_VAR(*error_msg); + ZVAL_STRING(*error_msg, parser_status->syntax_error, 1); + } + efree(parser_status->syntax_error); + } + } - PHALCON_MM_GROW(); + phvolt_Free(phvolt_parser, phvolt_wrapper_free); - phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_VV(last_key, prefix, key_name); - } - if (zend_is_true(last_key)) { - - PHALCON_OBS_VAR(memcache); - phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); - if (Z_TYPE_P(memcache) != IS_OBJECT) { - phalcon_call_method_key(NULL, this_ptr, "_connect", 4074190766UL); - - PHALCON_OBS_NVAR(memcache); - phalcon_read_property_this_quick(&memcache, this_ptr, SL("_memcache"), 958186231UL, PH_NOISY_CC); - } - - PHALCON_INIT_VAR(cache_exists); - phalcon_call_method_p1_key(cache_exists, memcache, "get", last_key, 2090288933UL); - if (PHALCON_IS_NOT_FALSE(cache_exists)) { - RETURN_MM_TRUE; + if (status != FAILURE) { + if (parser_status->status == PHVOLT_PARSING_OK) { + if (parser_status->ret) { + ZVAL_ZVAL(*result, parser_status->ret, 0, 0); + ZVAL_NULL(parser_status->ret); + zval_ptr_dtor(&parser_status->ret); + } else { + array_init(*result); + } } } - - RETURN_MM_FALSE; -} + efree(parser_status); + efree(state); + + return status; +} +/* Generated by re2c 0.13.5 on Fri Jun 28 19:17:30 2013 */ +// 1 "scanner.re" #ifdef HAVE_CONFIG_H @@ -87469,4211 +87076,4839 @@ static PHP_METHOD(Phalcon_Cache_Backend_Memcache, exists){ +#define KKCTYPE unsigned char +#define KKCURSOR (s->start) +#define KKLIMIT (s->end) +#define KKMARKER q +static void phvolt_rtrim(phvolt_scanner_token *token) { + char *cursor, *removed_str; + unsigned int i; + unsigned char ch; + if (token->len > 0) { -PHALCON_INIT_CLASS(Phalcon_Cache_Backend_Memory){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, Memory, cache_backend_memory, "phalcon\\cache\\backend", phalcon_cache_backend_memory_method_entry, 0); + cursor = token->value; + cursor += (token->len - 1); + for (i = token->len; i > 0; i--) { + ch = (*cursor); + if (ch == '\t' || ch == '\n' || ch == '\r' || ch == ' ' || ch == '\v') { + cursor--; + continue; + } + break; + } - zend_declare_property_null(phalcon_cache_backend_memory_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); + removed_str = emalloc(i + 1); + memcpy(removed_str, token->value, i); + removed_str[i] = '\0'; - zend_class_implements(phalcon_cache_backend_memory_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); + efree(token->value); + token->value = removed_str; + token->len = i; + } - return SUCCESS; } -static PHP_METHOD(Phalcon_Cache_Backend_Memory, get){ +static void phvolt_ltrim(phvolt_scanner_token *token) { - zval *key_name, *lifetime = NULL, *last_key = NULL, *prefix, *data; - zval *cached_content, *frontend; + char *cursor, *removed_str; + unsigned int i; + unsigned char ch; - PHALCON_MM_GROW(); + if (token->len > 0) { - phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_VV(last_key, prefix, key_name); - } - - PHALCON_OBS_VAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - if (!phalcon_array_isset(data, last_key)) { - RETURN_MM_NULL(); - } - - PHALCON_OBS_VAR(cached_content); - phalcon_array_fetch(&cached_content, data, last_key, PH_NOISY); - if (Z_TYPE_P(cached_content) == IS_NULL) { - RETURN_MM_NULL(); + cursor = token->value; + for (i = 0; i < token->len; i++) { + ch = (*cursor); + if (ch == '\t' || ch == '\n' || ch == '\r' || ch == ' ' || ch == '\v') { + cursor++; + continue; + } + break; + } + + removed_str = emalloc(token->len - i + 1); + memcpy(removed_str, token->value + i, token->len - i); + removed_str[token->len - i] = '\0'; + + efree(token->value); + token->value = removed_str; + token->len = token->len - i; } - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - phalcon_call_method_p1_key(return_value, frontend, "afterretrieve", cached_content, 3229641981UL); - RETURN_MM(); + } -static PHP_METHOD(Phalcon_Cache_Backend_Memory, save){ +static int phvolt_get_token(phvolt_scanner_state *s, phvolt_scanner_token *token) { - zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; - zval *last_key = NULL, *prefix, *frontend, *cached_content = NULL; - zval *prepared_content, *is_buffering; + unsigned char next, double_next; + char *q = KKCURSOR, *start = KKCURSOR; + int status = PHVOLT_SCANNER_RETCODE_IMPOSSIBLE; - PHALCON_MM_GROW(); + while (PHVOLT_SCANNER_RETCODE_IMPOSSIBLE == status) { - phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!content) { - PHALCON_INIT_VAR(content); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (!stop_buffer) { - PHALCON_INIT_VAR(stop_buffer); - ZVAL_BOOL(stop_buffer, 1); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_VV(last_key, prefix, key_name); - } - if (!zend_is_true(last_key)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); - return; - } - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - if (Z_TYPE_P(content) == IS_NULL) { - PHALCON_INIT_VAR(cached_content); - phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); - } else { - PHALCON_CPY_WRT(cached_content, content); - } - - PHALCON_INIT_VAR(prepared_content); - phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); - phalcon_update_property_array(this_ptr, SL("_data"), last_key, prepared_content TSRMLS_CC); - - PHALCON_INIT_VAR(is_buffering); - phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); - if (PHALCON_IS_TRUE(stop_buffer)) { - phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); - } - - if (PHALCON_IS_TRUE(is_buffering)) { - zend_print_zval(cached_content, 0); - } - - phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} + if (s->mode == PHVOLT_MODE_RAW || s->mode == PHVOLT_MODE_COMMENT) { -static PHP_METHOD(Phalcon_Cache_Backend_Memory, delete){ + next = '\0'; + double_next = '\0'; - zval *key_name, *prefix, *key, *data; + if (*KKCURSOR == '\n') { + s->active_line++; + } - PHALCON_MM_GROW(); + if (*KKCURSOR != '\0') { + next = *(KKCURSOR + 1); + if (next != '\0') { + double_next = *(KKCURSOR + 2); + } + } - phalcon_fetch_params(1, 1, 0, &key_name); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(key); - PHALCON_CONCAT_VV(key, prefix, key_name); - - PHALCON_OBS_VAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - if (phalcon_array_isset(data, key)) { - phalcon_unset_property_array(this_ptr, SL("_data"), key TSRMLS_CC); - RETURN_MM_TRUE; - } - - RETURN_MM_FALSE; -} + if (*KKCURSOR == '\0' || (*KKCURSOR == '{' && (next == '%' || next == '{' || next == '#'))) { + + if (next != '#') { + + s->mode = PHVOLT_MODE_CODE; + + if (s->raw_buffer_cursor > 0) { + + token->opcode = PHVOLT_T_RAW_FRAGMENT; + token->value = emalloc(sizeof(char) * s->raw_buffer_cursor + 1); + memcpy(token->value, s->raw_buffer, s->raw_buffer_cursor); + token->value[s->raw_buffer_cursor] = 0; + token->len = s->raw_buffer_cursor; + + if (s->whitespace_control == 1) { + phvolt_ltrim(token); + s->whitespace_control = 0; + } + + if (double_next == '-') { + phvolt_rtrim(token); + } + + s->raw_buffer_cursor = 0; + q = KKCURSOR; + } else { + token->opcode = PHVOLT_T_IGNORE; + } + + } else { + + while ((next = *(++KKCURSOR))) { + if (next == '#' && *(KKCURSOR + 1) == '}') { + KKCURSOR+=2; + token->opcode = PHVOLT_T_IGNORE; + return 0; + } else { + if (next == '\n') { + s->active_line++; + } + } + } -static PHP_METHOD(Phalcon_Cache_Backend_Memory, queryKeys){ + return PHVOLT_SCANNER_RETCODE_EOF; + } - zval *prefix = NULL, *keys; + return 0; - PHALCON_MM_GROW(); + } else { - phalcon_fetch_params(1, 0, 1, &prefix); - - if (!prefix) { - PHALCON_INIT_VAR(prefix); - ZVAL_STRING(prefix, "", 1); - } - - PHALCON_INIT_VAR(keys); - array_init(keys); - - PHALCON_MM_RESTORE(); -} + if (s->raw_buffer_cursor == s->raw_buffer_size) { + s->raw_buffer_size += PHVOLT_RAW_BUFFER_SIZE; + s->raw_buffer = erealloc(s->raw_buffer, s->raw_buffer_size); + } -static PHP_METHOD(Phalcon_Cache_Backend_Memory, exists){ + memcpy(s->raw_buffer+s->raw_buffer_cursor, KKCURSOR, 1); + s->raw_buffer_cursor++; - zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *data; + ++KKCURSOR; + } - PHALCON_MM_GROW(); + } else { - phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_VV(last_key, prefix, key_name); - } - if (zend_is_true(last_key)) { - - PHALCON_OBS_VAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - if (phalcon_array_isset(data, last_key)) { - RETURN_MM_TRUE; + +// 184 "scanner.c" + { + KKCTYPE kkch; + unsigned int kkaccept = 0; + + kkch = *KKCURSOR; + switch (kkch) { + case 0x00: goto kk70; + case '\t': + case '\r': + case ' ': goto kk66; + case '\n': goto kk68; + case '!': goto kk58; + case '"': goto kk27; + case '%': goto kk21; + case '\'': goto kk29; + case '(': goto kk44; + case ')': goto kk46; + case '*': goto kk34; + case '+': goto kk32; + case ',': goto kk42; + case '-': goto kk23; + case '.': goto kk40; + case '/': goto kk36; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto kk2; + case ':': goto kk62; + case '<': goto kk52; + case '=': goto kk54; + case '>': goto kk56; + case '?': goto kk64; + case 'A': + case 'a': goto kk11; + case 'B': + case 'b': goto kk13; + case 'C': + case 'c': goto kk15; + case 'D': + case 'd': goto kk18; + case 'E': + case 'e': goto kk6; + case 'F': + case 'f': goto kk7; + case 'G': + case 'H': + case 'J': + case 'K': + case 'L': + case 'P': + case 'Q': + case 'U': + case 'V': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'g': + case 'h': + case 'j': + case 'k': + case 'l': + case 'p': + case 'q': + case 'u': + case 'v': + case 'x': + case 'y': + case 'z': goto kk31; + case 'I': + case 'i': goto kk4; + case 'M': + case 'm': goto kk14; + case 'N': + case 'n': goto kk9; + case 'O': + case 'o': goto kk12; + case 'R': + case 'r': goto kk17; + case 'S': + case 's': goto kk8; + case 'T': + case 't': goto kk10; + case 'W': + case 'w': goto kk16; + case '[': goto kk48; + case '\\': goto kk30; + case ']': goto kk50; + case '{': goto kk19; + case '|': goto kk60; + case '}': goto kk25; + case '~': goto kk38; + default: goto kk72; + } +kk2: + kkaccept = 0; + kkch = *(KKMARKER = ++KKCURSOR); + goto kk292; +kk3: +// 185 "scanner.re" + { + token->opcode = PHVOLT_T_INTEGER; + token->value = estrndup(start, KKCURSOR - start); + token->len = KKCURSOR - start; + q = KKCURSOR; + return 0; + } +// 298 "scanner.c" +kk4: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case 'F': + case 'f': goto kk278; + case 'N': + case 'n': goto kk280; + case 'S': + case 's': goto kk282; + default: goto kk100; + } +kk5: +// 450 "scanner.re" + { + token->opcode = PHVOLT_T_IDENTIFIER; + token->value = estrndup(start, KKCURSOR - start); + token->len = KKCURSOR - start; + q = KKCURSOR; + return 0; + } +// 319 "scanner.c" +kk6: + kkch = *++KKCURSOR; + switch (kkch) { + case 'L': + case 'l': goto kk219; + case 'N': + case 'n': goto kk220; + case 'X': + case 'x': goto kk221; + default: goto kk100; + } +kk7: + kkch = *++KKCURSOR; + switch (kkch) { + case 'A': + case 'a': goto kk211; + case 'O': + case 'o': goto kk212; + default: goto kk100; + } +kk8: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk208; + default: goto kk100; + } +kk9: + kkch = *++KKCURSOR; + switch (kkch) { + case 'O': + case 'o': goto kk201; + case 'U': + case 'u': goto kk202; + default: goto kk100; + } +kk10: + kkch = *++KKCURSOR; + switch (kkch) { + case 'R': + case 'r': goto kk197; + default: goto kk100; + } +kk11: + kkch = *++KKCURSOR; + switch (kkch) { + case 'N': + case 'n': goto kk184; + case 'U': + case 'u': goto kk185; + default: goto kk100; + } +kk12: + kkch = *++KKCURSOR; + switch (kkch) { + case 'R': + case 'r': goto kk182; + default: goto kk100; + } +kk13: + kkch = *++KKCURSOR; + switch (kkch) { + case 'L': + case 'l': goto kk172; + case 'R': + case 'r': goto kk173; + default: goto kk100; + } +kk14: + kkch = *++KKCURSOR; + switch (kkch) { + case 'A': + case 'a': goto kk167; + default: goto kk100; + } +kk15: + kkch = *++KKCURSOR; + switch (kkch) { + case 'A': + case 'a': goto kk151; + case 'O': + case 'o': goto kk152; + default: goto kk100; + } +kk16: + kkch = *++KKCURSOR; + switch (kkch) { + case 'I': + case 'i': goto kk147; + default: goto kk100; + } +kk17: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk141; + default: goto kk100; + } +kk18: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk132; + case 'O': + case 'o': goto kk133; + default: goto kk100; + } +kk19: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '%': goto kk126; + case '{': goto kk124; + default: goto kk20; + } +kk20: +// 533 "scanner.re" + { + token->opcode = PHVOLT_T_CBRACKET_OPEN; + return 0; + } +// 440 "scanner.c" +kk21: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '}': goto kk122; + default: goto kk22; + } +kk22: +// 478 "scanner.re" + { + token->opcode = PHVOLT_T_MOD; + return 0; + } +// 453 "scanner.c" +kk23: + kkaccept = 1; + kkch = *(KKMARKER = ++KKCURSOR); + switch (kkch) { + case '%': goto kk117; + case '-': goto kk114; + case '=': goto kk112; + case '}': goto kk116; + default: goto kk24; + } +kk24: +// 463 "scanner.re" + { + token->opcode = PHVOLT_T_SUB; + return 0; + } +// 470 "scanner.c" +kk25: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '}': goto kk110; + default: goto kk26; + } +kk26: +// 538 "scanner.re" + { + token->opcode = PHVOLT_T_CBRACKET_CLOSE; + return 0; + } +// 483 "scanner.c" +kk27: + kkaccept = 2; + kkch = *(KKMARKER = ++KKCURSOR); + if (kkch >= 0x01) goto kk108; +kk28: +// 649 "scanner.re" + { + status = PHVOLT_SCANNER_RETCODE_ERR; + break; + } +// 494 "scanner.c" +kk29: + kkaccept = 2; + kkch = *(KKMARKER = ++KKCURSOR); + if (kkch <= 0x00) goto kk28; + goto kk102; +kk30: + kkch = *++KKCURSOR; + switch (kkch) { + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk28; + } +kk31: + kkch = *++KKCURSOR; + goto kk100; +kk32: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '+': goto kk97; + case '=': goto kk95; + default: goto kk33; + } +kk33: +// 458 "scanner.re" + { + token->opcode = PHVOLT_T_ADD; + return 0; + } +// 574 "scanner.c" +kk34: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '=': goto kk93; + default: goto kk35; + } +kk35: +// 468 "scanner.re" + { + token->opcode = PHVOLT_T_MUL; + return 0; + } +// 587 "scanner.c" +kk36: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '=': goto kk91; + default: goto kk37; + } +kk37: +// 473 "scanner.re" + { + token->opcode = PHVOLT_T_DIV; + return 0; + } +// 600 "scanner.c" +kk38: + ++KKCURSOR; +// 493 "scanner.re" + { + token->opcode = PHVOLT_T_CONCAT; + return 0; + } +// 608 "scanner.c" +kk40: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '.': goto kk89; + default: goto kk41; + } +kk41: +// 503 "scanner.re" + { + token->opcode = PHVOLT_T_DOT; + return 0; + } +// 621 "scanner.c" +kk42: + ++KKCURSOR; +// 508 "scanner.re" + { + token->opcode = PHVOLT_T_COMMA; + return 0; + } +// 629 "scanner.c" +kk44: + ++KKCURSOR; +// 513 "scanner.re" + { + token->opcode = PHVOLT_T_PARENTHESES_OPEN; + return 0; } - } - - RETURN_MM_FALSE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -static int phalcon_cache_backend_is_apcu = -1; - -PHALCON_INIT_CLASS(Phalcon_Cache_Backend_Apc){ - - if (-1 == phalcon_cache_backend_is_apcu) { - phalcon_cache_backend_is_apcu = zend_hash_exists(&module_registry, SS("apcu")); - } - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, Apc, cache_backend_apc, "phalcon\\cache\\backend", phalcon_cache_backend_apc_method_entry, 0); - - zend_class_implements(phalcon_cache_backend_apc_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Cache_Backend_Apc, get){ - - zval *key_name, *lifetime = NULL, *frontend, *prefix, *prefixed_key; - zval *cached_content, *processed; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_SVV(prefixed_key, "_PHCA", prefix, key_name); - phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), prefixed_key, 394299009UL TSRMLS_CC); - - PHALCON_INIT_VAR(cached_content); - phalcon_call_func_p1(cached_content, "apc_fetch", prefixed_key); - if (PHALCON_IS_FALSE(cached_content)) { - RETURN_MM_NULL(); - } - - PHALCON_INIT_VAR(processed); - phalcon_call_method_p1_key(processed, frontend, "afterretrieve", cached_content, 3229641981UL); - - RETURN_CCTOR(processed); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Apc, save){ - - zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; - zval *last_key = NULL, *prefix, *frontend, *cached_content = NULL; - zval *prepared_content, *ttl = NULL, *is_buffering; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!content) { - PHALCON_INIT_VAR(content); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (!stop_buffer) { - PHALCON_INIT_VAR(stop_buffer); - ZVAL_BOOL(stop_buffer, 1); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_SVV(last_key, "_PHCA", prefix, key_name); - } - if (!zend_is_true(last_key)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); - return; - } - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - if (Z_TYPE_P(content) == IS_NULL) { - PHALCON_INIT_VAR(cached_content); - phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); - } else { - PHALCON_CPY_WRT(cached_content, content); - } - - PHALCON_INIT_VAR(prepared_content); - phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); - - if (Z_TYPE_P(lifetime) == IS_NULL) { - - PHALCON_OBS_VAR(ttl); - phalcon_read_property_this_quick(&ttl, this_ptr, SL("_lastLifetime"), 3936785351UL, PH_NOISY_CC); - if (Z_TYPE_P(ttl) == IS_NULL) { - PHALCON_INIT_NVAR(ttl); - phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); +// 637 "scanner.c" +kk46: + ++KKCURSOR; +// 518 "scanner.re" + { + token->opcode = PHVOLT_T_PARENTHESES_CLOSE; + return 0; } - } else { - PHALCON_CPY_WRT(ttl, lifetime); - } - - phalcon_call_func_p3_noret("apc_store", last_key, prepared_content, ttl); - - PHALCON_INIT_VAR(is_buffering); - phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); - if (PHALCON_IS_TRUE(stop_buffer)) { - phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); - } - - if (PHALCON_IS_TRUE(is_buffering)) { - zend_print_zval(cached_content, 0); - } - - phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Apc, delete){ - - zval *key_name, *prefix, *key; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key_name); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(key); - PHALCON_CONCAT_SVV(key, "_PHCA", prefix, key_name); - - phalcon_call_func_p1(return_value, "apc_delete", key); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Apc, queryKeys){ - - zval *prefix = NULL, *keys, *type, *prefix_pattern, *iterator; - zval *key = NULL; - zend_class_entry *ce0; -#if PHP_VERSION_ID < 50500 - char *str_key; - uint str_key_len; - ulong int_key; - int key_type; -#else - zval *itkey = NULL; -#endif - zend_object_iterator *it; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &prefix); - - PHALCON_INIT_VAR(prefix_pattern); - if (!prefix) { - ZVAL_STRING(prefix_pattern, "/^_PHCA/", 1); - } - else { - PHALCON_CONCAT_SVS(prefix_pattern, "/^_PHCA", prefix, "/"); - } - - PHALCON_INIT_VAR(keys); - array_init(keys); - - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "user", 1); - - ce0 = zend_fetch_class(SL("APCIterator"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - - PHALCON_INIT_VAR(iterator); - object_init_ex(iterator, ce0); - if (phalcon_has_constructor(iterator TSRMLS_CC)) { - if (!phalcon_cache_backend_is_apcu) { - phalcon_call_method_p2_key(NULL, iterator, "__construct", type, prefix_pattern, 1107214344UL); +// 645 "scanner.c" +kk48: + ++KKCURSOR; +// 523 "scanner.re" + { + token->opcode = PHVOLT_T_SBRACKET_OPEN; + return 0; } - else { - phalcon_call_method_p1_key(NULL, iterator, "__construct", prefix_pattern, 1107214344UL); +// 653 "scanner.c" +kk50: + ++KKCURSOR; +// 528 "scanner.re" + { + token->opcode = PHVOLT_T_SBRACKET_CLOSE; + return 0; } - } - - /* APCIterator implements Iterator */ - assert(instanceof_function_ex(ce0, zend_ce_iterator, 1 TSRMLS_CC)); - - it = ce0->get_iterator(ce0, iterator, 0 TSRMLS_CC); - - /* APCIterator is an iterator */ - assert(it != NULL); - - /* APCIterator has key() method */ - assert(it->funcs->get_current_key != NULL); - - /* APCIterator has rewind() method */ - assert(it->funcs->rewind != NULL); - - it->funcs->rewind(it TSRMLS_CC); - while (it->funcs->valid(it TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_NVAR(key); -#if PHP_VERSION_ID < 50500 - key_type = it->funcs->get_current_key(it, &str_key, &str_key_len, &int_key TSRMLS_CC); - if (likely(key_type == HASH_KEY_IS_STRING)) { - ZVAL_STRINGL(key, str_key + 5, str_key_len - 5 - 1, 1); - efree(str_key); - - phalcon_array_append(&keys, key, PH_COPY); +// 661 "scanner.c" +kk52: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '=': goto kk87; + case '>': goto kk85; + default: goto kk53; + } +kk53: +// 608 "scanner.re" + { + token->opcode = PHVOLT_T_LESS; + return 0; } -#else - PHALCON_INIT_NVAR(itkey); - it->funcs->get_current_key(it, itkey TSRMLS_CC); - if (likely(Z_TYPE_P(itkey) == IS_STRING)) { - ZVAL_STRINGL(key, Z_STRVAL_P(itkey) + 5, Z_STRLEN_P(itkey) - 5, 1); - phalcon_array_append(&keys, key, PH_COPY); +// 675 "scanner.c" +kk54: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '=': goto kk81; + default: goto kk55; + } +kk55: +// 548 "scanner.re" + { + token->opcode = PHVOLT_T_ASSIGN; + return 0; } -#endif - - it->funcs->move_forward(it TSRMLS_CC); - } - - it->funcs->dtor(it TSRMLS_CC); - - RETURN_CTOR(keys); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Apc, exists){ - - zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *cache_exists; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_SVV(last_key, "_PHCA", prefix, key_name); - } - if (zend_is_true(last_key)) { - - PHALCON_INIT_VAR(cache_exists); - phalcon_call_func_p1(cache_exists, "apc_exists", last_key); - if (PHALCON_IS_NOT_FALSE(cache_exists)) { - RETURN_MM_TRUE; +// 688 "scanner.c" +kk56: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '=': goto kk79; + default: goto kk57; + } +kk57: +// 613 "scanner.re" + { + token->opcode = PHVOLT_T_GREATER; + return 0; } - } - - RETURN_MM_FALSE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Cache_Backend_File){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, File, cache_backend_file, "phalcon\\cache\\backend", phalcon_cache_backend_file_method_entry, 0); - - zend_class_implements(phalcon_cache_backend_file_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Cache_Backend_File, __construct){ - - zval *frontend, *options = NULL, *cache_dir; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &frontend, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (!phalcon_array_isset_quick_string(options, SS("cacheDir"), 1104587096UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cache directory must be specified with the option cacheDir"); - return; - } - - PHALCON_OBS_VAR(cache_dir); - phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); - PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\File", "__construct", frontend, options); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_File, get){ - - zval *key_name, *lifetime = NULL, *options, *prefix, *prefixed_key; - zval *cache_dir, *cache_file, *frontend, *timestamp; - zval *ttl = NULL, *modified_time, *difference, *not_expired; - zval *cached_content, *exception_message; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } else { - PHALCON_SEPARATE_PARAM(lifetime); - } - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); - phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), prefixed_key, 394299009UL TSRMLS_CC); - - PHALCON_OBS_VAR(cache_dir); - phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); - - PHALCON_INIT_VAR(cache_file); - PHALCON_CONCAT_VV(cache_file, cache_dir, prefixed_key); - - if (phalcon_file_exists(cache_file TSRMLS_CC) == SUCCESS) { - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(timestamp); - ZVAL_LONG(timestamp, (long) time(NULL)); - - if (Z_TYPE_P(lifetime) == IS_NULL) { - - PHALCON_OBS_NVAR(lifetime); - phalcon_read_property_this_quick(&lifetime, this_ptr, SL("_lastLifetime"), 3936785351UL, PH_NOISY_CC); - if (Z_TYPE_P(lifetime) == IS_NULL) { - PHALCON_INIT_VAR(ttl); - phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); - } else { - PHALCON_CPY_WRT(ttl, lifetime); +// 701 "scanner.c" +kk58: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '=': goto kk75; + default: goto kk59; + } +kk59: +// 603 "scanner.re" + { + token->opcode = PHVOLT_T_NOT; + return 0; + } +// 714 "scanner.c" +kk60: + ++KKCURSOR; +// 618 "scanner.re" + { + token->opcode = PHVOLT_T_PIPE; + return 0; + } +// 722 "scanner.c" +kk62: + ++KKCURSOR; +// 623 "scanner.re" + { + token->opcode = PHVOLT_T_COLON; + return 0; + } +// 730 "scanner.c" +kk64: + ++KKCURSOR; +// 628 "scanner.re" + { + token->opcode = PHVOLT_T_QUESTION; + return 0; + } +// 738 "scanner.c" +kk66: + ++KKCURSOR; + kkch = *KKCURSOR; + goto kk74; +kk67: +// 633 "scanner.re" + { + token->opcode = PHVOLT_T_IGNORE; + return 0; + } +// 749 "scanner.c" +kk68: + ++KKCURSOR; +// 638 "scanner.re" + { + s->active_line++; + token->opcode = PHVOLT_T_IGNORE; + return 0; + } +// 758 "scanner.c" +kk70: + ++KKCURSOR; +// 644 "scanner.re" + { + status = PHVOLT_SCANNER_RETCODE_EOF; + break; + } +// 766 "scanner.c" +kk72: + kkch = *++KKCURSOR; + goto kk28; +kk73: + ++KKCURSOR; + kkch = *KKCURSOR; +kk74: + switch (kkch) { + case '\t': + case '\r': + case ' ': goto kk73; + default: goto kk67; } - } else { - PHALCON_CPY_WRT(ttl, lifetime); +kk75: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '=': goto kk77; + default: goto kk76; + } +kk76: +// 583 "scanner.re" + { + token->opcode = PHVOLT_T_NOTEQUALS; + return 0; } - - PHALCON_INIT_VAR(modified_time); - phalcon_call_func_p1(modified_time, "filemtime", cache_file); - - PHALCON_INIT_VAR(difference); - sub_function(difference, timestamp, ttl TSRMLS_CC); - - PHALCON_INIT_VAR(not_expired); - is_smaller_function(not_expired, difference, modified_time TSRMLS_CC); - - if (PHALCON_IS_TRUE(not_expired)) { - - PHALCON_INIT_VAR(cached_content); - phalcon_file_get_contents(cached_content, cache_file TSRMLS_CC); - if (PHALCON_IS_FALSE(cached_content)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Cache file ", cache_file, " could not be opened"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_cache_exception_ce, exception_message); - return; +// 792 "scanner.c" +kk77: + ++KKCURSOR; +// 598 "scanner.re" + { + token->opcode = PHVOLT_T_NOTIDENTICAL; + return 0; + } +// 800 "scanner.c" +kk79: + ++KKCURSOR; +// 573 "scanner.re" + { + token->opcode = PHVOLT_T_GREATEREQUAL; + return 0; + } +// 808 "scanner.c" +kk81: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '=': goto kk83; + default: goto kk82; } - - phalcon_call_method_p1_key(return_value, frontend, "afterretrieve", cached_content, 3229641981UL); - RETURN_MM(); +kk82: +// 578 "scanner.re" + { + token->opcode = PHVOLT_T_EQUALS; + return 0; } - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_File, save){ - - zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; - zval *last_key = NULL, *prefix, *frontend, *options, *cache_dir; - zval *cache_file, *cached_content = NULL, *prepared_content; - zval *status, *is_buffering; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!content) { - PHALCON_INIT_VAR(content); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (!stop_buffer) { - PHALCON_INIT_VAR(stop_buffer); - ZVAL_BOOL(stop_buffer, 1); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_VV(last_key, prefix, key_name); - } - if (!zend_is_true(last_key)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); - return; - } - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(cache_dir); - phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); - - PHALCON_INIT_VAR(cache_file); - PHALCON_CONCAT_VV(cache_file, cache_dir, last_key); - if (!zend_is_true(content)) { - PHALCON_INIT_VAR(cached_content); - phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); - } else { - PHALCON_CPY_WRT(cached_content, content); - } - - PHALCON_INIT_VAR(prepared_content); - phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); - - PHALCON_INIT_VAR(status); - phalcon_file_put_contents(status, cache_file, prepared_content TSRMLS_CC); - if (PHALCON_IS_FALSE(status)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cache directory can't be written"); - return; - } - - PHALCON_INIT_VAR(is_buffering); - phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); - if (PHALCON_IS_TRUE(stop_buffer)) { - phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); - } - - if (PHALCON_IS_TRUE(is_buffering)) { - zend_print_zval(cached_content, 0); - } - - phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_File, delete){ - - zval *key_name, *options, *prefix, *prefixed_key; - zval *cache_dir, *cache_file; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key_name); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); - - PHALCON_OBS_VAR(cache_dir); - phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); - - PHALCON_INIT_VAR(cache_file); - PHALCON_CONCAT_VV(cache_file, cache_dir, prefixed_key); - - if (phalcon_file_exists(cache_file TSRMLS_CC) == SUCCESS) { - phalcon_call_func_p1(return_value, "unlink", cache_file); - RETURN_MM(); - } - - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Cache_Backend_File, queryKeys){ - - zval *prefix = NULL, *keys, *options, *cache_dir, *iterator; - zval *item = NULL, *is_directory = NULL, *key = NULL; - zval *r0 = NULL; - zend_class_entry *ce0; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &prefix); - - if (!prefix) { - PHALCON_INIT_VAR(prefix); - } - - PHALCON_INIT_VAR(keys); - array_init(keys); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(cache_dir); - phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); - - ce0 = zend_fetch_class(SL("DirectoryIterator"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - - PHALCON_INIT_VAR(iterator); - object_init_ex(iterator, ce0); - if (phalcon_has_constructor(iterator TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, iterator, "__construct", cache_dir, 1107214344UL); - } - phalcon_call_method_key(NULL, iterator, "rewind", 1064078190UL); - - while (1) { - - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, iterator, "valid", 574098517UL); - if (zend_is_true(r0)) { - } else { - break; +// 821 "scanner.c" +kk83: + ++KKCURSOR; +// 593 "scanner.re" + { + token->opcode = PHVOLT_T_IDENTICAL; + return 0; } - - PHALCON_INIT_NVAR(item); - phalcon_call_method_key(item, iterator, "current", 431662984UL); - - PHALCON_INIT_NVAR(is_directory); - phalcon_call_method_key(is_directory, item, "isdir", 86397952UL); - if (PHALCON_IS_FALSE(is_directory)) { - - PHALCON_INIT_NVAR(key); - phalcon_call_method_key(key, item, "getfilename", 984101030UL); - if (zend_is_true(prefix)) { - if (!phalcon_start_with(key, prefix, NULL)) { - continue; - } +// 829 "scanner.c" +kk85: + ++KKCURSOR; +// 588 "scanner.re" + { + token->opcode = PHVOLT_T_NOTEQUALS; + return 0; + } +// 837 "scanner.c" +kk87: + ++KKCURSOR; +// 543 "scanner.re" + { + token->opcode = PHVOLT_T_LESSEQUAL; + return 0; + } +// 845 "scanner.c" +kk89: + ++KKCURSOR; +// 498 "scanner.re" + { + token->opcode = PHVOLT_T_RANGE; + return 0; + } +// 853 "scanner.c" +kk91: + ++KKCURSOR; +// 568 "scanner.re" + { + token->opcode = PHVOLT_T_DIV_ASSIGN; + return 0; + } +// 861 "scanner.c" +kk93: + ++KKCURSOR; +// 563 "scanner.re" + { + token->opcode = PHVOLT_T_MUL_ASSIGN; + return 0; + } +// 869 "scanner.c" +kk95: + ++KKCURSOR; +// 553 "scanner.re" + { + token->opcode = PHVOLT_T_ADD_ASSIGN; + return 0; + } +// 877 "scanner.c" +kk97: + ++KKCURSOR; +// 483 "scanner.re" + { + token->opcode = PHVOLT_T_INCR; + return 0; + } +// 885 "scanner.c" +kk99: + ++KKCURSOR; + kkch = *KKCURSOR; +kk100: + switch (kkch) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk5; } - - phalcon_array_append(&keys, key, PH_SEPARATE); +kk101: + ++KKCURSOR; + kkch = *KKCURSOR; +kk102: + switch (kkch) { + case 0x00: goto kk103; + case '\'': goto kk105; + case '\\': goto kk104; + default: goto kk101; + } +kk103: + KKCURSOR = KKMARKER; + switch (kkaccept) { + case 0: goto kk3; + case 1: goto kk24; + case 2: goto kk28; + } +kk104: + ++KKCURSOR; + kkch = *KKCURSOR; + switch (kkch) { + case '\n': goto kk103; + default: goto kk101; + } +kk105: + ++KKCURSOR; +// 441 "scanner.re" + { + token->opcode = PHVOLT_T_STRING; + token->value = estrndup(q, KKCURSOR - q - 1); + token->len = KKCURSOR - q - 1; + q = KKCURSOR; + return 0; } - - phalcon_call_method_key(NULL, iterator, "next", 268367684UL); - } - - RETURN_CTOR(keys); -} - -static PHP_METHOD(Phalcon_Cache_Backend_File, exists){ - - zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *options; - zval *cache_dir, *cache_file, *frontend, *timestamp; - zval *ttl = NULL, *modified_time, *difference, *not_expired; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_VV(last_key, prefix, key_name); - } - if (zend_is_true(last_key)) { - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(cache_dir); - phalcon_array_fetch_quick_string(&cache_dir, options, SS("cacheDir"), 1104587096UL, PH_NOISY); - - PHALCON_INIT_VAR(cache_file); - PHALCON_CONCAT_VV(cache_file, cache_dir, last_key); - - if (phalcon_file_exists(cache_file TSRMLS_CC) == SUCCESS) { - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(timestamp); - ZVAL_LONG(timestamp, (long) time(NULL)); - if (Z_TYPE_P(lifetime) == IS_NULL) { - PHALCON_INIT_VAR(ttl); - phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); - } else { - PHALCON_CPY_WRT(ttl, lifetime); +// 991 "scanner.c" +kk107: + ++KKCURSOR; + kkch = *KKCURSOR; +kk108: + switch (kkch) { + case 0x00: goto kk103; + case '"': goto kk105; + case '\\': goto kk109; + default: goto kk107; + } +kk109: + ++KKCURSOR; + kkch = *KKCURSOR; + switch (kkch) { + case '\n': goto kk103; + default: goto kk107; + } +kk110: + ++KKCURSOR; +// 420 "scanner.re" + { + s->mode = PHVOLT_MODE_RAW; + token->opcode = PHVOLT_T_CLOSE_EDELIMITER; + return 0; + } +// 1017 "scanner.c" +kk112: + ++KKCURSOR; +// 558 "scanner.re" + { + token->opcode = PHVOLT_T_SUB_ASSIGN; + return 0; + } +// 1025 "scanner.c" +kk114: + ++KKCURSOR; +// 488 "scanner.re" + { + token->opcode = PHVOLT_T_DECR; + return 0; + } +// 1033 "scanner.c" +kk116: + kkch = *++KKCURSOR; + switch (kkch) { + case '}': goto kk120; + default: goto kk103; } - - PHALCON_INIT_VAR(modified_time); - phalcon_call_func_p1(modified_time, "filemtime", cache_file); - - PHALCON_INIT_VAR(difference); - sub_function(difference, timestamp, ttl TSRMLS_CC); - - PHALCON_INIT_VAR(not_expired); - is_smaller_function(not_expired, difference, modified_time TSRMLS_CC); - if (PHALCON_IS_TRUE(not_expired)) { - RETURN_MM_TRUE; +kk117: + kkch = *++KKCURSOR; + switch (kkch) { + case '}': goto kk118; + default: goto kk103; } +kk118: + ++KKCURSOR; +// 406 "scanner.re" + { + s->mode = PHVOLT_MODE_RAW; + s->whitespace_control = 1; + token->opcode = PHVOLT_T_CLOSE_DELIMITER; + return 0; } - } - - RETURN_MM_FALSE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Cache_Backend_Mongo){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, Mongo, cache_backend_mongo, "phalcon\\cache\\backend", phalcon_cache_backend_mongo_method_entry, 0); - - zend_declare_property_null(phalcon_cache_backend_mongo_ce, SL("_collection"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_cache_backend_mongo_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Cache_Backend_Mongo, __construct){ - - zval *frontend, *options = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &frontend, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (!phalcon_array_isset_quick_string(options, SS("mongo"), 238552933UL)) { - if (!phalcon_array_isset_quick_string(options, SS("server"), 2350074396UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'server' is required"); - return; +// 1055 "scanner.c" +kk120: + ++KKCURSOR; +// 433 "scanner.re" + { + s->mode = PHVOLT_MODE_RAW; + s->whitespace_control = 1; + token->opcode = PHVOLT_T_CLOSE_EDELIMITER; + return 0; } - } - if (!phalcon_array_isset_quick_string(options, SS("db"), 193489131UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'db' is required"); - return; - } - - if (!phalcon_array_isset_quick_string(options, SS("collection"), 1563790257UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'collection' is required"); - return; - } - - PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\Mongo", "__construct", frontend, options); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Mongo, _getCollection){ - - zval *mongo_collection = NULL, *options, *mongo = NULL, *server; - zval *database, *collection, *mongo_database; - zend_class_entry *ce0; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(mongo_collection); - phalcon_read_property_this_quick(&mongo_collection, this_ptr, SL("_collection"), 4106104656UL, PH_NOISY_CC); - if (Z_TYPE_P(mongo_collection) != IS_OBJECT) { - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - if (phalcon_array_isset_quick_string(options, SS("mongo"), 238552933UL)) { - - PHALCON_OBS_VAR(mongo); - phalcon_array_fetch_quick_string(&mongo, options, SS("mongo"), 238552933UL, PH_NOISY); - if (Z_TYPE_P(mongo) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The 'mongo' parameter must be a valid Mongo instance"); - return; - } - } else { - PHALCON_OBS_VAR(server); - phalcon_array_fetch_quick_string(&server, options, SS("server"), 2350074396UL, PH_NOISY); - if (Z_TYPE_P(server) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB connection string"); - return; +// 1065 "scanner.c" +kk122: + ++KKCURSOR; +// 394 "scanner.re" + { + s->mode = PHVOLT_MODE_RAW; + token->opcode = PHVOLT_T_CLOSE_DELIMITER; + return 0; + } +// 1074 "scanner.c" +kk124: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '-': goto kk130; + default: goto kk125; } - - ce0 = zend_fetch_class(SL("Mongo"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - - PHALCON_INIT_NVAR(mongo); - object_init_ex(mongo, ce0); - if (phalcon_has_constructor(mongo TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, mongo, "__construct", server, 1107214344UL); +kk125: +// 413 "scanner.re" + { + s->whitespace_control = 0; + s->statement_position++; + token->opcode = PHVOLT_T_OPEN_EDELIMITER; + return 0; + } +// 1089 "scanner.c" +kk126: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '-': goto kk128; + default: goto kk127; } +kk127: +// 388 "scanner.re" + { + s->whitespace_control = 0; + token->opcode = PHVOLT_T_OPEN_DELIMITER; + return 0; } - - PHALCON_OBS_VAR(database); - phalcon_array_fetch_quick_string(&database, options, SS("db"), 193489131UL, PH_NOISY); - if (Z_TYPE_P(database) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB db"); - return; +// 1103 "scanner.c" +kk128: + ++KKCURSOR; +// 400 "scanner.re" + { + s->whitespace_control = 0; + token->opcode = PHVOLT_T_OPEN_DELIMITER; + return 0; } - - PHALCON_OBS_VAR(collection); - phalcon_array_fetch_quick_string(&collection, options, SS("collection"), 1563790257UL, PH_NOISY); - if (Z_TYPE_P(collection) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The backend requires a valid MongoDB collection"); - return; +// 1112 "scanner.c" +kk130: + ++KKCURSOR; +// 426 "scanner.re" + { + s->whitespace_control = 0; + s->statement_position++; + token->opcode = PHVOLT_T_OPEN_EDELIMITER; + return 0; } - - PHALCON_INIT_VAR(mongo_database); - phalcon_call_method_p1_key(mongo_database, mongo, "selectdb", database, 3899113387UL); - - PHALCON_INIT_NVAR(mongo_collection); - phalcon_call_method_p1_key(mongo_collection, mongo_database, "selectcollection", collection, 3563037297UL); - } - - RETURN_CCTOR(mongo_collection); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Mongo, get){ - - zval *key_name, *lifetime = NULL, *frontend, *prefix, *prefixed_key; - zval *collection, *conditions, *document, *timestamp; - zval *ttl = NULL, *modified_time, *difference, *not_expired; - zval *cached_content; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } else { - PHALCON_SEPARATE_PARAM(lifetime); - } - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); - phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), prefixed_key, 394299009UL TSRMLS_CC); - - PHALCON_INIT_VAR(collection); - phalcon_call_method_key(collection, this_ptr, "_getcollection", 4161728624UL); - - PHALCON_INIT_VAR(conditions); - array_init_size(conditions, 1); - phalcon_array_update_quick_string(&conditions, SS("key"), 2090432846UL, &prefixed_key, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(document); - phalcon_call_method_p1_key(document, collection, "findone", conditions, 947441000UL); - if (Z_TYPE_P(document) == IS_ARRAY) { - - PHALCON_INIT_VAR(timestamp); - ZVAL_LONG(timestamp, (long) time(NULL)); - - if (Z_TYPE_P(lifetime) == IS_NULL) { - - PHALCON_OBS_NVAR(lifetime); - phalcon_read_property_this_quick(&lifetime, this_ptr, SL("_lastLifetime"), 3936785351UL, PH_NOISY_CC); - if (Z_TYPE_P(lifetime) == IS_NULL) { - PHALCON_INIT_VAR(ttl); - phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); - } else { - PHALCON_CPY_WRT(ttl, lifetime); +// 1122 "scanner.c" +kk132: + kkch = *++KKCURSOR; + switch (kkch) { + case 'F': + case 'f': goto kk135; + default: goto kk100; + } +kk133: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk134; + } +kk134: +// 358 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_DO; + return 0; + } +// 1206 "scanner.c" +kk135: + kkch = *++KKCURSOR; + switch (kkch) { + case 'I': + case 'i': goto kk136; + default: goto kk100; + } +kk136: + kkch = *++KKCURSOR; + switch (kkch) { + case 'N': + case 'n': goto kk137; + default: goto kk100; + } +kk137: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk138; + default: goto kk100; + } +kk138: + kkch = *++KKCURSOR; + switch (kkch) { + case 'D': + case 'd': goto kk139; + default: goto kk100; + } +kk139: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk140; + } +kk140: +// 335 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_DEFINED; + return 0; + } +// 1311 "scanner.c" +kk141: + kkch = *++KKCURSOR; + switch (kkch) { + case 'T': + case 't': goto kk142; + default: goto kk100; + } +kk142: + kkch = *++KKCURSOR; + switch (kkch) { + case 'U': + case 'u': goto kk143; + default: goto kk100; + } +kk143: + kkch = *++KKCURSOR; + switch (kkch) { + case 'R': + case 'r': goto kk144; + default: goto kk100; + } +kk144: + kkch = *++KKCURSOR; + switch (kkch) { + case 'N': + case 'n': goto kk145; + default: goto kk100; + } +kk145: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk146; } - } else { - PHALCON_CPY_WRT(ttl, lifetime); - } - - if (!phalcon_array_isset_quick_string(document, SS("time"), 275614484UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache is currupted"); - return; +kk146: +// 312 "scanner.re" + { + token->opcode = PHVOLT_T_RETURN; + return 0; } - - PHALCON_OBS_VAR(modified_time); - phalcon_array_fetch_quick_string(&modified_time, document, SS("time"), 275614484UL, PH_NOISY); - - PHALCON_INIT_VAR(difference); - sub_function(difference, timestamp, ttl TSRMLS_CC); - - PHALCON_INIT_VAR(not_expired); - is_smaller_function(not_expired, difference, modified_time TSRMLS_CC); - - if (PHALCON_IS_TRUE(not_expired)) { - if (!phalcon_array_isset_quick_string(document, SS("data"), 256359743UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache is currupted"); - return; +// 1415 "scanner.c" +kk147: + kkch = *++KKCURSOR; + switch (kkch) { + case 'T': + case 't': goto kk148; + default: goto kk100; } - - PHALCON_OBS_VAR(cached_content); - phalcon_array_fetch_quick_string(&cached_content, document, SS("data"), 256359743UL, PH_NOISY); - phalcon_call_method_p1_key(return_value, frontend, "afterretrieve", cached_content, 3229641981UL); - RETURN_MM(); - } - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Mongo, save){ - - zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; - zval *last_key = NULL, *prefix, *frontend, *cached_content = NULL; - zval *prepared_content, *ttl = NULL, *collection, *timestamp; - zval *conditions, *document, *data, *is_buffering; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!content) { - PHALCON_INIT_VAR(content); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (!stop_buffer) { - PHALCON_INIT_VAR(stop_buffer); - ZVAL_BOOL(stop_buffer, 1); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_VV(last_key, prefix, key_name); - } - if (!zend_is_true(last_key)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); - return; - } - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - if (Z_TYPE_P(content) == IS_NULL) { - PHALCON_INIT_VAR(cached_content); - phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); - } else { - PHALCON_CPY_WRT(cached_content, content); - } - - PHALCON_INIT_VAR(prepared_content); - phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); - if (Z_TYPE_P(lifetime) == IS_NULL) { - PHALCON_INIT_VAR(ttl); - phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); - } else { - PHALCON_CPY_WRT(ttl, lifetime); - } - - PHALCON_INIT_VAR(collection); - phalcon_call_method_key(collection, this_ptr, "_getcollection", 4161728624UL); - - PHALCON_INIT_VAR(timestamp); - ZVAL_LONG(timestamp, (long) time(NULL)); - - PHALCON_INIT_NVAR(ttl); - phalcon_add_function(ttl, lifetime, timestamp TSRMLS_CC); - - PHALCON_INIT_VAR(conditions); - array_init_size(conditions, 1); - phalcon_array_update_quick_string(&conditions, SS("key"), 2090432846UL, &last_key, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(document); - phalcon_call_method_p1_key(document, collection, "findone", conditions, 947441000UL); - if (Z_TYPE_P(document) == IS_ARRAY) { - phalcon_array_update_quick_string(&document, SS("time"), 275614484UL, &ttl, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&document, SS("data"), 256359743UL, &prepared_content, PH_COPY | PH_SEPARATE); - phalcon_call_method_p1_key(NULL, collection, "save", document, 274150868UL); - } else { - PHALCON_INIT_VAR(data); - array_init_size(data, 3); - phalcon_array_update_quick_string(&data, SS("key"), 2090432846UL, &last_key, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("time"), 275614484UL, &ttl, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&data, SS("data"), 256359743UL, &prepared_content, PH_COPY | PH_SEPARATE); - phalcon_call_method_p1_key(NULL, collection, "save", data, 274150868UL); - } - - PHALCON_INIT_VAR(is_buffering); - phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); - if (PHALCON_IS_TRUE(stop_buffer)) { - phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); - } - - if (PHALCON_IS_TRUE(is_buffering)) { - zend_print_zval(cached_content, 0); - } - - phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Mongo, delete){ - - zval *key_name, *prefix, *prefixed_key, *collection; - zval *conditions; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key_name); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_VV(prefixed_key, prefix, key_name); - - PHALCON_INIT_VAR(collection); - phalcon_call_method_key(collection, this_ptr, "_getcollection", 4161728624UL); - - PHALCON_INIT_VAR(conditions); - array_init_size(conditions, 1); - phalcon_array_update_quick_string(&conditions, SS("key"), 2090432846UL, &prefixed_key, PH_COPY | PH_SEPARATE); - phalcon_call_method_p1_key(NULL, collection, "remove", conditions, 1052443347UL); - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Cache_Backend_Mongo, queryKeys){ - - zval *prefix = NULL, *collection, *fields = NULL, *pattern, *regex; - zval *conditions = NULL, *documents, *keys, *documents_array; - zval *document = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - zend_class_entry *ce0; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &prefix); - - if (!prefix) { - PHALCON_INIT_VAR(prefix); - } - - PHALCON_INIT_VAR(collection); - phalcon_call_method_key(collection, this_ptr, "_getcollection", 4161728624UL); - - PHALCON_INIT_VAR(fields); - array_init_size(fields, 1); - add_next_index_stringl(fields, SL("key"), 1); - if (Z_TYPE_P(prefix) != IS_NULL) { - PHALCON_INIT_VAR(pattern); - PHALCON_CONCAT_SVS(pattern, "/^", prefix, "/"); - ce0 = zend_fetch_class(SL("MongoRegex"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); - - PHALCON_INIT_VAR(regex); - object_init_ex(regex, ce0); - if (phalcon_has_constructor(regex TSRMLS_CC)) { - phalcon_call_method_p1_key(NULL, regex, "__construct", pattern, 1107214344UL); - } - - PHALCON_INIT_VAR(conditions); - array_init_size(conditions, 1); - phalcon_array_update_quick_string(&conditions, SS("key"), 2090432846UL, ®ex, PH_COPY | PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(conditions); - array_init(conditions); - } - - PHALCON_INIT_NVAR(fields); - array_init_size(fields, 1); - add_next_index_stringl(fields, SL("key"), 1); - - PHALCON_INIT_VAR(documents); - phalcon_call_method_p2_key(documents, collection, "find", conditions, fields, 259012646UL); - - PHALCON_INIT_VAR(keys); - array_init(keys); - - PHALCON_INIT_VAR(documents_array); - phalcon_call_func_p1(documents_array, "iterator_to_array", documents); - - 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_OBS_NVAR(key); - phalcon_array_fetch_quick_string(&key, document, SS("key"), 2090432846UL, PH_NOISY); - phalcon_array_append(&keys, key, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CTOR(keys); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Mongo, exists){ - - zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *collection; - zval *conditions, *number, *zero; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_VV(last_key, prefix, key_name); - } - if (zend_is_true(last_key)) { - PHALCON_INIT_VAR(collection); - phalcon_call_method_key(collection, this_ptr, "_getcollection", 4161728624UL); - - PHALCON_INIT_VAR(conditions); - array_init_size(conditions, 1); - phalcon_array_update_quick_string(&conditions, SS("key"), 2090432846UL, &last_key, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(number); - phalcon_call_method_p1_key(number, collection, "count", conditions, 4142425646UL); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - is_smaller_function(return_value, zero, number TSRMLS_CC); - RETURN_MM(); - } - - RETURN_MM_FALSE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Cache_Backend_Xcache){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache\\Backend, Xcache, cache_backend_xcache, "phalcon\\cache\\backend", phalcon_cache_backend_xcache_method_entry, 0); - - zend_class_implements(phalcon_cache_backend_xcache_ce TSRMLS_CC, 1, phalcon_cache_backendinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Cache_Backend_Xcache, __construct){ - - zval *frontend, *options = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &frontend, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } else { - PHALCON_SEPARATE_PARAM(options); - } - - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_INIT_NVAR(options); - array_init(options); - } - if (!phalcon_array_isset_quick_string(options, SS("statsKey"), 2508919229UL)) { - phalcon_array_update_string_string(&options, SL("statsKey"), SL("_PHCX"), PH_SEPARATE); - } - - PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Cache\\Backend\\Xcache", "__construct", frontend, options); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Xcache, get){ - - zval *key_name, *lifetime = NULL, *frontend, *prefix, *prefixed_key; - zval *cached_content; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_SVV(prefixed_key, "_PHCX", prefix, key_name); - phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), prefixed_key, 394299009UL TSRMLS_CC); - - PHALCON_INIT_VAR(cached_content); - phalcon_call_func_p1(cached_content, "xcache_get", prefixed_key); - if (Z_TYPE_P(cached_content) == IS_NULL) { - RETURN_MM_NULL(); - } - - phalcon_call_method_p1_key(return_value, frontend, "afterretrieve", cached_content, 3229641981UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Xcache, save){ - - zval *key_name = NULL, *content = NULL, *lifetime = NULL, *stop_buffer = NULL; - zval *last_key = NULL, *prefix, *frontend, *cached_content = NULL; - zval *prepared_content, *ttl = NULL, *success, *is_buffering; - zval *options, *special_key, *keys = NULL, *zero; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 4, &key_name, &content, &lifetime, &stop_buffer); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!content) { - PHALCON_INIT_VAR(content); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (!stop_buffer) { - PHALCON_INIT_VAR(stop_buffer); - ZVAL_BOOL(stop_buffer, 1); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_SVV(last_key, "_PHCX", prefix, key_name); - } - if (!zend_is_true(last_key)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The cache must be started first"); - return; - } - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - if (Z_TYPE_P(content) == IS_NULL) { - PHALCON_INIT_VAR(cached_content); - phalcon_call_method_key(cached_content, frontend, "getcontent", 3141446400UL); - } else { - PHALCON_CPY_WRT(cached_content, content); - } - - PHALCON_INIT_VAR(prepared_content); - phalcon_call_method_p1_key(prepared_content, frontend, "beforestore", cached_content, 2051590149UL); - - if (Z_TYPE_P(lifetime) == IS_NULL) { - - PHALCON_OBS_NVAR(ttl); - phalcon_read_property_this_quick(&ttl, this_ptr, SL("_lastLifetime"), 3936785351UL, PH_NOISY_CC); - if (Z_TYPE_P(ttl) == IS_NULL) { - PHALCON_INIT_NVAR(ttl); - phalcon_call_method_key(ttl, frontend, "getlifetime", 673603636UL); +kk148: + kkch = *++KKCURSOR; + switch (kkch) { + case 'H': + case 'h': goto kk149; + default: goto kk100; + } +kk149: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk150; + } +kk150: +// 307 "scanner.re" + { + token->opcode = PHVOLT_T_WITH; + return 0; } - } else { - PHALCON_CPY_WRT(ttl, lifetime); - } - - PHALCON_INIT_VAR(success); - phalcon_call_func_p3(success, "xcache_set", last_key, prepared_content, ttl); - - PHALCON_INIT_VAR(is_buffering); - phalcon_call_method_key(is_buffering, frontend, "isbuffering", 3755417113UL); - if (PHALCON_IS_TRUE(stop_buffer)) { - phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); - } - - if (PHALCON_IS_TRUE(is_buffering)) { - zend_print_zval(cached_content, 0); - } - - phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); - - if (zend_is_true(success)) { - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(special_key); - phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); - - PHALCON_INIT_VAR(keys); - phalcon_call_func_p1(keys, "xcache_get", special_key); - if (Z_TYPE_P(keys) != IS_ARRAY) { - PHALCON_INIT_NVAR(keys); - array_init(keys); +// 1505 "scanner.c" +kk151: + kkch = *++KKCURSOR; + switch (kkch) { + case 'C': + case 'c': goto kk161; + case 'L': + case 'l': goto kk160; + default: goto kk100; + } +kk152: + kkch = *++KKCURSOR; + switch (kkch) { + case 'N': + case 'n': goto kk153; + default: goto kk100; + } +kk153: + kkch = *++KKCURSOR; + switch (kkch) { + case 'T': + case 't': goto kk154; + default: goto kk100; + } +kk154: + kkch = *++KKCURSOR; + switch (kkch) { + case 'I': + case 'i': goto kk155; + default: goto kk100; + } +kk155: + kkch = *++KKCURSOR; + switch (kkch) { + case 'N': + case 'n': goto kk156; + default: goto kk100; + } +kk156: + kkch = *++KKCURSOR; + switch (kkch) { + case 'U': + case 'u': goto kk157; + default: goto kk100; + } +kk157: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk158; + default: goto kk100; + } +kk158: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk159; + } +kk159: +// 376 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_CONTINUE; + return 0; } - - if (!zend_is_true(keys)) { - phalcon_array_update_zval(&keys, last_key, &ttl, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); +// 1633 "scanner.c" +kk160: + kkch = *++KKCURSOR; + switch (kkch) { + case 'L': + case 'l': goto kk165; + default: goto kk100; + } +kk161: + kkch = *++KKCURSOR; + switch (kkch) { + case 'H': + case 'h': goto kk162; + default: goto kk100; + } +kk162: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk163; + default: goto kk100; + } +kk163: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk164; + } +kk164: +// 347 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_CACHE; + return 0; } - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Xcache, delete){ - - zval *key_name, *prefix, *prefixed_key, *success; - zval *options, *special_key, *keys, *zero; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key_name); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_SVV(prefixed_key, "_PHCX", prefix, key_name); - - PHALCON_INIT_VAR(success); - phalcon_call_func_p1(success, "xcache_unset", prefixed_key); - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(special_key); - phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); - - PHALCON_INIT_VAR(keys); - phalcon_call_func_p1(keys, "xcache_get", special_key); - if (Z_TYPE_P(keys) == IS_ARRAY) { - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - phalcon_array_unset(&keys, special_key, PH_SEPARATE); - phalcon_call_func_p3_noret("xcache_set", special_key, keys, zero); - } - - RETURN_CCTOR(success); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Xcache, queryKeys){ - - zval *prefix = NULL, *prefixed, *options, *special_key; - zval *keys, *prefixed_keys, *ttl = NULL, *key = NULL, *real_key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &prefix); - - PHALCON_INIT_VAR(prefixed); - if (!prefix) { - ZVAL_STRING(prefixed, "_PHCX", 1); - } - else { - PHALCON_CONCAT_SV(prefixed, "_PHCX", prefix); - } - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(special_key); - phalcon_array_fetch_quick_string(&special_key, options, SS("statsKey"), 2508919229UL, PH_NOISY); - - PHALCON_INIT_VAR(keys); - phalcon_call_func_p1(keys, "xcache_get", special_key); - if (Z_TYPE_P(keys) == IS_ARRAY) { - - PHALCON_INIT_VAR(prefixed_keys); - array_init(prefixed_keys); - - phalcon_is_iterable(keys, &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(ttl); - - if (!phalcon_memnstr(key, prefixed)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; +// 1731 "scanner.c" +kk165: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk166; + } +kk166: +// 296 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_CALL; + return 0; + } +// 1808 "scanner.c" +kk167: + kkch = *++KKCURSOR; + switch (kkch) { + case 'C': + case 'c': goto kk168; + default: goto kk100; + } +kk168: + kkch = *++KKCURSOR; + switch (kkch) { + case 'R': + case 'r': goto kk169; + default: goto kk100; + } +kk169: + kkch = *++KKCURSOR; + switch (kkch) { + case 'O': + case 'o': goto kk170; + default: goto kk100; + } +kk170: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk171; } - - PHALCON_INIT_NVAR(real_key); - phalcon_substr(real_key, key, 5, 0); - phalcon_array_append(&prefixed_keys, real_key, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CTOR(prefixed_keys); - } - - RETURN_MM_EMPTY_ARRAY(); -} - -static PHP_METHOD(Phalcon_Cache_Backend_Xcache, exists){ - - zval *key_name = NULL, *lifetime = NULL, *last_key = NULL, *prefix, *cache_exists; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &key_name, &lifetime); - - if (!key_name) { - PHALCON_INIT_VAR(key_name); - } - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - if (Z_TYPE_P(key_name) == IS_NULL) { - PHALCON_OBS_VAR(last_key); - phalcon_read_property_this_quick(&last_key, this_ptr, SL("_lastKey"), 394299009UL, PH_NOISY_CC); - } else { - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_NVAR(last_key); - PHALCON_CONCAT_SVV(last_key, "_PHCX", prefix, key_name); - } - if (zend_is_true(last_key)) { - - PHALCON_INIT_VAR(cache_exists); - phalcon_call_func_p1(cache_exists, "xcache_isset", last_key); - if (PHALCON_IS_NOT_FALSE(cache_exists)) { - RETURN_MM_TRUE; +kk171: +// 285 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_MACRO; + return 0; } - } - - RETURN_MM_FALSE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Cache_BackendInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Cache, BackendInterface, cache_backendinterface, phalcon_cache_backendinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Cache_Backend){ - - PHALCON_REGISTER_CLASS(Phalcon\\Cache, Backend, cache_backend, phalcon_cache_backend_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - zend_declare_property_null(phalcon_cache_backend_ce, SL("_frontend"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cache_backend_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_cache_backend_ce, SL("_prefix"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_cache_backend_ce, SL("_lastKey"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cache_backend_ce, SL("_lastLifetime"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_cache_backend_ce, SL("_fresh"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_cache_backend_ce, SL("_started"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Cache_Backend, __construct){ - - zval *frontend, *options = NULL, *prefix; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &frontend, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (Z_TYPE_P(frontend) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Frontend must be an Object"); - return; - } - - if (phalcon_array_isset_quick_string(options, SS("prefix"), 3263410483UL)) { - PHALCON_OBS_VAR(prefix); - phalcon_array_fetch_quick_string(&prefix, options, SS("prefix"), 3263410483UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); - } - - phalcon_update_property_this_quick(this_ptr, SL("_frontend"), frontend, 3187914628UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Cache_Backend, start){ - - zval *key_name, *lifetime = NULL, *existing_cache, *fresh = NULL; - zval *frontend; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &key_name, &lifetime); - - if (!lifetime) { - PHALCON_INIT_VAR(lifetime); - } - - PHALCON_INIT_VAR(existing_cache); - phalcon_call_method_p2_key(existing_cache, this_ptr, "get", key_name, lifetime, 2090288933UL); - if (Z_TYPE_P(existing_cache) == IS_NULL) { - PHALCON_INIT_VAR(fresh); - ZVAL_BOOL(fresh, 1); - - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - phalcon_call_method_key(NULL, frontend, "start", 478839859UL); - } else { - PHALCON_INIT_NVAR(fresh); - ZVAL_BOOL(fresh, 0); - } - - phalcon_update_property_this_quick(this_ptr, SL("_fresh"), fresh, 2329058172UL TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_started"), 1 TSRMLS_CC); - - if (Z_TYPE_P(lifetime) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_lastLifetime"), lifetime, 3936785351UL TSRMLS_CC); - } - - RETURN_CCTOR(existing_cache); -} - -static PHP_METHOD(Phalcon_Cache_Backend, stop){ - - zval *stop_buffer = NULL, *frontend; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &stop_buffer); - - if (!stop_buffer) { - PHALCON_INIT_VAR(stop_buffer); - ZVAL_BOOL(stop_buffer, 1); - } - - if (PHALCON_IS_TRUE(stop_buffer)) { - PHALCON_OBS_VAR(frontend); - phalcon_read_property_this_quick(&frontend, this_ptr, SL("_frontend"), 3187914628UL, PH_NOISY_CC); - phalcon_call_method_key(NULL, frontend, "stop", 274826411UL); - } - phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Cache_Backend, getFrontend){ - - - RETURN_MEMBER_QUICK(this_ptr, "_frontend", 3187914628UL); -} - -static PHP_METHOD(Phalcon_Cache_Backend, getOptions){ - - - RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); -} - -static PHP_METHOD(Phalcon_Cache_Backend, isFresh){ - - - RETURN_MEMBER_QUICK(this_ptr, "_fresh", 2329058172UL); -} - -static PHP_METHOD(Phalcon_Cache_Backend, isStarted){ - - - RETURN_MEMBER_QUICK(this_ptr, "_started", 433407867UL); -} - -static PHP_METHOD(Phalcon_Cache_Backend, setLastKey){ - - zval *last_key; - - phalcon_fetch_params(0, 1, 0, &last_key); - - phalcon_update_property_this_quick(this_ptr, SL("_lastKey"), last_key, 394299009UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Cache_Backend, getLastKey){ - - - RETURN_MEMBER_QUICK(this_ptr, "_lastKey", 394299009UL); -} - -static PHP_METHOD(Phalcon_Cache_Backend, getLifetime){ - - - RETURN_MEMBER_QUICK(this_ptr, "_lastLifetime", 3936785351UL); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Cache_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Cache, Exception, cache_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Escaper){ - - PHALCON_REGISTER_CLASS(Phalcon, Escaper, escaper, phalcon_escaper_method_entry, 0); - - zend_declare_property_string(phalcon_escaper_ce, SL("_encoding"), "utf-8", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_escaper_ce, SL("_htmlEscapeMap"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_escaper_ce, SL("_htmlQuoteType"), 3, ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_escaper_ce TSRMLS_CC, 1, phalcon_escaperinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Escaper, setEncoding){ - - zval *encoding; - - phalcon_fetch_params(0, 1, 0, &encoding); - - if (unlikely(Z_TYPE_P(encoding) != IS_STRING)) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_escaper_exception_ce, "The character set must be string"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_encoding"), encoding, 4261080171UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Escaper, getEncoding){ - - - RETURN_MEMBER_QUICK(this_ptr, "_encoding", 4261080171UL); -} - -static PHP_METHOD(Phalcon_Escaper, setHtmlQuoteType){ - - zval *quote_type; - - phalcon_fetch_params(0, 1, 0, "e_type); - - if (Z_TYPE_P(quote_type) != IS_LONG) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_escaper_exception_ce, "The quoting type is not valid"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_htmlQuoteType"), quote_type, 477993385UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Escaper, detectEncoding){ - - zval *str, *charset = NULL, *strict_check, *detected = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &str); - - PHALCON_INIT_VAR(charset); - phalcon_is_basic_charset(charset, str); - if (Z_TYPE_P(charset) == IS_STRING) { - RETURN_CTOR(charset); - } - - if (phalcon_function_quick_exists_ex(SS("mb_detect_encoding"), 2715391634UL TSRMLS_CC) == FAILURE) { - RETURN_MM_NULL(); - } - - PHALCON_INIT_VAR(strict_check); - ZVAL_BOOL(strict_check, 1); - - PHALCON_INIT_NVAR(charset); - ZVAL_STRING(charset, "UTF-32", 1); - - PHALCON_INIT_VAR(detected); - phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check); - if (zend_is_true(detected)) { - RETURN_CTOR(charset); - } - - PHALCON_INIT_NVAR(charset); - ZVAL_STRING(charset, "UTF-16", 1); - - PHALCON_INIT_NVAR(detected); - phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check); - if (zend_is_true(detected)) { - RETURN_CTOR(charset); - } - - PHALCON_INIT_NVAR(charset); - ZVAL_STRING(charset, "UTF-8", 1); - - PHALCON_INIT_NVAR(detected); - phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check); - if (zend_is_true(detected)) { - RETURN_CTOR(charset); - } - - PHALCON_INIT_NVAR(charset); - ZVAL_STRING(charset, "ISO-8859-1", 1); - - PHALCON_INIT_NVAR(detected); - phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check); - if (zend_is_true(detected)) { - RETURN_CTOR(charset); - } - - PHALCON_INIT_NVAR(charset); - ZVAL_STRING(charset, "ASCII", 1); - - PHALCON_INIT_NVAR(detected); - phalcon_call_func_p3(detected, "mb_detect_encoding", str, charset, strict_check); - if (zend_is_true(detected)) { - RETURN_CTOR(charset); - } - - phalcon_call_func_p1(return_value, "mb_detect_encoding", str); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Escaper, normalizeEncoding){ - - zval *str, *encoding, *charset; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &str); - - if (phalcon_function_quick_exists_ex(SS("mb_convert_encoding"), 2165643194UL TSRMLS_CC) == FAILURE) { - PHALCON_THROW_EXCEPTION_STR(phalcon_escaper_exception_ce, "Extension 'mbstring' is required"); - return; - } - - PHALCON_INIT_VAR(encoding); - phalcon_call_method_p1_key(encoding, this_ptr, "detectencoding", str, 3095134469UL); - - PHALCON_INIT_VAR(charset); - ZVAL_STRING(charset, "UTF-32", 1); - - phalcon_call_func_p3(return_value, "mb_convert_encoding", str, charset, encoding); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Escaper, escapeHtml){ - - zval *text, *html_quote_type, *encoding; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &text); - - if (Z_TYPE_P(text) == IS_STRING) { - PHALCON_OBS_VAR(html_quote_type); - phalcon_read_property_this_quick(&html_quote_type, this_ptr, SL("_htmlQuoteType"), 477993385UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(encoding); - phalcon_read_property_this_quick(&encoding, this_ptr, SL("_encoding"), 4261080171UL, PH_NOISY_CC); - phalcon_call_func_p3(return_value, "htmlspecialchars", text, html_quote_type, encoding); - RETURN_MM(); - } - - RETURN_CCTOR(text); -} - -static PHP_METHOD(Phalcon_Escaper, escapeHtmlAttr){ - - zval *attribute, *normalized; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &attribute); - - if (Z_TYPE_P(attribute) == IS_STRING) { - if (zend_is_true(attribute)) { - - PHALCON_INIT_VAR(normalized); - phalcon_call_method_p1_key(normalized, this_ptr, "normalizeencoding", attribute, 3216085085UL); - - phalcon_escape_htmlattr(return_value, normalized); - RETURN_MM(); +// 1906 "scanner.c" +kk172: + kkch = *++KKCURSOR; + switch (kkch) { + case 'O': + case 'o': goto kk178; + default: goto kk100; + } +kk173: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk174; + default: goto kk100; + } +kk174: + kkch = *++KKCURSOR; + switch (kkch) { + case 'A': + case 'a': goto kk175; + default: goto kk100; + } +kk175: + kkch = *++KKCURSOR; + switch (kkch) { + case 'K': + case 'k': goto kk176; + default: goto kk100; + } +kk176: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk177; + } +kk177: +// 382 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_BREAK; + return 0; } - } - - RETURN_CCTOR(attribute); -} - -static PHP_METHOD(Phalcon_Escaper, escapeCss){ - - zval *css, *normalized; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &css); - - if (Z_TYPE_P(css) == IS_STRING) { - if (zend_is_true(css)) { - - PHALCON_INIT_VAR(normalized); - phalcon_call_method_p1_key(normalized, this_ptr, "normalizeencoding", css, 3216085085UL); - - phalcon_escape_css(return_value, normalized); - RETURN_MM(); +// 2011 "scanner.c" +kk178: + kkch = *++KKCURSOR; + switch (kkch) { + case 'C': + case 'c': goto kk179; + default: goto kk100; + } +kk179: + kkch = *++KKCURSOR; + switch (kkch) { + case 'K': + case 'k': goto kk180; + default: goto kk100; + } +kk180: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk181; + } +kk181: +// 274 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_BLOCK; + return 0; } - } - - RETURN_CCTOR(css); -} - -static PHP_METHOD(Phalcon_Escaper, escapeJs){ - - zval *js, *normalized; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &js); - - if (Z_TYPE_P(js) == IS_STRING) { - if (zend_is_true(js)) { - - PHALCON_INIT_VAR(normalized); - phalcon_call_method_p1_key(normalized, this_ptr, "normalizeencoding", js, 3216085085UL); - - phalcon_escape_js(return_value, normalized); - RETURN_MM(); +// 2102 "scanner.c" +kk182: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk183; + } +kk183: +// 269 "scanner.re" + { + token->opcode = PHVOLT_T_OR; + return 0; + } +// 2178 "scanner.c" +kk184: + kkch = *++KKCURSOR; + switch (kkch) { + case 'D': + case 'd': goto kk195; + default: goto kk100; + } +kk185: + kkch = *++KKCURSOR; + switch (kkch) { + case 'T': + case 't': goto kk186; + default: goto kk100; + } +kk186: + kkch = *++KKCURSOR; + switch (kkch) { + case 'O': + case 'o': goto kk187; + default: goto kk100; + } +kk187: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk188; + default: goto kk100; + } +kk188: + kkch = *++KKCURSOR; + switch (kkch) { + case 'S': + case 's': goto kk189; + default: goto kk100; + } +kk189: + kkch = *++KKCURSOR; + switch (kkch) { + case 'C': + case 'c': goto kk190; + default: goto kk100; + } +kk190: + kkch = *++KKCURSOR; + switch (kkch) { + case 'A': + case 'a': goto kk191; + default: goto kk100; + } +kk191: + kkch = *++KKCURSOR; + switch (kkch) { + case 'P': + case 'p': goto kk192; + default: goto kk100; + } +kk192: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk193; + default: goto kk100; + } +kk193: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk194; + } +kk194: +// 364 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_AUTOESCAPE; + return 0; + } +// 2318 "scanner.c" +kk195: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk196; + } +kk196: +// 264 "scanner.re" + { + token->opcode = PHVOLT_T_AND; + return 0; } - } - - RETURN_CCTOR(js); -} - -static PHP_METHOD(Phalcon_Escaper, escapeUrl){ - - zval *url; - - phalcon_fetch_params(0, 1, 0, &url); - - phalcon_raw_url_encode(return_value, url); - return; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_CryptInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon, CryptInterface, cryptinterface, phalcon_cryptinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_CLI_Router){ - - PHALCON_REGISTER_CLASS(Phalcon\\CLI, Router, cli_router, phalcon_cli_router_method_entry, 0); - - zend_declare_property_null(phalcon_cli_router_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cli_router_ce, SL("_module"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cli_router_ce, SL("_task"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cli_router_ce, SL("_action"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cli_router_ce, SL("_params"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cli_router_ce, SL("_defaultModule"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cli_router_ce, SL("_defaultTask"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cli_router_ce, SL("_defaultAction"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cli_router_ce, SL("_defaultParams"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_cli_router_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_CLI_Router, __construct){ - - - phalcon_update_property_empty_array(phalcon_cli_router_ce, this_ptr, SL("_params") TSRMLS_CC); - - phalcon_update_property_empty_array(phalcon_cli_router_ce, this_ptr, SL("_defaultParams") TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_CLI_Router, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_CLI_Router, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -static PHP_METHOD(Phalcon_CLI_Router, setDefaultModule){ - - zval *module_name; - - phalcon_fetch_params(0, 1, 0, &module_name); - - phalcon_update_property_this_quick(this_ptr, SL("_defaultModule"), module_name, 3959488399UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_CLI_Router, setDefaultTask){ - - zval *task_name; - - phalcon_fetch_params(0, 1, 0, &task_name); - - phalcon_update_property_this_quick(this_ptr, SL("_defaultTask"), task_name, 3852862556UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_CLI_Router, setDefaultAction){ - - zval *action_name; - - phalcon_fetch_params(0, 1, 0, &action_name); - - phalcon_update_property_this_quick(this_ptr, SL("_defaultAction"), action_name, 895696999UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_CLI_Router, handle){ - - zval *arguments = NULL, *module_name = NULL, *task_name = NULL, *action_name = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &arguments); - - if (!arguments) { - PHALCON_INIT_VAR(arguments); - array_init(arguments); - } else { - PHALCON_SEPARATE_PARAM(arguments); - } - - if (Z_TYPE_P(arguments) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cli_router_exception_ce, "Arguments must be an Array"); - return; - } - - PHALCON_INIT_VAR(module_name); - - PHALCON_INIT_VAR(task_name); - - PHALCON_INIT_VAR(action_name); - - if (phalcon_array_isset_quick_string(arguments, SS("module"), 3565923467UL)) { - PHALCON_OBS_NVAR(module_name); - phalcon_array_fetch_quick_string(&module_name, arguments, SS("module"), 3565923467UL, PH_NOISY); - phalcon_array_unset_string(&arguments, SS("module"), PH_SEPARATE); - } - - if (phalcon_array_isset_quick_string(arguments, SS("task"), 275333720UL)) { - PHALCON_OBS_NVAR(task_name); - phalcon_array_fetch_quick_string(&task_name, arguments, SS("task"), 275333720UL, PH_NOISY); - phalcon_array_unset_string(&arguments, SS("task"), PH_SEPARATE); - } - - if (phalcon_array_isset_quick_string(arguments, SS("action"), 502132067UL)) { - PHALCON_OBS_NVAR(action_name); - phalcon_array_fetch_quick_string(&action_name, arguments, SS("action"), 502132067UL, PH_NOISY); - phalcon_array_unset_string(&arguments, SS("action"), PH_SEPARATE); - } - - phalcon_update_property_this_quick(this_ptr, SL("_module"), module_name, 4176304298UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_task"), task_name, 3991100087UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_action"), action_name, 1112512898UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_params"), arguments, 3223731112UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_CLI_Router, getModuleName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_module", 4176304298UL); -} - -static PHP_METHOD(Phalcon_CLI_Router, getTaskName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_task", 3991100087UL); -} - -static PHP_METHOD(Phalcon_CLI_Router, getActionName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_action", 1112512898UL); -} - -static PHP_METHOD(Phalcon_CLI_Router, getParams){ - - - RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_CLI_Router_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Router, Exception, cli_router_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_CLI_Task){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI, Task, cli_task, "phalcon\\di\\injectable", phalcon_cli_task_method_entry, 0); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_CLI_Task, __construct){ - - - -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_CLI_Dispatcher){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI, Dispatcher, cli_dispatcher, "phalcon\\dispatcher", phalcon_cli_dispatcher_method_entry, 0); - - zend_declare_property_string(phalcon_cli_dispatcher_ce, SL("_handlerSuffix"), "Task", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_cli_dispatcher_ce, SL("_defaultHandler"), "main", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_cli_dispatcher_ce, SL("_defaultAction"), "main", ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_CLI_Dispatcher, setTaskSuffix){ - - zval *task_suffix; - - phalcon_fetch_params(0, 1, 0, &task_suffix); - - phalcon_update_property_this_quick(this_ptr, SL("_handlerSuffix"), task_suffix, 1659190583UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_CLI_Dispatcher, setDefaultTask){ - - zval *task_name; - - phalcon_fetch_params(0, 1, 0, &task_name); - - phalcon_update_property_this_quick(this_ptr, SL("_defaultHandler"), task_name, 2940762855UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_CLI_Dispatcher, setTaskName){ - - zval *task_name; - - phalcon_fetch_params(0, 1, 0, &task_name); - - phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), task_name, 2743819555UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_CLI_Dispatcher, getTaskName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_handlerName", 2743819555UL); -} - -static PHP_METHOD(Phalcon_CLI_Dispatcher, _throwDispatchException){ - - zval *message, *exception_code = NULL, *exception, *events_manager; - zval *event_name, *status; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &message, &exception_code); - - if (!exception_code) { - PHALCON_INIT_VAR(exception_code); - ZVAL_LONG(exception_code, 0); - } - - PHALCON_INIT_VAR(exception); - object_init_ex(exception, phalcon_cli_dispatcher_exception_ce); - phalcon_call_method_p2_key(NULL, exception, "__construct", message, exception_code, 1107214344UL); - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "dispatch:beforeException", 1); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, exception, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; +// 2394 "scanner.c" +kk197: + kkch = *++KKCURSOR; + switch (kkch) { + case 'U': + case 'u': goto kk198; + default: goto kk100; + } +kk198: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk199; + default: goto kk100; + } +kk199: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk200; + } +kk200: +// 259 "scanner.re" + { + token->opcode = PHVOLT_T_TRUE; + return 0; + } +// 2484 "scanner.c" +kk201: + kkch = *++KKCURSOR; + switch (kkch) { + case 'T': + case 't': goto kk206; + default: goto kk100; + } +kk202: + kkch = *++KKCURSOR; + switch (kkch) { + case 'L': + case 'l': goto kk203; + default: goto kk100; + } +kk203: + kkch = *++KKCURSOR; + switch (kkch) { + case 'L': + case 'l': goto kk204; + default: goto kk100; + } +kk204: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk205; + } +kk205: +// 249 "scanner.re" + { + token->opcode = PHVOLT_T_NULL; + return 0; } - } - - phalcon_throw_exception(exception TSRMLS_CC); - return; -} - -static PHP_METHOD(Phalcon_CLI_Dispatcher, _handleException){ - - zval *exception, *events_manager, *event_name; - zval *status; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &exception); - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "dispatch:beforeException", 1); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, exception, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; +// 2581 "scanner.c" +kk206: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk207; + } +kk207: +// 329 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_NOT; + return 0; } - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_CLI_Dispatcher, getTaskClass){ - - - PHALCON_MM_GROW(); - - phalcon_call_method_key(return_value, this_ptr, "gethandlername", 1725429572UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_CLI_Dispatcher, getLastTask){ - - - RETURN_MEMBER_QUICK(this_ptr, "_lastHandler", 1315517974UL); -} - -static PHP_METHOD(Phalcon_CLI_Dispatcher, getActiveTask){ - - - RETURN_MEMBER_QUICK(this_ptr, "_activeHandler", 2923197278UL); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_CLI_Console){ - - PHALCON_REGISTER_CLASS(Phalcon\\CLI, Console, cli_console, phalcon_cli_console_method_entry, 0); - - zend_declare_property_null(phalcon_cli_console_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cli_console_ce, SL("_eventsManager"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cli_console_ce, SL("_modules"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_cli_console_ce, SL("_moduleObject"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_cli_console_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_events_eventsawareinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_CLI_Console, __construct){ - - zval *dependency_injector = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &dependency_injector); - - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } - - if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_CLI_Console, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_cli_console_exception_ce, "Dependency Injector is invalid"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_CLI_Console, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -static PHP_METHOD(Phalcon_CLI_Console, setEventsManager){ - - zval *events_manager; - - phalcon_fetch_params(0, 1, 0, &events_manager); - - phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_CLI_Console, getEventsManager){ - - - RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); -} - -static PHP_METHOD(Phalcon_CLI_Console, registerModules){ - - zval *modules; - - phalcon_fetch_params(0, 1, 0, &modules); - - if (Z_TYPE_P(modules) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_cli_console_exception_ce, "Modules must be an Array"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_modules"), modules, 379092157UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_CLI_Console, addModules){ - - zval *modules, *original_modules, *register_modules; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &modules); - - if (Z_TYPE_P(modules) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cli_console_exception_ce, "Modules must be an Array"); - return; - } - - PHALCON_OBS_VAR(original_modules); - phalcon_read_property_this_quick(&original_modules, this_ptr, SL("_modules"), 379092157UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(register_modules); - phalcon_fast_array_merge(register_modules, &modules, &original_modules TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_modules"), register_modules, 379092157UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_CLI_Console, getModules){ - - - RETURN_MEMBER_QUICK(this_ptr, "_modules", 379092157UL); -} - -static PHP_METHOD(Phalcon_CLI_Console, handle){ - - zval *arguments = NULL, *dependency_injector, *events_manager; - zval *service = NULL, *router, *module_name, *event_name = NULL; - zval *status = NULL, *modules, *exception_msg = NULL, *module; - zval *path, *class_name = NULL, *module_object, *task_name; - zval *action_name, *params, *dispatcher, *task; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &arguments); - - if (!arguments) { - PHALCON_INIT_VAR(arguments); - array_init(arguments); - } - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cli_console_exception_ce, "A dependency injection object is required to access internal services"); - return; - } - - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "router", 1); - - PHALCON_INIT_VAR(router); - phalcon_call_method_p1_key(router, dependency_injector, "getshared", service, 1727570332UL); - phalcon_call_method_p1_key(NULL, router, "handle", arguments, 866903697UL); - - PHALCON_INIT_VAR(module_name); - phalcon_call_method_key(module_name, router, "getmodulename", 3538616428UL); - if (zend_is_true(module_name)) { - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "console:beforeStartModule", 1); - - PHALCON_INIT_VAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, module_name, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; +// 2658 "scanner.c" +kk208: + kkch = *++KKCURSOR; + switch (kkch) { + case 'T': + case 't': goto kk209; + default: goto kk100; + } +kk209: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk210; + } +kk210: +// 244 "scanner.re" + { + token->opcode = PHVOLT_T_SET; + return 0; + } +// 2741 "scanner.c" +kk211: + kkch = *++KKCURSOR; + switch (kkch) { + case 'L': + case 'l': goto kk215; + default: goto kk100; + } +kk212: + kkch = *++KKCURSOR; + switch (kkch) { + case 'R': + case 'r': goto kk213; + default: goto kk100; + } +kk213: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk214; + } +kk214: +// 228 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_FOR; + return 0; + } +// 2832 "scanner.c" +kk215: + kkch = *++KKCURSOR; + switch (kkch) { + case 'S': + case 's': goto kk216; + default: goto kk100; + } +kk216: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk217; + default: goto kk100; } +kk217: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk218; + } +kk218: +// 254 "scanner.re" + { + token->opcode = PHVOLT_T_FALSE; + return 0; } - - PHALCON_OBS_VAR(modules); - phalcon_read_property_this_quick(&modules, this_ptr, SL("_modules"), 379092157UL, PH_NOISY_CC); - if (!phalcon_array_isset(modules, module_name)) { - PHALCON_INIT_VAR(exception_msg); - PHALCON_CONCAT_SVS(exception_msg, "Module '", module_name, "' isn't registered in the console container"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_cli_console_exception_ce, exception_msg); - return; +// 2922 "scanner.c" +kk219: + kkch = *++KKCURSOR; + switch (kkch) { + case 'S': + case 's': goto kk268; + default: goto kk100; + } +kk220: + kkch = *++KKCURSOR; + switch (kkch) { + case 'D': + case 'd': goto kk228; + default: goto kk100; + } +kk221: + kkch = *++KKCURSOR; + switch (kkch) { + case 'T': + case 't': goto kk222; + default: goto kk100; + } +kk222: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk223; + default: goto kk100; + } +kk223: + kkch = *++KKCURSOR; + switch (kkch) { + case 'N': + case 'n': goto kk224; + default: goto kk100; + } +kk224: + kkch = *++KKCURSOR; + switch (kkch) { + case 'D': + case 'd': goto kk225; + default: goto kk100; + } +kk225: + kkch = *++KKCURSOR; + switch (kkch) { + case 'S': + case 's': goto kk226; + default: goto kk100; + } +kk226: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk227; + } +kk227: +// 317 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_EXTENDS; + return 0; } - - PHALCON_OBS_VAR(module); - phalcon_array_fetch(&module, modules, module_name, PH_NOISY); - if (Z_TYPE_P(module) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_cli_console_exception_ce, "Invalid module definition path"); - return; +// 3048 "scanner.c" +kk228: + kkch = *++KKCURSOR; + switch (kkch) { + case 'A': + case 'a': goto kk229; + case 'B': + case 'b': goto kk230; + case 'C': + case 'c': goto kk231; + case 'F': + case 'f': goto kk232; + case 'I': + case 'i': goto kk233; + case 'M': + case 'm': goto kk234; + default: goto kk100; + } +kk229: + kkch = *++KKCURSOR; + switch (kkch) { + case 'U': + case 'u': goto kk258; + default: goto kk100; + } +kk230: + kkch = *++KKCURSOR; + switch (kkch) { + case 'L': + case 'l': goto kk253; + default: goto kk100; + } +kk231: + kkch = *++KKCURSOR; + switch (kkch) { + case 'A': + case 'a': goto kk245; + default: goto kk100; + } +kk232: + kkch = *++KKCURSOR; + switch (kkch) { + case 'O': + case 'o': goto kk242; + default: goto kk100; + } +kk233: + kkch = *++KKCURSOR; + switch (kkch) { + case 'F': + case 'f': goto kk240; + default: goto kk100; + } +kk234: + kkch = *++KKCURSOR; + switch (kkch) { + case 'A': + case 'a': goto kk235; + default: goto kk100; + } +kk235: + kkch = *++KKCURSOR; + switch (kkch) { + case 'C': + case 'c': goto kk236; + default: goto kk100; + } +kk236: + kkch = *++KKCURSOR; + switch (kkch) { + case 'R': + case 'r': goto kk237; + default: goto kk100; + } +kk237: + kkch = *++KKCURSOR; + switch (kkch) { + case 'O': + case 'o': goto kk238; + default: goto kk100; + } +kk238: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk239; + } +kk239: +// 291 "scanner.re" + { + token->opcode = PHVOLT_T_ENDMACRO; + return 0; } - - if (phalcon_array_isset_quick_string(module, SS("path"), 270591026UL)) { - - PHALCON_OBS_VAR(path); - phalcon_array_fetch_quick_string(&path, module, SS("path"), 270591026UL, PH_NOISY); - if (phalcon_file_exists(path TSRMLS_CC) == SUCCESS) { - if (phalcon_require(path TSRMLS_CC) == FAILURE) { - return; - } - } else { - PHALCON_INIT_NVAR(exception_msg); - PHALCON_CONCAT_SVS(exception_msg, "Module definition path '", path, "\" doesn't exist"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_cli_console_exception_ce, exception_msg); - return; +// 3204 "scanner.c" +kk240: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk241; + } +kk241: +// 223 "scanner.re" + { + token->opcode = PHVOLT_T_ENDIF; + return 0; + } +// 3280 "scanner.c" +kk242: + kkch = *++KKCURSOR; + switch (kkch) { + case 'R': + case 'r': goto kk243; + default: goto kk100; + } +kk243: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk244; } +kk244: +// 234 "scanner.re" + { + token->opcode = PHVOLT_T_ENDFOR; + return 0; } - - if (phalcon_array_isset_quick_string(module, SS("className"), 362439804UL)) { - PHALCON_OBS_VAR(class_name); - phalcon_array_fetch_quick_string(&class_name, module, SS("className"), 362439804UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(class_name); - ZVAL_STRING(class_name, "Module", 1); - } - - PHALCON_INIT_VAR(module_object); - phalcon_call_method_p1_key(module_object, dependency_injector, "get", class_name, 2090288933UL); - phalcon_call_method_key(NULL, module_object, "registerautoloaders", 1488981101UL); - phalcon_call_method_p1_key(NULL, module_object, "registerservices", dependency_injector, 3636598030UL); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_moduleObject"), module_object, 121977121UL TSRMLS_CC); - - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "console:afterStartModule", 1); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, module_name, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; +// 3363 "scanner.c" +kk245: + kkch = *++KKCURSOR; + switch (kkch) { + case 'C': + case 'c': goto kk246; + case 'L': + case 'l': goto kk247; + default: goto kk100; } +kk246: + kkch = *++KKCURSOR; + switch (kkch) { + case 'H': + case 'h': goto kk250; + default: goto kk100; + } +kk247: + kkch = *++KKCURSOR; + switch (kkch) { + case 'L': + case 'l': goto kk248; + default: goto kk100; + } +kk248: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk249; + } +kk249: +// 302 "scanner.re" + { + token->opcode = PHVOLT_T_ENDCALL; + return 0; } - } - - PHALCON_INIT_VAR(task_name); - phalcon_call_method_key(task_name, router, "gettaskname", 1614697657UL); - - PHALCON_INIT_VAR(action_name); - phalcon_call_method_key(action_name, router, "getactionname", 2461134148UL); - - PHALCON_INIT_VAR(params); - phalcon_call_method_key(params, router, "getparams", 1893744905UL); - - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "dispatcher", 1); - - PHALCON_INIT_VAR(dispatcher); - phalcon_call_method_p1_key(dispatcher, dependency_injector, "getshared", service, 1727570332UL); - phalcon_call_method_p1_key(NULL, dispatcher, "settaskname", task_name, 2879829317UL); - phalcon_call_method_p1_key(NULL, dispatcher, "setactionname", action_name, 1505009872UL); - phalcon_call_method_p1_key(NULL, dispatcher, "setparams", params, 2707361429UL); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "console:beforeHandleTask", 1); - - PHALCON_INIT_NVAR(status); - phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, dispatcher, 259017035UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } - - PHALCON_INIT_VAR(task); - phalcon_call_method_key(task, dispatcher, "dispatch", 4202735573UL); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "console:afterHandleTask", 1); - phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, task, 259017035UL); - } - - RETURN_CCTOR(task); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_CLI_Console_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Console, Exception, cli_console_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_CLI_Dispatcher_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Dispatcher, Exception, cli_dispatcher_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Forms_Element){ - - PHALCON_REGISTER_CLASS(Phalcon\\Forms, Element, forms_element, phalcon_forms_element_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - zend_declare_property_null(phalcon_forms_element_ce, SL("_form"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_element_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_element_ce, SL("_value"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_element_ce, SL("_label"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_element_ce, SL("_attributes"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_element_ce, SL("_validators"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_element_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_element_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_element_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Forms_Element, __construct){ - - zval *name, *attributes = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &name, &attributes); - - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } - - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The element's name must be a string"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); - if (Z_TYPE_P(attributes) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Forms_Element, setForm){ - - zval *form; - - phalcon_fetch_params(0, 1, 0, &form); - - phalcon_update_property_this_quick(this_ptr, SL("_form"), form, 3974999288UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Forms_Element, getForm){ - - - RETURN_MEMBER_QUICK(this_ptr, "_form", 3974999288UL); -} - -static PHP_METHOD(Phalcon_Forms_Element, setName){ - - zval *name; - - phalcon_fetch_params(0, 1, 0, &name); - - phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Forms_Element, getName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); -} - -static PHP_METHOD(Phalcon_Forms_Element, setFilters){ - - zval *filters; - - phalcon_fetch_params(0, 1, 0, &filters); - - phalcon_update_property_this_quick(this_ptr, SL("_filters"), filters, 3850488637UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Forms_Element, addFilter){ - - zval *filter, *filters, *new_filters; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &filter); - - PHALCON_OBS_VAR(filters); - phalcon_read_property_this_quick(&filters, this_ptr, SL("_filters"), 3850488637UL, PH_NOISY_CC); - if (Z_TYPE_P(filters) == IS_ARRAY) { - phalcon_update_property_array_append(this_ptr, SL("_filters"), filter TSRMLS_CC); - } else { - PHALCON_INIT_VAR(new_filters); - array_init_size(new_filters, 2); - phalcon_array_append(&new_filters, filters, PH_SEPARATE); - phalcon_array_append(&new_filters, filter, PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_filters"), new_filters, 3850488637UL TSRMLS_CC); - } - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Forms_Element, getFilters){ - - - RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL); -} - -static PHP_METHOD(Phalcon_Forms_Element, addValidators){ - - zval *validators, *merge = NULL, *current_validators; - zval *merged_validators = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &validators, &merge); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 1); - } - - if (Z_TYPE_P(validators) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The validators parameter must be an array"); - return; - } - if (zend_is_true(merge)) { - - PHALCON_OBS_VAR(current_validators); - phalcon_read_property_this_quick(¤t_validators, this_ptr, SL("_validators"), 2342846045UL, PH_NOISY_CC); - if (Z_TYPE_P(current_validators) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_validators); - phalcon_fast_array_merge(merged_validators, ¤t_validators, &validators TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_validators, validators); - } - - phalcon_update_property_this_quick(this_ptr, SL("_validators"), merged_validators, 2342846045UL TSRMLS_CC); - } - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Forms_Element, addValidator){ - - zval *validator; - - phalcon_fetch_params(0, 1, 0, &validator); - - if (Z_TYPE_P(validator) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The validators parameter must be an object"); - return; - } - phalcon_update_property_array_append(this_ptr, SL("_validators"), validator TSRMLS_CC); - - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Forms_Element, getValidators){ - - - RETURN_MEMBER_QUICK(this_ptr, "_validators", 2342846045UL); -} - -static PHP_METHOD(Phalcon_Forms_Element, prepareAttributes){ - - zval *attributes = NULL, *use_checked = NULL, *name, *widget_attributes = NULL; - zval *default_attributes, *merged_attributes = NULL; - zval *value, *current_value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &attributes, &use_checked); - - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } - - if (!use_checked) { - PHALCON_INIT_VAR(use_checked); - ZVAL_BOOL(use_checked, 0); - } - - PHALCON_OBS_VAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - - if (Z_TYPE_P(attributes) != IS_ARRAY) { - PHALCON_INIT_VAR(widget_attributes); - array_init(widget_attributes); - } else { - PHALCON_CPY_WRT(widget_attributes, attributes); - } - - phalcon_array_update_long(&widget_attributes, 0, &name, PH_COPY | PH_SEPARATE); - - PHALCON_OBS_VAR(default_attributes); - phalcon_read_property_this_quick(&default_attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); - if (Z_TYPE_P(default_attributes) == IS_ARRAY) { - PHALCON_INIT_VAR(merged_attributes); - phalcon_fast_array_merge(merged_attributes, &default_attributes, &widget_attributes TSRMLS_CC); - } else { - PHALCON_CPY_WRT(merged_attributes, widget_attributes); - } - - PHALCON_INIT_VAR(value); - phalcon_call_method_key(value, this_ptr, "getvalue", 31703298UL); - - if (Z_TYPE_P(value) != IS_NULL) { - if (zend_is_true(use_checked)) { - - if (phalcon_array_isset_quick_string(merged_attributes, SS("value"), 574111618UL)) { - - PHALCON_OBS_VAR(current_value); - phalcon_array_fetch_quick_string(¤t_value, merged_attributes, SS("value"), 574111618UL, PH_NOISY); - if (PHALCON_IS_EQUAL(current_value, value)) { - phalcon_array_update_string_string(&merged_attributes, SL("checked"), SL("checked"), PH_SEPARATE); - } - } else { - if (zend_is_true(value)) { - phalcon_array_update_string_string(&merged_attributes, SL("checked"), SL("checked"), PH_SEPARATE); - } - phalcon_array_update_quick_string(&merged_attributes, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); +// 3462 "scanner.c" +kk250: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk251; + default: goto kk100; + } +kk251: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk252; } - } else { - phalcon_array_update_quick_string(&merged_attributes, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); +kk252: +// 353 "scanner.re" + { + token->opcode = PHVOLT_T_ENDCACHE; + return 0; } - } - - RETURN_CCTOR(merged_attributes); -} - -static PHP_METHOD(Phalcon_Forms_Element, setAttribute){ - - zval *attribute, *value; - - phalcon_fetch_params(0, 2, 0, &attribute, &value); - - phalcon_update_property_array(this_ptr, SL("_attributes"), attribute, value TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Forms_Element, getAttribute){ - - zval *attribute, *default_value = NULL, *attributes; - zval *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &attribute, &default_value); - - if (!default_value) { - PHALCON_INIT_VAR(default_value); - } - - PHALCON_OBS_VAR(attributes); - phalcon_read_property_this_quick(&attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); - if (phalcon_array_isset(attributes, attribute)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, attributes, attribute, PH_NOISY); - RETURN_CCTOR(value); - } - - RETURN_CCTOR(default_value); -} - -static PHP_METHOD(Phalcon_Forms_Element, setAttributes){ - - zval *attributes; - - phalcon_fetch_params(0, 1, 0, &attributes); - - if (Z_TYPE_P(attributes) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "Parameter 'attributes' must be an array"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC); - - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Forms_Element, getAttributes){ - - zval *attributes; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(attributes); - phalcon_read_property_this_quick(&attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); - if (Z_TYPE_P(attributes) != IS_ARRAY) { - RETURN_MM_EMPTY_ARRAY(); - } - - RETURN_CCTOR(attributes); -} - -static PHP_METHOD(Phalcon_Forms_Element, 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(); -} - -static PHP_METHOD(Phalcon_Forms_Element, getUserOption){ - - zval *option, *default_value = NULL, *options, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &option, &default_value); - - if (!default_value) { - PHALCON_INIT_VAR(default_value); - } - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (phalcon_array_isset(options, option)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, options, option, PH_NOISY); - RETURN_CCTOR(value); - } - - RETURN_CCTOR(default_value); -} - -static PHP_METHOD(Phalcon_Forms_Element, setUserOptions){ - - zval *options; - - phalcon_fetch_params(0, 1, 0, &options); - - 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(); -} - -static PHP_METHOD(Phalcon_Forms_Element, getUserOptions){ - - - RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); -} - -static PHP_METHOD(Phalcon_Forms_Element, setLabel){ - - zval *label; - - phalcon_fetch_params(0, 1, 0, &label); - - phalcon_update_property_this_quick(this_ptr, SL("_label"), label, 2543586948UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Forms_Element, getLabel){ - - - RETURN_MEMBER_QUICK(this_ptr, "_label", 2543586948UL); -} - -static PHP_METHOD(Phalcon_Forms_Element, label){ - - zval *label, *attributes, *name = NULL, *html = NULL; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(label); - phalcon_read_property_this_quick(&label, this_ptr, SL("_label"), 2543586948UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(attributes); - phalcon_read_property_this_quick(&attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); - - if (phalcon_array_isset_quick_string(attributes, SS("id"), 193494642UL)) { - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, attributes, SS("id"), 193494642UL, PH_NOISY); - } else { - PHALCON_OBS_NVAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - } - - if (zend_is_true(label)) { - PHALCON_INIT_VAR(html); - PHALCON_CONCAT_SVSVS(html, ""); - } else { - PHALCON_INIT_NVAR(html); - PHALCON_CONCAT_SVSVS(html, ""); - } - - RETURN_CTOR(html); -} - -static PHP_METHOD(Phalcon_Forms_Element, setDefault){ - - zval *value; - - phalcon_fetch_params(0, 1, 0, &value); - - phalcon_update_property_this_quick(this_ptr, SL("_value"), value, 2935317441UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Forms_Element, getDefault){ - - - RETURN_MEMBER_QUICK(this_ptr, "_value", 2935317441UL); -} - -static PHP_METHOD(Phalcon_Forms_Element, getValue){ - - zval *name, *value = NULL, *form, *has_default_value; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(value); - - PHALCON_OBS_VAR(form); - phalcon_read_property_this_quick(&form, this_ptr, SL("_form"), 3974999288UL, PH_NOISY_CC); - if (Z_TYPE_P(form) == IS_OBJECT) { - - PHALCON_INIT_VAR(has_default_value); - PHALCON_CALL_STATIC_PARAMS_1(has_default_value, "phalcon\\tag", "hasvalue", name); - if (!zend_is_true(has_default_value)) { - phalcon_call_method_p1_key(value, form, "getvalue", name, 31703298UL); +// 3545 "scanner.c" +kk253: + kkch = *++KKCURSOR; + switch (kkch) { + case 'O': + case 'o': goto kk254; + default: goto kk100; + } +kk254: + kkch = *++KKCURSOR; + switch (kkch) { + case 'C': + case 'c': goto kk255; + default: goto kk100; + } +kk255: + kkch = *++KKCURSOR; + switch (kkch) { + case 'K': + case 'k': goto kk256; + default: goto kk100; + } +kk256: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk257; + } +kk257: +// 280 "scanner.re" + { + token->opcode = PHVOLT_T_ENDBLOCK; + return 0; } - } - - if (Z_TYPE_P(value) == IS_NULL) { - PHALCON_OBS_NVAR(value); - phalcon_read_property_this_quick(&value, this_ptr, SL("_value"), 2935317441UL, PH_NOISY_CC); - } - - RETURN_CCTOR(value); -} - -static PHP_METHOD(Phalcon_Forms_Element, getMessages){ - - zval *messages = NULL; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (Z_TYPE_P(messages) == IS_OBJECT) { - RETURN_CCTOR(messages); - } - - PHALCON_INIT_NVAR(messages); - object_init_ex(messages, phalcon_validation_message_group_ce); - phalcon_call_method_key(NULL, messages, "__construct", 1107214344UL); - - phalcon_update_property_this_quick(this_ptr, SL("_messages"), messages, 743366684UL TSRMLS_CC); - - RETURN_CCTOR(messages); -} - -static PHP_METHOD(Phalcon_Forms_Element, hasMessages){ - - zval *messages; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (Z_TYPE_P(messages) == IS_OBJECT) { - if (phalcon_fast_count_ev(messages TSRMLS_CC)) { - RETURN_MM_TRUE; +// 3642 "scanner.c" +kk258: + kkch = *++KKCURSOR; + switch (kkch) { + case 'T': + case 't': goto kk259; + default: goto kk100; + } +kk259: + kkch = *++KKCURSOR; + switch (kkch) { + case 'O': + case 'o': goto kk260; + default: goto kk100; + } +kk260: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk261; + default: goto kk100; + } +kk261: + kkch = *++KKCURSOR; + switch (kkch) { + case 'S': + case 's': goto kk262; + default: goto kk100; + } +kk262: + kkch = *++KKCURSOR; + switch (kkch) { + case 'C': + case 'c': goto kk263; + default: goto kk100; + } +kk263: + kkch = *++KKCURSOR; + switch (kkch) { + case 'A': + case 'a': goto kk264; + default: goto kk100; + } +kk264: + kkch = *++KKCURSOR; + switch (kkch) { + case 'P': + case 'p': goto kk265; + default: goto kk100; + } +kk265: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk266; + default: goto kk100; + } +kk266: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk267; + } +kk267: +// 370 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_ENDAUTOESCAPE; + return 0; } - } - - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Forms_Element, setMessages){ - - zval *group; - - phalcon_fetch_params(0, 1, 0, &group); - - if (Z_TYPE_P(group) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The message group is not valid"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_messages"), group, 743366684UL TSRMLS_CC); - - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Forms_Element, appendMessage){ - - zval *message, *messages = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &message); - - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (Z_TYPE_P(messages) != IS_OBJECT) { - PHALCON_INIT_NVAR(messages); - object_init_ex(messages, phalcon_validation_message_group_ce); - phalcon_call_method_key(NULL, messages, "__construct", 1107214344UL); - - phalcon_update_property_this_quick(this_ptr, SL("_messages"), messages, 743366684UL TSRMLS_CC); - } - - phalcon_call_method_p1_key(NULL, messages, "appendmessage", message, 2313005058UL); - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Forms_Element, clear){ - - zval *znull, *name; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(znull); - - PHALCON_OBS_VAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - PHALCON_CALL_STATIC_PARAMS_2_NORETURN("phalcon\\tag", "setdefault", name, znull); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Forms_Element, __toString){ - - - PHALCON_MM_GROW(); - - phalcon_call_method_key(return_value, this_ptr, "render", 1053215877UL); - RETURN_MM(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Forms_Form){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms, Form, forms_form, "phalcon\\di\\injectable", phalcon_forms_form_method_entry, 0); - - zend_declare_property_null(phalcon_forms_form_ce, SL("_position"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_form_ce, SL("_entity"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_form_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_form_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_form_ce, SL("_elements"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_form_ce, SL("_elementsIndexed"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_form_ce, SL("_messages"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_forms_form_ce, SL("_action"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_forms_form_ce TSRMLS_CC, 2, spl_ce_Countable, zend_ce_iterator); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Forms_Form, __construct){ - - zval *entity = NULL, *user_options = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &entity, &user_options); - - if (!entity) { - PHALCON_INIT_VAR(entity); - } - - if (!user_options) { - PHALCON_INIT_VAR(user_options); - } - - if (Z_TYPE_P(entity) != IS_NULL) { - if (Z_TYPE_P(entity) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The base entity is not valid"); - return; +// 3775 "scanner.c" +kk268: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk269; + default: goto kk100; + } +kk269: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'G': + case 'H': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'g': + case 'h': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + case 'F': + case 'f': goto kk271; + case 'I': + case 'i': goto kk272; + default: goto kk270; + } +kk270: +// 208 "scanner.re" + { + token->opcode = PHVOLT_T_ELSE; + return 0; } - phalcon_update_property_this_quick(this_ptr, SL("_entity"), entity, 2413912609UL TSRMLS_CC); - } - - 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_call_method_p2_key(NULL, this_ptr, "initialize", entity, user_options, 2896075127UL); - } - - PHALCON_MM_RESTORE(); -} - -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(); -} - -static PHP_METHOD(Phalcon_Forms_Form, getAction){ - - - RETURN_MEMBER_QUICK(this_ptr, "_action", 1112512898UL); -} - -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(); -} - -static PHP_METHOD(Phalcon_Forms_Form, getUserOption){ - - zval *option, *default_value = NULL, *options, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &option, &default_value); - - if (!default_value) { - PHALCON_INIT_VAR(default_value); - } - - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - if (phalcon_array_isset(options, option)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, options, option, PH_NOISY); - RETURN_CCTOR(value); - } - - RETURN_CCTOR(default_value); -} - -static PHP_METHOD(Phalcon_Forms_Form, setUserOptions){ - - zval *options; - - phalcon_fetch_params(0, 1, 0, &options); - - 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(); -} - -static PHP_METHOD(Phalcon_Forms_Form, getUserOptions){ - - - RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); -} - -static PHP_METHOD(Phalcon_Forms_Form, setEntity){ - - zval *entity; - - phalcon_fetch_params(0, 1, 0, &entity); - - phalcon_update_property_this_quick(this_ptr, SL("_entity"), entity, 2413912609UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Forms_Form, getEntity){ - - - RETURN_MEMBER_QUICK(this_ptr, "_entity", 2413912609UL); -} - -static PHP_METHOD(Phalcon_Forms_Form, getElements){ - - - RETURN_MEMBER_QUICK(this_ptr, "_elements", 3134610529UL); -} - -static PHP_METHOD(Phalcon_Forms_Form, bind){ - - zval *data, *entity, *whitelist = NULL, *elements, *filter = NULL; - zval *value = NULL, *key = NULL, *element = NULL, *filters = NULL, *service_name = NULL; - zval *dependency_injector = NULL, *filtered_value = NULL; - zval *method = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &data, &entity, &whitelist); - - if (!whitelist) { - PHALCON_INIT_VAR(whitelist); - } - - 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_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - 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; +// 3858 "scanner.c" +kk271: + kkch = *++KKCURSOR; + switch (kkch) { + case 'O': + case 'o': goto kk275; + default: goto kk100; + } +kk272: + kkch = *++KKCURSOR; + switch (kkch) { + case 'F': + case 'f': goto kk273; + default: goto kk100; + } +kk273: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk274; + } +kk274: +// 218 "scanner.re" + { + token->opcode = PHVOLT_T_ELSEIF; + return 0; + } +// 3948 "scanner.c" +kk275: + kkch = *++KKCURSOR; + switch (kkch) { + case 'R': + case 'r': goto kk276; + default: goto kk100; + } +kk276: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk277; + } +kk277: +// 213 "scanner.re" + { + token->opcode = PHVOLT_T_ELSEFOR; + return 0; } - - if (Z_TYPE_P(whitelist) == IS_ARRAY) { - if (!phalcon_fast_in_array(key, whitelist TSRMLS_CC)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; +// 4031 "scanner.c" +kk278: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk279; } +kk279: +// 202 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_IF; + return 0; } - - PHALCON_OBS_NVAR(element); - phalcon_array_fetch(&element, elements, key, PH_NOISY); - - PHALCON_INIT_NVAR(filters); - phalcon_call_method_key(filters, element, "getfilters", 2910616766UL); - if (zend_is_true(filters)) { - if (Z_TYPE_P(filter) != IS_OBJECT) { - PHALCON_INIT_NVAR(service_name); - ZVAL_STRING(service_name, "filter", 1); - - PHALCON_INIT_NVAR(dependency_injector); - phalcon_call_method_key(dependency_injector, this_ptr, "getdi", 4287060818UL); - - PHALCON_INIT_NVAR(filter); - phalcon_call_method_p1_key(filter, dependency_injector, "getshared", service_name, 1727570332UL); +// 4108 "scanner.c" +kk280: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + case 'C': + case 'c': goto kk284; + default: goto kk281; } - - PHALCON_INIT_NVAR(filtered_value); - phalcon_call_method_p2_key(filtered_value, filter, "sanitize", value, filters, 3688332940UL); - } else { - PHALCON_CPY_WRT(filtered_value, value); +kk281: +// 239 "scanner.re" + { + token->opcode = PHVOLT_T_IN; + return 0; } - - PHALCON_INIT_NVAR(method); - PHALCON_CONCAT_SV(method, "set", key); - - if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { - phalcon_call_method_zval_p1_noret(entity, method, filtered_value); - zend_hash_move_forward_ex(ah0, &hp0); - continue; +// 4184 "scanner.c" +kk282: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk283; + } +kk283: +// 323 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_IS; + return 0; } - - 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(); -} - -static PHP_METHOD(Phalcon_Forms_Form, isValid){ - - zval *data = NULL, *entity = NULL, *elements, *status, *not_failed = NULL; - zval *messages, *element = NULL, *validators = NULL, *name = NULL, *prepared_validators = NULL; - zval *validator = NULL, *scope = NULL, *validation = NULL, *filters = NULL; - zval *element_messages = NULL; - HashTable *ah0, *ah1; - HashPosition hp0, hp1; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &data, &entity); - - if (!data) { - PHALCON_INIT_VAR(data); - } else { - PHALCON_SEPARATE_PARAM(data); - } - - if (!entity) { - PHALCON_INIT_VAR(entity); - } - - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - if (Z_TYPE_P(elements) != IS_ARRAY) { - RETURN_MM_TRUE; - } - - if (Z_TYPE_P(entity) == IS_OBJECT) { - phalcon_call_method_p2_key(NULL, this_ptr, "bind", data, entity, 254268962UL); - } - - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_OBS_NVAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - } - - if (phalcon_method_quick_exists_ex(this_ptr, SS("beforevalidation"), 4025473891UL TSRMLS_CC) == SUCCESS) { - - PHALCON_INIT_VAR(status); - phalcon_call_method_p2_key(status, this_ptr, "beforevalidation", data, entity, 4025473891UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_CCTOR(status); +// 4261 "scanner.c" +kk284: + kkch = *++KKCURSOR; + switch (kkch) { + case 'L': + case 'l': goto kk285; + default: goto kk100; + } +kk285: + kkch = *++KKCURSOR; + switch (kkch) { + case 'U': + case 'u': goto kk286; + default: goto kk100; + } +kk286: + kkch = *++KKCURSOR; + switch (kkch) { + case 'D': + case 'd': goto kk287; + default: goto kk100; + } +kk287: + kkch = *++KKCURSOR; + switch (kkch) { + case 'E': + case 'e': goto kk288; + default: goto kk100; + } +kk288: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case 'A': + case 'B': + case 'C': + case 'D': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'M': + case 'N': + case 'O': + case 'P': + case 'Q': + case 'R': + case 'S': + case 'T': + case 'U': + case 'V': + case 'W': + case 'X': + case 'Y': + case 'Z': + case '\\': + case '_': + case 'a': + case 'b': + case 'c': + case 'd': + case 'e': + case 'f': + case 'g': + case 'h': + case 'i': + case 'j': + case 'k': + case 'l': + case 'm': + case 'n': + case 'o': + case 'p': + case 'q': + case 'r': + case 's': + case 't': + case 'u': + case 'v': + case 'w': + case 'x': + case 'y': + case 'z': goto kk99; + default: goto kk289; + } +kk289: +// 341 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_INCLUDE; + return 0; } - } - - PHALCON_INIT_VAR(not_failed); - ZVAL_BOOL(not_failed, 1); - - 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_INIT_NVAR(validators); - phalcon_call_method_key(validators, element, "getvalidators", 1790233662UL); - if (Z_TYPE_P(validators) == IS_ARRAY) { - if (phalcon_fast_count_ev(validators TSRMLS_CC)) { - - PHALCON_INIT_NVAR(name); - phalcon_call_method_key(name, element, "getname", 4286441094UL); - - 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, PH_SEPARATE); - phalcon_array_append(&scope, validator, PH_SEPARATE); - 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_p1_key(NULL, validation, "__construct", prepared_validators, 1107214344UL); - - PHALCON_INIT_NVAR(filters); - phalcon_call_method_key(filters, element, "getfilters", 2910616766UL); - - if (Z_TYPE_P(filters) == IS_ARRAY) { - PHALCON_INIT_NVAR(name); - phalcon_call_method_key(name, element, "getname", 4286441094UL); - phalcon_call_method_p2_key(NULL, validation, "setfilters", name, filters, 3990158282UL); - } - - PHALCON_INIT_NVAR(element_messages); - phalcon_call_method_p2_key(element_messages, validation, "validate", data, entity, 2654098287UL); - if (phalcon_fast_count_ev(element_messages TSRMLS_CC)) { - PHALCON_INIT_NVAR(name); - phalcon_call_method_key(name, element, "getname", 4286441094UL); - phalcon_array_update_zval(&messages, name, &element_messages, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_NVAR(not_failed); - ZVAL_BOOL(not_failed, 0); - } +// 4366 "scanner.c" +kk290: + kkch = *++KKCURSOR; + switch (kkch) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto kk293; + default: goto kk103; + } +kk291: + kkaccept = 0; + KKMARKER = ++KKCURSOR; + kkch = *KKCURSOR; +kk292: + switch (kkch) { + case '.': goto kk290; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto kk291; + default: goto kk3; + } +kk293: + ++KKCURSOR; + kkch = *KKCURSOR; + switch (kkch) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': goto kk293; + default: goto kk295; } +kk295: +// 194 "scanner.re" + { + token->opcode = PHVOLT_T_DOUBLE; + token->value = estrndup(start, KKCURSOR - start); + token->len = KKCURSOR - start; + q = KKCURSOR; + return 0; + } +// 4426 "scanner.c" + } +// 654 "scanner.re" + + } - - 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_p1_key(NULL, this_ptr, "aftervalidation", messages, 1795965282UL); } - - - RETURN_NCTOR(not_failed); + + return status; } -static PHP_METHOD(Phalcon_Forms_Form, getMessages){ - zval *by_item_name = NULL, *messages, *group, *element_messages = NULL; - zval *element = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &by_item_name); - - if (!by_item_name) { - PHALCON_INIT_VAR(by_item_name); - ZVAL_BOOL(by_item_name, 0); - } - - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (zend_is_true(by_item_name)) { - if (Z_TYPE_P(messages) != IS_ARRAY) { - object_init_ex(return_value, phalcon_validation_message_group_ce); - phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL); - - RETURN_MM(); - } - - RETURN_CCTOR(messages); - } - - PHALCON_INIT_VAR(group); - object_init_ex(group, phalcon_validation_message_group_ce); - phalcon_call_method_key(NULL, group, "__construct", 1107214344UL); - - phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(element, ah0, hp0); - PHALCON_GET_HVALUE(element_messages); - - phalcon_call_method_p1_key(NULL, group, "appendmessages", element_messages, 3314726677UL); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CTOR(group); -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Forms_Form, getMessagesFor){ - zval *name, *messages, *element_messages, *group; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (phalcon_array_isset(messages, name)) { - PHALCON_OBS_VAR(element_messages); - phalcon_array_fetch(&element_messages, messages, name, PH_NOISY); - RETURN_CCTOR(element_messages); - } - - PHALCON_INIT_VAR(group); - object_init_ex(group, phalcon_validation_message_group_ce); - phalcon_call_method_key(NULL, group, "__construct", 1107214344UL); - - phalcon_update_property_array(this_ptr, SL("_messages"), name, group TSRMLS_CC); - - RETURN_CTOR(group); -} -static PHP_METHOD(Phalcon_Forms_Form, hasMessagesFor){ - zval *name, *messages, *element_messages; - PHALCON_MM_GROW(); +PHALCON_INIT_CLASS(Phalcon_Mvc_View_Engine_Volt){ - phalcon_fetch_params(1, 1, 0, &name); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View\\Engine, Volt, mvc_view_engine_volt, "phalcon\\mvc\\view\\engine", phalcon_mvc_view_engine_volt_method_entry, 0); + + zend_declare_property_null(phalcon_mvc_view_engine_volt_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_engine_volt_ce, SL("_compiler"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_view_engine_volt_ce TSRMLS_CC, 1, phalcon_mvc_view_engineinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, setOptions){ + + zval *options; + + phalcon_fetch_params(0, 1, 0, &options); - PHALCON_OBS_VAR(messages); - phalcon_read_property_this_quick(&messages, this_ptr, SL("_messages"), 743366684UL, PH_NOISY_CC); - if (phalcon_array_isset(messages, name)) { - PHALCON_OBS_VAR(element_messages); - phalcon_array_fetch(&element_messages, messages, name, PH_NOISY); - RETURN_CCTOR(element_messages); + if (Z_TYPE_P(options) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Options parameter must be an array"); + return; } + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Forms_Form, add){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, getOptions){ - zval *element, *name; + + RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); +} + +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, getCompiler){ + + zval *compiler = NULL, *view, *options, *dependency_injector; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &element); + PHALCON_OBS_VAR(compiler); + phalcon_read_property_this_quick(&compiler, this_ptr, SL("_compiler"), 96166463UL, PH_NOISY_CC); + if (Z_TYPE_P(compiler) != IS_OBJECT) { - if (Z_TYPE_P(element) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The element is not valid"); - return; - } + PHALCON_OBS_VAR(view); + phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, element, "getname", 4286441094UL); + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - phalcon_call_method_p1_key(NULL, element, "setform", this_ptr, 302702757UL); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - phalcon_update_property_array(this_ptr, SL("_elements"), name, element TSRMLS_CC); + PHALCON_INIT_NVAR(compiler); + object_init_ex(compiler, phalcon_mvc_view_engine_volt_compiler_ce); + phalcon_call_method_p1_key(NULL, compiler, "__construct", view, 1107214344UL); - RETURN_THIS(); + if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + phalcon_call_method_p1_key(NULL, compiler, "setdi", dependency_injector, 461718238UL); + } + + if (Z_TYPE_P(options) == IS_ARRAY) { + phalcon_call_method_p1_key(NULL, compiler, "setoptions", options, 1759822653UL); + } + + phalcon_update_property_this_quick(this_ptr, SL("_compiler"), compiler, 96166463UL TSRMLS_CC); + } + + RETURN_CCTOR(compiler); } -static PHP_METHOD(Phalcon_Forms_Form, render){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, render){ - zval *name, *attributes = NULL, *elements, *exception_message; - zval *element, *code; + zval *template_path, *params, *must_clean = NULL, *compiler; + zval *compiled_template_path, *value = NULL, *key = NULL, *contents; + zval *view; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, &attributes); + phalcon_fetch_params(1, 2, 1, &template_path, ¶ms, &must_clean); - if (!attributes) { - PHALCON_INIT_VAR(attributes); + if (!must_clean) { + PHALCON_INIT_VAR(must_clean); + ZVAL_BOOL(must_clean, 0); } - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The name must be a string"); - return; + if (PHALCON_IS_TRUE(must_clean)) { + phalcon_ob_clean(TSRMLS_C); } - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - if (!phalcon_array_isset(elements, name)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); - return; - } + PHALCON_INIT_VAR(compiler); + phalcon_call_method_key(compiler, this_ptr, "getcompiler", 3440133088UL); + phalcon_call_method_p1_key(NULL, compiler, "compile", template_path, 1074882030UL); - PHALCON_OBS_VAR(element); - phalcon_array_fetch(&element, elements, name, PH_NOISY); + PHALCON_INIT_VAR(compiled_template_path); + phalcon_call_method_key(compiled_template_path, compiler, "getcompiledtemplatepath", 652904091UL); - PHALCON_INIT_VAR(code); - phalcon_call_method_p1_key(code, element, "render", attributes, 1053215877UL); + if (Z_TYPE_P(params) == IS_ARRAY) { - RETURN_CCTOR(code); -} - -static PHP_METHOD(Phalcon_Forms_Form, get){ - - zval *name, *elements, *exception_message, *element; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); + phalcon_is_iterable(params, &ah0, &hp0, 0, 0); - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - if (!phalcon_array_isset(elements, name)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); + + if (phalcon_set_symbol(key, value TSRMLS_CC) == FAILURE){ + return; + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } + + if (phalcon_require(compiled_template_path TSRMLS_CC) == FAILURE) { return; } + if (PHALCON_IS_TRUE(must_clean)) { + PHALCON_INIT_VAR(contents); + phalcon_ob_get_contents(contents TSRMLS_CC); - PHALCON_OBS_VAR(element); - phalcon_array_fetch(&element, elements, name, PH_NOISY); + PHALCON_OBS_VAR(view); + phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); + phalcon_call_method_p1_key(NULL, view, "setcontent", contents, 4220987916UL); + } - RETURN_CCTOR(element); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Forms_Form, label){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, length){ - zval *name, *elements, *exception_message, *element; - zval *html; + zval *item, *length = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); + phalcon_fetch_params(1, 1, 0, &item); - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - if (!phalcon_array_isset(elements, name)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); - return; + PHALCON_INIT_VAR(length); + ZVAL_LONG(length, 0); + if (Z_TYPE_P(item) == IS_OBJECT) { + phalcon_fast_count(length, item TSRMLS_CC); + } else { + if (Z_TYPE_P(item) == IS_ARRAY) { + PHALCON_INIT_NVAR(length); + phalcon_fast_count(length, item TSRMLS_CC); + } else { + if (phalcon_function_quick_exists_ex(SS("mb_strlen"), 3716840971UL TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_NVAR(length); + phalcon_call_func_p1(length, "mb_strlen", item); + } else { + PHALCON_INIT_NVAR(length); + phalcon_fast_strlen(length, item); + } + } } - PHALCON_OBS_VAR(element); - phalcon_array_fetch(&element, elements, name, PH_NOISY); - - PHALCON_INIT_VAR(html); - phalcon_call_method_key(html, element, "label", 182381125UL); - - RETURN_CCTOR(html); + RETURN_CCTOR(length); } -static PHP_METHOD(Phalcon_Forms_Form, getLabel){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, isIncluded){ - zval *name, *elements, *exception_message, *element; - zval *label; + zval *needle, *haystack; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); + phalcon_fetch_params(1, 2, 0, &needle, &haystack); - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - if (!phalcon_array_isset(elements, name)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Element with ID=", name, " is not part of the form"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); - return; + if (Z_TYPE_P(haystack) == IS_ARRAY) { + phalcon_call_func_p2(return_value, "in_array", needle, haystack); + RETURN_MM(); } - - PHALCON_OBS_VAR(element); - phalcon_array_fetch(&element, elements, name, PH_NOISY); - - PHALCON_INIT_VAR(label); - phalcon_call_method_key(label, element, "getlabel", 3934940101UL); - - if (!zend_is_true(label)) { - RETURN_CCTOR(name); + if (Z_TYPE_P(haystack) == IS_STRING) { + if (phalcon_function_quick_exists_ex(SS("mb_strpos"), 3716995774UL TSRMLS_CC) == SUCCESS) { + phalcon_call_func_p2(return_value, "mb_strpos", haystack, needle); + RETURN_MM(); + } + phalcon_fast_strpos(return_value, haystack, needle); + RETURN_MM(); } - RETURN_CCTOR(label); + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Invalid haystack"); + return; } -static PHP_METHOD(Phalcon_Forms_Form, getValue){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, convertEncoding){ - zval *name, *entity, *method, *value = NULL, *data; + zval *text, *from, *to; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(entity); - phalcon_read_property_this_quick(&entity, this_ptr, SL("_entity"), 2413912609UL, PH_NOISY_CC); - if (Z_TYPE_P(entity) == IS_OBJECT) { + phalcon_fetch_params(1, 3, 0, &text, &from, &to); - PHALCON_INIT_VAR(method); - PHALCON_CONCAT_SV(method, "get", name); - if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { - phalcon_call_method_zval(return_value, entity, method); + if (PHALCON_IS_STRING(from, "latin1")) { + if (PHALCON_IS_STRING(to, "utf8")) { + phalcon_call_func_p1(return_value, "utf8_encode", text); RETURN_MM(); } - - if (phalcon_isset_property_zval(entity, name TSRMLS_CC)) { - PHALCON_OBS_VAR(value); - phalcon_read_property_zval(&value, entity, name, PH_NOISY_CC); - RETURN_CCTOR(value); - } } - PHALCON_OBS_VAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - if (Z_TYPE_P(data) == IS_ARRAY) { - - if (phalcon_array_isset(data, name)) { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, data, name, PH_NOISY); - RETURN_CCTOR(value); + if (PHALCON_IS_STRING(to, "latin1")) { + if (PHALCON_IS_STRING(from, "utf8")) { + phalcon_call_func_p1(return_value, "utf8_decode", text); + RETURN_MM(); } } - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Forms_Form, has){ - - zval *name, *elements; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - - if (phalcon_array_isset(elements, name)) { - RETURN_MM_TRUE; + if (phalcon_function_quick_exists_ex(SS("mb_convert_encoding"), 2165643194UL TSRMLS_CC) == SUCCESS) { + phalcon_call_func_p3(return_value, "mb_convert_encoding", text, from, to); + RETURN_MM(); } - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Forms_Form, remove){ - - zval *name, *elements; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - - if (phalcon_array_isset(elements, name)) { - phalcon_unset_property_array(this_ptr, SL("_elements"), name TSRMLS_CC); - RETURN_MM_TRUE; + if (phalcon_function_quick_exists_ex(SS("iconv"), 67824100UL TSRMLS_CC) == SUCCESS) { + phalcon_call_func_p3(return_value, "iconv", from, to, text); + RETURN_MM(); } - phalcon_update_property_null(this_ptr, SL("_elementsIndexed") TSRMLS_CC); - RETURN_MM_FALSE; + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Any of 'mbstring' or 'iconv' is required to perform the charset conversion"); + return; } -static PHP_METHOD(Phalcon_Forms_Form, clear){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, slice){ - zval *fields = NULL, *elements, *element = NULL, *name = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *value, *start, *end = NULL, *slice, *length = NULL, *position; + zval *current = NULL, *one, *range; + zval *r0 = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &fields); + phalcon_fetch_params(1, 2, 1, &value, &start, &end); - if (!fields) { - PHALCON_INIT_VAR(fields); + if (!end) { + PHALCON_INIT_VAR(end); } - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - if (Z_TYPE_P(elements) == IS_ARRAY) { + if (Z_TYPE_P(value) == IS_OBJECT) { - phalcon_is_iterable(elements, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(slice); + array_init(slice); + if (Z_TYPE_P(end) == IS_NULL) { + PHALCON_INIT_VAR(length); + phalcon_fast_count(length, value TSRMLS_CC); + } else { + PHALCON_CPY_WRT(length, end); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(position); + ZVAL_LONG(position, 0); + phalcon_call_method_key(NULL, value, "rewind", 1064078190UL); - PHALCON_GET_HVALUE(element); + while (1) { - if (Z_TYPE_P(fields) != IS_ARRAY) { - phalcon_call_method_key(NULL, element, "clear", 4138278668UL); + PHALCON_INIT_NVAR(r0); + phalcon_call_method_key(r0, value, "valid", 574098517UL); + if (zend_is_true(r0)) { } else { - PHALCON_INIT_NVAR(name); - phalcon_call_method_key(name, element, "getname", 4286441094UL); - if (phalcon_fast_in_array(name, fields TSRMLS_CC)) { - phalcon_call_method_key(NULL, element, "clear", 4138278668UL); + break; + } + + if (PHALCON_GE(position, start)) { + if (PHALCON_LE(position, length)) { + PHALCON_INIT_NVAR(current); + phalcon_call_method_key(current, value, "current", 431662984UL); + phalcon_array_append(&slice, current, PH_SEPARATE); } } + phalcon_call_method_key(NULL, value, "next", 268367684UL); + PHALCON_SEPARATE(position); + phalcon_increment(position); + } - zend_hash_move_forward_ex(ah0, &hp0); + RETURN_CTOR(slice); + } + + if (Z_TYPE_P(end) != IS_NULL) { + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + + PHALCON_INIT_VAR(range); + sub_function(range, end, start TSRMLS_CC); + + PHALCON_INIT_NVAR(length); + phalcon_add_function(length, range, one TSRMLS_CC); + } else { + PHALCON_INIT_NVAR(length); + } + + if (Z_TYPE_P(value) == IS_ARRAY) { + phalcon_call_func_p3(return_value, "array_slice", value, start, length); + RETURN_MM(); + } + + if (phalcon_function_quick_exists_ex(SS("mb_substr"), 3737269654UL TSRMLS_CC) == SUCCESS) { + if (Z_TYPE_P(length) != IS_NULL) { + phalcon_call_func_p3(return_value, "mb_substr", value, start, length); + RETURN_MM(); } + phalcon_call_func_p2(return_value, "mb_substr", value, start); + RETURN_MM(); + } + if (Z_TYPE_P(length) != IS_NULL) { + phalcon_call_func_p3(return_value, "substr", value, start, length); + RETURN_MM(); } - RETURN_THIS(); + phalcon_call_func_p2(return_value, "substr", value, start); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Forms_Form, count){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, sort){ - zval *elements; + zval *value; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - phalcon_fast_count(return_value, elements TSRMLS_CC); - RETURN_MM(); + phalcon_fetch_params(1, 1, 0, &value); + + Z_SET_ISREF_P(value); + phalcon_call_func_p1_noret("asort", value); + Z_UNSET_ISREF_P(value); + RETURN_CCTOR(value); } -static PHP_METHOD(Phalcon_Forms_Form, rewind){ - zval *elements, *elements_indexed; - PHALCON_MM_GROW(); - phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC); - - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elements"), 3134610529UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(elements_indexed); - phalcon_call_func_p1(elements_indexed, "array_values", elements); - phalcon_update_property_this_quick(this_ptr, SL("_elementsIndexed"), elements_indexed, 4269762082UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Forms_Form, current){ +#ifdef HAVE_CONFIG_H +#endif - zval *position, *elements, *element; - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elementsIndexed"), 4269762082UL, PH_NOISY_CC); - if (phalcon_array_isset(elements, position)) { - PHALCON_OBS_VAR(element); - phalcon_array_fetch(&element, elements, position, PH_NOISY); - RETURN_CCTOR(element); - } - - RETURN_MM_NULL(); -} -static PHP_METHOD(Phalcon_Forms_Form, key){ - RETURN_MEMBER_QUICK(this_ptr, "_position", 2925265369UL); -} -static PHP_METHOD(Phalcon_Forms_Form, next){ +PHALCON_INIT_CLASS(Phalcon_Mvc_View_Engine){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View, Engine, mvc_view_engine, "phalcon\\di\\injectable", phalcon_mvc_view_engine_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - phalcon_property_incr(this_ptr, SL("_position") TSRMLS_CC); - + zend_declare_property_null(phalcon_mvc_view_engine_ce, SL("_view"), ZEND_ACC_PROTECTED TSRMLS_CC); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Forms_Form, valid){ +static PHP_METHOD(Phalcon_Mvc_View_Engine, __construct){ - zval *position, *elements; + zval *view, *dependency_injector = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 1, &view, &dependency_injector); - PHALCON_OBS_VAR(elements); - phalcon_read_property_this_quick(&elements, this_ptr, SL("_elementsIndexed"), 4269762082UL, PH_NOISY_CC); - if (phalcon_array_isset(elements, position)) { - RETURN_MM_TRUE; + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); } - RETURN_MM_FALSE; + phalcon_update_property_this_quick(this_ptr, SL("_view"), view, 3993744575UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Mvc_View_Engine, getContent){ + zval *view; + PHALCON_MM_GROW(); + PHALCON_OBS_VAR(view); + phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); + phalcon_call_method_key(return_value, view, "getcontent", 3141446400UL); + RETURN_MM(); +} -#ifdef HAVE_CONFIG_H -#endif - - +static PHP_METHOD(Phalcon_Mvc_View_Engine, partial){ -PHALCON_INIT_CLASS(Phalcon_Forms_ElementInterface){ + zval *partial_path, *params = NULL, *view; - PHALCON_REGISTER_INTERFACE(Phalcon\\Forms, ElementInterface, forms_elementinterface, phalcon_forms_elementinterface_method_entry); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 1, 1, &partial_path, ¶ms); + + if (!params) { + PHALCON_INIT_VAR(params); + } + + PHALCON_OBS_VAR(view); + phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); + phalcon_call_method_p2_key(return_value, view, "partial", partial_path, params, 363586066UL); + RETURN_MM(); } +static PHP_METHOD(Phalcon_Mvc_View_Engine, getView){ + RETURN_MEMBER_QUICK(this_ptr, "_view", 3993744575UL); +} +#ifdef HAVE_CONFIG_H +#endif +PHALCON_INIT_CLASS(Phalcon_Mvc_View_EngineInterface){ + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\View, EngineInterface, mvc_view_engineinterface, phalcon_mvc_view_engineinterface_method_entry); + return SUCCESS; +} @@ -91683,15 +91918,20 @@ PHALCON_INIT_CLASS(Phalcon_Forms_ElementInterface){ +#ifdef HAVE_CONFIG_H +#endif +PHALCON_INIT_CLASS(Phalcon_Mvc_View_Exception){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View, Exception, mvc_view_exception, "phalcon\\exception", NULL, 0); - + return SUCCESS; +} @@ -91706,558 +91946,641 @@ PHALCON_INIT_CLASS(Phalcon_Forms_ElementInterface){ -PHALCON_INIT_CLASS(Phalcon_Forms_Manager){ +PHALCON_INIT_CLASS(Phalcon_Mvc_View_Simple){ - PHALCON_REGISTER_CLASS(Phalcon\\Forms, Manager, forms_manager, phalcon_forms_manager_method_entry, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View, Simple, mvc_view_simple, "phalcon\\di\\injectable", phalcon_mvc_view_simple_method_entry, 0); - zend_declare_property_null(phalcon_forms_manager_ce, SL("_forms"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_viewsDir"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_partialsDir"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_viewParams"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_view_simple_ce, SL("_engines"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_registeredEngines"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_activeRenderPath"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_content"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_view_simple_ce, SL("_cache"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_simple_ce, SL("_cacheOptions"), ZEND_ACC_PROTECTED TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_Forms_Manager, create){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, __construct){ - zval *name = NULL, *entity = NULL, *form; + zval *options = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &name, &entity); - - if (!name) { - PHALCON_INIT_VAR(name); - } + phalcon_fetch_params(1, 0, 1, &options); - if (!entity) { - PHALCON_INIT_VAR(entity); + if (!options) { + PHALCON_INIT_VAR(options); } - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The form name must be string"); - return; + if (Z_TYPE_P(options) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); } - PHALCON_INIT_VAR(form); - object_init_ex(form, phalcon_forms_form_ce); - phalcon_call_method_p1_key(NULL, form, "__construct", entity, 1107214344UL); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_View_Simple, setViewsDir){ + + zval *views_dir; + + phalcon_fetch_params(0, 1, 0, &views_dir); - phalcon_update_property_array(this_ptr, SL("_forms"), name, form TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_viewsDir"), views_dir, 3398309201UL TSRMLS_CC); - RETURN_CTOR(form); } -static PHP_METHOD(Phalcon_Forms_Manager, get){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, getViewsDir){ - zval *name, *forms, *exception_message, *form; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_viewsDir", 3398309201UL); +} - phalcon_fetch_params(1, 1, 0, &name); +static PHP_METHOD(Phalcon_Mvc_View_Simple, registerEngines){ + + zval *engines; + + phalcon_fetch_params(0, 1, 0, &engines); - PHALCON_OBS_VAR(forms); - phalcon_read_property_this_quick(&forms, this_ptr, SL("_forms"), 2325961419UL, PH_NOISY_CC); - if (!phalcon_array_isset(forms, name)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "There is no form with name='", name, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_forms_exception_ce, exception_message); + if (Z_TYPE_P(engines) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Engines to register must be an array"); return; } + phalcon_update_property_this_quick(this_ptr, SL("_registeredEngines"), engines, 3326968731UL TSRMLS_CC); - PHALCON_OBS_VAR(form); - phalcon_array_fetch(&form, forms, name, PH_NOISY); - - RETURN_CCTOR(form); } -static PHP_METHOD(Phalcon_Forms_Manager, has){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, _loadTemplateEngines){ - zval *name, *forms; + zval *engines = NULL, *dependency_injector, *registered_engines; + zval *php_engine, *arguments, *engine_service = NULL; + zval *extension = NULL, *engine_object = NULL, *exception_message = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); + PHALCON_OBS_VAR(engines); + phalcon_read_property_this_quick(&engines, this_ptr, SL("_engines"), 1840711053UL, PH_NOISY_CC); - PHALCON_OBS_VAR(forms); - phalcon_read_property_this_quick(&forms, this_ptr, SL("_forms"), 2325961419UL, PH_NOISY_CC); - if (!phalcon_array_isset(forms, name)) { - RETURN_MM_TRUE; + if (PHALCON_IS_FALSE(engines)) { + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + + PHALCON_INIT_NVAR(engines); + array_init(engines); + + PHALCON_OBS_VAR(registered_engines); + phalcon_read_property_this_quick(®istered_engines, this_ptr, SL("_registeredEngines"), 3326968731UL, PH_NOISY_CC); + if (Z_TYPE_P(registered_engines) != IS_ARRAY) { + PHALCON_INIT_VAR(php_engine); + object_init_ex(php_engine, phalcon_mvc_view_engine_php_ce); + phalcon_call_method_p2_key(NULL, php_engine, "__construct", this_ptr, dependency_injector, 1107214344UL); + + phalcon_array_update_string(&engines, SL(".phtml"), &php_engine, PH_COPY | PH_SEPARATE); + } else { + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "A dependency injector container is required to obtain the application services"); + return; + } + + PHALCON_INIT_VAR(arguments); + array_init_size(arguments, 2); + phalcon_array_append(&arguments, this_ptr, PH_SEPARATE); + phalcon_array_append(&arguments, dependency_injector, PH_SEPARATE); + + phalcon_is_iterable(registered_engines, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(extension, ah0, hp0); + PHALCON_GET_HVALUE(engine_service); + + if (Z_TYPE_P(engine_service) == IS_OBJECT) { + + if (phalcon_is_instance_of(engine_service, SL("Closure") TSRMLS_CC)) { + PHALCON_INIT_NVAR(engine_object); + PHALCON_CALL_USER_FUNC_ARRAY(engine_object, engine_service, arguments); + } else { + PHALCON_CPY_WRT(engine_object, engine_service); + } + } else { + if (Z_TYPE_P(engine_service) == IS_STRING) { + PHALCON_INIT_NVAR(engine_object); + phalcon_call_method_p2_key(engine_object, dependency_injector, "getshared", engine_service, arguments, 1727570332UL); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Invalid template engine registration for extension: ", extension); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; + } + } + phalcon_array_update_zval(&engines, extension, &engine_object, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } + + phalcon_update_property_this_quick(this_ptr, SL("_engines"), engines, 1840711053UL TSRMLS_CC); + } else { + PHALCON_OBS_NVAR(engines); + phalcon_read_property_this_quick(&engines, this_ptr, SL("_engines"), 1840711053UL, PH_NOISY_CC); } - RETURN_MM_FALSE; + RETURN_CCTOR(engines); } -static PHP_METHOD(Phalcon_Forms_Manager, set){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, _internalRender){ - zval *name, *form; + zval *path, *params, *events_manager, *event_name = NULL; + zval *status = NULL, *not_exists = NULL, *must_clean, *views_dir; + zval *views_dir_path, *engines, *engine = NULL, *extension = NULL; + zval *view_engine_path = NULL, *exception_message; + HashTable *ah0; + HashPosition hp0; + zval **hd; - phalcon_fetch_params(0, 2, 0, &name, &form); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &path, ¶ms); - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The form name must be string"); - return; + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_activeRenderPath"), path, 1528023309UL TSRMLS_CC); } - if (Z_TYPE_P(form) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_forms_exception_ce, "The form is not valid"); + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "view:beforeRender", 1); + + PHALCON_INIT_VAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_NULL(); + } + } + + PHALCON_INIT_VAR(not_exists); + ZVAL_BOOL(not_exists, 1); + + PHALCON_INIT_VAR(must_clean); + ZVAL_BOOL(must_clean, 1); + + PHALCON_OBS_VAR(views_dir); + phalcon_read_property_this_quick(&views_dir, this_ptr, SL("_viewsDir"), 3398309201UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(views_dir_path); + PHALCON_CONCAT_VV(views_dir_path, views_dir, path); + + PHALCON_INIT_VAR(engines); + phalcon_call_method_key(engines, this_ptr, "_loadtemplateengines", 4149337481UL); + + phalcon_is_iterable(engines, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(extension, ah0, hp0); + PHALCON_GET_HVALUE(engine); + + PHALCON_INIT_NVAR(view_engine_path); + PHALCON_CONCAT_VV(view_engine_path, views_dir_path, extension); + + if (phalcon_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { + + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "view:beforeRenderView", 1); + + PHALCON_INIT_NVAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, view_engine_path, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } + phalcon_call_method_p3_key(NULL, engine, "render", view_engine_path, params, must_clean, 1053215877UL); + + PHALCON_INIT_NVAR(not_exists); + ZVAL_BOOL(not_exists, 0); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "view:afterRenderView", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } + + break; + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + if (PHALCON_IS_TRUE(not_exists)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "View '", views_dir_path, "' was not found in the views directory"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); return; } - phalcon_update_property_array(this_ptr, SL("_forms"), name, form TSRMLS_CC); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "view:afterRender", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } - RETURN_THISW(); + PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Mvc_View_Simple, render){ + zval *path, *params = NULL, *cache, *is_started = NULL, *key = NULL, *lifetime = NULL; + zval *cache_options, *content = NULL, *view_params; + zval *merged_params = NULL, *is_fresh; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Forms_Element_Select){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Select, forms_element_select, "phalcon\\forms\\element", phalcon_forms_element_select_method_entry, 0); - - zend_declare_property_null(phalcon_forms_element_select_ce, SL("_optionsValues"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_forms_element_select_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); - - return SUCCESS; + phalcon_fetch_params(1, 1, 1, &path, ¶ms); + + if (!params) { + PHALCON_INIT_VAR(params); + } + + PHALCON_INIT_VAR(cache); + phalcon_call_method_key(cache, this_ptr, "getcache", 3582760537UL); + if (Z_TYPE_P(cache) == IS_OBJECT) { + + PHALCON_INIT_VAR(is_started); + phalcon_call_method_key(is_started, cache, "isstarted", 527759032UL); + if (PHALCON_IS_FALSE(is_started)) { + + PHALCON_INIT_VAR(key); + + PHALCON_INIT_VAR(lifetime); + + PHALCON_OBS_VAR(cache_options); + phalcon_read_property_this_quick(&cache_options, this_ptr, SL("_cacheOptions"), 528255652UL, PH_NOISY_CC); + + if (Z_TYPE_P(cache_options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(cache_options, SS("key"), 2090432846UL)) { + PHALCON_OBS_NVAR(key); + phalcon_array_fetch_quick_string(&key, cache_options, SS("key"), 2090432846UL, PH_NOISY); + } + if (phalcon_array_isset_quick_string(cache_options, SS("lifetime"), 2639810228UL)) { + PHALCON_OBS_NVAR(lifetime); + phalcon_array_fetch_quick_string(&lifetime, cache_options, SS("lifetime"), 2639810228UL, PH_NOISY); + } + } + + if (Z_TYPE_P(key) == IS_NULL) { + PHALCON_INIT_NVAR(key); + phalcon_md5(key, path); + } + + PHALCON_INIT_VAR(content); + phalcon_call_method_p2_key(content, cache, "start", key, lifetime, 478839859UL); + if (Z_TYPE_P(content) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_content"), content, 4081318271UL TSRMLS_CC); + RETURN_CCTOR(content); + } + } + } + + phalcon_create_symbol_table(TSRMLS_C); + + phalcon_ob_start(TSRMLS_C); + + PHALCON_OBS_VAR(view_params); + phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + + if (Z_TYPE_P(params) == IS_ARRAY) { + if (Z_TYPE_P(view_params) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_params); + phalcon_fast_array_merge(merged_params, &view_params, ¶ms TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_params, params); + } + } else { + PHALCON_CPY_WRT(merged_params, view_params); + } + + phalcon_call_method_p2_key(NULL, this_ptr, "_internalrender", path, merged_params, 608460065UL); + + if (Z_TYPE_P(cache) == IS_OBJECT) { + + PHALCON_INIT_NVAR(is_started); + phalcon_call_method_key(is_started, cache, "isstarted", 527759032UL); + if (PHALCON_IS_TRUE(is_started)) { + + PHALCON_INIT_VAR(is_fresh); + phalcon_call_method_key(is_fresh, cache, "isfresh", 3981662073UL); + if (PHALCON_IS_TRUE(is_fresh)) { + phalcon_call_method_key(NULL, cache, "save", 274150868UL); + } else { + phalcon_call_method_key(NULL, cache, "stop", 274826411UL); + } + } else { + phalcon_call_method_key(NULL, cache, "stop", 274826411UL); + } + } + + phalcon_ob_end_clean(TSRMLS_C); + + PHALCON_OBS_NVAR(content); + phalcon_read_property_this_quick(&content, this_ptr, SL("_content"), 4081318271UL, PH_NOISY_CC); + + RETURN_CCTOR(content); } -static PHP_METHOD(Phalcon_Forms_Element_Select, __construct){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, partial){ - zval *name, *options = NULL, *attributes = NULL; + zval *partial_path, *params = NULL, *view_params, *merged_params = NULL; + zval *content; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &name, &options, &attributes); + phalcon_fetch_params(1, 1, 1, &partial_path, ¶ms); + + if (!params) { + PHALCON_INIT_VAR(params); + } - if (!options) { - PHALCON_INIT_VAR(options); + phalcon_ob_start(TSRMLS_C); + + if (Z_TYPE_P(params) == IS_ARRAY) { + + PHALCON_OBS_VAR(view_params); + phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + + if (Z_TYPE_P(view_params) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_params); + phalcon_fast_array_merge(merged_params, &view_params, ¶ms TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_params, params); + } + + phalcon_create_symbol_table(TSRMLS_C); + + } else { + PHALCON_CPY_WRT(merged_params, params); } - if (!attributes) { - PHALCON_INIT_VAR(attributes); + phalcon_call_method_p2_key(NULL, this_ptr, "_internalrender", partial_path, merged_params, 608460065UL); + + if (Z_TYPE_P(params) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), view_params, 1685283331UL TSRMLS_CC); } - phalcon_update_property_this_quick(this_ptr, SL("_optionsValues"), options, 842653632UL TSRMLS_CC); - PHALCON_CALL_PARENT_PARAMS_2_NORETURN(this_ptr, "Phalcon\\Forms\\Element\\Select", "__construct", name, attributes); + phalcon_ob_end_clean(TSRMLS_C); + + PHALCON_OBS_VAR(content); + phalcon_read_property_this_quick(&content, this_ptr, SL("_content"), 4081318271UL, PH_NOISY_CC); + + zend_print_zval(content, 0); PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Forms_Element_Select, setOptions){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, setCacheOptions){ zval *options; phalcon_fetch_params(0, 1, 0, &options); - phalcon_update_property_this_quick(this_ptr, SL("_optionsValues"), options, 842653632UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_cacheOptions"), options, 528255652UL TSRMLS_CC); RETURN_THISW(); } -static PHP_METHOD(Phalcon_Forms_Element_Select, getOptions){ - - - RETURN_MEMBER_QUICK(this_ptr, "_optionsValues", 842653632UL); -} - -static PHP_METHOD(Phalcon_Forms_Element_Select, addOption){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, getCacheOptions){ - zval *option; - phalcon_fetch_params(0, 1, 0, &option); - - phalcon_update_property_array_append(this_ptr, SL("_optionsValues"), option TSRMLS_CC); - RETURN_THISW(); + RETURN_MEMBER_QUICK(this_ptr, "_cacheOptions", 528255652UL); } -static PHP_METHOD(Phalcon_Forms_Element_Select, render){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, _createCache){ - zval *attributes = NULL, *options, *widget_attributes; + zval *dependency_injector, *cache_service = NULL; + zval *cache_options, *view_cache; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &attributes); - - if (!attributes) { - PHALCON_INIT_VAR(attributes); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "A dependency injector container is required to obtain the view cache services"); + return; } - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_optionsValues"), 842653632UL, PH_NOISY_CC); + PHALCON_INIT_VAR(cache_service); + ZVAL_STRING(cache_service, "viewCache", 1); - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); - PHALCON_CALL_STATIC_PARAMS_2(return_value, "phalcon\\tag\\select", "selectfield", widget_attributes, options); - RETURN_MM(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Forms_Element_Password){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Password, forms_element_password, "phalcon\\forms\\element", phalcon_forms_element_password_method_entry, 0); - - zend_class_implements(phalcon_forms_element_password_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Forms_Element_Password, render){ - - zval *attributes = NULL, *widget_attributes; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &attributes); + PHALCON_OBS_VAR(cache_options); + phalcon_read_property_this_quick(&cache_options, this_ptr, SL("_cacheOptions"), 528255652UL, PH_NOISY_CC); + if (Z_TYPE_P(cache_options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(cache_options, SS("service"), 243174486UL)) { + PHALCON_OBS_NVAR(cache_service); + phalcon_array_fetch_quick_string(&cache_service, cache_options, SS("service"), 243174486UL, PH_NOISY); + } + } - if (!attributes) { - PHALCON_INIT_VAR(attributes); + PHALCON_INIT_VAR(view_cache); + phalcon_call_method_p1_key(view_cache, dependency_injector, "getshared", cache_service, 1727570332UL); + if (Z_TYPE_P(view_cache) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The injected caching service is invalid"); + return; } - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); - PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "passwordfield", widget_attributes); - RETURN_MM(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Forms_Element_Date){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Date, forms_element_date, "phalcon\\forms\\element", phalcon_forms_element_date_method_entry, 0); - - zend_class_implements(phalcon_forms_element_date_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); - - return SUCCESS; + RETURN_CCTOR(view_cache); } -static PHP_METHOD(Phalcon_Forms_Element_Date, render){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, getCache){ - zval *attributes = NULL, *widget_attributes; + zval *cache = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &attributes); - - if (!attributes) { - PHALCON_INIT_VAR(attributes); + PHALCON_OBS_VAR(cache); + phalcon_read_property_this_quick(&cache, this_ptr, SL("_cache"), 2191407384UL, PH_NOISY_CC); + if (zend_is_true(cache)) { + if (Z_TYPE_P(cache) != IS_OBJECT) { + PHALCON_INIT_NVAR(cache); + phalcon_call_method_key(cache, this_ptr, "_createcache", 1216889100UL); + phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); + } } - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); - PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "datefield", widget_attributes); - RETURN_MM(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Forms_Element_Numeric){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Numeric, forms_element_numeric, "phalcon\\forms\\element", phalcon_forms_element_numeric_method_entry, 0); - - zend_class_implements(phalcon_forms_element_numeric_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); - - return SUCCESS; + RETURN_CCTOR(cache); } -static PHP_METHOD(Phalcon_Forms_Element_Numeric, render){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, cache){ - zval *attributes = NULL, *widget_attributes; + zval *options = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &attributes); + phalcon_fetch_params(1, 0, 1, &options); - if (!attributes) { - PHALCON_INIT_VAR(attributes); + if (!options) { + PHALCON_INIT_VAR(options); + ZVAL_BOOL(options, 1); } - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); - PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "numericfield", widget_attributes); - RETURN_MM(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Forms_Element_TextArea){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, TextArea, forms_element_textarea, "phalcon\\forms\\element", phalcon_forms_element_textarea_method_entry, 0); - - zend_class_implements(phalcon_forms_element_textarea_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Forms_Element_TextArea, render){ - - zval *attributes = NULL, *widget_attributes; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &attributes); - - if (!attributes) { - PHALCON_INIT_VAR(attributes); + if (Z_TYPE_P(options) == IS_ARRAY) { + phalcon_update_property_bool(this_ptr, SL("_cache"), 1 TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_cacheOptions"), options, 528255652UL TSRMLS_CC); + } else { + if (zend_is_true(options)) { + phalcon_update_property_bool(this_ptr, SL("_cache"), 1 TSRMLS_CC); + } else { + phalcon_update_property_bool(this_ptr, SL("_cache"), 0 TSRMLS_CC); + } } - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); - PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "textarea", widget_attributes); - RETURN_MM(); + RETURN_THIS(); } +static PHP_METHOD(Phalcon_Mvc_View_Simple, setParamToView){ + zval *key, *value; - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Forms_Element_Submit){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Submit, forms_element_submit, "phalcon\\forms\\element", phalcon_forms_element_submit_method_entry, 0); - - zend_class_implements(phalcon_forms_element_submit_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); - - return SUCCESS; + phalcon_fetch_params(0, 2, 0, &key, &value); + + phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Forms_Element_Submit, render){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, setVars){ - zval *attributes = NULL, *widget_attributes, *code; + zval *params, *merge = NULL, *view_params, *merged_params = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &attributes); + phalcon_fetch_params(1, 1, 1, ¶ms, &merge); - if (!attributes) { - PHALCON_INIT_VAR(attributes); + if (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 1); } - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); + if (Z_TYPE_P(params) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The render parameters must be an array"); + return; + } + if (zend_is_true(merge)) { - PHALCON_INIT_VAR(code); - PHALCON_CALL_STATIC_PARAMS_1(code, "phalcon\\tag", "submitbutton", widget_attributes); - RETURN_CCTOR(code); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Forms_Element_Email){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Email, forms_element_email, "phalcon\\forms\\element", phalcon_forms_element_email_method_entry, 0); - - zend_class_implements(phalcon_forms_element_email_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Forms_Element_Email, render){ - - zval *attributes = NULL, *widget_attributes; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &attributes); + PHALCON_OBS_VAR(view_params); + phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + if (Z_TYPE_P(view_params) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_params); + phalcon_fast_array_merge(merged_params, &view_params, ¶ms TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_params, params); + } - if (!attributes) { - PHALCON_INIT_VAR(attributes); + phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), merged_params, 1685283331UL TSRMLS_CC); + } else { + phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), params, 1685283331UL TSRMLS_CC); } - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); - PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "emailfield", widget_attributes); - RETURN_MM(); + RETURN_THIS(); } +static PHP_METHOD(Phalcon_Mvc_View_Simple, setVar){ + zval *key, *value; - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Forms_Element_File){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, File, forms_element_file, "phalcon\\forms\\element", phalcon_forms_element_file_method_entry, 0); - - zend_class_implements(phalcon_forms_element_file_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); - - return SUCCESS; + phalcon_fetch_params(0, 2, 0, &key, &value); + + phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Forms_Element_File, render){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, getVar){ - zval *attributes = NULL, *widget_attributes; + zval *key, *params, *value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &attributes); + phalcon_fetch_params(1, 1, 0, &key); - if (!attributes) { - PHALCON_INIT_VAR(attributes); + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + if (phalcon_array_isset(params, key)) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, params, key, PH_NOISY); + RETURN_CCTOR(value); } - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); - PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "filefield", widget_attributes); - RETURN_MM(); + RETURN_MM_NULL(); } +static PHP_METHOD(Phalcon_Mvc_View_Simple, getParamsToView){ - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Forms_Element_Hidden){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Hidden, forms_element_hidden, "phalcon\\forms\\element", phalcon_forms_element_hidden_method_entry, 0); - - zend_class_implements(phalcon_forms_element_hidden_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); - - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_viewParams", 1685283331UL); } -static PHP_METHOD(Phalcon_Forms_Element_Hidden, render){ - - zval *attributes = NULL, *widget_attributes; +static PHP_METHOD(Phalcon_Mvc_View_Simple, setContent){ - PHALCON_MM_GROW(); + zval *content; - phalcon_fetch_params(1, 0, 1, &attributes); + phalcon_fetch_params(0, 1, 0, &content); - if (!attributes) { - PHALCON_INIT_VAR(attributes); + if (Z_TYPE_P(content) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Content must be a string"); + return; } + phalcon_update_property_this_quick(this_ptr, SL("_content"), content, 4081318271UL TSRMLS_CC); - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); - PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "hiddenfield", widget_attributes); - RETURN_MM(); + RETURN_THISW(); } +static PHP_METHOD(Phalcon_Mvc_View_Simple, getContent){ + RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); +} - -#ifdef HAVE_CONFIG_H -#endif - - - - - +static PHP_METHOD(Phalcon_Mvc_View_Simple, getActiveRenderPath){ -PHALCON_INIT_CLASS(Phalcon_Forms_Element_Text){ + RETURN_MEMBER_QUICK(this_ptr, "_activeRenderPath", 1528023309UL); +} - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Text, forms_element_text, "phalcon\\forms\\element", phalcon_forms_element_text_method_entry, 0); +static PHP_METHOD(Phalcon_Mvc_View_Simple, __set){ - zend_class_implements(phalcon_forms_element_text_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + zval *key, *value; - return SUCCESS; + phalcon_fetch_params(0, 2, 0, &key, &value); + + phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); + } -static PHP_METHOD(Phalcon_Forms_Element_Text, render){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, __get){ - zval *attributes = NULL, *widget_attributes; + zval *key, *params, *value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &attributes); + phalcon_fetch_params(1, 1, 0, &key); - if (!attributes) { - PHALCON_INIT_VAR(attributes); + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + if (phalcon_array_isset(params, key)) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, params, key, PH_NOISY); + RETURN_CCTOR(value); } - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p1_key(widget_attributes, this_ptr, "prepareattributes", attributes, 597834619UL); - PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "textfield", widget_attributes); - RETURN_MM(); + RETURN_MM_NULL(); } @@ -92273,1228 +92596,1245 @@ static PHP_METHOD(Phalcon_Forms_Element_Text, render){ -PHALCON_INIT_CLASS(Phalcon_Forms_Element_Check){ +PHALCON_INIT_CLASS(Phalcon_Mvc_View){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms\\Element, Check, forms_element_check, "phalcon\\forms\\element", phalcon_forms_element_check_method_entry, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, View, mvc_view, "phalcon\\di\\injectable", phalcon_mvc_view_method_entry, 0); - zend_class_implements(phalcon_forms_element_check_ce TSRMLS_CC, 1, phalcon_forms_elementinterface_ce); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_mvc_view_ce, SL("_basePath"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_mvc_view_ce, SL("_content"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_view_ce, SL("_renderLevel"), 5, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_disabledLevels"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_viewParams"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_layout"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_mvc_view_ce, SL("_layoutsDir"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_mvc_view_ce, SL("_partialsDir"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_viewsDir"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_templatesBefore"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_templatesAfter"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_view_ce, SL("_engines"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_registeredEngines"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_string(phalcon_mvc_view_ce, SL("_mainView"), "index", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_controllerName"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_actionName"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_params"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_pickView"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_cache"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_view_ce, SL("_cacheLevel"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_mvc_view_ce, SL("_activeRenderPath"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_mvc_view_ce, SL("_disabled"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_MAIN_LAYOUT"), 5 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_AFTER_TEMPLATE"), 4 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_LAYOUT"), 3 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_BEFORE_TEMPLATE"), 2 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_ACTION_VIEW"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_mvc_view_ce, SL("LEVEL_NO_RENDER"), 0 TSRMLS_CC); + + zend_class_implements(phalcon_mvc_view_ce TSRMLS_CC, 1, phalcon_mvc_viewinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Forms_Element_Check, render){ +static PHP_METHOD(Phalcon_Mvc_View, __construct){ - zval *attributes = NULL, *use_checked, *widget_attributes; + zval *options = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &attributes); + phalcon_fetch_params(1, 0, 1, &options); - if (!attributes) { - PHALCON_INIT_VAR(attributes); + if (!options) { + PHALCON_INIT_VAR(options); } - PHALCON_INIT_VAR(use_checked); - ZVAL_BOOL(use_checked, 1); + if (Z_TYPE_P(options) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + } - PHALCON_INIT_VAR(widget_attributes); - phalcon_call_method_p2_key(widget_attributes, this_ptr, "prepareattributes", attributes, use_checked, 597834619UL); - PHALCON_CALL_STATIC_PARAMS_1(return_value, "phalcon\\tag", "checkfield", widget_attributes); - RETURN_MM(); + PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Mvc_View, setViewsDir){ + zval *views_dir; + phalcon_fetch_params(0, 1, 0, &views_dir); + + if (Z_TYPE_P(views_dir) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "The views directory must be a string"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_viewsDir"), views_dir, 3398309201UL TSRMLS_CC); + + RETURN_THISW(); +} - -#ifdef HAVE_CONFIG_H -#endif +static PHP_METHOD(Phalcon_Mvc_View, getViewsDir){ + RETURN_MEMBER_QUICK(this_ptr, "_viewsDir", 3398309201UL); +} +static PHP_METHOD(Phalcon_Mvc_View, setLayoutsDir){ + zval *layouts_dir; + phalcon_fetch_params(0, 1, 0, &layouts_dir); + + phalcon_update_property_this_quick(this_ptr, SL("_layoutsDir"), layouts_dir, 313056692UL TSRMLS_CC); + RETURN_THISW(); +} -PHALCON_INIT_CLASS(Phalcon_Forms_Exception){ +static PHP_METHOD(Phalcon_Mvc_View, getLayoutsDir){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Forms, Exception, forms_exception, "phalcon\\exception", NULL, 0); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_layoutsDir", 313056692UL); } +static PHP_METHOD(Phalcon_Mvc_View, setPartialsDir){ + zval *partials_dir; + phalcon_fetch_params(0, 1, 0, &partials_dir); + + phalcon_update_property_this_quick(this_ptr, SL("_partialsDir"), partials_dir, 2130168739UL TSRMLS_CC); + RETURN_THISW(); +} - -#ifdef HAVE_CONFIG_H -#endif +static PHP_METHOD(Phalcon_Mvc_View, getPartialsDir){ + RETURN_MEMBER_QUICK(this_ptr, "_partialsDir", 2130168739UL); +} -PHALCON_INIT_CLASS(Phalcon_Filter_UserFilterInterface){ +static PHP_METHOD(Phalcon_Mvc_View, setBasePath){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Filter, UserFilterInterface, filter_userfilterinterface, phalcon_filter_userfilterinterface_method_entry); + zval *base_path; - return SUCCESS; + phalcon_fetch_params(0, 1, 0, &base_path); + + phalcon_update_property_this_quick(this_ptr, SL("_basePath"), base_path, 1477430348UL TSRMLS_CC); + RETURN_THISW(); } +static PHP_METHOD(Phalcon_Mvc_View, setRenderLevel){ + zval *level; + phalcon_fetch_params(0, 1, 0, &level); + + phalcon_update_property_this_quick(this_ptr, SL("_renderLevel"), level, 3194989084UL TSRMLS_CC); + RETURN_THISW(); +} +static PHP_METHOD(Phalcon_Mvc_View, disableLevel){ + zval *level, *disabled; -#ifdef HAVE_CONFIG_H -#endif - + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &level); + + if (Z_TYPE_P(level) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_disabledLevels"), level, 1575004551UL TSRMLS_CC); + } else { + PHALCON_INIT_VAR(disabled); + ZVAL_BOOL(disabled, 1); + phalcon_update_property_array(this_ptr, SL("_disabledLevels"), level, disabled TSRMLS_CC); + } + + RETURN_THIS(); +} +static PHP_METHOD(Phalcon_Mvc_View, setMainView){ + zval *view_path; + phalcon_fetch_params(0, 1, 0, &view_path); + + phalcon_update_property_this_quick(this_ptr, SL("_mainView"), view_path, 1829858724UL TSRMLS_CC); + RETURN_THISW(); +} -PHALCON_INIT_CLASS(Phalcon_Filter_Exception){ +static PHP_METHOD(Phalcon_Mvc_View, getMainView){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Filter, Exception, filter_exception, "phalcon\\exception", NULL, 0); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_mainView", 1829858724UL); } +static PHP_METHOD(Phalcon_Mvc_View, setLayout){ + + zval *layout; + phalcon_fetch_params(0, 1, 0, &layout); + + phalcon_update_property_this_quick(this_ptr, SL("_layout"), layout, 2361639842UL TSRMLS_CC); + RETURN_THISW(); +} +static PHP_METHOD(Phalcon_Mvc_View, getLayout){ -#ifdef HAVE_CONFIG_H -#endif + RETURN_MEMBER_QUICK(this_ptr, "_layout", 2361639842UL); +} +static PHP_METHOD(Phalcon_Mvc_View, setTemplateBefore){ + zval *template_before, *array_template; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &template_before); + + if (Z_TYPE_P(template_before) != IS_ARRAY) { + PHALCON_INIT_VAR(array_template); + array_init_size(array_template, 1); + phalcon_array_append(&array_template, template_before, PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_templatesBefore"), array_template, 3273177030UL TSRMLS_CC); + } else { + phalcon_update_property_this_quick(this_ptr, SL("_templatesBefore"), template_before, 3273177030UL TSRMLS_CC); + } + + RETURN_THIS(); +} +static PHP_METHOD(Phalcon_Mvc_View, cleanTemplateBefore){ -PHALCON_INIT_CLASS(Phalcon_Security){ + phalcon_update_property_null(this_ptr, SL("_templatesBefore") TSRMLS_CC); + RETURN_THISW(); +} - PHALCON_REGISTER_CLASS(Phalcon, Security, security, phalcon_security_method_entry, 0); +static PHP_METHOD(Phalcon_Mvc_View, setTemplateAfter){ - zend_declare_property_null(phalcon_security_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_security_ce, SL("_workFactor"), 8, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_security_ce, SL("_numberBytes"), 16, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_security_ce, SL("_csrf"), ZEND_ACC_PROTECTED TSRMLS_CC); + zval *template_after, *array_template; - zend_class_implements(phalcon_security_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 1, 0, &template_after); + + if (Z_TYPE_P(template_after) != IS_ARRAY) { + PHALCON_INIT_VAR(array_template); + array_init_size(array_template, 1); + phalcon_array_append(&array_template, template_after, PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_templatesAfter"), array_template, 3575793989UL TSRMLS_CC); + } else { + phalcon_update_property_this_quick(this_ptr, SL("_templatesAfter"), template_after, 3575793989UL TSRMLS_CC); + } + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Security, setDI){ +static PHP_METHOD(Phalcon_Mvc_View, cleanTemplateAfter){ - zval *dependency_injector; - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - + phalcon_update_property_null(this_ptr, SL("_templatesAfter") TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Security, getDI){ +static PHP_METHOD(Phalcon_Mvc_View, setParamToView){ + zval *key, *value; - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); + phalcon_fetch_params(0, 2, 0, &key, &value); + + phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Security, setRandomBytes){ +static PHP_METHOD(Phalcon_Mvc_View, setVars){ - zval *random_bytes; + zval *params, *merge = NULL, *view_params, *merged_params = NULL; - phalcon_fetch_params(0, 1, 0, &random_bytes); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, ¶ms, &merge); - if (Z_TYPE_P(random_bytes) != IS_LONG) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_security_exception_ce, "Random bytes must be integer"); - return; + if (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 1); } - if (PHALCON_LT_LONG(random_bytes, 16)) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_security_exception_ce, "At least 16 bytes are needed to produce a correct salt"); + + if (Z_TYPE_P(params) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The render parameters must be an array"); return; } + if (zend_is_true(merge)) { - phalcon_update_property_this_quick(this_ptr, SL("_numberBytes"), random_bytes, 1300189556UL TSRMLS_CC); + PHALCON_OBS_VAR(view_params); + phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + if (Z_TYPE_P(view_params) == IS_ARRAY) { + PHALCON_INIT_VAR(merged_params); + phalcon_fast_array_merge(merged_params, &view_params, ¶ms TSRMLS_CC); + } else { + PHALCON_CPY_WRT(merged_params, params); + } + + phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), merged_params, 1685283331UL TSRMLS_CC); + } else { + phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), params, 1685283331UL TSRMLS_CC); + } + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Security, getRandomBytes){ +static PHP_METHOD(Phalcon_Mvc_View, setVar){ + zval *key, *value; - RETURN_MEMBER_QUICK(this_ptr, "_numberBytes", 1300189556UL); + phalcon_fetch_params(0, 2, 0, &key, &value); + + phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Security, setWorkFactor){ +static PHP_METHOD(Phalcon_Mvc_View, getVar){ - zval *work_factor; + zval *key, *params, *value; - phalcon_fetch_params(0, 1, 0, &work_factor); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &key); - if (Z_TYPE_P(work_factor) != IS_LONG) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_security_exception_ce, "Work factor must be integer"); - return; + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + if (phalcon_array_isset(params, key)) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, params, key, PH_NOISY); + RETURN_CCTOR(value); } - phalcon_update_property_this_quick(this_ptr, SL("_workFactor"), work_factor, 3598705926UL TSRMLS_CC); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Security, getWorkFactor){ +static PHP_METHOD(Phalcon_Mvc_View, getParamsToView){ - RETURN_MEMBER_QUICK(this_ptr, "_workFactor", 3598705926UL); + RETURN_MEMBER_QUICK(this_ptr, "_viewParams", 1685283331UL); } -static PHP_METHOD(Phalcon_Security, getSaltBytes){ +static PHP_METHOD(Phalcon_Mvc_View, getControllerName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_controllerName", 3332183433UL); +} + +static PHP_METHOD(Phalcon_Mvc_View, getActionName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_actionName", 2975797059UL); +} + +static PHP_METHOD(Phalcon_Mvc_View, getParams){ + + + RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); +} + +static PHP_METHOD(Phalcon_Mvc_View, start){ - zval *number_bytes, *random_bytes = NULL, *base64bytes = NULL; - zval *safe_bytes = NULL, *bytes_length = NULL; PHALCON_MM_GROW(); - if (phalcon_function_quick_exists_ex(SS("openssl_random_pseudo_bytes"), 2196693822UL TSRMLS_CC) == FAILURE) { - PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "Openssl extension must be loaded"); - return; - } + phalcon_update_property_null(this_ptr, SL("_content") TSRMLS_CC); + phalcon_ob_start(TSRMLS_C); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_View, _loadTemplateEngines){ + + zval *engines = NULL, *dependency_injector, *registered_engines; + zval *php_engine, *arguments, *engine_service = NULL; + zval *extension = NULL, *engine_object = NULL, *exception_message = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(engines); + phalcon_read_property_this_quick(&engines, this_ptr, SL("_engines"), 1840711053UL, PH_NOISY_CC); - PHALCON_OBS_VAR(number_bytes); - phalcon_read_property_this_quick(&number_bytes, this_ptr, SL("_numberBytes"), 1300189556UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(engines)) { - while (1) { + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(random_bytes); - phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); + PHALCON_INIT_NVAR(engines); + array_init(engines); - PHALCON_INIT_NVAR(base64bytes); - phalcon_base64_encode(base64bytes, random_bytes); + PHALCON_OBS_VAR(registered_engines); + phalcon_read_property_this_quick(®istered_engines, this_ptr, SL("_registeredEngines"), 3326968731UL, PH_NOISY_CC); + if (Z_TYPE_P(registered_engines) != IS_ARRAY) { + PHALCON_INIT_VAR(php_engine); + object_init_ex(php_engine, phalcon_mvc_view_engine_php_ce); + phalcon_call_method_p2_key(NULL, php_engine, "__construct", this_ptr, dependency_injector, 1107214344UL); - PHALCON_INIT_NVAR(safe_bytes); - phalcon_filter_alphanum(safe_bytes, base64bytes); - if (!zend_is_true(safe_bytes)) { - continue; - } + phalcon_array_update_string(&engines, SL(".phtml"), &php_engine, PH_COPY | PH_SEPARATE); + } else { + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "A dependency injector container is required to obtain the application services"); + return; + } + + PHALCON_INIT_VAR(arguments); + array_init_size(arguments, 2); + phalcon_array_append(&arguments, this_ptr, PH_SEPARATE); + phalcon_array_append(&arguments, dependency_injector, PH_SEPARATE); + + phalcon_is_iterable(registered_engines, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(extension, ah0, hp0); + PHALCON_GET_HVALUE(engine_service); + + if (Z_TYPE_P(engine_service) == IS_OBJECT) { + + if (phalcon_is_instance_of(engine_service, SL("Closure") TSRMLS_CC)) { + PHALCON_INIT_NVAR(engine_object); + PHALCON_CALL_USER_FUNC_ARRAY(engine_object, engine_service, arguments); + } else { + PHALCON_CPY_WRT(engine_object, engine_service); + } + } else { + if (Z_TYPE_P(engine_service) == IS_STRING) { + PHALCON_INIT_NVAR(engine_object); + phalcon_call_method_p2_key(engine_object, dependency_injector, "getshared", engine_service, arguments, 1727570332UL); + } else { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "Invalid template engine registration for extension: ", extension); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; + } + } + phalcon_array_update_zval(&engines, extension, &engine_object, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_INIT_NVAR(bytes_length); - phalcon_fast_strlen(bytes_length, safe_bytes); - if (PHALCON_LT_LONG(bytes_length, 22)) { - continue; } - break; + phalcon_update_property_this_quick(this_ptr, SL("_engines"), engines, 1840711053UL TSRMLS_CC); + } else { + PHALCON_OBS_NVAR(engines); + phalcon_read_property_this_quick(&engines, this_ptr, SL("_engines"), 1840711053UL, PH_NOISY_CC); } - RETURN_CTOR(safe_bytes); + RETURN_CCTOR(engines); } -static PHP_METHOD(Phalcon_Security, hash){ +static PHP_METHOD(Phalcon_Mvc_View, _engineRender){ - zval *password, *work_factor = NULL, *format, *factor; - zval *salt_bytes, *salt; + zval *engines, *view_path, *silence, *must_clean; + zval *cache, *not_exists = NULL, *views_dir, *base_path; + zval *views_dir_path, *render_level, *cache_level; + zval *is_started, *key = NULL, *lifetime = NULL, *view_options; + zval *cache_options, *cached_view, *is_fresh; + zval *view_params, *events_manager, *engine = NULL; + zval *extension = NULL, *view_engine_path = NULL, *event_name = NULL; + zval *status = NULL, *exception_message; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &password, &work_factor); + phalcon_fetch_params(1, 5, 0, &engines, &view_path, &silence, &must_clean, &cache); - if (!work_factor) { - PHALCON_INIT_VAR(work_factor); - } else { - PHALCON_SEPARATE_PARAM(work_factor); - } + PHALCON_INIT_VAR(not_exists); + ZVAL_BOOL(not_exists, 1); - if (Z_TYPE_P(work_factor) == IS_NULL) { - PHALCON_OBS_NVAR(work_factor); - phalcon_read_property_this_quick(&work_factor, this_ptr, SL("_workFactor"), 3598705926UL, PH_NOISY_CC); - } + PHALCON_OBS_VAR(views_dir); + phalcon_read_property_this_quick(&views_dir, this_ptr, SL("_viewsDir"), 3398309201UL, PH_NOISY_CC); - PHALCON_INIT_VAR(format); - ZVAL_STRING(format, "%02s", 1); + PHALCON_OBS_VAR(base_path); + phalcon_read_property_this_quick(&base_path, this_ptr, SL("_basePath"), 1477430348UL, PH_NOISY_CC); - PHALCON_INIT_VAR(factor); - phalcon_call_func_p2(factor, "sprintf", format, work_factor); + PHALCON_INIT_VAR(views_dir_path); + PHALCON_CONCAT_VVV(views_dir_path, base_path, views_dir, view_path); - PHALCON_INIT_VAR(salt_bytes); - phalcon_call_method_key(salt_bytes, this_ptr, "getsaltbytes", 2293626208UL); + if (Z_TYPE_P(cache) == IS_OBJECT) { - PHALCON_INIT_VAR(salt); - PHALCON_CONCAT_SVSV(salt, "$2a$", factor, "$", salt_bytes); - phalcon_call_func_p2(return_value, "crypt", password, salt); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Security, checkHash){ - - zval *password, *password_hash, *hash; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &password, &password_hash); + PHALCON_OBS_VAR(render_level); + phalcon_read_property_this_quick(&render_level, this_ptr, SL("_renderLevel"), 3194989084UL, PH_NOISY_CC); - PHALCON_INIT_VAR(hash); - phalcon_call_func_p2(hash, "crypt", password, password_hash); - is_equal_function(return_value, hash, password_hash TSRMLS_CC); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Security, isLegacyHash){ - - zval *password_hash; - - phalcon_fetch_params(0, 1, 0, &password_hash); + PHALCON_OBS_VAR(cache_level); + phalcon_read_property_this_quick(&cache_level, this_ptr, SL("_cacheLevel"), 3155415824UL, PH_NOISY_CC); + if (PHALCON_GE(render_level, cache_level)) { - if (phalcon_start_with_str(password_hash, SL("$2a$"))) { - RETURN_TRUE; + PHALCON_INIT_VAR(is_started); + phalcon_call_method_key(is_started, cache, "isstarted", 527759032UL); + if (PHALCON_IS_FALSE(is_started)) { + + PHALCON_INIT_VAR(key); + + PHALCON_INIT_VAR(lifetime); + + PHALCON_OBS_VAR(view_options); + phalcon_read_property_this_quick(&view_options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + + if (Z_TYPE_P(view_options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(view_options, SS("cache"), 4125168857UL)) { + + PHALCON_OBS_VAR(cache_options); + phalcon_array_fetch_quick_string(&cache_options, view_options, SS("cache"), 4125168857UL, PH_NOISY); + if (Z_TYPE_P(cache_options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(cache_options, SS("key"), 2090432846UL)) { + PHALCON_OBS_NVAR(key); + phalcon_array_fetch_quick_string(&key, cache_options, SS("key"), 2090432846UL, PH_NOISY); + } + if (phalcon_array_isset_quick_string(cache_options, SS("lifetime"), 2639810228UL)) { + PHALCON_OBS_NVAR(lifetime); + phalcon_array_fetch_quick_string(&lifetime, cache_options, SS("lifetime"), 2639810228UL, PH_NOISY); + } + } + } + } + + if (Z_TYPE_P(key) == IS_NULL) { + PHALCON_INIT_NVAR(key); + phalcon_md5(key, view_path); + } + + PHALCON_INIT_VAR(cached_view); + phalcon_call_method_p2_key(cached_view, cache, "start", key, lifetime, 478839859UL); + if (Z_TYPE_P(cached_view) != IS_NULL) { + phalcon_update_property_this_quick(this_ptr, SL("_content"), cached_view, 4081318271UL TSRMLS_CC); + RETURN_MM_NULL(); + } + } + + PHALCON_INIT_VAR(is_fresh); + phalcon_call_method_key(is_fresh, cache, "isfresh", 3981662073UL); + if (!zend_is_true(is_fresh)) { + RETURN_MM_NULL(); + } + } } - RETURN_FALSE; -} - -static PHP_METHOD(Phalcon_Security, getTokenKey){ - - zval *number_bytes = NULL, *random_bytes, *base64bytes; - zval *safe_bytes, *dependency_injector, *service; - zval *session, *key; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &number_bytes); - if (!number_bytes) { - PHALCON_INIT_VAR(number_bytes); - ZVAL_LONG(number_bytes, 12); - } + PHALCON_OBS_VAR(view_params); + phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + + phalcon_is_iterable(engines, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HKEY(extension, ah0, hp0); + PHALCON_GET_HVALUE(engine); + + PHALCON_INIT_NVAR(view_engine_path); + PHALCON_CONCAT_VV(view_engine_path, views_dir_path, extension); - if (phalcon_function_quick_exists_ex(SS("openssl_random_pseudo_bytes"), 2196693822UL TSRMLS_CC) == FAILURE) { - PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "Openssl extension must be loaded"); - return; - } + if (phalcon_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_VAR(random_bytes); - phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_activeRenderPath"), view_engine_path, 1528023309UL TSRMLS_CC); - PHALCON_INIT_VAR(base64bytes); - phalcon_base64_encode(base64bytes, random_bytes); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "view:beforeRenderView", 1); - PHALCON_INIT_VAR(safe_bytes); - phalcon_filter_alphanum(safe_bytes, base64bytes); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p3_key(status, events_manager, "fire", event_name, this_ptr, view_engine_path, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } + phalcon_call_method_p3_key(NULL, engine, "render", view_engine_path, view_params, must_clean, 1053215877UL); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); - return; + PHALCON_INIT_NVAR(not_exists); + ZVAL_BOOL(not_exists, 0); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "view:afterRenderView", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } + + break; + } + + zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "session", 1); + if (PHALCON_IS_TRUE(not_exists)) { - PHALCON_INIT_VAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_activeRenderPath"), view_engine_path, 1528023309UL TSRMLS_CC); - PHALCON_INIT_VAR(key); - ZVAL_STRING(key, "$PHALCON/CSRF/KEY$", 1); - phalcon_call_method_p2_key(NULL, session, "set", key, safe_bytes, 2090720177UL); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "view:notFoundView", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } + if (!zend_is_true(silence)) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVS(exception_message, "View '", views_dir_path, "' was not found in the views directory"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); + return; + } + } - RETURN_CTOR(safe_bytes); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Security, getToken){ - - zval *number_bytes = NULL, *random_bytes, *token, *dependency_injector; - zval *service, *session, *key; +static PHP_METHOD(Phalcon_Mvc_View, registerEngines){ - PHALCON_MM_GROW(); + zval *engines; - phalcon_fetch_params(1, 0, 1, &number_bytes); - - if (!number_bytes) { - PHALCON_INIT_VAR(number_bytes); - ZVAL_LONG(number_bytes, 12); - } - - if (phalcon_function_quick_exists_ex(SS("openssl_random_pseudo_bytes"), 2196693822UL TSRMLS_CC) == FAILURE) { - PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "Openssl extension must be loaded"); - return; - } - - PHALCON_INIT_VAR(random_bytes); - phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); - - PHALCON_INIT_VAR(token); - phalcon_md5(token, random_bytes); + phalcon_fetch_params(0, 1, 0, &engines); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); + if (Z_TYPE_P(engines) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Engines to register must be an array"); return; } + phalcon_update_property_this_quick(this_ptr, SL("_registeredEngines"), engines, 3326968731UL TSRMLS_CC); - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "session", 1); - - PHALCON_INIT_VAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); - - PHALCON_INIT_VAR(key); - ZVAL_STRING(key, "$PHALCON/CSRF$", 1); - phalcon_call_method_p2_key(NULL, session, "set", key, token, 2090720177UL); - - RETURN_CTOR(token); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Security, checkToken){ +static PHP_METHOD(Phalcon_Mvc_View, render){ - zval *token_key = NULL, *token_value = NULL, *dependency_injector; - zval *service = NULL, *session, *key = NULL, *request, *token = NULL, *session_token; + zval *controller_name, *action_name, *params = NULL; + zval *disabled, *contents = NULL, *layouts_dir = NULL, *layout; + zval *layout_name = NULL, *engines, *pick_view, *render_view = NULL; + zval *pick_view_action, *cache = NULL, *cache_level; + zval *events_manager, *event_name = NULL, *status, *must_clean; + zval *silence = NULL, *disabled_levels, *render_level; + zval *templates_before, *template_before = NULL; + zval *view_temp_path = NULL, *templates_after, *template_after = NULL; + zval *main_view, *is_started, *is_fresh; + HashTable *ah0, *ah1; + HashPosition hp0, hp1; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &token_key, &token_value); - - if (!token_key) { - PHALCON_INIT_VAR(token_key); - } else { - PHALCON_SEPARATE_PARAM(token_key); - } + phalcon_fetch_params(1, 2, 1, &controller_name, &action_name, ¶ms); - if (!token_value) { - PHALCON_INIT_VAR(token_value); + if (!params) { + PHALCON_INIT_VAR(params); } - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); - return; + PHALCON_OBS_VAR(disabled); + phalcon_read_property_this_quick(&disabled, this_ptr, SL("_disabled"), 2601399228UL, PH_NOISY_CC); + if (PHALCON_IS_NOT_FALSE(disabled)) { + PHALCON_INIT_VAR(contents); + phalcon_ob_get_contents(contents TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_content"), contents, 4081318271UL TSRMLS_CC); + RETURN_MM_FALSE; } - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "session", 1); - - PHALCON_INIT_VAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); - if (Z_TYPE_P(token_key) == IS_NULL) { - PHALCON_INIT_VAR(key); - ZVAL_STRING(key, "$PHALCON/CSRF/KEY$", 1); + phalcon_update_property_this_quick(this_ptr, SL("_controllerName"), controller_name, 3332183433UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_actionName"), action_name, 2975797059UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_params"), params, 3223731112UL TSRMLS_CC); - PHALCON_INIT_NVAR(token_key); - phalcon_call_method_p1_key(token_key, session, "get", key, 2090288933UL); + PHALCON_OBS_VAR(layouts_dir); + phalcon_read_property_this_quick(&layouts_dir, this_ptr, SL("_layoutsDir"), 313056692UL, PH_NOISY_CC); + if (!zend_is_true(layouts_dir)) { + PHALCON_INIT_NVAR(layouts_dir); + ZVAL_STRING(layouts_dir, "layouts/", 1); } - if (Z_TYPE_P(token_value) == IS_NULL) { - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "request", 1); - - PHALCON_INIT_VAR(request); - phalcon_call_method_p1_key(request, dependency_injector, "getshared", service, 1727570332UL); - - PHALCON_INIT_VAR(token); - phalcon_call_method_p1_key(token, request, "getpost", token_key, 4289323083UL); + PHALCON_OBS_VAR(layout); + phalcon_read_property_this_quick(&layout, this_ptr, SL("_layout"), 2361639842UL, PH_NOISY_CC); + if (zend_is_true(layout)) { + PHALCON_CPY_WRT(layout_name, layout); } else { - PHALCON_CPY_WRT(token, token_value); + PHALCON_CPY_WRT(layout_name, controller_name); } - PHALCON_INIT_NVAR(key); - ZVAL_STRING(key, "$PHALCON/CSRF$", 1); + PHALCON_INIT_VAR(engines); + phalcon_call_method_key(engines, this_ptr, "_loadtemplateengines", 4149337481UL); - PHALCON_INIT_VAR(session_token); - phalcon_call_method_p1_key(session_token, session, "get", key, 2090288933UL); + PHALCON_OBS_VAR(pick_view); + phalcon_read_property_this_quick(&pick_view, this_ptr, SL("_pickView"), 1471709510UL, PH_NOISY_CC); + if (Z_TYPE_P(pick_view) == IS_NULL) { + PHALCON_INIT_VAR(render_view); + PHALCON_CONCAT_VSV(render_view, controller_name, "/", action_name); + } else { + PHALCON_OBS_NVAR(render_view); + phalcon_array_fetch_long(&render_view, pick_view, 0, PH_NOISY); + if (phalcon_array_isset_long(pick_view, 1)) { + PHALCON_OBS_VAR(pick_view_action); + phalcon_array_fetch_long(&pick_view_action, pick_view, 1, PH_NOISY); + PHALCON_CPY_WRT(layout_name, pick_view_action); + } + } - is_equal_function(return_value, token, session_token TSRMLS_CC); + PHALCON_INIT_VAR(cache); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Security, getSessionToken){ - - zval *dependency_injector, *service, *session; - zval *key, *session_token; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); - return; + PHALCON_OBS_VAR(cache_level); + phalcon_read_property_this_quick(&cache_level, this_ptr, SL("_cacheLevel"), 3155415824UL, PH_NOISY_CC); + if (zend_is_true(cache_level)) { + phalcon_call_method_key(cache, this_ptr, "getcache", 3582760537UL); } - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "session", 1); - - PHALCON_INIT_VAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - PHALCON_INIT_VAR(key); - ZVAL_STRING(key, "$PHALCON/CSRF$", 1); + phalcon_create_symbol_table(TSRMLS_C); - PHALCON_INIT_VAR(session_token); - phalcon_call_method_p1_key(session_token, session, "get", key, 2090288933UL); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - RETURN_CCTOR(session_token); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Filter){ - - PHALCON_REGISTER_CLASS(Phalcon, Filter, filter, phalcon_filter_method_entry, 0); - - zend_declare_property_null(phalcon_filter_ce, SL("_filters"), ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_filter_ce TSRMLS_CC, 1, phalcon_filterinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Filter, add){ - - zval *name, *handler; - - phalcon_fetch_params(0, 2, 0, &name, &handler); + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "view:beforeRender", 1); - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_filter_exception_ce, "Filter name must be string"); - return; - } - if (Z_TYPE_P(handler) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_filter_exception_ce, "Filter must be an object"); - return; + PHALCON_INIT_VAR(status); + phalcon_call_method_p2_key(status, events_manager, "fire", event_name, this_ptr, 259017035UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } } - phalcon_update_property_array(this_ptr, SL("_filters"), name, handler TSRMLS_CC); + PHALCON_INIT_NVAR(contents); + phalcon_ob_get_contents(contents TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_content"), contents, 4081318271UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Filter, sanitize){ - - zval *value, *filters, *new_value = NULL, *filter = NULL, *array_value = NULL; - zval *item_value = NULL, *item_key = NULL, *filter_value = NULL, *sanizited_value = NULL; - zval *key = NULL; - HashTable *ah0, *ah1, *ah2; - HashPosition hp0, hp1, hp2; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &value, &filters); + PHALCON_INIT_VAR(must_clean); + ZVAL_BOOL(must_clean, 1); - if (Z_TYPE_P(filters) == IS_ARRAY) { - PHALCON_CPY_WRT(new_value, value); - if (Z_TYPE_P(value) != IS_NULL) { + PHALCON_INIT_VAR(silence); + ZVAL_BOOL(silence, 1); - phalcon_is_iterable(filters, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(disabled_levels); + phalcon_read_property_this_quick(&disabled_levels, this_ptr, SL("_disabledLevels"), 1575004551UL, PH_NOISY_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_VAR(render_level); + phalcon_read_property_this_quick(&render_level, this_ptr, SL("_renderLevel"), 3194989084UL, PH_NOISY_CC); + if (zend_is_true(render_level)) { - PHALCON_GET_HVALUE(filter); + if (PHALCON_GE_LONG(render_level, 1)) { + if (!phalcon_array_isset_long(disabled_levels, 1)) { + phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, render_view, silence, must_clean, cache, 828860954UL); + } + } - if (Z_TYPE_P(new_value) == IS_ARRAY) { + if (PHALCON_GE_LONG(render_level, 2)) { + if (!phalcon_array_isset_long(disabled_levels, 2)) { - PHALCON_INIT_NVAR(array_value); - array_init(array_value); + PHALCON_OBS_VAR(templates_before); + phalcon_read_property_this_quick(&templates_before, this_ptr, SL("_templatesBefore"), 3273177030UL, PH_NOISY_CC); - phalcon_is_iterable(new_value, &ah1, &hp1, 0, 0); + if (Z_TYPE_P(templates_before) == IS_ARRAY) { - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + ZVAL_BOOL(silence, 0); - PHALCON_GET_HKEY(item_key, ah1, hp1); - PHALCON_GET_HVALUE(item_value); + phalcon_is_iterable(templates_before, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(filter_value); - phalcon_call_method_p2_key(filter_value, this_ptr, "_sanitize", item_value, filter, 2673127019UL); - phalcon_array_update_zval(&array_value, item_key, &filter_value, PH_COPY | PH_SEPARATE); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - zend_hash_move_forward_ex(ah1, &hp1); + PHALCON_GET_HVALUE(template_before); + + PHALCON_INIT_NVAR(view_temp_path); + PHALCON_CONCAT_VV(view_temp_path, layouts_dir, template_before); + phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache, 828860954UL); + + zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_CPY_WRT(new_value, array_value); - } else { - PHALCON_INIT_NVAR(filter_value); - phalcon_call_method_p2_key(filter_value, this_ptr, "_sanitize", new_value, filter, 2673127019UL); - PHALCON_CPY_WRT(new_value, filter_value); + PHALCON_INIT_NVAR(silence); + ZVAL_BOOL(silence, 1); } - - zend_hash_move_forward_ex(ah0, &hp0); } + } + if (PHALCON_GE_LONG(render_level, 3)) { + if (!phalcon_array_isset_long(disabled_levels, 3)) { + PHALCON_INIT_NVAR(view_temp_path); + PHALCON_CONCAT_VV(view_temp_path, layouts_dir, layout_name); + phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache, 828860954UL); + } } - RETURN_CCTOR(new_value); - } + if (PHALCON_GE_LONG(render_level, 4)) { + if (!phalcon_array_isset_long(disabled_levels, 4)) { - if (Z_TYPE_P(value) == IS_ARRAY) { + PHALCON_OBS_VAR(templates_after); + phalcon_read_property_this_quick(&templates_after, this_ptr, SL("_templatesAfter"), 3575793989UL, PH_NOISY_CC); + if (Z_TYPE_P(templates_after) == IS_ARRAY) { - PHALCON_INIT_VAR(sanizited_value); - array_init(sanizited_value); + PHALCON_INIT_NVAR(silence); + ZVAL_BOOL(silence, 0); - phalcon_is_iterable(value, &ah2, &hp2, 0, 0); + phalcon_is_iterable(templates_after, &ah1, &hp1, 0, 0); - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_GET_HKEY(key, ah2, hp2); - PHALCON_GET_HVALUE(item_value); + PHALCON_GET_HVALUE(template_after); - PHALCON_INIT_NVAR(filter_value); - phalcon_call_method_p2_key(filter_value, this_ptr, "_sanitize", item_value, filters, 2673127019UL); - phalcon_array_update_zval(&sanizited_value, key, &filter_value, PH_COPY | PH_SEPARATE); + PHALCON_INIT_NVAR(view_temp_path); + PHALCON_CONCAT_VV(view_temp_path, layouts_dir, template_after); + phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, view_temp_path, silence, must_clean, cache, 828860954UL); - zend_hash_move_forward_ex(ah2, &hp2); + zend_hash_move_forward_ex(ah1, &hp1); + } + + PHALCON_INIT_NVAR(silence); + ZVAL_BOOL(silence, 1); + } + } } - } else { - PHALCON_INIT_NVAR(sanizited_value); - phalcon_call_method_p2_key(sanizited_value, this_ptr, "_sanitize", value, filters, 2673127019UL); + if (PHALCON_GE_LONG(render_level, 5)) { + if (!phalcon_array_isset_long(disabled_levels, 5)) { + PHALCON_OBS_VAR(main_view); + phalcon_read_property_this_quick(&main_view, this_ptr, SL("_mainView"), 1829858724UL, PH_NOISY_CC); + phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, main_view, silence, must_clean, cache, 828860954UL); + } + } + + if (Z_TYPE_P(cache) == IS_OBJECT) { + + PHALCON_INIT_VAR(is_started); + phalcon_call_method_key(is_started, cache, "isstarted", 527759032UL); + if (PHALCON_IS_TRUE(is_started)) { + + PHALCON_INIT_VAR(is_fresh); + phalcon_call_method_key(is_fresh, cache, "isfresh", 3981662073UL); + if (PHALCON_IS_TRUE(is_fresh)) { + phalcon_call_method_key(NULL, cache, "save", 274150868UL); + } else { + phalcon_call_method_key(NULL, cache, "stop", 274826411UL); + } + } else { + phalcon_call_method_key(NULL, cache, "stop", 274826411UL); + } + } } - RETURN_CCTOR(sanizited_value); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "view:afterRender", 1); + phalcon_call_method_p2_key(NULL, events_manager, "fire", event_name, this_ptr, 259017035UL); + } + + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Filter, _sanitize){ +static PHP_METHOD(Phalcon_Mvc_View, pick){ - zval *value, *filter, *filters, *filter_object; - zval *arguments, *type = NULL, *quote, *empty_str, *escaped; - zval *filtered = NULL, *allow_fraction, *options, *exception_message; + zval *render_view, *pick_view = NULL, *layout = NULL, *parts; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &value, &filter); - - PHALCON_OBS_VAR(filters); - phalcon_read_property_this_quick(&filters, this_ptr, SL("_filters"), 3850488637UL, PH_NOISY_CC); - if (phalcon_array_isset(filters, filter)) { + phalcon_fetch_params(1, 1, 0, &render_view); - PHALCON_OBS_VAR(filter_object); - phalcon_array_fetch(&filter_object, filters, filter, PH_NOISY); + if (Z_TYPE_P(render_view) == IS_ARRAY) { + PHALCON_CPY_WRT(pick_view, render_view); + } else { + PHALCON_INIT_VAR(layout); + if (phalcon_memnstr_str(render_view, SL("/"))) { + PHALCON_INIT_VAR(parts); + phalcon_fast_explode_str(parts, SL("/"), render_view); - if (phalcon_is_instance_of(filter_object, SL("Closure") TSRMLS_CC)) { - PHALCON_INIT_VAR(arguments); - array_init_size(arguments, 1); - phalcon_array_append(&arguments, value, PH_SEPARATE); - PHALCON_CALL_USER_FUNC_ARRAY(return_value, filter_object, arguments); - RETURN_MM(); + PHALCON_OBS_NVAR(layout); + phalcon_array_fetch_long(&layout, parts, 0, PH_NOISY); } - phalcon_call_method_p1_key(return_value, filter_object, "filter", value, 2890214155UL); - RETURN_MM(); + PHALCON_INIT_NVAR(pick_view); + array_init_size(pick_view, 1); + phalcon_array_append(&pick_view, render_view, PH_SEPARATE); + if (Z_TYPE_P(layout) != IS_NULL) { + phalcon_array_append(&pick_view, layout, PH_SEPARATE); + } } + phalcon_update_property_this_quick(this_ptr, SL("_pickView"), pick_view, 1471709510UL TSRMLS_CC); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_View, partial){ + + zval *partial_path, *params = NULL, *view_params, *new_params = NULL; + zval *zfalse, *partials_dir, *real_path, *engines; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &partial_path, ¶ms); - if (PHALCON_IS_STRING(filter, "email")) { - PHALCON_INIT_VAR(type); - ZVAL_LONG(type, 517); - - PHALCON_INIT_VAR(quote); - ZVAL_STRING(quote, "'", 1); + if (!params) { + PHALCON_INIT_VAR(params); + } - PHALCON_INIT_VAR(empty_str); - ZVAL_STRING(empty_str, "", 1); + if (Z_TYPE_P(params) == IS_ARRAY) { - PHALCON_INIT_VAR(escaped); - phalcon_fast_str_replace(escaped, quote, empty_str, value); + PHALCON_OBS_VAR(view_params); + phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); - PHALCON_INIT_VAR(filtered); - phalcon_call_func_p2(filtered, "filter_var", escaped, type); - goto ph_end_0; - } + if (Z_TYPE_P(view_params) == IS_ARRAY) { + PHALCON_INIT_VAR(new_params); + phalcon_fast_array_merge(new_params, &view_params, ¶ms TSRMLS_CC); + } else { + PHALCON_CPY_WRT(new_params, params); + } - if (PHALCON_IS_STRING(filter, "int")) { - PHALCON_INIT_NVAR(type); - ZVAL_LONG(type, 519); + phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), new_params, 1685283331UL TSRMLS_CC); + + phalcon_create_symbol_table(TSRMLS_C); - PHALCON_INIT_NVAR(filtered); - phalcon_call_func_p2(filtered, "filter_var", value, type); - goto ph_end_0; } - if (PHALCON_IS_STRING(filter, "string")) { - PHALCON_INIT_NVAR(type); - ZVAL_LONG(type, 513); + PHALCON_INIT_VAR(zfalse); + ZVAL_BOOL(zfalse, 0); - PHALCON_INIT_NVAR(filtered); - phalcon_call_func_p2(filtered, "filter_var", value, type); - goto ph_end_0; - } + PHALCON_OBS_VAR(partials_dir); + phalcon_read_property_this_quick(&partials_dir, this_ptr, SL("_partialsDir"), 2130168739UL, PH_NOISY_CC); - if (PHALCON_IS_STRING(filter, "float")) { - PHALCON_INIT_VAR(allow_fraction); - ZVAL_LONG(allow_fraction, 4096); + PHALCON_INIT_VAR(real_path); + PHALCON_CONCAT_VV(real_path, partials_dir, partial_path); - PHALCON_INIT_VAR(options); - array_init_size(options, 1); - phalcon_array_update_quick_string(&options, SS("flags"), 4255547666UL, &allow_fraction, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(engines); + phalcon_call_method_key(engines, this_ptr, "_loadtemplateengines", 4149337481UL); - PHALCON_INIT_NVAR(type); - ZVAL_LONG(type, 520); + phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, real_path, zfalse, zfalse, zfalse, 828860954UL); - PHALCON_INIT_NVAR(filtered); - phalcon_call_func_p3(filtered, "filter_var", value, type, options); - goto ph_end_0; + if (Z_TYPE_P(params) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), view_params, 1685283331UL TSRMLS_CC); } - if (PHALCON_IS_STRING(filter, "alphanum")) { - PHALCON_INIT_NVAR(filtered); - phalcon_filter_alphanum(filtered, value); - goto ph_end_0; + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_View, getRender){ + + zval *controller_name, *action_name, *params = NULL; + zval *config_callback = NULL, *view, *status, *content; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 2, &controller_name, &action_name, ¶ms, &config_callback); + + if (!params) { + PHALCON_INIT_VAR(params); + } else { + PHALCON_SEPARATE_PARAM(params); } - if (PHALCON_IS_STRING(filter, "trim")) { - PHALCON_INIT_NVAR(filtered); - phalcon_fast_trim(filtered, value, PHALCON_TRIM_BOTH TSRMLS_CC); - goto ph_end_0; + if (!config_callback) { + PHALCON_INIT_VAR(config_callback); } - if (PHALCON_IS_STRING(filter, "striptags")) { - PHALCON_INIT_NVAR(filtered); - phalcon_fast_strip_tags(filtered, value); - goto ph_end_0; + PHALCON_INIT_VAR(view); + if (phalcon_clone(view, this_ptr TSRMLS_CC) == FAILURE) { + return; } - if (PHALCON_IS_STRING(filter, "lower")) { - if (phalcon_function_quick_exists_ex(SS("mb_strtolower"), 3802586680UL TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_NVAR(filtered); - phalcon_call_func_p1(filtered, "mb_strtolower", value); - } else { - PHALCON_INIT_NVAR(filtered); - phalcon_fast_strtolower(filtered, value); - } - goto ph_end_0; + phalcon_call_method_key(NULL, view, "reset", 422548360UL); + + if (Z_TYPE_P(params) == IS_ARRAY) { + phalcon_call_method_p1_key(NULL, view, "setvars", params, 321174573UL); } - if (PHALCON_IS_STRING(filter, "upper")) { - if (phalcon_function_quick_exists_ex(SS("mb_strtoupper"), 4155739579UL TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_NVAR(filtered); - phalcon_call_func_p1(filtered, "mb_strtoupper", value); - } else { - PHALCON_INIT_NVAR(filtered); - phalcon_fast_strtoupper(filtered, value); - } - goto ph_end_0; + if (Z_TYPE_P(config_callback) == IS_OBJECT) { + PHALCON_INIT_NVAR(params); + array_init_size(params, 1); + phalcon_array_append(¶ms, view, PH_SEPARATE); + + PHALCON_INIT_VAR(status); + PHALCON_CALL_USER_FUNC_ARRAY(status, config_callback, params); } - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Sanitize filter ", filter, " is not supported"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_filter_exception_ce, exception_message); - return; + phalcon_call_method_key(NULL, view, "start", 478839859UL); - ph_end_0: + phalcon_call_method_p2_key(NULL, view, "render", controller_name, action_name, 1053215877UL); - RETURN_CCTOR(filtered); -} - -static PHP_METHOD(Phalcon_Filter, getFilters){ - - - RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL); + phalcon_ob_end_clean(TSRMLS_C); + + PHALCON_INIT_VAR(content); + phalcon_call_method_key(content, view, "getcontent", 3141446400UL); + + RETURN_CCTOR(content); } +static PHP_METHOD(Phalcon_Mvc_View, finish){ + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Escaper_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Escaper, Exception, escaper_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; + phalcon_ob_end_clean(TSRMLS_C); + RETURN_THIS(); } +static PHP_METHOD(Phalcon_Mvc_View, _createCache){ + zval *dependency_injector, *cache_service = NULL; + zval *view_options, *cache_options, *view_cache; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Acl){ - - PHALCON_REGISTER_CLASS(Phalcon, Acl, acl, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - zend_declare_class_constant_long(phalcon_acl_ce, SL("ALLOW"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_acl_ce, SL("DENY"), 0 TSRMLS_CC); - - return SUCCESS; + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "A dependency injector container is required to obtain the view cache services"); + return; + } + + PHALCON_INIT_VAR(cache_service); + ZVAL_STRING(cache_service, "viewCache", 1); + + PHALCON_OBS_VAR(view_options); + phalcon_read_property_this_quick(&view_options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (Z_TYPE_P(view_options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(view_options, SS("cache"), 4125168857UL)) { + + PHALCON_OBS_VAR(cache_options); + phalcon_array_fetch_quick_string(&cache_options, view_options, SS("cache"), 4125168857UL, PH_NOISY); + if (Z_TYPE_P(cache_options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(cache_options, SS("service"), 243174486UL)) { + PHALCON_OBS_NVAR(cache_service); + phalcon_array_fetch_quick_string(&cache_service, cache_options, SS("service"), 243174486UL, PH_NOISY); + } + } + } + } + + PHALCON_INIT_VAR(view_cache); + phalcon_call_method_p1_key(view_cache, dependency_injector, "getshared", cache_service, 1727570332UL); + if (Z_TYPE_P(view_cache) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The injected caching service is invalid"); + return; + } + + RETURN_CCTOR(view_cache); } +static PHP_METHOD(Phalcon_Mvc_View, isCaching){ + zval *zero, *cache_level; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_DI){ - - PHALCON_REGISTER_CLASS(Phalcon, DI, di, phalcon_di_method_entry, 0); - - zend_declare_property_null(phalcon_di_ce, SL("_services"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_di_ce, SL("_sharedInstances"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_di_ce, SL("_freshInstance"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_di_ce, SL("_default"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - - zend_class_implements(phalcon_di_ce TSRMLS_CC, 1, phalcon_diinterface_ce); - - return SUCCESS; + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + + PHALCON_OBS_VAR(cache_level); + phalcon_read_property_this_quick(&cache_level, this_ptr, SL("_cacheLevel"), 3155415824UL, PH_NOISY_CC); + is_smaller_function(return_value, zero, cache_level TSRMLS_CC); + RETURN_MM(); } -static PHP_METHOD(Phalcon_DI, __construct){ +static PHP_METHOD(Phalcon_Mvc_View, getCache){ - zval *default_di; + zval *cache = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(default_di); - phalcon_read_static_property(&default_di, SL("phalcon\\di"), SL("_default") TSRMLS_CC); - if (!zend_is_true(default_di)) { - phalcon_update_static_property(SL("phalcon\\di"), SL("_default"), this_ptr TSRMLS_CC); + PHALCON_OBS_VAR(cache); + phalcon_read_property_this_quick(&cache, this_ptr, SL("_cache"), 2191407384UL, PH_NOISY_CC); + if (zend_is_true(cache)) { + if (Z_TYPE_P(cache) != IS_OBJECT) { + PHALCON_INIT_NVAR(cache); + phalcon_call_method_key(cache, this_ptr, "_createcache", 1216889100UL); + phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); + } + } else { + PHALCON_INIT_NVAR(cache); + phalcon_call_method_key(cache, this_ptr, "_createcache", 1216889100UL); + phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); } - PHALCON_MM_RESTORE(); + RETURN_CCTOR(cache); } -static PHP_METHOD(Phalcon_DI, set){ +static PHP_METHOD(Phalcon_Mvc_View, cache){ - zval *name, *definition, *shared = NULL, *service; + zval *options = NULL, *view_options = NULL, *cache_options = NULL; + zval *value = NULL, *key = NULL, *cache_level; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &name, &definition, &shared); + phalcon_fetch_params(1, 0, 1, &options); - if (!shared) { - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 0); + if (!options) { + PHALCON_INIT_VAR(options); + ZVAL_BOOL(options, 1); } - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service name must be a string"); - return; - } + if (Z_TYPE_P(options) == IS_ARRAY) { - PHALCON_INIT_VAR(service); - object_init_ex(service, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, service, "__construct", name, definition, shared, 1107214344UL); + PHALCON_OBS_VAR(view_options); + phalcon_read_property_this_quick(&view_options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + if (Z_TYPE_P(view_options) != IS_ARRAY) { + PHALCON_INIT_NVAR(view_options); + array_init(view_options); + } - phalcon_update_property_array(this_ptr, SL("_services"), name, service TSRMLS_CC); + if (phalcon_array_isset_quick_string(view_options, SS("cache"), 4125168857UL)) { + PHALCON_OBS_VAR(cache_options); + phalcon_array_fetch_quick_string(&cache_options, view_options, SS("cache"), 4125168857UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(cache_options); + array_init(cache_options); + } - RETURN_CTOR(service); -} - -static PHP_METHOD(Phalcon_DI, setShared){ - - zval *name, *definition, *shared, *service; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &name, &definition); + phalcon_is_iterable(options, &ah0, &hp0, 0, 0); - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service name must be a string"); - return; - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 1); + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - PHALCON_INIT_VAR(service); - object_init_ex(service, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, service, "__construct", name, definition, shared, 1107214344UL); + phalcon_array_update_zval(&cache_options, key, &value, PH_COPY | PH_SEPARATE); - phalcon_update_property_array(this_ptr, SL("_services"), name, service TSRMLS_CC); + zend_hash_move_forward_ex(ah0, &hp0); + } - RETURN_CTOR(service); -} - -static PHP_METHOD(Phalcon_DI, remove){ - - zval *name; - - phalcon_fetch_params(0, 1, 0, &name); + if (phalcon_array_isset_quick_string(cache_options, SS("level"), 187843549UL)) { + PHALCON_OBS_VAR(cache_level); + phalcon_array_fetch_quick_string(&cache_level, cache_options, SS("level"), 187843549UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_cacheLevel"), cache_level, 3155415824UL TSRMLS_CC); + } else { + phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 5 TSRMLS_CC); + } - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "The service name must be a string"); - return; + phalcon_array_update_quick_string(&view_options, SS("cache"), 4125168857UL, &cache_options, PH_COPY | PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_options"), view_options, 1620153008UL TSRMLS_CC); + } else { + if (zend_is_true(options)) { + phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 5 TSRMLS_CC); + } else { + phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 0 TSRMLS_CC); + } } - phalcon_unset_property_array(this_ptr, SL("_services"), name TSRMLS_CC); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_DI, attempt){ - - zval *name, *definition, *shared = NULL, *services, *service; +static PHP_METHOD(Phalcon_Mvc_View, setContent){ - PHALCON_MM_GROW(); + zval *content; - phalcon_fetch_params(1, 2, 1, &name, &definition, &shared); - - if (!shared) { - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 0); - } + phalcon_fetch_params(0, 1, 0, &content); - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service name must be a string"); + if (Z_TYPE_P(content) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Content must be a string"); return; } + phalcon_update_property_this_quick(this_ptr, SL("_content"), content, 4081318271UL TSRMLS_CC); - PHALCON_OBS_VAR(services); - phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); - if (!phalcon_array_isset(services, name)) { - PHALCON_INIT_VAR(service); - object_init_ex(service, phalcon_di_service_ce); - phalcon_call_method_p3_key(NULL, service, "__construct", name, definition, shared, 1107214344UL); - - phalcon_update_property_array(this_ptr, SL("_services"), name, service TSRMLS_CC); - RETURN_CTOR(service); - } - - RETURN_MM_NULL(); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_DI, setRaw){ +static PHP_METHOD(Phalcon_Mvc_View, getContent){ - zval *name, *raw_definition; - phalcon_fetch_params(0, 2, 0, &name, &raw_definition); - - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "The service name must be a string"); - return; - } - if (Z_TYPE_P(raw_definition) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_di_exception_ce, "The service definition must be an object"); - return; - } - - phalcon_update_property_array(this_ptr, SL("_services"), name, raw_definition TSRMLS_CC); - - RETURN_CCTORW(raw_definition); + RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); } -static PHP_METHOD(Phalcon_DI, getRaw){ - - zval *name, *services, *service, *exception_message; +static PHP_METHOD(Phalcon_Mvc_View, getActiveRenderPath){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); - - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service name must be a string"); - return; - } - - PHALCON_OBS_VAR(services); - phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); - if (phalcon_array_isset(services, name)) { - PHALCON_OBS_VAR(service); - phalcon_array_fetch(&service, services, name, PH_NOISY); - phalcon_call_method_key(return_value, service, "getdefinition", 1943795982UL); - RETURN_MM(); - } - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Service '", name, "' wasn't found in the dependency injection container"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; + RETURN_MEMBER_QUICK(this_ptr, "_activeRenderPath", 1528023309UL); } -static PHP_METHOD(Phalcon_DI, getService){ +static PHP_METHOD(Phalcon_Mvc_View, disable){ - zval *name, *services, *service, *exception_message; - PHALCON_MM_GROW(); + phalcon_update_property_bool(this_ptr, SL("_disabled"), 1 TSRMLS_CC); + RETURN_THISW(); +} - phalcon_fetch_params(1, 1, 0, &name); - - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service name must be a string"); - return; - } - - PHALCON_OBS_VAR(services); - phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); - if (phalcon_array_isset(services, name)) { - PHALCON_OBS_VAR(service); - phalcon_array_fetch(&service, services, name, PH_NOISY); - RETURN_CCTOR(service); - } - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Service '", name, "' wasn't found in the dependency injection container"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; +static PHP_METHOD(Phalcon_Mvc_View, enable){ + + + phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_DI, get){ +static PHP_METHOD(Phalcon_Mvc_View, reset){ - zval *name, *parameters = NULL, *services, *service, *instance = NULL; - zval *exception_message; + zval *znull; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service alias must be a string"); - return; - } - - PHALCON_OBS_VAR(services); - phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); - if (phalcon_array_isset(services, name)) { - PHALCON_OBS_VAR(service); - phalcon_array_fetch(&service, services, name, PH_NOISY); - - PHALCON_INIT_VAR(instance); - phalcon_call_method_p2_key(instance, service, "resolve", parameters, this_ptr, 605366917UL); - } else { - if (phalcon_class_exists(name, 1 TSRMLS_CC)) { - if (Z_TYPE_P(parameters) == IS_ARRAY) { - if (phalcon_fast_count_ev(parameters TSRMLS_CC)) { - PHALCON_INIT_NVAR(instance); - if (phalcon_create_instance_params(instance, name, parameters TSRMLS_CC) == FAILURE) { - return; - } - } else { - PHALCON_INIT_NVAR(instance); - if (phalcon_create_instance(instance, name TSRMLS_CC) == FAILURE) { - return; - } - } - } else { - PHALCON_INIT_NVAR(instance); - if (phalcon_create_instance(instance, name TSRMLS_CC) == FAILURE) { - return; - } - } - } else { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Service '", name, "' wasn't found in the dependency injection container"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; - } - } - - if (Z_TYPE_P(instance) == IS_OBJECT) { - if (phalcon_method_quick_exists_ex(instance, SS("setdi"), 461718238UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_p1_key(NULL, instance, "setdi", this_ptr, 461718238UL); - } - } - - RETURN_CCTOR(instance); + PHALCON_INIT_VAR(znull); + phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_engines"), 0 TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_cache"), znull, 2191407384UL TSRMLS_CC); + phalcon_update_property_long(this_ptr, SL("_renderLevel"), 5 TSRMLS_CC); + phalcon_update_property_long(this_ptr, SL("_cacheLevel"), 0 TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_content"), znull, 4081318271UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_templatesBefore"), znull, 3273177030UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_templatesAfter"), znull, 3575793989UL TSRMLS_CC); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_DI, getShared){ - - zval *name, *parameters = NULL, *shared_instances, *instance = NULL; +static PHP_METHOD(Phalcon_Mvc_View, __set){ - PHALCON_MM_GROW(); + zval *key, *value; - phalcon_fetch_params(1, 1, 1, &name, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service alias must be a string"); - return; - } - - PHALCON_OBS_VAR(shared_instances); - phalcon_read_property_this_quick(&shared_instances, this_ptr, SL("_sharedInstances"), 479369827UL, PH_NOISY_CC); - if (phalcon_array_isset(shared_instances, name)) { - PHALCON_OBS_VAR(instance); - phalcon_array_fetch(&instance, shared_instances, name, PH_NOISY); - phalcon_update_property_bool(this_ptr, SL("_freshInstance"), 0 TSRMLS_CC); - } else { - PHALCON_INIT_NVAR(instance); - phalcon_call_method_p2_key(instance, this_ptr, "get", name, parameters, 2090288933UL); + phalcon_fetch_params(0, 2, 0, &key, &value); - phalcon_update_property_array(this_ptr, SL("_sharedInstances"), name, instance TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_freshInstance"), 1 TSRMLS_CC); - } + phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); - RETURN_CCTOR(instance); } -static PHP_METHOD(Phalcon_DI, has){ +static PHP_METHOD(Phalcon_Mvc_View, __get){ - zval *name, *services, *is_set_service = NULL; - zval *r0 = NULL; + zval *key, *params, *value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); + phalcon_fetch_params(1, 1, 0, &key); - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service alias must be a string"); - return; + PHALCON_OBS_VAR(params); + phalcon_read_property_this_quick(¶ms, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); + if (phalcon_array_isset(params, key)) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, params, key, PH_NOISY); + RETURN_CCTOR(value); } - PHALCON_OBS_VAR(services); - phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(r0); - ZVAL_BOOL(r0, phalcon_array_isset(services, name)); - PHALCON_CPY_WRT(is_set_service, r0); - - RETURN_NCTOR(is_set_service); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_DI, wasFreshInstance){ - RETURN_MEMBER_QUICK(this_ptr, "_freshInstance", 1734543825UL); -} -static PHP_METHOD(Phalcon_DI, getServices){ +#ifdef HAVE_CONFIG_H +#endif - RETURN_MEMBER_QUICK(this_ptr, "_services", 2714588616UL); -} +PHALCON_INIT_CLASS(Phalcon_Mvc_ViewInterface){ + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ViewInterface, mvc_viewinterface, phalcon_mvc_viewinterface_method_entry); + return SUCCESS; +} -static PHP_METHOD(Phalcon_DI, __call){ - zval *method, *arguments = NULL, *services, *service_name = NULL; - zval *possible_service = NULL, *handler, *exception_message; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &method, &arguments); - - if (!arguments) { - PHALCON_INIT_VAR(arguments); - } - - if (phalcon_start_with_str(method, SL("get"))) { - - PHALCON_OBS_VAR(services); - phalcon_read_property_this_quick(&services, this_ptr, SL("_services"), 2714588616UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(service_name); - phalcon_substr(service_name, method, 3, 0); - - PHALCON_INIT_VAR(possible_service); - phalcon_lcfirst(possible_service, service_name); - if (phalcon_array_isset(services, possible_service)) { - if (phalcon_fast_count_ev(arguments TSRMLS_CC)) { - phalcon_call_method_p2_key(return_value, this_ptr, "get", possible_service, arguments, 2090288933UL); - RETURN_MM(); - } - phalcon_call_method_p1_key(return_value, this_ptr, "get", possible_service, 2090288933UL); - RETURN_MM(); - } - } - - if (phalcon_start_with_str(method, SL("set"))) { - if (phalcon_array_isset_long(arguments, 0)) { - PHALCON_INIT_NVAR(service_name); - phalcon_substr(service_name, method, 3, 0); - - PHALCON_INIT_NVAR(possible_service); - phalcon_lcfirst(possible_service, service_name); - - PHALCON_OBS_VAR(handler); - phalcon_array_fetch_long(&handler, arguments, 0, PH_NOISY); - phalcon_call_method_p2_key(NULL, this_ptr, "set", possible_service, handler, 2090720177UL); - RETURN_MM_NULL(); - } - } - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Call to undefined method or service '", method, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_di_exception_ce, exception_message); - return; -} -static PHP_METHOD(Phalcon_DI, setDefault){ - zval *dependency_injector; - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - phalcon_update_static_property(SL("phalcon\\di"), SL("_default"), dependency_injector TSRMLS_CC); - -} -static PHP_METHOD(Phalcon_DI, getDefault){ - zval *default_di; - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(default_di); - phalcon_read_static_property(&default_di, SL("phalcon\\di"), SL("_default") TSRMLS_CC); - RETURN_CCTOR(default_di); -} -static PHP_METHOD(Phalcon_DI, reset){ - zval *null_value; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(null_value); - phalcon_update_static_property(SL("phalcon\\di"), SL("_default"), null_value TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} -#ifdef HAVE_CONFIG_H -#endif -PHALCON_INIT_CLASS(Phalcon_Session_AdapterInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Session, AdapterInterface, session_adapterinterface, phalcon_session_adapterinterface_method_entry); - return SUCCESS; -} @@ -93520,189 +93860,353 @@ PHALCON_INIT_CLASS(Phalcon_Session_AdapterInterface){ +PHALCON_INIT_CLASS(Phalcon_Paginator_Adapter_Model){ -PHALCON_INIT_CLASS(Phalcon_Session_Adapter){ + PHALCON_REGISTER_CLASS(Phalcon\\Paginator\\Adapter, Model, paginator_adapter_model, phalcon_paginator_adapter_model_method_entry, 0); - PHALCON_REGISTER_CLASS(Phalcon\\Session, Adapter, session_adapter, phalcon_session_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + zend_declare_property_null(phalcon_paginator_adapter_model_ce, SL("_limitRows"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_paginator_adapter_model_ce, SL("_config"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_paginator_adapter_model_ce, SL("_page"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_session_adapter_ce, SL("_uniqueId"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_session_adapter_ce, SL("_started"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_session_adapter_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_class_implements(phalcon_paginator_adapter_model_ce TSRMLS_CC, 1, phalcon_paginator_adapterinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Session_Adapter, __construct){ +static PHP_METHOD(Phalcon_Paginator_Adapter_Model, __construct){ - zval *options = NULL; + zval *config, *limit, *page; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &options); + phalcon_fetch_params(1, 1, 0, &config); - if (!options) { - PHALCON_INIT_VAR(options); + phalcon_update_property_this_quick(this_ptr, SL("_config"), config, 4157843450UL TSRMLS_CC); + if (phalcon_array_isset_quick_string(config, SS("limit"), 192268420UL)) { + PHALCON_OBS_VAR(limit); + phalcon_array_fetch_quick_string(&limit, config, SS("limit"), 192268420UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_limitRows"), limit, 597448366UL TSRMLS_CC); } - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_call_method_p1_key(NULL, this_ptr, "setoptions", options, 1759822653UL); + if (phalcon_array_isset_quick_string(config, SS("page"), 270576770UL)) { + PHALCON_OBS_VAR(page); + phalcon_array_fetch_quick_string(&page, config, SS("page"), 270576770UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_page"), page, 3986343137UL TSRMLS_CC); } PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Session_Adapter, start){ +static PHP_METHOD(Phalcon_Paginator_Adapter_Model, setCurrentPage){ - if (!SG(headers_sent)) { - phalcon_session_start(TSRMLS_C); - phalcon_update_property_bool(this_ptr, SL("_started"), 1 TSRMLS_CC); - RETURN_TRUE; - } + zval *page; + + phalcon_fetch_params(0, 1, 0, &page); + + phalcon_update_property_this_quick(this_ptr, SL("_page"), page, 3986343137UL TSRMLS_CC); - RETURN_FALSE; } -static PHP_METHOD(Phalcon_Session_Adapter, setOptions){ +static PHP_METHOD(Phalcon_Paginator_Adapter_Model, getPaginate){ - zval *options, *unique_id; + zval *one, *zero, *show, *config, *items, *page_number = NULL; + zval *n, *page, *last_show_page, *start, *last_page; + zval *possible_pages = NULL, *total_pages, *page_items; + zval *i, *valid = NULL, *current = NULL, *maximum_pages, *next = NULL, *additional_page; + zval *before = NULL, *remainder, *pages_total = NULL; + zval *r0 = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &options); + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_session_exception_ce, "Options must be an Array"); + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + + PHALCON_OBS_VAR(show); + phalcon_read_property_this_quick(&show, this_ptr, SL("_limitRows"), 597448366UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(config); + phalcon_read_property_this_quick(&config, this_ptr, SL("_config"), 4157843450UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(items); + phalcon_array_fetch_quick_string(&items, config, SS("data"), 256359743UL, PH_NOISY); + + PHALCON_OBS_VAR(page_number); + phalcon_read_property_this_quick(&page_number, this_ptr, SL("_page"), 3986343137UL, PH_NOISY_CC); + if (Z_TYPE_P(page_number) == IS_NULL) { + PHALCON_CPY_WRT(page_number, one); + } + + if (PHALCON_LT(show, zero)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "The start page number is zero or less"); return; } - if (phalcon_array_isset_quick_string(options, SS("uniqueId"), 1442667433UL)) { - PHALCON_OBS_VAR(unique_id); - phalcon_array_fetch_quick_string(&unique_id, options, SS("uniqueId"), 1442667433UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_uniqueId"), unique_id, 427461512UL TSRMLS_CC); + + PHALCON_INIT_VAR(n); + phalcon_fast_count(n, items TSRMLS_CC); + + PHALCON_INIT_VAR(page); + object_init(page); + + PHALCON_INIT_VAR(last_show_page); + sub_function(last_show_page, page_number, one TSRMLS_CC); + + PHALCON_INIT_VAR(start); + mul_function(start, show, last_show_page TSRMLS_CC); + + PHALCON_INIT_VAR(last_page); + sub_function(last_page, n, one TSRMLS_CC); + + PHALCON_INIT_VAR(possible_pages); + div_function(possible_pages, last_page, show TSRMLS_CC); + + PHALCON_INIT_VAR(total_pages); + phalcon_call_func_p1(total_pages, "ceil", possible_pages); + if (Z_TYPE_P(items) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "Invalid data for paginator"); + return; } - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + if (!zend_is_true(page_number)) { + PHALCON_CPY_WRT(page_number, one); + } - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(page_items); + array_init(page_items); + if (PHALCON_GT(n, zero)) { + + if (PHALCON_LE(start, n)) { + phalcon_call_method_p1_key(NULL, items, "seek", start, 274276301UL); + } else { + phalcon_call_method_p1_key(NULL, items, "seek", one, 274276301UL); + PHALCON_CPY_WRT(page_number, one); + } + + PHALCON_INIT_VAR(i); + ZVAL_LONG(i, 1); + + while (1) { + + PHALCON_INIT_NVAR(r0); + phalcon_call_method_key(r0, items, "valid", 574098517UL); + PHALCON_CPY_WRT(valid, r0); + if (PHALCON_IS_NOT_FALSE(valid)) { + } else { + break; + } + + PHALCON_INIT_NVAR(current); + phalcon_call_method_key(current, items, "current", 431662984UL); + phalcon_array_append(&page_items, current, PH_SEPARATE); + if (PHALCON_GE(i, show)) { + break; + } + + PHALCON_SEPARATE(i); + phalcon_increment(i); + } + } + + phalcon_update_property_zval(page, SL("items"), page_items TSRMLS_CC); + + PHALCON_INIT_VAR(maximum_pages); + phalcon_add_function(maximum_pages, start, show TSRMLS_CC); + if (PHALCON_LT(maximum_pages, n)) { + PHALCON_INIT_VAR(next); + phalcon_add_function(next, page_number, one TSRMLS_CC); + } else { + if (PHALCON_IS_EQUAL(maximum_pages, n)) { + PHALCON_CPY_WRT(next, n); + } else { + div_function(possible_pages, n, show TSRMLS_CC); + + PHALCON_INIT_VAR(additional_page); + phalcon_add_function(additional_page, possible_pages, one TSRMLS_CC); + + PHALCON_INIT_NVAR(next); + ZVAL_LONG(next, phalcon_get_intval(additional_page)); + } + } + + if (PHALCON_GT(next, total_pages)) { + PHALCON_CPY_WRT(next, total_pages); + } + + phalcon_update_property_zval(page, SL("next"), next TSRMLS_CC); + if (PHALCON_GT(page_number, one)) { + PHALCON_INIT_VAR(before); + sub_function(before, page_number, one TSRMLS_CC); + } else { + PHALCON_CPY_WRT(before, one); + } + + phalcon_update_property_zval(page, SL("first"), one TSRMLS_CC); + phalcon_update_property_zval(page, SL("before"), before TSRMLS_CC); + phalcon_update_property_zval(page, SL("current"), page_number TSRMLS_CC); + + PHALCON_INIT_VAR(remainder); + mod_function(remainder, n, show TSRMLS_CC); + + PHALCON_INIT_NVAR(possible_pages); + div_function(possible_pages, n, show TSRMLS_CC); + if (!PHALCON_IS_LONG(remainder, 0)) { + PHALCON_INIT_NVAR(next); + phalcon_add_function(next, possible_pages, one TSRMLS_CC); + + PHALCON_INIT_VAR(pages_total); + ZVAL_LONG(pages_total, phalcon_get_intval(next)); + } else { + PHALCON_CPY_WRT(pages_total, possible_pages); + } + + phalcon_update_property_zval(page, SL("last"), pages_total TSRMLS_CC); + phalcon_update_property_zval(page, SL("total_pages"), pages_total TSRMLS_CC); + phalcon_update_property_zval(page, SL("total_items"), n TSRMLS_CC); + + RETURN_CTOR(page); } -static PHP_METHOD(Phalcon_Session_Adapter, getOptions){ - zval *options; - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - RETURN_CCTOR(options); + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Paginator_Adapter_NativeArray){ + + PHALCON_REGISTER_CLASS(Phalcon\\Paginator\\Adapter, NativeArray, paginator_adapter_nativearray, phalcon_paginator_adapter_nativearray_method_entry, 0); + + zend_declare_property_null(phalcon_paginator_adapter_nativearray_ce, SL("_limitRows"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_paginator_adapter_nativearray_ce, SL("_config"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_paginator_adapter_nativearray_ce, SL("_page"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_paginator_adapter_nativearray_ce TSRMLS_CC, 1, phalcon_paginator_adapterinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Session_Adapter, get){ +static PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, __construct){ - zval *index, *default_value = NULL, *unique_id, *key, *_SESSION; - zval *value; + zval *config, *limit, *page; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &index, &default_value); + phalcon_fetch_params(1, 1, 0, &config); - if (!default_value) { - PHALCON_INIT_VAR(default_value); + phalcon_update_property_this_quick(this_ptr, SL("_config"), config, 4157843450UL TSRMLS_CC); + if (phalcon_array_isset_quick_string(config, SS("limit"), 192268420UL)) { + PHALCON_OBS_VAR(limit); + phalcon_array_fetch_quick_string(&limit, config, SS("limit"), 192268420UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_limitRows"), limit, 597448366UL TSRMLS_CC); } - PHALCON_OBS_VAR(unique_id); - phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(key); - PHALCON_CONCAT_VV(key, unique_id, index); - phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); - if (phalcon_array_isset(_SESSION, key)) { - - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, _SESSION, key, PH_NOISY); - if (PHALCON_IS_NOT_EMPTY(value)) { - RETURN_CCTOR(value); - } + if (phalcon_array_isset_quick_string(config, SS("page"), 270576770UL)) { + PHALCON_OBS_VAR(page); + phalcon_array_fetch_quick_string(&page, config, SS("page"), 270576770UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_page"), page, 3986343137UL TSRMLS_CC); } - RETURN_CCTOR(default_value); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Session_Adapter, set){ - - zval *index, *value, *unique_id, *key, *_SESSION; +static PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, setCurrentPage){ - PHALCON_MM_GROW(); + zval *page; - phalcon_fetch_params(1, 2, 0, &index, &value); - - PHALCON_OBS_VAR(unique_id); - phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + phalcon_fetch_params(0, 1, 0, &page); - PHALCON_INIT_VAR(key); - PHALCON_CONCAT_VV(key, unique_id, index); - phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); - phalcon_array_update_zval(&_SESSION, key, &value, PH_COPY); + phalcon_update_property_this_quick(this_ptr, SL("_page"), page, 3986343137UL TSRMLS_CC); - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Session_Adapter, has){ +static PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, getPaginate){ - zval *index, *unique_id, *key, *_SESSION; + zval *one, *config, *items, *show, *page_number = NULL, *page; + zval *number, *rounded_total, *total_pages, *before_page_number; + zval *start, *slice, *next = NULL, *before = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &index); + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); - PHALCON_OBS_VAR(unique_id); - phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + PHALCON_OBS_VAR(config); + phalcon_read_property_this_quick(&config, this_ptr, SL("_config"), 4157843450UL, PH_NOISY_CC); - PHALCON_INIT_VAR(key); - PHALCON_CONCAT_VV(key, unique_id, index); - phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); - if (phalcon_array_isset(_SESSION, key)) { - RETURN_MM_TRUE; + PHALCON_OBS_VAR(items); + phalcon_array_fetch_quick_string(&items, config, SS("data"), 256359743UL, PH_NOISY); + if (Z_TYPE_P(items) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "Invalid data for paginator"); + return; } - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Session_Adapter, remove){ - - zval *index, *unique_id, *key, *_SESSION; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &index); + PHALCON_OBS_VAR(show); + phalcon_read_property_this_quick(&show, this_ptr, SL("_limitRows"), 597448366UL, PH_NOISY_CC); - PHALCON_OBS_VAR(unique_id); - phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + PHALCON_OBS_VAR(page_number); + phalcon_read_property_this_quick(&page_number, this_ptr, SL("_page"), 3986343137UL, PH_NOISY_CC); + if (!zend_is_true(page_number)) { + PHALCON_CPY_WRT(page_number, one); + } + + PHALCON_INIT_VAR(page); + object_init(page); + + PHALCON_INIT_VAR(number); + phalcon_fast_count(number, items TSRMLS_CC); + + PHALCON_INIT_VAR(rounded_total); + div_function(rounded_total, number, show TSRMLS_CC); + + PHALCON_INIT_VAR(total_pages); + ZVAL_LONG(total_pages, phalcon_get_intval(rounded_total)); + + if (!PHALCON_IS_EQUAL(total_pages, rounded_total)) { + PHALCON_SEPARATE_NMO(total_pages); + phalcon_increment(total_pages); + } + + PHALCON_INIT_VAR(before_page_number); + sub_function(before_page_number, page_number, one TSRMLS_CC); + + PHALCON_INIT_VAR(start); + mul_function(start, show, before_page_number TSRMLS_CC); + + PHALCON_INIT_VAR(slice); + phalcon_call_func_p3(slice, "array_slice", items, start, show); + phalcon_update_property_zval(page, SL("items"), slice TSRMLS_CC); + if (PHALCON_LT(page_number, total_pages)) { + PHALCON_INIT_VAR(next); + phalcon_add_function(next, page_number, one TSRMLS_CC); + } else { + PHALCON_CPY_WRT(next, total_pages); + } + + phalcon_update_property_zval(page, SL("next"), next TSRMLS_CC); + if (PHALCON_GT(page_number, one)) { + PHALCON_INIT_VAR(before); + sub_function(before, page_number, one TSRMLS_CC); + } else { + PHALCON_CPY_WRT(before, one); + } - PHALCON_INIT_VAR(key); - PHALCON_CONCAT_VV(key, unique_id, index); - phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); - phalcon_array_unset(&_SESSION, key, 0); + phalcon_update_property_zval(page, SL("first"), one TSRMLS_CC); + phalcon_update_property_zval(page, SL("before"), before TSRMLS_CC); + phalcon_update_property_zval(page, SL("current"), page_number TSRMLS_CC); + phalcon_update_property_zval(page, SL("last"), total_pages TSRMLS_CC); + phalcon_update_property_zval(page, SL("total_pages"), total_pages TSRMLS_CC); + phalcon_update_property_zval(page, SL("total_items"), number TSRMLS_CC); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Session_Adapter, getId){ - - phalcon_get_session_id(return_value TSRMLS_CC); -} - -static PHP_METHOD(Phalcon_Session_Adapter, isStarted){ - - - RETURN_MEMBER_QUICK(this_ptr, "_started", 433407867UL); -} - -static PHP_METHOD(Phalcon_Session_Adapter, destroy){ - - - phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); - phalcon_session_destroy(TSRMLS_C); - RETURN_TRUE; + RETURN_CTOR(page); } @@ -93718,280 +94222,175 @@ static PHP_METHOD(Phalcon_Session_Adapter, destroy){ -PHALCON_INIT_CLASS(Phalcon_Session_Bag){ +PHALCON_INIT_CLASS(Phalcon_Paginator_Adapter_QueryBuilder){ - PHALCON_REGISTER_CLASS(Phalcon\\Session, Bag, session_bag, phalcon_session_bag_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Paginator\\Adapter, QueryBuilder, paginator_adapter_querybuilder, phalcon_paginator_adapter_querybuilder_method_entry, 0); - zend_declare_property_null(phalcon_session_bag_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_session_bag_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_session_bag_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_bool(phalcon_session_bag_ce, SL("_initalized"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_session_bag_ce, SL("_session"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_paginator_adapter_querybuilder_ce, SL("_config"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_paginator_adapter_querybuilder_ce, SL("_builder"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_paginator_adapter_querybuilder_ce, SL("_limitRows"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_paginator_adapter_querybuilder_ce, SL("_page"), 1, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_session_bag_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_session_baginterface_ce); + zend_class_implements(phalcon_paginator_adapter_querybuilder_ce TSRMLS_CC, 1, phalcon_paginator_adapterinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Session_Bag, __construct){ +static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, __construct){ - zval *name; + zval *config, *builder, *limit, *page; - phalcon_fetch_params(0, 1, 0, &name); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &config); - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_session_exception_ce, "The name parameter must be a string"); + phalcon_update_property_this_quick(this_ptr, SL("_config"), config, 4157843450UL TSRMLS_CC); + if (!phalcon_array_isset_quick_string(config, SS("builder"), 403513100UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "Parameter 'builder' is required"); return; + } else { + PHALCON_OBS_VAR(builder); + phalcon_array_fetch_quick_string(&builder, config, SS("builder"), 403513100UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_builder"), builder, 3366211339UL TSRMLS_CC); } - phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Session_Bag, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_session_exception_ce, "The dependency injector must be an Object"); + if (!phalcon_array_isset_quick_string(config, SS("limit"), 192268420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "Parameter 'limit' is required"); return; + } else { + PHALCON_OBS_VAR(limit); + phalcon_array_fetch_quick_string(&limit, config, SS("limit"), 192268420UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_limitRows"), limit, 597448366UL TSRMLS_CC); + } + + if (phalcon_array_isset_quick_string(config, SS("page"), 270576770UL)) { + PHALCON_OBS_VAR(page); + phalcon_array_fetch_quick_string(&page, config, SS("page"), 270576770UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_page"), page, 3986343137UL TSRMLS_CC); } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Session_Bag, getDI){ +static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, setCurrentPage){ + zval *current_page; - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); + phalcon_fetch_params(0, 1, 0, ¤t_page); + + phalcon_update_property_this_quick(this_ptr, SL("_page"), current_page, 3986343137UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Session_Bag, initialize){ +static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate){ - zval *session = NULL, *dependency_injector = NULL, *service; - zval *name, *data = NULL; + zval *original_builder, *builder, *total_builder; + zval *limit, *number_page = NULL, *one, *prev_number_page; + zval *number, *query, *page, *before = NULL, *items, *select_count; + zval *null_order, *total_query, *result, *row, *rowcount; + zval *total_pages = NULL, *int_total_pages, *next = NULL; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(session); - phalcon_read_property_this_quick(&session, this_ptr, SL("_session"), 3241463720UL, PH_NOISY_CC); - if (Z_TYPE_P(session) != IS_OBJECT) { + PHALCON_OBS_VAR(original_builder); + phalcon_read_property_this_quick(&original_builder, this_ptr, SL("_builder"), 3366211339UL, PH_NOISY_CC); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_VAR(builder); + if (phalcon_clone(builder, original_builder TSRMLS_CC) == FAILURE) { + return; + } - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + PHALCON_INIT_VAR(total_builder); + if (phalcon_clone(total_builder, builder TSRMLS_CC) == FAILURE) { + return; + } - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_session_exception_ce, "A dependency injection object is required to access the 'session' service"); - return; - } - } + PHALCON_OBS_VAR(limit); + phalcon_read_property_this_quick(&limit, this_ptr, SL("_limitRows"), 597448366UL, PH_NOISY_CC); - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "session", 1); + PHALCON_OBS_VAR(number_page); + phalcon_read_property_this_quick(&number_page, this_ptr, SL("_page"), 3986343137UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_property_this_quick(this_ptr, SL("_session"), session, 3241463720UL TSRMLS_CC); + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + if (!zend_is_true(number_page)) { + PHALCON_CPY_WRT(number_page, one); } - PHALCON_OBS_VAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(data); - phalcon_call_method_p1_key(data, session, "get", name, 2090288933UL); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_INIT_NVAR(data); - array_init(data); - } + PHALCON_INIT_VAR(prev_number_page); + sub_function(prev_number_page, number_page, one TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC); - phalcon_update_property_bool(this_ptr, SL("_initalized"), 1 TSRMLS_CC); + PHALCON_INIT_VAR(number); + mul_function(number, limit, prev_number_page TSRMLS_CC); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Session_Bag, destroy){ - - zval *initalized, *name, *session; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(initalized); - phalcon_read_property_this_quick(&initalized, this_ptr, SL("_initalized"), 4124099953UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(initalized)) { - phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); + if (PHALCON_LT(number, limit)) { + phalcon_call_method_p1_key(NULL, builder, "limit", limit, 192268420UL); + } else { + phalcon_call_method_p2_key(NULL, builder, "limit", limit, number, 192268420UL); } - PHALCON_OBS_VAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(session); - phalcon_read_property_this_quick(&session, this_ptr, SL("_session"), 3241463720UL, PH_NOISY_CC); - phalcon_call_method_p1_key(NULL, session, "remove", name, 1052443347UL); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Session_Bag, set){ - - zval *property, *value, *initalized, *name, *data; - zval *session; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &property, &value); + PHALCON_INIT_VAR(query); + phalcon_call_method_key(query, builder, "getquery", 4154457883UL); - PHALCON_OBS_VAR(initalized); - phalcon_read_property_this_quick(&initalized, this_ptr, SL("_initalized"), 4124099953UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(initalized)) { - phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); + PHALCON_INIT_VAR(page); + object_init(page); + phalcon_update_property_zval(page, SL("first"), one TSRMLS_CC); + if (PHALCON_IS_EQUAL(number_page, one)) { + PHALCON_CPY_WRT(before, one); + } else { + PHALCON_INIT_NVAR(before); + sub_function(before, number_page, one TSRMLS_CC); } - phalcon_update_property_array(this_ptr, SL("_data"), property, value TSRMLS_CC); + phalcon_update_property_zval(page, SL("before"), before TSRMLS_CC); - PHALCON_OBS_VAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); + PHALCON_INIT_VAR(items); + phalcon_call_method_key(items, query, "execute", 3117639032UL); + phalcon_update_property_zval(page, SL("items"), items TSRMLS_CC); - PHALCON_OBS_VAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + PHALCON_INIT_VAR(select_count); + ZVAL_STRING(select_count, "COUNT(*) [rowcount]", 1); - PHALCON_OBS_VAR(session); - phalcon_read_property_this_quick(&session, this_ptr, SL("_session"), 3241463720UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, session, "set", name, data, 2090720177UL); + phalcon_call_method_p1_key(NULL, total_builder, "columns", select_count, 1041822630UL); - PHALCON_MM_RESTORE(); -} - - -static PHP_METHOD(Phalcon_Session_Bag, get){ - - zval *property, *default_value = NULL, *initalized; - zval *data, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &property, &default_value); + PHALCON_INIT_VAR(null_order); + phalcon_call_method_p1_key(NULL, total_builder, "orderby", null_order, 609575676UL); - if (!default_value) { - PHALCON_INIT_VAR(default_value); - } + PHALCON_INIT_VAR(total_query); + phalcon_call_method_key(total_query, total_builder, "getquery", 4154457883UL); - PHALCON_OBS_VAR(initalized); - phalcon_read_property_this_quick(&initalized, this_ptr, SL("_initalized"), 4124099953UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(initalized)) { - phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); - } + PHALCON_INIT_VAR(result); + phalcon_call_method_key(result, total_query, "execute", 3117639032UL); - PHALCON_OBS_VAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - if (phalcon_array_isset(data, property)) { + PHALCON_INIT_VAR(row); + phalcon_call_method_key(row, result, "getfirst", 3710205613UL); - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, data, property, PH_NOISY); - if (PHALCON_IS_NOT_EMPTY(value)) { - RETURN_CCTOR(value); - } - } + PHALCON_OBS_VAR(rowcount); + phalcon_read_property(&rowcount, row, SL("rowcount"), PH_NOISY_CC); - RETURN_CCTOR(default_value); -} - - -static PHP_METHOD(Phalcon_Session_Bag, has){ - - zval *property, *initalized, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &property); + PHALCON_INIT_VAR(total_pages); + div_function(total_pages, rowcount, limit TSRMLS_CC); - PHALCON_OBS_VAR(initalized); - phalcon_read_property_this_quick(&initalized, this_ptr, SL("_initalized"), 4124099953UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(initalized)) { - phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); + PHALCON_INIT_VAR(int_total_pages); + ZVAL_LONG(int_total_pages, phalcon_get_intval(total_pages)); + if (!PHALCON_IS_EQUAL(int_total_pages, total_pages)) { + phalcon_add_function(total_pages, int_total_pages, one TSRMLS_CC); } - PHALCON_OBS_VAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - if (phalcon_array_isset(data, property)) { - RETURN_MM_TRUE; + if (PHALCON_LT(number_page, total_pages)) { + PHALCON_INIT_VAR(next); + phalcon_add_function(next, number_page, one TSRMLS_CC); + } else { + PHALCON_CPY_WRT(next, total_pages); } - RETURN_MM_FALSE; -} - - -static PHP_METHOD(Phalcon_Session_Bag, remove){ - - zval *property, *data = NULL, *name, *session; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &property); - - PHALCON_OBS_VAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - if (phalcon_array_isset(data, property)) { - phalcon_unset_property_array(this_ptr, SL("_data"), property TSRMLS_CC); - - PHALCON_OBS_NVAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(session); - phalcon_read_property_this_quick(&session, this_ptr, SL("_session"), 3241463720UL, PH_NOISY_CC); - phalcon_call_method_p2_key(NULL, session, "set", name, data, 2090720177UL); - RETURN_MM_TRUE; - } + phalcon_update_property_zval(page, SL("next"), next TSRMLS_CC); + phalcon_update_property_zval(page, SL("last"), total_pages TSRMLS_CC); + phalcon_update_property_zval(page, SL("current"), number_page TSRMLS_CC); + phalcon_update_property_zval(page, SL("total_pages"), total_pages TSRMLS_CC); + phalcon_update_property_zval(page, SL("total_items"), rowcount TSRMLS_CC); - RETURN_MM_FALSE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Session_Adapter_Files){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Session\\Adapter, Files, session_adapter_files, "phalcon\\session\\adapter", NULL, 0); - - zend_class_implements(phalcon_session_adapter_files_ce TSRMLS_CC, 1, phalcon_session_adapterinterface_ce); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Session_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Session, Exception, session_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; + RETURN_CTOR(page); } @@ -94003,9 +94402,9 @@ PHALCON_INIT_CLASS(Phalcon_Session_Exception){ -PHALCON_INIT_CLASS(Phalcon_Session_BagInterface){ +PHALCON_INIT_CLASS(Phalcon_Paginator_AdapterInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Session, BagInterface, session_baginterface, phalcon_session_baginterface_method_entry); + PHALCON_REGISTER_INTERFACE(Phalcon\\Paginator, AdapterInterface, paginator_adapterinterface, phalcon_paginator_adapterinterface_method_entry); return SUCCESS; } @@ -94017,11 +94416,6 @@ PHALCON_INIT_CLASS(Phalcon_Session_BagInterface){ - - - - - #ifdef HAVE_CONFIG_H #endif @@ -94030,35 +94424,13 @@ PHALCON_INIT_CLASS(Phalcon_Session_BagInterface){ -PHALCON_INIT_CLASS(Phalcon_Logger_Formatter_Json){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Formatter, Json, logger_formatter_json, "phalcon\\logger\\formatter", phalcon_logger_formatter_json_method_entry, 0); +PHALCON_INIT_CLASS(Phalcon_Paginator_Exception){ - zend_class_implements(phalcon_logger_formatter_json_ce TSRMLS_CC, 1, phalcon_logger_formatterinterface_ce); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Paginator, Exception, paginator_exception, "phalcon\\exception", NULL, 0); return SUCCESS; } -static PHP_METHOD(Phalcon_Logger_Formatter_Json, format){ - - zval *message, *type, *timestamp, *type_str, *log; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &message, &type, ×tamp); - - PHALCON_INIT_VAR(type_str); - phalcon_call_method_p1_key(type_str, this_ptr, "gettypestring", type, 2427941566UL); - - PHALCON_INIT_VAR(log); - array_init_size(log, 3); - phalcon_array_update_quick_string(&log, SS("type"), 276192743UL, &type_str, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&log, SS("message"), 2265848874UL, &message, PH_COPY | PH_SEPARATE); - phalcon_array_update_quick_string(&log, SS("timestamp"), 3706650937UL, ×tamp, PH_COPY | PH_SEPARATE); - phalcon_json_encode(return_value, log, 0 TSRMLS_CC); - RETURN_MM(); -} - @@ -94072,129 +94444,67 @@ static PHP_METHOD(Phalcon_Logger_Formatter_Json, format){ -PHALCON_INIT_CLASS(Phalcon_Logger_Formatter_Line){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Formatter, Line, logger_formatter_line, "phalcon\\logger\\formatter", phalcon_logger_formatter_line_method_entry, 0); +PHALCON_INIT_CLASS(Phalcon_Queue_Beanstalk_Job){ - zend_declare_property_string(phalcon_logger_formatter_line_ce, SL("_dateFormat"), "D, d M y H:i:s O", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_string(phalcon_logger_formatter_line_ce, SL("_format"), "[%date%][%type%] %message%", ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_REGISTER_CLASS(Phalcon\\Queue\\Beanstalk, Job, queue_beanstalk_job, phalcon_queue_beanstalk_job_method_entry, 0); - zend_class_implements(phalcon_logger_formatter_line_ce TSRMLS_CC, 1, phalcon_logger_formatterinterface_ce); + zend_declare_property_null(phalcon_queue_beanstalk_job_ce, SL("_queue"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_queue_beanstalk_job_ce, SL("_id"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_queue_beanstalk_job_ce, SL("_body"), ZEND_ACC_PROTECTED TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_Logger_Formatter_Line, __construct){ - - zval *format = NULL, *date_format = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &format, &date_format); - - if (!format) { - PHALCON_INIT_VAR(format); - } - - if (!date_format) { - PHALCON_INIT_VAR(date_format); - } - - if (Z_TYPE_P(format) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_format"), format, 3742267021UL TSRMLS_CC); - } - if (Z_TYPE_P(date_format) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_dateFormat"), date_format, 959184011UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Logger_Formatter_Line, setFormat){ +static PHP_METHOD(Phalcon_Queue_Beanstalk_Job, __construct){ - zval *format; + zval *queue, *id, *body; - phalcon_fetch_params(0, 1, 0, &format); + phalcon_fetch_params(0, 3, 0, &queue, &id, &body); - phalcon_update_property_this_quick(this_ptr, SL("_format"), format, 3742267021UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_queue"), queue, 2763107337UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_id"), id, 2090005265UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_body"), body, 3970240754UL TSRMLS_CC); } -static PHP_METHOD(Phalcon_Logger_Formatter_Line, getFormat){ - - - RETURN_MEMBER_QUICK(this_ptr, "_format", 3742267021UL); -} - -static PHP_METHOD(Phalcon_Logger_Formatter_Line, setDateFormat){ +static PHP_METHOD(Phalcon_Queue_Beanstalk_Job, getId){ - zval *date; - phalcon_fetch_params(0, 1, 0, &date); - - phalcon_update_property_this_quick(this_ptr, SL("_dateFormat"), date, 959184011UL TSRMLS_CC); - + RETURN_MEMBER_QUICK(this_ptr, "_id", 2090005265UL); } -static PHP_METHOD(Phalcon_Logger_Formatter_Line, getDateFormat){ +static PHP_METHOD(Phalcon_Queue_Beanstalk_Job, getBody){ - RETURN_MEMBER_QUICK(this_ptr, "_dateFormat", 959184011UL); + RETURN_MEMBER_QUICK(this_ptr, "_body", 3970240754UL); } -static PHP_METHOD(Phalcon_Logger_Formatter_Line, format){ +static PHP_METHOD(Phalcon_Queue_Beanstalk_Job, delete){ - zval *message, *type, *timestamp, *format = NULL, *date_format; - zval *date, *date_wildcard, *new_format = NULL, *type_string; - zval *type_wildcard, *message_wildcard, *eol; + zval *id, *command, *queue, *response, *status; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &message, &type, ×tamp); - - PHALCON_OBS_VAR(format); - phalcon_read_property_this_quick(&format, this_ptr, SL("_format"), 3742267021UL, PH_NOISY_CC); - - if (phalcon_memnstr_str(format, SL("%date%"))) { - PHALCON_OBS_VAR(date_format); - phalcon_read_property_this_quick(&date_format, this_ptr, SL("_dateFormat"), 959184011UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(date); - phalcon_call_func_p2(date, "date", date_format, timestamp); - - PHALCON_INIT_VAR(date_wildcard); - ZVAL_STRING(date_wildcard, "%date%", 1); - - PHALCON_INIT_VAR(new_format); - phalcon_fast_str_replace(new_format, date_wildcard, date, format); - } else { - PHALCON_CPY_WRT(new_format, format); - } - - if (phalcon_memnstr_str(format, SL("%type%"))) { - PHALCON_INIT_VAR(type_string); - phalcon_call_method_p1_key(type_string, this_ptr, "gettypestring", type, 2427941566UL); - - PHALCON_INIT_VAR(type_wildcard); - ZVAL_STRING(type_wildcard, "%type%", 1); + PHALCON_OBS_VAR(id); + phalcon_read_property_this_quick(&id, this_ptr, SL("_id"), 2090005265UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(format); - phalcon_fast_str_replace(format, type_wildcard, type_string, new_format); - } else { - PHALCON_CPY_WRT(format, new_format); - } + PHALCON_INIT_VAR(command); + PHALCON_CONCAT_SV(command, "delete ", id); - PHALCON_INIT_VAR(message_wildcard); - ZVAL_STRING(message_wildcard, "%message%", 1); + PHALCON_OBS_VAR(queue); + phalcon_read_property_this_quick(&queue, this_ptr, SL("_queue"), 2763107337UL, PH_NOISY_CC); + phalcon_call_method_p1_key(NULL, queue, "write", command, 633298768UL); - PHALCON_INIT_NVAR(new_format); - phalcon_fast_str_replace(new_format, message_wildcard, message, format); + PHALCON_INIT_VAR(response); + phalcon_call_method_key(response, queue, "readstatus", 4258812709UL); - PHALCON_INIT_VAR(eol); - ZVAL_STRING(eol, PHP_EOL, 1); - PHALCON_CONCAT_VV(return_value, new_format, eol); + PHALCON_OBS_VAR(status); + phalcon_array_fetch_long(&status, response, 0, PH_NOISY); + if (PHALCON_IS_STRING(status, "DELETED")) { + RETURN_MM_TRUE; + } - RETURN_MM(); + RETURN_MM_FALSE; } @@ -94210,167 +94520,432 @@ static PHP_METHOD(Phalcon_Logger_Formatter_Line, format){ -PHALCON_INIT_CLASS(Phalcon_Logger_Formatter_Syslog){ +PHALCON_INIT_CLASS(Phalcon_Queue_Beanstalk){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Formatter, Syslog, logger_formatter_syslog, "phalcon\\logger\\formatter", phalcon_logger_formatter_syslog_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Queue, Beanstalk, queue_beanstalk, phalcon_queue_beanstalk_method_entry, 0); - zend_class_implements(phalcon_logger_formatter_syslog_ce TSRMLS_CC, 1, phalcon_logger_formatterinterface_ce); + zend_declare_property_null(phalcon_queue_beanstalk_ce, SL("_connection"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_queue_beanstalk_ce, SL("_parameters"), ZEND_ACC_PROTECTED TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_Logger_Formatter_Syslog, format){ +static PHP_METHOD(Phalcon_Queue_Beanstalk, __construct){ - zval *message, *type, *timestamp; + zval *options = NULL, *parameters = NULL; - phalcon_fetch_params(0, 3, 0, &message, &type, ×tamp); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &options); - array_init_size(return_value, 2); - phalcon_array_append(&return_value, type, PH_SEPARATE); - phalcon_array_append(&return_value, message, PH_SEPARATE); - return; + if (!options) { + PHALCON_INIT_VAR(options); + } + + if (Z_TYPE_P(options) != IS_ARRAY) { + PHALCON_INIT_VAR(parameters); + array_init(parameters); + } else { + PHALCON_CPY_WRT(parameters, options); + } + if (!phalcon_array_isset_quick_string(parameters, SS("host"), 261606083UL)) { + phalcon_array_update_string_string(¶meters, SL("host"), SL("127.0.0.1"), PH_SEPARATE); + } + + if (!phalcon_array_isset_quick_string(parameters, SS("port"), 271092362UL)) { + phalcon_array_update_string_long(¶meters, SL("port"), 11300, PH_SEPARATE); + } + + phalcon_update_property_this_quick(this_ptr, SL("_parameters"), parameters, 2188379992UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } +static PHP_METHOD(Phalcon_Queue_Beanstalk, connect){ + + zval *connection = NULL, *parameters, *host, *port, *error_num; + zval *error_str, *no_timeout, *microseconds; + PHALCON_MM_GROW(); + PHALCON_OBS_VAR(connection); + phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + if (Z_TYPE_P(connection) == IS_RESOURCE) { + phalcon_call_method_key(NULL, this_ptr, "disconnect", 3328810223UL); + } + + PHALCON_OBS_VAR(parameters); + phalcon_read_property_this_quick(¶meters, this_ptr, SL("_parameters"), 2188379992UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(host); + phalcon_array_fetch_quick_string(&host, parameters, SS("host"), 261606083UL, PH_NOISY); + + PHALCON_OBS_VAR(port); + phalcon_array_fetch_quick_string(&port, parameters, SS("port"), 271092362UL, PH_NOISY); + + PHALCON_INIT_VAR(error_num); + + PHALCON_INIT_VAR(error_str); + Z_SET_ISREF_P(error_num); + Z_SET_ISREF_P(error_str); + + PHALCON_INIT_NVAR(connection); + phalcon_call_func_p4(connection, "fsockopen", host, port, error_num, error_str); + Z_UNSET_ISREF_P(error_num); + Z_UNSET_ISREF_P(error_str); + if (Z_TYPE_P(connection) != IS_RESOURCE) { + PHALCON_THROW_EXCEPTION_STR(phalcon_exception_ce, "Can't connect to Beanstalk server"); + return; + } + + PHALCON_INIT_VAR(no_timeout); + ZVAL_LONG(no_timeout, -1); + + PHALCON_INIT_VAR(microseconds); + phalcon_call_func_p3_noret("stream_set_timeout", connection, no_timeout, microseconds); + phalcon_update_property_this_quick(this_ptr, SL("_connection"), connection, 3057302292UL TSRMLS_CC); + + RETURN_CCTOR(connection); +} +static PHP_METHOD(Phalcon_Queue_Beanstalk, put){ -#ifdef HAVE_CONFIG_H -#endif + zval *data, *options = NULL, *priority = NULL, *delay = NULL, *ttr = NULL, *serialized; + zval *serialized_length, *command, *response; + zval *status, *job_id = NULL; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 1, &data, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } + + if (phalcon_array_isset_quick_string(options, SS("priority"), 3149449863UL)) { + PHALCON_OBS_VAR(priority); + phalcon_array_fetch_quick_string(&priority, options, SS("priority"), 3149449863UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(priority); + ZVAL_STRING(priority, "100", 1); + } + if (phalcon_array_isset_quick_string(options, SS("delay"), 4169364404UL)) { + PHALCON_OBS_VAR(delay); + phalcon_array_fetch_quick_string(&delay, options, SS("delay"), 4169364404UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(delay); + ZVAL_STRING(delay, "0", 1); + } + + if (phalcon_array_isset_quick_string(options, SS("ttr"), 2090772383UL)) { + PHALCON_OBS_VAR(ttr); + phalcon_array_fetch_quick_string(&ttr, options, SS("ttr"), 2090772383UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(ttr); + ZVAL_STRING(ttr, "86400", 1); + } + + PHALCON_INIT_VAR(serialized); + phalcon_serialize(serialized, &data TSRMLS_CC); + + PHALCON_INIT_VAR(serialized_length); + phalcon_fast_strlen(serialized_length, serialized); + + PHALCON_INIT_VAR(command); + PHALCON_CONCAT_SVSV(command, "put ", priority, " ", delay); + PHALCON_SCONCAT_SVSV(command, " ", ttr, " ", serialized_length); + phalcon_call_method_p1_key(NULL, this_ptr, "write", command, 633298768UL); + phalcon_call_method_p1_key(NULL, this_ptr, "write", serialized, 633298768UL); + + PHALCON_INIT_VAR(response); + phalcon_call_method_key(response, this_ptr, "readstatus", 4258812709UL); + + PHALCON_OBS_VAR(status); + phalcon_array_fetch_long(&status, response, 0, PH_NOISY); + if (PHALCON_IS_STRING(status, "INSERTED")) { + PHALCON_OBS_VAR(job_id); + phalcon_array_fetch_long(&job_id, response, 1, PH_NOISY); + RETURN_CCTOR(job_id); + } + + if (PHALCON_IS_STRING(status, "BURIED")) { + PHALCON_OBS_NVAR(job_id); + phalcon_array_fetch_long(&job_id, response, 1, PH_NOISY); + RETURN_CCTOR(job_id); + } + + RETURN_MM_FALSE; +} +static PHP_METHOD(Phalcon_Queue_Beanstalk, reserve){ + zval *timeout = NULL, *command = NULL, *response, *status, *job_id; + zval *length, *serialized_body, *body; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 0, 1, &timeout); + + if (!timeout) { + PHALCON_INIT_VAR(timeout); + } + + if (zend_is_true(timeout)) { + PHALCON_INIT_VAR(command); + PHALCON_CONCAT_SV(command, "reserve-with-timeout ", timeout); + } else { + PHALCON_INIT_NVAR(command); + ZVAL_STRING(command, "reserve", 1); + } + phalcon_call_method_p1_key(NULL, this_ptr, "write", command, 633298768UL); + + PHALCON_INIT_VAR(response); + phalcon_call_method_key(response, this_ptr, "readstatus", 4258812709UL); + + PHALCON_OBS_VAR(status); + phalcon_array_fetch_long(&status, response, 0, PH_NOISY); + if (PHALCON_IS_STRING(status, "RESERVED")) { + PHALCON_OBS_VAR(job_id); + phalcon_array_fetch_long(&job_id, response, 1, PH_NOISY); + + PHALCON_OBS_VAR(length); + phalcon_array_fetch_long(&length, response, 2, PH_NOISY); + + PHALCON_INIT_VAR(serialized_body); + phalcon_call_method_p1_key(serialized_body, this_ptr, "read", length, 273085793UL); + + PHALCON_INIT_VAR(body); + phalcon_unserialize(body, serialized_body TSRMLS_CC); + + object_init_ex(return_value, phalcon_queue_beanstalk_job_ce); + phalcon_call_method_p3_key(NULL, return_value, "__construct", this_ptr, job_id, body, 1107214344UL); + + RETURN_MM(); + } + + RETURN_MM_FALSE; +} -PHALCON_INIT_CLASS(Phalcon_Logger_Formatter_Firephp){ +static PHP_METHOD(Phalcon_Queue_Beanstalk, choose){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Formatter, Firephp, logger_formatter_firephp, "phalcon\\logger\\formatter", phalcon_logger_formatter_firephp_method_entry, 0); + zval *tube, *command, *response, *status, *using_tube; - zend_class_implements(phalcon_logger_formatter_firephp_ce TSRMLS_CC, 1, phalcon_logger_formatterinterface_ce); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 1, 0, &tube); + + PHALCON_INIT_VAR(command); + PHALCON_CONCAT_SV(command, "use ", tube); + phalcon_call_method_p1_key(NULL, this_ptr, "write", command, 633298768UL); + + PHALCON_INIT_VAR(response); + phalcon_call_method_key(response, this_ptr, "readstatus", 4258812709UL); + + PHALCON_OBS_VAR(status); + phalcon_array_fetch_long(&status, response, 0, PH_NOISY); + if (PHALCON_IS_STRING(status, "USING")) { + PHALCON_OBS_VAR(using_tube); + phalcon_array_fetch_long(&using_tube, response, 1, PH_NOISY); + RETURN_CCTOR(using_tube); + } + + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Logger_Formatter_Firephp, getTypeString) { - - static const char* lut[10] = { - "ERROR", "ERROR", "WARN", "ERROR", "WARN", - "INFO", "INFO", "LOG", "INFO", "LOG" - }; +static PHP_METHOD(Phalcon_Queue_Beanstalk, watch){ - zval *type; - int itype; + zval *tube, *command, *response, *status, *watching_tube; - phalcon_fetch_params(0, 1, 0, &type); + PHALCON_MM_GROW(); - itype = phalcon_get_intval(type); - if (itype > 0 && itype < 10) { - RETURN_STRING(lut[itype], 1); + phalcon_fetch_params(1, 1, 0, &tube); + + PHALCON_INIT_VAR(command); + PHALCON_CONCAT_SV(command, "watch ", tube); + phalcon_call_method_p1_key(NULL, this_ptr, "write", command, 633298768UL); + + PHALCON_INIT_VAR(response); + phalcon_call_method_key(response, this_ptr, "readstatus", 4258812709UL); + + PHALCON_OBS_VAR(status); + phalcon_array_fetch_long(&status, response, 0, PH_NOISY); + if (PHALCON_IS_STRING(status, "WATCH")) { + PHALCON_OBS_VAR(watching_tube); + phalcon_array_fetch_long(&watching_tube, response, 1, PH_NOISY); + RETURN_CCTOR(watching_tube); } - - RETURN_STRING("CUSTOM", 1); + + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Logger_Formatter_Firephp, format) { +static PHP_METHOD(Phalcon_Queue_Beanstalk, peekReady){ - zval *message, *type, *type_str, *timestamp; - zval *payload, *backtrace, *meta, *encoded; - smart_str result = { NULL, 0, 0 }; - int i; - Bucket *p; + zval *command, *response, *status, *job_id, *length; + zval *serialized_body, *body; - phalcon_fetch_params(0, 3, 0, &message, &type, ×tamp); + PHALCON_MM_GROW(); + PHALCON_INIT_VAR(command); + ZVAL_STRING(command, "peek-ready", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "write", command, 633298768UL); + + PHALCON_INIT_VAR(response); + phalcon_call_method_key(response, this_ptr, "readstatus", 4258812709UL); + + PHALCON_OBS_VAR(status); + phalcon_array_fetch_long(&status, response, 0, PH_NOISY); + if (PHALCON_IS_STRING(status, "FOUND")) { + PHALCON_OBS_VAR(job_id); + phalcon_array_fetch_long(&job_id, response, 1, PH_NOISY); + + PHALCON_OBS_VAR(length); + phalcon_array_fetch_long(&length, response, 2, PH_NOISY); + + PHALCON_INIT_VAR(serialized_body); + phalcon_call_method_p1_key(serialized_body, this_ptr, "read", length, 273085793UL); + + PHALCON_INIT_VAR(body); + phalcon_unserialize(body, serialized_body TSRMLS_CC); + object_init_ex(return_value, phalcon_queue_beanstalk_job_ce); + phalcon_call_method_p3_key(NULL, return_value, "__construct", this_ptr, job_id, body, 1107214344UL); + + RETURN_MM(); + } + + RETURN_MM_FALSE; +} - PHALCON_ALLOC_ZVAL(type_str); - phalcon_call_method_p1_key(type_str, this_ptr, "gettypestring", type, 2427941566UL); +static PHP_METHOD(Phalcon_Queue_Beanstalk, readStatus){ - PHALCON_ALLOC_ZVAL(backtrace); -#if PHP_VERSION_ID < 50306 - zend_fetch_debug_backtrace(backtrace, 1, 0 TSRMLS_CC); -#elif PHP_VERSION_ID < 50400 - zend_fetch_debug_backtrace(backtrace, 1, DEBUG_BACKTRACE_IGNORE_ARGS TSRMLS_CC); -#else - zend_fetch_debug_backtrace(backtrace, 1, DEBUG_BACKTRACE_IGNORE_ARGS, 0 TSRMLS_CC); -#endif + zval *response; - if (Z_TYPE_P(backtrace) == IS_ARRAY) { - HashPosition pos; - HashTable *ht = Z_ARRVAL_P(backtrace); - zval **ppzval; - int found = 0; - ulong idx; - char *key; - uint key_len; + PHALCON_MM_GROW(); + PHALCON_INIT_VAR(response); + phalcon_call_method_key(response, this_ptr, "read", 273085793UL); + phalcon_fast_explode_str(return_value, SL(" "), response); + RETURN_MM(); +} - for ( - zend_hash_internal_pointer_reset_ex(ht, &pos); - zend_hash_has_more_elements_ex(ht, &pos) == SUCCESS; - ) { - zend_hash_get_current_data_ex(ht, (void**)&ppzval, &pos); - zend_hash_get_current_key_ex(ht, &key, &key_len, &idx, 0, &pos); - zend_hash_move_forward_ex(ht, &pos); +static PHP_METHOD(Phalcon_Queue_Beanstalk, read){ - if (Z_TYPE_PP(ppzval) == IS_ARRAY) { - if (!found && !zend_hash_exists(Z_ARRVAL_PP(ppzval), SS("file"))) { - zend_hash_index_del(ht, idx); - } - else { - zend_hash_del(Z_ARRVAL_PP(ppzval), "args", sizeof("args")); - zend_hash_del(Z_ARRVAL_PP(ppzval), "object", sizeof("object")); - found = 1; - } - } - } + zval *length = NULL, *connection = NULL, *is_eof, *eof_chars; + zval *total_length = NULL, *data, *meta, *timeout, *mask; + zval *packet = NULL, *end_of_file; - p = ht->pListHead; - i = 0; - while (p != NULL) { - p->nKeyLength = 0; - p->h = i++; - p = p->pListNext; - } + PHALCON_MM_GROW(); - ht->nNextFreeElement = i; - zend_hash_rehash(ht); + phalcon_fetch_params(1, 0, 1, &length); + + if (!length) { + PHALCON_INIT_VAR(length); + } + + PHALCON_OBS_VAR(connection); + phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + if (Z_TYPE_P(connection) != IS_RESOURCE) { + + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, this_ptr, "connect", 1111492527UL); + if (Z_TYPE_P(connection) != IS_RESOURCE) { + RETURN_MM_FALSE; + } + } + + if (zend_is_true(length)) { + + PHALCON_INIT_VAR(is_eof); + phalcon_call_func_p1(is_eof, "feof", connection); + if (zend_is_true(is_eof)) { + RETURN_MM_FALSE; + } + + PHALCON_INIT_VAR(eof_chars); + ZVAL_LONG(eof_chars, 2); + + PHALCON_INIT_VAR(total_length); + phalcon_add_function(total_length, length, eof_chars TSRMLS_CC); + + PHALCON_INIT_VAR(data); + phalcon_call_func_p2(data, "fread", connection, total_length); + + PHALCON_INIT_VAR(meta); + phalcon_call_func_p1(meta, "stream_get_meta_data", connection); + + PHALCON_OBS_VAR(timeout); + phalcon_array_fetch_quick_string(&timeout, meta, SS("timed_out"), 3095227663UL, PH_NOISY); + if (zend_is_true(timeout)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_exception_ce, "Connection timed out"); + return; + } + + PHALCON_INIT_VAR(mask); + ZVAL_STRING(mask, "\r\n", 1); + + PHALCON_INIT_VAR(packet); + phalcon_call_func_p2(packet, "rtrim", data, mask); + } else { + PHALCON_INIT_NVAR(total_length); + ZVAL_LONG(total_length, 16384); + + PHALCON_INIT_VAR(end_of_file); + ZVAL_STRING(end_of_file, "\r\n", 1); + + PHALCON_INIT_NVAR(packet); + phalcon_call_func_p3(packet, "stream_get_line", connection, total_length, end_of_file); } + + RETURN_CCTOR(packet); +} - PHALCON_ALLOC_ZVAL(payload); - array_init_size(payload, 2); +static PHP_METHOD(Phalcon_Queue_Beanstalk, write){ - PHALCON_ALLOC_ZVAL(meta); - array_init_size(meta, 2); - add_assoc_zval(meta, "type", type_str); - add_assoc_zval(meta, "backtrace", backtrace); + zval *data, *connection = NULL, *packet, *data_length; - add_next_index_zval(payload, meta); - add_next_index_zval(payload, message); + PHALCON_MM_GROW(); - ALLOC_INIT_ZVAL(encoded); - phalcon_json_encode(encoded, payload, 0 TSRMLS_CC); + phalcon_fetch_params(1, 1, 0, &data); + + PHALCON_OBS_VAR(connection); + phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + if (Z_TYPE_P(connection) != IS_RESOURCE) { + + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, this_ptr, "connect", 1111492527UL); + if (Z_TYPE_P(connection) != IS_RESOURCE) { + RETURN_MM_FALSE; + } + } + + PHALCON_INIT_VAR(packet); + PHALCON_CONCAT_VS(packet, data, "\r\n"); + + PHALCON_INIT_VAR(data_length); + phalcon_fast_strlen(data_length, packet); + phalcon_call_func_p3(return_value, "fwrite", connection, packet, data_length); + RETURN_MM(); +} - zval_ptr_dtor(&payload); +static PHP_METHOD(Phalcon_Queue_Beanstalk, disconnect){ - smart_str_alloc4(&result, Z_STRLEN_P(encoded) + 2 + 5, 0, i); + zval *connection; - smart_str_append_long(&result, Z_STRLEN_P(encoded)); - smart_str_appendc(&result, '|'); - smart_str_appendl(&result, Z_STRVAL_P(encoded), Z_STRLEN_P(encoded)); - smart_str_appendc(&result, '|'); - smart_str_0(&result); + PHALCON_MM_GROW(); - /* We don't need the JSON message anymore */ - zval_ptr_dtor(&encoded); - /* Do not free the samrt string because we steal its data for zval */ - RETURN_STRINGL(result.c, result.len, 0); + PHALCON_OBS_VAR(connection); + phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + if (Z_TYPE_P(connection) != IS_RESOURCE) { + RETURN_MM_FALSE; + } + + phalcon_call_func_p1_noret("fclose", connection); + RETURN_MM_TRUE; } + #ifdef HAVE_CONFIG_H #endif @@ -94379,32 +94954,11 @@ static PHP_METHOD(Phalcon_Logger_Formatter_Firephp, format) { +PHALCON_INIT_CLASS(Phalcon_Security_Exception){ -PHALCON_INIT_CLASS(Phalcon_Logger_Formatter){ - - PHALCON_REGISTER_CLASS(Phalcon\\Logger, Formatter, logger_formatter, phalcon_logger_formatter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Logger_Formatter, getTypeString){ - - static const char *lut[10] = { - "EMERGENCY", "CRITICAL", "ALERT", "ERROR", "WARNING", - "NOTICE", "INFO", "DEBUG", "CUSTOM", "SPECIAL" - }; - - zval *type; - int itype; - - phalcon_fetch_params(0, 1, 0, &type); - - itype = phalcon_get_intval(type); - if (itype > 0 && itype < 10) { - RETURN_STRING(lut[itype], 1); - } - - RETURN_STRING("CUSTOM", 1); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Security, Exception, security_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } @@ -94420,214 +94974,367 @@ static PHP_METHOD(Phalcon_Logger_Formatter, getTypeString){ -PHALCON_INIT_CLASS(Phalcon_Logger_Multiple){ +PHALCON_INIT_CLASS(Phalcon_Security){ - PHALCON_REGISTER_CLASS(Phalcon\\Logger, Multiple, logger_multiple, phalcon_logger_multiple_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon, Security, security, phalcon_security_method_entry, 0); - zend_declare_property_null(phalcon_logger_multiple_ce, SL("_loggers"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_logger_multiple_ce, SL("_formatter"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_security_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_security_ce, SL("_workFactor"), 8, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_security_ce, SL("_numberBytes"), 16, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_security_ce, SL("_csrf"), ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_security_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Logger_Multiple, push){ +static PHP_METHOD(Phalcon_Security, setDI){ - zval *logger; + zval *dependency_injector; - phalcon_fetch_params(0, 1, 0, &logger); + phalcon_fetch_params(0, 1, 0, &dependency_injector); - if (Z_TYPE_P(logger) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "The logger is invalid"); - return; - } - phalcon_update_property_array_append(this_ptr, SL("_loggers"), logger TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); } -static PHP_METHOD(Phalcon_Logger_Multiple, getLoggers){ +static PHP_METHOD(Phalcon_Security, getDI){ - RETURN_MEMBER_QUICK(this_ptr, "_loggers", 810888023UL); + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -static PHP_METHOD(Phalcon_Logger_Multiple, setFormatter){ - - zval *formatter, *loggers, *logger = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; +static PHP_METHOD(Phalcon_Security, setRandomBytes){ - PHALCON_MM_GROW(); + zval *random_bytes; - phalcon_fetch_params(1, 1, 0, &formatter); - - PHALCON_OBS_VAR(loggers); - phalcon_read_property_this_quick(&loggers, this_ptr, SL("_loggers"), 810888023UL, PH_NOISY_CC); - if (Z_TYPE_P(loggers) == IS_ARRAY) { - - phalcon_is_iterable(loggers, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + phalcon_fetch_params(0, 1, 0, &random_bytes); - PHALCON_GET_HVALUE(logger); + if (Z_TYPE_P(random_bytes) != IS_LONG) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_security_exception_ce, "Random bytes must be integer"); + return; + } + if (PHALCON_LT_LONG(random_bytes, 16)) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_security_exception_ce, "At least 16 bytes are needed to produce a correct salt"); + return; + } - phalcon_call_method_p1_key(NULL, logger, "setformatter", formatter, 3614631813UL); + phalcon_update_property_this_quick(this_ptr, SL("_numberBytes"), random_bytes, 1300189556UL TSRMLS_CC); - zend_hash_move_forward_ex(ah0, &hp0); - } +} + +static PHP_METHOD(Phalcon_Security, getRandomBytes){ + + + RETURN_MEMBER_QUICK(this_ptr, "_numberBytes", 1300189556UL); +} + +static PHP_METHOD(Phalcon_Security, setWorkFactor){ + + zval *work_factor; + + phalcon_fetch_params(0, 1, 0, &work_factor); + if (Z_TYPE_P(work_factor) != IS_LONG) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_security_exception_ce, "Work factor must be integer"); + return; } + phalcon_update_property_this_quick(this_ptr, SL("_workFactor"), work_factor, 3598705926UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Logger_Multiple, getFormatter){ +static PHP_METHOD(Phalcon_Security, getWorkFactor){ - RETURN_MEMBER_QUICK(this_ptr, "_formatter", 1838243768UL); + RETURN_MEMBER_QUICK(this_ptr, "_workFactor", 3598705926UL); } -static PHP_METHOD(Phalcon_Logger_Multiple, log){ +static PHP_METHOD(Phalcon_Security, getSaltBytes){ - zval *message, *type = NULL, *loggers, *logger = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *number_bytes, *random_bytes = NULL, *base64bytes = NULL; + zval *safe_bytes = NULL, *bytes_length = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &message, &type); - - if (!type) { - PHALCON_INIT_VAR(type); - ZVAL_LONG(type, 7); + if (phalcon_function_quick_exists_ex(SS("openssl_random_pseudo_bytes"), 2196693822UL TSRMLS_CC) == FAILURE) { + PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "Openssl extension must be loaded"); + return; } - PHALCON_OBS_VAR(loggers); - phalcon_read_property_this_quick(&loggers, this_ptr, SL("_loggers"), 810888023UL, PH_NOISY_CC); - if (Z_TYPE_P(loggers) == IS_ARRAY) { + PHALCON_OBS_VAR(number_bytes); + phalcon_read_property_this_quick(&number_bytes, this_ptr, SL("_numberBytes"), 1300189556UL, PH_NOISY_CC); - phalcon_is_iterable(loggers, &ah0, &hp0, 0, 0); + while (1) { - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_NVAR(random_bytes); + phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); - PHALCON_GET_HVALUE(logger); + PHALCON_INIT_NVAR(base64bytes); + phalcon_base64_encode(base64bytes, random_bytes); - phalcon_call_method_p2_key(NULL, logger, "log", message, type, 2090479079UL); + PHALCON_INIT_NVAR(safe_bytes); + phalcon_filter_alphanum(safe_bytes, base64bytes); + if (!zend_is_true(safe_bytes)) { + continue; + } - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_INIT_NVAR(bytes_length); + phalcon_fast_strlen(bytes_length, safe_bytes); + if (PHALCON_LT_LONG(bytes_length, 22)) { + continue; } + break; } - PHALCON_MM_RESTORE(); + RETURN_CTOR(safe_bytes); } -static PHP_METHOD(Phalcon_Logger_Multiple, emergence){ +static PHP_METHOD(Phalcon_Security, hash){ - zval *message, *type; + zval *password, *work_factor = NULL, *format, *factor; + zval *salt_bytes, *salt; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 1, &password, &work_factor); - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("EMERGENCE") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + if (!work_factor) { + PHALCON_INIT_VAR(work_factor); + } else { + PHALCON_SEPARATE_PARAM(work_factor); + } - PHALCON_MM_RESTORE(); + if (Z_TYPE_P(work_factor) == IS_NULL) { + PHALCON_OBS_NVAR(work_factor); + phalcon_read_property_this_quick(&work_factor, this_ptr, SL("_workFactor"), 3598705926UL, PH_NOISY_CC); + } + + PHALCON_INIT_VAR(format); + ZVAL_STRING(format, "%02s", 1); + + PHALCON_INIT_VAR(factor); + phalcon_call_func_p2(factor, "sprintf", format, work_factor); + + PHALCON_INIT_VAR(salt_bytes); + phalcon_call_method_key(salt_bytes, this_ptr, "getsaltbytes", 2293626208UL); + + PHALCON_INIT_VAR(salt); + PHALCON_CONCAT_SVSV(salt, "$2a$", factor, "$", salt_bytes); + phalcon_call_func_p2(return_value, "crypt", password, salt); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Logger_Multiple, debug){ +static PHP_METHOD(Phalcon_Security, checkHash){ - zval *message, *type; + zval *password, *password_hash, *hash; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); - - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("DEBUG") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + phalcon_fetch_params(1, 2, 0, &password, &password_hash); - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(hash); + phalcon_call_func_p2(hash, "crypt", password, password_hash); + is_equal_function(return_value, hash, password_hash TSRMLS_CC); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Logger_Multiple, error){ - - zval *message, *type; +static PHP_METHOD(Phalcon_Security, isLegacyHash){ - PHALCON_MM_GROW(); + zval *password_hash; - phalcon_fetch_params(1, 1, 0, &message); - - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("ERROR") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + phalcon_fetch_params(0, 1, 0, &password_hash); - PHALCON_MM_RESTORE(); + if (phalcon_start_with_str(password_hash, SL("$2a$"))) { + RETURN_TRUE; + } + RETURN_FALSE; } -static PHP_METHOD(Phalcon_Logger_Multiple, info){ +static PHP_METHOD(Phalcon_Security, getTokenKey){ - zval *message, *type; + zval *number_bytes = NULL, *random_bytes, *base64bytes; + zval *safe_bytes, *dependency_injector, *service; + zval *session, *key; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 0, 1, &number_bytes); - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("INFO") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + if (!number_bytes) { + PHALCON_INIT_VAR(number_bytes); + ZVAL_LONG(number_bytes, 12); + } - PHALCON_MM_RESTORE(); + if (phalcon_function_quick_exists_ex(SS("openssl_random_pseudo_bytes"), 2196693822UL TSRMLS_CC) == FAILURE) { + PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "Openssl extension must be loaded"); + return; + } + + PHALCON_INIT_VAR(random_bytes); + phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); + + PHALCON_INIT_VAR(base64bytes); + phalcon_base64_encode(base64bytes, random_bytes); + + PHALCON_INIT_VAR(safe_bytes); + phalcon_filter_alphanum(safe_bytes, base64bytes); + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); + return; + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "session", 1); + + PHALCON_INIT_VAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + + PHALCON_INIT_VAR(key); + ZVAL_STRING(key, "$PHALCON/CSRF/KEY$", 1); + phalcon_call_method_p2_key(NULL, session, "set", key, safe_bytes, 2090720177UL); + + RETURN_CTOR(safe_bytes); } -static PHP_METHOD(Phalcon_Logger_Multiple, notice){ +static PHP_METHOD(Phalcon_Security, getToken){ - zval *message, *type; + zval *number_bytes = NULL, *random_bytes, *token, *dependency_injector; + zval *service, *session, *key; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 0, 1, &number_bytes); - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("NOTICE") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + if (!number_bytes) { + PHALCON_INIT_VAR(number_bytes); + ZVAL_LONG(number_bytes, 12); + } - PHALCON_MM_RESTORE(); + if (phalcon_function_quick_exists_ex(SS("openssl_random_pseudo_bytes"), 2196693822UL TSRMLS_CC) == FAILURE) { + PHALCON_THROW_EXCEPTION_STR(phalcon_security_exception_ce, "Openssl extension must be loaded"); + return; + } + + PHALCON_INIT_VAR(random_bytes); + phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); + + PHALCON_INIT_VAR(token); + phalcon_md5(token, random_bytes); + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); + return; + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "session", 1); + + PHALCON_INIT_VAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + + PHALCON_INIT_VAR(key); + ZVAL_STRING(key, "$PHALCON/CSRF$", 1); + phalcon_call_method_p2_key(NULL, session, "set", key, token, 2090720177UL); + + RETURN_CTOR(token); } -static PHP_METHOD(Phalcon_Logger_Multiple, warning){ +static PHP_METHOD(Phalcon_Security, checkToken){ - zval *message, *type; + zval *token_key = NULL, *token_value = NULL, *dependency_injector; + zval *service = NULL, *session, *key = NULL, *request, *token = NULL, *session_token; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 0, 2, &token_key, &token_value); - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("WARNING") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + if (!token_key) { + PHALCON_INIT_VAR(token_key); + } else { + PHALCON_SEPARATE_PARAM(token_key); + } - PHALCON_MM_RESTORE(); + if (!token_value) { + PHALCON_INIT_VAR(token_value); + } + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); + return; + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "session", 1); + + PHALCON_INIT_VAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + if (Z_TYPE_P(token_key) == IS_NULL) { + PHALCON_INIT_VAR(key); + ZVAL_STRING(key, "$PHALCON/CSRF/KEY$", 1); + + PHALCON_INIT_NVAR(token_key); + phalcon_call_method_p1_key(token_key, session, "get", key, 2090288933UL); + } + + if (Z_TYPE_P(token_value) == IS_NULL) { + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "request", 1); + + PHALCON_INIT_VAR(request); + phalcon_call_method_p1_key(request, dependency_injector, "getshared", service, 1727570332UL); + + PHALCON_INIT_VAR(token); + phalcon_call_method_p1_key(token, request, "getpost", token_key, 4289323083UL); + } else { + PHALCON_CPY_WRT(token, token_value); + } + + PHALCON_INIT_NVAR(key); + ZVAL_STRING(key, "$PHALCON/CSRF$", 1); + + PHALCON_INIT_VAR(session_token); + phalcon_call_method_p1_key(session_token, session, "get", key, 2090288933UL); + + is_equal_function(return_value, token, session_token TSRMLS_CC); + + RETURN_MM(); } -static PHP_METHOD(Phalcon_Logger_Multiple, alert){ +static PHP_METHOD(Phalcon_Security, getSessionToken){ - zval *message, *type; + zval *dependency_injector, *service, *session; + zval *key, *session_token; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); + return; + } - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("ALERT") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "session", 1); - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + + PHALCON_INIT_VAR(key); + ZVAL_STRING(key, "$PHALCON/CSRF$", 1); + + PHALCON_INIT_VAR(session_token); + phalcon_call_method_p1_key(session_token, session, "get", key, 2090288933UL); + + RETURN_CCTOR(session_token); } @@ -94639,40 +95346,14 @@ static PHP_METHOD(Phalcon_Logger_Multiple, alert){ -PHALCON_INIT_CLASS(Phalcon_Logger_AdapterInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Logger, AdapterInterface, logger_adapterinterface, phalcon_logger_adapterinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - +PHALCON_INIT_CLASS(Phalcon_Session_Adapter_Files){ -PHALCON_INIT_CLASS(Phalcon_Logger_FormatterInterface){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Session\\Adapter, Files, session_adapter_files, "phalcon\\session\\adapter", NULL, 0); - PHALCON_REGISTER_INTERFACE(Phalcon\\Logger, FormatterInterface, logger_formatterinterface, phalcon_logger_formatterinterface_method_entry); + zend_class_implements(phalcon_session_adapter_files_ce TSRMLS_CC, 1, phalcon_session_adapterinterface_ce); return SUCCESS; } @@ -94681,7 +95362,6 @@ PHALCON_INIT_CLASS(Phalcon_Logger_FormatterInterface){ - #ifdef HAVE_CONFIG_H #endif @@ -94691,264 +95371,189 @@ PHALCON_INIT_CLASS(Phalcon_Logger_FormatterInterface){ -PHALCON_INIT_CLASS(Phalcon_Logger_Adapter){ - PHALCON_REGISTER_CLASS(Phalcon\\Logger, Adapter, logger_adapter, phalcon_logger_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); +PHALCON_INIT_CLASS(Phalcon_Session_Adapter){ - zend_declare_property_bool(phalcon_logger_adapter_ce, SL("_transaction"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_logger_adapter_ce, SL("_queue"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_logger_adapter_ce, SL("_formatter"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_logger_adapter_ce, SL("_logLevel"), 9, ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_REGISTER_CLASS(Phalcon\\Session, Adapter, session_adapter, phalcon_session_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + zend_declare_property_null(phalcon_session_adapter_ce, SL("_uniqueId"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_session_adapter_ce, SL("_started"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_session_adapter_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_Logger_Adapter, setLogLevel){ +static PHP_METHOD(Phalcon_Session_Adapter, __construct){ - zval *level; + zval *options = NULL; - phalcon_fetch_params(0, 1, 0, &level); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &options); - if (Z_TYPE_P(level) != IS_LONG) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "The log level is not valid"); - return; + if (!options) { + PHALCON_INIT_VAR(options); } - phalcon_update_property_this_quick(this_ptr, SL("_logLevel"), level, 4227944734UL TSRMLS_CC); - - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Logger_Adapter, getLogLevel){ - - - RETURN_MEMBER_QUICK(this_ptr, "_logLevel", 4227944734UL); -} - -static PHP_METHOD(Phalcon_Logger_Adapter, setFormatter){ - - zval *formatter; - - phalcon_fetch_params(0, 1, 0, &formatter); - if (Z_TYPE_P(formatter) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "The formatter is not valid"); - return; + if (Z_TYPE_P(options) == IS_ARRAY) { + phalcon_call_method_p1_key(NULL, this_ptr, "setoptions", options, 1759822653UL); } - phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Logger_Adapter, begin){ - - - phalcon_update_property_bool(this_ptr, SL("_transaction"), 1 TSRMLS_CC); - RETURN_THISW(); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Logger_Adapter, commit){ - - zval *transaction, *queue, *message = NULL, *message_str = NULL; - zval *type = NULL, *time = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); +static PHP_METHOD(Phalcon_Session_Adapter, start){ - PHALCON_OBS_VAR(transaction); - phalcon_read_property_this_quick(&transaction, this_ptr, SL("_transaction"), 1141465066UL, PH_NOISY_CC); - if (!zend_is_true(transaction)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "There is no active transaction"); - return; - } - - phalcon_update_property_bool(this_ptr, SL("_transaction"), 0 TSRMLS_CC); - - PHALCON_OBS_VAR(queue); - phalcon_read_property_this_quick(&queue, this_ptr, SL("_queue"), 2763107337UL, PH_NOISY_CC); - if (Z_TYPE_P(queue) == IS_ARRAY) { - - phalcon_is_iterable(queue, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(message); - - PHALCON_INIT_NVAR(message_str); - phalcon_call_method_key(message_str, message, "getmessage", 4288675242UL); - - PHALCON_INIT_NVAR(type); - phalcon_call_method_key(type, message, "gettype", 4294422375UL); - - PHALCON_INIT_NVAR(time); - phalcon_call_method_key(time, message, "gettime", 4293844116UL); - phalcon_call_method_p3_key(NULL, this_ptr, "loginternal", message_str, type, time, 2472438692UL); - - zend_hash_move_forward_ex(ah0, &hp0); - } - + if (!SG(headers_sent)) { + phalcon_session_start(TSRMLS_C); + phalcon_update_property_bool(this_ptr, SL("_started"), 1 TSRMLS_CC); + RETURN_TRUE; } - RETURN_THIS(); + RETURN_FALSE; } -static PHP_METHOD(Phalcon_Logger_Adapter, rollback){ +static PHP_METHOD(Phalcon_Session_Adapter, setOptions){ - zval *transaction, *queue; + zval *options, *unique_id; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(transaction); - phalcon_read_property_this_quick(&transaction, this_ptr, SL("_transaction"), 1141465066UL, PH_NOISY_CC); - if (!zend_is_true(transaction)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "There is no active transaction"); + phalcon_fetch_params(1, 1, 0, &options); + + if (Z_TYPE_P(options) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_session_exception_ce, "Options must be an Array"); return; } + if (phalcon_array_isset_quick_string(options, SS("uniqueId"), 1442667433UL)) { + PHALCON_OBS_VAR(unique_id); + phalcon_array_fetch_quick_string(&unique_id, options, SS("uniqueId"), 1442667433UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_uniqueId"), unique_id, 427461512UL TSRMLS_CC); + } - phalcon_update_property_bool(this_ptr, SL("_transaction"), 0 TSRMLS_CC); - - PHALCON_INIT_VAR(queue); - array_init(queue); - phalcon_update_property_this_quick(this_ptr, SL("_queue"), queue, 2763107337UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - RETURN_THIS(); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Logger_Adapter, emergence){ +static PHP_METHOD(Phalcon_Session_Adapter, getOptions){ - zval *message, *type; + zval *options; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); - - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("EMERGENCE") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); - RETURN_THIS(); + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + RETURN_CCTOR(options); } -static PHP_METHOD(Phalcon_Logger_Adapter, debug){ +static PHP_METHOD(Phalcon_Session_Adapter, get){ - zval *message, *type; + zval *index, *default_value = NULL, *unique_id, *key, *_SESSION; + zval *value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 1, &index, &default_value); - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("DEBUG") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); - RETURN_THIS(); + if (!default_value) { + PHALCON_INIT_VAR(default_value); + } + + PHALCON_OBS_VAR(unique_id); + phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_VV(key, unique_id, index); + phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); + if (phalcon_array_isset(_SESSION, key)) { + + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, _SESSION, key, PH_NOISY); + if (PHALCON_IS_NOT_EMPTY(value)) { + RETURN_CCTOR(value); + } + } + + RETURN_CCTOR(default_value); } -static PHP_METHOD(Phalcon_Logger_Adapter, error){ +static PHP_METHOD(Phalcon_Session_Adapter, set){ - zval *message, *type; + zval *index, *value, *unique_id, *key, *_SESSION; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 2, 0, &index, &value); - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("ERROR") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); - RETURN_THIS(); + PHALCON_OBS_VAR(unique_id); + phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_VV(key, unique_id, index); + phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); + phalcon_array_update_zval(&_SESSION, key, &value, PH_COPY); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Logger_Adapter, info){ +static PHP_METHOD(Phalcon_Session_Adapter, has){ - zval *message, *type; + zval *index, *unique_id, *key, *_SESSION; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 0, &index); - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("INFO") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); - RETURN_THIS(); + PHALCON_OBS_VAR(unique_id); + phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_VV(key, unique_id, index); + phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); + if (phalcon_array_isset(_SESSION, key)) { + RETURN_MM_TRUE; + } + + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Logger_Adapter, notice){ +static PHP_METHOD(Phalcon_Session_Adapter, remove){ - zval *message, *type; + zval *index, *unique_id, *key, *_SESSION; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 0, &index); - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("NOTICE") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); - RETURN_THIS(); + PHALCON_OBS_VAR(unique_id); + phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_VV(key, unique_id, index); + phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); + phalcon_array_unset(&_SESSION, key, 0); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Logger_Adapter, warning){ - - zval *message, *type; - - PHALCON_MM_GROW(); +static PHP_METHOD(Phalcon_Session_Adapter, getId){ - phalcon_fetch_params(1, 1, 0, &message); - - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("WARNING") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); - RETURN_THIS(); + phalcon_get_session_id(return_value TSRMLS_CC); } -static PHP_METHOD(Phalcon_Logger_Adapter, alert){ - - zval *message, *type; +static PHP_METHOD(Phalcon_Session_Adapter, isStarted){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); - - PHALCON_INIT_VAR(type); - phalcon_get_class_constant(type, phalcon_logger_ce, SS("ALERT") TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "log", message, type, 2090479079UL); - RETURN_THIS(); + RETURN_MEMBER_QUICK(this_ptr, "_started", 433407867UL); } -static PHP_METHOD(Phalcon_Logger_Adapter, log){ - - zval *message, *type = NULL, *timestamp, *transaction; - zval *queue_item, *log_level; +static PHP_METHOD(Phalcon_Session_Adapter, destroy){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &message, &type); - - if (!type) { - PHALCON_INIT_VAR(type); - ZVAL_LONG(type, 7); - } - - PHALCON_INIT_VAR(timestamp); - ZVAL_LONG(timestamp, (long) time(NULL)); - - PHALCON_OBS_VAR(transaction); - phalcon_read_property_this_quick(&transaction, this_ptr, SL("_transaction"), 1141465066UL, PH_NOISY_CC); - if (zend_is_true(transaction)) { - PHALCON_INIT_VAR(queue_item); - object_init_ex(queue_item, phalcon_logger_item_ce); - phalcon_call_method_p3_key(NULL, queue_item, "__construct", message, type, timestamp, 1107214344UL); - - phalcon_update_property_array_append(this_ptr, SL("_queue"), queue_item TSRMLS_CC); - RETURN_THIS(); - } - - PHALCON_OBS_VAR(log_level); - phalcon_read_property_this_quick(&log_level, this_ptr, SL("_logLevel"), 4227944734UL, PH_NOISY_CC); - - if (PHALCON_GE(log_level, type)) { - phalcon_call_method_p3_key(NULL, this_ptr, "loginternal", message, type, timestamp, 2472438692UL); - } - - RETURN_THIS(); + phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); + phalcon_session_destroy(TSRMLS_C); + RETURN_TRUE; } @@ -94960,321 +95565,352 @@ static PHP_METHOD(Phalcon_Logger_Adapter, log){ +PHALCON_INIT_CLASS(Phalcon_Session_AdapterInterface){ + PHALCON_REGISTER_INTERFACE(Phalcon\\Session, AdapterInterface, session_adapterinterface, phalcon_session_adapterinterface_method_entry); + return SUCCESS; +} -PHALCON_INIT_CLASS(Phalcon_Logger_Item){ - PHALCON_REGISTER_CLASS(Phalcon\\Logger, Item, logger_item, phalcon_logger_item_method_entry, 0); - zend_declare_property_null(phalcon_logger_item_ce, SL("_type"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_logger_item_ce, SL("_message"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_logger_item_ce, SL("_time"), ZEND_ACC_PROTECTED TSRMLS_CC); - return SUCCESS; -} -static PHP_METHOD(Phalcon_Logger_Item, __construct){ - zval *message, *type, *time = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &message, &type, &time); - - if (!time) { - PHALCON_INIT_VAR(time); - ZVAL_LONG(time, 0); - } - - phalcon_update_property_this_quick(this_ptr, SL("_message"), message, 933579817UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_time"), time, 3991380851UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Logger_Item, getMessage){ - RETURN_MEMBER_QUICK(this_ptr, "_message", 933579817UL); -} -static PHP_METHOD(Phalcon_Logger_Item, getType){ - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); -} -static PHP_METHOD(Phalcon_Logger_Item, getTime){ +#ifdef HAVE_CONFIG_H +#endif - RETURN_MEMBER_QUICK(this_ptr, "_time", 3991380851UL); -} -#ifdef HAVE_CONFIG_H -#endif +PHALCON_INIT_CLASS(Phalcon_Session_Bag){ + PHALCON_REGISTER_CLASS(Phalcon\\Session, Bag, session_bag, phalcon_session_bag_method_entry, 0); + zend_declare_property_null(phalcon_session_bag_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_session_bag_ce, SL("_name"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_session_bag_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_bool(phalcon_session_bag_ce, SL("_initalized"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_null(phalcon_session_bag_ce, SL("_session"), ZEND_ACC_PROTECTED TSRMLS_CC); + zend_class_implements(phalcon_session_bag_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_session_baginterface_ce); + return SUCCESS; +} +static PHP_METHOD(Phalcon_Session_Bag, __construct){ + zval *name; -PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_Syslog){ + phalcon_fetch_params(0, 1, 0, &name); + + if (Z_TYPE_P(name) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_session_exception_ce, "The name parameter must be a string"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_name"), name, 3983977829UL TSRMLS_CC); + +} - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, Syslog, logger_adapter_syslog, "phalcon\\logger\\adapter", phalcon_logger_adapter_syslog_method_entry, 0); +static PHP_METHOD(Phalcon_Session_Bag, setDI){ - zend_declare_property_bool(phalcon_logger_adapter_syslog_ce, SL("_opened"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); + zval *dependency_injector; - zend_class_implements(phalcon_logger_adapter_syslog_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_session_exception_ce, "The dependency injector must be an Object"); + return; + } + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + +} - return SUCCESS; +static PHP_METHOD(Phalcon_Session_Bag, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, __construct){ +static PHP_METHOD(Phalcon_Session_Bag, initialize){ - zval *name, *options = NULL, *option = NULL, *facility = NULL; + zval *session = NULL, *dependency_injector = NULL, *service; + zval *name, *data = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, &options); + PHALCON_OBS_VAR(session); + phalcon_read_property_this_quick(&session, this_ptr, SL("_session"), 3241463720UL, PH_NOISY_CC); + if (Z_TYPE_P(session) != IS_OBJECT) { - if (!options) { - PHALCON_INIT_VAR(options); - } + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - if (zend_is_true(name)) { - if (phalcon_array_isset_quick_string(options, SS("option"), 1911574558UL)) { - PHALCON_OBS_VAR(option); - phalcon_array_fetch_quick_string(&option, options, SS("option"), 1911574558UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(option); - ZVAL_LONG(option, 4); - } - if (phalcon_array_isset_quick_string(options, SS("facility"), 2721335866UL)) { - PHALCON_OBS_VAR(facility); - phalcon_array_fetch_quick_string(&facility, options, SS("facility"), 2721335866UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(facility); - ZVAL_LONG(facility, 8); + PHALCON_INIT_NVAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_session_exception_ce, "A dependency injection object is required to access the 'session' service"); + return; + } } - phalcon_call_func_p3_noret("openlog", name, option, facility); - phalcon_update_property_bool(this_ptr, SL("_opened"), 1 TSRMLS_CC); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "session", 1); + + PHALCON_INIT_NVAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + phalcon_update_property_this_quick(this_ptr, SL("_session"), session, 3241463720UL TSRMLS_CC); + } + + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(data); + phalcon_call_method_p1_key(data, session, "get", name, 2090288933UL); + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_INIT_NVAR(data); + array_init(data); } + phalcon_update_property_this_quick(this_ptr, SL("_data"), data, 3972126110UL TSRMLS_CC); + phalcon_update_property_bool(this_ptr, SL("_initalized"), 1 TSRMLS_CC); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, getFormatter){ +static PHP_METHOD(Phalcon_Session_Bag, destroy){ - zval *formatter = NULL; + zval *initalized, *name, *session; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(formatter); - phalcon_read_property_this_quick(&formatter, this_ptr, SL("_formatter"), 1838243768UL, PH_NOISY_CC); - if (Z_TYPE_P(formatter) != IS_OBJECT) { - PHALCON_INIT_NVAR(formatter); - object_init_ex(formatter, phalcon_logger_formatter_syslog_ce); - phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); + PHALCON_OBS_VAR(initalized); + phalcon_read_property_this_quick(&initalized, this_ptr, SL("_initalized"), 4124099953UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(initalized)) { + phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); } - RETURN_CCTOR(formatter); + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(session); + phalcon_read_property_this_quick(&session, this_ptr, SL("_session"), 3241463720UL, PH_NOISY_CC); + phalcon_call_method_p1_key(NULL, session, "remove", name, 1052443347UL); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, logInternal){ +static PHP_METHOD(Phalcon_Session_Bag, set){ - zval *message, *type, *time, *formatter, *applied_format; - zval *syslog_type, *syslog_message; + zval *property, *value, *initalized, *name, *data; + zval *session; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &message, &type, &time); - - PHALCON_INIT_VAR(formatter); - phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); + phalcon_fetch_params(1, 2, 0, &property, &value); - PHALCON_INIT_VAR(applied_format); - phalcon_call_method_p3_key(applied_format, formatter, "format", message, type, time, 3131886190UL); - if (Z_TYPE_P(applied_format) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "The formatted message is not valid"); - return; + PHALCON_OBS_VAR(initalized); + phalcon_read_property_this_quick(&initalized, this_ptr, SL("_initalized"), 4124099953UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(initalized)) { + phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); } - PHALCON_OBS_VAR(syslog_type); - phalcon_array_fetch_long(&syslog_type, applied_format, 0, PH_NOISY); + phalcon_update_property_array(this_ptr, SL("_data"), property, value TSRMLS_CC); - PHALCON_OBS_VAR(syslog_message); - phalcon_array_fetch_long(&syslog_message, applied_format, 1, PH_NOISY); - phalcon_call_func_p2_noret("syslog", syslog_type, syslog_message); + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(session); + phalcon_read_property_this_quick(&session, this_ptr, SL("_session"), 3241463720UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, session, "set", name, data, 2090720177UL); PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, close){ - zval *opened; +static PHP_METHOD(Phalcon_Session_Bag, get){ + + zval *property, *default_value = NULL, *initalized; + zval *data, *value; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(opened); - phalcon_read_property_this_quick(&opened, this_ptr, SL("_opened"), 2504335039UL, PH_NOISY_CC); - if (zend_is_true(opened)) { - phalcon_call_func_noret("closelog"); + phalcon_fetch_params(1, 1, 1, &property, &default_value); + + if (!default_value) { + PHALCON_INIT_VAR(default_value); } - PHALCON_MM_RESTORE(); + PHALCON_OBS_VAR(initalized); + phalcon_read_property_this_quick(&initalized, this_ptr, SL("_initalized"), 4124099953UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(initalized)) { + phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); + } + + PHALCON_OBS_VAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + if (phalcon_array_isset(data, property)) { + + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, data, property, PH_NOISY); + if (PHALCON_IS_NOT_EMPTY(value)) { + RETURN_CCTOR(value); + } + } + + RETURN_CCTOR(default_value); } +static PHP_METHOD(Phalcon_Session_Bag, has){ + zval *property, *initalized, *data; + PHALCON_MM_GROW(); -#ifdef HAVE_CONFIG_H -#endif + phalcon_fetch_params(1, 1, 0, &property); + + PHALCON_OBS_VAR(initalized); + phalcon_read_property_this_quick(&initalized, this_ptr, SL("_initalized"), 4124099953UL, PH_NOISY_CC); + if (PHALCON_IS_FALSE(initalized)) { + phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); + } + + PHALCON_OBS_VAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + if (phalcon_array_isset(data, property)) { + RETURN_MM_TRUE; + } + + RETURN_MM_FALSE; +} + + +static PHP_METHOD(Phalcon_Session_Bag, remove){ + + zval *property, *data = NULL, *name, *session; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 0, &property); + + PHALCON_OBS_VAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + if (phalcon_array_isset(data, property)) { + phalcon_unset_property_array(this_ptr, SL("_data"), property TSRMLS_CC); + + PHALCON_OBS_NVAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); + + PHALCON_OBS_VAR(session); + phalcon_read_property_this_quick(&session, this_ptr, SL("_session"), 3241463720UL, PH_NOISY_CC); + phalcon_call_method_p2_key(NULL, session, "set", name, data, 2090720177UL); + RETURN_MM_TRUE; + } + + RETURN_MM_FALSE; +} +#ifdef HAVE_CONFIG_H +#endif -PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_Firephp){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, Firephp, logger_adapter_firephp, "phalcon\\logger\\adapter", phalcon_logger_adapter_firephp_method_entry, 0); - zend_declare_property_bool(phalcon_logger_adapter_firephp_ce, SL("_initialized"), 0, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_long(phalcon_logger_adapter_firephp_ce, SL("_index"), 1, ZEND_ACC_PRIVATE | ZEND_ACC_STATIC TSRMLS_CC); +PHALCON_INIT_CLASS(Phalcon_Session_BagInterface){ - zend_class_implements(phalcon_logger_adapter_firephp_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + PHALCON_REGISTER_INTERFACE(Phalcon\\Session, BagInterface, session_baginterface, phalcon_session_baginterface_method_entry); return SUCCESS; } -static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, getFormatter){ - zval *formatter = NULL; - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(formatter); - phalcon_read_property_this_quick(&formatter, this_ptr, SL("_formatter"), 1838243768UL, PH_NOISY_CC); - if (Z_TYPE_P(formatter) != IS_OBJECT) { - /* This will update $this->_formatter, no need to call phalcon_update_property_this() explicitly */ - object_init_ex(formatter, phalcon_logger_formatter_firephp_ce); - } - RETURN_CCTOR(formatter); -} -static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, logInternal){ - zval *message, *type, *time, *formatter, *applied_format; - zval *initialized, *index; - sapi_header_line h = { NULL, 0, 0 }; - smart_str str = { NULL, 0, 0 }; - int size, offset, num_bytes; - const int chunk = 4960; - /* If headers has already been sent, we can do nothing. Exit early. */ - if (SG(headers_sent)) { - RETURN_FALSE; - } - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &message, &type, &time); - PHALCON_INIT_VAR(formatter); - phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); - PHALCON_OBS_VAR(initialized); - phalcon_read_static_property(&initialized, SL("phalcon\\logger\\adapter\\firephp"), SL("_initialized") TSRMLS_CC); - if (!zend_is_true(initialized)) { - h.line = "X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2"; - h.line_len = sizeof("X-Wf-Protocol-1: http://meta.wildfirehq.org/Protocol/JsonStream/0.2")-1; - sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC); - h.line = "X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3"; - h.line_len = sizeof("X-Wf-1-Plugin-1: http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3")-1; - sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC); +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Session_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Session, Exception, session_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + - h.line = "X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1"; - h.line_len = sizeof("X-Wf-1-Structure-1: http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1")-1; - sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC); - ZVAL_TRUE(initialized); /* This will also update the property because "initialized" was not separated */ - } - PHALCON_INIT_VAR(applied_format); - phalcon_call_method_p3_key(applied_format, formatter, "format", message, type, time, 3131886190UL); - if (Z_TYPE_P(applied_format) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "The formatted message is not valid"); - return; - } - PHALCON_OBS_VAR(index); - phalcon_read_static_property(&index, SL("phalcon\\logger\\adapter\\firephp"), SL("_index") TSRMLS_CC); +PHALCON_INIT_CLASS(Phalcon_Session){ - size = Z_STRLEN_P(applied_format); - offset = 0; + PHALCON_REGISTER_CLASS(Phalcon, Session, session, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - smart_str_alloc4(&str, (size > chunk ? chunk : size), 0, num_bytes); + return SUCCESS; +} - while (size > 0) { - smart_str_appends(&str, "X-Wf-1-1-1-"); - smart_str_append_long(&str, Z_LVAL_P(index)); - smart_str_appends(&str, ": "); - num_bytes = size > chunk ? chunk : size; - if (offset) { - /* This is not the first chunk, prepend the payload with "|" */ - smart_str_appendc(&str, '|'); - } - /* Grab the chunk from the encoded string */ - smart_str_appendl(&str, Z_STRVAL_P(applied_format) + offset, num_bytes); - size -= num_bytes; - offset += num_bytes; - if (size) { - /* If we have more data to send, append "|/" */ - smart_str_appendl(&str, "|\\", 2); - } +#ifdef HAVE_CONFIG_H +#endif - smart_str_0(&str); /* Not strictly necessary but just to be safe */ - /* Send the result */ - h.line = str.c; - h.line_len = str.len; - sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC); - /* Update header index; this will update Phalcon\Logger\Adapter\Firephp as well */ - ZVAL_LONG(index, Z_LVAL_P(index)+1); - str.len = 0; - } - /* Deallocate the smnart string if it is not empty */ - if (str.c) { - smart_str_free(&str); - } - PHALCON_MM_RESTORE(); -} +PHALCON_INIT_CLASS(Phalcon_Tag_Exception){ -static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, close){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Tag, Exception, tag_exception, "phalcon\\exception", NULL, 0); - RETURN_TRUE; + return SUCCESS; } @@ -95290,1528 +95926,1781 @@ static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, close){ -PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_File){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, File, logger_adapter_file, "phalcon\\logger\\adapter", phalcon_logger_adapter_file_method_entry, 0); - - zend_declare_property_null(phalcon_logger_adapter_file_ce, SL("_fileHandler"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_logger_adapter_file_ce, SL("_path"), ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_logger_adapter_file_ce, SL("_options"), ZEND_ACC_PROTECTED TSRMLS_CC); +PHALCON_INIT_CLASS(Phalcon_Tag_Select){ - zend_class_implements(phalcon_logger_adapter_file_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + PHALCON_REGISTER_CLASS(Phalcon\\Tag, Select, tag_select, phalcon_tag_select_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); return SUCCESS; } -static PHP_METHOD(Phalcon_Logger_Adapter_File, __construct){ +static PHP_METHOD(Phalcon_Tag_Select, selectField){ - zval *name, *options = NULL, *mode = NULL, *handler, *exception_message; + zval *parameters, *data = NULL, *params = NULL, *eol, *id = NULL, *name, *value = NULL; + zval *use_empty = NULL, *empty_value = NULL, *empty_text = NULL, *code; + zval *avalue = NULL, *key = NULL, *close_option, *options = NULL, *using; + zval *resultset_options, *array_options; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, &options); + phalcon_fetch_params(1, 1, 1, ¶meters, &data); - if (!options) { - PHALCON_INIT_VAR(options); + if (!data) { + PHALCON_INIT_VAR(data); } - if (phalcon_array_isset_quick_string(options, SS("mode"), 267518858UL)) { + if (Z_TYPE_P(parameters) != IS_ARRAY) { + PHALCON_INIT_VAR(params); + array_init_size(params, 2); + phalcon_array_append(¶ms, parameters, PH_SEPARATE); + phalcon_array_append(¶ms, data, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(params, parameters); + } - PHALCON_OBS_VAR(mode); - phalcon_array_fetch_quick_string(&mode, options, SS("mode"), 267518858UL, PH_NOISY); - if (phalcon_memnstr_str(mode, SL("r"))) { - PHALCON_THROW_EXCEPTION_STR(phalcon_logger_exception_ce, "Logger must be opened in append or write mode"); - return; + PHALCON_INIT_VAR(eol); + ZVAL_STRING(eol, PHP_EOL, 1); + if (!phalcon_array_isset_long(params, 0)) { + PHALCON_OBS_VAR(id); + phalcon_array_fetch_quick_string(&id, params, SS("id"), 193494642UL, PH_NOISY); + phalcon_array_update_long(¶ms, 0, &id, PH_COPY | PH_SEPARATE); + } + + PHALCON_OBS_NVAR(id); + phalcon_array_fetch_long(&id, params, 0, PH_NOISY); + if (!phalcon_array_isset_quick_string(params, SS("name"), 268211462UL)) { + phalcon_array_update_quick_string(¶ms, SS("name"), 268211462UL, &id, PH_COPY | PH_SEPARATE); + } else { + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, params, SS("name"), 268211462UL, PH_NOISY); + if (!zend_is_true(name)) { + phalcon_array_update_quick_string(¶ms, SS("name"), 268211462UL, &id, PH_COPY | PH_SEPARATE); + } + } + + if (!phalcon_memnstr_str(id, SL("["))) { + if (!phalcon_array_isset_quick_string(params, SS("id"), 193494642UL)) { + phalcon_array_update_quick_string(¶ms, SS("id"), 193494642UL, &id, PH_COPY | PH_SEPARATE); } + } + + if (!phalcon_array_isset_quick_string(params, SS("value"), 574111618UL)) { + PHALCON_INIT_VAR(value); + PHALCON_CALL_STATIC_PARAMS_2(value, "phalcon\\tag", "getvalue", id, params); } else { - PHALCON_INIT_NVAR(mode); - ZVAL_STRING(mode, "ab", 1); + PHALCON_OBS_NVAR(value); + phalcon_array_fetch_quick_string(&value, params, SS("value"), 574111618UL, PH_NOISY); + phalcon_array_unset_string(¶ms, SS("value"), PH_SEPARATE); } - PHALCON_INIT_VAR(handler); - phalcon_call_func_p2(handler, "fopen", name, mode); - if (!zend_is_true(handler)) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Can't open log file at '", name, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_logger_exception_ce, exception_message); - return; + PHALCON_INIT_VAR(use_empty); + ZVAL_BOOL(use_empty, 0); + if (phalcon_array_isset_quick_string(params, SS("useEmpty"), 1479578401UL)) { + if (!phalcon_array_isset_quick_string(params, SS("emptyValue"), 2008930769UL)) { + PHALCON_INIT_VAR(empty_value); + ZVAL_STRING(empty_value, "", 1); + } else { + PHALCON_OBS_NVAR(empty_value); + phalcon_array_fetch_quick_string(&empty_value, params, SS("emptyValue"), 2008930769UL, PH_NOISY); + phalcon_array_unset_string(¶ms, SS("emptyValue"), PH_SEPARATE); + } + if (!phalcon_array_isset_quick_string(params, SS("emptyText"), 3312424633UL)) { + PHALCON_INIT_VAR(empty_text); + ZVAL_STRING(empty_text, "Choose...", 1); + } else { + PHALCON_OBS_NVAR(empty_text); + phalcon_array_fetch_quick_string(&empty_text, params, SS("emptyText"), 3312424633UL, PH_NOISY); + phalcon_array_unset_string(¶ms, SS("emptyText"), PH_SEPARATE); + } + + PHALCON_OBS_NVAR(use_empty); + phalcon_array_fetch_quick_string(&use_empty, params, SS("useEmpty"), 1479578401UL, PH_NOISY); + phalcon_array_unset_string(¶ms, SS("useEmpty"), PH_SEPARATE); } - phalcon_update_property_this_quick(this_ptr, SL("_path"), name, 3986357393UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_fileHandler"), handler, 1678121186UL TSRMLS_CC); + PHALCON_INIT_VAR(code); + ZVAL_STRING(code, "", eol); + + PHALCON_INIT_VAR(close_option); + PHALCON_CONCAT_SV(close_option, "", eol); + if (zend_is_true(use_empty)) { + PHALCON_SCONCAT_SVSVV(code, "\t", eol); - if (zend_is_true(use_empty)) { - PHALCON_SCONCAT_SVSVV(code, "\t