8000 [FrameworkBundle] Add --show-aliases option to debug:router command · symfony/symfony@a0441c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit a0441c1

Browse files
committed
[FrameworkBundle] Add --show-aliases option to debug:router command
1 parent 6df4a31 commit a0441c1

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CHANGELOG
2222
* Deprecate the `Http\Client\HttpClient` service, use `Psr\Http\Client\ClientInterface` instead
2323
* Add `stop_worker_on_signals` configuration option to `messenger` to define signals which would stop a worker
2424
* Add support for `--all` option to clear all cache pools with `cache:pool:clear` command
25+
* Add `--show-aliases` option to `debug:router` command
2526

2627
6.2
2728
---

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ protected function configure(): void
5656
->setDefinition([
5757
new InputArgument('name', InputArgument::OPTIONAL, 'A route name'),
5858
new InputOption('show-controllers', null, InputOption::VALUE_NONE, 'Show assigned controllers in overview'),
59+
new InputOption('show-aliases', null, InputOption::VALUE_NONE, 'Show aliases in overview'),
5960
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), 'txt'),
6061
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw route(s)'),
62+
6163
])
6264
->setHelp(<<<'EOF'
6365
The <info>%command.name%</info> displays the configured routes:
@@ -92,6 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9294
'format' => $input->getOption('format'),
9395
'raw_text' => $input->getOption('raw'),
9496
'show_controllers' => $input->getOption('show-controllers'),
97+
'show_aliases' => $input->getOption('show-aliases'),
9598
'output' => $io,
9699
]);
97100

@@ -120,6 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
120123
'format' => $input->getOption('format'),
121124
'raw_text' => $input->getOption('raw'),
122125
'show_controllers' => $input->getOption('show-controllers'),
126+
'show_aliases' => $input->getOption('show-aliases'),
123127
'output' => $io,
124128
'container' => $container,
125129
]);

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,21 @@ public function __construct(FileLinkFormatter $fileLinkFormatter = null)
4747
protected function describeRouteCollection(RouteCollection $routes, array $options = []): void
4848
{
4949
$showControllers = isset($options['show_controllers']) && $options['show_controllers'];
50+
$showAliases = $options['show_aliases'] ?? false;
5051

5152
$tableHeaders = ['Name', 'Method', 'Scheme', 'Host', 'Path'];
5253
if ($showControllers) {
5354
$tableHeaders[] = 'Controller';
5455
}
5556

57+
if ($showAliases) {
58+
$tableHeaders[] = 'Aliases';
59+
$reverseAliases = [];
60+
foreach ($routes->getAliases() as $name => $alias) {
61+
$reverseAliases[$alias->getId()][] = $name;
62+
}
63+
}
64+
5665
$tableRows = [];
5766
foreach ($routes->all() as $name => $route) {
5867
$controller = $route->getDefault('_controller');
@@ -69,6 +78,10 @@ protected function describeRouteCollection(RouteCollection $routes, array $optio
6978
$row[] = $controller ? $this->formatControllerLink($controller, $this->formatCallable($controller), $options['container'] ?? null) : '';
7079
}
7180

81+
if ($showAliases) {
82+
$row[] = implode('|', $reverseAliases[$name] ?? []);
83+
}
84+
7285
$tableRows[] = $row;
7386
}
7487

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ public function testComplete(array $input, array 67E6 $expectedSuggestions)
9696
$this->assertSame($expectedSuggestions, $tester->complete($input));
9797
}
9898

99+
public function testShowAliases()
100+
{
101+
$tester = $this->createCommandTester();
102+
103+
$this->assertSame(0, $tester->execute(['--show-aliases' => true]));
104+
$this->assertStringContainsString('my_custom_alias', $tester->getDisplay());
105+
}
106+
99107
public static function provideCompletionSuggestions()
100108
{
101109
yield 'option --format' => [

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/RouterDebug/routing.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ routerdebug_session_logout:
1313
routerdebug_test:
1414
path: /test
1515
defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SessionController::welcomeAction }
16+
17+
my_custom_alias:
18+
alias: routerdebug_test

0 commit comments

Comments
 (0)
0