Minor code changes.

pull/25/head
Mike Cao 12 years ago
parent 65807a1f29
commit 4cf069a552

@ -86,8 +86,7 @@ class Router {
*/ */
public function match($pattern, $url) { public function match($pattern, $url) {
$ids = array(); $ids = array();
$char = substr($pattern, -1);
// Convert optional parameters
$pattern = str_replace(')', ')?', $pattern); $pattern = str_replace(')', ')?', $pattern);
// Build the regex for matching // Build the regex for matching
@ -104,11 +103,11 @@ class Router {
); );
// Fix trailing slash // Fix trailing slash
if (substr($pattern, -1) === '/') { if ($char === '/') {
$regex .= '?'; $regex .= '?';
} }
// Replace wildcard // Replace wildcard
else if (substr($pattern, -1) === '*') { else if ($char === '*') {
$regex = str_replace('*', '.+?', $pattern); $regex = str_replace('*', '.+?', $pattern);
} }
// Allow trailing slash // Allow trailing slash
@ -139,6 +138,7 @@ class Router {
*/ */
public function route(Request $request) { public function route(Request $request) {
$this->matched = null; $this->matched = null;
$this->regex = null;
$this->params = array(); $this->params = array();
$routes = isset($this->routes[$request->method]) ? $this->routes[$request->method] : array(); $routes = isset($this->routes[$request->method]) ? $this->routes[$request->method] : array();

Loading…
Cancel
Save