8000 [WebServerBundle] Added ability to display the current hostname address if available when binding to 0.0.0.0 by respinoza · Pull Request #28586 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WebServerBundle] Added ability to display the current hostname address if available when binding to 0.0.0.0 #28586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[WebServerBundle] Added ability to display the current hostname addre…
…ss if available when binding to 0.0.0.0
  • Loading branch information
respinoza committed Oct 9, 2018
commit dfd2e8b4e6d77a59a18f4a40b09c878242413d58
1 change: 1 addition & 0 deletions src/Symfony/Bundle/WebServerBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

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

3.4.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$server = new WebServer();
$config = new WebServerConfig($documentRoot, $env, $input->getArgument('addressport'), $input->getOption('router'));

$io->success(sprintf('Server listening on http://%s', $config->getAddress()));
$message = sprintf('Server listening on http://%s', $config->getAddress());
if ('' !== $displayAddress = $config->getDisplayAddress()) {
$message = sprintf('Server listening on all interfaces, port %s -- see http://%s', $config->getPort(), $displayAddress);
}
$io->success($message);
if (ini_get('xdebug.profiler_enable_trigger')) {
$io->comment('Xdebug profiler trigger enabled.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$config = new WebServerConfig($documentRoot, $env, $input->getArgument('addressport'), $input->getOption('router'));

if (WebServer::STARTED === $server->start($config, $input->getOption('pidfile'))) {
$io->success(sprintf('Server listening on http://%s', $config->getAddress()));
$message = sprintf('Server listening on http://%s', $config->getAddress());
if ('' !== $displayAddress = $config->getDisplayAddress()) {
$message = sprintf('Server listening on all interfaces, port %s -- see http://%s', $config->getPort(), $displayAddress);
}
$io->success($message);
if (ini_get('xdebug.profiler_enable_trigger')) {
$io->comment('Xdebug profiler trigger enabled.');
}
Expand Down
16 changes: 16 additions & 0 deletions src/Symfony/Bundle/WebServerBundle/WebServerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ public function getAddress()
return $this->hostname.':'.$this->port;
}

/**
* @return string contains resolved hostname if available, empty string otherwise
*/
public function getDisplayAddress()
{
if ('0.0.0.0' !== $this->hostname) {
return '';
}

if (false === $localHostname = gethostname()) {
return '';
}

return gethostbyname($localHostname).':'.$this->port;
}

private function findFrontController($documentRoot, $env)
{
$fileNames = $this->getFrontControllerFileNames($env);
Expand Down
0