[BUGFIX] Fixed method not allowed exception.

- Method request type are now checked on all classes in the RouterBase class.
This commit is contained in:
Simon Sessingø
2015-10-21 10:14:21 +02:00
parent a497c36ea4
commit 58e4eb85bb
6 changed files with 99 additions and 89 deletions
+16
View File
@@ -94,16 +94,32 @@ class RouterBase {
return strcmp($b->getUrl(), $a->getUrl());
});
$routeNotAllowed = false;
/* @var $route RouterEntry */
foreach($this->controllerUrlMap as $route) {
$routeMatch = $route->matchRoute($this->request);
if($routeMatch && !($routeMatch instanceof RouterGroup)) {
if(count($route->getRequestMethods()) && !in_array($this->request->getMethod(), $route->getRequestMethods())) {
$routeNotAllowed = true;
continue;
}
$routeNotAllowed = false;
$this->loadedRoute = $routeMatch;
$routeMatch->renderRoute($this->request);
break;
}
}
if($routeNotAllowed) {
throw new RouterException('Route or method not allowed', 403);
}
if(!$this->loadedRoute) {
throw new RouterException(sprintf('Route not found: %s', $this->request->getUri()), 404);
}