Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Route list urifilter #40815

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/Illuminate/Foundation/Console/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Illuminate\Console\Command;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Routing\Router;
use Illuminate\Support\Arr;
Expand Down Expand Up @@ -126,6 +127,7 @@ protected function getRouteInformation(Route $route)
'name' => $route->getName(),
'action' => ltrim($route->getActionName(), '\\'),
'middleware' => $this->getMiddleware($route),
'route' => $route,
]);
}

Expand Down Expand Up @@ -187,16 +189,31 @@ protected function getMiddleware($route)
}

/**
* Filter the route by URI and / or name.
* Filter the route according to options given.
*
* @param array $route
* @return array|null
* @return array|void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect phpdoc. Needs to be null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove that if you like; I made that change because it was tripping static analysis tools.

*/
protected function filterRoute(array $route)
{
if (($this->option('name') && ! Str::contains($route['name'], $this->option('name'))) ||
$this->option('path') && ! Str::contains($route['uri'], $this->option('path')) ||
$this->option('method') && ! Str::contains($route['method'], strtoupper($this->option('method')))) {
if (
($this->option('name') && ! Str::contains($route['name'], $this->option('name'))) ||
($this->option('path') && ! Str::contains($route['uri'], $this->option('path'))) ||
($this->option('method') && ! Str::contains($route['method'], strtoupper($this->option('method'))))
) {
return;
}
//The domain option behaves differently depending on whether the uri option is also provided
if ($this->option('uri')) {
if (! $route['route']->matches(
Request::create(
($this->option('domain') ? 'https://'.$this->option('domain') : '').$this->option('uri'),
$this->option('method') ?: 'GET'
)
)) {
return;
}
} elseif ($this->option('domain') && ! Str::contains($route['domain'], $this->option('domain'))) {
return;
}

Expand Down Expand Up @@ -293,7 +310,9 @@ protected function getOptions()
['json', null, InputOption::VALUE_NONE, 'Output the route list as JSON'],
['method', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by method'],
['name', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by name'],
['path', null, InputOption::VALUE_OPTIONAL, 'Only show routes matching the given path pattern'],
['domain', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by domain'],
['path', null, InputOption::VALUE_OPTIONAL, 'Filter the routes by path'],
['uri', null, InputOption::VALUE_OPTIONAL, 'Evaluate a URI against routing rules'],
['except-path', null, InputOption::VALUE_OPTIONAL, 'Do not display the routes matching the given path pattern'],
['reverse', 'r', InputOption::VALUE_NONE, 'Reverse the ordering of the routes'],
['sort', null, InputOption::VALUE_OPTIONAL, 'The column (precedence, domain, method, uri, name, action, middleware) to sort by', 'uri'],
Expand Down