Skip to content

Commit

Permalink
Merge branch 'cleanup-route-list' of https://github.com/garygreen/fra…
Browse files Browse the repository at this point in the history
…mework into garygreen-cleanup-route-list
  • Loading branch information
taylorotwell committed Oct 7, 2016
2 parents cc1df99 + d978cbb commit 0e1c090
Showing 1 changed file with 6 additions and 64 deletions.
70 changes: 6 additions & 64 deletions src/Illuminate/Foundation/Console/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Foundation\Console;

use Closure;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Routing\Route;
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 0e1c090

Please sign in to comment.