Refactoring router.

This commit is contained in:
Taylor Otwell 2011-07-13 13:13:18 -07:00
parent 6c6f92a7c9
commit 03044c7d4c
1 changed files with 3 additions and 12 deletions

View File

@ -41,7 +41,9 @@ public static function route($method, $uri)
{
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));
}
@ -76,17 +78,6 @@ private static function load_from_directory($uri)
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.
*