From 277729ed3eb0ba151eb822abbf842eacf027e1d7 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 13 Sep 2011 22:35:27 -0500 Subject: [PATCH] continued refactoring routing. --- laravel/routing/route.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/laravel/routing/route.php b/laravel/routing/route.php index de460bd6..c54f3867 100644 --- a/laravel/routing/route.php +++ b/laravel/routing/route.php @@ -47,13 +47,27 @@ class Route { $this->callback = $callback; $this->parameters = $parameters; + // The extractor closure will retrieve the URI from a given route destination. + // If the request is to the root of the application, a single forward slash + // will be returned, otherwise the leading slash will be removed. + $extractor = function($segment) + { + $segment = substr($segment, strpos($segment, ' ') + 1); + + return ($segment !== '/') ? trim($segment, '/') : $segment; + }; + // Extract each URI out of the route key. Since the route key has the request // method, we will extract the method off of the string. If the URI points to // the root of the application, a single forward slash will be returned. // Otherwise, the leading slash will be removed. - foreach (explode(', ', $key) as $segment) + if (strpos($key, ', ') === false) { - $this->uris[] = ($segment = (substr($segment, strpos($segment, ' ') + 1)) !== '/') ? trim($segment, '/') : $segment; + $this->uris = array($extractor($this->key)); + } + else + { + $this->uris = array_map(function($segment) use ($extractor) { return $extractor($segment); }, explode(', ', $key)); } // The route callback must be either a Closure, an array, or a string. Closures