mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-06-17 00:37:52 +00:00
- Removed support from middlewares on each load - this should be implemented in custom Router instead.
- Updated documentation to reflect how to implement Middlewares loaded on each route.
This commit is contained in:
@@ -19,7 +19,6 @@ class RouterBase {
|
||||
protected $defaultNamespace;
|
||||
protected $bootManagers;
|
||||
protected $baseCsrfVerifier;
|
||||
protected $middlewaresToLoad;
|
||||
protected $exceptionHandlers;
|
||||
|
||||
// TODO: clean up - cut some of the methods down to smaller pieces
|
||||
@@ -30,7 +29,6 @@ class RouterBase {
|
||||
$this->backStack = array();
|
||||
$this->controllerUrlMap = array();
|
||||
$this->bootManagers = array();
|
||||
$this->middlewaresToLoad = array();
|
||||
$this->exceptionHandlers = array();
|
||||
}
|
||||
|
||||
@@ -91,12 +89,9 @@ class RouterBase {
|
||||
$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)) {
|
||||
if($route->getExceptionHandler() !== null) {
|
||||
$this->exceptionHandlers[] = $route->getExceptionHandler();
|
||||
}
|
||||
$this->middlewaresToLoad[] = $route;
|
||||
// Add exceptionhandler
|
||||
if($route->matchRoute($this->request) && $route->getExceptionHandler() !== null) {
|
||||
$this->exceptionHandlers[] = $route->getExceptionHandler();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,22 +131,8 @@ class RouterBase {
|
||||
// Loop through each route-request
|
||||
$this->processRoutes($this->routes);
|
||||
|
||||
// Load group middlewares
|
||||
/* @var $route RouterEntry */
|
||||
foreach($this->middlewaresToLoad as $route) {
|
||||
$route->loadMiddleware($this->request);
|
||||
}
|
||||
|
||||
$routeNotAllowed = false;
|
||||
|
||||
// Make sure routes with longer urls are rendered first
|
||||
usort($this->controllerUrlMap, function($a, $b) {
|
||||
if(strlen($a->getUrl()) < strlen($b->getUrl())) {
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
});
|
||||
|
||||
$max = count($this->controllerUrlMap);
|
||||
|
||||
/* @var $route RouterEntry */
|
||||
|
||||
@@ -92,20 +92,11 @@ class RouterGroup extends RouterEntry {
|
||||
if($this->getNamespace() !== null && isset($settings['namespace'])) {
|
||||
unset($settings['namespace']);
|
||||
}
|
||||
|
||||
if(is_array($settings)) {
|
||||
$this->settings = array_merge($this->settings, $settings);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMergeableSettings() {
|
||||
$settings = parent::getMergeableSettings();
|
||||
|
||||
if(isset($settings['middleware'])) {
|
||||
unset($settings['middleware']);
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user