8000 feature #28586 [WebServerBundle] Added ability to display the current… · symfony/symfony@c10d2c0 · GitHub
[go: up one dir, main page]

Skip to content

Commit c10d2c0

Browse files
committed
feature #28586 [WebServerBundle] Added ability to display the current hostname address if available when binding to 0.0.0.0 (respinoza)
This PR was merged into the 4.2-dev branch. Discussion ---------- [WebServerBundle] Added ability to display the current hostname address if available when binding to 0.0.0.0 | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | ? (no tests for server commands) | Fixed tickets | #28585 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Tries to get the local hostname into an ip (if available) using the PHP gethostname* methods. Commits ------- dfd2e8b [WebServerBundle] Added ability to display the current hostname address if available when binding to 0.0.0.0
2 parents 6a4c8b9 + dfd2e8b commit c10d2c0

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

src/Symfony/Bundle/WebServerBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Deprecated omitting the `$environment` argument of the `ServerRunCommand` and
88
`ServerStartCommand` constructors
9+
* Added ability to display the current hostname address if available when binding to 0.0.0.0
910

1011
3.4.0
1112
-----

src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
137137
$server = new WebServer();
138138
$config = new WebServerConfig($documentRoot, $env, $input->getArgument('addressport'), $input->getOption('router'));
139139

140-
$io->success(sprintf('Server listening on http://%s', $config->getAddress()));
140+
$message = sprintf('Server listening on http://%s', $config->getAddress());
141+
if ('' !== $displayAddress = $config->getDisplayAddress()) {
142+
$message = sprintf('Server listening on all interfaces, port %s -- see http://%s', $config->getPort(), $displayAddress);
143+
}
144+
$io->success($message);
141145
if (ini_get('xdebug.profiler_enable_trigger')) {
142146
$io->comment('Xdebug profiler trigger enabled.');
143147
}

src/Symfony/Bundle/WebServerBundle/Command/ServerStartCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
148148
$config = new WebServerConfig($documentRoot, $env, $input->getArgument('addressport'), $input->getOption('router'));
149149

150150
if (WebServer::STARTED === $server->start($config, $input->getOption('pidfile'))) {
151-
$io->success(sprintf('Server listening on http://%s', $config->getAddress()));
151+
$message = sprintf('Server listening on http://%s', $config->getAddress());
152+
if ('' !== $displayAddress = $config->getDisplayAddress()) {
153+
$message = sprintf('Server listening on all interfaces, port %s -- see http://%s', $config->getPort(), $displayAddress);
154+
}
155+
$io->success($message);
152156
if (ini_get('xdebug.profiler_enable_trigger')) {
153157
$io->comment('Xdebug profiler trigger enabled.');
154158
}

src/Symfony/Bundle/WebServerBundle/WebServerConfig.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ public function getAddress()
101101
return $this->hostname.':'.$this->port;
102102
}
103103

104+
/**
105+
* @return string contains resolved hostname if available, empty string otherwise
106+
*/
107+
public function getDisplayAddress()
108+
{
109+
if ('0.0.0.0' !== $this->hostname) {
110+
return '';
111+
}
112+
113+
if (false === $localHostname = gethostname()) {
114+
return '';
115+
}
116+
117+
return gethostbyname($localHostname).':'.$this->port;
118+
}
119+
104120
private function findFrontController($documentRoot, $env)
105121
{
106122
$fileNames = $this->getFrontControllerFileNames($env);

0 commit comments

Comments
 (0)
0