From aab031a10ec2f903550b5656dc89a9e3939257c7 Mon Sep 17 00:00:00 2001 From: Haider Ali <47752310+haider00125@users.noreply.github.com> Date: Tue, 24 Aug 2021 17:54:53 +0500 Subject: [PATCH] [8.x] Add colon port support in serve host option. (#38522) * Add colon port support in server host option. * Adding style changes. * Update ServeCommand.php Co-authored-by: Taylor Otwell --- .../Foundation/Console/ServeCommand.php | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Console/ServeCommand.php b/src/Illuminate/Foundation/Console/ServeCommand.php index e5477c28700b..331b9dbcb7a6 100644 --- a/src/Illuminate/Foundation/Console/ServeCommand.php +++ b/src/Illuminate/Foundation/Console/ServeCommand.php @@ -138,7 +138,9 @@ protected function serverCommand() */ protected function host() { - return $this->input->getOption('host'); + [$host, ] = $this->getHostAndPort(); + + return $host; } /** @@ -148,11 +150,32 @@ protected function host() */ protected function port() { - $port = $this->input->getOption('port') ?: 8000; + $port = $this->input->getOption('port'); + + if (is_null($port)) { + [, $port] = $this->getHostAndPort(); + } + + $port = $port ?: 8000; return $port + $this->portOffset; } + /** + * Get the host and port from the host option string. + * + * @return array + */ + protected function getHostAndPort() + { + $hostParts = explode(':', $this->input->getOption('host')); + + return [ + $hostParts[0], + $hostParts[1] ?? null, + ]; + } + /** * Check if the command has reached its max amount of port tries. *