From 462999d2d2b3e667e07f341ac69fdf8bf3f4685f Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Sat, 14 Apr 2012 19:21:10 +0200 Subject: [PATCH] [Routing] display hostname pattern in router:debug output --- .../Command/RouterDebugCommand.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index 1bc4d0d463..b225857553 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -82,8 +82,10 @@ EOF $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']) @@ -91,20 +93,18 @@ EOF ? 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, 'Name', 'Method', 'Pattern')); + $format1 = '%-'.($maxName + 19).'s %-'.($maxMethod + 19).'s %-'.($maxHostname + 19).'s %s'; + $output->writeln(sprintf($format1, 'Name', 'Method', 'Hostname', 'Pattern')); foreach ($routes as $name => $route) { $requirements = $route->getRequirements(); $method = isset($requirements['_method']) @@ -112,7 +112,9 @@ EOF ? 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())); } }