From ce5a922b871e8c8f3f6f3c1d60dca98783e82f5d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 4 Feb 2012 20:13:10 -0600 Subject: [PATCH] cleaning up the uri method. --- laravel/uri.php | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/laravel/uri.php b/laravel/uri.php index e94b16a4..1ff22f33 100644 --- a/laravel/uri.php +++ b/laravel/uri.php @@ -33,22 +33,14 @@ public static function current() $uri = static::remove($uri, parse_url(URL::base(), PHP_URL_PATH)); // We'll also remove the application's index page as it is not used for at - // all for routing and is totally unnecessary as far as the framework is - // concerned. It is only in the URI when mod_rewrite is not available. + // all for routing and is totally unnecessary as far as the routing of + // incoming requests to the framework is concerned. if (($index = '/'.Config::get('application.index')) !== '/') { $uri = static::remove($uri, $index); } - static::$uri = static::format($uri); - - // Cache the URI segments. This allows us to avoid having to explode - // the segments every time the developer requests one of them. The - // extra slashes have already been stripped off of the URI so no - // extraneous elements should be present in the segment array. - $segments = explode('/', trim(static::$uri, '/')); - - static::$segments = array_diff($segments, array('')); + static::segments(static::$uri = static::format($uri)); return static::$uri; } @@ -75,6 +67,19 @@ public static function segment($index, $default = null) return array_get(static::$segments, $index - 1, $default); } + /** + * Set the URI segments for the request. + * + * @param string $uri + * @return void + */ + protected function segments($uri) + { + $segments = explode('/', trim($uri, '/')); + + static::$segments = array_diff($segments, array('')); + } + /** * Remove a given value from the URI. *