mirror of
https://github.com/skipperbent/simple-php-router.git
synced 2026-07-11 14:02:14 +00:00
[TASK] Load group middleware if prefix matches
- Middlewares from groups are now loaded if prefix matches. - Optimisations.
This commit is contained in:
@@ -68,7 +68,7 @@ class RouterBase {
|
|||||||
|
|
||||||
$newPrefixes = $prefixes;
|
$newPrefixes = $prefixes;
|
||||||
|
|
||||||
if($route->getPrefix()) {
|
if($route->getPrefix() && trim($route->getPrefix(), '/') !== '') {
|
||||||
array_push($newPrefixes, trim($route->getPrefix(), '/'));
|
array_push($newPrefixes, trim($route->getPrefix(), '/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +85,12 @@ 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->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());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ abstract class RouterEntry {
|
|||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setPrefix($prefix) {
|
public function setPrefix($prefix) {
|
||||||
$this->prefix = '/' . trim($prefix, '/') . '/';
|
$this->prefix = '/' . ltrim($prefix, '/');
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ use Pecee\Http\Request;
|
|||||||
|
|
||||||
class RouterGroup extends RouterEntry {
|
class RouterGroup extends RouterEntry {
|
||||||
|
|
||||||
public function __construct() {
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function matchDomain(Request $request) {
|
public function matchDomain(Request $request) {
|
||||||
if($this->domain !== null) {
|
if($this->domain !== null) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user