Commit 03044c7d authored by Taylor Otwell's avatar Taylor Otwell

Refactoring router.

parent 6c6f92a7
...@@ -41,7 +41,9 @@ class Router { ...@@ -41,7 +41,9 @@ class Router {
{ {
foreach (explode(', ', $keys) as $key) foreach (explode(', ', $keys) as $key)
{ {
if (preg_match('#^'.$key = static::translate_wildcards($key).'$#', $uri)) $key = str_replace(':num', '[0-9]+', str_replace(':any', '[a-zA-Z0-9\-_]+', $key));
if (preg_match('#^'.$key.'$#', $uri))
{ {
return Request::$route = new Route($keys, $callback, static::parameters($uri, $key)); return Request::$route = new Route($keys, $callback, static::parameters($uri, $key));
} }
...@@ -76,17 +78,6 @@ class Router { ...@@ -76,17 +78,6 @@ class Router {
return (file_exists($path = APP_PATH.'routes/'.$segments[0].EXT)) ? require $path : array(); return (file_exists($path = APP_PATH.'routes/'.$segments[0].EXT)) ? require $path : array();
} }
/**
* Translate route URI wildcards to regular expressions.
*
* @param string $key
* @return string
*/
private static function translate_wildcards($key)
{
return str_replace(':num', '[0-9]+', str_replace(':any', '[a-zA-Z0-9\-_]+', $key));
}
/** /**
* Extract the parameters from a URI based on a route URI. * Extract the parameters from a URI based on a route URI.
* *
......
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