mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 08:47:52 +00:00
[BUGFIX] Middlewares are no longer loaded on invalid routes
This commit is contained in:
@@ -116,6 +116,7 @@ class RouterBase {
|
|||||||
$routeNotAllowed = false;
|
$routeNotAllowed = false;
|
||||||
|
|
||||||
$this->loadedRoute = $routeMatch;
|
$this->loadedRoute = $routeMatch;
|
||||||
|
$routeMatch->loadMiddleware($this->request);
|
||||||
$routeMatch->renderRoute($this->request);
|
$routeMatch->renderRoute($this->request);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ abstract class RouterEntry {
|
|||||||
return new $name();
|
return new $name();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadMiddleware(Request $request) {
|
public function loadMiddleware(Request $request) {
|
||||||
if($this->getMiddleware()) {
|
if($this->getMiddleware()) {
|
||||||
$middleware = $this->loadClass($this->getMiddleware());
|
$middleware = $this->loadClass($this->getMiddleware());
|
||||||
if (!($middleware instanceof Middleware)) {
|
if (!($middleware instanceof Middleware)) {
|
||||||
@@ -256,8 +256,6 @@ abstract class RouterEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function renderRoute(Request $request) {
|
public function renderRoute(Request $request) {
|
||||||
// Load middleware
|
|
||||||
$this->loadMiddleware($request);
|
|
||||||
|
|
||||||
if(is_object($this->getCallback()) && is_callable($this->getCallback())) {
|
if(is_object($this->getCallback()) && is_callable($this->getCallback())) {
|
||||||
|
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ class RouterResource extends RouterEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function renderRoute(Request $request) {
|
public function renderRoute(Request $request) {
|
||||||
// Load middleware
|
|
||||||
$this->loadMiddleware($request);
|
|
||||||
|
|
||||||
if(is_object($this->getCallback()) && is_callable($this->getCallback())) {
|
if(is_object($this->getCallback()) && is_callable($this->getCallback())) {
|
||||||
// When the callback is a function
|
// When the callback is a function
|
||||||
call_user_func_array($this->getCallback(), $this->getParameters());
|
call_user_func_array($this->getCallback(), $this->getParameters());
|
||||||
|
|||||||
Reference in New Issue
Block a user