Commit 881d7f78 authored by Taylor Otwell's avatar Taylor Otwell

Trim comment bloat from Router class.

parent cf8e5e2f
...@@ -18,9 +18,7 @@ class Router { ...@@ -18,9 +18,7 @@ class Router {
*/ */
public static function route($method, $uri) public static function route($method, $uri)
{ {
// --------------------------------------------------------------
// Prepend a forward slash since all routes begin with one. // Prepend a forward slash since all routes begin with one.
// --------------------------------------------------------------
$uri = ($uri != '/') ? '/'.$uri : $uri; $uri = ($uri != '/') ? '/'.$uri : $uri;
if (is_null(static::$routes)) if (is_null(static::$routes))
...@@ -28,28 +26,18 @@ class Router { ...@@ -28,28 +26,18 @@ class Router {
static::$routes = Route\Loader::load($uri); static::$routes = Route\Loader::load($uri);
} }
// --------------------------------------------------------------
// Is there an exact match for the request? // Is there an exact match for the request?
// --------------------------------------------------------------
if (isset(static::$routes[$method.' '.$uri])) if (isset(static::$routes[$method.' '.$uri]))
{ {
return Request::$route = new Route($method.' '.$uri, static::$routes[$method.' '.$uri]); return Request::$route = new Route($method.' '.$uri, static::$routes[$method.' '.$uri]);
} }
// --------------------------------------------------------------
// No exact match... check each route individually.
// --------------------------------------------------------------
foreach (static::$routes as $keys => $callback) foreach (static::$routes as $keys => $callback)
{ {
// -------------------------------------------------------------- // Only check routes that have multiple URIs or wildcards. All other routes would have
// Only check routes that have multiple URIs or wildcards. // been caught by a literal match.
// All other routes would have been caught by a literal match.
// --------------------------------------------------------------
if (strpos($keys, '(') !== false or strpos($keys, ',') !== false ) if (strpos($keys, '(') !== false or strpos($keys, ',') !== false )
{ {
// --------------------------------------------------------------
// Routes can be comma-delimited, so spin through each one.
// --------------------------------------------------------------
foreach (explode(', ', $keys) as $key) foreach (explode(', ', $keys) as $key)
{ {
$key = str_replace(':num', '[0-9]+', str_replace(':any', '[a-zA-Z0-9\-_]+', $key)); $key = str_replace(':num', '[0-9]+', str_replace(':any', '[a-zA-Z0-9\-_]+', $key));
......
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