mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 22:12:18 +00:00
Merge pull request #88 from skipperbent/development
[TASK] Moved group-middleware rendering to routeRequest to ensure all…
This commit is contained in:
@@ -19,15 +19,17 @@ class RouterBase {
|
|||||||
protected $defaultNamespace;
|
protected $defaultNamespace;
|
||||||
protected $bootManagers;
|
protected $bootManagers;
|
||||||
protected $baseCsrfVerifier;
|
protected $baseCsrfVerifier;
|
||||||
|
protected $middlewaresToLoad;
|
||||||
|
|
||||||
// TODO: clean up - cut some of the methods down to smaller pieces
|
// TODO: clean up - cut some of the methods down to smaller pieces
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
$this->request = Request::getInstance();
|
||||||
$this->routes = array();
|
$this->routes = array();
|
||||||
$this->backStack = array();
|
$this->backStack = array();
|
||||||
$this->controllerUrlMap = array();
|
$this->controllerUrlMap = array();
|
||||||
$this->request = Request::getInstance();
|
|
||||||
$this->bootManagers = array();
|
$this->bootManagers = array();
|
||||||
|
$this->middlewaresToLoad = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addRoute(RouterEntry $route) {
|
public function addRoute(RouterEntry $route) {
|
||||||
@@ -56,11 +58,9 @@ class RouterBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($this->defaultNamespace && !$route->getNamespace()) {
|
if($this->defaultNamespace && !$route->getNamespace()) {
|
||||||
$namespace = null;
|
$namespace = $this->defaultNamespace;
|
||||||
if ($route->getNamespace()) {
|
if ($route->getNamespace()) {
|
||||||
$namespace = $this->defaultNamespace . '\\' . $route->getNamespace();
|
$namespace .= '\\' . $route->getNamespace();
|
||||||
} else {
|
|
||||||
$namespace = $this->defaultNamespace;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$route->setNamespace($namespace);
|
$route->setNamespace($namespace);
|
||||||
@@ -86,13 +86,13 @@ class RouterBase {
|
|||||||
if($route instanceof RouterGroup && is_callable($route->getCallback())) {
|
if($route instanceof RouterGroup && is_callable($route->getCallback())) {
|
||||||
$group = $route;
|
$group = $route;
|
||||||
|
|
||||||
// Load middleware on group if route matches
|
|
||||||
if($route->getPrefix() !== null && $route->matchRoute($this->request)) {
|
|
||||||
$route->loadMiddleware($this->request);
|
|
||||||
}
|
|
||||||
|
|
||||||
$route->renderRoute($this->request);
|
$route->renderRoute($this->request);
|
||||||
$mergedSettings = array_merge($settings, $route->getMergeableSettings());
|
$mergedSettings = array_merge($settings, $route->getMergeableSettings());
|
||||||
|
|
||||||
|
// Load middleware on group if route matches
|
||||||
|
if($route->getPrefix() !== null && $route->matchRoute($this->request)) {
|
||||||
|
$this->middlewaresToLoad[] = $route;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->currentRoute = null;
|
$this->currentRoute = null;
|
||||||
@@ -111,6 +111,13 @@ class RouterBase {
|
|||||||
|
|
||||||
$originalUri = $this->request->getUri();
|
$originalUri = $this->request->getUri();
|
||||||
|
|
||||||
|
// Load group middlewares
|
||||||
|
|
||||||
|
/* @var $middleware RouterEntry */
|
||||||
|
foreach($this->middlewaresToLoad as $middleware) {
|
||||||
|
$middleware->loadMiddleware($this->request);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize boot-managers
|
// Initialize boot-managers
|
||||||
if(count($this->bootManagers)) {
|
if(count($this->bootManagers)) {
|
||||||
/* @var $manager RouterBootManager */
|
/* @var $manager RouterBootManager */
|
||||||
|
|||||||
@@ -102,13 +102,8 @@ class RouterRoute extends RouterEntry {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if(strtolower($this->getAlias()) === strtolower($name)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return strtolower($this->getAlias()) === strtolower($name);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user