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 cbcc6ca

Browse filesBrowse files
committed
feature #20809 [FrameworkBundle] Display the controller class name in 'debug:router' (lyrixx)
This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] Display the controller class name in 'debug:router' | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - --- Before: ![screenshot7](https://cloud.githubusercontent.com/assets/408368/21152351/318af764-c166-11e6-8245-1729779e9809.png) After: ![screenshot3](https://cloud.githubusercontent.com/assets/408368/21563210/02cf043e-ce80-11e6-94be-34736d85bb3b.png) Commits ------- 157a830 [FrameworkBundle] Display the controller class name in 'debug:router'
2 parents 1099f6b + 157a830 commit cbcc6ca
Copy full SHA for cbcc6ca

File tree

2 files changed

+33
-2
lines changed
Filter options

2 files changed

+33
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
+30-2Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\Console\Input\InputOption;
1818
use Symfony\Component\Console\Output\OutputInterface;
1919
use Symfony\Component\Console\Style\SymfonyStyle;
20+
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2021
use Symfony\Component\Routing\RouterInterface;
2122
use Symfony\Component\Routing\Route;
2223

@@ -85,13 +86,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
8586
throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name));
8687
}
8788

88-
$this->convertController($route);
89+
$callable = $this->extractCallable($route);
8990

9091
$helper->describe($io, $route, array(
9192
'format' => $input->getOption('format'),
9293
'raw_text' => $input->getOption('raw'),
9394
'name' => $name,
9495
'output' => $io,
96+
'callable' => $callable,
9597
));
9698
} else {
9799
foreach ($routes as $route) {
@@ -109,12 +111,38 @@ protected function execute(InputInterface $input, OutputInterface $output)
109111

110112
private function convertController(Route $route)
111113
{
112-
$nameParser = $this->getContainer()->get('controller_name_converter');
113114
if ($route->hasDefault('_controller')) {
115+
$nameParser = $this->getContainer()->get('controller_name_converter');
114116
try {
115117
$route->setDefault('_controller', $nameParser->build($route->getDefault('_controller')));
116118
} catch (\InvalidArgumentException $e) {
117119
}
118120
}
119121
}
122+
123+
private function extractCallable(Route $route)
124+
{
125+
if (!$route->hasDefault('_controller')) {
126+
return;
127+
}
128+
129+
$controller = $route->getDefault('_controller');
130+
131+
if (1 === substr_count($controller, ':')) {
132+
list($service, $method) = explode(':', $controller);
133+
try {
134+
return sprintf('%s::%s', get_class($this->getContainer()->get($service)), $method);
135+
} catch (ServiceNotFoundException $e) {
136+
}
137+
}
138+
139+
$nameParser = $this->getContainer()->get('controller_name_converter');
140+
try {
141+
$shortNotation = $nameParser->build($controller);
142+
$route->setDefault('_controller', $shortNotation);
143+
144+
return $controller;
145+
} catch (\InvalidArgumentException $e) {
146+
}
147+
}
120148
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ protected function describeRoute(Route $route, array $options = array())
9292
array('Defaults', $this->formatRouterConfig($route->getDefaults())),
9393
array('Options', $this->formatRouterConfig($route->getOptions())),
9494
);
95+
if (isset($options['callable'])) {
96+
$tableRows[] = array('Callable', $options['callable']);
97+
}
9598

9699
$table = new Table($this->getOutput());
97100
$table->setHeaders($tableHeaders)->setRows($tableRows);

0 commit comments

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