From d978cbb0b0b2cacb1e2f240bb86ae2b7fedea4d1 Mon Sep 17 00:00:00 2001 From: Gary Green Date: Fri, 7 Oct 2016 13:46:42 +0100 Subject: [PATCH] Cleanup route:list command. --- .../Foundation/Console/RouteListCommand.php | 70 ++----------------- 1 file changed, 6 insertions(+), 64 deletions(-) diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index 511d04f314d4..a0ae2f479183 100644 --- a/src/Illuminate/Foundation/Console/RouteListCommand.php +++ b/src/Illuminate/Foundation/Console/RouteListCommand.php @@ -2,6 +2,7 @@ namespace Illuminate\Foundation\Console; +use Closure; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Routing\Route; @@ -137,74 +138,15 @@ protected function displayRoutes(array $routes) */ protected function getMiddleware($route) { - $middlewares = array_values($route->middleware()); + $middlewares = $route->gatherMiddleware(); - $actionName = $route->getActionName(); - - if (! empty($actionName) && $actionName !== 'Closure') { - $middlewares = array_merge($middlewares, $this->getControllerMiddleware($actionName)); - } - - return implode(',', $middlewares); - } - - /** - * Get the middleware for the given Controller@action name. - * - * @param string $actionName - * @return array - */ - protected function getControllerMiddleware($actionName) - { - $segments = explode('@', $actionName); - - return $this->getControllerMiddlewareFromInstance( - $this->laravel->make($segments[0]), - isset($segments[1]) ? $segments[1] : null - ); - } - - /** - * Get the middlewares for the given controller instance and method. - * - * @param \Illuminate\Routing\Controller $controller - * @param string|null $method - * @return array - */ - protected function getControllerMiddlewareFromInstance($controller, $method) - { - if (! method_exists($controller, 'getMiddleware')) { - return []; - } - - $middleware = $this->router->getMiddleware(); - - $results = []; - - foreach ($controller->getMiddleware() as $data) { - if (! is_string($data['middleware'])) { - continue; - } - - if (! $method || ! $this->methodExcludedByOptions($method, $data['options'])) { - $results[] = Arr::get($middleware, $data['middleware'], $data['middleware']); + foreach ($middlewares as $i => $middleware) { + if ($middleware instanceof Closure) { + $middlewares[$i] = 'Closure'; } } - return $results; - } - - /** - * Determine if the given options exclude a particular method. - * - * @param string $method - * @param array $options - * @return bool - */ - protected function methodExcludedByOptions($method, array $options) - { - return (! empty($options['only']) && ! in_array($method, (array) $options['only'])) || - (! empty($options['except']) && in_array($method, (array) $options['except'])); + return implode(',', $middlewares); } /**