Commit 277729ed authored by Taylor Otwell's avatar Taylor Otwell

continued refactoring routing.

parent 2fae372c
...@@ -47,13 +47,27 @@ class Route { ...@@ -47,13 +47,27 @@ class Route {
$this->callback = $callback; $this->callback = $callback;
$this->parameters = $parameters; $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 // 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 // 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. // the root of the application, a single forward slash will be returned.
// Otherwise, the leading slash will be removed. // Otherwise, the leading slash will be removed.
foreach (explode(', ', $key) as $segment) if (strpos($key, ', ') === false)
{
$this->uris = array($extractor($this->key));
}
else
{ {
$this->uris[] = ($segment = (substr($segment, strpos($segment, ' ') + 1)) !== '/') ? trim($segment, '/') : $segment; $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 // The route callback must be either a Closure, an array, or a string. Closures
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment