Skip to content

Commit

Permalink
fxied group middleware bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JanHuang committed Jan 26, 2018
1 parent 7e9749d commit 76bd4dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ public function group($path, callable $callback)
if (is_array($path)) {
$middlewareOptions = isset($path['middleware']) ? $path['middleware'] : [];
if (is_array($middlewareOptions)) {
$middleware = array_merge($middleware, $middlewareOptions);
$this->middleware = array_merge($this->middleware, $middlewareOptions);
} else {
$middleware[] = $middlewareOptions;
$this->middleware[] = $middlewareOptions;
}
$path = $path['prefix'];
$path = isset($path['prefix']) ? $path['prefix'] : '';
}

array_push($this->with, $path);
Expand Down Expand Up @@ -260,7 +260,7 @@ public function addRoute($method, $path, $callback, array $defaults = [])
$name = $path = implode('/', $this->with).$path;

if (isset($this->aliasMap[$method][$name])) {
return $this->getRoute($name);
return $this->aliasMap[$method][$name];
}

$route = $this->createRoute($method, $path, $callback, $defaults);
Expand Down
10 changes: 10 additions & 0 deletions tests/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@ public function testMiddleware()
$collection->get('/welcome', 'IndexController@welcome');
$this->assertEmpty($collection->getRoute('/welcome')->getMiddleware());
}

public function testGroup()
{
$collection = new RouteCollection();
$collection->group([
'middleware' => 'test1',
], function ($router) {
$router->get('/', 'Demo@Demo')->withAddMiddleware('test');
});
}
}

0 comments on commit 76bd4dd

Please sign in to comment.