From d0ba4719d800c790a9fc0948bfb13d7c1797258b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 9 Jul 2011 23:54:07 -0500 Subject: [PATCH] extracted the route wildcard translation to a separate method. --- system/router.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/system/router.php b/system/router.php index 3aa7e5d9..97dc0830 100644 --- a/system/router.php +++ b/system/router.php @@ -41,9 +41,7 @@ public static function route($method, $uri) { foreach (explode(', ', $keys) as $key) { - $key = str_replace(':num', '[0-9]+', str_replace(':any', '[a-zA-Z0-9\-_]+', $key)); - - if (preg_match('#^'.$key.'$#', $uri)) + if (preg_match('#^'.$key = static::translate_wildcards($key).'$#', $uri)) { return Request::$route = new Route($keys, $callback, static::parameters($uri, $key)); } @@ -85,6 +83,17 @@ private static function load_from_directory($uri) return (file_exists($path = APP_PATH.'routes/'.$segments[0].EXT)) ? array_merge(require $path, $home) : $home; } + /** + * 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. *