Skip to content

Commit

Permalink
feature #20809 [FrameworkBundle] Display the controller class name in…
Browse files Browse the repository at this point in the history
… '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'
  • Loading branch information
fabpot committed Jan 2, 2017
2 parents 1099f6b + 157a830 commit cbcc6ca
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
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) {
}
}
}
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

0 comments on commit cbcc6ca

Please sign in to comment.