public function dispatch(Request $request) { if (!$request->isInit()) { $request->init(); } $request->process(); return $this->lastResponse = $request->getResponse(); }
public static function introspect($url, $method = Request::GET) { if (strpos($url, '://') !== FALSE) { $url = parse_url($url, PHP_URL_PATH); } $url = ltrim($url, '/'); $request = Request::factory($url)->method($method); return Request::process($request); }
public function before() { $baseUrl = URL::base(true); if (substr($this->request->referrer(), 0, strlen($baseUrl)) == $baseUrl) { $urlPath = ltrim(parse_url($this->request->referrer(), PHP_URL_PATH), '/'); $processedRef = Request::process(new Request($urlPath)); $referrerController = Arr::path($processedRef, 'params.controller', false); if ($referrerController && $referrerController != 'user' && !Session::instance()->get('noReturn', false)) { Session::instance()->set('returnUrl', $this->request->referrer()); } } if ($this->request->action() == "profile") { if (isset($_GET["old"])) { $this->template = "admin"; } else { $this->template = "admin"; } } parent::before(); }
/** * Processes the request, executing the controller action that handles this * request, determined by the [Route]. * * 1. Before the controller action is called, the [Controller::before] method * will be called. * 2. Next the controller action will be called. * 3. After the controller action is called, the [Controller::after] method * will be called. * * By default, the output from the controller is captured and returned, and * no headers are sent. * * $request->execute(); * * @return Response * @throws Request_Exception * @throws HTTP_Exception_404 * @uses [Kohana::$profiling] * @uses [Profiler] */ public function execute() { if (!$this->_external) { $processed = Request::process($this, $this->_routes); if ($processed) { // Store the matching route $this->_route = $processed['route']; $params = $processed['params']; // Is this route external? $this->_external = $this->_route->is_external(); if (isset($params['directory'])) { // Controllers are in a sub-directory $this->_directory = $params['directory']; } // Store the controller $this->_controller = $params['controller']; // Store the action $this->_action = isset($params['action']) ? $params['action'] : Route::$default_action; // These are accessible as public vars and can be overloaded unset($params['controller'], $params['action'], $params['directory']); // Params cannot be changed once matched $this->_params = $params; } } if (!$this->_route instanceof Route) { return HTTP_Exception::factory(404, 'Unable to find a route to match the URI: :uri', array(':uri' => $this->_uri))->request($this)->get_response(); } if (!$this->_client instanceof Request_Client) { throw new Request_Exception('Unable to execute :uri without a Kohana_Request_Client', array(':uri' => $this->_uri)); } // Add custom header for CSRF protection where an Ajax // request is made via HTTP POST if ($this->method() === 'POST' and $this->is_ajax()) { $this->headers('X-CSRF-Token', CSRF::token()); } return $this->_client->execute($this); }
/** * Processes the request, executing the controller action that handles this * request, determined by the [Route]. * * 1. Before the controller action is called, the [Controller::before] method * will be called. * 2. Next the controller action will be called. * 3. After the controller action is called, the [Controller::after] method * will be called. * * By default, the output from the controller is captured and returned, and * no headers are sent. * * $request->execute(); * * @return Response * @throws Request_Exception * @throws HTTP_Exception_404 * @uses [JsonApiApplication::$profiling] * @uses [Profiler] */ public function execute() { if (!$this->_external) { $processed = Request::process($this, $this->_routes); if ($processed) { // Store the matching route $this->_route = $processed['route']; $params = $processed['params']; // Is this route external? $this->_external = $this->_route->is_external(); if (isset($params['directory'])) { // Controllers are in a sub-directory $this->_directory = $params['directory']; } // Store the controller $this->_controller = $params['controller']; // Store the action $this->_action = isset($params['action']) ? $params['action'] : Route::$default_action; // These are accessible as public vars and can be overloaded unset($params['controller'], $params['action'], $params['directory']); // Params cannot be changed once matched $this->_params = $params; } } if (!$this->_route instanceof Route) { return HTTP_Exception::factory(404, 'Unable to find a route to match the URI: :uri', array(':uri' => $this->_uri))->request($this)->get_response(); } if (!$this->_client instanceof Request_Client) { throw new Request_Exception('Unable to execute :uri without a JsonApiApplication_Request_Client', array(':uri' => $this->_uri)); } return $this->_client->execute($this); }
<?php include 'host.php'; try { $request = new Request(); $request->process(); } catch (Exception $e) { header("Status: 401"); print $e->getMessage(); } class Request { private $class; private $method; private $id; private $content_type; public function __construct() { foreach (array('class', 'method', 'id') as $key) { if (array_key_exists($key, $_REQUEST)) { $this->{$key} = $_REQUEST[$key]; } } switch ($_SERVER['HTTP_ACCEPT']) { case 'text/javascript': case 'application/json': $this->content_type = 'json'; break; case 'text/xml': default: $this->content_type = 'xml';
<?php foreach (glob("library/*.php") as $filename) { require $filename; } $server = $_SERVER; require __DIR__ . '/config/database.php'; // It brings the database details $db = new DatabaseConnection($host, $database, $user, $password); $request = new Request($server); $request->process($db);
static function init() { // Begin the benchmark self::$time_init = microtime(true); register_shutdown_function(array('Kennel', 'onShutdown')); if (array_key_exists('HTTP_HOST', $_SERVER)) { // Running from a HTTP request self::$ROOT_PATH = str_replace('\\', '/', dirname($_SERVER['SCRIPT_FILENAME'])); self::$ROOT_URL = trim("http://{$_SERVER['HTTP_HOST']}", '\\/') . '/' . trim(substr(self::$ROOT_PATH, strlen($_SERVER['DOCUMENT_ROOT'])), '\\/'); self::$ROOT_URL = trim(self::$ROOT_URL, '/'); } else { // Runing from the command line self::$ROOT_PATH = str_replace('\\', '/', $_SERVER['PWD']); } // Get the application settings if (file_exists('settings.php')) { require_once 'settings.php'; self::$_APP_SETTINGS = $settings; } else { self::controllerAction('Ksetup', 'firststeps'); } // Detect the modules self::fetchModules(); // Accept language prefixes if i18n is being used if (self::getSetting('i18n', 'enabled')) { router::prefix(self::getSetting('i18n', 'list')); } // Set the default timezone date_default_timezone_set(self::getSetting('application', 'timezone')); // Process the HTTP request (skipped when running from the command line) if (array_key_exists('HTTP_HOST', $_SERVER)) { Request::process(); } }
<?php require_once 's/s.php'; require_once BASE . 'inc/core/core.php'; Request::process(_SERVER('REQUEST_URI')); if (LOG_DEBUG_INFO) { $debuglog_str = dflush_str(); _log("[[ Info ]]\n\n{$debuglog_str}\n\n"); }
/** * Processes the request, executing the controller action that handles this * request, determined by the [Route]. * * 1. Before the controller action is called, the [Controller::before] method * will be called. * 2. Next the controller action will be called. * 3. After the controller action is called, the [Controller::after] method * will be called. * * By default, the output from the controller is captured and returned, and * no headers are sent. * * $request->execute(); */ public function execute() { if (!$this->_external) { $processed = Request::process($this, $this->_routes); if ($processed) { // Store the matching route $this->_route = $processed['route']; $params = $processed['params']; // Is this route external? //$this->_external = $this->_route->is_external(); $this->_external = FALSE; if (isset($params['directory'])) { // Controllers are in a sub-directory $this->_directory = $params['directory']; } // Store the controller $this->_controller = isset($params['controller']) ? $params['controller'] : Route::$default_controller; // Store the action $this->_action = isset($params['action']) ? $params['action'] : Route::$default_action; // These are accessible as public vars and can be overloaded unset($params['controller'], $params['action'], $params['directory']); // Params cannot be changed once matched $this->_params = $params; } } return $this; }