Commit 7f8e67c6 by Scott

Fix exception thrown too early

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