/** * Handles method calls when a method is not implemented * * @param string $method * @param array $arguments * @return mixed */ PHP_METHOD(Phalcon_Mvc_View_Engine, __call){ zval *method, *args = NULL, method_name = {}, arguments = {}, *methods, func = {}, exception_message = {}, service_name = {}, service = {}, callback = {}; phalcon_fetch_params(0, 1, 1, &method, &arguments); PHALCON_CPY_WRT(&method_name, method); if (!args) { array_init(&arguments); } else { PHALCON_CPY_WRT(&arguments, args); } methods = phalcon_read_property(getThis(), SL("_methods"), PH_NOISY); if (phalcon_array_isset_fetch(&func, methods, &method_name)) { PHALCON_CALL_USER_FUNC_ARRAYW(return_value, &func, &arguments); return; } if (phalcon_compare_strict_string(&method_name, SL("get")) || phalcon_compare_strict_string(&method_name, SL("getPost")) || phalcon_compare_strict_string(&method_name, SL("getPut")) || phalcon_compare_strict_string(&method_name, SL("getQuery")) || phalcon_compare_strict_string(&method_name, SL("getServer"))) { ZVAL_STRING(&service_name, ISV(request)); } else if (phalcon_compare_strict_string(&method_name, SL("getSession"))) { ZVAL_STRING(&method_name, "get"); ZVAL_STRING(&service_name, ISV(session)); } else if (phalcon_compare_strict_string(&method_name, SL("getParam"))) { ZVAL_STRING(&service_name, ISV(dispatcher)); } PHALCON_CALL_METHODW(&service, getThis(), "getresolveservice", &service_name); if (Z_TYPE(service) != IS_OBJECT) { PHALCON_CONCAT_SVS(&exception_message, "The injected service '", &service_name, "' is not valid"); PHALCON_THROW_EXCEPTION_ZVALW(phalcon_mvc_view_exception_ce, &exception_message); return; } if (!phalcon_method_exists(&service, &method_name) == FAILURE) { PHALCON_CONCAT_SVS(&exception_message, "The method \"", &method_name, "\" doesn't exist on view"); PHALCON_THROW_EXCEPTION_ZVALW(phalcon_mvc_view_exception_ce, &exception_message); return; } array_init(&callback); phalcon_array_append(&callback, &service, PH_COPY); phalcon_array_append(&callback, &method_name, PH_COPY); PHALCON_CALL_USER_FUNC_ARRAYW(return_value, &callback, &arguments); }
/** * Gets a value from the the internal related entity or from the default value * * @param string $name * @return mixed */ PHP_METHOD(Phalcon_Forms_Form, getValue){ zval *name, *entity, *method, *value = NULL, *data; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { RETURN_MM_NULL(); } PHALCON_OBS_VAR(entity); phalcon_read_property(&entity, this_ptr, SL("_entity"), PH_NOISY_CC); if (Z_TYPE_P(entity) == IS_OBJECT) { /** * Check if the entity has a getter */ PHALCON_INIT_VAR(method); PHALCON_CONCAT_SV(method, "get", name); if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(value); PHALCON_CALL_METHOD(value, entity, Z_STRVAL_P(method)); RETURN_CCTOR(value); } /** * Check if the entity has a public property */ if (phalcon_isset_property_zval(entity, name TSRMLS_CC)) { PHALCON_OBS_NVAR(value); phalcon_read_property_zval(&value, entity, name, PH_NOISY_CC); RETURN_CCTOR(value); } } PHALCON_OBS_VAR(data); phalcon_read_property(&data, this_ptr, SL("_data"), PH_NOISY_CC); if (Z_TYPE_P(data) == IS_ARRAY) { /** * Check if the data is in the data array */ if (phalcon_array_isset(data, name)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch(&value, data, name, PH_NOISY_CC); RETURN_CCTOR(value); } } RETURN_MM_NULL(); }
/** * Gets the a value to validate in the array/object data source * * @param string $attribute * @return mixed */ 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; zval *filtered; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 0, &attribute); PHALCON_OBS_VAR(entity); phalcon_read_property_this(&entity, this_ptr, SL("_entity"), PH_NOISY_CC); /** * If the entity is an object use it to retrieve the values */ 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_exists_ex(entity, SS("readattribute") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_NVAR(value); phalcon_call_method(value, entity, "readattribute"); } 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_OBS_VAR(data); phalcon_read_property_this(&data, this_ptr, SL("_data"), 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; } } /** * Check if there is a calculated value */ PHALCON_OBS_VAR(values); phalcon_read_property_this(&values, this_ptr, SL("_values"), PH_NOISY_CC); if (phalcon_array_isset(values, attribute)) { PHALCON_OBS_NVAR(value); phalcon_array_fetch(&value, values, attribute, PH_NOISY_CC); 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_CC); } } 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); } } } if (Z_TYPE_P(value) != IS_NULL) { PHALCON_OBS_VAR(filters); phalcon_read_property_this(&filters, this_ptr, SL("_filters"), 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_CC); 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(dependency_injector, this_ptr, "getdi"); 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(filter_service, dependency_injector, "getshared", service_name); 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(filtered); phalcon_call_method_p2(filtered, filter_service, "sanitize", value, field_filters); RETURN_CCTOR(filtered); } } } /** * Cache the calculated value */ phalcon_update_property_array(this_ptr, SL("_values"), attribute, value TSRMLS_CC); RETURN_CCTOR(value); } RETURN_MM_NULL(); }
/** * Dispatches a controller action taking into account the routing parameters * * @param Phalcon_Request $request * @param Phalcon_Response $response * @param Phalcon_View $view * @param Phalcon_Model_Manager $model * @return Phalcon_Controller */ PHP_METHOD(Phalcon_Dispatcher, dispatch){ zval *request = NULL, *response = NULL, *view = NULL, *model = NULL, *controllers_dir = NULL; zval *value = NULL, *controller = NULL, *number_dispatches = NULL; zval *controller_name = NULL, *controllers = NULL, *controller_class = NULL; zval *controller_path = NULL, *params = NULL, *action_name = NULL; zval *action_method = NULL; zval *r0 = NULL, *r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL, *r5 = NULL, *r6 = NULL; zval *r7 = NULL, *r8 = NULL, *r9 = NULL, *r10 = NULL, *r11 = NULL, *r12 = NULL; zval *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL, *t4 = NULL, *t5 = NULL, *t6 = NULL; zval *t7 = NULL, *t8 = NULL, *t9 = NULL, *t10 = NULL; zval *c0 = NULL, *c1 = NULL, *c2 = NULL; zval *i0 = NULL; zval *a0 = NULL, *a1 = NULL; zval *p0[] = { NULL, NULL, NULL, NULL, NULL }; int eval_int; zend_class_entry *ce0; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|zz", &request, &response, &view, &model) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!view) { PHALCON_INIT_VAR(view); ZVAL_NULL(view); } if (!model) { PHALCON_INIT_VAR(model); ZVAL_NULL(model); } PHALCON_ALLOC_ZVAL_MM(r0); PHALCON_ALLOC_ZVAL_MM(t0); phalcon_read_property(&t0, this_ptr, SL("_basePath"), PHALCON_NOISY TSRMLS_CC); PHALCON_ALLOC_ZVAL_MM(t1); phalcon_read_property(&t1, this_ptr, SL("_controllersDir"), PHALCON_NOISY TSRMLS_CC); PHALCON_CONCAT_VV(r0, t0, t1); PHALCON_CPY_WRT(controllers_dir, r0); PHALCON_INIT_VAR(value); ZVAL_NULL(value); PHALCON_INIT_VAR(controller); ZVAL_NULL(controller); PHALCON_INIT_VAR(number_dispatches); ZVAL_LONG(number_dispatches, 0); phalcon_update_property_bool(this_ptr, SL("_finished"), 0 TSRMLS_CC); ws_e10f_0: PHALCON_INIT_VAR(t2); phalcon_read_property(&t2, this_ptr, SL("_finished"), PHALCON_NOISY TSRMLS_CC); if (zend_is_true(t2)) { goto we_e10f_0; } phalcon_update_property_bool(this_ptr, SL("_finished"), 1 TSRMLS_CC); PHALCON_INIT_VAR(t3); phalcon_read_property(&t3, this_ptr, SL("_controllerName"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controller_name, t3); if (!zend_is_true(controller_name)) { PHALCON_INIT_VAR(t4); phalcon_read_property(&t4, this_ptr, SL("_defaultController"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controller_name, t4); phalcon_update_property_zval(this_ptr, SL("_controllerName"), controller_name TSRMLS_CC); } PHALCON_INIT_VAR(t5); phalcon_read_property(&t5, this_ptr, SL("_controllers"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controllers, t5); PHALCON_INIT_VAR(r1); PHALCON_INIT_VAR(r2); PHALCON_CALL_STATIC_PARAMS_1(r2, "phalcon_text", "camelize", controller_name); PHALCON_CONCAT_VS(r1, r2, "Controller"); PHALCON_CPY_WRT(controller_class, r1); eval_int = phalcon_array_isset(controllers, controller_class); if (!eval_int) { PHALCON_INIT_VAR(c0); ZVAL_BOOL(c0, 0); PHALCON_INIT_VAR(r3); PHALCON_CALL_FUNC_PARAMS_2(r3, "class_exists", controller_class, c0); if (!zend_is_true(r3)) { PHALCON_INIT_VAR(r4); PHALCON_CONCAT_VVS(r4, controllers_dir, controller_class, ".php"); PHALCON_CPY_WRT(controller_path, r4); if (phalcon_file_exists(controller_path TSRMLS_CC) == SUCCESS) { if (phalcon_require(controller_path TSRMLS_CC) == FAILURE) { return; } } else { PHALCON_INIT_VAR(r5); PHALCON_CONCAT_SVS(r5, "File for controller class ", controller_class, " doesn't exist"); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, r5, PHALCON_NO_CHECK); } PHALCON_INIT_VAR(c1); ZVAL_BOOL(c1, 0); PHALCON_INIT_VAR(r6); PHALCON_CALL_FUNC_PARAMS_2(r6, "class_exists", controller_class, c1); if (!zend_is_true(r6)) { PHALCON_INIT_VAR(r7); PHALCON_CONCAT_SVS(r7, "Class ", controller_class, " was not found on controller file"); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, r7, PHALCON_NO_CHECK); } } ce0 = phalcon_fetch_class(controller_class TSRMLS_CC); PHALCON_INIT_VAR(i0); object_init_ex(i0, ce0); p0[0] = this_ptr; p0[1] = request; p0[2] = response; p0[3] = view; p0[4] = model; PHALCON_CALL_METHOD_PARAMS_NORETURN(i0, "__construct", 5, p0, PHALCON_CHECK); PHALCON_CPY_WRT(controller, i0); if (phalcon_method_exists_ex(controller, SL("initialize") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD_NORETURN(controller, "initialize", PHALCON_NO_CHECK); } PHALCON_INIT_VAR(t6); phalcon_read_property(&t6, this_ptr, SL("_controllers"), PHALCON_NOISY TSRMLS_CC); phalcon_array_update(&t6, controller_class, &controller, PHALCON_NO_SEPARATE_THX, PHALCON_COPY, PHALCON_NO_CTOR TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_controllers"), t6 TSRMLS_CC); } else { PHALCON_INIT_VAR(r8); phalcon_array_fetch(&r8, controllers, controller_class, PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(controller, r8); } PHALCON_INIT_VAR(t7); phalcon_read_property(&t7, this_ptr, SL("_params"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(params, t7); PHALCON_INIT_VAR(t8); phalcon_read_property(&t8, this_ptr, SL("_actionName"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(action_name, t8); if (!zend_is_true(action_name)) { PHALCON_INIT_VAR(t9); phalcon_read_property(&t9, this_ptr, SL("_defaultAction"), PHALCON_NOISY TSRMLS_CC); PHALCON_CPY_WRT(action_name, t9); phalcon_update_property_zval(this_ptr, SL("_actionName"), action_name TSRMLS_CC); } if (phalcon_method_exists_ex(controller, SL("beforedispatch") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(r9); PHALCON_CALL_METHOD_PARAMS_3(r9, controller, "beforedispatch", controller_name, action_name, params, PHALCON_NO_CHECK); if (Z_TYPE_P(r9) == IS_BOOL && !Z_BVAL_P(r9)) { PHALCON_INIT_VAR(value); ZVAL_BOOL(value, 0); goto we_e10f_0; } } PHALCON_INIT_VAR(r10); PHALCON_CONCAT_VS(r10, action_name, "Action"); PHALCON_CPY_WRT(action_method, r10); if (phalcon_method_exists(controller, action_method TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(a0); array_init(a0); phalcon_array_append(&a0, controller, PHALCON_SEPARATE_PLZ TSRMLS_CC); phalcon_array_append(&a0, action_method, PHALCON_SEPARATE_PLZ TSRMLS_CC); PHALCON_INIT_VAR(value); PHALCON_CALL_FUNC_PARAMS_2(value, "call_user_func_array", a0, params); } else { if (phalcon_method_exists_ex(controller, SL("notfoundaction") TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(a1); array_init(a1); phalcon_array_append(&a1, controller, PHALCON_SEPARATE_PLZ TSRMLS_CC); add_next_index_stringl(a1, SL("notFoundAction"), 1); PHALCON_INIT_VAR(value); PHALCON_CALL_FUNC_PARAMS_2(value, "call_user_func_array", a1, params); } else { PHALCON_INIT_VAR(r11); PHALCON_CONCAT_SVSVS(r11, "Action '", action_name, "' was not found on controller '", controller_name, "'"); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, r11, PHALCON_NO_CHECK); } } if (phalcon_method_exists_ex(controller, SL("afterdispatch") TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD_PARAMS_3_NORETURN(controller, "afterdispatch", controller_name, action_name, params, PHALCON_NO_CHECK); } PHALCON_SEPARATE(number_dispatches); increment_function(number_dispatches); PHALCON_INIT_VAR(t10); ZVAL_LONG(t10, 256); PHALCON_INIT_VAR(r12); is_smaller_function(r12, t10, number_dispatches TSRMLS_CC); if (zend_is_true(r12)) { PHALCON_INIT_VAR(c2); ZVAL_STRING(c2, "Dispatcher has detected a cyclic routing causing stability problems", 1); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(this_ptr, "_throwdispatchexception", response, c2, PHALCON_NO_CHECK); } goto ws_e10f_0; we_e10f_0: phalcon_update_property_zval(this_ptr, SL("_returnedValue"), value TSRMLS_CC); phalcon_update_property_zval(this_ptr, SL("_lastController"), controller TSRMLS_CC); RETURN_CHECK_CTOR(controller); }
/** * Internal handler to call a queue of events * * @param \SplPriorityQueue $queue * @param Phalcon\Events\Event $event * @return mixed */ 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); /** * Get the event type */ PHALCON_INIT_VAR(event_name); phalcon_call_method(event_name, event, "gettype"); if (unlikely(Z_TYPE_P(event_name) != IS_STRING)) { PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "The event type not valid"); return; } /** * Get the object who triggered the event */ PHALCON_INIT_VAR(source); phalcon_call_method(source, event, "getsource"); /** * Get extra data passed to the event */ PHALCON_INIT_VAR(data); phalcon_call_method(data, event, "getdata"); /** * Tell if the event is cancelable */ PHALCON_INIT_VAR(cancelable); phalcon_call_method(cancelable, event, "getcancelable"); /** * Responses need to be traced? */ PHALCON_OBS_VAR(collect); phalcon_read_property_this(&collect, this_ptr, SL("_collect"), PH_NOISY_CC); if (Z_TYPE_P(queue) == IS_OBJECT) { /** * We need to clone the queue before iterate over it */ PHALCON_INIT_VAR(iterator); if (phalcon_clone(iterator, queue TSRMLS_CC) == FAILURE) { return; } /** * Move the queue to the top */ phalcon_call_method_noret(iterator, "top"); while (1) { PHALCON_INIT_NVAR(r0); phalcon_call_method(r0, iterator, "valid"); if (zend_is_true(r0)) { } else { break; } /** * Get the current data */ PHALCON_INIT_NVAR(handler); phalcon_call_method(handler, iterator, "current"); /** * Only handler objects are valid */ if (likely(Z_TYPE_P(handler) == IS_OBJECT)) { /** * Check if the event is a closure */ if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) { /** * Create the closure arguments */ 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); } /** * Call the function in the PHP userland */ PHALCON_INIT_NVAR(status); PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments); /** * Trace the response */ if (zend_is_true(collect)) { phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); } if (zend_is_true(cancelable)) { /** * Check if the event was stopped by the user */ PHALCON_INIT_NVAR(is_stopped); phalcon_call_method(is_stopped, event, "isstopped"); if (zend_is_true(is_stopped)) { break; } } } else { /** * Check if the listener has implemented an event with the same name */ if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { /** * Call the function in the PHP userland */ PHALCON_INIT_NVAR(status); phalcon_call_method_zval_p3(status, handler, event_name, event, source, data); /** * Collect the response */ if (zend_is_true(collect)) { phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); } if (zend_is_true(cancelable)) { /** * Check if the event was stopped by the user */ PHALCON_INIT_NVAR(is_stopped); phalcon_call_method(is_stopped, event, "isstopped"); if (zend_is_true(is_stopped)) { break; } } } } } /** * Move the queue to the next handler */ phalcon_call_method_noret(iterator, "next"); } } 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); /** * Only handler objects are valid */ if (likely(Z_TYPE_P(handler) == IS_OBJECT)) { /** * Check if the event is a closure */ if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) { /** * Create the closure arguments */ 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); } /** * Call the function in the PHP userland */ PHALCON_INIT_NVAR(status); PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments); /** * Trace the response */ if (zend_is_true(collect)) { phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); } if (zend_is_true(cancelable)) { /** * Check if the event was stopped by the user */ PHALCON_INIT_NVAR(is_stopped); phalcon_call_method(is_stopped, event, "isstopped"); if (zend_is_true(is_stopped)) { break; } } } else { /** * Check if the listener has implemented an event with the same name */ if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { /** * Call the function in the PHP userland */ PHALCON_INIT_NVAR(status); phalcon_call_method_zval_p3(status, handler, event_name, event, source, data); /** * Collect the response */ if (zend_is_true(collect)) { phalcon_update_property_array_append(this_ptr, SL("_responses"), status TSRMLS_CC); } if (zend_is_true(cancelable)) { /** * Check if the event was stopped by the user */ PHALCON_INIT_NVAR(is_stopped); phalcon_call_method(is_stopped, event, "isstopped"); if (zend_is_true(is_stopped)) { break; } } } } } zend_hash_move_forward_ex(ah0, &hp0); } } RETURN_CCTOR(status); }
/** * Fires a event in the events manager causing that the acive listeners will be notified about it * * @param string $eventType * @param object $source * @return mixed */ PHP_METHOD(Phalcon_Events_Manager, fire){ zval *event_type = NULL, *source = NULL, *colon = NULL, *event_parts = NULL; zval *exception_message = NULL, *exception = NULL, *type = NULL, *event_name = NULL; zval *status = NULL, *events = NULL, *fire_events = NULL, *handler = NULL, *event = NULL; zval *class_name = NULL, *arguments = NULL; HashTable *ah0; HashPosition hp0; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &event_type, &source) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } PHALCON_INIT_VAR(colon); ZVAL_STRING(colon, ":", 1); PHALCON_INIT_VAR(event_parts); phalcon_fast_explode(event_parts, colon, event_type TSRMLS_CC); eval_int = phalcon_array_isset_long(event_parts, 1); if (!eval_int) { PHALCON_INIT_VAR(exception_message); PHALCON_CONCAT_SV(exception_message, "Invalid event type ", event_type); PHALCON_INIT_VAR(exception); object_init_ex(exception, phalcon_events_exception_ce); PHALCON_CALL_METHOD_PARAMS_1_NORETURN(exception, "__construct", exception_message, PH_CHECK); phalcon_throw_exception(exception TSRMLS_CC); return; } PHALCON_INIT_VAR(type); phalcon_array_fetch_long(&type, event_parts, 0, PH_NOISY_CC); PHALCON_INIT_VAR(event_name); phalcon_array_fetch_long(&event_name, event_parts, 1, PH_NOISY_CC); PHALCON_INIT_VAR(status); ZVAL_NULL(status); PHALCON_INIT_VAR(events); phalcon_read_property(&events, this_ptr, SL("_events"), PH_NOISY_CC); eval_int = phalcon_array_isset(events, type); if (eval_int) { PHALCON_INIT_VAR(fire_events); phalcon_array_fetch(&fire_events, events, type, PH_NOISY_CC); if (!phalcon_valid_foreach(fire_events TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(fire_events); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if(zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS){ goto ph_cycle_end_0; } PHALCON_GET_FOREACH_VALUE(handler); if (Z_TYPE_P(handler) == IS_OBJECT) { PHALCON_INIT_VAR(event); object_init_ex(event, phalcon_events_event_ce); PHALCON_CALL_METHOD_PARAMS_2_NORETURN(event, "__construct", event_name, source, PH_CHECK); PHALCON_INIT_VAR(class_name); phalcon_get_class(class_name, handler TSRMLS_CC); if (PHALCON_COMPARE_STRING(class_name, "Closure")) { PHALCON_INIT_VAR(arguments); array_init(arguments); phalcon_array_append(&arguments, event, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&arguments, source, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_VAR(status); PHALCON_CALL_FUNC_PARAMS_2(status, "call_user_func_array", handler, arguments); } else { if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { PHALCON_INIT_VAR(status); PHALCON_CALL_METHOD_PARAMS_2(status, handler, Z_STRVAL_P(event_name), event, source, PH_NO_CHECK); } } } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: if(0){} } RETURN_CCTOR(status); }
/** * Fires a event in the events manager causing that the acive listeners will be notified about it * * @param string $eventType * @param object $source * @param mixed $data * @return mixed */ PHP_METHOD(Phalcon_Events_Manager, fire){ zval *event_type, *source, *data = NULL, *events, *exception_message; zval *colon, *event_parts, *type, *event_name, *status = NULL; zval *fire_events = NULL, *handler = NULL, *event = NULL, *arguments = NULL; HashTable *ah0, *ah1; HashPosition hp0, hp1; zval **hd; int eval_int; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &event_type, &source, &data) == FAILURE) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!data) { PHALCON_INIT_NVAR(data); } if (Z_TYPE_P(event_type) != IS_STRING) { PHALCON_THROW_EXCEPTION_STR(phalcon_events_exception_ce, "Event type must be a string"); return; } PHALCON_INIT_VAR(events); phalcon_read_property(&events, this_ptr, SL("_events"), PH_NOISY_CC); if (Z_TYPE_P(events) != IS_ARRAY) { PHALCON_MM_RESTORE(); RETURN_NULL(); } if (!phalcon_memnstr_str(event_type, SL(":") TSRMLS_CC)) { 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(colon); ZVAL_STRING(colon, ":", 1); PHALCON_INIT_VAR(event_parts); phalcon_fast_explode(event_parts, colon, event_type TSRMLS_CC); PHALCON_INIT_VAR(type); phalcon_array_fetch_long(&type, event_parts, 0, PH_NOISY_CC); PHALCON_INIT_VAR(event_name); phalcon_array_fetch_long(&event_name, event_parts, 1, PH_NOISY_CC); PHALCON_INIT_VAR(status); eval_int = phalcon_array_isset(events, type); if (eval_int) { PHALCON_INIT_VAR(fire_events); phalcon_array_fetch(&fire_events, events, type, PH_NOISY_CC); if (Z_TYPE_P(fire_events) == IS_ARRAY) { if (!phalcon_valid_foreach(fire_events TSRMLS_CC)) { return; } ah0 = Z_ARRVAL_P(fire_events); zend_hash_internal_pointer_reset_ex(ah0, &hp0); ph_cycle_start_0: if (zend_hash_get_current_data_ex(ah0, (void**) &hd, &hp0) != SUCCESS) { goto ph_cycle_end_0; } PHALCON_GET_FOREACH_VALUE(handler); if (Z_TYPE_P(handler) == IS_OBJECT) { if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) { PHALCON_INIT_NVAR(event); object_init_ex(event, phalcon_events_event_ce); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(event, "__construct", event_name, source, data, PH_CHECK); PHALCON_INIT_NVAR(arguments); array_init(arguments); phalcon_array_append(&arguments, event, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&arguments, source, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&arguments, data, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_NVAR(status); PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments); } else { if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { PHALCON_INIT_NVAR(event); object_init_ex(event, phalcon_events_event_ce); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(event, "__construct", event_name, source, data, PH_CHECK); PHALCON_INIT_NVAR(status); PHALCON_CALL_METHOD_PARAMS_3(status, handler, Z_STRVAL_P(event_name), event, source, data, PH_NO_CHECK); } } } zend_hash_move_forward_ex(ah0, &hp0); goto ph_cycle_start_0; ph_cycle_end_0: if(0){} } } eval_int = phalcon_array_isset(events, event_type); if (eval_int) { PHALCON_INIT_NVAR(fire_events); phalcon_array_fetch(&fire_events, events, event_type, PH_NOISY_CC); if (Z_TYPE_P(fire_events) == IS_ARRAY) { if (!phalcon_valid_foreach(fire_events TSRMLS_CC)) { return; } ah1 = Z_ARRVAL_P(fire_events); zend_hash_internal_pointer_reset_ex(ah1, &hp1); ph_cycle_start_1: if (zend_hash_get_current_data_ex(ah1, (void**) &hd, &hp1) != SUCCESS) { goto ph_cycle_end_1; } PHALCON_GET_FOREACH_VALUE(handler); if (Z_TYPE_P(handler) == IS_OBJECT) { if (phalcon_is_instance_of(handler, SL("Closure") TSRMLS_CC)) { PHALCON_INIT_NVAR(event); object_init_ex(event, phalcon_events_event_ce); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(event, "__construct", event_name, source, data, PH_CHECK); PHALCON_INIT_NVAR(arguments); array_init(arguments); phalcon_array_append(&arguments, event, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&arguments, source, PH_SEPARATE TSRMLS_CC); phalcon_array_append(&arguments, data, PH_SEPARATE TSRMLS_CC); PHALCON_INIT_NVAR(status); PHALCON_CALL_USER_FUNC_ARRAY(status, handler, arguments); } else { if (phalcon_method_exists(handler, event_name TSRMLS_CC) == SUCCESS) { PHALCON_INIT_NVAR(event); object_init_ex(event, phalcon_events_event_ce); PHALCON_CALL_METHOD_PARAMS_3_NORETURN(event, "__construct", event_name, source, data, PH_CHECK); PHALCON_INIT_NVAR(status); PHALCON_CALL_METHOD_PARAMS_3(status, handler, Z_STRVAL_P(event_name), event, source, data, PH_NO_CHECK); } } } zend_hash_move_forward_ex(ah1, &hp1); goto ph_cycle_start_1; ph_cycle_end_1: if(0){} } } RETURN_CCTOR(status); }
/** * Binds data to the entity * * @param array $data * @param object $entity * @param object $entity * @return Phalcon\Forms\Form */ PHP_METHOD(Phalcon_Forms_Form, bind){ zval *data, *entity, *whitelist = NULL, *elements, *value = NULL; zval *key = NULL, *method = NULL; HashTable *ah0; HashPosition hp0; zval **hd; PHALCON_MM_GROW(); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|z", &data, &entity, &whitelist) == FAILURE) { RETURN_MM_NULL(); } if (!whitelist) { PHALCON_INIT_VAR(whitelist); } /** * The data must be an array */ if (Z_TYPE_P(data) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "The data must be an array"); return; } PHALCON_OBS_VAR(elements); phalcon_read_property(&elements, this_ptr, SL("_elements"), PH_NOISY_CC); if (Z_TYPE_P(elements) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_forms_exception_ce, "There are no elements in the form"); return; } if (!phalcon_is_iterable(data, &ah0, &hp0, 0, 0 TSRMLS_CC)) { 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); if (!phalcon_array_isset(elements, key)) { zend_hash_move_forward_ex(ah0, &hp0); continue; } /** * Use the setter if any available */ PHALCON_INIT_NVAR(method); PHALCON_CONCAT_SV(method, "set", key); if (phalcon_method_exists(entity, method TSRMLS_CC) == SUCCESS) { PHALCON_CALL_METHOD_PARAMS_1_NORETURN(entity, Z_STRVAL_P(method), value); zend_hash_move_forward_ex(ah0, &hp0); continue; } /** * Use the public property if it doesn't have a setter */ phalcon_update_property_zval_zval(entity, key, value TSRMLS_CC); zend_hash_move_forward_ex(ah0, &hp0); } phalcon_update_property_zval(this_ptr, SL("_data"), data TSRMLS_CC); PHALCON_MM_RESTORE(); }