Skip to content

Commit 412261c

Browse files
committed
formatting and fixes
1 parent 346b131 commit 412261c

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

src/Illuminate/Routing/Route.php

+22-20
Original file line numberDiff line numberDiff line change
@@ -932,42 +932,44 @@ public function middleware($middleware = null)
932932
}
933933

934934
/**
935-
* Set which middleware(s) to skip.
935+
* Get the middleware for the route's controller.
936936
*
937-
* @param array|string|null $middleware
938-
* @return $this|array
937+
* @return array
939938
*/
940-
public function skipMiddleware($middleware = null)
939+
public function controllerMiddleware()
941940
{
942-
if (is_null($middleware)) {
943-
return (array) ($this->action['skip_middleware'] ?? []);
941+
if (! $this->isControllerAction()) {
942+
return [];
944943
}
945944

946-
if (is_string($middleware)) {
947-
$middleware = func_get_args();
948-
}
945+
return $this->controllerDispatcher()->getMiddleware(
946+
$this->getController(), $this->getControllerMethod()
947+
);
948+
}
949949

950-
$this->action['skip_middleware'] = array_merge(
951-
(array) ($this->action['skip_middleware'] ?? []), $middleware
950+
/**
951+
* Specify middleware that should be removed from the given route.
952+
*
953+
* @param array|string $middleware
954+
* @return $this|array
955+
*/
956+
public function withoutMiddleware($middleware)
957+
{
958+
$this->action['excluded_middleware'] = array_merge(
959+
(array) ($this->action['excluded_middleware'] ?? []), Arr::wrap($middleware)
952960
);
953961

954962
return $this;
955963
}
956964

957965
/**
958-
* Get the middleware for the route's controller.
966+
* Get the middleware should be removed from the route.
959967
*
960968
* @return array
961969
*/
962-
public function controllerMiddleware()
970+
public function excludedMiddleware()
963971
{
964-
if (! $this->isControllerAction()) {
965-
return [];
966-
}
967-
968-
return $this->controllerDispatcher()->getMiddleware(
969-
$this->getController(), $this->getControllerMethod()
970-
);
972+
return (array) ($this->action['excluded_middleware'] ?? []);
971973
}
972974

973975
/**

src/Illuminate/Routing/Router.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,15 @@ protected function runRouteWithinStack(Route $route, Request $request)
695695
*/
696696
public function gatherRouteMiddleware(Route $route)
697697
{
698+
$excluded = collect($route->excludedMiddleware())->map(function ($name) {
699+
return (array) MiddlewareNameResolver::resolve($name, $this->middleware, $this->middlewareGroups);
700+
})->flatten()->values()->all();
701+
698702
$middleware = collect($route->gatherMiddleware())->map(function ($name) {
699703
return (array) MiddlewareNameResolver::resolve($name, $this->middleware, $this->middlewareGroups);
700-
})->flatten()->reject(function ($name) use ($route) {
701-
return in_array($name, $route->skipMiddleware(), true);
702-
});
704+
})->flatten()->reject(function ($name) use ($route, $excluded) {
705+
return in_array($name, $excluded, true);
706+
})->values();
703707

704708
return $this->sortMiddleware($middleware);
705709
}

tests/Routing/RouteRegistrarTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public function testMiddlewareFluentRegistration()
6060
$this->assertEquals(['seven'], $this->getRoute()->middleware());
6161
}
6262

63-
public function testSkipMiddlewareRegistration()
63+
public function testWithoutMiddlewareRegistration()
6464
{
6565
$this->router->middleware(['one', 'two'])->get('users', function () {
6666
return 'all-users';
67-
})->skipMiddleware('one');
67+
})->withoutMiddleware('one');
6868

6969
$this->seeResponse('all-users', Request::create('users', 'GET'));
7070

71-
$this->assertEquals(['one'], $this->getRoute()->skipMiddleware());
71+
$this->assertEquals(['one'], $this->getRoute()->excludedMiddleware());
7272
}
7373

7474
public function testCanRegisterGetRouteWithClosureAction()

tests/Routing/RoutingRouteTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function testMiddlewareCanBeSkipped()
200200

201201
$router->get('foo/bar', ['middleware' => 'web', function () {
202202
return 'hello';
203-
}])->skipMiddleware(RoutingTestMiddlewareGroupTwo::class);
203+
}])->withoutMiddleware(RoutingTestMiddlewareGroupTwo::class);
204204

205205
$this->assertEquals('hello', $router->dispatch(Request::create('foo/bar', 'GET'))->getContent());
206206
}

0 commit comments

Comments
 (0)