mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
[BUGFIX] Fixed method not allowed exception.
- Method request type are now checked on all classes in the RouterBase class.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user