/** * 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); }
/** * 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); }
/** * 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(); }
/** * 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(); }
/** * 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); }
/** * 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); }