Skip to content

Commit

Permalink
feature #28586 [WebServerBundle] Added ability to display the current…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
fabpot committed Oct 10, 2018
2 parents 6a4c8b9 + dfd2e8b commit c10d2c0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Bundle/WebServerBundle/CHANGELOG.md
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
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
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
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 comments on commit c10d2c0

Please sign in to comment.