Skip to content

Commit 462999d

Browse files
committed
[Routing] display hostname pattern in router:debug output
1 parent 805806a commit 462999d

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,37 +82,39 @@ protected function outputRoutes(OutputInterface $output, $routes = null)
8282

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

85-
$maxName = 4;
86-
$maxMethod = 6;
85+
$maxName = strlen('name');
86+
$maxMethod = strlen('method');
87+
$maxHostname = strlen('hostname');
88+
8789
foreach ($routes as $name => $route) {
8890
$requirements = $route->getRequirements();
8991
$method = isset($requirements['_method'])
9092
? strtoupper(is_array($requirements['_method'])
9193
? implode(', ', $requirements['_method']) : $requirements['_method']
9294
)
9395
: 'ANY';
96+
$hostname = null !== $route->getHostnamePattern()
97+
? $route->getHostnamePattern() : 'ANY';
9498

95-
if (strlen($name) > $maxName) {
96-
$maxName = strlen($name);
97-
}
98-
99-
if (strlen($method) > $maxMethod) {
100-
$maxMethod = strlen($method);
101-
}
99+
$maxName = max($maxName, strlen($name));
100+
$maxMethod = max($maxMethod, strlen($method));
101+
$maxHostname = max($maxHostname, strlen($hostname));
102102
}
103-
$format = '%-'.$maxName.'s %-'.$maxMethod.'s %s';
103+
$format = '%-'.$maxName.'s %-'.$maxMethod.'s %-'.$maxHostname.'s %s';
104104

105105
// displays the generated routes
106-
$format1 = '%-'.($maxName + 19).'s %-'.($maxMethod + 19).'s %s';
107-
$output->writeln(sprintf($format1, '<comment>Name</comment>', '<comment>Method</comment>', '<comment>Pattern</comment>'));
106+
$format1 = '%-'.($maxName + 19).'s %-'.($maxMethod + 19).'s %-'.($maxHostname + 19).'s %s';
107+
$output->writeln(sprintf($format1, '<comment>Name</comment>', '<comment>Method</comment>', '<comment>Hostname</comment>', '<comment>Pattern</comment>'));
108108
foreach ($routes as $name => $route) {
109109
$requirements = $route->getRequirements();
110110
$method = isset($requirements['_method'])
111111
? strtoupper(is_array($requirements['_method'])
112112
? implode(', ', $requirements['_method']) : $requirements['_method']
113113
)
114114
: 'ANY';
115-
$output->writeln(sprintf($format, $name, $method, $route->getPattern()));
115+
$hostname = null !== $route->getHostnamePattern()
116+
? $route->getHostnamePattern() : 'ANY';
117+
$output->writeln(sprintf($format, $name, $method, $hostname, $route->getPattern()));
116118
}
117119
}
118120

0 commit comments

Comments
 (0)