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

[9.x] Fix route:list --except-vendor hiding Route::view() & Route::redirect() #41465

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Illuminate/Foundation/Console/RouteListCommand.php
Expand Up @@ -223,7 +223,11 @@ protected function isVendorRoute(Route $route)
str_contains($route->action['uses'], 'SerializableClosure')) {
return false;
} elseif (is_string($route->action['uses'])) {
$path = (new ReflectionClass(explode('@', $route->action['uses'])[0]))
if ($this->isFrameworkController($route)) {
return false;
}

$path = (new ReflectionClass($route->getControllerClass()))
->getFileName();
} else {
return false;
Expand All @@ -232,6 +236,20 @@ protected function isVendorRoute(Route $route)
return str_starts_with($path, base_path('vendor'));
}

/**
* Determine if the route uses a framework controller.
*
* @param \Illuminate\Routing\Route $route
* @return bool
*/
protected function isFrameworkController(Route $route)
{
return in_array($route->getControllerClass(), [
'\Illuminate\Routing\RedirectController',
'\Illuminate\Routing\ViewController',
], true);
}

/**
* Filter the route by URI and / or name.
*
Expand Down
12 changes: 11 additions & 1 deletion src/Illuminate/Routing/Route.php
Expand Up @@ -270,14 +270,24 @@ protected function runController()
public function getController()
{
if (! $this->controller) {
$class = $this->parseControllerCallback()[0];
$class = $this->getControllerClass();

$this->controller = $this->container->make(ltrim($class, '\\'));
}

return $this->controller;
}

/**
* Get the controller class used for the route.
*
* @return string
*/
public function getControllerClass()
{
return $this->parseControllerCallback()[0];
}

/**
* Get the controller method used for the route.
*
Expand Down
15 changes: 15 additions & 0 deletions tests/Testing/Console/RouteListCommandTest.php
Expand Up @@ -113,6 +113,21 @@ public function testRouteCanBeFilteredByName()
->expectsOutput('');
}

public function testDisplayRoutesExceptVendor()
{
$this->router->get('foo/{user}', [FooController::class, 'show']);
$this->router->view('view', 'blade.path');
$this->router->redirect('redirect', 'destination');

$this->artisan(RouteListCommand::class, ['-v' => true, '--except-vendor' => true])
->assertSuccessful()
->expectsOutput('')
->expectsOutput(' GET|HEAD foo/{user} Illuminate\Tests\Testing\Console\FooController@show')
->expectsOutput(' ANY redirect .... Illuminate\Routing\RedirectController')
->expectsOutput(' GET|HEAD view .............................................. ')
->expectsOutput('');
}

protected function tearDown(): void
{
parent::tearDown();
Expand Down