/** * 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); }
/** * Phalcon\DI\FactoryDefault\CLI constructor */ PHP_METHOD(Phalcon_DI_FactoryDefault_CLI, __construct){ zval *shared, name = {}, definition = {}; PHALCON_CALL_PARENTW(NULL, phalcon_di_factorydefault_cli_ce, getThis(), "__construct"); shared = &PHALCON_GLOBAL(z_true); ZVAL_STRING(&name, ISV(router)); ZVAL_STRING(&definition, "Phalcon\\CLI\\Router"); PHALCON_CALL_SELFW(NULL, "set", &name, &definition, shared); ZVAL_STRING(&name, ISV(dispatcher)); ZVAL_STRING(&definition, "Phalcon\\CLI\\Dispatcher"); PHALCON_CALL_SELFW(NULL, "set", &name, &definition, shared); }
/** * Create a new Query Builder for Delete * * * @return Phalcon\Mvc\Model\Query\Builder\Delete */ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, createDeleteBuilder){ zval *params = NULL, *_di = NULL, di = {}, service_name = {}; phalcon_fetch_params(0, 0, 2, ¶ms, &_di); if (!params) { params = &PHALCON_GLOBAL(z_null); } if (!_di) { _di = &PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(_di) == IS_OBJECT) { PHALCON_VERIFY_INTERFACEW(_di, phalcon_diinterface_ce); PHALCON_CPY_WRT(&di, _di); } else { PHALCON_CALL_CE_STATICW(&di, phalcon_di_ce, "getdefault", _di); } PHALCON_STR(&service_name, ISV(modelsQueryBuilderForDelete)); PHALCON_CALL_METHODW(return_value, &di, "get", &service_name, &PHALCON_GLOBAL(z_null), &PHALCON_GLOBAL(z_true)); if (Z_TYPE_P(return_value) != IS_OBJECT) { object_init_ex(return_value, phalcon_mvc_model_query_builder_delete_ce); PHALCON_CALL_METHODW(NULL, return_value, "__construct", params); } PHALCON_VERIFY_INTERFACEW(return_value, phalcon_mvc_model_query_builderinterface_ce); }
/** * Gets a param by its name or numeric index * * @param mixed $param * @param string|array $filters * @param mixed $defaultValue * @return mixed */ PHP_METHOD(Phalcon_Http_Request, getParam){ zval *param, *filters = NULL, *default_value = NULL, dependency_injector = {}, service = {}, dispatcher = {}; phalcon_fetch_params(0, 1, 2, ¶m, &filters, &default_value); if (!filters) { filters = &PHALCON_GLOBAL(z_null); } if (!default_value) { default_value = &PHALCON_GLOBAL(z_null); } PHALCON_CALL_METHODW(&dependency_injector, getThis(), "getdi"); if (Z_TYPE(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STRW(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service"); return; } PHALCON_STR(&service, ISV(dispatcher)); PHALCON_CALL_METHODW(&dispatcher, &dependency_injector, "getshared", &service); PHALCON_CALL_METHODW(NULL, &dispatcher, "getparam", param, filters, default_value); }
/** * Checks whether HTTP method is HEAD. if $_SERVER['REQUEST_METHOD']=='HEAD' * * @return boolean */ PHP_METHOD(Phalcon_Http_Request, isHead){ zval head = {}, method = {}; if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { RETURN_BOOL(!strcmp(phalcon_http_request_getmethod_helper(), "HEAD")); } PHALCON_STR(&head, ISV(HEAD)); PHALCON_CALL_METHODW(&method, getThis(), "getmethod"); is_equal_function(return_value, &method, &head); }
/** * Checks whether HTTP method is GET. if $_SERVER['REQUEST_METHOD']=='GET' * * @return boolean */ PHP_METHOD(Phalcon_Http_Request, isGet){ zval get = {}, method = {}; if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { RETURN_BOOL(!strcmp(phalcon_http_request_getmethod_helper(), "GET")); } PHALCON_STR(&get, ISV(GET)); PHALCON_CALL_METHODW(&method, getThis(), "getmethod"); is_equal_function(return_value, &method, &get); }
/** * Checks whether HTTP method is PATCH. if $_SERVER['REQUEST_METHOD']=='PATCH' * * @return boolean */ PHP_METHOD(Phalcon_Http_Request, isPatch){ zval patch = {}, method = {}; if (Z_OBJCE_P(getThis()) == phalcon_http_request_ce) { RETURN_BOOL(!strcmp(phalcon_http_request_getmethod_helper(), "PATCH")); } PHALCON_STR(&patch, ISV(PATCH)); PHALCON_CALL_METHODW(&method, getThis(), "getmethod"); is_equal_function(return_value, &method, &patch); }
/** * Internal get wrapper to filter * * @param string $name * @param string|array $filters * @param mixed $defaultValue * @param boolean $notAllowEmpty * @param boolean $noRecursive * @return mixed */ PHP_METHOD(Phalcon_Http_Request, _get) { zval *data, *name, *filters, *default_value, *not_allow_empty, *norecursive; zval value = {}, dependency_injector = {}, service = {}, filter = {}, filter_value = {}; phalcon_fetch_params(0, 6, 0, &data, &name, &filters, &default_value, ¬_allow_empty, &norecursive); if (Z_TYPE_P(name) != IS_NULL) { if (!phalcon_array_isset_fetch(&value, data, name, 0)) { RETURN_CTORW(default_value); } } else { PHALCON_CPY_WRT_CTOR(&value, data); } if (Z_TYPE_P(filters) != IS_NULL) { phalcon_return_property(&filter, getThis(), SL("_filter")); if (Z_TYPE(filter) != IS_OBJECT) { PHALCON_CALL_METHODW(&dependency_injector, getThis(), "getdi"); if (Z_TYPE(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STRW(phalcon_http_request_exception_ce, "A dependency injection object is required to access the 'filter' service"); return; } PHALCON_STR(&service, ISV(filter)); PHALCON_CALL_METHODW(&filter, &dependency_injector, "getshared", &service); PHALCON_VERIFY_INTERFACEW(&filter, phalcon_filterinterface_ce); phalcon_update_property_zval(getThis(), SL("_filter"), &filter); } PHALCON_CALL_METHODW(&filter_value, &filter, "sanitize", &value, filters, norecursive); if ((PHALCON_IS_EMPTY(&filter_value) && zend_is_true(not_allow_empty)) || PHALCON_IS_FALSE(&filter_value)) { RETURN_CTORW(default_value); } RETURN_CTORW(&filter_value); } if (PHALCON_IS_EMPTY(&value) && zend_is_true(not_allow_empty)) { RETURN_CTORW(default_value); } RETURN_CTORW(&value); }
/** * Returns the query built * * @return Phalcon\Mvc\Model\Query */ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, getQuery){ zval phql = {}, bind_params = {}, bind_types = {}, dependency_injector = {}, service_name = {}, has = {}, args = {}, query = {}; /** * Process the PHQL */ PHALCON_CALL_METHODW(&phql, getThis(), "getphql"); PHALCON_CALL_METHODW(&bind_params, getThis(), "getmergebindparams"); PHALCON_CALL_METHODW(&bind_types, getThis(), "getmergebindtypes"); PHALCON_CALL_METHODW(&dependency_injector, getThis(), "getdi", &PHALCON_GLOBAL(z_true)); PHALCON_STR(&service_name, ISV(modelsQuery)); PHALCON_CALL_METHODW(&has, &dependency_injector, "has", &service_name); if (zend_is_true(&has)) {; array_init(&args); phalcon_array_append(&args, &phql, PH_COPY); phalcon_array_append(&args, &dependency_injector, PH_COPY); PHALCON_CALL_METHODW(&query, &dependency_injector, "get", &service_name, &args); } else { object_init_ex(&query, phalcon_mvc_model_query_ce); PHALCON_CALL_METHODW(NULL, &query, "__construct", &phql, &dependency_injector); } /** * Set default bind params */ if (Z_TYPE(bind_params) == IS_ARRAY) { PHALCON_CALL_METHODW(NULL, &query, "setbindparams", &bind_params); } /** * Set default bind params */ if (Z_TYPE(bind_types) == IS_ARRAY) { PHALCON_CALL_METHODW(NULL, &query, "setbindtypes", &bind_types); } RETURN_CTORW(&query); }
/** * Reads the cookie-related info from the SESSION to restore the cookie as it was set * This method is automatically called internally so normally you don't need to call it * * @return Phalcon\Http\Cookie */ PHP_METHOD(Phalcon_Http_Cookie, restore) { zval *restored, *dependency_injector, service = {}, session = {}, name = {}, key = {}, definition = {}, expire = {}, domain = {}, path = {}, secure = {}, http_only = {}; restored = phalcon_read_property(getThis(), SL("_restored"), PH_NOISY); if (!zend_is_true(restored)) { dependency_injector = phalcon_read_property(getThis(), SL("_dependencyInjector"), PH_NOISY); if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { ZVAL_STRING(&service, ISV(session)); PHALCON_CALL_METHODW(&session, dependency_injector, "getshared", &service); PHALCON_VERIFY_INTERFACEW(&session, phalcon_session_adapterinterface_ce); phalcon_return_property(&name, getThis(), SL("_name")); PHALCON_CONCAT_SV(&key, "_PHCOOKIE_", &name); PHALCON_CALL_METHODW(&definition, &session, "get", &key); if (Z_TYPE(definition) == IS_ARRAY) { if (phalcon_array_isset_fetch_str(&expire, &definition, SL("expire"))) { phalcon_update_property_this(getThis(), SL("_expire"), &expire); } if (phalcon_array_isset_fetch_str(&domain, &definition, SL("domain"))) { phalcon_update_property_this(getThis(), SL("_domain"), &domain); } if (phalcon_array_isset_fetch_str(&path, &definition, SL("path"))) { phalcon_update_property_this(getThis(), SL("_path"), &path); } if (phalcon_array_isset_fetch_str(&secure, &definition, SL("secure"))) { phalcon_update_property_this(getThis(), SL("_secure"), &secure); } if (phalcon_array_isset_fetch_str(&http_only, &definition, SL("httpOnly"))) { phalcon_update_property_this(getThis(), SL("_httpOnly"), &http_only); } } } phalcon_update_property_bool(getThis(), SL("_restored"), 1); } RETURN_THISW(); }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_Regex, validate){ zval *validator, *attribute, *value = NULL, *allow_empty, *pattern, *valid = NULL, *label, *pairs; zval *message_str, *code, *prepared = NULL, *message; zend_class_entry *ce = Z_OBJCE_P(getThis()); PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 1); PHALCON_CALL_METHOD(&value, validator, "getvalue", attribute); PHALCON_OBS_VAR(allow_empty); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &allow_empty, getThis(), ISV(allowEmpty))); if (zend_is_true(allow_empty) && phalcon_validation_validator_isempty_helper(value)) { RETURN_MM_TRUE; } /* The regular expression is set in the option 'pattern' */ PHALCON_OBS_VAR(pattern); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &pattern, getThis(), "pattern")); PHALCON_CALL_SELF(&valid, "valid", value, pattern); if (PHALCON_IS_FALSE(valid)) { PHALCON_OBS_VAR(label); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &label, getThis(), ISV(label))); if (!zend_is_true(label)) { PHALCON_CALL_METHOD(&label, validator, "getlabel", attribute); if (!zend_is_true(label)) { PHALCON_CPY_WRT(label, attribute); } } PHALCON_ALLOC_INIT_ZVAL(pairs); array_init_size(pairs, 1); Z_TRY_ADDREF_P(label); add_assoc_zval_ex(pairs, SL(":field"), label); PHALCON_OBS_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &message_str, getThis(), ISV(message))); if (!zend_is_true(message_str)) { PHALCON_OBSERVE_OR_NULLIFY_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(Z_OBJCE_P(validator), message_str, validator, "Regex")); } PHALCON_OBS_VAR(code); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &code, getThis(), ISV(code))); if (Z_TYPE_P(code) == IS_NULL) { ZVAL_LONG(code, 0); } PHALCON_CALL_FUNCTION(&prepared, "strtr", message_str, pairs); message = phalcon_validation_message_construct_helper(prepared, attribute, "Regex", code); Z_TRY_DELREF_P(message); PHALCON_CALL_METHOD(NULL, validator, "appendmessage", message); RETURN_MM_FALSE; } RETURN_MM_TRUE; }
/** * Create a new Query Builder of the given type. * *<code> * Phalcon\Mvc\Model\Query\Builder::create(Phalcon\Mvc\Model\Query::TYPE_SELECT); *</code> * * @return Phalcon\Mvc\Model\Query\Builder */ PHP_METHOD(Phalcon_Mvc_Model_Query_Builder, create){ zval *type, *params = NULL, *_di = NULL, di = {}, service_name = {}, has = {}, exception_message = {}; phalcon_fetch_params(0, 1, 2, &type, ¶ms, &_di); if (!params) { params = &PHALCON_GLOBAL(z_null); } if (!_di) { _di = &PHALCON_GLOBAL(z_null); } if (Z_TYPE_P(_di) == IS_OBJECT) { PHALCON_VERIFY_INTERFACEW(_di, phalcon_diinterface_ce); PHALCON_CPY_WRT(&di, _di); } else { PHALCON_CALL_CE_STATICW(&di, phalcon_di_ce, "getdefault", _di); } switch (phalcon_get_intval(type)) { case PHQL_T_SELECT: PHALCON_STR(&service_name, ISV(modelsQueryBuilderForSelect)); PHALCON_CALL_METHODW(&has, &di, "has", &service_name); if (zend_is_true(&has)) { PHALCON_CALL_METHODW(return_value, &di, "get", &service_name); } else { object_init_ex(return_value, phalcon_mvc_model_query_builder_select_ce); } PHALCON_CALL_METHODW(NULL, return_value, "__construct", params); break; case PHQL_T_INSERT: PHALCON_STR(&service_name, ISV(modelsQueryBuilderForInsert)); PHALCON_CALL_METHODW(&has, &di, "has", &service_name); if (zend_is_true(&has)) { PHALCON_CALL_METHODW(return_value, &di, "get", &service_name, params); } else { object_init_ex(return_value, phalcon_mvc_model_query_builder_insert_ce); } PHALCON_CALL_METHODW(NULL, return_value, "__construct", params); break; case PHQL_T_UPDATE: PHALCON_STR(&service_name, ISV(modelsQueryBuilderForUpdate)); PHALCON_CALL_METHODW(&has, &di, "has", &service_name); if (zend_is_true(&has)) { PHALCON_CALL_METHODW(return_value, &di, "get", &service_name, params); } else { object_init_ex(return_value, phalcon_mvc_model_query_builder_delete_ce); } PHALCON_CALL_METHODW(NULL, return_value, "__construct", params); break; case PHQL_T_DELETE: PHALCON_STR(&service_name, ISV(modelsQueryBuilderForDelete)); PHALCON_CALL_METHODW(&has, &di, "has", &service_name); if (zend_is_true(&has)) { PHALCON_CALL_METHODW(return_value, &di, "get", &service_name, params); } else { object_init_ex(return_value, phalcon_mvc_model_query_builder_delete_ce); } PHALCON_CALL_METHODW(NULL, return_value, "__construct", params); break; default: PHALCON_CONCAT_SV(&exception_message, "Not found builder: ", type); PHALCON_THROW_EXCEPTION_ZVALW(phalcon_mvc_model_query_exception_ce, &exception_message); return; } PHALCON_VERIFY_INTERFACEW(return_value, phalcon_mvc_model_query_builderinterface_ce); }
/** * Sends the cookie to the HTTP client * Stores the cookie definition in session * * @return Phalcon\Http\Cookie */ PHP_METHOD(Phalcon_Http_Cookie, send){ zval *name, *value, *expire, *domain, *path, *secure, *http_only, *dependency_injector; zval service = {}, has_session = {}, definition = {}, session = {}, key = {}, encryption = {}, crypt = {}, encrypt_value = {}; name = phalcon_read_property(getThis(), SL("_name"), PH_NOISY); value = phalcon_read_property(getThis(), SL("_value"), PH_NOISY); expire = phalcon_read_property(getThis(), SL("_expire"), PH_NOISY); domain = phalcon_read_property(getThis(), SL("_domain"), PH_NOISY); path = phalcon_read_property(getThis(), SL("_path"), PH_NOISY); secure = phalcon_read_property(getThis(), SL("_secure"), PH_NOISY); http_only = phalcon_read_property(getThis(), SL("_httpOnly"), PH_NOISY); dependency_injector = phalcon_read_property(getThis(), SL("_dependencyInjector"), PH_NOISY); if (Z_TYPE_P(dependency_injector) == IS_OBJECT) { ZVAL_STRING(&service, ISV(session)); PHALCON_CALL_METHODW(&has_session, dependency_injector, "has", &service); if (zend_is_true(&has_session)) { array_init(&definition); if (!PHALCON_IS_LONG(expire, 0)) { phalcon_array_update_str(&definition, SL("expire"), expire, PH_COPY); } if (PHALCON_IS_NOT_EMPTY(path)) { phalcon_array_update_str(&definition, SL("path"), path, PH_COPY); } if (PHALCON_IS_NOT_EMPTY(domain)) { phalcon_array_update_string(&definition, IS(domain), domain, PH_COPY); } if (PHALCON_IS_NOT_EMPTY(secure)) { phalcon_array_update_str(&definition, SL("secure"), secure, PH_COPY); } if (PHALCON_IS_NOT_EMPTY(http_only)) { phalcon_array_update_str(&definition, SL("httpOnly"), http_only, PH_COPY); } /** * The definition is stored in session */ if (phalcon_fast_count_ev(&definition)) { PHALCON_CALL_METHODW(&session, dependency_injector, "getshared", &service); if (Z_TYPE(session) != IS_NULL) { PHALCON_VERIFY_INTERFACEW(&session, phalcon_session_adapterinterface_ce); PHALCON_CONCAT_SV(&key, "_PHCOOKIE_", name); PHALCON_CALL_METHODW(NULL, &session, "set", &key, &definition); } } } } phalcon_return_property(&encryption, getThis(), SL("_useEncryption")); if (zend_is_true(&encryption) && PHALCON_IS_NOT_EMPTY(value)) { if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STRW(phalcon_http_cookie_exception_ce, "A dependency injection object is required to access the 'filter' service"); return; } ZVAL_STRING(&service, "crypt"); PHALCON_CALL_METHODW(&crypt, dependency_injector, "getshared", &service); PHALCON_VERIFY_INTERFACEW(&crypt, phalcon_cryptinterface_ce); /** * Encrypt the value also coding it with base64 */ PHALCON_CALL_METHODW(&encrypt_value, &crypt, "encryptbase64", value); } else { PHALCON_CPY_WRT_CTOR(&encrypt_value, value); } /** * Sets the cookie using the standard 'setcookie' function */ convert_to_string_ex(name); convert_to_long_ex(expire); convert_to_string_ex(domain); convert_to_string_ex(path); convert_to_long_ex(secure); convert_to_long_ex(http_only); convert_to_string_ex(&encrypt_value); php_setcookie(Z_STR_P(name), Z_STR(encrypt_value), Z_LVAL_P(expire), Z_STR_P(path), Z_STR_P(domain), Z_LVAL_P(secure), 1, Z_LVAL_P(http_only)); RETURN_THISW(); }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_StringLength, validate){ zval *validator, *attribute, *value = NULL, *allow_empty; zval *valid = NULL, *type, *maximum, *minimum, *label; zval *code, *pairs, *message_str = NULL, *prepared = NULL, *message; zend_class_entry *ce = Z_OBJCE_P(getThis()); PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 1); PHALCON_CALL_METHOD(&value, validator, "getvalue", attribute); PHALCON_OBS_VAR(allow_empty); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &allow_empty, getThis(), ISV(allowEmpty))); if (zend_is_true(allow_empty) && phalcon_validation_validator_isempty_helper(value)) { RETURN_MM_TRUE; } PHALCON_OBS_VAR(maximum); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &maximum, getThis(), "max")); PHALCON_OBS_VAR(minimum); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &minimum, getThis(), "min")); PHALCON_CALL_SELF(&valid, "valid", value, minimum, maximum); if (PHALCON_IS_FALSE(valid)) { type = phalcon_read_property(getThis(), SL("_type"), PH_NOISY); PHALCON_OBS_VAR(label); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &label, getThis(), ISV(label))); if (!zend_is_true(label)) { PHALCON_CALL_METHOD(&label, validator, "getlabel", attribute); if (!zend_is_true(label)) { PHALCON_CPY_WRT(label, attribute); } } PHALCON_OBS_VAR(code); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &code, getThis(), ISV(code))); if (Z_TYPE_P(code) == IS_NULL) { ZVAL_LONG(code, 0); } if (phalcon_compare_strict_string(type, SL("TooLong"))) { PHALCON_ALLOC_INIT_ZVAL(pairs); array_init_size(pairs, 2); Z_TRY_ADDREF_P(label); add_assoc_zval_ex(pairs, SL(":field"), label); Z_TRY_ADDREF_P(maximum); add_assoc_zval_ex(pairs, SL(":max"), maximum); PHALCON_OBS_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &message_str, getThis(), "messageMaximum")); if (!zend_is_true(message_str)) { PHALCON_OBSERVE_OR_NULLIFY_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(Z_OBJCE_P(validator), message_str, validator, "TooLong")); } PHALCON_CALL_FUNCTION(&prepared, "strtr", message_str, pairs); message = phalcon_validation_message_construct_helper(prepared, attribute, "TooLong", code); } else { PHALCON_ALLOC_INIT_ZVAL(pairs); array_init_size(pairs, 2); Z_TRY_ADDREF_P(label); add_assoc_zval_ex(pairs, SL(":field"), label); Z_TRY_ADDREF_P(minimum); add_assoc_zval_ex(pairs, SL(":min"), minimum); PHALCON_OBS_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &message_str, getThis(), "messageMinimum")); if (!zend_is_true(message_str)) { PHALCON_OBSERVE_OR_NULLIFY_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(Z_OBJCE_P(validator), message_str, validator, "TooShort")); } PHALCON_CALL_FUNCTION(&prepared, "strtr", message_str, pairs); message = phalcon_validation_message_construct_helper(prepared, attribute, "TooShort", code); } Z_TRY_DELREF_P(message); PHALCON_CALL_METHOD(NULL, validator, "appendmessage", message); RETURN_MM_FALSE; } RETURN_MM_TRUE; }
/** * Handle the command-line arguments. * * * <code> * $arguments = array( * 'task' => 'taskname', * 'action' => 'action', * 'params' => array('parameter1', 'parameter2') * ); * $console->handle($arguments); * </code> * * @param array $arguments * @return mixed */ PHP_METHOD(Phalcon_CLI_Console, handle){ zval *_arguments = NULL, arguments = {}, dependency_injector = {}, events_manager = {}, event_name = {}, service = {}, router = {}, module_name = {}; zval status = {}, modules = {}, exception_msg = {}, module = {}, path = {}, class_name = {}, module_object = {}; zval namespace_name = {}, task_name = {}, action_name = {}, params = {}, dispatcher = {}; phalcon_fetch_params(0, 0, 1, &_arguments); if (!_arguments) { array_init(&arguments); } else { PHALCON_CPY_WRT(&arguments, _arguments); } phalcon_return_property(&events_manager, getThis(), SL("_eventsManager")); ZVAL_STRING(&service, ISV(router)); PHALCON_CALL_METHODW(&dependency_injector, getThis(), "getdi"); if (Z_TYPE(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_FORMATW(phalcon_cli_console_exception_ce, "A dependency injection container is required to access the '%s' service", Z_STRVAL(service)); return; } PHALCON_CALL_METHODW(&router, &dependency_injector, "getshared", &service); PHALCON_VERIFY_CLASSW(&router, phalcon_cli_router_ce); PHALCON_CALL_METHODW(NULL, &router, "handle", &arguments); PHALCON_CALL_METHODW(&module_name, &router, "getmodulename"); if (zend_is_true(&module_name)) { if (Z_TYPE(events_manager) == IS_OBJECT) { ZVAL_STRING(&event_name, "console:beforeStartModule"); PHALCON_CALL_METHODW(&status, &events_manager, "fire", &event_name, getThis(), &module_name); if (PHALCON_IS_FALSE(&status)) { RETURN_FALSE; } } phalcon_read_property(&modules, getThis(), SL("_modules"), PH_NOISY); if (!phalcon_array_isset_fetch(&module, &modules, &module_name, 0)) { PHALCON_CONCAT_SVS(&exception_msg, "Module '", &module_name, "' isn't registered in the console container"); PHALCON_THROW_EXCEPTION_ZVALW(phalcon_cli_console_exception_ce, &exception_msg); return; } if (Z_TYPE_P(&module) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STRW(phalcon_cli_console_exception_ce, "Invalid module definition path"); return; } if (phalcon_array_isset_fetch_str(&path, &module, SL("path"))) { convert_to_string_ex(&path); if (phalcon_file_exists(&path) == SUCCESS) { RETURN_ON_FAILURE(phalcon_require(Z_STRVAL(path))); } else { zend_throw_exception_ex(phalcon_cli_console_exception_ce, 0, "Modules definition path '%s' does not exist", Z_STRVAL(path)); return; } } if (!phalcon_array_isset_fetch_str(&class_name, &module, SL("className"))) { ZVAL_STRING(&class_name, "Module"); } PHALCON_CALL_METHODW(&module_object, &dependency_injector, "getshared", &class_name); PHALCON_CALL_METHODW(NULL, &module_object, "registerautoloaders"); PHALCON_CALL_METHODW(NULL, &module_object, "registerservices", &dependency_injector); if (Z_TYPE(events_manager) == IS_OBJECT) { phalcon_update_property_zval(getThis(), SL("_moduleObject"), &module_object); ZVAL_STRING(&event_name, "console:afterStartModule"); PHALCON_CALL_METHODW(&status, &events_manager, "fire", &event_name, getThis(), &module_name); if (PHALCON_IS_FALSE(&status)) { RETURN_FALSE; } } } PHALCON_CALL_METHODW(&namespace_name, &router, "getnamespacename"); PHALCON_CALL_METHODW(&task_name, &router, "gettaskname"); PHALCON_CALL_METHODW(&action_name, &router, "getactionname"); PHALCON_CALL_METHODW(¶ms, &router, "getparams"); ZVAL_STRING(&service, ISV(dispatcher)); PHALCON_CALL_METHODW(&dispatcher, &dependency_injector, "getshared", &service); PHALCON_VERIFY_INTERFACEW(&dispatcher, phalcon_dispatcherinterface_ce); PHALCON_CALL_METHODW(NULL, &dispatcher, "setnamespacename", &namespace_name); PHALCON_CALL_METHODW(NULL, &dispatcher, "settaskname", &task_name); PHALCON_CALL_METHODW(NULL, &dispatcher, "setactionname", &action_name); PHALCON_CALL_METHODW(NULL, &dispatcher, "setparams", ¶ms); if (Z_TYPE(events_manager) == IS_OBJECT) { ZVAL_STRING(&event_name, "console:beforeHandleTask"); PHALCON_CALL_METHODW(&status, &events_manager, "fire", &event_name, getThis(), &dispatcher); if (PHALCON_IS_FALSE(&status)) { RETURN_FALSE; } } PHALCON_CALL_METHODW(&status, &dispatcher, "dispatch"); if (Z_TYPE(events_manager) == IS_OBJECT) { ZVAL_STRING(&event_name, "console:afterHandleTask"); PHALCON_CALL_METHODW(NULL, &events_manager, "fire", &event_name, getThis(), &status); } RETURN_CTORW(&status); }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_File, validate) { zval *validator, *attribute, value = {}, allow_empty = {}, mimes = {}, minsize = {}, maxsize = {}, minwidth = {}, maxwidth = {}, minheight = {}, maxheight = {}; zval valid = {}, type = {}, code = {}, message_str = {}, message = {}, join_mimes = {}, label = {}, pairs = {}, prepared = {}; zend_class_entry *ce = Z_OBJCE_P(getThis()); phalcon_fetch_params(0, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 0); PHALCON_CALL_METHODW(&value, validator, "getvalue", attribute); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&allow_empty, ce, getThis(), ISV(allowEmpty))); if (zend_is_true(&allow_empty) && phalcon_validation_validator_isempty_helper(&value)) { RETURN_TRUE; } RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&mimes, ce, getThis(), "mimes")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minsize, ce, getThis(), "minsize")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maxsize, ce, getThis(), "maxsize")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minwidth, ce, getThis(), "minwidth")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maxwidth, ce, getThis(), "maxwidth")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&minheight, ce, getThis(), "minheight")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&maxheight, ce, getThis(), "maxheight")); PHALCON_CALL_SELFW(&valid, "valid", &value, &minsize, &maxsize, &mimes, &minwidth, &maxwidth, &minheight, &maxheight); if (PHALCON_IS_FALSE(&valid)) { phalcon_return_property(&type, getThis(), SL("_type")); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&label, ce, getThis(), ISV(label))); if (!zend_is_true(&label)) { PHALCON_CALL_METHODW(&label, validator, "getlabel", attribute); if (!zend_is_true(&label)) { PHALCON_CPY_WRT_CTOR(&label, attribute); } } RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&code, ce, getThis(), ISV(code))); if (Z_TYPE(code) == IS_NULL) { ZVAL_LONG(&code, 0); } array_init(&pairs); phalcon_array_update_str(&pairs, SL(":field"), &label, PH_COPY); if (phalcon_compare_strict_string(&type, SL("TooLarge"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxsize, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileMaxSize")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooLarge", &code); } else if (phalcon_compare_strict_string(&type, SL("TooSmall"))) { phalcon_array_update_str(&pairs, SL(":min"), &minsize, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileMinSize")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooSmall", &code); } else if (phalcon_compare_strict_string(&type, SL("MimeValid"))) { phalcon_fast_join_str(&join_mimes, SL(", "), &mimes); phalcon_array_update_str(&pairs, SL(":mimes"), &join_mimes, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileType")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "FileType", &code); } else if (phalcon_compare_strict_string(&type, SL("TooLarge"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxsize, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileMaxSize")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooLarge", &code); } else if (phalcon_compare_strict_string(&type, SL("TooNarrow"))) { phalcon_array_update_str(&pairs, SL(":min"), &minwidth, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMinWidth")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooNarrow", &code); } else if (phalcon_compare_strict_string(&type, SL("TooWide"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxwidth, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMaxWidth")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooWide", &code); } else if (phalcon_compare_strict_string(&type, SL("TooShort"))) { phalcon_array_update_str(&pairs, SL(":min"), &minheight, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMinHeight")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooShort", &code); } else if (phalcon_compare_strict_string(&type, SL("TooLong"))) { phalcon_array_update_str(&pairs, SL(":max"), &maxheight, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "ImageMaxHeight")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "TooLong", &code); } else { RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "FileValid")); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "File", &code); } PHALCON_CALL_METHODW(NULL, validator, "appendmessage", &message); RETURN_FALSE; } RETURN_TRUE; }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_InclusionIn, validate){ zval *validator, *attribute, *value = NULL, *allow_empty, *valid = NULL; zval *label, *domain, *joined_domain, *pairs, *message_str, *message, *code; zval *prepared = NULL; zend_class_entry *ce = Z_OBJCE_P(getThis()); PHALCON_MM_GROW(); phalcon_fetch_params(1, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 1); PHALCON_CALL_METHOD(&value, validator, "getvalue", attribute); PHALCON_OBS_VAR(allow_empty); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &allow_empty, getThis(), ISV(allowEmpty))); if (zend_is_true(allow_empty) && phalcon_validation_validator_isempty_helper(value)) { RETURN_MM_TRUE; } /* A domain is an array with a list of valid values */ PHALCON_OBS_VAR(domain); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &domain, getThis(), ISV(domain))); if (Z_TYPE_P(domain) != IS_ARRAY) { PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "Option 'domain' must be an array"); return; } PHALCON_CALL_SELF(&valid, "valid", value, domain); if (PHALCON_IS_FALSE(valid)) { PHALCON_OBS_VAR(label); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &label, getThis(), ISV(label))); if (!zend_is_true(label)) { PHALCON_CALL_METHOD(&label, validator, "getlabel", attribute); if (!zend_is_true(label)) { PHALCON_CPY_WRT(label, attribute); } } PHALCON_ALLOC_INIT_ZVAL(joined_domain); phalcon_fast_join_str(joined_domain, SL(", "), domain); PHALCON_ALLOC_INIT_ZVAL(pairs); array_init_size(pairs, 2); Z_TRY_ADDREF_P(label); add_assoc_zval_ex(pairs, SL(":field"), label); add_assoc_zval_ex(pairs, SL(":domain"), joined_domain); PHALCON_OBS_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &message_str, getThis(), ISV(message))); if (!zend_is_true(message_str)) { PHALCON_OBSERVE_OR_NULLIFY_VAR(message_str); RETURN_MM_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(Z_OBJCE_P(validator), message_str, validator, "InclusionIn")); } PHALCON_OBS_VAR(code); RETURN_MM_ON_FAILURE(phalcon_validation_validator_getoption_helper(ce, &code, getThis(), ISV(code))); if (Z_TYPE_P(code) == IS_NULL) { ZVAL_LONG(code, 0); } PHALCON_CALL_FUNCTION(&prepared, "strtr", message_str, pairs); message = phalcon_validation_message_construct_helper(prepared, attribute, "InclusionIn", code); Z_TRY_DELREF_P(message); PHALCON_CALL_METHOD(NULL, validator, "appendmessage", message); RETURN_MM_FALSE; } RETURN_MM_TRUE; }
/** * Executes the validation * * @param Phalcon\Validation $validator * @param string $attribute * @return boolean */ PHP_METHOD(Phalcon_Validation_Validator_Numericality, validate){ zval *validator, *attribute, value = {}, allow_empty = {}, valid = {}, label = {}, pairs = {}, message_str = {}, code = {}, prepared = {}, message = {}; zend_class_entry *ce = Z_OBJCE_P(getThis()); phalcon_fetch_params(0, 2, 0, &validator, &attribute); PHALCON_VERIFY_CLASS_EX(validator, phalcon_validation_ce, phalcon_validation_exception_ce, 0); PHALCON_CALL_METHODW(&value, validator, "getvalue", attribute); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&allow_empty, ce, getThis(), ISV(allowEmpty))); if (zend_is_true(&allow_empty) && phalcon_validation_validator_isempty_helper(&value)) { RETURN_TRUE; } PHALCON_CALL_SELFW(&valid, "valid", &value); if (PHALCON_IS_FALSE(&valid)) { RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&label, ce, getThis(), ISV(label))); if (!zend_is_true(&label)) { PHALCON_CALL_METHODW(&label, validator, "getlabel", attribute); if (!zend_is_true(&label)) { PHALCON_CPY_WRT_CTOR(&label, attribute); } } array_init_size(&pairs, 1); phalcon_array_update_str(&pairs, SL(":field"), &label, PH_COPY); RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&message_str, ce, getThis(), ISV(message))); if (!zend_is_true(&message_str)) { RETURN_ON_FAILURE(phalcon_validation_getdefaultmessage_helper(&message_str, Z_OBJCE_P(validator), validator, "Numericality")); } RETURN_ON_FAILURE(phalcon_validation_validator_getoption_helper(&code, ce, getThis(), ISV(code))); if (Z_TYPE(code) == IS_NULL) { ZVAL_LONG(&code, 0); } PHALCON_CALL_FUNCTIONW(&prepared, "strtr", &message_str, &pairs); phalcon_validation_message_construct_helper(&message, &prepared, attribute, "Numericality", &code); PHALCON_CALL_METHODW(NULL, validator, "appendmessage", &message); RETURN_FALSE; } RETURN_TRUE; }
/** * Deletes the cookie by setting an expire time in the past * */ PHP_METHOD(Phalcon_Http_Cookie, delete) { zval *name, *domain, *path, *secure, *http_only, service = {}, session = {}, key = {}; name = phalcon_read_property(getThis(), SL("_name"), PH_NOISY); domain = phalcon_read_property(getThis(), SL("_domain"), PH_NOISY); path = phalcon_read_property(getThis(), SL("_path"), PH_NOISY); secure = phalcon_read_property(getThis(), SL("_secure"), PH_NOISY); http_only = phalcon_read_property(getThis(), SL("_httpOnly"), PH_NOISY); ZVAL_STRING(&service, ISV(session)); PHALCON_CALL_METHODW(&session, getThis(), "getresolveservice", &service); PHALCON_VERIFY_INTERFACEW(&session, phalcon_session_adapterinterface_ce); PHALCON_CONCAT_SV(&key, "_PHCOOKIE_", name); PHALCON_CALL_METHODW(NULL, &session, "remove", &key); phalcon_update_property_null(getThis(), SL("_value")); convert_to_string_ex(name); convert_to_string_ex(path); convert_to_string_ex(domain); convert_to_long_ex(secure); convert_to_long_ex(http_only);
/** * Returns the cookie's value * * @param string|array $filters * @param string $defaultValue * @return mixed */ PHP_METHOD(Phalcon_Http_Cookie, getValue) { zval *filters = NULL, *default_value = NULL, *restored, *dependency_injector = NULL, *readed, *name, *_COOKIE, value = {}, *encryption; zval service = {}, crypt = {}, decrypted_value = {}, filter = {}; phalcon_fetch_params(0, 0, 2, &filters, &default_value); if (!filters) { filters = &PHALCON_GLOBAL(z_null); } if (!default_value) { default_value = &PHALCON_GLOBAL(z_null); } restored = phalcon_read_property(getThis(), SL("_restored"), PH_NOISY); if (!zend_is_true(restored)) { PHALCON_CALL_METHODW(NULL, getThis(), "restore"); } dependency_injector = phalcon_read_property(getThis(), SL("_dependencyInjector"), PH_NOISY); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STRW(phalcon_http_cookie_exception_ce, "A dependency injection object is required to access the 'filter' service"); return; } readed = phalcon_read_property(getThis(), SL("_readed"), PH_NOISY); if (PHALCON_IS_FALSE(readed)) { name = phalcon_read_property(getThis(), SL("_name"), PH_NOISY); _COOKIE = phalcon_get_global_str(SL("_COOKIE")); if (phalcon_array_isset_fetch(&value, _COOKIE, name)) { encryption = phalcon_read_property(getThis(), SL("_useEncryption"), PH_NOISY); if (zend_is_true(encryption) && PHALCON_IS_NOT_EMPTY(&value)) { ZVAL_STRING(&service, "crypt"); PHALCON_CALL_METHODW(&crypt, dependency_injector, "getshared", &service); PHALCON_VERIFY_INTERFACEW(&crypt, phalcon_cryptinterface_ce); /** * Decrypt the value also decoding it with base64 */ PHALCON_CALL_METHODW(&decrypted_value, &crypt, "decryptbase64", &value); } else { PHALCON_CPY_WRT_CTOR(&decrypted_value, &value); } /** * Update the decrypted value */ phalcon_update_property_this(getThis(), SL("_value"), &decrypted_value); if (Z_TYPE_P(filters) != IS_NULL) { phalcon_return_property(&filter, getThis(), SL("_filter")); if (Z_TYPE(filter) != IS_OBJECT) { ZVAL_STRING(&service, ISV(filter)); PHALCON_CALL_METHODW(&filter, dependency_injector, "getshared", &service); PHALCON_VERIFY_INTERFACEW(&filter, phalcon_filterinterface_ce); phalcon_update_property_this(getThis(), SL("_filter"), &filter); } PHALCON_RETURN_CALL_METHOD(&filter, "sanitize", &decrypted_value, filters); return; } /** * Return the value without filtering */ RETURN_CTORW(&decrypted_value); } RETURN_CTORW(default_value); } phalcon_return_property(&value, getThis(), SL("_value")); RETURN_CTORW(&value); }