Skip to content

Commit

Permalink
[8.x] Add colon port support in serve host option. (laravel#38522)
Browse files Browse the repository at this point in the history
* Add colon port support in server host option.

* Adding style changes.

* Update ServeCommand.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
2 people authored and victorvilella committed Oct 12, 2021
1 parent 342b629 commit aab031a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/Illuminate/Foundation/Console/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ protected function serverCommand()
*/
protected function host()
{
return $this->input->getOption('host');
[$host, ] = $this->getHostAndPort();

return $host;
}

/**
Expand All @@ -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.
*
Expand Down

0 comments on commit aab031a

Please sign in to comment.