/** * Phalcon\Cache\Backend\Memcache constructor * * @param Phalcon\Cache\FrontendInterface $frontend * @param array $options */ PHP_METHOD(Phalcon_Cache_Backend_Memcache, __construct){ zval *frontend, *opts = NULL, options = {}; phalcon_fetch_params(0, 1, 1, &frontend, &opts); if (opts) { PHALCON_CPY_WRT(&options, opts); } if (Z_TYPE(options) != IS_ARRAY) { array_init_size(&options, 4); } if (!phalcon_array_isset_str(&options, SL("host"))) { phalcon_array_update_str_str(&options, SL("host"), SL("127.0.0.1"), PH_COPY); } if (!phalcon_array_isset_str(&options, SL("port"))) { phalcon_array_update_str_long(&options, SL("port"), 11211, 0); } if (!phalcon_array_isset_str(&options, SL("persistent"))) { phalcon_array_update_str_bool(&options, SL("persistent"), 0, 0); } if (!phalcon_array_isset_str(&options, SL("statsKey"))) { phalcon_array_update_str_str(&options, SL("statsKey"), SL("_PHCM"), PH_COPY); } PHALCON_CALL_PARENTW(NULL, phalcon_cache_backend_memcache_ce, getThis(), "__construct", frontend, &options); }
/** * Phalcon\Flash constructor * * @param array $cssClasses */ PHP_METHOD(Phalcon_Flash, __construct){ zval *css_classes = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 0, 1, &css_classes); if (!css_classes) { PHALCON_INIT_VAR(css_classes); } else { PHALCON_SEPARATE_PARAM(css_classes); } if (Z_TYPE_P(css_classes) != IS_ARRAY) { PHALCON_INIT_NVAR(css_classes); array_init_size(css_classes, 4); phalcon_array_update_str_str(css_classes, SL("error"), SL("errorMessage"), PH_COPY); phalcon_array_update_str_str(css_classes, SL("notice"), SL("noticeMessage"), PH_COPY); phalcon_array_update_str_str(css_classes, SL("success"), SL("successMessage"), PH_COPY); phalcon_array_update_str_str(css_classes, SL("warning"), SL("warningMessage"), PH_COPY); } phalcon_update_property_this(getThis(), SL("_cssClasses"), css_classes); PHALCON_MM_RESTORE(); }
/** * Phalcon\Cache\Backend\Xcache constructor * * @param Phalcon\Cache\FrontendInterface $frontend * @param array $options */ PHP_METHOD(Phalcon_Cache_Backend_Xcache, __construct){ zval *frontend, *options = NULL; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &frontend, &options); if (!options) { PHALCON_INIT_VAR(options); } else { PHALCON_SEPARATE_PARAM(options); } if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_INIT_NVAR(options); array_init(options); } if (!phalcon_array_isset_str(options, SL("statsKey"))) { phalcon_array_update_str_str(options, SL("statsKey"), SL("_PHCX"), PH_COPY); } PHALCON_CALL_PARENT(NULL, phalcon_cache_backend_xcache_ce, getThis(), "__construct", frontend, options); PHALCON_MM_RESTORE(); }
/** * Phalcon\Cache\Backend\Libmemcached constructor * * @param Phalcon\Cache\FrontendInterface $frontend * @param array $options */ PHP_METHOD(Phalcon_Cache_Backend_Libmemcached, __construct){ zval *frontend, *options = NULL, *server, *servers; PHALCON_MM_GROW(); phalcon_fetch_params(1, 1, 1, &frontend, &options); if (!options) { PHALCON_INIT_VAR(options); } else { PHALCON_SEPARATE_PARAM(options); } if (Z_TYPE_P(options) != IS_ARRAY) { PHALCON_INIT_NVAR(options); array_init(options); } if (!phalcon_array_isset_str(options, SL("servers"))) { PHALCON_INIT_VAR(servers); array_init_size(servers, 1); PHALCON_INIT_VAR(server); array_init_size(server, 3); phalcon_array_update_str_str(server, SL("host"), SL("127.0.0.1"), PH_COPY); phalcon_array_update_str_long(server, SL("port"), 11211, PH_COPY); phalcon_array_update_str_long(server, SL("weight"), 1, PH_COPY); phalcon_array_append(servers, server, PH_COPY); phalcon_array_update_str(options, SL("servers"), servers, PH_COPY); } if (!phalcon_array_isset_str(options, SL("statsKey"))) { phalcon_array_update_str_str(options, SL("statsKey"), SL("_PHCM"), PH_COPY); } PHALCON_CALL_PARENT(NULL, phalcon_cache_backend_libmemcached_ce, getThis(), "__construct", frontend, options); PHALCON_MM_RESTORE(); }
/** * Phalcon\Cache\Backend\Xcache constructor * * @param Phalcon\Cache\FrontendInterface $frontend * @param array $options */ PHP_METHOD(Phalcon_Cache_Backend_Xcache, __construct){ zval *frontend, *_options = NULL, options = {}; phalcon_fetch_params(0, 1, 1, &frontend, &_options); if (!_options) { array_init(&options); } else { if (Z_TYPE_P(_options) != IS_ARRAY) { array_init(&options); } else { PHALCON_CPY_WRT(&options, _options); } } if (!phalcon_array_isset_str(&options, SL("statsKey"))) { phalcon_array_update_str_str(&options, SL("statsKey"), SL("_PHCX"), PH_COPY); } PHALCON_CALL_PARENTW(NULL, phalcon_cache_backend_xcache_ce, getThis(), "__construct", frontend, &options); }
/** * Phalcon\Mvc\Model\MetaData\Libmemcached constructor * * @param array $options */ PHP_METHOD(Phalcon_Mvc_Model_MetaData_Libmemcached, __construct){ zval *options = NULL; zval *servers, *client, *lifetime, *prefix; zval *frontend_data, *libmemcached, *option; 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, "The options must be an array"); return; } if (!phalcon_array_isset_str_fetch(&servers, options, SL("servers"))) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_model_exception_ce, "No servers given in options"); return; } if (!phalcon_array_isset_str_fetch(&client, options, SL("client"))) { client = NULL; } if (!phalcon_array_isset_str_fetch(&lifetime, options, SL("lifetime"))) { PHALCON_INIT_VAR(lifetime); ZVAL_LONG(lifetime, 8600); } phalcon_update_property_this(getThis(), SL("_lifetime"), lifetime); if (!phalcon_array_isset_str_fetch(&prefix, options, SL("prefix"))) { PHALCON_INIT_VAR(prefix); ZVAL_EMPTY_STRING(prefix); } /* create libmemcached instance */ PHALCON_INIT_VAR(option); array_init_size(option, 1); phalcon_array_update_str(option, SL("lifetime"), lifetime, PH_COPY); PHALCON_INIT_VAR(frontend_data); object_init_ex(frontend_data, phalcon_cache_frontend_data_ce); PHALCON_CALL_METHOD(NULL, frontend_data, "__construct", option); PHALCON_INIT_NVAR(option); array_init(option); phalcon_array_update_str_str(option, SL("statsKey"), SL("$PMM$"), PH_COPY); phalcon_array_update_str(option, SL("servers"), servers, PH_COPY); if (client) { phalcon_array_update_str(option, SL("client"), client, PH_COPY); } phalcon_array_update_str(option, SL("prefix"), prefix, PH_COPY); PHALCON_INIT_VAR(libmemcached); object_init_ex(libmemcached, phalcon_cache_backend_libmemcached_ce); PHALCON_CALL_METHOD(NULL, libmemcached, "__construct", frontend_data, option); phalcon_update_property_this(getThis(), SL("_libmemcached"), libmemcached); phalcon_update_property_empty_array(getThis(), SL("_metaData")); PHALCON_MM_RESTORE(); }
/** * Handles a MVC request * * @param string $uri * @return Phalcon\Http\ResponseInterface */ PHP_METHOD(Phalcon_Mvc_JsonRpc, handle){ zval *uri = NULL, *dependency_injector, *events_manager; zval *status = NULL, *service = NULL, *request = NULL, *response = NULL; zval *json = NULL, *data = NULL, *jsonrpc_message, *jsonrpc_error, *jsonrpc_result = NULL; zval *jsonrpc_method, *jsonrpc_params, *jsonrpc_id; zval *url = NULL, *router = NULL, *module_name = NULL; zval *module_object = NULL, *modules; zval *module, *class_name = NULL, *module_params; zval *namespace_name = NULL; zval *controller_name = NULL, *action_name = NULL, *params = NULL, *exact = NULL; zval *dispatcher = NULL, *controller = NULL, *returned_response = NULL; zval *path; PHALCON_MM_GROW(); dependency_injector = phalcon_read_property(getThis(), SL("_dependencyInjector"), PH_NOISY); if (Z_TYPE_P(dependency_injector) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_jsonrpc_exception_ce, "A dependency injection object is required to access internal services"); return; } events_manager = phalcon_read_property(getThis(), SL("_eventsManager"), PH_NOISY); if (Z_TYPE_P(events_manager) != IS_OBJECT) { events_manager = NULL; } else { PHALCON_VERIFY_INTERFACE_EX(events_manager, phalcon_events_managerinterface_ce, phalcon_mvc_jsonrpc_exception_ce, 1); } /* Call boot event, this allows the developer to perform initialization actions */ if (FAILURE == phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:boot", getThis(), NULL)) { RETURN_MM_FALSE; } /* Deserializer Json */ PHALCON_INIT_NVAR(service); ZVAL_STR(service, IS(request)); PHALCON_CALL_METHOD(&request, dependency_injector, "getshared", service); PHALCON_VERIFY_INTERFACE(request, phalcon_http_requestinterface_ce); PHALCON_CALL_METHOD(&json, request, "getrawbody"); PHALCON_CALL_FUNCTION(&data, "json_decode", json, &PHALCON_GLOBAL(z_true)); PHALCON_INIT_NVAR(service); ZVAL_STR(service, IS(response)); PHALCON_CALL_METHOD(&response, dependency_injector, "getshared", service); PHALCON_VERIFY_INTERFACE(response, phalcon_http_responseinterface_ce); PHALCON_INIT_VAR(jsonrpc_message); array_init(jsonrpc_message); PHALCON_INIT_VAR(jsonrpc_error); array_init(jsonrpc_error); if (PHALCON_IS_EMPTY(data)) { phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0); phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Parse error"), PH_COPY); } else if (Z_TYPE_P(data) != IS_ARRAY) { phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0); phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Parse error"), PH_COPY); } else if (!phalcon_array_isset_str(data, SL("jsonrpc"))) { phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0); phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Invalid Request"), PH_COPY); } else if (!phalcon_array_isset_str(data, SL("method"))) { phalcon_array_update_str_long(jsonrpc_error, SL("code"), __LINE__, 0); phalcon_array_update_str_str(jsonrpc_error, SL("message"), SL("Invalid Request"), PH_COPY); } else { PHALCON_OBS_VAR(jsonrpc_method); phalcon_array_fetch_str(&jsonrpc_method, data, SL("method"), PH_NOISY); if (phalcon_array_isset_str(data, SL("params"))) { PHALCON_OBS_VAR(jsonrpc_params); phalcon_array_fetch_str(&jsonrpc_params, data, SL("params"), PH_NOISY); } else { PHALCON_INIT_VAR(jsonrpc_params); array_init(jsonrpc_params); } PHALCON_INIT_NVAR(service); ZVAL_STR(service, IS(url)); PHALCON_CALL_METHOD(&url, dependency_injector, "getshared", service); PHALCON_VERIFY_INTERFACE(url, phalcon_mvc_urlinterface_ce); PHALCON_CALL_METHOD(&uri, url, "get", jsonrpc_method); PHALCON_INIT_NVAR(service); ZVAL_STR(service, IS(router)); PHALCON_CALL_METHOD(&router, dependency_injector, "getshared", service); PHALCON_VERIFY_INTERFACE(router, phalcon_mvc_routerinterface_ce); /* Handle the URI pattern (if any) */ PHALCON_CALL_METHOD(NULL, router, "handle", uri); /* Load module config */ PHALCON_CALL_METHOD(&module_name, router, "getmodulename"); /* Load module config */ PHALCON_CALL_METHOD(&module_name, router, "getmodulename"); /* If the router doesn't return a valid module we use the default module */ if (!zend_is_true(module_name)) { module_name = phalcon_read_property(getThis(), SL("_defaultModule"), PH_NOISY); } /** * Process the module definition */ if (zend_is_true(module_name)) { if (FAILURE == phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:beforeStartModule", getThis(), module_name)) { RETURN_MM_FALSE; } /** * Check if the module passed by the router is registered in the modules container */ modules = phalcon_read_property(getThis(), SL("_modules"), PH_NOISY); if (!phalcon_array_isset_fetch(&module, modules, module_name)) { convert_to_string(module_name); zend_throw_exception_ex(phalcon_mvc_jsonrpc_exception_ce, 0, "Module %s is not registered in the jsonrpc container", Z_STRVAL_P(module_name)); RETURN_MM(); } /** * A module definition must be an array or an object */ if (Z_TYPE_P(module) != IS_ARRAY && Z_TYPE_P(module) != IS_OBJECT) { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_jsonrpc_exception_ce, "Invalid module definition"); return; } /* An array module definition contains a path to a module definition class */ if (Z_TYPE_P(module) == IS_ARRAY) { /* Class name used to load the module definition */ if (phalcon_array_isset_str(module, SL("className"))) { PHALCON_OBS_VAR(class_name); phalcon_array_fetch_str(&class_name, module, SL("className"), PH_NOISY); } else { PHALCON_INIT_NVAR(class_name); ZVAL_STRING(class_name, "Module"); } /* If the developer has specified a path, try to include the file */ if (phalcon_array_isset_str(module, SL("path"))) { PHALCON_OBS_VAR(path); phalcon_array_fetch_str(&path, module, SL("path"), PH_NOISY); convert_to_string_ex(path); if (Z_TYPE_P(class_name) != IS_STRING || phalcon_class_exists(class_name, 0) == NULL) { if (phalcon_file_exists(path) == SUCCESS) { RETURN_MM_ON_FAILURE(phalcon_require(Z_STRVAL_P(path))); } else { zend_throw_exception_ex(phalcon_mvc_jsonrpc_exception_ce, 0, "Module definition path '%s' does not exist", Z_STRVAL_P(path)); RETURN_MM(); } } } PHALCON_CALL_METHOD(&module_object, dependency_injector, "get", class_name); /** * 'registerAutoloaders' and 'registerServices' are automatically called */ PHALCON_CALL_METHOD(NULL, module_object, "registerautoloaders", dependency_injector); PHALCON_CALL_METHOD(NULL, module_object, "registerservices", dependency_injector); } else if (Z_TYPE_P(module) == IS_OBJECT && instanceof_function(Z_OBJCE_P(module), zend_ce_closure)) { /* A module definition object, can be a Closure instance */ PHALCON_INIT_VAR(module_params); array_init_size(module_params, 1); phalcon_array_append(module_params, dependency_injector, PH_COPY); PHALCON_CALL_USER_FUNC_ARRAY(&status, module, module_params); } else { PHALCON_THROW_EXCEPTION_STR(phalcon_mvc_jsonrpc_exception_ce, "Invalid module definition"); return; } /* Calling afterStartModule event */ if (events_manager) { if (!module_object) { module_object = &PHALCON_GLOBAL(z_null); } phalcon_update_property_this(getThis(), SL("_moduleObject"), module_object); if (FAILURE == phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:afterStartModule", getThis(), module_name)) { RETURN_MM_FALSE; } } } /* We get the parameters from the router and assign them to the dispatcher */ PHALCON_CALL_METHOD(&module_name, router, "getmodulename"); PHALCON_CALL_METHOD(&namespace_name, router, "getnamespacename"); PHALCON_CALL_METHOD(&controller_name, router, "getcontrollername"); PHALCON_CALL_METHOD(&action_name, router, "getactionname"); PHALCON_CALL_METHOD(¶ms, router, "getparams"); PHALCON_CALL_METHOD(&exact, router, "isexactcontrollername"); PHALCON_INIT_NVAR(service); ZVAL_STR(service, IS(dispatcher)); PHALCON_CALL_METHOD(&dispatcher, dependency_injector, "getshared", service); PHALCON_VERIFY_INTERFACE(dispatcher, phalcon_dispatcherinterface_ce); /* Assign the values passed from the router */ PHALCON_CALL_METHOD(NULL, dispatcher, "setmodulename", module_name); PHALCON_CALL_METHOD(NULL, dispatcher, "setnamespacename", namespace_name); PHALCON_CALL_METHOD(NULL, dispatcher, "setcontrollername", controller_name, exact); PHALCON_CALL_METHOD(NULL, dispatcher, "setactionname", action_name); PHALCON_CALL_METHOD(NULL, dispatcher, "setparams", jsonrpc_params); /* Calling beforeHandleRequest */ RETURN_MM_ON_FAILURE(phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:beforeHandleRequest", getThis(), dispatcher)); /* The dispatcher must return an object */ PHALCON_CALL_METHOD(&controller, dispatcher, "dispatch"); PHALCON_INIT_VAR(returned_response); /* Get the latest value returned by an action */ PHALCON_CALL_METHOD(&jsonrpc_result, dispatcher, "getreturnedvalue"); } /* Calling afterHandleRequest */ if (FAILURE == phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:afterHandleRequest", getThis(), controller) && EG(exception)) { RETURN_MM(); } phalcon_array_update_str_str(jsonrpc_message, SL("jsonrpc"), SL("2.0"), PH_COPY); if (PHALCON_IS_NOT_EMPTY(jsonrpc_error)) { phalcon_array_update_str(jsonrpc_message, SL("error"), jsonrpc_error, PH_COPY); } if (jsonrpc_result != NULL) { phalcon_array_update_str(jsonrpc_message, SL("result"), jsonrpc_result, PH_COPY); } if (phalcon_array_isset_str_fetch(&jsonrpc_id, data, SL("id"))) { phalcon_array_update_str(jsonrpc_message, SL("id"), jsonrpc_id, PH_COPY); } else { phalcon_array_update_str(jsonrpc_message, SL("id"), &PHALCON_GLOBAL(z_null), PH_COPY); } PHALCON_CALL_METHOD(NULL, response, "setjsoncontent", jsonrpc_message); /* Calling beforeSendResponse */ if (FAILURE == phalcon_mvc_jsonrpc_fire_event(events_manager, "jsonrpc:beforeSendResponse", getThis(), response) && EG(exception)) { RETURN_MM(); } /* Headers are automatically sent */ PHALCON_CALL_METHOD(NULL, response, "sendheaders"); /* Cookies are automatically sent */ PHALCON_CALL_METHOD(NULL, response, "sendcookies"); /* Return the response */ RETURN_CCTOR(response); }