Commit 7f8e67c6 by Scott

Fix exception thrown too early

parent 042a3bda
...@@ -68,18 +68,24 @@ class Router ...@@ -68,18 +68,24 @@ class Router
*/ */
public function match($request) public function match($request)
{ {
$matchedRoute = false;
foreach ($this->routes as $route) { foreach ($this->routes as $route) {
$pathRegex = $this->buildPathRegex($route->getRoutePath()); $pathRegex = $this->buildPathRegex($route->getRoutePath());
if (preg_match($pathRegex, $request, $matches)) { if (preg_match($pathRegex, $request, $matches)) {
if ($route->getHttpMethod() !== $this->httpMethod) { $matchedRoute = true;
throw new MethodNotAllowedException; if ($route->getHttpMethod() === $this->httpMethod) {
$route->setParameters(array_slice($matches, 1));
return $route;
} }
$route->setParameters(array_slice($matches, 1));
return $route;
} }
} }
// we matched a route but not the HTTP method
if ($matchedRoute) {
throw new MethodNotAllowedException;
}
return null; return null;
} }
......
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