From 5791b3648d04a3f7d5d2e7436cff0f18311202e6 Mon Sep 17 00:00:00 2001 From: Nikolaos Dimopoulos Date: Tue, 6 Aug 2013 10:00:52 -0400 Subject: [PATCH] Regenerated compile files --- build/32bits/phalcon.c | 180748 +++++++++++--------------------------- build/64bits/phalcon.c | 180748 +++++++++++--------------------------- build/safe/phalcon.c | 180748 +++++++++++--------------------------- 3 files changed, 160956 insertions(+), 381288 deletions(-) diff --git a/build/32bits/phalcon.c b/build/32bits/phalcon.c index 40899c3850f..c58a72db824 100644 --- a/build/32bits/phalcon.c +++ b/build/32bits/phalcon.c @@ -12114,7 +12114,6 @@ static PHP_METHOD(Phalcon_Escaper, escapeHtmlAttr){ PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &attribute); -<<<<<<< HEAD if (Z_TYPE_P(attribute) == IS_STRING) { if (zend_is_true(attribute)) { @@ -12130,59 +12129,6 @@ static PHP_METHOD(Phalcon_Escaper, escapeHtmlAttr){ RETURN_CCTOR(attribute); } -static PHP_METHOD(Phalcon_Escaper, escapeCss){ - - zval *css, *normalized; -======= - - 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); ->>>>>>> 1.2.2 - - phalcon_escape_htmlattr(return_value, normalized); - RETURN_MM(); - } - } - -<<<<<<< HEAD - 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(); - } - } - - 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_CCTOR(attribute); -} - static PHP_METHOD(Phalcon_Escaper, escapeCss){ zval *css, *normalized; @@ -12198,43 +12144,10 @@ static PHP_METHOD(Phalcon_Escaper, escapeCss){ phalcon_call_method_p1_key(normalized, this_ptr, "normalizeencoding", css, 3216085085UL); phalcon_escape_css(return_value, normalized); ->>>>>>> 1.2.2 RETURN_MM(); } } -<<<<<<< HEAD - 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_Events_EventsAwareInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Events, EventsAwareInterface, events_eventsawareinterface, phalcon_events_eventsawareinterface_method_entry); - - return SUCCESS; -} - - -======= RETURN_CCTOR(css); } @@ -12269,7 +12182,6 @@ static PHP_METHOD(Phalcon_Escaper, escapeUrl){ phalcon_raw_url_encode(return_value, url); return; } ->>>>>>> 1.2.2 @@ -12280,15 +12192,9 @@ static PHP_METHOD(Phalcon_Escaper, escapeUrl){ -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Events_ManagerInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Events, ManagerInterface, events_managerinterface, phalcon_events_managerinterface_method_entry); -======= PHALCON_INIT_CLASS(Phalcon_Events_EventsAwareInterface){ PHALCON_REGISTER_INTERFACE(Phalcon\\Events, EventsAwareInterface, events_eventsawareinterface, phalcon_events_eventsawareinterface_method_entry); ->>>>>>> 1.2.2 return SUCCESS; } @@ -12299,8 +12205,6 @@ PHALCON_INIT_CLASS(Phalcon_Events_EventsAwareInterface){ -<<<<<<< HEAD -======= #ifdef HAVE_CONFIG_H #endif @@ -12319,7 +12223,6 @@ PHALCON_INIT_CLASS(Phalcon_Events_ManagerInterface){ ->>>>>>> 1.2.2 #ifdef HAVE_CONFIG_H @@ -12580,10 +12483,6 @@ static PHP_METHOD(Phalcon_Events_Manager, isCollecting){ RETURN_MEMBER_QUICK(this_ptr, "_collect", 3993548138UL); } -<<<<<<< HEAD - -static PHP_METHOD(Phalcon_Events_Manager, getResponses){ -======= static PHP_METHOD(Phalcon_Events_Manager, getResponses){ @@ -12596,7 +12495,6 @@ static PHP_METHOD(Phalcon_Events_Manager, dettachAll){ zval *type = NULL, *events = NULL, *null_value; PHALCON_MM_GROW(); ->>>>>>> 1.2.2 phalcon_fetch_params(1, 0, 1, &type); @@ -12620,37 +12518,6 @@ static PHP_METHOD(Phalcon_Events_Manager, dettachAll){ PHALCON_MM_RESTORE(); } -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_responses", 77555686UL); -} - -static PHP_METHOD(Phalcon_Events_Manager, dettachAll){ - - zval *type = NULL, *events = NULL, *null_value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &type); - - if (!type) { - PHALCON_INIT_VAR(type); - } - - 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_update_property_this_quick(this_ptr, SL("_events"), events, 2709386425UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -======= static PHP_METHOD(Phalcon_Events_Manager, fireQueue){ zval *queue, *event, *status = NULL, *arguments = NULL, *event_name; @@ -12962,202 +12829,12 @@ static PHP_METHOD(Phalcon_Events_Manager, getListeners){ } RETURN_MM_EMPTY_ARRAY(); ->>>>>>> 1.2.2 } -static PHP_METHOD(Phalcon_Events_Manager, fireQueue){ - - 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, 2, 0, &queue, &event); - - 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; - } - - 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; - } - - 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); - - 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_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)) { - } else { - break; - } - - PHALCON_INIT_NVAR(handler); - phalcon_call_method_key(handler, iterator, "current", 431662984UL); - - 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); - } - - 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(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); - } - - 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; - } - } - } - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - RETURN_CCTOR(status); -} -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Events_Manager, fire){ - 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(); -======= #ifdef HAVE_CONFIG_H #endif @@ -13169,140 +12846,19 @@ static PHP_METHOD(Phalcon_Events_Manager, fire){ PHALCON_INIT_CLASS(Phalcon_Events_Exception){ PHALCON_REGISTER_CLASS_EX(Phalcon\\Events, Exception, events_exception, "phalcon\\exception", NULL, 0); ->>>>>>> 1.2.2 - 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_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); + return SUCCESS; } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Events_Manager, hasListeners){ - - zval *type, *events; -======= - ->>>>>>> 1.2.2 -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 0, &type); - - 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_Events_Manager, getListeners){ - - zval *type, *events, *fire_events; -======= #ifdef HAVE_CONFIG_H #endif ->>>>>>> 1.2.2 -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 0, &type); - - 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_EMPTY_ARRAY(); -} -======= ->>>>>>> 1.2.2 @@ -13323,11 +12879,7 @@ PHALCON_INIT_CLASS(Phalcon_Acl){ #ifdef HAVE_CONFIG_H #endif -PHALCON_INIT_CLASS(Phalcon_Events_Exception){ -<<<<<<< HEAD - PHALCON_REGISTER_CLASS_EX(Phalcon\\Events, Exception, events_exception, "phalcon\\exception", NULL, 0); -======= @@ -13335,7 +12887,6 @@ PHALCON_INIT_CLASS(Phalcon_Events_Exception){ PHALCON_INIT_CLASS(Phalcon_CLI_Dispatcher_Exception){ PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Dispatcher, Exception, cli_dispatcher_exception, "phalcon\\exception", NULL, 0); ->>>>>>> 1.2.2 return SUCCESS; } @@ -13352,18 +12903,9 @@ PHALCON_INIT_CLASS(Phalcon_CLI_Dispatcher_Exception){ -<<<<<<< HEAD -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); -======= PHALCON_INIT_CLASS(Phalcon_CLI_Console_Exception){ PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Console, Exception, cli_console_exception, "phalcon\\exception", NULL, 0); ->>>>>>> 1.2.2 return SUCCESS; } @@ -13380,11 +12922,7 @@ PHALCON_INIT_CLASS(Phalcon_CLI_Console_Exception){ -PHALCON_INIT_CLASS(Phalcon_CLI_Dispatcher_Exception){ -<<<<<<< HEAD - PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Dispatcher, Exception, cli_dispatcher_exception, "phalcon\\exception", NULL, 0); -======= PHALCON_INIT_CLASS(Phalcon_CLI_Router){ PHALCON_REGISTER_CLASS(Phalcon\\CLI, Router, cli_router, phalcon_cli_router_method_entry, 0); @@ -13400,22 +12938,10 @@ PHALCON_INIT_CLASS(Phalcon_CLI_Router){ 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); ->>>>>>> 1.2.2 return SUCCESS; } -<<<<<<< HEAD - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -======= static PHP_METHOD(Phalcon_CLI_Router, __construct){ @@ -13434,29 +12960,16 @@ static PHP_METHOD(Phalcon_CLI_Router, setDI){ phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); } ->>>>>>> 1.2.2 static PHP_METHOD(Phalcon_CLI_Router, getDI){ -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_CLI_Console_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Console, Exception, cli_console_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} - - - -======= RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } static PHP_METHOD(Phalcon_CLI_Router, setDefaultModule){ zval *module_name; ->>>>>>> 1.2.2 phalcon_fetch_params(0, 1, 0, &module_name); @@ -13464,23 +12977,10 @@ static PHP_METHOD(Phalcon_CLI_Router, setDefaultModule){ } -<<<<<<< HEAD -#ifdef HAVE_CONFIG_H -#endif -======= static PHP_METHOD(Phalcon_CLI_Router, setDefaultTask){ ->>>>>>> 1.2.2 zval *task_name; -<<<<<<< HEAD - - - - - -PHALCON_INIT_CLASS(Phalcon_CLI_Router){ -======= phalcon_fetch_params(0, 1, 0, &task_name); phalcon_update_property_this_quick(this_ptr, SL("_defaultTask"), task_name, 3852862556UL TSRMLS_CC); @@ -13500,33 +13000,9 @@ static PHP_METHOD(Phalcon_CLI_Router, setDefaultAction){ static PHP_METHOD(Phalcon_CLI_Router, handle){ zval *arguments = NULL, *module_name = NULL, *task_name = NULL, *action_name = NULL; ->>>>>>> 1.2.2 - - PHALCON_REGISTER_CLASS(Phalcon\\CLI, Router, cli_router, phalcon_cli_router_method_entry, 0); - -<<<<<<< HEAD - 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_MM_GROW(); - 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); -======= phalcon_fetch_params(1, 0, 1, &arguments); if (!arguments) { @@ -13569,27 +13045,13 @@ static PHP_METHOD(Phalcon_CLI_Router, __construct){ 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); ->>>>>>> 1.2.2 + PHALCON_MM_RESTORE(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_CLI_Router, setDI){ -======= static PHP_METHOD(Phalcon_CLI_Router, getModuleName){ ->>>>>>> 1.2.2 - - zval *dependency_injector; -<<<<<<< HEAD - 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, "_module", 4176304298UL); } @@ -13604,139 +13066,29 @@ static PHP_METHOD(Phalcon_CLI_Router, getActionName){ RETURN_MEMBER_QUICK(this_ptr, "_action", 1112512898UL); } ->>>>>>> 1.2.2 static PHP_METHOD(Phalcon_CLI_Router, getParams){ -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); + + RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); } -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; +#ifdef HAVE_CONFIG_H +#endif - 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; -======= - - RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_CLI_Task){ ->>>>>>> 1.2.2 +PHALCON_INIT_CLASS(Phalcon_CLI_Task){ PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI, Task, cli_task, "phalcon\\di\\injectable", phalcon_cli_task_method_entry, 0); -<<<<<<< HEAD - 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); -======= return SUCCESS; } @@ -13763,41 +13115,18 @@ PHALCON_INIT_CLASS(Phalcon_CLI_Router_Exception){ PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Router, Exception, cli_router_exception, "phalcon\\exception", NULL, 0); return SUCCESS; ->>>>>>> 1.2.2 } - #ifdef HAVE_CONFIG_H #endif -<<<<<<< HEAD - - -PHALCON_INIT_CLASS(Phalcon_CLI_Task){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI, Task, cli_task, "phalcon\\di\\injectable", phalcon_cli_task_method_entry, 0); -======= ->>>>>>> 1.2.2 - - -static PHP_METHOD(Phalcon_CLI_Task, __construct){ - - - -} - - - - -#ifdef HAVE_CONFIG_H -#endif PHALCON_INIT_CLASS(Phalcon_CLI_Console){ @@ -13811,19 +13140,10 @@ PHALCON_INIT_CLASS(Phalcon_CLI_Console){ zend_class_implements(phalcon_cli_console_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_events_eventsawareinterface_ce); -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_CLI_Router_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\CLI\\Router, Exception, cli_router_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} -======= return SUCCESS; } static PHP_METHOD(Phalcon_CLI_Console, __construct){ ->>>>>>> 1.2.2 zval *dependency_injector = NULL; @@ -13866,18 +13186,6 @@ static PHP_METHOD(Phalcon_CLI_Console, setEventsManager){ zval *events_manager; -<<<<<<< HEAD -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); -======= phalcon_fetch_params(0, 1, 0, &events_manager); phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); @@ -13886,94 +13194,22 @@ PHALCON_INIT_CLASS(Phalcon_CLI_Console){ static PHP_METHOD(Phalcon_CLI_Console, getEventsManager){ ->>>>>>> 1.2.2 RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_CLI_Console, __construct){ - - zval *dependency_injector = NULL; -======= static PHP_METHOD(Phalcon_CLI_Console, registerModules){ ->>>>>>> 1.2.2 zval *modules; -<<<<<<< HEAD - phalcon_fetch_params(1, 0, 1, &dependency_injector); - - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); -======= 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; ->>>>>>> 1.2.2 } phalcon_update_property_this_quick(this_ptr, SL("_modules"), modules, 379092157UL TSRMLS_CC); -<<<<<<< HEAD - 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); - -======= ->>>>>>> 1.2.2 } static PHP_METHOD(Phalcon_CLI_Console, addModules){ @@ -14031,126 +13267,6 @@ static PHP_METHOD(Phalcon_CLI_Console, handle){ PHALCON_OBS_VAR(events_manager); phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); -<<<<<<< HEAD - - 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; - } - } - - 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_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; - } - - 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; - } - } - - 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; - } - } - } - - 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); - } - -======= PHALCON_INIT_VAR(service); ZVAL_STRING(service, "router", 1); @@ -14269,7 +13385,6 @@ static PHP_METHOD(Phalcon_CLI_Console, handle){ phalcon_call_method_p3_key(NULL, events_manager, "fire", event_name, this_ptr, task, 259017035UL); } ->>>>>>> 1.2.2 RETURN_CCTOR(task); } @@ -14498,21 +13613,12 @@ static PHP_METHOD(Phalcon_Crypt, setMode){ else { Z_ADDREF_P(mode); } -<<<<<<< HEAD - - phalcon_update_property_this_quick(this_ptr, SL("_mode"), mode, 3983285225UL TSRMLS_CC); - zval_ptr_dtor(&mode); - RETURN_THISW(); -} - -======= phalcon_update_property_this_quick(this_ptr, SL("_mode"), mode, 3983285225UL TSRMLS_CC); zval_ptr_dtor(&mode); RETURN_THISW(); } ->>>>>>> 1.2.2 static PHP_METHOD(Phalcon_Crypt, getMode){ @@ -14599,7 +13705,6 @@ static void phalcon_crypt_pad_text(zval *return_value, zval *text, zval *mode, u padding[padding_size-1] = (unsigned char)padding_size; break; -<<<<<<< HEAD case PHALCON_CRYPT_PADDING_ISO_IEC_7816_4: padding[0] = 0x80; @@ -14739,147 +13844,6 @@ static PHP_METHOD(Phalcon_Crypt, encrypt){ phalcon_fetch_params(1, 1, 1, &source, &key); -======= - - case PHALCON_CRYPT_PADDING_ISO_IEC_7816_4: - padding[0] = 0x80; - memset(padding + 1, 0, padding_size - 1); - break; - - case PHALCON_CRYPT_PADDING_ZERO: - memset(padding, 0, padding_size); - break; - - case PHALCON_CRYPT_PADDING_SPACE: - memset(padding, 0x20, padding_size); - break; - - default: - padding_size = 0; - break; - } - } - - if (!padding_size) { - ZVAL_ZVAL(return_value, text, 1, 0); - } - else { - assert(padding_size <= block_size); - phalcon_concat_vs(&return_value, text, padding, padding_size, 0 TSRMLS_CC); - } -} - -static void phalcon_crypt_unpad_text(zval *return_value, zval *text, zval *mode, uint block_size, int padding_type TSRMLS_DC) -{ - uint padding_size; - char padding[256]; - int i; - char *str_mode; - char *str_text; - int text_len; - - assert(Z_TYPE_P(text) == IS_STRING); - assert(Z_TYPE_P(mode) == IS_STRING); - - padding_size = 0; - str_mode = Z_STRVAL_P(mode); - str_text = Z_STRVAL_P(text); - text_len = Z_STRLEN_P(text); - - if (text_len && (text_len % block_size == 0) && (!strcmp(str_mode, "ecb") || !strcmp(str_mode, "cbc"))) { - switch (padding_type) { - case PHALCON_CRYPT_PADDING_ANSI_X_923: - if (str_text[text_len-1] <= block_size) { - padding_size = str_text[text_len-1]; - - memset(padding, 0, padding_size - 1); - padding[padding_size-1] = (unsigned char)padding_size; - - if (memcmp(padding, str_text + text_len - padding_size, padding_size)) { - padding_size = 0; - } - } - - break; - - case PHALCON_CRYPT_PADDING_PKCS7: - if (str_text[text_len-1] <= block_size) { - padding_size = str_text[text_len-1]; - - memset(padding, padding_size, padding_size); - - if (memcmp(padding, str_text + text_len - padding_size, padding_size)) { - padding_size = 0; - } - } - - break; - - case PHALCON_CRYPT_PADDING_ISO_10126: - padding_size = str_text[text_len-1]; - break; - - case PHALCON_CRYPT_PADDING_ISO_IEC_7816_4: - i = text_len - 1; - while (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; - } - - break; - - case PHALCON_CRYPT_PADDING_SPACE: - i = text_len - 1; - while (i >= 0 && str_text[i] == 0x20 && padding_size <= block_size) { - ++padding_size; - --i; - } - - break; - - default: - break; - } - - 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_Crypt, encrypt){ - - 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, 1, &source, &key); - ->>>>>>> 1.2.2 /* 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); @@ -15602,7 +14566,6 @@ static PHP_METHOD(Phalcon_Http_Cookie, setExpiration){ } static PHP_METHOD(Phalcon_Http_Cookie, getExpiration){ -<<<<<<< HEAD zval *restored, *expire; @@ -15682,114 +14645,12 @@ static PHP_METHOD(Phalcon_Http_Cookie, getDomain){ PHALCON_MM_GROW(); -======= - - 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_OBS_VAR(expire); - phalcon_read_property_this_quick(&expire, this_ptr, SL("_expire"), 2800520017UL, PH_NOISY_CC); - - RETURN_CCTOR(expire); -} - -static PHP_METHOD(Phalcon_Http_Cookie, setPath){ - - zval *path, *restored; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &path); - - 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("_path"), path, 3986357393UL TSRMLS_CC); - - 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_OBS_VAR(path); - phalcon_read_property_this_quick(&path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_CC); - - RETURN_CCTOR(path); -} - -static PHP_METHOD(Phalcon_Http_Cookie, setDomain){ - - zval *domain, *restored; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &domain); - - 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("_domain"), domain, 1152978748UL TSRMLS_CC); - - 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(domain); - phalcon_read_property_this_quick(&domain, this_ptr, SL("_domain"), 1152978748UL, PH_NOISY_CC); - - RETURN_CCTOR(domain); -} - -static PHP_METHOD(Phalcon_Http_Cookie, setSecure){ - - zval *secure, *restored; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &secure); - ->>>>>>> 1.2.2 - 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); - } - -<<<<<<< HEAD PHALCON_OBS_VAR(domain); phalcon_read_property_this_quick(&domain, this_ptr, SL("_domain"), 1152978748UL, PH_NOISY_CC); @@ -15804,26 +14665,12 @@ static PHP_METHOD(Phalcon_Http_Cookie, setSecure){ phalcon_fetch_params(1, 1, 0, &secure); -======= - phalcon_update_property_this_quick(this_ptr, SL("_secure"), secure, 2942644203UL TSRMLS_CC); - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Http_Cookie, getSecure){ - - zval *restored, *secure; - - PHALCON_MM_GROW(); - ->>>>>>> 1.2.2 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); } -<<<<<<< HEAD phalcon_update_property_this_quick(this_ptr, SL("_secure"), secure, 2942644203UL TSRMLS_CC); RETURN_THIS(); @@ -15835,29 +14682,12 @@ static PHP_METHOD(Phalcon_Http_Cookie, getSecure){ PHALCON_MM_GROW(); -======= - PHALCON_OBS_VAR(secure); - phalcon_read_property_this_quick(&secure, this_ptr, SL("_secure"), 2942644203UL, PH_NOISY_CC); - - 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); - ->>>>>>> 1.2.2 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); } -<<<<<<< HEAD PHALCON_OBS_VAR(secure); phalcon_read_property_this_quick(&secure, this_ptr, SL("_secure"), 2942644203UL, PH_NOISY_CC); @@ -15872,26 +14702,12 @@ static PHP_METHOD(Phalcon_Http_Cookie, setHttpOnly){ phalcon_fetch_params(1, 1, 0, &http_only); -======= - phalcon_update_property_this_quick(this_ptr, SL("_httpOnly"), http_only, 41231174UL TSRMLS_CC); - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Http_Cookie, getHttpOnly){ - - zval *restored, *http_only; - - PHALCON_MM_GROW(); - ->>>>>>> 1.2.2 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); } -<<<<<<< HEAD phalcon_update_property_this_quick(this_ptr, SL("_httpOnly"), http_only, 41231174UL TSRMLS_CC); RETURN_THIS(); @@ -15947,46 +14763,6 @@ PHALCON_INIT_CLASS(Phalcon_Http_Request_FileInterface){ return SUCCESS; } -======= - PHALCON_OBS_VAR(http_only); - phalcon_read_property_this_quick(&http_only, this_ptr, SL("_httpOnly"), 41231174UL, PH_NOISY_CC); - - RETURN_CCTOR(http_only); -} - -static PHP_METHOD(Phalcon_Http_Cookie, __toString){ - - zval *value = NULL; - - PHALCON_MM_GROW(); - - 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); - } - - RETURN_CCTOR(value); -} - - - - - -#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; -} - ->>>>>>> 1.2.2 @@ -16206,41 +14982,12 @@ PHALCON_INIT_CLASS(Phalcon_Http_Cookie_Exception){ #ifdef HAVE_CONFIG_H #endif -<<<<<<< HEAD -======= -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_Http_Response, __construct){ - - zval *content = NULL, *code = NULL, *status = NULL; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - - - - PHALCON_INIT_CLASS(Phalcon_Http_Response){ PHALCON_REGISTER_CLASS(Phalcon\\Http, Response, http_response, phalcon_http_response_method_entry, 0); @@ -16263,8 +15010,6 @@ static PHP_METHOD(Phalcon_Http_Response, __construct){ PHALCON_MM_GROW(); -======= ->>>>>>> 1.2.2 phalcon_fetch_params(1, 0, 3, &content, &code, &status); if (!content) { @@ -17182,50 +15927,6 @@ static PHP_METHOD(Phalcon_Http_Response_Cookies, set){ if (zend_is_true(encryption)) { phalcon_call_method_p1_key(NULL, cookie, "useencryption", encryption, 603643197UL); -<<<<<<< HEAD - } - - 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_OBS_VAR(registered); - phalcon_read_property_this_quick(®istered, this_ptr, SL("_registered"), 3990603890UL, PH_NOISY_CC); - if (PHALCON_IS_FALSE(registered)) { - - 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_VAR(service); - ZVAL_STRING(service, "response", 1); - - PHALCON_INIT_VAR(response); - phalcon_call_method_p1_key(response, dependency_injector, "getshared", service, 1727570332UL); - - phalcon_call_method_p1_key(NULL, response, "setcookies", this_ptr, 4249583934UL); - } - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Http_Response_Cookies, get){ - - zval *name, *cookies, *cookie = NULL, *dependency_injector; - zval *encryption; -======= } phalcon_update_property_array(this_ptr, SL("_cookies"), name, cookie TSRMLS_CC); @@ -17335,52 +16036,6 @@ static PHP_METHOD(Phalcon_Http_Response_Cookies, has){ static PHP_METHOD(Phalcon_Http_Response_Cookies, delete){ zval *name, *cookies, *cookie; ->>>>>>> 1.2.2 - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); - -<<<<<<< HEAD - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_http_cookie_exception_ce, "The cookie name must be string"); - return; - } - - 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_INIT_NVAR(cookie); - object_init_ex(cookie, phalcon_http_cookie_ce); - phalcon_call_method_p1_key(NULL, cookie, "__construct", name, 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_call_method_p1_key(NULL, cookie, "setdi", dependency_injector, 461718238UL); - - PHALCON_OBS_VAR(encryption); - phalcon_read_property_this_quick(&encryption, this_ptr, SL("_useEncryption"), 2628069468UL, PH_NOISY_CC); - - if (zend_is_true(encryption)) { - phalcon_call_method_p1_key(NULL, cookie, "useencryption", encryption, 603643197UL); - } - } - - phalcon_update_property_array(this_ptr, SL("_cookies"), name, cookie TSRMLS_CC); - - RETURN_CCTOR(cookie); -} - -static PHP_METHOD(Phalcon_Http_Response_Cookies, has){ - - zval *name, *cookies, *_COOKIE; PHALCON_MM_GROW(); @@ -17389,67 +16044,6 @@ static PHP_METHOD(Phalcon_Http_Response_Cookies, has){ PHALCON_OBS_VAR(cookies); phalcon_read_property_this_quick(&cookies, this_ptr, SL("_cookies"), 4109914289UL, PH_NOISY_CC); - if (phalcon_array_isset(cookies, name)) { - RETURN_MM_TRUE; - } - - phalcon_get_global(&_COOKIE, SS("_COOKIE") TSRMLS_CC); - if (phalcon_array_isset(_COOKIE, name)) { - RETURN_MM_TRUE; - } - - 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); - - 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); - phalcon_call_method_key(NULL, cookie, "delete", 150213496UL); - RETURN_MM_TRUE; - } - - 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)) { - - PHALCON_OBS_VAR(cookies); - phalcon_read_property_this_quick(&cookies, this_ptr, SL("_cookies"), 4109914289UL, PH_NOISY_CC); - - phalcon_is_iterable(cookies, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(cookie); - - phalcon_call_method_key(NULL, cookie, "send", 274285871UL); - - zend_hash_move_forward_ex(ah0, &hp0); - } -======= - 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); @@ -17484,7 +16078,6 @@ static PHP_METHOD(Phalcon_Http_Response_Cookies, send){ zend_hash_move_forward_ex(ah0, &hp0); } ->>>>>>> 1.2.2 RETURN_MM_TRUE; } @@ -18070,179 +16663,6 @@ static PHP_METHOD(Phalcon_Http_Request, getHttpHost){ RETURN_MM(); } -<<<<<<< HEAD - -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 (!trust_forwarded_header) { - PHALCON_INIT_VAR(trust_forwarded_header); - ZVAL_BOOL(trust_forwarded_header, 0); - } - - PHALCON_INIT_VAR(address); - - 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); - } - } - - 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 (Z_TYPE_P(address) == IS_STRING) { - if (phalcon_memnstr_str(address, SL(","))) { - PHALCON_INIT_VAR(addresses); - phalcon_fast_explode_str(addresses, SL(","), address); - - PHALCON_OBS_VAR(first); - phalcon_array_fetch_long(&first, addresses, 0, PH_NOISY); - RETURN_CCTOR(first); - } - - RETURN_CCTOR(address); - } - - 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); - } - - return ""; - } - - 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); - } - - 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(user_agent); - ZVAL_STRING(user_agent, "", 1); - } - - RETURN_CCTOR(user_agent); -} - -static PHP_METHOD(Phalcon_Http_Request, isMethod){ - - 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_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_MM_GROW(); - - PHALCON_INIT_VAR(get); - ZVAL_STRING(get, "GET", 1); -======= static PHP_METHOD(Phalcon_Http_Request, getClientAddress){ @@ -18422,24 +16842,6 @@ static PHP_METHOD(Phalcon_Http_Request, isGet){ RETURN_MM(); } -static PHP_METHOD(Phalcon_Http_Request, isPut){ - - 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")); - } ->>>>>>> 1.2.2 - - PHALCON_INIT_VAR(method); - phalcon_call_method_key(method, this_ptr, "getmethod", 2473474950UL); - is_equal_function(return_value, method, get TSRMLS_CC); - -<<<<<<< HEAD - RETURN_MM(); -} - static PHP_METHOD(Phalcon_Http_Request, isPut){ zval *put, *method; @@ -18545,103 +16947,6 @@ static PHP_METHOD(Phalcon_Http_Request, isOptions){ RETURN_MM(); } -static int phalcon_http_request_hasfiles_helper(zval *arr, int only_successful) -{ -======= - 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); - - 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); - - 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); - - 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); - - 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); - - RETURN_MM(); -} - static int phalcon_http_request_hasfiles_helper(zval *arr, int only_successful) { HashTable *ah0; @@ -18671,41 +16976,10 @@ static int phalcon_http_request_hasfiles_helper(zval *arr, int only_successful) static PHP_METHOD(Phalcon_Http_Request, hasFiles){ zval *not_errored = NULL, *_FILES, *error = NULL; ->>>>>>> 1.2.2 HashTable *ah0; HashPosition hp0; zval **hd; int nfiles = 0; -<<<<<<< HEAD - - 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; -======= int only_successful; phalcon_fetch_params(0, 0, 1, ¬_errored); @@ -18842,35 +17116,10 @@ static PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ zval **hd; int only_successful; smart_str prefix = { NULL, 0, 0 }; ->>>>>>> 1.2.2 phalcon_fetch_params(0, 0, 1, ¬_errored); only_successful = not_errored ? phalcon_get_intval(not_errored) : 1; -<<<<<<< HEAD - - 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); -======= array_init(return_value); @@ -18926,109 +17175,10 @@ static PHP_METHOD(Phalcon_Http_Request, getUploadedFiles){ smart_str_appendc(&prefix, '.'); phalcon_http_request_getuploadedfiles_helper(&return_value, name, type, tmp_name, error, size, only_successful, &prefix TSRMLS_CC); ->>>>>>> 1.2.2 } } zend_hash_move_forward_ex(ah0, &hp0); -<<<<<<< HEAD - } - - 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); - - 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){ -======= } if (prefix.c) { @@ -19153,196 +17303,9 @@ static PHP_METHOD(Phalcon_Http_Request, _getBestQuality){ HashPosition hp0; zval **hd; long int i = 0; ->>>>>>> 1.2.2 - - 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 }; - -<<<<<<< HEAD - 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)) { - - 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); - } - - 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_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); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - 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_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(); -} -======= phalcon_fetch_params(1, 2, 0, &quality_parts, &name); PHALCON_INIT_VAR(quality); @@ -19480,222 +17443,33 @@ static PHP_METHOD(Phalcon_Http_Request, getBestLanguage){ #ifdef HAVE_CONFIG_H #endif ->>>>>>> 1.2.2 -static PHP_METHOD(Phalcon_Http_Request, _getBestQuality){ -<<<<<<< HEAD - 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_INIT_CLASS(Phalcon_Http_RequestInterface){ - 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); - } - } + PHALCON_REGISTER_INTERFACE(Phalcon\\Http, RequestInterface, http_requestinterface, phalcon_http_requestinterface_method_entry); - ++i; - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_CCTOR(selected_name); + return SUCCESS; } -static PHP_METHOD(Phalcon_Http_Request, getAcceptableContent){ - zval *accept_header, *quality_index; -======= -PHALCON_INIT_CLASS(Phalcon_Http_RequestInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Http, RequestInterface, http_requestinterface, phalcon_http_requestinterface_method_entry); ->>>>>>> 1.2.2 - PHALCON_MM_GROW(); - 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(); -} -static PHP_METHOD(Phalcon_Http_Request, getBestAccept){ -<<<<<<< HEAD - 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){ - - 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(); -} - -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_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(); -} -======= - - - - - - - - - - - - - - - ->>>>>>> 1.2.2 - - - - -<<<<<<< HEAD - -#ifdef HAVE_CONFIG_H -#endif -======= ->>>>>>> 1.2.2 -PHALCON_INIT_CLASS(Phalcon_Http_RequestInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Http, RequestInterface, http_requestinterface, phalcon_http_requestinterface_method_entry); - - return SUCCESS; -} - - - - - - -<<<<<<< HEAD -======= - - - - ->>>>>>> 1.2.2 - - - - - - - - -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; -} - - @@ -19711,45 +17485,17 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_RelationInterface){ -<<<<<<< HEAD -======= -#ifdef HAVE_CONFIG_H -#endif ->>>>>>> 1.2.2 - - - - - -<<<<<<< HEAD - -======= -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; ->>>>>>> 1.2.2 #ifdef HAVE_CONFIG_H #endif -<<<<<<< HEAD PHALCON_INIT_CLASS(Phalcon_Mvc_Model_RelationInterface){ @@ -19760,58 +17506,8 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_RelationInterface){ } -======= - 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; ->>>>>>> 1.2.2 -<<<<<<< HEAD @@ -19904,14 +17600,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, valid){ 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_OBS_VAR(type); phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); if (zend_is_true(type)) { @@ -20269,7 +17957,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, valid){ PHALCON_OBS_VAR(result); phalcon_read_property_this_quick(&result, this_ptr, SL("_result"), 1670144931UL, PH_NOISY_CC); if (PHALCON_IS_NOT_FALSE(result)) { ->>>>>>> 1.2.2 PHALCON_INIT_VAR(row); phalcon_call_method_p1_key(row, result, "fetch", result, 4247924303UL); } else { @@ -20279,181 +17966,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, valid){ } else { PHALCON_OBS_VAR(rows); phalcon_read_property_this_quick(&rows, this_ptr, SL("_rows"), 3989235983UL, PH_NOISY_CC); -<<<<<<< HEAD - 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; - } - - 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); - } - - 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); -======= if (Z_TYPE_P(rows) == IS_ARRAY) { PHALCON_INIT_NVAR(row); @@ -20606,98 +18118,10 @@ static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Simple, toArray){ break; } ->>>>>>> 1.2.2 zend_hash_move_forward_ex(ah0, &hp0); } -<<<<<<< HEAD - } - - 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_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); @@ -20809,7 +18233,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, unserialize){ 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); ->>>>>>> 1.2.2 PHALCON_MM_RESTORE(); } @@ -20830,409 +18253,57 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_ManagerInterface){ } -<<<<<<< HEAD -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); -======= ->>>>>>> 1.2.2 -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, __construct){ - zval *columns_types, *result, *cache = NULL, *fetch_assoc; -======= ->>>>>>> 1.2.2 -<<<<<<< HEAD - 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(); + + + + + + + + + + + + + + + + + + + +#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; } -======= ->>>>>>> 1.2.2 -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; -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model_Resultset_Complex, toArray){ -======= - - ->>>>>>> 1.2.2 - - 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){ - -<<<<<<< HEAD - 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; -======= - - - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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(); -} -======= ->>>>>>> 1.2.2 - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_ManagerInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, ManagerInterface, mvc_model_managerinterface, phalcon_mvc_model_managerinterface_method_entry); -======= -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); ->>>>>>> 1.2.2 - - return SUCCESS; -} -<<<<<<< HEAD -======= ->>>>>>> 1.2.2 - - - - -<<<<<<< HEAD -======= #ifdef HAVE_CONFIG_H #endif ->>>>>>> 1.2.2 @@ -21240,43 +18311,15 @@ PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query_StatusInterface){ -<<<<<<< HEAD - - -======= 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); ->>>>>>> 1.2.2 zend_class_implements(phalcon_mvc_model_query_status_ce TSRMLS_CC, 1, phalcon_mvc_model_query_statusinterface_ce); -<<<<<<< HEAD - - - - - - - - - - -#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; -} -======= return SUCCESS; } @@ -21321,7 +18364,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Status, success){ ->>>>>>> 1.2.2 #ifdef HAVE_CONFIG_H @@ -21333,13 +18375,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Status, success){ -<<<<<<< HEAD -#ifdef HAVE_CONFIG_H -#endif - - - -======= PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query_Lang){ PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\Query, Lang, mvc_model_query_lang, phalcon_mvc_model_query_lang_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); @@ -21364,69 +18399,16 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Lang, parsePHQL){ } RETURN_MM(); } ->>>>>>> 1.2.2 -<<<<<<< HEAD -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); -======= #ifdef HAVE_CONFIG_H #endif ->>>>>>> 1.2.2 - - zend_class_implements(phalcon_mvc_model_query_status_ce TSRMLS_CC, 1, phalcon_mvc_model_query_statusinterface_ce); - -<<<<<<< HEAD - 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); -======= @@ -21537,7 +18519,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, __construct){ } PHALCON_MM_RESTORE(); ->>>>>>> 1.2.2 } static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, setDI){ @@ -21571,12 +18552,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, columns){ RETURN_THISW(); } -<<<<<<< HEAD - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query_Lang){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\Query, Lang, mvc_model_query_lang, phalcon_mvc_model_query_lang_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); -======= static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getColumns){ @@ -21586,7 +18561,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getColumns){ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, from){ zval *models; ->>>>>>> 1.2.2 phalcon_fetch_params(0, 1, 0, &models); @@ -21594,475 +18568,119 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, from){ RETURN_THISW(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model_Query_Lang, parsePHQL){ +static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, addFrom){ - zval *phql; + zval *model, *alias = NULL, *models = NULL, *current_model = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &phql); + phalcon_fetch_params(1, 1, 1, &model, &alias); - if (Z_TYPE_P(phql) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "PHQL statement must be string"); - return; + if (!alias) { + PHALCON_INIT_VAR(alias); } - if (phql_parse_phql(return_value, phql TSRMLS_CC) == FAILURE) { - 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) { + 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); + } } - RETURN_MM(); + + 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){ -#ifdef HAVE_CONFIG_H -#endif - - - - - + zval *model, *conditions = NULL, *alias = NULL, *type = NULL, *join; + PHALCON_MM_GROW(); -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Query_Builder){ + 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(); +} - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\Query, Builder, mvc_model_query_builder, phalcon_mvc_model_query_builder_method_entry, 0); +static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, innerJoin){ - 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 *model, *conditions = NULL, *alias = NULL, *type, *join; - 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_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, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, leftJoin){ - 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 *model, *conditions = NULL, *alias = NULL, *type, *join; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, ¶ms, &dependency_injector); + phalcon_fetch_params(1, 1, 2, &model, &conditions, &alias); - 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); - } - } - - 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); - } - - 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); - } - - 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); - } - - 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); - } - - 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); - } - - 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); - } - - 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 (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_Model_Query_Builder, setDI){ -======= -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(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, rightJoin){ - - zval *model, *conditions = NULL, *alias = NULL, *type, *join; ->>>>>>> 1.2.2 - - zval *dependency_injector; - -<<<<<<< HEAD - 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 must be an Object"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getDI){ - -======= - 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; ->>>>>>> 1.2.2 - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, columns){ - - zval *columns; - - 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){ - - - RETURN_MEMBER_QUICK(this_ptr, "_columns", 4004520869UL); -} - -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 (!conditions) { + PHALCON_INIT_VAR(conditions); } if (!alias) { @@ -22130,18 +18748,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, where){ } phalcon_update_property_this_quick(this_ptr, SL("_conditions"), conditions, 3598010654UL TSRMLS_CC); -======= - 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) { @@ -22266,7 +18872,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orWhere){ } phalcon_update_property_this_quick(this_ptr, SL("_conditions"), new_conditions, 3598010654UL TSRMLS_CC); ->>>>>>> 1.2.2 if (Z_TYPE_P(bind_params) == IS_ARRAY) { @@ -22274,11 +18879,7 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orWhere){ 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); -<<<<<<< HEAD - phalcon_fast_array_merge(merged_params, ¤t_bind_params, &bind_params TSRMLS_CC); -======= phalcon_add_function(merged_params, bind_params, current_bind_params TSRMLS_CC); ->>>>>>> 1.2.2 } else { PHALCON_CPY_WRT(merged_params, bind_params); } @@ -22292,11 +18893,7 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orWhere){ 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); -<<<<<<< HEAD - phalcon_fast_array_merge(merged_types, ¤t_bind_types, &bind_types TSRMLS_CC); -======= phalcon_add_function(merged_types, bind_types, current_bind_types TSRMLS_CC); ->>>>>>> 1.2.2 } else { PHALCON_CPY_WRT(merged_types, bind_types); } @@ -22307,280 +18904,73 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orWhere){ RETURN_THIS(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, andWhere){ +static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, betweenWhere){ - 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; + 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, 1, 2, &conditions, &bind_params, &bind_types); - - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } - - 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_fetch_params(1, 3, 0, &expr, &minimum, &maximum); - phalcon_update_property_this_quick(this_ptr, SL("_conditions"), new_conditions, 3598010654UL TSRMLS_CC); + PHALCON_OBS_VAR(hidden_param); + phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); - if (Z_TYPE_P(bind_params) == IS_ARRAY) { + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); - 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_INIT_VAR(next_hidden_param); + phalcon_add_function(next_hidden_param, hidden_param, one TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_bindParams"), merged_params, 2293392709UL TSRMLS_CC); - } + PHALCON_INIT_VAR(minimum_key); + PHALCON_CONCAT_SV(minimum_key, "phb", hidden_param); - if (Z_TYPE_P(bind_types) == IS_ARRAY) { + PHALCON_INIT_VAR(maximum_key); + PHALCON_CONCAT_SV(maximum_key, "phb", next_hidden_param); - 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_INIT_VAR(conditions); + PHALCON_CONCAT_VSVSVS(conditions, expr, " BETWEEN :", minimum_key, ": AND :", maximum_key, ":"); - phalcon_update_property_this_quick(this_ptr, SL("_bindTypes"), merged_types, 514734038UL TSRMLS_CC); - } + 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, orWhere){ +static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, notBetweenWhere){ - 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; + 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, 1, 2, &conditions, &bind_params, &bind_types); + phalcon_fetch_params(1, 3, 0, &expr, &minimum, &maximum); - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } + PHALCON_OBS_VAR(hidden_param); + phalcon_read_property_this_quick(&hidden_param, this_ptr, SL("_hiddenParamNumber"), 3119958698UL, PH_NOISY_CC); - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); - PHALCON_OBS_VAR(current_conditions); - phalcon_read_property_this_quick(¤t_conditions, this_ptr, SL("_conditions"), 3598010654UL, PH_NOISY_CC); + PHALCON_INIT_VAR(next_hidden_param); + phalcon_add_function(next_hidden_param, hidden_param, one TSRMLS_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); - } + PHALCON_INIT_VAR(minimum_key); + PHALCON_CONCAT_SV(minimum_key, "phb", hidden_param); - phalcon_update_property_this_quick(this_ptr, SL("_conditions"), new_conditions, 3598010654UL TSRMLS_CC); + PHALCON_INIT_VAR(maximum_key); + PHALCON_CONCAT_SV(maximum_key, "phb", next_hidden_param); - 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(); -} - -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){ - - 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){ -======= -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){ - - 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(conditions); + PHALCON_CONCAT_VSVSVS(conditions, expr, " NOT BETWEEN :", minimum_key, ": AND :", maximum_key, ":"); PHALCON_INIT_VAR(bind_params); array_init_size(bind_params, 2); @@ -22653,73 +19043,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, inWhere){ } static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, notInWhere){ ->>>>>>> 1.2.2 - - 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); -<<<<<<< HEAD - PHALCON_CONCAT_VSVS(conditions, expr, " IN (", joined_keys, ")"); -======= - PHALCON_CONCAT_VSVS(conditions, expr, " NOT IN (", joined_keys, ")"); ->>>>>>> 1.2.2 - - 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(); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, notInWhere){ -======= -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getWhere){ ->>>>>>> 1.2.2 zval *expr, *values, *hidden_param, *bind_params; zval *bind_keys, *value = NULL, *key = NULL, *query_key = NULL, *joined_keys; @@ -22728,7 +19051,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getWhere){ HashPosition hp0; zval **hd; -<<<<<<< HEAD PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &expr, &values); @@ -22784,11 +19106,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getWhere){ RETURN_MEMBER_QUICK(this_ptr, "_conditions", 3598010654UL); } -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orderBy){ -======= - RETURN_MEMBER_QUICK(this_ptr, "_conditions", 3598010654UL); -} - static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orderBy){ zval *order_by; @@ -22800,42 +19117,8 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, orderBy){ } static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getOrderBy){ ->>>>>>> 1.2.2 - - zval *order_by; - -<<<<<<< HEAD - phalcon_fetch_params(0, 1, 0, &order_by); - - 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){ - - - RETURN_MEMBER_QUICK(this_ptr, "_order", 2681225856UL); -} -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, having){ - - zval *having; - - phalcon_fetch_params(0, 1, 0, &having); - - phalcon_update_property_this_quick(this_ptr, SL("_having"), having, 1486953825UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getHaving){ - - - RETURN_MEMBER_QUICK(this_ptr, "_having", 1486953825UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, limit){ -======= RETURN_MEMBER_QUICK(this_ptr, "_order", 2681225856UL); } @@ -22857,7 +19140,6 @@ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getHaving){ static PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, limit){ ->>>>>>> 1.2.2 zval *limit, *offset = NULL; PHALCON_MM_GROW(); @@ -23550,7 +19832,6 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { token->len = YYCURSOR - q; q = YYCURSOR; return 0; -<<<<<<< HEAD } // 170 "scanner.c" yy4: @@ -23576,11 +19857,6 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { } // 192 "scanner.c" yy6: -======= - } -// 170 "scanner.c" -yy4: ->>>>>>> 1.2.2 ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -23592,7 +19868,6 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case '6': case '7': case '8': -<<<<<<< HEAD case '9': goto yy282; default: goto yy7; } @@ -23608,21 +19883,6 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { yych = *(YYMARKER = ++YYCURSOR); switch (yych) { case '-': -======= - case '9': goto yy285; - default: goto yy5; - } -yy5: -// 353 "scanner.re" - { - token->opcode = PHQL_T_DOT; - return 0; - } -// 192 "scanner.c" -yy6: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { ->>>>>>> 1.2.2 case '0': case '1': case '2': @@ -23632,7 +19892,6 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case '6': case '7': case '8': -<<<<<<< HEAD case '9': case 'A': case 'B': @@ -24522,22 +20781,30 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'n': goto yy107; default: goto yy87; } -======= - case '9': goto yy282; - default: goto yy7; +yy102: + yych = *++YYCURSOR; + switch (yych) { + case 'O': + case 'o': goto yy103; + default: goto yy87; } -yy7: -// 448 "scanner.re" - { - status = PHQL_SCANNER_RETCODE_ERR; - break; - } -// 214 "scanner.c" -yy8: - yyaccept = 0; - yych = *(YYMARKER = ++YYCURSOR); +yy103: + yych = *++YYCURSOR; switch (yych) { - case '-': + 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': @@ -24574,6 +20841,7 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'X': case 'Y': case 'Z': + case '\\': case '_': case 'a': case 'b': @@ -24600,207 +20868,57 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'w': case 'x': case 'y': - case 'z': goto yy278; - default: goto yy9; - } -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; + case 'z': goto yy86; + default: goto yy106; } -yy11: -// 301 "scanner.re" +yy106: +// 231 "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; + token->opcode = PHQL_T_CROSS; return 0; } -// 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; - } -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: +// 1214 "scanner.c" +yy107: yych = *++YYCURSOR; switch (yych) { - case 'A': - case 'a': goto yy144; + case 'V': + case 'v': goto yy108; default: goto yy87; } -yy23: +yy108: 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; + case 'e': goto yy109; default: goto yy87; } -yy27: +yy109: yych = *++YYCURSOR; switch (yych) { - case 'A': - case 'a': goto yy100; - case 'O': - case 'o': goto yy101; case 'R': - case 'r': goto yy102; + case 'r': goto yy110; default: goto yy87; } -yy28: +yy110: yych = *++YYCURSOR; switch (yych) { - case 'R': - case 'r': goto yy96; + case 'T': + case 't': goto yy111; 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) { +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': @@ -24827,6 +20945,7 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'X': case 'Y': case 'Z': + case '\\': case '_': case 'a': case 'b': @@ -24854,15 +20973,35 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy7; + default: goto yy112; } -yy32: +yy112: +// 271 "scanner.re" + { + token->opcode = PHQL_T_CONVERT; + return 0; + } +// 1318 "scanner.c" +yy113: yych = *++YYCURSOR; - goto yy87; -yy33: - yyaccept = 1; - yych = *(YYMARKER = ++YYCURSOR); switch (yych) { + case 'T': + case 't': goto yy114; + default: goto yy87; + } +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': @@ -24916,222 +21055,40 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { 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; - } -// 664 "scanner.c" -yy50: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '=': goto yy79; - default: goto yy51; + case 'z': goto yy86; + default: goto yy115; } -yy51: -// 413 "scanner.re" +yy115: +// 266 "scanner.re" { - token->opcode = PHQL_T_NOT; + token->opcode = PHQL_T_CAST; return 0; } -// 677 "scanner.c" -yy52: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '=': goto yy75; - case '>': goto yy77; - default: goto yy53; +// 1401 "scanner.c" +yy116: + yych = *++YYCURSOR; + switch (yych) { + case 'G': + case 'g': goto yy117; + default: goto yy87; } -yy53: -// 398 "scanner.re" - { - token->opcode = PHQL_T_LESS; - return 0; - } -// 691 "scanner.c" -yy54: - ++YYCURSOR; - switch ((yych = *YYCURSOR)) { - case '=': goto yy73; - default: goto yy55; +yy117: + yych = *++YYCURSOR; + switch (yych) { + case 'H': + case 'h': goto yy118; + default: goto yy87; } -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: +yy118: yych = *++YYCURSOR; - goto yy7; -yy71: - ++YYCURSOR; - yych = *YYCURSOR; -yy72: switch (yych) { - case '\t': - case '\n': - case '\r': - case ' ': goto yy71; - default: goto yy67; + case 'T': + case 't': goto yy119; + default: goto yy87; } -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: +yy119: ++YYCURSOR; - yych = *YYCURSOR; - switch (yych) { + switch ((yych = *YYCURSOR)) { case '0': case '1': case '2': @@ -25195,32 +21152,33 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { 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; + case 'z': goto yy86; + default: goto yy120; } -yy84: - ++YYCURSOR; -// 320 "scanner.re" +yy120: +// 226 "scanner.re" { - token->opcode = PHQL_T_IDENTIFIER; - token->value = estrndup(q, YYCURSOR - q - 1); - token->len = YYCURSOR - q - 1; - q = YYCURSOR; + token->opcode = PHQL_T_RIGHT; return 0; } -// 897 "scanner.c" -yy86: - ++YYCURSOR; - yych = *YYCURSOR; -yy87: +// 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': @@ -25285,68 +21243,37 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { 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; + default: goto yy124; } -yy91: - ++YYCURSOR; -// 292 "scanner.re" +yy124: +// 211 "scanner.re" { - token->opcode = PHQL_T_STRING; - token->value = estrndup(q, YYCURSOR - q - 1); - token->len = YYCURSOR - q - 1; - q = YYCURSOR; + token->opcode = PHQL_T_JOIN; return 0; } -// 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; +// 1588 "scanner.c" +yy125: + yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy83; - default: goto yy93; + case 'T': + case 't': goto yy130; + default: goto yy87; } -yy96: +yy126: yych = *++YYCURSOR; switch (yych) { - case 'U': - case 'u': goto yy97; + case 'L': + case 'l': goto yy127; default: goto yy87; } -yy97: +yy127: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy98; + case 'L': + case 'l': goto yy128; default: goto yy87; } -yy98: +yy128: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -25413,53 +21340,16 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy99; + default: goto yy129; } -yy99: -// 281 "scanner.re" +yy129: +// 251 "scanner.re" { - token->opcode = PHQL_T_TRUE; + token->opcode = PHQL_T_NULL; return 0; } -// 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; - } ->>>>>>> 1.2.2 -yy102: - yych = *++YYCURSOR; - switch (yych) { - case 'O': - case 'o': goto yy103; - default: goto yy87; -<<<<<<< HEAD - } -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: +// 1685 "scanner.c" +yy130: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -25526,61 +21416,46 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy106; + default: goto yy131; } -yy106: -// 231 "scanner.re" +yy131: +// 171 "scanner.re" { - token->opcode = PHQL_T_CROSS; + token->opcode = PHQL_T_NOT; return 0; } -// 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: +// 1761 "scanner.c" +yy132: yych = *++YYCURSOR; switch (yych) { - case 'R': - case 'r': goto yy110; + case 'F': + case 'f': goto yy141; default: goto yy87; } -yy110: +yy133: yych = *++YYCURSOR; switch (yych) { - case 'T': - case 't': goto yy111; + case 'K': + case 'k': goto yy135; + case 'M': + case 'm': goto yy134; default: goto yy87; } -yy111: -======= - } -yy103: +yy134: yych = *++YYCURSOR; switch (yych) { - case 'S': - case 's': goto yy104; + case 'I': + case 'i': goto yy138; default: goto yy87; } -yy104: +yy135: yych = *++YYCURSOR; switch (yych) { - case 'S': - case 's': goto yy105; + case 'E': + case 'e': goto yy136; default: goto yy87; } -yy105: +yy136: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -25647,44 +21522,23 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy106; + default: goto yy137; } -yy106: -// 231 "scanner.re" +yy137: +// 186 "scanner.re" { - token->opcode = PHQL_T_CROSS; + token->opcode = PHQL_T_LIKE; return 0; } -// 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: +// 1867 "scanner.c" +yy138: yych = *++YYCURSOR; switch (yych) { case 'T': - case 't': goto yy111; + case 't': goto yy139; default: goto yy87; } -yy111: +yy139: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -25751,23 +21605,23 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy112; + default: goto yy140; } -yy112: -// 271 "scanner.re" +yy140: +// 161 "scanner.re" { - token->opcode = PHQL_T_CONVERT; + token->opcode = PHQL_T_LIMIT; return 0; } -// 1318 "scanner.c" -yy113: +// 1950 "scanner.c" +yy141: yych = *++YYCURSOR; switch (yych) { case 'T': - case 't': goto yy114; + case 't': goto yy142; default: goto yy87; } -yy114: +yy142: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -25834,38 +21688,44 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy115; + default: goto yy143; } -yy115: -// 266 "scanner.re" +yy143: +// 221 "scanner.re" { - token->opcode = PHQL_T_CAST; + token->opcode = PHQL_T_LEFT; return 0; } -// 1401 "scanner.c" -yy116: +// 2033 "scanner.c" +yy144: yych = *++YYCURSOR; switch (yych) { - case 'G': - case 'g': goto yy117; + case 'V': + case 'v': goto yy145; default: goto yy87; } -yy117: +yy145: yych = *++YYCURSOR; switch (yych) { - case 'H': - case 'h': goto yy118; + case 'I': + case 'i': goto yy146; default: goto yy87; } -yy118: +yy146: yych = *++YYCURSOR; switch (yych) { - case 'T': - case 't': goto yy119; + case 'N': + case 'n': goto yy147; default: goto yy87; } -yy119: ->>>>>>> 1.2.2 +yy147: + yych = *++YYCURSOR; + switch (yych) { + case 'G': + case 'g': goto yy148; + default: goto yy87; + } +yy148: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -25932,24 +21792,37 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; -<<<<<<< HEAD - default: goto yy112; + default: goto yy149; } -yy112: -// 271 "scanner.re" +yy149: +// 156 "scanner.re" { - token->opcode = PHQL_T_CONVERT; + token->opcode = PHQL_T_HAVING; return 0; } -// 1318 "scanner.c" -yy113: +// 2137 "scanner.c" +yy150: yych = *++YYCURSOR; switch (yych) { - case 'T': - case 't': goto yy114; + case 'O': + case 'o': goto yy151; default: goto yy87; } -yy114: +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': @@ -26016,62 +21889,127 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy115; + default: goto yy154; } -yy115: -// 266 "scanner.re" +yy154: +// 151 "scanner.re" { - token->opcode = PHQL_T_CAST; + token->opcode = PHQL_T_GROUP; return 0; } -// 1401 "scanner.c" -yy116: +// 2234 "scanner.c" +yy155: yych = *++YYCURSOR; switch (yych) { - case 'G': - case 'g': goto yy117; + case 'T': + case 't': goto yy158; default: goto yy87; } -yy117: +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; + } +// 2317 "scanner.c" +yy158: yych = *++YYCURSOR; switch (yych) { - case 'H': - case 'h': goto yy118; + case 'W': + case 'w': goto yy159; default: goto yy87; } -yy118: +yy159: yych = *++YYCURSOR; switch (yych) { - case 'T': - case 't': goto yy119; + case 'E': + case 'e': goto yy160; default: goto yy87; } -yy119: -======= - default: goto yy120; - } -yy120: -// 226 "scanner.re" - { - token->opcode = PHQL_T_RIGHT; - return 0; - } -// 1498 "scanner.c" -yy121: +yy160: yych = *++YYCURSOR; switch (yych) { - case 'I': - case 'i': goto yy122; + case 'E': + case 'e': goto yy161; default: goto yy87; } -yy122: +yy161: yych = *++YYCURSOR; switch (yych) { case 'N': - case 'n': goto yy123; + case 'n': goto yy162; default: goto yy87; } -yy123: +yy162: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -26138,38 +22076,23 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy124; + default: goto yy163; } -yy124: -// 211 "scanner.re" +yy163: +// 261 "scanner.re" { - token->opcode = PHQL_T_JOIN; + token->opcode = PHQL_T_BETWEEN; 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: +// 2421 "scanner.c" +yy164: yych = *++YYCURSOR; switch (yych) { - case 'L': - case 'l': goto yy128; + case 'F': + case 'f': goto yy178; default: goto yy87; } -yy128: ->>>>>>> 1.2.2 +yy165: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -26236,31 +22159,16 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; -<<<<<<< HEAD - default: goto yy120; + default: goto yy166; } -yy120: -// 226 "scanner.re" +yy166: +// 206 "scanner.re" { - token->opcode = PHQL_T_RIGHT; + token->opcode = PHQL_T_ON; 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: +// 2504 "scanner.c" +yy167: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -26276,7 +22184,6 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'A': case 'B': case 'C': - case 'D': case 'E': case 'F': case 'G': @@ -26304,7 +22211,6 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'a': case 'b': case 'c': - case 'd': case 'e': case 'f': case 'g': @@ -26327,48 +22233,39 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy124; + case 'D': + case 'd': goto yy174; + default: goto yy168; } -yy124: -// 211 "scanner.re" +yy168: +// 181 "scanner.re" { - token->opcode = PHQL_T_JOIN; + token->opcode = PHQL_T_OR; return 0; } -// 1588 "scanner.c" -yy125: +// 2580 "scanner.c" +yy169: yych = *++YYCURSOR; switch (yych) { case 'T': - case 't': goto yy130; + case 't': goto yy170; default: goto yy87; } -yy126: +yy170: yych = *++YYCURSOR; switch (yych) { - case 'L': - case 'l': goto yy127; + case 'E': + case 'e': goto yy171; default: goto yy87; } -yy127: +yy171: yych = *++YYCURSOR; switch (yych) { - case 'L': - case 'l': goto yy128; + case 'R': + case 'r': goto yy172; default: goto yy87; } -yy128: -======= - default: goto yy129; - } -yy129: -// 251 "scanner.re" - { - token->opcode = PHQL_T_NULL; - return 0; - } -// 1685 "scanner.c" -yy130: +yy172: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -26435,46 +22332,30 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy131; + default: goto yy173; } -yy131: -// 171 "scanner.re" +yy173: +// 236 "scanner.re" { - token->opcode = PHQL_T_NOT; + token->opcode = PHQL_T_OUTER; return 0; } -// 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: +// 2677 "scanner.c" +yy174: yych = *++YYCURSOR; switch (yych) { - case 'I': - case 'i': goto yy138; + case 'E': + case 'e': goto yy175; default: goto yy87; } -yy135: +yy175: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy136; + case 'R': + case 'r': goto yy176; default: goto yy87; } -yy136: +yy176: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -26541,23 +22422,37 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy137; + default: goto yy177; } -yy137: -// 186 "scanner.re" +yy177: +// 131 "scanner.re" { - token->opcode = PHQL_T_LIKE; + token->opcode = PHQL_T_ORDER; return 0; } -// 1867 "scanner.c" -yy138: +// 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 yy139; + case 't': goto yy181; default: goto yy87; } -yy139: +yy181: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -26624,23 +22519,37 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy140; + default: goto yy182; } -yy140: -// 161 "scanner.re" +yy182: +// 166 "scanner.re" { - token->opcode = PHQL_T_LIMIT; + token->opcode = PHQL_T_OFFSET; return 0; } -// 1950 "scanner.c" -yy141: +// 2864 "scanner.c" +yy183: yych = *++YYCURSOR; switch (yych) { - case 'T': - case 't': goto yy142; + case 'E': + case 'e': goto yy184; default: goto yy87; } -yy142: +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': @@ -26707,44 +22616,44 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy143; + default: goto yy187; } -yy143: -// 221 "scanner.re" +yy187: +// 121 "scanner.re" { - token->opcode = PHQL_T_LEFT; + token->opcode = PHQL_T_WHERE; return 0; } -// 2033 "scanner.c" -yy144: +// 2961 "scanner.c" +yy188: yych = *++YYCURSOR; switch (yych) { - case 'V': - case 'v': goto yy145; + case 'L': + case 'l': goto yy189; default: goto yy87; } -yy145: +yy189: yych = *++YYCURSOR; switch (yych) { - case 'I': - case 'i': goto yy146; + case 'U': + case 'u': goto yy190; default: goto yy87; } -yy146: +yy190: yych = *++YYCURSOR; switch (yych) { - case 'N': - case 'n': goto yy147; + case 'E': + case 'e': goto yy191; default: goto yy87; } -yy147: +yy191: yych = *++YYCURSOR; switch (yych) { - case 'G': - case 'g': goto yy148; + case 'S': + case 's': goto yy192; default: goto yy87; } -yy148: +yy192: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -26811,38 +22720,23 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy149; + default: goto yy193; } -yy149: -// 156 "scanner.re" +yy193: +// 116 "scanner.re" { - token->opcode = PHQL_T_HAVING; + token->opcode = PHQL_T_VALUES; return 0; } -// 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: +// 3065 "scanner.c" +yy194: yych = *++YYCURSOR; switch (yych) { - case 'P': - case 'p': goto yy153; + case 'I': + case 'i': goto yy211; default: goto yy87; } -yy153: ->>>>>>> 1.2.2 +yy195: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -26868,13 +22762,10 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'K': case 'L': case 'M': - case 'N': case 'O': case 'P': case 'Q': case 'R': - case 'S': - case 'T': case 'U': case 'V': case 'W': @@ -26896,30 +22787,32 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'k': case 'l': case 'm': - case 'n': 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; -<<<<<<< HEAD - default: goto yy129; + case 'N': + case 'n': goto yy201; + case 'S': + case 's': goto yy199; + case 'T': + case 't': goto yy200; + default: goto yy196; } -yy129: -// 251 "scanner.re" +yy196: +// 201 "scanner.re" { - token->opcode = PHQL_T_NULL; + token->opcode = PHQL_T_IN; return 0; } -// 1685 "scanner.c" -yy130: +// 3148 "scanner.c" +yy197: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -26986,46 +22879,44 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy131; + default: goto yy198; } -yy131: -// 171 "scanner.re" +yy198: +// 246 "scanner.re" { - token->opcode = PHQL_T_NOT; + token->opcode = PHQL_T_IS; return 0; } -// 1761 "scanner.c" -yy132: +// 3224 "scanner.c" +yy199: yych = *++YYCURSOR; switch (yych) { - case 'F': - case 'f': goto yy141; + case 'E': + case 'e': goto yy207; default: goto yy87; } -yy133: +yy200: yych = *++YYCURSOR; switch (yych) { - case 'K': - case 'k': goto yy135; - case 'M': - case 'm': goto yy134; + case 'O': + case 'o': goto yy205; default: goto yy87; } -yy134: +yy201: yych = *++YYCURSOR; switch (yych) { - case 'I': - case 'i': goto yy138; + case 'E': + case 'e': goto yy202; default: goto yy87; } -yy135: +yy202: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy136; + case 'R': + case 'r': goto yy203; default: goto yy87; } -yy136: +yy203: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -27092,41 +22983,16 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy137; - } -yy137: -// 186 "scanner.re" - { - token->opcode = PHQL_T_LIKE; - return 0; - } -// 1867 "scanner.c" -yy138: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy139; - default: goto yy87; - } -yy139: -======= - default: goto yy154; + default: goto yy204; } -yy154: -// 151 "scanner.re" +yy204: +// 216 "scanner.re" { - token->opcode = PHQL_T_GROUP; + token->opcode = PHQL_T_INNER; return 0; } -// 2234 "scanner.c" -yy155: - yych = *++YYCURSOR; - switch (yych) { - case 'T': - case 't': goto yy158; - default: goto yy87; - } -yy156: +// 3328 "scanner.c" +yy205: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -27193,45 +23059,30 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy157; + default: goto yy206; } -yy157: -// 136 "scanner.re" +yy206: +// 111 "scanner.re" { - token->opcode = PHQL_T_BY; + token->opcode = PHQL_T_INTO; return 0; } -// 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: +// 3404 "scanner.c" +yy207: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy161; + case 'R': + case 'r': goto yy208; default: goto yy87; } -yy161: +yy208: yych = *++YYCURSOR; switch (yych) { - case 'N': - case 'n': goto yy162; + case 'T': + case 't': goto yy209; default: goto yy87; } -yy162: ->>>>>>> 1.2.2 +yy209: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -27298,43 +23149,30 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; -<<<<<<< HEAD - default: goto yy140; + default: goto yy210; } -yy140: -// 161 "scanner.re" +yy210: +// 106 "scanner.re" { - token->opcode = PHQL_T_LIMIT; + token->opcode = PHQL_T_INSERT; return 0; } -// 1950 "scanner.c" -yy141: +// 3494 "scanner.c" +yy211: yych = *++YYCURSOR; switch (yych) { - case 'T': - case 't': goto yy142; + case 'K': + case 'k': goto yy212; default: goto yy87; } -yy142: -======= - default: goto yy163; - } -yy163: -// 261 "scanner.re" - { - token->opcode = PHQL_T_BETWEEN; - return 0; - } -// 2421 "scanner.c" -yy164: +yy212: yych = *++YYCURSOR; switch (yych) { - case 'F': - case 'f': goto yy178; + case 'E': + case 'e': goto yy213; default: goto yy87; } -yy165: ->>>>>>> 1.2.2 +yy213: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -27401,56 +23239,30 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; -<<<<<<< HEAD - default: goto yy143; + default: goto yy214; } -yy143: -// 221 "scanner.re" +yy214: +// 191 "scanner.re" { - token->opcode = PHQL_T_LEFT; + token->opcode = PHQL_T_ILIKE; return 0; } -// 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: +// 3584 "scanner.c" +yy215: yych = *++YYCURSOR; switch (yych) { - case 'N': - case 'n': goto yy147; + case 'A': + case 'a': goto yy223; default: goto yy87; } -yy147: +yy216: yych = *++YYCURSOR; switch (yych) { - case 'G': - case 'g': goto yy148; + case 'D': + case 'd': goto yy221; default: goto yy87; } -yy148: -======= - default: goto yy166; - } -yy166: -// 206 "scanner.re" - { - token->opcode = PHQL_T_ON; - return 0; - } -// 2504 "scanner.c" -yy167: +yy217: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -27465,7 +23277,7 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case '9': case 'A': case 'B': - case 'C': + case 'D': case 'E': case 'F': case 'G': @@ -27492,7 +23304,7 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case '_': case 'a': case 'b': - case 'c': + case 'd': case 'e': case 'f': case 'g': @@ -27515,40 +23327,18 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - case 'D': - case 'd': goto yy174; - default: goto yy168; + case 'C': + case 'c': goto yy219; + default: goto yy218; } -yy168: -// 181 "scanner.re" +yy218: +// 101 "scanner.re" { - token->opcode = PHQL_T_OR; + token->opcode = PHQL_T_AS; return 0; } -// 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: ->>>>>>> 1.2.2 +// 3674 "scanner.c" +yy219: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -27615,38 +23405,16 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; -<<<<<<< HEAD - default: goto yy149; + default: goto yy220; } -yy149: -// 156 "scanner.re" +yy220: +// 141 "scanner.re" { - token->opcode = PHQL_T_HAVING; + token->opcode = PHQL_T_ASC; return 0; } -// 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: +// 3750 "scanner.c" +yy221: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -27713,49 +23481,44 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy154; + default: goto yy222; } -yy154: -// 151 "scanner.re" +yy222: +// 176 "scanner.re" { - token->opcode = PHQL_T_GROUP; + token->opcode = PHQL_T_AND; return 0; } -// 2234 "scanner.c" -yy155: +// 3826 "scanner.c" +yy223: yych = *++YYCURSOR; switch (yych) { - case 'T': - case 't': goto yy158; + case 'I': + case 'i': goto yy224; default: goto yy87; } -yy156: -======= - default: goto yy173; +yy224: + yych = *++YYCURSOR; + switch (yych) { + case 'N': + case 'n': goto yy225; + default: goto yy87; } -yy173: -// 236 "scanner.re" - { - token->opcode = PHQL_T_OUTER; - return 0; - } -// 2677 "scanner.c" -yy174: +yy225: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy175; + case 'S': + case 's': goto yy226; default: goto yy87; } -yy175: +yy226: yych = *++YYCURSOR; switch (yych) { - case 'R': - case 'r': goto yy176; + case 'T': + case 't': goto yy227; default: goto yy87; } -yy176: ->>>>>>> 1.2.2 +yy227: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -27822,45 +23585,44 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; -<<<<<<< HEAD - default: goto yy157; + default: goto yy228; } -yy157: -// 136 "scanner.re" +yy228: +// 196 "scanner.re" { - token->opcode = PHQL_T_BY; + token->opcode = PHQL_T_AGAINST; return 0; } -// 2317 "scanner.c" -yy158: +// 3930 "scanner.c" +yy229: yych = *++YYCURSOR; switch (yych) { - case 'W': - case 'w': goto yy159; + case 'L': + case 'l': goto yy238; default: goto yy87; } -yy159: +yy230: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy160; + case 'O': + case 'o': goto yy235; default: goto yy87; } -yy160: +yy231: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy161; + case 'L': + case 'l': goto yy232; default: goto yy87; } -yy161: +yy232: yych = *++YYCURSOR; switch (yych) { - case 'N': - case 'n': goto yy162; + case 'L': + case 'l': goto yy233; default: goto yy87; } -yy162: +yy233: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -27927,23 +23689,23 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy163; + default: goto yy234; } -yy163: -// 261 "scanner.re" +yy234: +// 241 "scanner.re" { - token->opcode = PHQL_T_BETWEEN; + token->opcode = PHQL_T_FULL; return 0; } -// 2421 "scanner.c" -yy164: +// 4034 "scanner.c" +yy235: yych = *++YYCURSOR; switch (yych) { - case 'F': - case 'f': goto yy178; + case 'M': + case 'm': goto yy236; default: goto yy87; } -yy165: +yy236: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -28010,16 +23772,30 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy166; + default: goto yy237; } -yy166: -// 206 "scanner.re" +yy237: +// 96 "scanner.re" { - token->opcode = PHQL_T_ON; + token->opcode = PHQL_T_FROM; return 0; } -// 2504 "scanner.c" -yy167: +// 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': @@ -28035,6 +23811,7 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'A': case 'B': case 'C': + case 'D': case 'E': case 'F': case 'G': @@ -28062,6 +23839,7 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'a': case 'b': case 'c': + case 'd': case 'e': case 'f': case 'g': @@ -28084,72 +23862,67 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - case 'D': - case 'd': goto yy174; - default: goto yy168; + default: goto yy241; } -yy168: -// 181 "scanner.re" +yy241: +// 286 "scanner.re" { - token->opcode = PHQL_T_OR; + token->opcode = PHQL_T_FALSE; return 0; } -// 2580 "scanner.c" -yy169: +// 4207 "scanner.c" +yy242: yych = *++YYCURSOR; switch (yych) { - case 'T': - case 't': goto yy170; + case 'L': + case 'l': goto yy251; + case 'S': + case 's': goto yy252; default: goto yy87; } -yy170: +yy243: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy171; + case 'S': + case 's': goto yy244; default: goto yy87; } -yy171: +yy244: yych = *++YYCURSOR; switch (yych) { - case 'R': - case 'r': goto yy172; + case 'T': + case 't': goto yy245; default: goto yy87; } -yy172: -======= - default: goto yy177; +yy245: + yych = *++YYCURSOR; + switch (yych) { + case 'I': + case 'i': goto yy246; + default: goto yy87; } -yy177: -// 131 "scanner.re" - { - token->opcode = PHQL_T_ORDER; - return 0; - } -// 2767 "scanner.c" -yy178: +yy246: yych = *++YYCURSOR; switch (yych) { - case 'S': - case 's': goto yy179; + case 'N': + case 'n': goto yy247; default: goto yy87; } -yy179: +yy247: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy180; + case 'C': + case 'c': goto yy248; default: goto yy87; } -yy180: +yy248: yych = *++YYCURSOR; switch (yych) { case 'T': - case 't': goto yy181; + case 't': goto yy249; default: goto yy87; } -yy181: ->>>>>>> 1.2.2 +yy249: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -28216,64 +23989,30 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; -<<<<<<< HEAD - default: goto yy173; - } -yy173: -// 236 "scanner.re" - { - token->opcode = PHQL_T_OUTER; - return 0; - } -// 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: -======= - default: goto yy182; + default: goto yy250; } -yy182: -// 166 "scanner.re" +yy250: +// 256 "scanner.re" { - token->opcode = PHQL_T_OFFSET; + token->opcode = PHQL_T_DISTINCT; return 0; } -// 2864 "scanner.c" -yy183: +// 4334 "scanner.c" +yy251: yych = *++YYCURSOR; switch (yych) { case 'E': - case 'e': goto yy184; - default: goto yy87; - } -yy184: - yych = *++YYCURSOR; - switch (yych) { - case 'R': - case 'r': goto yy185; + case 'e': goto yy255; default: goto yy87; } -yy185: +yy252: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy186; + case 'C': + case 'c': goto yy253; default: goto yy87; } -yy186: ->>>>>>> 1.2.2 +yy253: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -28340,77 +24079,30 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; -<<<<<<< HEAD - default: goto yy177; + default: goto yy254; } -yy177: -// 131 "scanner.re" +yy254: +// 146 "scanner.re" { - token->opcode = PHQL_T_ORDER; + token->opcode = PHQL_T_DESC; return 0; } -// 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: +// 4424 "scanner.c" +yy255: yych = *++YYCURSOR; switch (yych) { case 'T': - case 't': goto yy181; - default: goto yy87; - } -yy181: -======= - default: goto yy187; - } -yy187: -// 121 "scanner.re" - { - token->opcode = PHQL_T_WHERE; - return 0; - } -// 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; + case 't': goto yy256; default: goto yy87; } -yy190: +yy256: yych = *++YYCURSOR; switch (yych) { case 'E': - case 'e': goto yy191; - default: goto yy87; - } -yy191: - yych = *++YYCURSOR; - switch (yych) { - case 'S': - case 's': goto yy192; + case 'e': goto yy257; default: goto yy87; } -yy192: +yy257: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -28477,99 +24169,25 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy193; + default: goto yy258; } -yy193: -// 116 "scanner.re" +yy258: +// 91 "scanner.re" { - token->opcode = PHQL_T_VALUES; + token->opcode = PHQL_T_DELETE; return 0; } -// 3065 "scanner.c" -yy194: +// 4514 "scanner.c" +yy259: 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 'l': goto yy262; case 'T': - case 't': goto yy200; - default: goto yy196; + case 't': goto yy260; + default: goto yy87; } -yy196: -// 201 "scanner.re" - { - token->opcode = PHQL_T_IN; - return 0; - } -// 3148 "scanner.c" -yy197: +yy260: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -28636,45 +24254,37 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy198; + default: goto yy261; } -yy198: -// 246 "scanner.re" +yy261: +// 86 "scanner.re" { - token->opcode = PHQL_T_IS; + token->opcode = PHQL_T_SET; return 0; } -// 3224 "scanner.c" -yy199: +// 4599 "scanner.c" +yy262: yych = *++YYCURSOR; switch (yych) { case 'E': - case 'e': goto yy207; - default: goto yy87; - } -yy200: - yych = *++YYCURSOR; - switch (yych) { - case 'O': - case 'o': goto yy205; + case 'e': goto yy263; default: goto yy87; } -yy201: +yy263: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy202; + case 'C': + case 'c': goto yy264; default: goto yy87; } -yy202: +yy264: yych = *++YYCURSOR; switch (yych) { - case 'R': - case 'r': goto yy203; + case 'T': + case 't': goto yy265; default: goto yy87; } -yy203: ->>>>>>> 1.2.2 +yy265: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -28741,38 +24351,44 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; -<<<<<<< HEAD - default: goto yy182; + default: goto yy266; } -yy182: -// 166 "scanner.re" +yy266: +// 126 "scanner.re" { - token->opcode = PHQL_T_OFFSET; + token->opcode = PHQL_T_SELECT; return 0; } -// 2864 "scanner.c" -yy183: +// 4696 "scanner.c" +yy267: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy184; + case 'D': + case 'd': goto yy273; default: goto yy87; } -yy184: +yy268: yych = *++YYCURSOR; switch (yych) { - case 'R': - case 'r': goto yy185; + case 'I': + case 'i': goto yy269; default: goto yy87; } -yy185: +yy269: yych = *++YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy186; + case 'N': + case 'n': goto yy270; default: goto yy87; } -yy186: +yy270: + yych = *++YYCURSOR; + switch (yych) { + case 'G': + case 'g': goto yy271; + default: goto yy87; + } +yy271: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -28839,55 +24455,37 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy187; + default: goto yy272; } -yy187: -// 121 "scanner.re" +yy272: +// 276 "scanner.re" { - token->opcode = PHQL_T_WHERE; + token->opcode = PHQL_T_USING; return 0; } -// 2961 "scanner.c" -yy188: +// 4800 "scanner.c" +yy273: yych = *++YYCURSOR; switch (yych) { - case 'L': - case 'l': goto yy189; + case 'A': + case 'a': goto yy274; default: goto yy87; } -yy189: +yy274: yych = *++YYCURSOR; switch (yych) { - case 'U': - case 'u': goto yy190; + case 'T': + case 't': goto yy275; default: goto yy87; } -yy190: +yy275: yych = *++YYCURSOR; switch (yych) { case 'E': - case 'e': goto yy191; - default: goto yy87; - } -yy191: - yych = *++YYCURSOR; - switch (yych) { - case 'S': - case 's': goto yy192; + case 'e': goto yy276; default: goto yy87; } -yy192: -======= - default: goto yy204; - } -yy204: -// 216 "scanner.re" - { - token->opcode = PHQL_T_INNER; - return 0; - } -// 3328 "scanner.c" -yy205: +yy276: ++YYCURSOR; switch ((yych = *YYCURSOR)) { case '0': @@ -28954,33 +24552,20 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'x': case 'y': case 'z': goto yy86; - default: goto yy206; + default: goto yy277; } -yy206: -// 111 "scanner.re" +yy277: +// 81 "scanner.re" { - token->opcode = PHQL_T_INTO; + token->opcode = PHQL_T_UPDATE; 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: ->>>>>>> 1.2.2 +// 4897 "scanner.c" +yy278: ++YYCURSOR; - switch ((yych = *YYCURSOR)) { + yych = *YYCURSOR; + switch (yych) { + case '-': case '0': case '1': case '2': @@ -29017,7 +24602,6 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'X': case 'Y': case 'Z': - case '\\': case '_': case 'a': case 'b': @@ -29044,27 +24628,25 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { case 'w': case 'x': case 'y': - case 'z': goto yy86; -<<<<<<< HEAD - default: goto yy193; + case 'z': goto yy278; + case ':': goto yy280; + default: goto yy83; } -yy193: -// 116 "scanner.re" +yy280: + ++YYCURSOR; +// 73 "scanner.re" { - token->opcode = PHQL_T_VALUES; + token->opcode = PHQL_T_SPLACEHOLDER; + token->value = estrndup(q, YYCURSOR - q - 1); + token->len = YYCURSOR - q - 1; + q = YYCURSOR; return 0; } -// 3065 "scanner.c" -yy194: - yych = *++YYCURSOR; - switch (yych) { - case 'I': - case 'i': goto yy211; - default: goto yy87; - } -yy195: +// 4979 "scanner.c" +yy282: ++YYCURSOR; - switch ((yych = *YYCURSOR)) { + yych = *YYCURSOR; + switch (yych) { case '0': case '1': case '2': @@ -29074,73 +24656,23 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { 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; + case '9': goto yy282; + default: goto yy284; } -yy196: -// 201 "scanner.re" +yy284: +// 64 "scanner.re" { - token->opcode = PHQL_T_IN; + token->opcode = PHQL_T_NPLACEHOLDER; + token->value = estrndup(q, YYCURSOR - q); + token->len = YYCURSOR - q; + q = YYCURSOR; return 0; } -// 3148 "scanner.c" -yy197: +// 5005 "scanner.c" +yy285: ++YYCURSOR; - switch ((yych = *YYCURSOR)) { + yych = *YYCURSOR; + switch (yych) { case '0': case '1': case '2': @@ -29150,126 +24682,40 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { 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; - } -// 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: -======= - default: goto yy210; + case '9': goto yy285; + default: goto yy287; } -yy210: -// 106 "scanner.re" +yy287: +// 55 "scanner.re" { - token->opcode = PHQL_T_INSERT; + token->opcode = PHQL_T_DOUBLE; + token->value = estrndup(q, YYCURSOR - q); + token->len = YYCURSOR - q; + q = YYCURSOR; return 0; } -// 3494 "scanner.c" -yy211: - yych = *++YYCURSOR; - switch (yych) { - case 'K': - case 'k': goto yy212; - default: goto yy87; - } -yy212: - yych = *++YYCURSOR; +// 5031 "scanner.c" +yy288: + ++YYCURSOR; + yych = *YYCURSOR; switch (yych) { - case 'E': - case 'e': goto yy213; - default: goto yy87; + 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; } -yy213: +yy290: ++YYCURSOR; - switch ((yych = *YYCURSOR)) { + yych = *YYCURSOR; + switch (yych) { + case '.': goto yy288; case '0': case '1': case '2': @@ -29279,83061 +24725,11588 @@ static int phql_get_token(phql_scanner_state *s, phql_scanner_token *token) { 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; - } -// 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; - } -// 3674 "scanner.c" -yy219: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto yy204; + case '9': goto yy290; + default: goto yy3; } -yy204: -// 216 "scanner.re" - { - token->opcode = PHQL_T_INNER; - return 0; } -// 3328 "scanner.c" -yy205: -======= - default: goto yy220; +// 453 "scanner.re" + + } + + return status; +} + + +/* 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 +#endif + + + + +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; + + 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); + + 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; + + 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; + + 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; + + MAKE_STD_ZVAL(ret); + array_init(ret); + + 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); + + return ret; +} + +static zval *phql_ret_update_statement(zval *U, zval *W, zval *L) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init(ret); + + 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); + } + + return ret; +} + +static zval *phql_ret_update_clause(zval *tables, zval *values) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 2); + add_assoc_zval(ret, "tables", tables); + add_assoc_zval(ret, "values", values); + + return ret; +} + +static zval *phql_ret_update_item(zval *column, zval *expr) +{ + + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 2); + add_assoc_zval(ret, "column", column); + add_assoc_zval(ret, "expr", expr); + + return ret; +} + +static zval *phql_ret_delete_statement(zval *D, zval *W, zval *L) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init(ret); + + 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); + } + + return ret; +} + +static zval *phql_ret_delete_clause(zval *tables) +{ + zval *ret; + + MAKE_STD_ZVAL(ret); + array_init_size(ret, 1); + add_assoc_zval(ret, "tables", tables); + + return ret; +} + +static zval *phql_ret_zval_list(zval *list_left, zval *right_list) +{ + + zval *ret; + HashPosition pos; + HashTable *list; + + MAKE_STD_ZVAL(ret); + array_init(ret); + + 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; } -yy220: -// 141 "scanner.re" - { - token->opcode = PHQL_T_ASC; - return 0; + + Z_ADDREF_PP(item); + add_next_index_zval(ret, *item); + } -// 3750 "scanner.c" -yy221: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - 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: -======= - default: goto yy222; - } -yy222: -// 176 "scanner.re" - { - token->opcode = PHQL_T_AND; - return 0; - } -// 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; - } -// 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; - } -yy241: -// 286 "scanner.re" - { - token->opcode = PHQL_T_FALSE; - return 0; - } -// 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; - } -// 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; - } -// 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto yy210; - } -yy210: -// 106 "scanner.re" - { - token->opcode = PHQL_T_INSERT; - return 0; - } -// 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; - } -// 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; - } -// 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; - } -// 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; - } -// 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; - } -// 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; - } -yy241: -// 286 "scanner.re" - { - token->opcode = PHQL_T_FALSE; - return 0; - } -// 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; - } -// 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; - } -// 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" -======= - 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; -} - - -/* 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 -#endif - - - - -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; - - 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); - - 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; - - 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; - - 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; - - MAKE_STD_ZVAL(ret); - array_init(ret); - - 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); - - return ret; -} - -static zval *phql_ret_update_statement(zval *U, zval *W, zval *L) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - - 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); - } - - return ret; -} - -static zval *phql_ret_update_clause(zval *tables, zval *values) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 2); - add_assoc_zval(ret, "tables", tables); - add_assoc_zval(ret, "values", values); - - return ret; -} - -static zval *phql_ret_update_item(zval *column, zval *expr) -{ - - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 2); - add_assoc_zval(ret, "column", column); - add_assoc_zval(ret, "expr", expr); - - return ret; -} - -static zval *phql_ret_delete_statement(zval *D, zval *W, zval *L) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - - 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); - } - - return ret; -} - -static zval *phql_ret_delete_clause(zval *tables) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 1); - add_assoc_zval(ret, "tables", tables); - - return ret; -} - -static zval *phql_ret_zval_list(zval *list_left, zval *right_list) -{ - - zval *ret; - HashPosition pos; - HashTable *list; - - MAKE_STD_ZVAL(ret); - array_init(ret); - - 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); - - } - zval_ptr_dtor(&list_left); - } else { - add_next_index_zval(ret, list_left); - } - - if (right_list) { - add_next_index_zval(ret, right_list); - } - - 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; -} - -static zval *phql_ret_assoc_name(zval *qualified_name, phql_parser_token *alias) -{ - - zval *ret; - - 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); - } - - return ret; - -} - -static zval *phql_ret_join_type(int type) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - ZVAL_LONG(ret, type); - - return ret; -} - -static zval *phql_ret_join_item(zval *type, zval *qualified, zval *alias, zval *conditions) -{ - - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_zval(ret, "type", type); - - if (qualified) { - add_assoc_zval(ret, "qualified", qualified); - } - - if (alias) { - add_assoc_zval(ret, "alias", alias); - } - - if (conditions) { - add_assoc_zval(ret, "conditions", conditions); - } - - return ret; - -} - -static zval *phql_ret_expr(int type, zval *left, zval *right) -{ - zval *ret; - - 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); - } - - 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); - } - - return ret; -} - - -// 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 */ - -#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 */ - -#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 */ - -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 -} - -void *phql_Alloc(void *(*mallocProc)(size_t)){ - yyParser *pParser; - pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); - if( pParser ){ - pParser->yyidx = -1; - } - return pParser; -} - -/* 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)); - } -} -// 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]; - - 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; -} - -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 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); - } -#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]; - } -} - -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 -} - -/* 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; -} -// 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; -} -// 1621 "parser.c" - break; - case 5: -// 546 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[0].minor.yy132, NULL, NULL, NULL, NULL, NULL); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 1855 "parser.c" - break; - case 37: -// 680 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_column_item(PHQL_T_EXPR, yymsp[0].minor.yy132, NULL, NULL); -} -// 1862 "parser.c" - break; - case 40: -// 696 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_zval_list(yymsp[-1].minor.yy132, yymsp[0].minor.yy132); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 1914 "parser.c" - break; - case 49: -// 744 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_type(PHQL_T_INNERJOIN); - yy_destructor(32,&yymsp[0].minor); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 1997 "parser.c" - break; - case 58: -// 782 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; - yy_destructor(39,&yymsp[-1].minor); -} -// 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); -} -// 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); -} -// 2031 "parser.c" - break; - case 67: -// 831 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_statement(yymsp[0].minor.yy132, NULL, NULL); -} -// 2038 "parser.c" - break; - case 68: -// 835 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); -} -// 2045 "parser.c" - break; - case 69: -// 839 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); -} -// 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); -} -// 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); -} -// 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); -} -// 2076 "parser.c" - break; - case 76: -// 877 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_delete_statement(yymsp[0].minor.yy132, NULL, NULL); -} -// 2083 "parser.c" - break; - case 77: -// 881 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_delete_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); -} -// 2090 "parser.c" - break; - case 78: -// 885 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_delete_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); -} -// 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); -} -// 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); -} -// 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); -} -// 2121 "parser.c" - break; - case 82: -// 905 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_assoc_name(yymsp[-1].minor.yy132, yymsp[0].minor.yy0); -} -// 2128 "parser.c" - break; - case 83: -// 909 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_assoc_name(yymsp[0].minor.yy132, NULL); -} -// 2135 "parser.c" - break; - case 85: -// 921 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; - yy_destructor(48,&yymsp[-1].minor); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 2184 "parser.c" - break; - case 96: -// 979 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; - yy_destructor(54,&yymsp[-1].minor); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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 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); - - } - - if (!token_name) { - token_length = strlen("UNKNOWN"); - token_name = estrndup("UNKNOWN", token_length); - token_found = 0; - } - - 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); - - 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'; - } - - if (!token_found) { - if (token_name) { - efree(token_name); - } - } - } - } else { - status->syntax_error_len = strlen("Syntax error, unexpected EOF"); - status->syntax_error = estrndup("Syntax error, unexpected EOF", status->syntax_error_len); - } - - 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); -} - -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 { - 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 { - ZVAL_STRING(*error_msg, "Scanning error near to EOF", 1); - } - - if (error) { - efree(error); - } -} - -static int phql_parse_phql(zval *result, zval *phql TSRMLS_DC) { - - zval *error_msg = NULL; - - ZVAL_NULL(result); - - 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; - } - - 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; - } - } - } - - phql_parser = phql_Alloc(phql_wrapper_alloc); - - parser_status = emalloc(sizeof(phql_parser_status)); - state = emalloc(sizeof(phql_scanner_state)); - - 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; - - state->active_token = 0; - state->start = phql; - state->start_length = 0; - state->end = state->start; - - token.value = NULL; - token.len = 0; - - while (0 <= (scanner_status = phql_get_token(state, &token))) { - - /* 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; - - 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; - - 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; - } - - if (parser_status->status != PHQL_PARSING_OK) { - status = FAILURE; - break; - } - - 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; -} - - - - -#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_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_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); - } - } 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); - } - } 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); - } - } 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); - } - } 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); - } - - 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(); -} - -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); - } - - 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(); -} - -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(); -} - -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); - } - - 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(); -} - -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_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; ->>>>>>> 1.2.2 - - } - -<<<<<<< HEAD - return status; -======= - 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; - } - } - - 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); - } - } - } - - 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; - } - } - - 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); - } - } - - 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); ->>>>>>> 1.2.2 -} - - -/* 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 -#endif - - - - -static zval *phql_ret_literal_zval(int type, phql_parser_token *T) -{ - zval *ret; - -<<<<<<< HEAD - 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_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; ->>>>>>> 1.2.2 - } - -<<<<<<< HEAD - 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; -======= -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; ->>>>>>> 1.2.2 - - MAKE_STD_ZVAL(ret); - array_init(ret); - -<<<<<<< HEAD - add_assoc_long(ret, "type", PHQL_T_QUALIFIED); -======= -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getEventsManager){ ->>>>>>> 1.2.2 - - 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; -} - -<<<<<<< HEAD -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); -======= -static PHP_METHOD(Phalcon_Mvc_Model_Manager, setCustomEventsManager){ - - zval *model, *events_manager, *class_name; ->>>>>>> 1.2.2 - - return ret; -} - -<<<<<<< HEAD -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; - - 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; - - 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; - - MAKE_STD_ZVAL(ret); - array_init(ret); - - 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); - - return ret; -} - -static zval *phql_ret_update_statement(zval *U, zval *W, zval *L) -{ - zval *ret; -======= - 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){ ->>>>>>> 1.2.2 - - MAKE_STD_ZVAL(ret); - array_init(ret); - -<<<<<<< HEAD - 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); - } - - return ret; -} - -static zval *phql_ret_update_clause(zval *tables, zval *values) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 2); - add_assoc_zval(ret, "tables", tables); - add_assoc_zval(ret, "values", values); - - return ret; -} - -static zval *phql_ret_update_item(zval *column, zval *expr) -{ - - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 2); - add_assoc_zval(ret, "column", column); - add_assoc_zval(ret, "expr", expr); - - return ret; -} - -static zval *phql_ret_delete_statement(zval *D, zval *W, zval *L) -{ - zval *ret; -======= - 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; ->>>>>>> 1.2.2 - - MAKE_STD_ZVAL(ret); - array_init(ret); - -<<<<<<< HEAD - 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); - } - - return ret; -} - -static zval *phql_ret_delete_clause(zval *tables) -{ - zval *ret; -======= - 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; - } - RETURN_CCTOR(cloned); - } - - 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); - } - 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; ->>>>>>> 1.2.2 - - MAKE_STD_ZVAL(ret); - array_init_size(ret, 1); - add_assoc_zval(ret, "tables", tables); - -<<<<<<< HEAD - return ret; -} - -static zval *phql_ret_zval_list(zval *list_left, zval *right_list) -{ - - zval *ret; - HashPosition pos; - HashTable *list; -======= - 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; ->>>>>>> 1.2.2 - - MAKE_STD_ZVAL(ret); - array_init(ret); - -<<<<<<< HEAD - 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); - - } - zval_ptr_dtor(&list_left); - } else { - add_next_index_zval(ret, list_left); - } - - if (right_list) { - add_next_index_zval(ret, right_list); - } - - 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; -} - -static zval *phql_ret_assoc_name(zval *qualified_name, phql_parser_token *alias) -{ - - zval *ret; - - 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); - } - - return ret; - -} - -static zval *phql_ret_join_type(int type) -{ - zval *ret; - - MAKE_STD_ZVAL(ret); - ZVAL_LONG(ret, type); - - return ret; -} - -static zval *phql_ret_join_item(zval *type, zval *qualified, zval *alias, zval *conditions) -{ - - zval *ret; - - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_zval(ret, "type", type); - - if (qualified) { - add_assoc_zval(ret, "qualified", qualified); - } - - if (alias) { - add_assoc_zval(ret, "alias", alias); - } - - if (conditions) { - add_assoc_zval(ret, "conditions", conditions); - } - - return ret; - -} - -static zval *phql_ret_expr(int type, zval *left, zval *right) -{ - zval *ret; - - 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); - } - - 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); - } - - return ret; -======= - 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); - } - } - - 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); - } - } - - RETURN_MM_NULL(); ->>>>>>> 1.2.2 -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, setConnectionService){ - -<<<<<<< HEAD -// 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 */ - -#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 */ - -#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 */ - -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 -} - -void *phql_Alloc(void *(*mallocProc)(size_t)){ - yyParser *pParser; - pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); - if( pParser ){ - pParser->yyidx = -1; - } - return pParser; -} - -/* 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)); - } -} -// 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]; - - 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; -} - -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 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); - } -#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]; - } -} - -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 -} - -/* 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 */ -======= - 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; ->>>>>>> 1.2.2 - -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; -} -// 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; -} -// 1621 "parser.c" - break; - case 5: -// 546 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_select_statement(yymsp[0].minor.yy132, NULL, NULL, NULL, NULL, NULL); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 1855 "parser.c" - break; - case 37: -// 680 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_column_item(PHQL_T_EXPR, yymsp[0].minor.yy132, NULL, NULL); -} -// 1862 "parser.c" - break; - case 40: -// 696 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_zval_list(yymsp[-1].minor.yy132, yymsp[0].minor.yy132); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 1914 "parser.c" - break; - case 49: -// 744 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_join_type(PHQL_T_INNERJOIN); - yy_destructor(32,&yymsp[0].minor); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 1997 "parser.c" - break; - case 58: -// 782 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; - yy_destructor(39,&yymsp[-1].minor); -} -// 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); -} -// 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); -} -// 2031 "parser.c" - break; - case 67: -// 831 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_statement(yymsp[0].minor.yy132, NULL, NULL); -} -// 2038 "parser.c" - break; - case 68: -// 835 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); -} -// 2045 "parser.c" - break; - case 69: -// 839 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_update_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); -} -// 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); -} -// 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); -} -// 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); -} -// 2076 "parser.c" - break; - case 76: -// 877 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_delete_statement(yymsp[0].minor.yy132, NULL, NULL); -} -// 2083 "parser.c" - break; - case 77: -// 881 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_delete_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); -} -// 2090 "parser.c" - break; - case 78: -// 885 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_delete_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); -} -// 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); -} -// 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); -} -// 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); -} -// 2121 "parser.c" - break; - case 82: -// 905 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_assoc_name(yymsp[-1].minor.yy132, yymsp[0].minor.yy0); -} -// 2128 "parser.c" - break; - case 83: -// 909 "parser.lemon" -{ - yygotominor.yy132 = phql_ret_assoc_name(yymsp[0].minor.yy132, NULL); -} -// 2135 "parser.c" - break; - case 85: -// 921 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; - yy_destructor(48,&yymsp[-1].minor); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 2184 "parser.c" - break; - case 96: -// 979 "parser.lemon" -{ - yygotominor.yy132 = yymsp[0].minor.yy132; - yy_destructor(54,&yymsp[-1].minor); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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); -} -// 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 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); - - } - - if (!token_name) { - token_length = strlen("UNKNOWN"); - token_name = estrndup("UNKNOWN", token_length); - token_found = 0; - } - - 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); - - 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'; - } - - if (!token_found) { - if (token_name) { - efree(token_name); - } - } - } - } else { - status->syntax_error_len = strlen("Syntax error, unexpected EOF"); - status->syntax_error = estrndup("Syntax error, unexpected EOF", status->syntax_error_len); - } - - 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); -} - -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 { - 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 { - ZVAL_STRING(*error_msg, "Scanning error near to EOF", 1); - } - - if (error) { - efree(error); - } -} - -static int phql_parse_phql(zval *result, zval *phql TSRMLS_DC) { - - zval *error_msg = NULL; - - ZVAL_NULL(result); - - 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; - } - - 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; - } - } - } - - phql_parser = phql_Alloc(phql_wrapper_alloc); - - parser_status = emalloc(sizeof(phql_parser_status)); - state = emalloc(sizeof(phql_scanner_state)); - - 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; - - state->active_token = 0; - state->start = phql; - state->start_length = 0; - state->end = state->start; - - token.value = NULL; - token.len = 0; - - while (0 <= (scanner_status = phql_get_token(state, &token))) { - - /* 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; - - 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_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); - } - } - - 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); - } - } - - 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); - } - } - - 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); - } - - } - } - - 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); - } - } - } - - 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); - } - - } - } - - 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); - } - } - - 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); - } - } - - 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; - } - } - - 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; - } - } - - 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; - } - } - - 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; - } - } - - 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; - } - } - - 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(); - - 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(); - - 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(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_Manager, existsHasOne){ - - zval *model_name, *model_relation, *initialized; - zval *entity_name, *entity_relation, *key_relation; - zval *has_one; - - PHALCON_MM_GROW(); - - 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(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; - } - - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, existsHasManyToMany){ - - zval *model_name, *model_relation, *initialized; - zval *entity_name, *entity_relation, *key_relation; - zval *has_many_to_many; - - PHALCON_MM_GROW(); - - 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(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_Manager, getRelationByAlias){ - - zval *model_name, *alias, *aliases, *key_alias; - zval *key_lower, *relation; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model_name, &alias); - - 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_INIT_VAR(key_alias); - PHALCON_CONCAT_VSV(key_alias, model_name, "$", alias); - - 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_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getRelationRecords){ - - 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, 3, 1, &relation, &method, &record, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } else { - PHALCON_SEPARATE_PARAM(parameters); - } - - PHALCON_INIT_VAR(pre_conditions); - - 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); - } - } - - 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_INIT_VAR(referenced_model); - phalcon_call_method_key(referenced_model, relation, "getreferencedmodel", 478093161UL); - - PHALCON_INIT_VAR(is_through); - phalcon_call_method_key(is_through, relation, "isthrough", 2540564770UL); - if (zend_is_true(is_through)) { - - PHALCON_INIT_VAR(conditions); - array_init(conditions); - - PHALCON_INIT_VAR(intermediate_model); - phalcon_call_method_key(intermediate_model, relation, "getintermediatemodel", 851527441UL); - - PHALCON_INIT_VAR(intermediate_fields); - phalcon_call_method_key(intermediate_fields, relation, "getintermediatefields", 1646880791UL); - - 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_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_INIT_VAR(join_conditions); - array_init(join_conditions); - - 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_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_INIT_VAR(joined_join_conditions); - phalcon_fast_join_str(joined_join_conditions, SL(" AND "), join_conditions TSRMLS_CC); - - if (PHALCON_IS_NOT_EMPTY(pre_conditions)) { - phalcon_array_append(&conditions, pre_conditions, PH_SEPARATE); - } - - PHALCON_INIT_VAR(joined_conditions); - phalcon_fast_join_str(joined_conditions, SL(" AND "), conditions TSRMLS_CC); - - 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); - - PHALCON_INIT_VAR(query); - phalcon_call_method_key(query, builder, "getquery", 4154457883UL); - - phalcon_call_method_key(return_value, query, "execute", 3117639032UL); - RETURN_MM(); - } - - 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_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); - - PHALCON_INIT_VAR(referenced_field); - phalcon_call_method_key(referenced_field, relation, "getreferencedfields", 2208451439UL); - - 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(fields, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(ref_position, ah0, hp0); - PHALCON_GET_HVALUE(field); - - PHALCON_INIT_NVAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); - - 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_INIT_VAR(dependency_injector); - phalcon_call_method_key(dependency_injector, record, "getdi", 4287060818UL); - - 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_INIT_VAR(arguments); - array_init_size(arguments, 1); - phalcon_array_append(&arguments, find_arguments, PH_SEPARATE); - - if (Z_TYPE_P(method) == IS_NULL) { - PHALCON_INIT_VAR(type); - phalcon_call_method_key(type, relation, "gettype", 4294422375UL); - - switch (phalcon_get_intval(type)) { - - case 0: - PHALCON_INIT_VAR(retrieve_method); - ZVAL_STRING(retrieve_method, "findFirst", 1); - break; - - case 1: - PHALCON_INIT_NVAR(retrieve_method); - ZVAL_STRING(retrieve_method, "findFirst", 1); - break; - - case 2: - PHALCON_INIT_NVAR(retrieve_method); - ZVAL_STRING(retrieve_method, "find", 1); - break; - - } - } else { - PHALCON_CPY_WRT(retrieve_method, method); - } - - 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); - } - - RETURN_CCTOR(records); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getReusableRecords){ - - zval *model_name, *key, *reusable, *records; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model_name, &key); - - 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); - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, setReusableRecords){ - - zval *model_name, *key, *records; - - phalcon_fetch_params(0, 3, 0, &model_name, &key, &records); - - phalcon_update_property_array(this_ptr, SL("_reusable"), key, records TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, clearReusableObjects){ - - - 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, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - 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_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(belongs_to, key_relation)) { - RETURN_MM_FALSE; - } - - PHALCON_OBS_VAR(relations); - phalcon_array_fetch(&relations, belongs_to, 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; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasManyRecords){ - - 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_fetch_params(1, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - 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_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_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(); - } - - 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; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getBelongsTo){ - - zval *model, *belongs_to_single, *lower_name; - zval *relations; - - PHALCON_MM_GROW(); - - 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(); -} - -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(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasManyToMany){ - - zval *model, *has_many_to_many_single, *lower_name; - zval *relations; - - PHALCON_MM_GROW(); - - 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_Manager, getHasOneAndHasMany){ - - zval *model, *has_one, *has_many; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(has_one); - phalcon_call_method_p1_key(has_one, this_ptr, "gethasone", model, 153625411UL); - - 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_Manager, getRelations){ - - 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_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_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)) { - - 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_Manager, getRelationsBetween){ - - zval *first, *second, *first_name, *second_name; - zval *key_relation, *belongs_to, *relations = NULL; - zval *has_many, *has_one; - - 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(); - - 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_MM_GROW(); - - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getLastQuery){ - - - RETURN_MEMBER_QUICK(this_ptr, "_lastQuery", 148087694UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, registerNamespaceAlias){ - - zval *alias, *namespace; - - phalcon_fetch_params(0, 2, 0, &alias, &namespace); - - 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(namespace) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The namespace must be a string"); - return; - } - - phalcon_update_property_array(this_ptr, SL("_namespaceAliases"), alias, namespace TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getNamespaceAlias){ - - zval *alias, *namespace_aliases, *namespace; - zval *exception_message; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &alias); - - 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); - } - - 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_Manager, getNamespaceAliases){ - - - RETURN_MEMBER_QUICK(this_ptr, "_namespaceAliases", 3928808595UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, __destruct){ - - - PHALCON_MM_GROW(); - - phalcon_orm_destroy_cache(TSRMLS_C); - - PHALCON_MM_RESTORE(); -} - - - - - -#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; -} - - - - - - - -#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); - } - - 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_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; - } - } else { - PHALCON_CPY_WRT(real_column_name, column_name); - } - } - - 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); - } - - } 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_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); - } - - 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; - - } - - 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); - } - - 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; ->>>>>>> 1.2.2 - - 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; - } - -<<<<<<< HEAD - if (parser_status->status != PHQL_PARSING_OK) { - status = FAILURE; - break; - } - - 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); -======= - 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); - } - - 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; - } - - 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); ->>>>>>> 1.2.2 - } - - 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); - } -<<<<<<< HEAD - - 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); -======= - - 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); ->>>>>>> 1.2.2 - } - - 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); - } -<<<<<<< HEAD - - phql_Free(phql_parser, phql_wrapper_free); - - if (status != FAILURE) { - if (parser_status->status == PHQL_PARSING_OK) { - if (parser_status->ret) { -======= - - 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; ->>>>>>> 1.2.2 - - 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++); - } - } - -<<<<<<< HEAD - 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); - } -======= - 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); - } - - 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; ->>>>>>> 1.2.2 - - Z_ADDREF_PP(result); - -<<<<<<< HEAD - 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; -} -======= - 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); - } - } - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); - return; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getJoinType){ ->>>>>>> 1.2.2 - - zval *join, *type, *join_type = NULL, *phql, *exception_message; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - -#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; -======= - 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); ->>>>>>> 1.2.2 -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query, _getSingleJoin){ - -<<<<<<< HEAD - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#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_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); - } - } 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); - } - } 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); - } - } 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); - } - } 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); - } - - 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(); -} - -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); - } - - 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(); -} - -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(); -} - -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; -======= - 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; - } - - 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); - } - - } - - 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; - } - - 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); - } - - } 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; - } - - 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; - } - - 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); - } - - 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); - } - - 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); - } - - zend_hash_move_forward_ex(ah3, &hp3); - } - - 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; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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); - } - - 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(); -} - -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_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; - } - } - - 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); - } - } - } - - 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; - } - } - - 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); - } - } - - 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_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_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); - } - } 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_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); - } - - } 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); - } - - 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); - } - - 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; - } - - 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); - } - - 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); - } - } 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); - } - } - } - 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); - } - - 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); ->>>>>>> 1.2.2 - } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - -<<<<<<< HEAD -} - -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; - } - RETURN_CCTOR(cloned); - } - - 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); - } - 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); - } - } - - 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); - } - } - - 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); - } - } - - 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); - } - } - - 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); - } - } - - 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); - } - - } - } - - 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); - } - } - } - - 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); - } - - } - } - - 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); - } - } - - 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); - } - } - - 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; -======= - 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; - } - - 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); ->>>>>>> 1.2.2 - } - } - -<<<<<<< HEAD - 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; - } - } - - 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; - } - } - - 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; - } - } - - 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; - } - } - - 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(); - - 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(); - - 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(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_Manager, existsHasOne){ - - zval *model_name, *model_relation, *initialized; - zval *entity_name, *entity_relation, *key_relation; - zval *has_one; - - PHALCON_MM_GROW(); - - 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(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; - } - - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, existsHasManyToMany){ - - zval *model_name, *model_relation, *initialized; - zval *entity_name, *entity_relation, *key_relation; - zval *has_many_to_many; - - PHALCON_MM_GROW(); - - 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(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_Manager, getRelationByAlias){ - - zval *model_name, *alias, *aliases, *key_alias; - zval *key_lower, *relation; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model_name, &alias); - - 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_INIT_VAR(key_alias); - PHALCON_CONCAT_VSV(key_alias, model_name, "$", alias); - - 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); - } -======= - 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_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); - } - - 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_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); - } - } - } - - 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; - - } - } - } - - 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; - } - } 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); - } - - 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; - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - 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); - } - - 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); - } - } - } else { - PHALCON_INIT_NVAR(is_simple_std); - ZVAL_BOOL(is_simple_std, 1); - } - } - - 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); - } - - 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); - } - } - } - - zend_hash_move_forward_ex(ah2, &hp2); ->>>>>>> 1.2.2 - } - zend_hash_destroy(ah2); - efree(ah2); - -<<<<<<< HEAD - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getRelationRecords){ - - 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, 3, 1, &relation, &method, &record, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } else { - PHALCON_SEPARATE_PARAM(parameters); - } - - PHALCON_INIT_VAR(pre_conditions); - - 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); - } - } - - 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_INIT_VAR(referenced_model); - phalcon_call_method_key(referenced_model, relation, "getreferencedmodel", 478093161UL); - - PHALCON_INIT_VAR(is_through); - phalcon_call_method_key(is_through, relation, "isthrough", 2540564770UL); - if (zend_is_true(is_through)) { - - PHALCON_INIT_VAR(conditions); - array_init(conditions); - - PHALCON_INIT_VAR(intermediate_model); - phalcon_call_method_key(intermediate_model, relation, "getintermediatemodel", 851527441UL); - - PHALCON_INIT_VAR(intermediate_fields); - phalcon_call_method_key(intermediate_fields, relation, "getintermediatefields", 1646880791UL); - - 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_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_INIT_VAR(join_conditions); - array_init(join_conditions); - - 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_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_INIT_VAR(joined_join_conditions); - phalcon_fast_join_str(joined_join_conditions, SL(" AND "), join_conditions TSRMLS_CC); - - if (PHALCON_IS_NOT_EMPTY(pre_conditions)) { - phalcon_array_append(&conditions, pre_conditions, PH_SEPARATE); - } - - PHALCON_INIT_VAR(joined_conditions); - phalcon_fast_join_str(joined_conditions, SL(" AND "), conditions TSRMLS_CC); - - 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); - - PHALCON_INIT_VAR(query); - phalcon_call_method_key(query, builder, "getquery", 4154457883UL); - - phalcon_call_method_key(return_value, query, "execute", 3117639032UL); - RETURN_MM(); - } - - 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_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); - - PHALCON_INIT_VAR(referenced_field); - phalcon_call_method_key(referenced_field, relation, "getreferencedfields", 2208451439UL); - - 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(fields, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(ref_position, ah0, hp0); - PHALCON_GET_HVALUE(field); - - PHALCON_INIT_NVAR(value); - phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); - - 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_INIT_VAR(dependency_injector); - phalcon_call_method_key(dependency_injector, record, "getdi", 4287060818UL); - - 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_INIT_VAR(arguments); - array_init_size(arguments, 1); - phalcon_array_append(&arguments, find_arguments, PH_SEPARATE); - - if (Z_TYPE_P(method) == IS_NULL) { - PHALCON_INIT_VAR(type); - phalcon_call_method_key(type, relation, "gettype", 4294422375UL); - - switch (phalcon_get_intval(type)) { - - case 0: - PHALCON_INIT_VAR(retrieve_method); - ZVAL_STRING(retrieve_method, "findFirst", 1); - break; - - case 1: - PHALCON_INIT_NVAR(retrieve_method); - ZVAL_STRING(retrieve_method, "findFirst", 1); - break; - - case 2: - PHALCON_INIT_NVAR(retrieve_method); - ZVAL_STRING(retrieve_method, "find", 1); - break; - - } - } else { - PHALCON_CPY_WRT(retrieve_method, method); - } - - 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); - } - - RETURN_CCTOR(records); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getReusableRecords){ - - zval *model_name, *key, *reusable, *records; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model_name, &key); - - 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); - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, setReusableRecords){ - - zval *model_name, *key, *records; - - phalcon_fetch_params(0, 3, 0, &model_name, &key, &records); - - phalcon_update_property_array(this_ptr, SL("_reusable"), key, records TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, clearReusableObjects){ - - - 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, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - 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_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(belongs_to, key_relation)) { - RETURN_MM_FALSE; - } - - PHALCON_OBS_VAR(relations); - phalcon_array_fetch(&relations, belongs_to, 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; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasManyRecords){ - - 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_fetch_params(1, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - 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_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_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(); - } - - 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; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getBelongsTo){ - - zval *model, *belongs_to_single, *lower_name; - zval *relations; - - PHALCON_MM_GROW(); - - 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(); -} - -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(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasManyToMany){ - - zval *model, *has_many_to_many_single, *lower_name; - zval *relations; - - PHALCON_MM_GROW(); - - 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_Manager, getHasOneAndHasMany){ - - zval *model, *has_one, *has_many; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &model); - - PHALCON_INIT_VAR(has_one); - phalcon_call_method_p1_key(has_one, this_ptr, "gethasone", model, 153625411UL); - - 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_Manager, getRelations){ - - 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_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_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)) { - - 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_Manager, getRelationsBetween){ - - zval *first, *second, *first_name, *second_name; - zval *key_relation, *belongs_to, *relations = NULL; - zval *has_many, *has_one; - - 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(); - - 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_MM_GROW(); - - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getLastQuery){ - - - RETURN_MEMBER_QUICK(this_ptr, "_lastQuery", 148087694UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, registerNamespaceAlias){ - - zval *alias, *namespace; - - phalcon_fetch_params(0, 2, 0, &alias, &namespace); - - 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(namespace) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The namespace must be a string"); - return; - } - - phalcon_update_property_array(this_ptr, SL("_namespaceAliases"), alias, namespace TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, getNamespaceAlias){ - - zval *alias, *namespace_aliases, *namespace; - zval *exception_message; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &alias); - - 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); - } - - 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_Manager, getNamespaceAliases){ - - - RETURN_MEMBER_QUICK(this_ptr, "_namespaceAliases", 3928808595UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Manager, __destruct){ - - - PHALCON_MM_GROW(); - - phalcon_orm_destroy_cache(TSRMLS_C); - - PHALCON_MM_RESTORE(); -} - - - - - -#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; -} - - - - - - - -#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); - } - - 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_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; - } - } else { - PHALCON_CPY_WRT(real_column_name, column_name); - } - } - - 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); - } - - } 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_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); - } - - 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; - - } - - 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); - } - - 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_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); - } - - } 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); - } - - 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; - - } - - 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); - } - - 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; - } - - 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(); - } - - 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; - } - - 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(); - } - - 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; - } - - 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; - } - - 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_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){ - ->>>>>>> 1.2.2 - - RETURN_MEMBER_QUICK(this_ptr, "_bindTypes", 514734038UL); -} - -<<<<<<< HEAD - 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); - } - - 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; - } - - 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); - } - - 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); - } - - 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); - } - - 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); - } - } - 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; -======= -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_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); - } - 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_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; -} - -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); - } - - } - } - - 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); - } - - 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; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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; - } - - 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); - -======= - 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); - } - - if (zend_is_true(collect)) { - phalcon_call_method_p1_key(NULL, this_ptr, "_collecttransaction", transaction, 3516646160UL); - } - ->>>>>>> 1.2.2 - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - -<<<<<<< HEAD - 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; - } - - 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); - } - - } 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; -======= - 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; ->>>>>>> 1.2.2 - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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; - } - - 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; - } - - 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); - } - - phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); -======= - 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_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_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); ->>>>>>> 1.2.2 - } - 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); - -<<<<<<< HEAD - 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); - } - - 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); - } - - zend_hash_move_forward_ex(ah3, &hp3); - } - - 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); - } - } 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_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); - } - - } 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_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_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; -} - - - - - -#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); - } - - 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_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_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; -} - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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); - } - - 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); - } - - 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; - } - - 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); - } - - 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); - } - } 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); - } - } - } - 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); - } - - 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); -======= - -#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; - } - } - - 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); ->>>>>>> 1.2.2 - - 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"); - } - -<<<<<<< HEAD - 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; - } - - 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); - } - - 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_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_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; -} - - - - - -#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); - } - - 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_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"); - } - - 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_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"); - } - - 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_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"); - } - - 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){ - - 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_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; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, __construct){ - - zval *message, *field = NULL, *type = NULL, *model = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 3, &message, &field, &type, &model); - - if (!field) { - PHALCON_INIT_VAR(field); - } - - if (!type) { - PHALCON_INIT_VAR(type); - } - - if (!model) { - PHALCON_INIT_VAR(model); - } - - 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_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, 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_Message, getType){ - - - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, setMessage){ - - zval *message; - - 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_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_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_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); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, __set_state){ - - zval *message, *message_text, *field, *type; - - PHALCON_MM_GROW(); - - 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_mvc_model_message_ce); - phalcon_call_method_p3_key(NULL, return_value, "__construct", message_text, field, type, 1107214344UL); - - RETURN_MM(); -} - - - - - -#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_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_CriteriaInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, CriteriaInterface, mvc_model_criteriainterface, phalcon_mvc_model_criteriainterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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); - } - - 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_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); - } -======= - - - - - - - -#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_MessageInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, MessageInterface, mvc_model_messageinterface, phalcon_mvc_model_messageinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - -#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; -} - -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); ->>>>>>> 1.2.2 - } - } - } - -<<<<<<< HEAD - 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; - - } - } - } - - 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){ -======= - 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(); -} - -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); - -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -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); - -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getStrategy){ - - zval *strategy = NULL; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_cacheOptions", 528255652UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query, getCache){ -======= - 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); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, readMetaData){ - - zval *model, *table, *schema, *class_name, *key, *meta_data = NULL; - zval *data; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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; - } - } 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); - } - - 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; - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - 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); - } - - 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); - } - } - } else { - PHALCON_INIT_NVAR(is_simple_std); - ZVAL_BOOL(is_simple_std, 1); - } - } - - 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); - } - - 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); - } - } - } - - 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); - } - - 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); - } - - 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; -======= - 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); -} - -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); -} - -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(); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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(); -} - -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(); -} - -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); -} - -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); -} - -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; -} - -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; -} - -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(); -} - - - - - -#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_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_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_MetaData_Session){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\MetaData, Session, mvc_model_metadata_session, "phalcon\\mvc\\model\\metadata", phalcon_mvc_model_metadata_session_method_entry, 0); - - zend_declare_property_string(phalcon_mvc_model_metadata_session_ce, SL("_prefix"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_metadata_session_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Session, __construct){ - - zval *options = NULL, *prefix, *empty_array; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (Z_TYPE_P(options) == IS_ARRAY) { - 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(empty_array); - array_init(empty_array); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Session, read){ - - zval *key, *session = NULL, *_SESSION, *prefix, *prefix_key; - zval *meta_data; - zval *r0 = NULL, *r1 = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); - PHALCON_CPY_WRT(session, _SESSION); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefix_key); - PHALCON_CONCAT_SV(prefix_key, "$PMM$", prefix); - if (phalcon_array_isset(session, prefix_key)) { - - PHALCON_OBS_VAR(r0); - phalcon_array_fetch(&r0, session, prefix_key, PH_NOISY); - if (phalcon_array_isset(r0, key)) { - PHALCON_OBS_VAR(r1); - phalcon_array_fetch(&r1, session, prefix_key, PH_NOISY); - PHALCON_OBS_VAR(meta_data); - phalcon_array_fetch(&meta_data, r1, key, PH_NOISY); - RETURN_CCTOR(meta_data); - } - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Session, write){ - - zval *key, *data, *prefix, *prefix_key, *_SESSION; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &key, &data); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefix_key); - PHALCON_CONCAT_SV(prefix_key, "$PMM$", prefix); - phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); - phalcon_array_update_multi_2(&_SESSION, prefix_key, key, &data, 0); - - PHALCON_MM_RESTORE(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Strategy_Introspection){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\MetaData\\Strategy, Introspection, mvc_model_metadata_strategy_introspection, phalcon_mvc_model_metadata_strategy_introspection_method_entry, 0); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Introspection, getMetaData){ - - zval *model, *dependency_injector, *class_name; - zval *schema, *table, *read_connection, *exists; - zval *complete_table = NULL, *exception_message = NULL; - zval *columns, *attributes, *primary_keys, *non_primary_keys; - zval *numeric_typed, *not_null, *field_types; - zval *field_bind_types, *automatic_default; - zval *identity_field = NULL, *column = NULL, *field_name = NULL, *feature = NULL; - zval *type = NULL, *bind_type = NULL, *model_metadata; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, model, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - - PHALCON_INIT_VAR(table); - phalcon_call_method_key(table, model, "getsource", 2025234358UL); - - PHALCON_INIT_VAR(read_connection); - phalcon_call_method_key(read_connection, model, "getreadconnection", 488334257UL); - - PHALCON_INIT_VAR(exists); - phalcon_call_method_p2_key(exists, read_connection, "tableexists", table, schema, 1944065613UL); - if (!zend_is_true(exists)) { - if (zend_is_true(schema)) { - PHALCON_INIT_VAR(complete_table); - PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); - } else { - PHALCON_CPY_WRT(complete_table, table); - } - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Table \"", complete_table, "\" doesn't exist on database when dumping meta-data for ", class_name); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_INIT_VAR(columns); - phalcon_call_method_p2_key(columns, read_connection, "describecolumns", table, schema, 4645575UL); - if (!phalcon_fast_count_ev(columns TSRMLS_CC)) { - if (zend_is_true(schema)) { - PHALCON_INIT_NVAR(complete_table); - PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); - } else { - PHALCON_CPY_WRT(complete_table, table); - } - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Cannot obtain table columns for the mapped source \"", complete_table, "\" used in model ", class_name); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_INIT_VAR(attributes); - array_init(attributes); - - PHALCON_INIT_VAR(primary_keys); - array_init(primary_keys); - - PHALCON_INIT_VAR(non_primary_keys); - array_init(non_primary_keys); - - PHALCON_INIT_VAR(numeric_typed); - array_init(numeric_typed); - - PHALCON_INIT_VAR(not_null); - array_init(not_null); - - PHALCON_INIT_VAR(field_types); - array_init(field_types); - - PHALCON_INIT_VAR(field_bind_types); - array_init(field_bind_types); - - PHALCON_INIT_VAR(automatic_default); - array_init(automatic_default); - - PHALCON_INIT_VAR(identity_field); - ZVAL_BOOL(identity_field, 0); - - 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(field_name); - phalcon_call_method_key(field_name, column, "getname", 4286441094UL); - phalcon_array_append(&attributes, field_name, PH_SEPARATE); - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_key(feature, column, "isprimary", 3539965925UL); - if (PHALCON_IS_TRUE(feature)) { - phalcon_array_append(&primary_keys, field_name, PH_SEPARATE); - } else { - phalcon_array_append(&non_primary_keys, field_name, PH_SEPARATE); - } - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_key(feature, column, "isnumeric", 3929517108UL); - if (PHALCON_IS_TRUE(feature)) { - phalcon_array_update_zval_bool(&numeric_typed, field_name, 1, PH_SEPARATE); - } - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_key(feature, column, "isnotnull", 760409005UL); - if (PHALCON_IS_TRUE(feature)) { - phalcon_array_append(¬_null, field_name, PH_SEPARATE); - } - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_key(feature, column, "isautoincrement", 572890271UL); - if (PHALCON_IS_TRUE(feature)) { - PHALCON_CPY_WRT(identity_field, field_name); - } - - PHALCON_INIT_NVAR(type); - phalcon_call_method_key(type, column, "gettype", 4294422375UL); - phalcon_array_update_zval(&field_types, field_name, &type, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_NVAR(bind_type); - phalcon_call_method_key(bind_type, column, "getbindtype", 13600356UL); - phalcon_array_update_zval(&field_bind_types, field_name, &bind_type, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(model_metadata); - array_init(model_metadata); - phalcon_array_update_long(&model_metadata, 0, &attributes, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 4, &field_types, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 9, &field_bind_types, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 10, &automatic_default, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 11, &automatic_default, PH_COPY | PH_SEPARATE); - - RETURN_CTOR(model_metadata); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Introspection, getColumnMaps){ - - zval *model, *dependency_injector, *ordered_column_map = NULL; - zval *reversed_column_map = NULL, *user_column_map; - zval *user_name = NULL, *name = NULL, *model_column_map; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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; - - } - - 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); - } - - 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_fetch_params(1, 2, 0, &model, &dependency_injector); - - PHALCON_INIT_VAR(ordered_column_map); - - PHALCON_INIT_VAR(reversed_column_map); - - if (phalcon_method_quick_exists_ex(model, SS("columnmap"), 673371633UL TSRMLS_CC) == SUCCESS) { - - PHALCON_INIT_VAR(user_column_map); - phalcon_call_method_key(user_column_map, model, "columnmap", 673371633UL); - if (Z_TYPE_P(user_column_map) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "columnMap() not returned an array"); - return; - } - - array_init(reversed_column_map); - PHALCON_CPY_WRT(ordered_column_map, user_column_map); - - phalcon_is_iterable(user_column_map, &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(user_name); - - phalcon_array_update_zval(&reversed_column_map, user_name, &name, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - PHALCON_INIT_VAR(model_column_map); - array_init(model_column_map); - phalcon_array_update_long(&model_column_map, 0, &ordered_column_map, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_column_map, 1, &reversed_column_map, PH_COPY | PH_SEPARATE); - - RETURN_CTOR(model_column_map); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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; -======= - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Strategy_Annotations){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\MetaData\\Strategy, Annotations, mvc_model_metadata_strategy_annotations, phalcon_mvc_model_metadata_strategy_annotations_method_entry, 0); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getMetaData){ - - zval *model, *dependency_injector, *service; - zval *annotations, *class_name, *reflection; - zval *exception_message = NULL, *properties_annotations; - zval *attributes, *primary_keys, *non_primary_keys; - zval *numeric_typed, *not_null, *field_types; - zval *field_bind_types, *automatic_default; - zval *identity_field = NULL, *column_annot_name; - zval *primary_annot_name, *id_annot_name; - zval *column_type_name, *column_nullable_name; - zval *prop_annotations = NULL, *property = NULL, *has_annotation = NULL; - zval *column_annotation = NULL, *feature = NULL, *model_metadata; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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_fetch_params(1, 2, 0, &model, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); - return; - } - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "annotations", 1); - - PHALCON_INIT_VAR(annotations); - phalcon_call_method_p1_key(annotations, dependency_injector, "get", service, 2090288933UL); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, model, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(reflection); - phalcon_call_method_p1_key(reflection, annotations, "get", class_name, 2090288933UL); - if (Z_TYPE_P(reflection) != IS_OBJECT) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "No annotations were found in class ", class_name); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_INIT_VAR(properties_annotations); - phalcon_call_method_key(properties_annotations, reflection, "getpropertiesannotations", 3353352384UL); - if (!phalcon_fast_count_ev(properties_annotations TSRMLS_CC)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "No properties with annotations were found in class ", class_name); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_INIT_VAR(attributes); - array_init(attributes); - - PHALCON_INIT_VAR(primary_keys); - array_init(primary_keys); - - PHALCON_INIT_VAR(non_primary_keys); - array_init(non_primary_keys); - - PHALCON_INIT_VAR(numeric_typed); - array_init(numeric_typed); - - PHALCON_INIT_VAR(not_null); - array_init(not_null); - - PHALCON_INIT_VAR(field_types); - array_init(field_types); - - PHALCON_INIT_VAR(field_bind_types); - array_init(field_bind_types); - - PHALCON_INIT_VAR(automatic_default); - array_init(automatic_default); - - PHALCON_INIT_VAR(identity_field); - ZVAL_BOOL(identity_field, 0); - - PHALCON_INIT_VAR(column_annot_name); - ZVAL_STRING(column_annot_name, "Column", 1); - - PHALCON_INIT_VAR(primary_annot_name); - ZVAL_STRING(primary_annot_name, "Primary", 1); - - PHALCON_INIT_VAR(id_annot_name); - ZVAL_STRING(id_annot_name, "Identity", 1); - - PHALCON_INIT_VAR(column_type_name); - ZVAL_STRING(column_type_name, "type", 1); - - PHALCON_INIT_VAR(column_nullable_name); - ZVAL_STRING(column_nullable_name, "nullable", 1); - - phalcon_is_iterable(properties_annotations, &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(prop_annotations); - - PHALCON_INIT_NVAR(has_annotation); - phalcon_call_method_p1_key(has_annotation, prop_annotations, "has", column_annot_name, 2090320481UL); - if (!zend_is_true(has_annotation)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; ->>>>>>> 1.2.2 - } - phalcon_array_update_zval(&update_values, field_name, &update_value, PH_COPY | PH_SEPARATE); - -<<<<<<< HEAD - 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; - } - - 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(); - } - - 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; - } - - 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(); - } - - 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; - } - - 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; - } - - 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_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; -======= - PHALCON_INIT_NVAR(column_annotation); - phalcon_call_method_p1_key(column_annotation, prop_annotations, "get", column_annot_name, 2090288933UL); - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_p1_key(feature, column_annotation, "getnamedparameter", column_type_name, 3202516043UL); - if (PHALCON_IS_STRING(feature, "integer")) { - phalcon_array_update_zval_long(&field_types, property, 0, PH_SEPARATE); - phalcon_array_update_zval_long(&field_bind_types, property, 1, PH_SEPARATE); - phalcon_array_update_zval_bool(&numeric_typed, property, 1, PH_SEPARATE); - } else { - if (PHALCON_IS_STRING(feature, "decimal")) { - phalcon_array_update_zval_long(&field_types, property, 3, PH_SEPARATE); - phalcon_array_update_zval_long(&field_bind_types, property, 32, PH_SEPARATE); - phalcon_array_update_zval_bool(&numeric_typed, property, 1, PH_SEPARATE); - } else { - if (PHALCON_IS_STRING(feature, "boolean")) { - phalcon_array_update_zval_long(&field_types, property, 8, PH_SEPARATE); - phalcon_array_update_zval_long(&field_bind_types, property, 5, PH_SEPARATE); - } else { - if (PHALCON_IS_STRING(feature, "date")) { - phalcon_array_update_zval_long(&field_types, property, 1, PH_SEPARATE); - } else { - phalcon_array_update_zval_long(&field_types, property, 2, PH_SEPARATE); - } - phalcon_array_update_zval_long(&field_bind_types, property, 2, PH_SEPARATE); - } - } - } - - PHALCON_INIT_NVAR(has_annotation); - phalcon_call_method_p1_key(has_annotation, prop_annotations, "has", primary_annot_name, 2090320481UL); - if (zend_is_true(has_annotation)) { - phalcon_array_append(&primary_keys, property, PH_SEPARATE); - } else { - phalcon_array_append(&non_primary_keys, property, PH_SEPARATE); - } - - PHALCON_INIT_NVAR(has_annotation); - phalcon_call_method_p1_key(has_annotation, prop_annotations, "has", id_annot_name, 2090320481UL); - if (zend_is_true(has_annotation)) { - PHALCON_CPY_WRT(identity_field, property); - } - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_p1_key(feature, column_annotation, "getnamedparameter", column_nullable_name, 3202516043UL); - if (!zend_is_true(feature)) { - phalcon_array_append(¬_null, property, PH_SEPARATE); - } - - phalcon_array_append(&attributes, property, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(model_metadata); - array_init(model_metadata); - phalcon_array_update_long(&model_metadata, 0, &attributes, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 4, &field_types, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 9, &field_bind_types, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 10, &automatic_default, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 11, &automatic_default, PH_COPY | PH_SEPARATE); - - RETURN_CTOR(model_metadata); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getColumnMaps){ - - - -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Apc){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\MetaData, Apc, mvc_model_metadata_apc, "phalcon\\mvc\\model\\metadata", phalcon_mvc_model_metadata_apc_method_entry, 0); - - zend_declare_property_string(phalcon_mvc_model_metadata_apc_ce, SL("_prefix"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_model_metadata_apc_ce, SL("_ttl"), 172800, ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_metadata_apc_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, __construct){ - - zval *options = NULL, *prefix, *ttl, *empty_array; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); ->>>>>>> 1.2.2 - - } - -<<<<<<< HEAD - 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){ -======= - if (Z_TYPE_P(options) == IS_ARRAY) { - 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); - } - if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_VAR(ttl); - phalcon_array_fetch_quick_string(&ttl, options, SS("lifetime"), 2639810228UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_ttl"), ttl, 251113304UL TSRMLS_CC); - } - } - - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, read){ - - zval *key, *prefix, *apc_key, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(apc_key); - PHALCON_CONCAT_SVV(apc_key, "$PMM$", prefix, key); - - PHALCON_INIT_VAR(data); - phalcon_call_func_p1(data, "apc_fetch", apc_key); - if (Z_TYPE_P(data) == IS_ARRAY) { - RETURN_CCTOR(data); - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, write){ - - zval *key, *data, *prefix, *apc_key, *ttl; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &key, &data); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(apc_key); - PHALCON_CONCAT_SVV(apc_key, "$PMM$", prefix, key); - - PHALCON_OBS_VAR(ttl); - phalcon_read_property_this_quick(&ttl, this_ptr, SL("_ttl"), 251113304UL, PH_NOISY_CC); - phalcon_call_func_p3_noret("apc_store", apc_key, data, ttl); - - PHALCON_MM_RESTORE(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Files){ - - 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); - - zend_declare_property_string(phalcon_mvc_model_metadata_files_ce, SL("_metaDataDir"), "./", ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_metadata_files_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, __construct){ - - zval *options = NULL, *meta_data_dir, *empty_array; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - 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); - } - } - - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, read){ - - zval *key, *separator, *meta_data_dir, *virtual_key; - zval *path, *data; ->>>>>>> 1.2.2 - - zval *type; - -<<<<<<< HEAD - phalcon_fetch_params(0, 1, 0, &type); -======= - 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"); - - 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); - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, write){ - - 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, ">>>>>> 1.2.2 - - phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query, getType){ - - -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Query, setBindParams){ -======= - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Xcache){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\MetaData, Xcache, mvc_model_metadata_xcache, "phalcon\\mvc\\model\\metadata", phalcon_mvc_model_metadata_xcache_method_entry, 0); - - zend_declare_property_string(phalcon_mvc_model_metadata_xcache_ce, SL("_prefix"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_model_metadata_xcache_ce, SL("_ttl"), 172800, ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_metadata_xcache_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Xcache, __construct){ - - zval *options = NULL, *prefix, *ttl, *empty_array; ->>>>>>> 1.2.2 - - zval *bind_params; - -<<<<<<< HEAD - 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); -======= - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (Z_TYPE_P(options) == IS_ARRAY) { - 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); - } - if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_VAR(ttl); - phalcon_array_fetch_quick_string(&ttl, options, SS("lifetime"), 2639810228UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_ttl"), ttl, 251113304UL TSRMLS_CC); - } - } - - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Xcache, read){ - - zval *key, *prefix, *xc_key, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(xc_key); - PHALCON_CONCAT_SVV(xc_key, "$PMM$", prefix, key); - - PHALCON_INIT_VAR(data); - phalcon_call_func_p1(data, "xcache_get", xc_key); - if (Z_TYPE_P(data) == IS_ARRAY) { - RETURN_CCTOR(data); - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Xcache, write){ - - zval *key, *data, *prefix, *xc_key, *ttl; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &key, &data); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(xc_key); - PHALCON_CONCAT_SVV(xc_key, "$PMM$", prefix, key); - - PHALCON_OBS_VAR(ttl); - phalcon_read_property_this_quick(&ttl, this_ptr, SL("_ttl"), 251113304UL, PH_NOISY_CC); - phalcon_call_func_p3_noret("xcache_set", xc_key, data, ttl); - - PHALCON_MM_RESTORE(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Memory){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\MetaData, Memory, mvc_model_metadata_memory, "phalcon\\mvc\\model\\metadata", phalcon_mvc_model_metadata_memory_method_entry, 0); - - zend_class_implements(phalcon_mvc_model_metadata_memory_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Memory, __construct){ - - zval *options = NULL, *empty_array; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Memory, read){ - - zval *key; - - phalcon_fetch_params(0, 1, 0, &key); - - RETURN_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Memory, write){ - - zval *key, *meta_data; - - phalcon_fetch_params(0, 2, 0, &key, &meta_data); - - RETURN_NULL(); ->>>>>>> 1.2.2 -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -<<<<<<< HEAD -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); -======= -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); ->>>>>>> 1.2.2 - - return SUCCESS; -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model_Behavior, __construct){ - - zval *options = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); -======= -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); ->>>>>>> 1.2.2 - - 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(); - } - -<<<<<<< HEAD - 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); - } - 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); -======= - 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); - } - } ->>>>>>> 1.2.2 - - RETURN_NULL(); -} - -<<<<<<< HEAD -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_Transaction_ManagerInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model\\Transaction, ManagerInterface, mvc_model_transaction_managerinterface, phalcon_mvc_model_transaction_managerinterface_method_entry); - - return SUCCESS; -} - -======= ->>>>>>> 1.2.2 - - - - - - - - - - - -<<<<<<< HEAD - - -#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); ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - -======= -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; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - -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); -======= - 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); - } - } ->>>>>>> 1.2.2 - -} - -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; - -<<<<<<< HEAD - 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){ - -======= -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); ->>>>>>> 1.2.2 - - RETURN_MEMBER_QUICK(this_ptr, "_service", 3205872725UL); -} - -<<<<<<< HEAD -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); - } - - } - } - - 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){ - -======= -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); - } - 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(); -} - -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); - } - } - - 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){ ->>>>>>> 1.2.2 - - zval *is_new; - -<<<<<<< HEAD - 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_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){ ->>>>>>> 1.2.2 - - zval *rollback_on_abort; - -<<<<<<< HEAD - 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); - } - - 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_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){ ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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); - } - - if (zend_is_true(collect)) { - phalcon_call_method_p1_key(NULL, this_ptr, "_collecttransaction", transaction, 3516646160UL); - } - - 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; -======= - 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){ ->>>>>>> 1.2.2 - - zval *record; - -<<<<<<< HEAD - 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_fetch_params(0, 1, 0, &record); - - phalcon_update_property_this_quick(this_ptr, SL("_rollbackRecord"), record, 3406866061UL TSRMLS_CC); - -} - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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; -======= - - -#ifdef HAVE_CONFIG_H -#endif ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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(); -} -======= ->>>>>>> 1.2.2 - - - - - -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); - -<<<<<<< HEAD - -======= - 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); ->>>>>>> 1.2.2 - - -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction_Exception){ -======= -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, next){ ->>>>>>> 1.2.2 - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Transaction, Exception, mvc_model_transaction_exception, "phalcon\\mvc\\model\\exception", NULL, 0); - -<<<<<<< HEAD - return SUCCESS; -======= - phalcon_property_incr(this_ptr, SL("_pointer") TSRMLS_CC); - ->>>>>>> 1.2.2 -} - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, key){ - - - RETURN_MEMBER_QUICK(this_ptr, "_pointer", 3868032485UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, rewind){ - -<<<<<<< HEAD -#ifdef HAVE_CONFIG_H -#endif -======= - zval *type, *result = NULL, *active_row, *zero, *rows = NULL; ->>>>>>> 1.2.2 - - 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); - } - } - } 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); - } - } - - 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(); - } - -<<<<<<< HEAD -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); -} -======= - 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); - } - } - - 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; - } ->>>>>>> 1.2.2 - - 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; - - 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(); -} - -<<<<<<< HEAD -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); -======= -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetGet){ - - zval *index, *count, *pointer, *valid; - - PHALCON_MM_GROW(); ->>>>>>> 1.2.2 - - 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; -} - -<<<<<<< HEAD -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; -======= -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; ->>>>>>> 1.2.2 -} - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getLast){ - - zval *one, *count, *pre_count, *valid; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - -#ifdef HAVE_CONFIG_H -#endif - - - -======= - 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; -} ->>>>>>> 1.2.2 - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, setIsFresh){ - - zval *is_fresh; - -<<<<<<< HEAD - -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); -======= - 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){ - ->>>>>>> 1.2.2 - - RETURN_MEMBER_QUICK(this_ptr, "_isFresh", 1397060440UL); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model_Validator_Url, validate){ - - zval *record, *option = NULL, *field, *value, *flag, *is_valid; - zval *message = NULL, *type; -======= -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, setHydrateMode){ ->>>>>>> 1.2.2 - - zval *hydrate_mode; - -<<<<<<< HEAD - 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; -======= - phalcon_fetch_params(0, 1, 0, &hydrate_mode); - - phalcon_update_property_this_quick(this_ptr, SL("_hydrateMode"), hydrate_mode, 2551752186UL TSRMLS_CC); - RETURN_THISW(); ->>>>>>> 1.2.2 -} - -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){ - -<<<<<<< HEAD -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_MEMBER_QUICK(this_ptr, "_activeRow", 3086770360UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getMessages){ - ->>>>>>> 1.2.2 - - RETURN_MEMBER_QUICK(this_ptr, "_errorMessages", 1019066246UL); -} - -<<<<<<< HEAD -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; -} - - - - - -#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); - } - - 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; -======= -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; - } - - 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; - } - } - - 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; - } - } - - 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_ControllerInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ControllerInterface, mvc_controllerinterface, NULL); - - 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); - - 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; ->>>>>>> 1.2.2 - } - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - -<<<<<<< HEAD - RETURN_MM_TRUE; -======= -} - -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); - - 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_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Url, setStaticBaseUri){ - - 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(); ->>>>>>> 1.2.2 -} - -static PHP_METHOD(Phalcon_Mvc_Url, getBaseUri){ - - zval *base_uri = NULL, *slash, *_SERVER, *php_self, *uri = NULL; - - 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_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_INIT_VAR(uri); - phalcon_get_uri(uri, php_self); - } else { - PHALCON_INIT_NVAR(uri); - } - - 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); - } - - RETURN_CCTOR(base_uri); -} - -<<<<<<< HEAD -#ifdef HAVE_CONFIG_H -#endif - - -======= -static PHP_METHOD(Phalcon_Mvc_Url, getStaticBaseUri){ - - zval *static_base_uri; ->>>>>>> 1.2.2 - - 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_call_method_key(return_value, this_ptr, "getbaseuri", 2750461136UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Url, setBasePath){ - - zval *base_path; - -<<<<<<< HEAD -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); -======= - 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){ - ->>>>>>> 1.2.2 - - RETURN_MEMBER_QUICK(this_ptr, "_basePath", 1477430348UL); -} - -<<<<<<< HEAD -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 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 (!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_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_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(service); - ZVAL_STRING(service, "router", 1); - - 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_OBS_VAR(route_name); - phalcon_array_fetch_quick_string(&route_name, uri, SS("for"), 2090263820UL, PH_NOISY); - - 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_INIT_VAR(pattern); - phalcon_call_method_key(pattern, route, "getpattern", 2464558051UL); - - 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); - } - - 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_Url, getStatic){ - - zval *uri = NULL, *static_base_uri, *base_uri; - - 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_INIT_VAR(base_uri); - phalcon_call_method_key(base_uri, this_ptr, "getbaseuri", 2750461136UL); - PHALCON_CONCAT_VV(return_value, base_uri, uri); - - 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 (!path) { - PHALCON_INIT_VAR(path); - } - - 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(); ->>>>>>> 1.2.2 -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Dispatcher_Exception){ - -<<<<<<< HEAD -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); -======= - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Dispatcher, Exception, mvc_dispatcher_exception, "phalcon\\exception", NULL, 0); ->>>>>>> 1.2.2 - - return SUCCESS; -} - -<<<<<<< HEAD -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; -======= - - - - -#ifdef HAVE_CONFIG_H -#endif - - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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_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 (!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, "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_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); ->>>>>>> 1.2.2 - - 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; -} - -<<<<<<< HEAD - -======= -static PHP_METHOD(Phalcon_Mvc_Model, getEventsManager){ - - zval *models_manager; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - -#ifdef HAVE_CONFIG_H -#endif - -======= - 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; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - - - - -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); - } - - 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; -======= - 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(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); - } - - 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 (Z_TYPE_P(transaction) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_transaction"), transaction, 1141465066UL TSRMLS_CC); - RETURN_THISW(); - } - 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(); ->>>>>>> 1.2.2 -} - -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); - - 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(); -} - -<<<<<<< HEAD - -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); -======= -static PHP_METHOD(Phalcon_Mvc_Model, setConnectionService){ - - zval *connection_service, *models_manager; - - PHALCON_MM_GROW(); ->>>>>>> 1.2.2 - - 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(); -} - -<<<<<<< HEAD -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; -======= -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_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_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(); ->>>>>>> 1.2.2 -} - -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); - - 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); -} - -<<<<<<< HEAD -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); -======= -static PHP_METHOD(Phalcon_Mvc_Model, getReadConnection){ - - zval *models_manager; - - PHALCON_MM_GROW(); ->>>>>>> 1.2.2 - - 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(); -} - -<<<<<<< HEAD -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"); - } - - 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_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"); - } - - 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){ - - 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_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; -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, __construct){ - - zval *message, *field = NULL, *type = NULL, *model = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 3, &message, &field, &type, &model); - - if (!field) { - PHALCON_INIT_VAR(field); - } - - if (!type) { - PHALCON_INIT_VAR(type); - } - - if (!model) { - PHALCON_INIT_VAR(model); - } - - 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_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, 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_Message, getType){ - - - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, setMessage){ - - zval *message; - - 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_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_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_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); -} - -static PHP_METHOD(Phalcon_Mvc_Model_Message, __set_state){ - - zval *message, *message_text, *field, *type; - - PHALCON_MM_GROW(); - - 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_mvc_model_message_ce); - phalcon_call_method_p3_key(NULL, return_value, "__construct", message_text, field, type, 1107214344UL); - - RETURN_MM(); -} - - - - - -#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_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_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_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_MessageInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, MessageInterface, mvc_model_messageinterface, phalcon_mvc_model_messageinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - -#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; -} - -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(); -} - -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); -======= -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_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_Model, assign){ - - 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, 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, "Data to dump in the object must be an Array"); - return; - } - - 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(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(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; - } - } else { - phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - - 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); - - if (!dirty_state) { - PHALCON_INIT_VAR(dirty_state); - ZVAL_LONG(dirty_state, 0); - } - - if (!keep_snapshots) { - PHALCON_INIT_VAR(keep_snapshots); - } - - 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_INIT_VAR(object); - if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { - return; - } - - phalcon_call_method_p1_key(NULL, object, "setdirtystate", dirty_state, 1304577662UL); - - 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) { - - 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); - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - if (zend_is_true(keep_snapshots)) { - phalcon_call_method_p2_key(NULL, object, "setsnapshotdata", data, column_map, 1073494651UL); - } - - if (phalcon_method_quick_exists_ex(object, SS("afterfetch"), 1256108385UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, object, "afterfetch", 1256108385UL); - } - - 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 (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data to hidrate must be an Array"); - return; - } - - if (Z_TYPE_P(column_map) != IS_ARRAY) { - if (PHALCON_IS_LONG(hydration_mode, 1)) { - RETURN_CCTOR(data); - } - } - - if (PHALCON_IS_LONG(hydration_mode, 1)) { - PHALCON_INIT_VAR(hydrate); - array_init(hydrate); - } else { - PHALCON_INIT_NVAR(hydrate); - object_init(hydrate); - } - - 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) { - if (Z_TYPE_P(column_map) == IS_ARRAY) { - - 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); - 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); - } - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - 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 (!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_INIT_VAR(object); - if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { - return; - } - - phalcon_call_method_p1_key(NULL, object, "setdirtystate", dirty_state, 1304577662UL); - - 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) { - 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); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - if (phalcon_method_quick_exists_ex(object, SS("afterfetch"), 1256108385UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, object, "afterfetch", 1256108385UL); - } - - 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); - } - - PHALCON_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); - if (Z_TYPE_P(parameters) != IS_ARRAY) { - - 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_INIT_VAR(builder); - object_init_ex(builder, phalcon_mvc_model_query_builder_ce); - phalcon_call_method_p1_key(NULL, builder, "__construct", params, 1107214344UL); - - phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - - 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); - } - } - - 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(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_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 (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - PHALCON_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); - if (Z_TYPE_P(parameters) != IS_ARRAY) { - - 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_INIT_VAR(builder); - object_init_ex(builder, phalcon_mvc_model_query_builder_ce); - phalcon_call_method_p1_key(NULL, builder, "__construct", params, 1107214344UL); - - phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - - 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); - } - } - - 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(unique); - ZVAL_BOOL(unique, 1); - - phalcon_call_method_p1_key(NULL, query, "setuniquerow", unique, 2999205376UL); - - 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); - - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } else { - PHALCON_SEPARATE_PARAM(dependency_injector); - } - - PHALCON_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - } - - 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); - - 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); - - if (!table) { - PHALCON_INIT_VAR(table); - } else { - PHALCON_SEPARATE_PARAM(table); - } - - PHALCON_INIT_VAR(unique_params); - - PHALCON_INIT_VAR(unique_types); - - 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_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); - - PHALCON_INIT_VAR(number_primary); - phalcon_fast_count(number_primary, primary_keys TSRMLS_CC); - if (!zend_is_true(number_primary)) { - RETURN_MM_FALSE; - } - - 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(null_value); - - PHALCON_INIT_VAR(number_empty); - ZVAL_LONG(number_empty, 0); - - PHALCON_INIT_VAR(where_pk); - array_init(where_pk); - - array_init(unique_params); - - array_init(unique_types); - - phalcon_is_iterable(primary_keys, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(field); - - 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_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); - - if (PHALCON_IS_EMPTY(value)) { - PHALCON_SEPARATE(number_empty); - phalcon_increment(number_empty); - } - - 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); - } - - PHALCON_INIT_NVAR(escaped_field); - phalcon_call_method_p1_key(escaped_field, connection, "escapeidentifier", field, 585773337UL); - - 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; - } - - 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); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - if (PHALCON_IS_EQUAL(number_primary, number_empty)) { - RETURN_MM_FALSE; - } - - PHALCON_INIT_VAR(join_where); - phalcon_fast_join_str(join_where, SL(" AND "), where_pk TSRMLS_CC); - - 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); - } - - 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 (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 (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 (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); - } - - 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_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_VAR(escaped_table); - phalcon_call_method_p1_key(escaped_table, connection, "escapeidentifier", table, 585773337UL); - - PHALCON_INIT_VAR(null_mode); - - PHALCON_INIT_VAR(select); - PHALCON_CONCAT_SVSV(select, "SELECT COUNT(*) \"rowcount\" FROM ", escaped_table, " WHERE ", unique_key); - - PHALCON_INIT_VAR(num); - phalcon_call_method_p4_key(num, connection, "fetchone", select, null_mode, unique_params, unique_types, 1637187313UL); - - 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); - } - - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Model, _groupResult){ - - 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, 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_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); - - 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_call_method_p1_key(NULL, builder, "columns", columns, 1041822630UL); - phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - - 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(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); - } ->>>>>>> 1.2.2 - - if (phalcon_array_isset_quick_string(params, SS("group"), 7349554UL)) { - RETURN_CCTOR(resultset); - } - - 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); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData, setStrategy){ -======= -static PHP_METHOD(Phalcon_Mvc_Model, count){ - - zval *parameters = NULL, *function, *alias; ->>>>>>> 1.2.2 - - zval *strategy; - -<<<<<<< HEAD - 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); - -} - -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); -} - -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); -} - -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); -} - -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(); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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); -} - -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; -======= - phalcon_fetch_params(1, 0, 1, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "COUNT", 1); - - 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 (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - 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); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "MAX", 1); - - 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); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "MIN", 1); - - 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); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "AVG", 1); - - 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); - - 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(); -} - -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_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; -} - -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_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - - 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); - - 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); - - 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); - - 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); - } - - } - - 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; - } - } - - 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); - - 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_GET_HKEY(position, ah1, hp1); - PHALCON_GET_HVALUE(field); - - 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_OBS_NVAR(referenced_field); - phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - - 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); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - } 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(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_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_NVAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - - 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_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_INIT_NVAR(type); - ZVAL_STRING(type, "ConstraintViolation", 1); - - 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_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - - 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; - } ->>>>>>> 1.2.2 - } - - RETURN_CCTOR(data); -} - -<<<<<<< HEAD -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); -} - -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); -} - -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(); -} - -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(); -} - -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); -} - -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); -} - -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; -} - -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; -} - -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(); -} - - - - - -#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); -======= -static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysReverseRestrict){ - - 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_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_INIT_VAR(error); - ZVAL_BOOL(error, 0); - - 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_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(fields); - phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - - PHALCON_INIT_NVAR(referenced_fields); - phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - - PHALCON_INIT_NVAR(conditions); - array_init(conditions); - - PHALCON_INIT_NVAR(bind_params); - array_init(bind_params); - 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_GET_HKEY(position, ah1, hp1); - PHALCON_GET_HVALUE(field); - - 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_OBS_NVAR(referenced_field); - phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - - 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); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - } 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(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_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_NVAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - - 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_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 { - PHALCON_INIT_NVAR(user_message); - PHALCON_CONCAT_SV(user_message, "Record is referenced by model ", relation_class); - } - - PHALCON_INIT_NVAR(type); - ZVAL_STRING(type, "ConstraintViolation", 1); - - 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_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - - 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; - } - } ->>>>>>> 1.2.2 - - RETURN_MM_TRUE; -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model_ValidationFailed, getMessages){ - -======= -static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysReverseCascade){ - - 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; ->>>>>>> 1.2.2 - - RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model_ValidationFailed, getModel){ - - - RETURN_MEMBER_QUICK(this_ptr, "_model", 2599397109UL); -} - - -======= - 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_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, 0); - - 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, 2)) { - - 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(fields); - phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - - PHALCON_INIT_NVAR(referenced_fields); - phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - - PHALCON_INIT_NVAR(conditions); - array_init(conditions); - - PHALCON_INIT_NVAR(bind_params); - array_init(bind_params); - 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_GET_HKEY(position, ah1, hp1); - PHALCON_GET_HVALUE(field); - - 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_OBS_NVAR(referenced_field); - phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - - 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); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - } 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(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_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_NVAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - - 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_NVAR(resulset); - phalcon_call_method_p1_key(resulset, referenced_model, "find", parameters, 259012646UL); - - 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); - } - - } - - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Mvc_Model, _preSave){ - - 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; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - -#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_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_MetaData_Session){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\MetaData, Session, mvc_model_metadata_session, "phalcon\\mvc\\model\\metadata", phalcon_mvc_model_metadata_session_method_entry, 0); - - zend_declare_property_string(phalcon_mvc_model_metadata_session_ce, SL("_prefix"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_metadata_session_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Session, __construct){ - - zval *options = NULL, *prefix, *empty_array; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (Z_TYPE_P(options) == IS_ARRAY) { - 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(empty_array); - array_init(empty_array); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Session, read){ - - zval *key, *session = NULL, *_SESSION, *prefix, *prefix_key; - zval *meta_data; - zval *r0 = NULL, *r1 = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); - PHALCON_CPY_WRT(session, _SESSION); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefix_key); - PHALCON_CONCAT_SV(prefix_key, "$PMM$", prefix); - if (phalcon_array_isset(session, prefix_key)) { - - PHALCON_OBS_VAR(r0); - phalcon_array_fetch(&r0, session, prefix_key, PH_NOISY); - if (phalcon_array_isset(r0, key)) { - PHALCON_OBS_VAR(r1); - phalcon_array_fetch(&r1, session, prefix_key, PH_NOISY); - PHALCON_OBS_VAR(meta_data); - phalcon_array_fetch(&meta_data, r1, key, PH_NOISY); - RETURN_CCTOR(meta_data); - } - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Session, write){ - - zval *key, *data, *prefix, *prefix_key, *_SESSION; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &key, &data); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefix_key); - PHALCON_CONCAT_SV(prefix_key, "$PMM$", prefix); - phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); - phalcon_array_update_multi_2(&_SESSION, prefix_key, key, &data, 0); - - PHALCON_MM_RESTORE(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Strategy_Introspection){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\MetaData\\Strategy, Introspection, mvc_model_metadata_strategy_introspection, phalcon_mvc_model_metadata_strategy_introspection_method_entry, 0); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Introspection, getMetaData){ - - zval *model, *dependency_injector, *class_name; - zval *schema, *table, *read_connection, *exists; - zval *complete_table = NULL, *exception_message = NULL; - zval *columns, *attributes, *primary_keys, *non_primary_keys; - zval *numeric_typed, *not_null, *field_types; - zval *field_bind_types, *automatic_default; - zval *identity_field = NULL, *column = NULL, *field_name = NULL, *feature = NULL; - zval *type = NULL, *bind_type = NULL, *model_metadata; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, model, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(schema); - phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - - PHALCON_INIT_VAR(table); - phalcon_call_method_key(table, model, "getsource", 2025234358UL); - - PHALCON_INIT_VAR(read_connection); - phalcon_call_method_key(read_connection, model, "getreadconnection", 488334257UL); - - PHALCON_INIT_VAR(exists); - phalcon_call_method_p2_key(exists, read_connection, "tableexists", table, schema, 1944065613UL); - if (!zend_is_true(exists)) { - if (zend_is_true(schema)) { - PHALCON_INIT_VAR(complete_table); - PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); - } else { - PHALCON_CPY_WRT(complete_table, table); - } - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Table \"", complete_table, "\" doesn't exist on database when dumping meta-data for ", class_name); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_INIT_VAR(columns); - phalcon_call_method_p2_key(columns, read_connection, "describecolumns", table, schema, 4645575UL); - if (!phalcon_fast_count_ev(columns TSRMLS_CC)) { - if (zend_is_true(schema)) { - PHALCON_INIT_NVAR(complete_table); - PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); - } else { - PHALCON_CPY_WRT(complete_table, table); - } - - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVSV(exception_message, "Cannot obtain table columns for the mapped source \"", complete_table, "\" used in model ", class_name); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_INIT_VAR(attributes); - array_init(attributes); - - PHALCON_INIT_VAR(primary_keys); - array_init(primary_keys); - - PHALCON_INIT_VAR(non_primary_keys); - array_init(non_primary_keys); - - PHALCON_INIT_VAR(numeric_typed); - array_init(numeric_typed); - - PHALCON_INIT_VAR(not_null); - array_init(not_null); - - PHALCON_INIT_VAR(field_types); - array_init(field_types); - - PHALCON_INIT_VAR(field_bind_types); - array_init(field_bind_types); - - PHALCON_INIT_VAR(automatic_default); - array_init(automatic_default); - - PHALCON_INIT_VAR(identity_field); - ZVAL_BOOL(identity_field, 0); - - 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(field_name); - phalcon_call_method_key(field_name, column, "getname", 4286441094UL); - phalcon_array_append(&attributes, field_name, PH_SEPARATE); - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_key(feature, column, "isprimary", 3539965925UL); - if (PHALCON_IS_TRUE(feature)) { - phalcon_array_append(&primary_keys, field_name, PH_SEPARATE); - } else { - phalcon_array_append(&non_primary_keys, field_name, PH_SEPARATE); - } - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_key(feature, column, "isnumeric", 3929517108UL); - if (PHALCON_IS_TRUE(feature)) { - phalcon_array_update_zval_bool(&numeric_typed, field_name, 1, PH_SEPARATE); - } - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_key(feature, column, "isnotnull", 760409005UL); - if (PHALCON_IS_TRUE(feature)) { - phalcon_array_append(¬_null, field_name, PH_SEPARATE); - } - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_key(feature, column, "isautoincrement", 572890271UL); - if (PHALCON_IS_TRUE(feature)) { - PHALCON_CPY_WRT(identity_field, field_name); - } - - PHALCON_INIT_NVAR(type); - phalcon_call_method_key(type, column, "gettype", 4294422375UL); - phalcon_array_update_zval(&field_types, field_name, &type, PH_COPY | PH_SEPARATE); - - PHALCON_INIT_NVAR(bind_type); - phalcon_call_method_key(bind_type, column, "getbindtype", 13600356UL); - phalcon_array_update_zval(&field_bind_types, field_name, &bind_type, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(model_metadata); - array_init(model_metadata); - phalcon_array_update_long(&model_metadata, 0, &attributes, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 4, &field_types, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 9, &field_bind_types, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 10, &automatic_default, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 11, &automatic_default, PH_COPY | PH_SEPARATE); - - RETURN_CTOR(model_metadata); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Introspection, getColumnMaps){ - - zval *model, *dependency_injector, *ordered_column_map = NULL; - zval *reversed_column_map = NULL, *user_column_map; - zval *user_name = NULL, *name = NULL, *model_column_map; -======= - phalcon_fetch_params(1, 3, 0, &meta_data, &exists, &identity_field); - - if (PHALCON_GLOBAL(orm).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; - } - } - - if (PHALCON_GLOBAL(orm).virtual_foreign_keys) { - - PHALCON_INIT_NVAR(status); - phalcon_call_method_key(status, this_ptr, "_checkforeignkeysrestrict", 3705233048UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } - - 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_INIT_NVAR(column_map); - } - - 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(error); - ZVAL_BOOL(error, 0); - - PHALCON_INIT_VAR(null_value); - - phalcon_is_iterable(not_null, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(field); - - if (!phalcon_array_isset(automatic_attributes, field)) { - - 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); - } - - 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); - - 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); - } - - if (PHALCON_IS_TRUE(is_null)) { - if (!zend_is_true(exists)) { - - if (PHALCON_IS_EQUAL(field, identity_field)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_VS(message, attribute_field, " is required"); - - PHALCON_INIT_NVAR(type); - ZVAL_STRING(type, "PresenceOf", 1); - - 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); - - phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), model_message TSRMLS_CC); - - PHALCON_INIT_NVAR(error); - ZVAL_BOOL(error, 1); - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - 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); - } - RETURN_MM_FALSE; - } - } - } - - 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 (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 (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(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_update_property_bool(this_ptr, SL("_skipped"), 0 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_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_Model, _postSave){ - - zval *success, *exists, *event_name = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &success, &exists); - - 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_NVAR(event_name); - ZVAL_STRING(event_name, "afterSave", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - - RETURN_CCTOR(success); - } - - 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_Model, _doLowInsert){ - - 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; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); - - PHALCON_INIT_VAR(ordered_column_map); - - PHALCON_INIT_VAR(reversed_column_map); - - if (phalcon_method_quick_exists_ex(model, SS("columnmap"), 673371633UL TSRMLS_CC) == SUCCESS) { -======= - phalcon_fetch_params(1, 4, 0, &meta_data, &connection, &table, &identity_field); - - PHALCON_INIT_VAR(null_value); - - PHALCON_INIT_VAR(bind_skip); - ZVAL_LONG(bind_skip, 1024); - - PHALCON_INIT_VAR(fields); - array_init(fields); - - PHALCON_INIT_VAR(values); - array_init(values); - - 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_is_iterable(attributes, &ah0, &hp0, 0, 0); ->>>>>>> 1.2.2 - - PHALCON_INIT_VAR(user_column_map); - phalcon_call_method_key(user_column_map, model, "columnmap", 673371633UL); - if (Z_TYPE_P(user_column_map) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "columnMap() not returned an array"); - return; - } - -<<<<<<< HEAD - array_init(reversed_column_map); - PHALCON_CPY_WRT(ordered_column_map, user_column_map); - - phalcon_is_iterable(user_column_map, &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(user_name); - - phalcon_array_update_zval(&reversed_column_map, user_name, &name, PH_COPY | PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); -======= - PHALCON_GET_HVALUE(field); - - if (!phalcon_array_isset(automatic_attributes, field)) { - - 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_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); - } - } ->>>>>>> 1.2.2 - } - - } - -<<<<<<< HEAD - PHALCON_INIT_VAR(model_column_map); - array_init(model_column_map); - phalcon_array_update_long(&model_column_map, 0, &ordered_column_map, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_column_map, 1, &reversed_column_map, PH_COPY | PH_SEPARATE); - - RETURN_CTOR(model_column_map); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Strategy_Annotations){ - - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\MetaData\\Strategy, Annotations, mvc_model_metadata_strategy_annotations, phalcon_mvc_model_metadata_strategy_annotations_method_entry, 0); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getMetaData){ - - zval *model, *dependency_injector, *service; - zval *annotations, *class_name, *reflection; - zval *exception_message = NULL, *properties_annotations; - zval *attributes, *primary_keys, *non_primary_keys; - zval *numeric_typed, *not_null, *field_types; - zval *field_bind_types, *automatic_default; - zval *identity_field = NULL, *column_annot_name; - zval *primary_annot_name, *id_annot_name; - zval *column_type_name, *column_nullable_name; - zval *prop_annotations = NULL, *property = NULL, *has_annotation = NULL; - zval *column_annotation = NULL, *feature = NULL, *model_metadata; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); - return; - } - - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "annotations", 1); - - PHALCON_INIT_VAR(annotations); - phalcon_call_method_p1_key(annotations, dependency_injector, "get", service, 2090288933UL); - - PHALCON_INIT_VAR(class_name); - phalcon_get_class(class_name, model, 0 TSRMLS_CC); - - PHALCON_INIT_VAR(reflection); - phalcon_call_method_p1_key(reflection, annotations, "get", class_name, 2090288933UL); - if (Z_TYPE_P(reflection) != IS_OBJECT) { - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "No annotations were found in class ", class_name); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_INIT_VAR(properties_annotations); - phalcon_call_method_key(properties_annotations, reflection, "getpropertiesannotations", 3353352384UL); - if (!phalcon_fast_count_ev(properties_annotations TSRMLS_CC)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SV(exception_message, "No properties with annotations were found in class ", class_name); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); - return; - } - - PHALCON_INIT_VAR(attributes); - array_init(attributes); - - PHALCON_INIT_VAR(primary_keys); - array_init(primary_keys); - - PHALCON_INIT_VAR(non_primary_keys); - array_init(non_primary_keys); - - PHALCON_INIT_VAR(numeric_typed); - array_init(numeric_typed); - - PHALCON_INIT_VAR(not_null); - array_init(not_null); - - PHALCON_INIT_VAR(field_types); - array_init(field_types); - - PHALCON_INIT_VAR(field_bind_types); - array_init(field_bind_types); - - PHALCON_INIT_VAR(automatic_default); - array_init(automatic_default); - - PHALCON_INIT_VAR(identity_field); - ZVAL_BOOL(identity_field, 0); - - PHALCON_INIT_VAR(column_annot_name); - ZVAL_STRING(column_annot_name, "Column", 1); - - PHALCON_INIT_VAR(primary_annot_name); - ZVAL_STRING(primary_annot_name, "Primary", 1); - - PHALCON_INIT_VAR(id_annot_name); - ZVAL_STRING(id_annot_name, "Identity", 1); - - PHALCON_INIT_VAR(column_type_name); - ZVAL_STRING(column_type_name, "type", 1); - - PHALCON_INIT_VAR(column_nullable_name); - ZVAL_STRING(column_nullable_name, "nullable", 1); - - phalcon_is_iterable(properties_annotations, &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(prop_annotations); - - PHALCON_INIT_NVAR(has_annotation); - phalcon_call_method_p1_key(has_annotation, prop_annotations, "has", column_annot_name, 2090320481UL); - if (!zend_is_true(has_annotation)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - - PHALCON_INIT_NVAR(column_annotation); - phalcon_call_method_p1_key(column_annotation, prop_annotations, "get", column_annot_name, 2090288933UL); - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_p1_key(feature, column_annotation, "getnamedparameter", column_type_name, 3202516043UL); - if (PHALCON_IS_STRING(feature, "integer")) { - phalcon_array_update_zval_long(&field_types, property, 0, PH_SEPARATE); - phalcon_array_update_zval_long(&field_bind_types, property, 1, PH_SEPARATE); - phalcon_array_update_zval_bool(&numeric_typed, property, 1, PH_SEPARATE); - } else { - if (PHALCON_IS_STRING(feature, "decimal")) { - phalcon_array_update_zval_long(&field_types, property, 3, PH_SEPARATE); - phalcon_array_update_zval_long(&field_bind_types, property, 32, PH_SEPARATE); - phalcon_array_update_zval_bool(&numeric_typed, property, 1, PH_SEPARATE); - } else { - if (PHALCON_IS_STRING(feature, "boolean")) { - phalcon_array_update_zval_long(&field_types, property, 8, PH_SEPARATE); - phalcon_array_update_zval_long(&field_bind_types, property, 5, PH_SEPARATE); - } else { - if (PHALCON_IS_STRING(feature, "date")) { - phalcon_array_update_zval_long(&field_types, property, 1, PH_SEPARATE); - } else { - phalcon_array_update_zval_long(&field_types, property, 2, PH_SEPARATE); - } - phalcon_array_update_zval_long(&field_bind_types, property, 2, PH_SEPARATE); - } - } - } - - PHALCON_INIT_NVAR(has_annotation); - phalcon_call_method_p1_key(has_annotation, prop_annotations, "has", primary_annot_name, 2090320481UL); - if (zend_is_true(has_annotation)) { - phalcon_array_append(&primary_keys, property, PH_SEPARATE); - } else { - phalcon_array_append(&non_primary_keys, property, PH_SEPARATE); - } - - PHALCON_INIT_NVAR(has_annotation); - phalcon_call_method_p1_key(has_annotation, prop_annotations, "has", id_annot_name, 2090320481UL); - if (zend_is_true(has_annotation)) { - PHALCON_CPY_WRT(identity_field, property); - } - - PHALCON_INIT_NVAR(feature); - phalcon_call_method_p1_key(feature, column_annotation, "getnamedparameter", column_nullable_name, 3202516043UL); - if (!zend_is_true(feature)) { - phalcon_array_append(¬_null, property, PH_SEPARATE); - } - - phalcon_array_append(&attributes, property, PH_SEPARATE); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_INIT_VAR(model_metadata); - array_init(model_metadata); - phalcon_array_update_long(&model_metadata, 0, &attributes, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 4, &field_types, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 9, &field_bind_types, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 10, &automatic_default, PH_COPY | PH_SEPARATE); - phalcon_array_update_long(&model_metadata, 11, &automatic_default, PH_COPY | PH_SEPARATE); - - RETURN_CTOR(model_metadata); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getColumnMaps){ - - - -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Apc){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\MetaData, Apc, mvc_model_metadata_apc, "phalcon\\mvc\\model\\metadata", phalcon_mvc_model_metadata_apc_method_entry, 0); - - zend_declare_property_string(phalcon_mvc_model_metadata_apc_ce, SL("_prefix"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_long(phalcon_mvc_model_metadata_apc_ce, SL("_ttl"), 172800, ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_metadata_apc_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, __construct){ - - zval *options = NULL, *prefix, *ttl, *empty_array; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (Z_TYPE_P(options) == IS_ARRAY) { - 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); - } - if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { - PHALCON_OBS_VAR(ttl); - phalcon_array_fetch_quick_string(&ttl, options, SS("lifetime"), 2639810228UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_ttl"), ttl, 251113304UL TSRMLS_CC); - } - } - - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, read){ - - zval *key, *prefix, *apc_key, *data; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(apc_key); - PHALCON_CONCAT_SVV(apc_key, "$PMM$", prefix, key); - - PHALCON_INIT_VAR(data); - phalcon_call_func_p1(data, "apc_fetch", apc_key); - if (Z_TYPE_P(data) == IS_ARRAY) { - RETURN_CCTOR(data); - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, write){ - - zval *key, *data, *prefix, *apc_key, *ttl; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &key, &data); - - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(apc_key); - PHALCON_CONCAT_SVV(apc_key, "$PMM$", prefix, key); - - PHALCON_OBS_VAR(ttl); - phalcon_read_property_this_quick(&ttl, this_ptr, SL("_ttl"), 251113304UL, PH_NOISY_CC); - phalcon_call_func_p3_noret("apc_store", apc_key, data, ttl); - - PHALCON_MM_RESTORE(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Files){ - - 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); - - zend_declare_property_string(phalcon_mvc_model_metadata_files_ce, SL("_metaDataDir"), "./", ZEND_ACC_PROTECTED TSRMLS_CC); - - zend_class_implements(phalcon_mvc_model_metadata_files_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, __construct){ - - zval *options = NULL, *meta_data_dir, *empty_array; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - 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); - } - } - - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, read){ - - zval *key, *separator, *meta_data_dir, *virtual_key; - zval *path, *data; - - 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"); - - 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); - } - - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, write){ - - 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, "= 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; - - 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); -======= - 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); - } - - 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_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); - 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); - } - - 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_array_append(&values, value, PH_SEPARATE); - - 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(success); - phalcon_call_method_p4_key(success, connection, "insert", table, values, fields, bind_types, 2673104346UL); - if (PHALCON_IS_NOT_FALSE(identity_field)) { - - PHALCON_INIT_VAR(sequence_name); - - 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_NVAR(sequence_name); - PHALCON_CONCAT_VSVS(sequence_name, source, "_", identity_field, "_seq"); - } - } - - 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_update_property_null(this_ptr, SL("_uniqueParams") TSRMLS_CC); - } - - RETURN_CCTOR(success); -} - -static PHP_METHOD(Phalcon_Mvc_Model, _doLowUpdate){ - - 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, 3, 0, &meta_data, &connection, &table); - - PHALCON_INIT_VAR(null_value); - - PHALCON_INIT_VAR(bind_skip); - ZVAL_LONG(bind_skip, 1024); - - PHALCON_INIT_VAR(fields); - array_init(fields); - - 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_INIT_VAR(bind_data_types); - phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); - - PHALCON_INIT_VAR(non_primary); - phalcon_call_method_p1_key(non_primary, meta_data, "getnonprimarykeyattributes", this_ptr, 1524832420UL); - - 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(non_primary, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(field); - - if (!phalcon_array_isset(automatic_attributes, field)) { - - 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; - } - - 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_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); - - if (!zend_is_true(use_dynamic_update)) { - 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 { - 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); - } - } - - 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); - } - } - - 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_is_iterable(primary_keys, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(field); - - 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_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); - } - - 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_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_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; -} - -static PHP_METHOD(Phalcon_Mvc_Model, _postSaveRelatedRecords){ - - 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, 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; - } - - zend_hash_move_forward_ex(ah1, &hp1); - } - - } 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; - } - } - - 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){ - - 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 (!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); - } - } ->>>>>>> 1.2.2 - - 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; - } - -<<<<<<< HEAD - 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; - } - - 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; - } - } - - 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; - } - } - - 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_ControllerInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ControllerInterface, mvc_controllerinterface, NULL); - - 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); - - 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); - - 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_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Url, setStaticBaseUri){ - - 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_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_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_INIT_VAR(uri); - phalcon_get_uri(uri, php_self); - } else { - PHALCON_INIT_NVAR(uri); - } - - 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); - } - - RETURN_CCTOR(base_uri); -} - -static PHP_METHOD(Phalcon_Mvc_Url, getStaticBaseUri){ -======= - 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; - } - } - - RETURN_CCTOR(new_success); -} - -static PHP_METHOD(Phalcon_Mvc_Model, create){ - - 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_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 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); - } - - } - - 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_Model, update){ - - 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, 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; - } - } - - phalcon_call_method_key(return_value, this_ptr, "save", 274150868UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, delete){ - - 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_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 (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_update_property_long(this_ptr, SL("_dirtyState"), 2 TSRMLS_CC); - - RETURN_CCTOR(success); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getOperationMade){ ->>>>>>> 1.2.2 - - zval *static_base_uri; - -<<<<<<< HEAD - 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_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); - - 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_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_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(service); - ZVAL_STRING(service, "router", 1); - - 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_OBS_VAR(route_name); - phalcon_array_fetch_quick_string(&route_name, uri, SS("for"), 2090263820UL, PH_NOISY); - - 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_INIT_VAR(pattern); - phalcon_call_method_key(pattern, route, "getpattern", 2464558051UL); - - 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); - } - - 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_Url, getStatic){ - - zval *uri = NULL, *static_base_uri, *base_uri; - - 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_INIT_VAR(base_uri); - phalcon_call_method_key(base_uri, this_ptr, "getbaseuri", 2750461136UL); - PHALCON_CONCAT_VV(return_value, base_uri, uri); - - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Url, path){ - - zval *path = NULL, *base_path; -======= - RETURN_MEMBER_QUICK(this_ptr, "_operationMade", 3968152972UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model, refresh){ - - 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(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); - } - - 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); - -} - -static PHP_METHOD(Phalcon_Mvc_Model, 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_Model, writeAttribute){ ->>>>>>> 1.2.2 - - zval *attribute, *value; - -<<<<<<< HEAD - phalcon_fetch_params(1, 0, 1, &path); - - if (!path) { - PHALCON_INIT_VAR(path); - } - - 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(); -} - - -======= - phalcon_fetch_params(0, 2, 0, &attribute, &value); - - phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Model, skipAttributes){ - - zval *attributes, *null_value, *keys_attributes; - zval *attribute = NULL, *meta_data; - HashTable *ah0; - HashPosition hp0; - zval **hd; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - -#ifdef HAVE_CONFIG_H -#endif - - - - -======= - 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 PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnCreate){ - - zval *attributes, *null_value, *keys_attributes; - zval *attribute = NULL, *meta_data; - HashTable *ah0; - HashPosition hp0; - zval **hd; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD -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_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_MM_RESTORE(); -} ->>>>>>> 1.2.2 - -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(); - -<<<<<<< HEAD -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 (!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, "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_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; - - 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(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); - } - - RETURN_CCTOR(meta_data); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getModelsManager){ -======= - 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(); -} - -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(); -} - -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(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, hasMany){ - - zval *fields, *reference_model, *referenced_fields; - zval *options = NULL, *manager; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_modelsManager", 3699347875UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model, setTransaction){ - - zval *transaction; - - phalcon_fetch_params(0, 1, 0, &transaction); - - if (Z_TYPE_P(transaction) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_transaction"), transaction, 1141465066UL TSRMLS_CC); - RETURN_THISW(); - } - 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); - - 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(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_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_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); - - 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_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_Model, assign){ - - zval *data, *column_map = NULL, *value = NULL, *key = NULL, *attribute = NULL; - zval *exception_message = NULL; -======= - 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(); -} - -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_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(); -} - -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(); -} - -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(); -} - -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; -} - -static PHP_METHOD(Phalcon_Mvc_Model, getSnapshotData){ - - - RETURN_MEMBER_QUICK(this_ptr, "_snapshot", 3325604532UL); -} - -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; -} - -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; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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, "Data to dump in the object must be an Array"); - return; - } - - 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(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(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; - } - } else { - phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - - 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); - - if (!dirty_state) { - PHALCON_INIT_VAR(dirty_state); - ZVAL_LONG(dirty_state, 0); - } - - if (!keep_snapshots) { - PHALCON_INIT_VAR(keep_snapshots); - } - - 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_INIT_VAR(object); - if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { - return; - } - - phalcon_call_method_p1_key(NULL, object, "setdirtystate", dirty_state, 1304577662UL); - - 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) { - - 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); - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - if (zend_is_true(keep_snapshots)) { - phalcon_call_method_p2_key(NULL, object, "setsnapshotdata", data, column_map, 1073494651UL); - } - - if (phalcon_method_quick_exists_ex(object, SS("afterfetch"), 1256108385UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, object, "afterfetch", 1256108385UL); - } - - 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 (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Data to hidrate must be an Array"); - return; - } - - if (Z_TYPE_P(column_map) != IS_ARRAY) { - if (PHALCON_IS_LONG(hydration_mode, 1)) { - RETURN_CCTOR(data); - } - } - - if (PHALCON_IS_LONG(hydration_mode, 1)) { - PHALCON_INIT_VAR(hydrate); - array_init(hydrate); - } else { - PHALCON_INIT_NVAR(hydrate); - object_init(hydrate); - } - - phalcon_is_iterable(data, &ah0, &hp0, 0, 0); -======= - 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); -} - -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(); -} - -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(); -} - -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); ->>>>>>> 1.2.2 - - if (phalcon_start_with_str(method, SL("get"))) { - PHALCON_INIT_VAR(alias); - phalcon_substr(alias, method, 3, 0); - -<<<<<<< HEAD - PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); - - if (Z_TYPE_P(key) == IS_STRING) { - if (Z_TYPE_P(column_map) == IS_ARRAY) { - - 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); - 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_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); ->>>>>>> 1.2.2 - - PHALCON_INIT_NVAR(relation); - phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", model_name, alias, 785467656UL); - } - } - -<<<<<<< HEAD - 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 (!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_INIT_VAR(object); - if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { - return; - } - - phalcon_call_method_p1_key(NULL, object, "setdirtystate", dirty_state, 1304577662UL); - - 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) { - 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 (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(); -} - -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); ->>>>>>> 1.2.2 - - 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); - } - -<<<<<<< HEAD - if (phalcon_method_quick_exists_ex(object, SS("afterfetch"), 1256108385UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, object, "afterfetch", 1256108385UL); - } - - 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); - } - - PHALCON_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); - if (Z_TYPE_P(parameters) != IS_ARRAY) { - - 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_INIT_VAR(builder); - object_init_ex(builder, phalcon_mvc_model_query_builder_ce); - phalcon_call_method_p1_key(NULL, builder, "__construct", params, 1107214344UL); - - phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - - 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); - } - } - - 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(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_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 (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - PHALCON_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); - if (Z_TYPE_P(parameters) != IS_ARRAY) { - - 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_INIT_VAR(builder); - object_init_ex(builder, phalcon_mvc_model_query_builder_ce); - phalcon_call_method_p1_key(NULL, builder, "__construct", params, 1107214344UL); - - phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - - 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); - } - } - - 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(unique); - ZVAL_BOOL(unique, 1); - - phalcon_call_method_p1_key(NULL, query, "setuniquerow", unique, 2999205376UL); - - 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); - - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } else { - PHALCON_SEPARATE_PARAM(dependency_injector); - } - - PHALCON_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); - - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - } - - 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); - - 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; -======= - 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_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(); -} - -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); -} - -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(); -} - -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; -} - -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(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, unserialize){ - - zval *data, *attributes, *dependency_injector; - zval *service, *manager, *value = NULL, *key = NULL; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - phalcon_fetch_params(1, 2, 1, &meta_data, &connection, &table); - - if (!table) { - PHALCON_INIT_VAR(table); - } else { - PHALCON_SEPARATE_PARAM(table); - } - - PHALCON_INIT_VAR(unique_params); - - PHALCON_INIT_VAR(unique_types); - - 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_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); - - PHALCON_INIT_VAR(number_primary); - phalcon_fast_count(number_primary, primary_keys TSRMLS_CC); - if (!zend_is_true(number_primary)) { - RETURN_MM_FALSE; - } - - 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(null_value); - - PHALCON_INIT_VAR(number_empty); - ZVAL_LONG(number_empty, 0); - - PHALCON_INIT_VAR(where_pk); - array_init(where_pk); - - array_init(unique_params); - - array_init(unique_types); - - phalcon_is_iterable(primary_keys, &ah0, &hp0, 0, 0); -======= - 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); ->>>>>>> 1.2.2 - - phalcon_call_method_p1_key(NULL, manager, "initialize", this_ptr, 2896075127UL); - -<<<<<<< HEAD - PHALCON_GET_HVALUE(field); - - 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_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); - - if (PHALCON_IS_EMPTY(value)) { - PHALCON_SEPARATE(number_empty); - phalcon_increment(number_empty); - } - - 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); - } - - PHALCON_INIT_NVAR(escaped_field); - phalcon_call_method_p1_key(escaped_field, connection, "escapeidentifier", field, 585773337UL); - - 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; - } - - 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); - - zend_hash_move_forward_ex(ah0, &hp0); - } - - if (PHALCON_IS_EQUAL(number_primary, number_empty)) { - RETURN_MM_FALSE; - } - - PHALCON_INIT_VAR(join_where); - phalcon_fast_join_str(join_where, SL(" AND "), where_pk TSRMLS_CC); - - 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); - } - - 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 (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 (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 (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); - } - - 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_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_VAR(escaped_table); - phalcon_call_method_p1_key(escaped_table, connection, "escapeidentifier", table, 585773337UL); - - PHALCON_INIT_VAR(null_mode); - - PHALCON_INIT_VAR(select); - PHALCON_CONCAT_SVSV(select, "SELECT COUNT(*) \"rowcount\" FROM ", escaped_table, " WHERE ", unique_key); - - PHALCON_INIT_VAR(num); - phalcon_call_method_p4_key(num, connection, "fetchone", select, null_mode, unique_params, unique_types, 1637187313UL); - - 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); - } - - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Model, _groupResult){ - - 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, 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_INIT_VAR(model_name); - phalcon_get_called_class(model_name TSRMLS_CC); - - 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_call_method_p1_key(NULL, builder, "columns", columns, 1041822630UL); - phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - - 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(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); - } - - 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); -======= - 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_Model, dump){ - - - PHALCON_MM_GROW(); - - phalcon_call_func_p1(return_value, "get_object_vars", this_ptr); - RETURN_MM(); -} - -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); -} - -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(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_ViewInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ViewInterface, mvc_viewinterface, phalcon_mvc_viewinterface_method_entry); - - return SUCCESS; ->>>>>>> 1.2.2 -} - -static PHP_METHOD(Phalcon_Mvc_Model, count){ - - zval *parameters = NULL, *function, *alias; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - phalcon_fetch_params(1, 0, 1, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "COUNT", 1); - - PHALCON_INIT_VAR(alias); - ZVAL_STRING(alias, "rowcount", 1); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); - RETURN_MM(); -} -======= - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ->>>>>>> 1.2.2 - -static PHP_METHOD(Phalcon_Mvc_Model, sum){ - - zval *parameters = NULL, *function, *alias; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - 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; - -<<<<<<< HEAD - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "MAX", 1); - - 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_INIT_CLASS(Phalcon_Mvc_User_Component){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Component, mvc_user_component, "phalcon\\di\\injectable", NULL, 0); ->>>>>>> 1.2.2 - - phalcon_fetch_params(1, 0, 1, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "MIN", 1); - - PHALCON_INIT_VAR(alias); - ZVAL_STRING(alias, "minimum", 1); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); - RETURN_MM(); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model, average){ - - zval *parameters = NULL, *function, *alias; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - PHALCON_INIT_VAR(function); - ZVAL_STRING(function, "AVG", 1); - - 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); - - 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(); -} - -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_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; -} - -static PHP_METHOD(Phalcon_Mvc_Model, _cancelOperation){ - - zval *operation_made, *event_name = NULL; -======= - - - - -#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; -} - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, appendMessage){ - - zval *message, *type, *exception_message; -======= - -#ifdef HAVE_CONFIG_H -#endif - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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); - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, validate){ - - zval *validator, *status, *messages, *message = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; -======= - - ->>>>>>> 1.2.2 - -PHALCON_INIT_CLASS(Phalcon_Mvc_User_Plugin){ - -<<<<<<< HEAD - 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); - } - - } - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, validationHasFailed){ - - zval *error_messages; -======= - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Plugin, mvc_user_plugin, "phalcon\\di\\injectable", NULL, 0); - - return SUCCESS; -} - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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; -} - -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; -======= - -#ifdef HAVE_CONFIG_H -#endif - - - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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_GET_HKEY(position, ah1, hp1); - PHALCON_GET_HVALUE(field); - - 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_OBS_NVAR(referenced_field); - phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - - 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); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - } 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(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_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_NVAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - - 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_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_INIT_NVAR(type); - ZVAL_STRING(type, "ConstraintViolation", 1); - - 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_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - - 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; - } - } - - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysReverseRestrict){ - - 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_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_INIT_VAR(error); - ZVAL_BOOL(error, 0); - - 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_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(fields); - phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - - PHALCON_INIT_NVAR(referenced_fields); - phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - - PHALCON_INIT_NVAR(conditions); - array_init(conditions); - - PHALCON_INIT_NVAR(bind_params); - array_init(bind_params); - 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_GET_HKEY(position, ah1, hp1); - PHALCON_GET_HVALUE(field); - - 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_OBS_NVAR(referenced_field); - phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - - 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); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - } 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(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_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_NVAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - - 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_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 { - PHALCON_INIT_NVAR(user_message); - PHALCON_CONCAT_SV(user_message, "Record is referenced by model ", relation_class); - } - - PHALCON_INIT_NVAR(type); - ZVAL_STRING(type, "ConstraintViolation", 1); - - 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_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - - 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; -======= - -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); ->>>>>>> 1.2.2 - } - - phalcon_update_property_this_quick(this_ptr, SL("_modules"), merged_modules, 379092157UL TSRMLS_CC); - } - -<<<<<<< HEAD - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysReverseCascade){ - - 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; -======= - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Application, getModules){ ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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_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, 0); - - 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, 2)) { - - 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(fields); - phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - - PHALCON_INIT_NVAR(referenced_fields); - phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - - PHALCON_INIT_NVAR(conditions); - array_init(conditions); - - PHALCON_INIT_NVAR(bind_params); - array_init(bind_params); - 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_GET_HKEY(position, ah1, hp1); - PHALCON_GET_HVALUE(field); - - 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_OBS_NVAR(referenced_field); - phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - - 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); - - zend_hash_move_forward_ex(ah1, &hp1); - } - - } 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(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_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_NVAR(join_conditions); - phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - - 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_NVAR(resulset); - phalcon_call_method_p1_key(resulset, referenced_model, "find", parameters, 259012646UL); - - 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); -======= - 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; - } - } - - 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; - } ->>>>>>> 1.2.2 - } - - } - -<<<<<<< HEAD - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Mvc_Model, _preSave){ - - 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, 3, 0, &meta_data, &exists, &identity_field); - - if (PHALCON_GLOBAL(orm).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; - } - } - - if (PHALCON_GLOBAL(orm).virtual_foreign_keys) { - - PHALCON_INIT_NVAR(status); - phalcon_call_method_key(status, this_ptr, "_checkforeignkeysrestrict", 3705233048UL); -======= - 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); ->>>>>>> 1.2.2 - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } - } - -<<<<<<< HEAD - 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_INIT_NVAR(column_map); - } - - 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(error); - ZVAL_BOOL(error, 0); - - PHALCON_INIT_VAR(null_value); - - phalcon_is_iterable(not_null, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(field); - - if (!phalcon_array_isset(automatic_attributes, field)) { - - 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); - } - - 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); - - 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); - } - - if (PHALCON_IS_TRUE(is_null)) { - if (!zend_is_true(exists)) { - - if (PHALCON_IS_EQUAL(field, identity_field)) { - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } - } - - PHALCON_INIT_NVAR(message); - PHALCON_CONCAT_VS(message, attribute_field, " is required"); - - PHALCON_INIT_NVAR(type); - ZVAL_STRING(type, "PresenceOf", 1); - - 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); - - phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), model_message TSRMLS_CC); - - PHALCON_INIT_NVAR(error); - ZVAL_BOOL(error, 1); - } - } -======= - 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); ->>>>>>> 1.2.2 - - phalcon_call_method_p3_key(NULL, view, "render", controller_name, action_name, params, 1053215877UL); - } - } -<<<<<<< HEAD - - 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); - } - RETURN_MM_FALSE; - } - } - } - - 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 (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 (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(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_update_property_bool(this_ptr, SL("_skipped"), 0 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_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_Model, _postSave){ - - zval *success, *exists, *event_name = NULL; -======= - } - } - - 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); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - phalcon_fetch_params(1, 2, 0, &success, &exists); - - 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_NVAR(event_name); - ZVAL_STRING(event_name, "afterSave", 1); - phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - - RETURN_CCTOR(success); - } - - 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_Model, _doLowInsert){ - - 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, 4, 0, &meta_data, &connection, &table, &identity_field); - - PHALCON_INIT_VAR(null_value); - - PHALCON_INIT_VAR(bind_skip); - ZVAL_LONG(bind_skip, 1024); - - PHALCON_INIT_VAR(fields); - array_init(fields); - - PHALCON_INIT_VAR(values); - array_init(values); - - 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_is_iterable(attributes, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(field); - - if (!phalcon_array_isset(automatic_attributes, field)) { - - 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_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); - } - - 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); - } - - 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_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); - 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); - } - - 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_array_append(&values, value, PH_SEPARATE); - - 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(success); - phalcon_call_method_p4_key(success, connection, "insert", table, values, fields, bind_types, 2673104346UL); - if (PHALCON_IS_NOT_FALSE(identity_field)) { - - PHALCON_INIT_VAR(sequence_name); - - 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_NVAR(sequence_name); - PHALCON_CONCAT_VSVS(sequence_name, source, "_", identity_field, "_seq"); - } - } - - 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_update_property_null(this_ptr, SL("_uniqueParams") TSRMLS_CC); - } - - RETURN_CCTOR(success); -} - -static PHP_METHOD(Phalcon_Mvc_Model, _doLowUpdate){ - - 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; -======= -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){ - - - RETURN_MEMBER_QUICK(this_ptr, "_modelsManager", 3699347875UL); -} - -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); -} - -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; - - 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){ - - 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(); -} - -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); -} - -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 PHP_METHOD(Phalcon_Mvc_Collection, writeAttribute){ - - zval *attribute, *value; - - phalcon_fetch_params(0, 2, 0, &attribute, &value); - - phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ - - zval *collection, *document, *cloned_collection; - zval *value = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - 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); -} - -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; ->>>>>>> 1.2.2 - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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_INIT_VAR(fields); - array_init(fields); - - 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_INIT_VAR(bind_data_types); - phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); - - PHALCON_INIT_VAR(non_primary); - phalcon_call_method_p1_key(non_primary, meta_data, "getnonprimarykeyattributes", this_ptr, 1524832420UL); - - 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(non_primary, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(field); - - if (!phalcon_array_isset(automatic_attributes, field)) { - - 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; - } - - 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_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); - - if (!zend_is_true(use_dynamic_update)) { - 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 { - 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); - } - } - - 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); - } - } - - 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_is_iterable(primary_keys, &ah1, &hp1, 0, 0); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(field); - - 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_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); - } - - 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_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; -======= - 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 { - PHALCON_INIT_NVAR(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); - } - - 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 PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ - - zval *params, *collection, *connection, *source; - zval *mongo_collection, *conditions = NULL, *simple = NULL; - zval *documents_cursor, *limit, *sort = NULL; - - PHALCON_MM_GROW(); - - 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 { - PHALCON_INIT_NVAR(conditions); - array_init(conditions); - } - } - - PHALCON_INIT_VAR(simple); - ZVAL_BOOL(simple, 1); - if (phalcon_array_isset_quick_string(params, SS("limit"), 192268420UL)) { - ZVAL_BOOL(simple, 0); - } else { - 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 (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 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); - - 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; - } - } - - 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 (!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; -} - -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); - - 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; -} - -static PHP_METHOD(Phalcon_Mvc_Collection, validate){ - - zval *validator, *status, *messages, *message = NULL; - HashTable *ah0; - HashPosition hp0; ->>>>>>> 1.2.2 - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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); -======= - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, 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; - } - } - - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Collection, fireEvent){ - - zval *event_name, *models_manager; - - PHALCON_MM_GROW(); - - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, fireEventCancel){ - - zval *event_name, *status = NULL, *models_manager; - - 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; -} - -static PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ - - zval *disable_events, *operation_made, *event_name = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &disable_events); - - if (!zend_is_true(disable_events)) { - - PHALCON_OBS_VAR(operation_made); - phalcon_read_property_this_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; -} - -static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ - - zval *collection, *id, *mongo_id = NULL, *models_manager; - zval *use_implicit_ids, *parameters, *document_count; - zval *zero; - zend_class_entry *ce0; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &collection); - - if (phalcon_isset_property(this_ptr, SS("_id") TSRMLS_CC)) { - - PHALCON_OBS_VAR(id); - phalcon_read_property_this_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); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - is_smaller_function(return_value, zero, document_count TSRMLS_CC); - - RETURN_MM(); - } - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Collection, getMessages){ - - - RETURN_MEMBER_QUICK(this_ptr, "_errorMessages", 1019066246UL); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, appendMessage){ - - zval *message, *type, *exception_message; - - 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; ->>>>>>> 1.2.2 - } - phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - -<<<<<<< HEAD - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Mvc_Model, _postSaveRelatedRecords){ - - 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; -======= - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, save){ - - 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; ->>>>>>> 1.2.2 - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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); -======= - 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_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; - - 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_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; - - 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 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(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, find){ - - zval *parameters = NULL, *class_name, *collection, *connection; - zval *unique; - zend_class_entry *ce0; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, ¶meters); ->>>>>>> 1.2.2 - - zend_hash_move_forward_ex(ah3, &hp3); - } - -<<<<<<< HEAD - phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); - RETURN_MM_FALSE; - } - - zend_hash_move_forward_ex(ah1, &hp1); - } - - } 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; - } -======= - 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; ->>>>>>> 1.2.2 - } - } - -<<<<<<< HEAD - 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){ - - 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); -======= - 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); ->>>>>>> 1.2.2 - - if (!data) { - PHALCON_INIT_VAR(data); - } - -<<<<<<< HEAD - 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); -======= - 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; ->>>>>>> 1.2.2 - } - } - -<<<<<<< HEAD - 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; - } - } - - RETURN_CCTOR(new_success); -} - -static PHP_METHOD(Phalcon_Mvc_Model, create){ - - 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_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 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); -======= - 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; - } - } - - 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); - } - - RETURN_CCTOR(first_retval); - } - - 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; ->>>>>>> 1.2.2 - } - - } - -<<<<<<< HEAD - 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_Model, update){ - - 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, 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; -======= - 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); - } - } 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); - } - } - } 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); - } - } else { - if (!phalcon_array_isset(reserved, key)) { - phalcon_array_update_zval(&data, key, &value, PH_COPY | PH_SEPARATE); - } ->>>>>>> 1.2.2 - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - -<<<<<<< HEAD - phalcon_call_method_key(return_value, this_ptr, "save", 274150868UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, delete){ - - 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_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 (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_update_property_long(this_ptr, SL("_dirtyState"), 2 TSRMLS_CC); - - RETURN_CCTOR(success); -} - -static PHP_METHOD(Phalcon_Mvc_Model, getOperationMade){ - - - RETURN_MEMBER_QUICK(this_ptr, "_operationMade", 3968152972UL); -} - -static PHP_METHOD(Phalcon_Mvc_Model, refresh){ - - 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(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); -======= - 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; - } - - 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_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; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_View){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, View, mvc_view, "phalcon\\di\\injectable", phalcon_mvc_view_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_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_Mvc_View, __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) { - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - } - - 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(); -} - -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(); -} - -static PHP_METHOD(Phalcon_Mvc_View, getLayoutsDir){ - - - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_View, getPartialsDir){ - - - RETURN_MEMBER_QUICK(this_ptr, "_partialsDir", 2130168739UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, 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_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; - - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_View, getMainView){ - - - 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){ - - - 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_update_property_null(this_ptr, SL("_templatesBefore") TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, setTemplateAfter){ - - zval *template_after, *array_template; - - PHALCON_MM_GROW(); - - 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_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_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); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 1); - } - - if (Z_TYPE_P(params) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The render parameters must be an array"); - return; ->>>>>>> 1.2.2 - } - if (zend_is_true(merge)) { - -<<<<<<< HEAD - 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); -======= - 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_Mvc_View, setVar){ - - zval *key, *value; - - 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_Mvc_View, getVar){ - - zval *key, *params, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - 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); ->>>>>>> 1.2.2 - } - - RETURN_MM_NULL(); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model, skipOperation){ -======= -static PHP_METHOD(Phalcon_Mvc_View, getParamsToView){ ->>>>>>> 1.2.2 - - zval *skip; - -<<<<<<< HEAD - phalcon_fetch_params(0, 1, 0, &skip); - - phalcon_update_property_this_quick(this_ptr, SL("_skipped"), skip, 2005665588UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Model, 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_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 PHP_METHOD(Phalcon_Mvc_Model, skipAttributes){ - - zval *attributes, *null_value, *keys_attributes; - zval *attribute = NULL, *meta_data; -======= - 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; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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 PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnCreate){ - - 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, "setautomaticcreateattributes", this_ptr, keys_attributes, 316109587UL); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnUpdate){ - - zval *attributes, *null_value, *keys_attributes; - zval *attribute = NULL, *meta_data; -======= - PHALCON_OBS_VAR(engines); - phalcon_read_property_this_quick(&engines, this_ptr, SL("_engines"), 1840711053UL, PH_NOISY_CC); - - 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_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; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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(); -} - -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); -======= - phalcon_fetch_params(1, 5, 0, &engines, &view_path, &silence, &must_clean, &cache); - - PHALCON_INIT_VAR(not_exists); - ZVAL_BOOL(not_exists, 1); - - PHALCON_OBS_VAR(views_dir); - phalcon_read_property_this_quick(&views_dir, this_ptr, SL("_viewsDir"), 3398309201UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(base_path); - phalcon_read_property_this_quick(&base_path, this_ptr, SL("_basePath"), 1477430348UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(views_dir_path); - PHALCON_CONCAT_VVV(views_dir_path, base_path, views_dir, view_path); - - if (Z_TYPE_P(cache) == IS_OBJECT) { - - PHALCON_OBS_VAR(render_level); - phalcon_read_property_this_quick(&render_level, this_ptr, SL("_renderLevel"), 3194989084UL, PH_NOISY_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_INIT_VAR(is_started); - phalcon_call_method_key(is_started, cache, "isstarted", 527759032UL); - if (PHALCON_IS_FALSE(is_started)) { - - PHALCON_INIT_VAR(key); ->>>>>>> 1.2.2 - - PHALCON_INIT_VAR(lifetime); - -<<<<<<< HEAD - 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_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(); -} - -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); -======= - 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); - } ->>>>>>> 1.2.2 - - 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(); - } - } - -<<<<<<< HEAD - 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(); -} - -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_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_INIT_VAR(is_fresh); - phalcon_call_method_key(is_fresh, cache, "isfresh", 3981662073UL); - if (!zend_is_true(is_fresh)) { - RETURN_MM_NULL(); - } - } - } - - 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_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { - - 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_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, view_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)) { - - 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_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; - } - } ->>>>>>> 1.2.2 - - PHALCON_MM_RESTORE(); -} - -<<<<<<< HEAD -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(); -} - -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; -======= -static PHP_METHOD(Phalcon_Mvc_View, registerEngines){ - - zval *engines; - - phalcon_fetch_params(0, 1, 0, &engines); - - 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); - - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, render){ - - 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; ->>>>>>> 1.2.2 - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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; -======= - 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_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); - } - - 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(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_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - - phalcon_create_symbol_table(TSRMLS_C); - - 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_FALSE; - } - } - - 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(must_clean); - ZVAL_BOOL(must_clean, 1); - - PHALCON_INIT_VAR(silence); - ZVAL_BOOL(silence, 1); - - PHALCON_OBS_VAR(disabled_levels); - phalcon_read_property_this_quick(&disabled_levels, this_ptr, SL("_disabledLevels"), 1575004551UL, PH_NOISY_CC); - - 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)) { - - 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 (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); - - if (Z_TYPE_P(templates_before) == IS_ARRAY) { - - ZVAL_BOOL(silence, 0); - - phalcon_is_iterable(templates_before, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - 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_INIT_NVAR(silence); - ZVAL_BOOL(silence, 1); - } ->>>>>>> 1.2.2 - } - -<<<<<<< HEAD - 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_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; -} - -static PHP_METHOD(Phalcon_Mvc_Model, getSnapshotData){ - - - RETURN_MEMBER_QUICK(this_ptr, "_snapshot", 3325604532UL); -} - -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; - } -======= - 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); - } - } - - 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); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(template_after); - - 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(ah1, &hp1); - } - - PHALCON_INIT_NVAR(silence); - ZVAL_BOOL(silence, 1); - } - } - } - - 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); - } - } - } - - 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_Mvc_View, pick){ - - zval *render_view, *pick_view = NULL, *layout = NULL, *parts; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &render_view); - - 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_OBS_NVAR(layout); - phalcon_array_fetch_long(&layout, parts, 0, PH_NOISY); - } - - 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 (!params) { - PHALCON_INIT_VAR(params); - } - - 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(new_params); - phalcon_fast_array_merge(new_params, &view_params, ¶ms TSRMLS_CC); - } else { - PHALCON_CPY_WRT(new_params, params); - } - - phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), new_params, 1685283331UL TSRMLS_CC); - - phalcon_create_symbol_table(TSRMLS_C); - - } - - PHALCON_INIT_VAR(zfalse); - ZVAL_BOOL(zfalse, 0); - - PHALCON_OBS_VAR(partials_dir); - phalcon_read_property_this_quick(&partials_dir, this_ptr, SL("_partialsDir"), 2130168739UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(real_path); - PHALCON_CONCAT_VV(real_path, partials_dir, partial_path); - - PHALCON_INIT_VAR(engines); - phalcon_call_method_key(engines, this_ptr, "_loadtemplateengines", 4149337481UL); - - phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, real_path, zfalse, zfalse, zfalse, 828860954UL); ->>>>>>> 1.2.2 - - if (Z_TYPE_P(params) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), view_params, 1685283331UL TSRMLS_CC); - } - -<<<<<<< HEAD - RETURN_MM_FALSE; -} - -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); -} - -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(); -} - -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_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 (!config_callback) { - PHALCON_INIT_VAR(config_callback); - } - - PHALCON_INIT_VAR(view); - if (phalcon_clone(view, this_ptr TSRMLS_CC) == FAILURE) { - return; - } - - 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 (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_call_method_key(NULL, view, "start", 478839859UL); - - phalcon_call_method_p2_key(NULL, view, "render", controller_name, action_name, 1053215877UL); - - 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(); - - 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(); - - 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(); - - 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_Mvc_View, getCache){ - - zval *cache = NULL; - - 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); - } - - RETURN_CCTOR(cache); -} - -static PHP_METHOD(Phalcon_Mvc_View, cache){ - - zval *options = NULL, *view_options = NULL, *cache_options = NULL; - zval *value = NULL, *key = NULL, *cache_level; - HashTable *ah0; - HashPosition hp0; - zval **hd; ->>>>>>> 1.2.2 - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &alias, &arguments); - -<<<<<<< HEAD - 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(); -} - -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; -======= - if (!options) { - PHALCON_INIT_VAR(options); - ZVAL_BOOL(options, 1); - } - - if (Z_TYPE_P(options) == 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); - } - - 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); - } - - phalcon_is_iterable(options, &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_array_update_zval(&cache_options, key, &value, PH_COPY | PH_SEPARATE); - - 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); - } - } - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_View, setContent){ ->>>>>>> 1.2.2 - - zval *content; - -<<<<<<< HEAD - 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(); -======= - phalcon_fetch_params(0, 1, 0, &content); - - if (Z_TYPE_P(content) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_view_exception_ce, "Content must be a string"); - return; ->>>>>>> 1.2.2 - } - phalcon_update_property_this_quick(this_ptr, SL("_content"), content, 4081318271UL TSRMLS_CC); - - RETURN_THISW(); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model, __call){ - - zval *method, *arguments = NULL, *model_name, *records; - zval *models_manager, *status, *exception_message; -======= -static PHP_METHOD(Phalcon_Mvc_View, getContent){ - ->>>>>>> 1.2.2 - - RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); -} - -<<<<<<< HEAD - 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_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; -======= -static PHP_METHOD(Phalcon_Mvc_View, getActiveRenderPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_activeRenderPath", 1528023309UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, disable){ - - - phalcon_update_property_bool(this_ptr, SL("_disabled"), 1 TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, enable){ - - - phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, reset){ - - zval *znull; - - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_View, __set){ - - zval *key, *value; - - phalcon_fetch_params(0, 2, 0, &key, &value); - - phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_View, __get){ - - zval *key, *params, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - 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_NULL(); -} - - - - - -#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_RouterInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, RouterInterface, mvc_routerinterface, phalcon_mvc_routerinterface_method_entry); - - return SUCCESS; -} - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_Model, __set){ -======= - - - - - - - - - - - - - - - - - - - - - - - - -#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){ ->>>>>>> 1.2.2 - - 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) { - -<<<<<<< HEAD - 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); - } -======= -} - -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); ->>>>>>> 1.2.2 - - phalcon_update_property_zval_zval(this_ptr, property, value TSRMLS_CC); - - RETURN_CCTOR(value); -} - -<<<<<<< HEAD -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; -======= -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getEventsManager){ ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - 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(); -} - -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; -} - -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); -======= - 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); - } - } - - 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); ->>>>>>> 1.2.2 - - PHALCON_INIT_VAR(data); - array_init(data); - -<<<<<<< HEAD - 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_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_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); ->>>>>>> 1.2.2 - - 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; -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Model, dump){ - -======= -static PHP_METHOD(Phalcon_Mvc_Collection_Manager, isUsingImplicitObjectIds){ - - zval *model, *entity_name, *implicit_objects_ids; - zval *implicit; ->>>>>>> 1.2.2 - - PHALCON_MM_GROW(); - - phalcon_call_func_p1(return_value, "get_object_vars", this_ptr); - RETURN_MM(); -} - -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); - -<<<<<<< HEAD - 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_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(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_ViewInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ViewInterface, mvc_viewinterface, phalcon_mvc_viewinterface_method_entry); - - return SUCCESS; -} - - -======= - 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); - } - } - - 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; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - - - - - - -======= - 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); -} - ->>>>>>> 1.2.2 - - - - -<<<<<<< HEAD -======= -#ifdef HAVE_CONFIG_H -#endif ->>>>>>> 1.2.2 - - - - - - - -<<<<<<< HEAD - - - - - - - - - -======= -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; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - -======= - 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; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - - -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; -======= - 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); - ->>>>>>> 1.2.2 -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Mvc_User_Module){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Module, mvc_user_module, "phalcon\\di\\injectable", NULL, 0); -======= -PHALCON_INIT_CLASS(Phalcon_Mvc_Collection_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Collection, Exception, mvc_collection_exception, "phalcon\\exception", NULL, 0); ->>>>>>> 1.2.2 - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -<<<<<<< HEAD - - - -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; -} - - -======= ->>>>>>> 1.2.2 - - - -#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(); - -<<<<<<< HEAD - 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){ -======= -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(); ->>>>>>> 1.2.2 - - 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(); -} - -<<<<<<< HEAD - 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_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){ ->>>>>>> 1.2.2 - -static PHP_METHOD(Phalcon_Mvc_Application, getDefaultModule){ - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); -} - -<<<<<<< HEAD - 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; - } - } - - 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); -} - - - - - -#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){ -======= -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); - } - } - } 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_Router, setUriSource){ ->>>>>>> 1.2.2 - - zval *uri_source; - -<<<<<<< HEAD - 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){ - - - RETURN_MEMBER_QUICK(this_ptr, "_modelsManager", 3699347875UL); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, getReservedAttributes){ - - zval *reserved = NULL, *dummy; -======= - 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){ ->>>>>>> 1.2.2 - - zval *controller_name; - -<<<<<<< HEAD - 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); -} - -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; - - 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){ - - 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(); -} - -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); -} - -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); -======= - 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); ->>>>>>> 1.2.2 - } - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, writeAttribute){ - - zval *attribute, *value; - - phalcon_fetch_params(0, 2, 0, &attribute, &value); - -<<<<<<< HEAD - phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ - - zval *collection, *document, *cloned_collection; - zval *value = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - 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); -} - -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); - - 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 { - PHALCON_INIT_NVAR(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); - } - - 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 PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ - - zval *params, *collection, *connection, *source; - zval *mongo_collection, *conditions = NULL, *simple = NULL; - zval *documents_cursor, *limit, *sort = NULL; - - PHALCON_MM_GROW(); - - 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 { - PHALCON_INIT_NVAR(conditions); - array_init(conditions); - } - } - - PHALCON_INIT_VAR(simple); - ZVAL_BOOL(simple, 1); - if (phalcon_array_isset_quick_string(params, SS("limit"), 192268420UL)) { - ZVAL_BOOL(simple, 0); - } else { - 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 (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 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); - - 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; - } - } - - 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 (!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; -} - -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); - - 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; -} - -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); - - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, 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; - } - } - - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Collection, fireEvent){ - - zval *event_name, *models_manager; - - PHALCON_MM_GROW(); - - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, fireEventCancel){ - - zval *event_name, *status = NULL, *models_manager; - - 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; -} - -static PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ - - zval *disable_events, *operation_made, *event_name = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &disable_events); - - if (!zend_is_true(disable_events)) { - - PHALCON_OBS_VAR(operation_made); - phalcon_read_property_this_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; -} - -static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ - - zval *collection, *id, *mongo_id = NULL, *models_manager; - zval *use_implicit_ids, *parameters, *document_count; - zval *zero; - zend_class_entry *ce0; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &collection); - - if (phalcon_isset_property(this_ptr, SS("_id") TSRMLS_CC)) { - - PHALCON_OBS_VAR(id); - phalcon_read_property_this_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); - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - is_smaller_function(return_value, zero, document_count TSRMLS_CC); - - RETURN_MM(); - } - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Mvc_Collection, getMessages){ -======= - 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; - } - } - - 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); - } - - 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; - } - } - - 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); - } - } - - 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); - } - - 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); - } - - 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); - } - - 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); - } - - 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); - } - - 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); - } - - 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){ ->>>>>>> 1.2.2 - - zval *pattern, *paths = NULL, *method; - -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_errorMessages", 1019066246UL); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, appendMessage){ - - zval *message, *type, *exception_message; - - 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_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); ->>>>>>> 1.2.2 - } - phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), message TSRMLS_CC); - -<<<<<<< HEAD - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, save){ - - 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; -======= - 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; ->>>>>>> 1.2.2 - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - 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_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; - - 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_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; - - 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 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(); -} - -static PHP_METHOD(Phalcon_Mvc_Collection, find){ - - zval *parameters = NULL, *class_name, *collection, *connection; - zval *unique; - 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 find"); - return; - } - } - - PHALCON_INIT_VAR(class_name); - phalcon_get_called_class(class_name TSRMLS_CC); - ce0 = phalcon_fetch_class(class_name TSRMLS_CC); - - PHALCON_INIT_VAR(collection); - object_init_ex(collection, ce0); - if (phalcon_has_constructor(collection TSRMLS_CC)) { - phalcon_call_method_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; - } - } - - 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; - } - } - - 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_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); - } - - } - - 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); - } - - } - - 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; - } ->>>>>>> 1.2.2 - } - phalcon_update_property_this_quick(this_ptr, SL("_notFoundPaths"), paths, 189519377UL TSRMLS_CC); - -<<<<<<< HEAD - 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); - } - - RETURN_CCTOR(first_retval); - } - - 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; - } - } - - 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); - } - } 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); - } - } - } 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); - } - } 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); - } - - RETURN_CTOR(data); -======= - 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); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_MM_FALSE; ->>>>>>> 1.2.2 -} - -static PHP_METHOD(Phalcon_Mvc_Collection, serialize){ - - zval *data; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - PHALCON_INIT_VAR(data); - phalcon_call_method_key(data, this_ptr, "toarray", 3566966151UL); - - phalcon_serialize(return_value, &data TSRMLS_CC); - RETURN_MM(); -======= - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_ModelInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ModelInterface, mvc_modelinterface, phalcon_mvc_modelinterface_method_entry); - - return SUCCESS; ->>>>>>> 1.2.2 -} - -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; - } - - 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_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; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_View){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, View, mvc_view, "phalcon\\di\\injectable", phalcon_mvc_view_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_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); - -<<<<<<< HEAD - zend_class_implements(phalcon_mvc_view_ce TSRMLS_CC, 1, phalcon_mvc_viewinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Mvc_View, __construct){ - - zval *options = NULL; -======= - - - - - - - - - - - - - - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} -======= ->>>>>>> 1.2.2 - -static PHP_METHOD(Phalcon_Mvc_View, setViewsDir){ - - zval *views_dir; - -<<<<<<< HEAD - 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(); -} - -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(); -} - -static PHP_METHOD(Phalcon_Mvc_View, getLayoutsDir){ - - - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_View, getPartialsDir){ - - - RETURN_MEMBER_QUICK(this_ptr, "_partialsDir", 2130168739UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, 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_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; - - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_View, getMainView){ - - - 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){ - - - 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_update_property_null(this_ptr, SL("_templatesBefore") TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, setTemplateAfter){ - - zval *template_after, *array_template; - - PHALCON_MM_GROW(); - - 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_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_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); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 1); - } - - 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_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_Mvc_View, setVar){ - - zval *key, *value; - - 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_Mvc_View, getVar){ - - zval *key, *params, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - 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_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); - - 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_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); - - PHALCON_INIT_VAR(not_exists); - ZVAL_BOOL(not_exists, 1); - - PHALCON_OBS_VAR(views_dir); - phalcon_read_property_this_quick(&views_dir, this_ptr, SL("_viewsDir"), 3398309201UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(base_path); - phalcon_read_property_this_quick(&base_path, this_ptr, SL("_basePath"), 1477430348UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(views_dir_path); - PHALCON_CONCAT_VVV(views_dir_path, base_path, views_dir, view_path); - - if (Z_TYPE_P(cache) == IS_OBJECT) { - - PHALCON_OBS_VAR(render_level); - phalcon_read_property_this_quick(&render_level, this_ptr, SL("_renderLevel"), 3194989084UL, PH_NOISY_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_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(); - } - } - } - - 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_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { - - 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_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, view_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)) { - - 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_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_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_View, registerEngines){ - - zval *engines; - - phalcon_fetch_params(0, 1, 0, &engines); - - 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); - - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, render){ - - 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, 2, 1, &controller_name, &action_name, ¶ms); -======= - - -#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; -} - - - - - -#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_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_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_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 (!options) { - PHALCON_INIT_VAR(options); - } - - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - } - - 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_this_quick(this_ptr, SL("_viewsDir"), views_dir, 3398309201UL TSRMLS_CC); - -} - -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(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); - -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, _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); - - 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_CCTOR(engines); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, _internalRender){ - - 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_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_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; - } - - 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_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(); - - phalcon_fetch_params(1, 1, 1, &path, ¶ms); ->>>>>>> 1.2.2 - - if (!params) { - PHALCON_INIT_VAR(params); - } - -<<<<<<< HEAD - 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_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); - } - - 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(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_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - - phalcon_create_symbol_table(TSRMLS_C); - - 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_FALSE; - } - } - - 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(must_clean); - ZVAL_BOOL(must_clean, 1); - - PHALCON_INIT_VAR(silence); - ZVAL_BOOL(silence, 1); - - PHALCON_OBS_VAR(disabled_levels); - phalcon_read_property_this_quick(&disabled_levels, this_ptr, SL("_disabledLevels"), 1575004551UL, PH_NOISY_CC); - - 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)) { - - 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 (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); - - if (Z_TYPE_P(templates_before) == IS_ARRAY) { - - ZVAL_BOOL(silence, 0); - - phalcon_is_iterable(templates_before, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - 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_INIT_NVAR(silence); - ZVAL_BOOL(silence, 1); - } - } - } - - 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); - } - } - - 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); - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HVALUE(template_after); - - 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(ah1, &hp1); - } - - PHALCON_INIT_NVAR(silence); - ZVAL_BOOL(silence, 1); - } - } - } - - 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); -======= - 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); ->>>>>>> 1.2.2 - } - } - } - -<<<<<<< HEAD - 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_Mvc_View, pick){ - - zval *render_view, *pick_view = NULL, *layout = NULL, *parts; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &render_view); - - 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_OBS_NVAR(layout); - phalcon_array_fetch_long(&layout, parts, 0, PH_NOISY); - } - - 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); -======= - 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_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); - - if (!params) { - PHALCON_INIT_VAR(params); - } - - 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); - } - - 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_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_Mvc_View_Simple, setCacheOptions){ - - zval *options; - - phalcon_fetch_params(0, 1, 0, &options); - - phalcon_update_property_this_quick(this_ptr, SL("_cacheOptions"), options, 528255652UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, getCacheOptions){ - - - RETURN_MEMBER_QUICK(this_ptr, "_cacheOptions", 528255652UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, _createCache){ - - zval *dependency_injector, *cache_service = NULL; - zval *cache_options, *view_cache; - - 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_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(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_Simple, getCache){ - - zval *cache = NULL; - - 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); - } - } - - RETURN_CCTOR(cache); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, cache){ - - zval *options = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - ZVAL_BOOL(options, 1); - } - - 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); - } - } ->>>>>>> 1.2.2 - - RETURN_THIS(); -} - -<<<<<<< HEAD -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 (!params) { - PHALCON_INIT_VAR(params); - } - - 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(new_params); - phalcon_fast_array_merge(new_params, &view_params, ¶ms TSRMLS_CC); - } else { - PHALCON_CPY_WRT(new_params, params); - } - - phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), new_params, 1685283331UL TSRMLS_CC); - - phalcon_create_symbol_table(TSRMLS_C); - - } - - PHALCON_INIT_VAR(zfalse); - ZVAL_BOOL(zfalse, 0); - - PHALCON_OBS_VAR(partials_dir); - phalcon_read_property_this_quick(&partials_dir, this_ptr, SL("_partialsDir"), 2130168739UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(real_path); - PHALCON_CONCAT_VV(real_path, partials_dir, partial_path); - - PHALCON_INIT_VAR(engines); - phalcon_call_method_key(engines, this_ptr, "_loadtemplateengines", 4149337481UL); - - phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, real_path, zfalse, zfalse, zfalse, 828860954UL); - - if (Z_TYPE_P(params) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), view_params, 1685283331UL TSRMLS_CC); - } - - 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 (!config_callback) { - PHALCON_INIT_VAR(config_callback); - } - - PHALCON_INIT_VAR(view); - if (phalcon_clone(view, this_ptr TSRMLS_CC) == FAILURE) { - return; - } - - 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 (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_call_method_key(NULL, view, "start", 478839859UL); - - phalcon_call_method_p2_key(NULL, view, "render", controller_name, action_name, 1053215877UL); - - 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(); - - 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(); - - 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(); - - 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_Mvc_View, getCache){ - - zval *cache = NULL; - - 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); - } - - RETURN_CCTOR(cache); -} - -static PHP_METHOD(Phalcon_Mvc_View, cache){ - - 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, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - ZVAL_BOOL(options, 1); - } - - if (Z_TYPE_P(options) == 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); - } - - 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); - } - - phalcon_is_iterable(options, &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_array_update_zval(&cache_options, key, &value, PH_COPY | PH_SEPARATE); - - 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); - } - } - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_View, setContent){ - - zval *content; - - phalcon_fetch_params(0, 1, 0, &content); - - 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); - - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, getContent){ - - - RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, getActiveRenderPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_activeRenderPath", 1528023309UL); -} - -static PHP_METHOD(Phalcon_Mvc_View, disable){ - - - phalcon_update_property_bool(this_ptr, SL("_disabled"), 1 TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, enable){ - - - phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View, reset){ - - zval *znull; - - 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(); -} - -static PHP_METHOD(Phalcon_Mvc_View, __set){ - - zval *key, *value; - - phalcon_fetch_params(0, 2, 0, &key, &value); - - phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_View, __get){ - - zval *key, *params, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - 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_NULL(); -} - - - - - -#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; -======= -static PHP_METHOD(Phalcon_Mvc_View_Simple, setParamToView){ - - zval *key, *value; - - 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_Mvc_View_Simple, setVars){ - - zval *params, *merge = NULL, *view_params, *merged_params = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, ¶ms, &merge); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 1); - } - - 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_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_Mvc_View_Simple, setVar){ - - zval *key, *value; - - 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_Mvc_View_Simple, getVar){ - - zval *key, *params, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - 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_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, getParamsToView){ - - - RETURN_MEMBER_QUICK(this_ptr, "_viewParams", 1685283331UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, setContent){ - - zval *content; - - phalcon_fetch_params(0, 1, 0, &content); - - 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); - - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, getContent){ - - - RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, getActiveRenderPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_activeRenderPath", 1528023309UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, __set){ - - zval *key, *value; - - phalcon_fetch_params(0, 2, 0, &key, &value); - - phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, __get){ - - zval *key, *params, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - 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_NULL(); -} - - - - - -#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_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(); -} - -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); - - 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; -} - - - - - - - - - -#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_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; - } - - 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(); ->>>>>>> 1.2.2 -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Mvc_RouterInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, RouterInterface, mvc_routerinterface, phalcon_mvc_routerinterface_method_entry); -======= - - - - -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); ->>>>>>> 1.2.2 - - return SUCCESS; -} - -<<<<<<< HEAD - - - - - - - - - - - - - - - - - - - - - - - - - - - -#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); - } - } - - 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); - } - } - - 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); - } - } - - 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); -} - - - - - -#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_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_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); - } - } - } 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_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; - } - } - - 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); - } - - 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; - } - } - - 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); - } - } - - 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); - } - - 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); - } - - 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); - } - - 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); - } - - 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); - } - - 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); - } - - 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); - } - - } - - 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); - } - - } - - 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; - } - } - 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); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - RETURN_MM_FALSE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Mvc_ModelInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ModelInterface, mvc_modelinterface, phalcon_mvc_modelinterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#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; -} - - - - - -#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_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_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_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 (!options) { - PHALCON_INIT_VAR(options); - } - - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - } - - 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_this_quick(this_ptr, SL("_viewsDir"), views_dir, 3398309201UL TSRMLS_CC); - -} - -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(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); - -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, _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); - - 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_CCTOR(engines); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, _internalRender){ - - 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_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_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; - } - - 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_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(); - - 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_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); - - if (!params) { - PHALCON_INIT_VAR(params); - } - - 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); - } - - 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_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_Mvc_View_Simple, setCacheOptions){ - - zval *options; - - phalcon_fetch_params(0, 1, 0, &options); - - phalcon_update_property_this_quick(this_ptr, SL("_cacheOptions"), options, 528255652UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, getCacheOptions){ - - - RETURN_MEMBER_QUICK(this_ptr, "_cacheOptions", 528255652UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, _createCache){ - - zval *dependency_injector, *cache_service = NULL; - zval *cache_options, *view_cache; - - 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_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(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_Simple, getCache){ - - zval *cache = NULL; - - 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); - } - } - - RETURN_CCTOR(cache); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, cache){ - - zval *options = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - ZVAL_BOOL(options, 1); - } - - 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); - } - } - - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, setParamToView){ - - zval *key, *value; - - 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_Mvc_View_Simple, setVars){ - - zval *params, *merge = NULL, *view_params, *merged_params = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, ¶ms, &merge); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 1); - } - - 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_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_Mvc_View_Simple, setVar){ - - zval *key, *value; - - 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_Mvc_View_Simple, getVar){ - - zval *key, *params, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - 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_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, getParamsToView){ - - - RETURN_MEMBER_QUICK(this_ptr, "_viewParams", 1685283331UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, setContent){ - - zval *content; - - phalcon_fetch_params(0, 1, 0, &content); - - 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); - - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, getContent){ - - - RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, getActiveRenderPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_activeRenderPath", 1528023309UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, __set){ - - zval *key, *value; - - phalcon_fetch_params(0, 2, 0, &key, &value); - - phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_View_Simple, __get){ - - zval *key, *params, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &key); - - 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_NULL(); -} - - - - - -#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_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(); -} - -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); - - 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; -} - - - - - - - - - -#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_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; - } - - 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_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_Engine_Volt_Compiler, __construct){ - - zval *view = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &view); - - if (!view) { - PHALCON_INIT_VAR(view); - } - - if (Z_TYPE_P(view) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_view"), view, 3993744575UL TSRMLS_CC); - } - - 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); - -} - -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); - -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setOption){ - - zval *option, *value; - - phalcon_fetch_params(0, 2, 0, &option, &value); - - phalcon_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, 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_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getOptions){ - - - 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, 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_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_Engine_Volt_Compiler, getExtensions){ - - - 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(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(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getFunctions){ - - - RETURN_MEMBER_QUICK(this_ptr, "_functions", 2704716189UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addFilter){ - - zval *name, *definition; - - 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_Engine_Volt_Compiler, getFilters){ - - - RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setUniquePrefix){ - - 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_View_Engine_Volt_Compiler, getUniquePrefix){ - - zval *prefix = NULL, *current_path, *parameters, *calculated_prefix; - - 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; - } - - RETURN_CCTOR(prefix); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, attributeReader){ - - 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_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); - } - - if (phalcon_array_isset(array_helpers, name)) { - PHALCON_CONCAT_SVSVS(return_value, "Phalcon\\Tag::", method, "(array(", arguments, "))"); - RETURN_MM(); - } - - PHALCON_CONCAT_SVSVS(return_value, "Phalcon\\Tag::", method, "(", arguments, ")"); - - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "url")) { - PHALCON_CONCAT_SVS(return_value, "$this->url->get(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "static_url")) { - PHALCON_CONCAT_SVS(return_value, "$this->url->getStatic(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "date")) { - PHALCON_CONCAT_SVS(return_value, "date(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "time")) { - PHALCON_INIT_NVAR(code); - ZVAL_STRING(code, "time()", 1); - RETURN_CCTOR(code); - } - - if (PHALCON_IS_STRING(name, "dump")) { - PHALCON_CONCAT_SVS(return_value, "var_dump(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "version")) { - RETURN_MM_STRING("Phalcon\\Version::get()", 1); - } - - if (PHALCON_IS_STRING(name, "version_id")) { - RETURN_MM_STRING("Phalcon\\Version::getId()", 1); - } - - if (PHALCON_IS_STRING(name, "constant")) { - PHALCON_CONCAT_SVS(return_value, "constant(", arguments, ")"); - RETURN_MM(); - } - - 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; - } - - 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_View_Engine_Volt_Compiler, resolveTest){ - - zval *test, *left, *type, *name = NULL, *test_name, *test_arguments = NULL; - zval *arguments = NULL, *right_code; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &test, &left); - - if (Z_TYPE_P(test) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted test"); - return; - } - - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, test, SS("type"), 276192743UL, PH_NOISY); - - 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(); - } - - if (PHALCON_IS_STRING(name, "even")) { - PHALCON_CONCAT_SVS(return_value, "(((", left, ") % 2) == 0)"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "odd")) { - PHALCON_CONCAT_SVS(return_value, "(((", left, ") % 2) != 0)"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "numeric")) { - PHALCON_CONCAT_SVS(return_value, "is_numeric(", left, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "scalar")) { - PHALCON_CONCAT_SVS(return_value, "is_scalar(", left, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "iterable")) { - PHALCON_CONCAT_SVSVS(return_value, "(is_array(", left, ") || (", left, ") instanceof Traversable)"); - RETURN_MM(); - } - } - - if (PHALCON_IS_LONG(type, 350)) { - - 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_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(arguments); - phalcon_call_method_p1_key(arguments, this_ptr, "expression", test_arguments, 218841909UL); - PHALCON_CONCAT_SVSVS(return_value, "(((", left, ") % (", arguments, ")) == 0)"); - RETURN_MM(); - } - - 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_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_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_View_Engine_Volt_Compiler, resolveFilter){ - - 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, 2, 0, &filter, &left); - - if (Z_TYPE_P(filter) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted filter"); - return; - } - - PHALCON_INIT_VAR(code); - - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, filter, SS("type"), 276192743UL, PH_NOISY); - - 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); - - 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_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_INIT_VAR(arguments); - - if (phalcon_array_isset_quick_string(filter, SS("arguments"), 3751272283UL)) { - - PHALCON_OBS_NVAR(file); - phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); - - PHALCON_OBS_NVAR(line); - phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); - - 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_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); - } - } - -======= -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, __construct){ - - zval *view = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &view); - - if (!view) { - PHALCON_INIT_VAR(view); - } - - if (Z_TYPE_P(view) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_view"), view, 3993744575UL TSRMLS_CC); - } - - 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); - -} - -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); - -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setOption){ - - zval *option, *value; - - phalcon_fetch_params(0, 2, 0, &option, &value); - - phalcon_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, 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_NULL(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getOptions){ - - - 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, 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_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_Engine_Volt_Compiler, getExtensions){ - - - 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(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(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getFunctions){ - - - RETURN_MEMBER_QUICK(this_ptr, "_functions", 2704716189UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addFilter){ - - zval *name, *definition; - - 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_Engine_Volt_Compiler, getFilters){ - - - RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setUniquePrefix){ - - 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_View_Engine_Volt_Compiler, getUniquePrefix){ - - zval *prefix = NULL, *current_path, *parameters, *calculated_prefix; - - 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; - } - - RETURN_CCTOR(prefix); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, attributeReader){ - - 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_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); - } - - if (phalcon_array_isset(array_helpers, name)) { - PHALCON_CONCAT_SVSVS(return_value, "Phalcon\\Tag::", method, "(array(", arguments, "))"); - RETURN_MM(); - } - - PHALCON_CONCAT_SVSVS(return_value, "Phalcon\\Tag::", method, "(", arguments, ")"); - - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "url")) { - PHALCON_CONCAT_SVS(return_value, "$this->url->get(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "static_url")) { - PHALCON_CONCAT_SVS(return_value, "$this->url->getStatic(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "date")) { - PHALCON_CONCAT_SVS(return_value, "date(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "time")) { - PHALCON_INIT_NVAR(code); - ZVAL_STRING(code, "time()", 1); - RETURN_CCTOR(code); - } - - if (PHALCON_IS_STRING(name, "dump")) { - PHALCON_CONCAT_SVS(return_value, "var_dump(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "version")) { - RETURN_MM_STRING("Phalcon\\Version::get()", 1); - } - - if (PHALCON_IS_STRING(name, "version_id")) { - RETURN_MM_STRING("Phalcon\\Version::getId()", 1); - } - - if (PHALCON_IS_STRING(name, "constant")) { - PHALCON_CONCAT_SVS(return_value, "constant(", arguments, ")"); - RETURN_MM(); - } - - 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; - } - - 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_View_Engine_Volt_Compiler, resolveTest){ - - zval *test, *left, *type, *name = NULL, *test_name, *test_arguments = NULL; - zval *arguments = NULL, *right_code; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &test, &left); - - if (Z_TYPE_P(test) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted test"); - return; - } - - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, test, SS("type"), 276192743UL, PH_NOISY); - - 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(); - } - - if (PHALCON_IS_STRING(name, "even")) { - PHALCON_CONCAT_SVS(return_value, "(((", left, ") % 2) == 0)"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "odd")) { - PHALCON_CONCAT_SVS(return_value, "(((", left, ") % 2) != 0)"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "numeric")) { - PHALCON_CONCAT_SVS(return_value, "is_numeric(", left, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "scalar")) { - PHALCON_CONCAT_SVS(return_value, "is_scalar(", left, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "iterable")) { - PHALCON_CONCAT_SVSVS(return_value, "(is_array(", left, ") || (", left, ") instanceof Traversable)"); - RETURN_MM(); - } - } - - if (PHALCON_IS_LONG(type, 350)) { - - 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_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(arguments); - phalcon_call_method_p1_key(arguments, this_ptr, "expression", test_arguments, 218841909UL); - PHALCON_CONCAT_SVSVS(return_value, "(((", left, ") % (", arguments, ")) == 0)"); - RETURN_MM(); - } - - 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_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_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_View_Engine_Volt_Compiler, resolveFilter){ - - 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, 2, 0, &filter, &left); - - if (Z_TYPE_P(filter) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted filter"); - return; - } - - PHALCON_INIT_VAR(code); - - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, filter, SS("type"), 276192743UL, PH_NOISY); - - 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); - - 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_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_INIT_VAR(arguments); - - if (phalcon_array_isset_quick_string(filter, SS("arguments"), 3751272283UL)) { - - PHALCON_OBS_NVAR(file); - phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); - - PHALCON_OBS_NVAR(line); - phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); - - 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_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); - } - } - ->>>>>>> 1.2.2 - 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_OBS_VAR(definition); - phalcon_array_fetch(&definition, filters, 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_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; - } - } - - if (PHALCON_IS_STRING(name, "length")) { - PHALCON_CONCAT_SVS(return_value, "$this->length(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "e")) { - PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtml(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "escape")) { - PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtml(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "escape_css")) { - PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeCss(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "escape_js")) { - PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeJs(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "escape_attr")) { - PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtmlAttr(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "trim")) { - PHALCON_CONCAT_SVS(return_value, "trim(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "left_trim")) { - PHALCON_CONCAT_SVS(return_value, "ltrim(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "right_trim")) { - PHALCON_CONCAT_SVS(return_value, "rtrim(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "striptags")) { - PHALCON_CONCAT_SVS(return_value, "strip_tags(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "url_encode")) { - PHALCON_CONCAT_SVS(return_value, "urlencode(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "slashes")) { - PHALCON_CONCAT_SVS(return_value, "addslashes(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "stripslashes")) { - PHALCON_CONCAT_SVS(return_value, "stripslashes(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "nl2br")) { - PHALCON_CONCAT_SVS(return_value, "nl2br(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "keys")) { - PHALCON_CONCAT_SVS(return_value, "array_keys(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "join")) { - PHALCON_CONCAT_SVS(return_value, "join(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "lowercase")) { - PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::lower(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "lower")) { - PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::lower(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "uppercase")) { - PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::upper(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "upper")) { - PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::upper(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "capitalize")) { - PHALCON_CONCAT_SVS(return_value, "ucwords(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "sort")) { - PHALCON_CONCAT_SVS(return_value, "$this->sort(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "json_encode")) { - PHALCON_CONCAT_SVS(return_value, "json_encode(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "json_decode")) { - PHALCON_CONCAT_SVS(return_value, "json_decode(", arguments, ")"); - RETURN_MM(); - } - - if (PHALCON_IS_STRING(name, "format")) { - PHALCON_CONCAT_SVS(return_value, "sprintf(", arguments, ")"); - RETURN_MM(); - } - - 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_View_Engine_Volt_Compiler, expression){ - - 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, 1, 0, &expr); - - if (Z_TYPE_P(expr) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted expression"); - return; - } - - 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); - - 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) { -<<<<<<< HEAD - break; - } - } - if (!phalcon_array_isset_quick_string(expr, SS("type"), 276192743UL)) { - - PHALCON_INIT_NVAR(items); - array_init(items); - - phalcon_is_iterable(expr, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(single_expr); - - PHALCON_OBS_NVAR(single_expr_expr); - phalcon_array_fetch_quick_string(&single_expr_expr, single_expr, SS("expr"), 258368420UL, PH_NOISY); - - 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_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; - } - - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, expr, SS("type"), 276192743UL, PH_NOISY); - - 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 (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; - } - - 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_NVAR(expr_code); - phalcon_call_method_p2_key(expr_code, this_ptr, "resolvefilter", right_code, left_code, 3562260459UL); - break; - } - - 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_NVAR(right_code); - phalcon_call_method_p1_key(right_code, this_ptr, "expression", right, 218841909UL); - } - - PHALCON_INIT_NVAR(expr_code); - - switch (phalcon_get_intval(type)) { - - case 33: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "!", right_code); - break; - - case 42: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " * ", right_code); - break; - - case 43: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " + ", right_code); - break; - - case 45: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " - ", right_code); - break; - - case 47: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " / ", right_code); - break; - - case 37: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " % ", right_code); - break; - - case 60: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " < ", right_code); - break; - - case 61: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " > ", right_code); - break; - - case 62: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " > ", right_code); - break; - - case 126: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " . ", right_code); - break; - - case 278: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "pow(", left_code, ", ", right_code, ")"); - break; - - 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; - - case 258: - PHALCON_OBS_NVAR(expr_code); - phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); - break; - - case 259: - PHALCON_OBS_NVAR(expr_code); - phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); - break; - - case 260: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - - PHALCON_INIT_NVAR(single_quote); - ZVAL_STRING(single_quote, "'", 1); - - PHALCON_INIT_NVAR(escaped_quoute); - ZVAL_STRING(escaped_quoute, "\\'", 1); - - PHALCON_INIT_NVAR(escaped_string); - phalcon_fast_str_replace(escaped_string, single_quote, escaped_quoute, value); - - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "'", escaped_string, "'"); - break; - - case 261: - PHALCON_INIT_NVAR(expr_code); - ZVAL_STRING(expr_code, "null", 1); - break; - - case 262: - PHALCON_INIT_NVAR(expr_code); - ZVAL_STRING(expr_code, "false", 1); - break; - - case 263: - PHALCON_INIT_NVAR(expr_code); - ZVAL_STRING(expr_code, "true", 1); - break; - - case 265: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "$", value); - break; - - case 266: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " && ", right_code); - break; - - case 267: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " || ", right_code); - break; - - case 270: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " <= ", right_code); - break; - - case 271: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " >= ", right_code); - break; - - 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; - - case 274: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " === ", right_code); - break; - - case 275: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " !== ", right_code); - break; - - case 276: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "range(", left_code, ", ", right_code, ")"); - break; - - case 350: - PHALCON_INIT_NVAR(expr_code); - phalcon_call_method_p1_key(expr_code, this_ptr, "functioncall", expr, 1638966055UL); - break; - - case 356: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "(", left_code, ")"); - break; - - case 361: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSVS(expr_code, left_code, "[", right_code, "]"); - break; - - 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(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); - } - - 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); - - 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(expr_code); - PHALCON_CONCAT_SVSVSVS(expr_code, "$this->slice(", left_code, ", ", start_code, ", ", end_code, ")"); - break; - - case 362: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "!isset(", left_code, ")"); - break; - - case 363: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "isset(", left_code, ")"); - break; - - case 309: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "$this->isIncluded(", left_code, ", ", right_code, ")"); - break; - - case 369: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "!$this->isIncluded(", left_code, ", ", right_code, ")"); - break; - - case 366: - PHALCON_OBS_NVAR(ternary); - phalcon_array_fetch_quick_string(&ternary, expr, SS("ternary"), 4197153930UL, PH_NOISY); - - PHALCON_INIT_NVAR(ternary_code); - phalcon_call_method_p1_key(ternary_code, this_ptr, "expression", ternary, 218841909UL); - - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVSVS(expr_code, "(", ternary_code, " ? ", left_code, " : ", right_code, ")"); - break; - - case 367: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "-", right_code); - break; - - case 368: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "+", right_code); - break; - - case 364: - PHALCON_OBS_NVAR(expr_code); - phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); - break; - - default: - 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, "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_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); - - if (Z_TYPE_P(statements) != IS_ARRAY) { - RETURN_CCTOR(statements); - } - - PHALCON_INIT_VAR(is_statement_list); - ZVAL_BOOL(is_statement_list, 1); - if (!phalcon_array_isset_quick_string(statements, SS("type"), 276192743UL)) { - - 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_INIT_NVAR(is_statement_list); - ZVAL_BOOL(is_statement_list, 0); - break; - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - 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); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileForeach){ - - 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, 1, 1, &statement, &extends_mode); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { -======= - break; - } - } - if (!phalcon_array_isset_quick_string(expr, SS("type"), 276192743UL)) { - - PHALCON_INIT_NVAR(items); - array_init(items); - - phalcon_is_iterable(expr, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(single_expr); - - PHALCON_OBS_NVAR(single_expr_expr); - phalcon_array_fetch_quick_string(&single_expr_expr, single_expr, SS("expr"), 258368420UL, PH_NOISY); - - 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_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; - } - - PHALCON_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, expr, SS("type"), 276192743UL, PH_NOISY); - - 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 (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; - } - - 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_NVAR(expr_code); - phalcon_call_method_p2_key(expr_code, this_ptr, "resolvefilter", right_code, left_code, 3562260459UL); - break; - } - - 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_NVAR(right_code); - phalcon_call_method_p1_key(right_code, this_ptr, "expression", right, 218841909UL); - } - - PHALCON_INIT_NVAR(expr_code); - - switch (phalcon_get_intval(type)) { - - case 33: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "!", right_code); - break; - - case 42: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " * ", right_code); - break; - - case 43: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " + ", right_code); - break; - - case 45: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " - ", right_code); - break; - - case 47: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " / ", right_code); - break; - - case 37: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " % ", right_code); - break; - - case 60: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " < ", right_code); - break; - - case 61: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " > ", right_code); - break; - - case 62: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " > ", right_code); - break; - - case 126: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " . ", right_code); - break; - - case 278: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "pow(", left_code, ", ", right_code, ")"); - break; - - 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; - - case 258: - PHALCON_OBS_NVAR(expr_code); - phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); - break; - - case 259: - PHALCON_OBS_NVAR(expr_code); - phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); - break; - - case 260: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - - PHALCON_INIT_NVAR(single_quote); - ZVAL_STRING(single_quote, "'", 1); - - PHALCON_INIT_NVAR(escaped_quoute); - ZVAL_STRING(escaped_quoute, "\\'", 1); - - PHALCON_INIT_NVAR(escaped_string); - phalcon_fast_str_replace(escaped_string, single_quote, escaped_quoute, value); - - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "'", escaped_string, "'"); - break; - - case 261: - PHALCON_INIT_NVAR(expr_code); - ZVAL_STRING(expr_code, "null", 1); - break; - - case 262: - PHALCON_INIT_NVAR(expr_code); - ZVAL_STRING(expr_code, "false", 1); - break; - - case 263: - PHALCON_INIT_NVAR(expr_code); - ZVAL_STRING(expr_code, "true", 1); - break; - - case 265: - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "$", value); - break; - - case 266: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " && ", right_code); - break; - - case 267: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " || ", right_code); - break; - - case 270: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " <= ", right_code); - break; - - case 271: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " >= ", right_code); - break; - - 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; - - case 274: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " === ", right_code); - break; - - case 275: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSV(expr_code, left_code, " !== ", right_code); - break; - - case 276: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "range(", left_code, ", ", right_code, ")"); - break; - - case 350: - PHALCON_INIT_NVAR(expr_code); - phalcon_call_method_p1_key(expr_code, this_ptr, "functioncall", expr, 1638966055UL); - break; - - case 356: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "(", left_code, ")"); - break; - - case 361: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_VSVS(expr_code, left_code, "[", right_code, "]"); - break; - - 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(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); - } - - 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); - - 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(expr_code); - PHALCON_CONCAT_SVSVSVS(expr_code, "$this->slice(", left_code, ", ", start_code, ", ", end_code, ")"); - break; - - case 362: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "!isset(", left_code, ")"); - break; - - case 363: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVS(expr_code, "isset(", left_code, ")"); - break; - - case 309: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "$this->isIncluded(", left_code, ", ", right_code, ")"); - break; - - case 369: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVS(expr_code, "!$this->isIncluded(", left_code, ", ", right_code, ")"); - break; - - case 366: - PHALCON_OBS_NVAR(ternary); - phalcon_array_fetch_quick_string(&ternary, expr, SS("ternary"), 4197153930UL, PH_NOISY); - - PHALCON_INIT_NVAR(ternary_code); - phalcon_call_method_p1_key(ternary_code, this_ptr, "expression", ternary, 218841909UL); - - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SVSVSVS(expr_code, "(", ternary_code, " ? ", left_code, " : ", right_code, ")"); - break; - - case 367: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "-", right_code); - break; - - case 368: - PHALCON_INIT_NVAR(expr_code); - PHALCON_CONCAT_SV(expr_code, "+", right_code); - break; - - case 364: - PHALCON_OBS_NVAR(expr_code); - phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); - break; - - default: - 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, "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_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); - - if (Z_TYPE_P(statements) != IS_ARRAY) { - RETURN_CCTOR(statements); - } - - PHALCON_INIT_VAR(is_statement_list); - ZVAL_BOOL(is_statement_list, 1); - if (!phalcon_array_isset_quick_string(statements, SS("type"), 276192743UL)) { - - 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_INIT_NVAR(is_statement_list); - ZVAL_BOOL(is_statement_list, 0); - break; - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - } - - 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); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileForeach){ - - 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, 1, 1, &statement, &extends_mode); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - 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(compilation); - ZVAL_STRING(compilation, "", 1); - phalcon_property_incr(this_ptr, SL("_foreachLevel") TSRMLS_CC); - - PHALCON_INIT_VAR(prefix); - phalcon_call_method_key(prefix, this_ptr, "getuniqueprefix", 3888429962UL); - - PHALCON_OBS_VAR(level); - phalcon_read_property_this_quick(&level, this_ptr, SL("_foreachLevel"), 1560648116UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefix_level); - PHALCON_CONCAT_VV(prefix_level, prefix, level); - - 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_OBS_VAR(block_statements); - phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); - - PHALCON_INIT_VAR(for_else); - ZVAL_BOOL(for_else, 0); - if (Z_TYPE_P(block_statements) == IS_ARRAY) { - - phalcon_is_iterable(block_statements, &ah0, &hp0, 0, 0); - - 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); - } - - } - - PHALCON_INIT_VAR(code); - phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); - - 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_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(variable); - phalcon_array_fetch_quick_string(&variable, statement, SS("variable"), 1809440971UL, PH_NOISY); - - 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(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)); ?>"); - } - - if (Z_TYPE_P(for_else) == IS_STRING) { - PHALCON_SCONCAT_SVS(compilation, ""); - } - - 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 { - if (phalcon_array_isset(loop_context, level)) { - PHALCON_SCONCAT_SVS(compilation, ""); - } else { - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - } - } - - phalcon_property_decr(this_ptr, SL("_foreachLevel") TSRMLS_CC); - - 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_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_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_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileIf){ - - zval *statement, *extends_mode = NULL, *compilation; - zval *expr, *expr_code, *block_statements = NULL, *code = NULL; - - 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); - - 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); - } - - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - - 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); - - 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_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); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - 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(compilation); - - 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, "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_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); - - 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); - - 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, "]; } ?>"); - } - - 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); - - 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(compilation); - - 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_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_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, expr, SS("name"), 268211462UL, PH_NOISY); - - 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_OBS_VAR(name_value); - phalcon_array_fetch_quick_string(&name_value, name, SS("value"), 574111618UL, PH_NOISY); - - if (PHALCON_IS_STRING(name_value, "super")) { - RETURN_CCTOR(expr_code); - } - } - } - - 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_View_Engine_Volt_Compiler, compileInclude){ - - 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_fetch_params(1, 1, 0, &statement); - - if (!phalcon_array_isset_quick_string(statement, SS("path"), 270591026UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } - - PHALCON_OBS_VAR(path_expr); - phalcon_array_fetch_quick_string(&path_expr, statement, SS("path"), 270591026UL, PH_NOISY); - - PHALCON_OBS_VAR(expr_type); - phalcon_array_fetch_quick_string(&expr_type, path_expr, SS("type"), 276192743UL, PH_NOISY); - - if (PHALCON_IS_LONG(expr_type, 260)) { - - if (!phalcon_array_isset_quick_string(statement, SS("params"), 2613350281UL)) { - - PHALCON_OBS_VAR(path); - phalcon_array_fetch_quick_string(&path, path_expr, SS("value"), 574111618UL, PH_NOISY); - - 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_VAR(final_path); - PHALCON_CONCAT_VV(final_path, views_dir, path); - } else { - PHALCON_CPY_WRT(final_path, path); - } - - PHALCON_INIT_VAR(extended); - ZVAL_BOOL(extended, 0); - - PHALCON_INIT_VAR(sub_compiler); - if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { - return; - } - - PHALCON_INIT_VAR(compilation); - phalcon_call_method_p2_key(compilation, sub_compiler, "compile", final_path, extended, 1074882030UL); - - 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(compilation); - phalcon_file_get_contents(compilation, compiled_path TSRMLS_CC); - } - - RETURN_CCTOR(compilation); - } - } - - 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_OBS_VAR(expr_params); - phalcon_array_fetch_quick_string(&expr_params, statement, SS("params"), 2613350281UL, PH_NOISY); - - PHALCON_INIT_VAR(params); - phalcon_call_method_p1_key(params, this_ptr, "expression", expr_params, 218841909UL); - PHALCON_CONCAT_SVSVS(return_value, "partial(", path, ", ", params, "); ?>"); - - 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_array_isset_quick_string(statement, SS("assignments"), 2364482705UL)) { ->>>>>>> 1.2.2 - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } - - PHALCON_INIT_VAR(compilation); -<<<<<<< HEAD - ZVAL_STRING(compilation, "", 1); - phalcon_property_incr(this_ptr, SL("_foreachLevel") TSRMLS_CC); - - PHALCON_INIT_VAR(prefix); - phalcon_call_method_key(prefix, this_ptr, "getuniqueprefix", 3888429962UL); - - PHALCON_OBS_VAR(level); - phalcon_read_property_this_quick(&level, this_ptr, SL("_foreachLevel"), 1560648116UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(prefix_level); - PHALCON_CONCAT_VV(prefix_level, prefix, level); -======= - ZVAL_STRING(compilation, "") TSRMLS_CC); - - RETURN_CTOR(compilation); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileDo){ - - zval *statement, *expr, *expr_code; - - 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; - } ->>>>>>> 1.2.2 - - 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); - -<<<<<<< HEAD - PHALCON_OBS_VAR(block_statements); - phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); - - PHALCON_INIT_VAR(for_else); - ZVAL_BOOL(for_else, 0); - if (Z_TYPE_P(block_statements) == IS_ARRAY) { - - phalcon_is_iterable(block_statements, &ah0, &hp0, 0, 0); - - 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); - } - - } - - PHALCON_INIT_VAR(code); - phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); - - 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_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(variable); - phalcon_array_fetch_quick_string(&variable, statement, SS("variable"), 1809440971UL, PH_NOISY); - - 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(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)); ?>"); - } - - if (Z_TYPE_P(for_else) == IS_STRING) { - PHALCON_SCONCAT_SVS(compilation, ""); - } - - 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 { - if (phalcon_array_isset(loop_context, level)) { - PHALCON_SCONCAT_SVS(compilation, ""); - } else { - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - } - } - - phalcon_property_decr(this_ptr, SL("_foreachLevel") TSRMLS_CC); - - 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_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_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_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileIf){ - - zval *statement, *extends_mode = NULL, *compilation; - zval *expr, *expr_code, *block_statements = NULL, *code = NULL; - - 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); - - 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); - } - - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - - 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); - - 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_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); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - 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(compilation); - - 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, "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_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); - - 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); - - 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, "]; } ?>"); - } - - 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); - - 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(compilation); - - 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_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_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, expr, SS("name"), 268211462UL, PH_NOISY); - - 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_OBS_VAR(name_value); - phalcon_array_fetch_quick_string(&name_value, name, SS("value"), 574111618UL, PH_NOISY); - - if (PHALCON_IS_STRING(name_value, "super")) { - RETURN_CCTOR(expr_code); - } - } - } - - 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_View_Engine_Volt_Compiler, compileInclude){ - - 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_fetch_params(1, 1, 0, &statement); - - if (!phalcon_array_isset_quick_string(statement, SS("path"), 270591026UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } - - PHALCON_OBS_VAR(path_expr); - phalcon_array_fetch_quick_string(&path_expr, statement, SS("path"), 270591026UL, PH_NOISY); - - PHALCON_OBS_VAR(expr_type); - phalcon_array_fetch_quick_string(&expr_type, path_expr, SS("type"), 276192743UL, PH_NOISY); - - if (PHALCON_IS_LONG(expr_type, 260)) { - - if (!phalcon_array_isset_quick_string(statement, SS("params"), 2613350281UL)) { - - PHALCON_OBS_VAR(path); - phalcon_array_fetch_quick_string(&path, path_expr, SS("value"), 574111618UL, PH_NOISY); - - 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_VAR(final_path); - PHALCON_CONCAT_VV(final_path, views_dir, path); - } else { - PHALCON_CPY_WRT(final_path, path); - } - - PHALCON_INIT_VAR(extended); - ZVAL_BOOL(extended, 0); - - PHALCON_INIT_VAR(sub_compiler); - if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { - return; - } - - PHALCON_INIT_VAR(compilation); - phalcon_call_method_p2_key(compilation, sub_compiler, "compile", final_path, extended, 1074882030UL); - - 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(compilation); - phalcon_file_get_contents(compilation, compiled_path TSRMLS_CC); - } - - RETURN_CCTOR(compilation); - } - } - - 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_OBS_VAR(expr_params); - phalcon_array_fetch_quick_string(&expr_params, statement, SS("params"), 2613350281UL, PH_NOISY); - - PHALCON_INIT_VAR(params); - phalcon_call_method_p1_key(params, this_ptr, "expression", expr_params, 218841909UL); - PHALCON_CONCAT_SVSVS(return_value, "partial(", path, ", ", params, "); ?>"); - - 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_array_isset_quick_string(statement, SS("assignments"), 2364482705UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } - - PHALCON_INIT_VAR(compilation); - ZVAL_STRING(compilation, "") TSRMLS_CC); - - RETURN_CTOR(compilation); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileDo){ - - zval *statement, *expr, *expr_code; - - 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_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_View_Engine_Volt_Compiler, compileReturn){ - - zval *statement, *expr, *expr_code; - - 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_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_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); - - if (!phalcon_array_isset_quick_string(statement, SS("enable"), 1780738348UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } - - PHALCON_OBS_VAR(old_autoescape); - phalcon_read_property_this_quick(&old_autoescape, this_ptr, SL("_autoescape"), 2399648718UL, PH_NOISY_CC); - - 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_OBS_VAR(block_statements); - phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); - - 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); - - 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 (!phalcon_array_isset_quick_string(statement, SS("name"), 268211462UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } - - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, statement, SS("name"), 268211462UL, PH_NOISY); - - 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_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); - } - - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, ""); - } else { - PHALCON_SCONCAT_VS(code, name, "($__p) { "); - - PHALCON_OBS_VAR(parameters); - phalcon_array_fetch_quick_string(¶meters, statement, SS("parameters"), 3941032889UL, PH_NOISY); - - phalcon_is_iterable(parameters, &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(parameter); - - 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); - } - - 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_View_Engine_Volt_Compiler, compileCall){ - - - -} - -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, 1, 1, &statements, &extends_mode); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - if (!phalcon_fast_count_ev(statements TSRMLS_CC)) { - RETURN_MM_EMPTY_STRING(); - } - - PHALCON_OBS_VAR(extended); - phalcon_read_property_this_quick(&extended, this_ptr, SL("_extended"), 1049215029UL, PH_NOISY_CC); - - 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_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_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_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 (Z_TYPE_P(extensions) == IS_ARRAY) { - - PHALCON_INIT_NVAR(event); - ZVAL_STRING(event, "compileStatement", 1); - - PHALCON_INIT_NVAR(fire_arguments); - array_init_size(fire_arguments, 1); - phalcon_array_append(&fire_arguments, statement, PH_SEPARATE); - - 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_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, statement, SS("type"), 276192743UL, PH_NOISY); - - - switch (phalcon_get_intval(type)) { - - 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; - - 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; - - 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; - - 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; - - 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; - - 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; - - 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 (Z_TYPE_P(compilation) != IS_NULL) { - phalcon_array_append(&blocks, compilation, PH_SEPARATE); - - PHALCON_INIT_NVAR(compilation); - } - - 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); - } - } - - break; - - 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_NVAR(final_path); - PHALCON_CONCAT_VV(final_path, views_dir, path); - } else { - PHALCON_CPY_WRT(final_path, path); - } - - PHALCON_INIT_NVAR(extended); - ZVAL_BOOL(extended, 1); - - PHALCON_INIT_NVAR(sub_compiler); - if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { - return; - } - - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p2_key(temp_compilation, sub_compiler, "compile", final_path, extended, 1074882030UL); - - 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_NVAR(temp_compilation); - phalcon_file_get_contents(temp_compilation, compiled_path TSRMLS_CC); - } - - 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; - - 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; - - 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; - - 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; - - 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; - - 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; - - case 319: - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - break; - - 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; - - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - if (PHALCON_IS_TRUE(block_mode)) { - - PHALCON_OBS_VAR(level); - phalcon_read_property_this_quick(&level, this_ptr, SL("_blockLevel"), 160754279UL, PH_NOISY_CC); - if (PHALCON_IS_LONG(level, 1)) { - - if (Z_TYPE_P(compilation) != IS_NULL) { - phalcon_update_property_array_append(this_ptr, SL("_blocks"), compilation TSRMLS_CC); - } - } - - phalcon_property_decr(this_ptr, SL("_blockLevel") TSRMLS_CC); - } - - phalcon_property_decr(this_ptr, SL("_level") TSRMLS_CC); - - RETURN_CCTOR(compilation); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _compileSource){ - - 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, 1, 1, &view_code, &extends_mode); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - PHALCON_OBS_VAR(current_path); - phalcon_read_property_this_quick(¤t_path, this_ptr, SL("_currentPath"), 3436123892UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(intermediate); - if (phvolt_parse_view(intermediate, view_code, current_path TSRMLS_CC) == FAILURE) { - return; - } - - if (Z_TYPE_P(intermediate) == IS_ARRAY) { - - PHALCON_INIT_VAR(compilation); - phalcon_call_method_p2_key(compilation, this_ptr, "_statementlist", intermediate, extends_mode, 1357145205UL); - - PHALCON_OBS_VAR(extended); - phalcon_read_property_this_quick(&extended, this_ptr, SL("_extended"), 1049215029UL, PH_NOISY_CC); - if (PHALCON_IS_TRUE(extended)) { - - if (PHALCON_IS_TRUE(extends_mode)) { - PHALCON_INIT_VAR(final_compilation); - array_init(final_compilation); - } else { - PHALCON_INIT_NVAR(final_compilation); - } - - PHALCON_OBS_VAR(blocks); - phalcon_read_property_this_quick(&blocks, this_ptr, SL("_blocks"), 2750049986UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(extended_blocks); - phalcon_read_property_this_quick(&extended_blocks, this_ptr, SL("_extendedBlocks"), 3140083987UL, PH_NOISY_CC); - - phalcon_is_iterable(extended_blocks, &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(block); - - 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(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); - - 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); - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - 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); - } - - RETURN_CCTOR(compilation); - } - - 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 (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - 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_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); - } - - 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; - } - - 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(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_update_property_this_quick(this_ptr, SL("_currentPath"), path, 3436123892UL TSRMLS_CC); - - PHALCON_INIT_VAR(compilation); - phalcon_call_method_p2_key(compilation, this_ptr, "_compilesource", view_code, extends_mode, 1468654718UL); - - 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_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_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); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - - PHALCON_INIT_VAR(znull); - - PHALCON_INIT_VAR(zfalse); - ZVAL_BOOL(zfalse, 0); - - 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_INIT_VAR(stat); - ZVAL_BOOL(stat, 1); - PHALCON_CPY_WRT(compile_always, zfalse); - - PHALCON_INIT_VAR(compiled_path); - ZVAL_STRING(compiled_path, "", 1); - PHALCON_CPY_WRT(prefix, znull); - - PHALCON_INIT_VAR(compiled_separator); - ZVAL_STRING(compiled_separator, "%%", 1); - - PHALCON_INIT_VAR(compiled_extension); - ZVAL_STRING(compiled_extension, ".php", 1); - PHALCON_CPY_WRT(compilation, znull); - - 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("compileAlways"), 595908511UL)) { - - 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_quick_string(options, SS("prefix"), 3263410483UL)) { - - 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 (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; - } - } - } - - if (phalcon_array_isset_quick_string(options, SS("compiledSeparator"), 3462898403UL)) { - - 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 (phalcon_array_isset_quick_string(options, SS("compiledExtension"), 401304207UL)) { - - 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 (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); - - 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_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)) { - - 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(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 (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_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(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(); -} - - - -/* 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; - } - 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; - } - 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; - } - -} - -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++; - } - - if (*KKCURSOR != '\0') { - next = *(KKCURSOR + 1); - if (next != '\0') { - double_next = *(KKCURSOR + 2); - } - } - - 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; - } - - } 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; -======= - PHALCON_CONCAT_SVS(return_value, ""); - - 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); - - 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_CONCAT_SVS(return_value, ""); - - 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); - - if (!phalcon_array_isset_quick_string(statement, SS("enable"), 1780738348UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } - - PHALCON_OBS_VAR(old_autoescape); - phalcon_read_property_this_quick(&old_autoescape, this_ptr, SL("_autoescape"), 2399648718UL, PH_NOISY_CC); - - 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_OBS_VAR(block_statements); - phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); - - 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); - - 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 (!phalcon_array_isset_quick_string(statement, SS("name"), 268211462UL)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); - return; - } - - PHALCON_OBS_VAR(name); - phalcon_array_fetch_quick_string(&name, statement, SS("name"), 268211462UL, PH_NOISY); - - 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_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); - } - - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, ""); - } else { - PHALCON_SCONCAT_VS(code, name, "($__p) { "); - - PHALCON_OBS_VAR(parameters); - phalcon_array_fetch_quick_string(¶meters, statement, SS("parameters"), 3941032889UL, PH_NOISY); - - phalcon_is_iterable(parameters, &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(parameter); - - 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); - } - - 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_View_Engine_Volt_Compiler, compileCall){ - - - -} - -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, 1, 1, &statements, &extends_mode); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - if (!phalcon_fast_count_ev(statements TSRMLS_CC)) { - RETURN_MM_EMPTY_STRING(); - } - - PHALCON_OBS_VAR(extended); - phalcon_read_property_this_quick(&extended, this_ptr, SL("_extended"), 1049215029UL, PH_NOISY_CC); - - 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_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_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_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 (Z_TYPE_P(extensions) == IS_ARRAY) { - - PHALCON_INIT_NVAR(event); - ZVAL_STRING(event, "compileStatement", 1); - - PHALCON_INIT_NVAR(fire_arguments); - array_init_size(fire_arguments, 1); - phalcon_array_append(&fire_arguments, statement, PH_SEPARATE); - - 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_OBS_NVAR(type); - phalcon_array_fetch_quick_string(&type, statement, SS("type"), 276192743UL, PH_NOISY); - - - switch (phalcon_get_intval(type)) { - - 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; - - 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; - - 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; - - 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; - - 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; - - 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; - - 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 (Z_TYPE_P(compilation) != IS_NULL) { - phalcon_array_append(&blocks, compilation, PH_SEPARATE); - - PHALCON_INIT_NVAR(compilation); - } - - 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); - } - } - - break; - - 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_NVAR(final_path); - PHALCON_CONCAT_VV(final_path, views_dir, path); - } else { - PHALCON_CPY_WRT(final_path, path); - } - - PHALCON_INIT_NVAR(extended); - ZVAL_BOOL(extended, 1); - - PHALCON_INIT_NVAR(sub_compiler); - if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { - return; - } - - PHALCON_INIT_NVAR(temp_compilation); - phalcon_call_method_p2_key(temp_compilation, sub_compiler, "compile", final_path, extended, 1074882030UL); - - 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_NVAR(temp_compilation); - phalcon_file_get_contents(temp_compilation, compiled_path TSRMLS_CC); - } - - 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; - - 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; - - 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; - - 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; - - 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; - - 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; - - case 319: - phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - break; - - 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; - - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - if (PHALCON_IS_TRUE(block_mode)) { - - PHALCON_OBS_VAR(level); - phalcon_read_property_this_quick(&level, this_ptr, SL("_blockLevel"), 160754279UL, PH_NOISY_CC); - if (PHALCON_IS_LONG(level, 1)) { - - if (Z_TYPE_P(compilation) != IS_NULL) { - phalcon_update_property_array_append(this_ptr, SL("_blocks"), compilation TSRMLS_CC); - } - } - - phalcon_property_decr(this_ptr, SL("_blockLevel") TSRMLS_CC); - } - - phalcon_property_decr(this_ptr, SL("_level") TSRMLS_CC); - - RETURN_CCTOR(compilation); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _compileSource){ - - 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, 1, 1, &view_code, &extends_mode); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - PHALCON_OBS_VAR(current_path); - phalcon_read_property_this_quick(¤t_path, this_ptr, SL("_currentPath"), 3436123892UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(intermediate); - if (phvolt_parse_view(intermediate, view_code, current_path TSRMLS_CC) == FAILURE) { - return; - } - - if (Z_TYPE_P(intermediate) == IS_ARRAY) { - - PHALCON_INIT_VAR(compilation); - phalcon_call_method_p2_key(compilation, this_ptr, "_statementlist", intermediate, extends_mode, 1357145205UL); - - PHALCON_OBS_VAR(extended); - phalcon_read_property_this_quick(&extended, this_ptr, SL("_extended"), 1049215029UL, PH_NOISY_CC); - if (PHALCON_IS_TRUE(extended)) { - - if (PHALCON_IS_TRUE(extends_mode)) { - PHALCON_INIT_VAR(final_compilation); - array_init(final_compilation); - } else { - PHALCON_INIT_NVAR(final_compilation); - } - - PHALCON_OBS_VAR(blocks); - phalcon_read_property_this_quick(&blocks, this_ptr, SL("_blocks"), 2750049986UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(extended_blocks); - phalcon_read_property_this_quick(&extended_blocks, this_ptr, SL("_extendedBlocks"), 3140083987UL, PH_NOISY_CC); - - phalcon_is_iterable(extended_blocks, &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(block); - - 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(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); - - 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); - } - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - 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); - } - - RETURN_CCTOR(compilation); - } - - 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 (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - 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_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); - } - - 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; - } - - 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(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_update_property_this_quick(this_ptr, SL("_currentPath"), path, 3436123892UL TSRMLS_CC); - - PHALCON_INIT_VAR(compilation); - phalcon_call_method_p2_key(compilation, this_ptr, "_compilesource", view_code, extends_mode, 1468654718UL); - - 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_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_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); - - if (!extends_mode) { - PHALCON_INIT_VAR(extends_mode); - ZVAL_BOOL(extends_mode, 0); - } - - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - - PHALCON_INIT_VAR(znull); - - PHALCON_INIT_VAR(zfalse); - ZVAL_BOOL(zfalse, 0); - - 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_INIT_VAR(stat); - ZVAL_BOOL(stat, 1); - PHALCON_CPY_WRT(compile_always, zfalse); - - PHALCON_INIT_VAR(compiled_path); - ZVAL_STRING(compiled_path, "", 1); - PHALCON_CPY_WRT(prefix, znull); - - PHALCON_INIT_VAR(compiled_separator); - ZVAL_STRING(compiled_separator, "%%", 1); - - PHALCON_INIT_VAR(compiled_extension); - ZVAL_STRING(compiled_extension, ".php", 1); - PHALCON_CPY_WRT(compilation, znull); - - 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("compileAlways"), 595908511UL)) { - - 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_quick_string(options, SS("prefix"), 3263410483UL)) { - - 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 (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; - } - } - } - - if (phalcon_array_isset_quick_string(options, SS("compiledSeparator"), 3462898403UL)) { - - 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 (phalcon_array_isset_quick_string(options, SS("compiledExtension"), 401304207UL)) { - - 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 (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); - - 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_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)) { - - 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(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 (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_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(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(); -} - - - -/* 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; - } - 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; - } - 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; - } - -} - -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++; - } - - if (*KKCURSOR != '\0') { - next = *(KKCURSOR + 1); - if (next != '\0') { - double_next = *(KKCURSOR + 2); - } - } - - 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; - } - - } 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; - 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; - } -// 637 "scanner.c" -kk46: - ++KKCURSOR; -// 518 "scanner.re" - { - token->opcode = PHVOLT_T_PARENTHESES_CLOSE; - return 0; - } -// 645 "scanner.c" -kk48: - ++KKCURSOR; -// 523 "scanner.re" - { - token->opcode = PHVOLT_T_SBRACKET_OPEN; - return 0; - } -// 653 "scanner.c" -kk50: - ++KKCURSOR; -// 528 "scanner.re" - { - token->opcode = PHVOLT_T_SBRACKET_CLOSE; - return 0; - } -// 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; - } -// 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; - } -// 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; - } -// 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; - } -kk75: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '=': goto kk77; - default: goto kk76; - } -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; - } -// 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; - } -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; - } -// 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; - } -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; - } -// 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; - } -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; - } -// 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; - } -// 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; - } -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; - } -// 1103 "scanner.c" -kk128: - ++KKCURSOR; -// 400 "scanner.re" - { - s->whitespace_control = 0; - token->opcode = PHVOLT_T_OPEN_DELIMITER; - return 0; - } -// 1112 "scanner.c" -kk130: - ++KKCURSOR; -// 426 "scanner.re" - { - s->whitespace_control = 0; - s->statement_position++; - token->opcode = PHVOLT_T_OPEN_EDELIMITER; - return 0; - } -// 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)) { ->>>>>>> 1.2.2 - 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': -<<<<<<< HEAD - 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 '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': ->>>>>>> 1.2.2 - case 'E': - case 'e': goto kk208; - default: goto kk100; - } -kk9: - kkch = *++KKCURSOR; - switch (kkch) { - case 'O': - case 'o': goto kk201; - case 'U': -<<<<<<< HEAD - 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 '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; - } -kk146: -// 312 "scanner.re" - { - token->opcode = PHVOLT_T_RETURN; - return 0; - } -// 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; - } -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': ->>>>>>> 1.2.2 - 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': -<<<<<<< HEAD - 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 '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; - } -// 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; - } -// 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': ->>>>>>> 1.2.2 - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - 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; -<<<<<<< HEAD - 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; - } -// 637 "scanner.c" -kk46: - ++KKCURSOR; -// 518 "scanner.re" - { - token->opcode = PHVOLT_T_PARENTHESES_CLOSE; - return 0; - } -// 645 "scanner.c" -kk48: - ++KKCURSOR; -// 523 "scanner.re" - { - token->opcode = PHVOLT_T_SBRACKET_OPEN; - return 0; - } -// 653 "scanner.c" -kk50: - ++KKCURSOR; -// 528 "scanner.re" - { - token->opcode = PHVOLT_T_SBRACKET_CLOSE; - return 0; - } -// 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; - } -// 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; - } -// 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; - } -// 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; - } -kk75: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { - case '=': goto kk77; - default: goto kk76; - } -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; - } -// 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; - } -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; - } -// 885 "scanner.c" -kk99: - ++KKCURSOR; - kkch = *KKCURSOR; -kk100: - switch (kkch) { -======= - default: goto kk164; - } -kk164: -// 347 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_CACHE; - return 0; - } -// 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; - } -kk171: -// 285 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_MACRO; - return 0; - } -// 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)) { ->>>>>>> 1.2.2 - 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; -<<<<<<< HEAD - 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; - } -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; - } -// 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; - } -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; - } -// 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; - } -// 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; - } -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; - } -// 1103 "scanner.c" -kk128: - ++KKCURSOR; -// 400 "scanner.re" - { - s->whitespace_control = 0; - token->opcode = PHVOLT_T_OPEN_DELIMITER; - return 0; - } -// 1112 "scanner.c" -kk130: - ++KKCURSOR; -// 426 "scanner.re" - { - s->whitespace_control = 0; - s->statement_position++; - token->opcode = PHVOLT_T_OPEN_EDELIMITER; - return 0; - } -// 1122 "scanner.c" -kk132: - kkch = *++KKCURSOR; - switch (kkch) { - case 'F': - case 'f': goto kk135; - default: goto kk100; - } -kk133: -======= - default: goto kk177; - } -kk177: -// 382 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_BREAK; - return 0; - } -// 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; - } -// 2102 "scanner.c" -kk182: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - 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: -======= - 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - 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: -======= - default: goto kk194; - } -kk194: -// 364 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_AUTOESCAPE; - return 0; - } -// 2318 "scanner.c" -kk195: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk146; - } -kk146: -// 312 "scanner.re" - { - token->opcode = PHVOLT_T_RETURN; - return 0; - } -// 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; - } -kk149: -======= - default: goto kk196; - } -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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk150; - } -kk150: -// 307 "scanner.re" - { - token->opcode = PHVOLT_T_WITH; - return 0; - } -// 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: -======= - 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk159; - } -kk159: -// 376 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_CONTINUE; - return 0; - } -// 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: -======= - default: goto kk205; - } -kk205: -// 249 "scanner.re" - { - token->opcode = PHVOLT_T_NULL; - return 0; - } -// 2581 "scanner.c" -kk206: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk164; - } -kk164: -// 347 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_CACHE; - return 0; - } -// 1731 "scanner.c" -kk165: -======= - default: goto kk207; - } -kk207: -// 329 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_NOT; - return 0; - } -// 2658 "scanner.c" -kk208: - kkch = *++KKCURSOR; - switch (kkch) { - case 'T': - case 't': goto kk209; - default: goto kk100; - } -kk209: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - 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: -======= - 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk171; - } -kk171: -// 285 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_MACRO; - return 0; - } -// 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: -======= - 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk177; - } -kk177: -// 382 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_BREAK; - return 0; - } -// 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: -======= - default: goto kk218; - } -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; - } -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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk181; - } -kk181: -// 274 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_BLOCK; - return 0; - } -// 2102 "scanner.c" -kk182: -======= - default: goto kk227; - } -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; - } -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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - 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: -======= - default: goto kk239; - } -kk239: -// 291 "scanner.re" - { - token->opcode = PHVOLT_T_ENDMACRO; - return 0; - } -// 3204 "scanner.c" -kk240: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk194; - } -kk194: -// 364 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_AUTOESCAPE; - return 0; - } -// 2318 "scanner.c" -kk195: -======= - 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk196; - } -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: -======= - default: goto kk244; - } -kk244: -// 234 "scanner.re" - { - token->opcode = PHVOLT_T_ENDFOR; - return 0; - } -// 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - 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: -======= - default: goto kk249; - } -kk249: -// 302 "scanner.re" - { - token->opcode = PHVOLT_T_ENDCALL; - return 0; - } -// 3462 "scanner.c" -kk250: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk251; - default: goto kk100; - } -kk251: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk205; - } -kk205: -// 249 "scanner.re" - { - token->opcode = PHVOLT_T_NULL; - return 0; - } -// 2581 "scanner.c" -kk206: -======= - default: goto kk252; - } -kk252: -// 353 "scanner.re" - { - token->opcode = PHVOLT_T_ENDCACHE; - return 0; - } -// 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk207; - } -kk207: -// 329 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_NOT; - return 0; - } -// 2658 "scanner.c" -kk208: - kkch = *++KKCURSOR; - switch (kkch) { - case 'T': - case 't': goto kk209; - default: goto kk100; - } -kk209: -======= - default: goto kk257; - } -kk257: -// 280 "scanner.re" - { - token->opcode = PHVOLT_T_ENDBLOCK; - return 0; - } -// 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - 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: -======= - default: goto kk267; - } -kk267: -// 370 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_ENDAUTOESCAPE; - return 0; - } -// 3775 "scanner.c" -kk268: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk269; - default: goto kk100; - } -kk269: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - 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: -======= - 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; - } -// 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk218; - } -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; - } -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: -======= - 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk227; - } -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; - } -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: -======= - default: goto kk277; - } -kk277: -// 213 "scanner.re" - { - token->opcode = PHVOLT_T_ELSEFOR; - return 0; - } -// 4031 "scanner.c" -kk278: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk239; - } -kk239: -// 291 "scanner.re" - { - token->opcode = PHVOLT_T_ENDMACRO; - return 0; - } -// 3204 "scanner.c" -kk240: -======= - default: goto kk279; - } -kk279: -// 202 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_IF; - return 0; - } -// 4108 "scanner.c" -kk280: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - 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: -======= - case 'C': - case 'c': goto kk284; - default: goto kk281; - } -kk281: -// 239 "scanner.re" - { - token->opcode = PHVOLT_T_IN; - return 0; - } -// 4184 "scanner.c" -kk282: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk244; - } -kk244: -// 234 "scanner.re" - { - token->opcode = PHVOLT_T_ENDFOR; - return 0; - } -// 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; - } -// 3462 "scanner.c" -kk250: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk251; - default: goto kk100; - } -kk251: -======= - default: goto kk283; - } -kk283: -// 323 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_IS; - return 0; - } -// 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: ->>>>>>> 1.2.2 - ++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; -<<<<<<< HEAD - default: goto kk252; - } -kk252: -// 353 "scanner.re" - { - token->opcode = PHVOLT_T_ENDCACHE; - return 0; - } -// 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)) { -======= - default: goto kk289; - } -kk289: -// 341 "scanner.re" - { - s->statement_position++; - token->opcode = PHVOLT_T_INCLUDE; - return 0; - } -// 4366 "scanner.c" -kk290: - kkch = *++KKCURSOR; - switch (kkch) { ->>>>>>> 1.2.2 - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': -<<<<<<< HEAD - 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; - } -// 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 '9': goto kk293; - default: goto kk103; - } -kk291: - kkaccept = 0; - KKMARKER = ++KKCURSOR; - kkch = *KKCURSOR; -kk292: - switch (kkch) { - case '.': goto kk290; ->>>>>>> 1.2.2 - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': -<<<<<<< HEAD - 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; - } -// 3775 "scanner.c" -kk268: - kkch = *++KKCURSOR; - switch (kkch) { - case 'E': - case 'e': goto kk269; - default: goto kk100; - } -kk269: - ++KKCURSOR; - switch ((kkch = *KKCURSOR)) { -======= - case '9': goto kk291; - default: goto kk3; - } -kk293: - ++KKCURSOR; - kkch = *KKCURSOR; - switch (kkch) { ->>>>>>> 1.2.2 - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': -<<<<<<< HEAD - 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; - } -// 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; - } -// 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; - } -// 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; - } -kk281: -// 239 "scanner.re" - { - token->opcode = PHVOLT_T_IN; - return 0; - } -// 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; - } -// 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; - } -// 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" - - - } - } - - return status; -} - - -/* 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); - - } - zval_ptr_dtor(&list_left); - } else { - add_next_index_zval(ret, list_left); - } - } - - 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 */ -======= - 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" - - - } - } ->>>>>>> 1.2.2 - -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); -} -<<<<<<< HEAD -// 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); - - } - - 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 { - - 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); - } - } - - /* 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); - } - } - } - - 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) { - 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; - } - - if (parser_status->status != PHVOLT_PARSING_OK) { - status = FAILURE; - break; - } - - 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); - } - } - - 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); - } - efree(parser_status->syntax_error); - } - } - - 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); - } - } - } - - efree(parser_status); - efree(state); - - return status; -} - - - - -#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; -======= - - -/* 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); + zval_ptr_dtor(&list_left); + } else { + add_next_index_zval(ret, list_left); + } - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); + if (right_list) { + add_next_index_zval(ret, right_list); + } return ret; } -static zval *phvolt_ret_empty_statement(phvolt_scanner_state *state) +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_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); + 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; } -static zval *phvolt_ret_break_statement(phvolt_scanner_state *state) +static zval *phql_ret_assoc_name(zval *qualified_name, phql_parser_token *alias) { + 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); + 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); + } return ret; + } -static zval *phvolt_ret_continue_statement(phvolt_scanner_state *state) +static zval *phql_ret_join_type(int type) { 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); + ZVAL_LONG(ret, type); return ret; } -static zval *phvolt_ret_zval_list(zval *list_left, zval *right_list) +static zval *phql_ret_join_item(zval *type, zval *qualified, zval *alias, zval *conditions) { zval *ret; - HashPosition pos; - HashTable *list; MAKE_STD_ZVAL(ret); array_init(ret); + add_assoc_zval(ret, "type", type); - 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); - - } - zval_ptr_dtor(&list_left); - } else { - add_next_index_zval(ret, list_left); - } + if (qualified) { + add_assoc_zval(ret, "qualified", qualified); } - 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); + if (alias) { + add_assoc_zval(ret, "alias", alias); } - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); + if (conditions) { + add_assoc_zval(ret, "conditions", conditions); + } return ret; + } -static zval *phvolt_ret_expr(int type, zval *left, zval *right, zval *ternary, phvolt_scanner_state *state) +static zval *phql_ret_expr(int type, zval *left, zval *right) { 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) +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", 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, + + 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); + } + + return ret; +} + + +// 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 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, +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 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 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, }; -#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 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, }; -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 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[] = { }; -#define KK_SZ_ACTTAB (sizeof(kk_action)/sizeof(kk_action[0])) +#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 */ + +#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 */ + +#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 */ + +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 +} + +void *phql_Alloc(void *(*mallocProc)(size_t)){ + yyParser *pParser; + pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) ); + if( pParser ){ + pParser->yyidx = -1; + } + return pParser; +} + +/* 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)); + } +} +// 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 */ + } +} -/* 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 */ +static int yy_pop_parser_stack(yyParser *pParser){ + YYCODETYPE yymajor; + yyStackEntry *yytos = &pParser->yystack[pParser->yyidx]; -/* 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. + 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; +} + +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 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); + } +#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]; + } +} + +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 +} + +/* The following table contains information about every rule that +** is used during the reduce. */ -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 */ +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 }, }; -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; +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 -#include -static FILE *kkTraceFILE = 0; -static char *kkTracePrompt = 0; + if( yyTraceFILE && yyruleno>=0 + && yyruleno + ** { ... } // User supplied code + ** // + ** break; + */ + case 0: +// 522 "parser.lemon" +{ + status->ret = yymsp[0].minor.yy132; +} +// 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; +} +// 1621 "parser.c" + break; + case 5: +// 546 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_select_statement(yymsp[0].minor.yy132, NULL, NULL, NULL, NULL, NULL); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 1855 "parser.c" + break; + case 37: +// 680 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_column_item(PHQL_T_EXPR, yymsp[0].minor.yy132, NULL, NULL); +} +// 1862 "parser.c" + break; + case 40: +// 696 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_zval_list(yymsp[-1].minor.yy132, yymsp[0].minor.yy132); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 1914 "parser.c" + break; + case 49: +// 744 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_join_type(PHQL_T_INNERJOIN); + yy_destructor(32,&yymsp[0].minor); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 1997 "parser.c" + break; + case 58: +// 782 "parser.lemon" +{ + yygotominor.yy132 = yymsp[0].minor.yy132; + yy_destructor(39,&yymsp[-1].minor); +} +// 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); +} +// 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); +} +// 2031 "parser.c" + break; + case 67: +// 831 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_update_statement(yymsp[0].minor.yy132, NULL, NULL); +} +// 2038 "parser.c" + break; + case 68: +// 835 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_update_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); +} +// 2045 "parser.c" + break; + case 69: +// 839 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_update_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); +} +// 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); +} +// 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); +} +// 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); +} +// 2076 "parser.c" + break; + case 76: +// 877 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_delete_statement(yymsp[0].minor.yy132, NULL, NULL); +} +// 2083 "parser.c" + break; + case 77: +// 881 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_delete_statement(yymsp[-1].minor.yy132, yymsp[0].minor.yy132, NULL); +} +// 2090 "parser.c" + break; + case 78: +// 885 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_delete_statement(yymsp[-1].minor.yy132, NULL, yymsp[0].minor.yy132); +} +// 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); +} +// 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); +} +// 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); +} +// 2121 "parser.c" + break; + case 82: +// 905 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_assoc_name(yymsp[-1].minor.yy132, yymsp[0].minor.yy0); +} +// 2128 "parser.c" + break; + case 83: +// 909 "parser.lemon" +{ + yygotominor.yy132 = phql_ret_assoc_name(yymsp[0].minor.yy132, NULL); +} +// 2135 "parser.c" + break; + case 85: +// 921 "parser.lemon" +{ + yygotominor.yy132 = yymsp[0].minor.yy132; + yy_destructor(48,&yymsp[-1].minor); +} +// 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); +} +// 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); +} +// 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); +} +// 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); } -#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 +// 2184 "parser.c" + break; + case 96: +// 979 "parser.lemon" +{ + yygotominor.yy132 = yymsp[0].minor.yy132; + yy_destructor(54,&yymsp[-1].minor); } - -void *phvolt_Alloc(void *(*mallocProc)(size_t)){ - kkParser *pParser; - pParser = (kkParser*)(*mallocProc)( (size_t)sizeof(kkParser) ); - if( pParser ){ - pParser->kkidx = -1; - } - return pParser; +// 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); } - -/* 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" +// 2201 "parser.c" + break; + case 98: +// 989 "parser.lemon" { - if ((kkpminor->kk0)) { - if ((kkpminor->kk0)->free_flag) { - efree((kkpminor->kk0)->token); - } - efree((kkpminor->kk0)); - } + 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); } -// 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 */ - } +// 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 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; +// 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 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); +// 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 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]; - } +// 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 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]; - } +// 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); +} +// 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); +} +// 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); +} +// 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); +} +// 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 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 +// 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); } - -/* 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" +// 2291 "parser.c" + break; + case 110: +// 1041 "parser.lemon" { - status->ret = kkmsp[0].minor.kk132; + yygotominor.yy132 = phql_ret_expr(PHQL_T_BITWISE_OR, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(14,&yymsp[-1].minor); } -// 2001 "parser.c" +// 2299 "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" + case 111: +// 1045 "parser.lemon" { - kkgotominor.kk132 = kkmsp[0].minor.kk132; + yygotominor.yy132 = phql_ret_expr(PHQL_T_BITWISE_XOR, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(15,&yymsp[-1].minor); } -// 2028 "parser.c" +// 2307 "parser.c" break; - case 2: -// 722 "parser.lemon" + case 112: +// 1049 "parser.lemon" { - kkgotominor.kk132 = phvolt_ret_zval_list(kkmsp[-1].minor.kk132, kkmsp[0].minor.kk132); + yygotominor.yy132 = phql_ret_expr(PHQL_T_EQUALS, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(3,&yymsp[-1].minor); } -// 2035 "parser.c" +// 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 3: - case 36: - case 45: case 116: - case 123: -// 726 "parser.lemon" +// 1065 "parser.lemon" { - kkgotominor.kk132 = phvolt_ret_zval_list(NULL, kkmsp[0].minor.kk132); + yygotominor.yy132 = phql_ret_expr(PHQL_T_GREATEREQUAL, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(7,&yymsp[-1].minor); } -// 2046 "parser.c" +// 2347 "parser.c" break; - case 23: -// 810 "parser.lemon" + case 117: +// 1069 "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); + yygotominor.yy132 = phql_ret_expr(PHQL_T_LESSEQUAL, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(8,&yymsp[-1].minor); } -// 2059 "parser.c" +// 2355 "parser.c" break; - case 24: -// 814 "parser.lemon" + case 118: +// 1073 "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); + yygotominor.yy132 = phql_ret_expr(PHQL_T_LIKE, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(11,&yymsp[-1].minor); } -// 2072 "parser.c" +// 2363 "parser.c" break; - case 25: -// 818 "parser.lemon" + case 119: +// 1077 "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); + 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); } -// 2088 "parser.c" +// 2372 "parser.c" break; - case 26: -// 822 "parser.lemon" + case 120: +// 1081 "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); + yygotominor.yy132 = phql_ret_expr(PHQL_T_ILIKE, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(12,&yymsp[-1].minor); } -// 2104 "parser.c" +// 2380 "parser.c" break; - case 27: -// 826 "parser.lemon" + case 121: +// 1085 "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); + 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); } -// 2120 "parser.c" +// 2389 "parser.c" break; - case 28: -// 832 "parser.lemon" + case 122: +// 1089 "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); + 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); } -// 2130 "parser.c" +// 2399 "parser.c" break; - case 29: -// 838 "parser.lemon" + case 123: +// 1093 "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); + 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); } -// 2140 "parser.c" +// 2410 "parser.c" break; - case 30: -// 844 "parser.lemon" + case 124: +// 1097 "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); + yygotominor.yy132 = phql_ret_expr(PHQL_T_AGAINST, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(1,&yymsp[-1].minor); } -// 2154 "parser.c" +// 2418 "parser.c" break; - case 31: -// 848 "parser.lemon" + case 125: +// 1101 "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); + 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); } -// 2169 "parser.c" +// 2429 "parser.c" break; - case 32: -// 852 "parser.lemon" + case 126: +// 1105 "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); + 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); } -// 2184 "parser.c" +// 2440 "parser.c" break; - case 33: -// 856 "parser.lemon" + 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" { - 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); + 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); } -// 2200 "parser.c" +// 2484 "parser.c" break; - case 34: -// 862 "parser.lemon" + case 136: +// 1151 "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); + yygotominor.yy132 = phql_ret_expr(PHQL_T_DISTINCT, NULL, yymsp[0].minor.yy132); + yy_destructor(23,&yymsp[-1].minor); } -// 2210 "parser.c" +// 2492 "parser.c" break; - case 35: - case 44: - case 115: - case 122: -// 868 "parser.lemon" + case 137: +// 1155 "parser.lemon" { - kkgotominor.kk132 = phvolt_ret_zval_list(kkmsp[-2].minor.kk132, kkmsp[0].minor.kk132); - kk_destructor(2,&kkmsp[-1].minor); + yygotominor.yy132 = phql_ret_expr(PHQL_T_BETWEEN, yymsp[-2].minor.yy132, yymsp[0].minor.yy132); + yy_destructor(2,&yymsp[-1].minor); } -// 2221 "parser.c" +// 2500 "parser.c" break; - case 37: -// 878 "parser.lemon" + case 138: +// 1159 "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); + yygotominor.yy132 = phql_ret_expr(PHQL_T_NOT, NULL, yymsp[0].minor.yy132); + yy_destructor(24,&yymsp[-1].minor); } -// 2229 "parser.c" +// 2508 "parser.c" break; - case 38: -// 882 "parser.lemon" + case 139: +// 1163 "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); + yygotominor.yy132 = phql_ret_expr(PHQL_T_BITWISE_NOT, NULL, yymsp[0].minor.yy132); + yy_destructor(25,&yymsp[-1].minor); } -// 2237 "parser.c" +// 2516 "parser.c" break; - case 39: -// 886 "parser.lemon" + case 140: +// 1167 "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); + 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); } -// 2245 "parser.c" +// 2525 "parser.c" break; - case 40: -// 890 "parser.lemon" + case 142: +// 1175 "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); + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_INTEGER, yymsp[0].minor.yy0); } -// 2253 "parser.c" +// 2532 "parser.c" break; - case 41: -// 894 "parser.lemon" + case 143: +// 1179 "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); + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_STRING, yymsp[0].minor.yy0); } -// 2261 "parser.c" +// 2539 "parser.c" break; - case 42: -// 900 "parser.lemon" + case 144: +// 1183 "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); + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_DOUBLE, yymsp[0].minor.yy0); } -// 2276 "parser.c" +// 2546 "parser.c" break; - case 43: -// 904 "parser.lemon" + case 145: +// 1187 "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); + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_NULL, NULL); + yy_destructor(61,&yymsp[0].minor); } -// 2291 "parser.c" +// 2554 "parser.c" break; - case 46: -// 920 "parser.lemon" + case 146: +// 1191 "parser.lemon" { - kkgotominor.kk132 = phvolt_ret_macro_parameter(kkmsp[0].minor.kk0, NULL, status->scanner_state); + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_TRUE, NULL); + yy_destructor(64,&yymsp[0].minor); } -// 2298 "parser.c" +// 2562 "parser.c" break; - case 47: -// 924 "parser.lemon" + case 147: +// 1195 "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); + yygotominor.yy132 = phql_ret_literal_zval(PHQL_T_FALSE, NULL); + yy_destructor(65,&yymsp[0].minor); } -// 2306 "parser.c" +// 2570 "parser.c" break; - case 48: - case 113: - case 127: -// 928 "parser.lemon" + case 148: +// 1199 "parser.lemon" { - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_INTEGER, kkmsp[0].minor.kk0, status->scanner_state); + yygotominor.yy132 = phql_ret_placeholder_zval(PHQL_T_NPLACEHOLDER, yymsp[0].minor.yy0); } -// 2315 "parser.c" +// 2577 "parser.c" break; - case 49: - case 128: -// 932 "parser.lemon" + case 149: +// 1203 "parser.lemon" { - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_STRING, kkmsp[0].minor.kk0, status->scanner_state); + yygotominor.yy132 = phql_ret_placeholder_zval(PHQL_T_SPLACEHOLDER, yymsp[0].minor.yy0); } -// 2323 "parser.c" +// 2584 "parser.c" break; - case 50: - case 129: -// 936 "parser.lemon" + case 150: +// 1209 "parser.lemon" { - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_DOUBLE, kkmsp[0].minor.kk0, status->scanner_state); + 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); } -// 2331 "parser.c" +// 2593 "parser.c" break; - case 51: - case 130: -// 940 "parser.lemon" + case 151: +// 1213 "parser.lemon" { - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_NULL, NULL, status->scanner_state); - kk_destructor(52,&kkmsp[0].minor); + yygotominor.yy132 = phql_ret_qualified_name(yymsp[-2].minor.yy0, NULL, yymsp[0].minor.yy0); + yy_destructor(68,&yymsp[-1].minor); } -// 2340 "parser.c" +// 2601 "parser.c" break; - case 52: - case 131: -// 944 "parser.lemon" + case 152: +// 1217 "parser.lemon" { - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_FALSE, NULL, status->scanner_state); - kk_destructor(53,&kkmsp[0].minor); + yygotominor.yy132 = phql_ret_qualified_name(NULL, yymsp[-2].minor.yy0, yymsp[0].minor.yy0); + yy_destructor(30,&yymsp[-1].minor); } -// 2349 "parser.c" +// 2609 "parser.c" break; - case 53: - case 132: -// 948 "parser.lemon" + }; + 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 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); + + } + + if (!token_name) { + token_length = strlen("UNKNOWN"); + token_name = estrndup("UNKNOWN", token_length); + token_found = 0; + } + + 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); + + 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'; + } + + if (!token_found) { + if (token_name) { + efree(token_name); + } + } + } + } else { + status->syntax_error_len = strlen("Syntax error, unexpected EOF"); + status->syntax_error = estrndup("Syntax error, unexpected EOF", status->syntax_error_len); + } + + 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[] = { - kkgotominor.kk132 = phvolt_ret_literal_zval(PHVOLT_T_TRUE, NULL, status->scanner_state); - kk_destructor(54,&kkmsp[0].minor); + { 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); } -// 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 void phql_wrapper_free(void *pointer){ + efree(pointer); } -// 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 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; } -// 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 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 { + 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 { + ZVAL_STRING(*error_msg, "Scanning error near to EOF", 1); + } + + if (error) { + efree(error); + } } -// 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 int phql_parse_phql(zval *result, zval *phql TSRMLS_DC) { + + zval *error_msg = NULL; + + ZVAL_NULL(result); + + 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; + } + + return SUCCESS; } -// 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 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; + } + } + } + + phql_parser = phql_Alloc(phql_wrapper_alloc); + + parser_status = emalloc(sizeof(phql_parser_status)); + state = emalloc(sizeof(phql_scanner_state)); + + 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; + + state->active_token = 0; + state->start = phql; + state->start_length = 0; + state->end = state->start; + + token.value = NULL; + token.len = 0; + + while (0 <= (scanner_status = phql_get_token(state, &token))) { + + /* 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; + + 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; + + 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; + } + + if (parser_status->status != PHQL_PARSING_OK) { + status = FAILURE; + break; + } + + 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; } -// 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); + + + + +#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; } -// 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); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#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; } -// 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); + + + + + + + + + + + + + + + + + +#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; } -// 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); + +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); + } -// 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); + +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(); } -// 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); + +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(); } -// 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); + +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); } -// 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); + +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(); } -// 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); + +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(); } -// 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); + +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(); } -// 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); + +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(); } -// 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); + +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(); } -// 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); + +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(); } -// 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); + +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(); } -// 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); + +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(); } -// 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_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(); } -// 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_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(); } -// 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_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(); } -// 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_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(); } -// 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_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(); } -// 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_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(); } -// 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_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(); } -// 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); + +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(); } -// 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_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(); } -// 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_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(); } -// 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_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(); } -// 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_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(); } -// 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_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(); } -// 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); + +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(); } -// 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); + +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(); } -// 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); + +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(); } -// 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_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(); } -// 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_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(); } -// 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_Mvc_Model_Criteria, getParams){ + + + RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); } -// 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); + +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(); } -// 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_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); } -// 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); + + + + + +#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; } -// 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_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(); } -// 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_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); + } -// 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_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); } -// 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_Mvc_Model_Relation, getFields){ + + + RETURN_MEMBER_QUICK(this_ptr, "_fields", 3492004987UL); } -// 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_Mvc_Model_Relation, getReferencedFields){ + + + RETURN_MEMBER_QUICK(this_ptr, "_referencedFields", 729137326UL); } -// 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_Mvc_Model_Relation, getOptions){ + + + RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); } -// 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); + +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; } -// 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_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; } -// 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_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; } -// 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_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; } -// 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_Mvc_Model_Relation, getIntermediateFields){ + + + RETURN_MEMBER_QUICK(this_ptr, "_intermediateFields", 1022734614UL); } -// 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_Mvc_Model_Relation, getIntermediateModel){ + + + RETURN_MEMBER_QUICK(this_ptr, "_intermediateModel", 312011824UL); } -// 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_Mvc_Model_Relation, getIntermediateReferencedFields){ + + + RETURN_MEMBER_QUICK(this_ptr, "_intermediateReferencedFields", 3351276297UL); } -// 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); + + + + + +#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; } -// 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_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); + } -// 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); + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getDI){ + + + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -// 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_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); + } -// 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_Mvc_Model_Manager, getEventsManager){ + + + RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); } -// 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_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(); } -// 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_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(); } -// 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_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; } -// 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_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); } -// 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_Mvc_Model_Manager, getLastInitialized){ + + + RETURN_MEMBER_QUICK(this_ptr, "_lastInitialized", 1491101038UL); } -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 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; + } + RETURN_CCTOR(cloned); + } + + 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); + } + 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 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" +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setModelSource){ - { + zval *model, *source, *entity_name; - smart_str error_str = {0}; + PHALCON_MM_GROW(); - char *token_name = NULL; - const phvolt_token_names *tokens = phvolt_tokens; - int token_len = 0; - int active_token = status->scanner_state->active_token; + 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(); +} - if (status->scanner_state->start_length) { +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getModelSource){ - if (active_token) { + zval *model, *entity_name, *sources, *source = NULL, *class_name; - do { - if (tokens->code == active_token) { - token_name = tokens->name; - token_len = tokens->len; - break; - } - ++tokens; - } while (tokens[0].code != 0); + 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); + } + } + + 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); +} - 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); - } +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setModelSchema){ - } else { + zval *model, *schema, *entity_name; - 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_MM_GROW(); - /* 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); - } - } + 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(); +} - /* 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); - } - } - } +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getModelSchema){ - smart_str_0(&error_str); + zval *model, *entity_name, *schemas, *schema; - if (error_str.len) { - status->syntax_error = error_str.c; - status->syntax_error_len = error_str.len; - } else { - status->syntax_error = NULL; - } + 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); + } } + + RETURN_MM_NULL(); +} - status->status = PHVOLT_PARSING_FAILED; +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setConnectionService){ -// 3094 "parser.c" - phvolt_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ -} + zval *model, *connection_service, *entity_name; -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 */ + 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(); } -/* 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 */ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setWriteConnectionService){ - /* (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; + zval *model, *connection_service, *entity_name; -#ifndef NDEBUG - if( kkTraceFILE ){ - fprintf(kkTraceFILE,"%sInput %s\n",kkTracePrompt,kkTokenName[kkmajor]); - } -#endif + PHALCON_MM_GROW(); - 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; + 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){ -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 } -}; + zval *model, *connection_service, *entity_name; -static void *phvolt_wrapper_alloc(size_t bytes){ - return emalloc(bytes); -} + PHALCON_MM_GROW(); -static void phvolt_wrapper_free(void *pointer){ - efree(pointer); + 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 void phvolt_parse_with_token(void* phvolt_parser, int opcode, int parsercode, phvolt_scanner_token *token, phvolt_parser_status *parser_status){ +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); + } + } + + 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); +} - phvolt_parser_token *pToken; +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getReadConnection){ - pToken = emalloc(sizeof(phvolt_parser_token)); - pToken->opcode = opcode; - pToken->token = token->value; - pToken->token_len = token->len; - pToken->free_flag = 1; + zval *model, *service = NULL, *connection_services; + zval *entity_name, *dependency_injector, *connection; - phvolt_(phvolt_parser, parsercode, pToken, parser_status); + PHALCON_MM_GROW(); - token->value = NULL; - token->len = 0; + 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); + } + } + + 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 void phvolt_create_error_msg(phvolt_parser_status *parser_status, char *message){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getReadConnectionService){ - unsigned int length = (128 + Z_STRLEN_P(parser_status->scanner_state->active_file)); - char *str = emalloc(sizeof(char) * length); + zval *model, *connection_services, *entity_name; + zval *connection; - 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_MM_GROW(); - parser_status->syntax_error = estrndup(str, strlen(str)); - efree(str); + 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); + } + } + + RETURN_MM_STRING("db", 1); } -static void phvolt_scanner_error_msg(phvolt_parser_status *parser_status, zval **error_msg TSRMLS_DC){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getWriteConnectionService){ - char *error, *error_part; - int length; - phvolt_scanner_state *state = parser_status->scanner_state; + zval *model, *connection_services, *entity_name; + zval *connection; - 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); + 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); } - } 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); + + RETURN_MM_STRING("db", 1); } -static int phvolt_parse_view(zval *result, zval *view_code, zval *template_path TSRMLS_DC){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, notifyEvent){ - zval *error_msg = NULL; + 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; - ZVAL_NULL(result); + PHALCON_MM_GROW(); - 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_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); + } + + } } - - 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_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); + } } - - 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) { - 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_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); + } } - marker++; } - - return 1; + + RETURN_CCTOR(status); } -static int phvolt_internal_parse_view(zval **result, zval *view_code, zval *template_path, zval **error_msg TSRMLS_DC) { +static PHP_METHOD(Phalcon_Mvc_Model_Manager, missingMethod){ - char *error; - phvolt_scanner_state *state; - phvolt_scanner_token token; - int scanner_status, status = SUCCESS; - phvolt_parser_status *parser_status = NULL; - void* phvolt_parser; + 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; - /** 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; - } + PHALCON_MM_GROW(); - if (!Z_STRLEN_P(view_code)) { - array_init(*result); - return SUCCESS; + 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); + } + + } } + + 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(); +} - /** Start the reentrant parser */ - phvolt_parser = phvolt_Alloc(phvolt_wrapper_alloc); - - parser_status = emalloc(sizeof(phvolt_parser_status)); - state = emalloc(sizeof(phvolt_scanner_state)); +static PHP_METHOD(Phalcon_Mvc_Model_Manager, addBehavior){ - parser_status->status = PHVOLT_PARSING_OK; - parser_status->scanner_state = state; - parser_status->ret = NULL; - parser_status->token = &token; - parser_status->syntax_error = NULL; + zval *model, *behavior, *entity_name, *behaviors; + zval *models_behaviors = 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; + PHALCON_MM_GROW(); - state->end = state->start; + 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(); +} - token.value = NULL; - token.len = 0; +static PHP_METHOD(Phalcon_Mvc_Model_Manager, keepSnapshots){ - while (0 <= (scanner_status = phvolt_get_token(state, &token))) { + zval *model, *keep_snapshots, *entity_name; - state->active_token = token.opcode; + PHALCON_MM_GROW(); - state->start_length = (Z_STRVAL_P(view_code) + Z_STRLEN_P(view_code) - state->start); + 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(); +} - switch (token.opcode) { +static PHP_METHOD(Phalcon_Mvc_Model_Manager, isKeepingSnapshots){ - case PHVOLT_T_IGNORE: - break; + zval *model, *keep_snapshots, *entity_name, *is_keeping; - 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, 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); + } + } + + RETURN_MM_FALSE; +} - 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_Mvc_Model_Manager, useDynamicUpdate){ - 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 *model, *dynamic_update, *entity_name; - 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_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(); +} - 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; +static PHP_METHOD(Phalcon_Mvc_Model_Manager, isUsingDynamicUpdate){ - 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; + zval *model, *dynamic_update, *entity_name, *is_using; - case PHVOLT_T_ELSEFOR: - phvolt_(phvolt_parser, PHVOLT_ELSEFOR, NULL, parser_status); - break; + PHALCON_MM_GROW(); - 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_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); + } + } + + RETURN_MM_FALSE; +} - case PHVOLT_T_ENDIF: - state->block_level--; - state->if_level--; - phvolt_(phvolt_parser, PHVOLT_ENDIF, NULL, parser_status); - break; +static PHP_METHOD(Phalcon_Mvc_Model_Manager, addHasOne){ - 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; ->>>>>>> 1.2.2 + 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; - case PHVOLT_T_IN: - phvolt_(phvolt_parser, PHVOLT_IN, NULL, parser_status); - break; + PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(1, 2, 1, &template_path, ¶ms, &must_clean); + phalcon_fetch_params(1, 4, 1, &model, &fields, &referenced_model, &referenced_fields, &options); - if (!must_clean) { - PHALCON_INIT_VAR(must_clean); - ZVAL_BOOL(must_clean, 0); + if (!options) { + PHALCON_INIT_VAR(options); } - if (PHALCON_IS_TRUE(must_clean)) { - phalcon_ob_clean(TSRMLS_C); + 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); } - PHALCON_INIT_VAR(compiler); - phalcon_call_method_key(compiler, this_ptr, "getcompiler", 3440133088UL); - phalcon_call_method_p1_key(NULL, compiler, "compile", template_path, 1074882030UL); + if (Z_TYPE_P(referenced_fields) == IS_ARRAY) { - PHALCON_INIT_VAR(compiled_template_path); - phalcon_call_method_key(compiled_template_path, compiler, "getcompiledtemplatepath", 652904091UL); + PHALCON_INIT_VAR(number_fields); + phalcon_fast_count(number_fields, fields TSRMLS_CC); - if (Z_TYPE_P(params) == IS_ARRAY) { + 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; + } + } - phalcon_is_iterable(params, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(type); + ZVAL_LONG(type, 1); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + 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_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + 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); - if (phalcon_set_symbol(key, value TSRMLS_CC) == FAILURE){ - return; - } + PHALCON_INIT_VAR(lower_alias); + phalcon_fast_strtolower(lower_alias, alias); + } else { + PHALCON_CPY_WRT(lower_alias, referenced_entity); + } - zend_hash_move_forward_ex(ah0, &hp0); - } + 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); } - if (phalcon_require(compiled_template_path TSRMLS_CC) == FAILURE) { - return; + 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); } - 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_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); } - PHALCON_MM_RESTORE(); + 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; + } + } + + 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_View_Engine_Volt, length){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, addHasMany){ - zval *item, *length = NULL; -======= - 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; + 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; - 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_MM_GROW(); - 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; ->>>>>>> 1.2.2 + 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; + } + } + + 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); +} - 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; +static PHP_METHOD(Phalcon_Mvc_Model_Manager, addHasManyToMany){ -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 0, &item); + 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); - PHALCON_INIT_VAR(length); - ZVAL_LONG(length, 0); - if (Z_TYPE_P(item) == IS_OBJECT) { - phalcon_fast_count(length, item TSRMLS_CC); + 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 { - 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_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; + } + } + + 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; } } - RETURN_CCTOR(length); + 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_View_Engine_Volt, isIncluded){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, existsBelongsTo){ - zval *needle, *haystack; + zval *model_name, *model_relation, *initialized; + zval *entity_name, *entity_relation, *key_relation; + zval *belongs_to; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &needle, &haystack); + phalcon_fetch_params(1, 2, 0, &model_name, &model_relation); - if (Z_TYPE_P(haystack) == IS_ARRAY) { - phalcon_call_func_p2(return_value, "in_array", needle, haystack); - RETURN_MM(); + 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); } - 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_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; } - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Invalid haystack"); - return; + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, convertEncoding){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, existsHasMany){ - zval *text, *from, *to; + zval *model_name, *model_relation, *initialized; + zval *entity_name, *entity_relation, *key_relation; + zval *has_many; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &text, &from, &to); + phalcon_fetch_params(1, 2, 0, &model_name, &model_relation); - if (PHALCON_IS_STRING(from, "latin1")) { - if (PHALCON_IS_STRING(to, "utf8")) { - phalcon_call_func_p1(return_value, "utf8_encode", text); - RETURN_MM(); - } - } + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); - if (PHALCON_IS_STRING(to, "latin1")) { - if (PHALCON_IS_STRING(from, "utf8")) { - phalcon_call_func_p1(return_value, "utf8_decode", text); - RETURN_MM(); - } - } + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); - 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(); + 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); } - 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_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; } - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Any of 'mbstring' or 'iconv' is required to perform the charset conversion"); - return; + RETURN_MM_FALSE; } -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; -======= - 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; +static PHP_METHOD(Phalcon_Mvc_Model_Manager, existsHasOne){ - case PHVOLT_T_CONTINUE: - phvolt_(phvolt_parser, PHVOLT_CONTINUE, NULL, parser_status); - break; ->>>>>>> 1.2.2 + zval *model_name, *model_relation, *initialized; + zval *entity_name, *entity_relation, *key_relation; + zval *has_one; - 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; + PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(1, 2, 1, &value, &start, &end); - - if (!end) { - PHALCON_INIT_VAR(end); - } - - if (Z_TYPE_P(value) == IS_OBJECT) { + phalcon_fetch_params(1, 2, 0, &model_name, &model_relation); - 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); - } + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); - PHALCON_INIT_VAR(position); - ZVAL_LONG(position, 0); - phalcon_call_method_key(NULL, value, "rewind", 1064078190UL); + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); - while (1) { + PHALCON_INIT_VAR(entity_relation); + phalcon_fast_strtolower(entity_relation, model_relation); - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, value, "valid", 574098517UL); - if (zend_is_true(r0)) { - } else { - break; - } + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, entity_name, "$", entity_relation); - 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); - } + if (!phalcon_array_isset(initialized, entity_name)) { + phalcon_call_method_p1_key(NULL, this_ptr, "load", model_name, 266329637UL); + } - RETURN_CTOR(slice); + 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; } - if (Z_TYPE_P(end) != IS_NULL) { - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, existsHasManyToMany){ + + zval *model_name, *model_relation, *initialized; + zval *entity_name, *entity_relation, *key_relation; + zval *has_many_to_many; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model_name, &model_relation); - PHALCON_INIT_VAR(range); - sub_function(range, end, start TSRMLS_CC); + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(length); - phalcon_add_function(length, range, one TSRMLS_CC); - } else { - PHALCON_INIT_NVAR(length); - } + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); - if (Z_TYPE_P(value) == IS_ARRAY) { - phalcon_call_func_p3(return_value, "array_slice", value, start, length); - RETURN_MM(); - } + PHALCON_INIT_VAR(entity_relation); + phalcon_fast_strtolower(entity_relation, model_relation); - 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(); + 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); } - if (Z_TYPE_P(length) != IS_NULL) { - phalcon_call_func_p3(return_value, "substr", value, start, length); - RETURN_MM(); + 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; } - phalcon_call_func_p2(return_value, "substr", value, start); - RETURN_MM(); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, sort){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getRelationByAlias){ - zval *value; + zval *model_name, *alias, *aliases, *key_alias; + zval *key_lower, *relation; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &value); + phalcon_fetch_params(1, 2, 0, &model_name, &alias); - Z_SET_ISREF_P(value); - phalcon_call_func_p1_noret("asort", value); - Z_UNSET_ISREF_P(value); - RETURN_CCTOR(value); + 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_INIT_VAR(key_alias); + PHALCON_CONCAT_VSV(key_alias, model_name, "$", alias); + + 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_FALSE; } -======= - 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; - } +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getRelationRecords){ - if (parser_status->status != PHVOLT_PARSING_OK) { - status = FAILURE; - break; - } + 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; - state->end = state->start; - } + PHALCON_MM_GROW(); - 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); - } + phalcon_fetch_params(1, 3, 1, &relation, &method, &record, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } else { + PHALCON_SEPARATE_PARAM(parameters); } - - 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); + + PHALCON_INIT_VAR(pre_conditions); + + 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); } - efree(parser_status->syntax_error); + } + } else { + if (Z_TYPE_P(parameters) == IS_STRING) { + PHALCON_CPY_WRT(pre_conditions, parameters); } } - - 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); - } + + 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); } - - efree(parser_status); - efree(state); - - return status; -} - - - - -#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){ ->>>>>>> 1.2.2 - - zval *options; - -<<<<<<< HEAD - -======= - 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); + PHALCON_INIT_VAR(referenced_model); + phalcon_call_method_key(referenced_model, relation, "getreferencedmodel", 478093161UL); + + PHALCON_INIT_VAR(is_through); + phalcon_call_method_key(is_through, relation, "isthrough", 2540564770UL); + if (zend_is_true(is_through)) { + + PHALCON_INIT_VAR(conditions); + array_init(conditions); + + PHALCON_INIT_VAR(intermediate_model); + phalcon_call_method_key(intermediate_model, relation, "getintermediatemodel", 851527441UL); + + PHALCON_INIT_VAR(intermediate_fields); + phalcon_call_method_key(intermediate_fields, relation, "getintermediatefields", 1646880791UL); + + 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_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_INIT_VAR(join_conditions); + array_init(join_conditions); + + 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_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_INIT_VAR(joined_join_conditions); + phalcon_fast_join_str(joined_join_conditions, SL(" AND "), join_conditions TSRMLS_CC); -} - -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, getOptions){ ->>>>>>> 1.2.2 - -#ifdef HAVE_CONFIG_H -#endif - -<<<<<<< HEAD - - - - - - -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 (PHALCON_IS_NOT_EMPTY(pre_conditions)) { + phalcon_array_append(&conditions, pre_conditions, PH_SEPARATE); + } - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } + PHALCON_INIT_VAR(joined_conditions); + phalcon_fast_join_str(joined_conditions, SL(" AND "), conditions 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(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); - 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); + PHALCON_INIT_VAR(query); + phalcon_call_method_key(query, builder, "getquery", 4154457883UL); - 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_call_method_key(return_value, query, "execute", 3117639032UL); + RETURN_MM(); } - 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); + 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_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL 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); - 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(referenced_field); + phalcon_call_method_key(referenced_field, relation, "getreferencedfields", 2208451439UL); - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + 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_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "add", route_pattern, 2090071694UL); + phalcon_is_iterable(fields, &ah0, &hp0, 0, 0); - 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); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - 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_GET_HKEY(ref_position, ah0, hp0); + PHALCON_GET_HVALUE(field); - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + PHALCON_INIT_NVAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addget", route_pattern, 522210158UL); + PHALCON_OBS_NVAR(referenced_field); + phalcon_array_fetch(&referenced_field, referenced_fields, ref_position, PH_NOISY); - 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); + 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); - 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); + zend_hash_move_forward_ex(ah0, &hp0); + } - 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(dependency_injector); + phalcon_call_method_key(dependency_injector, record, "getdi", 4287060818UL); - 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); + PHALCON_INIT_NVAR(joined_conditions); + phalcon_fast_join_str(joined_conditions, SL(" AND "), conditions 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(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_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + PHALCON_INIT_VAR(arguments); + array_init_size(arguments, 1); + phalcon_array_append(&arguments, find_arguments, PH_SEPARATE); - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addput", route_pattern, 522551015UL); + if (Z_TYPE_P(method) == IS_NULL) { + PHALCON_INIT_VAR(type); + phalcon_call_method_key(type, relation, "gettype", 4294422375UL); - 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); + switch (phalcon_get_intval(type)) { - 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); + case 0: + PHALCON_INIT_VAR(retrieve_method); + ZVAL_STRING(retrieve_method, "findFirst", 1); + break; - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + case 1: + PHALCON_INIT_NVAR(retrieve_method); + ZVAL_STRING(retrieve_method, "findFirst", 1); + break; - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addpatch", route_pattern, 2098765086UL); + case 2: + PHALCON_INIT_NVAR(retrieve_method); + ZVAL_STRING(retrieve_method, "find", 1); + break; - 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); + } + } else { + PHALCON_CPY_WRT(retrieve_method, method); + } - 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(reusable); + phalcon_call_method_key(reusable, relation, "isreusable", 3326378900UL); + if (zend_is_true(reusable)) { - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + PHALCON_INIT_VAR(unique_key); + phalcon_unique_key(unique_key, referenced_model, arguments TSRMLS_CC); - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addhead", route_pattern, 54234560UL); + 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(route_id); - phalcon_call_method_key(route_id, route, "getrouteid", 2741905729UL); - phalcon_update_property_array(this_ptr, SL("_handlers"), route_id, handler TSRMLS_CC); + PHALCON_INIT_VAR(referenced_entity); + phalcon_call_method_p1_key(referenced_entity, this_ptr, "load", referenced_model, 266329637UL); - RETURN_CCTOR(route); + 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); + } + + RETURN_CCTOR(records); } -static PHP_METHOD(Phalcon_Mvc_Micro, delete){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getReusableRecords){ - zval *route_pattern, *handler, *router, *route; - zval *route_id; + zval *model_name, *key, *reusable, *records; 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_fetch_params(1, 2, 0, &model_name, &key); - 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); + 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); + } - RETURN_CCTOR(route); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Mvc_Micro, options){ - - zval *route_pattern, *handler, *router, *route; - zval *route_id; +static PHP_METHOD(Phalcon_Mvc_Model_Manager, setReusableRecords){ - PHALCON_MM_GROW(); + zval *model_name, *key, *records; - 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_fetch_params(0, 3, 0, &model_name, &key, &records); - 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); + phalcon_update_property_array(this_ptr, SL("_reusable"), key, records TSRMLS_CC); - RETURN_CCTOR(route); } -static PHP_METHOD(Phalcon_Mvc_Micro, mount){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, clearReusableObjects){ - 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; -======= - RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); + + phalcon_update_property_null(this_ptr, SL("_reusable") TSRMLS_CC); + } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, getCompiler){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getBelongsToRecords){ - zval *compiler = NULL, *view, *options, *dependency_injector; + 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_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_fetch_params(1, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); - PHALCON_OBS_VAR(view); - phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + 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_OBS_VAR(dependency_injector); - phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); - 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); + PHALCON_INIT_VAR(entity_relation); + phalcon_fast_strtolower(entity_relation, model_relation); - if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { - phalcon_call_method_p1_key(NULL, compiler, "setdi", dependency_injector, 461718238UL); + 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 (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_call_method_p1_key(NULL, compiler, "setoptions", options, 1759822653UL); - } + PHALCON_OBS_VAR(relations); + phalcon_array_fetch(&relations, belongs_to, key_relation, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_compiler"), compiler, 96166463UL TSRMLS_CC); + 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_CCTOR(compiler); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, render){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasManyRecords){ - zval *template_path, *params, *must_clean = NULL, *compiler; - zval *compiled_template_path, *value = NULL, *key = NULL, *contents; - zval *view; ->>>>>>> 1.2.2 - 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(); -<<<<<<< HEAD - 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); - } - - 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; - } - - 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); - } - - 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); - } - -======= - 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_fetch_params(1, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); - PHALCON_INIT_VAR(compiled_template_path); - phalcon_call_method_key(compiled_template_path, compiler, "getcompiledtemplatepath", 652904091UL); + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } - if (Z_TYPE_P(params) == IS_ARRAY) { + 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_is_iterable(params, &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_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + 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; + } - if (phalcon_set_symbol(key, value TSRMLS_CC) == FAILURE){ - return; - } + PHALCON_OBS_VAR(relations); + phalcon_array_fetch(&relations, has_many, key_relation, PH_NOISY); ->>>>>>> 1.2.2 - zend_hash_move_forward_ex(ah0, &hp0); - } + 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(); } -<<<<<<< HEAD - 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(); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Micro, getRouter){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasOneRecords){ - zval *router = NULL, *service_name, *remove; + 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_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_fetch_params(1, 4, 1, &method, &model_name, &model_relation, &record, ¶meters); - PHALCON_INIT_NVAR(router); - phalcon_call_method_p1_key(router, this_ptr, "getsharedservice", service_name, 3519183981UL); + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } - phalcon_call_method_key(NULL, router, "clear", 4138278668UL); + 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(remove); - ZVAL_BOOL(remove, 1); + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); - phalcon_call_method_p1_key(NULL, router, "removeextraslashes", remove, 2128043402UL); + PHALCON_INIT_VAR(entity_relation); + phalcon_fast_strtolower(entity_relation, model_relation); - phalcon_update_property_this_quick(this_ptr, SL("_router"), router, 2063827077UL TSRMLS_CC); + 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_CCTOR(router); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Mvc_Micro, setService){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getBelongsTo){ - zval *service_name, *definition, *shared = NULL, *dependency_injector = NULL; + zval *model, *belongs_to_single, *lower_name; + zval *relations; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &service_name, &definition, &shared); - - if (!shared) { - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 0); - } + phalcon_fetch_params(1, 1, 0, &model); - 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_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_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + 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); + } } - phalcon_call_method_p3_key(return_value, dependency_injector, "set", service_name, definition, shared, 2090720177UL); - RETURN_MM(); + RETURN_MM_EMPTY_ARRAY(); } -static PHP_METHOD(Phalcon_Mvc_Micro, hasService){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasMany){ - zval *service_name, *dependency_injector = NULL; + zval *model, *has_many_single, *lower_name, *relations; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &service_name); + phalcon_fetch_params(1, 1, 0, &model); - 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_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_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + 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); + } } - phalcon_call_method_p1_key(return_value, dependency_injector, "has", service_name, 2090320481UL); - RETURN_MM(); + RETURN_MM_EMPTY_ARRAY(); } -static PHP_METHOD(Phalcon_Mvc_Micro, getService){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasOne){ - zval *service_name, *dependency_injector = NULL; + zval *model, *has_one_single, *lower_name, *relations; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &service_name); + phalcon_fetch_params(1, 1, 0, &model); - 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_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_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + 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); + } } - phalcon_call_method_p1_key(return_value, dependency_injector, "get", service_name, 2090288933UL); - RETURN_MM(); + RETURN_MM_EMPTY_ARRAY(); } -static PHP_METHOD(Phalcon_Mvc_Micro, getSharedService){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasManyToMany){ - zval *service_name, *dependency_injector = NULL; + zval *model, *has_many_to_many_single, *lower_name; + zval *relations; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &service_name); + phalcon_fetch_params(1, 1, 0, &model); - 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_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_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + 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); + } } - phalcon_call_method_p1_key(return_value, dependency_injector, "getshared", service_name, 1727570332UL); + RETURN_MM_EMPTY_ARRAY(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getHasOneAndHasMany){ + + zval *model, *has_one, *has_many; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); + + PHALCON_INIT_VAR(has_one); + phalcon_call_method_p1_key(has_one, this_ptr, "gethasone", model, 153625411UL); + + 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_Micro, handle){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getRelations){ - 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; + 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_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); + phalcon_fetch_params(1, 1, 0, &model_name); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_VAR(entity_name); + phalcon_fast_strtolower(entity_name, model_name); - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "micro:beforeExecuteRoute", 1); + PHALCON_INIT_VAR(all_relations); + array_init(all_relations); - 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); - } - } + 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(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_OBS_VAR(relations); + phalcon_array_fetch(&relations, belongs_to, entity_name, PH_NOISY); - phalcon_is_iterable(before_handlers, &ah0, &hp0, 0, 0); + phalcon_is_iterable(relations, &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_GET_HVALUE(relation); - 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); - } + phalcon_array_append(&all_relations, relation, PH_SEPARATE); zend_hash_move_forward_ex(ah0, &hp0); } } + } - 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(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)) { - 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_OBS_NVAR(relations); + phalcon_array_fetch(&relations, has_many, entity_name, PH_NOISY); - phalcon_is_iterable(after_handlers, &ah1, &hp1, 0, 0); + phalcon_is_iterable(relations, &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_GET_HVALUE(relation); - 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_array_append(&all_relations, relation, PH_SEPARATE); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, after, "call", this_ptr, 255165473UL); + zend_hash_move_forward_ex(ah1, &hp1); + } - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); + } + } - if (zend_is_true(stopped)) { - break; - } + 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)) { - 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_OBS_NVAR(relations); + phalcon_array_fetch(&relations, has_one, entity_name, PH_NOISY); - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC(status, after); + phalcon_is_iterable(relations, &ah2, &hp2, 0, 0); - zend_hash_move_forward_ex(ah1, &hp1); - } + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - } - } 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_GET_HVALUE(relation); - PHALCON_INIT_NVAR(event_name); - ZVAL_STRING(event_name, "micro:beforeNotFound", 1); + phalcon_array_append(&all_relations, relation, PH_SEPARATE); - 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; + zend_hash_move_forward_ex(ah2, &hp2); } - } - 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); - } + RETURN_CTOR(all_relations); +} + +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; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &first, &second); - 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_VAR(first_name); + phalcon_fast_strtolower(first_name, first); - PHALCON_INIT_NVAR(params); + PHALCON_INIT_VAR(second_name); + phalcon_fast_strtolower(second_name, second); - phalcon_is_iterable(finish_handlers, &ah2, &hp2, 0, 0); + PHALCON_INIT_VAR(key_relation); + PHALCON_CONCAT_VSV(key_relation, first_name, "$", second_name); - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + 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_GET_HVALUE(finish); + 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); + } + } - if (Z_TYPE_P(finish) == IS_OBJECT) { + 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); + } + } - PHALCON_INIT_NVAR(is_middleware); - phalcon_instance_of(is_middleware, finish, phalcon_mvc_micro_middlewareinterface_ce TSRMLS_CC); - if (PHALCON_IS_TRUE(is_middleware)) { + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, createQuery){ + + zval *phql, *dependency_injector, *query; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &phql); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, finish, "call", this_ptr, 255165473UL); + 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_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); + PHALCON_INIT_VAR(query); + object_init_ex(query, phalcon_mvc_model_query_ce); + phalcon_call_method_p1_key(NULL, query, "__construct", phql, 1107214344UL); - if (zend_is_true(stopped)) { - break; - } + phalcon_call_method_p1_key(NULL, query, "setdi", dependency_injector, 461718238UL); + phalcon_update_property_this_quick(this_ptr, SL("_lastQuery"), query, 148087694UL TSRMLS_CC); - 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; - } + 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 (Z_TYPE_P(params) == IS_NULL) { - PHALCON_INIT_NVAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, this_ptr, PH_SEPARATE); - } + if (!placeholders) { + PHALCON_INIT_VAR(placeholders); + } - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC_ARRAY(status, finish, 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; + } - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); + PHALCON_INIT_VAR(query); + object_init_ex(query, phalcon_mvc_model_query_ce); + phalcon_call_method_p1_key(NULL, query, "__construct", phql, 1107214344UL); - if (zend_is_true(stopped)) { - break; - } + phalcon_call_method_p1_key(NULL, query, "setdi", dependency_injector, 461718238UL); + phalcon_update_property_this_quick(this_ptr, SL("_lastQuery"), query, 148087694UL TSRMLS_CC); - zend_hash_move_forward_ex(ah2, &hp2); - } + 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_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, ¶ms); + if (!params) { + PHALCON_INIT_VAR(params); } - 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); - } + 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; } - RETURN_CCTOR(returned_value); + 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(); } -static PHP_METHOD(Phalcon_Mvc_Micro, stop){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getLastQuery){ - phalcon_update_property_bool(this_ptr, SL("_stopped"), 1 TSRMLS_CC); + RETURN_MEMBER_QUICK(this_ptr, "_lastQuery", 148087694UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Manager, registerNamespaceAlias){ + + zval *alias, *namespace; + + phalcon_fetch_params(0, 2, 0, &alias, &namespace); + + 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(namespace) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "The namespace must be a string"); + return; + } + + phalcon_update_property_array(this_ptr, SL("_namespaceAliases"), alias, namespace TSRMLS_CC); } -static PHP_METHOD(Phalcon_Mvc_Micro, setActiveHandler){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getNamespaceAlias){ - zval *active_handler; + zval *alias, *namespace_aliases, *namespace; + zval *exception_message; - phalcon_fetch_params(0, 1, 0, &active_handler); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &alias); - phalcon_update_property_this_quick(this_ptr, SL("_activeHandler"), active_handler, 2923197278UL TSRMLS_CC); + 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); + } + 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_Micro, getActiveHandler){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, getNamespaceAliases){ - RETURN_MEMBER_QUICK(this_ptr, "_activeHandler", 2923197278UL); + RETURN_MEMBER_QUICK(this_ptr, "_namespaceAliases", 3928808595UL); } -static PHP_METHOD(Phalcon_Mvc_Micro, getReturnedValue){ +static PHP_METHOD(Phalcon_Mvc_Model_Manager, __destruct){ - RETURN_MEMBER_QUICK(this_ptr, "_returnedValue", 4143876906UL); + PHALCON_MM_GROW(); + + phalcon_orm_destroy_cache(TSRMLS_C); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Micro, offsetUnset){ - zval *alias; +#ifdef HAVE_CONFIG_H +#endif - phalcon_fetch_params(0, 1, 0, &alias); - - RETURN_CCTORW(alias); + + +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; } -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(); + + + + +#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_Micro, after){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, __construct){ - zval *handler; + zval *phql = NULL, *dependency_injector = NULL; - phalcon_fetch_params(0, 1, 0, &handler); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, &phql, &dependency_injector); - phalcon_update_property_array_append(this_ptr, SL("_afterHandlers"), handler TSRMLS_CC); - RETURN_THISW(); + 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_Micro, finish){ -======= - if (phalcon_require(compiled_template_path TSRMLS_CC) == FAILURE) { +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; } - 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_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_View_Engine_Volt, length){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, getDI){ - zval *item, *length = NULL; + + 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, &item); + phalcon_fetch_params(1, 1, 0, &expr); - PHALCON_INIT_VAR(length); - ZVAL_LONG(length, 0); - if (Z_TYPE_P(item) == IS_OBJECT) { - phalcon_fast_count(length, item TSRMLS_CC); + 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 { - if (Z_TYPE_P(item) == IS_ARRAY) { - PHALCON_INIT_NVAR(length); - phalcon_fast_count(length, item TSRMLS_CC); + 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); + } + + 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_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 { - 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); + 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_INIT_NVAR(length); - phalcon_fast_strlen(length, item); + 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; } + } else { + PHALCON_CPY_WRT(real_column_name, column_name); } } - RETURN_CCTOR(length); + 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_View_Engine_Volt, isIncluded){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getCallArgument){ - zval *needle, *haystack; + zval *argument, *argument_type; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &needle, &haystack); + phalcon_fetch_params(1, 1, 0, &argument); - 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); + 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_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Invalid haystack"); - return; + phalcon_call_method_p1_key(return_value, this_ptr, "_getexpression", argument, 2816780276UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, convertEncoding){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getFunctionCall){ - zval *text, *from, *to; + 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, 3, 0, &text, &from, &to); + phalcon_fetch_params(1, 1, 0, &expr); - if (PHALCON_IS_STRING(from, "latin1")) { - if (PHALCON_IS_STRING(to, "utf8")) { - phalcon_call_func_p1(return_value, "utf8_encode", text); - RETURN_MM(); - } - } + 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)) { - if (PHALCON_IS_STRING(to, "latin1")) { - if (PHALCON_IS_STRING(from, "utf8")) { - phalcon_call_func_p1(return_value, "utf8_decode", text); - RETURN_MM(); - } - } + PHALCON_OBS_VAR(arguments); + phalcon_array_fetch_quick_string(&arguments, expr, SS("arguments"), 3751272283UL, PH_NOISY); + if (phalcon_array_isset_long(arguments, 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(); - } + PHALCON_INIT_VAR(function_args); + array_init(function_args); - 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_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); + } + + } 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_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); } - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Any of 'mbstring' or 'iconv' is required to perform the charset conversion"); - return; + RETURN_CTOR(function_call); } -static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, slice){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getExpression){ - zval *value, *start, *end = NULL, *slice, *length = NULL, *position; - zval *current = NULL, *one, *range; - zval *r0 = NULL; + 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, 2, 1, &value, &start, &end); + phalcon_fetch_params(1, 1, 1, &expr, "ing); - if (!end) { - PHALCON_INIT_VAR(end); + if (!quoting) { + PHALCON_INIT_VAR(quoting); + ZVAL_BOOL(quoting, 1); } - if (Z_TYPE_P(value) == IS_OBJECT) { + if (phalcon_array_isset_quick_string(expr, SS("type"), 276192743UL)) { - 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); + 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); } - PHALCON_INIT_VAR(position); - ZVAL_LONG(position, 0); - phalcon_call_method_key(NULL, value, "rewind", 1064078190UL); + 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); - while (1) { + PHALCON_INIT_VAR(right); + phalcon_call_method_p2_key(right, this_ptr, "_getexpression", expr_right, temp_not_quoting, 2816780276UL); + } - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, value, "valid", 574098517UL); - if (zend_is_true(r0)) { - } else { + 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; - } - 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); - } + 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; - RETURN_CTOR(slice); - } + 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; - if (Z_TYPE_P(end) != IS_NULL) { - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); + 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; - PHALCON_INIT_VAR(range); - sub_function(range, end, start TSRMLS_CC); + 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_NVAR(length); - phalcon_add_function(length, range, one TSRMLS_CC); - } else { - PHALCON_INIT_NVAR(length); - } + 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 (Z_TYPE_P(value) == IS_ARRAY) { - phalcon_call_func_p3(return_value, "array_slice", value, start, length); - RETURN_MM(); - } + 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; - 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(); - } + 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 (Z_TYPE_P(length) != IS_NULL) { - phalcon_call_func_p3(return_value, "substr", value, start, length); - RETURN_MM(); - } + case 355: + PHALCON_INIT_NVAR(expr_return); + phalcon_call_method_p1_key(expr_return, this_ptr, "_getqualified", expr, 3068781464UL); + break; - 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); + case 359: + PHALCON_INIT_NVAR(expr_return); + phalcon_call_method_p1_key(expr_return, this_ptr, "_getaliased", expr, 2254100183UL); + break; - Z_SET_ISREF_P(value); - phalcon_call_func_p1_noret("asort", value); - Z_UNSET_ISREF_P(value); - RETURN_CCTOR(value); -} - - - - - -#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); + 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; - if (!dependency_injector) { - PHALCON_INIT_VAR(dependency_injector); - } + 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 (Z_TYPE_P(dependency_injector) == IS_OBJECT) { - phalcon_call_method_p1_key(NULL, this_ptr, "setdi", dependency_injector, 461718238UL); - } + 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_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); + 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 (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_application_exception_ce, "The dependency injector must be an object"); - return; - } + 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; - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "application", 1); + 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_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); - } + 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_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + 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; - 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); + 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; - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + 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_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "add", route_pattern, 2090071694UL); + 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_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); + 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_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); + 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; - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + 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; - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addget", route_pattern, 522210158UL); + 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; - 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); + 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; - 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); + 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_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + 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; - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addpost", route_pattern, 64101428UL); + 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; - 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); + 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; - 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); + 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; - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + 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; - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addput", route_pattern, 522551015UL); + case 358: + PHALCON_OBS_NVAR(value); + phalcon_array_fetch_quick_string(&value, expr, SS("name"), 268211462UL, PH_NOISY); - 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); + 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; - 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); + case 350: + PHALCON_INIT_NVAR(expr_return); + phalcon_call_method_p1_key(expr_return, this_ptr, "_getfunctioncall", expr, 410399654UL); + break; - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + default: + PHALCON_INIT_VAR(expression_message); + PHALCON_CONCAT_SV(expression_message, "Unknown expression type ", expr_type); - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addpatch", route_pattern, 2098765086UL); + 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_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); + phalcon_throw_exception(expression TSRMLS_CC); + return; - 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); + RETURN_CCTOR(expr_return); + } - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addhead", route_pattern, 54234560UL); + if (phalcon_array_isset_quick_string(expr, SS("domain"), 542597917UL)) { + phalcon_call_method_p1_key(return_value, this_ptr, "_getqualified", expr, 3068781464UL); + RETURN_MM(); + } - 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); + if (phalcon_array_isset_long(expr, 0)) { - 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(list_items); + array_init(list_items); - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + phalcon_is_iterable(expr, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "adddelete", route_pattern, 2369167137UL); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - 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); + PHALCON_GET_HVALUE(expr_list_item); - 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_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); - PHALCON_INIT_VAR(router); - phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_INIT_VAR(route); - phalcon_call_method_p1_key(route, router, "addoptions", route_pattern, 3163448186UL); + 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); - 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_MM(); + } - RETURN_CCTOR(route); + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Unknown expression"); + return; } -static PHP_METHOD(Phalcon_Mvc_Micro, mount){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getSelectColumn){ - 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; + 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, &collection); + phalcon_fetch_params(1, 1, 0, &column); - if (Z_TYPE_P(collection) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "The collection is not valid"); + 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(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(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); + } + + RETURN_CTOR(sql_columns); } - 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"); + if (!phalcon_array_isset_quick_string(column, SS("column"), 3545634419UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); return; } - if (Z_TYPE_P(handlers) == IS_ARRAY) { + if (PHALCON_IS_LONG(column_type, 353)) { - 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); + PHALCON_OBS_VAR(sql_aliases); + phalcon_read_property_this_quick(&sql_aliases, this_ptr, SL("_sqlAliases"), 3407085878UL, PH_NOISY_CC); - } else { - PHALCON_CPY_WRT(lazy_handler, main_handler); + 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_INIT_VAR(prefix); - phalcon_call_method_key(prefix, collection, "getprefix", 2543805107UL); + PHALCON_OBS_VAR(source); + phalcon_array_fetch(&source, sql_aliases, column_domain, PH_NOISY); + PHALCON_CPY_WRT(sql_column_alias, source); - phalcon_is_iterable(handlers, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(sql_aliases_models); + phalcon_read_property_this_quick(&sql_aliases_models, this_ptr, SL("_sqlAliasesModels"), 848643194UL, PH_NOISY_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch(&model_name, sql_aliases_models, column_domain, PH_NOISY); - PHALCON_GET_HVALUE(handler); + PHALCON_OBS_VAR(sql_models_aliases); + phalcon_read_property_this_quick(&sql_models_aliases, this_ptr, SL("_sqlModelsAliases"), 1781491322UL, PH_NOISY_CC); - if (Z_TYPE_P(handler) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_micro_exception_ce, "One of the registered handlers is invalid"); - return; - } + PHALCON_OBS_VAR(best_alias); + phalcon_array_fetch(&best_alias, sql_models_aliases, model_name, PH_NOISY); - PHALCON_OBS_NVAR(methods); - phalcon_array_fetch_long(&methods, handler, 0, 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); + } - PHALCON_OBS_NVAR(pattern); - phalcon_array_fetch_long(&pattern, handler, 1, PH_NOISY); + 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); - PHALCON_OBS_NVAR(sub_handler); - phalcon_array_fetch_long(&sub_handler, handler, 2, PH_NOISY); + RETURN_CTOR(sql_columns); + } - 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); - } + if (PHALCON_IS_LONG(column_type, 354)) { - 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); - } + PHALCON_INIT_NVAR(sql_column); + array_init_size(sql_column, 1); + add_assoc_stringl_ex(sql_column, SS("type"), SL("scalar"), 1); - zend_hash_move_forward_ex(ah0, &hp0); + 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); } - } + 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_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, notFound){ ->>>>>>> 1.2.2 - - zval *handler; - - phalcon_fetch_params(0, 1, 0, &handler); + RETURN_CTOR(sql_columns); + } -<<<<<<< HEAD - 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); + 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); + } + + RETURN_CCTOR(source); + } + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); + return; +} -#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); +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getJoin){ - 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); + zval *manager, *join, *qualified, *qualified_type; + zval *model_name, *model, *source, *schema, *data; - zend_class_implements(phalcon_mvc_router_route_ce TSRMLS_CC, 1, phalcon_mvc_router_routeinterface_ce); + PHALCON_MM_GROW(); - return SUCCESS; + 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); + } + } + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); + return; } -static PHP_METHOD(Phalcon_Mvc_Router_Route, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getJoinType){ - zval *pattern, *paths = NULL, *http_methods = NULL, *unique_id = NULL; - zval *route_id = NULL, *one, *next_id; + zval *join, *type, *join_type = NULL, *phql, *exception_message; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); + phalcon_fetch_params(1, 1, 0, &join); - if (!paths) { - PHALCON_INIT_VAR(paths); + if (!phalcon_array_isset_quick_string(join, SS("type"), 276192743UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); + return; } - if (!http_methods) { - PHALCON_INIT_VAR(http_methods); - } + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, join, SS("type"), 276192743UL, PH_NOISY); - phalcon_call_method_p2_key(NULL, this_ptr, "reconfigure", pattern, paths, 18237790UL); + switch (phalcon_get_intval(type)) { - phalcon_update_property_this_quick(this_ptr, SL("_methods"), http_methods, 960170392UL TSRMLS_CC); + case 360: + PHALCON_INIT_VAR(join_type); + ZVAL_STRING(join_type, "INNER", 1); + break; - 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); - } + case 361: + PHALCON_INIT_NVAR(join_type); + ZVAL_STRING(join_type, "LEFT", 1); + break; - PHALCON_CPY_WRT(route_id, unique_id); - phalcon_update_property_this_quick(this_ptr, SL("_id"), route_id, 2090005265UL TSRMLS_CC); + case 362: + PHALCON_INIT_NVAR(join_type); + ZVAL_STRING(join_type, "RIGHT", 1); + break; - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); + case 363: + PHALCON_INIT_NVAR(join_type); + ZVAL_STRING(join_type, "CROSS", 1); + break; - 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); + case 364: + PHALCON_INIT_NVAR(join_type); + ZVAL_STRING(join_type, "FULL OUTER", 1); + break; - PHALCON_MM_RESTORE(); + 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_Router_Route, compilePattern){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getSingleJoin){ - zval *pattern, *compiled_pattern = NULL, *id_pattern; - zval *wildcard = NULL, *pattern_copy = NULL, *params_pattern; - zval *int_pattern; + 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, 1, 0, &pattern); + phalcon_fetch_params(1, 5, 0, &join_type, &join_source, &model_alias, &join_alias, &relation); - PHALCON_CPY_WRT(compiled_pattern, pattern); + PHALCON_INIT_VAR(fields); + phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - if (phalcon_memnstr_str(pattern, SL(":"))) { + 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(id_pattern); - ZVAL_STRING(id_pattern, "/([a-zA-Z0-9\\_\\-]+)", 1); + PHALCON_INIT_VAR(left_expr); + phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); - 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(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(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); - } + PHALCON_INIT_VAR(right_expr); + phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); - 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(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_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); - } + 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); - if (phalcon_memnstr_str(pattern, SL("/:namespace"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:namespace", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); + phalcon_is_iterable(fields, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (phalcon_memnstr_str(pattern, SL("/:action"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:action", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); + PHALCON_GET_HKEY(position, ah0, hp0); + PHALCON_GET_HVALUE(field); - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); - } + 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_memnstr_str(pattern, SL("/:params"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:params", 1); + 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_INIT_VAR(params_pattern); - ZVAL_STRING(params_pattern, "(/.*)*", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); + PHALCON_OBS_NVAR(referenced_field); + phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, params_pattern, pattern_copy); + 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); } - 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_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_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, int_pattern, pattern_copy); -======= - phalcon_update_property_this_quick(this_ptr, SL("_notFoundHandler"), handler, 2638317359UL TSRMLS_CC); - RETURN_THISW(); + RETURN_CTOR(sql_joins); } -static PHP_METHOD(Phalcon_Mvc_Micro, getRouter){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getMultiJoin){ - zval *router = NULL, *service_name, *remove; + 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_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_fetch_params(1, 5, 0, &join_type, &join_source, &model_alias, &join_alias, &relation); - PHALCON_INIT_NVAR(router); - phalcon_call_method_p1_key(router, this_ptr, "getsharedservice", service_name, 3519183981UL); + PHALCON_INIT_VAR(sql_joins); + array_init(sql_joins); - phalcon_call_method_key(NULL, router, "clear", 4138278668UL); + PHALCON_INIT_VAR(fields); + phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 1); + PHALCON_INIT_VAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - phalcon_call_method_p1_key(NULL, router, "removeextraslashes", remove, 2128043402UL); + PHALCON_INIT_VAR(intermediate_model_name); + phalcon_call_method_key(intermediate_model_name, relation, "getintermediatemodel", 851527441UL); - phalcon_update_property_this_quick(this_ptr, SL("_router"), router, 2063827077UL TSRMLS_CC); - } + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_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); + PHALCON_INIT_VAR(intermediate_model); + phalcon_call_method_p1_key(intermediate_model, manager, "load", intermediate_model_name, 266329637UL); - if (!shared) { - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 0); - } + PHALCON_INIT_VAR(intermediate_source); + phalcon_call_method_key(intermediate_source, intermediate_model, "getsource", 2025234358UL); - 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_INIT_VAR(intermediate_schema); + phalcon_call_method_key(intermediate_schema, intermediate_model, "getschema", 1539736246UL); - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } + 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_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_update_property_array(this_ptr, SL("_sqlAliases"), intermediate_model_name, intermediate_source 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); - object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); - phalcon_call_method_key(NULL, dependency_injector, "__construct", 1107214344UL); + phalcon_update_property_array(this_ptr, SL("_sqlAliasesModelsInstances"), intermediate_model_name, intermediate_model TSRMLS_CC); - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } + PHALCON_INIT_VAR(intermediate_fields); + phalcon_call_method_key(intermediate_fields, relation, "getintermediatefields", 1646880791UL); - 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_INIT_VAR(intermediate_referenced_fields); + phalcon_call_method_key(intermediate_referenced_fields, relation, "getintermediatereferencedfields", 3001626474UL); - 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_INIT_VAR(referenced_model_name); + phalcon_call_method_key(referenced_model_name, relation, "getreferencedmodel", 478093161UL); + if (Z_TYPE_P(fields) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } + phalcon_is_iterable(fields, &ah0, &hp0, 0, 0); - 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); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == 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_INIT_NVAR(dependency_injector); - object_init_ex(dependency_injector, phalcon_di_factorydefault_ce); - phalcon_call_method_key(NULL, dependency_injector, "__construct", 1107214344UL); + PHALCON_GET_HKEY(position, ah0, hp0); + PHALCON_GET_HVALUE(field); - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - } + 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_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); + 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 (!uri) { - PHALCON_INIT_VAR(uri); - } + PHALCON_OBS_NVAR(intermediate_field); + phalcon_array_fetch(&intermediate_field, intermediate_fields, position, 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_micro_exception_ce, "A dependency injection container is required to access related dispatching services"); - return; - } + 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_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(left_expr); + phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "micro:beforeHandleRoute", 1); + 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_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_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); } - } - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "router", 1); + } 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_VAR(router); - phalcon_call_method_p1_key(router, dependency_injector, "getshared", service, 1727570332UL); + PHALCON_INIT_NVAR(left_expr); + phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); - phalcon_call_method_p1_key(NULL, router, "handle", uri, 866903697UL); + 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(matched_route); - phalcon_call_method_key(matched_route, router, "getmatchedroute", 3985199242UL); - if (Z_TYPE_P(matched_route) == IS_OBJECT) { + 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_OBS_VAR(handlers); - phalcon_read_property_this_quick(&handlers, this_ptr, SL("_handlers"), 2445210229UL, PH_NOISY_CC); + 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_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_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_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); + PHALCON_INIT_NVAR(left_expr); + phalcon_call_method_p1_key(left_expr, this_ptr, "_getqualified", left, 3068781464UL); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { + 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(event_name); - ZVAL_STRING(event_name, "micro:beforeExecuteRoute", 1); + PHALCON_INIT_NVAR(right_expr); + phalcon_call_method_p1_key(right_expr, this_ptr, "_getqualified", right, 3068781464UL); - 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); - } ->>>>>>> 1.2.2 - } - } + 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); -<<<<<<< HEAD - if (phalcon_memnstr_str(compiled_pattern, SL("("))) { - PHALCON_CONCAT_SVS(return_value, "#^", compiled_pattern, "$#"); - RETURN_MM(); - } + 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); - if (phalcon_memnstr_str(compiled_pattern, SL("["))) { - PHALCON_CONCAT_SVS(return_value, "#^", compiled_pattern, "$#"); - RETURN_MM(); + 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_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(); + RETURN_CTOR(sql_joins); } -static PHP_METHOD(Phalcon_Mvc_Router_Route, reConfigure){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getJoins){ - 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; + 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, 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); + 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); - switch (phalcon_get_intval(number_parts)) { + PHALCON_OBS_VAR(sql_aliases); + phalcon_read_property_this_quick(&sql_aliases, this_ptr, SL("_sqlAliases"), 3407085878UL, PH_NOISY_CC); - case 3: - PHALCON_OBS_NVAR(module_name); - phalcon_array_fetch_long(&module_name, parts, 0, PH_NOISY); + PHALCON_OBS_VAR(sql_aliases_models); + phalcon_read_property_this_quick(&sql_aliases_models, this_ptr, SL("_sqlAliasesModels"), 848643194UL, PH_NOISY_CC); - PHALCON_OBS_NVAR(controller_name); - phalcon_array_fetch_long(&controller_name, parts, 1, 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_NVAR(action_name); - phalcon_array_fetch_long(&action_name, parts, 2, PH_NOISY); - break; + PHALCON_OBS_VAR(sql_aliases_models_instances); + phalcon_read_property_this_quick(&sql_aliases_models_instances, this_ptr, SL("_sqlAliasesModelsInstances"), 3347052930UL, PH_NOISY_CC); - case 2: - PHALCON_OBS_NVAR(controller_name); - phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); + 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_NVAR(action_name); - phalcon_array_fetch_long(&action_name, parts, 1, PH_NOISY); - break; + PHALCON_INIT_VAR(sql_joins); + array_init(sql_joins); - case 1: - PHALCON_OBS_NVAR(controller_name); - phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); - break; + PHALCON_INIT_VAR(join_models); + array_init(join_models); - } + PHALCON_INIT_VAR(join_sources); + array_init(join_sources); - PHALCON_INIT_VAR(route_paths); - array_init(route_paths); + PHALCON_INIT_VAR(join_types); + array_init(join_types); - if (Z_TYPE_P(module_name) != IS_NULL) { - phalcon_array_update_quick_string(&route_paths, SS("module"), 3565923467UL, &module_name, PH_COPY | PH_SEPARATE); - } + PHALCON_INIT_VAR(join_pre_condition); + array_init(join_pre_condition); - if (Z_TYPE_P(controller_name) != IS_NULL) { + PHALCON_INIT_VAR(join_prepared); + array_init(join_prepared); - if (phalcon_memnstr_str(controller_name, SL("\\"))) { + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - PHALCON_INIT_VAR(real_class_name); - phalcon_get_class_ns(real_class_name, controller_name, 0 TSRMLS_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_INIT_VAR(namespace_name); - phalcon_get_ns_class(namespace_name, controller_name, 0 TSRMLS_CC); + phalcon_is_iterable(select_joins, &ah0, &hp0, 0, 0); - 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); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(lower_name); - phalcon_uncamelize(lower_name, real_class_name); + PHALCON_GET_HVALUE(join_item); - phalcon_array_update_quick_string(&route_paths, SS("controller"), 2892024105UL, &lower_name, PH_COPY | PH_SEPARATE); - } + PHALCON_INIT_NVAR(join_data); + phalcon_call_method_p2_key(join_data, this_ptr, "_getjoin", manager, join_item, 2949927412UL); - 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 { - PHALCON_CPY_WRT(route_paths, paths); - } - } else { - PHALCON_INIT_NVAR(route_paths); - array_init(route_paths); - } + PHALCON_OBS_NVAR(source); + phalcon_array_fetch_quick_string(&source, join_data, SS("source"), 2744839734UL, PH_NOISY); - if (Z_TYPE_P(route_paths) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The route contains invalid paths"); - return; - } + PHALCON_OBS_NVAR(schema); + phalcon_array_fetch_quick_string(&schema, join_data, SS("schema"), 2259341622UL, PH_NOISY); - 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_OBS_NVAR(model); + phalcon_array_fetch_quick_string(&model, join_data, SS("model"), 238191286UL, PH_NOISY); - 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_OBS_NVAR(model_name); + phalcon_array_fetch_quick_string(&model_name, join_data, SS("modelName"), 440103543UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_pattern"), pattern, 3404429922UL TSRMLS_CC); + 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_update_property_this_quick(this_ptr, SL("_compiledPattern"), compiled_pattern, 4104436623UL TSRMLS_CC); + PHALCON_INIT_NVAR(join_type); + phalcon_call_method_p1_key(join_type, this_ptr, "_getjointype", join_item, 1296796086UL); - phalcon_update_property_this_quick(this_ptr, SL("_paths"), route_paths, 2700778884UL TSRMLS_CC); + if (phalcon_array_isset_quick_string(join_item, SS("alias"), 4060151663UL)) { - 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_OBS_NVAR(alias_expr); + phalcon_array_fetch_quick_string(&alias_expr, join_item, SS("alias"), 4060151663UL, PH_NOISY); - 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_OBS_NVAR(alias); + phalcon_array_fetch_quick_string(&alias, alias_expr, SS("name"), 268211462UL, PH_NOISY); - 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_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); + 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_is_iterable(before_handlers, &ah0, &hp0, 0, 0); + 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; + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + phalcon_array_append(&complete_source, alias, PH_SEPARATE); - PHALCON_GET_HVALUE(before); + phalcon_array_update_zval(&join_types, alias, &join_type, PH_COPY | PH_SEPARATE); - if (Z_TYPE_P(before) == IS_OBJECT) { + phalcon_array_update_zval(&sql_aliases, alias, &alias, PH_COPY | PH_SEPARATE); - 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_array_update_zval(&join_models, alias, &model_name, PH_COPY | PH_SEPARATE); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, before, "call", this_ptr, 255165473UL); + phalcon_array_update_zval(&sql_models_aliases, model_name, &alias, PH_COPY | PH_SEPARATE); - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); + phalcon_array_update_zval(&sql_aliases_models, alias, &model_name, PH_COPY | PH_SEPARATE); - if (zend_is_true(stopped)) { - break; - } + phalcon_array_update_zval(&sql_aliases_models_instances, alias, &model, PH_COPY | PH_SEPARATE); - 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_array_update_zval(&models, model_name, &alias, PH_COPY | PH_SEPARATE); - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC(status, before); - if (PHALCON_IS_FALSE(status)) { - RETURN_MM_FALSE; - } + phalcon_array_update_zval(&join_sources, alias, &complete_source, PH_COPY | PH_SEPARATE); - 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); - } + 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); - zend_hash_move_forward_ex(ah0, &hp0); + 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_INIT_VAR(params); - phalcon_call_method_key(params, router, "getparams", 1893744905UL); + phalcon_array_update_zval(&join_types, model_name, &join_type, PH_COPY | PH_SEPARATE); - PHALCON_INIT_VAR(returned_value); - PHALCON_CALL_USER_FUNC_ARRAY(returned_value, handler, params); + phalcon_array_update_zval(&sql_aliases, model_name, &source, PH_COPY | PH_SEPARATE); - phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), returned_value, 4143876906UL TSRMLS_CC); + phalcon_array_update_zval(&join_models, model_name, &source, PH_COPY | PH_SEPARATE); - 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_array_update_zval(&sql_models_aliases, model_name, &model_name, PH_COPY | PH_SEPARATE); - 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_array_update_zval(&sql_aliases_models, model_name, &model_name, PH_COPY | PH_SEPARATE); - phalcon_is_iterable(after_handlers, &ah1, &hp1, 0, 0); + phalcon_array_update_zval(&sql_aliases_models_instances, model_name, &model, PH_COPY | PH_SEPARATE); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + phalcon_array_update_zval(&models, model_name, &source, PH_COPY | PH_SEPARATE); - PHALCON_GET_HVALUE(after); + phalcon_array_update_zval(&join_sources, model_name, &complete_source, PH_COPY | PH_SEPARATE); - if (Z_TYPE_P(after) == IS_OBJECT) { + phalcon_array_update_zval(&join_prepared, model_name, &join_item, PH_COPY | PH_SEPARATE); + } - 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_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); - PHALCON_INIT_NVAR(status); - phalcon_call_method_p1_key(status, after, "call", this_ptr, 255165473UL); + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); + 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); - if (zend_is_true(stopped)) { - break; - } + phalcon_is_iterable(join_prepared, &ah1, &hp1, 0, 0); - 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; - } + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC(status, after); + PHALCON_GET_HKEY(join_alias_name, ah1, hp1); + PHALCON_GET_HVALUE(join_item); - zend_hash_move_forward_ex(ah1, &hp1); - } + 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); } - } 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); + zend_hash_move_forward_ex(ah1, &hp1); + } - 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; - } - } + PHALCON_OBS_NVAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - 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_is_iterable(from_models, &ah2, &hp2, 0, 0); - PHALCON_INIT_NVAR(returned_value); - PHALCON_CALL_USER_FUNC(returned_value, not_found_handler); + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), returned_value, 4143876906UL TSRMLS_CC); + PHALCON_GET_HKEY(from_model_name, ah2, hp2); + PHALCON_GET_HVALUE(source); - RETURN_CCTOR(returned_value); - } + phalcon_is_iterable(join_models, &ah3, &hp3, 0, 0); - 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); - } + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - 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_GET_HKEY(join_alias, ah3, hp3); + PHALCON_GET_HVALUE(join_model); - PHALCON_INIT_NVAR(params); + PHALCON_OBS_NVAR(join_source); + phalcon_array_fetch(&join_source, join_sources, join_alias, PH_NOISY); - phalcon_is_iterable(finish_handlers, &ah2, &hp2, 0, 0); + PHALCON_OBS_NVAR(join_type); + phalcon_array_fetch(&join_type, join_types, join_alias, PH_NOISY); - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + if (!phalcon_array_isset(join_pre_condition, join_alias)) { - PHALCON_GET_HVALUE(finish); + PHALCON_OBS_NVAR(model_name_alias); + phalcon_array_fetch(&model_name_alias, sql_aliases_models, join_alias, PH_NOISY); - if (Z_TYPE_P(finish) == IS_OBJECT) { + 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(is_middleware); - phalcon_instance_of(is_middleware, finish, phalcon_mvc_micro_middlewareinterface_ce TSRMLS_CC); - if (PHALCON_IS_TRUE(is_middleware)) { + 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(status); - phalcon_call_method_p1_key(status, finish, "call", this_ptr, 255165473UL); + 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_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, 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; + } - if (zend_is_true(stopped)) { - break; + PHALCON_OBS_NVAR(relation); + phalcon_array_fetch_long(&relation, relations, 0, PH_NOISY); } - - 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); - } + if (Z_TYPE_P(relation) == IS_OBJECT) { - PHALCON_INIT_NVAR(status); - PHALCON_CALL_USER_FUNC_ARRAY(status, finish, params); + PHALCON_OBS_NVAR(model_alias); + phalcon_array_fetch(&model_alias, sql_models_aliases, from_model_name, PH_NOISY); - PHALCON_OBS_NVAR(stopped); - phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, 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(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 (zend_is_true(stopped)) { - break; - } + 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); - zend_hash_move_forward_ex(ah2, &hp2); - } + 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); - if (Z_TYPE_P(returned_value) == IS_OBJECT) { + 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_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); + zend_hash_move_forward_ex(ah3, &hp3); } + + zend_hash_move_forward_ex(ah2, &hp2); } - RETURN_CCTOR(returned_value); + RETURN_CCTOR(sql_joins); } -static PHP_METHOD(Phalcon_Mvc_Micro, stop){ ->>>>>>> 1.2.2 +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(); -<<<<<<< HEAD - PHALCON_INIT_VAR(reversed); - array_init(reversed); + phalcon_fetch_params(1, 1, 0, &order); - PHALCON_OBS_VAR(paths); - phalcon_read_property_this_quick(&paths, this_ptr, SL("_paths"), 2700778884UL, PH_NOISY_CC); + 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_is_iterable(paths, &ah0, &hp0, 0, 0); + 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_HKEY(path, ah0, hp0); - PHALCON_GET_HVALUE(position); + PHALCON_GET_HVALUE(order_item); - phalcon_array_update_zval(&reversed, position, &path, PH_COPY | PH_SEPARATE); + 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); + } + } 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_array_append(&order_parts, order_part_sort, 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(); + RETURN_CTOR(order_parts); } -static PHP_METHOD(Phalcon_Mvc_Router_Route, getHttpMethods){ - - - RETURN_MEMBER_QUICK(this_ptr, "_methods", 960170392UL); -} +static PHP_METHOD(Phalcon_Mvc_Model_Query, _getGroupClause){ -static PHP_METHOD(Phalcon_Mvc_Router_Route, setHostname){ + zval *group, *group_parts = NULL, *group_item = NULL, *group_part_expr = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - zval *hostname; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &hostname); + phalcon_fetch_params(1, 1, 0, &group); - phalcon_update_property_this_quick(this_ptr, SL("_hostname"), hostname, 598751491UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getHostname){ -======= - phalcon_update_property_bool(this_ptr, SL("_stopped"), 1 TSRMLS_CC); + if (phalcon_array_isset_long(group, 0)) { -} - -static PHP_METHOD(Phalcon_Mvc_Micro, setActiveHandler){ - - zval *active_handler; - - phalcon_fetch_params(0, 1, 0, &active_handler); + PHALCON_INIT_VAR(group_parts); + array_init(group_parts); - phalcon_update_property_this_quick(this_ptr, SL("_activeHandler"), active_handler, 2923197278UL TSRMLS_CC); + phalcon_is_iterable(group, &ah0, &hp0, 0, 0); -} - -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){ ->>>>>>> 1.2.2 - - zval *alias; - -<<<<<<< HEAD - 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); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - phalcon_update_property_array(this_ptr, SL("_converters"), name, converter TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getConverters){ -======= - phalcon_fetch_params(0, 1, 0, &alias); + PHALCON_GET_HVALUE(group_item); - RETURN_CCTORW(alias); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, before){ - - zval *handler; - - phalcon_fetch_params(0, 1, 0, &handler); + 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_update_property_array_append(this_ptr, SL("_beforeHandlers"), handler TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, after){ ->>>>>>> 1.2.2 - - zval *handler; - -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_converters", 994353007UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, reset){ - - zval *zero; -======= - phalcon_fetch_params(0, 1, 0, &handler); + zend_hash_move_forward_ex(ah0, &hp0); + } - 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); + } else { + PHALCON_INIT_NVAR(group_part_expr); + phalcon_call_method_p1_key(group_part_expr, this_ptr, "_getexpression", group, 2816780276UL); - phalcon_update_property_array_append(this_ptr, SL("_finishHandlers"), handler TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Micro, getHandlers){ ->>>>>>> 1.2.2 - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); - phalcon_update_static_property(SL("phalcon\\mvc\\router\\route"), SL("_uniqueId"), zero TSRMLS_CC); + PHALCON_INIT_NVAR(group_parts); + array_init_size(group_parts, 1); + phalcon_array_append(&group_parts, group_part_expr, PH_SEPARATE); + } - PHALCON_MM_RESTORE(); -======= - RETURN_MEMBER_QUICK(this_ptr, "_handlers", 2445210229UL); ->>>>>>> 1.2.2 -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -<<<<<<< HEAD -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; -} - -======= ->>>>>>> 1.2.2 - - - - -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); - -<<<<<<< HEAD - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif -======= - zend_class_implements(phalcon_mvc_router_route_ce TSRMLS_CC, 1, phalcon_mvc_router_routeinterface_ce); ->>>>>>> 1.2.2 - - return SUCCESS; + RETURN_CTOR(group_parts); } -static PHP_METHOD(Phalcon_Mvc_Router_Route, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareSelect){ - zval *pattern, *paths = NULL, *http_methods = NULL, *unique_id = NULL; - zval *route_id = NULL, *one, *next_id; + 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_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); + PHALCON_OBS_VAR(ast); + phalcon_read_property_this_quick(&ast, this_ptr, SL("_ast"), 250429676UL, PH_NOISY_CC); - if (!paths) { - PHALCON_INIT_VAR(paths); + 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 (!http_methods) { - PHALCON_INIT_VAR(http_methods); + if (!phalcon_array_isset_quick_string(select, SS("columns"), 1041822630UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted SELECT AST"); + return; } - phalcon_call_method_p2_key(NULL, this_ptr, "reconfigure", pattern, paths, 18237790UL); + PHALCON_INIT_VAR(sql_models); + array_init(sql_models); - phalcon_update_property_this_quick(this_ptr, SL("_methods"), http_methods, 960170392UL TSRMLS_CC); + PHALCON_INIT_VAR(sql_tables); + array_init(sql_tables); - 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(sql_aliases); + array_init(sql_aliases); - PHALCON_CPY_WRT(route_id, unique_id); - phalcon_update_property_this_quick(this_ptr, SL("_id"), route_id, 2090005265UL TSRMLS_CC); + PHALCON_INIT_VAR(sql_columns); + array_init(sql_columns); - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); + PHALCON_INIT_VAR(sql_aliases_models); + array_init(sql_aliases_models); - 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_INIT_VAR(sql_models_aliases); + array_init(sql_models_aliases); - PHALCON_MM_RESTORE(); -} - -<<<<<<< HEAD -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_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); -======= -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_INIT_VAR(sql_aliases_models_instances); + array_init(sql_aliases_models_instances); - PHALCON_CPY_WRT(compiled_pattern, pattern); + PHALCON_INIT_VAR(models); + array_init(models); - if (phalcon_memnstr_str(pattern, SL(":"))) { + PHALCON_INIT_VAR(models_instances); + array_init(models_instances); - PHALCON_INIT_VAR(id_pattern); - ZVAL_STRING(id_pattern, "/([a-zA-Z0-9\\_\\-]+)", 1); + 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); + } - if (phalcon_memnstr_str(pattern, SL("/:module"))) { - PHALCON_INIT_VAR(wildcard); - ZVAL_STRING(wildcard, "/:module", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); - } + 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); - 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(real_namespace); + phalcon_call_method_p1_key(real_namespace, manager, "getnamespacealias", ns_alias, 3487123420UL); - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); + 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); } - 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(model); + phalcon_call_method_p1_key(model, manager, "load", real_model_name, 266329637UL); - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); - } + PHALCON_INIT_NVAR(schema); + phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - 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(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, id_pattern, pattern_copy); + 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); } - if (phalcon_memnstr_str(pattern, SL("/:params"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:params", 1); + if (phalcon_array_isset_quick_string(selected_model, SS("alias"), 4060151663UL)) { - PHALCON_INIT_VAR(params_pattern); - ZVAL_STRING(params_pattern, "(/.*)*", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); + PHALCON_OBS_NVAR(alias); + phalcon_array_fetch_quick_string(&alias, selected_model, SS("alias"), 4060151663UL, PH_NOISY); - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, params_pattern, pattern_copy); - } + 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); - if (phalcon_memnstr_str(pattern, SL("/:int"))) { - PHALCON_INIT_NVAR(wildcard); - ZVAL_STRING(wildcard, "/:int", 1); + 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_INIT_VAR(int_pattern); - ZVAL_STRING(int_pattern, "/([0-9]+)", 1); - PHALCON_CPY_WRT(pattern_copy, compiled_pattern); + 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); - PHALCON_INIT_NVAR(compiled_pattern); - phalcon_fast_str_replace(compiled_pattern, wildcard, int_pattern, pattern_copy); + 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); + } + + 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); } - } - if (phalcon_memnstr_str(compiled_pattern, SL("("))) { - PHALCON_CONCAT_SVS(return_value, "#^", compiled_pattern, "$#"); - RETURN_MM(); - } + 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); - if (phalcon_memnstr_str(compiled_pattern, SL("["))) { - PHALCON_CONCAT_SVS(return_value, "#^", compiled_pattern, "$#"); - RETURN_MM(); + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CCTOR(compiled_pattern); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, via){ - - zval *http_methods; ->>>>>>> 1.2.2 - - phalcon_fetch_params(0, 1, 0, &http_methods); + 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); - phalcon_update_property_this_quick(this_ptr, SL("_methods"), http_methods, 960170392UL TSRMLS_CC); - RETURN_THISW(); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Router_Group, __construct){ - - zval *paths = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &paths); -======= -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); ->>>>>>> 1.2.2 + if (phalcon_array_isset_quick_string(select, SS("joins"), 120974824UL)) { - if (!paths) { - PHALCON_INIT_VAR(paths); + 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); + } + } else { + PHALCON_INIT_NVAR(sql_joins); + array_init(sql_joins); } -<<<<<<< HEAD - if (Z_TYPE_P(paths) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_paths"), paths, 2700778884UL TSRMLS_CC); + 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 { - 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); - } -======= - if (Z_TYPE_P(pattern) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The pattern must be string"); - return; + PHALCON_CPY_WRT(select_columns, columns); } - 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); + PHALCON_INIT_VAR(position); + ZVAL_LONG(position, 0); - switch (phalcon_get_intval(number_parts)) { + PHALCON_INIT_VAR(sql_column_aliases); + array_init(sql_column_aliases); - case 3: - PHALCON_OBS_NVAR(module_name); - phalcon_array_fetch_long(&module_name, parts, 0, PH_NOISY); + phalcon_is_iterable(select_columns, &ah1, &hp1, 0, 0); - PHALCON_OBS_NVAR(controller_name); - phalcon_array_fetch_long(&controller_name, parts, 1, PH_NOISY); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_OBS_NVAR(action_name); - phalcon_array_fetch_long(&action_name, parts, 2, PH_NOISY); - break; + PHALCON_GET_HVALUE(column); - case 2: - PHALCON_OBS_NVAR(controller_name); - phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); + PHALCON_INIT_NVAR(sql_column_group); + phalcon_call_method_p1_key(sql_column_group, this_ptr, "_getselectcolumn", column, 3762838962UL); - PHALCON_OBS_NVAR(action_name); - phalcon_array_fetch_long(&action_name, parts, 1, PH_NOISY); - break; + phalcon_is_iterable(sql_column_group, &ah2, &hp2, 0, 0); - case 1: - PHALCON_OBS_NVAR(controller_name); - phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); - break; + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - } + PHALCON_GET_HVALUE(sql_column); - PHALCON_INIT_VAR(route_paths); - array_init(route_paths); + 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 (Z_TYPE_P(module_name) != IS_NULL) { - phalcon_array_update_quick_string(&route_paths, SS("module"), 3565923467UL, &module_name, PH_COPY | PH_SEPARATE); + 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); + } + } } + PHALCON_SEPARATE(position); + phalcon_increment(position); - 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); + zend_hash_move_forward_ex(ah2, &hp2); + } - PHALCON_INIT_VAR(namespace_name); - phalcon_get_ns_class(namespace_name, controller_name, 0 TSRMLS_CC); + zend_hash_move_forward_ex(ah1, &hp1); + } - 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_update_property_this_quick(this_ptr, SL("_sqlColumnAliases"), sql_column_aliases, 3031417188UL TSRMLS_CC); - PHALCON_INIT_VAR(lower_name); - phalcon_uncamelize(lower_name, real_class_name); + 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_array_update_quick_string(&route_paths, SS("controller"), 2892024105UL, &lower_name, 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); - 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 { - PHALCON_CPY_WRT(route_paths, paths); - } - } else { - PHALCON_INIT_NVAR(route_paths); - array_init(route_paths); + 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 (Z_TYPE_P(route_paths) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The route contains invalid paths"); - return; + 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_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); - } + 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(compiled_pattern); - phalcon_call_method_p1_key(compiled_pattern, this_ptr, "compilepattern", pcre_pattern, 2680336012UL); - } else { - PHALCON_CPY_WRT(compiled_pattern, pattern); + 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_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); + 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_update_property_this_quick(this_ptr, SL("_paths"), route_paths, 2700778884UL TSRMLS_CC); ->>>>>>> 1.2.2 + 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_MM_RESTORE(); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Router_Group, setHostname){ - - zval *hostname; - - phalcon_fetch_params(0, 1, 0, &hostname); + 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_this_quick(this_ptr, SL("_hostname"), hostname, 598751491UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, getHostname){ -======= -static PHP_METHOD(Phalcon_Mvc_Router_Route, getName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_name", 3983977829UL); + RETURN_CTOR(sql_select); } -static PHP_METHOD(Phalcon_Mvc_Router_Route, setName){ ->>>>>>> 1.2.2 - - zval *name; - -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_hostname", 598751491UL); -} +static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareInsert){ -static PHP_METHOD(Phalcon_Mvc_Router_Group, setPrefix){ + 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 *prefix; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &prefix); + 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; + } - 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){ -======= - phalcon_fetch_params(0, 1, 0, &name); + if (!phalcon_array_isset_quick_string(ast, SS("values"), 1765818005UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted INSERT AST"); + return; + } - 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_OBS_VAR(qualified_name); + phalcon_array_fetch_quick_string(&qualified_name, ast, SS("qualifiedName"), 2418332666UL, PH_NOISY); - 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){ ->>>>>>> 1.2.2 - - zval *before_match; - -<<<<<<< HEAD - phalcon_fetch_params(0, 1, 0, &before_match); + 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_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_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - phalcon_update_property_this_quick(this_ptr, SL("_paths"), paths, 2700778884UL TSRMLS_CC); + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, getPaths){ - -======= - 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; ->>>>>>> 1.2.2 - - RETURN_MEMBER_QUICK(this_ptr, "_paths", 2700778884UL); -} - -<<<<<<< HEAD -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_INIT_VAR(reversed); - array_init(reversed); + 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_OBS_VAR(paths); - phalcon_read_property_this_quick(&paths, this_ptr, SL("_paths"), 2700778884UL, PH_NOISY_CC); + PHALCON_INIT_VAR(expr_values); + array_init(expr_values); - phalcon_is_iterable(paths, &ah0, &hp0, 0, 0); + 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_HKEY(path, ah0, hp0); - PHALCON_GET_HVALUE(position); + PHALCON_GET_HVALUE(expr_value); - phalcon_array_update_zval(&reversed, position, &path, PH_COPY | PH_SEPARATE); + 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); } - RETURN_CTOR(reversed); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, setHttpMethods){ ->>>>>>> 1.2.2 - - zval *http_methods; - -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); + 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); - if (!paths) { - PHALCON_INIT_VAR(paths); - } + 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)) { - if (!http_methods) { - PHALCON_INIT_VAR(http_methods); - } + PHALCON_INIT_VAR(sql_fields); + array_init(sql_fields); - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + PHALCON_OBS_VAR(fields); + phalcon_array_fetch_quick_string(&fields, ast, SS("fields"), 2881624156UL, PH_NOISY); - PHALCON_INIT_VAR(prefix_pattern); - PHALCON_CONCAT_VV(prefix_pattern, prefix, pattern); + phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); - PHALCON_OBS_VAR(default_paths); - phalcon_read_property_this_quick(&default_paths, this_ptr, SL("_paths"), 2700778884UL, PH_NOISY_CC); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - 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); - } - } else { - PHALCON_CPY_WRT(merged_paths, paths); - } + PHALCON_GET_HVALUE(field); - 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_OBS_NVAR(name); + phalcon_array_fetch_quick_string(&name, field, SS("name"), 268211462UL, PH_NOISY); - phalcon_update_property_array_append(this_ptr, SL("_routes"), route TSRMLS_CC); + 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); - RETURN_CTOR(route); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, add){ - - zval *pattern, *paths = NULL, *http_methods = NULL; -======= - phalcon_fetch_params(0, 1, 0, &http_methods); + 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_update_property_this_quick(this_ptr, SL("_methods"), http_methods, 960170392UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Route, getHttpMethods){ - ->>>>>>> 1.2.2 - - RETURN_MEMBER_QUICK(this_ptr, "_methods", 960170392UL); -} - -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); + phalcon_array_append(&sql_fields, name, PH_SEPARATE); - if (!paths) { - PHALCON_INIT_VAR(paths); - } + zend_hash_move_forward_ex(ah1, &hp1); + } - if (!http_methods) { - PHALCON_INIT_VAR(http_methods); + phalcon_array_update_quick_string(&sql_insert, SS("fields"), 2881624156UL, &sql_fields, PH_COPY | PH_SEPARATE); } - phalcon_call_method_p3_key(return_value, this_ptr, "_addroute", pattern, paths, http_methods, 1178487196UL); - RETURN_MM(); + 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_Router_Group, addGet){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareUpdate){ - zval *pattern, *paths = NULL, *method; + 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_fetch_params(1, 1, 1, &pattern, &paths); + 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; + } - if (!paths) { - PHALCON_INIT_VAR(paths); + 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_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_Route, setHostname){ - - zval *hostname; - - phalcon_fetch_params(0, 1, 0, &hostname); + if (!phalcon_array_isset_quick_string(update, SS("values"), 1765818005UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted UPDATE AST"); + return; + } - 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_INIT_VAR(models); + array_init(models); - 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_INIT_VAR(models_instances); + array_init(models_instances); - PHALCON_MM_RESTORE(); ->>>>>>> 1.2.2 -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, addPost){ - - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); + PHALCON_INIT_VAR(sql_tables); + array_init(sql_tables); - if (!paths) { - PHALCON_INIT_VAR(paths); - } + PHALCON_INIT_VAR(sql_models); + array_init(sql_models); - 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){ - -<<<<<<< HEAD - zval *pattern, *paths = NULL, *method; - - PHALCON_MM_GROW(); -======= -PHALCON_INIT_CLASS(Phalcon_Mvc_Router_RouteInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Router, RouteInterface, mvc_router_routeinterface, phalcon_mvc_router_routeinterface_method_entry); ->>>>>>> 1.2.2 - - phalcon_fetch_params(1, 1, 1, &pattern, &paths); + PHALCON_INIT_VAR(sql_aliases); + array_init(sql_aliases); - if (!paths) { - PHALCON_INIT_VAR(paths); + 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_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); + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - if (!paths) { - PHALCON_INIT_VAR(paths); - } + phalcon_is_iterable(update_tables, &ah0, &hp0, 0, 0); - 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); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (!paths) { - PHALCON_INIT_VAR(paths); - } + PHALCON_GET_HVALUE(table); - 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); + PHALCON_OBS_NVAR(qualified_name); + phalcon_array_fetch_quick_string(&qualified_name, table, SS("qualifiedName"), 2418332666UL, PH_NOISY); - if (!paths) { - PHALCON_INIT_VAR(paths); - } + PHALCON_OBS_NVAR(model_name); + phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); - 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 (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); - if (!paths) { - PHALCON_INIT_VAR(paths); - } + PHALCON_INIT_NVAR(real_namespace); + phalcon_call_method_p1_key(real_namespace, manager, "getnamespacealias", ns_alias, 3487123420UL); - 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){ - -<<<<<<< HEAD - zval *empty_routes; - - PHALCON_MM_GROW(); -======= -#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); ->>>>>>> 1.2.2 - - PHALCON_INIT_VAR(empty_routes); - array_init(empty_routes); - phalcon_update_property_this_quick(this_ptr, SL("_routes"), empty_routes, 2063827110UL 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); + } - PHALCON_MM_RESTORE(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -<<<<<<< HEAD -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); -======= -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); ->>>>>>> 1.2.2 - - return SUCCESS; -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, addResource){ - - zval *handler, *prefix = NULL, *scope; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &handler, &prefix); + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", real_model_name, 266329637UL); - if (!prefix) { - PHALCON_INIT_VAR(prefix); - } + PHALCON_INIT_NVAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); - 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_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_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_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); + 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); - 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); + PHALCON_INIT_VAR(sql_fields); + array_init(sql_fields); - if (!prefix) { - PHALCON_INIT_VAR(prefix); + 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); } - if (Z_TYPE_P(module) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "The module is not a valid string"); - return; + 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); } - 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(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); } - 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); + 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_THIS(); + RETURN_CTOR(sql_update); } -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, handle){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _prepareDelete){ - 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 *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_fetch_params(1, 0, 1, &uri); - - if (!uri) { - PHALCON_INIT_VAR(uri); + 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; } - 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(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(processed); - phalcon_read_property_this_quick(&processed, this_ptr, SL("_processed"), 908491692UL, PH_NOISY_CC); - if (!zend_is_true(processed)) { + PHALCON_INIT_VAR(models); + array_init(models); - PHALCON_INIT_VAR(annotations_service); + PHALCON_INIT_VAR(models_instances); + array_init(models_instances); - 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_INIT_VAR(sql_tables); + array_init(sql_tables); - PHALCON_OBS_VAR(controller_suffix); - phalcon_read_property_this_quick(&controller_suffix, this_ptr, SL("_controllerSuffix"), 2437326621UL, PH_NOISY_CC); + PHALCON_INIT_VAR(sql_models); + array_init(sql_models); - phalcon_is_iterable(handlers, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(sql_aliases); + array_init(sql_aliases); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(sql_aliases_models_instances); + array_init(sql_aliases_models_instances); - PHALCON_GET_HVALUE(scope); + 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); + } - if (Z_TYPE_P(scope) == IS_ARRAY) { + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - 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; - } - } + phalcon_is_iterable(delete_tables, &ah0, &hp0, 0, 0); - if (Z_TYPE_P(annotations_service) != IS_OBJECT) { + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - 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_GET_HVALUE(table); - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "annotations", 1); + PHALCON_OBS_NVAR(qualified_name); + phalcon_array_fetch_quick_string(&qualified_name, table, SS("qualifiedName"), 2418332666UL, PH_NOISY); - PHALCON_INIT_NVAR(annotations_service); - phalcon_call_method_p1_key(annotations_service, dependency_injector, "getshared", service, 1727570332UL); - } + PHALCON_OBS_NVAR(model_name); + phalcon_array_fetch_quick_string(&model_name, qualified_name, SS("name"), 268211462UL, PH_NOISY); - 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); + 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(lower_controller_name); - phalcon_uncamelize(lower_controller_name, controller_name); + PHALCON_INIT_NVAR(real_namespace); + phalcon_call_method_p1_key(real_namespace, manager, "getnamespacealias", ns_alias, 3487123420UL); - 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(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(lower_controller_name); - phalcon_uncamelize(lower_controller_name, controller_name); + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", real_model_name, 266329637UL); - PHALCON_INIT_NVAR(namespace_name); - } + PHALCON_INIT_NVAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); - phalcon_update_property_null(this_ptr, SL("_routePrefix") TSRMLS_CC); + 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_long(scope, 2)) { - PHALCON_OBS_NVAR(module_name); - phalcon_array_fetch_long(&module_name, scope, 2, PH_NOISY); - } else { - PHALCON_INIT_NVAR(module_name); - } + 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_INIT_NVAR(sufixed); - PHALCON_CONCAT_VV(sufixed, handler, controller_suffix); + phalcon_array_append(&sql_models, model_name, PH_SEPARATE); + phalcon_array_update_zval(&models_instances, model_name, &model, PH_COPY | PH_SEPARATE); - PHALCON_INIT_NVAR(handler_annotations); - phalcon_call_method_p1_key(handler_annotations, annotations_service, "get", sufixed, 2090288933UL); + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_INIT_NVAR(class_annotations); - phalcon_call_method_key(class_annotations, handler_annotations, "getclassannotations", 3984548329UL); - if (Z_TYPE_P(class_annotations) == 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_INIT_NVAR(annotations); - phalcon_call_method_key(annotations, class_annotations, "getannotations", 163297043UL); - if (Z_TYPE_P(annotations) == IS_ARRAY) { + 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_is_iterable(annotations, &ah1, &hp1, 0, 0); + PHALCON_OBS_VAR(where); + phalcon_array_fetch_quick_string(&where, ast, SS("where"), 621293632UL, PH_NOISY); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + 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_GET_HVALUE(annotation); + 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); + } - phalcon_call_method_p2_key(NULL, this_ptr, "processcontrollerannotation", controller_name, annotation, 1441174403UL); + 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); + } - zend_hash_move_forward_ex(ah1, &hp1); - } + 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_NVAR(method_annotations); - phalcon_call_method_key(method_annotations, handler_annotations, "getmethodsannotations", 2860599943UL); - if (Z_TYPE_P(method_annotations) == IS_ARRAY) { + PHALCON_INIT_VAR(ir_phql); - PHALCON_INIT_NVAR(lowercased); - phalcon_uncamelize(lowercased, handler); + PHALCON_INIT_VAR(ir_phql_cache); - phalcon_is_iterable(method_annotations, &ah2, &hp2, 0, 0); + PHALCON_INIT_VAR(unique_id); - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + if (Z_TYPE_P(ast) == IS_ARRAY) { - PHALCON_GET_HKEY(method, ah2, hp2); - PHALCON_GET_HVALUE(collection); + if (phalcon_array_isset_quick_string(ast, SS("id"), 193494642UL)) { - if (Z_TYPE_P(collection) == IS_OBJECT) { + PHALCON_OBS_NVAR(unique_id); + phalcon_array_fetch_quick_string(&unique_id, ast, SS("id"), 193494642UL, PH_NOISY); - PHALCON_INIT_NVAR(annotations); - phalcon_call_method_key(annotations, collection, "getannotations", 163297043UL); + 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_is_iterable(annotations, &ah3, &hp3, 0, 0); + 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); + } + } + } - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { + if (phalcon_array_isset_quick_string(ast, SS("type"), 276192743UL)) { + phalcon_update_property_this_quick(this_ptr, SL("_ast"), ast, 250429676UL TSRMLS_CC); - PHALCON_GET_HVALUE(annotation); + 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); - phalcon_call_method_p5_key(NULL, this_ptr, "processactionannotation", module_name, namespace_name, lower_controller_name, method, annotation, 3018293437UL); + switch (phalcon_get_intval(type)) { - zend_hash_move_forward_ex(ah3, &hp3); - } + 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; - zend_hash_move_forward_ex(ah2, &hp2); - } + 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; - zend_hash_move_forward_ex(ah0, &hp0); - } + 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; + } } + } - phalcon_update_property_bool(this_ptr, SL("_processed"), 1 TSRMLS_CC); + if (Z_TYPE_P(ir_phql) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Corrupted AST"); + return; } - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Mvc\\Router\\Annotations", "handle", real_uri); + 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_MM_RESTORE(); + phalcon_update_property_this_quick(this_ptr, SL("_intermediate"), ir_phql, 1829292799UL TSRMLS_CC); + + RETURN_CCTOR(ir_phql); } -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, processControllerAnnotation){ - - zval *handler, *annotation, *name, *position, *value; +static PHP_METHOD(Phalcon_Mvc_Model_Query, cache){ - PHALCON_MM_GROW(); + zval *cache_options; - 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_fetch_params(0, 1, 0, &cache_options); - PHALCON_MM_RESTORE(); + phalcon_update_property_this_quick(this_ptr, SL("_cacheOptions"), cache_options, 528255652UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, processActionAnnotation){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, getCacheOptions){ - 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; + + 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, 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_fetch_params(1, 3, 0, &intermediate, &bind_params, &bind_types); - 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_SEPARATE_PARAM(intermediate); - 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_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(methods); - ZVAL_STRING(methods, "OPTIONS", 1); - } - } - } - } + 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); } - 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); - } + PHALCON_OBS_VAR(models); + phalcon_array_fetch_quick_string(&models, intermediate, SS("models"), 3565348937UL, PH_NOISY); - if (Z_TYPE_P(module) == IS_STRING) { - phalcon_array_update_quick_string(&paths, SS("module"), 3565923467UL, &module, PH_COPY | PH_SEPARATE); - } + PHALCON_INIT_VAR(number_models); + phalcon_fast_count(number_models, models TSRMLS_CC); + if (PHALCON_IS_LONG(number_models, 1)) { - if (Z_TYPE_P(namespace) == IS_STRING) { - phalcon_array_update_quick_string(&paths, SS("namespace"), 545490034UL, &namespace, PH_COPY | PH_SEPARATE); + 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_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 (phalcon_method_quick_exists_ex(model, SS("selectreadconnection"), 2893916401UL TSRMLS_CC) == SUCCESS) { - 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); + 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; } } else { - PHALCON_INIT_NVAR(uri); - PHALCON_CONCAT_VV(uri, route_prefix, action_name); + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, model, "getreadconnection", 488334257UL); } + } else { + PHALCON_INIT_VAR(connections); + array_init(connections); - PHALCON_INIT_VAR(route); - phalcon_call_method_p2_key(route, this_ptr, "add", uri, paths, 2090071694UL); - if (Z_TYPE_P(methods) == IS_NULL) { + phalcon_is_iterable(models, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(parameter); - ZVAL_STRING(parameter, "methods", 1); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - 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); + 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 { - if (Z_TYPE_P(methods) == IS_STRING) { - phalcon_call_method_p1_key(NULL, route, "via", methods, 2090831717UL); - } + PHALCON_OBS_NVAR(model); + phalcon_array_fetch(&model, models_instances, model_name, PH_NOISY); } - } 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); + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, model, "getreadconnection", 488334257UL); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_NVAR(type); + phalcon_call_method_key(type, connection, "gettype", 4294422375UL); - PHALCON_GET_HKEY(param, ah0, hp0); - PHALCON_GET_HVALUE(convert); + phalcon_array_update_zval_bool(&connections, type, 1, PH_SEPARATE); - phalcon_call_method_p2_key(NULL, route, "convert", param, convert, 1120996230UL); + PHALCON_INIT_NVAR(connection_types); + phalcon_fast_count(connection_types, connections TSRMLS_CC); - zend_hash_move_forward_ex(ah0, &hp0); + 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; } + zend_hash_move_forward_ex(ah0, &hp0); } - 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_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, intermediate, SS("columns"), 1041822630UL, PH_NOISY); - phalcon_is_iterable(converts, &ah1, &hp1, 0, 0); + PHALCON_INIT_VAR(have_objects); + ZVAL_BOOL(have_objects, 0); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + PHALCON_INIT_VAR(have_scalars); + ZVAL_BOOL(have_scalars, 0); - PHALCON_GET_HKEY(conversor_param, ah1, hp1); - PHALCON_GET_HVALUE(convert); + PHALCON_INIT_VAR(is_complex); + ZVAL_BOOL(is_complex, 0); - phalcon_call_method_p2_key(NULL, route, "convert", conversor_param, convert, 1120996230UL); + PHALCON_INIT_VAR(number_objects); + ZVAL_LONG(number_objects, 0); - zend_hash_move_forward_ex(ah1, &hp1); - } + phalcon_is_iterable(columns, &ah1, &hp1, 0, 0); - } + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_INIT_NVAR(parameter); - ZVAL_STRING(parameter, "name", 1); + PHALCON_GET_HVALUE(column); - 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); - } + 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); + } - RETURN_MM_TRUE; -======= -static PHP_METHOD(Phalcon_Mvc_Router_Group, __construct){ - - zval *paths = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &paths); + 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); + } - if (!paths) { - PHALCON_INIT_VAR(paths); + zend_hash_move_forward_ex(ah1, &hp1); } - 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_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); } } - 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); ->>>>>>> 1.2.2 - } - - PHALCON_MM_RESTORE(); -} - -<<<<<<< HEAD -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_INIT_VAR(select_columns); + array_init(select_columns); - phalcon_update_property_this_quick(this_ptr, SL("_actionSuffix"), action_suffix, 879621975UL TSRMLS_CC); + PHALCON_INIT_VAR(simple_column_map); + array_init(simple_column_map); -} - -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_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){ - -======= -static PHP_METHOD(Phalcon_Mvc_Router_Group, setHostname){ - - zval *hostname; - - phalcon_fetch_params(0, 1, 0, &hostname); + PHALCON_OBS_VAR(meta_data); + phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - 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){ ->>>>>>> 1.2.2 - - zval *prefix; - -<<<<<<< HEAD - 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_VAR(znull); - PHALCON_MM_RESTORE(); -======= - phalcon_fetch_params(0, 1, 0, &prefix); + phalcon_is_iterable(columns, &ah2, &hp2, 1, 0); - phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); - RETURN_THISW(); ->>>>>>> 1.2.2 -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, getPrefix){ - - -<<<<<<< HEAD - - -#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; -======= - RETURN_MEMBER_QUICK(this_ptr, "_prefix", 3873791314UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Group, beforeMatch){ ->>>>>>> 1.2.2 - - zval *before_match; - -<<<<<<< HEAD - phalcon_fetch_params(1, 3, 0, &method, &route_pattern, &handler); + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - 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_fetch_params(0, 1, 0, &before_match); ->>>>>>> 1.2.2 + PHALCON_GET_HMKEY(alias_copy, ah2, hp2); + PHALCON_GET_HVALUE(column); - phalcon_update_property_this_quick(this_ptr, SL("_beforeMatch"), before_match, 2834072708UL TSRMLS_CC); - RETURN_THISW(); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, setPrefix){ - - zval *prefix; - - phalcon_fetch_params(0, 1, 0, &prefix); + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, column, SS("type"), 276192743UL, PH_NOISY); - 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; -======= -static PHP_METHOD(Phalcon_Mvc_Router_Group, getBeforeMatch){ - ->>>>>>> 1.2.2 - - RETURN_MEMBER_QUICK(this_ptr, "_beforeMatch", 2834072708UL); -} - -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 1, &handler, &lazy); + PHALCON_OBS_NVAR(sql_column); + phalcon_array_fetch_quick_string(&sql_column, column, SS("column"), 3545634419UL, PH_NOISY); - if (!lazy) { - PHALCON_INIT_VAR(lazy); - ZVAL_BOOL(lazy, 0); - } + if (PHALCON_IS_STRING(type, "object")) { - 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_OBS_NVAR(model_name); + phalcon_array_fetch_quick_string(&model_name, column, SS("model"), 238191286UL, PH_NOISY); - 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); + 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); + } - 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_NVAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", instance, 1013165772UL); + if (PHALCON_IS_TRUE(is_complex)) { - 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); + 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_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_is_iterable(attributes, &ah3, &hp3, 0, 0); - 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); + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - 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_GET_HVALUE(attribute); - 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); -======= -static PHP_METHOD(Phalcon_Mvc_Router_Group, setPaths){ - - zval *paths; - - phalcon_fetch_params(0, 1, 0, &paths); + PHALCON_INIT_NVAR(hidden_alias); + PHALCON_CONCAT_SVSV(hidden_alias, "_", sql_column, "_", attribute); - phalcon_update_property_this_quick(this_ptr, SL("_paths"), paths, 2700778884UL TSRMLS_CC); + 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); -} - -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); + zend_hash_move_forward_ex(ah3, &hp3); + } - if (!paths) { - PHALCON_INIT_VAR(paths); - } + 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); - if (!http_methods) { - PHALCON_INIT_VAR(http_methods); - } + 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); - PHALCON_OBS_VAR(prefix); - phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { - PHALCON_INIT_VAR(prefix_pattern); - PHALCON_CONCAT_VV(prefix_pattern, prefix, pattern); + PHALCON_GET_HVALUE(attribute); - PHALCON_OBS_VAR(default_paths); - phalcon_read_property_this_quick(&default_paths, this_ptr, SL("_paths"), 2700778884UL, PH_NOISY_CC); + 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); - 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); + zend_hash_move_forward_ex(ah4, &hp4); + } + + } } else { - PHALCON_CPY_WRT(merged_paths, default_paths); + 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); } - } else { - PHALCON_CPY_WRT(merged_paths, paths); + + 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); + } + } + } + + zend_hash_move_forward_ex(ah2, &hp2); } + zend_hash_destroy(ah2); + efree(ah2); - 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_array_update_quick_string(&intermediate, SS("columns"), 1041822630UL, &select_columns, PH_COPY | PH_SEPARATE); - phalcon_update_property_array_append(this_ptr, SL("_routes"), route TSRMLS_CC); + PHALCON_INIT_VAR(dialect); + phalcon_call_method_key(dialect, connection, "getdialect", 3133083739UL); - 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); + PHALCON_INIT_VAR(sql_select); + phalcon_call_method_p1_key(sql_select, dialect, "select", intermediate, 2342345829UL); - if (!paths) { - PHALCON_INIT_VAR(paths); - } + if (Z_TYPE_P(bind_params) == IS_ARRAY) { - if (!http_methods) { - PHALCON_INIT_VAR(http_methods); - } + PHALCON_INIT_VAR(processed); + array_init(processed); - 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); + phalcon_is_iterable(bind_params, &ah5, &hp5, 0, 0); - if (!paths) { - PHALCON_INIT_VAR(paths); - } + while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { - 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); + PHALCON_GET_HKEY(wildcard, ah5, hp5); + PHALCON_GET_HVALUE(value); - if (!paths) { - PHALCON_INIT_VAR(paths); - } + 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); + } - 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); + zend_hash_move_forward_ex(ah5, &hp5); + } - if (!paths) { - PHALCON_INIT_VAR(paths); + } else { + PHALCON_CPY_WRT(processed, bind_params); } - 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 (Z_TYPE_P(bind_types) == IS_ARRAY) { - if (!paths) { - PHALCON_INIT_VAR(paths); - } + PHALCON_INIT_VAR(processed_types); + array_init(processed_types); - 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_is_iterable(bind_types, &ah6, &hp6, 0, 0); - if (!paths) { - PHALCON_INIT_VAR(paths); - } + while (zend_hash_get_current_data_ex(ah6, (void**) &hd, &hp6) == SUCCESS) { - 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); + PHALCON_GET_HKEY(type_wildcard, ah6, hp6); + PHALCON_GET_HVALUE(value); - if (!paths) { - PHALCON_INIT_VAR(paths); - } + 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); + } - 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); + zend_hash_move_forward_ex(ah6, &hp6); + } - if (!paths) { - PHALCON_INIT_VAR(paths); + } else { + PHALCON_CPY_WRT(processed_types, bind_types); } - 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); ->>>>>>> 1.2.2 + PHALCON_INIT_VAR(result); + phalcon_call_method_p3_key(result, connection, "query", sql_select, processed, processed_types, 401898907UL); - 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(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_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 - - - -<<<<<<< HEAD -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; -} - - -======= -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); ->>>>>>> 1.2.2 - - -<<<<<<< HEAD -======= -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, addResource){ - - zval *handler, *prefix = NULL, *scope; ->>>>>>> 1.2.2 - - PHALCON_MM_GROW(); - -<<<<<<< HEAD -#ifdef HAVE_CONFIG_H -#endif - -======= - phalcon_fetch_params(1, 1, 1, &handler, &prefix); + 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 (!prefix) { - PHALCON_INIT_VAR(prefix); - } + if (PHALCON_IS_TRUE(is_simple_std)) { + PHALCON_INIT_VAR(result_object); + object_init_ex(result_object, phalcon_mvc_model_row_ce); - 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_NVAR(is_keeping_snapshots); + ZVAL_BOOL(is_keeping_snapshots, 0); + } else { + PHALCON_CPY_WRT(result_object, model); - 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); + PHALCON_INIT_NVAR(simple_column_map); + phalcon_call_method_p1_key(simple_column_map, meta_data, "getcolumnmap", model, 213063537UL); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, addModuleResource){ - - zval *module, *handler, *prefix = NULL, *scope; ->>>>>>> 1.2.2 - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - - -======= - phalcon_fetch_params(1, 2, 1, &module, &handler, &prefix); + PHALCON_INIT_NVAR(is_keeping_snapshots); + phalcon_call_method_p1_key(is_keeping_snapshots, manager, "iskeepingsnapshots", model, 2646609383UL); + } - if (!prefix) { - PHALCON_INIT_VAR(prefix); - } + 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); - 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; + RETURN_CTOR(resultset); } - 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); + 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_THIS(); + RETURN_CTOR(resultset); } -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, handle){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _executeInsert){ - 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 *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; ->>>>>>> 1.2.2 - -PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_Exception){ - -<<<<<<< HEAD - 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_CollectionInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Micro, CollectionInterface, mvc_micro_collectioninterface, phalcon_mvc_micro_collectioninterface_method_entry); - - return SUCCESS; -} - - - - - - - - - - - - - + PHALCON_MM_GROW(); -======= - phalcon_fetch_params(1, 0, 1, &uri); + phalcon_fetch_params(1, 3, 0, &intermediate, &bind_params, &bind_types); - if (!uri) { - PHALCON_INIT_VAR(uri); - } + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch_quick_string(&model_name, intermediate, SS("model"), 238191286UL, PH_NOISY); - if (!zend_is_true(uri)) { - PHALCON_INIT_VAR(real_uri); - phalcon_call_method_key(real_uri, this_ptr, "getrewriteuri", 1631494103UL); + 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_CPY_WRT(real_uri, uri); + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); } - 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_VAR(connection); + phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "annotations", 1); + PHALCON_OBS_VAR(meta_data); + phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); - PHALCON_INIT_NVAR(annotations_service); - phalcon_call_method_p1_key(annotations_service, dependency_injector, "getshared", service, 1727570332UL); - } + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", model, 1013165772UL); - 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_VAR(automatic_fields); + ZVAL_BOOL(automatic_fields, 0); - PHALCON_INIT_NVAR(lower_controller_name); - phalcon_uncamelize(lower_controller_name, controller_name); + 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_INIT_NVAR(namespace_name); - phalcon_get_ns_class(namespace_name, handler, 0 TSRMLS_CC); - } else { - PHALCON_CPY_WRT(controller_name, handler); + PHALCON_OBS_VAR(values); + phalcon_array_fetch_quick_string(&values, intermediate, SS("values"), 1765818005UL, PH_NOISY); - PHALCON_INIT_NVAR(lower_controller_name); - phalcon_uncamelize(lower_controller_name, controller_name); + PHALCON_INIT_VAR(number_fields); + phalcon_fast_count(number_fields, fields TSRMLS_CC); - PHALCON_INIT_NVAR(namespace_name); - } + PHALCON_INIT_VAR(number_values); + phalcon_fast_count(number_values, values TSRMLS_CC); - phalcon_update_property_null(this_ptr, SL("_routePrefix") 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; + } - 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_VAR(dialect); + phalcon_call_method_key(dialect, connection, "getdialect", 3133083739UL); - PHALCON_INIT_NVAR(sufixed); - PHALCON_CONCAT_VV(sufixed, handler, controller_suffix); + PHALCON_INIT_VAR(double_colon); + ZVAL_STRING(double_colon, ":", 1); - PHALCON_INIT_NVAR(handler_annotations); - phalcon_call_method_p1_key(handler_annotations, annotations_service, "get", sufixed, 2090288933UL); + PHALCON_INIT_VAR(empty_string); + ZVAL_STRING(empty_string, "", 1); - 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_VAR(null_value); - PHALCON_INIT_NVAR(annotations); - phalcon_call_method_key(annotations, class_annotations, "getannotations", 163297043UL); - if (Z_TYPE_P(annotations) == IS_ARRAY) { + PHALCON_INIT_VAR(not_exists); + ZVAL_BOOL(not_exists, 0); - phalcon_is_iterable(annotations, &ah1, &hp1, 0, 0); + PHALCON_INIT_VAR(insert_values); + array_init(insert_values); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + phalcon_is_iterable(values, &ah0, &hp0, 0, 0); - PHALCON_GET_HVALUE(annotation); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - phalcon_call_method_p2_key(NULL, this_ptr, "processcontrollerannotation", controller_name, annotation, 1441174403UL); + PHALCON_GET_HKEY(number, ah0, hp0); + PHALCON_GET_HVALUE(value); - zend_hash_move_forward_ex(ah1, &hp1); - } + 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); - PHALCON_INIT_NVAR(method_annotations); - phalcon_call_method_key(method_annotations, handler_annotations, "getmethodsannotations", 2860599943UL); - if (Z_TYPE_P(method_annotations) == IS_ARRAY) { + switch (phalcon_get_intval(type)) { - PHALCON_INIT_NVAR(lowercased); - phalcon_uncamelize(lowercased, handler); + case 260: + PHALCON_INIT_NVAR(insert_value); + phalcon_call_method_p1_key(insert_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; - phalcon_is_iterable(method_annotations, &ah2, &hp2, 0, 0); + case 258: + PHALCON_INIT_NVAR(insert_value); + phalcon_call_method_p1_key(insert_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + case 259: + PHALCON_INIT_NVAR(insert_value); + phalcon_call_method_p1_key(insert_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; - PHALCON_GET_HKEY(method, ah2, hp2); - PHALCON_GET_HVALUE(collection); + case 322: + PHALCON_CPY_WRT(insert_value, null_value); + break; - if (Z_TYPE_P(collection) == IS_OBJECT) { + 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(annotations); - phalcon_call_method_key(annotations, collection, "getannotations", 163297043UL); + PHALCON_INIT_NVAR(insert_expr); + phalcon_call_method_p1_key(insert_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); - phalcon_is_iterable(annotations, &ah3, &hp3, 0, 0); + 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; + } - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { + PHALCON_OBS_NVAR(insert_value); + phalcon_array_fetch(&insert_value, bind_params, wildcard, PH_NOISY); + break; - PHALCON_GET_HVALUE(annotation); + 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_call_method_p5_key(NULL, this_ptr, "processactionannotation", module_name, namespace_name, lower_controller_name, method, annotation, 3018293437UL); + PHALCON_INIT_NVAR(insert_expr); + phalcon_call_method_p1_key(insert_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); - zend_hash_move_forward_ex(ah3, &hp3); - } + 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; - zend_hash_move_forward_ex(ah2, &hp2); - } + 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); - zend_hash_move_forward_ex(ah0, &hp0); - } + break; } - 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_OBS_NVAR(field_name); + phalcon_array_fetch(&field_name, fields, number, PH_NOISY); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, processControllerAnnotation){ - - zval *handler, *annotation, *name, *position, *value; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - - -======= - phalcon_fetch_params(1, 2, 0, &handler, &annotation); + if (PHALCON_IS_TRUE(automatic_fields)) { - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, annotation, "getname", 4286441094UL); + 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); + } - if (PHALCON_IS_STRING(name, "RoutePrefix")) { - PHALCON_INIT_VAR(position); - ZVAL_LONG(position, 0); + phalcon_array_update_zval(&insert_values, attribute_name, &insert_value, PH_COPY | PH_SEPARATE); - 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); + zend_hash_move_forward_ex(ah0, &hp0); } - 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; ->>>>>>> 1.2.2 - -#ifdef HAVE_CONFIG_H -#endif - -<<<<<<< HEAD - - - - - - -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_INIT_VAR(base_model); + phalcon_call_method_p1_key(base_model, manager, "load", model_name, 266329637UL); - 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(insert_model); + if (phalcon_clone(insert_model, base_model TSRMLS_CC) == FAILURE) { 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); - } - phalcon_update_property_this_quick(this_ptr, SL("_handler"), handler, 1505752930UL TSRMLS_CC); - } + PHALCON_INIT_VAR(success); + phalcon_call_method_p1_key(success, insert_model, "create", insert_values, 3654027737UL); - 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); + 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_CALL_USER_FUNC_ARRAY(return_value, call_handler, arguments); 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(); - -#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_fetch_params(1, 4, 0, &model, &intermediate, &bind_params, &bind_types); - phalcon_update_property_this_quick(this_ptr, SL("_defaultHandler"), controller_name, 2940762855UL TSRMLS_CC); + PHALCON_OBS_VAR(selected_tables); + phalcon_array_fetch_quick_string(&selected_tables, intermediate, SS("tables"), 3465666720UL, PH_NOISY); -} - -static PHP_METHOD(Phalcon_Mvc_Dispatcher, setControllerName){ - - zval *controller_name; - - phalcon_fetch_params(0, 1, 0, &controller_name); + PHALCON_OBS_VAR(selected_models); + phalcon_array_fetch_quick_string(&selected_models, intermediate, SS("models"), 3565348937UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), controller_name, 2743819555UL TSRMLS_CC); + PHALCON_INIT_VAR(source); + phalcon_call_method_key(source, model, "getsource", 2025234358UL); -} - -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); + PHALCON_INIT_VAR(model_name); + phalcon_get_class(model_name, model, 0 TSRMLS_CC); - if (!exception_code) { - PHALCON_INIT_VAR(exception_code); - ZVAL_LONG(exception_code, 0); - } else { - PHALCON_SEPARATE_PARAM(exception_code); - } + PHALCON_INIT_VAR(select_column); + array_init_size(select_column, 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_INIT_NVAR(exception_code); - ZVAL_LONG(exception_code, 0); + 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(exception_message); - ZVAL_STRING(exception_message, "A dependency injection container is required to access the 'response' service", 1); + PHALCON_INIT_VAR(selected_columns); + array_init_size(selected_columns, 1); + phalcon_array_append(&selected_columns, select_column, PH_SEPARATE); - 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_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_throw_exception(exception TSRMLS_CC); - return; + 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); } - 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); + 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(status_message); - ZVAL_STRING(status_message, "Not Found", 1); - phalcon_call_method_p2_key(NULL, response, "setstatuscode", status_code, status_message, 1498183248UL); + PHALCON_INIT_VAR(type_select); + ZVAL_LONG(type_select, 309); - 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(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_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(query); + object_init_ex(query, phalcon_mvc_model_query_ce); + phalcon_call_method_key(NULL, query, "__construct", 1107214344UL); - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "dispatch:beforeException", 1); + 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(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_INIT_VAR(records); + phalcon_call_method_p2_key(records, query, "execute", bind_params, bind_types, 3117639032UL); - phalcon_throw_exception(exception TSRMLS_CC); - return; + RETURN_CCTOR(records); } -static PHP_METHOD(Phalcon_Mvc_Dispatcher, _handleException){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _executeUpdate){ - zval *exception, *events_manager, *event_name; - zval *status; -======= - 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); + 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_INIT_NVAR(methods); - ZVAL_STRING(methods, "OPTIONS", 1); - } - } - } - } + 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; } - if (PHALCON_IS_TRUE(is_route)) { + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); - PHALCON_OBS_VAR(action_suffix); - phalcon_read_property_this_quick(&action_suffix, this_ptr, SL("_actionSuffix"), 879621975UL, 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_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_manager"), 4140832863UL, PH_NOISY_CC); - PHALCON_INIT_VAR(empty_str); - ZVAL_STRING(empty_str, "", 1); + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); + } - PHALCON_INIT_VAR(real_action_name); - phalcon_fast_str_replace(real_action_name, action_suffix, empty_str, action); + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); - PHALCON_INIT_VAR(action_name); - phalcon_fast_strtolower(action_name, real_action_name); + PHALCON_INIT_VAR(dialect); + phalcon_call_method_key(dialect, connection, "getdialect", 3133083739UL); - PHALCON_OBS_VAR(route_prefix); - phalcon_read_property_this_quick(&route_prefix, this_ptr, SL("_routePrefix"), 2004814177UL, PH_NOISY_CC); + PHALCON_INIT_VAR(double_colon); + ZVAL_STRING(double_colon, ":", 1); - PHALCON_INIT_VAR(parameter); - ZVAL_STRING(parameter, "paths", 1); + PHALCON_INIT_VAR(empty_string); + ZVAL_STRING(empty_string, "", 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); - } + PHALCON_OBS_VAR(fields); + phalcon_array_fetch_quick_string(&fields, intermediate, SS("fields"), 2881624156UL, PH_NOISY); - if (Z_TYPE_P(module) == IS_STRING) { - phalcon_array_update_quick_string(&paths, SS("module"), 3565923467UL, &module, PH_COPY | PH_SEPARATE); - } + PHALCON_OBS_VAR(values); + phalcon_array_fetch_quick_string(&values, intermediate, SS("values"), 1765818005UL, PH_NOISY); - if (Z_TYPE_P(namespace) == IS_STRING) { - phalcon_array_update_quick_string(&paths, SS("namespace"), 545490034UL, &namespace, PH_COPY | PH_SEPARATE); - } + PHALCON_INIT_VAR(update_values); + array_init(update_values); - 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_CPY_WRT(select_bind_params, bind_params); + PHALCON_CPY_WRT(select_bind_types, bind_types); - PHALCON_INIT_VAR(position); - ZVAL_LONG(position, 0); + PHALCON_INIT_VAR(null_value); - PHALCON_INIT_VAR(value); - phalcon_call_method_p1_key(value, annotation, "getargument", position, 3874091272UL); + phalcon_is_iterable(fields, &ah0, &hp0, 0, 0); - 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(uri); - PHALCON_CONCAT_VV(uri, route_prefix, action_name); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(route); - phalcon_call_method_p2_key(route, this_ptr, "add", uri, paths, 2090071694UL); - if (Z_TYPE_P(methods) == IS_NULL) { + PHALCON_GET_HKEY(number, ah0, hp0); + PHALCON_GET_HVALUE(field); - PHALCON_INIT_NVAR(parameter); - ZVAL_STRING(parameter, "methods", 1); + PHALCON_OBS_NVAR(field_name); + phalcon_array_fetch_quick_string(&field_name, field, SS("name"), 268211462UL, PH_NOISY); - 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_OBS_NVAR(value); + phalcon_array_fetch(&value, values, number, PH_NOISY); - PHALCON_INIT_NVAR(parameter); - ZVAL_STRING(parameter, "converts", 1); + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, value, SS("type"), 276192743UL, PH_NOISY); - PHALCON_INIT_VAR(converts); - phalcon_call_method_p1_key(converts, annotation, "getnamedparameter", parameter, 3202516043UL); - if (Z_TYPE_P(converts) == IS_ARRAY) { + PHALCON_OBS_NVAR(expr_value); + phalcon_array_fetch_quick_string(&expr_value, value, SS("value"), 574111618UL, PH_NOISY); - phalcon_is_iterable(converts, &ah0, &hp0, 0, 0); + switch (phalcon_get_intval(type)) { - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + case 260: + PHALCON_INIT_NVAR(update_value); + phalcon_call_method_p1_key(update_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; - PHALCON_GET_HKEY(param, ah0, hp0); - PHALCON_GET_HVALUE(convert); + case 258: + PHALCON_INIT_NVAR(update_value); + phalcon_call_method_p1_key(update_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; - phalcon_call_method_p2_key(NULL, route, "convert", param, convert, 1120996230UL); + case 259: + PHALCON_INIT_NVAR(update_value); + phalcon_call_method_p1_key(update_value, dialect, "getsqlexpression", expr_value, 3377787077UL); + break; - zend_hash_move_forward_ex(ah0, &hp0); - } + 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(parameter); - ZVAL_STRING(parameter, "conversors", 1); + PHALCON_INIT_NVAR(update_expr); + phalcon_call_method_p1_key(update_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); - PHALCON_INIT_NVAR(converts); - phalcon_call_method_p1_key(converts, annotation, "getnamedparameter", parameter, 3202516043UL); - if (Z_TYPE_P(converts) == IS_ARRAY) { + 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_is_iterable(converts, &ah1, &hp1, 0, 0); + break; - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + 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_GET_HKEY(conversor_param, ah1, hp1); - PHALCON_GET_HVALUE(convert); + PHALCON_INIT_NVAR(update_expr); + phalcon_call_method_p1_key(update_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); - phalcon_call_method_p2_key(NULL, route, "convert", conversor_param, convert, 1120996230UL); + 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; + } - zend_hash_move_forward_ex(ah1, &hp1); - } + break; - } + default: + PHALCON_INIT_NVAR(update_expr); + phalcon_call_method_p1_key(update_expr, dialect, "getsqlexpression", expr_value, 3377787077UL); - PHALCON_INIT_NVAR(parameter); - ZVAL_STRING(parameter, "name", 1); + 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_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); } + phalcon_array_update_zval(&update_values, field_name, &update_value, PH_COPY | PH_SEPARATE); - RETURN_MM_TRUE; + zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, setControllerSuffix){ ->>>>>>> 1.2.2 - - zval *controller_suffix; - -<<<<<<< HEAD - 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(records); + phalcon_call_method_p4_key(records, this_ptr, "_getrelatedrecords", model, intermediate, select_bind_params, select_bind_types, 1071693079UL); - PHALCON_INIT_VAR(event_name); - ZVAL_STRING(event_name, "dispatch:beforeException", 1); + 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); - 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; - } + RETURN_MM(); } - 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); -======= - phalcon_fetch_params(0, 1, 0, &controller_suffix); - - phalcon_update_property_this_quick(this_ptr, SL("_controllerSuffix"), controller_suffix, 2437326621UL TSRMLS_CC); + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, setActionSuffix){ - - zval *action_suffix; - - phalcon_fetch_params(0, 1, 0, &action_suffix); + phalcon_call_method_key(NULL, connection, "begin", 4090922282UL); + phalcon_call_method_key(NULL, records, "rewind", 1064078190UL); - phalcon_update_property_this_quick(this_ptr, SL("_actionSuffix"), action_suffix, 879621975UL TSRMLS_CC); + while (1) { -} - -static PHP_METHOD(Phalcon_Mvc_Router_Annotations, getResources){ - - - RETURN_MEMBER_QUICK(this_ptr, "_handlers", 2445210229UL); ->>>>>>> 1.2.2 -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Mvc_UrlInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, UrlInterface, mvc_urlinterface, phalcon_mvc_urlinterface_method_entry); -======= - ->>>>>>> 1.2.2 - - - -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_INIT_NVAR(r0); + phalcon_call_method_key(r0, records, "valid", 574098517UL); + if (PHALCON_IS_NOT_FALSE(r0)) { + } else { + break; + } - PHALCON_MM_RESTORE(); -} - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Security_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Security, Exception, security_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Validation){ - - PHALCON_REGISTER_CLASS_EX(Phalcon, Validation, validation, "phalcon\\di\\injectable", phalcon_validation_method_entry, 0); - - 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); -======= -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); ->>>>>>> 1.2.2 - - return SUCCESS; -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Validation, __construct){ - - zval *validators = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &validators); + PHALCON_INIT_NVAR(record); + phalcon_call_method_key(record, records, "current", 431662984UL); - if (!validators) { - PHALCON_INIT_VAR(validators); - } + 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); - 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; + RETURN_MM(); } - phalcon_update_property_this_quick(this_ptr, SL("_validators"), validators, 2342846045UL TSRMLS_CC); - } - if (phalcon_method_quick_exists_ex(this_ptr, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); + phalcon_call_method_key(NULL, records, "next", 268367684UL); } -======= -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); ->>>>>>> 1.2.2 + phalcon_call_method_key(NULL, connection, "commit", 3546528686UL); - PHALCON_MM_RESTORE(); + 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(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Validation, validate){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, _executeDelete){ - 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; + 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, 0, 2, &data, &entity); - - if (!data) { - PHALCON_INIT_VAR(data); - } - - if (!entity) { - PHALCON_INIT_VAR(entity); - } + phalcon_fetch_params(1, 3, 0, &intermediate, &bind_params, &bind_types); - 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"); + 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_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); + PHALCON_OBS_VAR(model_name); + phalcon_array_fetch_long(&model_name, models, 0, PH_NOISY); - if (phalcon_method_quick_exists_ex(this_ptr, SS("beforevalidation"), 4025473891UL TSRMLS_CC) == SUCCESS) { + 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_VAR(status); - phalcon_call_method_p3_key(status, this_ptr, "beforevalidation", data, entity, messages, 4025473891UL); - if (PHALCON_IS_FALSE(status)) { - RETURN_CCTOR(status); - } + PHALCON_INIT_NVAR(model); + phalcon_call_method_p1_key(model, manager, "load", model_name, 266329637UL); } - 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_INIT_VAR(records); + phalcon_call_method_p4_key(records, this_ptr, "_getrelatedrecords", model, intermediate, bind_params, bind_types, 1071693079UL); - PHALCON_INIT_VAR(cancel_on_fail); - ZVAL_STRING(cancel_on_fail, "cancelOnFail", 1); + if (!phalcon_fast_count_ev(records TSRMLS_CC)) { + PHALCON_INIT_VAR(success); + ZVAL_BOOL(success, 1); - phalcon_is_iterable(validators, &ah0, &hp0, 0, 0); + 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); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + RETURN_MM(); + } - PHALCON_GET_HVALUE(scope); + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, model, "getwriteconnection", 4280185952UL); - if (Z_TYPE_P(scope) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The validator scope is not valid"); - return; - } + phalcon_call_method_key(NULL, connection, "begin", 4090922282UL); + phalcon_call_method_key(NULL, records, "rewind", 1064078190UL); - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, scope, 0, PH_NOISY); + while (1) { - 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; + PHALCON_INIT_NVAR(r0); + phalcon_call_method_key(r0, records, "valid", 574098517UL); + if (PHALCON_IS_NOT_FALSE(r0)) { + } else { + break; } - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, validator, "validate", this_ptr, attribute, 2654098287UL); + PHALCON_INIT_NVAR(record); + phalcon_call_method_key(record, records, "current", 431662984UL); - if (PHALCON_IS_FALSE(status)) { + 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); - 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; - } + RETURN_MM(); } - zend_hash_move_forward_ex(ah0, &hp0); - } - - 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); + phalcon_call_method_key(NULL, records, "next", 268367684UL); } - RETURN_CCTOR(messages); -} - -static PHP_METHOD(Phalcon_Validation, add){ - - zval *attribute, *validator, *scope; -======= -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){ ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - phalcon_fetch_params(1, 2, 0, &attribute, &validator); + phalcon_call_method_key(NULL, connection, "commit", 3546528686UL); - if (Z_TYPE_P(attribute) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The attribute must be a string"); - return; - } - if (Z_TYPE_P(validator) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The validator must be an object"); - return; - } + PHALCON_INIT_NVAR(success); + ZVAL_BOOL(success, 1); - 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); + PHALCON_INIT_NVAR(null_value); + ZVAL_BOOL(null_value, 1); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Validation, setFilters){ - - zval *attribute, *filters; - - phalcon_fetch_params(0, 2, 0, &attribute, &filters); + 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_update_property_array(this_ptr, SL("_filters"), attribute, filters TSRMLS_CC); - RETURN_THISW(); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Validation, getFilters){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, execute){ - zval *attribute = NULL, *filters, *attribute_filters; + 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, 1, &attribute); + phalcon_fetch_params(1, 0, 2, &bind_params, &bind_types); - if (!attribute) { - PHALCON_INIT_VAR(attribute); + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); } - 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 (!bind_types) { + PHALCON_INIT_VAR(bind_types); } - RETURN_CCTOR(filters); -} - -static PHP_METHOD(Phalcon_Validation, getValidators){ -======= - 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); + PHALCON_OBS_VAR(unique_row); + phalcon_read_property_this_quick(&unique_row, this_ptr, SL("_uniqueRow"), 1221667347UL, PH_NOISY_CC); - if (!lazy) { - PHALCON_INIT_VAR(lazy); - ZVAL_BOOL(lazy, 0); - } + 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; + } - 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){ ->>>>>>> 1.2.2 - - zval *lazy; - -<<<<<<< HEAD - 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); -} - -static PHP_METHOD(Phalcon_Validation, appendMessage){ - - zval *message, *messages; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &message); + 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_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); + 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 (Z_TYPE_P(entity) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "The entity must be an object"); - 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(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_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); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Validation, getValue){ - - zval *attribute, *entity, *method, *value = NULL, *data, *values; - zval *filters, *field_filters, *service_name; - zval *dependency_injector = NULL, *filter_service; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &attribute); + 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_OBS_VAR(entity); - phalcon_read_property_this_quick(&entity, this_ptr, SL("_entity"), 2413912609UL, PH_NOISY_CC); + 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; + } - if (Z_TYPE_P(entity) == IS_OBJECT) { + PHALCON_INIT_VAR(is_fresh); + ZVAL_BOOL(is_fresh, 0); + phalcon_call_method_p1_key(NULL, result, "setisfresh", is_fresh, 2789062661UL); - 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); + if (zend_is_true(unique_row)) { + PHALCON_INIT_VAR(prepared_result); + phalcon_call_method_key(prepared_result, result, "getfirst", 3710205613UL); } 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); - } + PHALCON_CPY_WRT(prepared_result, result); } - } - - 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 (Z_TYPE_P(data) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "There is no data to validate"); - return; + RETURN_CCTOR(prepared_result); } - } - 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); + phalcon_update_property_this_quick(this_ptr, SL("_cache"), cache, 2191407384UL TSRMLS_CC); } - PHALCON_INIT_NVAR(value); + PHALCON_INIT_VAR(intermediate); + phalcon_call_method_key(intermediate, this_ptr, "parse", 339512704UL); - 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); + 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 { - 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_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); } - if (Z_TYPE_P(value) != IS_NULL) { + PHALCON_OBS_VAR(type); + phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); - 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)) { + switch (phalcon_get_intval(type)) { - PHALCON_OBS_VAR(field_filters); - phalcon_array_fetch(&field_filters, filters, attribute, PH_NOISY); - if (zend_is_true(field_filters)) { + case 309: + PHALCON_INIT_NVAR(result); + phalcon_call_method_p3_key(result, this_ptr, "_executeselect", intermediate, merged_params, merged_types, 125194679UL); + break; - PHALCON_INIT_VAR(service_name); - ZVAL_STRING(service_name, "filter", 1); + case 306: + PHALCON_INIT_NVAR(result); + phalcon_call_method_p3_key(result, this_ptr, "_executeinsert", intermediate, merged_params, merged_types, 455953196UL); + break; - PHALCON_INIT_VAR(dependency_injector); - phalcon_call_method_key(dependency_injector, this_ptr, "getdi", 4287060818UL); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + case 300: + PHALCON_INIT_NVAR(result); + phalcon_call_method_p3_key(result, this_ptr, "_executeupdate", intermediate, merged_params, merged_types, 3129006842UL); + break; - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + case 303: + PHALCON_INIT_NVAR(result); + phalcon_call_method_p3_key(result, this_ptr, "_executedelete", intermediate, merged_params, merged_types, 2228029642UL); + break; - 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; - } - } + 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; - 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(); - } - } + 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); + } - phalcon_update_property_array(this_ptr, SL("_values"), attribute, value TSRMLS_CC); + 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(value); + 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); } - RETURN_MM_NULL(); -======= - phalcon_fetch_params(0, 1, 0, &lazy); + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } - phalcon_update_property_this_quick(this_ptr, SL("_lazy"), lazy, 3981620804UL TSRMLS_CC); - RETURN_THISW(); + 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_Micro_Collection, isLazy){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, setType){ + zval *type; - RETURN_MEMBER_QUICK(this_ptr, "_lazy", 3981620804UL); + 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_Micro_Collection, getHandler){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, getType){ - RETURN_MEMBER_QUICK(this_ptr, "_handler", 1505752930UL); + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, map){ - - zval *route_pattern, *handler, *method; +static PHP_METHOD(Phalcon_Mvc_Model_Query, setBindParams){ - PHALCON_MM_GROW(); + zval *bind_params; - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + phalcon_fetch_params(0, 1, 0, &bind_params); - PHALCON_INIT_VAR(method); - phalcon_call_method_p3_key(return_value, this_ptr, "_addmap", method, route_pattern, handler, 1132802123UL); - RETURN_MM(); ->>>>>>> 1.2.2 + 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_Micro_Collection, get){ - - zval *route_pattern, *handler, *method; +static PHP_METHOD(Phalcon_Mvc_Model_Query, getBindParams){ - 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(); + RETURN_MEMBER_QUICK(this_ptr, "_bindParams", 2293392709UL); } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, post){ - - zval *route_pattern, *handler, *method; +static PHP_METHOD(Phalcon_Mvc_Model_Query, setBindTypes){ - PHALCON_MM_GROW(); + zval *bind_types; - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + phalcon_fetch_params(0, 1, 0, &bind_types); - 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(); + 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_Micro_Collection, put){ +static PHP_METHOD(Phalcon_Mvc_Model_Query, getBindTypes){ - zval *route_pattern, *handler, *method; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_bindTypes", 514734038UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model_Query, setIntermediate){ -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Version){ + zval *intermediate; - PHALCON_REGISTER_CLASS(Phalcon, Version, version, phalcon_version_method_entry, 0); -======= - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + phalcon_fetch_params(0, 1, 0, &intermediate); - 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(); + phalcon_update_property_this_quick(this_ptr, SL("_intermediate"), intermediate, 1829292799UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, patch){ - - zval *route_pattern, *handler, *method; ->>>>>>> 1.2.2 +static PHP_METHOD(Phalcon_Mvc_Model_Query, getIntermediate){ - 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(); + RETURN_MEMBER_QUICK(this_ptr, "_intermediate", 1829292799UL); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Version, _getVersion){ - zval *version; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(version); - array_init_size(version, 5); - add_next_index_long(version, 1); - add_next_index_long(version, 2); - add_next_index_long(version, 1); - add_next_index_long(version, 4); - add_next_index_long(version, 0); - RETURN_CTOR(version); -} -static PHP_METHOD(Phalcon_Version, get){ +#ifdef HAVE_CONFIG_H +#endif - zval *version, *major, *medium, *minor, *special, *special_number; - zval *result, *suffix = NULL; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(version); - PHALCON_CALL_SELF(version, this_ptr, "_getversion"); - PHALCON_OBS_VAR(major); - phalcon_array_fetch_long(&major, version, 0, PH_NOISY); - PHALCON_OBS_VAR(medium); - phalcon_array_fetch_long(&medium, version, 1, PH_NOISY); -======= -static PHP_METHOD(Phalcon_Mvc_Micro_Collection, head){ - zval *route_pattern, *handler, *method; - PHALCON_MM_GROW(); +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Behavior){ - 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(); + 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_Micro_Collection, delete){ +static PHP_METHOD(Phalcon_Mvc_Model_Behavior, __construct){ - zval *route_pattern, *handler, *method; + zval *options = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + phalcon_fetch_params(1, 0, 1, &options); - 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(); + 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_Micro_Collection, options){ +static PHP_METHOD(Phalcon_Mvc_Model_Behavior, mustTakeAction){ - zval *route_pattern, *handler, *method; + zval *event_name, *options; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); + phalcon_fetch_params(1, 1, 0, &event_name); - 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(); + 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); + } + RETURN_MM_NULL(); + } + + RETURN_CCTOR(options); +} +static PHP_METHOD(Phalcon_Mvc_Model_Behavior, notify){ -#ifdef HAVE_CONFIG_H -#endif + zval *type, *model; + phalcon_fetch_params(0, 2, 0, &type, &model); + + RETURN_NULL(); +} +static PHP_METHOD(Phalcon_Mvc_Model_Behavior, missingMethod){ -PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_MiddlewareInterface){ + zval *model, *method, *arguments = NULL; - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Micro, MiddlewareInterface, mvc_micro_middlewareinterface, phalcon_mvc_micro_middlewareinterface_method_entry); + PHALCON_MM_GROW(); - return SUCCESS; + phalcon_fetch_params(1, 2, 1, &model, &method, &arguments); + + if (!arguments) { + PHALCON_INIT_VAR(arguments); + } + + RETURN_MM_NULL(); } - #ifdef HAVE_CONFIG_H #endif ->>>>>>> 1.2.2 - - PHALCON_OBS_VAR(minor); - phalcon_array_fetch_long(&minor, version, 2, PH_NOISY); - -<<<<<<< HEAD - PHALCON_OBS_VAR(special); - phalcon_array_fetch_long(&special, version, 3, PH_NOISY); - - PHALCON_OBS_VAR(special_number); - phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY); - PHALCON_INIT_VAR(result); - PHALCON_CONCAT_VSVSVS(result, major, ".", medium, ".", minor, " "); - - switch (phalcon_get_intval(special)) { -======= +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); -PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_Exception){ + return SUCCESS; +} - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Micro, Exception, mvc_micro_exception, "phalcon\\exception", NULL, 0); ->>>>>>> 1.2.2 - case 1: - PHALCON_INIT_VAR(suffix); - PHALCON_CONCAT_SV(suffix, "ALPHA ", special_number); - break; -<<<<<<< HEAD - case 2: - PHALCON_INIT_NVAR(suffix); - PHALCON_CONCAT_SV(suffix, "BETA ", special_number); - break; - case 3: - PHALCON_INIT_NVAR(suffix); - PHALCON_CONCAT_SV(suffix, "RC ", special_number); - break; - default: - PHALCON_INIT_NVAR(suffix); - ZVAL_STRING(suffix, "", 1); - break; - } - phalcon_concat_self(&result, suffix TSRMLS_CC); - phalcon_fast_trim(return_value, result, PHALCON_TRIM_BOTH TSRMLS_CC); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Version, getId){ - zval *version, *major, *medium, *minor, *special, *special_number; - zval *format, *real_medium, *real_minor; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(version); - PHALCON_CALL_SELF(version, this_ptr, "_getversion"); - PHALCON_OBS_VAR(major); - phalcon_array_fetch_long(&major, version, 0, PH_NOISY); - PHALCON_OBS_VAR(medium); - phalcon_array_fetch_long(&medium, version, 1, PH_NOISY); - PHALCON_OBS_VAR(minor); - phalcon_array_fetch_long(&minor, version, 2, PH_NOISY); - PHALCON_OBS_VAR(special); - phalcon_array_fetch_long(&special, version, 3, PH_NOISY); +#ifdef HAVE_CONFIG_H +#endif - PHALCON_OBS_VAR(special_number); - phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY); - PHALCON_INIT_VAR(format); - ZVAL_STRING(format, "%02s", 1); -======= -#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); -PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_CollectionInterface){ + 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); - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Micro, CollectionInterface, mvc_micro_collectioninterface, phalcon_mvc_micro_collectioninterface_method_entry); + 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(); +} ->>>>>>> 1.2.2 +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, setDI){ - PHALCON_INIT_VAR(real_medium); - phalcon_call_func_p2(real_medium, "sprintf", format, medium); + zval *dependency_injector; -<<<<<<< HEAD - PHALCON_INIT_VAR(real_minor); - phalcon_call_func_p2(real_minor, "sprintf", format, minor); - PHALCON_CONCAT_VVVVV(return_value, major, real_medium, real_minor, special, special_number); - RETURN_MM(); + 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); +} ->>>>>>> 1.2.2 +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){ -<<<<<<< HEAD -#ifdef HAVE_CONFIG_H -#endif -======= ->>>>>>> 1.2.2 + 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){ -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Loader){ + RETURN_MEMBER_QUICK(this_ptr, "_rollbackPendent", 1836882012UL); +} - PHALCON_REGISTER_CLASS(Phalcon, Loader, loader, phalcon_loader_method_entry, 0); +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, has){ - 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); + zval *zero, *number; - zend_class_implements(phalcon_loader_ce TSRMLS_CC, 1, phalcon_events_eventsawareinterface_ce); + PHALCON_MM_GROW(); - return SUCCESS; + 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_Loader, __construct){ -======= -#ifdef HAVE_CONFIG_H -#endif +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){ ->>>>>>> 1.2.2 + zval *auto_begin = NULL, *dependency_injector, *number; + zval *transactions, *transaction = NULL, *false_value = NULL; + zval *service; + HashTable *ah0; + HashPosition hp0; + zval **hd; - zval *extensions; + PHALCON_MM_GROW(); -PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_LazyLoader){ + 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); + } + + } + } + + 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); +} - PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Micro, LazyLoader, mvc_micro_lazyloader, phalcon_mvc_micro_lazyloader_method_entry, 0); +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, rollbackPendent){ - 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; + PHALCON_MM_GROW(); + + phalcon_call_method_key(NULL, this_ptr, "rollback", 3199546639UL); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, commit){ - zval *definition; + zval *transactions, *transaction = NULL, *connection = NULL; + zval *is_under_transaction = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; -<<<<<<< HEAD - 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_fetch_params(0, 1, 0, &definition); + 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); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } - 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); ->>>>>>> 1.2.2 + PHALCON_MM_RESTORE(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Loader, setEventsManager){ -======= -static PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __call){ +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, rollback){ - zval *method, *arguments, *handler = NULL, *definition; - zval *call_handler; - zend_class_entry *ce0; ->>>>>>> 1.2.2 + zval *collect = NULL, *transactions, *transaction = NULL, *connection = NULL; + zval *is_under_transaction = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - zval *events_manager; + PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(0, 1, 0, &events_manager); + phalcon_fetch_params(1, 0, 1, &collect); - phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); + 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); + } + + if (zend_is_true(collect)) { + phalcon_call_method_p1_key(NULL, this_ptr, "_collecttransaction", transaction, 3516646160UL); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Loader, getEventsManager){ - - - RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); -} +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, notifyRollback){ -static PHP_METHOD(Phalcon_Loader, setExtensions){ + zval *transaction; - zval *extensions; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &extensions); + phalcon_fetch_params(1, 1, 0, &transaction); - 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_call_method_p1_key(NULL, this_ptr, "_collecttransaction", transaction, 3516646160UL); - RETURN_THISW(); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Loader, getExtensions){ +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, notifyCommit){ + zval *transaction; - RETURN_MEMBER_QUICK(this_ptr, "_extensions", 726159316UL); + 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_Loader, registerNamespaces){ +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Manager, _collectTransaction){ - zval *namespaces, *merge = NULL, *current_namespaces; - zval *merged_namespaces = NULL; + zval *transaction, *transactions, *new_transactions; + zval *managed_transaction = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &namespaces, &merge); + phalcon_fetch_params(1, 1, 0, &transaction); - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } + 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 (Z_TYPE_P(namespaces) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter namespaces must be an array"); - return; - } - if (zend_is_true(merge)) { + PHALCON_INIT_VAR(new_transactions); + array_init(new_transactions); - 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_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("_namespaces"), merged_namespaces, 3363620132UL TSRMLS_CC); - } else { - phalcon_update_property_this_quick(this_ptr, SL("_namespaces"), namespaces, 3363620132UL TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_transactions"), new_transactions, 3308612605UL TSRMLS_CC); } - RETURN_THIS(); -======= - phalcon_fetch_params(1, 2, 0, &method, &arguments); + 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_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_is_iterable(transactions, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(handler); - object_init_ex(handler, ce0); - if (phalcon_has_constructor(handler TSRMLS_CC)) { - phalcon_call_method_key(NULL, handler, "__construct", 1107214344UL); + 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_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_update_property_null(this_ptr, SL("_transactions") TSRMLS_CC); + } - PHALCON_CALL_USER_FUNC_ARRAY(return_value, call_handler, arguments); - RETURN_MM(); + PHALCON_MM_RESTORE(); } @@ -112348,241 +36321,159 @@ static PHP_METHOD(Phalcon_Loader, registerNamespaces){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction_Exception){ -PHALCON_INIT_CLASS(Phalcon_Mvc_Dispatcher){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\Transaction, Exception, mvc_model_transaction_exception, "phalcon\\mvc\\model\\exception", NULL, 0); - PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, Dispatcher, mvc_dispatcher, "phalcon\\dispatcher", phalcon_mvc_dispatcher_method_entry, 0); + return SUCCESS; +} - 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; +#ifdef HAVE_CONFIG_H +#endif - 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); - -} +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction_Failed){ -static PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerName){ + 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_MEMBER_QUICK(this_ptr, "_handlerName", 2743819555UL); + return SUCCESS; } -static PHP_METHOD(Phalcon_Mvc_Dispatcher, _throwDispatchException){ +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Failed, __construct){ - 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; + zval *message, *record; 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_fetch_params(1, 2, 0, &message, &record); - 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_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_throw_exception(exception TSRMLS_CC); - return; + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Mvc_Dispatcher, _handleException){ +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Failed, getRecordMessages){ - zval *exception, *events_manager, *event_name; - zval *status; + zval *record = NULL, *messages; 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_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_MM_RESTORE(); + PHALCON_INIT_VAR(messages); + phalcon_call_method_key(messages, this_ptr, "getmessage", 4288675242UL); + + RETURN_CCTOR(messages); } -static PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerClass){ - +static PHP_METHOD(Phalcon_Mvc_Model_Transaction_Failed, getRecord){ - PHALCON_MM_GROW(); - phalcon_call_method_key(return_value, this_ptr, "gethandlername", 1725429572UL); - RETURN_MM(); + RETURN_MEMBER_QUICK(this_ptr, "_record", 1650960579UL); } -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 -#ifdef HAVE_CONFIG_H -#endif +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Row){ -PHALCON_INIT_CLASS(Phalcon_Mvc_UrlInterface){ + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Row, mvc_model_row, phalcon_mvc_model_row_method_entry, 0); - PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, UrlInterface, mvc_urlinterface, phalcon_mvc_urlinterface_method_entry); + zend_class_implements(phalcon_mvc_model_row_ce TSRMLS_CC, 2, zend_ce_arrayaccess, phalcon_mvc_model_resultinterface_ce); return SUCCESS; ->>>>>>> 1.2.2 } -static PHP_METHOD(Phalcon_Loader, getNamespaces){ +static PHP_METHOD(Phalcon_Mvc_Model_Row, setDirtyState){ + zval *dirty_state; - RETURN_MEMBER_QUICK(this_ptr, "_namespaces", 3363620132UL); + phalcon_fetch_params(0, 1, 0, &dirty_state); + + RETURN_FALSE; } -static PHP_METHOD(Phalcon_Loader, registerPrefixes){ - - zval *prefixes, *merge = NULL, *current_prefixes, *merged_prefixes = NULL; +static PHP_METHOD(Phalcon_Mvc_Model_Row, offsetExists){ - PHALCON_MM_GROW(); + zval *index; - phalcon_fetch_params(1, 1, 1, &prefixes, &merge); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } + phalcon_fetch_params(0, 1, 0, &index); - if (Z_TYPE_P(prefixes) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter prefixes must be an array"); - return; + if (phalcon_isset_property_zval(this_ptr, index TSRMLS_CC)) { + RETURN_TRUE; } - 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); - } + RETURN_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model_Row, offsetGet){ + + zval *index, *value; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &index); - 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); + 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); - RETURN_THIS(); + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Row is an immutable ArrayAccess object"); + return; } -static PHP_METHOD(Phalcon_Loader, getPrefixes){ +static PHP_METHOD(Phalcon_Mvc_Model_Row, offsetUnset){ + zval *offset; - RETURN_MEMBER_QUICK(this_ptr, "_prefixes", 900970058UL); + phalcon_fetch_params(0, 1, 0, &offset); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_model_exception_ce, "Row is an immutable ArrayAccess object"); + return; } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Loader, registerDirs){ -======= + + + + #ifdef HAVE_CONFIG_H #endif @@ -112591,55 +36482,68 @@ static PHP_METHOD(Phalcon_Loader, registerDirs){ -PHALCON_INIT_CLASS(Phalcon_Security_Exception){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Security, Exception, security_exception, "phalcon\\exception", NULL, 0); +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){ ->>>>>>> 1.2.2 - - zval *directories, *merge = NULL, *current_directories; - zval *merged_directories = NULL; + zval *record, *option = NULL, *field, *value, *flag, *is_valid; + zval *message = NULL, *type; PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 1, &directories, &merge); + phalcon_fetch_params(1, 1, 0, &record); - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); - if (Z_TYPE_P(directories) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter directories must be an array"); + 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; } - 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_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_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); + 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_THIS(); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Loader, getDirs){ -======= + + + #ifdef HAVE_CONFIG_H #endif @@ -112649,543 +36553,342 @@ static PHP_METHOD(Phalcon_Loader, getDirs){ -PHALCON_INIT_CLASS(Phalcon_Validation){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Inclusionin){ - PHALCON_REGISTER_CLASS_EX(Phalcon, Validation, validation, "phalcon\\di\\injectable", phalcon_validation_method_entry, 0); + 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_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); ->>>>>>> 1.2.2 + zend_class_implements(phalcon_mvc_model_validator_inclusionin_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - RETURN_MEMBER_QUICK(this_ptr, "_directories", 3207828897UL); + return SUCCESS; } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Loader, registerClasses){ +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Inclusionin, validate){ - zval *classes, *merge = NULL, *current_classes, *merged_classes = NULL; + 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, 1, &classes, &merge); + phalcon_fetch_params(1, 1, 0, &record); - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } + PHALCON_INIT_VAR(field); + ZVAL_STRING(field, "field", 1); - if (Z_TYPE_P(classes) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter classes must be an array"); + 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; } - 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_INIT_NVAR(field); + ZVAL_STRING(field, "domain", 1); - 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); -======= -static PHP_METHOD(Phalcon_Validation, __construct){ - - zval *validators = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &validators); + 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; + } - if (!validators) { - PHALCON_INIT_VAR(validators); + 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; } - 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_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_update_property_this_quick(this_ptr, SL("_validators"), validators, 2342846045UL TSRMLS_CC); - } - if (phalcon_method_quick_exists_ex(this_ptr, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { - phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); ->>>>>>> 1.2.2 + 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_THIS(); + RETURN_MM_TRUE; } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Loader, getClasses){ - RETURN_MEMBER_QUICK(this_ptr, "_classes", 3992428914UL); -} -static PHP_METHOD(Phalcon_Loader, register){ - zval *registered, *autoloader; +#ifdef HAVE_CONFIG_H +#endif - 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); - } - - 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); - } - - RETURN_THIS(); + +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_Loader, autoLoad){ +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Uniqueness, validate){ - 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 *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, &class_name); - - 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_fetch_params(1, 1, 0, &record); - 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(option); + ZVAL_STRING(option, "field", 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(field); + phalcon_call_method_p1_key(field, this_ptr, "getoption", option, 1191969182UL); - 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(dependency_injector); + phalcon_call_method_key(dependency_injector, record, "getdi", 4287060818UL); - if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; - } - RETURN_MM_TRUE; - } - } + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "modelsMetadata", 1); - PHALCON_OBS_VAR(extensions); - phalcon_read_property_this_quick(&extensions, this_ptr, SL("_extensions"), 726159316UL, PH_NOISY_CC); + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_p1_key(meta_data, dependency_injector, "getshared", service, 1727570332UL); - PHALCON_INIT_VAR(ds); - ZVAL_STRING(ds, PHALCON_DIRECTORY_SEPARATOR, 1); + PHALCON_INIT_VAR(bind_types); + array_init(bind_types); - PHALCON_INIT_VAR(namespace_separator); - ZVAL_STRING(namespace_separator, "\\", 1); + 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(empty_str); - ZVAL_STRING(empty_str, "", 1); + PHALCON_INIT_VAR(conditions); + array_init(conditions); - PHALCON_INIT_VAR(zero); - ZVAL_LONG(zero, 0); + PHALCON_INIT_VAR(bind_params); + array_init(bind_params); - 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_INIT_VAR(number); + ZVAL_LONG(number, 0); + if (Z_TYPE_P(field) == IS_ARRAY) { - phalcon_is_iterable(namespaces, &ah0, &hp0, 0, 0); + phalcon_is_iterable(field, &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; - } - - zend_hash_move_forward_ex(ah1, &hp1); - } + 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); } - 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)) { - - PHALCON_INIT_NVAR(fixed_directory); - phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC); - - phalcon_is_iterable(extensions, &ah3, &hp3, 0, 0); - - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == 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_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 259017035UL); - } + 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; + } - if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_NVAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", compose_field, 95450773UL); - 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(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_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; - } + 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(ah3, &hp3); - } + 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; } - - zend_hash_move_forward_ex(ah2, &hp2); + } else { + PHALCON_CPY_WRT(column_field, field); } - } - - 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); + 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_is_iterable(extensions, &ah5, &hp5, 0, 0); + PHALCON_INIT_NVAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); - while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { + 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_GET_HVALUE(extension); + 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_NVAR(file_path); - PHALCON_CONCAT_VVSV(file_path, fixed_directory, ns_class_name, ".", extension); + PHALCON_INIT_VAR(operation_made); + phalcon_call_method_key(operation_made, record, "getoperationmade", 408703981UL); + if (PHALCON_IS_LONG(operation_made, 2)) { - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC); + 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_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_INIT_VAR(primary_fields); + phalcon_call_method_p1_key(primary_fields, meta_data, "getprimarykeyattributes", record, 692945721UL); - if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) { + phalcon_is_iterable(primary_fields, &ah1, &hp1, 0, 0); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - 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_GET_HVALUE(primary_field); - if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; - } + 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; + } - RETURN_MM_TRUE; + 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; } - - zend_hash_move_forward_ex(ah5, &hp5); + } else { + PHALCON_CPY_WRT(attribute_field, primary_field); } - zend_hash_move_forward_ex(ah4, &hp4); - } - - } - - 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){ -======= -static PHP_METHOD(Phalcon_Validation, validate){ - - 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; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 2, &data, &entity); - - if (!data) { - PHALCON_INIT_VAR(data); - } - - if (!entity) { - PHALCON_INIT_VAR(entity); - } - - 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; - } - - phalcon_update_property_null(this_ptr, SL("_values") TSRMLS_CC); + PHALCON_INIT_NVAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", primary_field, 95450773UL); - PHALCON_INIT_VAR(messages); - object_init_ex(messages, phalcon_validation_message_group_ce); - phalcon_call_method_key(NULL, messages, "__construct", 1107214344UL); + 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); - if (phalcon_method_quick_exists_ex(this_ptr, SS("beforevalidation"), 4025473891UL TSRMLS_CC) == SUCCESS) { + 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); - 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); + zend_hash_move_forward_ex(ah1, &hp1); } - } - 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_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(join_conditions); + phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - 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(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_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, scope, 0, PH_NOISY); + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, record, 0 TSRMLS_CC); - 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; - } + phalcon_call_zval_str_static_p1(number, class_name, "count", params); + if (!PHALCON_IS_LONG(number, 0)) { - PHALCON_INIT_NVAR(status); - phalcon_call_method_p2_key(status, validator, "validate", this_ptr, attribute, 2654098287UL); + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "message", 1); - if (PHALCON_IS_FALSE(status)) { + 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(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(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"); } } - zend_hash_move_forward_ex(ah0, &hp0); - } - - 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); - } - - RETURN_CCTOR(messages); -} - -static PHP_METHOD(Phalcon_Validation, add){ - - zval *attribute, *validator, *scope; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &attribute, &validator); - - if (Z_TYPE_P(attribute) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The attribute must be a string"); - return; - } - if (Z_TYPE_P(validator) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The validator must be an object"); - return; + 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; } - 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; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_checkedPath", 2930914648UL); + RETURN_MM_TRUE; } @@ -113200,111 +36903,89 @@ static PHP_METHOD(Phalcon_Validation, getFilters){ -PHALCON_INIT_CLASS(Phalcon_Kernel){ - - PHALCON_REGISTER_CLASS(Phalcon, Kernel, kernel, phalcon_kernel_method_entry, 0); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Kernel, preComputeHashKey){ - - char *arKey, *strKey; - unsigned int nKeyLength; - register ulong hash = 5381; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { - RETURN_NULL(); - } - - 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++; - } +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Regex){ - 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; - } + 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); - strKey = emalloc(24); - sprintf(strKey, "%lu", hash); + zend_class_implements(phalcon_mvc_model_validator_regex_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - RETURN_STRING(strKey, 0); + return SUCCESS; } -static PHP_METHOD(Phalcon_Kernel, preComputeHashKey32){ - - char *arKey, *strKey; - unsigned int nKeyLength; - ulong hash; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { - RETURN_NULL(); - } - - nKeyLength++; - hash = zend_inline_hash_func(arKey, nKeyLength) & 0xFFFFFFFFul; - strKey = emalloc(24); - sprintf(strKey, "%lu", hash); - - RETURN_STRING(strKey, 0); -} +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Regex, validate){ -static PHP_METHOD(Phalcon_Kernel, preComputeHashKey64){ + zval *record, *option = NULL, *field_name, *is_set, *value; + zval *failed = NULL, *matches, *pattern, *match_pattern; + zval *match_zero, *message = NULL, *type; - char *arKey, *strKey; - unsigned int nKeyLength; - register unsigned long long hash = 5381; + PHALCON_MM_GROW(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { - RETURN_NULL(); + 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; } - - 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++; + + 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; } - - 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; + + 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); } - - strKey = emalloc(24); - sprintf(strKey, "%llu", hash); - - RETURN_STRING(strKey, 0); + + 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; } @@ -113320,250 +37001,215 @@ static PHP_METHOD(Phalcon_Kernel, preComputeHashKey64){ -PHALCON_INIT_CLASS(Phalcon_Db){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_StringLength){ - PHALCON_REGISTER_CLASS(Phalcon, Db, db, phalcon_db_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + 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_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_mvc_model_validator_stringlength_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Db, setup){ +static PHP_METHOD(Phalcon_Mvc_Model_Validator_StringLength, validate){ - zval *options, *escape_identifiers; + 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, &options); + phalcon_fetch_params(1, 1, 0, &record); - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Options must be an array"); + 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; } - 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_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_MM_RESTORE(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Session){ - - PHALCON_REGISTER_CLASS(Phalcon, Session, session, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - return SUCCESS; -======= - phalcon_fetch_params(1, 0, 1, &attribute); + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); - if (!attribute) { - PHALCON_INIT_VAR(attribute); + 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_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); + 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; } - RETURN_MM_NULL(); } - RETURN_CCTOR(filters); + 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; } -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); -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Validation, getMessages){ - RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); -} -static PHP_METHOD(Phalcon_Validation, appendMessage){ - zval *message, *messages; - 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); - phalcon_call_method_p1_key(NULL, messages, "appendmessage", message, 2313005058UL); - RETURN_THIS(); -} +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Exclusionin){ -static PHP_METHOD(Phalcon_Validation, bind){ + 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); - zval *entity, *data; + zend_class_implements(phalcon_mvc_model_validator_exclusionin_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - phalcon_fetch_params(0, 2, 0, &entity, &data); - - if (Z_TYPE_P(entity) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "The entity must be an object"); - 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; - } - } - - 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 SUCCESS; } -static PHP_METHOD(Phalcon_Validation, getValue){ +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Exclusionin, validate){ - zval *attribute, *entity, *method, *value = NULL, *data, *values; - zval *filters, *field_filters, *service_name; - zval *dependency_injector = NULL, *filter_service; + 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, &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, &record); - 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; - } - } + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); - 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); + 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(value); + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "domain", 1); - 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); - } - } 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_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; } - 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_NVAR(option); + ZVAL_STRING(option, "domain", 1); - PHALCON_INIT_VAR(service_name); - ZVAL_STRING(service_name, "filter", 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(dependency_injector); - phalcon_call_method_key(dependency_injector, this_ptr, "getdi", 4287060818UL); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + if (phalcon_fast_in_array(value, domain TSRMLS_CC)) { - 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_NVAR(option); + ZVAL_STRING(option, "message", 1); - 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_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_call_method_p2_key(return_value, filter_service, "sanitize", value, field_filters, 3688332940UL); - RETURN_MM(); - } - } + PHALCON_INIT_NVAR(message); + PHALCON_CONCAT_SVSV(message, "Value of field '", field_name, "' must not be part of list: ", joined_domain); } - phalcon_update_property_array(this_ptr, SL("_values"), attribute, value TSRMLS_CC); - - RETURN_CCTOR(value); + 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_NULL(); ->>>>>>> 1.2.2 + RETURN_MM_TRUE; } @@ -113579,595 +37225,334 @@ static PHP_METHOD(Phalcon_Validation, getValue){ -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Tag){ - - PHALCON_REGISTER_CLASS(Phalcon, Tag, tag, phalcon_tag_method_entry, 0); - - zend_declare_property_null(phalcon_tag_ce, SL("_displayValues"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_null(phalcon_tag_ce, SL("_documentTitle"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_long(phalcon_tag_ce, SL("_documentType"), 11, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_null(phalcon_tag_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_null(phalcon_tag_ce, SL("_urlService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_null(phalcon_tag_ce, SL("_dispatcherService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_null(phalcon_tag_ce, SL("_escaperService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_bool(phalcon_tag_ce, SL("_autoEscape"), 1, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_PresenceOf){ - zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML32"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_STRICT"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_TRANSITIONAL"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_FRAMESET"), 4 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML5"), 5 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_STRICT"), 6 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_TRANSITIONAL"), 7 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_FRAMESET"), 8 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML11"), 9 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML20"), 10 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML5"), 11 TSRMLS_CC); -======= -PHALCON_INIT_CLASS(Phalcon_Version){ + 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); - PHALCON_REGISTER_CLASS(Phalcon, Version, version, phalcon_version_method_entry, 0); ->>>>>>> 1.2.2 + zend_class_implements(phalcon_mvc_model_validator_presenceof_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); return SUCCESS; } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Tag, 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_tag_exception_ce, "Parameter dependencyInjector must be an Object"); - return; - } - phalcon_update_static_property(SL("phalcon\\tag"), SL("_dependencyInjector"), dependency_injector TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Tag, getDI){ - - zval *dependency_injector; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_CC); - RETURN_CCTOR(dependency_injector); -} - -static PHP_METHOD(Phalcon_Tag, getUrlService){ +static PHP_METHOD(Phalcon_Mvc_Model_Validator_PresenceOf, validate){ - zval *url = NULL, *dependency_injector = NULL, *service; + zval *record, *option = NULL, *field_name, *value, *message = NULL; + zval *type; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(url); - phalcon_read_static_property(&url, SL("phalcon\\tag"), SL("_urlService") TSRMLS_CC); - if (Z_TYPE_P(url) != IS_OBJECT) { - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_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_tag_exception_ce, "A dependency injector container is required to obtain the \"url\" service"); - return; - } + phalcon_fetch_params(1, 1, 0, &record); - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "url", 1); + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); - PHALCON_INIT_NVAR(url); - phalcon_call_method_p1_key(url, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_urlService"), url TSRMLS_CC); + 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; } - RETURN_CCTOR(url); -} - -static PHP_METHOD(Phalcon_Tag, getEscaperService){ - - zval *escaper = NULL, *dependency_injector = NULL, *service; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(escaper); - phalcon_read_static_property(&escaper, SL("phalcon\\tag"), SL("_escaperService") TSRMLS_CC); - if (Z_TYPE_P(escaper) != IS_OBJECT) { + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); + if (PHALCON_IS_EMPTY(value)) { - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - } + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "message", 1); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the \"escaper\" service"); - return; + 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(service); - ZVAL_STRING(service, "escaper", 1); - - PHALCON_INIT_NVAR(escaper); - phalcon_call_method_p1_key(escaper, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_escaperService"), escaper TSRMLS_CC); + 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_CCTOR(escaper); -} - -static PHP_METHOD(Phalcon_Tag, setAutoescape){ - - zval *autoescape; - - phalcon_fetch_params(0, 1, 0, &autoescape); - - phalcon_update_static_property(SL("phalcon\\tag"), SL("_autoEscape"), autoescape TSRMLS_CC); - + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Tag, setDefault){ - zval *id, *value; - zval *t0 = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &id, &value); - - if (Z_TYPE_P(value) != IS_NULL) { - if (Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "Only scalar values can be assigned to UI components"); - return; - } - } - PHALCON_OBSERVE_VAR(t0); - phalcon_read_static_property(&t0, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); - if (Z_TYPE_P(t0) != IS_ARRAY) { - convert_to_array(t0); - } - phalcon_array_update_zval(&t0, id, &value, PH_COPY); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), t0 TSRMLS_CC); - - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Tag, setDefaults){ +#ifdef HAVE_CONFIG_H +#endif - zval *values; - phalcon_fetch_params(0, 1, 0, &values); - - if (Z_TYPE_P(values) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_tag_exception_ce, "An array is required as default values"); - return; - } - phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), values TSRMLS_CC); - -} -static PHP_METHOD(Phalcon_Tag, displayTo){ - zval *id, *value, *default_value; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &id, &value); - - PHALCON_INIT_VAR(default_value); - PHALCON_CALL_SELF_PARAMS_2(default_value, this_ptr, "setdefault", id, value); - RETURN_CCTOR(default_value); -} -static PHP_METHOD(Phalcon_Tag, hasValue){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator_Numericality){ - zval *name, *display_values, *_POST; + 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); - PHALCON_MM_GROW(); + zend_class_implements(phalcon_mvc_model_validator_numericality_ce TSRMLS_CC, 1, phalcon_mvc_model_validatorinterface_ce); - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(display_values); - phalcon_read_static_property(&display_values, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); - - if (phalcon_array_isset(display_values, name)) { - RETURN_MM_TRUE; - } else { - phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); - if (phalcon_array_isset(_POST, name)) { - RETURN_MM_TRUE; - } - } - - RETURN_MM_FALSE; + return SUCCESS; } -static PHP_METHOD(Phalcon_Tag, getValue){ +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Numericality, validate){ - zval *name, *params = NULL, *display_values, *value = NULL, *_POST; - zval *autoescape = NULL, *escaper = NULL; + zval *record, *option = NULL, *field, *value, *message = NULL, *type; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, ¶ms); - - if (!params) { - PHALCON_INIT_VAR(params); - } + phalcon_fetch_params(1, 1, 0, &record); - PHALCON_OBS_VAR(display_values); - phalcon_read_static_property(&display_values, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); - if (phalcon_array_isset(display_values, name)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, display_values, name, PH_NOISY); - } else { - phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); - if (phalcon_array_isset(_POST, name)) { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, _POST, name, PH_NOISY); - } else { - RETURN_MM_NULL(); - } + 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_OBS_VAR(autoescape); - phalcon_read_static_property(&autoescape, SL("phalcon\\tag"), SL("_autoEscape") TSRMLS_CC); + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field, 95450773UL); - if (Z_TYPE_P(value) == IS_STRING) { - if (zend_is_true(autoescape)) { - PHALCON_INIT_VAR(escaper); - PHALCON_CALL_SELF(escaper, this_ptr, "getescaperservice"); - phalcon_call_method_p1_key(return_value, escaper, "escapehtmlattr", value, 4208410982UL); - RETURN_MM(); - } else { - if (Z_TYPE_P(params) == IS_ARRAY) { + if (!phalcon_is_numeric(value)) { - if (phalcon_array_isset_quick_string(params, SS("escape"), 1978755574UL)) { + PHALCON_INIT_NVAR(option); + ZVAL_STRING(option, "message", 1); - PHALCON_OBS_NVAR(autoescape); - phalcon_array_fetch_quick_string(&autoescape, params, SS("escape"), 1978755574UL, PH_NOISY); - if (zend_is_true(autoescape)) { - PHALCON_INIT_NVAR(escaper); - PHALCON_CALL_SELF(escaper, this_ptr, "getescaperservice"); - phalcon_call_method_p1_key(return_value, escaper, "escapehtmlattr", value, 4208410982UL); - RETURN_MM(); - } - } - } + 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"); } + + 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_CCTOR(value); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Tag, resetInput){ - zval *empty_array = NULL; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), empty_array TSRMLS_CC); +#ifdef HAVE_CONFIG_H +#endif - phalcon_set_symbol_str(SS("_POST"), empty_array TSRMLS_CC); - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Tag, linkTo){ - zval *parameters, *text = NULL, *params = NULL, *action = NULL, *url, *internal_url; - zval *code, *value = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, ¶meters, &text); - - if (!text) { - PHALCON_INIT_VAR(text); - } else { - PHALCON_SEPARATE_PARAM(text); - } - - 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, text, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } - - PHALCON_INIT_VAR(action); - ZVAL_STRING(action, "", 1); - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_NVAR(action); - phalcon_array_fetch_long(&action, params, 0, PH_NOISY); - } else { - if (phalcon_array_isset_quick_string(params, SS("action"), 502132067UL)) { - PHALCON_OBS_NVAR(action); - phalcon_array_fetch_quick_string(&action, params, SS("action"), 502132067UL, PH_NOISY); - phalcon_array_unset_string(¶ms, SS("action"), PH_SEPARATE); - } - } - - PHALCON_INIT_NVAR(text); - ZVAL_STRING(text, "", 1); - if (phalcon_array_isset_long(params, 1)) { - PHALCON_OBS_NVAR(text); - phalcon_array_fetch_long(&text, params, 1, PH_NOISY); - } else { - if (phalcon_array_isset_quick_string(params, SS("text"), 275483210UL)) { - PHALCON_OBS_NVAR(text); - phalcon_array_fetch_quick_string(&text, params, SS("text"), 275483210UL, PH_NOISY); - phalcon_array_unset_string(¶ms, SS("text"), PH_SEPARATE); - } - } - - PHALCON_INIT_VAR(url); - PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); - - PHALCON_INIT_VAR(internal_url); - phalcon_call_method_p1_key(internal_url, url, "get", action, 2090288933UL); - - PHALCON_INIT_VAR(code); - PHALCON_CONCAT_SVS(code, "", text, ""); - - RETURN_CTOR(code); + +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_Tag, _inputField){ +static PHP_METHOD(Phalcon_Mvc_Model_Validator_Email, validate){ - zval *type, *parameters, *as_value = NULL, *params = NULL, *value = NULL; - zval *id = NULL, *name, *code, *key = NULL, *doctype; - HashTable *ah0; - HashPosition hp0; - zval **hd; + 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, 2, 1, &type, ¶meters, &as_value); + phalcon_fetch_params(1, 1, 0, &record); - if (!as_value) { - PHALCON_INIT_VAR(as_value); - ZVAL_BOOL(as_value, 0); - } + PHALCON_INIT_VAR(option); + ZVAL_STRING(option, "field", 1); - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); + 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); - if (PHALCON_IS_FALSE(as_value)) { - 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); - } - } + PHALCON_INIT_VAR(regs); - 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); - } - } + PHALCON_INIT_VAR(invalid); + ZVAL_BOOL(invalid, 0); - if (!phalcon_array_isset_quick_string(params, SS("value"), 574111618UL)) { - PHALCON_CALL_SELF_PARAMS_2(value, this_ptr, "getvalue", id, params); - phalcon_array_update_quick_string(¶ms, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); - } - } else { - if (!phalcon_array_isset_quick_string(params, SS("value"), 574111618UL)) { - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_long(&value, params, 0, PH_NOISY); - phalcon_array_update_quick_string(¶ms, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); - } - } - } + PHALCON_INIT_VAR(value); + phalcon_call_method_p1_key(value, record, "readattribute", field_name, 95450773UL); - PHALCON_INIT_VAR(code); - PHALCON_CONCAT_SVS(code, "") TSRMLS_CC); - } else { - phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); + 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_CTOR(code); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Tag, _inputFieldChecked){ - - zval *type, *parameters, *params = NULL, *value = NULL, *id = NULL, *name; - zval *current_value, *code, *key = NULL, *doctype; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &type, ¶meters); - - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); -======= -static PHP_METHOD(Phalcon_Version, _getVersion){ - zval *version; - PHALCON_MM_GROW(); +#ifdef HAVE_CONFIG_H +#endif - PHALCON_INIT_VAR(version); - array_init_size(version, 5); - add_next_index_long(version, 1); - add_next_index_long(version, 2); - add_next_index_long(version, 2); - add_next_index_long(version, 4); - add_next_index_long(version, 0); - RETURN_CTOR(version); -} -static PHP_METHOD(Phalcon_Version, get){ - zval *version, *major, *medium, *minor, *special, *special_number; - zval *result, *suffix = NULL; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(version); - PHALCON_CALL_SELF(version, this_ptr, "_getversion"); - PHALCON_OBS_VAR(major); - phalcon_array_fetch_long(&major, version, 0, PH_NOISY); - PHALCON_OBS_VAR(medium); - phalcon_array_fetch_long(&medium, version, 1, PH_NOISY); +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Validator){ - PHALCON_OBS_VAR(minor); - phalcon_array_fetch_long(&minor, version, 2, PH_NOISY); + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Validator, mvc_model_validator, phalcon_mvc_model_validator_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - PHALCON_OBS_VAR(special); - phalcon_array_fetch_long(&special, version, 3, PH_NOISY); + 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); - PHALCON_OBS_VAR(special_number); - phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY); + return SUCCESS; +} - PHALCON_INIT_VAR(result); - PHALCON_CONCAT_VSVSVS(result, major, ".", medium, ".", minor, " "); +static PHP_METHOD(Phalcon_Mvc_Model_Validator, __construct){ - switch (phalcon_get_intval(special)) { + zval *options; - case 1: - PHALCON_INIT_VAR(suffix); - PHALCON_CONCAT_SV(suffix, "ALPHA ", special_number); - break; + 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); + +} - case 2: - PHALCON_INIT_NVAR(suffix); - PHALCON_CONCAT_SV(suffix, "BETA ", special_number); - break; +static PHP_METHOD(Phalcon_Mvc_Model_Validator, appendMessage){ - case 3: - PHALCON_INIT_NVAR(suffix); - PHALCON_CONCAT_SV(suffix, "RC ", special_number); - break; + zval *message, *field = NULL, *type = NULL, *class_name, *suffix; + zval *empty_string, *model_message; - default: - PHALCON_INIT_NVAR(suffix); - ZVAL_STRING(suffix, "", 1); - break; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 2, &message, &field, &type); + + if (!field) { + PHALCON_INIT_VAR(field); } - phalcon_concat_self(&result, suffix TSRMLS_CC); - phalcon_fast_trim(return_value, result, PHALCON_TRIM_BOTH TSRMLS_CC); - RETURN_MM(); + + 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_Version, getId){ +static PHP_METHOD(Phalcon_Mvc_Model_Validator, getMessages){ - zval *version, *major, *medium, *minor, *special, *special_number; - zval *format, *real_medium, *real_minor; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); +} - PHALCON_INIT_VAR(version); - PHALCON_CALL_SELF(version, this_ptr, "_getversion"); +static PHP_METHOD(Phalcon_Mvc_Model_Validator, getOptions){ - PHALCON_OBS_VAR(major); - phalcon_array_fetch_long(&major, version, 0, PH_NOISY); - PHALCON_OBS_VAR(medium); - phalcon_array_fetch_long(&medium, version, 1, PH_NOISY); + RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); +} - PHALCON_OBS_VAR(minor); - phalcon_array_fetch_long(&minor, version, 2, PH_NOISY); +static PHP_METHOD(Phalcon_Mvc_Model_Validator, getOption){ - PHALCON_OBS_VAR(special); - phalcon_array_fetch_long(&special, version, 3, PH_NOISY); + zval *option, *options, *value; - PHALCON_OBS_VAR(special_number); - phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY); + PHALCON_MM_GROW(); - PHALCON_INIT_VAR(format); - ZVAL_STRING(format, "%02s", 1); + 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(); +} - PHALCON_INIT_VAR(real_medium); - phalcon_call_func_p2(real_medium, "sprintf", format, medium); +static PHP_METHOD(Phalcon_Mvc_Model_Validator, isSetOption){ - PHALCON_INIT_VAR(real_minor); - phalcon_call_func_p2(real_minor, "sprintf", format, minor); - PHALCON_CONCAT_VVVVV(return_value, major, real_medium, real_minor, special, special_number); - RETURN_MM(); + 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); } @@ -114183,1372 +37568,1024 @@ static PHP_METHOD(Phalcon_Version, getId){ -PHALCON_INIT_CLASS(Phalcon_Loader){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Message){ - PHALCON_REGISTER_CLASS(Phalcon, Loader, loader, phalcon_loader_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Message, mvc_model_message, phalcon_mvc_model_message_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_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_loader_ce TSRMLS_CC, 1, phalcon_events_eventsawareinterface_ce); + zend_class_implements(phalcon_mvc_model_message_ce TSRMLS_CC, 1, phalcon_mvc_model_messageinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Loader, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model_Message, __construct){ - zval *extensions; + zval *message, *field = NULL, *type = NULL, *model = 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_fetch_params(1, 1, 3, &message, &field, &type, &model); + + if (!field) { + PHALCON_INIT_VAR(field); + } + + if (!type) { + PHALCON_INIT_VAR(type); + } + + if (!model) { + PHALCON_INIT_VAR(model); + } + + 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_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Loader, setEventsManager){ +static PHP_METHOD(Phalcon_Mvc_Model_Message, setType){ - zval *events_manager; + zval *type; - 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, &type); + phalcon_update_property_this_quick(this_ptr, SL("_type"), type, 3991959110UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Loader, getEventsManager){ +static PHP_METHOD(Phalcon_Mvc_Model_Message, getType){ - RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); } -static PHP_METHOD(Phalcon_Loader, setExtensions){ +static PHP_METHOD(Phalcon_Mvc_Model_Message, setMessage){ - zval *extensions; + zval *message; - 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_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_Loader, getExtensions){ +static PHP_METHOD(Phalcon_Mvc_Model_Message, getMessage){ - RETURN_MEMBER_QUICK(this_ptr, "_extensions", 726159316UL); + RETURN_MEMBER_QUICK(this_ptr, "_message", 933579817UL); } -static PHP_METHOD(Phalcon_Loader, registerNamespaces){ - - zval *namespaces, *merge = NULL, *current_namespaces; - zval *merged_namespaces = NULL; +static PHP_METHOD(Phalcon_Mvc_Model_Message, setField){ - PHALCON_MM_GROW(); + zval *field; - phalcon_fetch_params(1, 1, 1, &namespaces, &merge); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } - - if (Z_TYPE_P(namespaces) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter namespaces must be an array"); - return; ->>>>>>> 1.2.2 - } - if (zend_is_true(merge)) { - -<<<<<<< HEAD - PHALCON_INIT_VAR(value); - 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); - } - } - - PHALCON_CALL_SELF_PARAMS_2(value, this_ptr, "getvalue", id, params); - - if (phalcon_array_isset_quick_string(params, SS("value"), 574111618UL)) { - - PHALCON_OBS_VAR(current_value); - phalcon_array_fetch_quick_string(¤t_value, params, SS("value"), 574111618UL, PH_NOISY); - if (PHALCON_IS_EQUAL(current_value, value)) { - phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE); - } - } else { - if (zend_is_true(value)) { - phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE); - } - - phalcon_array_update_quick_string(¶ms, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); - } - - PHALCON_INIT_VAR(code); - PHALCON_CONCAT_SVS(code, "") TSRMLS_CC); - } else { - phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); - } + phalcon_fetch_params(0, 1, 0, &field); - RETURN_CTOR(code); + phalcon_update_property_this_quick(this_ptr, SL("_field"), field, 2318377128UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Tag, textField){ -======= - 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_Message, getField){ -static PHP_METHOD(Phalcon_Loader, getNamespaces){ ->>>>>>> 1.2.2 - zval *parameters, *name; + RETURN_MEMBER_QUICK(this_ptr, "_field", 2318377128UL); +} -<<<<<<< HEAD - PHALCON_MM_GROW(); +static PHP_METHOD(Phalcon_Mvc_Model_Message, setModel){ - phalcon_fetch_params(1, 1, 0, ¶meters); + zval *model; + + phalcon_fetch_params(0, 1, 0, &model); - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "text", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); + phalcon_update_property_this_quick(this_ptr, SL("_model"), model, 2599397109UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Tag, numericField){ +static PHP_METHOD(Phalcon_Mvc_Model_Message, getModel){ - zval *parameters, *name; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_model", 2599397109UL); +} - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "number", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); +static PHP_METHOD(Phalcon_Mvc_Model_Message, __toString){ + + + RETURN_MEMBER_QUICK(this_ptr, "_message", 933579817UL); } -static PHP_METHOD(Phalcon_Tag, emailField){ +static PHP_METHOD(Phalcon_Mvc_Model_Message, __set_state){ - zval *parameters, *name; + zval *message, *message_text, *field, *type; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); + 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_mvc_model_message_ce); + phalcon_call_method_p3_key(NULL, return_value, "__construct", message_text, field, type, 1107214344UL); - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "email", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); RETURN_MM(); } -static PHP_METHOD(Phalcon_Tag, dateField){ -======= - RETURN_MEMBER_QUICK(this_ptr, "_namespaces", 3363620132UL); -} -static PHP_METHOD(Phalcon_Loader, registerPrefixes){ - zval *prefixes, *merge = NULL, *current_prefixes, *merged_prefixes = NULL; - 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(); +#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; } -static PHP_METHOD(Phalcon_Loader, getPrefixes){ ->>>>>>> 1.2.2 - zval *parameters, *name; -<<<<<<< HEAD - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "date", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); + + +#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; } -static PHP_METHOD(Phalcon_Tag, passwordField){ - zval *parameters, *name; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "password", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); + + + + + + + + +#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; } -static PHP_METHOD(Phalcon_Tag, hiddenField){ - zval *parameters, *name; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "hidden", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Tag, fileField){ - zval *parameters, *name; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "file", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Tag, checkField){ - zval *parameters, *name; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "checkbox", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfieldchecked", name, parameters); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Tag, radioField){ - zval *parameters, *name; -======= - RETURN_MEMBER_QUICK(this_ptr, "_prefixes", 900970058UL); -} -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); -} -static PHP_METHOD(Phalcon_Loader, registerClasses){ - zval *classes, *merge = NULL, *current_classes, *merged_classes = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &classes, &merge); - - if (!merge) { - PHALCON_INIT_VAR(merge); - ZVAL_BOOL(merge, 0); - } - - 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 { - phalcon_update_property_this_quick(this_ptr, SL("_classes"), classes, 3992428914UL TSRMLS_CC); - } - - RETURN_THIS(); -} -static PHP_METHOD(Phalcon_Loader, getClasses){ ->>>>>>> 1.2.2 - PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "radio", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfieldchecked", name, parameters); - RETURN_MM(); -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Tag, imageInput){ - zval *parameters, *name, *as_value; - PHALCON_MM_GROW(); +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_BehaviorInterface){ - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "image", 1); - - PHALCON_INIT_VAR(as_value); - ZVAL_BOOL(as_value, 1); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_inputfield", name, parameters, as_value); - RETURN_MM(); + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, BehaviorInterface, mvc_model_behaviorinterface, phalcon_mvc_model_behaviorinterface_method_entry); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Tag, submitButton){ - zval *parameters, *name, *as_value; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "submit", 1); - - PHALCON_INIT_VAR(as_value); - ZVAL_BOOL(as_value, 1); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_inputfield", name, parameters, as_value); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Tag, selectStatic){ - zval *parameters, *data = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, ¶meters, &data); - - if (!data) { - PHALCON_INIT_VAR(data); - } - - PHALCON_CALL_STATIC_PARAMS_2(return_value, "phalcon\\tag\\select", "selectfield", parameters, data); - RETURN_MM(); -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Tag, select){ - zval *parameters, *data = NULL; - PHALCON_MM_GROW(); +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MessageInterface){ - phalcon_fetch_params(1, 1, 1, ¶meters, &data); - - if (!data) { - PHALCON_INIT_VAR(data); - } - - PHALCON_CALL_STATIC_PARAMS_2(return_value, "phalcon\\tag\\select", "selectfield", parameters, data); - RETURN_MM(); + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Model, MessageInterface, mvc_model_messageinterface, phalcon_mvc_model_messageinterface_method_entry); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Tag, textArea){ - zval *parameters, *params = NULL, *id = NULL, *name, *content = NULL, *code; - zval *avalue = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); - - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } - if (!phalcon_array_isset_long(params, 0)) { - if (phalcon_array_isset_quick_string(params, SS("id"), 193494642UL)) { - 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_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_OBS_VAR(content); - phalcon_array_fetch_quick_string(&content, params, SS("value"), 574111618UL, PH_NOISY); - phalcon_array_unset_string(¶ms, SS("value"), PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(content); - PHALCON_CALL_SELF_PARAMS_2(content, this_ptr, "getvalue", id, params); - } - - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, "", content, ""); - - RETURN_CTOR(code); -} -static PHP_METHOD(Phalcon_Tag, form){ - zval *parameters = NULL, *params = NULL, *params_action = NULL, *action = NULL; - zval *url, *code, *avalue = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } else { - PHALCON_SEPARATE_PARAM(parameters); - } - - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_VAR(params_action); - phalcon_array_fetch_long(¶ms_action, params, 0, PH_NOISY); - } else { - if (phalcon_array_isset_quick_string(params, SS("action"), 502132067UL)) { - PHALCON_OBS_NVAR(params_action); - phalcon_array_fetch_quick_string(¶ms_action, params, SS("action"), 502132067UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(params_action); - } - } - - if (!phalcon_array_isset_quick_string(params, SS("method"), 3193080326UL)) { - phalcon_array_update_string_string(¶ms, SL("method"), SL("post"), PH_SEPARATE); - } - - PHALCON_INIT_VAR(action); - - if (Z_TYPE_P(params_action) != IS_NULL) { - PHALCON_INIT_VAR(url); - PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); - - phalcon_call_method_p1_key(action, url, "get", params_action, 2090288933UL); - } - - if (phalcon_array_isset_quick_string(params, SS("parameters"), 3941032889UL)) { - PHALCON_OBS_NVAR(parameters); - phalcon_array_fetch_quick_string(¶meters, params, SS("parameters"), 3941032889UL, PH_NOISY); - PHALCON_SCONCAT_SV(action, "?", parameters); - } - - if (Z_TYPE_P(action) != IS_NULL) { - phalcon_array_update_quick_string(¶ms, SS("action"), 502132067UL, &action, PH_COPY | PH_SEPARATE); - } - - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, "") TSRMLS_CC); - - RETURN_CTOR(code); -} -static PHP_METHOD(Phalcon_Tag, endForm){ - RETURN_STRING("", 1); -} -static PHP_METHOD(Phalcon_Tag, setTitle){ - zval *title; - phalcon_fetch_params(0, 1, 0, &title); - - phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), title TSRMLS_CC); - -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Tag, appendTitle){ - zval *title; - zval *t0 = NULL; - zval *r0 = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &title); - - PHALCON_OBS_VAR(t0); - phalcon_read_static_property(&t0, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); - PHALCON_ALLOC_ZVAL_MM(r0); - concat_function(r0, t0, title TSRMLS_CC); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), r0 TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Tag, prependTitle){ - zval *title, *document_title; - zval *r0 = NULL; - PHALCON_MM_GROW(); +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData){ - phalcon_fetch_params(1, 1, 0, &title); - - PHALCON_OBS_VAR(document_title); - phalcon_read_static_property(&document_title, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); - - PHALCON_INIT_VAR(r0); - PHALCON_CONCAT_VV(r0, title, document_title); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), r0 TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, MetaData, mvc_model_metadata, phalcon_mvc_model_metadata_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); -static PHP_METHOD(Phalcon_Tag, getTitle){ + 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); - zval *tags = NULL, *document_title, *eol; + 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); - PHALCON_MM_GROW(); + zend_class_implements(phalcon_mvc_model_metadata_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); - phalcon_fetch_params(1, 0, 1, &tags); - - if (!tags) { - PHALCON_INIT_VAR(tags); - ZVAL_BOOL(tags, 1); - } - - PHALCON_OBS_VAR(document_title); - phalcon_read_static_property(&document_title, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); - if (PHALCON_IS_TRUE(tags)) { - PHALCON_INIT_VAR(eol); - ZVAL_STRING(eol, PHP_EOL, 1); - PHALCON_CONCAT_SVSV(return_value, "", document_title, "", eol); - RETURN_MM(); - } - - RETURN_CCTOR(document_title); + return SUCCESS; } -static PHP_METHOD(Phalcon_Tag, stylesheetLink){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, _initialize){ - zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; - zval *url, *url_href, *href, *code, *value = NULL, *key = NULL, *doctype; - zval *eol; - HashTable *ah0; - HashPosition hp0; - zval **hd; + 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, 0, 2, ¶meters, &local); + phalcon_fetch_params(1, 4, 0, &model, &key, &table, &schema); - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + PHALCON_INIT_VAR(strategy); - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); - } else { - PHALCON_SEPARATE_PARAM(local); - } + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 0 TSRMLS_CC); + if (Z_TYPE_P(key) != IS_NULL) { - 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, local, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } - if (!phalcon_array_isset_quick_string(params, SS("href"), 261698186UL)) { - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_VAR(first_param); - phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY); - phalcon_array_update_quick_string(¶ms, SS("href"), 261698186UL, &first_param, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_string_string(¶ms, SL("href"), SL(""), 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(meta_data, key)) { - PHALCON_INIT_NVAR(local); - ZVAL_BOOL(local, 0); - if (phalcon_array_isset_long(params, 1)) { - PHALCON_OBS_NVAR(local); - phalcon_array_fetch_long(&local, params, 1, PH_NOISY); - } else { - if (phalcon_array_isset_quick_string(params, SS("local"), 199015600UL)) { - PHALCON_OBS_NVAR(local); - phalcon_array_fetch_quick_string(&local, params, SS("local"), 199015600UL, PH_NOISY); - phalcon_array_unset_string(¶ms, SS("local"), PH_SEPARATE); + 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_array_isset_quick_string(params, SS("type"), 276192743UL)) { - phalcon_array_update_string_string(¶ms, SL("type"), SL("text/css"), PH_SEPARATE); + if (!PHALCON_GLOBAL(orm).column_renaming) { + RETURN_MM_NULL(); } - if (zend_is_true(local)) { - PHALCON_INIT_VAR(url); - PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); - - PHALCON_OBS_VAR(url_href); - phalcon_array_fetch_quick_string(&url_href, params, SS("href"), 261698186UL, PH_NOISY); + PHALCON_INIT_VAR(key_name); + phalcon_fast_strtolower(key_name, class_name); - PHALCON_INIT_VAR(href); - phalcon_call_method_p1_key(href, url, "getstatic", url_href, 2197271245UL); - phalcon_array_update_quick_string(¶ms, SS("href"), 261698186UL, &href, PH_COPY | PH_SEPARATE); + 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(); } - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, "", eol); - } else { - PHALCON_SCONCAT_SV(code, ">", eol); - } + phalcon_call_method_p2_key(NULL, this_ptr, "write", prefix_key, model_column_map, 633298768UL); - RETURN_CTOR(code); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Tag, javascriptInclude){ - - zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; - zval *url, *params_src, *src, *eol, *code, *value = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, setDI){ - PHALCON_MM_GROW(); + zval *dependency_injector; - phalcon_fetch_params(1, 0, 2, ¶meters, &local); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } - - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); - } else { - PHALCON_SEPARATE_PARAM(local); - } + phalcon_fetch_params(0, 1, 0, &dependency_injector); - 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, local, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } - if (!phalcon_array_isset_quick_string(params, SS("src"), 2090733773UL)) { - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_VAR(first_param); - phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY); - phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &first_param, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE); - } + 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); - PHALCON_INIT_NVAR(local); - ZVAL_BOOL(local, 0); - if (phalcon_array_isset_long(params, 1)) { - PHALCON_OBS_NVAR(local); - phalcon_array_fetch_long(&local, params, 1, PH_NOISY); - } else { - if (phalcon_array_isset_quick_string(params, SS("local"), 199015600UL)) { - PHALCON_OBS_NVAR(local); - phalcon_array_fetch_quick_string(&local, params, SS("local"), 199015600UL, PH_NOISY); - phalcon_array_unset_string(¶ms, SS("local"), PH_SEPARATE); -======= - RETURN_MEMBER_QUICK(this_ptr, "_classes", 3992428914UL); } -static PHP_METHOD(Phalcon_Loader, register){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getDI){ - zval *registered, *autoloader; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +} - 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); +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); - RETURN_THIS(); } -static PHP_METHOD(Phalcon_Loader, unregister){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getStrategy){ - zval *registered, *autoloader; + zval *strategy = NULL; 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_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_THIS(); + RETURN_CCTOR(strategy); } -static PHP_METHOD(Phalcon_Loader, autoLoad){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, readMetaData){ - 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; + zval *model, *table, *schema, *class_name, *key, *meta_data = NULL; + zval *data; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &class_name); - - 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(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_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_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_fetch_params(1, 1, 0, &model); - if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; - } - RETURN_MM_TRUE; - } + 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_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_INIT_VAR(table); + phalcon_call_method_key(table, model, "getsource", 2025234358UL); - 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_INIT_VAR(schema); + phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - phalcon_is_iterable(namespaces, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 1 TSRMLS_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_VSVV(key, class_name, "-", schema, table); - PHALCON_GET_HKEY(ns_prefix, ah0, hp0); - PHALCON_GET_HVALUE(directory); + 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); - if (phalcon_start_with(class_name, ns_prefix, NULL)) { + PHALCON_OBS_NVAR(meta_data); + phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); + } - 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_OBS_VAR(data); + phalcon_array_fetch(&data, meta_data, key, PH_NOISY); - PHALCON_INIT_NVAR(fixed_directory); - phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC); + RETURN_CCTOR(data); +} + +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); - phalcon_is_iterable(extensions, &ah1, &hp1, 0, 0); + 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; + } - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + PHALCON_INIT_VAR(table); + phalcon_call_method_key(table, model, "getsource", 2025234358UL); - PHALCON_GET_HVALUE(extension); + PHALCON_INIT_VAR(schema); + phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - PHALCON_INIT_NVAR(file_path); - PHALCON_CONCAT_VVSV(file_path, fixed_directory, file_name, ".", extension); + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 1 TSRMLS_CC); - 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(key); + PHALCON_CONCAT_VSVV(key, class_name, "-", schema, table); - 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_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); - 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_OBS_NVAR(meta_data); + phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_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_OBS_VAR(meta_data_index); + phalcon_array_fetch(&meta_data_index, meta_data, key, PH_NOISY); - if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; - } + PHALCON_OBS_VAR(attributes); + phalcon_array_fetch(&attributes, meta_data_index, index, PH_NOISY); - RETURN_MM_TRUE; - } + RETURN_CCTOR(attributes); +} + +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); - zend_hash_move_forward_ex(ah1, &hp1); - } + 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; } - - 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_VAR(table); + phalcon_call_method_key(table, model, "getsource", 2025234358UL); - 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(schema); + phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - PHALCON_INIT_NVAR(fixed_directory); - phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC); + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 1 TSRMLS_CC); - phalcon_is_iterable(extensions, &ah3, &hp3, 0, 0); + PHALCON_INIT_VAR(key); + PHALCON_CONCAT_VSVV(key, class_name, "-", schema, table); - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { + 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_GET_HVALUE(extension); + PHALCON_OBS_NVAR(meta_data); + phalcon_read_property_this_quick(&meta_data, this_ptr, SL("_metaData"), 1295805989UL, PH_NOISY_CC); + } - PHALCON_INIT_NVAR(file_path); - PHALCON_CONCAT_VVSV(file_path, fixed_directory, file_name, ".", extension); + 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); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC); + PHALCON_MM_RESTORE(); +} + +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); - 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(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A model instance is required to retrieve the meta-data"); + return; + } - if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) { + PHALCON_INIT_VAR(key_name); + phalcon_get_class(key_name, model, 1 TSRMLS_CC); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL 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_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; - } + PHALCON_OBS_NVAR(column_map); + phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); + } - zend_hash_move_forward_ex(ah3, &hp3); - } + PHALCON_OBS_VAR(data); + phalcon_array_fetch(&data, column_map, key_name, PH_NOISY); - } - } + RETURN_CCTOR(data); +} + +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); - zend_hash_move_forward_ex(ah2, &hp2); ->>>>>>> 1.2.2 - } + 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; } - -<<<<<<< HEAD - if (!phalcon_array_isset_quick_string(params, SS("type"), 276192743UL)) { - phalcon_array_update_string_string(¶ms, SL("type"), SL("text/javascript"), PH_SEPARATE); + 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 (zend_is_true(local)) { - PHALCON_INIT_VAR(url); - PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); + PHALCON_INIT_VAR(key_name); + phalcon_get_class(key_name, model, 1 TSRMLS_CC); - PHALCON_OBS_VAR(params_src); - phalcon_array_fetch_quick_string(¶ms_src, params, SS("src"), 2090733773UL, PH_NOISY); + 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_INIT_VAR(src); - phalcon_call_method_p1_key(src, url, "getstatic", params_src, 2197271245UL); - phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &src, PH_COPY | PH_SEPARATE); + PHALCON_OBS_NVAR(column_map); + phalcon_read_property_this_quick(&column_map, this_ptr, SL("_columnMap"), 1530164624UL, PH_NOISY_CC); } - PHALCON_INIT_VAR(eol); - ZVAL_STRING(eol, PHP_EOL, 1); + PHALCON_OBS_VAR(column_map_model); + phalcon_array_fetch(&column_map_model, column_map, key_name, PH_NOISY); - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, "", eol); - - RETURN_CTOR(code); + RETURN_CCTOR(data); } -static PHP_METHOD(Phalcon_Tag, image){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getNonPrimaryKeyAttributes){ - zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; - zval *url, *url_src, *src, *code, *value = NULL, *key = NULL, *doctype; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *model, *index, *data; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, ¶meters, &local); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + phalcon_fetch_params(1, 1, 0, &model); - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); - } + PHALCON_INIT_VAR(index); + ZVAL_LONG(index, 2); - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } - if (!phalcon_array_isset_quick_string(params, SS("src"), 2090733773UL)) { - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_VAR(first_param); - phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY); - phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &first_param, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE); - } + 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; } - if (zend_is_true(local)) { - PHALCON_INIT_VAR(url); - PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); + RETURN_CCTOR(data); +} + +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getNotNullAttributes){ + + zval *model, *index, *data; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); - PHALCON_OBS_VAR(url_src); - phalcon_array_fetch_quick_string(&url_src, params, SS("src"), 2090733773UL, PH_NOISY); + PHALCON_INIT_VAR(index); + ZVAL_LONG(index, 3); - PHALCON_INIT_VAR(src); - phalcon_call_method_p1_key(src, url, "getstatic", url_src, 2197271245UL); - phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &src, PH_COPY | PH_SEPARATE); + 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; } - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, "") TSRMLS_CC); - } else { - phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); - } + PHALCON_INIT_VAR(index); + ZVAL_LONG(index, 8); - RETURN_CTOR(code); + PHALCON_INIT_VAR(data); + phalcon_call_method_p2_key(data, this_ptr, "readmetadataindex", model, index, 3936023514UL); + RETURN_CCTOR(data); } -static PHP_METHOD(Phalcon_Tag, friendlyTitle){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getBindTypes){ - zval *text, *separator = NULL, *lowercase = NULL, *pattern, *friendly; - zval *friendly_text = NULL; + zval *model, *index, *data; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &text, &separator, &lowercase); + phalcon_fetch_params(1, 1, 0, &model); - if (!separator) { - PHALCON_INIT_VAR(separator); - ZVAL_STRING(separator, "-", 1); - } + PHALCON_INIT_VAR(index); + ZVAL_LONG(index, 9); - if (!lowercase) { - PHALCON_INIT_VAR(lowercase); - ZVAL_BOOL(lowercase, 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; } - PHALCON_INIT_VAR(pattern); - ZVAL_STRING(pattern, "~[^a-z0-9A-Z]+~", 1); + RETURN_CCTOR(data); +} + +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(friendly); - phalcon_call_func_p3(friendly, "preg_replace", pattern, separator, text); - if (zend_is_true(lowercase)) { - PHALCON_INIT_VAR(friendly_text); - phalcon_fast_strtolower(friendly_text, friendly); - } else { - PHALCON_CPY_WRT(friendly_text, friendly); - } + PHALCON_INIT_VAR(index); + ZVAL_LONG(index, 10); - RETURN_CCTOR(friendly_text); -======= + 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; } - 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) { + RETURN_CCTOR(data); +} + +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getAutomaticUpdateAttributes){ + + zval *model, *index, *data; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); - PHALCON_GET_HVALUE(directory); + PHALCON_INIT_VAR(index); + ZVAL_LONG(index, 11); - PHALCON_INIT_NVAR(fixed_directory); - phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC); + 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; + } - phalcon_is_iterable(extensions, &ah5, &hp5, 0, 0); + RETURN_CCTOR(data); +} + +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, setAutomaticCreateAttributes){ + + zval *model, *attributes, *create_index; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &attributes); - while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { + 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_GET_HVALUE(extension); + PHALCON_MM_RESTORE(); +} + +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_NVAR(file_path); - PHALCON_CONCAT_VVSV(file_path, fixed_directory, ns_class_name, ".", extension); + PHALCON_INIT_VAR(create_index); + ZVAL_LONG(create_index, 11); + phalcon_call_method_p3_key(NULL, this_ptr, "writemetadataindex", model, create_index, attributes, 3417033257UL); - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_checkedPath"), file_path, 2930914648UL TSRMLS_CC); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getColumnMap){ + + zval *model, *index, *data; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &model); - 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_INIT_VAR(index); + ZVAL_LONG(index, 0); - if (phalcon_file_exists(file_path TSRMLS_CC) == SUCCESS) { + 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; + } + } - if (Z_TYPE_P(events_manager) == IS_OBJECT) { - phalcon_update_property_this_quick(this_ptr, SL("_foundPath"), file_path, 2210068013UL TSRMLS_CC); + RETURN_CCTOR(data); +} + +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, getReverseColumnMap){ + + zval *model, *index, *data; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &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); - } + PHALCON_INIT_VAR(index); + ZVAL_LONG(index, 1); - if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { - return; - } + 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_MM_TRUE; - } + RETURN_CCTOR(data); +} + +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); - zend_hash_move_forward_ex(ah5, &hp5); - } + if (Z_TYPE_P(attribute) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Attribute must be a string"); + return; + } - zend_hash_move_forward_ex(ah4, &hp4); + 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); - } - - 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); + 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; } -static PHP_METHOD(Phalcon_Loader, getFoundPath){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, isEmpty){ + zval *meta_data; - RETURN_MEMBER_QUICK(this_ptr, "_foundPath", 2210068013UL); + 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; } -static PHP_METHOD(Phalcon_Loader, getCheckedPath){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData, reset){ + zval *empty_array; - RETURN_MEMBER_QUICK(this_ptr, "_checkedPath", 2930914648UL); + 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(); } @@ -115563,117 +38600,97 @@ static PHP_METHOD(Phalcon_Loader, getCheckedPath){ -PHALCON_INIT_CLASS(Phalcon_Kernel){ - PHALCON_REGISTER_CLASS(Phalcon, Kernel, kernel, phalcon_kernel_method_entry, 0); +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_Kernel, preComputeHashKey){ +static PHP_METHOD(Phalcon_Mvc_Model_ValidationFailed, __construct){ - char *arKey, *strKey; - unsigned int nKeyLength; - register ulong hash = 5381; + zval *model, *validation_messages, *message; + zval *message_str = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { - RETURN_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(); +} - nKeyLength++; +static PHP_METHOD(Phalcon_Mvc_Model_ValidationFailed, getMessages){ - /* 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++; - } - 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_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); +} - strKey = emalloc(24); - sprintf(strKey, "%lu", hash); +static PHP_METHOD(Phalcon_Mvc_Model_ValidationFailed, getModel){ - RETURN_STRING(strKey, 0); + + RETURN_MEMBER_QUICK(this_ptr, "_model", 2599397109UL); } -static PHP_METHOD(Phalcon_Kernel, preComputeHashKey32){ - char *arKey, *strKey; - unsigned int nKeyLength; - ulong hash; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { - RETURN_NULL(); - } - nKeyLength++; - hash = zend_inline_hash_func(arKey, nKeyLength) & 0xFFFFFFFFul; - strKey = emalloc(24); - sprintf(strKey, "%lu", hash); - RETURN_STRING(strKey, 0); +#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; } -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(); - } - 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++; - } +#ifdef HAVE_CONFIG_H +#endif - 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; - } - strKey = emalloc(24); - sprintf(strKey, "%llu", hash); - RETURN_STRING(strKey, 0); +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 @@ -115683,112 +38700,95 @@ static PHP_METHOD(Phalcon_Kernel, preComputeHashKey64){ -PHALCON_INIT_CLASS(Phalcon_Db){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Session){ - PHALCON_REGISTER_CLASS(Phalcon, Db, db, phalcon_db_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\MetaData, Session, mvc_model_metadata_session, "phalcon\\mvc\\model\\metadata", phalcon_mvc_model_metadata_session_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_declare_property_string(phalcon_mvc_model_metadata_session_ce, SL("_prefix"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_metadata_session_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Db, setup){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Session, __construct){ - zval *options, *escape_identifiers; + zval *options = NULL, *prefix, *empty_array; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &options); + phalcon_fetch_params(1, 0, 1, &options); - if (Z_TYPE_P(options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Options must be an array"); - return; + if (!options) { + PHALCON_INIT_VAR(options); } - 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); + if (Z_TYPE_P(options) == IS_ARRAY) { + 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(empty_array); + array_init(empty_array); + phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); + PHALCON_MM_RESTORE(); ->>>>>>> 1.2.2 } -static PHP_METHOD(Phalcon_Tag, setDocType){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Session, read){ - zval *doctype; + zval *key, *session = NULL, *_SESSION, *prefix, *prefix_key; + zval *meta_data; + zval *r0 = NULL, *r1 = NULL; - phalcon_fetch_params(0, 1, 0, &doctype); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &key); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentType"), doctype TSRMLS_CC); + phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); + PHALCON_CPY_WRT(session, _SESSION); + + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(prefix_key); + PHALCON_CONCAT_SV(prefix_key, "$PMM$", prefix); + if (phalcon_array_isset(session, prefix_key)) { + + PHALCON_OBS_VAR(r0); + phalcon_array_fetch(&r0, session, prefix_key, PH_NOISY); + if (phalcon_array_isset(r0, key)) { + PHALCON_OBS_VAR(r1); + phalcon_array_fetch(&r1, session, prefix_key, PH_NOISY); + PHALCON_OBS_VAR(meta_data); + phalcon_array_fetch(&meta_data, r1, key, PH_NOISY); + RETURN_CCTOR(meta_data); + } + } + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Tag, getDocType){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Session, write){ - zval *doctype = NULL, *declaration, *eol, *doctype_html; + zval *key, *data, *prefix, *prefix_key, *_SESSION; PHALCON_MM_GROW(); - PHALCON_OBSERVE_VAR(doctype); - phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); - -<<<<<<< HEAD - PHALCON_INIT_VAR(eol); - ZVAL_STRING(eol, PHP_EOL, 1); - - PHALCON_INIT_VAR(declaration); - if (phalcon_compare_strict_long(doctype, 1 TSRMLS_CC)) { - ZVAL_STRING(declaration, " PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\"", 1); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 2 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01//EN\"", eol, "\t\"http://www.w3.org/TR/html4/strict.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 3 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"", eol, "\t\"http://www.w3.org/TR/html4/loose.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 4 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"", eol, "\t\"http://www.w3.org/TR/html4/frameset.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 6 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 7 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 8 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 9 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 10 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 2.0//EN\"", eol, "\t\"http://www.w3.org/MarkUp/DTD/xhtml2.dtd\""); - goto ph_end_0; - } - - ph_end_0: - - PHALCON_INIT_VAR(doctype_html); - PHALCON_CONCAT_SVSV(doctype_html, "", eol); -======= -PHALCON_INIT_CLASS(Phalcon_Session){ - - PHALCON_REGISTER_CLASS(Phalcon, Session, session, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - return SUCCESS; + phalcon_fetch_params(1, 2, 0, &key, &data); + + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(prefix_key); + PHALCON_CONCAT_SV(prefix_key, "$PMM$", prefix); + phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); + phalcon_array_update_multi_2(&_SESSION, prefix_key, key, &data, 0); + + PHALCON_MM_RESTORE(); } @@ -115804,766 +38804,744 @@ PHALCON_INIT_CLASS(Phalcon_Session){ -PHALCON_INIT_CLASS(Phalcon_Tag){ - - PHALCON_REGISTER_CLASS(Phalcon, Tag, tag, phalcon_tag_method_entry, 0); - - zend_declare_property_null(phalcon_tag_ce, SL("_displayValues"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_null(phalcon_tag_ce, SL("_documentTitle"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_long(phalcon_tag_ce, SL("_documentType"), 11, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_null(phalcon_tag_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_null(phalcon_tag_ce, SL("_urlService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_null(phalcon_tag_ce, SL("_dispatcherService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_null(phalcon_tag_ce, SL("_escaperService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); - zend_declare_property_bool(phalcon_tag_ce, SL("_autoEscape"), 1, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Strategy_Introspection){ - zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML32"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_STRICT"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_TRANSITIONAL"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_FRAMESET"), 4 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML5"), 5 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_STRICT"), 6 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_TRANSITIONAL"), 7 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_FRAMESET"), 8 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML11"), 9 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML20"), 10 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML5"), 11 TSRMLS_CC); ->>>>>>> 1.2.2 + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\MetaData\\Strategy, Introspection, mvc_model_metadata_strategy_introspection, phalcon_mvc_model_metadata_strategy_introspection_method_entry, 0); - RETURN_CTOR(doctype_html); + return SUCCESS; } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Tag, tagHtml){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Introspection, getMetaData){ - zval *tag_name, *parameters = NULL, *self_close = NULL, *only_start = NULL; - zval *use_eol = NULL, *params = NULL, *local_code, *value = NULL, *key = NULL; - zval *doctype, *eol; + zval *model, *dependency_injector, *class_name; + zval *schema, *table, *read_connection, *exists; + zval *complete_table = NULL, *exception_message = NULL; + zval *columns, *attributes, *primary_keys, *non_primary_keys; + zval *numeric_typed, *not_null, *field_types; + zval *field_bind_types, *automatic_default; + zval *identity_field = NULL, *column = NULL, *field_name = NULL, *feature = NULL; + zval *type = NULL, *bind_type = NULL, *model_metadata; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 4, &tag_name, ¶meters, &self_close, &only_start, &use_eol); + phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 0 TSRMLS_CC); - if (!self_close) { - PHALCON_INIT_VAR(self_close); - ZVAL_BOOL(self_close, 0); - } + PHALCON_INIT_VAR(schema); + phalcon_call_method_key(schema, model, "getschema", 1539736246UL); - if (!only_start) { - PHALCON_INIT_VAR(only_start); - ZVAL_BOOL(only_start, 0); - } + PHALCON_INIT_VAR(table); + phalcon_call_method_key(table, model, "getsource", 2025234358UL); - if (!use_eol) { - PHALCON_INIT_VAR(use_eol); - ZVAL_BOOL(use_eol, 0); + PHALCON_INIT_VAR(read_connection); + phalcon_call_method_key(read_connection, model, "getreadconnection", 488334257UL); + + PHALCON_INIT_VAR(exists); + phalcon_call_method_p2_key(exists, read_connection, "tableexists", table, schema, 1944065613UL); + if (!zend_is_true(exists)) { + if (zend_is_true(schema)) { + PHALCON_INIT_VAR(complete_table); + PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); + } else { + PHALCON_CPY_WRT(complete_table, table); + } + + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "Table \"", complete_table, "\" doesn't exist on database when dumping meta-data for ", class_name); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); + PHALCON_INIT_VAR(columns); + phalcon_call_method_p2_key(columns, read_connection, "describecolumns", table, schema, 4645575UL); + if (!phalcon_fast_count_ev(columns TSRMLS_CC)) { + if (zend_is_true(schema)) { + PHALCON_INIT_NVAR(complete_table); + PHALCON_CONCAT_VSV(complete_table, schema, "\".\"", table); + } else { + PHALCON_CPY_WRT(complete_table, table); + } + + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SVSV(exception_message, "Cannot obtain table columns for the mapped source \"", complete_table, "\" used in model ", class_name); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } - PHALCON_INIT_VAR(local_code); - PHALCON_CONCAT_SV(local_code, "<", tag_name); + PHALCON_INIT_VAR(attributes); + array_init(attributes); - phalcon_is_iterable(params, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(primary_keys); + array_init(primary_keys); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(non_primary_keys); + array_init(non_primary_keys); - PHALCON_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + PHALCON_INIT_VAR(numeric_typed); + array_init(numeric_typed); - if (Z_TYPE_P(key) != IS_LONG) { - PHALCON_SCONCAT_SVSVS(local_code, " ", key, "=\"", value, "\""); - } + PHALCON_INIT_VAR(not_null); + array_init(not_null); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_VAR(field_types); + array_init(field_types); - PHALCON_OBS_VAR(doctype); - phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); + PHALCON_INIT_VAR(field_bind_types); + array_init(field_bind_types); - if (PHALCON_GT_LONG(doctype, 5)) { - if (zend_is_true(self_close)) { - phalcon_concat_self_str(&local_code, SL(" />") TSRMLS_CC); - } else { - phalcon_concat_self_str(&local_code, SL(">") TSRMLS_CC); - } - } else { - if (zend_is_true(only_start)) { - phalcon_concat_self_str(&local_code, SL(">") TSRMLS_CC); - } else { - PHALCON_SCONCAT_SVS(local_code, ">"); - } -======= -static PHP_METHOD(Phalcon_Tag, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); + PHALCON_INIT_VAR(automatic_default); + array_init(automatic_default); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_tag_exception_ce, "Parameter dependencyInjector must be an Object"); - return; - } - phalcon_update_static_property(SL("phalcon\\tag"), SL("_dependencyInjector"), dependency_injector TSRMLS_CC); + PHALCON_INIT_VAR(identity_field); + ZVAL_BOOL(identity_field, 0); -} - -static PHP_METHOD(Phalcon_Tag, getDI){ - - zval *dependency_injector; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_CC); - RETURN_CCTOR(dependency_injector); -} - -static PHP_METHOD(Phalcon_Tag, getUrlService){ - - zval *url = NULL, *dependency_injector = NULL, *service; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(url); - phalcon_read_static_property(&url, SL("phalcon\\tag"), SL("_urlService") TSRMLS_CC); - if (Z_TYPE_P(url) != IS_OBJECT) { + phalcon_is_iterable(columns, &ah0, &hp0, 0, 0); - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the \"url\" service"); - return; - } + PHALCON_GET_HVALUE(column); - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "url", 1); + PHALCON_INIT_NVAR(field_name); + phalcon_call_method_key(field_name, column, "getname", 4286441094UL); + phalcon_array_append(&attributes, field_name, PH_SEPARATE); - PHALCON_INIT_NVAR(url); - phalcon_call_method_p1_key(url, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_urlService"), url TSRMLS_CC); - } + PHALCON_INIT_NVAR(feature); + phalcon_call_method_key(feature, column, "isprimary", 3539965925UL); + if (PHALCON_IS_TRUE(feature)) { + phalcon_array_append(&primary_keys, field_name, PH_SEPARATE); + } else { + phalcon_array_append(&non_primary_keys, field_name, PH_SEPARATE); + } - RETURN_CCTOR(url); -} - -static PHP_METHOD(Phalcon_Tag, getEscaperService){ - - zval *escaper = NULL, *dependency_injector = NULL, *service; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(escaper); - phalcon_read_static_property(&escaper, SL("phalcon\\tag"), SL("_escaperService") TSRMLS_CC); - if (Z_TYPE_P(escaper) != IS_OBJECT) { + PHALCON_INIT_NVAR(feature); + phalcon_call_method_key(feature, column, "isnumeric", 3929517108UL); + if (PHALCON_IS_TRUE(feature)) { + phalcon_array_update_zval_bool(&numeric_typed, field_name, 1, PH_SEPARATE); + } - PHALCON_OBS_VAR(dependency_injector); - phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_CC); - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_INIT_NVAR(dependency_injector); - PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); + PHALCON_INIT_NVAR(feature); + phalcon_call_method_key(feature, column, "isnotnull", 760409005UL); + if (PHALCON_IS_TRUE(feature)) { + phalcon_array_append(¬_null, field_name, PH_SEPARATE); } - if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "A dependency injector container is required to obtain the \"escaper\" service"); - return; + PHALCON_INIT_NVAR(feature); + phalcon_call_method_key(feature, column, "isautoincrement", 572890271UL); + if (PHALCON_IS_TRUE(feature)) { + PHALCON_CPY_WRT(identity_field, field_name); } - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "escaper", 1); + PHALCON_INIT_NVAR(type); + phalcon_call_method_key(type, column, "gettype", 4294422375UL); + phalcon_array_update_zval(&field_types, field_name, &type, PH_COPY | PH_SEPARATE); - PHALCON_INIT_NVAR(escaper); - phalcon_call_method_p1_key(escaper, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_escaperService"), escaper TSRMLS_CC); - } + PHALCON_INIT_NVAR(bind_type); + phalcon_call_method_key(bind_type, column, "getbindtype", 13600356UL); + phalcon_array_update_zval(&field_bind_types, field_name, &bind_type, PH_COPY | PH_SEPARATE); - RETURN_CCTOR(escaper); -} - -static PHP_METHOD(Phalcon_Tag, setAutoescape){ - - zval *autoescape; - - phalcon_fetch_params(0, 1, 0, &autoescape); + zend_hash_move_forward_ex(ah0, &hp0); + } - phalcon_update_static_property(SL("phalcon\\tag"), SL("_autoEscape"), autoescape TSRMLS_CC); + PHALCON_INIT_VAR(model_metadata); + array_init(model_metadata); + phalcon_array_update_long(&model_metadata, 0, &attributes, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 4, &field_types, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 9, &field_bind_types, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 10, &automatic_default, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 11, &automatic_default, PH_COPY | PH_SEPARATE); + RETURN_CTOR(model_metadata); } -static PHP_METHOD(Phalcon_Tag, setDefault){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Introspection, getColumnMaps){ - zval *id, *value; - zval *t0 = NULL; + zval *model, *dependency_injector, *ordered_column_map = NULL; + zval *reversed_column_map = NULL, *user_column_map; + zval *user_name = NULL, *name = NULL, *model_column_map; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &id, &value); + phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); - if (Z_TYPE_P(value) != IS_NULL) { - if (Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "Only scalar values can be assigned to UI components"); + PHALCON_INIT_VAR(ordered_column_map); + + PHALCON_INIT_VAR(reversed_column_map); + + if (phalcon_method_quick_exists_ex(model, SS("columnmap"), 673371633UL TSRMLS_CC) == SUCCESS) { + + PHALCON_INIT_VAR(user_column_map); + phalcon_call_method_key(user_column_map, model, "columnmap", 673371633UL); + if (Z_TYPE_P(user_column_map) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "columnMap() not returned an array"); return; } - } - PHALCON_OBSERVE_VAR(t0); - phalcon_read_static_property(&t0, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); - if (Z_TYPE_P(t0) != IS_ARRAY) { - convert_to_array(t0); ->>>>>>> 1.2.2 - } - phalcon_array_update_zval(&t0, id, &value, PH_COPY); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), t0 TSRMLS_CC); -<<<<<<< HEAD - if (zend_is_true(use_eol)) { - PHALCON_INIT_VAR(eol); - ZVAL_STRING(eol, PHP_EOL, 1); - phalcon_concat_self(&local_code, eol TSRMLS_CC); - } + array_init(reversed_column_map); + PHALCON_CPY_WRT(ordered_column_map, user_column_map); - RETURN_CTOR(local_code); -} - -static PHP_METHOD(Phalcon_Tag, tagHtmlClose){ - - zval *tag_name, *use_eol = NULL, *local_code, *eol; -======= + phalcon_is_iterable(user_column_map, &ah0, &hp0, 0, 0); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Tag, setDefaults){ ->>>>>>> 1.2.2 - - zval *values; - -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 1, &tag_name, &use_eol); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (!use_eol) { - PHALCON_INIT_VAR(use_eol); - ZVAL_BOOL(use_eol, 0); - } + PHALCON_GET_HKEY(name, ah0, hp0); + PHALCON_GET_HVALUE(user_name); - PHALCON_INIT_VAR(local_code); - PHALCON_CONCAT_SVS(local_code, ""); - if (zend_is_true(use_eol)) { - PHALCON_INIT_VAR(eol); - ZVAL_STRING(eol, PHP_EOL, 1); - phalcon_concat_self(&local_code, eol TSRMLS_CC); - } + phalcon_array_update_zval(&reversed_column_map, user_name, &name, PH_COPY | PH_SEPARATE); - RETURN_CTOR(local_code); -======= - phalcon_fetch_params(0, 1, 0, &values); + zend_hash_move_forward_ex(ah0, &hp0); + } - if (Z_TYPE_P(values) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_tag_exception_ce, "An array is required as default values"); - return; } - phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), values TSRMLS_CC); - ->>>>>>> 1.2.2 -} - -static PHP_METHOD(Phalcon_Tag, displayTo){ - - zval *id, *value, *default_value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &id, &value); - PHALCON_INIT_VAR(default_value); - PHALCON_CALL_SELF_PARAMS_2(default_value, this_ptr, "setdefault", id, value); - RETURN_CCTOR(default_value); + PHALCON_INIT_VAR(model_column_map); + array_init(model_column_map); + phalcon_array_update_long(&model_column_map, 0, &ordered_column_map, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_column_map, 1, &reversed_column_map, PH_COPY | PH_SEPARATE); + + RETURN_CTOR(model_column_map); } -static PHP_METHOD(Phalcon_Tag, hasValue){ -<<<<<<< HEAD +#ifdef HAVE_CONFIG_H +#endif -PHALCON_INIT_CLASS(Phalcon_Security){ - PHALCON_REGISTER_CLASS(Phalcon, Security, security, phalcon_security_method_entry, 0); - 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); -======= - zval *name, *display_values, *_POST; - PHALCON_MM_GROW(); ->>>>>>> 1.2.2 - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_OBS_VAR(display_values); - phalcon_read_static_property(&display_values, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); - - if (phalcon_array_isset(display_values, name)) { - RETURN_MM_TRUE; - } else { - phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); - if (phalcon_array_isset(_POST, name)) { - RETURN_MM_TRUE; - } - } - - RETURN_MM_FALSE; -} -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Security, setDI){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Strategy_Annotations){ - zval *dependency_injector; + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model\\MetaData\\Strategy, Annotations, mvc_model_metadata_strategy_annotations, phalcon_mvc_model_metadata_strategy_annotations_method_entry, 0); - phalcon_fetch_params(0, 1, 0, &dependency_injector); - - phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - + return SUCCESS; } -static PHP_METHOD(Phalcon_Security, getDI){ -======= -static PHP_METHOD(Phalcon_Tag, getValue){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getMetaData){ - zval *name, *params = NULL, *display_values, *value = NULL, *_POST; - zval *autoescape = NULL, *escaper = NULL; + zval *model, *dependency_injector, *service; + zval *annotations, *class_name, *reflection; + zval *exception_message = NULL, *properties_annotations; + zval *attributes, *primary_keys, *non_primary_keys; + zval *numeric_typed, *not_null, *field_types; + zval *field_bind_types, *automatic_default; + zval *identity_field = NULL, *column_annot_name; + zval *primary_annot_name, *id_annot_name; + zval *column_type_name, *column_nullable_name; + zval *prop_annotations = NULL, *property = NULL, *has_annotation = NULL; + zval *column_annotation = NULL, *feature = NULL, *model_metadata; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, ¶ms); + phalcon_fetch_params(1, 2, 0, &model, &dependency_injector); - if (!params) { - PHALCON_INIT_VAR(params); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The dependency injector is invalid"); + return; } - PHALCON_OBS_VAR(display_values); - phalcon_read_static_property(&display_values, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "annotations", 1); - if (phalcon_array_isset(display_values, name)) { - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, display_values, name, PH_NOISY); - } else { - phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); - if (phalcon_array_isset(_POST, name)) { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch(&value, _POST, name, PH_NOISY); - } else { - RETURN_MM_NULL(); - } + PHALCON_INIT_VAR(annotations); + phalcon_call_method_p1_key(annotations, dependency_injector, "get", service, 2090288933UL); + + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 0 TSRMLS_CC); + + PHALCON_INIT_VAR(reflection); + phalcon_call_method_p1_key(reflection, annotations, "get", class_name, 2090288933UL); + if (Z_TYPE_P(reflection) != IS_OBJECT) { + PHALCON_INIT_VAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "No annotations were found in class ", class_name); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; } - PHALCON_OBS_VAR(autoescape); - phalcon_read_static_property(&autoescape, SL("phalcon\\tag"), SL("_autoEscape") TSRMLS_CC); + PHALCON_INIT_VAR(properties_annotations); + phalcon_call_method_key(properties_annotations, reflection, "getpropertiesannotations", 3353352384UL); + if (!phalcon_fast_count_ev(properties_annotations TSRMLS_CC)) { + PHALCON_INIT_NVAR(exception_message); + PHALCON_CONCAT_SV(exception_message, "No properties with annotations were found in class ", class_name); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_model_exception_ce, exception_message); + return; + } - if (Z_TYPE_P(value) == IS_STRING) { - if (zend_is_true(autoescape)) { - PHALCON_INIT_VAR(escaper); - PHALCON_CALL_SELF(escaper, this_ptr, "getescaperservice"); - phalcon_call_method_p1_key(return_value, escaper, "escapehtmlattr", value, 4208410982UL); - RETURN_MM(); - } else { - if (Z_TYPE_P(params) == IS_ARRAY) { + PHALCON_INIT_VAR(attributes); + array_init(attributes); - if (phalcon_array_isset_quick_string(params, SS("escape"), 1978755574UL)) { + PHALCON_INIT_VAR(primary_keys); + array_init(primary_keys); - PHALCON_OBS_NVAR(autoescape); - phalcon_array_fetch_quick_string(&autoescape, params, SS("escape"), 1978755574UL, PH_NOISY); - if (zend_is_true(autoescape)) { - PHALCON_INIT_NVAR(escaper); - PHALCON_CALL_SELF(escaper, this_ptr, "getescaperservice"); - phalcon_call_method_p1_key(return_value, escaper, "escapehtmlattr", value, 4208410982UL); - RETURN_MM(); + PHALCON_INIT_VAR(non_primary_keys); + array_init(non_primary_keys); + + PHALCON_INIT_VAR(numeric_typed); + array_init(numeric_typed); + + PHALCON_INIT_VAR(not_null); + array_init(not_null); + + PHALCON_INIT_VAR(field_types); + array_init(field_types); + + PHALCON_INIT_VAR(field_bind_types); + array_init(field_bind_types); + + PHALCON_INIT_VAR(automatic_default); + array_init(automatic_default); + + PHALCON_INIT_VAR(identity_field); + ZVAL_BOOL(identity_field, 0); + + PHALCON_INIT_VAR(column_annot_name); + ZVAL_STRING(column_annot_name, "Column", 1); + + PHALCON_INIT_VAR(primary_annot_name); + ZVAL_STRING(primary_annot_name, "Primary", 1); + + PHALCON_INIT_VAR(id_annot_name); + ZVAL_STRING(id_annot_name, "Identity", 1); + + PHALCON_INIT_VAR(column_type_name); + ZVAL_STRING(column_type_name, "type", 1); + + PHALCON_INIT_VAR(column_nullable_name); + ZVAL_STRING(column_nullable_name, "nullable", 1); + + phalcon_is_iterable(properties_annotations, &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(prop_annotations); + + PHALCON_INIT_NVAR(has_annotation); + phalcon_call_method_p1_key(has_annotation, prop_annotations, "has", column_annot_name, 2090320481UL); + if (!zend_is_true(has_annotation)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + + PHALCON_INIT_NVAR(column_annotation); + phalcon_call_method_p1_key(column_annotation, prop_annotations, "get", column_annot_name, 2090288933UL); + + PHALCON_INIT_NVAR(feature); + phalcon_call_method_p1_key(feature, column_annotation, "getnamedparameter", column_type_name, 3202516043UL); + if (PHALCON_IS_STRING(feature, "integer")) { + phalcon_array_update_zval_long(&field_types, property, 0, PH_SEPARATE); + phalcon_array_update_zval_long(&field_bind_types, property, 1, PH_SEPARATE); + phalcon_array_update_zval_bool(&numeric_typed, property, 1, PH_SEPARATE); + } else { + if (PHALCON_IS_STRING(feature, "decimal")) { + phalcon_array_update_zval_long(&field_types, property, 3, PH_SEPARATE); + phalcon_array_update_zval_long(&field_bind_types, property, 32, PH_SEPARATE); + phalcon_array_update_zval_bool(&numeric_typed, property, 1, PH_SEPARATE); + } else { + if (PHALCON_IS_STRING(feature, "boolean")) { + phalcon_array_update_zval_long(&field_types, property, 8, PH_SEPARATE); + phalcon_array_update_zval_long(&field_bind_types, property, 5, PH_SEPARATE); + } else { + if (PHALCON_IS_STRING(feature, "date")) { + phalcon_array_update_zval_long(&field_types, property, 1, PH_SEPARATE); + } else { + phalcon_array_update_zval_long(&field_types, property, 2, PH_SEPARATE); } + phalcon_array_update_zval_long(&field_bind_types, property, 2, PH_SEPARATE); } } } + + PHALCON_INIT_NVAR(has_annotation); + phalcon_call_method_p1_key(has_annotation, prop_annotations, "has", primary_annot_name, 2090320481UL); + if (zend_is_true(has_annotation)) { + phalcon_array_append(&primary_keys, property, PH_SEPARATE); + } else { + phalcon_array_append(&non_primary_keys, property, PH_SEPARATE); + } + + PHALCON_INIT_NVAR(has_annotation); + phalcon_call_method_p1_key(has_annotation, prop_annotations, "has", id_annot_name, 2090320481UL); + if (zend_is_true(has_annotation)) { + PHALCON_CPY_WRT(identity_field, property); + } + + PHALCON_INIT_NVAR(feature); + phalcon_call_method_p1_key(feature, column_annotation, "getnamedparameter", column_nullable_name, 3202516043UL); + if (!zend_is_true(feature)) { + phalcon_array_append(¬_null, property, PH_SEPARATE); + } + + phalcon_array_append(&attributes, property, PH_SEPARATE); + + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CCTOR(value); -} ->>>>>>> 1.2.2 - -static PHP_METHOD(Phalcon_Tag, resetInput){ - -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); + PHALCON_INIT_VAR(model_metadata); + array_init(model_metadata); + phalcon_array_update_long(&model_metadata, 0, &attributes, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 1, &primary_keys, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 2, &non_primary_keys, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 3, ¬_null, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 4, &field_types, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 5, &numeric_typed, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 8, &identity_field, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 9, &field_bind_types, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 10, &automatic_default, PH_COPY | PH_SEPARATE); + phalcon_array_update_long(&model_metadata, 11, &automatic_default, PH_COPY | PH_SEPARATE); + + RETURN_CTOR(model_metadata); } -static PHP_METHOD(Phalcon_Security, setRandomBytes){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Strategy_Annotations, getColumnMaps){ - zval *random_bytes; - phalcon_fetch_params(0, 1, 0, &random_bytes); - - 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_update_property_this_quick(this_ptr, SL("_numberBytes"), random_bytes, 1300189556UL TSRMLS_CC); } -static PHP_METHOD(Phalcon_Security, getRandomBytes){ -======= - zval *empty_array = NULL; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), empty_array TSRMLS_CC); - phalcon_set_symbol_str(SS("_POST"), empty_array TSRMLS_CC); +#ifdef HAVE_CONFIG_H +#endif - PHALCON_MM_RESTORE(); -} ->>>>>>> 1.2.2 -static PHP_METHOD(Phalcon_Tag, linkTo){ -<<<<<<< HEAD - 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); - -} -static PHP_METHOD(Phalcon_Security, getWorkFactor){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Apc){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Model\\MetaData, Apc, mvc_model_metadata_apc, "phalcon\\mvc\\model\\metadata", phalcon_mvc_model_metadata_apc_method_entry, 0); + zend_declare_property_string(phalcon_mvc_model_metadata_apc_ce, SL("_prefix"), "", ZEND_ACC_PROTECTED TSRMLS_CC); + zend_declare_property_long(phalcon_mvc_model_metadata_apc_ce, SL("_ttl"), 172800, ZEND_ACC_PROTECTED TSRMLS_CC); - RETURN_MEMBER_QUICK(this_ptr, "_workFactor", 3598705926UL); + zend_class_implements(phalcon_mvc_model_metadata_apc_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Security, getSaltBytes){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, __construct){ - zval *number_bytes, *random_bytes = NULL, *base64bytes = NULL; - zval *safe_bytes = NULL, *bytes_length = NULL; + zval *options = NULL, *prefix, *ttl, *empty_array; 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_OBS_VAR(number_bytes); - phalcon_read_property_this_quick(&number_bytes, this_ptr, SL("_numberBytes"), 1300189556UL, PH_NOISY_CC); - - while (1) { - - PHALCON_INIT_NVAR(random_bytes); - phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); + phalcon_fetch_params(1, 0, 1, &options); - PHALCON_INIT_NVAR(base64bytes); - phalcon_base64_encode(base64bytes, random_bytes); + if (!options) { + PHALCON_INIT_VAR(options); + } - PHALCON_INIT_NVAR(safe_bytes); - phalcon_filter_alphanum(safe_bytes, base64bytes); - if (!zend_is_true(safe_bytes)) { - continue; + if (Z_TYPE_P(options) == IS_ARRAY) { + 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_NVAR(bytes_length); - phalcon_fast_strlen(bytes_length, safe_bytes); - if (PHALCON_LT_LONG(bytes_length, 22)) { - continue; + if (phalcon_array_isset_quick_string(options, SS("lifetime"), 2639810228UL)) { + PHALCON_OBS_VAR(ttl); + phalcon_array_fetch_quick_string(&ttl, options, SS("lifetime"), 2639810228UL, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_ttl"), ttl, 251113304UL TSRMLS_CC); } - - break; } - RETURN_CTOR(safe_bytes); + PHALCON_INIT_VAR(empty_array); + array_init(empty_array); + phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Security, hash){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, read){ - zval *password, *work_factor = NULL, *format, *factor; - zval *salt_bytes, *salt; + zval *key, *prefix, *apc_key, *data; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &password, &work_factor); - - if (!work_factor) { - PHALCON_INIT_VAR(work_factor); - } else { - PHALCON_SEPARATE_PARAM(work_factor); - } - - 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_fetch_params(1, 1, 0, &key); - PHALCON_INIT_VAR(format); - ZVAL_STRING(format, "%02s", 1); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - PHALCON_INIT_VAR(factor); - phalcon_call_func_p2(factor, "sprintf", format, work_factor); + PHALCON_INIT_VAR(apc_key); + PHALCON_CONCAT_SVV(apc_key, "$PMM$", prefix, key); - PHALCON_INIT_VAR(salt_bytes); - phalcon_call_method_key(salt_bytes, this_ptr, "getsaltbytes", 2293626208UL); + PHALCON_INIT_VAR(data); + phalcon_call_func_p1(data, "apc_fetch", apc_key); + if (Z_TYPE_P(data) == IS_ARRAY) { + RETURN_CCTOR(data); + } - PHALCON_INIT_VAR(salt); - PHALCON_CONCAT_SVSV(salt, "$2a$", factor, "$", salt_bytes); - phalcon_call_func_p2(return_value, "crypt", password, salt); - RETURN_MM(); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Security, checkHash){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Apc, write){ - zval *password, *password_hash, *hash; + zval *key, *data, *prefix, *apc_key, *ttl; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &password, &password_hash); + phalcon_fetch_params(1, 2, 0, &key, &data); - 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(); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); + + PHALCON_INIT_VAR(apc_key); + PHALCON_CONCAT_SVV(apc_key, "$PMM$", prefix, key); + + PHALCON_OBS_VAR(ttl); + phalcon_read_property_this_quick(&ttl, this_ptr, SL("_ttl"), 251113304UL, PH_NOISY_CC); + phalcon_call_func_p3_noret("apc_store", apc_key, data, ttl); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Security, isLegacyHash){ - zval *password_hash; - phalcon_fetch_params(0, 1, 0, &password_hash); - - if (phalcon_start_with_str(password_hash, SL("$2a$"))) { - RETURN_TRUE; - } - RETURN_FALSE; + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_MetaData_Files){ + + 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); + + zend_declare_property_string(phalcon_mvc_model_metadata_files_ce, SL("_metaDataDir"), "./", ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_mvc_model_metadata_files_ce TSRMLS_CC, 1, phalcon_mvc_model_metadatainterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Security, getTokenKey){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, __construct){ - zval *number_bytes = NULL, *random_bytes, *base64bytes; - zval *safe_bytes, *dependency_injector, *service; - zval *session, *key; + zval *options = NULL, *meta_data_dir, *empty_array; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &number_bytes); + phalcon_fetch_params(1, 0, 1, &options); - if (!number_bytes) { - PHALCON_INIT_VAR(number_bytes); - ZVAL_LONG(number_bytes, 12); + if (!options) { + PHALCON_INIT_VAR(options); } - 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 (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); + } } - PHALCON_INIT_VAR(random_bytes); - phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); + PHALCON_INIT_VAR(empty_array); + array_init(empty_array); + phalcon_update_property_this_quick(this_ptr, SL("_metaData"), empty_array, 1295805989UL TSRMLS_CC); - PHALCON_INIT_VAR(base64bytes); - phalcon_base64_encode(base64bytes, random_bytes); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, read){ + + zval *key, *separator, *meta_data_dir, *virtual_key; + zval *path, *data; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &key); - PHALCON_INIT_VAR(safe_bytes); - phalcon_filter_alphanum(safe_bytes, base64bytes); + PHALCON_INIT_VAR(separator); + ZVAL_STRING(separator, "_", 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_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); - return; - } + 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(service); - ZVAL_STRING(service, "session", 1); + PHALCON_INIT_VAR(virtual_key); + phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); - PHALCON_INIT_VAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + PHALCON_INIT_VAR(path); + PHALCON_CONCAT_VVS(path, meta_data_dir, virtual_key, ".php"); - PHALCON_INIT_VAR(key); - ZVAL_STRING(key, "$PHALCON/CSRF/KEY$", 1); - phalcon_call_method_p2_key(NULL, session, "set", key, safe_bytes, 2090720177UL); + 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); + } - RETURN_CTOR(safe_bytes); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Security, getToken){ +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Files, write){ - zval *number_bytes = NULL, *random_bytes, *token, *dependency_injector; - zval *service, *session, *key; + zval *key, *data, *separator, *meta_data_dir, *virtual_key; + zval *path, *to_string, *export, *php_export, *status; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &number_bytes); + phalcon_fetch_params(1, 2, 0, &key, &data); - if (!number_bytes) { - PHALCON_INIT_VAR(number_bytes); - ZVAL_LONG(number_bytes, 12); - } + PHALCON_INIT_VAR(separator); + ZVAL_STRING(separator, "_", 1); - 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(meta_data_dir); + phalcon_read_property_this_quick(&meta_data_dir, this_ptr, SL("_metaDataDir"), 1346965284UL, PH_NOISY_CC); - PHALCON_INIT_VAR(random_bytes); - phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); + PHALCON_INIT_VAR(virtual_key); + phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); - PHALCON_INIT_VAR(token); - phalcon_md5(token, random_bytes); + PHALCON_INIT_VAR(path); + PHALCON_CONCAT_VVS(path, meta_data_dir, virtual_key, ".php"); - 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(to_string); + ZVAL_BOOL(to_string, 1); - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "session", 1); + PHALCON_INIT_VAR(export); + phalcon_call_func_p2(export, "var_export", data, to_string); - PHALCON_INIT_VAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + PHALCON_INIT_VAR(php_export); + PHALCON_CONCAT_SVS(php_export, "", text, ""); + RETURN_NULL(); +} + +static PHP_METHOD(Phalcon_Mvc_Model_MetaData_Memory, write){ + + zval *key, *meta_data; + + phalcon_fetch_params(0, 2, 0, &key, &meta_data); - RETURN_CTOR(code); + RETURN_NULL(); } -static PHP_METHOD(Phalcon_Tag, _inputField){ - zval *type, *parameters, *as_value = NULL, *params = NULL, *value = NULL; - zval *id = NULL, *name, *code, *key = NULL, *doctype; + + + +#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, 1, &type, ¶meters, &as_value); + phalcon_fetch_params(1, 2, 0, &type, &model); - if (!as_value) { - PHALCON_INIT_VAR(as_value); - ZVAL_BOOL(as_value, 0); + 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(); } - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } + PHALCON_INIT_VAR(options); + phalcon_call_method_p1_key(options, this_ptr, "getoptions", type, 680281137UL); + if (Z_TYPE_P(options) == IS_ARRAY) { - PHALCON_INIT_VAR(value); - if (PHALCON_IS_FALSE(as_value)) { - 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); + 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_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); + 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 { - 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_array_isset_quick_string(options, SS("generator"), 3205705004UL)) { - 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); + 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 (!phalcon_array_isset_quick_string(params, SS("value"), 574111618UL)) { - PHALCON_CALL_SELF_PARAMS_2(value, this_ptr, "getvalue", id, params); - phalcon_array_update_quick_string(¶ms, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); - } - } else { - if (!phalcon_array_isset_quick_string(params, SS("value"), 574111618UL)) { - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_NVAR(value); - phalcon_array_fetch_long(&value, params, 0, PH_NOISY); - phalcon_array_update_quick_string(¶ms, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); - } + if (Z_TYPE_P(timestamp) == IS_NULL) { + PHALCON_INIT_NVAR(timestamp); + ZVAL_LONG(timestamp, (long) time(NULL)); } - } - PHALCON_INIT_VAR(code); - PHALCON_CONCAT_SVS(code, "") TSRMLS_CC); - } else { - phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); + } else { + phalcon_call_method_p2_key(NULL, model, "writeattribute", field, timestamp, 3716971876UL); + } } - RETURN_CTOR(code); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Tag, _inputFieldChecked){ - zval *type, *parameters, *params = NULL, *value = NULL, *id = NULL, *name; - zval *current_value, *code, *key = NULL, *doctype; + + + +#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, ¶meters); - - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } + phalcon_fetch_params(1, 2, 0, &type, &model); - PHALCON_INIT_VAR(value); - 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); - } + if (PHALCON_IS_STRING(type, "beforeDelete")) { - 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); + 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_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(options, SS("field"), 4252138601UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The option 'field' is required"); + return; } - } - PHALCON_CALL_SELF_PARAMS_2(value, this_ptr, "getvalue", id, params); + PHALCON_INIT_VAR(skip); + ZVAL_BOOL(skip, 1); - if (phalcon_array_isset_quick_string(params, SS("value"), 574111618UL)) { + phalcon_call_method_p1_key(NULL, model, "skipoperation", skip, 1652216141UL); - PHALCON_OBS_VAR(current_value); - phalcon_array_fetch_quick_string(¤t_value, params, SS("value"), 574111618UL, PH_NOISY); - if (PHALCON_IS_EQUAL(current_value, value)) { - phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE); - } - } else { - if (zend_is_true(value)) { - phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE); - } + 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_array_update_quick_string(¶ms, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); - } + 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(code); - PHALCON_CONCAT_SVS(code, "") TSRMLS_CC); - } else { - phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); + RETURN_MM_FALSE; + } + + phalcon_call_method_p2_key(NULL, model, "writeattribute", field, value, 3716971876UL); + } } - RETURN_CTOR(code); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Tag, textField){ - zval *parameters, *name; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "text", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Tag, numericField){ +#ifdef HAVE_CONFIG_H +#endif - zval *parameters, *name; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "number", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Tag, emailField){ - zval *parameters, *name; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "email", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); -} +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Transaction){ -static PHP_METHOD(Phalcon_Tag, dateField){ + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Transaction, mvc_model_transaction, phalcon_mvc_model_transaction_method_entry, 0); - zval *parameters, *name; + 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); - PHALCON_MM_GROW(); + zend_class_implements(phalcon_mvc_model_transaction_ce TSRMLS_CC, 1, phalcon_mvc_model_transactioninterface_ce); - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "date", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); + return SUCCESS; } -static PHP_METHOD(Phalcon_Tag, passwordField){ +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, __construct){ - zval *parameters, *name; + zval *dependency_injector, *auto_begin = NULL, *service = NULL; + zval *connection; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); + phalcon_fetch_params(1, 1, 2, &dependency_injector, &auto_begin, &service); - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "password", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); + 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_Tag, hiddenField){ - - zval *parameters, *name; +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setTransactionManager){ - PHALCON_MM_GROW(); + zval *manager; - phalcon_fetch_params(1, 1, 0, ¶meters); + 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); - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "hidden", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); - RETURN_MM(); } -static PHP_METHOD(Phalcon_Tag, fileField){ +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, begin){ - zval *parameters, *name; + zval *connection; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "file", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); + 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_Tag, checkField){ - - zval *parameters, *name; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - -PHALCON_INIT_CLASS(Phalcon_Db_ReferenceInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ReferenceInterface, db_referenceinterface, phalcon_db_referenceinterface_method_entry); +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, commit){ - return SUCCESS; -} + zval *manager, *call_object, *arguments, *connection; + PHALCON_MM_GROW(); -======= - phalcon_fetch_params(1, 1, 0, ¶meters); + 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(name); - ZVAL_STRING(name, "checkbox", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfieldchecked", name, parameters); + 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_Tag, radioField){ - - zval *parameters, *name; ->>>>>>> 1.2.2 - +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, rollback){ -<<<<<<< HEAD + 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, 1, 0, ¶meters); + phalcon_fetch_params(1, 0, 2, &rollback_message, &rollback_record); - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "radio", 1); - PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfieldchecked", name, parameters); - RETURN_MM(); + 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(); } -static PHP_METHOD(Phalcon_Tag, imageInput){ +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, getConnection){ - zval *parameters, *name, *as_value; ->>>>>>> 1.2.2 + 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); + } + } + + PHALCON_OBS_VAR(connection); + phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + + RETURN_CCTOR(connection); +} -<<<<<<< HEAD +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setIsNewTransaction){ + zval *is_new; -======= - phalcon_fetch_params(1, 1, 0, ¶meters); + phalcon_fetch_params(0, 1, 0, &is_new); - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "image", 1); + phalcon_update_property_this_quick(this_ptr, SL("_isNewTransaction"), is_new, 3116442896UL TSRMLS_CC); - PHALCON_INIT_VAR(as_value); - ZVAL_BOOL(as_value, 1); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_inputfield", name, parameters, as_value); - RETURN_MM(); } -static PHP_METHOD(Phalcon_Tag, submitButton){ - - zval *parameters, *name, *as_value; ->>>>>>> 1.2.2 +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setRollbackOnAbort){ + zval *rollback_on_abort; -<<<<<<< HEAD + phalcon_fetch_params(0, 1, 0, &rollback_on_abort); + + phalcon_update_property_this_quick(this_ptr, SL("_rollbackOnAbort"), rollback_on_abort, 3438288323UL TSRMLS_CC); + +} -#ifdef HAVE_CONFIG_H -#endif +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); +} -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo){ +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, isValid){ - 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); + zval *connection; - 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); + PHALCON_MM_GROW(); - return SUCCESS; + 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_Db_Adapter_Pdo, __construct){ - - zval *descriptor; +static PHP_METHOD(Phalcon_Mvc_Model_Transaction, setRollbackedRecord){ - PHALCON_MM_GROW(); + zval *record; - phalcon_fetch_params(1, 1, 0, &descriptor); + phalcon_fetch_params(0, 1, 0, &record); - 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_update_property_this_quick(this_ptr, SL("_rollbackRecord"), record, 3406866061UL TSRMLS_CC); - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect){ - 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(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { - RETURN_MM_NULL(); - } - if (!descriptor) { - PHALCON_INIT_VAR(descriptor); - } else { - PHALCON_SEPARATE_PARAM(descriptor); - } +#ifdef HAVE_CONFIG_H +#endif - if (Z_TYPE_P(descriptor) == IS_NULL) { - PHALCON_OBS_NVAR(descriptor); - phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); - } -======= - phalcon_fetch_params(1, 1, 0, ¶meters); - - PHALCON_INIT_VAR(name); - ZVAL_STRING(name, "submit", 1); - - PHALCON_INIT_VAR(as_value); - ZVAL_BOOL(as_value, 1); - PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_inputfield", name, parameters, as_value); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Tag, selectStatic){ - zval *parameters, *data = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, ¶meters, &data); - - if (!data) { - PHALCON_INIT_VAR(data); - } - - PHALCON_CALL_STATIC_PARAMS_2(return_value, "phalcon\\tag\\select", "selectfield", parameters, data); - RETURN_MM(); -} -static PHP_METHOD(Phalcon_Tag, select){ - zval *parameters, *data = NULL; +PHALCON_INIT_CLASS(Phalcon_Mvc_Model_Resultset){ - PHALCON_MM_GROW(); + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Model, Resultset, mvc_model_resultset, phalcon_mvc_model_resultset_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - phalcon_fetch_params(1, 1, 1, ¶meters, &data); - - if (!data) { - PHALCON_INIT_VAR(data); - } - - PHALCON_CALL_STATIC_PARAMS_2(return_value, "phalcon\\tag\\select", "selectfield", parameters, data); - RETURN_MM(); -} + 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); -static PHP_METHOD(Phalcon_Tag, textArea){ + 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); - zval *parameters, *params = NULL, *id = NULL, *name, *content = NULL, *code; - zval *avalue = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; ->>>>>>> 1.2.2 + 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); - 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 SUCCESS; +} -<<<<<<< HEAD - 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_Mvc_Model_Resultset, next){ - 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_fetch_params(1, 1, 0, ¶meters); - - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } - if (!phalcon_array_isset_long(params, 0)) { - if (phalcon_array_isset_quick_string(params, SS("id"), 193494642UL)) { - 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_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_OBS_VAR(content); - phalcon_array_fetch_quick_string(&content, params, SS("value"), 574111618UL, PH_NOISY); - phalcon_array_unset_string(¶ms, SS("value"), PH_SEPARATE); - } else { - PHALCON_INIT_NVAR(content); - PHALCON_CALL_SELF_PARAMS_2(content, this_ptr, "getvalue", id, params); - } - - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, "", content, ""); + phalcon_update_property_long(this_ptr, SL("_pointer"), 0 TSRMLS_CC); - RETURN_CTOR(code); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Tag, form){ +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, seek){ - zval *parameters = NULL, *params = NULL, *params_action = NULL, *action = NULL; - zval *url, *code, *avalue = NULL, *key = NULL; + long i; + zval *type, *result, *rows, *position; + zval *pointer, *is_different; HashTable *ah0; - HashPosition hp0; - zval **hd; ->>>>>>> 1.2.2 - PHALCON_INIT_VAR(dsn_parts); - array_init(dsn_parts); + PHALCON_MM_GROW(); -<<<<<<< HEAD - if (!phalcon_is_iterable_ex(descriptor, &ah0, &hp0, 0, 0)) { - return; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &position) == FAILURE) { + PHALCON_MM_RESTORE(); + RETURN_NULL(); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_VAR(pointer); + phalcon_read_property(&pointer, this_ptr, SL("_pointer"), PH_NOISY_CC); - PHALCON_GET_FOREACH_KEY(key, ah0, hp0); - PHALCON_GET_FOREACH_VALUE(value); + PHALCON_INIT_VAR(is_different); + is_not_equal_function(is_different, pointer, position TSRMLS_CC); + if (PHALCON_IS_TRUE(is_different)) { - PHALCON_INIT_NVAR(dsn_attribute); - PHALCON_CONCAT_VSV(dsn_attribute, key, "=", value); - phalcon_array_append(&dsn_parts, dsn_attribute, PH_SEPARATE); + PHALCON_OBS_VAR(type); + phalcon_read_property(&type, this_ptr, SL("_type"), PH_NOISY_CC); + if (zend_is_true(type)) { - zend_hash_move_forward_ex(ah0, &hp0); - } + 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); - 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); - } + } else { - PHALCON_OBS_VAR(pdo_type); - phalcon_read_property(&pdo_type, this_ptr, SL("_type"), PH_NOISY_CC); + PHALCON_OBS_VAR(rows); + phalcon_read_property(&rows, this_ptr, SL("_rows"), PH_NOISY_CC); - PHALCON_INIT_VAR(dsn); - PHALCON_CONCAT_VSV(dsn, pdo_type, ":", dsn_attributes); + 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); + } + } - 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); + convert_to_long(position); - if (phalcon_array_isset_quick_string(descriptor, SS("persistent"), 2222052598UL)) { + if(Z_TYPE_P(rows) == IS_ARRAY){ - 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); + 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++; + } + } + + phalcon_update_property_zval(this_ptr, SL("_pointer"), position TSRMLS_CC); } } - ce = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); + PHALCON_MM_RESTORE();} - PHALCON_INIT_VAR(pdo); - object_init_ex(pdo, ce); - phalcon_call_method_p4_key(NULL, pdo, "__construct", dsn, username, password, options, 1107214344UL); -======= - phalcon_fetch_params(1, 0, 1, ¶meters); +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 (!parameters) { - PHALCON_INIT_VAR(parameters); - } else { - PHALCON_SEPARATE_PARAM(parameters); - } + if (Z_TYPE_P(count) == IS_NULL) { - if (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_VAR(params_action); - phalcon_array_fetch_long(¶ms_action, params, 0, PH_NOISY); - } else { - if (phalcon_array_isset_quick_string(params, SS("action"), 502132067UL)) { - PHALCON_OBS_NVAR(params_action); - phalcon_array_fetch_quick_string(¶ms_action, params, SS("action"), 502132067UL, PH_NOISY); - } else { - PHALCON_INIT_NVAR(params_action); - } - } + PHALCON_INIT_NVAR(count); + ZVAL_LONG(count, 0); - if (!phalcon_array_isset_quick_string(params, SS("method"), 3193080326UL)) { - phalcon_array_update_string_string(¶ms, SL("method"), SL("post"), PH_SEPARATE); - } + PHALCON_OBS_VAR(type); + phalcon_read_property_this_quick(&type, this_ptr, SL("_type"), 3991959110UL, PH_NOISY_CC); + if (zend_is_true(type)) { - PHALCON_INIT_VAR(action); + 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); - if (Z_TYPE_P(params_action) != IS_NULL) { - PHALCON_INIT_VAR(url); - PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); + 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_call_method_p1_key(action, url, "get", params_action, 2090288933UL); - } + 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 (phalcon_array_isset_quick_string(params, SS("parameters"), 3941032889UL)) { - PHALCON_OBS_NVAR(parameters); - phalcon_array_fetch_quick_string(¶meters, params, SS("parameters"), 3941032889UL, PH_NOISY); - PHALCON_SCONCAT_SV(action, "?", parameters); - } + PHALCON_INIT_NVAR(count); + phalcon_fast_count(count, rows TSRMLS_CC); + } - if (Z_TYPE_P(action) != IS_NULL) { - phalcon_array_update_quick_string(¶ms, SS("action"), 502132067UL, &action, PH_COPY | PH_SEPARATE); + phalcon_update_property_this_quick(this_ptr, SL("_count"), count, 2208664173UL TSRMLS_CC); } - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, "") TSRMLS_CC); - - RETURN_CTOR(code); + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "The index does not exist in the cursor"); + return; } -static PHP_METHOD(Phalcon_Tag, endForm){ +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetSet){ + zval *index, *value; - RETURN_STRING("", 1); + 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_Tag, setTitle){ +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, offsetUnset){ - zval *title; + zval *offset; - phalcon_fetch_params(0, 1, 0, &title); - - phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), title TSRMLS_CC); + 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_Tag, appendTitle){ - - zval *title; - zval *t0 = NULL; - zval *r0 = NULL; +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getType){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &title); - - PHALCON_OBS_VAR(t0); - phalcon_read_static_property(&t0, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); - PHALCON_ALLOC_ZVAL_MM(r0); - concat_function(r0, t0, title TSRMLS_CC); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), r0 TSRMLS_CC); - - PHALCON_MM_RESTORE(); + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); } -static PHP_METHOD(Phalcon_Tag, prependTitle){ +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getFirst){ - zval *title, *document_title; - zval *r0 = NULL; ->>>>>>> 1.2.2 + zval *pointer, *valid; - phalcon_update_property_zval(this_ptr, SL("_pdo"), pdo TSRMLS_CC); + PHALCON_MM_GROW(); -<<<<<<< HEAD - PHALCON_MM_RESTORE(); + 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_Db_Adapter_Pdo, prepare){ +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getLast){ - zval *sql_statement, *pdo; + zval *one, *count, *pre_count, *valid; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &sql_statement); + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); - 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_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_Db_Adapter_Pdo, executePrepared){ +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, setIsFresh){ - zval *statement = NULL, *placeholders = NULL, *data_types = NULL; - zval *one, *value = NULL, *wildcard = NULL, *parameter = NULL, *type = NULL, *cast_value = NULL; -======= - phalcon_fetch_params(1, 1, 0, &title); - - PHALCON_OBS_VAR(document_title); - phalcon_read_static_property(&document_title, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); - - PHALCON_INIT_VAR(r0); - PHALCON_CONCAT_VV(r0, title, document_title); - phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), r0 TSRMLS_CC); + zval *is_fresh; + + phalcon_fetch_params(0, 1, 0, &is_fresh); - PHALCON_MM_RESTORE(); + phalcon_update_property_this_quick(this_ptr, SL("_isFresh"), is_fresh, 1397060440UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Tag, getTitle){ +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, isFresh){ - zval *tags = NULL, *document_title, *eol; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_isFresh", 1397060440UL); +} - phalcon_fetch_params(1, 0, 1, &tags); - - if (!tags) { - PHALCON_INIT_VAR(tags); - ZVAL_BOOL(tags, 1); - } - - PHALCON_OBS_VAR(document_title); - phalcon_read_static_property(&document_title, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); - if (PHALCON_IS_TRUE(tags)) { - PHALCON_INIT_VAR(eol); - ZVAL_STRING(eol, PHP_EOL, 1); - PHALCON_CONCAT_SVSV(return_value, "", document_title, "", eol); - RETURN_MM(); - } +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, setHydrateMode){ + + zval *hydrate_mode; + + phalcon_fetch_params(0, 1, 0, &hydrate_mode); - RETURN_CCTOR(document_title); + phalcon_update_property_this_quick(this_ptr, SL("_hydrateMode"), hydrate_mode, 2551752186UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Tag, stylesheetLink){ +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getHydrateMode){ - zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; - zval *url, *url_href, *href, *code, *value = NULL, *key = NULL, *doctype; - zval *eol; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_hydrateMode", 2551752186UL); +} -<<<<<<< HEAD - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &statement, &placeholders, &data_types) == FAILURE) { - RETURN_MM_NULL(); - } +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getCache){ - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - if (!phalcon_is_iterable_ex(placeholders, &ah0, &hp0, 0, 0)) { - return; - } + RETURN_MEMBER_QUICK(this_ptr, "_cache", 2191407384UL); +} - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, current){ - 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; - } - } + RETURN_MEMBER_QUICK(this_ptr, "_activeRow", 3086770360UL); +} - if (Z_TYPE_P(data_types) == IS_ARRAY) { +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, getMessages){ - if (likely(phalcon_array_isset(data_types, wildcard))) { -======= - phalcon_fetch_params(1, 0, 2, ¶meters, &local); + + 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 (!parameters) { - PHALCON_INIT_VAR(parameters); + if (!condition_callback) { + PHALCON_INIT_VAR(condition_callback); } - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); - } else { - PHALCON_SEPARATE_PARAM(local); - } + PHALCON_INIT_VAR(transaction); + ZVAL_BOOL(transaction, 0); + phalcon_call_method_key(NULL, this_ptr, "rewind", 1064078190UL); - 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, local, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } - if (!phalcon_array_isset_quick_string(params, SS("href"), 261698186UL)) { - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_VAR(first_param); - phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY); - phalcon_array_update_quick_string(¶ms, SS("href"), 261698186UL, &first_param, PH_COPY | PH_SEPARATE); + while (1) { + + PHALCON_INIT_NVAR(r0); + phalcon_call_method_key(r0, this_ptr, "valid", 574098517UL); + if (zend_is_true(r0)) { } else { - phalcon_array_update_string_string(¶ms, SL("href"), SL(""), PH_SEPARATE); + break; } - } - PHALCON_INIT_NVAR(local); - ZVAL_BOOL(local, 0); - if (phalcon_array_isset_long(params, 1)) { - PHALCON_OBS_NVAR(local); - phalcon_array_fetch_long(&local, params, 1, PH_NOISY); - } else { - if (phalcon_array_isset_quick_string(params, SS("local"), 199015600UL)) { - PHALCON_OBS_NVAR(local); - phalcon_array_fetch_quick_string(&local, params, SS("local"), 199015600UL, PH_NOISY); - phalcon_array_unset_string(¶ms, SS("local"), PH_SEPARATE); - } - } + PHALCON_INIT_NVAR(record); + phalcon_call_method_key(record, this_ptr, "current", 431662984UL); + if (PHALCON_IS_FALSE(transaction)) { - if (!phalcon_array_isset_quick_string(params, SS("type"), 276192743UL)) { - phalcon_array_update_string_string(¶ms, SL("type"), SL("text/css"), PH_SEPARATE); - } + 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; + } - if (zend_is_true(local)) { - PHALCON_INIT_VAR(url); - PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); + PHALCON_INIT_NVAR(connection); + phalcon_call_method_key(connection, record, "getwriteconnection", 4280185952UL); + phalcon_call_method_key(NULL, connection, "begin", 4090922282UL); - PHALCON_OBS_VAR(url_href); - phalcon_array_fetch_quick_string(&url_href, params, SS("href"), 261698186UL, PH_NOISY); + PHALCON_INIT_NVAR(transaction); + ZVAL_BOOL(transaction, 1); + } - PHALCON_INIT_VAR(href); - phalcon_call_method_p1_key(href, url, "getstatic", url_href, 2197271245UL); - phalcon_array_update_quick_string(¶ms, SS("href"), 261698186UL, &href, PH_COPY | PH_SEPARATE); - } + if (Z_TYPE_P(condition_callback) == IS_OBJECT) { - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, "", eol); - } else { - PHALCON_SCONCAT_SV(code, ">", eol); + if (PHALCON_IS_TRUE(transaction)) { + phalcon_call_method_key(NULL, connection, "commit", 3546528686UL); } - RETURN_CTOR(code); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Tag, javascriptInclude){ - - zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; - zval *url, *params_src, *src, *eol, *code, *value = NULL, *key = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; ->>>>>>> 1.2.2 - - PHALCON_OBS_NVAR(type); - phalcon_array_fetch(&type, data_types, wildcard, PH_NOISY); - if (phalcon_compare_strict_long(type, 32 TSRMLS_CC)) { - -<<<<<<< HEAD - PHALCON_INIT_NVAR(cast_value); - phalcon_cast(cast_value, value, IS_DOUBLE); +static PHP_METHOD(Phalcon_Mvc_Model_Resultset, filter){ - PHALCON_INIT_NVAR(type); - ZVAL_LONG(type, 1024); - } else { - PHALCON_CPY_WRT(cast_value, value); - } + zval *filter, *records, *parameters, *record = NULL, *processed_record = NULL; + zval *r0 = NULL; - 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); + PHALCON_MM_GROW(); - } 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_fetch_params(1, 0, 2, ¶meters, &local); + phalcon_fetch_params(1, 1, 0, &filter); - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + PHALCON_INIT_VAR(records); + array_init(records); + phalcon_call_method_key(NULL, this_ptr, "rewind", 1064078190UL); - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); - } else { - PHALCON_SEPARATE_PARAM(local); - } + PHALCON_INIT_VAR(parameters); + array_init(parameters); - 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, local, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } - if (!phalcon_array_isset_quick_string(params, SS("src"), 2090733773UL)) { - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_VAR(first_param); - phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY); - phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &first_param, PH_COPY | PH_SEPARATE); - } else { - phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE); - } - } + while (1) { - PHALCON_INIT_NVAR(local); - ZVAL_BOOL(local, 0); - if (phalcon_array_isset_long(params, 1)) { - PHALCON_OBS_NVAR(local); - phalcon_array_fetch_long(&local, params, 1, PH_NOISY); - } else { - if (phalcon_array_isset_quick_string(params, SS("local"), 199015600UL)) { - PHALCON_OBS_NVAR(local); - phalcon_array_fetch_quick_string(&local, params, SS("local"), 199015600UL, PH_NOISY); - phalcon_array_unset_string(¶ms, SS("local"), PH_SEPARATE); + PHALCON_INIT_NVAR(r0); + phalcon_call_method_key(r0, this_ptr, "valid", 574098517UL); + if (zend_is_true(r0)) { + } else { + break; } - } - if (!phalcon_array_isset_quick_string(params, SS("type"), 276192743UL)) { - phalcon_array_update_string_string(¶ms, SL("type"), SL("text/javascript"), PH_SEPARATE); - } + PHALCON_INIT_NVAR(record); + phalcon_call_method_key(record, this_ptr, "current", 431662984UL); + phalcon_array_update_long(¶meters, 0, &record, PH_COPY | PH_SEPARATE); - if (zend_is_true(local)) { - PHALCON_INIT_VAR(url); - PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); + PHALCON_INIT_NVAR(processed_record); + PHALCON_CALL_USER_FUNC_ARRAY(processed_record, filter, parameters); - PHALCON_OBS_VAR(params_src); - phalcon_array_fetch_quick_string(¶ms_src, params, SS("src"), 2090733773UL, PH_NOISY); + if (Z_TYPE_P(processed_record) != IS_OBJECT) { + if (Z_TYPE_P(processed_record) != IS_ARRAY) { + continue; + } + } - PHALCON_INIT_VAR(src); - phalcon_call_method_p1_key(src, url, "getstatic", params_src, 2197271245UL); - phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &src, PH_COPY | PH_SEPARATE); + phalcon_array_append(&records, processed_record, PH_SEPARATE); + phalcon_call_method_key(NULL, this_ptr, "next", 268367684UL); } - PHALCON_INIT_VAR(eol); - ZVAL_STRING(eol, PHP_EOL, 1); - - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, ">>>>>> 1.2.2 - } +} - zend_hash_move_forward_ex(ah0, &hp0); - } -<<<<<<< HEAD +static PHP_METHOD(Phalcon_Mvc_Url, getDI){ - phalcon_call_method_key(NULL, statement, "execute", 3117639032UL); - RETURN_CCTOR(statement); + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, query){ +static PHP_METHOD(Phalcon_Mvc_Url, setBaseUri){ - zval *sql_statement, *bind_params = NULL, *bind_types = NULL; - zval *events_manager, *event_name = NULL, *status, *pdo; - zval *statement = NULL, *new_statement; + zval *base_uri, *static_base_uri; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &sql_statement, &bind_params, &bind_types); + phalcon_fetch_params(1, 1, 0, &base_uri); - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } + phalcon_update_property_this_quick(this_ptr, SL("_baseUri"), base_uri, 3689183023UL TSRMLS_CC); - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + 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(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_SCONCAT_SV(code, ">", eol); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Mvc_Url, setStaticBaseUri){ + + zval *static_base_uri; + + phalcon_fetch_params(0, 1, 0, &static_base_uri); - RETURN_CTOR(code); + phalcon_update_property_this_quick(this_ptr, SL("_staticBaseUri"), static_base_uri, 2610838775UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Tag, image){ +static PHP_METHOD(Phalcon_Mvc_Url, getBaseUri){ - zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; - zval *url, *url_src, *src, *code, *value = NULL, *key = NULL, *doctype; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *base_uri = NULL, *slash, *_SERVER, *php_self, *uri = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, ¶meters, &local); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + 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 (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); - } + 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 (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } - if (!phalcon_array_isset_quick_string(params, SS("src"), 2090733773UL)) { - if (phalcon_array_isset_long(params, 0)) { - PHALCON_OBS_VAR(first_param); - phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY); - phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &first_param, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(uri); + phalcon_get_uri(uri, php_self); } else { - phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE); + PHALCON_INIT_NVAR(uri); } - } - - if (zend_is_true(local)) { - PHALCON_INIT_VAR(url); - PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); - - PHALCON_OBS_VAR(url_src); - phalcon_array_fetch_quick_string(&url_src, params, SS("src"), 2090733773UL, PH_NOISY); - - PHALCON_INIT_VAR(src); - phalcon_call_method_p1_key(src, url, "getstatic", url_src, 2197271245UL); - phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &src, PH_COPY | PH_SEPARATE); - } - - PHALCON_INIT_VAR(code); - ZVAL_STRING(code, ">>>>>> 1.2.2 - - 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; + 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); } - } - -<<<<<<< HEAD - 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); - } - } else { - PHALCON_INIT_NVAR(statement); - phalcon_call_method_p1_key(statement, pdo, "query", sql_statement, 401898907UL); + phalcon_update_property_this_quick(this_ptr, SL("_baseUri"), base_uri, 3689183023UL 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); -======= - if (Z_TYPE_P(key) != IS_LONG) { - PHALCON_SCONCAT_SVSVS(code, " ", key, "=\"", value, "\""); ->>>>>>> 1.2.2 - } - 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); - - RETURN_MM(); + RETURN_CCTOR(base_uri); +} + +static PHP_METHOD(Phalcon_Mvc_Url, getStaticBaseUri){ + + zval *static_base_uri; + + 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); } -<<<<<<< HEAD - RETURN_CCTOR(statement); + phalcon_call_method_key(return_value, this_ptr, "getbaseuri", 2750461136UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, execute){ +static PHP_METHOD(Phalcon_Mvc_Url, setBasePath){ - 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 *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, 1, 2, &sql_statement, &bind_params, &bind_types); + phalcon_fetch_params(1, 0, 2, &uri, &args); - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + if (!uri) { + PHALCON_INIT_VAR(uri); } - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } + 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_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(router); + phalcon_read_property_this_quick(&router, this_ptr, SL("_router"), 2063827077UL, PH_NOISY_CC); - 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); + if (Z_TYPE_P(router) != IS_OBJECT) { - 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(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(affected_rows); - ZVAL_LONG(affected_rows, 0); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "router", 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(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(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_OBS_VAR(route_name); + phalcon_array_fetch_quick_string(&route_name, uri, SS("for"), 2090263820UL, PH_NOISY); - phalcon_call_method_key(affected_rows, new_statement, "rowcount", 4184721862UL); + 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; } - } else { - PHALCON_INIT_NVAR(affected_rows); - phalcon_call_method_p1_key(affected_rows, pdo, "exec", sql_statement, 258355946UL); + + PHALCON_INIT_VAR(pattern); + phalcon_call_method_key(pattern, route, "getpattern", 2464558051UL); + + 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); } - 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); + 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_TRUE; -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, affectedRows){ - - RETURN_MEMBER_QUICK(this_ptr, "_affectedRows", 3226297793UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, close){ +static PHP_METHOD(Phalcon_Mvc_Url, getStatic){ - zval *pdo; + zval *uri = NULL, *static_base_uri, *base_uri; 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, 0, 1, &uri); + + if (!uri) { + PHALCON_INIT_VAR(uri); } - RETURN_MM_TRUE; + 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(base_uri); + phalcon_call_method_key(base_uri, this_ptr, "getbaseuri", 2750461136UL); + PHALCON_CONCAT_VV(return_value, base_uri, uri); + + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, escapeIdentifier){ +static PHP_METHOD(Phalcon_Mvc_Url, path){ - zval *identifier, *domain, *name; + zval *path = NULL, *base_path; 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_OBS_VAR(name); - phalcon_array_fetch_long(&name, identifier, 1, PH_NOISY); - PHALCON_CONCAT_SVSVS(return_value, "\"", domain, "\".\"", name, "\""); - RETURN_MM(); -======= - PHALCON_OBS_VAR(doctype); - phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); + phalcon_fetch_params(1, 0, 1, &path); - if (PHALCON_GT_LONG(doctype, 5)) { - phalcon_concat_self_str(&code, SL(" />") TSRMLS_CC); - } else { - phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); + if (!path) { + PHALCON_INIT_VAR(path); } - RETURN_CTOR(code); + 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(); } -static PHP_METHOD(Phalcon_Tag, friendlyTitle){ - zval *text, *separator = NULL, *lowercase = NULL, *pattern, *friendly; - zval *friendly_text = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &text, &separator, &lowercase); - - if (!separator) { - PHALCON_INIT_VAR(separator); - ZVAL_STRING(separator, "-", 1); - } - - if (!lowercase) { - PHALCON_INIT_VAR(lowercase); - ZVAL_BOOL(lowercase, 1); - } - - PHALCON_INIT_VAR(pattern); - ZVAL_STRING(pattern, "~[^a-z0-9A-Z]+~", 1); - - PHALCON_INIT_VAR(friendly); - phalcon_call_func_p3(friendly, "preg_replace", pattern, separator, text); - if (zend_is_true(lowercase)) { - PHALCON_INIT_VAR(friendly_text); - phalcon_fast_strtolower(friendly_text, friendly); - } else { - PHALCON_CPY_WRT(friendly_text, friendly); - } - - RETURN_CCTOR(friendly_text); -} -static PHP_METHOD(Phalcon_Tag, setDocType){ +#ifdef HAVE_CONFIG_H +#endif - zval *doctype; - phalcon_fetch_params(0, 1, 0, &doctype); - - phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentType"), doctype TSRMLS_CC); - + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_Dispatcher_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Dispatcher, Exception, mvc_dispatcher_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Tag, getDocType){ - zval *doctype = NULL, *declaration, *eol, *doctype_html; - PHALCON_MM_GROW(); - PHALCON_OBSERVE_VAR(doctype); - phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); - PHALCON_INIT_VAR(eol); - ZVAL_STRING(eol, PHP_EOL, 1); +#ifdef HAVE_CONFIG_H +#endif - PHALCON_INIT_VAR(declaration); - if (phalcon_compare_strict_long(doctype, 1 TSRMLS_CC)) { - ZVAL_STRING(declaration, " PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\"", 1); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 2 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01//EN\"", eol, "\t\"http://www.w3.org/TR/html4/strict.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 3 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"", eol, "\t\"http://www.w3.org/TR/html4/loose.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 4 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"", eol, "\t\"http://www.w3.org/TR/html4/frameset.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 6 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 7 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 8 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 9 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\""); - goto ph_end_0; - } - if (phalcon_compare_strict_long(doctype, 10 TSRMLS_CC)) { - PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 2.0//EN\"", eol, "\t\"http://www.w3.org/MarkUp/DTD/xhtml2.dtd\""); - goto ph_end_0; - } - ph_end_0: - PHALCON_INIT_VAR(doctype_html); - PHALCON_CONCAT_SVSV(doctype_html, "", eol); - RETURN_CTOR(doctype_html); + + + +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_Tag, tagHtml){ +static PHP_METHOD(Phalcon_Mvc_Model, __construct){ - zval *tag_name, *parameters = NULL, *self_close = NULL, *only_start = NULL; - zval *use_eol = NULL, *params = NULL, *local_code, *value = NULL, *key = NULL; - zval *doctype, *eol; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *dependency_injector = NULL, *models_manager = NULL; + zval *service_name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 4, &tag_name, ¶meters, &self_close, &only_start, &use_eol); + phalcon_fetch_params(1, 0, 2, &dependency_injector, &models_manager); - if (!parameters) { - PHALCON_INIT_VAR(parameters); + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); + } else { + PHALCON_SEPARATE_PARAM(dependency_injector); } - if (!self_close) { - PHALCON_INIT_VAR(self_close); - ZVAL_BOOL(self_close, 0); + if (!models_manager) { + PHALCON_INIT_VAR(models_manager); + } else { + PHALCON_SEPARATE_PARAM(models_manager); } - if (!only_start) { - PHALCON_INIT_VAR(only_start); - ZVAL_BOOL(only_start, 0); + if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { + PHALCON_INIT_NVAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); } - - if (!use_eol) { - PHALCON_INIT_VAR(use_eol); - ZVAL_BOOL(use_eol, 0); + 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 (Z_TYPE_P(parameters) != IS_ARRAY) { - PHALCON_INIT_VAR(params); - array_init_size(params, 1); - phalcon_array_append(¶ms, parameters, PH_SEPARATE); - } else { - PHALCON_CPY_WRT(params, parameters); - } + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - PHALCON_INIT_VAR(local_code); - PHALCON_CONCAT_SV(local_code, "<", tag_name); + if (Z_TYPE_P(models_manager) != IS_OBJECT) { - phalcon_is_iterable(params, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(service_name); + ZVAL_STRING(service_name, "modelsManager", 1); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + 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_GET_HKEY(key, ah0, hp0); - PHALCON_GET_HVALUE(value); + phalcon_update_property_this_quick(this_ptr, SL("_modelsManager"), models_manager, 3699347875UL TSRMLS_CC); - if (Z_TYPE_P(key) != IS_LONG) { - PHALCON_SCONCAT_SVSVS(local_code, " ", key, "=\"", value, "\""); - } + phalcon_call_method_p1_key(NULL, models_manager, "initialize", this_ptr, 2896075127UL); - zend_hash_move_forward_ex(ah0, &hp0); + if (phalcon_method_quick_exists_ex(this_ptr, SS("onconstruct"), 564344039UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, this_ptr, "onconstruct", 564344039UL); } - PHALCON_OBS_VAR(doctype); - phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, setDI){ + + zval *dependency_injector; + + phalcon_fetch_params(0, 1, 0, &dependency_injector); - if (PHALCON_GT_LONG(doctype, 5)) { - if (zend_is_true(self_close)) { - phalcon_concat_self_str(&local_code, SL(" />") TSRMLS_CC); - } else { - phalcon_concat_self_str(&local_code, SL(">") TSRMLS_CC); - } - } else { - if (zend_is_true(only_start)) { - phalcon_concat_self_str(&local_code, SL(">") TSRMLS_CC); - } else { - PHALCON_SCONCAT_SVS(local_code, ">"); - } ->>>>>>> 1.2.2 - } - PHALCON_CONCAT_SVS(return_value, "\"", identifier, "\""); + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); -<<<<<<< HEAD - RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, escapeString){ +static PHP_METHOD(Phalcon_Mvc_Model, getDI){ - zval *str, *pdo; + + 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, &str); + phalcon_fetch_params(1, 1, 0, &events_manager); - 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); + 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_Db_Adapter_Pdo, convertBoundParams){ +static PHP_METHOD(Phalcon_Mvc_Model, getModelsMetaData){ - 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; + zval *meta_data = NULL, *dependency_injector, *service; 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_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_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_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_array_append(&placeholders, value, PH_SEPARATE); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "modelsMetadata", 1); - zend_hash_move_forward_ex(ah0, &hp0); + 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_INIT_VAR(question); - ZVAL_STRING(question, "?", 1); + phalcon_update_property_this_quick(this_ptr, SL("_modelsMetaData"), meta_data, 3906670569UL TSRMLS_CC); + } - PHALCON_INIT_VAR(bound_sql); - phalcon_call_func_p3(bound_sql, "preg_replace", bind_pattern, question, sql); - } else { - PHALCON_CPY_WRT(bound_sql, sql); + 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 (Z_TYPE_P(transaction) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_transaction"), transaction, 1141465066UL TSRMLS_CC); + RETURN_THISW(); } + 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); - 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); + 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); + 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_Db_Adapter_Pdo, lastInsertId){ +static PHP_METHOD(Phalcon_Mvc_Model, setConnectionService){ - zval *sequence_name = NULL, *pdo; -======= - if (zend_is_true(use_eol)) { - PHALCON_INIT_VAR(eol); - ZVAL_STRING(eol, PHP_EOL, 1); - phalcon_concat_self(&local_code, eol TSRMLS_CC); - } + zval *connection_service, *models_manager; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &connection_service); - RETURN_CTOR(local_code); + 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_Tag, tagHtmlClose){ +static PHP_METHOD(Phalcon_Mvc_Model, setReadConnectionService){ - zval *tag_name, *use_eol = NULL, *local_code, *eol; + zval *connection_service, *models_manager; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &tag_name, &use_eol); - - if (!use_eol) { - PHALCON_INIT_VAR(use_eol); - ZVAL_BOOL(use_eol, 0); - } - - PHALCON_INIT_VAR(local_code); - PHALCON_CONCAT_SVS(local_code, ""); - if (zend_is_true(use_eol)) { - PHALCON_INIT_VAR(eol); - ZVAL_STRING(eol, PHP_EOL, 1); - phalcon_concat_self(&local_code, eol TSRMLS_CC); - } + phalcon_fetch_params(1, 1, 0, &connection_service); - RETURN_CTOR(local_code); + 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_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(); +} -#ifdef HAVE_CONFIG_H -#endif - +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_INIT_CLASS(Phalcon_Security){ + PHALCON_MM_GROW(); - PHALCON_REGISTER_CLASS(Phalcon, Security, security, phalcon_security_method_entry, 0); + 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(); +} - 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); +static PHP_METHOD(Phalcon_Mvc_Model, setDirtyState){ - zend_class_implements(phalcon_security_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); + zval *dirty_state; - return SUCCESS; + 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_Security, setDI){ +static PHP_METHOD(Phalcon_Mvc_Model, getDirtyState){ - 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); - + RETURN_MEMBER_QUICK(this_ptr, "_dirtyState", 1560981745UL); } -static PHP_METHOD(Phalcon_Security, getDI){ +static PHP_METHOD(Phalcon_Mvc_Model, getReadConnection){ + zval *models_manager; - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); + 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_Security, setRandomBytes){ +static PHP_METHOD(Phalcon_Mvc_Model, getWriteConnection){ - zval *random_bytes; + zval *transaction, *models_manager; - phalcon_fetch_params(0, 1, 0, &random_bytes); - - 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_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_update_property_this_quick(this_ptr, SL("_numberBytes"), random_bytes, 1300189556UL 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, "getwriteconnection", this_ptr, 4280185952UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Security, getRandomBytes){ +static PHP_METHOD(Phalcon_Mvc_Model, assign){ ->>>>>>> 1.2.2 + zval *data, *column_map = NULL, *value = NULL, *key = NULL, *attribute = NULL; + zval *exception_message = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - RETURN_MEMBER_QUICK(this_ptr, "_numberBytes", 1300189556UL); -} + PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(1, 0, 1, &sequence_name); + phalcon_fetch_params(1, 1, 1, &data, &column_map); - if (!sequence_name) { - PHALCON_INIT_VAR(sequence_name); + if (!column_map) { + PHALCON_INIT_VAR(column_map); } - 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; -======= -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"); + 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; ->>>>>>> 1.2.2 } - phalcon_update_property_this_quick(this_ptr, SL("_workFactor"), work_factor, 3598705926UL TSRMLS_CC); -<<<<<<< HEAD - phalcon_call_method_p1_key(return_value, pdo, "lastinsertid", sequence_name, 106913211UL); - RETURN_MM(); + 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(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(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; + } + } else { + phalcon_update_property_zval_zval(this_ptr, key, value TSRMLS_CC); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, begin){ +static PHP_METHOD(Phalcon_Mvc_Model, cloneResultMap){ - zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; - zval *event_name = NULL, *ntw_savepoint, *savepoint_name; + 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, 0, 1, &nesting); + phalcon_fetch_params(1, 3, 2, &base, &data, &column_map, &dirty_state, &keep_snapshots); - if (!nesting) { - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 1); + if (!dirty_state) { + PHALCON_INIT_VAR(dirty_state); + ZVAL_LONG(dirty_state, 0); } - 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 (!keep_snapshots) { + PHALCON_INIT_VAR(keep_snapshots); } - 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)) { + 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(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + PHALCON_INIT_VAR(object); + if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { + return; + } - 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_p1_key(NULL, object, "setdirtystate", dirty_state, 1304577662UL); - phalcon_call_method_key(return_value, pdo, "begintransaction", 4233116368UL); - RETURN_MM(); - } else { - if (zend_is_true(transaction_level)) { - if (zend_is_true(nesting)) { + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(ntw_savepoint); - phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); - if (zend_is_true(ntw_savepoint)) { + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - PHALCON_INIT_VAR(savepoint_name); - phalcon_call_method_key(savepoint_name, this_ptr, "getnestedtransactionsavepointname", 1903082728UL); + if (Z_TYPE_P(key) == IS_STRING) { - 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); - } + if (Z_TYPE_P(column_map) == IS_ARRAY) { - phalcon_call_method_p1_key(return_value, this_ptr, "createsavepoint", savepoint_name, 2980652562UL); - RETURN_MM(); + 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); } } + + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_MM_FALSE; + if (zend_is_true(keep_snapshots)) { + phalcon_call_method_p2_key(NULL, object, "setsnapshotdata", data, column_map, 1073494651UL); + } + + if (phalcon_method_quick_exists_ex(object, SS("afterfetch"), 1256108385UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, object, "afterfetch", 1256108385UL); + } + + RETURN_CCTOR(object); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, rollback){ +static PHP_METHOD(Phalcon_Mvc_Model, cloneResultMapHydrate){ - zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; - zval *event_name = NULL, *ntw_savepoint, *savepoint_name; + 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, 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_fetch_params(1, 3, 0, &data, &column_map, &hydration_mode); - 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"); + 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_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); + if (Z_TYPE_P(column_map) != IS_ARRAY) { + if (PHALCON_IS_LONG(hydration_mode, 1)) { + RETURN_CCTOR(data); } + } - phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); - phalcon_call_method_key(return_value, pdo, "rollback", 3199546639UL); - RETURN_MM(); + if (PHALCON_IS_LONG(hydration_mode, 1)) { + PHALCON_INIT_VAR(hydrate); + array_init(hydrate); } else { - if (zend_is_true(transaction_level)) { - if (zend_is_true(nesting)) { + PHALCON_INIT_NVAR(hydrate); + object_init(hydrate); + } - PHALCON_INIT_VAR(ntw_savepoint); - phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); - if (zend_is_true(ntw_savepoint)) { + phalcon_is_iterable(data, &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_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - 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); - } + if (Z_TYPE_P(key) == IS_STRING) { + if (Z_TYPE_P(column_map) == IS_ARRAY) { - 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_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); + 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_GT_LONG(transaction_level, 0)) { - phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); + zend_hash_move_forward_ex(ah0, &hp0); } -======= -} - -static PHP_METHOD(Phalcon_Security, getWorkFactor){ - - - RETURN_MEMBER_QUICK(this_ptr, "_workFactor", 3598705926UL); + + RETURN_CCTOR(hydrate); } -static PHP_METHOD(Phalcon_Security, getSaltBytes){ +static PHP_METHOD(Phalcon_Mvc_Model, cloneResult){ - zval *number_bytes, *random_bytes = NULL, *base64bytes = NULL; - zval *safe_bytes = NULL, *bytes_length = NULL; + zval *base, *data, *dirty_state = NULL, *object, *value = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; 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"); + phalcon_fetch_params(1, 2, 1, &base, &data, &dirty_state); + + 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(number_bytes); - phalcon_read_property_this_quick(&number_bytes, this_ptr, SL("_numberBytes"), 1300189556UL, PH_NOISY_CC); + PHALCON_INIT_VAR(object); + if (phalcon_clone(object, base TSRMLS_CC) == FAILURE) { + return; + } - while (1) { + phalcon_call_method_p1_key(NULL, object, "setdirtystate", dirty_state, 1304577662UL); - PHALCON_INIT_NVAR(random_bytes); - phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(base64bytes); - phalcon_base64_encode(base64bytes, random_bytes); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_NVAR(safe_bytes); - phalcon_filter_alphanum(safe_bytes, base64bytes); - if (!zend_is_true(safe_bytes)) { - continue; - } + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - PHALCON_INIT_NVAR(bytes_length); - phalcon_fast_strlen(bytes_length, safe_bytes); - if (PHALCON_LT_LONG(bytes_length, 22)) { - continue; + 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); - break; + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CTOR(safe_bytes); + if (phalcon_method_quick_exists_ex(object, SS("afterfetch"), 1256108385UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, object, "afterfetch", 1256108385UL); + } + + RETURN_CCTOR(object); } -static PHP_METHOD(Phalcon_Security, hash){ +static PHP_METHOD(Phalcon_Mvc_Model, find){ - zval *password, *work_factor = NULL, *format, *factor; - zval *salt_bytes, *salt; + 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, 1, 1, &password, &work_factor); + phalcon_fetch_params(1, 0, 1, ¶meters); - if (!work_factor) { - PHALCON_INIT_VAR(work_factor); - } else { - PHALCON_SEPARATE_PARAM(work_factor); + if (!parameters) { + PHALCON_INIT_VAR(parameters); } - 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(model_name); + phalcon_get_called_class(model_name TSRMLS_CC); + if (Z_TYPE_P(parameters) != IS_ARRAY) { + + 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_INIT_VAR(format); - ZVAL_STRING(format, "%02s", 1); + 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(factor); - phalcon_call_func_p2(factor, "sprintf", format, work_factor); + phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - PHALCON_INIT_VAR(salt_bytes); - phalcon_call_method_key(salt_bytes, this_ptr, "getsaltbytes", 2293626208UL); + PHALCON_INIT_VAR(query); + phalcon_call_method_key(query, builder, "getquery", 4154457883UL); - 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_INIT_VAR(bind_params); - 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_INIT_VAR(bind_types); - if (phalcon_start_with_str(password_hash, SL("$2a$"))) { - RETURN_TRUE; + 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); + } + } + + 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(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_FALSE; + + RETURN_CCTOR(resultset); } -static PHP_METHOD(Phalcon_Security, getTokenKey){ +static PHP_METHOD(Phalcon_Mvc_Model, findFirst){ - zval *number_bytes = NULL, *random_bytes, *base64bytes; - zval *safe_bytes, *dependency_injector, *service; - zval *session, *key; + 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, &number_bytes); + phalcon_fetch_params(1, 0, 1, ¶meters); - if (!number_bytes) { - PHALCON_INIT_VAR(number_bytes); - ZVAL_LONG(number_bytes, 12); + if (!parameters) { + PHALCON_INIT_VAR(parameters); } - 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(model_name); + phalcon_get_called_class(model_name TSRMLS_CC); + if (Z_TYPE_P(parameters) != IS_ARRAY) { + + 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_INIT_VAR(random_bytes); - phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); + 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(base64bytes); - phalcon_base64_encode(base64bytes, random_bytes); + phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - PHALCON_INIT_VAR(safe_bytes); - phalcon_filter_alphanum(safe_bytes, base64bytes); + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + phalcon_call_method_p1_key(NULL, builder, "limit", one, 192268420UL); - 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(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(service); - ZVAL_STRING(service, "session", 1); + 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(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + PHALCON_INIT_VAR(unique); + ZVAL_BOOL(unique, 1); - PHALCON_INIT_VAR(key); - ZVAL_STRING(key, "$PHALCON/CSRF/KEY$", 1); - phalcon_call_method_p2_key(NULL, session, "set", key, safe_bytes, 2090720177UL); + phalcon_call_method_p1_key(NULL, query, "setuniquerow", unique, 2999205376UL); - RETURN_CTOR(safe_bytes); + phalcon_call_method_p2_key(return_value, query, "execute", bind_params, bind_types, 3117639032UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Security, getToken){ +static PHP_METHOD(Phalcon_Mvc_Model, query){ - zval *number_bytes = NULL, *random_bytes, *token, *dependency_injector; - zval *service, *session, *key; + zval *dependency_injector = NULL, *model_name, *criteria; 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_fetch_params(1, 0, 1, &dependency_injector); - 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 (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); + } else { + PHALCON_SEPARATE_PARAM(dependency_injector); } - 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_INIT_VAR(model_name); + phalcon_get_called_class(model_name 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_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); - return; + PHALCON_INIT_NVAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); } - 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); ->>>>>>> 1.2.2 + 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); - RETURN_CTOR(token); + RETURN_CTOR(criteria); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, commit){ +static PHP_METHOD(Phalcon_Mvc_Model, _exists){ - zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; - zval *event_name = NULL, *ntw_savepoint, *savepoint_name; + 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, 0, 1, &nesting); + phalcon_fetch_params(1, 2, 1, &meta_data, &connection, &table); - if (!nesting) { - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 1); + if (!table) { + PHALCON_INIT_VAR(table); + } else { + PHALCON_SEPARATE_PARAM(table); } - 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_INIT_VAR(unique_params); - 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; - } + PHALCON_INIT_VAR(unique_types); - if (PHALCON_IS_LONG(transaction_level, 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_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + PHALCON_INIT_VAR(primary_keys); + phalcon_call_method_p1_key(primary_keys, meta_data, "getprimarykeyattributes", this_ptr, 692945721UL); - 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_INIT_VAR(bind_data_types); + phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); + + PHALCON_INIT_VAR(number_primary); + phalcon_fast_count(number_primary, primary_keys TSRMLS_CC); + if (!zend_is_true(number_primary)) { + RETURN_MM_FALSE; } - 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)) { + 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(ntw_savepoint); - phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); - if (zend_is_true(ntw_savepoint)) { + PHALCON_INIT_VAR(null_value); - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + PHALCON_INIT_VAR(number_empty); + ZVAL_LONG(number_empty, 0); - PHALCON_INIT_VAR(savepoint_name); - phalcon_call_method_key(savepoint_name, this_ptr, "getnestedtransactionsavepointname", 1903082728UL); + PHALCON_INIT_VAR(where_pk); + array_init(where_pk); - 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); - } + array_init(unique_params); - phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); - phalcon_call_method_p1_key(return_value, this_ptr, "releasesavepoint", savepoint_name, 3823765247UL); - RETURN_MM(); + array_init(unique_types); + + phalcon_is_iterable(primary_keys, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(field); + + 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_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); + + if (PHALCON_IS_EMPTY(value)) { + PHALCON_SEPARATE(number_empty); + phalcon_increment(number_empty); } + + 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); + } + + PHALCON_INIT_NVAR(escaped_field); + phalcon_call_method_p1_key(escaped_field, connection, "escapeidentifier", field, 585773337UL); + + 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; } + + 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); + + zend_hash_move_forward_ex(ah0, &hp0); + } + + if (PHALCON_IS_EQUAL(number_primary, number_empty)) { + RETURN_MM_FALSE; } + + PHALCON_INIT_VAR(join_where); + phalcon_fast_join_str(join_where, SL(" AND "), where_pk TSRMLS_CC); + + 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_GT_LONG(transaction_level, 0)) { - phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); + 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 (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 (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 (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); + } + + 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_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_VAR(escaped_table); + phalcon_call_method_p1_key(escaped_table, connection, "escapeidentifier", table, 585773337UL); + + PHALCON_INIT_VAR(null_mode); + + PHALCON_INIT_VAR(select); + PHALCON_CONCAT_SVSV(select, "SELECT COUNT(*) \"rowcount\" FROM ", escaped_table, " WHERE ", unique_key); + + PHALCON_INIT_VAR(num); + phalcon_call_method_p4_key(num, connection, "fetchone", select, null_mode, unique_params, unique_types, 1637187313UL); + + 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); } RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, getTransactionLevel){ -======= -static PHP_METHOD(Phalcon_Security, checkToken){ +static PHP_METHOD(Phalcon_Mvc_Model, _groupResult){ - zval *token_key = NULL, *token_value = NULL, *dependency_injector; - zval *service = NULL, *session, *key = NULL, *request, *token = NULL, *session_token; + 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, 0, 2, &token_key, &token_value); + phalcon_fetch_params(1, 3, 0, &function, &alias, ¶meters); - if (!token_key) { - PHALCON_INIT_VAR(token_key); + 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_SEPARATE_PARAM(token_key); - } - - if (!token_value) { - PHALCON_INIT_VAR(token_value); + PHALCON_CPY_WRT(params, parameters); } - - 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; + 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(service); - ZVAL_STRING(service, "session", 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(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_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(token_key); - phalcon_call_method_p1_key(token_key, session, "get", key, 2090288933UL); + 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 (Z_TYPE_P(token_value) == IS_NULL) { - PHALCON_INIT_NVAR(service); - ZVAL_STRING(service, "request", 1); + PHALCON_INIT_VAR(model_name); + phalcon_get_called_class(model_name TSRMLS_CC); - PHALCON_INIT_VAR(request); - phalcon_call_method_p1_key(request, dependency_injector, "getshared", service, 1727570332UL); + 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(token); - phalcon_call_method_p1_key(token, request, "getpost", token_key, 4289323083UL); - } else { - PHALCON_CPY_WRT(token, token_value); - } + phalcon_call_method_p1_key(NULL, builder, "columns", columns, 1041822630UL); + phalcon_call_method_p1_key(NULL, builder, "from", model_name, 259337465UL); - PHALCON_INIT_NVAR(key); - ZVAL_STRING(key, "$PHALCON/CSRF$", 1); + PHALCON_INIT_VAR(query); + phalcon_call_method_key(query, builder, "getquery", 4154457883UL); - PHALCON_INIT_VAR(session_token); - phalcon_call_method_p1_key(session_token, session, "get", key, 2090288933UL); + PHALCON_INIT_VAR(bind_params); - is_equal_function(return_value, token, session_token TSRMLS_CC); + PHALCON_INIT_VAR(bind_types); + if (phalcon_array_isset_quick_string(params, SS("bind"), 254268962UL)) { - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Security, getSessionToken){ - - zval *dependency_injector, *service, *session; - zval *key, *session_token; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_transactionLevel", 2789346594UL); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, isUnderTransaction){ - - 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(); -======= - 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_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(service); - ZVAL_STRING(service, "session", 1); + PHALCON_INIT_VAR(resultset); + phalcon_call_method_p2_key(resultset, query, "execute", bind_params, bind_types, 3117639032UL); - PHALCON_INIT_VAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + 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(key); - ZVAL_STRING(key, "$PHALCON/CSRF$", 1); + if (phalcon_array_isset_quick_string(params, SS("group"), 7349554UL)) { + RETURN_CCTOR(resultset); + } - PHALCON_INIT_VAR(session_token); - phalcon_call_method_p1_key(session_token, session, "get", key, 2090288933UL); + PHALCON_INIT_VAR(number_rows); + phalcon_fast_count(number_rows, resultset TSRMLS_CC); - RETURN_CCTOR(session_token); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Db_ReferenceInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ReferenceInterface, db_referenceinterface, phalcon_db_referenceinterface_method_entry); - - return SUCCESS; + 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); } +static PHP_METHOD(Phalcon_Mvc_Model, count){ + zval *parameters = NULL, *function, *alias; + PHALCON_MM_GROW(); - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo){ - - 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; + phalcon_fetch_params(1, 0, 1, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } + + PHALCON_INIT_VAR(function); + ZVAL_STRING(function, "COUNT", 1); + + 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_Db_Adapter_Pdo, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model, sum){ - zval *descriptor; + zval *parameters = NULL, *function, *alias; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &descriptor); + phalcon_fetch_params(1, 0, 1, ¶meters); - if (Z_TYPE_P(descriptor) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The descriptor must be an array"); - return; ->>>>>>> 1.2.2 + if (!parameters) { + PHALCON_INIT_VAR(parameters); } - 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); -<<<<<<< HEAD - RETURN_MM_FALSE; + 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_Db_Adapter_Pdo, getInternalHandler){ +static PHP_METHOD(Phalcon_Mvc_Model, maximum){ - zval *pdo; + zval *parameters = NULL, *function, *alias; 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_MM_RESTORE(); + phalcon_fetch_params(1, 0, 1, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } + + PHALCON_INIT_VAR(function); + ZVAL_STRING(function, "MAX", 1); + + 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_Db_Adapter_Pdo, connect){ +static PHP_METHOD(Phalcon_Mvc_Model, minimum){ - 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 *parameters = NULL, *function, *alias; PHALCON_MM_GROW(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { - RETURN_MM_NULL(); - } - - if (!descriptor) { - PHALCON_INIT_VAR(descriptor); - } else { - PHALCON_SEPARATE_PARAM(descriptor); + phalcon_fetch_params(1, 0, 1, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); } + + PHALCON_INIT_VAR(function); + ZVAL_STRING(function, "MIN", 1); + + PHALCON_INIT_VAR(alias); + ZVAL_STRING(alias, "minimum", 1); + PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); + RETURN_MM(); +} - if (Z_TYPE_P(descriptor) == IS_NULL) { - PHALCON_OBS_NVAR(descriptor); - phalcon_read_property(&descriptor, this_ptr, SL("_descriptor"), PH_NOISY_CC); - } +static PHP_METHOD(Phalcon_Mvc_Model, average){ - 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); - } + zval *parameters = NULL, *function, *alias; - 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); - } + PHALCON_MM_GROW(); - 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); + phalcon_fetch_params(1, 0, 1, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); } + + PHALCON_INIT_VAR(function); + ZVAL_STRING(function, "AVG", 1); + + PHALCON_INIT_VAR(alias); + ZVAL_STRING(alias, "average", 1); + PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_groupresult", function, alias, parameters); + RETURN_MM(); +} - 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; - } - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_FOREACH_KEY(key, ah0, hp0); - PHALCON_GET_FOREACH_VALUE(value); +static PHP_METHOD(Phalcon_Mvc_Model, fireEvent){ - PHALCON_INIT_NVAR(dsn_attribute); - PHALCON_CONCAT_VSV(dsn_attribute, key, "=", value); - phalcon_array_append(&dsn_parts, dsn_attribute, PH_SEPARATE); + zval *event_name, *models_manager; - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_MM_GROW(); - 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_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(); +} - 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); +static PHP_METHOD(Phalcon_Mvc_Model, fireEventCancel){ - 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); + zval *event_name, *status = NULL, *models_manager; - if (phalcon_array_isset_quick_string(descriptor, SS("persistent"), 2222052598UL)) { + PHALCON_MM_GROW(); - 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); + 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; +} - ce = zend_fetch_class(SL("PDO"), ZEND_FETCH_CLASS_AUTO TSRMLS_CC); +static PHP_METHOD(Phalcon_Mvc_Model, _cancelOperation){ - PHALCON_INIT_VAR(pdo); - object_init_ex(pdo, ce); - phalcon_call_method_p4_key(NULL, pdo, "__construct", dsn, username, password, options, 1107214344UL); + zval *operation_made, *event_name = NULL; - phalcon_update_property_zval(this_ptr, SL("_pdo"), pdo TSRMLS_CC); + 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_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, prepare){ +static PHP_METHOD(Phalcon_Mvc_Model, appendMessage){ - zval *sql_statement, *pdo; + zval *message, *type, *exception_message; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &sql_statement); + phalcon_fetch_params(1, 1, 0, &message); - 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(); + 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); + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, executePrepared){ +static PHP_METHOD(Phalcon_Mvc_Model, validate){ - zval *statement = NULL, *placeholders = NULL, *data_types = NULL; - zval *one, *value = NULL, *wildcard = NULL, *parameter = NULL, *type = NULL, *cast_value = NULL; + zval *validator, *status, *messages, *message = NULL; HashTable *ah0; HashPosition hp0; zval **hd; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - -#ifdef HAVE_CONFIG_H -#endif - -======= - 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)) { - - 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); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, query){ - - zval *sql_statement, *bind_params = NULL, *bind_types = NULL; - zval *events_manager, *event_name = NULL, *status, *pdo; - zval *statement = NULL, *new_statement; ->>>>>>> 1.2.2 - - -<<<<<<< HEAD + 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, 0, &validator); - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + if (Z_TYPE_P(validator) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Validator must be an Object"); + return; } - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + PHALCON_INIT_VAR(status); + phalcon_call_method_p1_key(status, validator, "validate", this_ptr, 2654098287UL); + if (PHALCON_IS_FALSE(status)) { - if (Z_TYPE_P(events_manager) == IS_OBJECT) { + PHALCON_INIT_VAR(messages); + phalcon_call_method_key(messages, validator, "getmessages", 4087333309UL); - 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_is_iterable(messages, &ah0, &hp0, 0, 0); - 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; - } - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - 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_GET_HVALUE(message); - 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_update_property_array_append(this_ptr, SL("_errorMessages"), message 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); + zend_hash_move_forward_ex(ah0, &hp0); } - 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); - RETURN_MM(); } - RETURN_CCTOR(statement); + RETURN_THIS(); } -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; ->>>>>>> 1.2.2 +static PHP_METHOD(Phalcon_Mvc_Model, validationHasFailed){ + zval *error_messages; -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Mysql){ + PHALCON_MM_GROW(); - 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_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; +} - 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); +static PHP_METHOD(Phalcon_Mvc_Model, getMessages){ - zend_class_implements(phalcon_db_adapter_pdo_mysql_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_errorMessages", 1019066246UL); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, escapeIdentifier){ +static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysRestrict){ - zval *identifier, *domain, *name; + 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_fetch_params(1, 1, 0, &identifier); + 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); - if (Z_TYPE_P(identifier) == IS_ARRAY) { + PHALCON_INIT_NVAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); + if (Z_TYPE_P(fields) == IS_ARRAY) { - PHALCON_OBS_VAR(domain); - phalcon_array_fetch_long(&domain, identifier, 0, PH_NOISY); + phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); - 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(); - } + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_CONCAT_VSV(return_value, domain, ".", name); + PHALCON_GET_HKEY(position, ah1, hp1); + PHALCON_GET_HVALUE(field); - RETURN_MM(); - } - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_CONCAT_SVS(return_value, "`", identifier, "`"); - RETURN_MM(); - } + 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(identifier); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ - - 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; -======= - phalcon_fetch_params(1, 1, 2, &sql_statement, &bind_params, &bind_types); + PHALCON_OBS_NVAR(referenced_field); + phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } + 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 (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } + zend_hash_move_forward_ex(ah1, &hp1); + } - 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) { + } 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(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(condition); + PHALCON_CONCAT_SVS(condition, "[", referenced_fields, "] = ?0"); + phalcon_array_append(&conditions, condition, PH_SEPARATE); + phalcon_array_append(&bind_params, value, PH_SEPARATE); + } - 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 (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(affected_rows); - ZVAL_LONG(affected_rows, 0); + PHALCON_INIT_NVAR(join_conditions); + phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - 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(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(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_NVAR(rowcount); + phalcon_call_method_p1_key(rowcount, referenced_model, "count", parameters, 4142425646UL); + if (!zend_is_true(rowcount)) { - phalcon_call_method_key(affected_rows, new_statement, "rowcount", 4184721862UL); + 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_INIT_NVAR(type); + ZVAL_STRING(type, "ConstraintViolation", 1); + + 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_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); + + PHALCON_INIT_NVAR(error); + ZVAL_BOOL(error, 1); + break; + } + } + } + + zend_hash_move_forward_ex(ah0, &hp0); } - } 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); + 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; } } 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){ +static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysReverseRestrict){ - zval *pdo; + 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_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_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - RETURN_MM_TRUE; -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, escapeIdentifier){ - - zval *identifier, *domain, *name; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &identifier); + PHALCON_INIT_VAR(relations); + phalcon_call_method_p1_key(relations, manager, "gethasoneandhasmany", this_ptr, 775341383UL); + if (phalcon_fast_count_ev(relations TSRMLS_CC)) { - if (Z_TYPE_P(identifier) == IS_ARRAY) { - PHALCON_OBS_VAR(domain); - phalcon_array_fetch_long(&domain, identifier, 0, PH_NOISY); + PHALCON_INIT_VAR(error); + ZVAL_BOOL(error, 0); - 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, "\""); + phalcon_is_iterable(relations, &ah0, &hp0, 0, 0); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, escapeString){ - - zval *str, *pdo; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &str); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - 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; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 1, &table, &schema); + PHALCON_GET_HVALUE(relation); - if (!schema) { - PHALCON_INIT_VAR(schema); - } + PHALCON_INIT_NVAR(foreign_key); + phalcon_call_method_key(foreign_key, relation, "getforeignkey", 3855868664UL); + if (PHALCON_IS_NOT_FALSE(foreign_key)) { - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(action); + ZVAL_LONG(action, 1); - PHALCON_INIT_VAR(ztrue); - ZVAL_BOOL(ztrue, 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); + } + } - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); -======= - phalcon_fetch_params(1, 2, 0, &sql, ¶ms); + if (PHALCON_IS_LONG(action, 1)) { - PHALCON_INIT_VAR(query_params); - array_init(query_params); + PHALCON_INIT_NVAR(relation_class); + phalcon_call_method_key(relation_class, relation, "getreferencedmodel", 478093161UL); - PHALCON_INIT_VAR(placeholders); - array_init(placeholders); + PHALCON_INIT_NVAR(referenced_model); + phalcon_call_method_p1_key(referenced_model, manager, "load", relation_class, 266329637UL); - PHALCON_INIT_VAR(matches); + PHALCON_INIT_NVAR(fields); + phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - PHALCON_INIT_VAR(set_order); - ZVAL_LONG(set_order, 2); + PHALCON_INIT_NVAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - PHALCON_INIT_VAR(bind_pattern); - ZVAL_STRING(bind_pattern, "/\\?([0-9]+)|:([a-zA-Z0-9_]+):/", 1); - Z_SET_ISREF_P(matches); + PHALCON_INIT_NVAR(conditions); + array_init(conditions); - 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_INIT_NVAR(bind_params); + array_init(bind_params); + if (Z_TYPE_P(fields) == IS_ARRAY) { - phalcon_is_iterable(matches, &ah0, &hp0, 0, 0); ->>>>>>> 1.2.2 + phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { -<<<<<<< HEAD - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + PHALCON_GET_HKEY(position, ah1, hp1); + PHALCON_GET_HVALUE(field); - PHALCON_INIT_VAR(old_column); -======= - PHALCON_GET_HVALUE(place_match); + 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_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(referenced_field); + phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - 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_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_array_append(&placeholders, value, PH_SEPARATE); ->>>>>>> 1.2.2 + zend_hash_move_forward_ex(ah1, &hp1); + } - PHALCON_INIT_VAR(size_pattern); - ZVAL_STRING(size_pattern, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); + } 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); + } -<<<<<<< HEAD - PHALCON_INIT_VAR(columns); - array_init(columns); + 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_is_iterable(describe, &ah0, &hp0, 0, 0); + 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); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_NVAR(join_conditions); + phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - PHALCON_GET_HVALUE(field); + 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_NVAR(definition); - array_init_size(definition, 1); - add_assoc_long_ex(definition, SS("bindType"), 2); + PHALCON_INIT_NVAR(rowcount); + phalcon_call_method_p1_key(rowcount, referenced_model, "count", parameters, 4142425646UL); + if (zend_is_true(rowcount)) { - PHALCON_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); + 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); + } - while (1) { + PHALCON_INIT_NVAR(type); + ZVAL_STRING(type, "ConstraintViolation", 1); - if (phalcon_memnstr_str(column_type, SL("enum"))) { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - break; - } + 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); - 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; - } + phalcon_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); - if (phalcon_memnstr_str(column_type, SL("varchar"))) { - phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); - break; + PHALCON_INIT_NVAR(error); + ZVAL_BOOL(error, 1); + break; + } + } } - if (phalcon_memnstr_str(column_type, SL("datetime"))) { - phalcon_array_update_string_long(&definition, SL("type"), 4, PH_SEPARATE); - break; - } + zend_hash_move_forward_ex(ah0, &hp0); + } - 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_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_memnstr_str(column_type, SL("char"))) { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - break; - } + RETURN_MM_TRUE; +} + +static PHP_METHOD(Phalcon_Mvc_Model, _checkForeignKeysReverseCascade){ + + 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_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - if (phalcon_memnstr_str(column_type, SL("date"))) { - phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE); - break; - } + 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_memnstr_str(column_type, SL("text"))) { - phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); - break; - } + phalcon_is_iterable(relations, &ah0, &hp0, 0, 0); - 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; - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); - break; - } + PHALCON_GET_HVALUE(relation); - if (phalcon_memnstr_str(column_type, SL("("))) { + PHALCON_INIT_NVAR(foreign_key); + phalcon_call_method_key(foreign_key, relation, "getforeignkey", 3855868664UL); + if (PHALCON_IS_NOT_FALSE(foreign_key)) { - PHALCON_INIT_NVAR(matches); + PHALCON_INIT_NVAR(action); + ZVAL_LONG(action, 0); - 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 (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_memnstr_str(column_type, SL("unsigned"))) { - phalcon_array_update_quick_string(&definition, SS("unsigned"), 1143113122UL, &ztrue, PH_COPY | PH_SEPARATE); - } + if (PHALCON_IS_LONG(action, 2)) { - 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_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(fields); + phalcon_call_method_key(fields, relation, "getfields", 2162018780UL); - 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_INIT_NVAR(referenced_fields); + phalcon_call_method_key(referenced_fields, relation, "getreferencedfields", 2208451439UL); - 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_INIT_NVAR(conditions); + array_init(conditions); - 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_INIT_NVAR(bind_params); + array_init(bind_params); + if (Z_TYPE_P(fields) == IS_ARRAY) { - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); + phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); - PHALCON_INIT_NVAR(column); - object_init_ex(column, phalcon_db_column_ce); - phalcon_call_method_p2_key(NULL, column, "__construct", column_name, definition, 1107214344UL); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - phalcon_array_append(&columns, column, PH_SEPARATE); - PHALCON_CPY_WRT(old_column, column_name); + PHALCON_GET_HKEY(position, ah1, hp1); + PHALCON_GET_HVALUE(field); - zend_hash_move_forward_ex(ah0, &hp0); - } + 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_CTOR(columns); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Oracle){ - - 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_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_Db_Adapter_Pdo_Oracle, connect){ - - zval *descriptor = NULL, *startup, *value = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &descriptor); + PHALCON_OBS_NVAR(referenced_field); + phalcon_array_fetch(&referenced_field, referenced_fields, position, PH_NOISY); - if (!descriptor) { - PHALCON_INIT_VAR(descriptor); - } else { - PHALCON_SEPARATE_PARAM(descriptor); - } + 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 (!zend_is_true(descriptor)) { - PHALCON_OBS_NVAR(descriptor); - phalcon_read_property_this_quick(&descriptor, this_ptr, SL("_descriptor"), 691635363UL, PH_NOISY_CC); - } + zend_hash_move_forward_ex(ah1, &hp1); + } - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Oracle", "connect", descriptor); + } 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); + } - if (phalcon_array_isset_quick_string(descriptor, SS("startup"), 1765694744UL)) { + 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(startup); - phalcon_array_fetch_quick_string(&startup, descriptor, SS("startup"), 1765694744UL, PH_NOISY); - if (Z_TYPE_P(startup) == IS_ARRAY) { + 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_is_iterable(startup, &ah0, &hp0, 0, 0); + PHALCON_INIT_NVAR(join_conditions); + phalcon_fast_join_str(join_conditions, SL(" AND "), conditions TSRMLS_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + 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_GET_HVALUE(value); + PHALCON_INIT_NVAR(resulset); + phalcon_call_method_p1_key(resulset, referenced_model, "find", parameters, 259012646UL); - phalcon_call_method_p1_key(NULL, this_ptr, "execute", value, 3117639032UL); + PHALCON_INIT_NVAR(status); + phalcon_call_method_key(status, resulset, "delete", 150213496UL); - zend_hash_move_forward_ex(ah0, &hp0); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } + } } + zend_hash_move_forward_ex(ah0, &hp0); } + } - PHALCON_MM_RESTORE(); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, describeColumns){ +static PHP_METHOD(Phalcon_Mvc_Model, _preSave){ - 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; + 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_INIT_VAR(question); - ZVAL_STRING(question, "?", 1); + phalcon_fetch_params(1, 3, 0, &meta_data, &exists, &identity_field); - PHALCON_INIT_VAR(bound_sql); - phalcon_call_func_p3(bound_sql, "preg_replace", bind_pattern, question, sql); - } else { - PHALCON_CPY_WRT(bound_sql, sql); - } + if (PHALCON_GLOBAL(orm).events) { - 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); + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "beforeValidation", 1); - 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); + 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 (!sequence_name) { - PHALCON_INIT_VAR(sequence_name); - } + 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_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_INIT_NVAR(status); + phalcon_call_method_p1_key(status, this_ptr, "fireeventcancel", event_name, 1906122291UL); + if (PHALCON_IS_FALSE(status)) { + RETURN_MM_FALSE; + } } - 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 (PHALCON_GLOBAL(orm).virtual_foreign_keys) { - 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_INIT_NVAR(status); + phalcon_call_method_key(status, this_ptr, "_checkforeignkeysrestrict", 3705233048UL); + if (PHALCON_IS_FALSE(status)) { + 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)) { + if (PHALCON_GLOBAL(orm).not_null_validations) { - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + 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) { - 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_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_call_method_key(return_value, pdo, "begintransaction", 4233116368UL); - RETURN_MM(); - } else { - if (zend_is_true(transaction_level)) { - if (zend_is_true(nesting)) { + 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(ntw_savepoint); - phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); - if (zend_is_true(ntw_savepoint)) { + PHALCON_INIT_VAR(error); + ZVAL_BOOL(error, 0); - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + PHALCON_INIT_VAR(null_value); - PHALCON_INIT_VAR(savepoint_name); - phalcon_call_method_key(savepoint_name, this_ptr, "getnestedtransactionsavepointname", 1903082728UL); + phalcon_is_iterable(not_null, &ah0, &hp0, 0, 0); - 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); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - phalcon_call_method_p1_key(return_value, this_ptr, "createsavepoint", savepoint_name, 2980652562UL); - RETURN_MM(); - } - } - } - } + PHALCON_GET_HVALUE(field); - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo, rollback){ - - 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 (!phalcon_array_isset(automatic_attributes, field)) { - if (!nesting) { - PHALCON_INIT_VAR(nesting); - ZVAL_BOOL(nesting, 1); - } + 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); + } - 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_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { - 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; - } + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); - if (PHALCON_IS_LONG(transaction_level, 1)) { + 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); + } - PHALCON_OBS_VAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + if (PHALCON_IS_TRUE(is_null)) { + if (!zend_is_true(exists)) { - 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); - } + if (PHALCON_IS_EQUAL(field, identity_field)) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } + } - 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_NVAR(message); + PHALCON_CONCAT_VS(message, attribute_field, " is required"); - PHALCON_INIT_VAR(ntw_savepoint); - phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); - if (zend_is_true(ntw_savepoint)) { + PHALCON_INIT_NVAR(type); + ZVAL_STRING(type, "PresenceOf", 1); - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); + 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); - PHALCON_INIT_VAR(savepoint_name); - phalcon_call_method_key(savepoint_name, this_ptr, "getnestedtransactionsavepointname", 1903082728UL); + phalcon_update_property_array_append(this_ptr, SL("_errorMessages"), model_message TSRMLS_CC); - 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_INIT_NVAR(error); + ZVAL_BOOL(error, 1); } + } - 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_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); } + RETURN_MM_FALSE; } } } - 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, commit){ - - 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); - } + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "validation", 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) { + 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; } - 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); + 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_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_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(ntw_savepoint); - phalcon_call_method_key(ntw_savepoint, this_ptr, "isnestedtransactionswithsavepoints", 2937158629UL); - if (zend_is_true(ntw_savepoint)) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "afterValidation", 1); - PHALCON_OBS_NVAR(events_manager); - phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_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_INIT_VAR(savepoint_name); - phalcon_call_method_key(savepoint_name, this_ptr, "getnestedtransactionsavepointname", 1903082728UL); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "beforeSave", 1); - 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_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_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); - phalcon_call_method_p1_key(return_value, this_ptr, "releasesavepoint", savepoint_name, 3823765247UL); - RETURN_MM(); - } - } + 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); } - } - if (PHALCON_GT_LONG(transaction_level, 0)) { - phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); - } + phalcon_update_property_bool(this_ptr, SL("_skipped"), 0 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){ - - 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(); + 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_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); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -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); - - 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_db_adapter_pdo_mysql_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); - - return SUCCESS; + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, escapeIdentifier){ +static PHP_METHOD(Phalcon_Mvc_Model, _postSave){ - zval *identifier, *domain, *name; + zval *success, *exists, *event_name = NULL; 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, 2, 0, &success, &exists); - 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(); + 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_CONCAT_VSV(return_value, domain, ".", name); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "afterSave", 1); + phalcon_call_method_p1_key(NULL, this_ptr, "fireevent", event_name, 555903053UL); - RETURN_MM(); - } - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_CONCAT_SVS(return_value, "`", identifier, "`"); - RETURN_MM(); + RETURN_CCTOR(success); } - RETURN_CCTOR(identifier); + 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_Db_Adapter_Pdo_Mysql, describeColumns){ +static PHP_METHOD(Phalcon_Mvc_Model, _doLowInsert){ - 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; + 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(); ->>>>>>> 1.2.2 - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 4, 0, &meta_data, &connection, &table, &identity_field); - if (!schema) { - PHALCON_INIT_VAR(schema); - } + PHALCON_INIT_VAR(null_value); -<<<<<<< HEAD - PHALCON_INIT_VAR(columns); - array_init(columns); + PHALCON_INIT_VAR(bind_skip); + ZVAL_LONG(bind_skip, 1024); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); -======= - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + PHALCON_INIT_VAR(fields); + array_init(fields); - PHALCON_INIT_VAR(ztrue); - ZVAL_BOOL(ztrue, 1); ->>>>>>> 1.2.2 + PHALCON_INIT_VAR(values); + array_init(values); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); + PHALCON_INIT_VAR(bind_types); + array_init(bind_types); - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + PHALCON_INIT_VAR(bind_data_types); + phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); - PHALCON_INIT_VAR(old_column); + 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); + } -<<<<<<< HEAD - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + phalcon_is_iterable(attributes, &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); + if (!phalcon_array_isset(automatic_attributes, field)) { - PHALCON_OBS_NVAR(column_size); - phalcon_array_fetch_long(&column_size, field, 2, 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_OBS_NVAR(column_precision); - phalcon_array_fetch_long(&column_precision, field, 3, PH_NOISY); + if (!PHALCON_IS_EQUAL(field, identity_field)) { + phalcon_array_append(&fields, field, PH_SEPARATE); - PHALCON_OBS_NVAR(column_scale); - phalcon_array_fetch_long(&column_scale, field, 4, PH_NOISY); + if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { - PHALCON_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 1, 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; + } - 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); + 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 { - 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); - } - } - } - } - } - } - } + phalcon_array_append(&values, null_value, PH_SEPARATE); + phalcon_array_append(&bind_types, bind_skip, 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); - } + zend_hash_move_forward_ex(ah0, &hp0); + } - 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); + 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_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); + 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); } - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); + if (phalcon_isset_property_zval(this_ptr, attribute_field 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_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_array_append(&columns, column, PH_SEPARATE); - PHALCON_CPY_WRT(old_column, column_name); + 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; + } - zend_hash_move_forward_ex(ah0, &hp0); + phalcon_array_append(&values, value, PH_SEPARATE); + + 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); + } + } } - 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); + 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 (!sequence_name) { PHALCON_INIT_VAR(sequence_name); - } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT ", sequence_name, ".CURRVAL FROM dual"); + 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(fetch_num); - ZVAL_LONG(fetch_num, 3); + PHALCON_INIT_NVAR(sequence_name); + PHALCON_CONCAT_VSVS(sequence_name, source, "_", identity_field, "_seq"); + } + } - PHALCON_INIT_VAR(ret); - phalcon_call_method_p2_key(ret, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + 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_OBS_VAR(insert_id); - phalcon_array_fetch_long(&insert_id, ret, 0, PH_NOISY); - RETURN_CCTOR(insert_id); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, useExplicitIdValue){ - - - 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); + phalcon_update_property_null(this_ptr, SL("_uniqueParams") TSRMLS_CC); + } - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, supportSequences){ - - - RETURN_TRUE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Postgresql){ - - 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; + RETURN_CCTOR(success); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, connect){ +static PHP_METHOD(Phalcon_Mvc_Model, _doLowUpdate){ - zval *descriptor = NULL, *schema = NULL, *sql; + 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, 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_fetch_params(1, 3, 0, &meta_data, &connection, &table); - 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(null_value); - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Postgresql", "connect", descriptor); + PHALCON_INIT_VAR(bind_skip); + ZVAL_LONG(bind_skip, 1024); - 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_VAR(fields); + array_init(fields); - 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(values); + array_init(values); - if (!schema) { - PHALCON_INIT_VAR(schema); - } + PHALCON_INIT_VAR(bind_types); + array_init(bind_types); - PHALCON_INIT_VAR(columns); - array_init(columns); + PHALCON_OBS_VAR(manager); + phalcon_read_property_this_quick(&manager, this_ptr, SL("_modelsManager"), 3699347875UL, PH_NOISY_CC); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, 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_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); + 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(fetch_num); - ZVAL_LONG(fetch_num, 3); + PHALCON_INIT_VAR(bind_data_types); + phalcon_call_method_p1_key(bind_data_types, meta_data, "getbindtypes", this_ptr, 448815543UL); - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + PHALCON_INIT_VAR(non_primary); + phalcon_call_method_p1_key(non_primary, meta_data, "getnonprimarykeyattributes", this_ptr, 1524832420UL); - PHALCON_INIT_VAR(old_column); + 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(describe, &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(field); - PHALCON_INIT_NVAR(definition); - array_init_size(definition, 1); - add_assoc_long_ex(definition, SS("bindType"), 2); + if (!phalcon_array_isset(automatic_attributes, field)) { - PHALCON_OBS_NVAR(char_size); - phalcon_array_fetch_long(&char_size, field, 2, 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(numeric_size); - phalcon_array_fetch_long(&numeric_size, field, 3, 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_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); + if (phalcon_isset_property_zval(this_ptr, attribute_field TSRMLS_CC)) { - 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); + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, attribute_field, PH_NOISY_CC); + + if (!zend_is_true(use_dynamic_update)) { + 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 { - 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); + if (!phalcon_array_isset(snapshot, attribute_field)) { + PHALCON_INIT_NVAR(changed); + ZVAL_BOOL(changed, 1); } 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); + 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 { - 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(size_pattern); - ZVAL_STRING(size_pattern, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); + PHALCON_INIT_NVAR(changed); + ZVAL_BOOL(changed, 0); + } + } - PHALCON_INIT_VAR(columns); - array_init(columns); + if (zend_is_true(changed)) { + phalcon_array_append(&fields, field, PH_SEPARATE); + phalcon_array_append(&values, value, PH_SEPARATE); - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + 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); + } + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_GET_HVALUE(field); + if (!phalcon_fast_count_ev(fields TSRMLS_CC)) { + RETURN_MM_TRUE; + } - PHALCON_INIT_NVAR(definition); - array_init_size(definition, 1); - add_assoc_long_ex(definition, SS("bindType"), 2); + PHALCON_OBS_VAR(unique_key); + phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); - PHALCON_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); + PHALCON_OBS_VAR(unique_params); + phalcon_read_property_this_quick(&unique_params, this_ptr, SL("_uniqueParams"), 1065564063UL, PH_NOISY_CC); - while (1) { + PHALCON_OBS_VAR(unique_types); + phalcon_read_property_this_quick(&unique_types, this_ptr, SL("_uniqueTypes"), 3340838640UL, PH_NOISY_CC); - if (phalcon_memnstr_str(column_type, SL("enum"))) { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - break; - } + if (Z_TYPE_P(unique_params) != IS_ARRAY) { - 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; - } + PHALCON_INIT_NVAR(unique_params); + array_init(unique_params); - if (phalcon_memnstr_str(column_type, SL("varchar"))) { - phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); - break; - } + PHALCON_INIT_VAR(primary_keys); + phalcon_call_method_p1_key(primary_keys, meta_data, "getprimarykeyattributes", this_ptr, 692945721UL); - if (phalcon_memnstr_str(column_type, SL("datetime"))) { - phalcon_array_update_string_long(&definition, SL("type"), 4, PH_SEPARATE); - break; - } + 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 (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; - } + phalcon_is_iterable(primary_keys, &ah1, &hp1, 0, 0); - if (phalcon_memnstr_str(column_type, SL("char"))) { - phalcon_array_update_string_long(&definition, SL("type"), 5, PH_SEPARATE); - break; - } + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - if (phalcon_memnstr_str(column_type, SL("date"))) { - phalcon_array_update_string_long(&definition, SL("type"), 1, PH_SEPARATE); - break; - } + PHALCON_GET_HVALUE(field); - if (phalcon_memnstr_str(column_type, SL("text"))) { - phalcon_array_update_string_long(&definition, SL("type"), 6, PH_SEPARATE); - 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); } - - 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; + 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); } - phalcon_array_update_string_long(&definition, SL("type"), 2, PH_SEPARATE); - break; + zend_hash_move_forward_ex(ah1, &hp1); } - if (phalcon_memnstr_str(column_type, SL("("))) { + } - PHALCON_INIT_NVAR(matches); + 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(pos); - phalcon_preg_match(pos, size_pattern, column_type, matches TSRMLS_CC); + phalcon_call_method_p5(return_value, connection, "update", table, fields, values, conditions, bind_types); + RETURN_MM(); +} - 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); +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_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; } - } - } - if (phalcon_memnstr_str(column_type, SL("unsigned"))) { - phalcon_array_update_quick_string(&definition, SS("unsigned"), 1143113122UL, &ztrue, PH_COPY | PH_SEPARATE); - } + PHALCON_INIT_NVAR(columns); + phalcon_call_method_key(columns, relation, "getfields", 2162018780UL); - 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_INIT_NVAR(referenced_model); + phalcon_call_method_key(referenced_model, relation, "getreferencedmodel", 478093161UL); - 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_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_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_INIT_NVAR(status); + phalcon_call_method_key(status, record, "save", 274150868UL); + if (!zend_is_true(status)) { - 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_INIT_NVAR(messages); + phalcon_call_method_key(messages, record, "getmessages", 4087333309UL); - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); + phalcon_is_iterable(messages, &ah1, &hp1, 0, 0); - PHALCON_INIT_NVAR(column); - object_init_ex(column, phalcon_db_column_ce); - phalcon_call_method_p2_key(NULL, column, "__construct", column_name, definition, 1107214344UL); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - phalcon_array_append(&columns, column, PH_SEPARATE); - PHALCON_CPY_WRT(old_column, column_name); + 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_CTOR(columns); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Oracle){ - - 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_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; + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, connect){ +static PHP_METHOD(Phalcon_Mvc_Model, _postSaveRelatedRecords){ - zval *descriptor = NULL, *startup, *value = 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, 0, 1, &descriptor); - - if (!descriptor) { - PHALCON_INIT_VAR(descriptor); - } else { - PHALCON_SEPARATE_PARAM(descriptor); - } + phalcon_fetch_params(1, 2, 0, &connection, &related); - 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(nesting); + ZVAL_BOOL(nesting, 0); - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Oracle", "connect", descriptor); + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, this_ptr, 0 TSRMLS_CC); - if (phalcon_array_isset_quick_string(descriptor, SS("startup"), 1765694744UL)) { + PHALCON_INIT_VAR(manager); + phalcon_call_method_key(manager, this_ptr, "getmodelsmanager", 2387491844UL); - 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(related, &ah0, &hp0, 0, 0); - phalcon_is_iterable(startup, &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(name, ah0, hp0); + PHALCON_GET_HVALUE(record); - PHALCON_GET_HVALUE(value); + PHALCON_INIT_NVAR(relation); + phalcon_call_method_p2_key(relation, manager, "getrelationbyalias", class_name, name, 785467656UL); + if (Z_TYPE_P(relation) == IS_OBJECT) { - phalcon_call_method_p1_key(NULL, this_ptr, "execute", value, 3117639032UL); + 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_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(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); + 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); - if (!schema) { - PHALCON_INIT_VAR(schema); - } + PHALCON_INIT_NVAR(intermediate_model_name); + phalcon_call_method_key(intermediate_model_name, relation, "getintermediatemodel", 851527441UL); - PHALCON_INIT_VAR(columns); - array_init(columns); + PHALCON_INIT_NVAR(intermediate_fields); + phalcon_call_method_key(intermediate_fields, relation, "getintermediatefields", 1646880791UL); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(intermediate_referenced_fields); + phalcon_call_method_key(intermediate_referenced_fields, relation, "getintermediatereferencedfields", 3001626474UL); + } - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); + phalcon_is_iterable(related_records, &ah1, &hp1, 0, 0); - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + PHALCON_GET_HVALUE(record_after); - PHALCON_INIT_VAR(old_column); + 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_is_iterable(describe, &ah0, &hp0, 0, 0); + phalcon_call_method_p2_key(NULL, intermediate_model, "writeattribute", intermediate_fields, value, 3716971876UL); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_NVAR(intermediate_value); + phalcon_read_property_zval(&intermediate_value, record_after, referenced_fields, PH_NOISY_CC); - PHALCON_GET_HVALUE(field); + phalcon_call_method_p2_key(NULL, intermediate_model, "writeattribute", intermediate_referenced_fields, intermediate_value, 3716971876UL); - PHALCON_INIT_NVAR(definition); - array_init_size(definition, 1); - add_assoc_long_ex(definition, SS("bindType"), 2); + PHALCON_INIT_NVAR(status); + phalcon_call_method_key(status, intermediate_model, "save", 274150868UL); + if (!zend_is_true(status)) { - PHALCON_OBS_NVAR(column_size); - phalcon_array_fetch_long(&column_size, field, 2, PH_NOISY); + PHALCON_INIT_NVAR(messages); + phalcon_call_method_key(messages, intermediate_model, "getmessages", 4087333309UL); - PHALCON_OBS_NVAR(column_precision); - phalcon_array_fetch_long(&column_precision, field, 3, PH_NOISY); + phalcon_is_iterable(messages, &ah2, &hp2, 0, 0); - PHALCON_OBS_NVAR(column_scale); - phalcon_array_fetch_long(&column_scale, field, 4, PH_NOISY); + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - PHALCON_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); + PHALCON_GET_HVALUE(message); - 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); ->>>>>>> 1.2.2 - } - } - } - } + 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; } } - } - } -<<<<<<< HEAD - if (phalcon_memnstr_str(column_type, SL("unsigned"))) { - phalcon_array_update_string_bool(&definition, SL("unsigned"), 1, PH_SEPARATE); - } -======= ->>>>>>> 1.2.2 + PHALCON_INIT_NVAR(status); + phalcon_call_method_key(status, record_after, "save", 274150868UL); + if (!zend_is_true(status)) { - 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(messages); + phalcon_call_method_key(messages, record_after, "getmessages", 4087333309UL); - PHALCON_OBS_NVAR(attribute); -<<<<<<< HEAD - phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); - if (PHALCON_IS_STRING(attribute, "PRI")) { -======= - phalcon_array_fetch_long(&attribute, field, 6, PH_NOISY); - if (PHALCON_IS_STRING(attribute, "P")) { ->>>>>>> 1.2.2 - phalcon_array_update_string_bool(&definition, SL("primary"), 1, PH_SEPARATE); - } + phalcon_is_iterable(messages, &ah3, &hp3, 0, 0); - PHALCON_OBS_NVAR(attribute); -<<<<<<< HEAD - 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); - } + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - 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_GET_HVALUE(message); - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); + if (Z_TYPE_P(message) == IS_OBJECT) { + phalcon_call_method_p1_key(NULL, message, "setmodel", record, 1672695874UL); + } - 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_call_method_p1_key(NULL, this_ptr, "appendmessage", message, 2313005058UL); -======= - 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); - } + zend_hash_move_forward_ex(ah3, &hp3); + } - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); + phalcon_call_method_p1_key(NULL, connection, "rollback", nesting, 3199546639UL); + RETURN_MM_FALSE; + } - PHALCON_INIT_NVAR(column); - object_init_ex(column, phalcon_db_column_ce); - phalcon_call_method_p2_key(NULL, column, "__construct", column_name, definition, 1107214344UL); + zend_hash_move_forward_ex(ah1, &hp1); + } ->>>>>>> 1.2.2 - phalcon_array_append(&columns, column, PH_SEPARATE); - PHALCON_CPY_WRT(old_column, column_name); + } 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; + } + } zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CTOR(columns); -} - -<<<<<<< HEAD -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); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, supportSequences){ - - - RETURN_TRUE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Sqlite){ - - 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); - - 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_class_implements(phalcon_db_adapter_pdo_sqlite_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); - - return SUCCESS; + phalcon_call_method_p1_key(NULL, connection, "commit", nesting, 3546528686UL); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, connect){ +static PHP_METHOD(Phalcon_Mvc_Model, save){ - zval *descriptor = NULL, *dbname; + 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, 1, &descriptor); + phalcon_fetch_params(1, 0, 2, &data, &white_list); - if (!descriptor) { - PHALCON_INIT_VAR(descriptor); - } else { - PHALCON_SEPARATE_PARAM(descriptor); + if (!data) { + PHALCON_INIT_VAR(data); } - 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 (!white_list) { + PHALCON_INIT_VAR(white_list); } - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Sqlite", "connect", descriptor); + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - 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; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); + 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 (!schema) { - PHALCON_INIT_VAR(schema); - } + 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_INIT_VAR(columns); - array_init(columns); + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(size_pattern); - ZVAL_STRING(size_pattern, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); + PHALCON_GET_HVALUE(attribute); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); + if (phalcon_array_isset(data, attribute)) { - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + 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_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, data, attribute, PH_NOISY); - PHALCON_INIT_VAR(old_column); + 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); + } + } - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + zend_hash_move_forward_ex(ah0, &hp0); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + } - PHALCON_GET_HVALUE(field); + PHALCON_INIT_VAR(write_connection); + phalcon_call_method_key(write_connection, this_ptr, "getwriteconnection", 4280185952UL); - PHALCON_INIT_NVAR(definition); - array_init_size(definition, 1); - add_assoc_long_ex(definition, SS("bindType"), 2); + 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_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 2, PH_NOISY); + 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_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_INIT_VAR(schema); + phalcon_call_method_key(schema, this_ptr, "getschema", 1539736246UL); - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); + 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); + } - 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); -======= -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); + PHALCON_INIT_VAR(read_connection); + phalcon_call_method_key(read_connection, this_ptr, "getreadconnection", 488334257UL); - if (!sequence_name) { - PHALCON_INIT_VAR(sequence_name); + 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(sql); - PHALCON_CONCAT_SVS(sql, "SELECT ", sequence_name, ".CURRVAL FROM dual"); + 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(fetch_num); - ZVAL_LONG(fetch_num, 3); + PHALCON_INIT_VAR(identity_field); + phalcon_call_method_p1_key(identity_field, meta_data, "getidentityfield", this_ptr, 1208930067UL); - PHALCON_INIT_VAR(ret); - phalcon_call_method_p2_key(ret, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + 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(insert_id); - phalcon_array_fetch_long(&insert_id, ret, 0, PH_NOISY); - RETURN_CCTOR(insert_id); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, useExplicitIdValue){ - - - 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); + 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); + } - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, supportSequences){ - - - RETURN_TRUE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Postgresql){ - - 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_Db_Adapter_Pdo_Postgresql, connect){ - - zval *descriptor = NULL, *schema = NULL, *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &descriptor); + 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); - if (!descriptor) { - PHALCON_INIT_VAR(descriptor); + 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_SEPARATE_PARAM(descriptor); + 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(descriptor)) { - PHALCON_OBS_NVAR(descriptor); - phalcon_read_property_this_quick(&descriptor, this_ptr, SL("_descriptor"), 691635363UL, PH_NOISY_CC); + if (zend_is_true(success)) { + phalcon_update_property_long(this_ptr, SL("_dirtyState"), 0 TSRMLS_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); + 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); } - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Postgresql", "connect", descriptor); + if (Z_TYPE_P(related) == IS_ARRAY) { - 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); + 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_MM_RESTORE(); + RETURN_CCTOR(new_success); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, describeColumns){ +static PHP_METHOD(Phalcon_Mvc_Model, create){ - 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; + 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_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 0, 2, &data, &white_list); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (!data) { + PHALCON_INIT_VAR(data); } - 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); + if (!white_list) { + PHALCON_INIT_VAR(white_list); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - PHALCON_GET_HVALUE(field); + 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_NVAR(definition); - array_init_size(definition, 1); - add_assoc_long_ex(definition, SS("bindType"), 2); + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); - PHALCON_OBS_NVAR(char_size); - phalcon_array_fetch_long(&char_size, field, 2, PH_NOISY); + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - PHALCON_OBS_NVAR(numeric_size); - phalcon_array_fetch_long(&numeric_size, field, 3, PH_NOISY); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 1, PH_NOISY); + PHALCON_GET_HVALUE(attribute); - 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); + 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 (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); ->>>>>>> 1.2.2 - 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); -<<<<<<< HEAD - } 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); -======= - 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); ->>>>>>> 1.2.2 - } 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); -<<<<<<< HEAD - 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); -======= - 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); - } ->>>>>>> 1.2.2 - } - } - } - } - } - } + 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); } - } -<<<<<<< HEAD - if (phalcon_memnstr_str(column_type, SL("("))) { + if (phalcon_array_isset(data, attribute_field)) { - PHALCON_INIT_NVAR(matches); + 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(pos); - phalcon_preg_match(pos, size_pattern, column_type, matches TSRMLS_CC); + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, data, attribute_field, PH_NOISY); - 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); + 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); } } - } - - 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); + zend_hash_move_forward_ex(ah0, &hp0); } - 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); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeIndexes){ - - 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; -======= - - 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_INIT_VAR(read_connection); + phalcon_call_method_key(read_connection, this_ptr, "getreadconnection", 488334257UL); - 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_VAR(exists); + phalcon_call_method_p2_key(exists, this_ptr, "_exists", meta_data, read_connection, 2792580580UL); - 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); - } + if (zend_is_true(exists)) { + PHALCON_INIT_VAR(field); - PHALCON_OBS_NVAR(column_name); - phalcon_array_fetch_long(&column_name, field, 0, PH_NOISY); + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "InvalidCreateAttempt", 1); - 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(message); + ZVAL_STRING(message, "Record cannot be created because it already exists", 1); - phalcon_array_append(&columns, column, PH_SEPARATE); - PHALCON_CPY_WRT(old_column, column_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); - zend_hash_move_forward_ex(ah0, &hp0); + 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; } - RETURN_CTOR(columns); -} - -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); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, supportSequences){ - - - RETURN_TRUE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Sqlite){ - - 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); - - 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_class_implements(phalcon_db_adapter_pdo_sqlite_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); - - return SUCCESS; + phalcon_call_method_key(return_value, this_ptr, "save", 274150868UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, connect){ +static PHP_METHOD(Phalcon_Mvc_Model, update){ - zval *descriptor = NULL, *dbname; + 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, 0, 1, &descriptor); + phalcon_fetch_params(1, 0, 2, &data, &white_list); - if (!descriptor) { - PHALCON_INIT_VAR(descriptor); - } else { - PHALCON_SEPARATE_PARAM(descriptor); + if (!data) { + PHALCON_INIT_VAR(data); } - 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 (!white_list) { + PHALCON_INIT_VAR(white_list); } - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Sqlite", "connect", descriptor); + PHALCON_INIT_VAR(meta_data); - 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; ->>>>>>> 1.2.2 - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); -<<<<<<< HEAD + 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; + } - if (!schema) { - PHALCON_INIT_VAR(schema); - } + 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_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + PHALCON_INIT_VAR(attributes); + phalcon_call_method_p1_key(attributes, meta_data, "getattributes", this_ptr, 1013165772UL); - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describeindexes", table, schema, 689092630UL); -======= + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (!schema) { - PHALCON_INIT_VAR(schema); - } + PHALCON_GET_HVALUE(attribute); - PHALCON_INIT_VAR(columns); - array_init(columns); + 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); + } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + if (phalcon_array_isset(data, attribute_field)) { - PHALCON_INIT_VAR(size_pattern); - ZVAL_STRING(size_pattern, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); + 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_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, data, attribute_field, PH_NOISY); - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); ->>>>>>> 1.2.2 + 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_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + zend_hash_move_forward_ex(ah0, &hp0); + } -<<<<<<< HEAD - PHALCON_INIT_VAR(indexes); - array_init(indexes); -======= - PHALCON_INIT_VAR(old_column); ->>>>>>> 1.2.2 + } - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + 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); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(read_connection); + phalcon_call_method_key(read_connection, this_ptr, "getreadconnection", 488334257UL); - PHALCON_GET_HVALUE(index); + 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); -<<<<<<< HEAD - 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_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_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_call_method_key(return_value, this_ptr, "save", 274150868UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, delete){ + + 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_INIT_VAR(meta_data); + phalcon_call_method_key(meta_data, this_ptr, "getmodelsmetadata", 3603043978UL); - phalcon_is_iterable(describe_index, &ah1, &hp1, 0, 0); + PHALCON_INIT_VAR(write_connection); + phalcon_call_method_key(write_connection, this_ptr, "getwriteconnection", 4280185952UL); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + phalcon_update_property_long(this_ptr, SL("_operationMade"), 3 TSRMLS_CC); - PHALCON_GET_HVALUE(index_column); + 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_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); + if (PHALCON_GLOBAL(orm).virtual_foreign_keys) { - zend_hash_move_forward_ex(ah1, &hp1); + 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; } - - zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_INIT_VAR(index_objects); - array_init(index_objects); - - phalcon_is_iterable(indexes, &ah2, &hp2, 0, 0); + PHALCON_INIT_VAR(values); + array_init(values); - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + PHALCON_INIT_VAR(bind_types); + array_init(bind_types); - PHALCON_GET_HKEY(name, ah2, hp2); - PHALCON_GET_HVALUE(index_columns); + PHALCON_INIT_VAR(conditions); + array_init(conditions); - 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(primary_keys); + phalcon_call_method_p1_key(primary_keys, meta_data, "getprimarykeyattributes", this_ptr, 692945721UL); - phalcon_array_update_zval(&index_objects, name, &index, PH_COPY | PH_SEPARATE); + 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); + } - zend_hash_move_forward_ex(ah2, &hp2); + 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; } - RETURN_CTOR(index_objects); -} - -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; -======= - PHALCON_INIT_NVAR(definition); - array_init_size(definition, 1); - add_assoc_long_ex(definition, SS("bindType"), 2); + phalcon_is_iterable(primary_keys, &ah0, &hp0, 0, 0); - PHALCON_OBS_NVAR(column_type); - phalcon_array_fetch_long(&column_type, field, 2, PH_NOISY); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - 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_GET_HVALUE(primary_key); - PHALCON_OBS_NVAR(attribute); - phalcon_array_fetch_long(&attribute, field, 5, PH_NOISY); + 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 (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); + 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 { - 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); - } - } - } - } - } - } - } + 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_memnstr_str(column_type, SL("("))) { + 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_INIT_NVAR(matches); + 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(pos); - phalcon_preg_match(pos, size_pattern, column_type, matches TSRMLS_CC); + PHALCON_INIT_NVAR(escaped_field); + phalcon_call_method_p1_key(escaped_field, write_connection, "escapeidentifier", primary_key, 585773337UL); - 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); - } - } - } + PHALCON_INIT_NVAR(primary_condition); + PHALCON_CONCAT_VS(primary_condition, escaped_field, " = ?"); + phalcon_array_append(&conditions, primary_condition, PH_SEPARATE); - if (phalcon_memnstr_str(column_type, SL("unsigned"))) { - phalcon_array_update_string_bool(&definition, SL("unsigned"), 1, 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); - if (!zend_is_true(old_column)) { - phalcon_array_update_string_bool(&definition, SL("first"), 1, 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_array_update_quick_string(&definition, SS("after"), 4053435767UL, &old_column, PH_COPY | PH_SEPARATE); + 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_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_INIT_VAR(schema); + phalcon_call_method_key(schema, this_ptr, "getschema", 1539736246UL); - 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(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_NVAR(column_name); - phalcon_array_fetch_long(&column_name, field, 1, PH_NOISY); + PHALCON_INIT_VAR(success); + phalcon_call_method_p4_key(success, write_connection, "delete", table, delete_conditions, values, bind_types, 150213496UL); - 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_GLOBAL(orm).virtual_foreign_keys) { - phalcon_array_append(&columns, column, PH_SEPARATE); - PHALCON_CPY_WRT(old_column, column_name); + 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_hash_move_forward_ex(ah0, &hp0); + 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); + } } - RETURN_CTOR(columns); + phalcon_update_property_long(this_ptr, SL("_dirtyState"), 2 TSRMLS_CC); + + RETURN_CCTOR(success); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeIndexes){ +static PHP_METHOD(Phalcon_Mvc_Model, getOperationMade){ - 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; ->>>>>>> 1.2.2 + + RETURN_MEMBER_QUICK(this_ptr, "_operationMade", 3968152972UL); +} + +static PHP_METHOD(Phalcon_Mvc_Model, refresh){ + + 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_fetch_params(1, 1, 1, &table, &schema); -<<<<<<< HEAD + 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; + } - if (!schema) { - PHALCON_INIT_VAR(schema); + 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(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + 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(sql); - phalcon_call_method_p2_key(sql, dialect, "describereferences", table, schema, 1939869288UL); + 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_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + PHALCON_OBS_NVAR(unique_key); + phalcon_read_property_this_quick(&unique_key, this_ptr, SL("_uniqueKey"), 1221404964UL, PH_NOISY_CC); + } - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + 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_INIT_VAR(reference_objects); - array_init(reference_objects); + PHALCON_OBS_VAR(unique_types); + phalcon_read_property_this_quick(&unique_types, this_ptr, SL("_uniqueTypes"), 3340838640UL, PH_NOISY_CC); - phalcon_is_iterable(describe, &ah0, &hp0, 0, 0); + 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_HKEY(number, ah0, hp0); - PHALCON_GET_HVALUE(reference_describe); + PHALCON_GET_HVALUE(attribute); - PHALCON_INIT_NVAR(constraint_name); - PHALCON_CONCAT_SV(constraint_name, "foreign_key_", number); + 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); - PHALCON_OBS_NVAR(referenced_table); - phalcon_array_fetch_long(&referenced_table, reference_describe, 2, PH_NOISY); + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_OBS_NVAR(from); - phalcon_array_fetch_long(&from, reference_describe, 3, PH_NOISY); + PHALCON_INIT_VAR(escaped_table); + phalcon_call_method_p1_key(escaped_table, read_connection, "escapeidentifier", table, 585773337UL); - PHALCON_OBS_NVAR(to); - phalcon_array_fetch_long(&to, reference_describe, 4, PH_NOISY); + 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_NVAR(columns); - array_init_size(columns, 1); - phalcon_array_append(&columns, from, PH_SEPARATE); + PHALCON_INIT_VAR(dialect); + phalcon_call_method_key(dialect, read_connection, "getdialect", 3133083739UL); - PHALCON_INIT_NVAR(referenced_columns); - array_init_size(referenced_columns, 1); - phalcon_array_append(&referenced_columns, to, PH_SEPARATE); + PHALCON_INIT_VAR(sql); + phalcon_call_method_p1_key(sql, dialect, "select", select, 2342345829UL); - 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_VAR(fetch_type); + ZVAL_LONG(fetch_type, 1); - 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_INIT_VAR(row); + phalcon_call_method_p4_key(row, read_connection, "fetchone", sql, fetch_type, unique_params, unique_types, 1637187313UL); - phalcon_array_update_zval(&reference_objects, constraint_name, &reference, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(column_map); + phalcon_call_method_p1_key(column_map, meta_data, "getcolumnmap", this_ptr, 213063537UL); - zend_hash_move_forward_ex(ah0, &hp0); + if (Z_TYPE_P(row) == IS_ARRAY) { + phalcon_call_method_p2_key(NULL, this_ptr, "assign", row, column_map, 1127103722UL); } - RETURN_CTOR(reference_objects); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, useExplicitIdValue){ +static PHP_METHOD(Phalcon_Mvc_Model, skipOperation){ + zval *skip; - RETURN_TRUE; + phalcon_fetch_params(0, 1, 0, &skip); + + phalcon_update_property_this_quick(this_ptr, SL("_skipped"), skip, 2005665588UL TSRMLS_CC); + } +static PHP_METHOD(Phalcon_Mvc_Model, 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(); +} -#ifdef HAVE_CONFIG_H -#endif +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 PHP_METHOD(Phalcon_Mvc_Model, skipAttributes){ + 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, "setautomaticcreateattributes", this_ptr, keys_attributes, 316109587UL); + phalcon_call_method_p2_key(NULL, meta_data, "setautomaticupdateattributes", this_ptr, keys_attributes, 2859965858UL); + + PHALCON_MM_RESTORE(); +} -PHALCON_INIT_CLASS(Phalcon_Db_Result_Pdo){ +static PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnCreate){ - PHALCON_REGISTER_CLASS(Phalcon\\Db\\Result, Pdo, db_result_pdo, phalcon_db_result_pdo_method_entry, 0); + zval *attributes, *null_value, *keys_attributes; + zval *attribute = NULL, *meta_data; + HashTable *ah0; + HashPosition hp0; + zval **hd; - 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_MM_GROW(); - return SUCCESS; + 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_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Result_Pdo, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model, skipAttributesOnUpdate){ - zval *connection, *result, *sql_statement = NULL, *bind_params = NULL; - zval *bind_types = 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, 2, 3, &connection, &result, &sql_statement, &bind_params, &bind_types); + phalcon_fetch_params(1, 1, 0, &attributes); - if (!sql_statement) { - PHALCON_INIT_VAR(sql_statement); + if (Z_TYPE_P(attributes) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "Attributes must be an array"); + return; } - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } + PHALCON_INIT_VAR(null_value); - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } + PHALCON_INIT_VAR(keys_attributes); + array_init(keys_attributes); - if (Z_TYPE_P(result) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid PDOStatement supplied to Phalcon\\Db\\Result\\Pdo"); - 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); - } + phalcon_is_iterable(attributes, &ah0, &hp0, 0, 0); - if (Z_TYPE_P(bind_params) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_bindParams"), bind_params, 2293392709UL TSRMLS_CC); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (Z_TYPE_P(bind_types) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_bindTypes"), bind_types, 514734038UL TSRMLS_CC); + 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_Db_Result_Pdo, execute){ +static PHP_METHOD(Phalcon_Mvc_Model, hasOne){ - zval *pdo_statement; + zval *fields, *reference_model, *referenced_fields; + zval *options = NULL, *manager; 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); + 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(); } -static PHP_METHOD(Phalcon_Db_Result_Pdo, fetch){ +static PHP_METHOD(Phalcon_Mvc_Model, belongsTo){ - zval *pdo_statement; + zval *fields, *reference_model, *referenced_fields; + zval *options = NULL, *manager; 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, "fetch", 4247924303UL); + 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(); } -static PHP_METHOD(Phalcon_Db_Result_Pdo, fetchArray){ +static PHP_METHOD(Phalcon_Mvc_Model, hasMany){ - zval *pdo_statement; + zval *fields, *reference_model, *referenced_fields; + zval *options = NULL, *manager; 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, "fetch", 4247924303UL); + 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(); } -static PHP_METHOD(Phalcon_Db_Result_Pdo, fetchAll){ +static PHP_METHOD(Phalcon_Mvc_Model, hasManyToMany){ - zval *pdo_statement; + 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_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); + 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_Db_Result_Pdo, numRows){ +static PHP_METHOD(Phalcon_Mvc_Model, addBehavior){ - 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; + zval *behavior, *manager; 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_fetch_params(1, 1, 0, &behavior); - PHALCON_OBS_VAR(connection); - phalcon_read_property_this_quick(&connection, this_ptr, SL("_connection"), 3057302292UL, PH_NOISY_CC); + 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_INIT_VAR(type); - phalcon_call_method_key(type, connection, "gettype", 4294422375UL); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Model, keepSnapshots){ + + zval *keep_snapshot, *manager; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &keep_snapshot); - 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_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_INIT_NVAR(row_count); - phalcon_call_method_key(row_count, pdo_statement, "rowcount", 4184721862UL); -======= + PHALCON_MM_RESTORE(); +} + +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 (!schema) { - PHALCON_INIT_VAR(schema); + if (!column_map) { + PHALCON_INIT_VAR(column_map); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + 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_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + if (Z_TYPE_P(column_map) == IS_ARRAY) { - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describeindexes", table, schema, 689092630UL); + PHALCON_INIT_VAR(snapshot); + array_init(snapshot); - PHALCON_INIT_VAR(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + phalcon_is_iterable(data, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(indexes); - array_init(indexes); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - phalcon_is_iterable(describe, &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) { + if (Z_TYPE_P(key) != IS_STRING) { + zend_hash_move_forward_ex(ah0, &hp0); + continue; + } - PHALCON_GET_HVALUE(index); + 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(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_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_INIT_NVAR(sql_index_describe); - phalcon_call_method_p1_key(sql_index_describe, dialect, "describeindex", key_name, 1925282846UL); + phalcon_update_property_this_quick(this_ptr, SL("_snapshot"), snapshot, 3325604532UL TSRMLS_CC); + RETURN_MM_NULL(); + } - PHALCON_INIT_NVAR(describe_index); - phalcon_call_method_p2_key(describe_index, this_ptr, "fetchall", sql_index_describe, fetch_num, 1636682248UL); + phalcon_update_property_this_quick(this_ptr, SL("_snapshot"), data, 3325604532UL TSRMLS_CC); - phalcon_is_iterable(describe_index, &ah1, &hp1, 0, 0); + PHALCON_MM_RESTORE(); +} + +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; + } - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + RETURN_MM_FALSE; +} + +static PHP_METHOD(Phalcon_Mvc_Model, getSnapshotData){ + + + RETURN_MEMBER_QUICK(this_ptr, "_snapshot", 3325604532UL); +} + +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); - PHALCON_GET_HVALUE(index_column); + if (!field_name) { + PHALCON_INIT_VAR(field_name); + } - 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_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; + } - zend_hash_move_forward_ex(ah1, &hp1); ->>>>>>> 1.2.2 + 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; } + } - 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_OBS_VAR(dirty_state); + phalcon_read_property_this_quick(&dirty_state, this_ptr, SL("_dirtyState"), 1560981745UL, PH_NOISY_CC); -<<<<<<< HEAD - PHALCON_INIT_NVAR(row_count); - phalcon_call_method_key(row_count, pdo_statement, "rowcount", 4184721862UL); + 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_IS_FALSE(row_count)) { + 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; + } - PHALCON_OBS_VAR(sql_statement); - phalcon_read_property_this_quick(&sql_statement, this_ptr, SL("_sqlStatement"), 18972457UL, PH_NOISY_CC); + 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; + } - if (!phalcon_start_with_str(sql_statement, SL("SELECT COUNT(*) "))) { + PHALCON_OBS_VAR(value); + phalcon_read_property_zval(&value, this_ptr, field_name, PH_NOISY_CC); - PHALCON_OBS_VAR(bind_params); - phalcon_read_property_this_quick(&bind_params, this_ptr, SL("_bindParams"), 2293392709UL, PH_NOISY_CC); + PHALCON_OBS_VAR(original_value); + phalcon_array_fetch(&original_value, snapshot, field_name, PH_NOISY); - PHALCON_OBS_VAR(bind_types); - phalcon_read_property_this_quick(&bind_types, this_ptr, SL("_bindTypes"), 514734038UL, PH_NOISY_CC); + if (PHALCON_IS_EQUAL(value, original_value)) { + RETURN_MM_FALSE; + } else { + RETURN_MM_TRUE; + } + } - PHALCON_INIT_VAR(matches); + phalcon_is_iterable(all_attributes, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(pattern); - ZVAL_STRING(pattern, "/^SELECT\\s+(.*)$/i", 1); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(match); - phalcon_preg_match(match, pattern, sql_statement, matches TSRMLS_CC); + PHALCON_GET_HKEY(name, ah0, hp0); + PHALCON_GET_HVALUE(type); - if (zend_is_true(match)) { - PHALCON_OBS_VAR(else_clauses); - phalcon_array_fetch_long(&else_clauses, matches, 1, PH_NOISY); + if (!phalcon_array_isset(snapshot, name)) { + RETURN_MM_TRUE; + } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "SELECT COUNT(*) \"numrows\" FROM (SELECT ", else_clauses, ")"); + if (!phalcon_isset_property_zval(this_ptr, name TSRMLS_CC)) { + RETURN_MM_TRUE; + } - PHALCON_INIT_VAR(result); - phalcon_call_method_p3_key(result, connection, "query", sql, bind_params, bind_types, 401898907UL); + PHALCON_OBS_NVAR(value); + phalcon_read_property_zval(&value, this_ptr, name, PH_NOISY_CC); - PHALCON_INIT_VAR(row); - phalcon_call_method_key(row, result, "fetch", 4247924303UL); + PHALCON_OBS_NVAR(original_value); + phalcon_array_fetch(&original_value, snapshot, name, PH_NOISY); - 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); - } + if (!PHALCON_IS_EQUAL(value, original_value)) { + RETURN_MM_TRUE; } - phalcon_update_property_this_quick(this_ptr, SL("_rowCount"), row_count, 1917183365UL TSRMLS_CC); + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CCTOR(row_count); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Result_Pdo, dataSeek){ +static PHP_METHOD(Phalcon_Mvc_Model, getChangedFields){ - long number = 0, n; - zval *connection, *pdo, *sql_statement; - zval *bind_params, *bind_types, *statement = NULL; - zval *temp_statement = NULL; - pdo_stmt_t *stmt; + 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(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &number) == FAILURE) { - RETURN_MM_NULL(); + 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); +} - PHALCON_OBS_VAR(connection); - phalcon_read_property(&connection, this_ptr, SL("_connection"), PH_NOISY_CC); - - PHALCON_INIT_VAR(pdo); - phalcon_call_method_key(pdo, connection, "getinternalhandler", 489229824UL); - - PHALCON_OBS_VAR(sql_statement); - phalcon_read_property(&sql_statement, this_ptr, SL("_sqlStatement"), PH_NOISY_CC); - - PHALCON_OBS_VAR(bind_params); - phalcon_read_property(&bind_params, this_ptr, SL("_bindParams"), PH_NOISY_CC); +static PHP_METHOD(Phalcon_Mvc_Model, useDynamicUpdate){ - if (Z_TYPE_P(bind_params) == IS_ARRAY) { + zval *dynamic_update, *manager; - PHALCON_OBS_VAR(bind_types); - phalcon_read_property(&bind_types, this_ptr, SL("_bindTypes"), PH_NOISY_CC); + PHALCON_MM_GROW(); - 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); - } + 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(); +} - } else { - PHALCON_INIT_NVAR(statement); - phalcon_call_method_p1_key(statement, pdo, "query", sql_statement, 401898907UL); - } +static PHP_METHOD(Phalcon_Mvc_Model, getRelated){ - phalcon_update_property_zval(this_ptr, SL("_pdoStatement"), statement TSRMLS_CC); + zval *alias, *arguments = NULL, *manager, *class_name; + zval *relation, *exception_message, *call_object; + zval *model_args; + PHALCON_MM_GROW(); - stmt = (pdo_stmt_t*) zend_object_store_get_object(statement TSRMLS_CC); - if (!stmt->dbh) { - PHALCON_MM_RESTORE(); - RETURN_FALSE; + phalcon_fetch_params(1, 1, 1, &alias, &arguments); + + if (!arguments) { + PHALCON_INIT_VAR(arguments); } - - n = -1; - number--; - while (n != number) { - - if(!stmt->methods->fetcher(stmt, PDO_FETCH_ORI_NEXT, 0 TSRMLS_CC)) { - PHALCON_MM_RESTORE(); - RETURN_NULL(); - } - - n++; + + 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_MM_RESTORE(); + + 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_Db_Result_Pdo, setFetchMode){ - +static PHP_METHOD(Phalcon_Mvc_Model, _getRelatedRecords){ - long fetch_mode; - zval *pdo_statement, *fetch_type; + 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(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fetch_mode) == FAILURE) { - RETURN_MM_NULL(); + 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); } - - PHALCON_INIT_VAR(fetch_type); - - 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(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_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 (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(); } -static PHP_METHOD(Phalcon_Db_Result_Pdo, getInternalResult){ - - - RETURN_MEMBER_QUICK(this_ptr, "_pdoStatement", 650036348UL); -} - - - - - -#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); +static PHP_METHOD(Phalcon_Mvc_Model, __call){ - 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); + zval *method, *arguments = NULL, *model_name, *records; + zval *models_manager, *status, *exception_message; - zend_class_implements(phalcon_db_column_ce TSRMLS_CC, 1, phalcon_db_columninterface_ce); + PHALCON_MM_GROW(); - 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_Db_Column, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model, __callStatic){ - 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; + 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, 2, 0, &column_name, &definition); - - phalcon_update_property_this_quick(this_ptr, SL("_columnName"), column_name, 3251978323UL TSRMLS_CC); + phalcon_fetch_params(1, 1, 1, &method, &arguments); - 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 (!arguments) { + PHALCON_INIT_VAR(arguments); } - 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_INIT_VAR(extra_method); - 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_start_with_str(method, SL("findFirstBy"))) { + PHALCON_INIT_VAR(type); + ZVAL_STRING(type, "findFirst", 1); - 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_substr(extra_method, method, 11, 0); } - if (phalcon_array_isset_quick_string(definition, SS("scale"), 458672173UL)) { + 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_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); + PHALCON_INIT_NVAR(extra_method); + phalcon_substr(extra_method, method, 6, 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; + 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); } } - 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); + 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_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_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; } - 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; - } - } + PHALCON_OBS_VAR(value); + phalcon_array_fetch_long(&value, arguments, 0, PH_NOISY); + ce0 = phalcon_fetch_class(model_name TSRMLS_CC); - 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); + 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 (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(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_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); + 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_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Db_Column, getSchemaName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_schemaName", 851420310UL); -} - -static PHP_METHOD(Phalcon_Db_Column, getName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_columnName", 3251978323UL); -} - -static PHP_METHOD(Phalcon_Db_Column, getType){ - - - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); -} - -static PHP_METHOD(Phalcon_Db_Column, getSize){ - - - RETURN_MEMBER_QUICK(this_ptr, "_size", 3990209087UL); -} - -static PHP_METHOD(Phalcon_Db_Column, getScale){ - - - RETURN_MEMBER_QUICK(this_ptr, "_scale", 2819877996UL); + 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(); } -static PHP_METHOD(Phalcon_Db_Column, isUnsigned){ - - - RETURN_MEMBER_QUICK(this_ptr, "_unsigned", 127907201UL); -} +static PHP_METHOD(Phalcon_Mvc_Model, __set){ -static PHP_METHOD(Phalcon_Db_Column, isNotNull){ + zval *property, *value, *is_model, *lower_property = NULL; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_notNull", 628108368UL); + 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); } -static PHP_METHOD(Phalcon_Db_Column, isPrimary){ - - - RETURN_MEMBER_QUICK(this_ptr, "_primary", 3445614760UL); -} +static PHP_METHOD(Phalcon_Mvc_Model, __get){ -static PHP_METHOD(Phalcon_Db_Column, isAutoIncrement){ + zval *property, *model_name, *manager, *lower_property; + zval *relation, *call_args, *call_object, *result; + zval *is_simple_model, *error_msg; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_autoIncrement", 3100381058UL); + 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(); } -static PHP_METHOD(Phalcon_Db_Column, isNumeric){ - - - RETURN_MEMBER_QUICK(this_ptr, "_isNumeric", 2501917651UL); -} +static PHP_METHOD(Phalcon_Mvc_Model, __isset){ -static PHP_METHOD(Phalcon_Db_Column, isFirst){ + zval *property, *model_name, *manager, *relation; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_first", 2318852460UL); + 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; } -static PHP_METHOD(Phalcon_Db_Column, getAfterPosition){ - - - RETURN_MEMBER_QUICK(this_ptr, "_after", 2119674294UL); -} +static PHP_METHOD(Phalcon_Mvc_Model, serialize){ -static PHP_METHOD(Phalcon_Db_Column, getBindType){ + zval *meta_data, *attributes, *null_value, *data; + zval *attribute = NULL, *value = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_bindType", 926651555UL); + 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(); } -static PHP_METHOD(Phalcon_Db_Column, __set_state){ +static PHP_METHOD(Phalcon_Mvc_Model, unserialize){ - zval *data, *definition, *column_name, *column_type; - zval *not_null, *primary, *size, *dunsigned, *after; - zval *is_numeric, *first, *bind_type; + 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_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column state must be an array"); - return; - } + if (Z_TYPE_P(data) == IS_STRING) { - 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(attributes); + phalcon_unserialize(attributes, data TSRMLS_CC); + if (Z_TYPE_P(attributes) == IS_ARRAY) { - 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(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - 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); - } + 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_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); - } + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL 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); - } + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "modelsManager", 1); - 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(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; + } - 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_update_property_this_quick(this_ptr, SL("_modelsManager"), manager, 3699347875UL TSRMLS_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); - } + phalcon_call_method_p1_key(NULL, manager, "initialize", this_ptr, 2896075127UL); - 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_is_iterable(attributes, &ah0, &hp0, 0, 0); - 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); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - object_init_ex(return_value, phalcon_db_column_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", column_name, definition, 1107214344UL); + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - RETURN_MM(); + 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_Model, dump){ + PHALCON_MM_GROW(); - -#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; + phalcon_call_func_p1(return_value, "get_object_vars", this_ptr); + RETURN_MM(); } +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(); - - - - - -#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; + 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); } -static PHP_METHOD(Phalcon_Db_Reference, __construct){ +static PHP_METHOD(Phalcon_Mvc_Model, setup){ - zval *reference_name, *definition, *referenced_table; - zval *columns, *referenced_columns, *schema; - zval *referenced_schema, *number_columns; - zval *number_referenced_columns; + 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, &reference_name, &definition); + phalcon_fetch_params(1, 1, 0, &options); - 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"); + 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(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(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(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(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(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(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(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); + 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); } - PHALCON_INIT_VAR(number_columns); - phalcon_fast_count(number_columns, columns TSRMLS_CC); + 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); + } - 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; + 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(); } -static PHP_METHOD(Phalcon_Db_Reference, getName){ - RETURN_MEMBER_QUICK(this_ptr, "_referenceName", 4269393812UL); -} -static PHP_METHOD(Phalcon_Db_Reference, getSchemaName){ +#ifdef HAVE_CONFIG_H +#endif - RETURN_MEMBER_QUICK(this_ptr, "_schemaName", 851420310UL); -} -static PHP_METHOD(Phalcon_Db_Reference, getReferencedSchema){ +PHALCON_INIT_CLASS(Phalcon_Mvc_ViewInterface){ - RETURN_MEMBER_QUICK(this_ptr, "_referencedSchema", 106854792UL); -} + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ViewInterface, mvc_viewinterface, phalcon_mvc_viewinterface_method_entry); -static PHP_METHOD(Phalcon_Db_Reference, getColumns){ + return SUCCESS; +} - 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 @@ -122726,36 +45606,18 @@ static PHP_METHOD(Phalcon_Db_Reference, __set_state){ -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_update_property_this_quick(this_ptr, SL("_value"), value, 2935317441UL TSRMLS_CC); - -} -static PHP_METHOD(Phalcon_Db_RawValue, getValue){ - RETURN_MEMBER_QUICK(this_ptr, "_value", 2935317441UL); -} -static PHP_METHOD(Phalcon_Db_RawValue, __toString){ - RETURN_MEMBER_QUICK(this_ptr, "_value", 2935317441UL); -} @@ -122769,79 +45631,49 @@ static PHP_METHOD(Phalcon_Db_RawValue, __toString){ +PHALCON_INIT_CLASS(Phalcon_Mvc_User_Component){ -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); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Component, mvc_user_component, "phalcon\\di\\injectable", NULL, 0); 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){ +#ifdef HAVE_CONFIG_H +#endif - 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_INIT_CLASS(Phalcon_Mvc_User_Module){ - phalcon_fetch_params(0, 1, 0, &final_time); - - phalcon_update_property_this_quick(this_ptr, SL("_finalTime"), final_time, 2101629981UL TSRMLS_CC); - + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Module, mvc_user_module, "phalcon\\di\\injectable", NULL, 0); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Profiler_Item, getInitialTime){ - RETURN_MEMBER_QUICK(this_ptr, "_initialTime", 3347691997UL); -} -static PHP_METHOD(Phalcon_Db_Profiler_Item, getFinalTime){ + +#ifdef HAVE_CONFIG_H +#endif + + - RETURN_MEMBER_QUICK(this_ptr, "_finalTime", 2101629981UL); -} -static PHP_METHOD(Phalcon_Db_Profiler_Item, getTotalElapsedSeconds){ - zval *final_time, *initial_time; +PHALCON_INIT_CLASS(Phalcon_Mvc_User_Plugin){ - PHALCON_MM_GROW(); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\User, Plugin, mvc_user_plugin, "phalcon\\di\\injectable", NULL, 0); - 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(); + return SUCCESS; } @@ -122853,1329 +45685,1933 @@ static PHP_METHOD(Phalcon_Db_Profiler_Item, getTotalElapsedSeconds){ -PHALCON_INIT_CLASS(Phalcon_Db_ResultInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ResultInterface, db_resultinterface, phalcon_db_resultinterface_method_entry); - return SUCCESS; -} +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){ -#ifdef HAVE_CONFIG_H -#endif + 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){ -PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Mysql){ + zval *default_module; - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Mysql, db_dialect_mysql, "phalcon\\db\\dialect", phalcon_db_dialect_mysql_method_entry, 0); + phalcon_fetch_params(0, 1, 0, &default_module); + + phalcon_update_property_this_quick(this_ptr, SL("_defaultModule"), default_module, 3959488399UL TSRMLS_CC); + RETURN_THISW(); +} - zend_declare_property_string(phalcon_db_dialect_mysql_ce, SL("_escapeChar"), "`", ZEND_ACC_PROTECTED TSRMLS_CC); +static PHP_METHOD(Phalcon_Mvc_Application, getDefaultModule){ - zend_class_implements(phalcon_db_dialect_mysql_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_defaultModule", 3959488399UL); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, getColumnDefinition){ +static PHP_METHOD(Phalcon_Mvc_Application, handle){ - zval *column, *size, *column_type, *column_sql = NULL; - zval *is_unsigned = NULL, *scale = NULL; + 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, 1, 0, &column); + phalcon_fetch_params(1, 0, 1, &uri); - 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"); + 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_INIT_VAR(size); - phalcon_call_method_key(size, column, "getsize", 4292672352UL); + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - PHALCON_INIT_VAR(column_type); - phalcon_call_method_key(column_type, column, "gettype", 4294422375UL); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - switch (phalcon_get_intval(column_type)) { + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "application:boot", 1); - case 0: - PHALCON_INIT_VAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "INT(", size, ")"); + 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(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_VAR(service); + ZVAL_STRING(service, "router", 1); - break; + PHALCON_INIT_VAR(router); + phalcon_call_method_p1_key(router, dependency_injector, "getshared", service, 1727570332UL); - case 1: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "DATE", 1); - break; + phalcon_call_method_p1_key(NULL, router, "handle", uri, 866903697UL); - case 2: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "VARCHAR(", size, ")"); - break; + PHALCON_INIT_VAR(module_name); + phalcon_call_method_key(module_name, router, "getmodulename", 3538616428UL); - case 3: - PHALCON_INIT_VAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + 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_NVAR(column_sql); - PHALCON_CONCAT_SVSVS(column_sql, "DECIMAL(", size, ",", scale, ")"); + PHALCON_INIT_VAR(module_object); - 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(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; } + } - break; + 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; + } - case 4: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "DATETIME", 1); - break; + 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; + } + } - case 5: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "CHAR(", size, ")"); - break; + if (Z_TYPE_P(module) == IS_ARRAY) { - case 6: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TEXT", 1); - break; + 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); + } - case 7: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "FLOAT", 1); + if (phalcon_array_isset_quick_string(module, SS("path"), 270591026UL)) { - 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_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_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_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; } + } - break; + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_moduleObject"), module_object, 121977121UL TSRMLS_CC); - case 8: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TINYINT(1)", 1); - break; + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "application:afterStartModule", 1); - default: - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized MySQL data type"); - return; + 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); } - RETURN_CTOR(column_sql); + 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); } -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; + + + +#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, 3, 0, &table_name, &schema_name, &column); + phalcon_fetch_params(1, 0, 2, &dependency_injector, &models_manager); - 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 (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); + } else { + PHALCON_SEPARATE_PARAM(dependency_injector); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD "); + + if (!models_manager) { + PHALCON_INIT_VAR(models_manager); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD "); + PHALCON_SEPARATE_PARAM(models_manager); } - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, column, "getname", 4286441094UL); + 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_INIT_VAR(column_definition); - phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); - PHALCON_SCONCAT_SVSV(sql, "`", name, "` ", column_definition); + phalcon_update_property_this_quick(this_ptr, SL("_modelsManager"), models_manager, 3699347875UL TSRMLS_CC); - 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_call_method_p1_key(NULL, models_manager, "initialize", this_ptr, 2896075127UL); - 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 (phalcon_method_quick_exists_ex(this_ptr, SS("onconstruct"), 564344039UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, this_ptr, "onconstruct", 564344039UL); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, modifyColumn){ +static PHP_METHOD(Phalcon_Mvc_Collection, setId){ - zval *table_name, *schema_name, *column, *sql = NULL, *name; - zval *column_definition, *is_not_null; + zval *id, *models_manager, *use_implicit_ids; + zval *mongo_id = NULL; + zend_class_entry *ce0; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); + phalcon_fetch_params(1, 1, 0, &id); - 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 "); + 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_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` MODIFY "); + PHALCON_CPY_WRT(mongo_id, id); } + phalcon_update_property_this_quick(this_ptr, SL("_id"), mongo_id, 2090005265UL TSRMLS_CC); - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, column, "getname", 4286441094UL); - - PHALCON_INIT_VAR(column_definition); - phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); - PHALCON_SCONCAT_SVSV(sql, "`", name, "` ", column_definition); + 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_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_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropColumn){ +static PHP_METHOD(Phalcon_Mvc_Collection, getDI){ - zval *table_name, *schema_name, *column_name; - zval *sql = NULL; + + 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, 3, 0, &table_name, &schema_name, &column_name); + phalcon_fetch_params(1, 1, 0, &events_manager); - 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, "`"); + 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); - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addIndex){ +static PHP_METHOD(Phalcon_Mvc_Collection, getEventsManager){ - zval *table_name, *schema_name, *index, *sql = NULL, *columns; - zval *quoted_column_list, *name; + zval *models_manager; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); + 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){ + + + RETURN_MEMBER_QUICK(this_ptr, "_modelsManager", 3699347875UL); +} + +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); - 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 INDEX "); - } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD INDEX "); + 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); } - PHALCON_INIT_VAR(columns); - phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); + RETURN_CCTOR(reserved); +} + +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_INIT_VAR(quoted_column_list); - phalcon_call_method_p1_key(quoted_column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); + 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_INIT_VAR(name); - phalcon_call_method_key(name, index, "getname", 4286441094UL); - PHALCON_SCONCAT_SVSVS(sql, "`", name, "` (", quoted_column_list, ")"); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_Collection, setSource){ + + zval *source; + + phalcon_fetch_params(0, 1, 0, &source); - RETURN_CTOR(sql); + phalcon_update_property_this_quick(this_ptr, SL("_source"), source, 3355220565UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropIndex){ +static PHP_METHOD(Phalcon_Mvc_Collection, getSource){ - zval *table_name, *schema_name, *index_name; - zval *sql = NULL; + zval *source = NULL, *class_name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index_name); + 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); - 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_INIT_NVAR(source); + phalcon_uncamelize(source, class_name); + phalcon_update_property_this_quick(this_ptr, SL("_source"), source, 3355220565UL TSRMLS_CC); } - PHALCON_SCONCAT_SVS(sql, "`", index_name, "`"); - RETURN_CTOR(sql); + RETURN_CCTOR(source); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addPrimaryKey){ +static PHP_METHOD(Phalcon_Mvc_Collection, setConnectionService){ - zval *table_name, *schema_name, *index, *sql = NULL, *columns; - zval *column_list; + zval *connection_service, *models_manager; 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; - } - 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_fetch_params(1, 1, 0, &connection_service); - PHALCON_INIT_VAR(columns); - phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); + 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){ + + 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(); +} + +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_VAR(column_list); - phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); - PHALCON_SCONCAT_SVS(sql, "(", column_list, ")"); + 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_CTOR(sql); + RETURN_CCTOR(connection); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropPrimaryKey){ +static PHP_METHOD(Phalcon_Mvc_Collection, readAttribute){ - zval *table_name, *schema_name, *sql = NULL; + zval *attribute, *attribute_value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &table_name, &schema_name); + phalcon_fetch_params(1, 1, 0, &attribute); - 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"); + 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, writeAttribute){ + + zval *attribute, *value; + + phalcon_fetch_params(0, 2, 0, &attribute, &value); + + phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_CC); - RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addForeignKey){ +static PHP_METHOD(Phalcon_Mvc_Collection, cloneResult){ - 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 *collection, *document, *cloned_collection; + zval *value = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference); + phalcon_fetch_params(1, 2, 0, &collection, &document); - 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"); -======= - PHALCON_INIT_VAR(index_objects); - array_init(index_objects); + 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_is_iterable(indexes, &ah2, &hp2, 0, 0); + PHALCON_INIT_VAR(cloned_collection); + if (phalcon_clone(cloned_collection, collection TSRMLS_CC) == FAILURE) { + return; + } - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + phalcon_is_iterable(document, &ah0, &hp0, 0, 0); - PHALCON_GET_HKEY(name, ah2, hp2); - PHALCON_GET_HVALUE(index_columns); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - 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_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - phalcon_array_update_zval(&index_objects, name, &index, PH_COPY | PH_SEPARATE); + phalcon_call_method_p2_key(NULL, cloned_collection, "writeattribute", key, value, 3716971876UL); - zend_hash_move_forward_ex(ah2, &hp2); + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CTOR(index_objects); + RETURN_CCTOR(cloned_collection); } -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, describeReferences){ +static PHP_METHOD(Phalcon_Mvc_Collection, _getResultset){ - 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; + 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, 1, 1, &table, &schema); + phalcon_fetch_params(1, 4, 0, ¶ms, &collection, &connection, &unique); - if (!schema) { - PHALCON_INIT_VAR(schema); + 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_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + PHALCON_INIT_VAR(mongo_collection); + phalcon_call_method_p1_key(mongo_collection, connection, "selectcollection", source, 3563037297UL); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "describereferences", table, schema, 1939869288UL); + 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(fetch_num); - ZVAL_LONG(fetch_num, 3); + 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(describe); - phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_num, 1636682248UL); + 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_INIT_VAR(reference_objects); - array_init(reference_objects); + 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_is_iterable(describe, &ah0, &hp0, 0, 0); + 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); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + 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_GET_HKEY(number, ah0, hp0); - PHALCON_GET_HVALUE(reference_describe); + 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); + } - PHALCON_INIT_NVAR(constraint_name); - PHALCON_CONCAT_SV(constraint_name, "foreign_key_", number); + if (PHALCON_IS_TRUE(unique)) { - PHALCON_OBS_NVAR(referenced_table); - phalcon_array_fetch_long(&referenced_table, reference_describe, 2, PH_NOISY); + phalcon_call_method_key(NULL, documents_cursor, "rewind", 1064078190UL); - PHALCON_OBS_NVAR(from); - phalcon_array_fetch_long(&from, reference_describe, 3, PH_NOISY); + 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(); + } - PHALCON_OBS_NVAR(to); - phalcon_array_fetch_long(&to, reference_describe, 4, PH_NOISY); + RETURN_MM_FALSE; + } - PHALCON_INIT_NVAR(columns); - array_init_size(columns, 1); - phalcon_array_append(&columns, from, PH_SEPARATE); + PHALCON_INIT_VAR(collections); + array_init(collections); - PHALCON_INIT_NVAR(referenced_columns); - array_init_size(referenced_columns, 1); - phalcon_array_append(&referenced_columns, to, PH_SEPARATE); + PHALCON_INIT_VAR(documents_array); + phalcon_call_func_p1(documents_array, "iterator_to_array", documents_cursor); - 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_is_iterable(documents_array, &ah0, &hp0, 0, 0); - 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); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - phalcon_array_update_zval(&reference_objects, constraint_name, &reference, PH_COPY | PH_SEPARATE); + 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(reference_objects); -} - -static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Sqlite, useExplicitIdValue){ - - - RETURN_TRUE; -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Result_Pdo){ - - PHALCON_REGISTER_CLASS(Phalcon\\Db\\Result, Pdo, db_result_pdo, phalcon_db_result_pdo_method_entry, 0); - - 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); - - return SUCCESS; + RETURN_CTOR(collections); } -static PHP_METHOD(Phalcon_Db_Result_Pdo, __construct){ +static PHP_METHOD(Phalcon_Mvc_Collection, _getGroupResultset){ - zval *connection, *result, *sql_statement = NULL, *bind_params = NULL; - zval *bind_types = NULL; + zval *params, *collection, *connection, *source; + zval *mongo_collection, *conditions = NULL, *simple = NULL; + zval *documents_cursor, *limit, *sort = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 3, &connection, &result, &sql_statement, &bind_params, &bind_types); + phalcon_fetch_params(1, 3, 0, ¶ms, &collection, &connection); - if (!sql_statement) { - PHALCON_INIT_VAR(sql_statement); + 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; } - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } + PHALCON_INIT_VAR(mongo_collection); + phalcon_call_method_p1_key(mongo_collection, connection, "selectcollection", source, 3563037297UL); - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); + 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 (Z_TYPE_P(result) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid PDOStatement supplied to Phalcon\\Db\\Result\\Pdo"); - 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); + PHALCON_INIT_VAR(simple); + ZVAL_BOOL(simple, 1); + if (phalcon_array_isset_quick_string(params, SS("limit"), 192268420UL)) { + ZVAL_BOOL(simple, 0); + } else { + 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 (Z_TYPE_P(bind_params) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_bindParams"), bind_params, 2293392709UL TSRMLS_CC); - } + if (PHALCON_IS_FALSE(simple)) { - if (Z_TYPE_P(bind_types) != IS_NULL) { - phalcon_update_property_this_quick(this_ptr, SL("_bindTypes"), bind_types, 514734038UL TSRMLS_CC); + 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_MM_RESTORE(); -} - -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){ - - 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, "fetch", 4247924303UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Result_Pdo, fetchArray){ - - 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, "fetch", 4247924303UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Result_Pdo, fetchAll){ - - 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, "fetchall", 1636682248UL); + phalcon_call_method_p1_key(return_value, mongo_collection, "count", conditions, 4142425646UL); RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Result_Pdo, numRows){ +static PHP_METHOD(Phalcon_Mvc_Collection, _preSave){ - 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; + zval *dependency_injector, *disable_events; + zval *exists, *event_name = NULL, *status = NULL; 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_fetch_params(1, 3, 0, &dependency_injector, &disable_events, &exists); - PHALCON_INIT_VAR(type); - phalcon_call_method_key(type, connection, "gettype", 4294422375UL); + if (!zend_is_true(disable_events)) { - 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_VAR(event_name); + ZVAL_STRING(event_name, "beforeValidation", 1); - PHALCON_INIT_NVAR(row_count); - phalcon_call_method_key(row_count, pdo_statement, "rowcount", 4184721862UL); + 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_STRING(type, "pgsql")) { - PHALCON_OBS_NVAR(pdo_statement); - phalcon_read_property_this_quick(&pdo_statement, this_ptr, SL("_pdoStatement"), 650036348UL, 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_NVAR(row_count); - phalcon_call_method_key(row_count, pdo_statement, "rowcount", 4184721862UL); + 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 (PHALCON_IS_FALSE(row_count)) { + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "validation", 1); - PHALCON_OBS_VAR(sql_statement); - phalcon_read_property_this_quick(&sql_statement, this_ptr, SL("_sqlStatement"), 18972457UL, PH_NOISY_CC); + 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_start_with_str(sql_statement, SL("SELECT COUNT(*) "))) { + if (!zend_is_true(disable_events)) { - PHALCON_OBS_VAR(bind_params); - phalcon_read_property_this_quick(&bind_params, this_ptr, SL("_bindParams"), 2293392709UL, PH_NOISY_CC); + 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_OBS_VAR(bind_types); - phalcon_read_property_this_quick(&bind_types, this_ptr, SL("_bindTypes"), 514734038UL, PH_NOISY_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_INIT_VAR(matches); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "afterValidation", 1); - PHALCON_INIT_VAR(pattern); - ZVAL_STRING(pattern, "/^SELECT\\s+(.*)$/i", 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(match); - phalcon_preg_match(match, pattern, sql_statement, matches TSRMLS_CC); + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "beforeSave", 1); - if (zend_is_true(match)) { - PHALCON_OBS_VAR(else_clauses); - phalcon_array_fetch_long(&else_clauses, matches, 1, PH_NOISY); + 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(sql); - PHALCON_CONCAT_SVS(sql, "SELECT COUNT(*) \"numrows\" FROM (SELECT ", else_clauses, ")"); + 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_VAR(result); - phalcon_call_method_p3_key(result, connection, "query", sql, bind_params, bind_types, 401898907UL); + 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(row); - phalcon_call_method_key(row, result, "fetch", 4247924303UL); + 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_OBS_NVAR(row_count); - phalcon_array_fetch_quick_string(&row_count, row, SS("numrows"), 887792640UL, PH_NOISY); - } + 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(row_count); - ZVAL_LONG(row_count, 1); + 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); } - phalcon_update_property_this_quick(this_ptr, SL("_rowCount"), row_count, 1917183365UL TSRMLS_CC); + 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); } - RETURN_CCTOR(row_count); + phalcon_call_method_p1_key(NULL, this_ptr, "_canceloperation", disable_events, 1716493051UL); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Result_Pdo, dataSeek){ +static PHP_METHOD(Phalcon_Mvc_Collection, validate){ - long number = 0, n; - zval *connection, *pdo, *sql_statement; - zval *bind_params, *bind_types, *statement = NULL; - zval *temp_statement = NULL; - pdo_stmt_t *stmt; + zval *validator, *status, *messages, *message = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &number) == FAILURE) { - RETURN_MM_NULL(); + 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(); +} - PHALCON_OBS_VAR(connection); - phalcon_read_property(&connection, this_ptr, SL("_connection"), PH_NOISY_CC); - - PHALCON_INIT_VAR(pdo); - phalcon_call_method_key(pdo, connection, "getinternalhandler", 489229824UL); - - PHALCON_OBS_VAR(sql_statement); - phalcon_read_property(&sql_statement, this_ptr, SL("_sqlStatement"), PH_NOISY_CC); - - PHALCON_OBS_VAR(bind_params); - phalcon_read_property(&bind_params, this_ptr, SL("_bindParams"), PH_NOISY_CC); +static PHP_METHOD(Phalcon_Mvc_Collection, validationHasFailed){ - if (Z_TYPE_P(bind_params) == IS_ARRAY) { + zval *error_messages; - PHALCON_OBS_VAR(bind_types); - phalcon_read_property(&bind_types, this_ptr, SL("_bindTypes"), PH_NOISY_CC); + PHALCON_MM_GROW(); - 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); + 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; } - - } else { - PHALCON_INIT_NVAR(statement); - phalcon_call_method_p1_key(statement, pdo, "query", sql_statement, 401898907UL); } + + RETURN_MM_FALSE; +} - phalcon_update_property_zval(this_ptr, SL("_pdoStatement"), statement TSRMLS_CC); - - - stmt = (pdo_stmt_t*) zend_object_store_get_object(statement TSRMLS_CC); - if (!stmt->dbh) { - PHALCON_MM_RESTORE(); - RETURN_FALSE; - } +static PHP_METHOD(Phalcon_Mvc_Collection, fireEvent){ - n = -1; - number--; - while (n != number) { + zval *event_name, *models_manager; - if(!stmt->methods->fetcher(stmt, PDO_FETCH_ORI_NEXT, 0 TSRMLS_CC)) { - PHALCON_MM_RESTORE(); - RETURN_NULL(); - } + PHALCON_MM_GROW(); - n++; + 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_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(return_value, models_manager, "notifyevent", event_name, this_ptr, 1223080128UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ - +static PHP_METHOD(Phalcon_Mvc_Collection, fireEventCancel){ - long fetch_mode; - zval *pdo_statement, *fetch_type; + zval *event_name, *status = NULL, *models_manager; PHALCON_MM_GROW(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fetch_mode) == FAILURE) { - RETURN_MM_NULL(); + 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; +} - PHALCON_INIT_VAR(fetch_type); +static PHP_METHOD(Phalcon_Mvc_Collection, _cancelOperation){ - 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); - } + zval *disable_events, *operation_made, *event_name = NULL; - 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); - } + PHALCON_MM_GROW(); - RETURN_MM_NULL(); + 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; } -static PHP_METHOD(Phalcon_Db_Result_Pdo, getInternalResult){ +static PHP_METHOD(Phalcon_Mvc_Collection, _exists){ + + 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, "_pdoStatement", 650036348UL); + 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); + + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); + is_smaller_function(return_value, zero, document_count TSRMLS_CC); + + RETURN_MM(); + } + RETURN_MM_FALSE; } +static PHP_METHOD(Phalcon_Mvc_Collection, getMessages){ + RETURN_MEMBER_QUICK(this_ptr, "_errorMessages", 1019066246UL); +} +static PHP_METHOD(Phalcon_Mvc_Collection, appendMessage){ -#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); + zval *message, *type, *exception_message; - zend_class_implements(phalcon_db_column_ce TSRMLS_CC, 1, phalcon_db_columninterface_ce); + PHALCON_MM_GROW(); - 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_Db_Column, __construct){ +static PHP_METHOD(Phalcon_Mvc_Collection, save){ - 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; + 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, 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"); + 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_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_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; } - 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); - } + PHALCON_INIT_VAR(connection); + phalcon_call_method_key(connection, this_ptr, "getconnection", 2504689909UL); - 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_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); } - if (phalcon_array_isset_quick_string(definition, SS("scale"), 458672173UL)) { + PHALCON_INIT_VAR(empty_array); + array_init(empty_array); - 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); - } + phalcon_update_property_this_quick(this_ptr, SL("_errorMessages"), empty_array, 1019066246UL TSRMLS_CC); - 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; - } - } + PHALCON_OBS_VAR(disable_events); + phalcon_read_static_property(&disable_events, SL("phalcon\\mvc\\collection"), SL("_disableEvents") TSRMLS_CC); - 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); + 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 (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(data); + array_init(data); - 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); + 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 { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column type cannot be auto-increment"); - return; + if (!phalcon_array_isset(reserved, key)) { + phalcon_array_update_zval(&data, key, &value, PH_COPY | PH_SEPARATE); + } } - } - 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); + zend_hash_move_forward_ex(ah0, &hp0); } - 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(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)) { - 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_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_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Db_Column, getSchemaName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_schemaName", 851420310UL); -} - -static PHP_METHOD(Phalcon_Db_Column, getName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_columnName", 3251978323UL); -} - -static PHP_METHOD(Phalcon_Db_Column, getType){ - - - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); + phalcon_call_method_p3_key(return_value, this_ptr, "_postsave", disable_events, success, exists, 3354288601UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Column, getSize){ - - - RETURN_MEMBER_QUICK(this_ptr, "_size", 3990209087UL); -} +static PHP_METHOD(Phalcon_Mvc_Collection, findById){ -static PHP_METHOD(Phalcon_Db_Column, getScale){ + zval *id, *class_name, *collection, *models_manager; + zval *use_implicit_ids, *mongo_id = NULL, *conditions; + zval *parameters; + zend_class_entry *ce0, *ce1; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_scale", 2819877996UL); + 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_Db_Column, isUnsigned){ - - - RETURN_MEMBER_QUICK(this_ptr, "_unsigned", 127907201UL); -} +static PHP_METHOD(Phalcon_Mvc_Collection, findFirst){ -static PHP_METHOD(Phalcon_Db_Column, isNotNull){ + zval *parameters = NULL, *class_name, *collection, *connection; + zval *unique; + zend_class_entry *ce0; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_notNull", 628108368UL); + 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(); } -static PHP_METHOD(Phalcon_Db_Column, isPrimary){ - - - RETURN_MEMBER_QUICK(this_ptr, "_primary", 3445614760UL); -} +static PHP_METHOD(Phalcon_Mvc_Collection, find){ -static PHP_METHOD(Phalcon_Db_Column, isAutoIncrement){ + zval *parameters = NULL, *class_name, *collection, *connection; + zval *unique; + zend_class_entry *ce0; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_autoIncrement", 3100381058UL); + 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; + } + } + + 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_Db_Column, isNumeric){ - - - RETURN_MEMBER_QUICK(this_ptr, "_isNumeric", 2501917651UL); -} +static PHP_METHOD(Phalcon_Mvc_Collection, count){ -static PHP_METHOD(Phalcon_Db_Column, isFirst){ + zval *parameters = NULL, *class_name, *collection, *connection; + zend_class_entry *ce0; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_first", 2318852460UL); + 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; + } + } + + 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_Db_Column, getAfterPosition){ - - - RETURN_MEMBER_QUICK(this_ptr, "_after", 2119674294UL); -} +static PHP_METHOD(Phalcon_Mvc_Collection, aggregate){ -static PHP_METHOD(Phalcon_Db_Column, getBindType){ + zval *parameters, *class_name, *model, *connection; + zval *source, *collection; + zend_class_entry *ce0; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_bindType", 926651555UL); + 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; + } + } + + 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_Db_Column, __set_state){ +static PHP_METHOD(Phalcon_Mvc_Collection, summatory){ - zval *data, *definition, *column_name, *column_type; - zval *not_null, *primary, *size, *dunsigned, *after; - zval *is_numeric, *first, *bind_type; + 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, 0, &data); + phalcon_fetch_params(1, 1, 2, &field, &conditions, &finalize); - if (Z_TYPE_P(data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column state must be an array"); + 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(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"); + 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_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(collection); + phalcon_call_method_p1_key(collection, connection, "selectcollection", source, 3563037297UL); - 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(keys); + array_init(keys); - 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); - } + PHALCON_INIT_VAR(empty_array); + array_init(empty_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(initial); + array_init_size(initial, 1); + phalcon_array_update_quick_string(&initial, SS("summatory"), 2358676118UL, &empty_array, PH_COPY | PH_SEPARATE); - 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(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_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(retval); + phalcon_array_fetch_quick_string(&retval, group, SS("retval"), 1060973715UL, PH_NOISY); + if (phalcon_array_isset_long(retval, 0)) { - 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(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); + } - 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); - } + RETURN_CCTOR(first_retval); + } - 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); + RETURN_CCTOR(retval); } - object_init_ex(return_value, phalcon_db_column_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", column_name, definition, 1107214344UL); - - RETURN_MM(); -} - - - - - -#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; -} - - - - - - - - - -#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; + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Reference, __construct){ +static PHP_METHOD(Phalcon_Mvc_Collection, delete){ - zval *reference_name, *definition, *referenced_table; - zval *columns, *referenced_columns, *schema; - zval *referenced_schema, *number_columns; - zval *number_referenced_columns; + 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(); - 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"); + 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; } - 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; + 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; + } } - 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"); + 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; } - 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); + 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); + } + } else { + PHALCON_CPY_WRT(mongo_id, id); + } } - 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(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; } - PHALCON_INIT_VAR(number_columns); - phalcon_fast_count(number_columns, columns TSRMLS_CC); + if (phalcon_array_isset_quick_string(status, SS("ok"), 193501407UL)) { - 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_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); + } + } + } else { + PHALCON_INIT_NVAR(success); + ZVAL_BOOL(success, 0); } - 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); + RETURN_NCTOR(success); } -static PHP_METHOD(Phalcon_Db_Reference, getReferencedSchema){ - - - RETURN_MEMBER_QUICK(this_ptr, "_referencedSchema", 106854792UL); -} +static PHP_METHOD(Phalcon_Mvc_Collection, toArray){ -static PHP_METHOD(Phalcon_Db_Reference, getColumns){ + zval *data, *reserved, *properties, *value = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_columns", 4004520869UL); + 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); + } + + RETURN_CTOR(data); } -static PHP_METHOD(Phalcon_Db_Reference, getReferencedTable){ - - - RETURN_MEMBER_QUICK(this_ptr, "_referencedTable", 39793215UL); -} +static PHP_METHOD(Phalcon_Mvc_Collection, serialize){ -static PHP_METHOD(Phalcon_Db_Reference, getReferencedColumns){ + zval *data; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_referencedColumns", 3024201272UL); + 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_Db_Reference, __set_state){ +static PHP_METHOD(Phalcon_Mvc_Collection, unserialize){ - zval *data, *constraint_name, *referenced_schema = NULL; - zval *referenced_table = NULL, *columns = NULL, *referenced_columns = NULL; - zval *definition; + 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 (!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 (Z_TYPE_P(data) == IS_STRING) { - 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); - } + PHALCON_INIT_VAR(attributes); + phalcon_unserialize(attributes, data TSRMLS_CC); + if (Z_TYPE_P(attributes) == IS_ARRAY) { - 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); - } + PHALCON_INIT_VAR(dependency_injector); + PHALCON_CALL_STATIC(dependency_injector, "phalcon\\di", "getdefault"); - 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); - } + 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_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); + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); - RETURN_MM(); + 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_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; } @@ -124191,1378 +47627,1222 @@ static PHP_METHOD(Phalcon_Db_Reference, __set_state){ -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_update_property_this_quick(this_ptr, SL("_value"), value, 2935317441UL TSRMLS_CC); - -} - -static PHP_METHOD(Phalcon_Db_RawValue, getValue){ +PHALCON_INIT_CLASS(Phalcon_Mvc_View){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc, View, mvc_view, "phalcon\\di\\injectable", phalcon_mvc_view_method_entry, 0); - RETURN_MEMBER_QUICK(this_ptr, "_value", 2935317441UL); -} + 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); -static PHP_METHOD(Phalcon_Db_RawValue, __toString){ + 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_MEMBER_QUICK(this_ptr, "_value", 2935317441UL); + return SUCCESS; } +static PHP_METHOD(Phalcon_Mvc_View, __construct){ + zval *options = NULL; + PHALCON_MM_GROW(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -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; + phalcon_fetch_params(1, 0, 1, &options); + + if (!options) { + PHALCON_INIT_VAR(options); + } + + if (Z_TYPE_P(options) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + } + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Profiler_Item, setSQLStatement){ +static PHP_METHOD(Phalcon_Mvc_View, setViewsDir){ - zval *sql_statement; + zval *views_dir; - phalcon_fetch_params(0, 1, 0, &sql_statement); + phalcon_fetch_params(0, 1, 0, &views_dir); - phalcon_update_property_this_quick(this_ptr, SL("_sqlStatement"), sql_statement, 18972457UL TSRMLS_CC); + 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(); } -static PHP_METHOD(Phalcon_Db_Profiler_Item, getSQLStatement){ +static PHP_METHOD(Phalcon_Mvc_View, getViewsDir){ - RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); + RETURN_MEMBER_QUICK(this_ptr, "_viewsDir", 3398309201UL); } -static PHP_METHOD(Phalcon_Db_Profiler_Item, setInitialTime){ +static PHP_METHOD(Phalcon_Mvc_View, setLayoutsDir){ - zval *initial_time; + zval *layouts_dir; - phalcon_fetch_params(0, 1, 0, &initial_time); - - phalcon_update_property_this_quick(this_ptr, SL("_initialTime"), initial_time, 3347691997UL TSRMLS_CC); + 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_Db_Profiler_Item, setFinalTime){ +static PHP_METHOD(Phalcon_Mvc_View, getLayoutsDir){ - 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); - + RETURN_MEMBER_QUICK(this_ptr, "_layoutsDir", 313056692UL); } -static PHP_METHOD(Phalcon_Db_Profiler_Item, getInitialTime){ +static PHP_METHOD(Phalcon_Mvc_View, setPartialsDir){ + zval *partials_dir; - RETURN_MEMBER_QUICK(this_ptr, "_initialTime", 3347691997UL); + phalcon_fetch_params(0, 1, 0, &partials_dir); + + phalcon_update_property_this_quick(this_ptr, SL("_partialsDir"), partials_dir, 2130168739UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Profiler_Item, getFinalTime){ +static PHP_METHOD(Phalcon_Mvc_View, getPartialsDir){ - RETURN_MEMBER_QUICK(this_ptr, "_finalTime", 2101629981UL); + RETURN_MEMBER_QUICK(this_ptr, "_partialsDir", 2130168739UL); } -static PHP_METHOD(Phalcon_Db_Profiler_Item, getTotalElapsedSeconds){ - - zval *final_time, *initial_time; +static PHP_METHOD(Phalcon_Mvc_View, setBasePath){ - PHALCON_MM_GROW(); + zval *base_path; - PHALCON_OBS_VAR(final_time); - phalcon_read_property_this_quick(&final_time, this_ptr, SL("_finalTime"), 2101629981UL, PH_NOISY_CC); + phalcon_fetch_params(0, 1, 0, &base_path); - 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(); + 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){ -#ifdef HAVE_CONFIG_H -#endif + zval *level, *disabled; + 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(); +} -PHALCON_INIT_CLASS(Phalcon_Db_ResultInterface){ +static PHP_METHOD(Phalcon_Mvc_View, setMainView){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ResultInterface, db_resultinterface, phalcon_db_resultinterface_method_entry); + zval *view_path; - return SUCCESS; + phalcon_fetch_params(0, 1, 0, &view_path); + + phalcon_update_property_this_quick(this_ptr, SL("_mainView"), view_path, 1829858724UL 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){ + 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){ + 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){ -#ifdef HAVE_CONFIG_H -#endif + phalcon_update_property_null(this_ptr, SL("_templatesBefore") TSRMLS_CC); + RETURN_THISW(); +} +static PHP_METHOD(Phalcon_Mvc_View, setTemplateAfter){ + zval *template_after, *array_template; + PHALCON_MM_GROW(); + 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_Mvc_View, cleanTemplateAfter){ -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); + phalcon_update_property_null(this_ptr, SL("_templatesAfter") TSRMLS_CC); + RETURN_THISW(); +} - zend_declare_property_string(phalcon_db_dialect_mysql_ce, SL("_escapeChar"), "`", ZEND_ACC_PROTECTED TSRMLS_CC); +static PHP_METHOD(Phalcon_Mvc_View, setParamToView){ - zend_class_implements(phalcon_db_dialect_mysql_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_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); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, getColumnDefinition){ +static PHP_METHOD(Phalcon_Mvc_View, setVars){ - zval *column, *size, *column_type, *column_sql = NULL; - zval *is_unsigned = NULL, *scale = NULL; + zval *params, *merge = NULL, *view_params, *merged_params = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &column); + phalcon_fetch_params(1, 1, 1, ¶ms, &merge); - 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 (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 1); } - 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); - PHALCON_CONCAT_SVS(column_sql, "INT(", size, ")"); - - 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); - } - - 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, "DECIMAL(", size, ",", scale, ")"); - - 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); - } - - break; - - case 4: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "DATETIME", 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(column_sql); - ZVAL_STRING(column_sql, "FLOAT", 1); - - 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_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); - } - - break; - - case 8: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TINYINT(1)", 1); - break; + 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)) { - default: - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized MySQL data type"); - return; + 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_CTOR(column_sql); + RETURN_THIS(); } -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; +static PHP_METHOD(Phalcon_Mvc_View, setVar){ - PHALCON_MM_GROW(); + zval *key, *value; - 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; - } - 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_VAR(name); - phalcon_call_method_key(name, column, "getname", 4286441094UL); - - PHALCON_INIT_VAR(column_definition); - phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); - PHALCON_SCONCAT_SVSV(sql, "`", name, "` ", column_definition); - - 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); - } - } + phalcon_fetch_params(0, 2, 0, &key, &value); - RETURN_CTOR(sql); + phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, modifyColumn){ +static PHP_METHOD(Phalcon_Mvc_View, getVar){ - zval *table_name, *schema_name, *column, *sql = NULL, *name; - zval *column_definition, *is_not_null; + zval *key, *params, *value; 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"); ->>>>>>> 1.2.2 - return; - } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); -<<<<<<< HEAD - 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(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, "`."); - } - - PHALCON_INIT_VAR(referenced_columns); - phalcon_call_method_key(referenced_columns, reference, "getreferencedcolumns", 301959449UL); - - 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, ")"); -======= - 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_VAR(name); - phalcon_call_method_key(name, column, "getname", 4286441094UL); - - PHALCON_INIT_VAR(column_definition); - phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); - PHALCON_SCONCAT_SVSV(sql, "`", name, "` ", column_definition); + phalcon_fetch_params(1, 1, 0, &key); - 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_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_CTOR(sql); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropColumn){ +static PHP_METHOD(Phalcon_Mvc_View, getParamsToView){ - zval *table_name, *schema_name, *column_name; - zval *sql = NULL; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_viewParams", 1685283331UL); +} - 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, "`"); ->>>>>>> 1.2.2 - - RETURN_CTOR(sql); +static PHP_METHOD(Phalcon_Mvc_View, getControllerName){ + + + RETURN_MEMBER_QUICK(this_ptr, "_controllerName", 3332183433UL); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropForeignKey){ +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 *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); + phalcon_update_property_null(this_ptr, SL("_content") TSRMLS_CC); + phalcon_ob_start(TSRMLS_C); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, _getTableOptions){ +static PHP_METHOD(Phalcon_Mvc_View, _loadTemplateEngines){ - 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 *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, &definition); + PHALCON_OBS_VAR(engines); + phalcon_read_property_this_quick(&engines, this_ptr, SL("_engines"), 1840711053UL, PH_NOISY_CC); - if (phalcon_array_isset_quick_string(definition, SS("options"), 2952422065UL)) { + if (PHALCON_IS_FALSE(engines)) { - PHALCON_INIT_VAR(table_options); - array_init(table_options); + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - PHALCON_OBS_VAR(options); - phalcon_array_fetch_quick_string(&options, definition, SS("options"), 2952422065UL, PH_NOISY); + PHALCON_INIT_NVAR(engines); + array_init(engines); - if (phalcon_array_isset_quick_string(options, SS("ENGINE"), 2119337627UL)) { + 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_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_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; } - } - - if (phalcon_array_isset_quick_string(options, SS("AUTO_INCREMENT"), 656925090UL)) { - 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_INIT_VAR(arguments); + array_init_size(arguments, 2); + phalcon_array_append(&arguments, this_ptr, PH_SEPARATE); + phalcon_array_append(&arguments, dependency_injector, PH_SEPARATE); - if (phalcon_array_isset_quick_string(options, SS("TABLE_COLLATION"), 1457306353UL)) { + phalcon_is_iterable(registered_engines, &ah0, &hp0, 0, 0); - 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); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_OBS_VAR(first_part); - phalcon_array_fetch_long(&first_part, collation_parts, 0, PH_NOISY); + PHALCON_GET_HKEY(extension, ah0, hp0); + PHALCON_GET_HVALUE(engine_service); - PHALCON_INIT_VAR(sql_charset); - PHALCON_CONCAT_SV(sql_charset, "DEFAULT CHARSET=", first_part); - phalcon_array_append(&table_options, sql_charset, PH_SEPARATE); + if (Z_TYPE_P(engine_service) == IS_OBJECT) { - PHALCON_INIT_VAR(sql_collate); - PHALCON_CONCAT_SV(sql_collate, "COLLATE=", table_collation); - phalcon_array_append(&table_options, sql_collate, 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); + } 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); } - } - 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); } + + 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_NULL(); + + RETURN_CCTOR(engines); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, createTable){ +static PHP_METHOD(Phalcon_Mvc_View, _engineRender){ - 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 *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, 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_fetch_params(1, 5, 0, &engines, &view_path, &silence, &must_clean, &cache); - PHALCON_INIT_VAR(temporary); - ZVAL_BOOL(temporary, 0); - if (phalcon_array_isset_quick_string(definition, SS("options"), 2952422065UL)) { + PHALCON_INIT_VAR(not_exists); + ZVAL_BOOL(not_exists, 1); - 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); - } - } + PHALCON_OBS_VAR(views_dir); + phalcon_read_property_this_quick(&views_dir, this_ptr, SL("_viewsDir"), 3398309201UL, PH_NOISY_CC); - 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_OBS_VAR(base_path); + phalcon_read_property_this_quick(&base_path, this_ptr, SL("_basePath"), 1477430348UL, PH_NOISY_CC); - PHALCON_INIT_VAR(create_lines); - array_init(create_lines); + PHALCON_INIT_VAR(views_dir_path); + PHALCON_CONCAT_VVV(views_dir_path, base_path, views_dir, view_path); - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); + if (Z_TYPE_P(cache) == IS_OBJECT) { - phalcon_is_iterable(columns, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(render_level); + phalcon_read_property_this_quick(&render_level, this_ptr, SL("_renderLevel"), 3194989084UL, PH_NOISY_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + 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_GET_HVALUE(column); + PHALCON_INIT_VAR(is_started); + phalcon_call_method_key(is_started, cache, "isstarted", 527759032UL); + if (PHALCON_IS_FALSE(is_started)) { - PHALCON_INIT_NVAR(column_name); - phalcon_call_method_key(column_name, column, "getname", 4286441094UL); + PHALCON_INIT_VAR(key); - PHALCON_INIT_NVAR(column_definition); - phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); + PHALCON_INIT_VAR(lifetime); - PHALCON_INIT_NVAR(column_line); - PHALCON_CONCAT_SVSV(column_line, "`", column_name, "` ", column_definition); + PHALCON_OBS_VAR(view_options); + phalcon_read_property_this_quick(&view_options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - 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); - } + if (Z_TYPE_P(view_options) == IS_ARRAY) { + if (phalcon_array_isset_quick_string(view_options, SS("cache"), 4125168857UL)) { - 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_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_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); - } + if (Z_TYPE_P(key) == IS_NULL) { + PHALCON_INIT_NVAR(key); + phalcon_md5(key, view_path); + } - phalcon_array_append(&create_lines, column_line, PH_SEPARATE); + 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(); + } + } - zend_hash_move_forward_ex(ah0, &hp0); + PHALCON_INIT_VAR(is_fresh); + phalcon_call_method_key(is_fresh, cache, "isfresh", 3981662073UL); + if (!zend_is_true(is_fresh)) { + RETURN_MM_NULL(); + } + } } - if (phalcon_array_isset_quick_string(definition, SS("indexes"), 1726269685UL)) { + PHALCON_OBS_VAR(view_params); + phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); - PHALCON_OBS_VAR(indexes); - phalcon_array_fetch_quick_string(&indexes, definition, SS("indexes"), 1726269685UL, PH_NOISY); + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - phalcon_is_iterable(indexes, &ah1, &hp1, 0, 0); + phalcon_is_iterable(engines, &ah0, &hp0, 0, 0); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_GET_HVALUE(index); + PHALCON_GET_HKEY(extension, ah0, hp0); + PHALCON_GET_HVALUE(engine); - PHALCON_INIT_NVAR(index_name); - phalcon_call_method_key(index_name, index, "getname", 4286441094UL); + PHALCON_INIT_NVAR(view_engine_path); + PHALCON_CONCAT_VV(view_engine_path, views_dir_path, extension); - PHALCON_INIT_NVAR(columns); - phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); + if (phalcon_file_exists(view_engine_path TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_NVAR(column_list); - phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_activeRenderPath"), view_engine_path, 1528023309UL TSRMLS_CC); - 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_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, view_params, must_clean, 1053215877UL); - phalcon_array_append(&create_lines, index_sql, PH_SEPARATE); + 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); + } - zend_hash_move_forward_ex(ah1, &hp1); + break; } + zend_hash_move_forward_ex(ah0, &hp0); } - if (phalcon_array_isset_quick_string(definition, SS("references"), 3245500135UL)) { + if (PHALCON_IS_TRUE(not_exists)) { - PHALCON_OBS_VAR(references); - phalcon_array_fetch_quick_string(&references, definition, SS("references"), 3245500135UL, PH_NOISY); + if (Z_TYPE_P(events_manager) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_activeRenderPath"), view_engine_path, 1528023309UL TSRMLS_CC); - phalcon_is_iterable(references, &ah2, &hp2, 0, 0); + 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; + } + } - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { -======= -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addIndex){ + PHALCON_MM_RESTORE(); +} - zval *table_name, *schema_name, *index, *sql = NULL, *columns; - zval *quoted_column_list, *name; +static PHP_METHOD(Phalcon_Mvc_View, registerEngines){ - PHALCON_MM_GROW(); + zval *engines; - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); + phalcon_fetch_params(0, 1, 0, &engines); - 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"); + 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 (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 "); - } - - 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(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("_registeredEngines"), engines, 3326968731UL TSRMLS_CC); - RETURN_CTOR(sql); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropIndex){ +static PHP_METHOD(Phalcon_Mvc_View, render){ - zval *table_name, *schema_name, *index_name; - zval *sql = NULL; + 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, 3, 0, &table_name, &schema_name, &index_name); + phalcon_fetch_params(1, 2, 1, &controller_name, &action_name, ¶ms); - 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 "); + if (!params) { + PHALCON_INIT_VAR(params); } - PHALCON_SCONCAT_SVS(sql, "`", index_name, "`"); - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addPrimaryKey){ - - zval *table_name, *schema_name, *index, *sql = NULL, *columns; - zval *column_list; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); + 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; + } - 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; + 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); } - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` ADD PRIMARY KEY "); + + 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_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD PRIMARY KEY "); + PHALCON_CPY_WRT(layout_name, controller_name); } - PHALCON_INIT_VAR(columns); - phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); - - PHALCON_INIT_VAR(column_list); - phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); - PHALCON_SCONCAT_SVS(sql, "(", column_list, ")"); - - RETURN_CTOR(sql); -} - -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); + PHALCON_INIT_VAR(engines); + phalcon_call_method_key(engines, this_ptr, "_loadtemplateengines", 4149337481UL); - if (zend_is_true(schema_name)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSVS(sql, "ALTER TABLE `", schema_name, "`.`", table_name, "` DROP PRIMARY KEY"); + 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_INIT_NVAR(sql); - PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` DROP PRIMARY KEY"); + 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); + } } - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addForeignKey){ - - 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, 3, 0, &table_name, &schema_name, &reference); + PHALCON_INIT_VAR(cache); - 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 "); + 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(columns); - phalcon_call_method_key(columns, reference, "getcolumns", 3064648998UL); + PHALCON_OBS_VAR(events_manager); + phalcon_read_property_this_quick(&events_manager, this_ptr, SL("_eventsManager"), 799100116UL, PH_NOISY_CC); - PHALCON_INIT_VAR(quoted_column_list); - phalcon_call_method_p1_key(quoted_column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); + phalcon_create_symbol_table(TSRMLS_C); - 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 (Z_TYPE_P(events_manager) == IS_OBJECT) { - 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(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_FALSE; + } } - PHALCON_INIT_VAR(referenced_columns); - phalcon_call_method_key(referenced_columns, reference, "getreferencedcolumns", 301959449UL); + 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(quoted_columns); - phalcon_call_method_p1_key(quoted_columns, this_ptr, "getcolumnlist", referenced_columns, 2735238095UL); + PHALCON_INIT_VAR(must_clean); + ZVAL_BOOL(must_clean, 1); - PHALCON_INIT_VAR(referenced_table); - phalcon_call_method_key(referenced_table, reference, "getreferencedtable", 735373536UL); - PHALCON_SCONCAT_SVSVS(sql, "`", referenced_table, "`(", quoted_columns, ")"); + PHALCON_INIT_VAR(silence); + ZVAL_BOOL(silence, 1); - RETURN_CTOR(sql); -} - -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); + PHALCON_OBS_VAR(disabled_levels); + phalcon_read_property_this_quick(&disabled_levels, this_ptr, SL("_disabledLevels"), 1575004551UL, PH_NOISY_CC); - 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, "`"); + 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)) { - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, _getTableOptions){ - - 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, 1, 0, &definition); + 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 (PHALCON_GE_LONG(render_level, 2)) { + if (!phalcon_array_isset_long(disabled_levels, 2)) { - if (phalcon_array_isset_quick_string(definition, SS("options"), 2952422065UL)) { + PHALCON_OBS_VAR(templates_before); + phalcon_read_property_this_quick(&templates_before, this_ptr, SL("_templatesBefore"), 3273177030UL, PH_NOISY_CC); - PHALCON_INIT_VAR(table_options); - array_init(table_options); + if (Z_TYPE_P(templates_before) == IS_ARRAY) { - PHALCON_OBS_VAR(options); - phalcon_array_fetch_quick_string(&options, definition, SS("options"), 2952422065UL, PH_NOISY); + ZVAL_BOOL(silence, 0); - if (phalcon_array_isset_quick_string(options, SS("ENGINE"), 2119337627UL)) { + phalcon_is_iterable(templates_before, &ah0, &hp0, 0, 0); - 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); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + 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_INIT_NVAR(silence); + ZVAL_BOOL(silence, 1); + } } } - if (phalcon_array_isset_quick_string(options, SS("AUTO_INCREMENT"), 656925090UL)) { - - 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); + 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); } } - if (phalcon_array_isset_quick_string(options, SS("TABLE_COLLATION"), 1457306353UL)) { + if (PHALCON_GE_LONG(render_level, 4)) { + if (!phalcon_array_isset_long(disabled_levels, 4)) { - 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_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_OBS_VAR(first_part); - phalcon_array_fetch_long(&first_part, collation_parts, 0, PH_NOISY); + PHALCON_INIT_NVAR(silence); + ZVAL_BOOL(silence, 0); - PHALCON_INIT_VAR(sql_charset); - PHALCON_CONCAT_SV(sql_charset, "DEFAULT CHARSET=", first_part); - phalcon_array_append(&table_options, sql_charset, PH_SEPARATE); + phalcon_is_iterable(templates_after, &ah1, &hp1, 0, 0); - PHALCON_INIT_VAR(sql_collate); - PHALCON_CONCAT_SV(sql_collate, "COLLATE=", table_collation); - phalcon_array_append(&table_options, sql_collate, PH_SEPARATE); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HVALUE(template_after); + + 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(ah1, &hp1); + } + + PHALCON_INIT_NVAR(silence); + ZVAL_BOOL(silence, 1); + } } } - 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); + 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); + } } } + + 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_Db_Dialect_Mysql, createTable){ +static PHP_METHOD(Phalcon_Mvc_View, pick){ - 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; + zval *render_view, *pick_view = NULL, *layout = NULL, *parts; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &definition); + phalcon_fetch_params(1, 1, 0, &render_view); - 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, "`"); + if (Z_TYPE_P(render_view) == IS_ARRAY) { + PHALCON_CPY_WRT(pick_view, render_view); } 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_INIT_VAR(layout); + if (phalcon_memnstr_str(render_view, SL("/"))) { + PHALCON_INIT_VAR(parts); + phalcon_fast_explode_str(parts, SL("/"), render_view); - 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); + PHALCON_OBS_NVAR(layout); + phalcon_array_fetch_long(&layout, parts, 0, 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_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); - 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); ->>>>>>> 1.2.2 - - PHALCON_GET_HVALUE(reference); - -<<<<<<< HEAD - 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_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); + 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); - PHALCON_INIT_NVAR(column_line); - PHALCON_CONCAT_SVSV(column_line, "`", column_name, "` ", column_definition); + if (!params) { + PHALCON_INIT_VAR(params); + } - 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); - } + if (Z_TYPE_P(params) == IS_ARRAY) { - 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_OBS_VAR(view_params); + phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_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); + 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); } - phalcon_array_append(&create_lines, column_line, PH_SEPARATE); ->>>>>>> 1.2.2 - - PHALCON_INIT_NVAR(column_list); - phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); + phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), new_params, 1685283331UL TSRMLS_CC); -<<<<<<< HEAD - PHALCON_INIT_NVAR(referenced_table); - phalcon_call_method_key(referenced_table, reference, "getreferencedtable", 735373536UL); + phalcon_create_symbol_table(TSRMLS_C); - 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(zfalse); + ZVAL_BOOL(zfalse, 0); - PHALCON_INIT_NVAR(constaint_sql); - PHALCON_CONCAT_SVSVS(constaint_sql, "CONSTRAINT `", name, "` FOREIGN KEY (", column_list, ")"); + PHALCON_OBS_VAR(partials_dir); + phalcon_read_property_this_quick(&partials_dir, this_ptr, SL("_partialsDir"), 2130168739UL, 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); + PHALCON_INIT_VAR(real_path); + PHALCON_CONCAT_VV(real_path, partials_dir, partial_path); - zend_hash_move_forward_ex(ah2, &hp2); - } + PHALCON_INIT_VAR(engines); + phalcon_call_method_key(engines, this_ptr, "_loadtemplateengines", 4149337481UL); - } + phalcon_call_method_p5_key(NULL, this_ptr, "_enginerender", engines, real_path, zfalse, zfalse, zfalse, 828860954UL); - 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); + if (Z_TYPE_P(params) == IS_ARRAY) { + phalcon_update_property_this_quick(this_ptr, SL("_viewParams"), view_params, 1685283331UL TSRMLS_CC); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropTable){ +static PHP_METHOD(Phalcon_Mvc_View, getRender){ - zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; + zval *controller_name, *action_name, *params = NULL; + zval *config_callback = NULL, *view, *status, *content; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); + phalcon_fetch_params(1, 2, 2, &controller_name, &action_name, ¶ms, &config_callback); - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if (!params) { + PHALCON_INIT_VAR(params); + } else { + PHALCON_SEPARATE_PARAM(params); } - 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 (!config_callback) { + PHALCON_INIT_VAR(config_callback); } - 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_INIT_VAR(view); + if (phalcon_clone(view, this_ptr TSRMLS_CC) == FAILURE) { + return; } - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, 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); + phalcon_call_method_key(NULL, view, "reset", 422548360UL); - 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 (Z_TYPE_P(params) == IS_ARRAY) { + phalcon_call_method_p1_key(NULL, view, "setvars", params, 321174573UL); } - 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, "`"); + 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(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); + phalcon_call_method_key(NULL, view, "start", 478839859UL); - RETURN_CTOR(sql); + phalcon_call_method_p2_key(NULL, view, "render", controller_name, action_name, 1053215877UL); + + 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_Db_Dialect_Mysql, dropView){ +static PHP_METHOD(Phalcon_Mvc_View, finish){ - 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); - - 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); + phalcon_ob_end_clean(TSRMLS_C); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableExists){ +static PHP_METHOD(Phalcon_Mvc_View, _createCache){ - zval *table_name, *schema_name = NULL; + zval *dependency_injector, *cache_service = NULL; + zval *view_options, *cache_options, *view_cache; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table_name, &schema_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_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "A dependency injector container is required to obtain the view cache services"); + return; + } - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + 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); + } + } + } } - 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_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_CONCAT_SVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`='", table_name, "'"); - RETURN_MM(); + RETURN_CCTOR(view_cache); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, viewExists){ +static PHP_METHOD(Phalcon_Mvc_View, isCaching){ - zval *view_name, *schema_name = NULL; + zval *zero, *cache_level; 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, "'"); + 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_Db_Dialect_Mysql, describeColumns){ +static PHP_METHOD(Phalcon_Mvc_View, getCache){ - zval *table, *schema = NULL; + zval *cache = NULL; PHALCON_MM_GROW(); - 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(); -======= - 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(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); } - 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) { + RETURN_CCTOR(cache); +} + +static PHP_METHOD(Phalcon_Mvc_View, cache){ + + 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, 0, 1, &options); - PHALCON_GET_HVALUE(reference); + if (!options) { + PHALCON_INIT_VAR(options); + ZVAL_BOOL(options, 1); + } - PHALCON_INIT_NVAR(name); - phalcon_call_method_key(name, reference, "getname", 4286441094UL); + if (Z_TYPE_P(options) == IS_ARRAY) { - PHALCON_INIT_NVAR(columns); - phalcon_call_method_key(columns, reference, "getcolumns", 3064648998UL); + 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_INIT_NVAR(column_list); - phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); + 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); + } - PHALCON_INIT_NVAR(referenced_table); - phalcon_call_method_key(referenced_table, reference, "getreferencedtable", 735373536UL); + phalcon_is_iterable(options, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(referenced_columns); - phalcon_call_method_key(referenced_columns, reference, "getreferencedcolumns", 301959449UL); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_NVAR(column_list); - phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", referenced_columns, 2735238095UL); + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - PHALCON_INIT_NVAR(constaint_sql); - PHALCON_CONCAT_SVSVS(constaint_sql, "CONSTRAINT `", name, "` FOREIGN KEY (", column_list, ")"); + phalcon_array_update_zval(&cache_options, key, &value, PH_COPY | PH_SEPARATE); - 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(ah0, &hp0); + } - zend_hash_move_forward_ex(ah2, &hp2); + 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); } ->>>>>>> 1.2.2 + 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_CONCAT_SVS(return_value, "DESCRIBE `", table, "`"); -<<<<<<< HEAD - RETURN_MM(); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, listTables){ - - zval *schema_name = NULL; +static PHP_METHOD(Phalcon_Mvc_View, setContent){ - PHALCON_MM_GROW(); + zval *content; - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(0, 1, 0, &content); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + 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); - if (zend_is_true(schema_name)) { - PHALCON_CONCAT_SVS(return_value, "SHOW TABLES FROM `", schema_name, "`"); - RETURN_MM(); - } - RETURN_MM_STRING("SHOW TABLES", 1); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, listViews){ +static PHP_METHOD(Phalcon_Mvc_View, getContent){ - zval *schema_name = NULL; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); +} - phalcon_fetch_params(1, 0, 1, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_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(); - } - RETURN_MM_STRING("SELECT `TABLE_NAME` AS view_name FROM `INFORMATION_SCHEMA`.`VIEWS` ORDER BY view_name", 1); +static PHP_METHOD(Phalcon_Mvc_View, getActiveRenderPath){ + + + RETURN_MEMBER_QUICK(this_ptr, "_activeRenderPath", 1528023309UL); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeIndexes){ +static PHP_METHOD(Phalcon_Mvc_View, disable){ - zval *table, *schema = NULL; - PHALCON_MM_GROW(); + phalcon_update_property_bool(this_ptr, SL("_disabled"), 1 TSRMLS_CC); + RETURN_THISW(); +} - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } - - if (zend_is_true(schema)) { - PHALCON_CONCAT_SVSVS(return_value, "SHOW INDEXES FROM `", schema, "`.`", table, "`"); - RETURN_MM(); - } - PHALCON_CONCAT_SVS(return_value, "SHOW INDEXES FROM `", table, "`"); - - RETURN_MM(); +static PHP_METHOD(Phalcon_Mvc_View, enable){ + + + phalcon_update_property_bool(this_ptr, SL("_disabled"), 0 TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeReferences){ +static PHP_METHOD(Phalcon_Mvc_View, reset){ - zval *table, *schema = NULL, *sql; + zval *znull; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } + 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_Mvc_View, __set){ + + zval *key, *value; + + phalcon_fetch_params(0, 2, 0, &key, &value); - 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, "\""); - } + phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); - RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableOptions){ +static PHP_METHOD(Phalcon_Mvc_View, __get){ - zval *table, *schema = NULL, *sql; + zval *key, *params, *value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } + phalcon_fetch_params(1, 1, 0, &key); - 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, "\""); + 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_CTOR(sql); + RETURN_MM_NULL(); +} + + + + + +#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; } @@ -125574,588 +48854,512 @@ static PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableOptions){ +PHALCON_INIT_CLASS(Phalcon_Mvc_RouterInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, RouterInterface, mvc_routerinterface, phalcon_mvc_routerinterface_method_entry); + + return SUCCESS; +} + + + + -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); + + + + + + + + + + + + + + + + + +#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; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, getColumnDefinition){ - zval *column, *size, *column_type, *column_sql = NULL; - zval *scale = NULL; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &column); + + + + + + + + + + + +#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(column) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column definition must be an object compatible with Phalcon\\Db\\ColumnInterface"); + 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); - 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; - - 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; +} + +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); - RETURN_CTOR(column_sql); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addColumn){ -======= - 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_Mvc_Collection_Manager, getEventsManager){ + + + RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropTable){ +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, setCustomEventsManager){ - zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; + zval *model, *events_manager, *class_name; 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); - } + phalcon_fetch_params(1, 2, 0, &model, &events_manager); - 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_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); - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, createView){ +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getCustomEventsManager){ - zval *view_name, *definition, *schema_name, *view_sql; - zval *view = NULL, *sql; + zval *model, *custom_events_manager, *class_name; + zval *events_manager; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); + phalcon_fetch_params(1, 1, 0, &model); - 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(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_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(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); + } } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); - - RETURN_CTOR(sql); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropView){ +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, initialize){ - zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; - zval *sql = NULL; ->>>>>>> 1.2.2 + zval *model, *class_name, *initialized, *events_manager; + zval *event_name; - zval *table_name, *schema_name, *column; + PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); + phalcon_fetch_params(1, 1, 0, &model); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, modifyColumn){ -======= - phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); + PHALCON_INIT_VAR(class_name); + phalcon_get_class(class_name, model, 1 TSRMLS_CC); - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); - } + PHALCON_OBS_VAR(initialized); + phalcon_read_property_this_quick(&initialized, this_ptr, SL("_initialized"), 3373198522UL, PH_NOISY_CC); - 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); + 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); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableExists){ +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, isInitialized){ - zval *table_name, *schema_name = NULL; ->>>>>>> 1.2.2 + zval *model_name, *initialized, *lowercased; + zval *is_intitialized = NULL; + zval *r0 = NULL; - zval *table_name, *schema_name, *column; + PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); + phalcon_fetch_params(1, 1, 0, &model_name); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + 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_Db_Dialect_Oracle, dropColumn){ +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getLastInitialized){ - 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; + RETURN_MEMBER_QUICK(this_ptr, "_lastInitialized", 1491101038UL); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addIndex){ +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, setConnectionService){ - zval *table_name, *schema_name, *index; -======= - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + zval *model, *connection_service, *entity_name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &connection_service); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (Z_TYPE_P(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A valid collection instance is required"); + return; } - 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, "'"); + 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); - RETURN_MM(); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, viewExists){ +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, useImplicitObjectIds){ - zval *view_name, *schema_name = NULL; ->>>>>>> 1.2.2 + zval *model, *use_implicit_object_ids, *entity_name; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &model, &use_implicit_object_ids); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + 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_Db_Dialect_Oracle, dropIndex){ +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, isUsingImplicitObjectIds){ - zval *table_name, *schema_name, *index_name; + zval *model, *entity_name, *implicit_objects_ids; + zval *implicit; -<<<<<<< HEAD - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} + PHALCON_MM_GROW(); -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addPrimaryKey){ -======= - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + phalcon_fetch_params(1, 1, 0, &model); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (Z_TYPE_P(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A valid collection instance is required"); + return; } - 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_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); } - PHALCON_CONCAT_SVS(return_value, "SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE `TABLE_NAME`='", view_name, "'"); - RETURN_MM(); + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeColumns){ +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, getConnection){ - zval *table, *schema = NULL; ->>>>>>> 1.2.2 + zval *model, *service = NULL, *connection_services; + zval *entity_name, *dependency_injector, *connection; - zval *table_name, *schema_name, *index; + PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + phalcon_fetch_params(1, 1, 0, &model); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropPrimaryKey){ -======= - phalcon_fetch_params(1, 1, 1, &table, &schema); + if (Z_TYPE_P(model) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "A valid collection instance is required"); + return; + } - if (!schema) { - PHALCON_INIT_VAR(schema); + 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); + } } - if (zend_is_true(schema)) { - PHALCON_CONCAT_SVSVS(return_value, "DESCRIBE `", schema, "`.`", table, "`"); - 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_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "A dependency injector container is required to obtain the services related to the ORM"); + return; } - PHALCON_CONCAT_SVS(return_value, "DESCRIBE `", table, "`"); - RETURN_MM(); + 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_Db_Dialect_Mysql, listTables){ +static PHP_METHOD(Phalcon_Mvc_Collection_Manager, notifyEvent){ - zval *schema_name = NULL; ->>>>>>> 1.2.2 + zval *event_name, *model, *status = NULL, *events_manager; + zval *fire_event_name = NULL, *custom_events_manager; + zval *entity_name; - zval *table_name, *schema_name; + PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(0, 2, 0, &table_name, &schema_name); + phalcon_fetch_params(1, 2, 0, &event_name, &model); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addForeignKey){ -======= - phalcon_fetch_params(1, 0, 1, &schema_name); + PHALCON_INIT_VAR(status); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + 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); + } } - if (zend_is_true(schema_name)) { - PHALCON_CONCAT_SVS(return_value, "SHOW TABLES FROM `", schema_name, "`"); - RETURN_MM(); + 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_MM_STRING("SHOW TABLES", 1); + + RETURN_CCTOR(status); } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, listViews){ - zval *schema_name = NULL; ->>>>>>> 1.2.2 - zval *table_name, *schema_name, *reference; -<<<<<<< HEAD - 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){ -======= - phalcon_fetch_params(1, 0, 1, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_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(); - } - RETURN_MM_STRING("SELECT `TABLE_NAME` AS view_name FROM `INFORMATION_SCHEMA`.`VIEWS` ORDER BY view_name", 1); -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeIndexes){ - zval *table, *schema = NULL; ->>>>>>> 1.2.2 - zval *table_name, *schema_name, *reference_name; -<<<<<<< HEAD - 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_Mvc_Collection_Document){ - phalcon_fetch_params(1, 1, 0, &definition); - - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - RETURN_CTOR(empty_array); + 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_Db_Dialect_Oracle, createTable){ -======= - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } +static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetExists){ + + zval *index; + + phalcon_fetch_params(0, 1, 0, &index); - if (zend_is_true(schema)) { - PHALCON_CONCAT_SVSVS(return_value, "SHOW INDEXES FROM `", schema, "`.`", table, "`"); - RETURN_MM(); + if (phalcon_isset_property_zval(this_ptr, index TSRMLS_CC)) { + RETURN_TRUE; } - PHALCON_CONCAT_SVS(return_value, "SHOW INDEXES FROM `", table, "`"); - - RETURN_MM(); + RETURN_FALSE; } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeReferences){ +static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetGet){ - zval *table, *schema = NULL, *sql; + zval *index, *value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } + phalcon_fetch_params(1, 1, 0, &index); - 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, "\""); + 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); } - - RETURN_CTOR(sql); + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_collection_exception_ce, "The index does not exist in the row"); + return; } -static PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableOptions){ - - zval *table, *schema = NULL, *sql; +static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetSet){ - PHALCON_MM_GROW(); + zval *index, *value; - phalcon_fetch_params(1, 1, 1, &table, &schema); - - if (!schema) { - PHALCON_INIT_VAR(schema); - } + phalcon_fetch_params(0, 2, 0, &index, &value); - 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, "\""); - } + phalcon_update_property_zval_zval(this_ptr, index, value TSRMLS_CC); - RETURN_CTOR(sql); } ->>>>>>> 1.2.2 +static PHP_METHOD(Phalcon_Mvc_Collection_Document, offsetUnset){ - zval *table_name, *schema_name, *definition; + zval *offset; -<<<<<<< HEAD - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &definition); + phalcon_fetch_params(0, 1, 0, &offset); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + PHALCON_THROW_EXCEPTION_STRW(phalcon_mvc_collection_exception_ce, "The index does not exist in the row"); return; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropTable){ +static PHP_METHOD(Phalcon_Mvc_Collection_Document, readAttribute){ - zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; + zval *attribute, *attribute_value; 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); - } + phalcon_fetch_params(1, 1, 0, &attribute); - 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_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_CTOR(sql); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, createView){ - - zval *view_name, *definition, *schema_name, *view_sql; - zval *view = NULL, *sql; +static PHP_METHOD(Phalcon_Mvc_Collection_Document, writeAttribute){ - PHALCON_MM_GROW(); + zval *attribute, *value; - 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_fetch_params(0, 2, 0, &attribute, &value); - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); + phalcon_update_property_zval_zval(this_ptr, attribute, value TSRMLS_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); - - 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_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_CTOR(sql); + +#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; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableExists){ - zval *table_name, *schema_name = NULL, *sql = NULL; -======= + #ifdef HAVE_CONFIG_H @@ -126167,1919 +49371,1923 @@ static PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableExists){ -PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Oracle){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Router){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Oracle, db_dialect_oracle, "phalcon\\db\\dialect", phalcon_db_dialect_oracle_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Mvc, Router, mvc_router, phalcon_mvc_router_method_entry, 0); - zend_declare_property_string(phalcon_db_dialect_oracle_ce, SL("_escapeChar"), "", 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_class_implements(phalcon_db_dialect_oracle_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); + 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_Db_Dialect_Oracle, getColumnDefinition){ +static PHP_METHOD(Phalcon_Mvc_Router, __construct){ - zval *column, *size, *column_type, *column_sql = NULL; - zval *scale = NULL; + zval *default_routes = NULL, *routes, *paths = NULL, *action_pattern; + zval *route = NULL, *params_pattern, *params; 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)) { + phalcon_update_property_empty_array(phalcon_mvc_router_ce, this_ptr, SL("_defaultParams") TSRMLS_CC); - case 0: - PHALCON_INIT_VAR(column_sql); - ZVAL_STRING(column_sql, "INTEGER", 1); - break; + phalcon_fetch_params(1, 0, 1, &default_routes); - case 1: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "DATE", 1); - break; + if (!default_routes) { + PHALCON_INIT_VAR(default_routes); + ZVAL_BOOL(default_routes, 1); + } - case 2: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "VARCHAR2(", size, ")"); - break; + 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); - case 3: - PHALCON_INIT_VAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + PHALCON_INIT_VAR(action_pattern); + ZVAL_STRING(action_pattern, "#^/([a-zA-Z0-9\\_\\-]+)[/]{0,1}$#", 1); - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVSVS(column_sql, "NUMBER(", size, ",", scale, ")"); - break; + 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); - case 4: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TIMESTAMP", 1); - break; + phalcon_array_append(&routes, route, PH_SEPARATE); - case 5: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "CHAR(", size, ")"); - break; + 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); - case 6: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TEXT", 1); - break; + PHALCON_INIT_VAR(params_pattern); + ZVAL_STRING(params_pattern, "#^/([a-zA-Z0-9\\_\\-]+)/([a-zA-Z0-9\\.\\_]+)(/.*)*$#", 1); - case 7: - PHALCON_INIT_NVAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + 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_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVSVS(column_sql, "FLOAT(", size, ",", scale, ")"); - break; + phalcon_array_append(&routes, route, PH_SEPARATE); + } - case 8: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TINYINT(1)", 1); - break; + 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); - default: - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized Oracle data type"); - return; + 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); - RETURN_CTOR(column_sql); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addColumn){ ->>>>>>> 1.2.2 +static PHP_METHOD(Phalcon_Mvc_Router, getDI){ - zval *table_name, *schema_name, *column; -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + 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 (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + if (!zend_is_true(uri_source)) { + phalcon_get_global(&_GET, SS("_GET") TSRMLS_CC); + if (phalcon_array_isset_quick_string(_GET, SS("_url"), 251147063UL)) { - 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, "'"); + 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_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, "'"); + 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_CTOR(sql); + RETURN_MM_STRING("/", 1); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, viewExists){ +static PHP_METHOD(Phalcon_Mvc_Router, setUriSource){ - zval *view_name, *schema_name = NULL, *sql = NULL; -======= - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); + zval *uri_source; + + phalcon_fetch_params(0, 1, 0, &uri_source); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + phalcon_update_property_this_quick(this_ptr, SL("_uriSource"), uri_source, 144947845UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, modifyColumn){ +static PHP_METHOD(Phalcon_Mvc_Router, removeExtraSlashes){ - zval *table_name, *schema_name, *column; + zval *remove; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); + phalcon_fetch_params(0, 1, 0, &remove); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + phalcon_update_property_this_quick(this_ptr, SL("_removeExtraSlashes"), remove, 1065444329UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropColumn){ +static PHP_METHOD(Phalcon_Mvc_Router, setDefaultNamespace){ - zval *table_name, *schema_name, *column_name; + zval *namespace_name; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column_name); + phalcon_fetch_params(0, 1, 0, &namespace_name); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + phalcon_update_property_this_quick(this_ptr, SL("_defaultNamespace"), namespace_name, 761145590UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addIndex){ +static PHP_METHOD(Phalcon_Mvc_Router, setDefaultModule){ - zval *table_name, *schema_name, *index; + zval *module_name; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + phalcon_fetch_params(0, 1, 0, &module_name); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + phalcon_update_property_this_quick(this_ptr, SL("_defaultModule"), module_name, 3959488399UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropIndex){ +static PHP_METHOD(Phalcon_Mvc_Router, setDefaultController){ - zval *table_name, *schema_name, *index_name; + zval *controller_name; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index_name); + phalcon_fetch_params(0, 1, 0, &controller_name); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + phalcon_update_property_this_quick(this_ptr, SL("_defaultController"), controller_name, 1418722861UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addPrimaryKey){ +static PHP_METHOD(Phalcon_Mvc_Router, setDefaultAction){ - zval *table_name, *schema_name, *index; + zval *action_name; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + phalcon_fetch_params(0, 1, 0, &action_name); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + phalcon_update_property_this_quick(this_ptr, SL("_defaultAction"), action_name, 895696999UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropPrimaryKey){ +static PHP_METHOD(Phalcon_Mvc_Router, setDefaults){ - zval *table_name, *schema_name; ->>>>>>> 1.2.2 + zval *defaults, *namespace_name, *module_name; + zval *controller_name, *action_name, *params; - phalcon_fetch_params(0, 2, 0, &table_name, &schema_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} + PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + phalcon_fetch_params(1, 1, 0, &defaults); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (Z_TYPE_P(defaults) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_router_exception_ce, "Defaults must be an array"); + return; } - 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, "'"); + 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); } - RETURN_CTOR(sql); + 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_Db_Dialect_Oracle, describeColumns){ +static PHP_METHOD(Phalcon_Mvc_Router, handle){ - zval *table, *schema = NULL, *sql = NULL; + 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, 1, &table, &schema); + 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; + } + } + + 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); + } + + 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; + } + } + + 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); + } + } + + 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); + } + + 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); + } + + 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); + } - if (!schema) { - PHALCON_INIT_VAR(schema); - } + 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 (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"); - } + if (phalcon_array_isset_quick_string(parts, SS("controller"), 2892024105UL)) { - 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_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); + } - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + 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 (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); - } + if (phalcon_array_isset_quick_string(parts, SS("action"), 502132067UL)) { - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, listViews){ - - zval *schema_name = NULL, *sql = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &schema_name); + 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); + } - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + 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 (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); - } + if (phalcon_array_isset_quick_string(parts, SS("params"), 2613350281UL)) { - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeIndexes){ - - zval *table, *schema = NULL, *sql = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table, &schema); + PHALCON_OBS_VAR(params_str); + phalcon_array_fetch_quick_string(¶ms_str, parts, SS("params"), 2613350281UL, PH_NOISY); - if (!schema) { - PHALCON_INIT_VAR(schema); - } + 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); - 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, "'"); -======= -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_INIT_NVAR(params); + phalcon_fast_explode(params, slash, str_params); + } - 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_array_unset_string(&parts, SS("params"), PH_SEPARATE); + } - 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); + 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_INIT_VAR(empty_array); - array_init(empty_array); - RETURN_CTOR(empty_array); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, createTable){ - - zval *table_name, *schema_name, *definition; - - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &definition); + 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_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropTable){ - - 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); + 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); - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); - } + 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); - 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); ->>>>>>> 1.2.2 + 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); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeReferences){ +static PHP_METHOD(Phalcon_Mvc_Router, add){ - zval *table, *schema = NULL, *sql; + zval *pattern, *paths = NULL, *http_methods = NULL, *route; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (!paths) { + PHALCON_INIT_VAR(paths); } - 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, "'"); + if (!http_methods) { + PHALCON_INIT_VAR(http_methods); } - RETURN_CTOR(sql); + 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_Db_Dialect_Oracle, tableOptions){ +static PHP_METHOD(Phalcon_Mvc_Router, addGet){ - zval *table, *schema = NULL; + zval *pattern, *paths = NULL, *method; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &schema); + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (!paths) { + PHALCON_INIT_VAR(paths); } - RETURN_MM_EMPTY_STRING(); + 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_Db_Dialect_Oracle, getSqlTable){ +static PHP_METHOD(Phalcon_Mvc_Router, addPost){ - zval *table, *escape_char = NULL, *table_name, *sql_table = NULL; - zval *schema_name, *sql_schema = NULL, *alias_name; - zval *sql_table_alias = NULL; + zval *pattern, *paths = NULL, *method; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table, &escape_char); + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - if (!escape_char) { - PHALCON_INIT_VAR(escape_char); - } else { - PHALCON_SEPARATE_PARAM(escape_char); + if (!paths) { + PHALCON_INIT_VAR(paths); } - 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); -======= -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, createView){ + 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(); +} - zval *view_name, *definition, *schema_name, *view_sql; - zval *view = NULL, *sql; +static PHP_METHOD(Phalcon_Mvc_Router, addPut){ + + zval *pattern, *paths = NULL, *method; 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, &pattern, &paths); - 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 (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); - - RETURN_CTOR(sql); + 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_Db_Dialect_Oracle, dropView){ +static PHP_METHOD(Phalcon_Mvc_Router, addPatch){ - zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; - zval *sql = NULL; + zval *pattern, *paths = NULL, *method; 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); ->>>>>>> 1.2.2 - } - if (Z_TYPE_P(table) == IS_ARRAY) { - -<<<<<<< HEAD - 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); - } - } else { - 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); - } + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - 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); + if (!paths) { + PHALCON_INIT_VAR(paths); } - RETURN_CCTOR(table); + 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_Db_Dialect_Oracle, limit){ +static PHP_METHOD(Phalcon_Mvc_Router, addDelete){ - zval *sql_query, *number, *limit, *sql_limit; + zval *pattern, *paths = NULL, *method; 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)) { - - 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); + phalcon_fetch_params(1, 1, 1, &pattern, &paths); + + if (!paths) { + PHALCON_INIT_VAR(paths); } - - RETURN_CCTOR(sql_query); + + 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_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(); - } - - 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); - - if (!phalcon_is_iterable_ex(columns, &ah0, &hp0, 0, 0)) { - return; - } - - 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_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, " ", 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); - } - - 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); - } +static PHP_METHOD(Phalcon_Mvc_Router, addOptions){ - PHALCON_OBS_VAR(tables); - phalcon_array_fetch_quick_string(&tables, definition, SS("tables"), 3465666720UL, PH_NOISY); - if (Z_TYPE_P(tables) == IS_ARRAY) { + zval *pattern, *paths = NULL, *method; - PHALCON_INIT_VAR(selected_tables); - array_init(selected_tables); -======= - 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_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &pattern, &paths); + + if (!paths) { + PHALCON_INIT_VAR(paths); } - RETURN_CTOR(sql); + 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_Db_Dialect_Oracle, tableExists){ +static PHP_METHOD(Phalcon_Mvc_Router, addHead){ - zval *table_name, *schema_name = NULL, *sql = NULL; + zval *pattern, *paths = NULL, *method; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - 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 (!paths) { + PHALCON_INIT_VAR(paths); } - RETURN_CTOR(sql); + 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_Db_Dialect_Oracle, viewExists){ +static PHP_METHOD(Phalcon_Mvc_Router, mount){ - zval *view_name, *schema_name = NULL, *sql = NULL; + 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, 1, &view_name, &schema_name); + phalcon_fetch_params(1, 1, 0, &group); - if (!schema_name) { - PHALCON_INIT_VAR(schema_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; } - 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, "'"); + 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); + } + + } + + 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); + } + + } + + 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_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_update_property_this_quick(this_ptr, SL("_routes"), group_routes, 2063827110UL TSRMLS_CC); } - RETURN_CTOR(sql); + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeColumns){ +static PHP_METHOD(Phalcon_Mvc_Router, notFound){ - zval *table, *schema = NULL, *sql = NULL; ->>>>>>> 1.2.2 + zval *paths; - if (!phalcon_is_iterable_ex(tables, &ah1, &hp1, 0, 0)) { + 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; } + } + phalcon_update_property_this_quick(this_ptr, SL("_notFoundPaths"), paths, 189519377UL TSRMLS_CC); + + RETURN_THISW(); +} -<<<<<<< HEAD - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { +static PHP_METHOD(Phalcon_Mvc_Router, clear){ - PHALCON_GET_FOREACH_VALUE(table); + zval *empty_routes; - 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_MM_GROW(); - zend_hash_move_forward_ex(ah1, &hp1); - } + 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(); +} - PHALCON_INIT_VAR(tables_sql); - phalcon_fast_join_str(tables_sql, SL(", "), selected_tables TSRMLS_CC); - } else { - PHALCON_CPY_WRT(tables_sql, tables); - } +static PHP_METHOD(Phalcon_Mvc_Router, getNamespaceName){ - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "SELECT ", columns_sql, " FROM ", tables_sql); - if (phalcon_array_isset_quick_string(definition, SS("joins"), 120974824UL)) { + RETURN_MEMBER_QUICK(this_ptr, "_namespace", 1403433009UL); +} - PHALCON_OBS_VAR(joins); - phalcon_array_fetch_quick_string(&joins, definition, SS("joins"), 120974824UL, PH_NOISY); +static PHP_METHOD(Phalcon_Mvc_Router, getModuleName){ - if (!phalcon_is_iterable_ex(joins, &ah2, &hp2, 0, 0)) { - return; - } - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + RETURN_MEMBER_QUICK(this_ptr, "_module", 4176304298UL); +} - PHALCON_GET_FOREACH_VALUE(join); +static PHP_METHOD(Phalcon_Mvc_Router, getControllerName){ - 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); + RETURN_MEMBER_QUICK(this_ptr, "_controller", 1139371208UL); +} - 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_Mvc_Router, getActionName){ - PHALCON_INIT_NVAR(sql_join); - PHALCON_CONCAT_SVSV(sql_join, " ", type, " JOIN ", sql_table); - if (phalcon_array_isset_quick_string(join, SS("conditions"), 1055696255UL)) { + RETURN_MEMBER_QUICK(this_ptr, "_action", 1112512898UL); +} - 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)) { +static PHP_METHOD(Phalcon_Mvc_Router, getParams){ - PHALCON_INIT_NVAR(join_expressions); - array_init(join_expressions); - if (!phalcon_is_iterable_ex(join_conditions_array, &ah3, &hp3, 0, 0)) { - return; - } + RETURN_MEMBER_QUICK(this_ptr, "_params", 3223731112UL); +} - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { +static PHP_METHOD(Phalcon_Mvc_Router, getMatchedRoute){ - 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); + RETURN_MEMBER_QUICK(this_ptr, "_matchedRoute", 3232330313UL); +} - zend_hash_move_forward_ex(ah3, &hp3); - } +static PHP_METHOD(Phalcon_Mvc_Router, getMatches){ - 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); + RETURN_MEMBER_QUICK(this_ptr, "_matches", 83085737UL); +} - zend_hash_move_forward_ex(ah2, &hp2); - } +static PHP_METHOD(Phalcon_Mvc_Router, wasMatched){ - } -======= - 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 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"); - } - - RETURN_CTOR(sql); + + RETURN_MEMBER_QUICK(this_ptr, "_wasMatched", 2908823365UL); } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, listTables){ +static PHP_METHOD(Phalcon_Mvc_Router, getRoutes){ - zval *schema_name = NULL, *sql = NULL; ->>>>>>> 1.2.2 - if (phalcon_array_isset_quick_string(definition, SS("where"), 621293632UL)) { + RETURN_MEMBER_QUICK(this_ptr, "_routes", 2063827110UL); +} -<<<<<<< HEAD - 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); - } - } +static PHP_METHOD(Phalcon_Mvc_Router, getRouteById){ - if (phalcon_array_isset_quick_string(definition, SS("group"), 7349554UL)) { + zval *id, *routes, *route = NULL, *route_id = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - PHALCON_INIT_VAR(group_items); - array_init(group_items); -======= - phalcon_fetch_params(1, 0, 1, &schema_name); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &id); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + PHALCON_OBS_VAR(routes); + phalcon_read_property_this_quick(&routes, this_ptr, SL("_routes"), 2063827110UL, PH_NOISY_CC); - 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_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_CTOR(sql); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, listViews){ - - zval *schema_name = NULL, *sql = NULL; ->>>>>>> 1.2.2 - - PHALCON_OBS_VAR(group_fields); - phalcon_array_fetch_quick_string(&group_fields, definition, SS("group"), 7349554UL, PH_NOISY); +static PHP_METHOD(Phalcon_Mvc_Router, getRouteByName){ -<<<<<<< HEAD - if (!phalcon_is_iterable_ex(group_fields, &ah4, &hp4, 0, 0)) { - return; - } + zval *name, *routes, *route = NULL, *route_name = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { + PHALCON_MM_GROW(); - PHALCON_GET_FOREACH_VALUE(group_field); -======= - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(1, 1, 0, &name); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + PHALCON_OBS_VAR(routes); + phalcon_read_property_this_quick(&routes, this_ptr, SL("_routes"), 2063827110UL, 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_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); + } + + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CTOR(sql); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeIndexes){ - zval *table, *schema = NULL, *sql = NULL; ->>>>>>> 1.2.2 - 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); -<<<<<<< HEAD - zend_hash_move_forward_ex(ah4, &hp4); - } - PHALCON_INIT_VAR(group_sql); - phalcon_fast_join_str(group_sql, SL(", "), group_items TSRMLS_CC); +#ifdef HAVE_CONFIG_H +#endif - PHALCON_INIT_VAR(group_clause); - PHALCON_CONCAT_SV(group_clause, " GROUP BY ", group_sql); - phalcon_concat_self(&sql, group_clause TSRMLS_CC); -======= - 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); + + +PHALCON_INIT_CLASS(Phalcon_Mvc_ModelInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ModelInterface, mvc_modelinterface, phalcon_mvc_modelinterface_method_entry); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeReferences){ - zval *table, *schema = NULL, *sql; ->>>>>>> 1.2.2 - 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); -<<<<<<< HEAD - 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_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); -} -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableOptions){ - zval *table, *schema = NULL; ->>>>>>> 1.2.2 - PHALCON_INIT_VAR(order_items); - array_init(order_items); -<<<<<<< HEAD - 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_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; ->>>>>>> 1.2.2 - PHALCON_OBS_NVAR(order_expression); - phalcon_array_fetch_long(&order_expression, order_item, 0, PH_NOISY); -<<<<<<< HEAD - 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_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); - } - } else { - 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); -} -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, limit){ - zval *sql_query, *number, *limit, *sql_limit; ->>>>>>> 1.2.2 - phalcon_array_append(&order_items, order_sql_item_type, PH_SEPARATE); -<<<<<<< HEAD - 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 PHP_METHOD(Phalcon_Db_Dialect_Oracle, supportsSavepoints){ -======= - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &sql_query, &number) == FAILURE) { - RETURN_MM_NULL(); - } - if (phalcon_is_numeric(number)) { - PHALCON_INIT_VAR(limit); - ZVAL_LONG(limit, phalcon_get_intval(number)); +#ifdef HAVE_CONFIG_H +#endif + + + + - PHALCON_INIT_VAR(sql_limit); - PHALCON_CONCAT_VSV(sql_limit, sql_query, " LIMIT ", limit); - RETURN_CTOR(sql_limit); - } - RETURN_CCTOR(sql_query); +PHALCON_INIT_CLASS(Phalcon_Mvc_Application_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Application, Exception, mvc_application_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } -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(); - } - 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; - } +#ifdef HAVE_CONFIG_H +#endif - 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_CLASS(Phalcon_Mvc_DispatcherInterface){ - PHALCON_INIT_VAR(selected_columns); - array_init(selected_columns); + PHALCON_REGISTER_INTERFACE_EX(Phalcon\\Mvc, DispatcherInterface, mvc_dispatcherinterface, "phalcon\\dispatcherinterface", phalcon_mvc_dispatcherinterface_method_entry); - if (!phalcon_is_iterable_ex(columns, &ah0, &hp0, 0, 0)) { - return; - } + return SUCCESS; +} - 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_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, " ", 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); - } - 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) { +#ifdef HAVE_CONFIG_H +#endif - PHALCON_INIT_VAR(selected_tables); - array_init(selected_tables); - if (!phalcon_is_iterable_ex(tables, &ah1, &hp1, 0, 0)) { - return; - } - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { ->>>>>>> 1.2.2 +PHALCON_INIT_CLASS(Phalcon_Mvc_ModuleDefinitionInterface){ - PHALCON_GET_FOREACH_VALUE(table); + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, ModuleDefinitionInterface, mvc_moduledefinitioninterface, phalcon_mvc_moduledefinitioninterface_method_entry); -<<<<<<< HEAD - RETURN_FALSE; + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, supportsReleaseSavepoints){ -======= - 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); - } ->>>>>>> 1.2.2 - PHALCON_INIT_VAR(tables_sql); - phalcon_fast_join_str(tables_sql, SL(", "), selected_tables TSRMLS_CC); - } else { - PHALCON_CPY_WRT(tables_sql, tables); - } -<<<<<<< HEAD - RETURN_FALSE; + + + +#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; } -======= - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "SELECT ", columns_sql, " FROM ", tables_sql); ->>>>>>> 1.2.2 - 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); - if (!phalcon_is_iterable_ex(joins, &ah2, &hp2, 0, 0)) { - return; - } - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { -<<<<<<< HEAD + + + + + + + + + + + + + + + + + + + + + #ifdef HAVE_CONFIG_H #endif -======= - PHALCON_GET_FOREACH_VALUE(join); ->>>>>>> 1.2.2 - - 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)) { -<<<<<<< HEAD -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); +PHALCON_INIT_CLASS(Phalcon_Mvc_View_Simple){ - zend_declare_property_string(phalcon_db_dialect_postgresql_ce, SL("_escapeChar"), "\"", ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View, Simple, mvc_view_simple, "phalcon\\di\\injectable", phalcon_mvc_view_simple_method_entry, 0); - zend_class_implements(phalcon_db_dialect_postgresql_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); + 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_Db_Dialect_Postgresql, getColumnDefinition){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, __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) { + phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + } + + 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_this_quick(this_ptr, SL("_viewsDir"), views_dir, 3398309201UL TSRMLS_CC); + +} + +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(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); + +} + +static PHP_METHOD(Phalcon_Mvc_View_Simple, _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); + + 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_CCTOR(engines); +} + +static PHP_METHOD(Phalcon_Mvc_View_Simple, _internalRender){ + + 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_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_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; + } + + 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_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Mvc_View_Simple, render){ - zval *column, *size, *column_type, *column_sql = NULL; - zval *scale; + 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(); - phalcon_fetch_params(1, 1, 0, &column); + phalcon_fetch_params(1, 1, 1, &path, ¶ms); - 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 (!params) { + PHALCON_INIT_VAR(params); } - PHALCON_INIT_VAR(size); - phalcon_call_method_key(size, column, "getsize", 4292672352UL); + PHALCON_INIT_VAR(cache); + phalcon_call_method_key(cache, this_ptr, "getcache", 3582760537UL); + if (Z_TYPE_P(cache) == IS_OBJECT) { - PHALCON_INIT_VAR(column_type); - phalcon_call_method_key(column_type, column, "gettype", 4294422375UL); + PHALCON_INIT_VAR(is_started); + phalcon_call_method_key(is_started, cache, "isstarted", 527759032UL); + if (PHALCON_IS_FALSE(is_started)) { - switch (phalcon_get_intval(column_type)) { + PHALCON_INIT_VAR(key); - case 0: - PHALCON_INIT_VAR(column_sql); - ZVAL_STRING(column_sql, "INT", 1); - break; + PHALCON_INIT_VAR(lifetime); - case 1: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "DATE", 1); - break; + PHALCON_OBS_VAR(cache_options); + phalcon_read_property_this_quick(&cache_options, this_ptr, SL("_cacheOptions"), 528255652UL, PH_NOISY_CC); - case 2: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "CHARACTER VARYING(", size, ")"); - break; + 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); + } + } - case 3: - PHALCON_INIT_VAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + if (Z_TYPE_P(key) == IS_NULL) { + PHALCON_INIT_NVAR(key); + phalcon_md5(key, path); + } - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVSVS(column_sql, "NUMERIC(", size, ",", scale, ")"); - break; + 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); + } + } + } - case 4: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TIMESTAMP", 1); - break; + phalcon_create_symbol_table(TSRMLS_C); - case 5: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "CHARACTER(", size, ")"); - break; + phalcon_ob_start(TSRMLS_C); - case 6: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TEXT", 1); - break; + PHALCON_OBS_VAR(view_params); + phalcon_read_property_this_quick(&view_params, this_ptr, SL("_viewParams"), 1685283331UL, PH_NOISY_CC); - case 7: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "FLOAT", 1); - break; + 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); + } - case 8: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "SMALLINT(1)", 1); - break; + phalcon_call_method_p2_key(NULL, this_ptr, "_internalrender", path, merged_params, 608460065UL); - default: - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized PostgreSQL data type"); - return; + 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); + } } - RETURN_CTOR(column_sql); -} - -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_ob_end_clean(TSRMLS_C); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + 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_Db_Dialect_Postgresql, modifyColumn){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, partial){ - zval *table_name, *schema_name, *column; + zval *partial_path, *params = NULL, *view_params, *merged_params = NULL; + zval *content; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &partial_path, ¶ms); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + if (!params) { + PHALCON_INIT_VAR(params); + } + + 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); + } + + 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_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_Db_Dialect_Postgresql, dropColumn){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, setCacheOptions){ - zval *table_name, *schema_name, *column_name; + zval *options; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column_name); + phalcon_fetch_params(0, 1, 0, &options); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + phalcon_update_property_this_quick(this_ptr, SL("_cacheOptions"), options, 528255652UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addIndex){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, getCacheOptions){ - 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; + RETURN_MEMBER_QUICK(this_ptr, "_cacheOptions", 528255652UL); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropIndex){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, _createCache){ - zval *table_name, *schema_name, *index_name; + zval *dependency_injector, *cache_service = NULL; + zval *cache_options, *view_cache; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index_name); + 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_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + PHALCON_INIT_VAR(cache_service); + ZVAL_STRING(cache_service, "viewCache", 1); + + 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(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_Db_Dialect_Postgresql, addPrimaryKey){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, getCache){ - zval *table_name, *schema_name, *index; + zval *cache = NULL; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + 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); + } + } - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + RETURN_CCTOR(cache); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropPrimaryKey){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, cache){ - zval *table_name, *schema_name; + zval *options = NULL; - phalcon_fetch_params(0, 2, 0, &table_name, &schema_name); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &options); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + if (!options) { + PHALCON_INIT_VAR(options); + ZVAL_BOOL(options, 1); + } + + 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); + } + } + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addForeignKey){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, setParamToView){ - zval *table_name, *schema_name, *reference; + zval *key, *value; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference); + phalcon_fetch_params(0, 2, 0, &key, &value); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropForeignKey){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, setVars){ - zval *table_name, *schema_name, *reference_name; + zval *params, *merge = NULL, *view_params, *merged_params = NULL; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference_name); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, ¶ms, &merge); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + if (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 1); + } + + 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_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_Db_Dialect_Postgresql, _getTableOptions){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, setVar){ - zval *definition; + zval *key, *value; - phalcon_fetch_params(0, 1, 0, &definition); + phalcon_fetch_params(0, 2, 0, &key, &value); - RETURN_EMPTY_ARRAY(); + phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, createTable){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, getVar){ - zval *table_name, *schema_name, *definition; + zval *key, *params, *value; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &definition); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &key); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - 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); + } + + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropTable){ +static PHP_METHOD(Phalcon_Mvc_View_Simple, getParamsToView){ - zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; -======= - PHALCON_INIT_NVAR(join_expressions); - array_init(join_expressions); - if (!phalcon_is_iterable_ex(join_conditions_array, &ah3, &hp3, 0, 0)) { - return; - } + RETURN_MEMBER_QUICK(this_ptr, "_viewParams", 1685283331UL); +} - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { +static PHP_METHOD(Phalcon_Mvc_View_Simple, setContent){ - PHALCON_GET_FOREACH_VALUE(join_condition); + zval *content; - 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); + phalcon_fetch_params(0, 1, 0, &content); + + 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); + + RETURN_THISW(); +} - zend_hash_move_forward_ex(ah3, &hp3); - } +static PHP_METHOD(Phalcon_Mvc_View_Simple, getContent){ - 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); + RETURN_MEMBER_QUICK(this_ptr, "_content", 4081318271UL); +} - zend_hash_move_forward_ex(ah2, &hp2); - } +static PHP_METHOD(Phalcon_Mvc_View_Simple, getActiveRenderPath){ - } - if (phalcon_array_isset_quick_string(definition, SS("where"), 621293632UL)) { + RETURN_MEMBER_QUICK(this_ptr, "_activeRenderPath", 1528023309UL); +} - 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); - } - } +static PHP_METHOD(Phalcon_Mvc_View_Simple, __set){ - if (phalcon_array_isset_quick_string(definition, SS("group"), 7349554UL)) { + zval *key, *value; - PHALCON_INIT_VAR(group_items); - array_init(group_items); + phalcon_fetch_params(0, 2, 0, &key, &value); + + phalcon_update_property_array(this_ptr, SL("_viewParams"), key, value TSRMLS_CC); + +} - PHALCON_OBS_VAR(group_fields); - phalcon_array_fetch_quick_string(&group_fields, definition, SS("group"), 7349554UL, PH_NOISY); +static PHP_METHOD(Phalcon_Mvc_View_Simple, __get){ - if (!phalcon_is_iterable_ex(group_fields, &ah4, &hp4, 0, 0)) { - return; - } + zval *key, *params, *value; - while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { + PHALCON_MM_GROW(); - PHALCON_GET_FOREACH_VALUE(group_field); + phalcon_fetch_params(1, 1, 0, &key); + + 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_NULL(); +} - 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); +#ifdef HAVE_CONFIG_H +#endif - 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_INIT_CLASS(Phalcon_Mvc_View_Engine){ - PHALCON_OBS_NVAR(order_expression); - phalcon_array_fetch_long(&order_expression, order_item, 0, PH_NOISY); + 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_INIT_NVAR(order_sql_item); - phalcon_call_method_p2_key(order_sql_item, this_ptr, "getsqlexpression", order_expression, escape_char, 3377787077UL); + zend_declare_property_null(phalcon_mvc_view_engine_ce, SL("_view"), ZEND_ACC_PROTECTED TSRMLS_CC); - 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); + return SUCCESS; +} - 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); - } +static PHP_METHOD(Phalcon_Mvc_View_Engine, __construct){ - phalcon_array_append(&order_items, order_sql_item_type, PH_SEPARATE); + zval *view, *dependency_injector = NULL; - zend_hash_move_forward_ex(ah5, &hp5); - } + PHALCON_MM_GROW(); - PHALCON_INIT_VAR(order_sql); - phalcon_fast_join_str(order_sql, SL(", "), order_items TSRMLS_CC); - PHALCON_SCONCAT_SV(sql, " ORDER BY ", order_sql); + phalcon_fetch_params(1, 1, 1, &view, &dependency_injector); + + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); } + + 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(); +} - if (phalcon_array_isset_quick_string(definition, SS("limit"), 192268420UL)) { +static PHP_METHOD(Phalcon_Mvc_View_Engine, getContent){ - PHALCON_OBS_VAR(limit_value); - phalcon_array_fetch_quick_string(&limit_value, definition, SS("limit"), 192268420UL, PH_NOISY); + zval *view; - if (Z_TYPE_P(limit_value) == IS_ARRAY) { + PHALCON_MM_GROW(); - PHALCON_OBS_VAR(number); - phalcon_array_fetch_quick_string(&number, limit_value, SS("number"), 807219790UL, PH_NOISY); + 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(); +} - 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); - } +static PHP_METHOD(Phalcon_Mvc_View_Engine, partial){ - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); ->>>>>>> 1.2.2 + zval *partial_path, *params = NULL, *view; - PHALCON_INIT_VAR(ini_range); - phalcon_add_function(ini_range, offset, one TSRMLS_CC); + PHALCON_MM_GROW(); -<<<<<<< HEAD - 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); - } + phalcon_fetch_params(1, 1, 1, &partial_path, ¶ms); - 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 (!params) { + PHALCON_INIT_VAR(params); } - RETURN_CTOR(sql); + 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_Db_Dialect_Postgresql, createView){ +static PHP_METHOD(Phalcon_Mvc_View_Engine, getView){ - zval *view_name, *definition, *schema_name, *view_sql; - zval *view = NULL, *sql; -======= - 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); + RETURN_MEMBER_QUICK(this_ptr, "_view", 3993744575UL); +} - } 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); +#ifdef HAVE_CONFIG_H +#endif - 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 PHP_METHOD(Phalcon_Db_Dialect_Oracle, supportsSavepoints){ +PHALCON_INIT_CLASS(Phalcon_Mvc_View_EngineInterface){ + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\View, EngineInterface, mvc_view_engineinterface, phalcon_mvc_view_engineinterface_method_entry); - RETURN_FALSE; + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Oracle, supportsReleaseSavepoints){ - RETURN_FALSE; -} ->>>>>>> 1.2.2 -<<<<<<< HEAD - 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); -} -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropView){ - zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; - zval *sql = NULL; +#ifdef HAVE_CONFIG_H +#endif - 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); - } - - 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); + + + + +PHALCON_INIT_CLASS(Phalcon_Mvc_View_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\View, Exception, mvc_view_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, tableExists){ - zval *table_name, *schema_name = NULL, *sql = NULL; -======= + + #ifdef HAVE_CONFIG_H #endif @@ -128090,6915 +51298,11219 @@ static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, tableExists){ -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); +PHALCON_INIT_CLASS(Phalcon_Mvc_View_Engine_Php){ - zend_declare_property_string(phalcon_db_dialect_postgresql_ce, SL("_escapeChar"), "\"", ZEND_ACC_PROTECTED TSRMLS_CC); + 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_db_dialect_postgresql_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); + zend_class_implements(phalcon_mvc_view_engine_php_ce TSRMLS_CC, 1, phalcon_mvc_view_engineinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, getColumnDefinition){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Php, render){ - zval *column, *size, *column_type, *column_sql = NULL; - zval *scale; + 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, 1, 0, &column); + phalcon_fetch_params(1, 2, 1, &path, ¶ms, &must_clean); - 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 (!must_clean) { + PHALCON_INIT_VAR(must_clean); + ZVAL_BOOL(must_clean, 0); } - 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; + if (PHALCON_IS_TRUE(must_clean)) { + phalcon_ob_clean(TSRMLS_C); + } - case 3: - PHALCON_INIT_VAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + if (Z_TYPE_P(params) == IS_ARRAY) { - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVSVS(column_sql, "NUMERIC(", size, ",", scale, ")"); - break; + phalcon_is_iterable(params, &ah0, &hp0, 0, 0); - case 4: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TIMESTAMP", 1); - break; + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - case 5: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "CHARACTER(", size, ")"); - break; + PHALCON_GET_HKEY(key, ah0, hp0); + PHALCON_GET_HVALUE(value); - case 6: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TEXT", 1); - break; + if (phalcon_set_symbol(key, value TSRMLS_CC) == FAILURE){ + return; + } - case 7: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "FLOAT", 1); - break; + zend_hash_move_forward_ex(ah0, &hp0); + } - 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; + 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); } - RETURN_CTOR(column_sql); + PHALCON_MM_RESTORE(); } -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_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; -} -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropColumn){ +#ifdef HAVE_CONFIG_H +#endif - 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_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; -} -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropIndex){ - zval *table_name, *schema_name, *index_name; +PHALCON_INIT_CLASS(Phalcon_Mvc_View_Engine_Volt_Compiler){ - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\View\\Engine\\Volt, Compiler, mvc_view_engine_volt_compiler, phalcon_mvc_view_engine_volt_compiler_method_entry, 0); -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addPrimaryKey){ + 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); - zval *table_name, *schema_name, *index; + zend_class_implements(phalcon_mvc_view_engine_volt_compiler_ce TSRMLS_CC, 1, phalcon_di_injectionawareinterface_ce); - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; + return SUCCESS; } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropPrimaryKey){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, __construct){ - zval *table_name, *schema_name; ->>>>>>> 1.2.2 + zval *view = NULL; - phalcon_fetch_params(0, 2, 0, &table_name, &schema_name); - - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; -} + PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + phalcon_fetch_params(1, 0, 1, &view); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!view) { + PHALCON_INIT_VAR(view); } - 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, "'"); + if (Z_TYPE_P(view) == IS_OBJECT) { + phalcon_update_property_this_quick(this_ptr, SL("_view"), view, 3993744575UL TSRMLS_CC); } - RETURN_CTOR(sql); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, viewExists){ - - zval *view_name, *schema_name = NULL, *sql = NULL; +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setDI){ - PHALCON_MM_GROW(); + zval *dependency_injector; - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + phalcon_fetch_params(0, 1, 0, &dependency_injector); - 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, "'"); + 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); -======= -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 PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropForeignKey){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getDI){ - 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; + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, _getTableOptions){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setOptions){ - zval *definition; + zval *options; - phalcon_fetch_params(0, 1, 0, &definition); + 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); - RETURN_EMPTY_ARRAY(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, createTable){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setOption){ - zval *table_name, *schema_name, *definition; + zval *option, *value; - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &definition); + phalcon_fetch_params(0, 2, 0, &option, &value); + + phalcon_update_property_array(this_ptr, SL("_options"), option, value TSRMLS_CC); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); - return; } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropTable){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getOption){ - zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; - zval *sql = NULL; + zval *option, *options, *value; 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); - } + phalcon_fetch_params(1, 1, 0, &option); - 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_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_CTOR(sql); + RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, createView){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getOptions){ - zval *view_name, *definition, *schema_name, *view_sql; - zval *view = NULL, *sql; + + 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, 3, 0, &view_name, &definition, &schema_name); + phalcon_fetch_params(1, 1, 1, &name, &arguments); - 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 (!arguments) { + PHALCON_INIT_VAR(arguments); } - 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_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); + } + } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); + zend_hash_move_forward_ex(ah0, &hp0); + } - RETURN_CTOR(sql); + } + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropView){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addExtension){ - zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; - zval *sql = NULL; + zval *extension; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); + phalcon_fetch_params(1, 1, 0, &extension); - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if (Z_TYPE_P(extension) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "The extension is not valid"); + return; } - 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); + if (phalcon_method_quick_exists_ex(extension, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_p1_key(NULL, extension, "initialize", this_ptr, 2896075127UL); } - RETURN_CTOR(sql); + phalcon_update_property_array_append(this_ptr, SL("_extensions"), extension TSRMLS_CC); + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, tableExists){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getExtensions){ - zval *table_name, *schema_name = NULL, *sql = NULL; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_extensions", 726159316UL); +} - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addFunction){ + + zval *name, *definition; + + phalcon_fetch_params(0, 2, 0, &name, &definition); - 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, "'"); + 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_CTOR(sql); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, viewExists){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getFunctions){ - zval *view_name, *schema_name = NULL, *sql = NULL; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_functions", 2704716189UL); +} - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, addFilter){ + + zval *name, *definition; + + phalcon_fetch_params(0, 2, 0, &name, &definition); - 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, "'"); + 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); ->>>>>>> 1.2.2 - RETURN_CTOR(sql); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, describeColumns){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getFilters){ - zval *table, *schema = NULL, *sql = NULL; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_filters", 3850488637UL); +} - 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 { - 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"); - } +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, setUniquePrefix){ + + zval *prefix; + + phalcon_fetch_params(0, 1, 0, &prefix); - RETURN_CTOR(sql); + phalcon_update_property_this_quick(this_ptr, SL("_prefix"), prefix, 3873791314UL TSRMLS_CC); + RETURN_THISW(); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, listTables){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getUniquePrefix){ - zval *schema_name = NULL, *sql = NULL; + zval *prefix = NULL, *current_path, *parameters, *calculated_prefix; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &schema_name); + PHALCON_OBS_VAR(prefix); + phalcon_read_property_this_quick(&prefix, this_ptr, SL("_prefix"), 3873791314UL, PH_NOISY_CC); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } -<<<<<<< HEAD + 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); - 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_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); - 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(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); + } } ->>>>>>> 1.2.2 - RETURN_CTOR(sql); + 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_Db_Dialect_Postgresql, listViews){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, attributeReader){ - zval *schema_name = NULL, *sql = NULL; + 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_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &schema_name); + phalcon_fetch_params(1, 1, 0, &expr); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + PHALCON_INIT_VAR(expr_code); - 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(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_NVAR(sql); - ZVAL_STRING(sql, "SELECT viewname AS view_name FROM pg_views WHERE schemaname = 'public' ORDER BY view_name", 1); + 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); + } } - 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_concat_self_str(&expr_code, SL("->") TSRMLS_CC); - if (!schema) { - PHALCON_INIT_VAR(schema); + 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); } - 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_CCTOR(expr_code); } -static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, describeReferences){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, functionCall){ - zval *table, *schema = NULL, *sql; + 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, 1, &table, &schema); + phalcon_fetch_params(1, 1, 0, &expr); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (Z_TYPE_P(expr) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted function call"); + return; } - 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, "'"); + 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_SCONCAT_SVS(sql, "tc.table_name='", table, "'"); + PHALCON_INIT_NVAR(arguments); + ZVAL_STRING(arguments, "", 1); } - 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_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); + } + + if (phalcon_array_isset(array_helpers, name)) { + PHALCON_CONCAT_SVSVS(return_value, "Phalcon\\Tag::", method, "(array(", arguments, "))"); + RETURN_MM(); + } + + PHALCON_CONCAT_SVSVS(return_value, "Phalcon\\Tag::", method, "(", arguments, ")"); + + RETURN_MM(); + } + + if (PHALCON_IS_STRING(name, "url")) { + PHALCON_CONCAT_SVS(return_value, "$this->url->get(", arguments, ")"); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(name, "static_url")) { + PHALCON_CONCAT_SVS(return_value, "$this->url->getStatic(", arguments, ")"); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(name, "date")) { + PHALCON_CONCAT_SVS(return_value, "date(", arguments, ")"); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(name, "time")) { + PHALCON_INIT_NVAR(code); + ZVAL_STRING(code, "time()", 1); + RETURN_CCTOR(code); + } + + if (PHALCON_IS_STRING(name, "dump")) { + PHALCON_CONCAT_SVS(return_value, "var_dump(", arguments, ")"); + RETURN_MM(); + } + + if (PHALCON_IS_STRING(name, "version")) { + RETURN_MM_STRING("Phalcon\\Version::get()", 1); + } + + if (PHALCON_IS_STRING(name, "version_id")) { + RETURN_MM_STRING("Phalcon\\Version::getId()", 1); + } + + if (PHALCON_IS_STRING(name, "constant")) { + PHALCON_CONCAT_SVS(return_value, "constant(", arguments, ")"); + RETURN_MM(); + } + + PHALCON_OBS_NVAR(line); + phalcon_array_fetch_quick_string(&line, expr, SS("line"), 266128205UL, PH_NOISY); - if (!schema) { - PHALCON_INIT_VAR(schema); + 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; } - RETURN_MM_EMPTY_STRING(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -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); - - zend_class_implements(phalcon_db_dialect_sqlite_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); - - return SUCCESS; + 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_Db_Dialect_Sqlite, getColumnDefinition){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, resolveTest){ - zval *column, *size, *column_type, *column_sql = NULL; - zval *scale; + 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, &column); + phalcon_fetch_params(1, 2, 0, &test, &left); - 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 (Z_TYPE_P(test) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted test"); return; } - PHALCON_INIT_VAR(size); - phalcon_call_method_key(size, column, "getsize", 4292672352UL); + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, test, SS("type"), 276192743UL, PH_NOISY); - PHALCON_INIT_VAR(column_type); - phalcon_call_method_key(column_type, column, "gettype", 4294422375UL); + if (PHALCON_IS_LONG(type, 265)) { - switch (phalcon_get_intval(column_type)) { + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, test, SS("value"), 574111618UL, PH_NOISY); - case 0: - PHALCON_INIT_VAR(column_sql); - ZVAL_STRING(column_sql, "INT", 1); - break; + if (PHALCON_IS_STRING(name, "empty")) { + PHALCON_CONCAT_SVS(return_value, "empty(", left, ")"); + RETURN_MM(); + } - case 1: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "DATE", 1); - break; + if (PHALCON_IS_STRING(name, "even")) { + PHALCON_CONCAT_SVS(return_value, "(((", left, ") % 2) == 0)"); + RETURN_MM(); + } - case 2: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "VARCHAR(", size, ")"); - break; + if (PHALCON_IS_STRING(name, "odd")) { + PHALCON_CONCAT_SVS(return_value, "(((", left, ") % 2) != 0)"); + RETURN_MM(); + } - case 3: - PHALCON_INIT_VAR(scale); - phalcon_call_method_key(scale, column, "getscale", 4211231149UL); + if (PHALCON_IS_STRING(name, "numeric")) { + PHALCON_CONCAT_SVS(return_value, "is_numeric(", left, ")"); + RETURN_MM(); + } - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVSVS(column_sql, "NUMERIC(", size, ",", scale, ")"); - break; + if (PHALCON_IS_STRING(name, "scalar")) { + PHALCON_CONCAT_SVS(return_value, "is_scalar(", left, ")"); + RETURN_MM(); + } - case 4: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TIMESTAMP", 1); - break; + if (PHALCON_IS_STRING(name, "iterable")) { + PHALCON_CONCAT_SVSVS(return_value, "(is_array(", left, ") || (", left, ") instanceof Traversable)"); + RETURN_MM(); + } + } - case 5: - PHALCON_INIT_NVAR(column_sql); - PHALCON_CONCAT_SVS(column_sql, "CHARACTER(", size, ")"); - break; + if (PHALCON_IS_LONG(type, 350)) { - case 6: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "TEXT", 1); - break; + 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)) { - case 7: - PHALCON_INIT_NVAR(column_sql); - ZVAL_STRING(column_sql, "FLOAT", 1); - break; + 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); - default: - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Unrecognized SQLite data type"); - return; + 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(); + } - } + if (PHALCON_IS_STRING(name, "sameas")) { + PHALCON_OBS_NVAR(test_arguments); + phalcon_array_fetch_quick_string(&test_arguments, test, SS("arguments"), 3751272283UL, PH_NOISY); - RETURN_CTOR(column_sql); -} - -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 "); - } - - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, column, "getname", 4286441094UL); - - PHALCON_INIT_VAR(column_definition); - phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); - PHALCON_SCONCAT_SVSV(sql, "\"", name, "\" ", column_definition); - - 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(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(); + } + } } - - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, 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, "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; - - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &column_name); + 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); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Dropping DB column is not supported by SQLite"); - return; + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addIndex){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, resolveFilter){ - zval *table_name, *schema_name, *index, *sql = NULL, *columns; - zval *quoted_column_list, *name; + 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, 3, 0, &table_name, &schema_name, &index); + phalcon_fetch_params(1, 2, 0, &filter, &left); - 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"); + if (Z_TYPE_P(filter) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted filter"); return; } - - PHALCON_INIT_VAR(name); - phalcon_call_method_key(name, index, "getname", 4286441094UL); - - 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, "\" ("); - } - - 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_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, "\""); -<<<<<<< HEAD - } - else { - PHALCON_CONCAT_SVS(sql, "DROP INDEX \"", index_name, "\""); + + PHALCON_INIT_VAR(code); + + PHALCON_OBS_VAR(type); + phalcon_array_fetch_quick_string(&type, filter, SS("type"), 276192743UL, PH_NOISY); + + 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); + + 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_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; + } } - - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, 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, "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_INIT_VAR(func_arguments); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Removing a primary key after table has been created is not supported by SQLite"); - return; -} - -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_INIT_VAR(arguments); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Adding a foreign key constraint to an existing table is not supported by SQLite"); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropForeignKey){ - - zval *table_name, *schema_name, *reference_name; - - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference_name); + if (phalcon_array_isset_quick_string(filter, SS("arguments"), 3751272283UL)) { - 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_OBS_NVAR(file); + phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); + + PHALCON_OBS_NVAR(line); + phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); + + 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); } - else { - PHALCON_CONCAT_SVS(sql, "DROP INDEX \"", index_name, "\""); + + 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); + } } - - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, 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, "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_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_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Removing a primary key after table has been created is not supported by SQLite"); - return; -} - -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_OBS_VAR(definition); + phalcon_array_fetch(&definition, filters, name, PH_NOISY); - PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Adding a foreign key constraint to an existing table is not supported by SQLite"); - return; -} - -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropForeignKey){ - - zval *table_name, *schema_name, *reference_name; - - phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference_name); + if (Z_TYPE_P(definition) == IS_STRING) { + PHALCON_CONCAT_VSVS(return_value, definition, "(", arguments, ")"); + RETURN_MM(); + } - 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); + 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_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; ->>>>>>> 1.2.2 - - phalcon_fetch_params(0, 1, 0, &definition); - -<<<<<<< HEAD - 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_OBS_NVAR(line); + phalcon_array_fetch_quick_string(&line, filter, SS("line"), 266128205UL, PH_NOISY); - 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; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); + PHALCON_OBS_NVAR(file); + phalcon_array_fetch_quick_string(&file, filter, SS("file"), 259010501UL, PH_NOISY); - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + 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 (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 (PHALCON_IS_STRING(name, "length")) { + PHALCON_CONCAT_SVS(return_value, "$this->length(", arguments, ")"); + RETURN_MM(); } - - 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 (PHALCON_IS_STRING(name, "e")) { + PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtml(", arguments, ")"); + RETURN_MM(); } -======= - 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 (PHALCON_IS_STRING(name, "escape")) { + PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtml(", arguments, ")"); + RETURN_MM(); } - 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 (PHALCON_IS_STRING(name, "escape_css")) { + PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeCss(", arguments, ")"); + RETURN_MM(); } - - 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 (PHALCON_IS_STRING(name, "escape_js")) { + PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeJs(", arguments, ")"); + RETURN_MM(); } - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, 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_IS_STRING(name, "escape_attr")) { + PHALCON_CONCAT_SVS(return_value, "$this->escaper->escapeHtmlAttr(", arguments, ")"); + RETURN_MM(); + } - 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 (PHALCON_IS_STRING(name, "trim")) { + PHALCON_CONCAT_SVS(return_value, "trim(", arguments, ")"); + RETURN_MM(); } - 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); + if (PHALCON_IS_STRING(name, "left_trim")) { + PHALCON_CONCAT_SVS(return_value, "ltrim(", arguments, ")"); + RETURN_MM(); } - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW \"", view, "\" AS ", view_sql); ->>>>>>> 1.2.2 + if (PHALCON_IS_STRING(name, "right_trim")) { + PHALCON_CONCAT_SVS(return_value, "rtrim(", arguments, ")"); + RETURN_MM(); + } - RETURN_CTOR(sql); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, 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_IS_STRING(name, "striptags")) { + PHALCON_CONCAT_SVS(return_value, "strip_tags(", arguments, ")"); + RETURN_MM(); + } - 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 (PHALCON_IS_STRING(name, "url_encode")) { + PHALCON_CONCAT_SVS(return_value, "urlencode(", arguments, ")"); + RETURN_MM(); } - PHALCON_OBS_VAR(view_sql); - phalcon_array_fetch_quick_string(&view_sql, definition, SS("sql"), 2090732981UL, PH_NOISY); -======= -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, 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); + if (PHALCON_IS_STRING(name, "slashes")) { + PHALCON_CONCAT_SVS(return_value, "addslashes(", arguments, ")"); + RETURN_MM(); + } - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if (PHALCON_IS_STRING(name, "stripslashes")) { + PHALCON_CONCAT_SVS(return_value, "stripslashes(", arguments, ")"); + RETURN_MM(); } ->>>>>>> 1.2.2 - 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 (PHALCON_IS_STRING(name, "nl2br")) { + PHALCON_CONCAT_SVS(return_value, "nl2br(", arguments, ")"); + RETURN_MM(); } -<<<<<<< HEAD - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "CREATE VIEW \"", view, "\" AS ", view_sql); -======= - 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 (PHALCON_IS_STRING(name, "keys")) { + PHALCON_CONCAT_SVS(return_value, "array_keys(", arguments, ")"); + RETURN_MM(); } ->>>>>>> 1.2.2 - RETURN_CTOR(sql); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, 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); + if (PHALCON_IS_STRING(name, "join")) { + PHALCON_CONCAT_SVS(return_value, "join(", arguments, ")"); + RETURN_MM(); + } - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + if (PHALCON_IS_STRING(name, "lowercase")) { + PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::lower(", arguments, ")"); + RETURN_MM(); } - 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 (PHALCON_IS_STRING(name, "lower")) { + PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::lower(", arguments, ")"); + RETURN_MM(); } - 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 (PHALCON_IS_STRING(name, "uppercase")) { + PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::upper(", arguments, ")"); + RETURN_MM(); } - RETURN_CTOR(sql); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, tableExists){ - - zval *table_name, *schema_name = NULL, *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); -======= -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, tableExists){ - - zval *table_name, *schema_name = NULL, *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + if (PHALCON_IS_STRING(name, "upper")) { + PHALCON_CONCAT_SVS(return_value, "Phalcon\\Text::upper(", arguments, ")"); + RETURN_MM(); + } - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (PHALCON_IS_STRING(name, "capitalize")) { + PHALCON_CONCAT_SVS(return_value, "ucwords(", arguments, ")"); + RETURN_MM(); } - 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); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, viewExists){ - - zval *view_name, *schema_name = NULL, *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); ->>>>>>> 1.2.2 + if (PHALCON_IS_STRING(name, "sort")) { + PHALCON_CONCAT_SVS(return_value, "$this->sort(", arguments, ")"); + RETURN_MM(); + } - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (PHALCON_IS_STRING(name, "json_encode")) { + PHALCON_CONCAT_SVS(return_value, "json_encode(", arguments, ")"); + RETURN_MM(); } - PHALCON_INIT_VAR(sql); -<<<<<<< HEAD - 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); -} - -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, viewExists){ - - zval *view_name, *schema_name = NULL, *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + if (PHALCON_IS_STRING(name, "json_decode")) { + PHALCON_CONCAT_SVS(return_value, "json_decode(", arguments, ")"); + RETURN_MM(); + } - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (PHALCON_IS_STRING(name, "format")) { + PHALCON_CONCAT_SVS(return_value, "sprintf(", arguments, ")"); + RETURN_MM(); } - 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 (PHALCON_IS_STRING(name, "abs")) { + PHALCON_CONCAT_SVS(return_value, "abs(", arguments, ")"); + RETURN_MM(); + } - if (!schema) { - PHALCON_INIT_VAR(schema); + if (PHALCON_IS_STRING(name, "slice")) { + PHALCON_CONCAT_SVS(return_value, "$this->slice(", arguments, ")"); + RETURN_MM(); } - 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 (PHALCON_IS_STRING(name, "default")) { + PHALCON_CONCAT_SVSVSVS(return_value, "(empty(", left, ") ? (", arguments, ") : (", left, "))"); + RETURN_MM(); + } -======= - 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); + 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_Db_Dialect_Sqlite, describeColumns){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, expression){ - zval *table, *schema = NULL, *sql; + 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, 1, 1, &table, &schema); + phalcon_fetch_params(1, 1, 0, &expr); - if (!schema) { - PHALCON_INIT_VAR(schema); + if (Z_TYPE_P(expr) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted expression"); + return; } - 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); + 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); + + 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; + } + } + if (!phalcon_array_isset_quick_string(expr, SS("type"), 276192743UL)) { + + PHALCON_INIT_NVAR(items); + array_init(items); + + phalcon_is_iterable(expr, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(single_expr); + + PHALCON_OBS_NVAR(single_expr_expr); + phalcon_array_fetch_quick_string(&single_expr_expr, single_expr, SS("expr"), 258368420UL, PH_NOISY); + + 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_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; + } + + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, expr, SS("type"), 276192743UL, PH_NOISY); + + 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 (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; + } + + 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_NVAR(expr_code); + phalcon_call_method_p2_key(expr_code, this_ptr, "resolvefilter", right_code, left_code, 3562260459UL); + break; + } + + 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_NVAR(right_code); + phalcon_call_method_p1_key(right_code, this_ptr, "expression", right, 218841909UL); + } + + PHALCON_INIT_NVAR(expr_code); + + switch (phalcon_get_intval(type)) { + + case 33: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SV(expr_code, "!", right_code); + break; + + case 42: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " * ", right_code); + break; + + case 43: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " + ", right_code); + break; + + case 45: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " - ", right_code); + break; + + case 47: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " / ", right_code); + break; + + case 37: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " % ", right_code); + break; + + case 60: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " < ", right_code); + break; + + case 61: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " > ", right_code); + break; + + case 62: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " > ", right_code); + break; + + case 126: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " . ", right_code); + break; + + case 278: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVS(expr_code, "pow(", left_code, ", ", right_code, ")"); + break; + + 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; ->>>>>>> 1.2.2 - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + case 258: + PHALCON_OBS_NVAR(expr_code); + phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); + break; - 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); + case 259: + PHALCON_OBS_NVAR(expr_code); + phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); + break; - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + case 260: + PHALCON_OBS_NVAR(value); + phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - 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); + PHALCON_INIT_NVAR(single_quote); + ZVAL_STRING(single_quote, "'", 1); - if (!schema) { - PHALCON_INIT_VAR(schema); - } + PHALCON_INIT_NVAR(escaped_quoute); + ZVAL_STRING(escaped_quoute, "\\'", 1); - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVS(sql, "PRAGMA index_list('", table, "')"); - RETURN_CTOR(sql); -<<<<<<< HEAD -} - -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_NVAR(escaped_string); + phalcon_fast_str_replace(escaped_string, single_quote, escaped_quoute, value); - 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); + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVS(expr_code, "'", escaped_string, "'"); + break; - if (!schema) { - PHALCON_INIT_VAR(schema); - } + case 261: + PHALCON_INIT_NVAR(expr_code); + ZVAL_STRING(expr_code, "null", 1); + break; - 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(); -} - -======= -} - -static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeIndex){ - - zval *index_name, *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &index_name); + case 262: + PHALCON_INIT_NVAR(expr_code); + ZVAL_STRING(expr_code, "false", 1); + break; - 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); + case 263: + PHALCON_INIT_NVAR(expr_code); + ZVAL_STRING(expr_code, "true", 1); + break; - if (!schema) { - PHALCON_INIT_VAR(schema); - } + case 265: + PHALCON_OBS_NVAR(value); + phalcon_array_fetch_quick_string(&value, expr, SS("value"), 574111618UL, PH_NOISY); - 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(); -} ->>>>>>> 1.2.2 - - - - -<<<<<<< HEAD -======= - ->>>>>>> 1.2.2 -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -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); - - zend_class_implements(phalcon_db_index_ce TSRMLS_CC, 1, phalcon_db_indexinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Db_Index, __construct){ - - zval *index_name, *columns; - - phalcon_fetch_params(0, 2, 0, &index_name, &columns); + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SV(expr_code, "$", value); + break; - 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); + case 266: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " && ", right_code); + break; -} - -static PHP_METHOD(Phalcon_Db_Index, getName){ - - - RETURN_MEMBER_QUICK(this_ptr, "_indexName", 3837120573UL); -} - -static PHP_METHOD(Phalcon_Db_Index, getColumns){ - - - RETURN_MEMBER_QUICK(this_ptr, "_columns", 4004520869UL); -} - -static PHP_METHOD(Phalcon_Db_Index, __set_state){ - - zval *data, *index_name, *columns; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &data); + case 267: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " || ", right_code); + break; - 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; - } + case 270: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " <= ", right_code); + break; - PHALCON_OBS_VAR(index_name); - phalcon_array_fetch_quick_string(&index_name, data, SS("_indexName"), 3837120573UL, PH_NOISY); + case 271: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " >= ", right_code); + break; - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, data, SS("_columns"), 4004520869UL, PH_NOISY); + case 272: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " == ", right_code); + break; - object_init_ex(return_value, phalcon_db_index_ce); - phalcon_call_method_p2_key(NULL, return_value, "__construct", index_name, columns, 1107214344UL); + case 273: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " != ", right_code); + break; - RETURN_MM(); -} - - - - - -#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; -} - - - - - -#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_Profiler){ - - PHALCON_REGISTER_CLASS(Phalcon\\Db, Profiler, db_profiler, phalcon_db_profiler_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); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Db_Profiler, startProfile){ - - zval *sql_statement, *active_profile, *micro; - zval *time; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &sql_statement); + case 274: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " === ", right_code); + break; - 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); + case 275: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSV(expr_code, left_code, " !== ", right_code); + break; - PHALCON_INIT_VAR(micro); - ZVAL_BOOL(micro, 1); + case 276: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVS(expr_code, "range(", left_code, ", ", right_code, ")"); + break; - 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); - } + case 350: + PHALCON_INIT_NVAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "functioncall", expr, 1638966055UL); + break; - phalcon_update_property_this_quick(this_ptr, SL("_activeProfile"), active_profile, 794883025UL TSRMLS_CC); + case 356: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVS(expr_code, "(", left_code, ")"); + break; - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Db_Profiler, stopProfile){ - - zval *micro, *final_time, *active_profile, *initial_time; - zval *diference, *total_seconds, *new_total_seconds; - - PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(micro); - ZVAL_BOOL(micro, 1); + case 361: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_VSVS(expr_code, left_code, "[", right_code, "]"); + break; - PHALCON_INIT_VAR(final_time); - phalcon_call_func_p1(final_time, "microtime", micro); + 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_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_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_VAR(initial_time); - phalcon_call_method_key(initial_time, active_profile, "getinitialtime", 2329302014UL); + 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); - PHALCON_INIT_VAR(diference); - sub_function(diference, final_time, initial_time TSRMLS_CC); + 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_OBS_VAR(total_seconds); - phalcon_read_property_this_quick(&total_seconds, this_ptr, SL("_totalSeconds"), 996888727UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVSVS(expr_code, "$this->slice(", left_code, ", ", start_code, ", ", end_code, ")"); + break; - 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); - } + case 362: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVS(expr_code, "!isset(", left_code, ")"); + break; - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Db_Profiler, getNumberTotalStatements){ - - zval *all_profiles; - - 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); -} - -static PHP_METHOD(Phalcon_Db_Profiler, reset){ - - zval *empty_arr; - - 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(); -} - -static PHP_METHOD(Phalcon_Db_Profiler, getLastProfile){ - - - RETURN_MEMBER_QUICK(this_ptr, "_activeProfile", 794883025UL); -<<<<<<< HEAD -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Adapter){ - - 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_fetch_params(1, 1, 0, &descriptor); + case 363: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVS(expr_code, "isset(", left_code, ")"); + break; - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); + case 309: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVS(expr_code, "$this->isIncluded(", left_code, ", ", right_code, ")"); + break; - PHALCON_OBS_VAR(connection_consecutive); - phalcon_read_static_property(&connection_consecutive, SL("phalcon\\db\\adapter"), SL("_connectionConsecutive") TSRMLS_CC); + case 369: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVS(expr_code, "!$this->isIncluded(", left_code, ", ", right_code, ")"); + break; - 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); + case 366: + PHALCON_OBS_NVAR(ternary); + phalcon_array_fetch_quick_string(&ternary, expr, SS("ternary"), 4197153930UL, PH_NOISY); - 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_INIT_NVAR(ternary_code); + phalcon_call_method_p1_key(ternary_code, this_ptr, "expression", ternary, 218841909UL); - PHALCON_INIT_VAR(dialect_class); - PHALCON_CONCAT_SV(dialect_class, "phalcon\\db\\dialect\\", dialect_type); - } else { - PHALCON_OBS_NVAR(dialect_class); - phalcon_array_fetch_quick_string(&dialect_class, descriptor, SS("dialectClass"), 2526466321UL, PH_NOISY); - } + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SVSVSVS(expr_code, "(", ternary_code, " ? ", left_code, " : ", right_code, ")"); + break; - 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); - } + case 367: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SV(expr_code, "-", right_code); + break; - phalcon_update_property_this_quick(this_ptr, SL("_descriptor"), descriptor, 691635363UL TSRMLS_CC); + case 368: + PHALCON_INIT_NVAR(expr_code); + PHALCON_CONCAT_SV(expr_code, "+", right_code); + break; - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Db_Adapter, setEventsManager){ - - zval *events_manager; - - phalcon_fetch_params(0, 1, 0, &events_manager); + case 364: + PHALCON_OBS_NVAR(expr_code); + phalcon_array_fetch_quick_string(&expr_code, expr, SS("value"), 574111618UL, PH_NOISY); + break; - phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); + default: + PHALCON_OBS_NVAR(line); + phalcon_array_fetch_quick_string(&line, expr, SS("line"), 266128205UL, PH_NOISY); -} - -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_OBS_NVAR(file); + phalcon_array_fetch_quick_string(&file, expr, SS("file"), 259010501UL, PH_NOISY); - phalcon_update_property_this_quick(this_ptr, SL("_dialect"), dialect, 4072955610UL TSRMLS_CC); + 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_CCTOR(expr_code); } -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_Mvc_View_Engine_Volt_Compiler, _statementListOrExtends){ - zval *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL; - zval *result; + zval *statements, *is_statement_list = NULL, *statement = NULL; + zval *code; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 3, &sql_query, &fetch_mode, &bind_params, &bind_types); + phalcon_fetch_params(1, 1, 0, &statements); - if (!fetch_mode) { - PHALCON_INIT_VAR(fetch_mode); - ZVAL_LONG(fetch_mode, 2); + if (Z_TYPE_P(statements) != IS_ARRAY) { + RETURN_CCTOR(statements); } - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } + PHALCON_INIT_VAR(is_statement_list); + ZVAL_BOOL(is_statement_list, 1); + if (!phalcon_array_isset_quick_string(statements, SS("type"), 276192743UL)) { - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } + phalcon_is_iterable(statements, &ah0, &hp0, 0, 0); - 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); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(statement); + + if (Z_TYPE_P(statement) != IS_ARRAY) { + PHALCON_INIT_NVAR(is_statement_list); + ZVAL_BOOL(is_statement_list, 0); + break; + } + + zend_hash_move_forward_ex(ah0, &hp0); } - phalcon_call_method_key(return_value, result, "fetch", 4247924303UL); - RETURN_MM(); + } - RETURN_MM_EMPTY_ARRAY(); + 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); } -static PHP_METHOD(Phalcon_Db_Adapter, fetchAll){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileForeach){ - zval *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL; - zval *results, *result, *row = NULL; - zval *r0 = NULL; + 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, 1, 3, &sql_query, &fetch_mode, &bind_params, &bind_types); + phalcon_fetch_params(1, 1, 1, &statement, &extends_mode); - if (!fetch_mode) { - PHALCON_INIT_VAR(fetch_mode); - ZVAL_LONG(fetch_mode, 2); + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); } - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); + if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; } - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } + PHALCON_INIT_VAR(compilation); + ZVAL_STRING(compilation, "", 1); + phalcon_property_incr(this_ptr, SL("_foreachLevel") TSRMLS_CC); - PHALCON_INIT_VAR(results); - array_init(results); + PHALCON_INIT_VAR(prefix); + phalcon_call_method_key(prefix, this_ptr, "getuniqueprefix", 3888429962UL); - 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_OBS_VAR(level); + phalcon_read_property_this_quick(&level, this_ptr, SL("_foreachLevel"), 1560648116UL, PH_NOISY_CC); - while (1) { + PHALCON_INIT_VAR(prefix_level); + PHALCON_CONCAT_VV(prefix_level, prefix, level); - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, result, "fetch", 4247924303UL); - PHALCON_CPY_WRT(row, r0); - if (zend_is_true(row)) { - } else { + 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_OBS_VAR(block_statements); + phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); + + PHALCON_INIT_VAR(for_else); + ZVAL_BOOL(for_else, 0); + if (Z_TYPE_P(block_statements) == IS_ARRAY) { + + phalcon_is_iterable(block_statements, &ah0, &hp0, 0, 0); + + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + + PHALCON_GET_HVALUE(bstatement); + + if (Z_TYPE_P(bstatement) != IS_ARRAY) { break; } - phalcon_array_append(&results, row, PH_SEPARATE); + 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); } + } - 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; -======= + PHALCON_INIT_VAR(code); + phalcon_call_method_p2_key(code, this_ptr, "_statementlist", block_statements, extends_mode, 1357145205UL); + + 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_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(variable); + phalcon_array_fetch_quick_string(&variable, statement, SS("variable"), 1809440971UL, PH_NOISY); + + 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(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)); ?>"); + } + + if (Z_TYPE_P(for_else) == IS_STRING) { + PHALCON_SCONCAT_SVS(compilation, ""); + } + + 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 { + if (phalcon_array_isset(loop_context, level)) { + PHALCON_SCONCAT_SVS(compilation, ""); + } else { + phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); + } + } + + phalcon_property_decr(this_ptr, SL("_foreachLevel") TSRMLS_CC); + + 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(); - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Db_Adapter){ - - 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; + PHALCON_OBS_VAR(level); + phalcon_read_property_this_quick(&level, this_ptr, SL("_foreachLevel"), 1560648116UL, PH_NOISY_CC); + + 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_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_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Db_Adapter, __construct){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileIf){ - zval *descriptor, *one, *connection_consecutive; - zval *next_consecutive, *dialect_type, *dialect_class = NULL; - zval *dialect_object; - zend_class_entry *ce0; + zval *statement, *extends_mode = NULL, *compilation; + zval *expr, *expr_code, *block_statements = NULL, *code = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &descriptor); + phalcon_fetch_params(1, 1, 1, &statement, &extends_mode); - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); + } - PHALCON_OBS_VAR(connection_consecutive); - phalcon_read_static_property(&connection_consecutive, SL("phalcon\\db\\adapter"), SL("_connectionConsecutive") TSRMLS_CC); + PHALCON_INIT_VAR(compilation); - 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(statement, SS("expr"), 258368420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; + } - 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_OBS_VAR(expr); + phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); - PHALCON_INIT_VAR(dialect_class); - PHALCON_CONCAT_SV(dialect_class, "phalcon\\db\\dialect\\", dialect_type); - } else { - PHALCON_OBS_NVAR(dialect_class); - phalcon_array_fetch_quick_string(&dialect_class, descriptor, SS("dialectClass"), 2526466321UL, PH_NOISY); - } + PHALCON_INIT_VAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); - 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_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); + + 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); } - phalcon_update_property_this_quick(this_ptr, SL("_descriptor"), descriptor, 691635363UL TSRMLS_CC); + phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); - PHALCON_MM_RESTORE(); + RETURN_CCTOR(compilation); } -static PHP_METHOD(Phalcon_Db_Adapter, setEventsManager){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileElseIf){ - zval *events_manager; + zval *statement, *expr, *expr_code; - phalcon_fetch_params(0, 1, 0, &events_manager); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &statement); - phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); + 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_CONCAT_SVS(return_value, ""); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, getEventsManager){ - - - RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); -} +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileCache){ -static PHP_METHOD(Phalcon_Db_Adapter, setDialect){ + zval *statement, *extends_mode = NULL, *compilation; + zval *expr, *expr_code, *lifetime = NULL, *block_statements; + zval *code; - zval *dialect; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &dialect); + phalcon_fetch_params(1, 1, 1, &statement, &extends_mode); + + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); + } + + 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(compilation); + + 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, "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_update_property_this_quick(this_ptr, SL("_dialect"), dialect, 4072955610UL TSRMLS_CC); + 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); + 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); + + 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, "]; } ?>"); + } + + RETURN_CCTOR(compilation); } -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_Mvc_View_Engine_Volt_Compiler, compileEcho){ - zval *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL; - zval *result; + zval *statement, *compilation, *expr, *expr_code; + zval *expr_type, *name, *name_type, *name_value; + zval *autoescape; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 3, &sql_query, &fetch_mode, &bind_params, &bind_types); + phalcon_fetch_params(1, 1, 0, &statement); - if (!fetch_mode) { - PHALCON_INIT_VAR(fetch_mode); - ZVAL_LONG(fetch_mode, 2); + if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; } - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } + PHALCON_INIT_VAR(compilation); - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } + PHALCON_OBS_VAR(expr); + phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); - 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_INIT_VAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); + + 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_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, expr, SS("name"), 268211462UL, PH_NOISY); + + 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_OBS_VAR(name_value); + phalcon_array_fetch_quick_string(&name_value, name, SS("value"), 574111618UL, PH_NOISY); + + if (PHALCON_IS_STRING(name_value, "super")) { + RETURN_CCTOR(expr_code); + } } - phalcon_call_method_key(return_value, result, "fetch", 4247924303UL); - RETURN_MM(); } - RETURN_MM_EMPTY_ARRAY(); + 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_Db_Adapter, fetchAll){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileInclude){ - zval *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL; - zval *results, *result, *row = NULL; - zval *r0 = NULL; + 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_fetch_params(1, 1, 3, &sql_query, &fetch_mode, &bind_params, &bind_types); + phalcon_fetch_params(1, 1, 0, &statement); - if (!fetch_mode) { - PHALCON_INIT_VAR(fetch_mode); - ZVAL_LONG(fetch_mode, 2); + if (!phalcon_array_isset_quick_string(statement, SS("path"), 270591026UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; } - if (!bind_params) { - PHALCON_INIT_VAR(bind_params); - } + PHALCON_OBS_VAR(path_expr); + phalcon_array_fetch_quick_string(&path_expr, statement, SS("path"), 270591026UL, PH_NOISY); - if (!bind_types) { - PHALCON_INIT_VAR(bind_types); - } + PHALCON_OBS_VAR(expr_type); + phalcon_array_fetch_quick_string(&expr_type, path_expr, SS("type"), 276192743UL, PH_NOISY); - PHALCON_INIT_VAR(results); - array_init(results); + if (PHALCON_IS_LONG(expr_type, 260)) { - 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); - } + if (!phalcon_array_isset_quick_string(statement, SS("params"), 2613350281UL)) { - while (1) { + PHALCON_OBS_VAR(path); + phalcon_array_fetch_quick_string(&path, path_expr, SS("value"), 574111618UL, PH_NOISY); - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, result, "fetch", 4247924303UL); - PHALCON_CPY_WRT(row, r0); - if (zend_is_true(row)) { + 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_VAR(final_path); + PHALCON_CONCAT_VV(final_path, views_dir, path); } else { - break; + PHALCON_CPY_WRT(final_path, path); } - phalcon_array_append(&results, row, PH_SEPARATE); + PHALCON_INIT_VAR(extended); + ZVAL_BOOL(extended, 0); + + PHALCON_INIT_VAR(sub_compiler); + if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { + return; + } + + PHALCON_INIT_VAR(compilation); + phalcon_call_method_p2_key(compilation, sub_compiler, "compile", final_path, extended, 1074882030UL); + + 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(compilation); + phalcon_file_get_contents(compilation, compiled_path TSRMLS_CC); + } + + RETURN_CCTOR(compilation); } } - RETURN_CTOR(results); + 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_OBS_VAR(expr_params); + phalcon_array_fetch_quick_string(&expr_params, statement, SS("params"), 2613350281UL, PH_NOISY); + + PHALCON_INIT_VAR(params); + phalcon_call_method_p1_key(params, this_ptr, "expression", expr_params, 218841909UL); + PHALCON_CONCAT_SVSVS(return_value, "partial(", path, ", ", params, "); ?>"); + + RETURN_MM(); } -static PHP_METHOD(Phalcon_Db_Adapter, insert){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileSet){ - 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 *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, 2, 2, &table, &values, &fields, &data_types); - - if (!fields) { - PHALCON_INIT_VAR(fields); - } - - if (!data_types) { - PHALCON_INIT_VAR(data_types); - } - - 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; - } + phalcon_fetch_params(1, 1, 0, &statement); - 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); + if (!phalcon_array_isset_quick_string(statement, SS("assignments"), 2364482705UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); return; } - PHALCON_INIT_VAR(placeholders); - array_init(placeholders); + PHALCON_INIT_VAR(compilation); + ZVAL_STRING(compilation, "") TSRMLS_CC); + + RETURN_CTOR(compilation); } -static PHP_METHOD(Phalcon_Db_Adapter, update){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileDo){ - 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; ->>>>>>> 1.2.2 - zval **hd; + zval *statement, *expr, *expr_code; PHALCON_MM_GROW(); -<<<<<<< HEAD - phalcon_fetch_params(1, 2, 2, &table, &values, &fields, &data_types); + phalcon_fetch_params(1, 1, 0, &statement); - if (!fields) { - PHALCON_INIT_VAR(fields); + if (!phalcon_array_isset_quick_string(statement, SS("expr"), 258368420UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; } - if (!data_types) { - PHALCON_INIT_VAR(data_types); - } + PHALCON_OBS_VAR(expr); + phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); - 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; - } + PHALCON_INIT_VAR(expr_code); + phalcon_call_method_p1_key(expr_code, this_ptr, "expression", expr, 218841909UL); - 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); + PHALCON_CONCAT_SVS(return_value, ""); + + 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); + + 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(placeholders); - array_init(placeholders); + PHALCON_OBS_VAR(expr); + phalcon_array_fetch_quick_string(&expr, statement, SS("expr"), 258368420UL, PH_NOISY); - 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_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_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); + + 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(values, &ah0, &hp0, 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(ah0, (void**) &hd, &hp0) == 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, ah0, hp0); - PHALCON_GET_HVALUE(value); + PHALCON_OBS_VAR(block_statements); + phalcon_array_fetch_quick_string(&block_statements, statement, SS("block_statements"), 883954391UL, PH_NOISY); - 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_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(bind_type); - phalcon_array_fetch(&bind_type, data_types, position, PH_NOISY); - phalcon_array_append(&bind_data_types, bind_type, PH_SEPARATE); - } - } - } + 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); - zend_hash_move_forward_ex(ah0, &hp0); + if (!phalcon_array_isset_quick_string(statement, SS("name"), 268211462UL)) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); + return; } - if (PHALCON_GLOBAL(db).escape_identifiers) { - PHALCON_INIT_VAR(escaped_table); - phalcon_call_method_p1_key(escaped_table, this_ptr, "escapeidentifier", table, 585773337UL); + PHALCON_OBS_VAR(name); + phalcon_array_fetch_quick_string(&name, statement, SS("name"), 268211462UL, PH_NOISY); + + 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_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_CPY_WRT(escaped_table, table); + phalcon_update_property_array(this_ptr, SL("_macros"), name, name 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) { - - PHALCON_INIT_VAR(escaped_fields); - array_init(escaped_fields); + PHALCON_INIT_VAR(code); + ZVAL_STRING(code, ""); + } else { + PHALCON_SCONCAT_VS(code, name, "($__p) { "); - phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); + PHALCON_OBS_VAR(parameters); + phalcon_array_fetch_quick_string(¶meters, statement, SS("parameters"), 3941032889UL, PH_NOISY); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + phalcon_is_iterable(parameters, &ah0, &hp0, 0, 0); - PHALCON_GET_HVALUE(field); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - 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_GET_HKEY(position, ah0, hp0); + PHALCON_GET_HVALUE(parameter); - zend_hash_move_forward_ex(ah1, &hp1); - } + 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); - } else { - PHALCON_CPY_WRT(escaped_fields, fields); + zend_hash_move_forward_ex(ah0, &hp0); } - PHALCON_INIT_VAR(joined_fields); - phalcon_fast_join_str(joined_fields, SL(", "), escaped_fields TSRMLS_CC); + phalcon_concat_self_str(&code, SL(" ?>") TSRMLS_CC); + } + + 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(insert_sql); - PHALCON_CONCAT_SVSVSVS(insert_sql, "INSERT INTO ", escaped_table, " (", joined_fields, ") VALUES (", joined_values, ")"); + 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_INIT_NVAR(insert_sql); - PHALCON_CONCAT_SVSVS(insert_sql, "INSERT INTO ", escaped_table, " VALUES (", joined_values, ")"); + phalcon_concat_self_str(&code, SL("") TSRMLS_CC); } - phalcon_call_method_p3_key(return_value, this_ptr, "execute", insert_sql, insert_values, bind_data_types, 3117639032UL); - RETURN_MM(); + RETURN_CTOR(code); } -static PHP_METHOD(Phalcon_Db_Adapter, update){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileCall){ - 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; + + +} + +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, 2, &table, &fields, &values, &where_condition, &data_types); + phalcon_fetch_params(1, 1, 1, &statements, &extends_mode); - if (!where_condition) { - PHALCON_INIT_VAR(where_condition); + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); } - if (!data_types) { - PHALCON_INIT_VAR(data_types); + if (!phalcon_fast_count_ev(statements TSRMLS_CC)) { + RETURN_MM_EMPTY_STRING(); } - PHALCON_INIT_VAR(placeholders); - array_init(placeholders); + PHALCON_OBS_VAR(extended); + phalcon_read_property_this_quick(&extended, this_ptr, SL("_extended"), 1049215029UL, PH_NOISY_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(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_is_iterable(values, &ah0, &hp0, 0, 0); + 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_HKEY(position, ah0, hp0); - PHALCON_GET_HVALUE(value); + PHALCON_GET_HVALUE(statement); - 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"); + if (Z_TYPE_P(statement) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Corrupted statement"); 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 (!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_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 (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(extensions) == IS_ARRAY) { - 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_INIT_NVAR(event); + ZVAL_STRING(event, "compileStatement", 1); + + PHALCON_INIT_NVAR(fire_arguments); + array_init_size(fire_arguments, 1); + phalcon_array_append(&fire_arguments, statement, PH_SEPARATE); + + 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_array_append(&placeholders, set_clause_part, PH_SEPARATE); } - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, statement, SS("type"), 276192743UL, PH_NOISY); - 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) { + switch (phalcon_get_intval(type)) { - PHALCON_INIT_VAR(update_sql); - PHALCON_CONCAT_SVSVS(update_sql, "UPDATE ", escaped_table, " SET ", set_clause, " WHERE "); + 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; - 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; - } + 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_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); - } + 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; - 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); - } + 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; -======= - phalcon_fetch_params(1, 3, 2, &table, &fields, &values, &where_condition, &data_types); + 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; - if (!where_condition) { - PHALCON_INIT_VAR(where_condition); - } + 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 (!data_types) { - PHALCON_INIT_VAR(data_types); - } + 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_INIT_VAR(placeholders); - array_init(placeholders); + 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_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); - } + if (Z_TYPE_P(compilation) != IS_NULL) { + phalcon_array_append(&blocks, compilation, PH_SEPARATE); - phalcon_is_iterable(values, &ah0, &hp0, 0, 0); + PHALCON_INIT_NVAR(compilation); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + 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_GET_HKEY(position, ah0, hp0); - PHALCON_GET_HVALUE(value); + break; - 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; - } + case 310: + PHALCON_OBS_NVAR(path); + phalcon_array_fetch_quick_string(&path, statement, SS("path"), 270591026UL, PH_NOISY); - 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(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); - 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_INIT_NVAR(final_path); + PHALCON_CONCAT_VV(final_path, views_dir, path); + } else { + PHALCON_CPY_WRT(final_path, path); + } - 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_INIT_NVAR(extended); + ZVAL_BOOL(extended, 1); + + PHALCON_INIT_NVAR(sub_compiler); + if (phalcon_clone(sub_compiler, this_ptr TSRMLS_CC) == FAILURE) { + return; } - } - phalcon_array_append(&placeholders, set_clause_part, PH_SEPARATE); - } - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_NVAR(temp_compilation); + phalcon_call_method_p2_key(temp_compilation, sub_compiler, "compile", final_path, extended, 1074882030UL); - 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 (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(set_clause); - phalcon_fast_join_str(set_clause, SL(", "), placeholders TSRMLS_CC); - if (Z_TYPE_P(where_condition) != IS_NULL) { + PHALCON_INIT_NVAR(temp_compilation); + phalcon_file_get_contents(temp_compilation, compiled_path TSRMLS_CC); + } - PHALCON_INIT_VAR(update_sql); - PHALCON_CONCAT_SVSVS(update_sql, "UPDATE ", escaped_table, " SET ", set_clause, " WHERE "); + 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; - 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; - } + 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; - 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); - } + 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; - 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); - } + 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; + + 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; + + 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; + + case 319: + phalcon_concat_self_str(&compilation, SL("") TSRMLS_CC); + break; + + 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; ->>>>>>> 1.2.2 - 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); + + zend_hash_move_forward_ex(ah0, &hp0); } - phalcon_call_method_p3_key(return_value, this_ptr, "execute", update_sql, update_values, bind_data_types, 3117639032UL); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Db_Adapter, delete){ - - zval *table, *where_condition = NULL, *placeholders = NULL; - zval *data_types = NULL, *escaped_table = NULL, *sql = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 3, &table, &where_condition, &placeholders, &data_types); + if (PHALCON_IS_TRUE(block_mode)) { - if (!where_condition) { - PHALCON_INIT_VAR(where_condition); - } + PHALCON_OBS_VAR(level); + phalcon_read_property_this_quick(&level, this_ptr, SL("_blockLevel"), 160754279UL, PH_NOISY_CC); + if (PHALCON_IS_LONG(level, 1)) { - if (!placeholders) { - PHALCON_INIT_VAR(placeholders); - } + if (Z_TYPE_P(compilation) != IS_NULL) { + phalcon_update_property_array_append(this_ptr, SL("_blocks"), compilation TSRMLS_CC); + } + } - if (!data_types) { - PHALCON_INIT_VAR(data_types); + phalcon_property_decr(this_ptr, SL("_blockLevel") TSRMLS_CC); } -<<<<<<< HEAD - 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_property_decr(this_ptr, SL("_level") TSRMLS_CC); - phalcon_call_method_p3_key(return_value, this_ptr, "execute", sql, placeholders, data_types, 3117639032UL); - RETURN_MM(); + RETURN_CCTOR(compilation); } -static PHP_METHOD(Phalcon_Db_Adapter, getColumnList){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, _compileSource){ - zval *column_list, *dialect; + 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, 1, 0, &column_list); + phalcon_fetch_params(1, 1, 1, &view_code, &extends_mode); - 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; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &sql_query, &number); + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); + } - 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_Db_Adapter, tableExists){ - - zval *table_name, *schema_name = NULL, *dialect, *sql; - zval *fetch_num, *num, *first; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); + PHALCON_OBS_VAR(current_path); + phalcon_read_property_this_quick(¤t_path, this_ptr, SL("_currentPath"), 3436123892UL, PH_NOISY_CC); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + PHALCON_INIT_VAR(intermediate); + if (phvolt_parse_view(intermediate, view_code, current_path TSRMLS_CC) == FAILURE) { + return; } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + if (Z_TYPE_P(intermediate) == IS_ARRAY) { - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "tableexists", table_name, schema_name, 1944065613UL); + PHALCON_INIT_VAR(compilation); + phalcon_call_method_p2_key(compilation, this_ptr, "_statementlist", intermediate, extends_mode, 1357145205UL); - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + 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(num); - phalcon_call_method_p2_key(num, this_ptr, "fetchone", sql, fetch_num, 1637187313UL); + if (PHALCON_IS_TRUE(extends_mode)) { + PHALCON_INIT_VAR(final_compilation); + array_init(final_compilation); + } else { + PHALCON_INIT_NVAR(final_compilation); + } - PHALCON_OBS_VAR(first); - phalcon_array_fetch_long(&first, num, 0, PH_NOISY); - RETURN_CCTOR(first); -} - -static PHP_METHOD(Phalcon_Db_Adapter, viewExists){ - - zval *view_name, *schema_name = NULL, *dialect, *sql, *fetch_num; - zval *num, *first; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + PHALCON_OBS_VAR(blocks); + phalcon_read_property_this_quick(&blocks, this_ptr, SL("_blocks"), 2750049986UL, PH_NOISY_CC); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + PHALCON_OBS_VAR(extended_blocks); + phalcon_read_property_this_quick(&extended_blocks, this_ptr, SL("_extendedBlocks"), 3140083987UL, PH_NOISY_CC); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + phalcon_is_iterable(extended_blocks, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "viewexists", view_name, schema_name, 1384087744UL); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + PHALCON_GET_HKEY(name, ah0, hp0); + PHALCON_GET_HVALUE(block); - PHALCON_INIT_VAR(num); - phalcon_call_method_p2_key(num, this_ptr, "fetchone", sql, fetch_num, 1637187313UL); + 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_OBS_VAR(first); - phalcon_array_fetch_long(&first, num, 0, PH_NOISY); - RETURN_CCTOR(first); -} - -static PHP_METHOD(Phalcon_Db_Adapter, forUpdate){ - - zval *sql_query, *dialect; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &sql_query); + 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); - 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_Db_Adapter, sharedLock){ - - zval *sql_query, *dialect; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &sql_query); + 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); + } + } - 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_Db_Adapter, createTable){ - - zval *table_name, *schema_name, *definition; - zval *exception_message, *columns, *dialect; - zval *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &definition); + zend_hash_move_forward_ex(ah0, &hp0); + } - 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; - } + RETURN_CCTOR(final_compilation); + } - 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; - } + 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_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + RETURN_CCTOR(compilation); + } - 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(); + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Invalid intermediate representation"); + return; } -static PHP_METHOD(Phalcon_Db_Adapter, dropTable){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileString){ - zval *table_name, *schema_name = NULL, *if_exists = NULL, *dialect; - zval *sql; + zval *view_code, *extends_mode = NULL, *current_path; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 2, &table_name, &schema_name, &if_exists); + phalcon_fetch_params(1, 1, 1, &view_code, &extends_mode); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); } - if (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + 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_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); + 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_Db_Adapter, createView){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compileFile){ - zval *view_name, *definition, *schema_name = NULL, *exception_message; - zval *dialect, *sql; + 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, &view_name, &definition, &schema_name); + phalcon_fetch_params(1, 2, 1, &path, &compiled_path, &extends_mode); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); } - if (Z_TYPE_P(definition) != IS_ARRAY) { + 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; + } + + if (phalcon_file_exists(path TSRMLS_CC) == FAILURE) { 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); + PHALCON_CONCAT_SVS(exception_message, "Template file ", path, " does not exist"); + PHALCON_THROW_EXCEPTION_ZVAL(phalcon_mvc_view_exception_ce, exception_message); return; } - if (!phalcon_array_isset_quick_string(definition, SS("sql"), 2090732981UL)) { -======= - 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(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 (PHALCON_IS_NOT_EMPTY(where_condition)) { - PHALCON_INIT_VAR(sql); - PHALCON_CONCAT_SVSV(sql, "DELETE FROM ", escaped_table, " WHERE ", where_condition); + + phalcon_update_property_this_quick(this_ptr, SL("_currentPath"), path, 3436123892UL TSRMLS_CC); + + PHALCON_INIT_VAR(compilation); + phalcon_call_method_p2_key(compilation, this_ptr, "_compilesource", view_code, extends_mode, 1468654718UL); + + if (Z_TYPE_P(compilation) == IS_ARRAY) { + PHALCON_INIT_VAR(final_compilation); + phalcon_serialize(final_compilation, &compilation TSRMLS_CC); } else { - PHALCON_INIT_NVAR(sql); - PHALCON_CONCAT_SV(sql, "DELETE FROM ", escaped_table); + PHALCON_CPY_WRT(final_compilation, compilation); } - 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(); -} - -static PHP_METHOD(Phalcon_Db_Adapter, limit){ - - zval *sql_query, *number, *dialect; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &sql_query, &number); + 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_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(); + RETURN_CCTOR(compilation); } -static PHP_METHOD(Phalcon_Db_Adapter, tableExists){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, compile){ - zval *table_name, *schema_name = NULL, *dialect, *sql; - zval *fetch_num, *num, *first; + 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, &table_name, &schema_name); + phalcon_fetch_params(1, 1, 1, &template_path, &extends_mode); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (!extends_mode) { + PHALCON_INIT_VAR(extends_mode); + ZVAL_BOOL(extends_mode, 0); } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + PHALCON_INIT_VAR(zero); + ZVAL_LONG(zero, 0); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "tableexists", table_name, schema_name, 1944065613UL); + PHALCON_INIT_VAR(znull); - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + PHALCON_INIT_VAR(zfalse); + ZVAL_BOOL(zfalse, 0); - 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("_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(first); - phalcon_array_fetch_long(&first, num, 0, PH_NOISY); - RETURN_CCTOR(first); -} - -static PHP_METHOD(Phalcon_Db_Adapter, viewExists){ - - zval *view_name, *schema_name = NULL, *dialect, *sql, *fetch_num; - zval *num, *first; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + PHALCON_INIT_VAR(stat); + ZVAL_BOOL(stat, 1); + PHALCON_CPY_WRT(compile_always, zfalse); - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + PHALCON_INIT_VAR(compiled_path); + ZVAL_STRING(compiled_path, "", 1); + PHALCON_CPY_WRT(prefix, znull); - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + PHALCON_INIT_VAR(compiled_separator); + ZVAL_STRING(compiled_separator, "%%", 1); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p2_key(sql, dialect, "viewexists", view_name, schema_name, 1384087744UL); + PHALCON_INIT_VAR(compiled_extension); + ZVAL_STRING(compiled_extension, ".php", 1); + PHALCON_CPY_WRT(compilation, znull); - PHALCON_INIT_VAR(fetch_num); - ZVAL_LONG(fetch_num, 3); + 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_INIT_VAR(num); - phalcon_call_method_p2_key(num, this_ptr, "fetchone", sql, fetch_num, 1637187313UL); + if (phalcon_array_isset_quick_string(options, SS("compileAlways"), 595908511UL)) { - PHALCON_OBS_VAR(first); - phalcon_array_fetch_long(&first, num, 0, PH_NOISY); - RETURN_CCTOR(first); -} - -static PHP_METHOD(Phalcon_Db_Adapter, forUpdate){ - - zval *sql_query, *dialect; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &sql_query); + 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_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_Db_Adapter, sharedLock){ - - zval *sql_query, *dialect; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &sql_query); + if (phalcon_array_isset_quick_string(options, SS("prefix"), 3263410483UL)) { - 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_Db_Adapter, createTable){ - - zval *table_name, *schema_name, *definition; - zval *exception_message, *columns, *dialect; - zval *sql; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &definition); + 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(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; + 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; + } + } + } + + if (phalcon_array_isset_quick_string(options, SS("compiledSeparator"), 3462898403UL)) { + + 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 (phalcon_array_isset_quick_string(options, SS("compiledExtension"), 401304207UL)) { + + 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 (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); + } } - PHALCON_OBS_VAR(columns); - phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); - if (!phalcon_fast_count_ev(columns TSRMLS_CC)) { ->>>>>>> 1.2.2 - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The table must contain at least one column"); - return; + 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); + + 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_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "compiledPath must be a string or a closure"); + return; + } + } } - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); + 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)) { + + if (phalcon_file_exists(compiled_template_path TSRMLS_CC) == SUCCESS) { - PHALCON_INIT_VAR(sql); -<<<<<<< HEAD - phalcon_call_method_p3_key(sql, dialect, "createview", view_name, definition, schema_name, 2593254036UL); -======= - phalcon_call_method_p3_key(sql, dialect, "createtable", table_name, schema_name, definition, 3885129953UL); ->>>>>>> 1.2.2 - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); -} - -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Adapter, dropView){ - - zval *view_name, *schema_name = NULL, *if_exists = NULL, *dialect; -======= -static PHP_METHOD(Phalcon_Db_Adapter, dropTable){ - - zval *table_name, *schema_name = NULL, *if_exists = NULL, *dialect; ->>>>>>> 1.2.2 - zval *sql; - - PHALCON_MM_GROW(); - -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 2, &view_name, &schema_name, &if_exists); -======= - phalcon_fetch_params(1, 1, 2, &table_name, &schema_name, &if_exists); ->>>>>>> 1.2.2 + 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)) { - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); - } + 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 (!if_exists) { - PHALCON_INIT_VAR(if_exists); - ZVAL_BOOL(if_exists, 1); + 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; + } + } } -<<<<<<< HEAD - 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("_compiledTemplatePath"), real_compiled_path, 2270620474UL TSRMLS_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(); + RETURN_CCTOR(compilation); } -static PHP_METHOD(Phalcon_Db_Adapter, addColumn){ - - zval *table_name, *schema_name, *column, *dialect; - zval *sql; +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getTemplatePath){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); -======= ->>>>>>> 1.2.2 - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); -<<<<<<< HEAD - 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(); + RETURN_MEMBER_QUICK(this_ptr, "_currentPath", 3436123892UL); } -static PHP_METHOD(Phalcon_Db_Adapter, modifyColumn){ - - zval *table_name, *schema_name, *column, *dialect; - zval *sql; +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, getCompiledTemplatePath){ - 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(); + RETURN_MEMBER_QUICK(this_ptr, "_compiledTemplatePath", 2270620474UL); } -static PHP_METHOD(Phalcon_Db_Adapter, dropColumn){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt_Compiler, parse){ - zval *table_name, *schema_name, *column_name; - zval *dialect, *sql; + zval *view_code, *current_path; 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_fetch_params(1, 1, 0, &view_code); - PHALCON_INIT_VAR(sql); - phalcon_call_method_p3_key(sql, dialect, "dropcolumn", table_name, schema_name, column_name, 2125320424UL); -======= - phalcon_call_method_p3_key(sql, dialect, "droptable", table_name, schema_name, if_exists, 3706194946UL); ->>>>>>> 1.2.2 - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); + 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(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Adapter, addIndex){ - zval *table_name, *schema_name, *index, *dialect; - zval *sql; - PHALCON_MM_GROW(); +/* Generated by re2c 0.13.5 on Fri Jun 28 19:17:30 2013 */ +// 1 "scanner.re" - 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); -======= -static PHP_METHOD(Phalcon_Db_Adapter, createView){ - zval *view_name, *definition, *schema_name = NULL, *exception_message; - zval *dialect, *sql; +#ifdef HAVE_CONFIG_H +#endif - 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); ->>>>>>> 1.2.2 - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); -} -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Adapter, dropIndex){ +#define KKCTYPE unsigned char +#define KKCURSOR (s->start) +#define KKLIMIT (s->end) +#define KKMARKER q - zval *table_name, *schema_name, *index_name; - zval *dialect, *sql; +static void phvolt_rtrim(phvolt_scanner_token *token) { - PHALCON_MM_GROW(); + char *cursor, *removed_str; + unsigned int i; + unsigned char ch; - 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); -======= -static PHP_METHOD(Phalcon_Db_Adapter, dropView){ + if (token->len > 0) { - zval *view_name, *schema_name = NULL, *if_exists = NULL, *dialect; - zval *sql; + 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; + } - PHALCON_MM_GROW(); + removed_str = emalloc(i + 1); + memcpy(removed_str, token->value, i); + removed_str[i] = '\0'; - 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); + efree(token->value); + token->value = removed_str; + token->len = i; } - - 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); ->>>>>>> 1.2.2 - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); + } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Adapter, addPrimaryKey){ +static void phvolt_ltrim(phvolt_scanner_token *token) { - zval *table_name, *schema_name, *index, *dialect; -======= -static PHP_METHOD(Phalcon_Db_Adapter, addColumn){ + char *cursor, *removed_str; + unsigned int i; + unsigned char ch; - zval *table_name, *schema_name, *column, *dialect; ->>>>>>> 1.2.2 - zval *sql; + if (token->len > 0) { - PHALCON_MM_GROW(); + 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; + } -<<<<<<< HEAD - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); -======= - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); ->>>>>>> 1.2.2 - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); -<<<<<<< HEAD - phalcon_call_method_p3_key(sql, dialect, "addprimarykey", table_name, schema_name, index, 1640564219UL); -======= - phalcon_call_method_p3_key(sql, dialect, "addcolumn", table_name, schema_name, column, 1469620764UL); ->>>>>>> 1.2.2 - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); -} + removed_str = emalloc(token->len - i + 1); + memcpy(removed_str, token->value + i, token->len - i); + removed_str[token->len - i] = '\0'; -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Adapter, dropPrimaryKey){ + efree(token->value); + token->value = removed_str; + token->len = token->len - i; + } - zval *table_name, *schema_name, *dialect, *sql; +} - PHALCON_MM_GROW(); +static int phvolt_get_token(phvolt_scanner_state *s, phvolt_scanner_token *token) { - phalcon_fetch_params(1, 2, 0, &table_name, &schema_name); -======= -static PHP_METHOD(Phalcon_Db_Adapter, modifyColumn){ + unsigned char next, double_next; + char *q = KKCURSOR, *start = KKCURSOR; + int status = PHVOLT_SCANNER_RETCODE_IMPOSSIBLE; - zval *table_name, *schema_name, *column, *dialect; - zval *sql; + while (PHVOLT_SCANNER_RETCODE_IMPOSSIBLE == status) { - PHALCON_MM_GROW(); + if (s->mode == PHVOLT_MODE_RAW || s->mode == PHVOLT_MODE_COMMENT) { - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); ->>>>>>> 1.2.2 - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); -<<<<<<< HEAD - phalcon_call_method_p2_key(sql, dialect, "dropprimarykey", table_name, schema_name, 1513142983UL); -======= - phalcon_call_method_p3_key(sql, dialect, "modifycolumn", table_name, schema_name, column, 382554075UL); ->>>>>>> 1.2.2 - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); -} + next = '\0'; + double_next = '\0'; -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Adapter, addForeignKey){ + if (*KKCURSOR == '\n') { + s->active_line++; + } - zval *table_name, *schema_name, *reference, *dialect; - zval *sql; + if (*KKCURSOR != '\0') { + next = *(KKCURSOR + 1); + if (next != '\0') { + double_next = *(KKCURSOR + 2); + } + } - PHALCON_MM_GROW(); + if (*KKCURSOR == '\0' || (*KKCURSOR == '{' && (next == '%' || next == '{' || next == '#'))) { - phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference); -======= -static PHP_METHOD(Phalcon_Db_Adapter, dropColumn){ + if (next != '#') { - zval *table_name, *schema_name, *column_name; - zval *dialect, *sql; + s->mode = PHVOLT_MODE_CODE; - PHALCON_MM_GROW(); + if (s->raw_buffer_cursor > 0) { - 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(); -} + 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; -static PHP_METHOD(Phalcon_Db_Adapter, addIndex){ + if (s->whitespace_control == 1) { + phvolt_ltrim(token); + s->whitespace_control = 0; + } - zval *table_name, *schema_name, *index, *dialect; - zval *sql; + if (double_next == '-') { + phvolt_rtrim(token); + } - PHALCON_MM_GROW(); + s->raw_buffer_cursor = 0; + q = KKCURSOR; + } else { + token->opcode = PHVOLT_T_IGNORE; + } - 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(); -} + } else { -static PHP_METHOD(Phalcon_Db_Adapter, dropIndex){ + while ((next = *(++KKCURSOR))) { + if (next == '#' && *(KKCURSOR + 1) == '}') { + KKCURSOR+=2; + token->opcode = PHVOLT_T_IGNORE; + return 0; + } else { + if (next == '\n') { + s->active_line++; + } + } + } - zval *table_name, *schema_name, *index_name; - zval *dialect, *sql; + return PHVOLT_SCANNER_RETCODE_EOF; + } - PHALCON_MM_GROW(); + return 0; - 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(); -} + } else { -static PHP_METHOD(Phalcon_Db_Adapter, addPrimaryKey){ + 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); + } - zval *table_name, *schema_name, *index, *dialect; - zval *sql; + memcpy(s->raw_buffer+s->raw_buffer_cursor, KKCURSOR, 1); + s->raw_buffer_cursor++; - PHALCON_MM_GROW(); + ++KKCURSOR; + } - 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(); -} + } else { -static PHP_METHOD(Phalcon_Db_Adapter, dropPrimaryKey){ + +// 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; + } +// 637 "scanner.c" +kk46: + ++KKCURSOR; +// 518 "scanner.re" + { + token->opcode = PHVOLT_T_PARENTHESES_CLOSE; + return 0; + } +// 645 "scanner.c" +kk48: + ++KKCURSOR; +// 523 "scanner.re" + { + token->opcode = PHVOLT_T_SBRACKET_OPEN; + return 0; + } +// 653 "scanner.c" +kk50: + ++KKCURSOR; +// 528 "scanner.re" + { + token->opcode = PHVOLT_T_SBRACKET_CLOSE; + return 0; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +kk75: + ++KKCURSOR; + switch ((kkch = *KKCURSOR)) { + case '=': goto kk77; + default: goto kk76; + } +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; + } +// 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; + } +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; + } +// 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; + } +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; + } +// 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; + } +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; + } +// 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; + } +// 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; + } +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; + } +// 1103 "scanner.c" +kk128: + ++KKCURSOR; +// 400 "scanner.re" + { + s->whitespace_control = 0; + token->opcode = PHVOLT_T_OPEN_DELIMITER; + return 0; + } +// 1112 "scanner.c" +kk130: + ++KKCURSOR; +// 426 "scanner.re" + { + s->whitespace_control = 0; + s->statement_position++; + token->opcode = PHVOLT_T_OPEN_EDELIMITER; + return 0; + } +// 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; + } +kk146: +// 312 "scanner.re" + { + token->opcode = PHVOLT_T_RETURN; + return 0; + } +// 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; + } +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; + } +// 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; + } +// 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; + } +// 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; + } +kk171: +// 285 "scanner.re" + { + s->statement_position++; + token->opcode = PHVOLT_T_MACRO; + return 0; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +// 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; + } +kk281: +// 239 "scanner.re" + { + token->opcode = PHVOLT_T_IN; + return 0; + } +// 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; + } +// 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; + } +// 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" - zval *table_name, *schema_name, *dialect, *sql; - PHALCON_MM_GROW(); + } + } - phalcon_fetch_params(1, 2, 0, &table_name, &schema_name); ->>>>>>> 1.2.2 - - PHALCON_OBS_VAR(dialect); - phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - - PHALCON_INIT_VAR(sql); -<<<<<<< HEAD - phalcon_call_method_p3_key(sql, dialect, "addforeignkey", table_name, schema_name, reference, 599632289UL); -======= - phalcon_call_method_p2_key(sql, dialect, "dropprimarykey", table_name, schema_name, 1513142983UL); ->>>>>>> 1.2.2 - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); + return status; } -<<<<<<< HEAD -======= -static PHP_METHOD(Phalcon_Db_Adapter, addForeignKey){ - zval *table_name, *schema_name, *reference, *dialect; - zval *sql; +/* 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" - 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 ->>>>>>> 1.2.2 -static PHP_METHOD(Phalcon_Db_Adapter, dropForeignKey){ - zval *table_name, *schema_name, *reference_name; - zval *dialect, *sql; - 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_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(); -} -static PHP_METHOD(Phalcon_Db_Adapter, getColumnDefinition){ +static zval *phvolt_ret_literal_zval(int type, phvolt_parser_token *T, phvolt_scanner_state *state) +{ + zval *ret; - zval *column, *dialect; + 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_MM_GROW(); + 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, 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(); + return ret; } -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; +static zval *phvolt_ret_if_statement(zval *expr, zval *true_statements, zval *false_statements, phvolt_scanner_state *state) +{ + zval *ret; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_IF); + add_assoc_zval(ret, "expr", expr); - phalcon_fetch_params(1, 0, 1, &schema_name); - - if (!schema_name) { - PHALCON_INIT_VAR(schema_name); + if (true_statements) { + add_assoc_zval(ret, "true_statements", true_statements); } - - 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); + if (false_statements) { + add_assoc_zval(ret, "false_statements", false_statements); } - - 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(); + 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, 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); + return ret; } -static PHP_METHOD(Phalcon_Db_Adapter, describeIndexes){ -<<<<<<< HEAD - - 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_MM_GROW(); - -======= +static zval *phvolt_ret_elseif_statement(zval *expr, phvolt_scanner_state *state) +{ + zval *ret; - 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; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_ELSEIF); + add_assoc_zval(ret, "expr", expr); - PHALCON_MM_GROW(); + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); ->>>>>>> 1.2.2 - 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 ret; } -static PHP_METHOD(Phalcon_Db_Adapter, describeReferences){ +static zval *phvolt_ret_elsefor_statement(phvolt_scanner_state *state) +{ + zval *ret; - 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; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_ELSEFOR); - PHALCON_MM_GROW(); + 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, 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); -<<<<<<< HEAD - } - - 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); + return ret; } -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(); -} +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; -static PHP_METHOD(Phalcon_Db_Adapter, createSavepoint){ -======= - } - - 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); -} + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_FOR); -static PHP_METHOD(Phalcon_Db_Adapter, tableOptions){ + add_assoc_stringl(ret, "variable", variable->token, variable->token_len, 0); + efree(variable); - zval *table_name, *schema_name = NULL, *dialect, *sql; - zval *fetch_assoc, *describe, *first; + if (key) { + add_assoc_stringl(ret, "key", key->token, key->token_len, 0); + efree(key); + } - PHALCON_MM_GROW(); + add_assoc_zval(ret, "expr", expr); - 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); + if (if_expr) { + add_assoc_zval(ret, "if_expr", if_expr); } - - RETURN_MM_EMPTY_ARRAY(); + + 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 PHP_METHOD(Phalcon_Db_Adapter, createSavepoint){ +static zval *phvolt_ret_cache_statement(zval *expr, phvolt_parser_token *lifetime, zval *block_statements, phvolt_scanner_state *state) +{ + zval *ret; - zval *name, *dialect, *supports_sp, *sql; + MAKE_STD_ZVAL(ret); + array_init(ret); - PHALCON_MM_GROW(); + add_assoc_long(ret, "type", PHVOLT_T_CACHE); + add_assoc_zval(ret, "expr", expr); - 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; + if (lifetime) { + add_assoc_stringl(ret, "lifetime", lifetime->token, lifetime->token_len, 0); + efree(lifetime); } - - 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(); + 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 PHP_METHOD(Phalcon_Db_Adapter, releaseSavepoint){ +static zval *phvolt_ret_set_statement(zval *assignments) +{ + zval *ret; - zval *name, *dialect, *supports_sp, *supports_rsp; - zval *sql; + MAKE_STD_ZVAL(ret); + array_init_size(ret, 2); + add_assoc_long(ret, "type", PHVOLT_T_SET); - PHALCON_MM_GROW(); + add_assoc_zval(ret, "assignments", assignments); - 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(); + return ret; } -static PHP_METHOD(Phalcon_Db_Adapter, rollbackSavepoint){ ->>>>>>> 1.2.2 +static zval *phvolt_ret_set_assignment(phvolt_parser_token *variable, int operator, zval *expr, phvolt_scanner_state *state) +{ - zval *name, *dialect, *supports_sp, *sql; + zval *ret; - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init_size(ret, 5); - 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)) { -<<<<<<< HEAD - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Savepoints are not supported by this database adapter."); -======= - PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Savepoints are not supported by this database adapter"); ->>>>>>> 1.2.2 - return; - } - - PHALCON_INIT_VAR(sql); -<<<<<<< HEAD - phalcon_call_method_p1_key(sql, dialect, "createsavepoint", name, 2980652562UL); -======= - phalcon_call_method_p1_key(sql, dialect, "rollbacksavepoint", name, 3444395528UL); ->>>>>>> 1.2.2 - phalcon_call_method_p1_key(return_value, this_ptr, "execute", sql, 3117639032UL); - RETURN_MM(); -} + add_assoc_stringl(ret, "variable", variable->token, variable->token_len, 0); + efree(variable); -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Adapter, releaseSavepoint){ + add_assoc_long(ret, "op", operator); - zval *name, *dialect, *supports_sp, *supports_rsp; - zval *sql; + add_assoc_zval(ret, "expr", expr); - PHALCON_MM_GROW(); + 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, 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(); + return ret; } -static PHP_METHOD(Phalcon_Db_Adapter, rollbackSavepoint){ +static zval *phvolt_ret_echo_statement(zval *expr, phvolt_scanner_state *state) +{ + zval *ret; - zval *name, *dialect, *supports_sp, *sql; + MAKE_STD_ZVAL(ret); + array_init_size(ret, 4); + add_assoc_long(ret, "type", PHVOLT_T_ECHO); + add_assoc_zval(ret, "expr", expr); - PHALCON_MM_GROW(); + 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, 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(); + return ret; } -static PHP_METHOD(Phalcon_Db_Adapter, setNestedTransactionsWithSavepoints){ +static zval *phvolt_ret_block_statement(phvolt_parser_token *name, zval *block_statements, phvolt_scanner_state *state) +{ + zval *ret; - zval *nested_transactions_with_savepoints; - zval *transaction_level, *dialect, *supports_sp; + MAKE_STD_ZVAL(ret); + array_init(ret); - PHALCON_MM_GROW(); + add_assoc_long(ret, "type", PHVOLT_T_BLOCK); - 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; + add_assoc_stringl(ret, "name", name->token, name->token_len, 0); + efree(name); + + if (block_statements) { + add_assoc_zval(ret, "block_statements", block_statements); } - - phalcon_update_property_this_quick(this_ptr, SL("_transactionsWithSavepoints"), nested_transactions_with_savepoints, 2137960997UL TSRMLS_CC); - - RETURN_THIS(); + + 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_Db_Adapter, isNestedTransactionsWithSavepoints){ -======= -static PHP_METHOD(Phalcon_Db_Adapter, setNestedTransactionsWithSavepoints){ +static zval *phvolt_ret_macro_statement(phvolt_parser_token *macro_name, zval *parameters, zval *block_statements, phvolt_scanner_state *state) +{ + zval *ret; - zval *nested_transactions_with_savepoints; - zval *transaction_level, *dialect, *supports_sp; + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_MACRO); - PHALCON_MM_GROW(); + add_assoc_stringl(ret, "name", macro_name->token, macro_name->token_len, 0); + efree(macro_name); - 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; + if (parameters) { + add_assoc_zval(ret, "parameters", parameters); } - - 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){ + 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_MEMBER_QUICK(this_ptr, "_transactionsWithSavepoints", 2137960997UL); + return ret; } -static PHP_METHOD(Phalcon_Db_Adapter, getNestedTransactionSavepointName){ +static zval *phvolt_ret_macro_parameter(phvolt_parser_token *variable, zval *default_value, phvolt_scanner_state *state) +{ + zval *ret; - zval *transaction_level; + MAKE_STD_ZVAL(ret); + array_init_size(ret, 5); - PHALCON_MM_GROW(); + add_assoc_stringl(ret, "variable", variable->token, variable->token_len, 0); + efree(variable); - 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(); + 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 PHP_METHOD(Phalcon_Db_Adapter, getDefaultIdValue){ ->>>>>>> 1.2.2 +static zval *phvolt_ret_extends_statement(phvolt_parser_token *P, phvolt_scanner_state *state) +{ + zval *ret; - zval *null_value; + MAKE_STD_ZVAL(ret); + array_init_size(ret, 4); -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_transactionsWithSavepoints", 2137960997UL); + 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 PHP_METHOD(Phalcon_Db_Adapter, getNestedTransactionSavepointName){ +static zval *phvolt_ret_include_statement(zval *path, zval *params, phvolt_scanner_state *state) +{ + zval *ret; - zval *transaction_level; -======= - PHALCON_MM_GROW(); + MAKE_STD_ZVAL(ret); + array_init_size(ret, 4); - 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(); -} + add_assoc_long(ret, "type", PHVOLT_T_INCLUDE); -static PHP_METHOD(Phalcon_Db_Adapter, supportSequences){ ->>>>>>> 1.2.2 + add_assoc_zval(ret, "path", path); + if (params) { + add_assoc_zval(ret, "params", params); + } - PHALCON_MM_GROW(); + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); -<<<<<<< HEAD - 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(); + return ret; } -static PHP_METHOD(Phalcon_Db_Adapter, getDefaultIdValue){ -======= - RETURN_FALSE; -} +static zval *phvolt_ret_do_statement(zval *expr, phvolt_scanner_state *state) +{ + zval *ret; -static PHP_METHOD(Phalcon_Db_Adapter, useExplicitIdValue){ ->>>>>>> 1.2.2 + MAKE_STD_ZVAL(ret); + array_init_size(ret, 4); - zval *null_value; + add_assoc_long(ret, "type", PHVOLT_T_DO); -<<<<<<< HEAD - PHALCON_MM_GROW(); + add_assoc_zval(ret, "expr", expr); - 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(); + 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_Db_Adapter, supportSequences){ +static zval *phvolt_ret_return_statement(zval *expr, phvolt_scanner_state *state) +{ + zval *ret; + MAKE_STD_ZVAL(ret); + array_init_size(ret, 4); - RETURN_FALSE; -} + add_assoc_long(ret, "type", PHVOLT_T_RETURN); -static PHP_METHOD(Phalcon_Db_Adapter, useExplicitIdValue){ + 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_FALSE; + return ret; } -static PHP_METHOD(Phalcon_Db_Adapter, getDescriptor){ -======= - RETURN_FALSE; -} +static zval *phvolt_ret_autoescape_statement(int enable, zval *block_statements, phvolt_scanner_state *state) +{ + zval *ret; -static PHP_METHOD(Phalcon_Db_Adapter, getDescriptor){ + 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); - RETURN_MEMBER_QUICK(this_ptr, "_descriptor", 691635363UL); + 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_Db_Adapter, getConnectionId){ +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); - RETURN_MEMBER_QUICK(this_ptr, "_connectionId", 802624385UL); + 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_Db_Adapter, getSQLStatement){ +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_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); + return ret; } -static PHP_METHOD(Phalcon_Db_Adapter, getRealSQLStatement){ +static zval *phvolt_ret_continue_statement(phvolt_scanner_state *state) +{ + zval *ret; ->>>>>>> 1.2.2 + MAKE_STD_ZVAL(ret); + array_init_size(ret, 3); + add_assoc_long(ret, "type", PHVOLT_T_CONTINUE); - RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); -} + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); -<<<<<<< HEAD - RETURN_MEMBER_QUICK(this_ptr, "_descriptor", 691635363UL); + return ret; } -static PHP_METHOD(Phalcon_Db_Adapter, getConnectionId){ -======= -static PHP_METHOD(Phalcon_Db_Adapter, getSQLVariables){ +static zval *phvolt_ret_zval_list(zval *list_left, zval *right_list) +{ + zval *ret; + HashPosition pos; + HashTable *list; - RETURN_MEMBER_QUICK(this_ptr, "_sqlVariables", 3213579853UL); -} ->>>>>>> 1.2.2 + MAKE_STD_ZVAL(ret); + array_init(ret); -static PHP_METHOD(Phalcon_Db_Adapter, getSQLBindTypes){ + if (list_left) { - RETURN_MEMBER_QUICK(this_ptr, "_connectionId", 802624385UL); -} + 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)) { -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Adapter, getSQLStatement){ -======= - RETURN_MEMBER_QUICK(this_ptr, "_sqlBindTypes", 3288357222UL); -} ->>>>>>> 1.2.2 + zval ** item; -static PHP_METHOD(Phalcon_Db_Adapter, getType){ + if (zend_hash_get_current_data_ex(list, (void**) &item, &pos) == FAILURE) { + break; + } - RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); -} + Z_ADDREF_PP(item); + add_next_index_zval(ret, *item); -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Adapter, getRealSQLStatement){ + } + zval_ptr_dtor(&list_left); + } else { + add_next_index_zval(ret, list_left); + } + } + add_next_index_zval(ret, right_list); - RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); -======= - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); + return ret; } -static PHP_METHOD(Phalcon_Db_Adapter, getDialectType){ +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_MEMBER_QUICK(this_ptr, "_dialectType", 1868597628UL); ->>>>>>> 1.2.2 + return ret; } -static PHP_METHOD(Phalcon_Db_Adapter, getSQLVariables){ - - - RETURN_MEMBER_QUICK(this_ptr, "_sqlVariables", 3213579853UL); -} +static zval *phvolt_ret_expr(int type, zval *left, zval *right, zval *ternary, phvolt_scanner_state *state) +{ + zval *ret; -static PHP_METHOD(Phalcon_Db_Adapter, getSQLBindTypes){ + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", type); + if (ternary) { + add_assoc_zval(ret, "ternary", ternary); + } - RETURN_MEMBER_QUICK(this_ptr, "_sqlBindTypes", 3288357222UL); -} + if (left) { + add_assoc_zval(ret, "left", left); + } -static PHP_METHOD(Phalcon_Db_Adapter, getType){ + 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_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); + return ret; } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Adapter, getDialectType){ +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); -PHALCON_INIT_CLASS(Phalcon_Db_Dialect){ + if (start != NULL) { + add_assoc_zval(ret, "start", start); + } - PHALCON_REGISTER_CLASS(Phalcon\\Db, Dialect, db_dialect, phalcon_db_dialect_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + if (end != NULL) { + add_assoc_zval(ret, "end", end); + } - zend_declare_property_null(phalcon_db_dialect_ce, SL("_escapeChar"), ZEND_ACC_PROTECTED TSRMLS_CC); ->>>>>>> 1.2.2 + Z_ADDREF_P(state->active_file); + add_assoc_zval(ret, "file", state->active_file); + add_assoc_long(ret, "line", state->active_line); - RETURN_MEMBER_QUICK(this_ptr, "_dialectType", 1868597628UL); + return ret; } -static PHP_METHOD(Phalcon_Db_Dialect, limit){ +static zval *phvolt_ret_func_call(zval *expr, zval *arguments, phvolt_scanner_state *state) +{ - zval *sql_query, *number, *limit; + 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, 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(); + if (arguments) { + add_assoc_zval(ret, "arguments", arguments); } - - RETURN_CCTOR(sql_query); -} - -static PHP_METHOD(Phalcon_Db_Dialect, forUpdate){ - zval *sql_query; + 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, &sql_query); - - PHALCON_CONCAT_VS(return_value, sql_query, " FOR UPDATE"); - return; + return ret; } -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 zval *phvolt_ret_macro_call_statement(zval *expr, zval *arguments, zval *caller, phvolt_scanner_state *state) +{ -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Db_Dialect){ + zval *ret; - PHALCON_REGISTER_CLASS(Phalcon\\Db, Dialect, db_dialect, phalcon_db_dialect_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + MAKE_STD_ZVAL(ret); + array_init(ret); + add_assoc_long(ret, "type", PHVOLT_T_CALL); + add_assoc_zval(ret, "name", expr); - zend_declare_property_null(phalcon_db_dialect_ce, SL("_escapeChar"), ZEND_ACC_PROTECTED TSRMLS_CC); -======= -static PHP_METHOD(Phalcon_Db_Dialect, getColumnList){ + if (arguments) { + add_assoc_zval(ret, "arguments", arguments); + } - zval *column_list, *str_list, *escape_char, *column = NULL; - zval *column_quoted = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + if (caller) { + add_assoc_zval(ret, "caller", caller); + } - PHALCON_MM_GROW(); ->>>>>>> 1.2.2 + 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, 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(); + return ret; } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Db_Dialect, limit){ - zval *sql_query, *number, *limit; +// 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])) - 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 KKFALLBACK +static const KKCODETYPE kkFallback[] = { +}; +#endif /* KKFALLBACK */ - 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); -} +/* 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; -static PHP_METHOD(Phalcon_Db_Dialect, forUpdate){ +/* 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; - zval *sql_query; +#ifndef NDEBUG +#include +static FILE *kkTraceFILE = 0; +static char *kkTracePrompt = 0; +#endif /* NDEBUG */ - phalcon_fetch_params(0, 1, 0, &sql_query); - - PHALCON_CONCAT_VS(return_value, sql_query, " FOR UPDATE"); - return; +#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_Db_Dialect, sharedLock){ +#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 *sql_query; +#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_fetch_params(0, 1, 0, &sql_query); - - PHALCON_CONCAT_VS(return_value, sql_query, " LOCK IN SHARE MODE"); - return; +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 } -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(); +void *phvolt_Alloc(void *(*mallocProc)(size_t)){ + kkParser *pParser; + pParser = (kkParser*)(*mallocProc)( (size_t)sizeof(kkParser) ); + if( pParser ){ + pParser->kkidx = -1; + } + return pParser; } -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); - } - } - 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(); - } - - 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(); - } - } - - 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); -======= -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); - } - } - 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(); - } - - 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(); - } - } - - 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(); - } - } - - 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); - } - - 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(); +/* 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_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; +} +// 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_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(); +static int kk_pop_parser_stack(kkParser *pParser){ + KKCODETYPE kkmajor; + kkStackEntry *kktos = &pParser->kkstack[pParser->kkidx]; - 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); ->>>>>>> 1.2.2 - } - if (Z_TYPE_P(table) == IS_ARRAY) { - -<<<<<<< HEAD - 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(); - } - } - - 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); - } - - 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; + 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_Db_Dialect, getSqlTable){ +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); +} - zval *table, *escape_char = NULL, *table_name, *sql_table = NULL; - zval *schema_name, *sql_schema = NULL, *alias_name; - zval *sql_table_alias = NULL; +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, 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); - } - } else { - 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, " 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); - } - - 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 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_Db_Dialect, select){ +/* 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 *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; +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); +} +// 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); } - -static PHP_METHOD(Phalcon_Db_Dialect, supportsSavepoints){ - - - RETURN_TRUE; +// 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_Db_Dialect, supportsReleaseSavepoints){ - - - PHALCON_MM_GROW(); - - phalcon_call_method_key(return_value, this_ptr, "supportssavepoints", 1063347073UL); - RETURN_MM(); +// 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_Db_Dialect, createSavepoint){ - - zval *name; - - phalcon_fetch_params(0, 1, 0, &name); - - PHALCON_CONCAT_SV(return_value, "SAVEPOINT ", name); - return; +// 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); } - -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; +// 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_Db_Dialect, rollbackSavepoint){ - - zval *name; - - phalcon_fetch_params(0, 1, 0, &name); - - PHALCON_CONCAT_SV(return_value, "ROLLBACK TO SAVEPOINT ", name); - return; +// 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); } - - - - - -#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; +// 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); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Db_DialectInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, DialectInterface, db_dialectinterface, phalcon_db_dialectinterface_method_entry); - - return SUCCESS; +// 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); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -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); - - return SUCCESS; +// 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); } - -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); +// 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); } - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -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_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); - } - } else { - 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, " 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); - } - - 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); +// 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); } - -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); - } - - 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); - } - - } - - 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); - - 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); - } - - 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); - - 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); - } - - 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); - } - } - - RETURN_CTOR(sql); +// 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); } - -static PHP_METHOD(Phalcon_Db_Dialect, supportsSavepoints){ - - - RETURN_TRUE; +// 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); } - -static PHP_METHOD(Phalcon_Db_Dialect, supportsReleaseSavepoints){ - - - PHALCON_MM_GROW(); - - phalcon_call_method_key(return_value, this_ptr, "supportssavepoints", 1063347073UL); - RETURN_MM(); +// 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); } - -static PHP_METHOD(Phalcon_Db_Dialect, createSavepoint){ - - zval *name; - - phalcon_fetch_params(0, 1, 0, &name); - - PHALCON_CONCAT_SV(return_value, "SAVEPOINT ", name); - return; +// 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); } - -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; +// 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); } - -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; +// 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_Db_AdapterInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, AdapterInterface, db_adapterinterface, phalcon_db_adapterinterface_method_entry); - - 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); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Db_DialectInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Db, DialectInterface, db_dialectinterface, phalcon_db_dialectinterface_method_entry); - - return SUCCESS; +// 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); } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -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); - - return SUCCESS; +// 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_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); +// 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); } - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -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); - } - } +// 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); } - -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; +// 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); } - -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(process_sections); - ZVAL_BOOL(process_sections, 1); - - PHALCON_INIT_VAR(ini_config); - phalcon_call_func_p2(ini_config, "parse_ini_file", file_path, process_sections); - - 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(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; - } - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HKEY(key, ah1, hp1); - PHALCON_GET_HVALUE(value); - - 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); - } - - zend_hash_move_forward_ex(ah1, &hp1); ->>>>>>> 1.2.2 - } - - zend_hash_move_forward_ex(ah0, &hp0); - } -<<<<<<< HEAD +// 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); } - -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; +// 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_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_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Config\\Adapter\\Ini", "__construct", config); - - PHALCON_MM_RESTORE(); +// 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); } - - ->>>>>>> 1.2.2 - - -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 0, &file_path); - - PHALCON_INIT_VAR(process_sections); - ZVAL_BOOL(process_sections, 1); - - PHALCON_INIT_VAR(ini_config); - phalcon_call_func_p2(ini_config, "parse_ini_file", file_path, process_sections); - - 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(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; - } - - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - - PHALCON_GET_HKEY(key, ah1, hp1); - PHALCON_GET_HVALUE(value); - - 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); - } - - zend_hash_move_forward_ex(ah1, &hp1); - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - - PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Config\\Adapter\\Ini", "__construct", config); - - PHALCON_MM_RESTORE(); +// 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); } - - - - -======= ->>>>>>> 1.2.2 - -#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; +// 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); } - - - - - -#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; +// 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); } - - - - - -#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; +// 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_Session_Bag, __construct){ - - zval *name; - - 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); -<<<<<<< HEAD - +// 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_Session_Bag, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); - -======= - +// 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_Session_Bag, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); - ->>>>>>> 1.2.2 - 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); - +// 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_Session_Bag, getDI){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); +// 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_Session_Bag, initialize){ - - zval *session = NULL, *dependency_injector = NULL, *service; - zval *name, *data = 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(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_session_exception_ce, "A dependency injection object is required to access the 'session' service"); - return; - } - } -<<<<<<< HEAD - - 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(); +// 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); } - -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); - } - - 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(); +// 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_Session_Bag, set){ - - zval *property, *value, *initalized, *name, *data; - zval *session; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &property, &value); - - 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_update_property_array(this_ptr, SL("_data"), property, value 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(); +// 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_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); - } ->>>>>>> 1.2.2 - - PHALCON_OBS_VAR(name); - phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - -<<<<<<< HEAD - 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(); +// 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_Session_Bag, get){ - - zval *property, *default_value = NULL, *initalized; - zval *data, *value; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &property, &default_value); - - if (!default_value) { - PHALCON_INIT_VAR(default_value); - } - - 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); +// 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 PHP_METHOD(Phalcon_Session_Bag, has){ - - zval *property, *initalized, *data; - - PHALCON_MM_GROW(); - - 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 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" -static PHP_METHOD(Phalcon_Session_Bag, remove){ + { - zval *property, *data = NULL, *name, *session; + smart_str error_str = {0}; - PHALCON_MM_GROW(); + char *token_name = NULL; + const phvolt_token_names *tokens = phvolt_tokens; + int token_len = 0; + int active_token = status->scanner_state->active_token; - 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; -} + 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); + } -#ifdef HAVE_CONFIG_H -#endif + } 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); + } + } + /* 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); + } + } + } + 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; + } -PHALCON_INIT_CLASS(Phalcon_Session_Exception){ + } - PHALCON_REGISTER_CLASS_EX(Phalcon\\Session, Exception, session_exception, "phalcon\\exception", NULL, 0); + status->status = PHVOLT_PARSING_FAILED; - return SUCCESS; +// 3094 "parser.c" + phvolt_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ } - - - - -#ifdef HAVE_CONFIG_H +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; -PHALCON_INIT_CLASS(Phalcon_Session_BagInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Session, BagInterface, session_baginterface, phalcon_session_baginterface_method_entry); +#ifndef NDEBUG + if( kkTraceFILE ){ + fprintf(kkTraceFILE,"%sInput %s\n",kkTracePrompt,kkTokenName[kkmajor]); + } +#endif - return SUCCESS; + 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'; -#ifdef HAVE_CONFIG_H -#endif - + 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; -PHALCON_INIT_CLASS(Phalcon_Session_Adapter){ + ZVAL_NULL(result); - PHALCON_REGISTER_CLASS(Phalcon\\Session, Adapter, session_adapter, phalcon_session_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + 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; + } - 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); + 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 PHP_METHOD(Phalcon_Session_Adapter, __construct){ - - zval *options = NULL; +static int phvolt_is_blank_string(phvolt_scanner_token *token){ - PHALCON_MM_GROW(); + char *marker = token->value; + unsigned int ch, i; - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_call_method_p1_key(NULL, this_ptr, "setoptions", options, 1759822653UL); + for (i = 0; i < token->len; i++) { + ch = *marker; + if (ch != ' ' && ch != '\t' && ch != '\n' && ch != '\r' && ch != 11) { + return 0; + } + marker++; } - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Session_Adapter, start){ - - if (!SG(headers_sent)) { - phalcon_session_start(TSRMLS_C); - phalcon_update_property_bool(this_ptr, SL("_started"), 1 TSRMLS_CC); - RETURN_TRUE; - } - - RETURN_FALSE; + return 1; } -static PHP_METHOD(Phalcon_Session_Adapter, setOptions){ - - zval *options, *unique_id; +static int phvolt_internal_parse_view(zval **result, zval *view_code, zval *template_path, zval **error_msg TSRMLS_DC) { - PHALCON_MM_GROW(); + char *error; + phvolt_scanner_state *state; + phvolt_scanner_token token; + int scanner_status, status = SUCCESS; + phvolt_parser_status *parser_status = NULL; + void* phvolt_parser; - 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; + /** 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 (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); + + if (!Z_STRLEN_P(view_code)) { + array_init(*result); + return SUCCESS; } - - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Session_Adapter, getOptions){ + /** Start the reentrant parser */ + phvolt_parser = phvolt_Alloc(phvolt_wrapper_alloc); - zval *options; + parser_status = emalloc(sizeof(phvolt_parser_status)); + state = emalloc(sizeof(phvolt_scanner_state)); - PHALCON_MM_GROW(); + parser_status->status = PHVOLT_PARSING_OK; + parser_status->scanner_state = state; + parser_status->ret = NULL; + parser_status->token = &token; + parser_status->syntax_error = NULL; - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - RETURN_CCTOR(options); -} + /** 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; -static PHP_METHOD(Phalcon_Session_Adapter, get){ + state->end = state->start; - zval *index, *default_value = NULL, *unique_id, *key, *_SESSION; - zval *value; + token.value = NULL; + token.len = 0; - PHALCON_MM_GROW(); + while (0 <= (scanner_status = phvolt_get_token(state, &token))) { - phalcon_fetch_params(1, 1, 1, &index, &default_value); - - if (!default_value) { - PHALCON_INIT_VAR(default_value); -======= - 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(); -} + state->active_token = token.opcode; -static PHP_METHOD(Phalcon_Session_Bag, set){ + state->start_length = (Z_STRVAL_P(view_code) + Z_STRLEN_P(view_code) - state->start); - zval *property, *value, *initalized, *name, *data; - zval *session; + switch (token.opcode) { - PHALCON_MM_GROW(); + case PHVOLT_T_IGNORE: + break; - phalcon_fetch_params(1, 2, 0, &property, &value); - - 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_update_property_array(this_ptr, SL("_data"), property, value TSRMLS_CC); - - 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(); -} + 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; -static PHP_METHOD(Phalcon_Session_Bag, get){ + 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 *property, *default_value = NULL, *initalized; - zval *data, *value; + 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_fetch_params(1, 1, 1, &property, &default_value); - - if (!default_value) { - PHALCON_INIT_VAR(default_value); - } - - 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); -} + 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; -static PHP_METHOD(Phalcon_Session_Bag, has){ + case PHVOLT_T_ELSEFOR: + phvolt_(phvolt_parser, PHVOLT_ELSEFOR, NULL, parser_status); + break; - zval *property, *initalized, *data; + 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, 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; -} + 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; -static PHP_METHOD(Phalcon_Session_Bag, remove){ + 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; - zval *property, *data = NULL, *name, *session; + 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_MM_GROW(); + 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; - 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; -} + 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; -#ifdef HAVE_CONFIG_H -#endif + 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; -PHALCON_INIT_CLASS(Phalcon_Session_Exception){ + case PHVOLT_T_BREAK: + phvolt_(phvolt_parser, PHVOLT_BREAK, NULL, parser_status); + break; - PHALCON_REGISTER_CLASS_EX(Phalcon\\Session, Exception, session_exception, "phalcon\\exception", NULL, 0); + case PHVOLT_T_CONTINUE: + phvolt_(phvolt_parser, PHVOLT_CONTINUE, NULL, parser_status); + break; - return SUCCESS; -} + 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; + } + 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); + } + } -#ifdef HAVE_CONFIG_H -#endif + 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); + } + efree(parser_status->syntax_error); + } + } + phvolt_Free(phvolt_parser, phvolt_wrapper_free); -PHALCON_INIT_CLASS(Phalcon_Session_BagInterface){ + 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); + } + } + } - PHALCON_REGISTER_INTERFACE(Phalcon\\Session, BagInterface, session_baginterface, phalcon_session_baginterface_method_entry); + efree(parser_status); + efree(state); - return SUCCESS; + return status; } - - - - - - - - - #ifdef HAVE_CONFIG_H #endif @@ -135008,1020 +62520,1195 @@ PHALCON_INIT_CLASS(Phalcon_Session_BagInterface){ +PHALCON_INIT_CLASS(Phalcon_Mvc_View_Engine_Volt){ -PHALCON_INIT_CLASS(Phalcon_Session_Adapter){ + 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); - PHALCON_REGISTER_CLASS(Phalcon\\Session, Adapter, session_adapter, phalcon_session_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + 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_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_mvc_view_engine_volt_ce TSRMLS_CC, 1, phalcon_mvc_view_engineinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Session_Adapter, __construct){ - - zval *options = NULL; +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, setOptions){ - PHALCON_MM_GROW(); + zval *options; - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } + phalcon_fetch_params(0, 1, 0, &options); - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_call_method_p1_key(NULL, this_ptr, "setoptions", options, 1759822653UL); + 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); - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Session_Adapter, start){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, getOptions){ - if (!SG(headers_sent)) { - phalcon_session_start(TSRMLS_C); - phalcon_update_property_bool(this_ptr, SL("_started"), 1 TSRMLS_CC); - RETURN_TRUE; - } - - RETURN_FALSE; + + RETURN_MEMBER_QUICK(this_ptr, "_options", 1620153008UL); } -static PHP_METHOD(Phalcon_Session_Adapter, setOptions){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, getCompiler){ - zval *options, *unique_id; + zval *compiler = NULL, *view, *options, *dependency_injector; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &options); + 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(options) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_session_exception_ce, "Options must be an Array"); - return; ->>>>>>> 1.2.2 - } - 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_OBS_VAR(view); + phalcon_read_property_this_quick(&view, this_ptr, SL("_view"), 3993744575UL, PH_NOISY_CC); -<<<<<<< HEAD - PHALCON_OBS_VAR(unique_id); - phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + PHALCON_OBS_VAR(options); + phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, 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(dependency_injector); + phalcon_read_property_this_quick(&dependency_injector, this_ptr, SL("_dependencyInjector"), 765199457UL, PH_NOISY_CC); - PHALCON_OBS_VAR(value); - phalcon_array_fetch(&value, _SESSION, key, PH_NOISY); - if (PHALCON_IS_NOT_EMPTY(value)) { - RETURN_CCTOR(value); + 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(default_value); + RETURN_CCTOR(compiler); } -static PHP_METHOD(Phalcon_Session_Adapter, set){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, render){ - zval *index, *value, *unique_id, *key, *_SESSION; + 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, 0, &index, &value); + phalcon_fetch_params(1, 2, 1, &template_path, ¶ms, &must_clean); - PHALCON_OBS_VAR(unique_id); - phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + if (!must_clean) { + PHALCON_INIT_VAR(must_clean); + ZVAL_BOOL(must_clean, 0); + } - 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); + 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; + } + + 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_Session_Adapter, has){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, length){ - zval *index, *unique_id, *key, *_SESSION; + zval *item, *length = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &index); - - PHALCON_OBS_VAR(unique_id); - phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 0, &item); - 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_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); + } + } } - RETURN_MM_FALSE; + RETURN_CCTOR(length); } -static PHP_METHOD(Phalcon_Session_Adapter, remove){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, isIncluded){ - zval *index, *unique_id, *key, *_SESSION; + zval *needle, *haystack; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &index); - - PHALCON_OBS_VAR(unique_id); - phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + phalcon_fetch_params(1, 2, 0, &needle, &haystack); - 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); + 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_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; -} - - - - - -#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; -} - - - - - - - - - - - - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Paginator_Adapter_Model){ - - PHALCON_REGISTER_CLASS(Phalcon\\Paginator\\Adapter, Model, paginator_adapter_model, phalcon_paginator_adapter_model_method_entry, 0); - - 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_class_implements(phalcon_paginator_adapter_model_ce TSRMLS_CC, 1, phalcon_paginator_adapterinterface_ce); - - return SUCCESS; + PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_view_exception_ce, "Invalid haystack"); + return; } -static PHP_METHOD(Phalcon_Paginator_Adapter_Model, __construct){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, convertEncoding){ - zval *config, *limit, *page; + zval *text, *from, *to; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &config); + phalcon_fetch_params(1, 3, 0, &text, &from, &to); - 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 (PHALCON_IS_STRING(from, "latin1")) { + if (PHALCON_IS_STRING(to, "utf8")) { + phalcon_call_func_p1(return_value, "utf8_encode", text); + RETURN_MM(); + } } - 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); + if (PHALCON_IS_STRING(to, "latin1")) { + if (PHALCON_IS_STRING(from, "utf8")) { + phalcon_call_func_p1(return_value, "utf8_decode", text); + RETURN_MM(); + } } - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Paginator_Adapter_Model, setCurrentPage){ - - zval *page; - - phalcon_fetch_params(0, 1, 0, &page); + 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(); + } - phalcon_update_property_this_quick(this_ptr, SL("_page"), page, 3986343137UL TSRMLS_CC); + 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_Paginator_Adapter_Model, getPaginate){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, slice){ - 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 *value, *start, *end = NULL, *slice, *length = NULL, *position; + zval *current = NULL, *one, *range; zval *r0 = NULL; PHALCON_MM_GROW(); - - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - 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; - } - - 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_fetch_params(1, 2, 1, &value, &start, &end); - if (!zend_is_true(page_number)) { - PHALCON_CPY_WRT(page_number, one); + if (!end) { + PHALCON_INIT_VAR(end); } - PHALCON_INIT_VAR(page_items); - array_init(page_items); - if (PHALCON_GT(n, zero)) { + if (Z_TYPE_P(value) == IS_OBJECT) { - if (PHALCON_LE(start, n)) { - phalcon_call_method_p1_key(NULL, items, "seek", start, 274276301UL); + 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_call_method_p1_key(NULL, items, "seek", one, 274276301UL); - PHALCON_CPY_WRT(page_number, one); + PHALCON_CPY_WRT(length, end); } - PHALCON_INIT_VAR(i); - ZVAL_LONG(i, 1); + 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, items, "valid", 574098517UL); - PHALCON_CPY_WRT(valid, r0); - if (PHALCON_IS_NOT_FALSE(valid)) { + phalcon_call_method_key(r0, value, "valid", 574098517UL); + if (zend_is_true(r0)) { } 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; + 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_SEPARATE(i); - phalcon_increment(i); + phalcon_call_method_key(NULL, value, "next", 268367684UL); + PHALCON_SEPARATE(position); + phalcon_increment(position); } - } - phalcon_update_property_zval(page, SL("items"), page_items TSRMLS_CC); + RETURN_CTOR(slice); + } - 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); + if (Z_TYPE_P(end) != IS_NULL) { + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); - PHALCON_INIT_VAR(additional_page); - phalcon_add_function(additional_page, possible_pages, one TSRMLS_CC); + PHALCON_INIT_VAR(range); + sub_function(range, end, start TSRMLS_CC); - PHALCON_INIT_NVAR(next); - ZVAL_LONG(next, phalcon_get_intval(additional_page)); - } + PHALCON_INIT_NVAR(length); + phalcon_add_function(length, range, one TSRMLS_CC); + } else { + PHALCON_INIT_NVAR(length); } - if (PHALCON_GT(next, total_pages)) { - PHALCON_CPY_WRT(next, total_pages); + if (Z_TYPE_P(value) == IS_ARRAY) { + phalcon_call_func_p3(return_value, "array_slice", value, start, length); + RETURN_MM(); } - 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); + 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(); } - 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); + if (Z_TYPE_P(length) != IS_NULL) { + phalcon_call_func_p3(return_value, "substr", value, start, length); + RETURN_MM(); } - 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); -======= - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); + phalcon_call_func_p2(return_value, "substr", value, start); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Session_Adapter, getOptions){ +static PHP_METHOD(Phalcon_Mvc_View_Engine_Volt, sort){ - zval *options; + zval *value; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); - RETURN_CCTOR(options); + 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_Session_Adapter, get){ - zval *index, *default_value = NULL, *unique_id, *key, *_SESSION; - zval *value; + + + +#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, 1, 1, &index, &default_value); + phalcon_fetch_params(1, 0, 1, &dependency_injector); - if (!default_value) { - PHALCON_INIT_VAR(default_value); + if (!dependency_injector) { + PHALCON_INIT_VAR(dependency_injector); } - 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 (Z_TYPE_P(dependency_injector) == IS_OBJECT) { + phalcon_call_method_p1_key(NULL, this_ptr, "setdi", dependency_injector, 461718238UL); } - RETURN_CCTOR(default_value); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Session_Adapter, set){ +static PHP_METHOD(Phalcon_Mvc_Micro, setDI){ - zval *index, *value, *unique_id, *key, *_SESSION; + zval *dependency_injector, *service, *exists; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &index, &value); + phalcon_fetch_params(1, 1, 0, &dependency_injector); - PHALCON_OBS_VAR(unique_id); - phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + 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(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_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_Session_Adapter, has){ +static PHP_METHOD(Phalcon_Mvc_Micro, map){ - zval *index, *unique_id, *key, *_SESSION; + zval *route_pattern, *handler, *router, *route; + zval *route_id; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &index); + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - PHALCON_OBS_VAR(unique_id); - phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + PHALCON_INIT_VAR(router); + phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); - 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_INIT_VAR(route); + phalcon_call_method_p1_key(route, router, "add", route_pattern, 2090071694UL); - RETURN_MM_FALSE; + 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_Session_Adapter, remove){ +static PHP_METHOD(Phalcon_Mvc_Micro, get){ - zval *index, *unique_id, *key, *_SESSION; + zval *route_pattern, *handler, *router, *route; + zval *route_id; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &index); + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - PHALCON_OBS_VAR(unique_id); - phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); + PHALCON_INIT_VAR(router); + phalcon_call_method_key(router, this_ptr, "getrouter", 733840870UL); - 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_INIT_VAR(route); + phalcon_call_method_p1_key(route, router, "addget", route_pattern, 522210158UL); - PHALCON_MM_RESTORE(); + 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_Session_Adapter, getId){ - - phalcon_get_session_id(return_value TSRMLS_CC); -} +static PHP_METHOD(Phalcon_Mvc_Micro, post){ -static PHP_METHOD(Phalcon_Session_Adapter, isStarted){ + zval *route_pattern, *handler, *router, *route; + zval *route_id; + PHALCON_MM_GROW(); - RETURN_MEMBER_QUICK(this_ptr, "_started", 433407867UL); + 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_Session_Adapter, destroy){ - +static PHP_METHOD(Phalcon_Mvc_Micro, put){ - phalcon_update_property_bool(this_ptr, SL("_started"), 0 TSRMLS_CC); - phalcon_session_destroy(TSRMLS_C); - RETURN_TRUE; -} + 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; -#ifdef HAVE_CONFIG_H -#endif + 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){ -PHALCON_INIT_CLASS(Phalcon_Session_AdapterInterface){ + zval *route_pattern, *handler, *router, *route; + zval *route_id; - PHALCON_REGISTER_INTERFACE(Phalcon\\Session, AdapterInterface, session_adapterinterface, phalcon_session_adapterinterface_method_entry); + PHALCON_MM_GROW(); - return SUCCESS; + 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); + } + + 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; + } + + 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); + } + + 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); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + } + + 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(); +} -#ifdef HAVE_CONFIG_H -#endif +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_INIT_CLASS(Phalcon_Paginator_Adapter_Model){ + 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(); +} - PHALCON_REGISTER_CLASS(Phalcon\\Paginator\\Adapter, Model, paginator_adapter_model, phalcon_paginator_adapter_model_method_entry, 0); +static PHP_METHOD(Phalcon_Mvc_Micro, hasService){ - 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); + zval *service_name, *dependency_injector = NULL; - zend_class_implements(phalcon_paginator_adapter_model_ce TSRMLS_CC, 1, phalcon_paginator_adapterinterface_ce); + PHALCON_MM_GROW(); - return SUCCESS; + 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_Paginator_Adapter_Model, __construct){ +static PHP_METHOD(Phalcon_Mvc_Micro, getService){ - zval *config, *limit, *page; + zval *service_name, *dependency_injector = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &config); + phalcon_fetch_params(1, 1, 0, &service_name); - 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(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); - 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(); + phalcon_call_method_p1_key(return_value, dependency_injector, "get", service_name, 2090288933UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Paginator_Adapter_Model, setCurrentPage){ +static PHP_METHOD(Phalcon_Mvc_Micro, getSharedService){ - zval *page; + zval *service_name, *dependency_injector = NULL; - phalcon_fetch_params(0, 1, 0, &page); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &service_name); - phalcon_update_property_this_quick(this_ptr, SL("_page"), page, 3986343137UL 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); + 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_Paginator_Adapter_Model, getPaginate){ +static PHP_METHOD(Phalcon_Mvc_Micro, handle){ - 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; + 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_INIT_VAR(one); - ZVAL_LONG(one, 1); - - 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_fetch_params(1, 0, 1, &uri); - 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 (!uri) { + PHALCON_INIT_VAR(uri); } - if (PHALCON_LT(show, zero)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "The start page number is zero or less"); + 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_INIT_VAR(n); - phalcon_fast_count(n, items TSRMLS_CC); - - PHALCON_INIT_VAR(page); - object_init(page); + 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(last_show_page); - sub_function(last_show_page, page_number, one TSRMLS_CC); + PHALCON_INIT_VAR(event_name); + ZVAL_STRING(event_name, "micro:beforeHandleRoute", 1); - PHALCON_INIT_VAR(start); - mul_function(start, show, last_show_page TSRMLS_CC); + 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(last_page); - sub_function(last_page, n, one TSRMLS_CC); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "router", 1); - PHALCON_INIT_VAR(possible_pages); - div_function(possible_pages, last_page, show TSRMLS_CC); + PHALCON_INIT_VAR(router); + phalcon_call_method_p1_key(router, dependency_injector, "getshared", service, 1727570332UL); - 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_call_method_p1_key(NULL, router, "handle", uri, 866903697UL); - if (!zend_is_true(page_number)) { - PHALCON_CPY_WRT(page_number, one); - } + PHALCON_INIT_VAR(matched_route); + phalcon_call_method_key(matched_route, router, "getmatchedroute", 3985199242UL); + if (Z_TYPE_P(matched_route) == IS_OBJECT) { - PHALCON_INIT_VAR(page_items); - array_init(page_items); - if (PHALCON_GT(n, zero)) { + PHALCON_OBS_VAR(handlers); + phalcon_read_property_this_quick(&handlers, this_ptr, SL("_handlers"), 2445210229UL, PH_NOISY_CC); - 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(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_INIT_VAR(i); - ZVAL_LONG(i, 1); + 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); - while (1) { + if (Z_TYPE_P(events_manager) == IS_OBJECT) { - PHALCON_INIT_NVAR(r0); - phalcon_call_method_key(r0, items, "valid", 574098517UL); - PHALCON_CPY_WRT(valid, r0); - if (PHALCON_IS_NOT_FALSE(valid)) { + 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 { - break; + PHALCON_OBS_NVAR(handler); + phalcon_read_property_this_quick(&handler, this_ptr, SL("_activeHandler"), 2923197278UL, PH_NOISY_CC); } + } - 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_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); } - PHALCON_SEPARATE(i); - phalcon_increment(i); } - } - phalcon_update_property_zval(page, SL("items"), page_items TSRMLS_CC); + PHALCON_INIT_VAR(params); + phalcon_call_method_key(params, router, "getparams", 1893744905UL); - 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(returned_value); + PHALCON_CALL_USER_FUNC_ARRAY(returned_value, handler, params); - PHALCON_INIT_VAR(additional_page); - phalcon_add_function(additional_page, possible_pages, one TSRMLS_CC); + phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), returned_value, 4143876906UL TSRMLS_CC); - PHALCON_INIT_NVAR(next); - ZVAL_LONG(next, phalcon_get_intval(additional_page)); + 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); } - } - if (PHALCON_GT(next, total_pages)) { - PHALCON_CPY_WRT(next, total_pages); - } + 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_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_is_iterable(after_handlers, &ah1, &hp1, 0, 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); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_INIT_VAR(remainder); - mod_function(remainder, n, show TSRMLS_CC); + PHALCON_GET_HVALUE(after); - 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); + if (Z_TYPE_P(after) == IS_OBJECT) { - PHALCON_INIT_VAR(pages_total); - ZVAL_LONG(pages_total, phalcon_get_intval(next)); - } else { - PHALCON_CPY_WRT(pages_total, possible_pages); - } + 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_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); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, after, "call", this_ptr, 255165473UL); - RETURN_CTOR(page); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Paginator_Adapter_QueryBuilder){ - - PHALCON_REGISTER_CLASS(Phalcon\\Paginator\\Adapter, QueryBuilder, paginator_adapter_querybuilder, phalcon_paginator_adapter_querybuilder_method_entry, 0); - - 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_paginator_adapter_querybuilder_ce TSRMLS_CC, 1, phalcon_paginator_adapterinterface_ce); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, __construct){ - - zval *config, *builder, *limit, *page; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &config); + PHALCON_OBS_NVAR(stopped); + phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); - 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); - } + if (zend_is_true(stopped)) { + break; + } - 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); - } + 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; + } - 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_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC(status, after); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, setCurrentPage){ - - zval *current_page; - - phalcon_fetch_params(0, 1, 0, ¤t_page); + zend_hash_move_forward_ex(ah1, &hp1); + } - phalcon_update_property_this_quick(this_ptr, SL("_page"), current_page, 3986343137UL TSRMLS_CC); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate){ - - 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(original_builder); - phalcon_read_property_this_quick(&original_builder, this_ptr, SL("_builder"), 3366211339UL, PH_NOISY_CC); + } + } 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_VAR(builder); - if (phalcon_clone(builder, original_builder TSRMLS_CC) == FAILURE) { - return; - } + PHALCON_INIT_NVAR(event_name); + ZVAL_STRING(event_name, "micro:beforeNotFound", 1); - PHALCON_INIT_VAR(total_builder); - if (phalcon_clone(total_builder, builder TSRMLS_CC) == FAILURE) { - return; - } + 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; + } + } - PHALCON_OBS_VAR(limit); - phalcon_read_property_this_quick(&limit, this_ptr, SL("_limitRows"), 597448366UL, PH_NOISY_CC); + 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_OBS_VAR(number_page); - phalcon_read_property_this_quick(&number_page, this_ptr, SL("_page"), 3986343137UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(returned_value); + PHALCON_CALL_USER_FUNC(returned_value, not_found_handler); - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - if (!zend_is_true(number_page)) { - PHALCON_CPY_WRT(number_page, one); + phalcon_update_property_this_quick(this_ptr, SL("_returnedValue"), returned_value, 4143876906UL TSRMLS_CC); + + RETURN_CCTOR(returned_value); } - PHALCON_INIT_VAR(prev_number_page); - sub_function(prev_number_page, number_page, one TSRMLS_CC); + 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_INIT_VAR(number); - mul_function(number, limit, prev_number_page TSRMLS_CC); + 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); - 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_INIT_NVAR(params); - PHALCON_INIT_VAR(query); - phalcon_call_method_key(query, builder, "getquery", 4154457883UL); + 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); - 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); - } + if (Z_TYPE_P(finish) == IS_OBJECT) { - phalcon_update_property_zval(page, SL("before"), before TSRMLS_CC); + 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_VAR(items); - phalcon_call_method_key(items, query, "execute", 3117639032UL); - phalcon_update_property_zval(page, SL("items"), items TSRMLS_CC); + PHALCON_INIT_NVAR(status); + phalcon_call_method_p1_key(status, finish, "call", this_ptr, 255165473UL); - PHALCON_INIT_VAR(select_count); - ZVAL_STRING(select_count, "COUNT(*) [rowcount]", 1); + PHALCON_OBS_NVAR(stopped); + phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); - phalcon_call_method_p1_key(NULL, total_builder, "columns", select_count, 1041822630UL); + if (zend_is_true(stopped)) { + break; + } - PHALCON_INIT_VAR(null_order); - phalcon_call_method_p1_key(NULL, total_builder, "orderby", null_order, 609575676UL); + 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; + } - PHALCON_INIT_VAR(total_query); - phalcon_call_method_key(total_query, total_builder, "getquery", 4154457883UL); + 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_VAR(result); - phalcon_call_method_key(result, total_query, "execute", 3117639032UL); + PHALCON_INIT_NVAR(status); + PHALCON_CALL_USER_FUNC_ARRAY(status, finish, params); - PHALCON_INIT_VAR(row); - phalcon_call_method_key(row, result, "getfirst", 3710205613UL); + PHALCON_OBS_NVAR(stopped); + phalcon_read_property_this_quick(&stopped, this_ptr, SL("_stopped"), 978787779UL, PH_NOISY_CC); - PHALCON_OBS_VAR(rowcount); - phalcon_read_property(&rowcount, row, SL("rowcount"), PH_NOISY_CC); + if (zend_is_true(stopped)) { + break; + } - PHALCON_INIT_VAR(total_pages); - div_function(total_pages, rowcount, limit TSRMLS_CC); + zend_hash_move_forward_ex(ah2, &hp2); + } - 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); } - 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); - } + if (Z_TYPE_P(returned_value) == IS_OBJECT) { - 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); ->>>>>>> 1.2.2 + 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_CTOR(page); + RETURN_CCTOR(returned_value); } +static PHP_METHOD(Phalcon_Mvc_Micro, stop){ + -<<<<<<< HEAD + phalcon_update_property_bool(this_ptr, SL("_stopped"), 1 TSRMLS_CC); + +} +static PHP_METHOD(Phalcon_Mvc_Micro, setActiveHandler){ + zval *active_handler; -#ifdef HAVE_CONFIG_H -#endif + 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); +} -PHALCON_INIT_CLASS(Phalcon_Paginator_Adapter_QueryBuilder){ - PHALCON_REGISTER_CLASS(Phalcon\\Paginator\\Adapter, QueryBuilder, paginator_adapter_querybuilder, phalcon_paginator_adapter_querybuilder_method_entry, 0); - 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_paginator_adapter_querybuilder_ce TSRMLS_CC, 1, phalcon_paginator_adapterinterface_ce); +static PHP_METHOD(Phalcon_Mvc_Micro, offsetUnset){ - return SUCCESS; + zval *alias; + + phalcon_fetch_params(0, 1, 0, &alias); + + RETURN_CCTORW(alias); } -static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, __construct){ +static PHP_METHOD(Phalcon_Mvc_Micro, before){ - zval *config, *builder, *limit, *page; -======= ->>>>>>> 1.2.2 + 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){ -<<<<<<< HEAD - phalcon_fetch_params(1, 1, 0, &config); + zval *handler; + + phalcon_fetch_params(0, 1, 0, &handler); - 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_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); - 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_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 @@ -136032,353 +63719,459 @@ static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, __construct){ -PHALCON_INIT_CLASS(Phalcon_Paginator_Adapter_NativeArray){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Route){ - PHALCON_REGISTER_CLASS(Phalcon\\Paginator\\Adapter, NativeArray, paginator_adapter_nativearray, phalcon_paginator_adapter_nativearray_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Router, Route, mvc_router_route, phalcon_mvc_router_route_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_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_paginator_adapter_nativearray_ce TSRMLS_CC, 1, phalcon_paginator_adapterinterface_ce); + zend_class_implements(phalcon_mvc_router_route_ce TSRMLS_CC, 1, phalcon_mvc_router_routeinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, __construct){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, __construct){ - zval *config, *limit, *page; + 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, &config); + phalcon_fetch_params(1, 1, 2, &pattern, &paths, &http_methods); - phalcon_update_property_this_quick(this_ptr, SL("_config"), config, 4157843450UL TSRMLS_CC); - if (phalcon_array_isset_quick_string(config, SS("limit"), 192268420UL)) { ->>>>>>> 1.2.2 - 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 (!paths) { + PHALCON_INIT_VAR(paths); } - 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); + 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(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, setCurrentPage){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, compilePattern){ - zval *current_page; + zval *pattern, *compiled_pattern = NULL, *id_pattern; + zval *wildcard = NULL, *pattern_copy = NULL, *params_pattern; + zval *int_pattern; - phalcon_fetch_params(0, 1, 0, ¤t_page); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &pattern); - phalcon_update_property_this_quick(this_ptr, SL("_page"), current_page, 3986343137UL TSRMLS_CC); + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } + } + + 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_Paginator_Adapter_QueryBuilder, getPaginate){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, reConfigure){ - 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; + 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_OBS_VAR(original_builder); - phalcon_read_property_this_quick(&original_builder, this_ptr, SL("_builder"), 3366211339UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - PHALCON_INIT_VAR(builder); - if (phalcon_clone(builder, original_builder TSRMLS_CC) == FAILURE) { - return; + if (!paths) { + PHALCON_INIT_VAR(paths); } - PHALCON_INIT_VAR(total_builder); - if (phalcon_clone(total_builder, builder TSRMLS_CC) == FAILURE) { + 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(limit); - phalcon_read_property_this_quick(&limit, this_ptr, SL("_limitRows"), 597448366UL, PH_NOISY_CC); + PHALCON_INIT_VAR(module_name); - PHALCON_OBS_VAR(number_page); - phalcon_read_property_this_quick(&number_page, this_ptr, SL("_page"), 3986343137UL, PH_NOISY_CC); + PHALCON_INIT_VAR(controller_name); - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - if (!zend_is_true(number_page)) { - PHALCON_CPY_WRT(number_page, one); - } + PHALCON_INIT_VAR(action_name); - PHALCON_INIT_VAR(prev_number_page); - sub_function(prev_number_page, number_page, one TSRMLS_CC); + PHALCON_INIT_VAR(parts); + phalcon_fast_explode_str(parts, SL("::"), paths); - PHALCON_INIT_VAR(number); - mul_function(number, limit, prev_number_page TSRMLS_CC); + PHALCON_INIT_VAR(number_parts); + phalcon_fast_count(number_parts, parts TSRMLS_CC); - 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_INIT_VAR(query); - phalcon_call_method_key(query, builder, "getquery", 4154457883UL); + switch (phalcon_get_intval(number_parts)) { - 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); - } + case 3: + PHALCON_OBS_NVAR(module_name); + phalcon_array_fetch_long(&module_name, parts, 0, PH_NOISY); - phalcon_update_property_zval(page, SL("before"), before TSRMLS_CC); + PHALCON_OBS_NVAR(controller_name); + phalcon_array_fetch_long(&controller_name, parts, 1, PH_NOISY); - PHALCON_INIT_VAR(items); - phalcon_call_method_key(items, query, "execute", 3117639032UL); - phalcon_update_property_zval(page, SL("items"), items TSRMLS_CC); + PHALCON_OBS_NVAR(action_name); + phalcon_array_fetch_long(&action_name, parts, 2, PH_NOISY); + break; - PHALCON_INIT_VAR(select_count); - ZVAL_STRING(select_count, "COUNT(*) [rowcount]", 1); + case 2: + PHALCON_OBS_NVAR(controller_name); + phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); - phalcon_call_method_p1_key(NULL, total_builder, "columns", select_count, 1041822630UL); + PHALCON_OBS_NVAR(action_name); + phalcon_array_fetch_long(&action_name, parts, 1, PH_NOISY); + break; - PHALCON_INIT_VAR(null_order); - phalcon_call_method_p1_key(NULL, total_builder, "orderby", null_order, 609575676UL); + case 1: + PHALCON_OBS_NVAR(controller_name); + phalcon_array_fetch_long(&controller_name, parts, 0, PH_NOISY); + break; - PHALCON_INIT_VAR(total_query); - phalcon_call_method_key(total_query, total_builder, "getquery", 4154457883UL); + } - PHALCON_INIT_VAR(result); - phalcon_call_method_key(result, total_query, "execute", 3117639032UL); + PHALCON_INIT_VAR(route_paths); + array_init(route_paths); - PHALCON_INIT_VAR(row); - phalcon_call_method_key(row, result, "getfirst", 3710205613UL); + if (Z_TYPE_P(module_name) != IS_NULL) { + phalcon_array_update_quick_string(&route_paths, SS("module"), 3565923467UL, &module_name, PH_COPY | PH_SEPARATE); + } - PHALCON_OBS_VAR(rowcount); - phalcon_read_property(&rowcount, row, SL("rowcount"), PH_NOISY_CC); + if (Z_TYPE_P(controller_name) != IS_NULL) { - PHALCON_INIT_VAR(total_pages); - div_function(total_pages, rowcount, limit TSRMLS_CC); + if (phalcon_memnstr_str(controller_name, SL("\\"))) { - 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_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); + } + + 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 { + PHALCON_CPY_WRT(route_paths, paths); + } + } else { + PHALCON_INIT_NVAR(route_paths); + array_init(route_paths); } - if (PHALCON_LT(number_page, total_pages)) { - PHALCON_INIT_VAR(next); - phalcon_add_function(next, number_page, one TSRMLS_CC); + 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); + } + + PHALCON_INIT_VAR(compiled_pattern); + phalcon_call_method_p1_key(compiled_pattern, this_ptr, "compilepattern", pcre_pattern, 2680336012UL); } else { - PHALCON_CPY_WRT(next, total_pages); + PHALCON_CPY_WRT(compiled_pattern, pattern); } - 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); + phalcon_update_property_this_quick(this_ptr, SL("_pattern"), pattern, 3404429922UL TSRMLS_CC); - RETURN_CTOR(page); + 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){ -#ifdef HAVE_CONFIG_H -#endif + 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); +} -PHALCON_INIT_CLASS(Phalcon_Paginator_Adapter_NativeArray){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, getRouteId){ - 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); + RETURN_MEMBER_QUICK(this_ptr, "_id", 2090005265UL); +} - zend_class_implements(phalcon_paginator_adapter_nativearray_ce TSRMLS_CC, 1, phalcon_paginator_adapterinterface_ce); +static PHP_METHOD(Phalcon_Mvc_Router_Route, getPattern){ - return SUCCESS; + + RETURN_MEMBER_QUICK(this_ptr, "_pattern", 3404429922UL); } -static PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, __construct){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, getCompiledPattern){ - zval *config, *limit, *page; - PHALCON_MM_GROW(); + RETURN_MEMBER_QUICK(this_ptr, "_compiledPattern", 4104436623UL); +} - phalcon_fetch_params(1, 1, 0, &config); - - 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 (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); -======= -static PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, setCurrentPage){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, getPaths){ - zval *page; - phalcon_fetch_params(0, 1, 0, &page); - - phalcon_update_property_this_quick(this_ptr, SL("_page"), page, 3986343137UL TSRMLS_CC); - + RETURN_MEMBER_QUICK(this_ptr, "_paths", 2700778884UL); } -static PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, getPaginate){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, getReversedPaths){ - 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; + zval *reversed, *paths, *position = NULL, *path = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; PHALCON_MM_GROW(); - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - 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); - if (Z_TYPE_P(items) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "Invalid data for paginator"); - return; - } - - PHALCON_OBS_VAR(show); - phalcon_read_property_this_quick(&show, this_ptr, SL("_limitRows"), 597448366UL, 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(reversed); + array_init(reversed); - PHALCON_INIT_VAR(total_pages); - ZVAL_LONG(total_pages, phalcon_get_intval(rounded_total)); + PHALCON_OBS_VAR(paths); + phalcon_read_property_this_quick(&paths, this_ptr, SL("_paths"), 2700778884UL, PH_NOISY_CC); - if (!PHALCON_IS_EQUAL(total_pages, rounded_total)) { - PHALCON_SEPARATE_NMO(total_pages); - phalcon_increment(total_pages); - } + phalcon_is_iterable(paths, &ah0, &hp0, 0, 0); - PHALCON_INIT_VAR(before_page_number); - sub_function(before_page_number, page_number, one TSRMLS_CC); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_VAR(start); - mul_function(start, show, before_page_number TSRMLS_CC); + PHALCON_GET_HKEY(path, ah0, hp0); + PHALCON_GET_HVALUE(position); - 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_array_update_zval(&reversed, position, &path, PH_COPY | PH_SEPARATE); - 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); + zend_hash_move_forward_ex(ah0, &hp0); } - 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); - - RETURN_CTOR(page); + 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); +} +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(); +} -PHALCON_INIT_CLASS(Phalcon_Paginator_Exception){ +static PHP_METHOD(Phalcon_Mvc_Router_Route, getHostname){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Paginator, Exception, paginator_exception, "phalcon\\exception", NULL, 0); - return SUCCESS; + 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){ -#ifdef HAVE_CONFIG_H -#endif + RETURN_MEMBER_QUICK(this_ptr, "_converters", 994353007UL); +} +static PHP_METHOD(Phalcon_Mvc_Router_Route, reset){ -PHALCON_INIT_CLASS(Phalcon_Paginator_AdapterInterface){ + zval *zero; - PHALCON_REGISTER_INTERFACE(Phalcon\\Paginator, AdapterInterface, paginator_adapterinterface, phalcon_paginator_adapterinterface_method_entry); + PHALCON_MM_GROW(); - return SUCCESS; + 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_FilterInterface){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Router_RouteInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon, FilterInterface, filterinterface, phalcon_filterinterface_method_entry); + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Router, RouteInterface, mvc_router_routeinterface, phalcon_mvc_router_routeinterface_method_entry); return SUCCESS; } @@ -136390,8 +64183,6 @@ PHALCON_INIT_CLASS(Phalcon_FilterInterface){ -#ifdef HAVE_CONFIG_H -#endif @@ -136399,54 +64190,22 @@ PHALCON_INIT_CLASS(Phalcon_FilterInterface){ -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; -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Annotations_Adapter_Apc, read){ - zval *key, *prefixed_key, *prefixed_lower, *data; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &key); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key); - - PHALCON_INIT_VAR(prefixed_lower); - phalcon_fast_strtolower(prefixed_lower, prefixed_key); - - PHALCON_INIT_VAR(data); - phalcon_call_func_p1(data, "apc_fetch", prefixed_lower); - if (Z_TYPE_P(data) == IS_OBJECT) { - RETURN_CCTOR(data); - } - - RETURN_MM_NULL(); -} -static PHP_METHOD(Phalcon_Annotations_Adapter_Apc, write){ - zval *key, *data, *prefixed_key, *prefixed_lower; +PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Exception){ - PHALCON_MM_GROW(); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Router, Exception, mvc_router_exception, "phalcon\\exception", NULL, 0); - phalcon_fetch_params(1, 2, 0, &key, &data); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key); - - 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(); + return SUCCESS; } @@ -136462,440 +64221,316 @@ static PHP_METHOD(Phalcon_Annotations_Adapter_Apc, write){ -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_Mvc_Router_Group){ - zend_declare_property_string(phalcon_annotations_adapter_files_ce, SL("_annotationsDir"), "./", ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Router, Group, mvc_router_group, phalcon_mvc_router_group_method_entry, 0); - zend_class_implements(phalcon_annotations_adapter_files_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce); + 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_Annotations_Adapter_Files, __construct){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, __construct){ - zval *options = NULL, *annotations_dir; + zval *paths = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &options); + phalcon_fetch_params(1, 0, 1, &paths); - if (!options) { - PHALCON_INIT_VAR(options); + if (!paths) { + PHALCON_INIT_VAR(paths); } - 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); + 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); } } - - 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_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"); - - 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); ->>>>>>> 1.2.2 + 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); } - RETURN_MM_NULL(); + PHALCON_MM_RESTORE(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, setCurrentPage){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, setHostname){ - zval *page; + zval *hostname; - phalcon_fetch_params(0, 1, 0, &page); - - phalcon_update_property_this_quick(this_ptr, SL("_page"), page, 3986343137UL TSRMLS_CC); + 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_Paginator_Adapter_NativeArray, getPaginate){ - - 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; +static PHP_METHOD(Phalcon_Mvc_Router_Group, getHostname){ - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(one); - ZVAL_LONG(one, 1); - - 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); - if (Z_TYPE_P(items) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_paginator_exception_ce, "Invalid data for paginator"); - return; - } - - PHALCON_OBS_VAR(show); - phalcon_read_property_this_quick(&show, this_ptr, SL("_limitRows"), 597448366UL, 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_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); - - RETURN_CTOR(page); + RETURN_MEMBER_QUICK(this_ptr, "_hostname", 598751491UL); } +static PHP_METHOD(Phalcon_Mvc_Router_Group, setPrefix){ -======= -static PHP_METHOD(Phalcon_Annotations_Adapter_Files, write){ - - zval *key, *data, *annotations_dir, *separator; - zval *virtual_key, *path, *to_string, *export, *php_export; - zval *status; - - PHALCON_MM_GROW(); + zval *prefix; - 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, ">>>>>> 1.2.2 - - -<<<<<<< HEAD - -#ifdef HAVE_CONFIG_H -#endif - - - +static PHP_METHOD(Phalcon_Mvc_Router_Group, getBeforeMatch){ + RETURN_MEMBER_QUICK(this_ptr, "_beforeMatch", 2834072708UL); +} -PHALCON_INIT_CLASS(Phalcon_Paginator_Exception){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, setPaths){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Paginator, Exception, paginator_exception, "phalcon\\exception", NULL, 0); + zval *paths; - return SUCCESS; -======= - phalcon_fetch_params(1, 2, 0, &key, &data); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key); - - PHALCON_INIT_VAR(prefixed_lower); - phalcon_fast_strtolower(prefixed_lower, prefixed_key); + phalcon_fetch_params(0, 1, 0, &paths); - PHALCON_INIT_VAR(serialized); - phalcon_serialize(serialized, &data TSRMLS_CC); - phalcon_call_func_p2_noret("xcache_set", prefixed_lower, serialized); + phalcon_update_property_this_quick(this_ptr, SL("_paths"), paths, 2700778884UL TSRMLS_CC); - PHALCON_MM_RESTORE(); ->>>>>>> 1.2.2 } +static PHP_METHOD(Phalcon_Mvc_Router_Group, getPaths){ + RETURN_MEMBER_QUICK(this_ptr, "_paths", 2700778884UL); +} +static PHP_METHOD(Phalcon_Mvc_Router_Group, getRoutes){ -#ifdef HAVE_CONFIG_H -#endif - - - -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Paginator_AdapterInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Paginator, AdapterInterface, paginator_adapterinterface, phalcon_paginator_adapterinterface_method_entry); - return SUCCESS; + 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); + } + } 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(); -#ifdef HAVE_CONFIG_H -#endif - + 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){ -PHALCON_INIT_CLASS(Phalcon_FilterInterface){ + zval *pattern, *paths = NULL, *method; - PHALCON_REGISTER_INTERFACE(Phalcon, FilterInterface, filterinterface, phalcon_filterinterface_method_entry); + PHALCON_MM_GROW(); - return SUCCESS; + 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(); -#ifdef HAVE_CONFIG_H -#endif - + 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(); +} -======= ->>>>>>> 1.2.2 +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(); +} -<<<<<<< HEAD +static PHP_METHOD(Phalcon_Mvc_Router_Group, addDelete){ -PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Apc){ + zval *pattern, *paths = NULL, *method; - PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Apc, annotations_adapter_apc, "phalcon\\annotations\\adapter", phalcon_annotations_adapter_apc_method_entry, 0); + PHALCON_MM_GROW(); - zend_class_implements(phalcon_annotations_adapter_apc_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce); -======= -PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Memory){ + 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(); +} - PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Memory, annotations_adapter_memory, "phalcon\\annotations\\adapter", phalcon_annotations_adapter_memory_method_entry, 0); +static PHP_METHOD(Phalcon_Mvc_Router_Group, addOptions){ - zend_declare_property_null(phalcon_annotations_adapter_memory_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); + zval *pattern, *paths = NULL, *method; - zend_class_implements(phalcon_annotations_adapter_memory_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce); ->>>>>>> 1.2.2 + PHALCON_MM_GROW(); - return SUCCESS; + 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(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Annotations_Adapter_Apc, read){ - - zval *key, *prefixed_key, *prefixed_lower, *data; -======= -static PHP_METHOD(Phalcon_Annotations_Adapter_Memory, read){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, addHead){ - zval *key, *data, *lowercased_key, *annotations; ->>>>>>> 1.2.2 + zval *pattern, *paths = NULL, *method; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &key); -<<<<<<< HEAD - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key); - - PHALCON_INIT_VAR(prefixed_lower); - phalcon_fast_strtolower(prefixed_lower, prefixed_key); - - PHALCON_INIT_VAR(data); - phalcon_call_func_p1(data, "apc_fetch", prefixed_lower); - if (Z_TYPE_P(data) == IS_OBJECT) { - RETURN_CCTOR(data); -======= - - PHALCON_OBS_VAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 1, &pattern, &paths); - PHALCON_INIT_VAR(lowercased_key); - phalcon_fast_strtolower(lowercased_key, key); - if (phalcon_array_isset(data, lowercased_key)) { - PHALCON_OBS_VAR(annotations); - phalcon_array_fetch(&annotations, data, lowercased_key, PH_NOISY); - RETURN_CCTOR(annotations); ->>>>>>> 1.2.2 + if (!paths) { + PHALCON_INIT_VAR(paths); } - RETURN_MM_NULL(); + 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(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Annotations_Adapter_Apc, write){ - - zval *key, *data, *prefixed_key, *prefixed_lower; -======= -static PHP_METHOD(Phalcon_Annotations_Adapter_Memory, write){ +static PHP_METHOD(Phalcon_Mvc_Router_Group, clear){ - zval *key, *data, *lowercased_key; ->>>>>>> 1.2.2 + zval *empty_routes; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &key, &data); -<<<<<<< HEAD - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key); - - PHALCON_INIT_VAR(prefixed_lower); - phalcon_fast_strtolower(prefixed_lower, prefixed_key); - phalcon_call_func_p2_noret("apc_store", prefixed_lower, data); -======= - - PHALCON_INIT_VAR(lowercased_key); - phalcon_fast_strtolower(lowercased_key, key); - phalcon_update_property_array(this_ptr, SL("_data"), lowercased_key, data TSRMLS_CC); ->>>>>>> 1.2.2 + 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(); } @@ -136913,564 +64548,530 @@ static PHP_METHOD(Phalcon_Annotations_Adapter_Memory, write){ -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Files){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Router_Annotations){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Files, annotations_adapter_files, "phalcon\\annotations\\adapter", phalcon_annotations_adapter_files_method_entry, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Router, Annotations, mvc_router_annotations, "phalcon\\mvc\\router", phalcon_mvc_router_annotations_method_entry, 0); - zend_declare_property_string(phalcon_annotations_adapter_files_ce, SL("_annotationsDir"), "./", ZEND_ACC_PROTECTED TSRMLS_CC); + 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); - zend_class_implements(phalcon_annotations_adapter_files_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce); -======= -PHALCON_INIT_CLASS(Phalcon_Annotations_Annotation){ + return SUCCESS; +} - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Annotation, annotations_annotation, phalcon_annotations_annotation_method_entry, 0); +static PHP_METHOD(Phalcon_Mvc_Router_Annotations, addResource){ - 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); ->>>>>>> 1.2.2 + zval *handler, *prefix = NULL, *scope; - return SUCCESS; + 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(); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Annotations_Adapter_Files, __construct){ +static PHP_METHOD(Phalcon_Mvc_Router_Annotations, addModuleResource){ - zval *options = NULL, *annotations_dir; + zval *module, *handler, *prefix = NULL, *scope; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &options); + phalcon_fetch_params(1, 2, 1, &module, &handler, &prefix); - if (!options) { - PHALCON_INIT_VAR(options); + if (!prefix) { + PHALCON_INIT_VAR(prefix); } - 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); -======= -static PHP_METHOD(Phalcon_Annotations_Annotation, __construct){ + 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(); +} - zval *reflection_data, *name = NULL, *arguments, *expr_arguments; - zval *argument = NULL, *expr = NULL, *resolved_argument = NULL; - HashTable *ah0; - HashPosition hp0; +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, 1, 0, &reflection_data); + phalcon_fetch_params(1, 0, 1, &uri); - if (Z_TYPE_P(reflection_data) != IS_ARRAY) { - PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "Reflection data must be an array"); - return; + if (!uri) { + PHALCON_INIT_VAR(uri); } - 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 (!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); + } - if (phalcon_array_isset_quick_string(reflection_data, SS("arguments"), 3751272283UL)) { + 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(arguments); - array_init(arguments); + PHALCON_INIT_VAR(annotations_service); - PHALCON_OBS_VAR(expr_arguments); - phalcon_array_fetch_quick_string(&expr_arguments, reflection_data, SS("arguments"), 3751272283UL, PH_NOISY); + 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_is_iterable(expr_arguments, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(controller_suffix); + phalcon_read_property_this_quick(&controller_suffix, this_ptr, SL("_controllerSuffix"), 2437326621UL, PH_NOISY_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + phalcon_is_iterable(handlers, &ah0, &hp0, 0, 0); - PHALCON_GET_HVALUE(argument); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_OBS_NVAR(expr); - phalcon_array_fetch_quick_string(&expr, argument, SS("expr"), 258368420UL, PH_NOISY); + PHALCON_GET_HVALUE(scope); - 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); - } + if (Z_TYPE_P(scope) == IS_ARRAY) { - zend_hash_move_forward_ex(ah0, &hp0); ->>>>>>> 1.2.2 - } + 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; + } + } -<<<<<<< HEAD - 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); + if (Z_TYPE_P(annotations_service) != IS_OBJECT) { - PHALCON_OBS_VAR(annotations_dir); - phalcon_read_property_this_quick(&annotations_dir, this_ptr, SL("_annotationsDir"), 4233102065UL, PH_NOISY_CC); + 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_VAR(separator); - ZVAL_STRING(separator, "_", 1); + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "annotations", 1); - PHALCON_INIT_VAR(virtual_key); - phalcon_prepare_virtual_path(virtual_key, key, separator TSRMLS_CC); + PHALCON_INIT_NVAR(annotations_service); + phalcon_call_method_p1_key(annotations_service, dependency_injector, "getshared", service, 1727570332UL); + } - PHALCON_INIT_VAR(path); - PHALCON_CONCAT_VVS(path, annotations_dir, virtual_key, ".php"); + 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); - 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_INIT_NVAR(lower_controller_name); + phalcon_uncamelize(lower_controller_name, controller_name); - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_Annotations_Adapter_Files, write){ - - zval *key, *data, *annotations_dir, *separator; - zval *virtual_key, *path, *to_string, *export, *php_export; - zval *status; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &key, &data); + PHALCON_INIT_NVAR(namespace_name); + phalcon_get_ns_class(namespace_name, handler, 0 TSRMLS_CC); + } else { + PHALCON_CPY_WRT(controller_name, handler); - PHALCON_OBS_VAR(annotations_dir); - phalcon_read_property_this_quick(&annotations_dir, this_ptr, SL("_annotationsDir"), 4233102065UL, PH_NOISY_CC); + 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); - PHALCON_INIT_VAR(separator); - ZVAL_STRING(separator, "_", 1); + zend_hash_move_forward_ex(ah3, &hp3); + } - 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"); + zend_hash_move_forward_ex(ah2, &hp2); + } - PHALCON_INIT_VAR(to_string); - ZVAL_BOOL(to_string, 1); + } + } - PHALCON_INIT_VAR(export); - phalcon_call_func_p2(export, "var_export", data, to_string); + zend_hash_move_forward_ex(ah0, &hp0); + } - PHALCON_INIT_VAR(php_export); - PHALCON_CONCAT_SVS(php_export, ">>>>>> 1.2.2 + RETURN_MM_TRUE; } PHALCON_MM_RESTORE(); } -<<<<<<< HEAD - +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); + +} -#ifdef HAVE_CONFIG_H -#endif +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); +} -PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Xcache){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Xcache, annotations_adapter_xcache, "phalcon\\annotations\\adapter", phalcon_annotations_adapter_xcache_method_entry, 0); - zend_class_implements(phalcon_annotations_adapter_xcache_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce); - return SUCCESS; -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Annotations_Adapter_Xcache, read){ - zval *key, *prefixed_key, *prefixed_lower, *serialized; - zval *data; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &key); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key); - - PHALCON_INIT_VAR(prefixed_lower); - phalcon_fast_strtolower(prefixed_lower, prefixed_key); - - PHALCON_INIT_VAR(serialized); - phalcon_call_func_p1(serialized, "xcache_get", prefixed_lower); - if (Z_TYPE_P(serialized) == IS_STRING) { - - PHALCON_INIT_VAR(data); - phalcon_unserialize(data, serialized TSRMLS_CC); - if (Z_TYPE_P(data) == IS_OBJECT) { - RETURN_CTOR(data); - } - } - - RETURN_MM_NULL(); -} -static PHP_METHOD(Phalcon_Annotations_Adapter_Xcache, write){ - zval *key, *data, *prefixed_key, *prefixed_lower; - zval *serialized; - PHALCON_MM_GROW(); +PHALCON_INIT_CLASS(Phalcon_Mvc_Controller){ - phalcon_fetch_params(1, 2, 0, &key, &data); - - PHALCON_INIT_VAR(prefixed_key); - PHALCON_CONCAT_SV(prefixed_key, "_PHAN", key); - - PHALCON_INIT_VAR(prefixed_lower); - phalcon_fast_strtolower(prefixed_lower, prefixed_key); - - PHALCON_INIT_VAR(serialized); - phalcon_serialize(serialized, &data TSRMLS_CC); - phalcon_call_func_p2_noret("xcache_set", prefixed_lower, serialized); + 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(); } @@ -137488,474 +65089,347 @@ static PHP_METHOD(Phalcon_Annotations_Adapter_Xcache, write){ -PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter_Memory){ +PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_Collection){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations\\Adapter, Memory, annotations_adapter_memory, "phalcon\\annotations\\adapter", phalcon_annotations_adapter_memory_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Mvc\\Micro, Collection, mvc_micro_collection, phalcon_mvc_micro_collection_method_entry, 0); - zend_declare_property_null(phalcon_annotations_adapter_memory_ce, SL("_data"), ZEND_ACC_PROTECTED TSRMLS_CC); + 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_annotations_adapter_memory_ce TSRMLS_CC, 1, phalcon_annotations_adapterinterface_ce); + zend_class_implements(phalcon_mvc_micro_collection_ce TSRMLS_CC, 1, phalcon_mvc_micro_collectioninterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Annotations_Adapter_Memory, read){ +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, _addMap){ - zval *key, *data, *lowercased_key, *annotations; + zval *method, *route_pattern, *handler, *handler_definition; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &key); - - PHALCON_OBS_VAR(data); - phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + phalcon_fetch_params(1, 3, 0, &method, &route_pattern, &handler); - PHALCON_INIT_VAR(lowercased_key); - phalcon_fast_strtolower(lowercased_key, key); - if (phalcon_array_isset(data, lowercased_key)) { - PHALCON_OBS_VAR(annotations); - phalcon_array_fetch(&annotations, data, lowercased_key, PH_NOISY); - RETURN_CCTOR(annotations); - } + 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); - RETURN_MM_NULL(); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Annotations_Adapter_Memory, write){ - - zval *key, *data, *lowercased_key; +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, setPrefix){ - PHALCON_MM_GROW(); + zval *prefix; - phalcon_fetch_params(1, 2, 0, &key, &data); - - PHALCON_INIT_VAR(lowercased_key); - phalcon_fast_strtolower(lowercased_key, key); - phalcon_update_property_array(this_ptr, SL("_data"), lowercased_key, data TSRMLS_CC); + phalcon_fetch_params(0, 1, 0, &prefix); - PHALCON_MM_RESTORE(); + 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){ -#ifdef HAVE_CONFIG_H -#endif + 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_INIT_CLASS(Phalcon_Annotations_Annotation){ + phalcon_fetch_params(0, 1, 0, &lazy); + + phalcon_update_property_this_quick(this_ptr, SL("_lazy"), lazy, 3981620804UL TSRMLS_CC); + RETURN_THISW(); +} - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Annotation, annotations_annotation, phalcon_annotations_annotation_method_entry, 0); +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, isLazy){ - 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); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_lazy", 3981620804UL); } -static PHP_METHOD(Phalcon_Annotations_Annotation, __construct){ +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, getHandler){ - zval *reflection_data, *name = NULL, *arguments, *expr_arguments; - zval *argument = NULL, *expr = NULL, *resolved_argument = NULL; -======= -static PHP_METHOD(Phalcon_Annotations_Collection, count){ - zval *annotations; + RETURN_MEMBER_QUICK(this_ptr, "_handler", 1505752930UL); +} + +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, map){ + + zval *route_pattern, *handler, *method; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(annotations); - phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC); - phalcon_fast_count(return_value, annotations TSRMLS_CC); + 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_Annotations_Collection, rewind){ +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, get){ + zval *route_pattern, *handler, *method; - phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC); + 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_Annotations_Collection, current){ +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, post){ - zval *position, *annotations, *annotation; + zval *route_pattern, *handler, *method; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(annotations); - phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC); - if (phalcon_array_isset(annotations, position)) { - PHALCON_OBS_VAR(annotation); - phalcon_array_fetch(&annotation, annotations, position, PH_NOISY); - RETURN_CCTOR(annotation); - } + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - RETURN_MM_NULL(); + 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_Annotations_Collection, key){ +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, put){ + zval *route_pattern, *handler, *method; - RETURN_MEMBER_QUICK(this_ptr, "_position", 2925265369UL); + 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_Annotations_Collection, next){ +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, patch){ + zval *route_pattern, *handler, *method; - phalcon_property_incr(this_ptr, SL("_position") TSRMLS_CC); + 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_Annotations_Collection, valid){ +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, head){ - zval *position, *annotations; + zval *route_pattern, *handler, *method; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(annotations); - phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC); - if (phalcon_array_isset(annotations, position)) { - RETURN_MM_TRUE; - } + phalcon_fetch_params(1, 2, 0, &route_pattern, &handler); - RETURN_MM_FALSE; + 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_Annotations_Collection, getAnnotations){ +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, delete){ + zval *route_pattern, *handler, *method; - RETURN_MEMBER_QUICK(this_ptr, "_annotations", 1219636498UL); + 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_Annotations_Collection, get){ +static PHP_METHOD(Phalcon_Mvc_Micro_Collection, options){ - zval *name, *annotations, *annotation = NULL, *annotation_name = NULL; - zval *exception_message; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *route_pattern, *handler, *method; PHALCON_MM_GROW(); -<<<<<<< HEAD - 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); -======= - phalcon_fetch_params(1, 1, 0, &name); - - 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) { - - phalcon_is_iterable(annotations, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(annotation); - - PHALCON_INIT_NVAR(annotation_name); - phalcon_call_method_key(annotation_name, annotation, "getname", 4286441094UL); - if (PHALCON_IS_EQUAL(name, annotation_name)) { - RETURN_CCTOR(annotation); ->>>>>>> 1.2.2 - } - - zend_hash_move_forward_ex(ah0, &hp0); - } - -<<<<<<< HEAD - 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(1, 2, 0, &route_pattern, &handler); - PHALCON_MM_RESTORE(); + 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(); } -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; -======= - } - - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "The collection doesn't have an annotation called '", name, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_annotations_exception_ce, exception_message); - return; -} +#ifdef HAVE_CONFIG_H +#endif -static PHP_METHOD(Phalcon_Annotations_Collection, getAll){ - zval *name, *found, *annotations, *annotation = NULL, *annotation_name = NULL; ->>>>>>> 1.2.2 - HashTable *ah0; - HashPosition hp0; - zval **hd; - PHALCON_MM_GROW(); +PHALCON_INIT_CLASS(Phalcon_Mvc_Micro_MiddlewareInterface){ -<<<<<<< HEAD - 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(); + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc\\Micro, MiddlewareInterface, mvc_micro_middlewareinterface, phalcon_mvc_micro_middlewareinterface_method_entry); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Annotations_Annotation, getExprArguments){ - RETURN_MEMBER_QUICK(this_ptr, "_exprArguments", 3152251737UL); -} -static PHP_METHOD(Phalcon_Annotations_Annotation, getArguments){ - RETURN_MEMBER_QUICK(this_ptr, "_arguments", 314247962UL); -} +#ifdef HAVE_CONFIG_H +#endif -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_INIT_CLASS(Phalcon_Mvc_Micro_Exception){ - PHALCON_MM_GROW(); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Mvc\\Micro, Exception, mvc_micro_exception, "phalcon\\exception", NULL, 0); - 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(); + return SUCCESS; } -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){ +#ifdef HAVE_CONFIG_H +#endif - 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(); +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; } -static PHP_METHOD(Phalcon_Annotations_Annotation, getNamedParameter){ - zval *name, *arguments, *value; - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); + + + + + + + + + + + + + + + + +#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(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); + 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); - RETURN_MM_NULL(); } -static PHP_METHOD(Phalcon_Annotations_Annotation, hasNamedArgument){ +static PHP_METHOD(Phalcon_Mvc_Micro_LazyLoader, __call){ - zval *name, *arguments; + zval *method, *arguments, *handler = NULL, *definition; + zval *call_handler; + zend_class_entry *ce0; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); + phalcon_fetch_params(1, 2, 0, &method, &arguments); - 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; + 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); + } + phalcon_update_property_this_quick(this_ptr, SL("_handler"), handler, 1505752930UL TSRMLS_CC); } - RETURN_MM_FALSE; + 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(); } @@ -137967,1340 +65441,1304 @@ static PHP_METHOD(Phalcon_Annotations_Annotation, hasNamedArgument){ -PHALCON_INIT_CLASS(Phalcon_Annotations_ReaderInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Annotations, ReaderInterface, annotations_readerinterface, phalcon_annotations_readerinterface_method_entry); - return SUCCESS; -} +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; +} -#ifdef HAVE_CONFIG_H -#endif +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){ -PHALCON_INIT_CLASS(Phalcon_Annotations_Collection){ + zval *controller_name; - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Collection, annotations_collection, phalcon_annotations_collection_method_entry, 0); + phalcon_fetch_params(0, 1, 0, &controller_name); + + phalcon_update_property_this_quick(this_ptr, SL("_handlerName"), controller_name, 2743819555UL TSRMLS_CC); + +} - zend_declare_property_long(phalcon_annotations_collection_ce, SL("_position"), 0, ZEND_ACC_PROTECTED TSRMLS_CC); - zend_declare_property_null(phalcon_annotations_collection_ce, SL("_annotations"), ZEND_ACC_PROTECTED TSRMLS_CC); +static PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerName){ - zend_class_implements(phalcon_annotations_collection_ce TSRMLS_CC, 2, zend_ce_iterator, spl_ce_Countable); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_handlerName", 2743819555UL); } -static PHP_METHOD(Phalcon_Annotations_Collection, __construct){ +static PHP_METHOD(Phalcon_Mvc_Dispatcher, _throwDispatchException){ - zval *reflection_data = NULL, *annotations, *annotation_data = NULL; - zval *annotation = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + 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, 0, 1, &reflection_data); + phalcon_fetch_params(1, 1, 1, &message, &exception_code); - if (!reflection_data) { - PHALCON_INIT_VAR(reflection_data); + if (!exception_code) { + PHALCON_INIT_VAR(exception_code); + ZVAL_LONG(exception_code, 0); + } else { + PHALCON_SEPARATE_PARAM(exception_code); } - if (Z_TYPE_P(reflection_data) != IS_NULL) { - 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(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; } - if (Z_TYPE_P(reflection_data) == IS_ARRAY) { - PHALCON_INIT_VAR(annotations); - array_init(annotations); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "response", 1); - phalcon_is_iterable(reflection_data, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(response); + phalcon_call_method_p1_key(response, dependency_injector, "getshared", service, 1727570332UL); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(status_code); + ZVAL_LONG(status_code, 404); - PHALCON_GET_HVALUE(annotation_data); + 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(annotation); - object_init_ex(annotation, phalcon_annotations_annotation_ce); - phalcon_call_method_p1_key(NULL, annotation, "__construct", annotation_data, 1107214344UL); + 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_array_append(&annotations, annotation, PH_SEPARATE); + 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) { - zend_hash_move_forward_ex(ah0, &hp0); + 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_update_property_this_quick(this_ptr, SL("_annotations"), annotations, 1219636498UL TSRMLS_CC); + 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_Annotations_Collection, count){ +static PHP_METHOD(Phalcon_Mvc_Dispatcher, getControllerClass){ - zval *annotations; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(annotations); - phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC); - phalcon_fast_count(return_value, annotations TSRMLS_CC); + phalcon_call_method_key(return_value, this_ptr, "gethandlername", 1725429572UL); RETURN_MM(); } -static PHP_METHOD(Phalcon_Annotations_Collection, rewind){ +static PHP_METHOD(Phalcon_Mvc_Dispatcher, getLastController){ - phalcon_update_property_long(this_ptr, SL("_position"), 0 TSRMLS_CC); - + RETURN_MEMBER_QUICK(this_ptr, "_lastHandler", 1315517974UL); } -static PHP_METHOD(Phalcon_Annotations_Collection, current){ - - zval *position, *annotations, *annotation; +static PHP_METHOD(Phalcon_Mvc_Dispatcher, getActiveController){ - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(annotations); - phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC); - if (phalcon_array_isset(annotations, position)) { - PHALCON_OBS_VAR(annotation); - phalcon_array_fetch(&annotation, annotations, position, PH_NOISY); - RETURN_CCTOR(annotation); - } - - RETURN_MM_NULL(); + RETURN_MEMBER_QUICK(this_ptr, "_activeHandler", 2923197278UL); } -static PHP_METHOD(Phalcon_Annotations_Collection, key){ - RETURN_MEMBER_QUICK(this_ptr, "_position", 2925265369UL); -} -static PHP_METHOD(Phalcon_Annotations_Collection, next){ + +#ifdef HAVE_CONFIG_H +#endif - phalcon_property_incr(this_ptr, SL("_position") TSRMLS_CC); - + +PHALCON_INIT_CLASS(Phalcon_Mvc_UrlInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Mvc, UrlInterface, mvc_urlinterface, phalcon_mvc_urlinterface_method_entry); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Annotations_Collection, valid){ - zval *position, *annotations; - PHALCON_MM_GROW(); - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); - - PHALCON_OBS_VAR(annotations); - phalcon_read_property_this_quick(&annotations, this_ptr, SL("_annotations"), 1219636498UL, PH_NOISY_CC); - if (phalcon_array_isset(annotations, position)) { - RETURN_MM_TRUE; - } - - RETURN_MM_FALSE; + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Security_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Security, Exception, security_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Annotations_Collection, getAnnotations){ - RETURN_MEMBER_QUICK(this_ptr, "_annotations", 1219636498UL); + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Validation){ + + PHALCON_REGISTER_CLASS_EX(Phalcon, Validation, validation, "phalcon\\di\\injectable", phalcon_validation_method_entry, 0); + + 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); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Annotations_Collection, get){ +static PHP_METHOD(Phalcon_Validation, __construct){ - zval *name, *annotations, *annotation = NULL, *annotation_name = NULL; - zval *exception_message; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *validators = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); - - 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) { - - phalcon_is_iterable(annotations, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HVALUE(annotation); + phalcon_fetch_params(1, 0, 1, &validators); - PHALCON_INIT_NVAR(annotation_name); - phalcon_call_method_key(annotation_name, annotation, "getname", 4286441094UL); - if (PHALCON_IS_EQUAL(name, annotation_name)) { - RETURN_CCTOR(annotation); - } + if (!validators) { + PHALCON_INIT_VAR(validators); + } - zend_hash_move_forward_ex(ah0, &hp0); + 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); + } + if (phalcon_method_quick_exists_ex(this_ptr, SS("initialize"), 2896075127UL TSRMLS_CC) == SUCCESS) { + phalcon_call_method_key(NULL, this_ptr, "initialize", 2896075127UL); } - PHALCON_INIT_VAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "The collection doesn't have an annotation called '", name, "'"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_annotations_exception_ce, exception_message); - return; + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Annotations_Collection, getAll){ +static PHP_METHOD(Phalcon_Validation, validate){ - zval *name, *found, *annotations, *annotation = NULL, *annotation_name = NULL; + 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; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); + phalcon_fetch_params(1, 0, 2, &data, &entity); - PHALCON_INIT_VAR(found); - array_init(found); + if (!data) { + PHALCON_INIT_VAR(data); + } - 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 (!entity) { + PHALCON_INIT_VAR(entity); + } - phalcon_is_iterable(annotations, &ah0, &hp0, 0, 0); + 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; + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + phalcon_update_property_null(this_ptr, SL("_values") TSRMLS_CC); - PHALCON_GET_HVALUE(annotation); + PHALCON_INIT_VAR(messages); + object_init_ex(messages, phalcon_validation_message_group_ce); + phalcon_call_method_key(NULL, messages, "__construct", 1107214344UL); - PHALCON_INIT_NVAR(annotation_name); - phalcon_call_method_key(annotation_name, annotation, "getname", 4286441094UL); - if (PHALCON_IS_EQUAL(name, annotation_name)) { - phalcon_array_append(&found, annotation, PH_SEPARATE); - } + if (phalcon_method_quick_exists_ex(this_ptr, SS("beforevalidation"), 4025473891UL TSRMLS_CC) == SUCCESS) { - zend_hash_move_forward_ex(ah0, &hp0); + 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); } - } - RETURN_CTOR(found); -} - -static PHP_METHOD(Phalcon_Annotations_Collection, has){ - - zval *name, *annotations, *annotation = NULL, *annotation_name = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); - - 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) { + 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_is_iterable(annotations, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(cancel_on_fail); + ZVAL_STRING(cancel_on_fail, "cancelOnFail", 1); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + phalcon_is_iterable(validators, &ah0, &hp0, 0, 0); - PHALCON_GET_HVALUE(annotation); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - PHALCON_INIT_NVAR(annotation_name); - phalcon_call_method_key(annotation_name, annotation, "getname", 4286441094UL); - if (PHALCON_IS_EQUAL(name, annotation_name)) { - RETURN_MM_TRUE; - } + PHALCON_GET_HVALUE(scope); - zend_hash_move_forward_ex(ah0, &hp0); + if (Z_TYPE_P(scope) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The validator scope is not valid"); + return; } - } - -======= - phalcon_fetch_params(1, 1, 0, &name); - - PHALCON_INIT_VAR(found); - array_init(found); - - 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) { + PHALCON_OBS_NVAR(attribute); + phalcon_array_fetch_long(&attribute, scope, 0, PH_NOISY); - phalcon_is_iterable(annotations, &ah0, &hp0, 0, 0); + 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; + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_NVAR(status); + phalcon_call_method_p2_key(status, validator, "validate", this_ptr, attribute, 2654098287UL); - PHALCON_GET_HVALUE(annotation); + if (PHALCON_IS_FALSE(status)) { - PHALCON_INIT_NVAR(annotation_name); - phalcon_call_method_key(annotation_name, annotation, "getname", 4286441094UL); - if (PHALCON_IS_EQUAL(name, annotation_name)) { - phalcon_array_append(&found, annotation, PH_SEPARATE); + 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; } - - zend_hash_move_forward_ex(ah0, &hp0); } + zend_hash_move_forward_ex(ah0, &hp0); } - RETURN_CTOR(found); + 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); + } + + RETURN_CCTOR(messages); } -static PHP_METHOD(Phalcon_Annotations_Collection, has){ +static PHP_METHOD(Phalcon_Validation, add){ - zval *name, *annotations, *annotation = NULL, *annotation_name = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *attribute, *validator, *scope; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &name); - - 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) { + phalcon_fetch_params(1, 2, 0, &attribute, &validator); - phalcon_is_iterable(annotations, &ah0, &hp0, 0, 0); + if (Z_TYPE_P(attribute) != IS_STRING) { + PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The attribute must be a string"); + return; + } + if (Z_TYPE_P(validator) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The validator must be an object"); + return; + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + 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); - PHALCON_GET_HVALUE(annotation); + RETURN_THIS(); +} + +static PHP_METHOD(Phalcon_Validation, setFilters){ + + zval *attribute, *filters; + + phalcon_fetch_params(0, 2, 0, &attribute, &filters); - PHALCON_INIT_NVAR(annotation_name); - phalcon_call_method_key(annotation_name, annotation, "getname", 4286441094UL); - if (PHALCON_IS_EQUAL(name, annotation_name)) { - RETURN_MM_TRUE; - } + 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); - zend_hash_move_forward_ex(ah0, &hp0); - } + if (!attribute) { + PHALCON_INIT_VAR(attribute); + } + 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(); } ->>>>>>> 1.2.2 - RETURN_MM_FALSE; + RETURN_CCTOR(filters); } +static PHP_METHOD(Phalcon_Validation, getValidators){ -/* Generated by re2c 0.13.5 on Fri Jun 28 19:00:52 2013 */ -// 1 "scanner.re" - - -#ifdef HAVE_CONFIG_H -#endif - + RETURN_MEMBER_QUICK(this_ptr, "_validators", 2342846045UL); +} +static PHP_METHOD(Phalcon_Validation, getEntity){ -#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) { + RETURN_MEMBER_QUICK(this_ptr, "_entity", 2413912609UL); +} - char next, *q = JJCURSOR, *start = JJCURSOR; - int status = PHANNOT_SCANNER_RETCODE_IMPOSSIBLE; +static PHP_METHOD(Phalcon_Validation, getMessages){ - while (PHANNOT_SCANNER_RETCODE_IMPOSSIBLE == status) { - if (s->mode == PHANNOT_MODE_RAW) { + RETURN_MEMBER_QUICK(this_ptr, "_messages", 743366684UL); +} - if (*JJCURSOR == '\n') { - s->active_line++; - } +static PHP_METHOD(Phalcon_Validation, appendMessage){ - next = *(JJCURSOR+1); + zval *message, *messages; - if (*JJCURSOR == '\0' || *JJCURSOR == '@') { - if ((next >= 'A' && next <= 'Z') || (next >= 'a' && next <= 'z')) { - s->mode = PHANNOT_MODE_ANNOTATION; - continue; - } - } + PHALCON_MM_GROW(); - ++JJCURSOR; - token->opcode = PHANNOT_T_IGNORE; - return 0; + 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); + phalcon_call_method_p1_key(NULL, messages, "appendmessage", message, 2313005058UL); + RETURN_THIS(); +} - } else { +static PHP_METHOD(Phalcon_Validation, bind){ - -// 66 "scanner.c" - { - JJCTYPE jjch; - unsigned int jjaccept = 0; + zval *entity, *data; - 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; - } -// 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; - } -// 192 "scanner.c" -jj6: - ++JJCURSOR; - switch ((jjch = *JJCURSOR)) { - case 'U': - case 'u': goto jj63; - default: goto jj44; - } -jj7: -// 109 "scanner.re" - { - token->opcode = PHANNOT_T_IDENTIFIER; - token->value = estrndup(start, JJCURSOR - start); - token->len = JJCURSOR - start; - q = JJCURSOR; - return 0; - } -// 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; - } -// 247 "scanner.c" -jj16: - ++JJCURSOR; -// 122 "scanner.re" - { - token->opcode = PHANNOT_T_PARENTHESES_CLOSE; - return 0; - } -// 255 "scanner.c" -jj18: - ++JJCURSOR; -// 127 "scanner.re" - { - token->opcode = PHANNOT_T_BRACKET_OPEN; - return 0; - } -// 263 "scanner.c" -jj20: - ++JJCURSOR; -// 132 "scanner.re" - { - token->opcode = PHANNOT_T_BRACKET_CLOSE; - return 0; - } -// 271 "scanner.c" -jj22: - ++JJCURSOR; -// 137 "scanner.re" - { - token->opcode = PHANNOT_T_SBRACKET_OPEN; - return 0; - } -// 279 "scanner.c" -jj24: - ++JJCURSOR; -// 142 "scanner.re" - { - token->opcode = PHANNOT_T_SBRACKET_CLOSE; - return 0; - } -// 287 "scanner.c" -jj26: - ++JJCURSOR; -// 147 "scanner.re" - { - token->opcode = PHANNOT_T_AT; - return 0; - } -// 295 "scanner.c" -jj28: - ++JJCURSOR; -// 152 "scanner.re" - { - token->opcode = PHANNOT_T_EQUALS; - return 0; - } -// 303 "scanner.c" -jj30: - ++JJCURSOR; -// 157 "scanner.re" - { - token->opcode = PHANNOT_T_COLON; - return 0; - } -// 311 "scanner.c" -jj32: - ++JJCURSOR; -// 162 "scanner.re" - { - token->opcode = PHANNOT_T_COMMA; - return 0; - } -// 319 "scanner.c" -jj34: - ++JJCURSOR; - jjch = *JJCURSOR; - goto jj42; -jj35: -// 167 "scanner.re" - { - token->opcode = PHANNOT_T_IGNORE; - return 0; - } -// 330 "scanner.c" -jj36: - ++JJCURSOR; -// 172 "scanner.re" - { - s->active_line++; - token->opcode = PHANNOT_T_IGNORE; - return 0; - } -// 339 "scanner.c" -jj38: - ++JJCURSOR; -// 178 "scanner.re" - { - status = PHANNOT_SCANNER_RETCODE_EOF; - break; - } -// 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; -<<<<<<< HEAD - } -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; - } -======= - } -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; + phalcon_fetch_params(0, 2, 0, &entity, &data); + + if (Z_TYPE_P(entity) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_validation_exception_ce, "The entity must be an object"); + 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; } -// 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; - } ->>>>>>> 1.2.2 -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; + } + + 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(); +} + +static PHP_METHOD(Phalcon_Validation, getValue){ + + zval *attribute, *entity, *method, *value = NULL, *data, *values; + zval *filters, *field_filters, *service_name; + zval *dependency_injector = NULL, *filter_service; + + 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); + } } -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; + + 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 (Z_TYPE_P(data) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "There is no data to validate"); + 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); + } + + 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); + } + } 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); } -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; -<<<<<<< HEAD + } + } + + 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(); + } } -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)) { -======= - } -jj62: -// 89 "scanner.re" - { - token->opcode = PHANNOT_T_FALSE; - return 0; + + phalcon_update_property_array(this_ptr, SL("_values"), attribute, value TSRMLS_CC); + + RETURN_CCTOR(value); + } + + RETURN_MM_NULL(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Version){ + + PHALCON_REGISTER_CLASS(Phalcon, Version, version, phalcon_version_method_entry, 0); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Version, _getVersion){ + + zval *version; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(version); + array_init_size(version, 5); + add_next_index_long(version, 1); + add_next_index_long(version, 2); + add_next_index_long(version, 2); + add_next_index_long(version, 4); + add_next_index_long(version, 0); + RETURN_CTOR(version); +} + +static PHP_METHOD(Phalcon_Version, get){ + + zval *version, *major, *medium, *minor, *special, *special_number; + zval *result, *suffix = NULL; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(version); + PHALCON_CALL_SELF(version, this_ptr, "_getversion"); + + PHALCON_OBS_VAR(major); + phalcon_array_fetch_long(&major, version, 0, PH_NOISY); + + PHALCON_OBS_VAR(medium); + phalcon_array_fetch_long(&medium, version, 1, PH_NOISY); + + PHALCON_OBS_VAR(minor); + phalcon_array_fetch_long(&minor, version, 2, PH_NOISY); + + PHALCON_OBS_VAR(special); + phalcon_array_fetch_long(&special, version, 3, PH_NOISY); + + PHALCON_OBS_VAR(special_number); + phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY); + + PHALCON_INIT_VAR(result); + PHALCON_CONCAT_VSVSVS(result, major, ".", medium, ".", minor, " "); + + switch (phalcon_get_intval(special)) { + + case 1: + PHALCON_INIT_VAR(suffix); + PHALCON_CONCAT_SV(suffix, "ALPHA ", special_number); + break; + + case 2: + PHALCON_INIT_NVAR(suffix); + PHALCON_CONCAT_SV(suffix, "BETA ", special_number); + break; + + case 3: + PHALCON_INIT_NVAR(suffix); + PHALCON_CONCAT_SV(suffix, "RC ", special_number); + break; + + default: + PHALCON_INIT_NVAR(suffix); + ZVAL_STRING(suffix, "", 1); + break; + + } + phalcon_concat_self(&result, suffix TSRMLS_CC); + phalcon_fast_trim(return_value, result, PHALCON_TRIM_BOTH TSRMLS_CC); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Version, getId){ + + zval *version, *major, *medium, *minor, *special, *special_number; + zval *format, *real_medium, *real_minor; + + PHALCON_MM_GROW(); + + PHALCON_INIT_VAR(version); + PHALCON_CALL_SELF(version, this_ptr, "_getversion"); + + PHALCON_OBS_VAR(major); + phalcon_array_fetch_long(&major, version, 0, PH_NOISY); + + PHALCON_OBS_VAR(medium); + phalcon_array_fetch_long(&medium, version, 1, PH_NOISY); + + PHALCON_OBS_VAR(minor); + phalcon_array_fetch_long(&minor, version, 2, PH_NOISY); + + PHALCON_OBS_VAR(special); + phalcon_array_fetch_long(&special, version, 3, PH_NOISY); + + PHALCON_OBS_VAR(special_number); + phalcon_array_fetch_long(&special_number, version, 4, PH_NOISY); + + PHALCON_INIT_VAR(format); + ZVAL_STRING(format, "%02s", 1); + + PHALCON_INIT_VAR(real_medium); + phalcon_call_func_p2(real_medium, "sprintf", format, medium); + + PHALCON_INIT_VAR(real_minor); + phalcon_call_func_p2(real_minor, "sprintf", format, minor); + PHALCON_CONCAT_VVVVV(return_value, major, real_medium, real_minor, special, special_number); + RETURN_MM(); +} + + + + + +#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_Loader, __construct){ + + zval *extensions; + + 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_Loader, 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_Loader, getEventsManager){ + + + RETURN_MEMBER_QUICK(this_ptr, "_eventsManager", 799100116UL); +} + +static PHP_METHOD(Phalcon_Loader, setExtensions){ + + zval *extensions; + + 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){ + + + RETURN_MEMBER_QUICK(this_ptr, "_extensions", 726159316UL); +} + +static PHP_METHOD(Phalcon_Loader, registerNamespaces){ + + zval *namespaces, *merge = NULL, *current_namespaces; + zval *merged_namespaces = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &namespaces, &merge); + + if (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 0); + } + + if (Z_TYPE_P(namespaces) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_loader_exception_ce, "Parameter namespaces must be an array"); + return; + } + 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_Loader, getNamespaces){ + + + RETURN_MEMBER_QUICK(this_ptr, "_namespaces", 3363620132UL); +} + +static PHP_METHOD(Phalcon_Loader, registerPrefixes){ + + zval *prefixes, *merge = NULL, *current_prefixes, *merged_prefixes = NULL; + + 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); } -// 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; + + 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){ + + + RETURN_MEMBER_QUICK(this_ptr, "_prefixes", 900970058UL); +} + +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); } -// 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; ->>>>>>> 1.2.2 - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': -<<<<<<< HEAD - 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; + + 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); +} + +static PHP_METHOD(Phalcon_Loader, registerClasses){ + + zval *classes, *merge = NULL, *current_classes, *merged_classes = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, &classes, &merge); + + if (!merge) { + PHALCON_INIT_VAR(merge); + ZVAL_BOOL(merge, 0); + } + + 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); } -// 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; + + 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_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); + } + + 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); + } + + 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_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(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_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_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); } -======= - case '9': goto jj68; - default: goto jj5; + + if (phalcon_require(file_path TSRMLS_CC) == FAILURE) { + return; } ->>>>>>> 1.2.2 -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; + 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; + } + + zend_hash_move_forward_ex(ah1, &hp1); + } + + } } -jj72: -// 76 "scanner.re" - { - token->opcode = PHANNOT_T_DOUBLE; - token->value = estrndup(start, JJCURSOR - start); - token->len = JJCURSOR - start; - q = JJCURSOR; - return 0; + + zend_hash_move_forward_ex(ah0, &hp0); } -// 819 "scanner.c" + + } + + 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)) { + + PHALCON_INIT_NVAR(fixed_directory); + phalcon_fix_path(&fixed_directory, directory, ds TSRMLS_CC); + + phalcon_is_iterable(extensions, &ah3, &hp3, 0, 0); + + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == 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_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 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; + } + + zend_hash_move_forward_ex(ah3, &hp3); + } + + } + } + + zend_hash_move_forward_ex(ah2, &hp2); } -// 188 "scanner.re" - - + + } + + 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); + + while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { + + PHALCON_GET_HVALUE(extension); + + PHALCON_INIT_NVAR(file_path); + PHALCON_CONCAT_VVSV(file_path, fixed_directory, ns_class_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_p3_key(NULL, events_manager, "fire", event_name, this_ptr, file_path, 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; + } + + zend_hash_move_forward_ex(ah5, &hp5); + } + + zend_hash_move_forward_ex(ah4, &hp4); } + } + + 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; +} - return status; +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); +} + + -/* 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" #ifdef HAVE_CONFIG_H @@ -139309,1946 +66747,2028 @@ static int phannot_get_token(phannot_scanner_state *s, phannot_scanner_token *to -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_INIT_CLASS(Phalcon_Kernel){ + + PHALCON_REGISTER_CLASS(Phalcon, Kernel, kernel, phalcon_kernel_method_entry, 0); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Kernel, preComputeHashKey){ + + char *arKey, *strKey; + unsigned int nKeyLength; + register ulong hash = 5381; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { + RETURN_NULL(); } - return ret; + 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++; + } + + 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; + } + + strKey = emalloc(24); + sprintf(strKey, "%lu", hash); + + RETURN_STRING(strKey, 0); } -static zval *phannot_ret_array(zval *items) -{ - zval *ret; +static PHP_METHOD(Phalcon_Kernel, preComputeHashKey32){ - MAKE_STD_ZVAL(ret); - array_init(ret); - add_assoc_long(ret, "type", PHANNOT_T_ARRAY); + char *arKey, *strKey; + unsigned int nKeyLength; + ulong hash; - if (items) { - add_assoc_zval(ret, "items", items); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { + RETURN_NULL(); } - return ret; + nKeyLength++; + hash = zend_inline_hash_func(arKey, nKeyLength) & 0xFFFFFFFFul; + strKey = emalloc(24); + sprintf(strKey, "%lu", hash); + + RETURN_STRING(strKey, 0); } -static zval *phannot_ret_zval_list(zval *list_left, zval *right_list) -{ +static PHP_METHOD(Phalcon_Kernel, preComputeHashKey64){ - zval *ret; - HashPosition pos; - HashTable *list; + char *arKey, *strKey; + unsigned int nKeyLength; + register unsigned long long hash = 5381; - MAKE_STD_ZVAL(ret); - array_init(ret); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { + RETURN_NULL(); + } + + 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++; + } + + 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; + } + + strKey = emalloc(24); + sprintf(strKey, "%llu", hash); + + RETURN_STRING(strKey, 0); +} + + + + + +#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); + + 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(); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +PHALCON_INIT_CLASS(Phalcon_Session){ + + PHALCON_REGISTER_CLASS(Phalcon, Session, session, NULL, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + return SUCCESS; +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Tag){ + + PHALCON_REGISTER_CLASS(Phalcon, Tag, tag, phalcon_tag_method_entry, 0); + + zend_declare_property_null(phalcon_tag_ce, SL("_displayValues"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + zend_declare_property_null(phalcon_tag_ce, SL("_documentTitle"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + zend_declare_property_long(phalcon_tag_ce, SL("_documentType"), 11, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + zend_declare_property_null(phalcon_tag_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + zend_declare_property_null(phalcon_tag_ce, SL("_urlService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + zend_declare_property_null(phalcon_tag_ce, SL("_dispatcherService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + zend_declare_property_null(phalcon_tag_ce, SL("_escaperService"), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + zend_declare_property_bool(phalcon_tag_ce, SL("_autoEscape"), 1, ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC); + + zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML32"), 1 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_STRICT"), 2 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_TRANSITIONAL"), 3 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML401_FRAMESET"), 4 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_tag_ce, SL("HTML5"), 5 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_STRICT"), 6 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_TRANSITIONAL"), 7 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML10_FRAMESET"), 8 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML11"), 9 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML20"), 10 TSRMLS_CC); + zend_declare_class_constant_long(phalcon_tag_ce, SL("XHTML5"), 11 TSRMLS_CC); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Tag, 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_tag_exception_ce, "Parameter dependencyInjector must be an Object"); + return; + } + phalcon_update_static_property(SL("phalcon\\tag"), SL("_dependencyInjector"), dependency_injector TSRMLS_CC); + +} + +static PHP_METHOD(Phalcon_Tag, getDI){ - if (list_left) { + zval *dependency_injector; - 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)) { + PHALCON_MM_GROW(); - zval ** item; + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_CC); + RETURN_CCTOR(dependency_injector); +} - if (zend_hash_get_current_data_ex(list, (void**) &item, &pos) == FAILURE) { - break; - } +static PHP_METHOD(Phalcon_Tag, getUrlService){ - Z_ADDREF_PP(item); - add_next_index_zval(ret, *item); + zval *url = NULL, *dependency_injector = NULL, *service; - } - zval_ptr_dtor(&list_left); - } else { - add_next_index_zval(ret, list_left); + PHALCON_MM_GROW(); + + PHALCON_OBS_VAR(url); + phalcon_read_static_property(&url, SL("phalcon\\tag"), SL("_urlService") TSRMLS_CC); + if (Z_TYPE_P(url) != IS_OBJECT) { + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_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_tag_exception_ce, "A dependency injector container is required to obtain the \"url\" service"); + return; } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "url", 1); + + PHALCON_INIT_NVAR(url); + phalcon_call_method_p1_key(url, dependency_injector, "getshared", service, 1727570332UL); + phalcon_update_static_property(SL("phalcon\\tag"), SL("_urlService"), url TSRMLS_CC); } + + RETURN_CCTOR(url); +} - add_next_index_zval(ret, right_list); +static PHP_METHOD(Phalcon_Tag, getEscaperService){ - return ret; -} + zval *escaper = NULL, *dependency_injector = NULL, *service; -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); + PHALCON_OBS_VAR(escaper); + phalcon_read_static_property(&escaper, SL("phalcon\\tag"), SL("_escaperService") TSRMLS_CC); + if (Z_TYPE_P(escaper) != IS_OBJECT) { + + PHALCON_OBS_VAR(dependency_injector); + phalcon_read_static_property(&dependency_injector, SL("phalcon\\tag"), SL("_dependencyInjector") TSRMLS_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_tag_exception_ce, "A dependency injector container is required to obtain the \"escaper\" service"); + return; + } + + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "escaper", 1); + + PHALCON_INIT_NVAR(escaper); + phalcon_call_method_p1_key(escaper, dependency_injector, "getshared", service, 1727570332UL); + phalcon_update_static_property(SL("phalcon\\tag"), SL("_escaperService"), escaper TSRMLS_CC); } - - return ret; + + RETURN_CCTOR(escaper); } -static zval *phannot_ret_annotation(phannot_parser_token *name, zval *arguments, phannot_scanner_state *state) -{ +static PHP_METHOD(Phalcon_Tag, setAutoescape){ - zval *ret; + zval *autoescape; - MAKE_STD_ZVAL(ret); - array_init(ret); + phalcon_fetch_params(0, 1, 0, &autoescape); + + phalcon_update_static_property(SL("phalcon\\tag"), SL("_autoEscape"), autoescape TSRMLS_CC); + +} - add_assoc_long(ret, "type", PHANNOT_T_ANNOTATION); +static PHP_METHOD(Phalcon_Tag, setDefault){ - if (name) { - add_assoc_stringl(ret, "name", name->token, name->token_len, 0); - efree(name); - } + zval *id, *value; + zval *t0 = NULL; - if (arguments) { - add_assoc_zval(ret, "arguments", arguments); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &id, &value); + + if (Z_TYPE_P(value) != IS_NULL) { + if (Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_tag_exception_ce, "Only scalar values can be assigned to UI components"); + return; + } + } + PHALCON_OBSERVE_VAR(t0); + phalcon_read_static_property(&t0, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); + if (Z_TYPE_P(t0) != IS_ARRAY) { + convert_to_array(t0); } + phalcon_array_update_zval(&t0, id, &value, PH_COPY); + phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), t0 TSRMLS_CC); + + + PHALCON_MM_RESTORE(); +} - Z_ADDREF_P(state->active_file); - add_assoc_zval(ret, "file", state->active_file); - add_assoc_long(ret, "line", state->active_line); +static PHP_METHOD(Phalcon_Tag, setDefaults){ - return ret; + zval *values; + + phalcon_fetch_params(0, 1, 0, &values); + + if (Z_TYPE_P(values) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_tag_exception_ce, "An array is required as default values"); + return; + } + phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), values TSRMLS_CC); + } +static PHP_METHOD(Phalcon_Tag, displayTo){ -// 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) + zval *id, *value, *default_value; -/* 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, -<<<<<<< HEAD -}; -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, -}; -======= -}; -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, -}; ->>>>>>> 1.2.2 -#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, -<<<<<<< HEAD -}; -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])) + 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 JJFALLBACK -static const JJCODETYPE jjFallback[] = { -}; -#endif /* JJFALLBACK */ + phalcon_fetch_params(1, 2, 0, &id, &value); + + PHALCON_INIT_VAR(default_value); + PHALCON_CALL_SELF_PARAMS_2(default_value, this_ptr, "setdefault", id, value); + RETURN_CCTOR(default_value); +} -/* 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_Tag, hasValue){ -/* 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; + zval *name, *display_values, *_POST; -#ifndef NDEBUG -#include -static FILE *jjTraceFILE = 0; -static char *jjTracePrompt = 0; -#endif /* NDEBUG */ + PHALCON_MM_GROW(); -#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; + phalcon_fetch_params(1, 1, 0, &name); + + PHALCON_OBS_VAR(display_values); + phalcon_read_static_property(&display_values, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); + + if (phalcon_array_isset(display_values, name)) { + RETURN_MM_TRUE; + } else { + phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); + if (phalcon_array_isset(_POST, name)) { + RETURN_MM_TRUE; + } + } + + RETURN_MM_FALSE; } -#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 *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 */ -#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 */ +static PHP_METHOD(Phalcon_Tag, getValue){ -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 -} + zval *name, *params = NULL, *display_values, *value = NULL, *_POST; + zval *autoescape = NULL, *escaper = NULL; -void *phannot_Alloc(void *(*mallocProc)(size_t)){ - jjParser *pParser; - pParser = (jjParser*)(*mallocProc)( (size_t)sizeof(jjParser) ); - if( pParser ){ - pParser->jjidx = -1; - } - return pParser; -} + PHALCON_MM_GROW(); -/* 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_fetch_params(1, 1, 1, &name, ¶ms); + + if (!params) { + PHALCON_INIT_VAR(params); + } + + PHALCON_OBS_VAR(display_values); + phalcon_read_static_property(&display_values, SL("phalcon\\tag"), SL("_displayValues") TSRMLS_CC); + + if (phalcon_array_isset(display_values, name)) { + PHALCON_OBS_VAR(value); + phalcon_array_fetch(&value, display_values, name, PH_NOISY); + } else { + phalcon_get_global(&_POST, SS("_POST") TSRMLS_CC); + if (phalcon_array_isset(_POST, name)) { + PHALCON_OBS_NVAR(value); + phalcon_array_fetch(&value, _POST, name, PH_NOISY); + } else { + RETURN_MM_NULL(); } - efree((jjpminor->jj0)); } -} -// 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 */ - } + + PHALCON_OBS_VAR(autoescape); + phalcon_read_static_property(&autoescape, SL("phalcon\\tag"), SL("_autoEscape") TSRMLS_CC); + + if (Z_TYPE_P(value) == IS_STRING) { + if (zend_is_true(autoescape)) { + PHALCON_INIT_VAR(escaper); + PHALCON_CALL_SELF(escaper, this_ptr, "getescaperservice"); + phalcon_call_method_p1_key(return_value, escaper, "escapehtmlattr", value, 4208410982UL); + RETURN_MM(); + } else { + if (Z_TYPE_P(params) == IS_ARRAY) { + + if (phalcon_array_isset_quick_string(params, SS("escape"), 1978755574UL)) { + + PHALCON_OBS_NVAR(autoescape); + phalcon_array_fetch_quick_string(&autoescape, params, SS("escape"), 1978755574UL, PH_NOISY); + if (zend_is_true(autoescape)) { + PHALCON_INIT_NVAR(escaper); + PHALCON_CALL_SELF(escaper, this_ptr, "getescaperservice"); + phalcon_call_method_p1_key(return_value, escaper, "escapehtmlattr", value, 4208410982UL); + RETURN_MM(); + } + } + } + } + } + + RETURN_CCTOR(value); } -static int jj_pop_parser_stack(jjParser *pParser){ - JJCODETYPE jjmajor; - jjStackEntry *jjtos = &pParser->jjstack[pParser->jjidx]; +static PHP_METHOD(Phalcon_Tag, resetInput){ - 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; -} + zval *empty_array = NULL; -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_MM_GROW(); -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]; - } -} + PHALCON_INIT_VAR(empty_array); + array_init(empty_array); -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]; - } -} + phalcon_update_static_property(SL("phalcon\\tag"), SL("_displayValues"), empty_array TSRMLS_CC); -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 + phalcon_set_symbol_str(SS("_POST"), empty_array TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -/* 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 PHP_METHOD(Phalcon_Tag, linkTo){ -static void jj_accept(jjParser*); /* Forward Declaration */ + zval *parameters, *text = NULL, *params = NULL, *action = NULL, *url, *internal_url; + zval *code, *value = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; -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); + phalcon_fetch_params(1, 1, 1, ¶meters, &text); + + if (!text) { + PHALCON_INIT_VAR(text); + } else { + PHALCON_SEPARATE_PARAM(text); + } + + 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, text, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(params, parameters); + } + + PHALCON_INIT_VAR(action); + ZVAL_STRING(action, "", 1); + if (phalcon_array_isset_long(params, 0)) { + PHALCON_OBS_NVAR(action); + phalcon_array_fetch_long(&action, params, 0, PH_NOISY); + } else { + if (phalcon_array_isset_quick_string(params, SS("action"), 502132067UL)) { + PHALCON_OBS_NVAR(action); + phalcon_array_fetch_quick_string(&action, params, SS("action"), 502132067UL, PH_NOISY); + phalcon_array_unset_string(¶ms, SS("action"), PH_SEPARATE); + } + } + + PHALCON_INIT_NVAR(text); + ZVAL_STRING(text, "", 1); + if (phalcon_array_isset_long(params, 1)) { + PHALCON_OBS_NVAR(text); + phalcon_array_fetch_long(&text, params, 1, PH_NOISY); + } else { + if (phalcon_array_isset_quick_string(params, SS("text"), 275483210UL)) { + PHALCON_OBS_NVAR(text); + phalcon_array_fetch_quick_string(&text, params, SS("text"), 275483210UL, PH_NOISY); + phalcon_array_unset_string(¶ms, SS("text"), PH_SEPARATE); + } + } + + PHALCON_INIT_VAR(url); + PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); + + PHALCON_INIT_VAR(internal_url); + phalcon_call_method_p1_key(internal_url, url, "get", action, 2090288933UL); + + PHALCON_INIT_VAR(code); + PHALCON_CONCAT_SVS(code, "", text, ""); + + RETURN_CTOR(code); } -// 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_Tag, _inputField){ + + zval *type, *parameters, *as_value = NULL, *params = NULL, *value = NULL; + zval *id = NULL, *name, *code, *key = NULL, *doctype; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 1, &type, ¶meters, &as_value); + + if (!as_value) { + PHALCON_INIT_VAR(as_value); + ZVAL_BOOL(as_value, 0); + } + + if (Z_TYPE_P(parameters) != IS_ARRAY) { + PHALCON_INIT_VAR(params); + array_init_size(params, 1); + phalcon_array_append(¶ms, parameters, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(params, parameters); + } + + PHALCON_INIT_VAR(value); + if (PHALCON_IS_FALSE(as_value)) { + 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_CALL_SELF_PARAMS_2(value, this_ptr, "getvalue", id, params); + phalcon_array_update_quick_string(¶ms, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); + } + } else { + if (!phalcon_array_isset_quick_string(params, SS("value"), 574111618UL)) { + if (phalcon_array_isset_long(params, 0)) { + PHALCON_OBS_NVAR(value); + phalcon_array_fetch_long(&value, params, 0, PH_NOISY); + phalcon_array_update_quick_string(¶ms, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); + } + } + } + + PHALCON_INIT_VAR(code); + PHALCON_CONCAT_SVS(code, "") TSRMLS_CC); + } else { + phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); + } + + RETURN_CTOR(code); } -// 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_Tag, _inputFieldChecked){ + + zval *type, *parameters, *params = NULL, *value = NULL, *id = NULL, *name; + zval *current_value, *code, *key = NULL, *doctype; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &type, ¶meters); + + if (Z_TYPE_P(parameters) != IS_ARRAY) { + PHALCON_INIT_VAR(params); + array_init_size(params, 1); + phalcon_array_append(¶ms, parameters, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(params, parameters); + } + + PHALCON_INIT_VAR(value); + 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); + } + } + + PHALCON_CALL_SELF_PARAMS_2(value, this_ptr, "getvalue", id, params); + + if (phalcon_array_isset_quick_string(params, SS("value"), 574111618UL)) { + + PHALCON_OBS_VAR(current_value); + phalcon_array_fetch_quick_string(¤t_value, params, SS("value"), 574111618UL, PH_NOISY); + if (PHALCON_IS_EQUAL(current_value, value)) { + phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE); + } + } else { + if (zend_is_true(value)) { + phalcon_array_update_string_string(¶ms, SL("checked"), SL("checked"), PH_SEPARATE); + } + + phalcon_array_update_quick_string(¶ms, SS("value"), 574111618UL, &value, PH_COPY | PH_SEPARATE); + } + + PHALCON_INIT_VAR(code); + PHALCON_CONCAT_SVS(code, "") TSRMLS_CC); + } else { + phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); + } + + RETURN_CTOR(code); } -// 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_Tag, textField){ + + zval *parameters, *name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, ¶meters); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "text", 1); + PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); + RETURN_MM(); } -// 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_Tag, numericField){ + + zval *parameters, *name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, ¶meters); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "number", 1); + PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); + RETURN_MM(); } -// 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_Tag, emailField){ + + zval *parameters, *name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, ¶meters); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "email", 1); + PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); + RETURN_MM(); } -// 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_Tag, dateField){ + + zval *parameters, *name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, ¶meters); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "date", 1); + PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); + RETURN_MM(); } -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_Tag, passwordField){ + + zval *parameters, *name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, ¶meters); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "password", 1); + PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); + RETURN_MM(); } -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_Tag, hiddenField){ - if (status->scanner_state->start_length) { - { + zval *parameters, *name; - 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_MM_GROW(); - if (active_token) { - do { - if (tokens->code == active_token) { - token_found = 1; - token_name = tokens->name; - break; - } - ++tokens; - } while (tokens[0].code != 0); - } + phalcon_fetch_params(1, 1, 0, ¶meters); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "hidden", 1); + PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); + RETURN_MM(); +} - if (!token_name) { - token_found = 0; - token_name = estrndup("UNKNOWN", strlen("UNKNOWN")); - } +static PHP_METHOD(Phalcon_Tag, fileField){ - 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); + zval *parameters, *name; - 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_MM_GROW(); - 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)); - } + phalcon_fetch_params(1, 1, 0, ¶meters); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "file", 1); + PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfield", name, parameters); + RETURN_MM(); +} - status->status = PHANNOT_PARSING_FAILED; +static PHP_METHOD(Phalcon_Tag, checkField){ -// 1019 "parser.c" - phannot_ARG_STORE; /* Suppress warning about unused %extra_argument variable */ + zval *parameters, *name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, ¶meters); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "checkbox", 1); + PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfieldchecked", name, parameters); + RETURN_MM(); } -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_Tag, radioField){ + + zval *parameters, *name; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, ¶meters); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "radio", 1); + PHALCON_CALL_SELF_PARAMS_2(return_value, this_ptr, "_inputfieldchecked", name, parameters); + RETURN_MM(); } -/* 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_Tag, imageInput){ - /* (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 *parameters, *name, *as_value; -#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, 1, 0, ¶meters); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "image", 1); + + PHALCON_INIT_VAR(as_value); + ZVAL_BOOL(as_value, 1); + PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_inputfield", name, parameters, as_value); + RETURN_MM(); } +static PHP_METHOD(Phalcon_Tag, submitButton){ -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 *parameters, *name, *as_value; -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, 0, ¶meters); + + PHALCON_INIT_VAR(name); + ZVAL_STRING(name, "submit", 1); + + PHALCON_INIT_VAR(as_value); + ZVAL_BOOL(as_value, 1); + PHALCON_CALL_SELF_PARAMS_3(return_value, this_ptr, "_inputfield", name, parameters, as_value); + RETURN_MM(); } -static void phannot_parse_with_token(void* phannot_parser, int opcode, int parsercode, phannot_scanner_token *token, phannot_parser_status *parser_status){ +static PHP_METHOD(Phalcon_Tag, selectStatic){ - phannot_parser_token *pToken; + zval *parameters, *data = NULL; - pToken = emalloc(sizeof(phannot_parser_token)); - pToken->opcode = opcode; - pToken->token = token->value; - pToken->token_len = token->len; - pToken->free_flag = 1; + PHALCON_MM_GROW(); - phannot_(phannot_parser, parsercode, pToken, parser_status); + phalcon_fetch_params(1, 1, 1, ¶meters, &data); + + if (!data) { + PHALCON_INIT_VAR(data); + } + + PHALCON_CALL_STATIC_PARAMS_2(return_value, "phalcon\\tag\\select", "selectfield", parameters, data); + RETURN_MM(); +} - token->value = NULL; - token->len = 0; +static PHP_METHOD(Phalcon_Tag, select){ + + zval *parameters, *data = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 1, ¶meters, &data); + + if (!data) { + PHALCON_INIT_VAR(data); + } + + PHALCON_CALL_STATIC_PARAMS_2(return_value, "phalcon\\tag\\select", "selectfield", parameters, data); + RETURN_MM(); } -static void phannot_scanner_error_msg(phannot_parser_status *parser_status, zval **error_msg TSRMLS_DC){ +static PHP_METHOD(Phalcon_Tag, textArea){ - int error_length; - char *error, *error_part; - phannot_scanner_state *state = parser_status->scanner_state; + zval *parameters, *params = NULL, *id = NULL, *name, *content = NULL, *code; + zval *avalue = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - 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); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, ¶meters); + + if (Z_TYPE_P(parameters) != IS_ARRAY) { + PHALCON_INIT_VAR(params); + array_init_size(params, 1); + phalcon_array_append(¶ms, parameters, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(params, parameters); + } + if (!phalcon_array_isset_long(params, 0)) { + if (phalcon_array_isset_quick_string(params, SS("id"), 193494642UL)) { + 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); } - error[error_length - 1] = '\0'; - ZVAL_STRING(*error_msg, error, 1); + } + + 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 { - 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_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); + } } - efree(error); + + 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_OBS_VAR(content); + phalcon_array_fetch_quick_string(&content, params, SS("value"), 574111618UL, PH_NOISY); + phalcon_array_unset_string(¶ms, SS("value"), PH_SEPARATE); + } else { + PHALCON_INIT_NVAR(content); + PHALCON_CALL_SELF_PARAMS_2(content, this_ptr, "getvalue", id, params); + } + + PHALCON_INIT_VAR(code); + ZVAL_STRING(code, "", content, ""); + + RETURN_CTOR(code); } -static int phannot_parse_annotations(zval *result, zval *comment, zval *file_path, zval *line TSRMLS_DC){ +static PHP_METHOD(Phalcon_Tag, form){ - zval *error_msg = NULL; + zval *parameters = NULL, *params = NULL, *params_action = NULL, *action = NULL; + zval *url, *code, *avalue = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; - 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, ¶meters); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } else { + PHALCON_SEPARATE_PARAM(parameters); } - - 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 (Z_TYPE_P(parameters) != IS_ARRAY) { + PHALCON_INIT_VAR(params); + array_init_size(params, 1); + phalcon_array_append(¶ms, parameters, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(params, parameters); + } + if (phalcon_array_isset_long(params, 0)) { + PHALCON_OBS_VAR(params_action); + phalcon_array_fetch_long(¶ms_action, params, 0, PH_NOISY); + } else { + if (phalcon_array_isset_quick_string(params, SS("action"), 502132067UL)) { + PHALCON_OBS_NVAR(params_action); + phalcon_array_fetch_quick_string(¶ms_action, params, SS("action"), 502132067UL, PH_NOISY); + } else { + PHALCON_INIT_NVAR(params_action); + } + } + + if (!phalcon_array_isset_quick_string(params, SS("method"), 3193080326UL)) { + phalcon_array_update_string_string(¶ms, SL("method"), SL("post"), PH_SEPARATE); + } + + PHALCON_INIT_VAR(action); + + if (Z_TYPE_P(params_action) != IS_NULL) { + PHALCON_INIT_VAR(url); + PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); + + phalcon_call_method_p1_key(action, url, "get", params_action, 2090288933UL); + } + + if (phalcon_array_isset_quick_string(params, SS("parameters"), 3941032889UL)) { + PHALCON_OBS_NVAR(parameters); + phalcon_array_fetch_quick_string(¶meters, params, SS("parameters"), 3941032889UL, PH_NOISY); + PHALCON_SCONCAT_SV(action, "?", parameters); + } + + if (Z_TYPE_P(action) != IS_NULL) { + phalcon_array_update_quick_string(¶ms, SS("action"), 502132067UL, &action, PH_COPY | PH_SEPARATE); + } + + PHALCON_INIT_VAR(code); + ZVAL_STRING(code, "") TSRMLS_CC); + + RETURN_CTOR(code); +} - return SUCCESS; +static PHP_METHOD(Phalcon_Tag, endForm){ + + + RETURN_STRING("", 1); } -static void phannot_remove_comment_separators(zval *return_value, char *comment, int length, int *start_lines) { +static PHP_METHOD(Phalcon_Tag, setTitle){ - int start_mode = 1, j, i, open_parentheses; - smart_str processed_str = {0}; - char ch; + zval *title; - (*start_lines) = 0; + phalcon_fetch_params(0, 1, 0, &title); + + phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), title TSRMLS_CC); + +} - for (i = 0; i < length; i++) { +static PHP_METHOD(Phalcon_Tag, appendTitle){ - ch = comment[i]; + zval *title; + zval *t0 = NULL; + zval *r0 = NULL; - if (start_mode) { - if (ch == ' ' || ch == '*' || ch == '/' || ch == '\t' || ch == 11) { - continue; - } - start_mode = 0; - } + PHALCON_MM_GROW(); - if (ch == '@') { + phalcon_fetch_params(1, 1, 0, &title); + + PHALCON_OBS_VAR(t0); + phalcon_read_static_property(&t0, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); + PHALCON_ALLOC_ZVAL_MM(r0); + concat_function(r0, t0, title TSRMLS_CC); + phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), r0 TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} - smart_str_appendc(&processed_str, ch); - i++; +static PHP_METHOD(Phalcon_Tag, prependTitle){ - open_parentheses = 0; - for (j = i; j < length; j++) { + zval *title, *document_title; + zval *r0 = NULL; - ch = comment[j]; + PHALCON_MM_GROW(); - if (start_mode) { - if (ch == ' ' || ch == '*' || ch == '/' || ch == '\t' || ch == 11) { - continue; - } - start_mode = 0; - } + phalcon_fetch_params(1, 1, 0, &title); + + PHALCON_OBS_VAR(document_title); + phalcon_read_static_property(&document_title, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); + + PHALCON_INIT_VAR(r0); + PHALCON_CONCAT_VV(r0, title, document_title); + phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentTitle"), r0 TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} - if (open_parentheses == 0) { +static PHP_METHOD(Phalcon_Tag, getTitle){ - if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { - smart_str_appendc(&processed_str, ch); - continue; - } + zval *tags = NULL, *document_title, *eol; - if (ch == '(') { - smart_str_appendc(&processed_str, ch); - open_parentheses++; - continue; - } + PHALCON_MM_GROW(); - } else { + phalcon_fetch_params(1, 0, 1, &tags); + + if (!tags) { + PHALCON_INIT_VAR(tags); + ZVAL_BOOL(tags, 1); + } + + PHALCON_OBS_VAR(document_title); + phalcon_read_static_property(&document_title, SL("phalcon\\tag"), SL("_documentTitle") TSRMLS_CC); + if (PHALCON_IS_TRUE(tags)) { + PHALCON_INIT_VAR(eol); + ZVAL_STRING(eol, PHP_EOL, 1); + PHALCON_CONCAT_SVSV(return_value, "", document_title, "", eol); + RETURN_MM(); + } + + RETURN_CCTOR(document_title); +} + +static PHP_METHOD(Phalcon_Tag, stylesheetLink){ + + zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; + zval *url, *url_href, *href, *code, *value = NULL, *key = NULL, *doctype; + zval *eol; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, ¶meters, &local); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } + + if (!local) { + PHALCON_INIT_VAR(local); + ZVAL_BOOL(local, 1); + } else { + PHALCON_SEPARATE_PARAM(local); + } + + 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, local, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(params, parameters); + } + if (!phalcon_array_isset_quick_string(params, SS("href"), 261698186UL)) { + if (phalcon_array_isset_long(params, 0)) { + PHALCON_OBS_VAR(first_param); + phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY); + phalcon_array_update_quick_string(¶ms, SS("href"), 261698186UL, &first_param, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_string_string(¶ms, SL("href"), SL(""), PH_SEPARATE); + } + } + + PHALCON_INIT_NVAR(local); + ZVAL_BOOL(local, 0); + if (phalcon_array_isset_long(params, 1)) { + PHALCON_OBS_NVAR(local); + phalcon_array_fetch_long(&local, params, 1, PH_NOISY); + } else { + if (phalcon_array_isset_quick_string(params, SS("local"), 199015600UL)) { + PHALCON_OBS_NVAR(local); + phalcon_array_fetch_quick_string(&local, params, SS("local"), 199015600UL, PH_NOISY); + phalcon_array_unset_string(¶ms, SS("local"), PH_SEPARATE); + } + } + + if (!phalcon_array_isset_quick_string(params, SS("type"), 276192743UL)) { + phalcon_array_update_string_string(¶ms, SL("type"), SL("text/css"), PH_SEPARATE); + } + + if (zend_is_true(local)) { + PHALCON_INIT_VAR(url); + PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); + + PHALCON_OBS_VAR(url_href); + phalcon_array_fetch_quick_string(&url_href, params, SS("href"), 261698186UL, PH_NOISY); + + PHALCON_INIT_VAR(href); + phalcon_call_method_p1_key(href, url, "getstatic", url_href, 2197271245UL); + phalcon_array_update_quick_string(¶ms, SS("href"), 261698186UL, &href, PH_COPY | PH_SEPARATE); + } + + PHALCON_INIT_VAR(code); + ZVAL_STRING(code, "", eol); + } else { + PHALCON_SCONCAT_SV(code, ">", eol); + } + + RETURN_CTOR(code); +} + +static PHP_METHOD(Phalcon_Tag, javascriptInclude){ + + zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; + zval *url, *params_src, *src, *eol, *code, *value = NULL, *key = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 2, ¶meters, &local); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } + + if (!local) { + PHALCON_INIT_VAR(local); + ZVAL_BOOL(local, 1); + } else { + PHALCON_SEPARATE_PARAM(local); + } + + 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, local, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(params, parameters); + } + if (!phalcon_array_isset_quick_string(params, SS("src"), 2090733773UL)) { + if (phalcon_array_isset_long(params, 0)) { + PHALCON_OBS_VAR(first_param); + phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY); + phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &first_param, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE); + } + } + + PHALCON_INIT_NVAR(local); + ZVAL_BOOL(local, 0); + if (phalcon_array_isset_long(params, 1)) { + PHALCON_OBS_NVAR(local); + phalcon_array_fetch_long(&local, params, 1, PH_NOISY); + } else { + if (phalcon_array_isset_quick_string(params, SS("local"), 199015600UL)) { + PHALCON_OBS_NVAR(local); + phalcon_array_fetch_quick_string(&local, params, SS("local"), 199015600UL, PH_NOISY); + phalcon_array_unset_string(¶ms, SS("local"), PH_SEPARATE); + } + } + + if (!phalcon_array_isset_quick_string(params, SS("type"), 276192743UL)) { + phalcon_array_update_string_string(¶ms, SL("type"), SL("text/javascript"), PH_SEPARATE); + } + + if (zend_is_true(local)) { + PHALCON_INIT_VAR(url); + PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); + + PHALCON_OBS_VAR(params_src); + phalcon_array_fetch_quick_string(¶ms_src, params, SS("src"), 2090733773UL, PH_NOISY); + + PHALCON_INIT_VAR(src); + phalcon_call_method_p1_key(src, url, "getstatic", params_src, 2197271245UL); + phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &src, PH_COPY | PH_SEPARATE); + } + + PHALCON_INIT_VAR(eol); + ZVAL_STRING(eol, PHP_EOL, 1); + + PHALCON_INIT_VAR(code); + ZVAL_STRING(code, "", eol); + + RETURN_CTOR(code); +} - smart_str_appendc(&processed_str, ch); +static PHP_METHOD(Phalcon_Tag, image){ - if (ch == '(') { - open_parentheses++; - } else { - if (ch == ')') { - open_parentheses--; - } else { - if (ch == '\n') { - (*start_lines)++; - start_mode = 1; - } - } - } + zval *parameters = NULL, *local = NULL, *params = NULL, *first_param; + zval *url, *url_src, *src, *code, *value = NULL, *key = NULL, *doctype; + HashTable *ah0; + HashPosition hp0; + zval **hd; - if (open_parentheses > 0) { - continue; - } - } + PHALCON_MM_GROW(); - i = j; - smart_str_appendc(&processed_str, ' '); - break; - } + phalcon_fetch_params(1, 0, 2, ¶meters, &local); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); + } + + if (!local) { + PHALCON_INIT_VAR(local); + ZVAL_BOOL(local, 1); + } + + if (Z_TYPE_P(parameters) != IS_ARRAY) { + PHALCON_INIT_VAR(params); + array_init_size(params, 1); + phalcon_array_append(¶ms, parameters, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(params, parameters); + } + if (!phalcon_array_isset_quick_string(params, SS("src"), 2090733773UL)) { + if (phalcon_array_isset_long(params, 0)) { + PHALCON_OBS_VAR(first_param); + phalcon_array_fetch_long(&first_param, params, 0, PH_NOISY); + phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &first_param, PH_COPY | PH_SEPARATE); + } else { + phalcon_array_update_string_string(¶ms, SL("src"), SL(""), PH_SEPARATE); } - - if (ch == '\n') { - (*start_lines)++; - start_mode = 1; + } + + if (zend_is_true(local)) { + PHALCON_INIT_VAR(url); + PHALCON_CALL_SELF(url, this_ptr, "geturlservice"); + + PHALCON_OBS_VAR(url_src); + phalcon_array_fetch_quick_string(&url_src, params, SS("src"), 2090733773UL, PH_NOISY); + + PHALCON_INIT_VAR(src); + phalcon_call_method_p1_key(src, url, "getstatic", url_src, 2197271245UL); + phalcon_array_update_quick_string(¶ms, SS("src"), 2090733773UL, &src, PH_COPY | PH_SEPARATE); + } + + PHALCON_INIT_VAR(code); + ZVAL_STRING(code, "") TSRMLS_CC); } else { - RETURN_EMPTY_STRING(); + phalcon_concat_self_str(&code, SL(">") TSRMLS_CC); } + + RETURN_CTOR(code); } -static int phannot_internal_parse_annotations(zval **result, zval *comment, zval *file_path, zval *line, zval **error_msg TSRMLS_DC) { +static PHP_METHOD(Phalcon_Tag, friendlyTitle){ - 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; + zval *text, *separator = NULL, *lowercase = NULL, *pattern, *friendly; + zval *friendly_text = NULL; - if (!Z_STRVAL_P(comment)) { - ZVAL_BOOL(*result, 0); - return FAILURE; - } + PHALCON_MM_GROW(); - if (Z_STRLEN_P(comment) < 2) { - ZVAL_BOOL(*result, 0); - return SUCCESS; + phalcon_fetch_params(1, 1, 2, &text, &separator, &lowercase); + + if (!separator) { + PHALCON_INIT_VAR(separator); + ZVAL_STRING(separator, "-", 1); } - - 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; + + if (!lowercase) { + PHALCON_INIT_VAR(lowercase); + ZVAL_BOOL(lowercase, 1); } - - 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; - - token.value = NULL; - token.len = 0; - - if (Z_TYPE_P(line) == IS_LONG) { - state->active_line = Z_LVAL_P(line) - start_lines; + + PHALCON_INIT_VAR(pattern); + ZVAL_STRING(pattern, "~[^a-z0-9A-Z]+~", 1); + + PHALCON_INIT_VAR(friendly); + phalcon_call_func_p3(friendly, "preg_replace", pattern, separator, text); + if (zend_is_true(lowercase)) { + PHALCON_INIT_VAR(friendly_text); + phalcon_fast_strtolower(friendly_text, friendly); } else { - state->active_line = 1; + PHALCON_CPY_WRT(friendly_text, friendly); } + + RETURN_CCTOR(friendly_text); +} - state->end = state->start; +static PHP_METHOD(Phalcon_Tag, setDocType){ - while(0 <= (scanner_status = phannot_get_token(state, &token))) { + zval *doctype; - state->active_token = token.opcode; + phalcon_fetch_params(0, 1, 0, &doctype); + + phalcon_update_static_property(SL("phalcon\\tag"), SL("_documentType"), doctype TSRMLS_CC); + +} - state->start_length = (Z_STRVAL(processed_comment) + Z_STRLEN(processed_comment) - state->start); +static PHP_METHOD(Phalcon_Tag, getDocType){ - switch (token.opcode) { + zval *doctype = NULL, *declaration, *eol, *doctype_html; - case PHANNOT_T_IGNORE: - break; + PHALCON_MM_GROW(); - 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_OBSERVE_VAR(doctype); + phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); - 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(eol); + ZVAL_STRING(eol, PHP_EOL, 1); - 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(declaration); + if (phalcon_compare_strict_long(doctype, 1 TSRMLS_CC)) { + ZVAL_STRING(declaration, " PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\"", 1); + goto ph_end_0; + } + if (phalcon_compare_strict_long(doctype, 2 TSRMLS_CC)) { + PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01//EN\"", eol, "\t\"http://www.w3.org/TR/html4/strict.dtd\""); + goto ph_end_0; + } + if (phalcon_compare_strict_long(doctype, 3 TSRMLS_CC)) { + PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"", eol, "\t\"http://www.w3.org/TR/html4/loose.dtd\""); + goto ph_end_0; + } + if (phalcon_compare_strict_long(doctype, 4 TSRMLS_CC)) { + PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"", eol, "\t\"http://www.w3.org/TR/html4/frameset.dtd\""); + goto ph_end_0; + } + if (phalcon_compare_strict_long(doctype, 6 TSRMLS_CC)) { + PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\""); + goto ph_end_0; + } + if (phalcon_compare_strict_long(doctype, 7 TSRMLS_CC)) { + PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\""); + goto ph_end_0; + } + if (phalcon_compare_strict_long(doctype, 8 TSRMLS_CC)) { + PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\""); + goto ph_end_0; + } + if (phalcon_compare_strict_long(doctype, 9 TSRMLS_CC)) { + PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"", eol, "\t\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\""); + goto ph_end_0; + } + if (phalcon_compare_strict_long(doctype, 10 TSRMLS_CC)) { + PHALCON_CONCAT_SVS(declaration, " PUBLIC \"-//W3C//DTD XHTML 2.0//EN\"", eol, "\t\"http://www.w3.org/MarkUp/DTD/xhtml2.dtd\""); + goto ph_end_0; + } - 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; + ph_end_0: - 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; + PHALCON_INIT_VAR(doctype_html); + PHALCON_CONCAT_SVSV(doctype_html, "", eol); - 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;*/ + RETURN_CTOR(doctype_html); +} - 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; - } +static PHP_METHOD(Phalcon_Tag, tagHtml){ - if (parser_status->status != PHANNOT_PARSING_OK) { - status = FAILURE; - break; - } + zval *tag_name, *parameters = NULL, *self_close = NULL, *only_start = NULL; + zval *use_eol = NULL, *params = NULL, *local_code, *value = NULL, *key = NULL; + zval *doctype, *eol; + HashTable *ah0; + HashPosition hp0; + zval **hd; - state->end = state->start; - } + PHALCON_MM_GROW(); - 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(1, 1, 4, &tag_name, ¶meters, &self_close, &only_start, &use_eol); + + if (!parameters) { + PHALCON_INIT_VAR(parameters); } - - 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); + + if (!self_close) { + PHALCON_INIT_VAR(self_close); + ZVAL_BOOL(self_close, 0); + } + + if (!only_start) { + PHALCON_INIT_VAR(only_start); + ZVAL_BOOL(only_start, 0); + } + + if (!use_eol) { + PHALCON_INIT_VAR(use_eol); + ZVAL_BOOL(use_eol, 0); + } + + if (Z_TYPE_P(parameters) != IS_ARRAY) { + PHALCON_INIT_VAR(params); + array_init_size(params, 1); + phalcon_array_append(¶ms, parameters, PH_SEPARATE); + } else { + PHALCON_CPY_WRT(params, parameters); + } + + PHALCON_INIT_VAR(local_code); + PHALCON_CONCAT_SV(local_code, "<", tag_name); + + 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 (Z_TYPE_P(key) != IS_LONG) { + PHALCON_SCONCAT_SVSVS(local_code, " ", key, "=\"", value, "\""); } + + zend_hash_move_forward_ex(ah0, &hp0); } - - 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); - } + + PHALCON_OBS_VAR(doctype); + phalcon_read_static_property(&doctype, SL("phalcon\\tag"), SL("_documentType") TSRMLS_CC); + + if (PHALCON_GT_LONG(doctype, 5)) { + if (zend_is_true(self_close)) { + phalcon_concat_self_str(&local_code, SL(" />") TSRMLS_CC); + } else { + phalcon_concat_self_str(&local_code, SL(">") TSRMLS_CC); + } + } else { + if (zend_is_true(only_start)) { + phalcon_concat_self_str(&local_code, SL(">") TSRMLS_CC); + } else { + PHALCON_SCONCAT_SVS(local_code, ">"); } } - - efree(Z_STRVAL(processed_comment)); - - efree(parser_status); - efree(state); - - return status; + + if (zend_is_true(use_eol)) { + PHALCON_INIT_VAR(eol); + ZVAL_STRING(eol, PHP_EOL, 1); + phalcon_concat_self(&local_code, eol TSRMLS_CC); + } + + RETURN_CTOR(local_code); } +static PHP_METHOD(Phalcon_Tag, tagHtmlClose){ + zval *tag_name, *use_eol = NULL, *local_code, *eol; + PHALCON_MM_GROW(); -#ifdef HAVE_CONFIG_H -#endif - + phalcon_fetch_params(1, 1, 1, &tag_name, &use_eol); + + if (!use_eol) { + PHALCON_INIT_VAR(use_eol); + ZVAL_BOOL(use_eol, 0); + } + + PHALCON_INIT_VAR(local_code); + PHALCON_CONCAT_SVS(local_code, ""); + if (zend_is_true(use_eol)) { + PHALCON_INIT_VAR(eol); + ZVAL_STRING(eol, PHP_EOL, 1); + phalcon_concat_self(&local_code, eol TSRMLS_CC); + } + + RETURN_CTOR(local_code); +} -PHALCON_INIT_CLASS(Phalcon_Annotations_Exception){ +#ifdef HAVE_CONFIG_H +#endif - PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations, Exception, annotations_exception, "phalcon\\exception", NULL, 0); - return SUCCESS; -} -#ifdef HAVE_CONFIG_H -#endif +PHALCON_INIT_CLASS(Phalcon_Security){ + PHALCON_REGISTER_CLASS(Phalcon, Security, security, phalcon_security_method_entry, 0); + 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_Security, setDI){ + zval *dependency_injector; -PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter){ + phalcon_fetch_params(0, 1, 0, &dependency_injector); + + phalcon_update_property_this_quick(this_ptr, SL("_dependencyInjector"), dependency_injector, 765199457UL TSRMLS_CC); + +} - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Adapter, annotations_adapter, phalcon_annotations_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); +static PHP_METHOD(Phalcon_Security, getDI){ - 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); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -static PHP_METHOD(Phalcon_Annotations_Adapter, setReader){ +static PHP_METHOD(Phalcon_Security, setRandomBytes){ - zval *reader; + zval *random_bytes; - phalcon_fetch_params(0, 1, 0, &reader); + phalcon_fetch_params(0, 1, 0, &random_bytes); - if (Z_TYPE_P(reader) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_annotations_exception_ce, "Invalid annotations reader"); + if (Z_TYPE_P(random_bytes) != IS_LONG) { + PHALCON_THROW_EXCEPTION_STRW(phalcon_security_exception_ce, "Random bytes must be integer"); return; } - phalcon_update_property_this_quick(this_ptr, SL("_reader"), reader, 1648179735UL TSRMLS_CC); + 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_update_property_this_quick(this_ptr, SL("_numberBytes"), random_bytes, 1300189556UL TSRMLS_CC); } -static PHP_METHOD(Phalcon_Annotations_Adapter, getReader){ - - zval *reader = NULL; +static PHP_METHOD(Phalcon_Security, getRandomBytes){ - PHALCON_MM_GROW(); - 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); + RETURN_MEMBER_QUICK(this_ptr, "_numberBytes", 1300189556UL); } -static PHP_METHOD(Phalcon_Annotations_Adapter, get){ - - zval *class_name, *real_class_name = NULL, *annotations; - zval *class_annotations = NULL, *reader, *parsed_annotations; +static PHP_METHOD(Phalcon_Security, setWorkFactor){ - PHALCON_MM_GROW(); + zval *work_factor; - phalcon_fetch_params(1, 1, 0, &class_name); - - 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); - } - - 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); - } - } - - 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); - - 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_fetch_params(0, 1, 0, &work_factor); - 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); - } + 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); - RETURN_CCTOR(class_annotations); } -static PHP_METHOD(Phalcon_Annotations_Adapter, getMethods){ - - zval *class_name, *class_annotations; +static PHP_METHOD(Phalcon_Security, getWorkFactor){ - 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(); + RETURN_MEMBER_QUICK(this_ptr, "_workFactor", 3598705926UL); } -static PHP_METHOD(Phalcon_Annotations_Adapter, getMethod){ +static PHP_METHOD(Phalcon_Security, getSaltBytes){ - zval *class_name, *method_name, *class_annotations; - zval *methods, *method = NULL, *name = 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, 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); + 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; + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_OBS_VAR(number_bytes); + phalcon_read_property_this_quick(&number_bytes, this_ptr, SL("_numberBytes"), 1300189556UL, PH_NOISY_CC); - PHALCON_GET_HKEY(name, ah0, hp0); - PHALCON_GET_HVALUE(method); + while (1) { - if (PHALCON_IS_EQUAL(name, method_name)) { - RETURN_CCTOR(method); - } + PHALCON_INIT_NVAR(random_bytes); + phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_NVAR(base64bytes); + phalcon_base64_encode(base64bytes, random_bytes); + PHALCON_INIT_NVAR(safe_bytes); + phalcon_filter_alphanum(safe_bytes, base64bytes); + if (!zend_is_true(safe_bytes)) { + continue; } - } - - 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_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); + PHALCON_INIT_NVAR(bytes_length); + phalcon_fast_strlen(bytes_length, safe_bytes); + if (PHALCON_LT_LONG(bytes_length, 22)) { + continue; + } - if (Z_TYPE_P(class_annotations) == IS_OBJECT) { - phalcon_call_method_key(return_value, class_annotations, "getpropertiesannotations", 3353352384UL); - RETURN_MM(); + break; } - RETURN_MM_EMPTY_ARRAY(); + RETURN_CTOR(safe_bytes); } -static PHP_METHOD(Phalcon_Annotations_Adapter, getProperty){ +static PHP_METHOD(Phalcon_Security, hash){ - zval *class_name, *property_name, *class_annotations; - zval *properties, *property = NULL, *name = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *password, *work_factor = NULL, *format, *factor; + zval *salt_bytes, *salt; 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_fetch_params(1, 1, 1, &password, &work_factor); - PHALCON_GET_HKEY(name, ah0, hp0); - PHALCON_GET_HVALUE(property); + if (!work_factor) { + PHALCON_INIT_VAR(work_factor); + } else { + PHALCON_SEPARATE_PARAM(work_factor); + } - if (PHALCON_IS_EQUAL(name, property_name)) { - RETURN_CCTOR(property); - } + 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); + } - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_VAR(format); + ZVAL_STRING(format, "%02s", 1); - } - } + PHALCON_INIT_VAR(factor); + phalcon_call_func_p2(factor, "sprintf", format, work_factor); - object_init_ex(return_value, phalcon_annotations_collection_ce); - phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL); + 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_Security, checkHash){ + zval *password, *password_hash, *hash; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 2, 0, &password, &password_hash); + + 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(); +} -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Annotations_Reflection){ - - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Reflection, annotations_reflection, phalcon_annotations_reflection_method_entry, 0); +static PHP_METHOD(Phalcon_Security, isLegacyHash){ - 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 *password_hash; - return SUCCESS; + phalcon_fetch_params(0, 1, 0, &password_hash); + + if (phalcon_start_with_str(password_hash, SL("$2a$"))) { + RETURN_TRUE; + } + RETURN_FALSE; } -static PHP_METHOD(Phalcon_Annotations_Reflection, __construct){ +static PHP_METHOD(Phalcon_Security, getTokenKey){ - zval *reflection_data = NULL; + 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, &reflection_data); + phalcon_fetch_params(1, 0, 1, &number_bytes); - if (!reflection_data) { - PHALCON_INIT_VAR(reflection_data); + if (!number_bytes) { + PHALCON_INIT_VAR(number_bytes); + ZVAL_LONG(number_bytes, 12); } - if (Z_TYPE_P(reflection_data) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_reflectionData"), reflection_data, 3848141129UL TSRMLS_CC); + 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_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Annotations_Reflection, getClassAnnotations){ - - zval *annotations, *reflection_data, *reflection_class; - zval *collection; - - 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(random_bytes); + phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); - PHALCON_INIT_VAR(collection); - object_init_ex(collection, phalcon_annotations_collection_ce); - phalcon_call_method_p1_key(NULL, collection, "__construct", reflection_class, 1107214344UL); + PHALCON_INIT_VAR(base64bytes); + phalcon_base64_encode(base64bytes, random_bytes); - phalcon_update_property_this_quick(this_ptr, SL("_classAnnotations"), collection, 372163368UL TSRMLS_CC); - RETURN_CTOR(collection); - } + PHALCON_INIT_VAR(safe_bytes); + phalcon_filter_alphanum(safe_bytes, base64bytes); - phalcon_update_property_bool(this_ptr, SL("_classAnnotations"), 0 TSRMLS_CC); - 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_THROW_EXCEPTION_STR(phalcon_flash_exception_ce, "A dependency injection container is required to access the 'session' service"); + return; } - RETURN_CCTOR(annotations); + 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_Annotations_Reflection, getMethodsAnnotations){ +static PHP_METHOD(Phalcon_Security, getToken){ - zval *annotations, *reflection_data, *reflection_methods; - zval *collections, *reflection_method = NULL, *method_name = NULL; - zval *collection = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *number_bytes = NULL, *random_bytes, *token, *dependency_injector; + zval *service, *session, *key; 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); + phalcon_fetch_params(1, 0, 1, &number_bytes); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + if (!number_bytes) { + PHALCON_INIT_VAR(number_bytes); + ZVAL_LONG(number_bytes, 12); + } - PHALCON_GET_HKEY(method_name, ah0, hp0); - PHALCON_GET_HVALUE(reflection_method); + 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_NVAR(collection); - object_init_ex(collection, phalcon_annotations_collection_ce); - phalcon_call_method_p1_key(NULL, collection, "__construct", reflection_method, 1107214344UL); + PHALCON_INIT_VAR(random_bytes); + phalcon_call_func_p1(random_bytes, "openssl_random_pseudo_bytes", number_bytes); - phalcon_array_update_zval(&collections, method_name, &collection, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(token); + phalcon_md5(token, random_bytes); - zend_hash_move_forward_ex(ah0, &hp0); - } + 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_update_property_this_quick(this_ptr, SL("_methodAnnotations"), collections, 4229536243UL TSRMLS_CC); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "session", 1); - RETURN_CTOR(collections); - } - } + PHALCON_INIT_VAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); - phalcon_update_property_bool(this_ptr, SL("_methodAnnotations"), 0 TSRMLS_CC); - RETURN_MM_FALSE; - } + PHALCON_INIT_VAR(key); + ZVAL_STRING(key, "$PHALCON/CSRF$", 1); + phalcon_call_method_p2_key(NULL, session, "set", key, token, 2090720177UL); - RETURN_CCTOR(annotations); + RETURN_CTOR(token); } -static PHP_METHOD(Phalcon_Annotations_Reflection, getPropertiesAnnotations){ +static PHP_METHOD(Phalcon_Security, checkToken){ - zval *annotations, *reflection_data, *reflection_properties; - zval *collections, *reflection_property = NULL, *property = NULL; - zval *collection = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *token_key = NULL, *token_value = NULL, *dependency_injector; + zval *service = NULL, *session, *key = NULL, *request, *token = NULL, *session_token; 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_fetch_params(1, 0, 2, &token_key, &token_value); - 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)) { + if (!token_key) { + PHALCON_INIT_VAR(token_key); + } else { + PHALCON_SEPARATE_PARAM(token_key); + } - 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)) { + if (!token_value) { + PHALCON_INIT_VAR(token_value); + } - PHALCON_INIT_VAR(collections); - array_init(collections); + 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_is_iterable(reflection_properties, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "session", 1); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + 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_GET_HKEY(property, ah0, hp0); - PHALCON_GET_HVALUE(reflection_property); + PHALCON_INIT_NVAR(token_key); + phalcon_call_method_p1_key(token_key, session, "get", key, 2090288933UL); + } - PHALCON_INIT_NVAR(collection); - object_init_ex(collection, phalcon_annotations_collection_ce); - phalcon_call_method_p1_key(NULL, collection, "__construct", reflection_property, 1107214344UL); + if (Z_TYPE_P(token_value) == IS_NULL) { + PHALCON_INIT_NVAR(service); + ZVAL_STRING(service, "request", 1); - phalcon_array_update_zval(&collections, property, &collection, PH_COPY | PH_SEPARATE); + PHALCON_INIT_VAR(request); + phalcon_call_method_p1_key(request, dependency_injector, "getshared", service, 1727570332UL); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_VAR(token); + phalcon_call_method_p1_key(token, request, "getpost", token_key, 4289323083UL); + } else { + PHALCON_CPY_WRT(token, token_value); + } - phalcon_update_property_this_quick(this_ptr, SL("_propertyAnnotations"), collections, 762458551UL TSRMLS_CC); + PHALCON_INIT_NVAR(key); + ZVAL_STRING(key, "$PHALCON/CSRF$", 1); - RETURN_CTOR(collections); - } - } + PHALCON_INIT_VAR(session_token); + phalcon_call_method_p1_key(session_token, session, "get", key, 2090288933UL); - phalcon_update_property_bool(this_ptr, SL("_propertyAnnotations"), 0 TSRMLS_CC); - RETURN_MM_FALSE; - } + is_equal_function(return_value, token, session_token TSRMLS_CC); - RETURN_CCTOR(annotations); -} - -static PHP_METHOD(Phalcon_Annotations_Reflection, getReflectionData){ - - - RETURN_MEMBER_QUICK(this_ptr, "_reflectionData", 3848141129UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Annotations_Reflection, __set_state){ +static PHP_METHOD(Phalcon_Security, getSessionToken){ - zval *data, *reflection_data; + zval *dependency_injector, *service, *session; + zval *key, *session_token; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &data); - - if (Z_TYPE_P(data) == IS_ARRAY) { + 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; + } - 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); + PHALCON_INIT_VAR(service); + ZVAL_STRING(service, "session", 1); - RETURN_MM(); - } - } - object_init_ex(return_value, phalcon_annotations_reflection_ce); - phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL); + PHALCON_INIT_VAR(session); + phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); - RETURN_MM(); + 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); } @@ -141260,9 +68780,9 @@ static PHP_METHOD(Phalcon_Annotations_Reflection, __set_state){ -PHALCON_INIT_CLASS(Phalcon_Annotations_AdapterInterface){ +PHALCON_INIT_CLASS(Phalcon_Db_ReferenceInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Annotations, AdapterInterface, annotations_adapterinterface, phalcon_annotations_adapterinterface_method_entry); + PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ReferenceInterface, db_referenceinterface, phalcon_db_referenceinterface_method_entry); return SUCCESS; } @@ -141278,6 +68798,7 @@ PHALCON_INIT_CLASS(Phalcon_Annotations_AdapterInterface){ + #ifdef HAVE_CONFIG_H #endif @@ -141287,591 +68808,788 @@ PHALCON_INIT_CLASS(Phalcon_Annotations_AdapterInterface){ -PHALCON_INIT_CLASS(Phalcon_Annotations_Reader){ +PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo){ - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Reader, annotations_reader, phalcon_annotations_reader_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_class_implements(phalcon_annotations_reader_ce TSRMLS_CC, 1, phalcon_annotations_readerinterface_ce); + 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_Annotations_Reader, parse){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, __construct){ - 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; + zval *descriptor; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &class_name); + phalcon_fetch_params(1, 1, 0, &descriptor); - if (unlikely(Z_TYPE_P(class_name) != IS_STRING)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "The class name must be an object"); + 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_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(); +} + +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, connect){ + + 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(); + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &descriptor) == FAILURE) { + RETURN_MM_NULL(); } - - 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) { + + if (!descriptor) { + PHALCON_INIT_VAR(descriptor); + } else { + PHALCON_SEPARATE_PARAM(descriptor); + } + + 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); + } + + 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); + } + + 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; } - - 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); - } - } - + + PHALCON_GET_FOREACH_KEY(key, ah0, hp0); + PHALCON_GET_FOREACH_VALUE(value); + + 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); } - - 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(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_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); + + 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); } } - - RETURN_CTOR(annotations); + + 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_Annotations_Reader, parseDocBlock){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, prepare){ - zval *doc_block, *file = NULL, *line = NULL; + zval *sql_statement, *pdo; PHALCON_MM_GROW(); - 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); - } + phalcon_fetch_params(1, 1, 0, &sql_statement); - 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; - } + 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(); } +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(); + } -#ifdef HAVE_CONFIG_H -#endif - - + 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; + } + } -PHALCON_INIT_CLASS(Phalcon_Text){ + if (Z_TYPE_P(data_types) == IS_ARRAY) { - PHALCON_REGISTER_CLASS(Phalcon, Text, text, phalcon_text_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + if (likely(phalcon_array_isset(data_types, wildcard))) { - zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_ALNUM"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_ALPHA"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_HEXDEC"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_NUMERIC"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_NOZERO"), 4 TSRMLS_CC); + PHALCON_OBS_NVAR(type); + phalcon_array_fetch(&type, data_types, wildcard, PH_NOISY); + if (phalcon_compare_strict_long(type, 32 TSRMLS_CC)) { - return SUCCESS; -} + PHALCON_INIT_NVAR(cast_value); + phalcon_cast(cast_value, value, IS_DOUBLE); -static PHP_METHOD(Phalcon_Text, camelize){ + PHALCON_INIT_NVAR(type); + ZVAL_LONG(type, 1024); + } else { + PHALCON_CPY_WRT(cast_value, value); + } - zval *str; + 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); - phalcon_fetch_params(0, 1, 0, &str); - - phalcon_camelize(return_value, str); - return; -} + } 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); + } -static PHP_METHOD(Phalcon_Text, uncamelize){ + zend_hash_move_forward_ex(ah0, &hp0); + } - zval *str; + phalcon_call_method_key(NULL, statement, "execute", 3117639032UL); - phalcon_fetch_params(0, 1, 0, &str); - - phalcon_uncamelize(return_value, str); - return; + RETURN_CCTOR(statement); } -static PHP_METHOD(Phalcon_Text, increment){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, query){ - zval *str, *separator = NULL, *parts, *number = NULL, *first_part; + 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_fetch_params(1, 1, 1, &str, &separator); + phalcon_fetch_params(1, 1, 2, &sql_statement, &bind_params, &bind_types); - if (!separator) { - PHALCON_INIT_VAR(separator); - } else { - PHALCON_SEPARATE_PARAM(separator); + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); } - if (Z_TYPE_P(separator) == IS_NULL) { - PHALCON_INIT_NVAR(separator); - ZVAL_STRING(separator, "_", 1); + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); } - PHALCON_INIT_VAR(parts); - phalcon_fast_explode(parts, separator, str); - if (phalcon_array_isset_long(parts, 1)) { - PHALCON_OBS_VAR(number); - phalcon_array_fetch_long(&number, parts, 1, PH_NOISY); - PHALCON_SEPARATE(number); - phalcon_increment(number); + 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(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); + } } else { - PHALCON_INIT_NVAR(number); - ZVAL_LONG(number, 1); + PHALCON_INIT_NVAR(statement); + phalcon_call_method_p1_key(statement, pdo, "query", sql_statement, 401898907UL); } - PHALCON_OBS_VAR(first_part); - phalcon_array_fetch_long(&first_part, parts, 0, PH_NOISY); - PHALCON_CONCAT_VVV(return_value, first_part, separator, number); + 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); - RETURN_MM(); + RETURN_MM(); + } + + RETURN_CCTOR(statement); } -static PHP_METHOD(Phalcon_Text, random){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, execute){ - zval *type, *length = NULL; + 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, 1, &type, &length); + phalcon_fetch_params(1, 1, 2, &sql_statement, &bind_params, &bind_types); - if (!length) { - PHALCON_INIT_VAR(length); - ZVAL_LONG(length, 8); + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); } - phalcon_random_string(return_value, type, length TSRMLS_CC); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Text, startsWith){ - - zval *str, *start, *ignore_case = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 1, &str, &start, &ignore_case); + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } - if (!ignore_case) { - PHALCON_INIT_VAR(ignore_case); - ZVAL_BOOL(ignore_case, 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: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_INIT_VAR(affected_rows); + ZVAL_LONG(affected_rows, 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) { + + 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_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); + } + + 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); + } } - if (phalcon_start_with(str, start, ignore_case)) { - RETURN_MM_TRUE; - } - RETURN_MM_FALSE; + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Text, endsWith){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, affectedRows){ - zval *str, *end, *ignore_case = NULL; + + RETURN_MEMBER_QUICK(this_ptr, "_affectedRows", 3226297793UL); +} + +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, close){ + + zval *pdo; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &str, &end, &ignore_case); - - if (!ignore_case) { - PHALCON_INIT_VAR(ignore_case); - ZVAL_BOOL(ignore_case, 1); - } - - if (phalcon_end_with(str, end, ignore_case)) { + 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_FALSE; + + RETURN_MM_TRUE; } -static PHP_METHOD(Phalcon_Text, lower){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, escapeIdentifier){ - zval *str; + zval *identifier, *domain, *name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &str); + phalcon_fetch_params(1, 1, 0, &identifier); - if (phalcon_function_quick_exists_ex(SS("mb_strtolower"), 3802586680UL TSRMLS_CC) == SUCCESS) { - phalcon_call_func_p1(return_value, "mb_strtolower", str); + 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_fast_strtolower(return_value, str); + PHALCON_CONCAT_SVS(return_value, "\"", identifier, "\""); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Text, upper){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, escapeString){ - zval *str; + zval *str, *pdo; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &str); - if (phalcon_function_quick_exists_ex(SS("mb_strtoupper"), 4155739579UL TSRMLS_CC) == SUCCESS) { - phalcon_call_func_p1(return_value, "mb_strtoupper", str); - RETURN_MM(); - } - phalcon_fast_strtoupper(return_value, 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){ - - - -#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; + 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, 1, 1, &name, &options); + phalcon_fetch_params(1, 2, 0, &sql, ¶ms); - if (!options) { - PHALCON_INIT_VAR(options); - } + PHALCON_INIT_VAR(query_params); + array_init(query_params); - if (phalcon_array_isset_quick_string(options, SS("mode"), 267518858UL)) { + PHALCON_INIT_VAR(placeholders); + array_init(placeholders); - 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; + 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); } - } else { - PHALCON_INIT_NVAR(mode); - ZVAL_STRING(mode, "ab", 1); - } - 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_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("_stream"), stream, 3546870672UL 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); - PHALCON_MM_RESTORE(); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Logger_Adapter_Stream, getFormatter){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, lastInsertId){ - zval *formatter = NULL; + zval *sequence_name = NULL, *pdo; 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_fetch_params(1, 0, 1, &sequence_name); - phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); + if (!sequence_name) { + PHALCON_INIT_VAR(sequence_name); } - RETURN_CCTOR(formatter); + 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_Logger_Adapter_Stream, logInternal){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, begin){ - zval *message, *type, *time, *stream, *formatter, *applied_format; + zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; + zval *event_name = NULL, *ntw_savepoint, *savepoint_name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &message, &type, &time); + phalcon_fetch_params(1, 0, 1, &nesting); - 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; + if (!nesting) { + PHALCON_INIT_VAR(nesting); + ZVAL_BOOL(nesting, 1); } - PHALCON_INIT_VAR(formatter); - phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); + 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_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_property_incr(this_ptr, SL("_transactionLevel") TSRMLS_CC); - PHALCON_MM_RESTORE(); + 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_Logger_Adapter_Stream, close){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, rollback){ - zval *stream; + zval *nesting = NULL, *pdo, *transaction_level, *events_manager = NULL; + zval *event_name = NULL, *ntw_savepoint, *savepoint_name; 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(); -} - - - - - -#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; + 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_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; } -static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, __construct){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, commit){ - zval *name, *options = NULL, *option = NULL, *facility = NULL; + 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, 1, &name, &options); + phalcon_fetch_params(1, 0, 1, &nesting); - if (!options) { - PHALCON_INIT_VAR(options); + if (!nesting) { + PHALCON_INIT_VAR(nesting); + ZVAL_BOOL(nesting, 1); } - 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); + 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); } - 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_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(); + } + } } + } - phalcon_call_func_p3_noret("openlog", name, option, facility); - phalcon_update_property_bool(this_ptr, SL("_opened"), 1 TSRMLS_CC); + if (PHALCON_GT_LONG(transaction_level, 0)) { + phalcon_property_decr(this_ptr, SL("_transactionLevel") TSRMLS_CC); } - PHALCON_MM_RESTORE(); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, getFormatter){ - - zval *formatter = NULL; +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, getTransactionLevel){ - 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); + RETURN_MEMBER_QUICK(this_ptr, "_transactionLevel", 2789346594UL); } -static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, logInternal){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, isUnderTransaction){ - zval *message, *type, *time, *formatter, *applied_format; - zval *syslog_type, *syslog_message; + zval *pdo; 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(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(); } - 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(); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, close){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo, getInternalHandler){ - zval *opened; + zval *pdo; 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(); + PHALCON_OBS_VAR(pdo); + phalcon_read_property_this_quick(&pdo, this_ptr, SL("_pdo"), 250952231UL, PH_NOISY_CC); + RETURN_CCTOR(pdo); } @@ -141887,141 +69605,220 @@ static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, close){ -PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_File){ +PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Mysql){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, File, logger_adapter_file, "phalcon\\logger\\adapter", phalcon_logger_adapter_file_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_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_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_logger_adapter_file_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + zend_class_implements(phalcon_db_adapter_pdo_mysql_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Logger_Adapter_File, __construct){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, escapeIdentifier){ - zval *name, *options = NULL, *mode = NULL, *handler, *exception_message; + zval *identifier, *domain, *name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, &options); + phalcon_fetch_params(1, 1, 0, &identifier); - if (!options) { - PHALCON_INIT_VAR(options); - } + if (Z_TYPE_P(identifier) == IS_ARRAY) { - if (phalcon_array_isset_quick_string(options, SS("mode"), 267518858UL)) { + PHALCON_OBS_VAR(domain); + phalcon_array_fetch_long(&domain, identifier, 0, PH_NOISY); - 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_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(); } - } 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_CONCAT_VSV(return_value, domain, ".", name); - 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); + RETURN_MM(); + } + if (PHALCON_GLOBAL(db).escape_identifiers) { + PHALCON_CONCAT_SVS(return_value, "`", identifier, "`"); + RETURN_MM(); + } - PHALCON_MM_RESTORE(); + RETURN_CCTOR(identifier); } -static PHP_METHOD(Phalcon_Logger_Adapter_File, getFormatter){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Mysql, describeColumns){ - zval *formatter = NULL; + 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_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_fetch_params(1, 1, 1, &table, &schema); - phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); + if (!schema) { + PHALCON_INIT_VAR(schema); } - RETURN_CCTOR(formatter); -} - -static PHP_METHOD(Phalcon_Logger_Adapter_File, logInternal){ - - zval *message, *type, *time, *file_handler, *formatter; - zval *applied_format; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 3, 0, &message, &type, &time); + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - 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; - } + PHALCON_INIT_VAR(ztrue); + ZVAL_BOOL(ztrue, 1); - PHALCON_INIT_VAR(formatter); - phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "describecolumns", table, schema, 4645575UL); - 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_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); - PHALCON_MM_RESTORE(); -} - -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 PHP_METHOD(Phalcon_Logger_Adapter_File, __wakeup){ - - zval *path, *options, *mode = NULL, *file_handler; - - PHALCON_MM_GROW(); + 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(size_pattern); + ZVAL_STRING(size_pattern, "#\\(([0-9]+)(,[0-9]+)*\\)#", 1); + + PHALCON_INIT_VAR(columns); + array_init(columns); + + 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, 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; + } + + 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_OBS_VAR(path); - phalcon_read_property_this_quick(&path, this_ptr, SL("_path"), 3986357393UL, PH_NOISY_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); + } + } + } - 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); - } + 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(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); + 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_MM_RESTORE(); + 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); } @@ -142037,1584 +69834,1562 @@ static PHP_METHOD(Phalcon_Logger_Adapter_File, __wakeup){ +PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Oracle){ -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); + 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_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); + 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_logger_adapter_firephp_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + zend_class_implements(phalcon_db_adapter_pdo_oracle_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, getFormatter){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, connect){ - zval *formatter = NULL; + zval *descriptor = NULL, *startup, *value = NULL; + HashTable *ah0; + HashPosition hp0; + zval **hd; 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); + phalcon_fetch_params(1, 0, 1, &descriptor); + + if (!descriptor) { + PHALCON_INIT_VAR(descriptor); + } else { + PHALCON_SEPARATE_PARAM(descriptor); } - - RETURN_CCTOR(formatter); + + 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_Logger_Adapter_Firephp, logInternal){ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, describeColumns){ - 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; + 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; - /* 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, 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); +} - PHALCON_MM_GROW(); +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, lastInsertId){ - phalcon_fetch_params(1, 3, 0, &message, &type, &time); + zval *sequence_name = NULL, *sql, *fetch_num, *ret, *insert_id; - PHALCON_INIT_VAR(formatter); - phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); + 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); +} - 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 PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, useExplicitIdValue){ - 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); - 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); + RETURN_FALSE; +} - ZVAL_TRUE(initialized); /* This will also update the property because "initialized" was not separated */ - } +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, getDefaultIdValue){ - 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; - } + zval *null_value; - PHALCON_OBS_VAR(index); - phalcon_read_static_property(&index, SL("phalcon\\logger\\adapter\\firephp"), SL("_index") TSRMLS_CC); + PHALCON_MM_GROW(); - size = Z_STRLEN_P(applied_format); - offset = 0; + 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(); +} - smart_str_alloc4(&str, (size > chunk ? chunk : size), 0, num_bytes); +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Oracle, supportSequences){ - 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, '|'); - } + RETURN_TRUE; +} - /* 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); - } - 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); +#ifdef HAVE_CONFIG_H +#endif - /* 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(); -} -static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, close){ - RETURN_TRUE; -======= -}; -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 */ +PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Postgresql){ -/* 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_REGISTER_CLASS_EX(Phalcon\\Db\\Adapter\\Pdo, Postgresql, db_adapter_pdo_postgresql, "phalcon\\db\\adapter\\pdo", phalcon_db_adapter_pdo_postgresql_method_entry, 0); -/* 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; + 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); -#ifndef NDEBUG -#include -static FILE *jjTraceFILE = 0; -static char *jjTracePrompt = 0; -#endif /* NDEBUG */ + zend_class_implements(phalcon_db_adapter_pdo_postgresql_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); -#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; + return SUCCESS; } -#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 *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 */ -#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 */ +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, connect){ -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 -} + zval *descriptor = NULL, *schema = NULL, *sql; -void *phannot_Alloc(void *(*mallocProc)(size_t)){ - jjParser *pParser; - pParser = (jjParser*)(*mallocProc)( (size_t)sizeof(jjParser) ); - if( pParser ){ - pParser->jjidx = -1; - } - return pParser; -} + PHALCON_MM_GROW(); -/* 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); - } - efree((jjpminor->jj0)); + phalcon_fetch_params(1, 0, 1, &descriptor); + + if (!descriptor) { + PHALCON_INIT_VAR(descriptor); + } else { + PHALCON_SEPARATE_PARAM(descriptor); } -} -// 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 */ - } + + 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 int jj_pop_parser_stack(jjParser *pParser){ - JJCODETYPE jjmajor; - jjStackEntry *jjtos = &pParser->jjstack[pParser->jjidx]; +static PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, describeColumns){ - 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; -} + 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; -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_MM_GROW(); -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]; - } + 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(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); + + 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 (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_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_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_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 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_Adapter_Pdo_Postgresql, useExplicitIdValue){ -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 + + RETURN_TRUE; } -/* 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 PHP_METHOD(Phalcon_Db_Adapter_Pdo_Postgresql, getDefaultIdValue){ -static void jj_accept(jjParser*); /* Forward Declaration */ + zval *null_value, *default_value; -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); + 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); } -// 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_Adapter_Pdo_Postgresql, supportSequences){ + + + RETURN_TRUE; } -// 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); + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Db_Adapter_Pdo_Sqlite){ + + 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); + + 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_class_implements(phalcon_db_adapter_pdo_sqlite_ce TSRMLS_CC, 1, phalcon_db_adapterinterface_ce); + + return SUCCESS; } -// 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_Adapter_Pdo_Sqlite, connect){ + + zval *descriptor = NULL, *dbname; + + 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); + } + 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_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Db\\Adapter\\Pdo\\Sqlite", "connect", descriptor); + + PHALCON_MM_RESTORE(); } -// 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_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; + + PHALCON_MM_GROW(); + + 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(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); + + 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_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 { + 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); } -// 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_Adapter_Pdo_Sqlite, describeIndexes){ + + 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, 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, 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_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); + } + + 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); } -// 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_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); } -// 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_Adapter_Pdo_Sqlite, useExplicitIdValue){ + + + RETURN_TRUE; } -static void jj_parse_failed( - jjParser *jjpParser /* The parser */ -){ - phannot_ARG_FETCH; -#ifndef NDEBUG - if( jjTraceFILE ){ - fprintf(jjTraceFILE,"%sFail!\n",jjTracePrompt); - } + + + + +#ifdef HAVE_CONFIG_H #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_Db_Result_Pdo){ - 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)); - } + PHALCON_REGISTER_CLASS(Phalcon\\Db\\Result, Pdo, db_result_pdo, phalcon_db_result_pdo_method_entry, 0); - status->status = PHANNOT_PARSING_FAILED; + 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); -// 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_Db_Result_Pdo, __construct){ + + zval *connection, *result, *sql_statement = NULL, *bind_params = NULL; + zval *bind_types = NULL; + + 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); + } + + if (Z_TYPE_P(result) != IS_OBJECT) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid PDOStatement supplied to Phalcon\\Db\\Result\\Pdo"); + 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(); } -/* 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_Result_Pdo, execute){ - /* (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 *pdo_statement; -#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_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){ -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 *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, "fetch", 4247924303UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Db_Result_Pdo, fetchArray){ + + zval *pdo_statement; -static void *phannot_wrapper_alloc(size_t bytes){ - return emalloc(bytes); -} + PHALCON_MM_GROW(); -static void phannot_wrapper_free(void *pointer){ - efree(pointer); + 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 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_Result_Pdo, fetchAll){ - pToken = emalloc(sizeof(phannot_parser_token)); - pToken->opcode = opcode; - pToken->token = token->value; - pToken->token_len = token->len; - pToken->free_flag = 1; + zval *pdo_statement; - phannot_(phannot_parser, parsercode, pToken, parser_status); + PHALCON_MM_GROW(); - token->value = NULL; - token->len = 0; + 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 void phannot_scanner_error_msg(phannot_parser_status *parser_status, zval **error_msg TSRMLS_DC){ +static PHP_METHOD(Phalcon_Db_Result_Pdo, numRows){ - int error_length; - char *error, *error_part; - phannot_scanner_state *state = parser_status->scanner_state; + 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; - 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); + 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); } - 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'; + + 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); } - efree(error); + + RETURN_CCTOR(row_count); } -static int phannot_parse_annotations(zval *result, zval *comment, zval *file_path, zval *line TSRMLS_DC){ - - zval *error_msg = NULL; +static PHP_METHOD(Phalcon_Db_Result_Pdo, dataSeek){ - ZVAL_NULL(result); + long number = 0, n; + zval *connection, *pdo, *sql_statement; + zval *bind_params, *bind_types, *statement = NULL; + zval *temp_statement = NULL; + pdo_stmt_t *stmt; - 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_MM_GROW(); - 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_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &number) == FAILURE) { + RETURN_MM_NULL(); } - return SUCCESS; -} + PHALCON_OBS_VAR(connection); + phalcon_read_property(&connection, this_ptr, SL("_connection"), PH_NOISY_CC); -static void phannot_remove_comment_separators(zval *return_value, char *comment, int length, int *start_lines) { + PHALCON_INIT_VAR(pdo); + phalcon_call_method_key(pdo, connection, "getinternalhandler", 489229824UL); - int start_mode = 1, j, i, open_parentheses; - smart_str processed_str = {0}; - char ch; + PHALCON_OBS_VAR(sql_statement); + phalcon_read_property(&sql_statement, this_ptr, SL("_sqlStatement"), PH_NOISY_CC); - (*start_lines) = 0; + PHALCON_OBS_VAR(bind_params); + phalcon_read_property(&bind_params, this_ptr, SL("_bindParams"), PH_NOISY_CC); - for (i = 0; i < length; i++) { + if (Z_TYPE_P(bind_params) == IS_ARRAY) { - ch = comment[i]; + PHALCON_OBS_VAR(bind_types); + phalcon_read_property(&bind_types, this_ptr, SL("_bindTypes"), PH_NOISY_CC); - if (start_mode) { - if (ch == ' ' || ch == '*' || ch == '/' || ch == '\t' || ch == 11) { - continue; - } - start_mode = 0; + 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); } - if (ch == '@') { - - smart_str_appendc(&processed_str, ch); - i++; + } else { + PHALCON_INIT_NVAR(statement); + phalcon_call_method_p1_key(statement, pdo, "query", sql_statement, 401898907UL); + } - open_parentheses = 0; - for (j = i; j < length; j++) { + phalcon_update_property_zval(this_ptr, SL("_pdoStatement"), statement TSRMLS_CC); - ch = comment[j]; - if (start_mode) { - if (ch == ' ' || ch == '*' || ch == '/' || ch == '\t' || ch == 11) { - continue; - } - start_mode = 0; - } + stmt = (pdo_stmt_t*) zend_object_store_get_object(statement TSRMLS_CC); + if (!stmt->dbh) { + PHALCON_MM_RESTORE(); + RETURN_FALSE; + } - if (open_parentheses == 0) { + n = -1; + number--; + while (n != number) { - if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { - smart_str_appendc(&processed_str, ch); - continue; - } + if(!stmt->methods->fetcher(stmt, PDO_FETCH_ORI_NEXT, 0 TSRMLS_CC)) { + PHALCON_MM_RESTORE(); + RETURN_NULL(); + } - if (ch == '(') { - smart_str_appendc(&processed_str, ch); - open_parentheses++; - continue; - } + n++; + } - } else { + PHALCON_MM_RESTORE(); +} - smart_str_appendc(&processed_str, ch); +static PHP_METHOD(Phalcon_Db_Result_Pdo, setFetchMode){ - if (ch == '(') { - open_parentheses++; - } else { - if (ch == ')') { - open_parentheses--; - } else { - if (ch == '\n') { - (*start_lines)++; - start_mode = 1; - } - } - } - if (open_parentheses > 0) { - continue; - } - } + long fetch_mode; + zval *pdo_statement, *fetch_type; - i = j; - smart_str_appendc(&processed_str, ' '); - break; - } - } + PHALCON_MM_GROW(); - if (ch == '\n') { - (*start_lines)++; - start_mode = 1; - } + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &fetch_mode) == FAILURE) { + RETURN_MM_NULL(); } - smart_str_0(&processed_str); + PHALCON_INIT_VAR(fetch_type); - if (processed_str.len) { - RETURN_STRINGL(processed_str.c, processed_str.len, 0); + 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 { - RETURN_EMPTY_STRING(); + ZVAL_LONG(fetch_type, 0); } -} -static int phannot_internal_parse_annotations(zval **result, zval *comment, zval *file_path, zval *line, zval **error_msg TSRMLS_DC) { + 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); + } - 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; + RETURN_MM_NULL(); +} - if (!Z_STRVAL_P(comment)) { - ZVAL_BOOL(*result, 0); - return FAILURE; - } +static PHP_METHOD(Phalcon_Db_Result_Pdo, getInternalResult){ - 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); + RETURN_MEMBER_QUICK(this_ptr, "_pdoStatement", 650036348UL); +} - 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); - switch (token.opcode) { +PHALCON_INIT_CLASS(Phalcon_Db_Column){ - case PHANNOT_T_IGNORE: - break; + PHALCON_REGISTER_CLASS(Phalcon\\Db, Column, db_column, phalcon_db_column_method_entry, 0); - 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; + 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); - 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; + 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); - 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; + zend_class_implements(phalcon_db_column_ce TSRMLS_CC, 1, phalcon_db_columninterface_ce); - 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 SUCCESS; +} - 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_Column, __construct){ - 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 *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; - 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_MM_GROW(); - if (parser_status->status != PHANNOT_PARSING_OK) { - status = FAILURE; - break; + 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); + } + + 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 (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; } - - state->end = state->start; } - - 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); - } + + 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); } - - 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); - } + + 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); } - - 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); - } - } + + 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(); +} - efree(Z_STRVAL(processed_comment)); +static PHP_METHOD(Phalcon_Db_Column, getSchemaName){ - efree(parser_status); - efree(state); - return status; + RETURN_MEMBER_QUICK(this_ptr, "_schemaName", 851420310UL); } +static PHP_METHOD(Phalcon_Db_Column, getName){ + RETURN_MEMBER_QUICK(this_ptr, "_columnName", 3251978323UL); +} -#ifdef HAVE_CONFIG_H -#endif +static PHP_METHOD(Phalcon_Db_Column, getType){ + 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_Annotations_Exception){ +static PHP_METHOD(Phalcon_Db_Column, getScale){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Annotations, Exception, annotations_exception, "phalcon\\exception", NULL, 0); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_scale", 2819877996UL); } +static PHP_METHOD(Phalcon_Db_Column, isUnsigned){ + RETURN_MEMBER_QUICK(this_ptr, "_unsigned", 127907201UL); +} +static PHP_METHOD(Phalcon_Db_Column, isNotNull){ -#ifdef HAVE_CONFIG_H -#endif + RETURN_MEMBER_QUICK(this_ptr, "_notNull", 628108368UL); +} +static PHP_METHOD(Phalcon_Db_Column, isPrimary){ + RETURN_MEMBER_QUICK(this_ptr, "_primary", 3445614760UL); +} +static PHP_METHOD(Phalcon_Db_Column, isAutoIncrement){ -PHALCON_INIT_CLASS(Phalcon_Annotations_Adapter){ + RETURN_MEMBER_QUICK(this_ptr, "_autoIncrement", 3100381058UL); +} - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Adapter, annotations_adapter, phalcon_annotations_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); +static PHP_METHOD(Phalcon_Db_Column, isNumeric){ - 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); - return SUCCESS; + RETURN_MEMBER_QUICK(this_ptr, "_isNumeric", 2501917651UL); } -static PHP_METHOD(Phalcon_Annotations_Adapter, setReader){ +static PHP_METHOD(Phalcon_Db_Column, isFirst){ - zval *reader; - phalcon_fetch_params(0, 1, 0, &reader); - - 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); - + RETURN_MEMBER_QUICK(this_ptr, "_first", 2318852460UL); } -static PHP_METHOD(Phalcon_Annotations_Adapter, getReader){ - - zval *reader = NULL; +static PHP_METHOD(Phalcon_Db_Column, getAfterPosition){ - PHALCON_MM_GROW(); - 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); + RETURN_MEMBER_QUICK(this_ptr, "_after", 2119674294UL); } -static PHP_METHOD(Phalcon_Annotations_Adapter, get){ - - zval *class_name, *real_class_name = NULL, *annotations; - zval *class_annotations = NULL, *reader, *parsed_annotations; +static PHP_METHOD(Phalcon_Db_Column, getBindType){ - PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &class_name); - - 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); - } - - 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); - } - } - - 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); - - 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_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); - } - } - - RETURN_CCTOR(class_annotations); + RETURN_MEMBER_QUICK(this_ptr, "_bindType", 926651555UL); } -static PHP_METHOD(Phalcon_Annotations_Adapter, getMethods){ +static PHP_METHOD(Phalcon_Db_Column, __set_state){ - zval *class_name, *class_annotations; + 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, 1, 0, &class_name); - - PHALCON_INIT_VAR(class_annotations); - phalcon_call_method_p1_key(class_annotations, this_ptr, "get", class_name, 2090288933UL); + phalcon_fetch_params(1, 1, 0, &data); - if (Z_TYPE_P(class_annotations) == IS_OBJECT) { - phalcon_call_method_key(return_value, class_annotations, "getmethodsannotations", 2860599943UL); - RETURN_MM(); + if (Z_TYPE_P(data) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Column state must be an array"); + return; } - 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(); - - phalcon_fetch_params(1, 2, 0, &class_name, &method_name); + 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(class_annotations); - phalcon_call_method_p1_key(class_annotations, this_ptr, "get", class_name, 2090288933UL); + 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); + } - if (Z_TYPE_P(class_annotations) == IS_OBJECT) { + 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(methods); - phalcon_call_method_key(methods, class_annotations, "getmethodsannotations", 2860599943UL); - if (Z_TYPE_P(methods) == IS_ARRAY) { + 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); + } - phalcon_is_iterable(methods, &ah0, &hp0, 0, 0); + 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); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + 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_GET_HKEY(name, ah0, hp0); - PHALCON_GET_HVALUE(method); + 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 (PHALCON_IS_EQUAL(name, method_name)) { - RETURN_CCTOR(method); - } + 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); + } - zend_hash_move_forward_ex(ah0, &hp0); - } + 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(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); } - object_init_ex(return_value, phalcon_annotations_collection_ce); - phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL); + object_init_ex(return_value, phalcon_db_column_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", column_name, definition, 1107214344UL); RETURN_MM(); } -static PHP_METHOD(Phalcon_Annotations_Adapter, getProperties){ - 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, "getpropertiesannotations", 3353352384UL); - RETURN_MM(); - } - - RETURN_MM_EMPTY_ARRAY(); -} -static PHP_METHOD(Phalcon_Annotations_Adapter, getProperty){ +#ifdef HAVE_CONFIG_H +#endif - 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(); ->>>>>>> 1.2.2 +PHALCON_INIT_CLASS(Phalcon_Db_IndexInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Db, IndexInterface, db_indexinterface, phalcon_db_indexinterface_method_entry); + + return SUCCESS; } + + + + #ifdef HAVE_CONFIG_H #endif @@ -143624,66 +71399,183 @@ static PHP_METHOD(Phalcon_Annotations_Adapter, getProperty){ -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Logger_Formatter){ +PHALCON_INIT_CLASS(Phalcon_Db_Reference){ - PHALCON_REGISTER_CLASS(Phalcon\\Logger, Formatter, logger_formatter, phalcon_logger_formatter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); -======= -PHALCON_INIT_CLASS(Phalcon_Annotations_Reflection){ + PHALCON_REGISTER_CLASS(Phalcon\\Db, Reference, db_reference, phalcon_db_reference_method_entry, 0); - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Reflection, annotations_reflection, phalcon_annotations_reflection_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_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); ->>>>>>> 1.2.2 + zend_class_implements(phalcon_db_reference_ce TSRMLS_CC, 1, phalcon_db_referenceinterface_ce); return SUCCESS; } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Logger_Formatter, getTypeString){ +static PHP_METHOD(Phalcon_Db_Reference, __construct){ - static const char *lut[10] = { - "EMERGENCY", "CRITICAL", "ALERT", "ERROR", "WARNING", - "NOTICE", "INFO", "DEBUG", "CUSTOM", "SPECIAL" - }; + zval *reference_name, *definition, *referenced_table; + zval *columns, *referenced_columns, *schema; + zval *referenced_schema, *number_columns; + zval *number_referenced_columns; - zval *type; - int itype; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &type); + phalcon_fetch_params(1, 2, 0, &reference_name, &definition); - itype = phalcon_get_intval(type); - if (itype > 0 && itype < 10) { - RETURN_STRING(lut[itype], 1); + 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; } - RETURN_STRING("CUSTOM", 1); + 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){ -#ifdef HAVE_CONFIG_H -#endif + RETURN_MEMBER_QUICK(this_ptr, "_schemaName", 851420310UL); +} +static PHP_METHOD(Phalcon_Db_Reference, getReferencedSchema){ -PHALCON_INIT_CLASS(Phalcon_Logger_FormatterInterface){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Logger, FormatterInterface, logger_formatterinterface, phalcon_logger_formatterinterface_method_entry); + RETURN_MEMBER_QUICK(this_ptr, "_referencedSchema", 106854792UL); +} - return SUCCESS; +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 @@ -143693,302 +71585,149 @@ PHALCON_INIT_CLASS(Phalcon_Logger_FormatterInterface){ -PHALCON_INIT_CLASS(Phalcon_Logger_Item){ +PHALCON_INIT_CLASS(Phalcon_Db_RawValue){ - PHALCON_REGISTER_CLASS(Phalcon\\Logger, Item, logger_item, phalcon_logger_item_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Db, RawValue, db_rawvalue, phalcon_db_rawvalue_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); + zend_declare_property_null(phalcon_db_rawvalue_ce, SL("_value"), ZEND_ACC_PROTECTED TSRMLS_CC); return SUCCESS; } -static PHP_METHOD(Phalcon_Logger_Item, __construct){ - - zval *message, *type, *time = NULL; +static PHP_METHOD(Phalcon_Db_RawValue, __construct){ - PHALCON_MM_GROW(); + zval *value; - phalcon_fetch_params(1, 2, 1, &message, &type, &time); - - if (!time) { - PHALCON_INIT_VAR(time); - ZVAL_LONG(time, 0); - } + phalcon_fetch_params(0, 1, 0, &value); - 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_update_property_this_quick(this_ptr, SL("_value"), value, 2935317441UL TSRMLS_CC); - PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Logger_Item, getMessage){ +static PHP_METHOD(Phalcon_Db_RawValue, getValue){ - RETURN_MEMBER_QUICK(this_ptr, "_message", 933579817UL); + RETURN_MEMBER_QUICK(this_ptr, "_value", 2935317441UL); } -static PHP_METHOD(Phalcon_Logger_Item, getType){ +static PHP_METHOD(Phalcon_Db_RawValue, __toString){ - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); + RETURN_MEMBER_QUICK(this_ptr, "_value", 2935317441UL); } -static PHP_METHOD(Phalcon_Logger_Item, getTime){ - RETURN_MEMBER_QUICK(this_ptr, "_time", 3991380851UL); -======= -static PHP_METHOD(Phalcon_Annotations_Reflection, __construct){ - zval *reflection_data = NULL; - PHALCON_MM_GROW(); +#ifdef HAVE_CONFIG_H +#endif - phalcon_fetch_params(1, 0, 1, &reflection_data); - - if (!reflection_data) { - PHALCON_INIT_VAR(reflection_data); - } - - if (Z_TYPE_P(reflection_data) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_reflectionData"), reflection_data, 3848141129UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Annotations_Reflection, getClassAnnotations){ - zval *annotations, *reflection_data, *reflection_class; - zval *collection; - 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_update_property_this_quick(this_ptr, SL("_classAnnotations"), collection, 372163368UL TSRMLS_CC); - RETURN_CTOR(collection); - } - - phalcon_update_property_bool(this_ptr, SL("_classAnnotations"), 0 TSRMLS_CC); - RETURN_MM_FALSE; - } - - RETURN_CCTOR(annotations); -} -static PHP_METHOD(Phalcon_Annotations_Reflection, getMethodsAnnotations){ - zval *annotations, *reflection_data, *reflection_methods; - zval *collections, *reflection_method = NULL, *method_name = NULL; - zval *collection = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; +PHALCON_INIT_CLASS(Phalcon_Db_Profiler_Item){ - PHALCON_MM_GROW(); + PHALCON_REGISTER_CLASS(Phalcon\\Db\\Profiler, Item, db_profiler_item, phalcon_db_profiler_item_method_entry, 0); - 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); -} + 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); -static PHP_METHOD(Phalcon_Annotations_Reflection, getPropertiesAnnotations){ + return SUCCESS; +} - zval *annotations, *reflection_data, *reflection_properties; - zval *collections, *reflection_property = NULL, *property = NULL; - zval *collection = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; +static PHP_METHOD(Phalcon_Db_Profiler_Item, setSQLStatement){ - PHALCON_MM_GROW(); + zval *sql_statement; - 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_fetch_params(0, 1, 0, &sql_statement); - phalcon_update_property_bool(this_ptr, SL("_propertyAnnotations"), 0 TSRMLS_CC); - RETURN_MM_FALSE; - } + phalcon_update_property_this_quick(this_ptr, SL("_sqlStatement"), sql_statement, 18972457UL TSRMLS_CC); - RETURN_CCTOR(annotations); } -static PHP_METHOD(Phalcon_Annotations_Reflection, getReflectionData){ +static PHP_METHOD(Phalcon_Db_Profiler_Item, getSQLStatement){ - RETURN_MEMBER_QUICK(this_ptr, "_reflectionData", 3848141129UL); + RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); } -static PHP_METHOD(Phalcon_Annotations_Reflection, __set_state){ - - zval *data, *reflection_data; +static PHP_METHOD(Phalcon_Db_Profiler_Item, setInitialTime){ - PHALCON_MM_GROW(); + zval *initial_time; - phalcon_fetch_params(1, 1, 0, &data); - - 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); + phalcon_fetch_params(0, 1, 0, &initial_time); - RETURN_MM(); - } - } - object_init_ex(return_value, phalcon_annotations_reflection_ce); - phalcon_call_method_key(NULL, return_value, "__construct", 1107214344UL); + phalcon_update_property_this_quick(this_ptr, SL("_initialTime"), initial_time, 3347691997UL TSRMLS_CC); - RETURN_MM(); } +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); + +} - -#ifdef HAVE_CONFIG_H -#endif +static PHP_METHOD(Phalcon_Db_Profiler_Item, getInitialTime){ + RETURN_MEMBER_QUICK(this_ptr, "_initialTime", 3347691997UL); +} -PHALCON_INIT_CLASS(Phalcon_Annotations_AdapterInterface){ +static PHP_METHOD(Phalcon_Db_Profiler_Item, getFinalTime){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Annotations, AdapterInterface, annotations_adapterinterface, phalcon_annotations_adapterinterface_method_entry); - return SUCCESS; ->>>>>>> 1.2.2 + 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(); +} -<<<<<<< HEAD -======= +#ifdef HAVE_CONFIG_H +#endif ->>>>>>> 1.2.2 -#ifdef HAVE_CONFIG_H -#endif +PHALCON_INIT_CLASS(Phalcon_Db_ResultInterface){ + PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ResultInterface, db_resultinterface, phalcon_db_resultinterface_method_entry); + return SUCCESS; +} -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Logger_Exception){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger, Exception, logger_exception, "phalcon\\exception", NULL, 0); -======= -PHALCON_INIT_CLASS(Phalcon_Annotations_Reader){ - PHALCON_REGISTER_CLASS(Phalcon\\Annotations, Reader, annotations_reader, phalcon_annotations_reader_method_entry, 0); - zend_class_implements(phalcon_annotations_reader_ce TSRMLS_CC, 1, phalcon_annotations_readerinterface_ce); ->>>>>>> 1.2.2 - return SUCCESS; -} -<<<<<<< HEAD @@ -144002,888 +71741,925 @@ PHALCON_INIT_CLASS(Phalcon_Annotations_Reader){ -PHALCON_INIT_CLASS(Phalcon_Logger_Multiple){ +PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Mysql){ - PHALCON_REGISTER_CLASS(Phalcon\\Logger, Multiple, logger_multiple, phalcon_logger_multiple_method_entry, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Mysql, db_dialect_mysql, "phalcon\\db\\dialect", phalcon_db_dialect_mysql_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_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_Logger_Multiple, push){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, getColumnDefinition){ - zval *logger; + zval *column, *size, *column_type, *column_sql = NULL; + zval *is_unsigned = NULL, *scale = NULL; - phalcon_fetch_params(0, 1, 0, &logger); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &column); - if (Z_TYPE_P(logger) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "The logger is invalid"); + 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_update_property_array_append(this_ptr, SL("_loggers"), logger TSRMLS_CC); + 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); + PHALCON_CONCAT_SVS(column_sql, "INT(", size, ")"); + + 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); + } + + 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, "DECIMAL(", size, ",", scale, ")"); + + 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); + } + + break; + + case 4: + PHALCON_INIT_NVAR(column_sql); + ZVAL_STRING(column_sql, "DATETIME", 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(column_sql); + ZVAL_STRING(column_sql, "FLOAT", 1); + + 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_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); + } + + 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 MySQL data type"); + return; + + } + + RETURN_CTOR(column_sql); } -static PHP_METHOD(Phalcon_Logger_Multiple, getLoggers){ - - - RETURN_MEMBER_QUICK(this_ptr, "_loggers", 810888023UL); -} - -static PHP_METHOD(Phalcon_Logger_Multiple, setFormatter){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addColumn){ - zval *formatter, *loggers, *logger = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + 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, 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_fetch_params(1, 3, 0, &table_name, &schema_name, &column); - phalcon_is_iterable(loggers, &ah0, &hp0, 0, 0); + 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 "); + } - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(name); + phalcon_call_method_key(name, column, "getname", 4286441094UL); - PHALCON_GET_HVALUE(logger); + PHALCON_INIT_VAR(column_definition); + phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); + PHALCON_SCONCAT_SVSV(sql, "`", name, "` ", column_definition); - phalcon_call_method_p1_key(NULL, logger, "setformatter", formatter, 3614631813UL); + 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); + } - zend_hash_move_forward_ex(ah0, &hp0); + 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); } - } - phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Logger_Multiple, getFormatter){ - - - RETURN_MEMBER_QUICK(this_ptr, "_formatter", 1838243768UL); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Multiple, log){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, modifyColumn){ - zval *message, *type = NULL, *loggers, *logger = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *table_name, *schema_name, *column, *sql = NULL, *name; + zval *column_definition, *is_not_null; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &message, &type); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); - if (!type) { - PHALCON_INIT_VAR(type); - ZVAL_LONG(type, 7); + 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_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_INIT_VAR(name); + phalcon_call_method_key(name, column, "getname", 4286441094UL); - PHALCON_GET_HVALUE(logger); + PHALCON_INIT_VAR(column_definition); + phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); + PHALCON_SCONCAT_SVSV(sql, "`", name, "` ", column_definition); - phalcon_call_method_p2_key(NULL, logger, "log", message, type, 2090479079UL); + 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); + } - zend_hash_move_forward_ex(ah0, &hp0); - } + RETURN_CTOR(sql); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropColumn){ + + zval *table_name, *schema_name, *column_name; + zval *sql = NULL; + + PHALCON_MM_GROW(); + + 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, "`"); - PHALCON_MM_RESTORE(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Multiple, emergence){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addIndex){ - zval *message, *type; + zval *table_name, *schema_name, *index, *sql = NULL, *columns; + zval *quoted_column_list, *name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); - 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 (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 INDEX "); + } else { + PHALCON_INIT_NVAR(sql); + PHALCON_CONCAT_SVS(sql, "ALTER TABLE `", table_name, "` ADD INDEX "); + } - PHALCON_MM_RESTORE(); + 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(name); + phalcon_call_method_key(name, index, "getname", 4286441094UL); + PHALCON_SCONCAT_SVSVS(sql, "`", name, "` (", quoted_column_list, ")"); + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Multiple, debug){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropIndex){ - zval *message, *type; + zval *table_name, *schema_name, *index_name; + zval *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index_name); - 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); + 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_MM_RESTORE(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Multiple, error){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addPrimaryKey){ - zval *message, *type; + zval *table_name, *schema_name, *index, *sql = NULL, *columns; + zval *column_list; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); - 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); + 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_MM_RESTORE(); + PHALCON_INIT_VAR(columns); + phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); + + PHALCON_INIT_VAR(column_list); + phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); + PHALCON_SCONCAT_SVS(sql, "(", column_list, ")"); + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Multiple, info){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropPrimaryKey){ - zval *message, *type; + zval *table_name, *schema_name, *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 2, 0, &table_name, &schema_name); - 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 (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"); + } - PHALCON_MM_RESTORE(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Multiple, notice){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, addForeignKey){ - zval *message, *type; + 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, 1, 0, &message); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference); - 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 (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 "); + } - PHALCON_MM_RESTORE(); + 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, "`."); + } + + PHALCON_INIT_VAR(referenced_columns); + phalcon_call_method_key(referenced_columns, reference, "getreferencedcolumns", 301959449UL); + + 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_Logger_Multiple, warning){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropForeignKey){ - zval *message, *type; + zval *table_name, *schema_name, *reference_name; + zval *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference_name); - 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 (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, "`"); - PHALCON_MM_RESTORE(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Multiple, alert){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, _getTableOptions){ - zval *message, *type; + 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, 1, 0, &message); + phalcon_fetch_params(1, 1, 0, &definition); - 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); -======= -static PHP_METHOD(Phalcon_Annotations_Reader, parse){ + if (phalcon_array_isset_quick_string(definition, SS("options"), 2952422065UL)) { + + PHALCON_INIT_VAR(table_options); + array_init(table_options); + + PHALCON_OBS_VAR(options); + phalcon_array_fetch_quick_string(&options, definition, SS("options"), 2952422065UL, PH_NOISY); + + if (phalcon_array_isset_quick_string(options, SS("ENGINE"), 2119337627UL)) { + + 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 (phalcon_array_isset_quick_string(options, SS("AUTO_INCREMENT"), 656925090UL)) { + + 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); + } + } + + if (phalcon_array_isset_quick_string(options, SS("TABLE_COLLATION"), 1457306353UL)) { + + 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_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); + } + } + + 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(); +} - 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; +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; - zend_class_entry *ce0; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &class_name); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &definition); - if (unlikely(Z_TYPE_P(class_name) != IS_STRING)) { - PHALCON_THROW_EXCEPTION_STR(phalcon_annotations_exception_ce, "The class name 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_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); + 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(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(temporary); + ZVAL_BOOL(temporary, 0); + if (phalcon_array_isset_quick_string(definition, SS("options"), 2952422065UL)) { - PHALCON_INIT_VAR(class_annotations); - if (phannot_parse_annotations(class_annotations, comment, file, line TSRMLS_CC) == FAILURE) { - return; + 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 (Z_TYPE_P(class_annotations) == IS_ARRAY) { - phalcon_array_update_quick_string(&annotations, SS("class"), 4138154555UL, &class_annotations, PH_COPY | PH_SEPARATE); - } + 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(properties); - phalcon_call_method_key(properties, reflection, "getproperties", 3608986354UL); - if (phalcon_fast_count_ev(properties TSRMLS_CC)) { + PHALCON_INIT_VAR(create_lines); + array_init(create_lines); - PHALCON_INIT_NVAR(line); - ZVAL_LONG(line, 1); + PHALCON_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); - PHALCON_INIT_VAR(annotations_properties); - array_init(annotations_properties); + phalcon_is_iterable(columns, &ah0, &hp0, 0, 0); - phalcon_is_iterable(properties, &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_HVALUE(column); - PHALCON_GET_HVALUE(property); + PHALCON_INIT_NVAR(column_name); + phalcon_call_method_key(column_name, column, "getname", 4286441094UL); - PHALCON_INIT_NVAR(comment); - phalcon_call_method_key(comment, property, "getdoccomment", 185815758UL); - if (Z_TYPE_P(comment) == IS_STRING) { + PHALCON_INIT_NVAR(column_definition); + phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); - PHALCON_INIT_NVAR(file); - phalcon_call_method_key(file, reflection, "getfilename", 984101030UL); + PHALCON_INIT_NVAR(column_line); + PHALCON_CONCAT_SVSV(column_line, "`", column_name, "` ", column_definition); - 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); - } - } + 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); + } - zend_hash_move_forward_ex(ah0, &hp0); + 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); } - 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_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); } - PHALCON_INIT_VAR(methods); - phalcon_call_method_key(methods, reflection, "getmethods", 20298521UL); - if (phalcon_fast_count_ev(methods TSRMLS_CC)) { + if (phalcon_array_isset_quick_string(definition, SS("indexes"), 1726269685UL)) { - PHALCON_INIT_VAR(annotations_methods); - array_init(annotations_methods); + PHALCON_OBS_VAR(indexes); + phalcon_array_fetch_quick_string(&indexes, definition, SS("indexes"), 1726269685UL, PH_NOISY); - phalcon_is_iterable(methods, &ah1, &hp1, 0, 0); + phalcon_is_iterable(indexes, &ah1, &hp1, 0, 0); while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - PHALCON_GET_HVALUE(method); + PHALCON_GET_HVALUE(index); - PHALCON_INIT_NVAR(comment); - phalcon_call_method_key(comment, method, "getdoccomment", 185815758UL); - if (Z_TYPE_P(comment) == IS_STRING) { + PHALCON_INIT_NVAR(index_name); + phalcon_call_method_key(index_name, index, "getname", 4286441094UL); - PHALCON_INIT_NVAR(file); - phalcon_call_method_key(file, method, "getfilename", 984101030UL); + PHALCON_INIT_NVAR(columns); + phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); - PHALCON_INIT_NVAR(line); - phalcon_call_method_key(line, method, "getstartline", 2520085083UL); + PHALCON_INIT_NVAR(column_list); + phalcon_call_method_p1_key(column_list, this_ptr, "getcolumnlist", columns, 2735238095UL); - 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); - } + 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); } - 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(); - - phalcon_fetch_params(1, 1, 2, &doc_block, &file, &line); + if (phalcon_array_isset_quick_string(definition, SS("references"), 3245500135UL)) { - if (!file) { - PHALCON_INIT_VAR(file); - } else { - PHALCON_SEPARATE_PARAM(file); - } + PHALCON_OBS_VAR(references); + phalcon_array_fetch_quick_string(&references, definition, SS("references"), 3245500135UL, PH_NOISY); - if (!line) { - PHALCON_INIT_VAR(line); - } + phalcon_is_iterable(references, &ah2, &hp2, 0, 0); - 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_Text){ - - PHALCON_REGISTER_CLASS(Phalcon, Text, text, phalcon_text_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - - zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_ALNUM"), 0 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_ALPHA"), 1 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_HEXDEC"), 2 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_NUMERIC"), 3 TSRMLS_CC); - zend_declare_class_constant_long(phalcon_text_ce, SL("RANDOM_NOZERO"), 4 TSRMLS_CC); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Text, camelize){ - - zval *str; - - phalcon_fetch_params(0, 1, 0, &str); + 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_camelize(return_value, str); - return; -} - -static PHP_METHOD(Phalcon_Text, uncamelize){ - - zval *str; - - phalcon_fetch_params(0, 1, 0, &str); + PHALCON_INIT_NVAR(constaint_sql); + PHALCON_CONCAT_SVSVS(constaint_sql, "CONSTRAINT `", name, "` FOREIGN KEY (", column_list, ")"); - phalcon_uncamelize(return_value, str); - return; -} - -static PHP_METHOD(Phalcon_Text, increment){ - - zval *str, *separator = NULL, *parts, *number = NULL, *first_part; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 1, &str, &separator); + 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 (!separator) { - PHALCON_INIT_VAR(separator); - } else { - PHALCON_SEPARATE_PARAM(separator); - } + zend_hash_move_forward_ex(ah2, &hp2); + } - if (Z_TYPE_P(separator) == IS_NULL) { - PHALCON_INIT_NVAR(separator); - ZVAL_STRING(separator, "_", 1); } - PHALCON_INIT_VAR(parts); - phalcon_fast_explode(parts, separator, str); - if (phalcon_array_isset_long(parts, 1)) { - PHALCON_OBS_VAR(number); - phalcon_array_fetch_long(&number, parts, 1, PH_NOISY); - PHALCON_SEPARATE(number); - phalcon_increment(number); - } else { - PHALCON_INIT_NVAR(number); - ZVAL_LONG(number, 1); + 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_OBS_VAR(first_part); - phalcon_array_fetch_long(&first_part, parts, 0, PH_NOISY); - PHALCON_CONCAT_VVV(return_value, first_part, separator, number); - - RETURN_MM(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Text, random){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropTable){ - zval *type, *length = NULL; + zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; + zval *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &type, &length); + phalcon_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); - if (!length) { - PHALCON_INIT_VAR(length); - ZVAL_LONG(length, 8); + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); } - phalcon_random_string(return_value, type, length TSRMLS_CC); - RETURN_MM(); + 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); + } + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Text, startsWith){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, createView){ - zval *str, *start, *ignore_case = NULL; + zval *view_name, *definition, *schema_name, *view_sql; + zval *view = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &str, &start, &ignore_case); + phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); - if (!ignore_case) { - PHALCON_INIT_VAR(ignore_case); - ZVAL_BOOL(ignore_case, 1); + 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 (phalcon_start_with(str, start, ignore_case)) { - RETURN_MM_TRUE; + 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, "`"); } - RETURN_MM_FALSE; + + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Text, endsWith){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, dropView){ - zval *str, *end, *ignore_case = NULL; + zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; + zval *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &str, &end, &ignore_case); + phalcon_fetch_params(1, 2, 1, &view_name, &schema_name, &if_exists); - if (!ignore_case) { - PHALCON_INIT_VAR(ignore_case); - ZVAL_BOOL(ignore_case, 1); + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); } - if (phalcon_end_with(str, end, ignore_case)) { - RETURN_MM_TRUE; + 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); } - RETURN_MM_FALSE; + 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_Text, lower){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableExists){ - zval *str; + zval *table_name, *schema_name = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &str); + phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - if (phalcon_function_quick_exists_ex(SS("mb_strtolower"), 3802586680UL TSRMLS_CC) == SUCCESS) { - phalcon_call_func_p1(return_value, "mb_strtolower", str); - RETURN_MM(); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - phalcon_fast_strtolower(return_value, str); - RETURN_MM(); -} - -static PHP_METHOD(Phalcon_Text, upper){ - - zval *str; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &str); - if (phalcon_function_quick_exists_ex(SS("mb_strtoupper"), 4155739579UL TSRMLS_CC) == SUCCESS) { - phalcon_call_func_p1(return_value, "mb_strtoupper", str); + 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_fast_strtoupper(return_value, str); + 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 - - - - - - - -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; + zval *view_name, *schema_name = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (phalcon_array_isset_quick_string(options, SS("mode"), 267518858UL)) { + phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - 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 (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - 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; + 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("_stream"), stream, 3546870672UL TSRMLS_CC); ->>>>>>> 1.2.2 - - PHALCON_MM_RESTORE(); + RETURN_MM(); } -<<<<<<< HEAD - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -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 PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeColumns){ -static PHP_METHOD(Phalcon_Logger_Adapter, setLogLevel){ + zval *table, *schema = NULL; - zval *level; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &level); + phalcon_fetch_params(1, 1, 1, &table, &schema); - if (Z_TYPE_P(level) != IS_LONG) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "The log level is not valid"); - return; + if (!schema) { + PHALCON_INIT_VAR(schema); } - 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 (zend_is_true(schema)) { + PHALCON_CONCAT_SVSVS(return_value, "DESCRIBE `", schema, "`.`", table, "`"); + RETURN_MM(); } - phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); + PHALCON_CONCAT_SVS(return_value, "DESCRIBE `", table, "`"); - RETURN_THISW(); -} - -static PHP_METHOD(Phalcon_Logger_Adapter, begin){ - - - phalcon_update_property_bool(this_ptr, SL("_transaction"), 1 TSRMLS_CC); - RETURN_THISW(); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Logger_Adapter, commit){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, listTables){ - zval *transaction, *queue, *message = NULL, *message_str = NULL; - zval *type = NULL, *time = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *schema_name = NULL; 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_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); - } + phalcon_fetch_params(1, 0, 1, &schema_name); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - RETURN_THIS(); -} - -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; + if (zend_is_true(schema_name)) { + PHALCON_CONCAT_SVS(return_value, "SHOW TABLES FROM `", schema_name, "`"); + RETURN_MM(); } - - 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(); + RETURN_MM_STRING("SHOW TABLES", 1); } -static PHP_METHOD(Phalcon_Logger_Adapter, emergence){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, listViews){ - zval *message, *type; + zval *schema_name = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 0, 1, &schema_name); - 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(); -} - -static PHP_METHOD(Phalcon_Logger_Adapter, debug){ - - zval *message, *type; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &message); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } - 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 (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_Logger_Adapter, error){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeIndexes){ - zval *message, *type; + zval *table, *schema = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 1, &table, &schema); - 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(); -} - -static PHP_METHOD(Phalcon_Logger_Adapter, info){ - - zval *message, *type; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &message); + if (!schema) { + PHALCON_INIT_VAR(schema); + } - 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(); -} - -static PHP_METHOD(Phalcon_Logger_Adapter, notice){ - - zval *message, *type; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &message); + if (zend_is_true(schema)) { + PHALCON_CONCAT_SVSVS(return_value, "SHOW INDEXES FROM `", schema, "`.`", table, "`"); + RETURN_MM(); + } + PHALCON_CONCAT_SVS(return_value, "SHOW INDEXES FROM `", table, "`"); - 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(); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Logger_Adapter, warning){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, describeReferences){ - zval *message, *type; + zval *table, *schema = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 1, &table, &schema); - 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 PHP_METHOD(Phalcon_Logger_Adapter, alert){ - - zval *message, *type; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &message); + if (!schema) { + PHALCON_INIT_VAR(schema); + } - 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(); + 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_Logger_Adapter, log){ +static PHP_METHOD(Phalcon_Db_Dialect_Mysql, tableOptions){ - zval *message, *type = NULL, *timestamp, *transaction; - zval *queue_item, *log_level; + zval *table, *schema = NULL, *sql; 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_fetch_params(1, 1, 1, &table, &schema); - PHALCON_OBS_VAR(log_level); - phalcon_read_property_this_quick(&log_level, this_ptr, SL("_logLevel"), 4227944734UL, PH_NOISY_CC); + if (!schema) { + PHALCON_INIT_VAR(schema); + } - if (PHALCON_GE(log_level, type)) { - phalcon_call_method_p3_key(NULL, this_ptr, "loginternal", message, type, timestamp, 2472438692UL); + 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_THIS(); + RETURN_CTOR(sql); } @@ -144899,697 +72675,960 @@ static PHP_METHOD(Phalcon_Logger_Adapter, log){ -PHALCON_INIT_CLASS(Phalcon_Logger_Formatter_Line){ +PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Oracle){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Formatter, Line, logger_formatter_line, "phalcon\\logger\\formatter", phalcon_logger_formatter_line_method_entry, 0); + 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_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_declare_property_string(phalcon_db_dialect_oracle_ce, SL("_escapeChar"), "", ZEND_ACC_PROTECTED TSRMLS_CC); - zend_class_implements(phalcon_logger_formatter_line_ce TSRMLS_CC, 1, phalcon_logger_formatterinterface_ce); + zend_class_implements(phalcon_db_dialect_oracle_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Logger_Formatter_Line, __construct){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, getColumnDefinition){ - zval *format = NULL, *date_format = NULL; + zval *column, *size, *column_type, *column_sql = NULL; + zval *scale = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &format, &date_format); + phalcon_fetch_params(1, 1, 0, &column); - if (!format) { - PHALCON_INIT_VAR(format); + 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 (!date_format) { - PHALCON_INIT_VAR(date_format); - } + 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; + + 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; - 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(); + RETURN_CTOR(column_sql); } -static PHP_METHOD(Phalcon_Logger_Formatter_Line, setFormat){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addColumn){ - zval *format; + zval *table_name, *schema_name, *column; - phalcon_fetch_params(0, 1, 0, &format); - - phalcon_update_property_this_quick(this_ptr, SL("_format"), format, 3742267021UL 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; } -static PHP_METHOD(Phalcon_Logger_Formatter_Line, getFormat){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, modifyColumn){ + zval *table_name, *schema_name, *column; - RETURN_MEMBER_QUICK(this_ptr, "_format", 3742267021UL); + 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_Logger_Formatter_Line, setDateFormat){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropColumn){ - zval *date; + zval *table_name, *schema_name, *column_name; - phalcon_fetch_params(0, 1, 0, &date); - - phalcon_update_property_this_quick(this_ptr, SL("_dateFormat"), date, 959184011UL TSRMLS_CC); + 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_Logger_Formatter_Line, getDateFormat){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, addIndex){ + zval *table_name, *schema_name, *index; - RETURN_MEMBER_QUICK(this_ptr, "_dateFormat", 959184011UL); + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } -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; +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropIndex){ - PHALCON_MM_GROW(); + zval *table_name, *schema_name, *index_name; - 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); + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index_name); - RETURN_MM(); + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; } +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, 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; +} +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropPrimaryKey){ -#ifdef HAVE_CONFIG_H -#endif - - + 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_INIT_CLASS(Phalcon_Logger_Formatter_Json){ + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &reference); + + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; +} - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Formatter, Json, logger_formatter_json, "phalcon\\logger\\formatter", phalcon_logger_formatter_json_method_entry, 0); +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropForeignKey){ - zend_class_implements(phalcon_logger_formatter_json_ce TSRMLS_CC, 1, phalcon_logger_formatterinterface_ce); + 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, "Not implemented yet"); + return; } -static PHP_METHOD(Phalcon_Logger_Formatter_Json, format){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, _getTableOptions){ - zval *message, *type, *timestamp, *type_str, *log; + zval *definition, *empty_array; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &message, &type, ×tamp); + phalcon_fetch_params(1, 1, 0, &definition); - PHALCON_INIT_VAR(type_str); - phalcon_call_method_p1_key(type_str, this_ptr, "gettypestring", type, 2427941566UL); + PHALCON_INIT_VAR(empty_array); + array_init(empty_array); + RETURN_CTOR(empty_array); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, createTable){ + + zval *table_name, *schema_name, *definition; + + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &definition); - 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(); -======= -static PHP_METHOD(Phalcon_Logger_Adapter_Stream, getFormatter){ + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); + return; +} - zval *formatter = NULL; +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropTable){ + + zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; + zval *sql = 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_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); - phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); } - RETURN_CCTOR(formatter); + 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); + } + + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Adapter_Stream, logInternal){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, createView){ - zval *message, *type, *time, *stream, *formatter, *applied_format; + zval *view_name, *definition, *schema_name, *view_sql; + zval *view = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 3, 0, &message, &type, &time); + phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); - 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"); + 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_INIT_VAR(formatter); - phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); + 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(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_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "CREATE VIEW ", view, " AS ", view_sql); - PHALCON_MM_RESTORE(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Adapter_Stream, close){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, dropView){ - zval *stream; + zval *view_name, *schema_name, *if_exists = NULL, *view = NULL; + zval *sql = NULL; 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(); -} - - - - - -#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; + 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_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_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, __construct){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableExists){ - zval *name, *options = NULL, *option = NULL, *facility = NULL; + zval *table_name, *schema_name = NULL, *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, &options); + phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - if (!options) { - PHALCON_INIT_VAR(options); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - 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); + 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, "'"); } - PHALCON_MM_RESTORE(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, getFormatter){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, viewExists){ - zval *formatter = NULL; + zval *view_name, *schema_name = NULL, *sql = 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); + phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - RETURN_CCTOR(formatter); + 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_Logger_Adapter_Syslog, logInternal){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeColumns){ - zval *message, *type, *time, *formatter, *applied_format; - zval *syslog_type, *syslog_message; + zval *table, *schema = NULL, *sql = NULL; 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, 1, 1, &table, &schema); - 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; + if (!schema) { + PHALCON_INIT_VAR(schema); } - 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); + 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"); + } - PHALCON_MM_RESTORE(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Adapter_Syslog, close){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, listTables){ - zval *opened; + zval *schema_name = NULL, *sql = NULL; 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, 0, 1, &schema_name); + + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - PHALCON_MM_RESTORE(); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_File){ + 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); +} - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, File, logger_adapter_file, "phalcon\\logger\\adapter", phalcon_logger_adapter_file_method_entry, 0); +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, listViews){ - 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); + zval *schema_name = NULL, *sql = NULL; - zend_class_implements(phalcon_logger_adapter_file_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + PHALCON_MM_GROW(); - return SUCCESS; + 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 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 PHP_METHOD(Phalcon_Logger_Adapter_File, __construct){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, describeIndexes){ - zval *name, *options = NULL, *mode = NULL, *handler, *exception_message; + zval *table, *schema = NULL, *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, &options); + phalcon_fetch_params(1, 1, 1, &table, &schema); - if (!options) { - PHALCON_INIT_VAR(options); + if (!schema) { + PHALCON_INIT_VAR(schema); } - 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; - } + 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(mode); - ZVAL_STRING(mode, "ab", 1); + 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(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; + 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); + + if (!schema) { + PHALCON_INIT_VAR(schema); } - 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(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, "'"); + } - PHALCON_MM_RESTORE(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Adapter_File, getFormatter){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, tableOptions){ - zval *formatter = NULL; + zval *table, *schema = 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_fetch_params(1, 1, 1, &table, &schema); - phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); + if (!schema) { + PHALCON_INIT_VAR(schema); } - RETURN_CCTOR(formatter); + RETURN_MM_EMPTY_STRING(); } -static PHP_METHOD(Phalcon_Logger_Adapter_File, logInternal){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, getSqlTable){ - zval *message, *type, *time, *file_handler, *formatter; - zval *applied_format; + 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, 3, 0, &message, &type, &time); + phalcon_fetch_params(1, 1, 1, &table, &escape_char); - 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; + if (!escape_char) { + PHALCON_INIT_VAR(escape_char); + } else { + PHALCON_SEPARATE_PARAM(escape_char); } - PHALCON_INIT_VAR(formatter); - phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); + 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_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_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_MM_RESTORE(); + 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); + } + + 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); } -static PHP_METHOD(Phalcon_Logger_Adapter_File, close){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, limit){ - zval *file_handler; + zval *sql_query, *number, *limit, *sql_limit; 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(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &sql_query, &number) == FAILURE) { + RETURN_MM_NULL(); + } + + 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 PHP_METHOD(Phalcon_Logger_Adapter_File, __wakeup){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, select){ - zval *path, *options, *mode = NULL, *file_handler; + 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(); - 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); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &definition) == FAILURE) { + RETURN_MM_NULL(); + } + + 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(mode); - ZVAL_STRING(mode, "ab", 1); + PHALCON_INIT_NVAR(escape_char); } - - 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(); -} + 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); + if (!phalcon_is_iterable_ex(columns, &ah0, &hp0, 0, 0)) { + return; + } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { -#ifdef HAVE_CONFIG_H -#endif + 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_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, " ", 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); + } + phalcon_array_append(&selected_columns, column_alias_sql, PH_SEPARATE); + zend_hash_move_forward_ex(ah0, &hp0); + } -PHALCON_INIT_CLASS(Phalcon_Logger_Adapter_Firephp){ + PHALCON_INIT_VAR(columns_sql); + phalcon_fast_join_str(columns_sql, SL(", "), selected_columns TSRMLS_CC); + } else { + PHALCON_CPY_WRT(columns_sql, columns); + } - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Adapter, Firephp, logger_adapter_firephp, "phalcon\\logger\\adapter", phalcon_logger_adapter_firephp_method_entry, 0); + PHALCON_OBS_VAR(tables); + phalcon_array_fetch_quick_string(&tables, definition, SS("tables"), 3465666720UL, PH_NOISY); + if (Z_TYPE_P(tables) == IS_ARRAY) { - 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_VAR(selected_tables); + array_init(selected_tables); - zend_class_implements(phalcon_logger_adapter_firephp_ce TSRMLS_CC, 1, phalcon_logger_adapterinterface_ce); + if (!phalcon_is_iterable_ex(tables, &ah1, &hp1, 0, 0)) { + return; + } - return SUCCESS; -} + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { -static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, getFormatter){ + PHALCON_GET_FOREACH_VALUE(table); - zval *formatter = NULL; + 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_MM_GROW(); + zend_hash_move_forward_ex(ah1, &hp1); + } - 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); + PHALCON_INIT_VAR(tables_sql); + phalcon_fast_join_str(tables_sql, SL(", "), selected_tables TSRMLS_CC); + } else { + PHALCON_CPY_WRT(tables_sql, tables); } - RETURN_CCTOR(formatter); -} + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "SELECT ", columns_sql, " FROM ", tables_sql); -static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, logInternal){ + if (phalcon_array_isset_quick_string(definition, SS("joins"), 120974824UL)) { - 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; + PHALCON_OBS_VAR(joins); + phalcon_array_fetch_quick_string(&joins, definition, SS("joins"), 120974824UL, PH_NOISY); - /* If headers has already been sent, we can do nothing. Exit early. */ - if (SG(headers_sent)) { - RETURN_FALSE; - } + if (!phalcon_is_iterable_ex(joins, &ah2, &hp2, 0, 0)) { + return; + } - PHALCON_MM_GROW(); + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - phalcon_fetch_params(1, 3, 0, &message, &type, &time); + PHALCON_GET_FOREACH_VALUE(join); - PHALCON_INIT_VAR(formatter); - phalcon_call_method_key(formatter, this_ptr, "getformatter", 519992697UL); + PHALCON_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, join, SS("type"), 276192743UL, PH_NOISY); - 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); + PHALCON_OBS_NVAR(table); + phalcon_array_fetch_quick_string(&table, join, SS("source"), 2744839734UL, PH_NOISY); - 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); + 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); - 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); + PHALCON_INIT_NVAR(sql_join); + PHALCON_CONCAT_SVSV(sql_join, " ", type, " JOIN ", sql_table); - ZVAL_TRUE(initialized); /* This will also update the property because "initialized" was not separated */ - } + 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); + } - 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); + if (phalcon_array_isset_quick_string(definition, SS("where"), 621293632UL)) { - size = Z_STRLEN_P(applied_format); - offset = 0; + 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); + } + } - smart_str_alloc4(&str, (size > chunk ? chunk : size), 0, num_bytes); + if (phalcon_array_isset_quick_string(definition, SS("group"), 7349554UL)) { - 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; + PHALCON_INIT_VAR(group_items); + array_init(group_items); - if (offset) { - /* This is not the first chunk, prepend the payload with "|" */ - smart_str_appendc(&str, '|'); + 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; } - /* Grab the chunk from the encoded string */ - smart_str_appendl(&str, Z_STRVAL_P(applied_format) + offset, num_bytes); + while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { - size -= num_bytes; - offset += num_bytes; + PHALCON_GET_FOREACH_VALUE(group_field); - if (size) { - /* If we have more data to send, append "|/" */ - smart_str_appendl(&str, "|\\", 2); + 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); } - smart_str_0(&str); /* Not strictly necessary but just to be safe */ + PHALCON_INIT_VAR(group_sql); + phalcon_fast_join_str(group_sql, SL(", "), group_items TSRMLS_CC); - /* Send the result */ - h.line = str.c; - h.line_len = str.len; - sapi_header_op(SAPI_HEADER_REPLACE, &h TSRMLS_CC); + PHALCON_INIT_VAR(group_clause); + PHALCON_CONCAT_SV(group_clause, " GROUP BY ", group_sql); + phalcon_concat_self(&sql, group_clause TSRMLS_CC); - /* Update header index; this will update Phalcon\Logger\Adapter\Firephp as well */ - ZVAL_LONG(index, Z_LVAL_P(index)+1); + 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); - str.len = 0; + 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); + } } - /* Deallocate the smnart string if it is not empty */ - if (str.c) { - smart_str_free(&str); - } + if (phalcon_array_isset_quick_string(definition, SS("order"), 320020033UL)) { - PHALCON_MM_RESTORE(); -} + PHALCON_OBS_VAR(order_fields); + phalcon_array_fetch_quick_string(&order_fields, definition, SS("order"), 320020033UL, PH_NOISY); -static PHP_METHOD(Phalcon_Logger_Adapter_Firephp, close){ + PHALCON_INIT_VAR(order_items); + array_init(order_items); - RETURN_TRUE; -} + 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); -#ifdef HAVE_CONFIG_H -#endif + 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); -PHALCON_INIT_CLASS(Phalcon_Logger_Formatter){ + if (Z_TYPE_P(limit_value) == IS_ARRAY) { - PHALCON_REGISTER_CLASS(Phalcon\\Logger, Formatter, logger_formatter, phalcon_logger_formatter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + PHALCON_OBS_VAR(number); + phalcon_array_fetch_quick_string(&number, limit_value, SS("number"), 807219790UL, PH_NOISY); - return SUCCESS; -} + 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); + } -static PHP_METHOD(Phalcon_Logger_Formatter, getTypeString){ + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); - static const char *lut[10] = { - "EMERGENCY", "CRITICAL", "ALERT", "ERROR", "WARNING", - "NOTICE", "INFO", "DEBUG", "CUSTOM", "SPECIAL" - }; + PHALCON_INIT_VAR(ini_range); + phalcon_add_function(ini_range, offset, one TSRMLS_CC); - zval *type; - int itype; + PHALCON_INIT_VAR(end_range); + phalcon_add_function(end_range, offset, number TSRMLS_CC); - 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_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); -#ifdef HAVE_CONFIG_H -#endif + 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); +} -PHALCON_INIT_CLASS(Phalcon_Logger_FormatterInterface){ +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, supportsSavepoints){ - PHALCON_REGISTER_INTERFACE(Phalcon\\Logger, FormatterInterface, logger_formatterinterface, phalcon_logger_formatterinterface_method_entry); - return SUCCESS; + RETURN_FALSE; } +static PHP_METHOD(Phalcon_Db_Dialect_Oracle, supportsReleaseSavepoints){ + + + RETURN_FALSE; +} @@ -145604,263 +73643,465 @@ PHALCON_INIT_CLASS(Phalcon_Logger_FormatterInterface){ -PHALCON_INIT_CLASS(Phalcon_Logger_Item){ +PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Postgresql){ - PHALCON_REGISTER_CLASS(Phalcon\\Logger, Item, logger_item, phalcon_logger_item_method_entry, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Postgresql, db_dialect_postgresql, "phalcon\\db\\dialect", phalcon_db_dialect_postgresql_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); + 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; } -static PHP_METHOD(Phalcon_Logger_Item, __construct){ +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, getColumnDefinition){ - zval *message, *type, *time = NULL; + zval *column, *size, *column_type, *column_sql = NULL; + zval *scale; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &message, &type, &time); + phalcon_fetch_params(1, 1, 0, &column); - if (!time) { - PHALCON_INIT_VAR(time); - ZVAL_LONG(time, 0); + 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_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_INIT_VAR(size); + phalcon_call_method_key(size, column, "getsize", 4292672352UL); - PHALCON_MM_RESTORE(); + 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); } -static PHP_METHOD(Phalcon_Logger_Item, getMessage){ +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addColumn){ + zval *table_name, *schema_name, *column; - RETURN_MEMBER_QUICK(this_ptr, "_message", 933579817UL); + 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_Logger_Item, getType){ +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, modifyColumn){ + zval *table_name, *schema_name, *column; - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); + 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_Logger_Item, getTime){ +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropColumn){ + zval *table_name, *schema_name, *column_name; - RETURN_MEMBER_QUICK(this_ptr, "_time", 3991380851UL); ->>>>>>> 1.2.2 + 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_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; +} +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropIndex){ -#ifdef HAVE_CONFIG_H -#endif - - - - - - -<<<<<<< HEAD - -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); -======= -PHALCON_INIT_CLASS(Phalcon_Logger_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger, Exception, logger_exception, "phalcon\\exception", NULL, 0); ->>>>>>> 1.2.2 + 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; } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Logger_Formatter_Syslog, format){ +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, addPrimaryKey){ - zval *message, *type, *timestamp; + zval *table_name, *schema_name, *index; - phalcon_fetch_params(0, 3, 0, &message, &type, ×tamp); + phalcon_fetch_params(0, 3, 0, &table_name, &schema_name, &index); - array_init_size(return_value, 2); - phalcon_array_append(&return_value, type, PH_SEPARATE); - phalcon_array_append(&return_value, message, PH_SEPARATE); + PHALCON_THROW_EXCEPTION_STRW(phalcon_db_exception_ce, "Not implemented yet"); return; } +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){ -#ifdef HAVE_CONFIG_H -#endif + 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 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_INIT_CLASS(Phalcon_Logger_Formatter_Firephp){ + phalcon_fetch_params(0, 1, 0, &definition); + + RETURN_EMPTY_ARRAY(); +} - PHALCON_REGISTER_CLASS_EX(Phalcon\\Logger\\Formatter, Firephp, logger_formatter_firephp, "phalcon\\logger\\formatter", phalcon_logger_formatter_firephp_method_entry, 0); +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, createTable){ - zend_class_implements(phalcon_logger_formatter_firephp_ce TSRMLS_CC, 1, phalcon_logger_formatterinterface_ce); + 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_Logger_Formatter_Firephp, getTypeString) { - - static const char* lut[10] = { - "ERROR", "ERROR", "WARN", "ERROR", "WARN", - "INFO", "INFO", "LOG", "INFO", "LOG" - }; +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, dropTable){ - zval *type; - int itype; + zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; + zval *sql = NULL; - 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, 2, 1, &table_name, &schema_name, &if_exists); + + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); } - - RETURN_STRING("CUSTOM", 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); + } + 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); } -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); +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, createView){ - 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 *view_name, *definition, *schema_name, *view_sql; + zval *view = NULL, *sql; - 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_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); +} - 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_Db_Dialect_Postgresql, dropView){ - 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 *view_name, *schema_name, *if_exists = NULL, *view = NULL; + zval *sql = NULL; - 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, 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); +} - PHALCON_ALLOC_ZVAL(payload); - array_init_size(payload, 2); +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, tableExists){ - PHALCON_ALLOC_ZVAL(meta); - array_init_size(meta, 2); - add_assoc_zval(meta, "type", type_str); - add_assoc_zval(meta, "backtrace", backtrace); + zval *table_name, *schema_name = NULL, *sql = NULL; - 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, 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); +} - zval_ptr_dtor(&payload); +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, viewExists){ - smart_str_alloc4(&result, Z_STRLEN_P(encoded) + 2 + 5, 0, i); + zval *view_name, *schema_name = NULL, *sql = NULL; - 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_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 PHP_METHOD(Phalcon_Db_Dialect_Postgresql, describeColumns){ + zval *table, *schema = NULL, *sql = NULL; + PHALCON_MM_GROW(); -#ifdef HAVE_CONFIG_H -#endif - + 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 { + 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"); + } + + RETURN_CTOR(sql); +} +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, listTables){ -PHALCON_INIT_CLASS(Phalcon_Logger_AdapterInterface){ + zval *schema_name = NULL, *sql = NULL; - PHALCON_REGISTER_INTERFACE(Phalcon\\Logger, AdapterInterface, logger_adapterinterface, phalcon_logger_adapterinterface_method_entry); + PHALCON_MM_GROW(); - return SUCCESS; + 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 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_CTOR(sql); } +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, listViews){ + + zval *schema_name = NULL, *sql = NULL; + PHALCON_MM_GROW(); + 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); +} +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, 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, "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); +} +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, 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); + 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); +} +static PHP_METHOD(Phalcon_Db_Dialect_Postgresql, tableOptions){ + zval *table, *schema = NULL; + PHALCON_MM_GROW(); + phalcon_fetch_params(1, 1, 1, &table, &schema); + + if (!schema) { + PHALCON_INIT_VAR(schema); + } + + RETURN_MM_EMPTY_STRING(); +} @@ -145875,451 +74116,570 @@ PHALCON_INIT_CLASS(Phalcon_Logger_AdapterInterface){ -PHALCON_INIT_CLASS(Phalcon_Flash_Direct){ +PHALCON_INIT_CLASS(Phalcon_Db_Dialect_Sqlite){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Flash, Direct, flash_direct, "phalcon\\flash", phalcon_flash_direct_method_entry, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db\\Dialect, Sqlite, db_dialect_sqlite, "phalcon\\db\\dialect", phalcon_db_dialect_sqlite_method_entry, 0); - zend_class_implements(phalcon_flash_direct_ce TSRMLS_CC, 1, phalcon_flashinterface_ce); + zend_declare_property_string(phalcon_db_dialect_sqlite_ce, SL("_escapeChar"), "\"", ZEND_ACC_PROTECTED TSRMLS_CC); + + zend_class_implements(phalcon_db_dialect_sqlite_ce TSRMLS_CC, 1, phalcon_db_dialectinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Flash_Direct, message){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, getColumnDefinition){ - zval *type, *message; + zval *column, *size, *column_type, *column_sql = NULL; + zval *scale; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &type, &message); + phalcon_fetch_params(1, 1, 0, &column); - phalcon_call_method_p2_key(return_value, this_ptr, "outputmessage", type, message, 924206491UL); - RETURN_MM(); + 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); } +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); -#ifdef HAVE_CONFIG_H -#endif - - - - - - + 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_CLASS(Phalcon_Flash_Session){ + 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 "); + } - PHALCON_REGISTER_CLASS_EX(Phalcon\\Flash, Session, flash_session, "phalcon\\flash", phalcon_flash_session_method_entry, 0); + PHALCON_INIT_VAR(name); + phalcon_call_method_key(name, column, "getname", 4286441094UL); - zend_declare_property_null(phalcon_flash_session_ce, SL("_dependencyInjector"), ZEND_ACC_PROTECTED TSRMLS_CC); + PHALCON_INIT_VAR(column_definition); + phalcon_call_method_p1_key(column_definition, this_ptr, "getcolumndefinition", column, 1668305756UL); + PHALCON_SCONCAT_SVSV(sql, "\"", name, "\" ", column_definition); - zend_class_implements(phalcon_flash_session_ce TSRMLS_CC, 2, phalcon_flashinterface_ce, phalcon_di_injectionawareinterface_ce); + 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 SUCCESS; + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Flash_Session, setDI){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, modifyColumn){ - zval *dependency_injector; + zval *table_name, *schema_name, *column; - 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, 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_Flash_Session, getDI){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropColumn){ + zval *table_name, *schema_name, *column_name; - RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); + 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_Flash_Session, _getSessionMessages){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addIndex){ - zval *remove, *dependency_injector, *service; - zval *session, *index_name, *messages; + zval *table_name, *schema_name, *index, *sql = NULL, *columns; + zval *quoted_column_list, *name; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &remove); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &index); - 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"); + 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; } - - 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(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); - } - - RETURN_CCTOR(messages); -} -static PHP_METHOD(Phalcon_Flash_Session, _setSessionMessages){ + PHALCON_INIT_VAR(name); + phalcon_call_method_key(name, index, "getname", 4286441094UL); - zval *messages, *dependency_injector, *service; - zval *session, *index_name; + 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, "\" ("); + } - PHALCON_MM_GROW(); + PHALCON_INIT_VAR(columns); + phalcon_call_method_key(columns, index, "getcolumns", 3064648998UL); - phalcon_fetch_params(1, 1, 0, &messages); - - 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, "session", 1); - - 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_call_method_p2_key(NULL, session, "set", index_name, messages, 2090720177UL); - - RETURN_CCTOR(messages); + 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_Flash_Session, message){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropIndex){ - zval *type, *message, *remove, *messages = NULL, *empty_array; + zval *table_name, *schema_name, *index_name; + zval *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &type, &message); - - 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); + 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, "\""); } - - 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); + else { + PHALCON_CONCAT_SVS(sql, "DROP INDEX \"", index_name, "\""); } - - phalcon_array_update_append_multi_2(&messages, type, message, 0); - phalcon_call_method_p1_key(NULL, this_ptr, "_setsessionmessages", messages, 2596691308UL); -======= - + RETURN_CTOR(sql); +} +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addPrimaryKey){ -#ifdef HAVE_CONFIG_H -#endif + 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; +} +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, addForeignKey){ + zval *table_name, *schema_name, *reference; -PHALCON_INIT_CLASS(Phalcon_Logger_Multiple){ + 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_REGISTER_CLASS(Phalcon\\Logger, Multiple, logger_multiple, phalcon_logger_multiple_method_entry, 0); +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropForeignKey){ - 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); + 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_Logger_Multiple, push){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, _getTableOptions){ - zval *logger; + zval *definition; - 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); - + phalcon_fetch_params(0, 1, 0, &definition); + + array_init(return_value); } -static PHP_METHOD(Phalcon_Logger_Multiple, getLoggers){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, createTable){ + zval *table_name, *schema_name, *definition; - RETURN_MEMBER_QUICK(this_ptr, "_loggers", 810888023UL); + 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_Logger_Multiple, setFormatter){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, dropTable){ - zval *formatter, *loggers, *logger = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *table_name, *schema_name, *if_exists = NULL, *table = NULL; + zval *sql = NULL; 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_fetch_params(1, 2, 1, &table_name, &schema_name, &if_exists); + if (!if_exists) { + PHALCON_INIT_VAR(if_exists); + ZVAL_BOOL(if_exists, 1); } - phalcon_update_property_this_quick(this_ptr, SL("_formatter"), formatter, 1838243768UL TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Logger_Multiple, getFormatter){ - + 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); + } - RETURN_MEMBER_QUICK(this_ptr, "_formatter", 1838243768UL); + 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_Logger_Multiple, log){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, createView){ - zval *message, *type = NULL, *loggers, *logger = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *view_name, *definition, *schema_name, *view_sql; + zval *view = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &message, &type); + phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name); - if (!type) { - PHALCON_INIT_VAR(type); - ZVAL_LONG(type, 7); + 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(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_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_GET_HVALUE(logger); + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "CREATE VIEW \"", view, "\" AS ", view_sql); - phalcon_call_method_p2_key(NULL, logger, "log", message, type, 2090479079UL); + RETURN_CTOR(sql); +} + +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, 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); - zend_hash_move_forward_ex(ah0, &hp0); - } + 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, "\""); } - PHALCON_MM_RESTORE(); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Multiple, emergence){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, tableExists){ - zval *message, *type; + zval *table_name, *schema_name = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - 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 (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } - PHALCON_MM_RESTORE(); + 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); } -static PHP_METHOD(Phalcon_Logger_Multiple, debug){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, viewExists){ - zval *message, *type; + zval *view_name, *schema_name = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - 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); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } - PHALCON_MM_RESTORE(); + 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_Logger_Multiple, error){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeColumns){ - zval *message, *type; + zval *table, *schema = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 1, &table, &schema); - 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); + if (!schema) { + PHALCON_INIT_VAR(schema); + } - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "PRAGMA table_info('", table, "')"); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Multiple, info){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, listTables){ - zval *message, *type; + zval *schema_name = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 0, 1, &schema_name); - 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 (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } - PHALCON_MM_RESTORE(); + 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_Logger_Multiple, notice){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, listViews){ - zval *message, *type; + zval *schema_name = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 0, 1, &schema_name); - 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 (!schema_name) { + PHALCON_INIT_VAR(schema_name); + } - PHALCON_MM_RESTORE(); + 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_Logger_Multiple, warning){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeIndexes){ - zval *message, *type; + zval *table, *schema = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 1, &table, &schema); - 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 (!schema) { + PHALCON_INIT_VAR(schema); + } - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "PRAGMA index_list('", table, "')"); + RETURN_CTOR(sql); } -static PHP_METHOD(Phalcon_Logger_Multiple, alert){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeIndex){ - zval *message, *type; + zval *index_name, *sql; 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); ->>>>>>> 1.2.2 + phalcon_fetch_params(1, 1, 0, &index_name); - PHALCON_MM_RESTORE(); + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVS(sql, "PRAGMA index_info('", index_name, "')"); + RETURN_CTOR(sql); } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Flash_Session, getMessages){ +static PHP_METHOD(Phalcon_Db_Dialect_Sqlite, describeReferences){ - zval *type = NULL, *remove = NULL, *messages, *return_messages; + zval *table, *schema = NULL, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &type, &remove); - - if (!type) { - PHALCON_INIT_VAR(type); - } + phalcon_fetch_params(1, 1, 1, &table, &schema); - if (!remove) { - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 1); + if (!schema) { + PHALCON_INIT_VAR(schema); } - 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_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_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); + + zend_class_implements(phalcon_db_index_ce TSRMLS_CC, 1, phalcon_db_indexinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Db_Index, __construct){ + + zval *index_name, *columns; + + phalcon_fetch_params(0, 2, 0, &index_name, &columns); - RETURN_CCTOR(messages); - } + 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_MM_EMPTY_ARRAY(); } -static PHP_METHOD(Phalcon_Flash_Session, output){ +static PHP_METHOD(Phalcon_Db_Index, getName){ - zval *remove = NULL, *messages, *message = NULL, *type = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + + RETURN_MEMBER_QUICK(this_ptr, "_indexName", 3837120573UL); +} + +static PHP_METHOD(Phalcon_Db_Index, getColumns){ + + + RETURN_MEMBER_QUICK(this_ptr, "_columns", 4004520869UL); +} + +static PHP_METHOD(Phalcon_Db_Index, __set_state){ + + zval *data, *index_name, *columns; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &remove); + phalcon_fetch_params(1, 1, 0, &data); - if (!remove) { - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 1); + 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_INIT_VAR(messages); - phalcon_call_method_p1_key(messages, this_ptr, "_getsessionmessages", remove, 1351193184UL); - if (Z_TYPE_P(messages) == IS_ARRAY) { - - phalcon_is_iterable(messages, &ah0, &hp0, 0, 0); - - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - - PHALCON_GET_HKEY(type, ah0, hp0); - PHALCON_GET_HVALUE(message); - - phalcon_call_method_p2_key(NULL, this_ptr, "outputmessage", type, message, 924206491UL); + PHALCON_OBS_VAR(index_name); + phalcon_array_fetch_quick_string(&index_name, data, SS("_indexName"), 3837120573UL, PH_NOISY); - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, data, SS("_columns"), 4004520869UL, PH_NOISY); - } + object_init_ex(return_value, phalcon_db_index_ce); + phalcon_call_method_p2_key(NULL, return_value, "__construct", index_name, columns, 1107214344UL); - PHALCON_MM_RESTORE(); + RETURN_MM(); } @@ -146334,9 +74694,9 @@ static PHP_METHOD(Phalcon_Flash_Session, output){ -PHALCON_INIT_CLASS(Phalcon_Flash_Exception){ +PHALCON_INIT_CLASS(Phalcon_Db_Exception){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Flash, Exception, flash_exception, "phalcon\\exception", NULL, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Db, Exception, db_exception, "phalcon\\exception", NULL, 0); return SUCCESS; } @@ -146350,1714 +74710,1592 @@ PHALCON_INIT_CLASS(Phalcon_Flash_Exception){ +PHALCON_INIT_CLASS(Phalcon_Db_ColumnInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Db, ColumnInterface, db_columninterface, phalcon_db_columninterface_method_entry); + + return SUCCESS; +} + -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_Assets_Manager, __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) { - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - } - - PHALCON_MM_RESTORE(); -} -static PHP_METHOD(Phalcon_Assets_Manager, setOptions){ - zval *options; - phalcon_fetch_params(0, 1, 0, &options); - - 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); - - 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; +#ifdef HAVE_CONFIG_H +#endif - phalcon_fetch_params(0, 1, 0, &implicit_output); - - phalcon_update_property_this_quick(this_ptr, SL("_implicitOutput"), implicit_output, 3405432336UL TSRMLS_CC); - RETURN_THISW(); + + + + + + +PHALCON_INIT_CLASS(Phalcon_Db_Profiler){ + + PHALCON_REGISTER_CLASS(Phalcon\\Db, Profiler, db_profiler, phalcon_db_profiler_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); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Assets_Manager, addCss){ +static PHP_METHOD(Phalcon_Db_Profiler, startProfile){ - zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type, *resource; + zval *sql_statement, *active_profile, *micro; + zval *time; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); + phalcon_fetch_params(1, 1, 0, &sql_statement); - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); - } + 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); - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); - } + PHALCON_INIT_VAR(micro); + ZVAL_BOOL(micro, 1); - if (!attributes) { - PHALCON_INIT_VAR(attributes); + 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); } - 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_update_property_this_quick(this_ptr, SL("_activeProfile"), active_profile, 794883025UL TSRMLS_CC); - phalcon_call_method_p2_key(NULL, this_ptr, "addresourcebytype", type, resource, 1257550035UL); RETURN_THIS(); } -static PHP_METHOD(Phalcon_Assets_Manager, addJs){ +static PHP_METHOD(Phalcon_Db_Profiler, stopProfile){ - zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type, *resource; + zval *micro, *final_time, *active_profile, *initial_time; + zval *diference, *total_seconds, *new_total_seconds; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 3, &path, &local, &filter, &attributes); + PHALCON_INIT_VAR(micro); + ZVAL_BOOL(micro, 1); - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); - } + PHALCON_INIT_VAR(final_time); + phalcon_call_func_p1(final_time, "microtime", micro); - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); - } + 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); - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } + PHALCON_INIT_VAR(initial_time); + phalcon_call_method_key(initial_time, active_profile, "getinitialtime", 2329302014UL); - PHALCON_INIT_VAR(type); - ZVAL_STRING(type, "js", 1); + PHALCON_INIT_VAR(diference); + sub_function(diference, final_time, initial_time TSRMLS_CC); - 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_OBS_VAR(total_seconds); + phalcon_read_property_this_quick(&total_seconds, this_ptr, SL("_totalSeconds"), 996888727UL, PH_NOISY_CC); + + 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_call_method_p2_key(NULL, this_ptr, "addresourcebytype", type, resource, 1257550035UL); RETURN_THIS(); } -static PHP_METHOD(Phalcon_Assets_Manager, addResourceByType){ +static PHP_METHOD(Phalcon_Db_Profiler, getNumberTotalStatements){ - zval *type, *resource, *collections, *collection = NULL; + zval *all_profiles; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &type, &resource); + 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); +} + +static PHP_METHOD(Phalcon_Db_Profiler, reset){ + + zval *empty_arr; + + 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(); +} + +static PHP_METHOD(Phalcon_Db_Profiler, getLastProfile){ + + + RETURN_MEMBER_QUICK(this_ptr, "_activeProfile", 794883025UL); +} + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Db_Adapter){ + + 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_fetch_params(1, 1, 0, &descriptor); - 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); + 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_INIT_VAR(dialect_class); + PHALCON_CONCAT_SV(dialect_class, "phalcon\\db\\dialect\\", dialect_type); } 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_OBS_NVAR(dialect_class); + phalcon_array_fetch_quick_string(&dialect_class, descriptor, SS("dialectClass"), 2526466321UL, PH_NOISY); } - phalcon_call_method_p1_key(NULL, collection, "add", resource, 2090071694UL); + 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); + } - RETURN_THIS(); + phalcon_update_property_this_quick(this_ptr, SL("_descriptor"), descriptor, 691635363UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Assets_Manager, addResource){ - - zval *resource, *type; +static PHP_METHOD(Phalcon_Db_Adapter, setEventsManager){ - PHALCON_MM_GROW(); + zval *events_manager; - 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_fetch_params(0, 1, 0, &events_manager); - phalcon_call_method_p2_key(NULL, this_ptr, "addresourcebytype", type, resource, 1257550035UL); + phalcon_update_property_this_quick(this_ptr, SL("_eventsManager"), events_manager, 799100116UL TSRMLS_CC); - RETURN_THIS(); } -static PHP_METHOD(Phalcon_Assets_Manager, set){ +static PHP_METHOD(Phalcon_Db_Adapter, getEventsManager){ - 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, "_eventsManager", 799100116UL); } -static PHP_METHOD(Phalcon_Assets_Manager, get){ - - zval *id, *collections, *collection; +static PHP_METHOD(Phalcon_Db_Adapter, setDialect){ - PHALCON_MM_GROW(); + zval *dialect; - 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_fetch_params(0, 1, 0, &dialect); - PHALCON_OBS_VAR(collection); - phalcon_array_fetch(&collection, collections, id, PH_NOISY); + phalcon_update_property_this_quick(this_ptr, SL("_dialect"), dialect, 4072955610UL TSRMLS_CC); - RETURN_CCTOR(collection); } -static PHP_METHOD(Phalcon_Assets_Manager, getCss){ - - zval *collections, *collection; +static PHP_METHOD(Phalcon_Db_Adapter, getDialect){ - PHALCON_MM_GROW(); - 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); + RETURN_MEMBER_QUICK(this_ptr, "_dialect", 4072955610UL); } -static PHP_METHOD(Phalcon_Assets_Manager, getJs){ +static PHP_METHOD(Phalcon_Db_Adapter, fetchOne){ - zval *collections, *collection; + zval *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL; + zval *result; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(collections); - phalcon_read_property_this_quick(&collections, this_ptr, SL("_collections"), 2357471267UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 3, &sql_query, &fetch_mode, &bind_params, &bind_types); - if (!phalcon_array_isset_quick_string(collections, SS("js"), 193496226UL)) { - object_init_ex(return_value, phalcon_assets_collection_ce); - RETURN_MM(); + if (!fetch_mode) { + PHALCON_INIT_VAR(fetch_mode); + ZVAL_LONG(fetch_mode, 2); } - PHALCON_OBS_VAR(collection); - phalcon_array_fetch_quick_string(&collection, collections, SS("js"), 193496226UL, PH_NOISY); + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); + } - RETURN_CCTOR(collection); -} - -static PHP_METHOD(Phalcon_Assets_Manager, collection){ - - zval *name, *collections, *collection = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } - 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(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_CCTOR(collection); + RETURN_MM_EMPTY_ARRAY(); } -static PHP_METHOD(Phalcon_Assets_Manager, output){ +static PHP_METHOD(Phalcon_Db_Adapter, fetchAll){ - 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 *sql_query, *fetch_mode = NULL, *bind_params = NULL, *bind_types = NULL; + zval *results, *result, *row = NULL; + zval *r0 = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 0, &collection, &callback); - - PHALCON_INIT_VAR(output); - - 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(resources); - phalcon_call_method_key(resources, collection, "getresources", 2001784992UL); - - PHALCON_INIT_VAR(filters); - phalcon_call_method_key(filters, collection, "getfilters", 2910616766UL); - - PHALCON_INIT_VAR(prefix); - phalcon_call_method_key(prefix, collection, "getprefix", 2543805107UL); + phalcon_fetch_params(1, 1, 3, &sql_query, &fetch_mode, &bind_params, &bind_types); - if (Z_TYPE_P(filters) == IS_ARRAY) { + if (!fetch_mode) { + PHALCON_INIT_VAR(fetch_mode); + ZVAL_LONG(fetch_mode, 2); + } - PHALCON_INIT_VAR(source_base_path); + if (!bind_params) { + PHALCON_INIT_VAR(bind_params); + } - PHALCON_INIT_VAR(target_base_path); + if (!bind_types) { + PHALCON_INIT_VAR(bind_types); + } - PHALCON_OBS_VAR(options); - phalcon_read_property_this_quick(&options, this_ptr, SL("_options"), 1620153008UL, PH_NOISY_CC); + PHALCON_INIT_VAR(results); + array_init(results); - if (Z_TYPE_P(options) == IS_ARRAY) { + 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); + } - 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); - } + while (1) { - 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_NVAR(r0); + phalcon_call_method_key(r0, result, "fetch", 4247924303UL); + PHALCON_CPY_WRT(row, r0); + if (zend_is_true(row)) { + } else { + break; } - } - - 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_array_append(&results, row, PH_SEPARATE); } + } - 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); - } + 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); - PHALCON_INIT_VAR(filtered_joined_content); + if (!fields) { + PHALCON_INIT_VAR(fields); + } - PHALCON_INIT_VAR(join); - phalcon_call_method_key(join, collection, "getjoin", 4282196469UL); + if (!data_types) { + PHALCON_INIT_VAR(data_types); + } - if (zend_is_true(join)) { + 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 (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; - } + 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_INIT_VAR(is_directory); - phalcon_call_func_p1(is_directory, "is_dir", complete_target_path); + PHALCON_INIT_VAR(placeholders); + array_init(placeholders); - 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; - } - } + 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_is_iterable(resources, &ah0, &hp0, 0, 0); + phalcon_is_iterable(values, &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_GET_HKEY(position, ah0, hp0); + PHALCON_GET_HVALUE(value); - 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); + 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; } - } 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_NVAR(target_path); - phalcon_call_method_p1_key(target_path, resource, "getrealtargetpath", complete_target_path, 3402259517UL); - - if (PHALCON_IS_EMPTY(target_path)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", source_path, "' does not have a valid target path"); - PHALCON_THROW_EXCEPTION_ZVAL(phalcon_assets_exception_ce, exception_message); - return; - } - - if (zend_is_true(local)) { - if (PHALCON_IS_EQUAL(target_path, source_path)) { - PHALCON_INIT_NVAR(exception_message); - PHALCON_CONCAT_SVS(exception_message, "Resource '", 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_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 (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); + } - zend_hash_move_forward_ex(ah0, &hp0); - continue; - } + 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(filter_needed)) { + 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_NVAR(content); - phalcon_call_method_p1_key(content, resource, "getcontent", complete_source_path, 3141446400UL); + PHALCON_INIT_VAR(escaped_fields); + array_init(escaped_fields); - PHALCON_INIT_NVAR(must_filter); - phalcon_call_method_key(must_filter, resource, "getfilter", 2170608779UL); + phalcon_is_iterable(fields, &ah1, &hp1, 0, 0); - if (zend_is_true(must_filter)) { + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { - phalcon_is_iterable(filters, &ah1, &hp1, 0, 0); + PHALCON_GET_HVALUE(field); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + 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_GET_HVALUE(filter); + zend_hash_move_forward_ex(ah1, &hp1); + } - if (Z_TYPE_P(filter) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STR(phalcon_assets_exception_ce, "Filter is invalid"); - return; - } + } else { + PHALCON_CPY_WRT(escaped_fields, fields); + } - PHALCON_INIT_NVAR(filtered_content); - phalcon_call_method_p1_key(filtered_content, filter, "filter", content, 2890214155UL); + PHALCON_INIT_VAR(joined_fields); + phalcon_fast_join_str(joined_fields, SL(", "), escaped_fields TSRMLS_CC); - 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, ";"); - } - } + 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, ")"); + } - zend_hash_move_forward_ex(ah1, &hp1); - } + phalcon_call_method_p3_key(return_value, this_ptr, "execute", insert_sql, insert_values, bind_data_types, 3117639032UL); + RETURN_MM(); +} + +static PHP_METHOD(Phalcon_Db_Adapter, update){ + + 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, 3, 2, &table, &fields, &values, &where_condition, &data_types); - } 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 (!where_condition) { + PHALCON_INIT_VAR(where_condition); + } - if (!zend_is_true(join)) { - phalcon_file_put_contents(NULL, target_path, filtered_content TSRMLS_CC); - } - } + if (!data_types) { + PHALCON_INIT_VAR(data_types); + } - if (!zend_is_true(join)) { + PHALCON_INIT_VAR(placeholders); + array_init(placeholders); - 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_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_NVAR(attributes); - phalcon_call_method_key(attributes, resource, "getattributes", 1013165772UL); + phalcon_is_iterable(values, &ah0, &hp0, 0, 0); - PHALCON_INIT_NVAR(local); - ZVAL_BOOL(local, 1); + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (Z_TYPE_P(attributes) == IS_ARRAY) { - phalcon_array_update_long(&attributes, 0, &prefixed_path, PH_COPY | PH_SEPARATE); + PHALCON_GET_HKEY(position, ah0, hp0); + PHALCON_GET_HVALUE(value); - 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); - } + 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_INIT_NVAR(html); - PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters); + 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 (zend_is_true(use_implicit_output)) { - zend_print_zval(html, 0); + 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_concat_self(&output, html TSRMLS_CC); + 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_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 (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); - } + 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_NVAR(attributes); - phalcon_call_method_key(attributes, collection, "getattributes", 1013165772UL); + 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_NVAR(local); - ZVAL_BOOL(local, 1); + PHALCON_INIT_VAR(update_sql); + PHALCON_CONCAT_SVSVS(update_sql, "UPDATE ", escaped_table, " SET ", set_clause, " WHERE "); - if (Z_TYPE_P(attributes) == IS_ARRAY) { - phalcon_array_update_long(&attributes, 0, &prefixed_path, PH_COPY | PH_SEPARATE); + 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(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); + 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); } - PHALCON_INIT_NVAR(html); - PHALCON_CALL_USER_FUNC_ARRAY(html, callback, parameters); + 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 (zend_is_true(use_implicit_output)) { - zend_print_zval(html, 0); - } else { - phalcon_concat_self(&output, html TSRMLS_CC); + 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(output); + phalcon_call_method_p3_key(return_value, this_ptr, "execute", update_sql, update_values, bind_data_types, 3117639032UL); + RETURN_MM(); } -static PHP_METHOD(Phalcon_Assets_Manager, outputCss){ +static PHP_METHOD(Phalcon_Db_Adapter, delete){ - zval *collection_name = NULL, *collection = NULL, *callback; - zval *output; + zval *table, *where_condition = NULL, *placeholders = NULL; + zval *data_types = NULL, *escaped_table = NULL, *sql = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &collection_name); + phalcon_fetch_params(1, 1, 3, &table, &where_condition, &placeholders, &data_types); - if (!collection_name) { - PHALCON_INIT_VAR(collection_name); + if (!where_condition) { + PHALCON_INIT_VAR(where_condition); } - if (PHALCON_IS_EMPTY(collection_name)) { - PHALCON_INIT_VAR(collection); - phalcon_call_method_key(collection, this_ptr, "getcss", 4034032270UL); - } else { - PHALCON_INIT_NVAR(collection); - phalcon_call_method_p1_key(collection, this_ptr, "get", collection_name, 2090288933UL); + if (!placeholders) { + PHALCON_INIT_VAR(placeholders); } - 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_Assets_Manager, outputJs){ - - zval *collection_name = NULL, *collection = NULL, *callback; - zval *output; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &collection_name); - - if (!collection_name) { - PHALCON_INIT_VAR(collection_name); + if (!data_types) { + PHALCON_INIT_VAR(data_types); } - if (PHALCON_IS_EMPTY(collection_name)) { - PHALCON_INIT_VAR(collection); - phalcon_call_method_key(collection, this_ptr, "getjs", 4287067682UL); + 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_INIT_NVAR(collection); - phalcon_call_method_p1_key(collection, this_ptr, "get", collection_name, 2090288933UL); + 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_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(output); - phalcon_call_method_p2_key(output, this_ptr, "output", collection, callback, 2107509814UL); - - RETURN_CCTOR(output); + 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_Assets_Resource){ +static PHP_METHOD(Phalcon_Db_Adapter, limit){ - PHALCON_REGISTER_CLASS(Phalcon\\Assets, Resource, assets_resource, phalcon_assets_resource_method_entry, 0); + zval *sql_query, *number, *dialect; - 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); + 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_Assets_Resource, __construct){ +static PHP_METHOD(Phalcon_Db_Adapter, tableExists){ - zval *type, *path, *local = NULL, *filter = NULL, *attributes = NULL; + zval *table_name, *schema_name = NULL, *dialect, *sql; + zval *fetch_num, *num, *first; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 3, &type, &path, &local, &filter, &attributes); + phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - if (!local) { - PHALCON_INIT_VAR(local); - ZVAL_BOOL(local, 1); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); - } + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } + PHALCON_INIT_VAR(sql); + phalcon_call_method_p2_key(sql, dialect, "tableexists", table_name, schema_name, 1944065613UL); - 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(fetch_num); + ZVAL_LONG(fetch_num, 3); - PHALCON_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Assets_Resource, setType){ - - zval *type; - - phalcon_fetch_params(0, 1, 0, &type); + 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("_type"), type, 3991959110UL TSRMLS_CC); - RETURN_THISW(); + PHALCON_OBS_VAR(first); + phalcon_array_fetch_long(&first, num, 0, PH_NOISY); + RETURN_CCTOR(first); } -static PHP_METHOD(Phalcon_Assets_Resource, getType){ - - - RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); -} +static PHP_METHOD(Phalcon_Db_Adapter, viewExists){ -static PHP_METHOD(Phalcon_Assets_Resource, setPath){ + zval *view_name, *schema_name = NULL, *dialect, *sql, *fetch_num; + zval *num, *first; - zval *path; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &path); + phalcon_fetch_params(1, 1, 1, &view_name, &schema_name); - phalcon_update_property_this_quick(this_ptr, SL("_path"), path, 3986357393UL TSRMLS_CC); - RETURN_THISW(); + 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_Assets_Resource, getPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_path", 3986357393UL); -} +static PHP_METHOD(Phalcon_Db_Adapter, forUpdate){ -static PHP_METHOD(Phalcon_Assets_Resource, setLocal){ + zval *sql_query, *dialect; - zval *local; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &local); + phalcon_fetch_params(1, 1, 0, &sql_query); - phalcon_update_property_this_quick(this_ptr, SL("_local"), local, 2560221423UL TSRMLS_CC); - RETURN_THISW(); + 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_Assets_Resource, getLocal){ - - - RETURN_MEMBER_QUICK(this_ptr, "_local", 2560221423UL); -} +static PHP_METHOD(Phalcon_Db_Adapter, sharedLock){ -static PHP_METHOD(Phalcon_Assets_Resource, setFilter){ + zval *sql_query, *dialect; - zval *filter; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &filter); + phalcon_fetch_params(1, 1, 0, &sql_query); - phalcon_update_property_this_quick(this_ptr, SL("_filter"), filter, 3500594986UL TSRMLS_CC); - RETURN_THISW(); + 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_Assets_Resource, getFilter){ - - - RETURN_MEMBER_QUICK(this_ptr, "_filter", 3500594986UL); -} +static PHP_METHOD(Phalcon_Db_Adapter, createTable){ -static PHP_METHOD(Phalcon_Assets_Resource, setAttributes){ + zval *table_name, *schema_name, *definition; + zval *exception_message, *columns, *dialect; + zval *sql; - zval *attributes; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &attributes); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &definition); - phalcon_update_property_this_quick(this_ptr, SL("_attributes"), attributes, 1565778155UL TSRMLS_CC); - RETURN_THISW(); + 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_Assets_Resource, getAttributes){ - - - RETURN_MEMBER_QUICK(this_ptr, "_attributes", 1565778155UL); -} +static PHP_METHOD(Phalcon_Db_Adapter, dropTable){ -static PHP_METHOD(Phalcon_Assets_Resource, setTargetUri){ + zval *table_name, *schema_name = NULL, *if_exists = NULL, *dialect; + zval *sql; - zval *target_uri; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &target_uri); + phalcon_fetch_params(1, 1, 2, &table_name, &schema_name, &if_exists); - phalcon_update_property_this_quick(this_ptr, SL("_targetUri"), target_uri, 2193460699UL TSRMLS_CC); - RETURN_THISW(); + 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_Assets_Resource, getTargetUri){ - - - RETURN_MEMBER_QUICK(this_ptr, "_targetUri", 2193460699UL); -} +static PHP_METHOD(Phalcon_Db_Adapter, createView){ -static PHP_METHOD(Phalcon_Assets_Resource, setSourcePath){ + zval *view_name, *definition, *schema_name = NULL, *exception_message; + zval *dialect, *sql; - zval *source_path; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &source_path); + phalcon_fetch_params(1, 2, 1, &view_name, &definition, &schema_name); - phalcon_update_property_this_quick(this_ptr, SL("_sourcePath"), source_path, 1419415746UL TSRMLS_CC); - RETURN_THISW(); + 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_Assets_Resource, getSourcePath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_targetPath", 3658201208UL); -======= - - - - -#ifdef HAVE_CONFIG_H -#endif - - - +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(); +} -PHALCON_INIT_CLASS(Phalcon_Logger_Adapter){ +static PHP_METHOD(Phalcon_Db_Adapter, addColumn){ - PHALCON_REGISTER_CLASS(Phalcon\\Logger, Adapter, logger_adapter, phalcon_logger_adapter_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + zval *table_name, *schema_name, *column, *dialect; + zval *sql; - 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_MM_GROW(); - return SUCCESS; + 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_Logger_Adapter, setLogLevel){ +static PHP_METHOD(Phalcon_Db_Adapter, modifyColumn){ - zval *level; + zval *table_name, *schema_name, *column, *dialect; + zval *sql; - phalcon_fetch_params(0, 1, 0, &level); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column); - if (Z_TYPE_P(level) != IS_LONG) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_logger_exception_ce, "The log level is not valid"); - return; - } - phalcon_update_property_this_quick(this_ptr, SL("_logLevel"), level, 4227944734UL TSRMLS_CC); + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - RETURN_THISW(); + 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_Logger_Adapter, getLogLevel){ - - - RETURN_MEMBER_QUICK(this_ptr, "_logLevel", 4227944734UL); -} +static PHP_METHOD(Phalcon_Db_Adapter, dropColumn){ -static PHP_METHOD(Phalcon_Logger_Adapter, setFormatter){ + zval *table_name, *schema_name, *column_name; + zval *dialect, *sql; - zval *formatter; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &formatter); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &column_name); - 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); + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - RETURN_THISW(); + 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_Logger_Adapter, begin){ +static PHP_METHOD(Phalcon_Db_Adapter, addIndex){ + zval *table_name, *schema_name, *index, *dialect; + zval *sql; - phalcon_update_property_bool(this_ptr, SL("_transaction"), 1 TSRMLS_CC); - RETURN_THISW(); + 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_Logger_Adapter, commit){ +static PHP_METHOD(Phalcon_Db_Adapter, dropIndex){ - zval *transaction, *queue, *message = NULL, *message_str = NULL; - zval *type = NULL, *time = NULL; - HashTable *ah0; - HashPosition hp0; - zval **hd; + zval *table_name, *schema_name, *index_name; + zval *dialect, *sql; 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_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); - } + 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); - RETURN_THIS(); + 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_Logger_Adapter, rollback){ +static PHP_METHOD(Phalcon_Db_Adapter, addPrimaryKey){ - zval *transaction, *queue; + zval *table_name, *schema_name, *index, *dialect; + zval *sql; 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_fetch_params(1, 3, 0, &table_name, &schema_name, &index); - PHALCON_INIT_VAR(queue); - array_init(queue); - phalcon_update_property_this_quick(this_ptr, SL("_queue"), queue, 2763107337UL TSRMLS_CC); + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - RETURN_THIS(); + 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_Logger_Adapter, emergence){ +static PHP_METHOD(Phalcon_Db_Adapter, dropPrimaryKey){ - zval *message, *type; + zval *table_name, *schema_name, *dialect, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 2, 0, &table_name, &schema_name); - 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(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_Logger_Adapter, debug){ +static PHP_METHOD(Phalcon_Db_Adapter, addForeignKey){ - zval *message, *type; + zval *table_name, *schema_name, *reference, *dialect; + zval *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference); - 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(); + 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(); } -static PHP_METHOD(Phalcon_Logger_Adapter, error){ +static PHP_METHOD(Phalcon_Db_Adapter, dropForeignKey){ - zval *message, *type; + zval *table_name, *schema_name, *reference_name; + zval *dialect, *sql; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 3, 0, &table_name, &schema_name, &reference_name); - 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(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(); } -static PHP_METHOD(Phalcon_Logger_Adapter, info){ +static PHP_METHOD(Phalcon_Db_Adapter, getColumnDefinition){ - zval *message, *type; + zval *column, *dialect; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 0, &column); - 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(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_Logger_Adapter, notice){ +static PHP_METHOD(Phalcon_Db_Adapter, listTables){ - zval *message, *type; + 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, 1, 0, &message); + phalcon_fetch_params(1, 0, 1, &schema_name); - 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(); + 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_Logger_Adapter, warning){ +static PHP_METHOD(Phalcon_Db_Adapter, listViews){ - zval *message, *type; + 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, 1, 0, &message); + phalcon_fetch_params(1, 0, 1, &schema_name); - 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(); + 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_Logger_Adapter, alert){ +static PHP_METHOD(Phalcon_Db_Adapter, describeIndexes){ - zval *message, *type; + 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_MM_GROW(); - phalcon_fetch_params(1, 1, 0, &message); + phalcon_fetch_params(1, 1, 1, &table, &schema); - 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(); + 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_Logger_Adapter, log){ +static PHP_METHOD(Phalcon_Db_Adapter, describeReferences){ - zval *message, *type = NULL, *timestamp, *transaction; - zval *queue_item, *log_level; + 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_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &message, &type); + phalcon_fetch_params(1, 1, 1, &table, &schema); - if (!type) { - PHALCON_INIT_VAR(type); - ZVAL_LONG(type, 7); + if (!schema) { + PHALCON_INIT_VAR(schema); } - PHALCON_INIT_VAR(timestamp); - ZVAL_LONG(timestamp, (long) time(NULL)); + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - 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_INIT_VAR(fetch_num); + ZVAL_LONG(fetch_num, 3); - phalcon_update_property_array_append(this_ptr, SL("_queue"), queue_item TSRMLS_CC); - RETURN_THIS(); + 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_OBS_VAR(log_level); - phalcon_read_property_this_quick(&log_level, this_ptr, SL("_logLevel"), 4227944734UL, PH_NOISY_CC); + 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); - if (PHALCON_GE(log_level, type)) { - phalcon_call_method_p3_key(NULL, this_ptr, "loginternal", message, type, timestamp, 2472438692UL); + phalcon_array_update_zval(&reference_objects, name, &reference, PH_COPY | PH_SEPARATE); + + zend_hash_move_forward_ex(ah1, &hp1); } - RETURN_THIS(); -} - - - - - -#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; + RETURN_CTOR(reference_objects); } -static PHP_METHOD(Phalcon_Logger_Formatter_Line, __construct){ +static PHP_METHOD(Phalcon_Db_Adapter, tableOptions){ - zval *format = NULL, *date_format = NULL; + zval *table_name, *schema_name = NULL, *dialect, *sql; + zval *fetch_assoc, *describe, *first; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &format, &date_format); + phalcon_fetch_params(1, 1, 1, &table_name, &schema_name); - if (!format) { - PHALCON_INIT_VAR(format); + if (!schema_name) { + PHALCON_INIT_VAR(schema_name); } - if (!date_format) { - PHALCON_INIT_VAR(date_format); - } + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - 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_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_MM_RESTORE(); -} - -static PHP_METHOD(Phalcon_Logger_Formatter_Line, setFormat){ - - zval *format; - - phalcon_fetch_params(0, 1, 0, &format); + PHALCON_INIT_VAR(describe); + phalcon_call_method_p2_key(describe, this_ptr, "fetchall", sql, fetch_assoc, 1636682248UL); - phalcon_update_property_this_quick(this_ptr, SL("_format"), format, 3742267021UL TSRMLS_CC); + PHALCON_OBS_VAR(first); + phalcon_array_fetch_long(&first, describe, 0, PH_NOISY); + RETURN_CCTOR(first); + } + RETURN_MM_EMPTY_ARRAY(); } -static PHP_METHOD(Phalcon_Logger_Formatter_Line, getFormat){ - - - RETURN_MEMBER_QUICK(this_ptr, "_format", 3742267021UL); -} +static PHP_METHOD(Phalcon_Db_Adapter, createSavepoint){ -static PHP_METHOD(Phalcon_Logger_Formatter_Line, setDateFormat){ + zval *name, *dialect, *supports_sp, *sql; - zval *date; + PHALCON_MM_GROW(); - phalcon_fetch_params(0, 1, 0, &date); + phalcon_fetch_params(1, 1, 0, &name); - phalcon_update_property_this_quick(this_ptr, SL("_dateFormat"), date, 959184011UL TSRMLS_CC); + 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_Logger_Formatter_Line, getDateFormat){ - - - RETURN_MEMBER_QUICK(this_ptr, "_dateFormat", 959184011UL); -} - -static PHP_METHOD(Phalcon_Logger_Formatter_Line, format){ +static PHP_METHOD(Phalcon_Db_Adapter, releaseSavepoint){ - zval *message, *type, *timestamp, *format = NULL, *date_format; - zval *date, *date_wildcard, *new_format = NULL, *type_string; - zval *type_wildcard, *message_wildcard, *eol; + zval *name, *dialect, *supports_sp, *supports_rsp; + zval *sql; 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_fetch_params(1, 1, 0, &name); - PHALCON_INIT_VAR(date_wildcard); - ZVAL_STRING(date_wildcard, "%date%", 1); + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - PHALCON_INIT_VAR(new_format); - phalcon_fast_str_replace(new_format, date_wildcard, date, format); - } else { - PHALCON_CPY_WRT(new_format, format); + 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; } - 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(supports_rsp); + phalcon_call_method_key(supports_rsp, dialect, "supportsreleasesavepoints", 141567298UL); + if (!zend_is_true(supports_rsp)) { + RETURN_MM_FALSE; } - 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); - + 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_Db_Adapter, rollbackSavepoint){ - - - -#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; -} - -static PHP_METHOD(Phalcon_Logger_Formatter_Json, format){ - - zval *message, *type, *timestamp, *type_str, *log; + zval *name, *dialect, *supports_sp, *sql; 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_fetch_params(1, 1, 0, &name); - 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(); -} - - - - - -#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; -} - -static PHP_METHOD(Phalcon_Logger_Formatter_Syslog, format){ - - zval *message, *type, *timestamp; - - phalcon_fetch_params(0, 3, 0, &message, &type, ×tamp); + PHALCON_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - array_init_size(return_value, 2); - phalcon_array_append(&return_value, type, PH_SEPARATE); - phalcon_array_append(&return_value, message, PH_SEPARATE); - return; -} - - - - - -#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; -} - -static PHP_METHOD(Phalcon_Logger_Formatter_Firephp, getTypeString) { - - static const char* lut[10] = { - "ERROR", "ERROR", "WARN", "ERROR", "WARN", - "INFO", "INFO", "LOG", "INFO", "LOG" - }; - - 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); -} - -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_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_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); -} - - - - -#ifdef HAVE_CONFIG_H -#endif - - - -PHALCON_INIT_CLASS(Phalcon_Logger_AdapterInterface){ - - PHALCON_REGISTER_INTERFACE(Phalcon\\Logger, AdapterInterface, logger_adapterinterface, phalcon_logger_adapterinterface_method_entry); - - return SUCCESS; ->>>>>>> 1.2.2 -} - -static PHP_METHOD(Phalcon_Assets_Resource, setTargetPath){ - -<<<<<<< HEAD - 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_Resource, getTargetPath){ - - - RETURN_MEMBER_QUICK(this_ptr, "_sourcePath", 1419415746UL); + 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_Assets_Resource, getContent){ +static PHP_METHOD(Phalcon_Db_Adapter, setNestedTransactionsWithSavepoints){ - zval *base_path = NULL, *source_path = NULL, *complete_path; - zval *local, *exception_message = NULL, *content; + zval *nested_transactions_with_savepoints; + zval *transaction_level, *dialect, *supports_sp; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &base_path); - - if (!base_path) { - PHALCON_INIT_VAR(base_path); - } + phalcon_fetch_params(1, 1, 0, &nested_transactions_with_savepoints); - 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_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_INIT_VAR(complete_path); - PHALCON_CONCAT_VV(complete_path, base_path, source_path); - - 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_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_OBS_VAR(dialect); + phalcon_read_property_this_quick(&dialect, this_ptr, SL("_dialect"), 4072955610UL, PH_NOISY_CC); - 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); + 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; } - RETURN_CCTOR(content); + phalcon_update_property_this_quick(this_ptr, SL("_transactionsWithSavepoints"), nested_transactions_with_savepoints, 2137960997UL TSRMLS_CC); + + RETURN_THIS(); } -static PHP_METHOD(Phalcon_Assets_Resource, getRealTargetUri){ - - zval *target_uri = NULL; +static PHP_METHOD(Phalcon_Db_Adapter, isNestedTransactionsWithSavepoints){ - 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); - } - - RETURN_CCTOR(target_uri); + RETURN_MEMBER_QUICK(this_ptr, "_transactionsWithSavepoints", 2137960997UL); } -static PHP_METHOD(Phalcon_Assets_Resource, getRealSourcePath){ +static PHP_METHOD(Phalcon_Db_Adapter, getNestedTransactionSavepointName){ - zval *base_path = NULL, *source_path = NULL, *local, *complete_path; + zval *transaction_level; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &base_path); - - if (!base_path) { - PHALCON_INIT_VAR(base_path); - } - - 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_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_call_func_p1(return_value, "realpath", complete_path); - RETURN_MM(); - } - - RETURN_CCTOR(source_path); + 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(); } -static PHP_METHOD(Phalcon_Assets_Resource, getRealTargetPath){ +static PHP_METHOD(Phalcon_Db_Adapter, getDefaultIdValue){ - zval *base_path = NULL, *target_path = NULL, *local, *complete_path; + zval *null_value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 1, &base_path); - - if (!base_path) { - PHALCON_INIT_VAR(base_path); - } - - 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(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); - } + 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_CCTOR(target_path); + 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; +} +static PHP_METHOD(Phalcon_Db_Adapter, getDescriptor){ + RETURN_MEMBER_QUICK(this_ptr, "_descriptor", 691635363UL); +} +static PHP_METHOD(Phalcon_Db_Adapter, getConnectionId){ -PHALCON_INIT_CLASS(Phalcon_Assets_Collection){ + RETURN_MEMBER_QUICK(this_ptr, "_connectionId", 802624385UL); +} - PHALCON_REGISTER_CLASS(Phalcon\\Assets, Collection, assets_collection, phalcon_assets_collection_method_entry, 0); +static PHP_METHOD(Phalcon_Db_Adapter, getSQLStatement){ - 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_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); +} +static PHP_METHOD(Phalcon_Db_Adapter, getRealSQLStatement){ + + + RETURN_MEMBER_QUICK(this_ptr, "_sqlStatement", 18972457UL); +} +static PHP_METHOD(Phalcon_Db_Adapter, getSQLVariables){ + RETURN_MEMBER_QUICK(this_ptr, "_sqlVariables", 3213579853UL); +} +static PHP_METHOD(Phalcon_Db_Adapter, getSQLBindTypes){ + RETURN_MEMBER_QUICK(this_ptr, "_sqlBindTypes", 3288357222UL); +} +static PHP_METHOD(Phalcon_Db_Adapter, getType){ + RETURN_MEMBER_QUICK(this_ptr, "_type", 3991959110UL); +} +static PHP_METHOD(Phalcon_Db_Adapter, getDialectType){ + RETURN_MEMBER_QUICK(this_ptr, "_dialectType", 1868597628UL); +} @@ -148072,989 +76310,840 @@ PHALCON_INIT_CLASS(Phalcon_Assets_Collection){ -PHALCON_INIT_CLASS(Phalcon_Flash_Direct){ +PHALCON_INIT_CLASS(Phalcon_Db_Dialect){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Flash, Direct, flash_direct, "phalcon\\flash", phalcon_flash_direct_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Db, Dialect, db_dialect, phalcon_db_dialect_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); - zend_class_implements(phalcon_flash_direct_ce TSRMLS_CC, 1, phalcon_flashinterface_ce); ->>>>>>> 1.2.2 + zend_declare_property_null(phalcon_db_dialect_ce, SL("_escapeChar"), ZEND_ACC_PROTECTED TSRMLS_CC); return SUCCESS; } -<<<<<<< HEAD -static PHP_METHOD(Phalcon_Assets_Collection, add){ +static PHP_METHOD(Phalcon_Db_Dialect, limit){ - zval *resource; + zval *sql_query, *number, *limit; - phalcon_fetch_params(0, 1, 0, &resource); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 2, 0, &sql_query, &number); - if (Z_TYPE_P(resource) != IS_OBJECT) { - PHALCON_THROW_EXCEPTION_STRW(phalcon_assets_exception_ce, "Resource must be an object"); + 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); + } + } + if (Z_TYPE_P(expression) != IS_ARRAY) { + PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "Invalid SQL expression"); return; } - phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC); - RETURN_THISW(); + 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(); + } + + 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(); + } + } + + 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(); + } + } + + 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); + } + + 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_Assets_Collection, addCss){ +static PHP_METHOD(Phalcon_Db_Dialect, getSqlTable){ - zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *collection_local = NULL; - zval *collection_attributes = NULL, *resource; + 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, 3, &path, &local, &filter, &attributes); + phalcon_fetch_params(1, 1, 1, &table, &escape_char); - if (!local) { - PHALCON_INIT_VAR(local); + if (!escape_char) { + PHALCON_INIT_VAR(escape_char); + } else { + PHALCON_SEPARATE_PARAM(escape_char); } - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); + 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); + } + } else { + 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, " 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); + } + + 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 (!attributes) { - PHALCON_INIT_VAR(attributes); + 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 (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); + 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_OBS_NVAR(collection_attributes); - phalcon_read_property_this_quick(&collection_attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); + PHALCON_INIT_NVAR(escape_char); } - 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_OBS_VAR(columns); + phalcon_array_fetch_quick_string(&columns, definition, SS("columns"), 1041822630UL, PH_NOISY); + if (Z_TYPE_P(columns) == IS_ARRAY) { - phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC); + PHALCON_INIT_VAR(selected_columns); + array_init(selected_columns); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Assets_Collection, addJs){ - - 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_is_iterable(columns, &ah0, &hp0, 0, 0); - if (!local) { - PHALCON_INIT_VAR(local); - } + while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { - if (!filter) { - PHALCON_INIT_VAR(filter); - ZVAL_BOOL(filter, 1); - } + PHALCON_GET_HVALUE(column); - if (!attributes) { - PHALCON_INIT_VAR(attributes); - } + 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 (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); + 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_OBS_NVAR(collection_attributes); - phalcon_read_property_this_quick(&collection_attributes, this_ptr, SL("_attributes"), 1565778155UL, PH_NOISY_CC); + PHALCON_CPY_WRT(columns_sql, columns); } - 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_OBS_VAR(tables); + phalcon_array_fetch_quick_string(&tables, definition, SS("tables"), 3465666720UL, PH_NOISY); + if (Z_TYPE_P(tables) == IS_ARRAY) { - phalcon_update_property_array_append(this_ptr, SL("_resources"), resource TSRMLS_CC); + PHALCON_INIT_VAR(selected_tables); + array_init(selected_tables); - RETURN_THIS(); -} - -static PHP_METHOD(Phalcon_Assets_Collection, getResources){ - - zval *resources; - - 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_is_iterable(tables, &ah1, &hp1, 0, 0); - RETURN_CCTOR(resources); -} - -static PHP_METHOD(Phalcon_Assets_Collection, count){ - - zval *resources; - - 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); + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { -} - -static PHP_METHOD(Phalcon_Assets_Collection, current){ - - zval *position, *resources, *resource; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); + PHALCON_GET_HVALUE(table); - 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); + 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); } - 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); + PHALCON_INIT_VAR(sql); + PHALCON_CONCAT_SVSV(sql, "SELECT ", columns_sql, " FROM ", tables_sql); -} - -static PHP_METHOD(Phalcon_Assets_Collection, valid){ - - zval *position, *resources; - - PHALCON_MM_GROW(); - - PHALCON_OBS_VAR(position); - phalcon_read_property_this_quick(&position, this_ptr, SL("_position"), 2925265369UL, PH_NOISY_CC); + if (phalcon_array_isset_quick_string(definition, SS("joins"), 120974824UL)) { - 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_OBS_VAR(joins); + phalcon_array_fetch_quick_string(&joins, definition, SS("joins"), 120974824UL, PH_NOISY); - RETURN_MM_FALSE; -} - -static PHP_METHOD(Phalcon_Assets_Collection, setTargetPath){ - - zval *target_path; - - phalcon_fetch_params(0, 1, 0, &target_path); + phalcon_is_iterable(joins, &ah2, &hp2, 0, 0); - 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); + while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { - 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_GET_HVALUE(join); - 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_OBS_NVAR(type); + phalcon_array_fetch_quick_string(&type, join, SS("type"), 276192743UL, PH_NOISY); - 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_OBS_NVAR(table); + phalcon_array_fetch_quick_string(&table, join, SS("source"), 2744839734UL, PH_NOISY); - 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); + 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); - 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_INIT_NVAR(sql_join); + PHALCON_CONCAT_SVSV(sql_join, " ", type, " JOIN ", sql_table); - 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(join, SS("conditions"), 1055696255UL)) { - 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); + 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)) { - 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); + PHALCON_INIT_NVAR(join_expressions); + array_init(join_expressions); - 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); + phalcon_is_iterable(join_conditions_array, &ah3, &hp3, 0, 0); - 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); + while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { - if (!base_path) { - PHALCON_INIT_VAR(base_path); - } + PHALCON_GET_HVALUE(join_condition); - PHALCON_OBS_VAR(target_path); - phalcon_read_property_this_quick(&target_path, this_ptr, SL("_targetPath"), 3658201208UL, PH_NOISY_CC); + 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); - PHALCON_INIT_VAR(complete_path); - PHALCON_CONCAT_VV(complete_path, base_path, target_path); + zend_hash_move_forward_ex(ah3, &hp3); + } - if (phalcon_file_exists(complete_path TSRMLS_CC) == SUCCESS) { - phalcon_call_func_p1(return_value, "realpath", complete_path); - RETURN_MM(); - } + 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, " "); + } + } - RETURN_CTOR(complete_path); -} - - - - - -#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; -} -======= -static PHP_METHOD(Phalcon_Flash_Direct, message){ - - zval *type, *message; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 2, 0, &type, &message); + phalcon_concat_self(&sql, sql_join TSRMLS_CC); - phalcon_call_method_p2_key(return_value, this_ptr, "outputmessage", type, message, 924206491UL); - RETURN_MM(); -} - - - - - -#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); - - return SUCCESS; -} - -static PHP_METHOD(Phalcon_Flash_Session, setDI){ - - zval *dependency_injector; - - phalcon_fetch_params(0, 1, 0, &dependency_injector); + zend_hash_move_forward_ex(ah2, &hp2); + } - 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){ - - zval *remove, *dependency_injector, *service; - zval *session, *index_name, *messages; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &remove); + if (phalcon_array_isset_quick_string(definition, SS("where"), 621293632UL)) { - 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_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_VAR(service); - ZVAL_STRING(service, "session", 1); + if (phalcon_array_isset_quick_string(definition, SS("group"), 7349554UL)) { - PHALCON_INIT_VAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + PHALCON_INIT_VAR(group_items); + array_init(group_items); - PHALCON_INIT_VAR(index_name); - ZVAL_STRING(index_name, "_flashMessages", 1); + PHALCON_OBS_VAR(group_fields); + phalcon_array_fetch_quick_string(&group_fields, definition, SS("group"), 7349554UL, PH_NOISY); - 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_is_iterable(group_fields, &ah4, &hp4, 0, 0); - RETURN_CCTOR(messages); -} - -static PHP_METHOD(Phalcon_Flash_Session, _setSessionMessages){ - - zval *messages, *dependency_injector, *service; - zval *session, *index_name; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &messages); + while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { - 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_GET_HVALUE(group_field); - PHALCON_INIT_VAR(service); - ZVAL_STRING(service, "session", 1); + 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); - PHALCON_INIT_VAR(session); - phalcon_call_method_p1_key(session, dependency_injector, "getshared", service, 1727570332UL); + zend_hash_move_forward_ex(ah4, &hp4); + } - 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(group_sql); + phalcon_fast_join_str(group_sql, SL(", "), group_items TSRMLS_CC); - 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(group_clause); + PHALCON_CONCAT_SV(group_clause, " GROUP BY ", group_sql); + phalcon_concat_self(&sql, group_clause TSRMLS_CC); - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 0); + 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(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(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(messages, type)) { - PHALCON_INIT_VAR(empty_array); - array_init(empty_array); - phalcon_array_update_zval(&messages, type, &empty_array, PH_COPY | PH_SEPARATE); - } + if (phalcon_array_isset_quick_string(definition, SS("order"), 320020033UL)) { - phalcon_array_update_append_multi_2(&messages, type, message, 0); - phalcon_call_method_p1_key(NULL, this_ptr, "_setsessionmessages", messages, 2596691308UL); + PHALCON_OBS_VAR(order_fields); + phalcon_array_fetch_quick_string(&order_fields, definition, SS("order"), 320020033UL, PH_NOISY); - 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_INIT_VAR(order_items); + array_init(order_items); - if (!type) { - PHALCON_INIT_VAR(type); - } + phalcon_is_iterable(order_fields, &ah5, &hp5, 0, 0); - if (!remove) { - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 1); - } + while (zend_hash_get_current_data_ex(ah5, (void**) &hd, &hp5) == SUCCESS) { - 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); - } - - RETURN_MM_EMPTY_ARRAY(); - } + PHALCON_GET_HVALUE(order_item); - RETURN_CCTOR(messages); - } + PHALCON_OBS_NVAR(order_expression); + phalcon_array_fetch_long(&order_expression, order_item, 0, PH_NOISY); - 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_NVAR(order_sql_item); + phalcon_call_method_p2_key(order_sql_item, this_ptr, "getsqlexpression", order_expression, escape_char, 3377787077UL); - if (!remove) { - PHALCON_INIT_VAR(remove); - ZVAL_BOOL(remove, 1); - } + 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_VAR(messages); - phalcon_call_method_p1_key(messages, this_ptr, "_getsessionmessages", remove, 1351193184UL); - if (Z_TYPE_P(messages) == IS_ARRAY) { + 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_is_iterable(messages, &ah0, &hp0, 0, 0); + phalcon_array_append(&order_items, order_sql_item_type, PH_SEPARATE); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + zend_hash_move_forward_ex(ah5, &hp5); + } - PHALCON_GET_HKEY(type, ah0, hp0); - PHALCON_GET_HVALUE(message); + PHALCON_INIT_VAR(order_sql); + phalcon_fast_join_str(order_sql, SL(", "), order_items TSRMLS_CC); + PHALCON_SCONCAT_SV(sql, " ORDER BY ", order_sql); + } - phalcon_call_method_p2_key(NULL, this_ptr, "outputmessage", type, message, 924206491UL); + if (phalcon_array_isset_quick_string(definition, SS("limit"), 192268420UL)) { - zend_hash_move_forward_ex(ah0, &hp0); - } + 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); + } } - PHALCON_MM_RESTORE(); + RETURN_CTOR(sql); } +static PHP_METHOD(Phalcon_Db_Dialect, supportsSavepoints){ - - -#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; + RETURN_TRUE; } +static PHP_METHOD(Phalcon_Db_Dialect, supportsReleaseSavepoints){ + PHALCON_MM_GROW(); + phalcon_call_method_key(return_value, this_ptr, "supportssavepoints", 1063347073UL); + RETURN_MM(); +} -#ifdef HAVE_CONFIG_H -#endif - - - - - - - -PHALCON_INIT_CLASS(Phalcon_Assets_Manager){ ->>>>>>> 1.2.2 +static PHP_METHOD(Phalcon_Db_Dialect, createSavepoint){ - PHALCON_REGISTER_CLASS(Phalcon\\Assets, Manager, assets_manager, phalcon_assets_manager_method_entry, 0); + zval *name; -<<<<<<< HEAD + phalcon_fetch_params(0, 1, 0, &name); + + PHALCON_CONCAT_SV(return_value, "SAVEPOINT ", name); + return; +} +static PHP_METHOD(Phalcon_Db_Dialect, releaseSavepoint){ -======= - 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); ->>>>>>> 1.2.2 + zval *name; - return SUCCESS; + phalcon_fetch_params(0, 1, 0, &name); + + PHALCON_CONCAT_SV(return_value, "RELEASE SAVEPOINT ", name); + return; } -static PHP_METHOD(Phalcon_Assets_Manager, __construct){ - - zval *options = NULL; +static PHP_METHOD(Phalcon_Db_Dialect, rollbackSavepoint){ - PHALCON_MM_GROW(); + zval *name; - phalcon_fetch_params(1, 0, 1, &options); - - if (!options) { - PHALCON_INIT_VAR(options); - } - - if (Z_TYPE_P(options) == IS_ARRAY) { - phalcon_update_property_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); - } + phalcon_fetch_params(0, 1, 0, &name); - PHALCON_MM_RESTORE(); + PHALCON_CONCAT_SV(return_value, "ROLLBACK TO SAVEPOINT ", name); + return; } -<<<<<<< HEAD -PHALCON_INIT_CLASS(Phalcon_Assets_Filters_Cssmin){ - - PHALCON_REGISTER_CLASS(Phalcon\\Assets\\Filters, Cssmin, assets_filters_cssmin, phalcon_assets_filters_cssmin_method_entry, 0); +#ifdef HAVE_CONFIG_H +#endif - return SUCCESS; -} -static PHP_METHOD(Phalcon_Assets_Filters_Cssmin, filter){ - zval *content; +PHALCON_INIT_CLASS(Phalcon_Db_AdapterInterface){ - PHALCON_MM_GROW(); + PHALCON_REGISTER_INTERFACE(Phalcon\\Db, AdapterInterface, db_adapterinterface, phalcon_db_adapterinterface_method_entry); - phalcon_fetch_params(1, 1, 0, &content); - - if (phalcon_cssmin(return_value, content TSRMLS_CC) == FAILURE) { - return; - } - - RETURN_MM(); + return SUCCESS; } -/* 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; -} -#ifdef HAVE_CONFIG_H -#endif @@ -149062,423 +77151,104 @@ static int phalcon_cssmin(zval *return_value, zval *style 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(); -} -/* jsmin.c - 2013-03-29 -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 JSMIN_ACTION_OUTPUT_NEXT 1 -#define JSMIN_ACTION_NEXT_DELETE 2 -#define JSMIN_ACTION_NEXT 3 +PHALCON_INIT_CLASS(Phalcon_Db_DialectInterface){ -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; + PHALCON_REGISTER_INTERFACE(Phalcon\\Db, DialectInterface, db_dialectinterface, phalcon_db_dialectinterface_method_entry); -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); + return SUCCESS; } -/* isAlphanum -- return true if the character is a letter, digit, underscore, - dollar sign, or non-ASCII character. -*/ -static int jsmin_isAlphanum(int c) { - return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c == '\\' || c > 126); -} -/* 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; -} -static char jsmin_get(jsmin_parser *parser) { - 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; - } - 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 ' '; -} -/* 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; -} -/* 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 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; -} -/* 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; - } - 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; - } - } - } - if (status == FAILURE) { - smart_str_free(&minified); - return FAILURE; - } - smart_str_0(&minified); - if (minified.len) { - ZVAL_STRINGL(return_value, minified.c, minified.len, 0); - } else { - ZVAL_STRING(return_value, "", 1); - } + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + +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); return SUCCESS; } -static int phalcon_jsmin(zval *return_value, zval *script TSRMLS_DC) { +static PHP_METHOD(Phalcon_Config_Adapter_Json, __construct){ - zval *error = NULL; + zval *file_path, *contents, *array; - ZVAL_NULL(return_value); + phalcon_fetch_params(0, 1, 0, &file_path); - 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; + 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); } - 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; + zval_ptr_dtor(&contents); + + 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); } @@ -149492,39 +77262,136 @@ static int phalcon_jsmin(zval *return_value, zval *script TSRMLS_DC) { -PHALCON_INIT_CLASS(Phalcon_Assets_Filters_None){ +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; - PHALCON_REGISTER_CLASS(Phalcon\\Assets\\Filters, None, assets_filters_none, phalcon_assets_filters_none_method_entry, 0); + 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_Assets_Filters_None, filter){ +static PHP_METHOD(Phalcon_Config_Adapter_Ini, __construct){ - zval *content; + 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_fetch_params(0, 1, 0, &content); + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &file_path); + + PHALCON_INIT_VAR(process_sections); + ZVAL_BOOL(process_sections, 1); + + PHALCON_INIT_VAR(ini_config); + phalcon_call_func_p2(ini_config, "parse_ini_file", file_path, process_sections); + + 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(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; + } + + while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + + PHALCON_GET_HKEY(key, ah1, hp1); + PHALCON_GET_HVALUE(value); + + 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); + } - RETURN_CCTORW(content); -} - - - - - -#ifdef HAVE_CONFIG_H -#endif - - - - - - -PHALCON_INIT_CLASS(Phalcon_Assets_Exception){ - - PHALCON_REGISTER_CLASS_EX(Phalcon\\Assets, Exception, assets_exception, "phalcon\\exception", NULL, 0); - - return SUCCESS; + zend_hash_move_forward_ex(ah1, &hp1); + } + + zend_hash_move_forward_ex(ah0, &hp0); + } + + PHALCON_CALL_PARENT_PARAMS_1_NORETURN(this_ptr, "Phalcon\\Config\\Adapter\\Ini", "__construct", config); + + PHALCON_MM_RESTORE(); } @@ -149539,50 +77406,13 @@ PHALCON_INIT_CLASS(Phalcon_Assets_Exception){ +PHALCON_INIT_CLASS(Phalcon_Config_Exception){ -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); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Config, Exception, config_exception, "phalcon\\exception", NULL, 0); return SUCCESS; } -static PHP_METHOD(Phalcon_Assets_Resource_Js, __construct){ - - zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type; - zval *p0[] = { NULL, NULL, NULL, NULL, NULL }; - - PHALCON_MM_GROW(); - - 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, "js", 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\\Js", "__construct", 5, p0); - - PHALCON_MM_RESTORE(); -} - @@ -149595,50 +77425,15 @@ static PHP_METHOD(Phalcon_Assets_Resource_Js, __construct){ +PHALCON_INIT_CLASS(Phalcon_Session_Adapter_Files){ -PHALCON_INIT_CLASS(Phalcon_Assets_Resource_Css){ + PHALCON_REGISTER_CLASS_EX(Phalcon\\Session\\Adapter, Files, session_adapter_files, "phalcon\\session\\adapter", NULL, 0); - PHALCON_REGISTER_CLASS_EX(Phalcon\\Assets\\Resource, Css, assets_resource_css, "phalcon\\assets\\resource", phalcon_assets_resource_css_method_entry, 0); + zend_class_implements(phalcon_session_adapter_files_ce TSRMLS_CC, 1, phalcon_session_adapterinterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_Assets_Resource_Css, __construct){ - - zval *path, *local = NULL, *filter = NULL, *attributes = NULL, *type; - zval *p0[] = { NULL, NULL, NULL, NULL, NULL }; - - PHALCON_MM_GROW(); - - 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_MM_RESTORE(); -} - @@ -149652,430 +77447,259 @@ static PHP_METHOD(Phalcon_Assets_Resource_Css, __construct){ -PHALCON_INIT_CLASS(Phalcon_DI){ +PHALCON_INIT_CLASS(Phalcon_Session_Bag){ - PHALCON_REGISTER_CLASS(Phalcon, DI, di, phalcon_di_method_entry, 0); + PHALCON_REGISTER_CLASS(Phalcon\\Session, Bag, session_bag, phalcon_session_bag_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_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_di_ce TSRMLS_CC, 1, phalcon_diinterface_ce); + zend_class_implements(phalcon_session_bag_ce TSRMLS_CC, 2, phalcon_di_injectionawareinterface_ce, phalcon_session_baginterface_ce); return SUCCESS; } -static PHP_METHOD(Phalcon_DI, __construct){ - - zval *default_di; - - 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_DI, set){ - - zval *name, *definition, *shared = NULL, *service; +static PHP_METHOD(Phalcon_Session_Bag, __construct){ - PHALCON_MM_GROW(); + zval *name; - 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, &name); if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service name must be a 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_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); } -static PHP_METHOD(Phalcon_DI, setShared){ - - zval *name, *definition, *shared, *service; +static PHP_METHOD(Phalcon_Session_Bag, setDI){ - PHALCON_MM_GROW(); + zval *dependency_injector; - phalcon_fetch_params(1, 2, 0, &name, &definition); + phalcon_fetch_params(0, 1, 0, &dependency_injector); - 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(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); - PHALCON_INIT_VAR(shared); - ZVAL_BOOL(shared, 1); - - 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); } -static PHP_METHOD(Phalcon_DI, remove){ +static PHP_METHOD(Phalcon_Session_Bag, getDI){ - zval *name; - 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); - + RETURN_MEMBER_QUICK(this_ptr, "_dependencyInjector", 765199457UL); } -static PHP_METHOD(Phalcon_DI, attempt){ +static PHP_METHOD(Phalcon_Session_Bag, initialize){ - zval *name, *definition, *shared = NULL, *services, *service; + zval *session = NULL, *dependency_injector = NULL, *service; + zval *name, *data = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 2, 1, &name, &definition, &shared); + 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 (!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) { - 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_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_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); + ZVAL_STRING(service, "session", 1); - phalcon_update_property_array(this_ptr, SL("_services"), name, service TSRMLS_CC); - RETURN_CTOR(service); + 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); } - RETURN_MM_NULL(); -} - -static PHP_METHOD(Phalcon_DI, setRaw){ - - zval *name, *raw_definition; - - phalcon_fetch_params(0, 2, 0, &name, &raw_definition); + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - 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_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_array(this_ptr, SL("_services"), name, raw_definition 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); - RETURN_CCTORW(raw_definition); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_DI, getRaw){ +static PHP_METHOD(Phalcon_Session_Bag, destroy){ - zval *name, *services, *service, *exception_message; + zval *initalized, *name, *session; 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_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(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(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_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_OBS_VAR(service); - phalcon_array_fetch(&service, services, name, PH_NOISY); - RETURN_CCTOR(service); - } + 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_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; + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_DI, get){ +static PHP_METHOD(Phalcon_Session_Bag, set){ - zval *name, *parameters = NULL, *services, *service, *instance = NULL; - zval *exception_message; + zval *property, *value, *initalized, *name, *data; + zval *session; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &name, ¶meters); + phalcon_fetch_params(1, 2, 0, &property, &value); - if (!parameters) { - PHALCON_INIT_VAR(parameters); + 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 (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service alias must be a string"); - return; - } + phalcon_update_property_array(this_ptr, SL("_data"), property, value 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_OBS_VAR(service); - phalcon_array_fetch(&service, services, name, PH_NOISY); + PHALCON_OBS_VAR(name); + phalcon_read_property_this_quick(&name, this_ptr, SL("_name"), 3983977829UL, PH_NOISY_CC); - 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; - } - } + PHALCON_OBS_VAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); - 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); - } - } + 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_CCTOR(instance); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_DI, getShared){ - zval *name, *parameters = NULL, *shared_instances, *instance = NULL; +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, &name, ¶meters); - - if (!parameters) { - PHALCON_INIT_VAR(parameters); - } + phalcon_fetch_params(1, 1, 1, &property, &default_value); - if (Z_TYPE_P(name) != IS_STRING) { - PHALCON_THROW_EXCEPTION_STR(phalcon_di_exception_ce, "The service alias must be a string"); - return; + if (!default_value) { + PHALCON_INIT_VAR(default_value); } - 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); + 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(instance); -} - -static PHP_METHOD(Phalcon_DI, has){ - - zval *name, *services, *is_set_service = NULL; - zval *r0 = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 1, 0, &name); + PHALCON_OBS_VAR(data); + phalcon_read_property_this_quick(&data, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + if (phalcon_array_isset(data, property)) { - 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(value); + phalcon_array_fetch(&value, data, property, PH_NOISY); + if (PHALCON_IS_NOT_EMPTY(value)) { + 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); -} - -static PHP_METHOD(Phalcon_DI, wasFreshInstance){ - - - RETURN_MEMBER_QUICK(this_ptr, "_freshInstance", 1734543825UL); -} - -static PHP_METHOD(Phalcon_DI, getServices){ - - - RETURN_MEMBER_QUICK(this_ptr, "_services", 2714588616UL); + RETURN_CCTOR(default_value); } +static PHP_METHOD(Phalcon_Session_Bag, has){ - - -static PHP_METHOD(Phalcon_DI, __call){ - - zval *method, *arguments = NULL, *services, *service_name = NULL; - zval *possible_service = NULL, *handler, *exception_message; + zval *property, *initalized, *data; 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_fetch_params(1, 1, 0, &property); - 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_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(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; + 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_DI, setDefault){ - zval *dependency_injector; +static PHP_METHOD(Phalcon_Session_Bag, remove){ - phalcon_fetch_params(0, 1, 0, &dependency_injector); + zval *property, *data = NULL, *name, *session; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &property); - phalcon_update_static_property(SL("phalcon\\di"), SL("_default"), dependency_injector 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)) { + 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; } -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){ +#ifdef HAVE_CONFIG_H +#endif - 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(); + + + +PHALCON_INIT_CLASS(Phalcon_Session_Exception){ + + PHALCON_REGISTER_CLASS_EX(Phalcon\\Session, Exception, session_exception, "phalcon\\exception", NULL, 0); + + return SUCCESS; } @@ -150087,913 +77711,790 @@ static PHP_METHOD(Phalcon_DI, reset){ +PHALCON_INIT_CLASS(Phalcon_Session_BagInterface){ + PHALCON_REGISTER_INTERFACE(Phalcon\\Session, BagInterface, session_baginterface, phalcon_session_baginterface_method_entry); + return SUCCESS; +} -PHALCON_INIT_CLASS(Phalcon_Debug){ - PHALCON_REGISTER_CLASS(Phalcon, Debug, debug, phalcon_debug_method_entry, 0); - 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_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 PHP_METHOD(Phalcon_Debug, setShowBackTrace){ - zval *show_back_trace; - 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_Debug, setShowFiles){ - zval *show_files; +#ifdef HAVE_CONFIG_H +#endif - 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_Debug, setShowFileFragment){ - zval *show_file_fragment; - 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(); + + + + +PHALCON_INIT_CLASS(Phalcon_Session_Adapter){ + + 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_Debug, listen){ +static PHP_METHOD(Phalcon_Session_Adapter, __construct){ - zval *exceptions = NULL, *low_severity = NULL; + zval *options = NULL; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 0, 2, &exceptions, &low_severity); + phalcon_fetch_params(1, 0, 1, &options); - if (!exceptions) { - PHALCON_INIT_VAR(exceptions); - ZVAL_BOOL(exceptions, 1); + if (!options) { + PHALCON_INIT_VAR(options); } - if (!low_severity) { - PHALCON_INIT_VAR(low_severity); - ZVAL_BOOL(low_severity, 0); + if (Z_TYPE_P(options) == IS_ARRAY) { + phalcon_call_method_p1_key(NULL, this_ptr, "setoptions", options, 1759822653UL); } - 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); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Session_Adapter, start){ + + 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_Debug, listenExceptions){ +static PHP_METHOD(Phalcon_Session_Adapter, setOptions){ - zval *handler; + zval *options, *unique_id; PHALCON_MM_GROW(); - 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_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_this_quick(this_ptr, SL("_options"), options, 1620153008UL TSRMLS_CC); + + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Debug, listenLowSeverity){ +static PHP_METHOD(Phalcon_Session_Adapter, getOptions){ - zval *handler; + zval *options; PHALCON_MM_GROW(); - 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(); + 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_Debug, debugVar){ +static PHP_METHOD(Phalcon_Session_Adapter, get){ - zval *var, *key = NULL, *ztime, *backtrace, *data; + zval *index, *default_value = NULL, *unique_id, *key, *_SESSION; + zval *value; PHALCON_MM_GROW(); - phalcon_fetch_params(1, 1, 1, &var, &key); + phalcon_fetch_params(1, 1, 1, &index, &default_value); - if (!key) { - PHALCON_INIT_VAR(key); + if (!default_value) { + PHALCON_INIT_VAR(default_value); } - PHALCON_INIT_VAR(ztime); - ZVAL_LONG(ztime, (long) time(NULL)); + PHALCON_OBS_VAR(unique_id); + phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_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(key); + PHALCON_CONCAT_VV(key, unique_id, index); + phalcon_get_global(&_SESSION, SS("_SESSION") TSRMLS_CC); + if (phalcon_array_isset(_SESSION, key)) { - 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_Debug, clearVars){ - - - phalcon_update_property_null(this_ptr, SL("_data") TSRMLS_CC); - RETURN_THISW(); + 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_Debug, _escapeString){ +static PHP_METHOD(Phalcon_Session_Adapter, set){ - zval *value, *charset, *ent_compat, *line_break; - zval *escaped_line_break, *replaced_value; + zval *index, *value, *unique_id, *key, *_SESSION; PHALCON_MM_GROW(); - 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_fetch_params(1, 2, 0, &index, &value); - PHALCON_INIT_VAR(escaped_line_break); - ZVAL_STRING(escaped_line_break, "\\n", 1); + PHALCON_OBS_VAR(unique_id); + phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); - 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_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); - RETURN_CCTOR(value); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Debug, _getArrayDump){ +static PHP_METHOD(Phalcon_Session_Adapter, has){ - 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 *index, *unique_id, *key, *_SESSION; 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); + phalcon_fetch_params(1, 1, 0, &index); - RETURN_CTOR(joined_dump); - } + PHALCON_OBS_VAR(unique_id); + phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); - RETURN_NCTOR(number_arguments); - } + 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_NULL(); + RETURN_MM_FALSE; } -static PHP_METHOD(Phalcon_Debug, _getVarDump){ +static PHP_METHOD(Phalcon_Session_Adapter, remove){ - zval *variable, *class_name, *dumped_object; - zval *array_dump = NULL, *dump = NULL; + zval *index, *unique_id, *key, *_SESSION; PHALCON_MM_GROW(); - 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); - } - - 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, ")"); - } + phalcon_fetch_params(1, 1, 0, &index); - RETURN_CTOR(dump); - } + PHALCON_OBS_VAR(unique_id); + phalcon_read_property_this_quick(&unique_id, this_ptr, SL("_uniqueId"), 427461512UL, PH_NOISY_CC); - 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(); - } + 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); - RETURN_MM_STRING(zend_zval_type_name(variable), 1); + PHALCON_MM_RESTORE(); } -static PHP_METHOD(Phalcon_Debug, getMajorVersion){ +static PHP_METHOD(Phalcon_Session_Adapter, getId){ - zval *version, *parts, *major; + phalcon_get_session_id(return_value TSRMLS_CC); +} - PHALCON_MM_GROW(); +static PHP_METHOD(Phalcon_Session_Adapter, isStarted){ - PHALCON_INIT_VAR(version); - PHALCON_CALL_STATIC(version, "phalcon\\version", "get"); - - 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); + + 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; +} + + + + + +#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; } -static PHP_METHOD(Phalcon_Debug, getVersion){ - zval *version; - PHALCON_MM_GROW(); - PHALCON_INIT_VAR(version); - phalcon_call_method_key(version, this_ptr, "getmajorversion", 1927318692UL); - PHALCON_CONCAT_SVSVS(return_value, "
Phalcon Framework ", version, "
"); - RETURN_MM(); + + + + + + + + + + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Paginator_Adapter_Model){ + + PHALCON_REGISTER_CLASS(Phalcon\\Paginator\\Adapter, Model, paginator_adapter_model, phalcon_paginator_adapter_model_method_entry, 0); + + 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_class_implements(phalcon_paginator_adapter_model_ce TSRMLS_CC, 1, phalcon_paginator_adapterinterface_ce); + + return SUCCESS; } -static PHP_METHOD(Phalcon_Debug, getCssSources){ +static PHP_METHOD(Phalcon_Paginator_Adapter_Model, __construct){ - zval *uri, *sources; + zval *config, *limit, *page; PHALCON_MM_GROW(); - PHALCON_OBS_VAR(uri); - phalcon_read_property_this_quick(&uri, this_ptr, SL("_uri"), 251146964UL, PH_NOISY_CC); + phalcon_fetch_params(1, 1, 0, &config); - PHALCON_INIT_VAR(sources); - PHALCON_CONCAT_SVS(sources, ""); - PHALCON_SCONCAT_SVS(sources, ""); - RETURN_CTOR(sources); + 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 (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_Debug, getJsSources){ - - zval *uri, *sources; +static PHP_METHOD(Phalcon_Paginator_Adapter_Model, setCurrentPage){ - PHALCON_MM_GROW(); + zval *page; - PHALCON_OBS_VAR(uri); - phalcon_read_property_this_quick(&uri, this_ptr, SL("_uri"), 251146964UL, PH_NOISY_CC); + phalcon_fetch_params(0, 1, 0, &page); + + phalcon_update_property_this_quick(this_ptr, SL("_page"), page, 3986343137UL TSRMLS_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_Debug, showTraceItem){ +static PHP_METHOD(Phalcon_Paginator_Adapter_Model, getPaginate){ - 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; + 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, 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_INIT_VAR(is_phalcon_class); - - phalcon_preg_match(is_phalcon_class, pattern, class_name, NULL TSRMLS_CC); - - if (zend_is_true(is_phalcon_class)) { - PHALCON_INIT_VAR(namespace_separator); - ZVAL_STRING(namespace_separator, "\\", 1); - - PHALCON_INIT_VAR(prepare_uri_class); - phalcon_fast_str_replace(prepare_uri_class, namespace_separator, underscore, class_name); + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); - 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_INIT_VAR(zero); + ZVAL_LONG(zero, 0); - 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_VAR(show); + phalcon_read_property_this_quick(&show, this_ptr, SL("_limitRows"), 597448366UL, PH_NOISY_CC); - PHALCON_INIT_VAR(prepare_internal_class); - phalcon_fast_str_replace(prepare_internal_class, underscore, minus, lower_class_name); + PHALCON_OBS_VAR(config); + phalcon_read_property_this_quick(&config, this_ptr, SL("_config"), 4157843450UL, PH_NOISY_CC); - PHALCON_SCONCAT_SVSVS(html, "", class_name, ""); - } else { - PHALCON_SCONCAT_SVS(html, "", class_name, ""); - } - } + PHALCON_OBS_VAR(items); + phalcon_array_fetch_quick_string(&items, config, SS("data"), 256359743UL, PH_NOISY); - PHALCON_OBS_VAR(type); - phalcon_array_fetch_quick_string(&type, trace, SS("type"), 276192743UL, PH_NOISY); - phalcon_concat_self(&html, type TSRMLS_CC); + 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_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); - - 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); - } - - PHALCON_INIT_NVAR(is_internal); - phalcon_call_method_key(is_internal, function_reflection, "isinternal", 2412550174UL); - - 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_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(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(n); + phalcon_fast_count(n, items TSRMLS_CC); - PHALCON_INIT_VAR(arguments); - array_init(arguments); + PHALCON_INIT_VAR(page); + object_init(page); - phalcon_is_iterable(trace_args, &ah0, &hp0, 0, 0); + PHALCON_INIT_VAR(last_show_page); + sub_function(last_show_page, page_number, one TSRMLS_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(start); + mul_function(start, show, last_show_page TSRMLS_CC); - PHALCON_GET_HVALUE(argument); + PHALCON_INIT_VAR(last_page); + sub_function(last_page, n, one TSRMLS_CC); - PHALCON_INIT_NVAR(dumped_argument); - phalcon_call_method_p1_key(dumped_argument, this_ptr, "_getvardump", argument, 2922816643UL); + PHALCON_INIT_VAR(possible_pages); + div_function(possible_pages, last_page, show TSRMLS_CC); - PHALCON_INIT_NVAR(span_argument); - PHALCON_CONCAT_SVS(span_argument, "", dumped_argument, ""); + 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_array_append(&arguments, span_argument, PH_SEPARATE); + if (!zend_is_true(page_number)) { + PHALCON_CPY_WRT(page_number, one); + } - zend_hash_move_forward_ex(ah0, &hp0); - } + PHALCON_INIT_VAR(page_items); + array_init(page_items); + if (PHALCON_GT(n, zero)) { - PHALCON_INIT_VAR(joined_arguments); - phalcon_fast_join_str(joined_arguments, SL(", "), arguments TSRMLS_CC); - PHALCON_SCONCAT_SVS(html, "(", joined_arguments, ")"); + if (PHALCON_LE(start, n)) { + phalcon_call_method_p1_key(NULL, items, "seek", start, 274276301UL); } else { - phalcon_concat_self_str(&html, SL("()") TSRMLS_CC); + phalcon_call_method_p1_key(NULL, items, "seek", one, 274276301UL); + PHALCON_CPY_WRT(page_number, one); } - } - - 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); + PHALCON_INIT_VAR(i); + ZVAL_LONG(i, 1); - if (PHALCON_GT(after_line, number_lines)) { - PHALCON_CPY_WRT(last_line, number_lines); - } else { - PHALCON_CPY_WRT(last_line, after_line); - } + while (1) { - PHALCON_SCONCAT_SVSVSVS(html, "
");
+			PHALCON_INIT_NVAR(r0);
+			phalcon_call_method_key(r0, items, "valid", 574098517UL);
+			PHALCON_CPY_WRT(valid, r0);
+			if (PHALCON_IS_NOT_FALSE(valid)) {
 			} else {
-				PHALCON_CPY_WRT(first_line, one);
-				PHALCON_CPY_WRT(last_line, number_lines);
-				PHALCON_SCONCAT_SVSVS(html, "
");
+				break;
 			}
 	
-			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) {
+			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;
+			}
 	
-				if (PHALCON_LE(i, last_line)) {
-				} else {
-					break;
-				}
+			PHALCON_SEPARATE(i);
+			phalcon_increment(i);
+		}
+	}
 	
-				PHALCON_INIT_NVAR(line_position);
-				sub_function(line_position, i, one TSRMLS_CC);
+	phalcon_update_property_zval(page, SL("items"), page_items TSRMLS_CC);
 	
-				PHALCON_OBS_NVAR(current_line);
-				phalcon_array_fetch(¤t_line, lines, line_position, PH_NOISY);
+	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);
 	
-				if (zend_is_true(show_file_fragment)) {
-					if (PHALCON_IS_EQUAL(i, first_line)) {
+			PHALCON_INIT_VAR(additional_page);
+			phalcon_add_function(additional_page, possible_pages, one TSRMLS_CC);
 	
-						PHALCON_INIT_NVAR(trimmed);
-						phalcon_fast_trim(trimmed, current_line, PHALCON_TRIM_RIGHT TSRMLS_CC);
+			PHALCON_INIT_NVAR(next);
+			ZVAL_LONG(next, phalcon_get_intval(additional_page));
+		}
+	}
 	
-						PHALCON_INIT_NVAR(is_comment);
+	if (PHALCON_GT(next, total_pages)) {
+		PHALCON_CPY_WRT(next, total_pages);
+	}
 	
-						phalcon_preg_match(is_comment, comment_pattern, current_line, NULL TSRMLS_CC);
+	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);
+	}
 	
-						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);
-						}
-					}
-				}
+	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);
 	
-				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_VAR(remainder);
+	mod_function(remainder, n, show TSRMLS_CC);
 	
-						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_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_SEPARATE(i);
-				phalcon_increment(i);
-			}
-			phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - } + PHALCON_INIT_VAR(pages_total); + ZVAL_LONG(pages_total, phalcon_get_intval(next)); + } else { + PHALCON_CPY_WRT(pages_total, possible_pages); } - phalcon_concat_self_str(&html, SL("") TSRMLS_CC); + 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(html); + RETURN_CTOR(page); } -static PHP_METHOD(Phalcon_Debug, onUncaughtException){ - 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; + + + +#ifdef HAVE_CONFIG_H +#endif + + + + + + + +PHALCON_INIT_CLASS(Phalcon_Paginator_Adapter_QueryBuilder){ + + PHALCON_REGISTER_CLASS(Phalcon\\Paginator\\Adapter, QueryBuilder, paginator_adapter_querybuilder, phalcon_paginator_adapter_querybuilder_method_entry, 0); + + 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_paginator_adapter_querybuilder_ce TSRMLS_CC, 1, phalcon_paginator_adapterinterface_ce); + + return SUCCESS; +} + +static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, __construct){ + + zval *config, *builder, *limit, *page; PHALCON_MM_GROW(); - 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_fetch_params(1, 1, 0, &config); - 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_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_OBS_VAR(show_back_trace); - phalcon_read_property_this_quick(&show_back_trace, this_ptr, SL("_showBackTrace"), 3370024901UL, PH_NOISY_CC); + 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 (zend_is_true(show_back_trace)) { + 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_OBS_VAR(data_vars); - phalcon_read_property_this_quick(&data_vars, this_ptr, SL("_data"), 3972126110UL, PH_NOISY_CC); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, setCurrentPage){ + + zval *current_page; + + phalcon_fetch_params(0, 1, 0, ¤t_page); - 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_update_property_this_quick(this_ptr, SL("_page"), current_page, 3986343137UL TSRMLS_CC); + RETURN_THISW(); +} + +static PHP_METHOD(Phalcon_Paginator_Adapter_QueryBuilder, getPaginate){ + + 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(original_builder); + phalcon_read_property_this_quick(&original_builder, this_ptr, SL("_builder"), 3366211339UL, PH_NOISY_CC); - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + PHALCON_INIT_VAR(builder); + if (phalcon_clone(builder, original_builder TSRMLS_CC) == FAILURE) { + return; + } - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); + PHALCON_INIT_VAR(total_builder); + if (phalcon_clone(total_builder, builder TSRMLS_CC) == FAILURE) { + return; + } - PHALCON_INIT_VAR(trace); - phalcon_call_method_key(trace, exception, "gettrace", 4268145556UL); + PHALCON_OBS_VAR(limit); + phalcon_read_property_this_quick(&limit, this_ptr, SL("_limitRows"), 597448366UL, PH_NOISY_CC); - phalcon_is_iterable(trace, &ah0, &hp0, 0, 0); + PHALCON_OBS_VAR(number_page); + phalcon_read_property_this_quick(&number_page, this_ptr, SL("_page"), 3986343137UL, PH_NOISY_CC); - while (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) == SUCCESS) { + PHALCON_INIT_VAR(one); + ZVAL_LONG(one, 1); + if (!zend_is_true(number_page)) { + PHALCON_CPY_WRT(number_page, one); + } - PHALCON_GET_HKEY(n, ah0, hp0); - PHALCON_GET_HVALUE(trace_item); + PHALCON_INIT_VAR(prev_number_page); + sub_function(prev_number_page, number_page, one TSRMLS_CC); - 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); + PHALCON_INIT_VAR(number); + mul_function(number, limit, prev_number_page TSRMLS_CC); - zend_hash_move_forward_ex(ah0, &hp0); - } + 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_concat_self_str(&html, SL("
") TSRMLS_CC); + PHALCON_INIT_VAR(query); + phalcon_call_method_key(query, builder, "getquery", 4154457883UL); - 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_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_is_iterable(_REQUEST, &ah1, &hp1, 0, 0); + phalcon_update_property_zval(page, SL("before"), before TSRMLS_CC); - while (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) == SUCCESS) { + PHALCON_INIT_VAR(items); + phalcon_call_method_key(items, query, "execute", 3117639032UL); + phalcon_update_property_zval(page, SL("items"), items TSRMLS_CC); - PHALCON_GET_HKEY(key_request, ah1, hp1); - PHALCON_GET_HVALUE(value); + PHALCON_INIT_VAR(select_count); + ZVAL_STRING(select_count, "COUNT(*) [rowcount]", 1); - PHALCON_SCONCAT_SVSVS(html, ""); + phalcon_call_method_p1_key(NULL, total_builder, "columns", select_count, 1041822630UL); - zend_hash_move_forward_ex(ah1, &hp1); - } + PHALCON_INIT_VAR(null_order); + phalcon_call_method_p1_key(NULL, total_builder, "orderby", null_order, 609575676UL); - phalcon_concat_self_str(&html, SL("
KeyValue
", key_request, "", value, "
") TSRMLS_CC); + PHALCON_INIT_VAR(total_query); + phalcon_call_method_key(total_query, total_builder, "getquery", 4154457883UL); - 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_INIT_VAR(result); + phalcon_call_method_key(result, total_query, "execute", 3117639032UL); - phalcon_is_iterable(_SERVER, &ah2, &hp2, 0, 0); + PHALCON_INIT_VAR(row); + phalcon_call_method_key(row, result, "getfirst", 3710205613UL); - while (zend_hash_get_current_data_ex(ah2, (void**) &hd, &hp2) == SUCCESS) { + PHALCON_OBS_VAR(rowcount); + phalcon_read_property(&rowcount, row, SL("rowcount"), PH_NOISY_CC); - PHALCON_GET_HKEY(key_server, ah2, hp2); - PHALCON_GET_HVALUE(value); + PHALCON_INIT_VAR(total_pages); + div_function(total_pages, rowcount, limit TSRMLS_CC); - PHALCON_SCONCAT_SVSVS(html, ""); + 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); + } - zend_hash_move_forward_ex(ah2, &hp2); - } + 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); + } - phalcon_concat_self_str(&html, SL("
KeyValue
", key_server, "", value, "
") TSRMLS_CC); + 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); - 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); + RETURN_CTOR(page); +} + + + + + +#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_Paginator_Adapter_NativeArray, __construct){ + + zval *config, *limit, *page; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 1, 0, &config); - phalcon_is_iterable(files, &ah3, &hp3, 0, 0); + 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); + } - while (zend_hash_get_current_data_ex(ah3, (void**) &hd, &hp3) == SUCCESS) { + 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_GET_HKEY(key_file, ah3, hp3); - PHALCON_GET_HVALUE(value); + PHALCON_MM_RESTORE(); +} + +static PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, setCurrentPage){ + + zval *page; + + phalcon_fetch_params(0, 1, 0, &page); - PHALCON_SCONCAT_SVSVS(html, ""); + phalcon_update_property_this_quick(this_ptr, SL("_page"), page, 3986343137UL TSRMLS_CC); - zend_hash_move_forward_ex(ah3, &hp3); - } +} + +static PHP_METHOD(Phalcon_Paginator_Adapter_NativeArray, getPaginate){ + + 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_INIT_VAR(one); + ZVAL_LONG(one, 1); - phalcon_concat_self_str(&html, SL("
#Path
", key_file, "", value, "
") TSRMLS_CC); + PHALCON_OBS_VAR(config); + phalcon_read_property_this_quick(&config, this_ptr, SL("_config"), 4157843450UL, PH_NOISY_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); + 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; + } - 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_OBS_VAR(show); + phalcon_read_property_this_quick(&show, this_ptr, SL("_limitRows"), 597448366UL, PH_NOISY_CC); - phalcon_is_iterable(data_vars, &ah4, &hp4, 0, 0); + 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); + } - while (zend_hash_get_current_data_ex(ah4, (void**) &hd, &hp4) == SUCCESS) { + PHALCON_INIT_VAR(page); + object_init(page); - PHALCON_GET_HKEY(key_var, ah4, hp4); - PHALCON_GET_HVALUE(data_var); + PHALCON_INIT_VAR(number); + phalcon_fast_count(number, items TSRMLS_CC); - PHALCON_OBS_NVAR(variable); - phalcon_array_fetch_long(&variable, data_var, 0, PH_NOISY); + PHALCON_INIT_VAR(rounded_total); + div_function(rounded_total, number, show TSRMLS_CC); - PHALCON_INIT_NVAR(dumped_argument); - phalcon_call_method_p1_key(dumped_argument, this_ptr, "_getvardump", variable, 2922816643UL); - PHALCON_SCONCAT_SVSVS(html, ""); + PHALCON_INIT_VAR(total_pages); + ZVAL_LONG(total_pages, phalcon_get_intval(rounded_total)); - zend_hash_move_forward_ex(ah4, &hp4); - } + if (!PHALCON_IS_EQUAL(total_pages, rounded_total)) { + PHALCON_SEPARATE_NMO(total_pages); + phalcon_increment(total_pages); + } - phalcon_concat_self_str(&html, SL("
KeyValue
", key_var, "", dumped_argument, "
") TSRMLS_CC); - } + PHALCON_INIT_VAR(before_page_number); + sub_function(before_page_number, page_number, one TSRMLS_CC); - phalcon_concat_self_str(&html, SL("
") TSRMLS_CC); - } + PHALCON_INIT_VAR(start); + mul_function(start, show, before_page_number TSRMLS_CC); - PHALCON_INIT_VAR(js_sources); - phalcon_call_method_key(js_sources, this_ptr, "getjssources", 3049944486UL); - PHALCON_SCONCAT_VS(html, js_sources, "
"); + 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); + } - zend_print_zval(html, 0); + 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_NVAR(is_active); - ZVAL_BOOL(is_active, 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_update_static_property(SL("phalcon\\debug"), SL("_isActive"), is_active TSRMLS_CC); - RETURN_MM_TRUE; + RETURN_CTOR(page); } @@ -151008,9 +78509,9 @@ static PHP_METHOD(Phalcon_Debug, onUncaughtException){ -PHALCON_INIT_CLASS(Phalcon_Tag_Exception){ +PHALCON_INIT_CLASS(Phalcon_Paginator_Exception){ - PHALCON_REGISTER_CLASS_EX(Phalcon\\Tag, Exception, tag_exception, "phalcon\\exception", NULL, 0); + PHALCON_REGISTER_CLASS_EX(Phalcon\\Paginator, Exception, paginator_exception, "phalcon\\exception", NULL, 0); return SUCCESS; } @@ -151024,312 +78525,216 @@ PHALCON_INIT_CLASS(Phalcon_Tag_Exception){ +PHALCON_INIT_CLASS(Phalcon_Paginator_AdapterInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon\\Paginator, AdapterInterface, paginator_adapterinterface, phalcon_paginator_adapterinterface_method_entry); + return SUCCESS; +} -PHALCON_INIT_CLASS(Phalcon_Tag_Select){ - PHALCON_REGISTER_CLASS(Phalcon\\Tag, Select, tag_select, phalcon_tag_select_method_entry, ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + + + + +#ifdef HAVE_CONFIG_H +#endif + + + +PHALCON_INIT_CLASS(Phalcon_FilterInterface){ + + PHALCON_REGISTER_INTERFACE(Phalcon, FilterInterface, filterinterface, phalcon_filterinterface_method_entry); return SUCCESS; } -static PHP_METHOD(Phalcon_Tag_Select, selectField){ - 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; + + + + + + +#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, 1, ¶meters, &data); - - if (!data) { - PHALCON_INIT_VAR(data); - } - - 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_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_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(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_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