Skip to content

[FrameworkBundle] Display the controller class name in 'debug:router' #20809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Routing\Route;

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

$this->convertController($route);
$callable = $this->extractCallable($route);

$helper->describe($io, $route, array(
'format' => $input->getOption('format'),
'raw_text' => $input->getOption('raw'),
'name' => $name,
'output' => $io,
'callable' => $callable,
));
} else {
foreach ($routes as $route) {
Expand All @@ -109,12 +111,38 @@ protected function execute(InputInterface $input, OutputInterface $output)

private function convertController(Route $route)
{
$nameParser = $this->getContainer()->get('controller_name_converter');
if ($route->hasDefault('_controller')) {
$nameParser = $this->getContainer()->get('controller_name_converter');
try {
$route->setDefault('_controller', $nameParser->build($route->getDefault('_controller')));
} catch (\InvalidArgumentException $e) {
}
}
}

private function extractCallable(Route $route)
{
if (!$route->hasDefault('_controller')) {
return;
}

$controller = $route->getDefault('_controller');

if (1 === substr_count($controller, ':')) {
list($service, $method) = explode(':', $controller);
try {
return sprintf('%s::%s', get_class($this->getContainer()->get($service)), $method);
} catch (ServiceNotFoundException $e) {
}
}

$nameParser = $this->getContainer()->get('controller_name_converter');
try {
$shortNotation = $nameParser->build($controller);
$route->setDefault('_controller', $shortNotation);

return $controller;
} catch (\InvalidArgumentException $e) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ protected function describeRoute(Route $route, array $options = array())
array('Defaults', $this->formatRouterConfig($route->getDefaults())),
array('Options', $this->formatRouterConfig($route->getOptions())),
);
if (isset($options['callable'])) {
$tableRows[] = array('Callable', $options['callable']);
}

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