Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit0a0345a

Browse files
committed
bug#45947 [FrameworkBundle] [Command] Fixdebug:router --no-interaction error … (WilliamBoulle)
This PR was squashed before being merged into the 4.4 branch.Discussion----------[FrameworkBundle] [Command] Fix `debug:router --no-interaction` error …| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets |Fix#45777| License | MITWhen command `debug:router` is used in non-interactive mode with a name that matches more than one route, render the list of matching routes![debug_router_profiler_nointeraction](https://user-images.githubusercontent.com/18715733/161756561-cb2b5f75-111d-4920-8e81-8066b302a887.png)Commits-------e92e261 [FrameworkBundle] [Command] Fix `debug:router --no-interaction` error …
2 parents33420de +e92e261 commit0a0345a

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,21 @@ 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+
$helper->describe($io,$this->findRouteContaining($name,$routes), [
89+
'format' =>$input->getOption('format'),
90+
'raw_text' =>$input->getOption('raw'),
91+
'show_controllers' =>$input->getOption('show-controllers'),
92+
'output' =>$io,
93+
]);
94+
95+
return0;
96+
}
97+
98+
if (!$route &&$matchingRoutes) {
8599
$default =1 ===\count($matchingRoutes) ?$matchingRoutes[0] :null;
86100
$name =$io->choice('Select one of the matching routes',$matchingRoutes,$default);
87101
$route =$routes->get($name);
@@ -120,4 +134,16 @@ private function findRouteNameContaining(string $name, RouteCollection $routes):
120134

121135
return$foundRoutesNames;
122136
}
137+
138+
privatefunctionfindRouteContaining(string$name,RouteCollection$routes):RouteCollection
139+
{
140+
$foundRoutes =newRouteCollection();
141+
foreach ($routesas$routeName =>$route) {
142+
if (false !==stripos($routeName,$name)) {
143+
$foundRoutes->add($routeName,$route);
144+
}
145+
}
146+
147+
return$foundRoutes;
148+
}
123149
}

‎src/Symfony/Bundle/FrameworkBundle/Tests/Functional/RouterDebugCommandTest.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ public function testSearchMultipleRoutes()
6161
$this->assertStringContainsString('/test',$tester->getDisplay());
6262
}
6363

64+
publicfunctiontestSearchMultipleRoutesWithoutInteraction()
65+
{
66+
$tester =$this->createCommandTester();
67+
$ret =$tester->execute(['name' =>'routerdebug'], ['interactive' =>false]);
68+
69+
$this->assertSame(0,$ret,'Returns 0 in case of success');
70+
$this->assertStringNotContainsString('Select one of the matching routes:',$tester->getDisplay());
71+
$this->assertStringContainsString('routerdebug_session_welcome',$tester->getDisplay());
72+
$this->assertStringContainsString('/session',$tester->getDisplay());
73+
$this->assertStringContainsString('routerdebug_session_welcome_name',$tester->getDisplay());
74+
$this->assertStringContainsString('/session/{name}',$tester->getDisplay());
75+
$this->assertStringContainsString('routerdebug_session_logout',$tester->getDisplay());
76+
$this->assertStringContainsString('/session_logout',$tester->getDisplay());
77+
$this->assertStringContainsString('routerdebug_test',$tester->getDisplay());
78+
$this->assertStringContainsString('/test',$tester->getDisplay());
79+
}
80+
6481
publicfunctiontestSearchWithThrow()
6582
{
6683
$this->expectException(\InvalidArgumentException::class);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp