public static function instance(&$uri = true) { if (!self::$instance) { self::$raw_req_body = @file_get_contents('php://input'); } return parent::instance($uri); }
public function method($method = NULL) { if (!$method) { return parent::method(); } return parent::method(Resource_Request::resolve_method($method)); }
/** * Main request singleton instance. If no URI is provided, the URI will * be automatically detected using PATH_INFO, REQUEST_URI, or PHP_SELF. * * @param string URI of the request * @return Request */ public static function instance(&$uri = TRUE) { $instance = parent::instance($uri); $index_page = Kohana::$index_file; $lang_uri_abbr = Kohana::config('appconf.lang_uri_abbr'); $default_lang = Kohana::config('appconf.language_abbr'); $lang_ignore = Kohana::config('appconf.lang_ignore'); /* get the lang_abbr from uri segments */ $segments = explode('/', $instance->uri); $lang_abbr = isset($segments[0]) ? $segments[0] : ''; /* get current language */ $cur_lang = $instance->param('lang', $default_lang); /* check for invalid abbreviation */ if (!isset($lang_uri_abbr[$lang_abbr])) { /* check for abbreviation to be ignored */ if ($cur_lang != $lang_ignore) { /* check and set the default uri identifier */ $index_page .= empty($index_page) ? $default_lang : "/{$default_lang}"; /* redirect after inserting language id */ header('Location: ' . Url::base() . $index_page . '/' . $instance->uri); die; } } return $instance; }
/** * Generate the url for the specified page. * * @param int $page * @return String */ public function url($page = 1) { // Clean the page number $page = max(1, (int) $page); // No page number in URLs to first page if ($page === 1 and !$this->config['first_page_in_url']) { $page = NULL; } $params = array_merge($this->route_params, array($this->config['param'] => $page)); $suffix = ''; if ($this->query != FALSE) { if (is_string($this->query)) { $suffix = $this->query != FALSE ? '?' . $this->query . '=' . $this->request->query($this->query) : ''; } elseif (is_array($this->query)) { $suffix = '?'; $first = TRUE; foreach ($this->query as $q) { if ($first) { $first = FALSE; $suffix .= $q . '=' . $this->request->query($q); } else { $suffix .= '&' . $q . '=' . $this->request->query($q); } } } } return URL::site($this->route->uri($params)) . $suffix; }
/** * Processes the request, checking for attached * Cache decorators. If decorators are found, * the request performs the following tasks. * * 1. Checks for existing cached response, returning valid hits * 2. Runs the Kohana_Request::execute() logic to create a response * 3. Caches the response using a decorator if valid * * $request->execute(); * * @return Kohana_Response * @throws Kohana_Exception * @uses [Kohana::$profiling] * @uses [Profiler] * @uses [Request_Cache] */ public function execute() { // If there are no cache adaptors if (!Request::$cache->cache_decorators) { // Get out of here return parent::execute(); } // Create the cache key $key = $this->create_cache_key($this->uri()); // Try and retrieve a cached response $response = Request::$cache->get($key); // If a response is returned if ($response instanceof Kohana_Response) { // Return the cached response return $response; } else { // Execute the contoller to get the response $response = parent::execute(); } // If the response method is in the allow list if (!in_array($this->method, Request_Cache::$cache_methods_allow)) { // return FALSE return $response; } else { if (!Request_Cache::validate_set($response)) { // return the non-cached result return $response; } } // Set the response to cache Request::$cache->set($key, $response); // Return the response return $response; }
public static function instance(&$uri = TRUE) { if (!Request::$instance and !Kohana::$is_cli) { // Detect mobile environment from HTTP HOST Request::$is_mobile = !!strstr(URL::base(TRUE, TRUE), '//mobile.'); } return parent::instance($uri); }
/** * * @return string */ public static function detect_uri() { $uri = parent::detect_uri(); if (!defined('URL_SUFFIX')) { return $uri; } else { return str_replace(URL_SUFFIX, '', $uri); } }
/** * Extension of the main request factory. If none given, the URI will * be automatically detected. If the URI contains no language segment, the user * will be redirected to the same URI with the default language prepended. * If the URI does contain a language segment, I18n and locale will be set. * Also, a cookie with the current language will be set. Finally, the language * segment is chopped off the URI and normal request processing continues. * * @param string $uri URI of the request * @param Cache $cache * @param array $injected_routes an array of routes to use, for testing * @return Request * @uses Lang::config * @uses Request::detect_uri * @uses Lang::find_current * @uses Lang::$default_prepended * @uses Lang::$default * @uses Request::lang_redirect * @uses Request::$lang * @uses I18n::$lang * @uses Cookie::get * @uses Lang::$cookie * @uses Cookie::set */ public static function factory($uri = TRUE, $client_params = array(), $allow_external = TRUE, $injected_routes = array()) { // Load config $config = Lang::config(); if ($uri === TRUE) { // We need the current URI $uri = Request::detect_uri(); } // Get current language from URI $current_language = Lang::find_current($uri); if (!Lang::$default_prepended and $current_language === Lang::$default and strpos($uri, '/' . Lang::$default) === 0) { // If default is not prepended and current language is the default, // then redirect to the same URI, but with default language removed Request::lang_redirect(NULL, ltrim($uri, '/' . Lang::$default)); } elseif (Lang::$default_prepended and $current_language === Lang::$default and strpos($uri, '/' . Lang::$default) !== 0) { // If the current language is the default which needs to be // prepended, but it's missing, then redirect to same URI but with // language prepended Request::lang_redirect($current_language, $uri); } // Language found in the URI Request::$lang = $current_language; // Store target language in I18n I18n::$lang = $config[Request::$lang]['i18n_code']; // Set locale setlocale(LC_ALL, $config[Request::$lang]['locale']); if (Cookie::get(Lang::$cookie) !== Request::$lang) { // Update language cookie if needed Cookie::set(Lang::$cookie, Request::$lang); } if (Lang::$default_prepended or Request::$lang !== Lang::$default) { // Remove language from URI if default is prepended or the language is not the default $uri = (string) substr($uri, strlen(Request::$lang) + 1); } // Continue normal request processing with the URI without language return parent::factory($uri, $client_params, $allow_external, $injected_routes); }
public static function factory($uri = TRUE, HTTP_Cache $cache = NULL, $injected_routes = array()) { $request = parent::factory($uri, $cache, $injected_routes); // for admin routes $exluded_routes = array('admin', 'admin_error', 'modules'); if ($request->route() !== NULL and in_array($request->route()->route_name, $exluded_routes)) { return $request; } // for public routes $request->define_site(); ORM_Base::$filter_mode = ORM_Base::FILTER_FRONTEND; ORM_Base::$site_id = $request->site_id; ORM_Base::$site_id_master = $request->site_id_master; if ($request->route() !== NULL) { return $request; } $request_uri = $request->uri(); $request->page = $page = Page_Route::page($request->uri()); if ($page !== NULL) { $routes = array(); if ($page['type'] == 'module' and !Helper_Module::is_stanalone($page['data'])) { $routes_config = Kohana::$config->load('routes/' . $page['data'])->as_array(); $request->set_module_routes($routes_config, $page['uri_full'], $page['id'], $cache); } elseif (Helper_Module::is_stanalone($page['data'])) { /* * For controllers which no need admin side (only public contoller) * and have one action (by default is 'index') * Can have route file or default controller (controller name equal 'data' field value) */ $routes_config = Kohana::$config->load('routes/' . $page['data'])->as_array(); if (empty($routes_config)) { $name = $page['id'] . '<->standalone_page'; $uri_callback = $page['uri_full']; $defaults = array('directory' => 'standalone', 'controller' => $page['data']); $route = new Route($uri_callback); $route->defaults($defaults); $routes[$name] = $route; Route::set($name, $uri_callback)->defaults($defaults); $processed_uri = Request::process_uri($request_uri, $routes); if ($processed_uri !== NULL) { $request->set_dinamic_route($processed_uri, $cache); } } else { $request->set_module_routes($routes_config, $page['uri_full'], $page['id'], $cache); } } else { /* * For simple static pages */ $name = $page['id'] . '<->std_page'; $uri_callback = $page['uri_full']; $defaults = array('controller' => 'page', 'action' => $page['type']); $route = new Route($uri_callback); $route->defaults($defaults); $routes[$name] = $route; Route::set($name, $uri_callback)->defaults($defaults); $processed_uri = Request::process_uri($request_uri, $routes); if ($processed_uri !== NULL) { $request->set_dinamic_route($processed_uri, $cache); } } } else { Kohana::$log->add(Log::ERROR, 'Page for :uri not found. [:file][:line] ', array(':file' => Debug::path(__FILE__), ':line' => __LINE__, ':uri' => $request->uri())); throw new HTTP_Exception_404(); } return $request; }
public function __construct($uri) { parent::__construct($uri); //merge all params into a single array. $this->_params = array_merge_recursive($this->_params, $_COOKIE, $_GET, $_POST, $_FILES, $_SERVER); }