Commit 7aecd785 authored by Taylor Otwell's avatar Taylor Otwell

refactoring the router.

parent 54e0bef6
...@@ -219,6 +219,17 @@ function array_strip_slashes($array) ...@@ -219,6 +219,17 @@ function array_strip_slashes($array)
return $result; return $result;
} }
/**
* Divide an array into two arrays. One with keys and the other with values.
*
* @param array $array
* @return array
*/
function array_divide($array)
{
return array(array_keys($array), array_values($array));
}
/** /**
* Determine if "Magic Quotes" are enabled on the server. * Determine if "Magic Quotes" are enabled on the server.
* *
......
...@@ -167,7 +167,9 @@ class Router { ...@@ -167,7 +167,9 @@ class Router {
$uri = ltrim($uri, '/'); $uri = ltrim($uri, '/');
} }
return static::controller($bundle, $method, $destination, Str::segments($uri)); $segments = Str::segments($uri);
return static::controller($bundle, $method, $destination, $segments);
} }
/** /**
...@@ -285,21 +287,26 @@ class Router { ...@@ -285,21 +287,26 @@ class Router {
} }
/** /**
* Translate route URI wildcards into actual regular expressions. * Translate route URI wildcards into regular expressions.
* *
* @param string $key * @param string $key
* @return string * @return string
*/ */
protected static function wildcards($key) protected static function wildcards($key)
{ {
list($search, $replace) = array_divide(static::$optional);
// For optional parameters, first translate the wildcards to their // For optional parameters, first translate the wildcards to their
// regex equivalent, sans the ")?" ending. We'll add the endings // regex equivalent, sans the ")?" ending. We'll add the endings
// back on after we know how many replacements we made. // back on after we know how many replacements we made.
$key = str_replace(array_keys(static::$optional), array_values(static::$optional), $key, $count); $key = str_replace($search, $replace, $key, $count);
$key .= ($count > 0) ? str_repeat(')?', $count) : ''; $key .= ($count > 0) ? str_repeat(')?', $count) : '';
return str_replace(array_keys(static::$patterns), array_values(static::$patterns), $key); // For "regular" parameters, we can just do a simple translate
// using the patterns array. There is not need to cap the
// pattern like we did with optional parameters.
return strtr($key, static::$patterns);
} }
} }
\ No newline at end of file
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