Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88b2ad2

Browse files
committed
[WebServerBundle] Added ability to display the current hostname address if available when binding to 0.0.0.0
1 parent 5dadd95 commit 88b2ad2

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/Symfony/Bundle/WebServerBundle/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.2.0
5+
-----
6+
7+
* Added ability to display the current hostname address if available when binding to 0.0.0.0
8+
49
3.4.0
510
-----
611

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

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

135-
$io->success(sprintf('Server listening on http://%s', $config->getAddress()));
135+
$message = sprintf('Server listening on http://%s', $config->getAddress());
136+
if ('' !== $extra = $config->getExtraAddress()) {
137+
$message = sprintf('%s (http://%s)', $message, $extra);
138+
}
139+
$io->success($message);
136140
if (ini_get('xdebug.profiler_enable_trigger')) {
137141
$io->comment('Xdebug profiler trigger enabled.');
138142
}

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

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

145145
if (WebServer::STARTED === $server->start($config, $input->getOption('pidfile'))) {
146-
$io->success(sprintf('Server listening on http://%s', $config->getAddress()));
146+
$message = sprintf('Server listening on http://%s', $config->getAddress());
147+
if ('' !== $extra = $config->getExtraAddress()) {
148+
$message = sprintf('%s (http://%s)', $message, $extra);
149+
}
150+
$io->success($message);
147151
if (ini_get('xdebug.profiler_enable_trigger')) {
148152
$io->comment('Xdebug profiler trigger enabled.');
149153
}

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 getExtraAddress()
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)