Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 39b9fb3

Browse filesBrowse files
committed
[FrameworkBundle][Command] Fix debug:router --no-interaction error when several route match
When command `debug:router` is used in non-interactive mode with a name that matches more than one route, render the list of matching routes
1 parent 81c9e39 commit 39b9fb3
Copy full SHA for 39b9fb3

File tree

1 file changed

+28
-1
lines changed
Filter options

1 file changed

+28
-1
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
+28-1Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8181
$routes = $this->router->getRouteCollection();
8282

8383
if ($name) {
84-
if (!($route = $routes->get($name)) && $matchingRoutes = $this->findRouteNameContaining($name, $routes)) {
84+
$route = $routes->get($name);
85+
$matchingRoutes = $this->findRouteNameContaining($name, $routes);
86+
87+
if (!$input->isInteractive() && !$route && count($matchingRoutes) > 1) {
88+
$foundRoutes = $this->findRouteContaining($name, $routes);
89+
$helper->describe($io, $foundRoutes, [
90+
'format' => $input->getOption('format'),
91+
'raw_text' => $input->getOption('raw'),
92+
'show_controllers' => $input->getOption('show-controllers'),
93+
'output' => $io,
94+
]);
95+
96+
return 0;
97+
}
98+
99+
if (!$route && $matchingRoutes) {
85100
$default = 1 === \count($matchingRoutes) ? $matchingRoutes[0] : null;
86101
$name = $io->choice('Select one of the matching routes', $matchingRoutes, $default);
87102
$route = $routes->get($name);
@@ -120,4 +135,16 @@ private function findRouteNameContaining(string $name, RouteCollection $routes):
120135

121136
return $foundRoutesNames;
122137
}
138+
139+
private function findRouteContaining(string $name, RouteCollection $routes): RouteCollection
140+
{
141+
$foundRoutes = new RouteCollection();
142+
foreach ($routes as $routeName => $route) {
143+
if (false !== stripos($routeName, $name)) {
144+
$foundRoutes->add($routeName, $route);
145+
}
146+
}
147+
148+
return $foundRoutes;
149+
}
123150
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.