Exemple #1
0
/**
 * 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);
}
Exemple #2
0
/**
 * Phalcon\Cache\Backend\Mongo constructor
 *
 * @param Phalcon\Cache\FrontendInterface $frontend
 * @param array $options
 */
PHP_METHOD(Phalcon_Cache_Backend_Mongo, __construct){

	zval *frontend, *options = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &frontend, &options);

	if (!options) {
		options = &PHALCON_GLOBAL(z_null);
	}

	if (!phalcon_array_isset_str(options, SL("mongo"))) {
		if (!phalcon_array_isset_str(options, SL("server"))) {
			PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'server' is required");
			return;
		}
	}

	if (!phalcon_array_isset_str(options, SL("db"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'db' is required");
		return;
	}

	if (!phalcon_array_isset_str(options, SL("collection"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "The parameter 'collection' is required");
		return;
	}

	PHALCON_CALL_PARENT(NULL, phalcon_cache_backend_mongo_ce, getThis(), "__construct", frontend, options);

	PHALCON_MM_RESTORE();
}
Exemple #3
0
/**
 * Generates SQL to create a view
 *
 * @param string $viewName
 * @param array $definition
 * @param string $schemaName
 * @return string
 */
PHP_METHOD(Phalcon_Db_Dialect_Sqlite, createView){

	zval *view_name, *definition, *schema_name, *view_sql;
	zval *view = NULL, *sql;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 3, 0, &view_name, &definition, &schema_name);
	
	if (!phalcon_array_isset_str(definition, SL("sql"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_db_exception_ce, "The index 'sql' is required in the definition array");
		return;
	}
	
	PHALCON_OBS_VAR(view_sql);
	phalcon_array_fetch_str(&view_sql, definition, SL("sql"), PH_NOISY);
	if (zend_is_true(schema_name)) {
		PHALCON_INIT_VAR(view);
		PHALCON_CONCAT_VSV(view, schema_name, "\".\"", view_name);
	} else {
		PHALCON_CPY_WRT(view, view_name);
	}
	
	PHALCON_INIT_VAR(sql);
	PHALCON_CONCAT_SVSV(sql, "CREATE VIEW \"", view, "\" AS ", view_sql);
	
	RETURN_CTOR(sql);
}
Exemple #4
0
/**
 * 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();
}
Exemple #5
0
/**
 * Phalcon\Logger\Adapter\Syslog constructor
 *
 * @param string $name
 * @param array $options
 */
PHP_METHOD(Phalcon_Logger_Adapter_Syslog, __construct){

	zval *name, *options = NULL, *option = NULL, *facility = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &name, &options);

	if (!options) {
		options = &PHALCON_GLOBAL(z_null);
	}

	/** 
	 * We use 'fopen' to respect to open-basedir directive
	 */
	if (zend_is_true(name)) {
		if (phalcon_array_isset_str(options, SL("option"))) {
			PHALCON_OBS_VAR(option);
			phalcon_array_fetch_str(&option, options, SL("option"), PH_NOISY);
		} else {
			/** 
			 * Open the log in LOG_ODELAY mode
			 */
			PHALCON_INIT_NVAR(option);
			ZVAL_LONG(option, 4);
		}
		if (phalcon_array_isset_str(options, SL("facility"))) {
			PHALCON_OBS_VAR(facility);
			phalcon_array_fetch_str(&facility, options, SL("facility"), PH_NOISY);
		} else {
			/** 
			 * By default the facility is LOG_USER
			 */
			PHALCON_INIT_NVAR(facility);
			ZVAL_LONG(facility, 8);
		}

		PHALCON_CALL_FUNCTION(NULL, "openlog", name, option, facility);
		phalcon_update_property_bool(getThis(), SL("_opened"), 1);
	}

	PHALCON_MM_RESTORE();
}
Exemple #6
0
/**
 * 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();
}
Exemple #7
0
/**
 * Check whether the relation act as a foreign key
 *
 * @return string|array
 */
PHP_METHOD(Phalcon_Mvc_Model_Relation, isForeignKey) {

    zval *options;

    PHALCON_MM_GROW();

    options = phalcon_read_property(getThis(), SL("_options"), PH_NOISY);
    if (Z_TYPE_P(options) == IS_ARRAY) {
        if (phalcon_array_isset_str(options, SL("foreignKey"))) {
            RETURN_MM_TRUE;
        }
    }

    RETURN_MM_FALSE;
}
Exemple #8
0
/**
 * Phalcon\Cache\Backend\File constructor
 *
 * @param Phalcon\Cache\FrontendInterface $frontend
 * @param array $options
 */
PHP_METHOD(Phalcon_Cache_Backend_File, __construct){

	zval *frontend, *options = NULL;

	PHALCON_MM_GROW();

	phalcon_fetch_params(1, 1, 1, &frontend, &options);

	if (!options || !phalcon_array_isset_str(options, SL("cacheDir"))) {
		PHALCON_THROW_EXCEPTION_STR(phalcon_cache_exception_ce, "Cache directory must be specified with the option cacheDir");
		return;
	}

	PHALCON_CALL_PARENT(NULL, phalcon_cache_backend_file_ce, getThis(), "__construct", frontend, options);

	PHALCON_MM_RESTORE();
}
Exemple #9
0
/**
 * Checks whether request has been made using SOAP
 *
 * @return boolean
 */
PHP_METHOD(Phalcon_Http_Request, isSoapRequested)
{
	zval *server, content_type = {};

	server = phalcon_get_global_str(SL("_SERVER"));
	if (phalcon_array_isset_str(server, SL("HTTP_SOAPACTION"))) {
		RETURN_TRUE;
	}

	if (phalcon_array_isset_fetch_str(&content_type, server, SL("CONTENT_TYPE"))) {
		if (phalcon_memnstr_str(&content_type, SL("application/soap+xml"))) {
			RETURN_TRUE;
		}
	}

	RETURN_FALSE;
}
Exemple #10
0
/**
 * 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);
}
Exemple #11
0
/**
 * 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;
	zval *session = NULL, *name, *key, *definition = NULL, *expire, *domain;
	zval *path, *secure, *http_only;

	PHALCON_MM_GROW();

	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) {

			PHALCON_INIT_VAR(service);
			ZVAL_STR(service, IS(session));

			PHALCON_CALL_METHOD(&session, dependency_injector, "getshared", service);
			PHALCON_VERIFY_INTERFACE(session, phalcon_session_adapterinterface_ce);

			name = phalcon_read_property(getThis(), SL("_name"), PH_NOISY);

			PHALCON_INIT_VAR(key);
			PHALCON_CONCAT_SV(key, "_PHCOOKIE_", name);

			PHALCON_CALL_METHOD(&definition, session, "get", key);
			if (Z_TYPE_P(definition) == IS_ARRAY) { 
				if (phalcon_array_isset_str(definition, SL("expire"))) {
					PHALCON_OBS_VAR(expire);
					phalcon_array_fetch_str(&expire, definition, SL("expire"), PH_NOISY);
					phalcon_update_property_this(getThis(), SL("_expire"), expire);
				}
				if (phalcon_array_isset_str(definition, SL("domain"))) {
					PHALCON_OBS_VAR(domain);
					phalcon_array_fetch_str(&domain, definition, SL("domain"), PH_NOISY);
					phalcon_update_property_this(getThis(), SL("_domain"), domain);
				}

				if (phalcon_array_isset_str(definition, SL("path"))) {
					PHALCON_OBS_VAR(path);
					phalcon_array_fetch_str(&path, definition, SL("path"), PH_NOISY);
					phalcon_update_property_this(getThis(), SL("_path"), path);
				}

				if (phalcon_array_isset_str(definition, SL("secure"))) {
					PHALCON_OBS_VAR(secure);
					phalcon_array_fetch_str(&secure, definition, SL("secure"), PH_NOISY);
					phalcon_update_property_this(getThis(), SL("_secure"), secure);
				}

				if (phalcon_array_isset_str(definition, SL("httpOnly"))) {
					PHALCON_OBS_VAR(http_only);
					phalcon_array_fetch_str(&http_only, definition, SL("httpOnly"), PH_NOISY);
					phalcon_update_property_this(getThis(), SL("_httpOnly"), http_only);
				}
			}
		}

		phalcon_update_property_bool(getThis(), SL("_restored"), 1);
	}

	RETURN_THIS();
}
Exemple #12
0
/**
 * 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(&params, 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);
}