Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 157a830

Browse files
committed
[FrameworkBundle] Display the controller class name in 'debug:router'
1 parent 61a67ec commit 157a830

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

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

Lines 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

Lines 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)