Skip to content

Commit

Permalink
[Routing] display hostname pattern in router:debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb committed Nov 12, 2012
1 parent 805806a commit 462999d
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php
Expand Up @@ -82,37 +82,39 @@ protected function outputRoutes(OutputInterface $output, $routes = null)

$output->writeln($this->getHelper('formatter')->formatSection('router', 'Current routes'));

$maxName = 4;
$maxMethod = 6;
$maxName = strlen('name');
$maxMethod = strlen('method');
$maxHostname = strlen('hostname');

foreach ($routes as $name => $route) {
$requirements = $route->getRequirements();
$method = isset($requirements['_method'])
? strtoupper(is_array($requirements['_method'])
? implode(', ', $requirements['_method']) : $requirements['_method']
)
: 'ANY';
$hostname = null !== $route->getHostnamePattern()
? $route->getHostnamePattern() : 'ANY';

if (strlen($name) > $maxName) {
$maxName = strlen($name);
}

if (strlen($method) > $maxMethod) {
$maxMethod = strlen($method);
}
$maxName = max($maxName, strlen($name));
$maxMethod = max($maxMethod, strlen($method));
$maxHostname = max($maxHostname, strlen($hostname));
}
$format = '%-'.$maxName.'s %-'.$maxMethod.'s %s';
$format = '%-'.$maxName.'s %-'.$maxMethod.'s %-'.$maxHostname.'s %s';

// displays the generated routes
$format1 = '%-'.($maxName + 19).'s %-'.($maxMethod + 19).'s %s';
$output->writeln(sprintf($format1, '<comment>Name</comment>', '<comment>Method</comment>', '<comment>Pattern</comment>'));
$format1 = '%-'.($maxName + 19).'s %-'.($maxMethod + 19).'s %-'.($maxHostname + 19).'s %s';
$output->writeln(sprintf($format1, '<comment>Name</comment>', '<comment>Method</comment>', '<comment>Hostname</comment>', '<comment>Pattern</comment>'));
foreach ($routes as $name => $route) {
$requirements = $route->getRequirements();
$method = isset($requirements['_method'])
? strtoupper(is_array($requirements['_method'])
? implode(', ', $requirements['_method']) : $requirements['_method']
)
: 'ANY';
$output->writeln(sprintf($format, $name, $method, $route->getPattern()));
$hostname = null !== $route->getHostnamePattern()
? $route->getHostnamePattern() : 'ANY';
$output->writeln(sprintf($format, $name, $method, $hostname, $route->getPattern()));
}
}

Expand Down

0 comments on commit 462999d

Please sign in to comment.