diff --git a/laravel/form.php b/laravel/form.php index bf9feea1..5f2b810b 100644 --- a/laravel/form.php +++ b/laravel/form.php @@ -82,7 +82,7 @@ class Form { */ protected static function action($action, $https) { - return HTML::entities(URL::to(((is_null($action)) ? Request::uri()->get() : $action), $https)); + return HTML::entities(URL::to(((is_null($action)) ? Request::uri() : $action), $https)); } /** diff --git a/laravel/laravel.php b/laravel/laravel.php index d4d61cc0..a961fd5d 100644 --- a/laravel/laravel.php +++ b/laravel/laravel.php @@ -37,7 +37,6 @@ if (Config::$items['session']['driver'] !== '') * Manually load some core classes that are used on every request * This allows to avoid using the loader for these classes. */ -require SYS_PATH.'uri'.EXT; require SYS_PATH.'input'.EXT; require SYS_PATH.'request'.EXT; require SYS_PATH.'response'.EXT; @@ -91,7 +90,7 @@ Input::$input = $input; */ Routing\Filter::register(require APP_PATH.'filters'.EXT); -list($uri, $method) = array(Request::uri()->get(), Request::method()); +list($uri, $method) = array(Request::uri(), Request::method()); Request::$route = IoC::container()->core('routing.router')->route($method, $uri); diff --git a/laravel/paginator.php b/laravel/paginator.php index 2f9669c0..4de36915 100644 --- a/laravel/paginator.php +++ b/laravel/paginator.php @@ -250,7 +250,7 @@ class Paginator { // We will assume the page links should use HTTPS if the current request // is also using HTTPS. Since pagination links automatically point to // the current URI, this makes pretty good sense. - list($uri, $secure) = array(Request::uri()->get(), Request::secure()); + list($uri, $secure) = array(Request::uri(), Request::secure()); $appendage = $this->appendage($element, $page); diff --git a/laravel/request.php b/laravel/request.php index c9103b9b..3b9909d7 100644 --- a/laravel/request.php +++ b/laravel/request.php @@ -5,7 +5,7 @@ class Request { /** * The request URI for the current request. * - * @var URI + * @var string */ public static $uri; @@ -24,13 +24,37 @@ class Request { const spoofer = '__spoofer'; /** - * Get the URI instance for the current request. + * Get the current request's URI. * - * @return URI + * @return string */ public static function uri() { - return (is_null(static::$uri)) ? static::$uri = new URI($_SERVER) : static::$uri; + if ( ! is_null(static::$uri)) return static::$uri; + + $uri = $_SERVER['REQUEST_URI']; + + // Remove the root application URL from the request URI. If the application + // is nested within a sub-directory of the web document root, this will get + // rid of the sub-directories from the request URI. + $base = parse_url(Config::$items['application']['url'], PHP_URL_PATH); + + if (strpos($uri, $base) === 0) + { + $uri = substr($uri, strlen($base)); + } + + $index = '/'.Config::$items['application']['index']; + + if ($index !== '/' and strpos($uri, $index) === 0) + { + $uri = substr($uri, strlen($index)); + } + + // If all we are left with is an empty string, we will return a single forward + // slash indicating the request is to the root of the application. If we have + // something left, we will its remove the leading and trailing slashes. + return static::$uri = (($uri = trim($uri, '/')) !== '') ? $uri : '/'; } /** diff --git a/laravel/uri.php b/laravel/uri.php deleted file mode 100644 index ed283269..00000000 --- a/laravel/uri.php +++ /dev/null @@ -1,98 +0,0 @@ -server = $server; - } - - /** - * Get the request URI for the current request. - * - * If the request is to the root of the application, a single forward slash - * will be returned. Otherwise, the URI will be returned with all leading - * and trailing slashes removed. The application URL and index file will - * also be removed since they are not used when routing the request. - * - * @return string - */ - public function get() - { - if ( ! is_null($this->uri)) return $this->uri; - - return $this->uri = $this->format($this->clean($this->parse($this->server['REQUEST_URI']))); - } - - /** - * Remove extraneous information from the given request URI. - * - * @param string $uri - * @return string - */ - protected function clean($uri) - { - $uri = $this->remove($uri, $this->parse(Config::$items['application']['url'])); - - if (($index = '/'.Config::$items['application']['index']) !== '/') - { - $uri = $this->remove($uri, $index); - } - - return $uri; - } - - /** - * Parse a given string URI using PHP_URL_PATH to remove the domain. - * - * @return string - */ - protected function parse($uri) - { - return parse_url($uri, PHP_URL_PATH); - } - - /** - * Remove a string from the beginning of a URI. - * - * @param string $uri - * @param string $remove - * @return string - */ - protected function remove($uri, $remove) - { - return (strpos($uri, $remove) === 0) ? substr($uri, strlen($remove)) : $uri; - } - - /** - * Format the URI for use throughout the framework. - * - * @param string $uri - * @return string - */ - protected function format($uri) - { - return (($uri = trim($uri, '/')) !== '') ? $uri : '/'; - } - -} \ No newline at end of file diff --git a/tests/Cases/RequestTest.php b/tests/Cases/RequestTest.php index 77f735f9..d23e8448 100644 --- a/tests/Cases/RequestTest.php +++ b/tests/Cases/RequestTest.php @@ -16,7 +16,7 @@ class RequestTest extends PHPUnit_Framework_TestCase { public function test_correct_uri_is_returned_when_request_uri_is_used($uri, $expectation) { $_SERVER['REQUEST_URI'] = $uri; - $this->assertEquals($expectation, Laravel\Request::uri()->get()); + $this->assertEquals($expectation, Laravel\Request::uri()); } public function test_request_method_returns_spoofed_method_if_uri_is_spoofed()