[TASK] Moved group-middleware rendering to routeRequest to ensure all route-urls has been initialised.

- Optimisations.
This commit is contained in:
Simon Sessingø
2016-04-09 15:26:18 +02:00
parent 491e920cfc
commit 22563671c5
2 changed files with 18 additions and 16 deletions
+17 -10
View File
@@ -19,15 +19,17 @@ class RouterBase {
protected $defaultNamespace;
protected $bootManagers;
protected $baseCsrfVerifier;
protected $middlewaresToLoad;
// TODO: clean up - cut some of the methods down to smaller pieces
public function __construct() {
$this->request = Request::getInstance();
$this->routes = array();
$this->backStack = array();
$this->controllerUrlMap = array();
$this->request = Request::getInstance();
$this->bootManagers = array();
$this->middlewaresToLoad = array();
}
public function addRoute(RouterEntry $route) {
@@ -56,11 +58,9 @@ class RouterBase {
}
if($this->defaultNamespace && !$route->getNamespace()) {
$namespace = null;
$namespace = $this->defaultNamespace;
if ($route->getNamespace()) {
$namespace = $this->defaultNamespace . '\\' . $route->getNamespace();
} else {
$namespace = $this->defaultNamespace;
$namespace .= '\\' . $route->getNamespace();
}
$route->setNamespace($namespace);
@@ -86,13 +86,13 @@ class RouterBase {
if($route instanceof RouterGroup && is_callable($route->getCallback())) {
$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);
$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;
@@ -111,6 +111,13 @@ class RouterBase {
$originalUri = $this->request->getUri();
// Load group middlewares
/* @var $middleware RouterEntry */
foreach($this->middlewaresToLoad as $middleware) {
$middleware->loadMiddleware($this->request);
}
// Initialize boot-managers
if(count($this->bootManagers)) {
/* @var $manager RouterBootManager */
+1 -6
View File
@@ -102,13 +102,8 @@ class RouterRoute extends RouterEntry {
return true;
}
}
} else {
if(strtolower($this->getAlias()) === strtolower($name)) {
return true;
}
}
return false;
return strtolower($this->getAlias()) === strtolower($name);
}
/**