From 3d684136b8c7d5d9f598e090627029cd792b2afc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2011 09:42:38 -0500 Subject: [PATCH] Refactor the request class. --- system/request.php | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/system/request.php b/system/request.php index 6c31cef4..3ea419a2 100644 --- a/system/request.php +++ b/system/request.php @@ -27,6 +27,28 @@ class Request { { if ( ! is_null(static::$uri)) return static::$uri; + $uri = static::raw_uri(); + + if (strpos($uri, $base = parse_url(Config::get('application.url'), PHP_URL_PATH)) === 0) + { + $uri = substr($uri, strlen($base)); + } + + if (strpos($uri, $index = '/index.php') === 0) + { + $uri = substr($uri, strlen($index)); + } + + return static::$uri = (($uri = trim($uri, '/')) == '') ? '/' : $uri; + } + + /** + * Get the raw request URI from the $_SERVER array. + * + * @return string + */ + private static function raw_uri() + { if (isset($_SERVER['PATH_INFO'])) { $uri = $_SERVER['PATH_INFO']; @@ -45,17 +67,7 @@ class Request { throw new \Exception("Malformed request URI. Request terminated."); } - if (strpos($uri, $base = parse_url(Config::get('application.url'), PHP_URL_PATH)) === 0) - { - $uri = substr($uri, strlen($base)); - } - - if (strpos($uri, $index = '/index.php') === 0) - { - $uri = substr($uri, strlen($index)); - } - - return static::$uri = (($uri = trim($uri, '/')) == '') ? '/' : $uri; + return $uri; } /** @@ -148,7 +160,6 @@ class Request { */ public static function __callStatic($method, $parameters) { - // Dynamically determine if a given route is handling the request. if (strpos($method, 'route_is_') === 0) { return static::route_is(substr($method, 9));