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

Skip to content

Commit 543f496

Browse files
committed
[FrameworkBundle] Display the class name in 'debug:router' when the controller is a service
1 parent 69dcf41 commit 543f496

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

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

Lines changed: 34 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,7 +86,12 @@ 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+
// Converts a short notation service:method to a class::method.
90+
if ('txt' === $input->getOption('format')) {
91+
$this->convertControllerWithClassName($route);
92+
} else {
93+
$this->convertController($route);
94+
}
8995

9096
$helper->describe($io, $route, array(
9197
'format' => $input->getOption('format'),
@@ -109,12 +115,38 @@ protected function execute(InputInterface $input, OutputInterface $output)
109115

110116
private function convertController(Route $route)
111117
{
112-
$nameParser = $this->getContainer()->get('controller_name_converter');
113118
if ($route->hasDefault('_controller')) {
119+
$nameParser = $this->getContainer()->get('controller_name_converter');
114120
try {
115121
$route->setDefault('_controller', $nameParser->build($route->getDefault('_controller')));
116122
} catch (\InvalidArgumentException $e) {
117123
}
118124
}
119125
}
126+
127+
private function convertControllerWithClassName(Route $route)
128+
{
129+
if (!$route->hasDefault('_controller')) {
130+
return;
131+
}
132+
133+
$controller = $route->getDefault('_controller');
134+
135+
if (1 === substr_count($controller, ':')) {
136+
list($service, $method) = explode(':', $controller);
137+
try {
138+
$route->setDefault('_controller', sprintf("%s\n class: %s", $service, get_class($this->getContainer()->get($service)), $method));
139+
} catch (ServiceNotFoundException $e) {
140+
}
141+
142+
return;
143+
}
144+
145+
$nameParser = $this->getContainer()->get('controller_name_converter');
146+
try {
147+
$shortNotation = $nameParser->build($controller);
148+
$route->setDefault('_controller', sprintf("%s\n class: %s", $shortNotation, $controller));
149+
} catch (\InvalidArgumentException $e) {
150+
}
151+
}
120152
}

0 commit comments

Comments
 (0)