From 87d254db6360cf1d694e64f3c2092bf03b7dea59 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Tue, 14 Apr 2020 21:43:06 +0200 Subject: [PATCH] wip --- app/Commands/ServeCommand.php | 3 ++- app/Server/Connections/ConnectionManager.php | 8 ++++---- app/Server/Factory.php | 12 +++++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/Commands/ServeCommand.php b/app/Commands/ServeCommand.php index 6874ead..c191fdf 100644 --- a/app/Commands/ServeCommand.php +++ b/app/Commands/ServeCommand.php @@ -8,7 +8,7 @@ use LaravelZero\Framework\Commands\Command; class ServeCommand extends Command { - protected $signature = 'serve {host=127.0.0.1}'; + protected $signature = 'serve {host=0.0.0.0} {hostname=localhost}'; protected $description = 'Start the shaft server'; @@ -16,6 +16,7 @@ class ServeCommand extends Command { (new Factory()) ->setHost($this->argument('host')) + ->setHostname($this->argument('hostname')) ->createServer() ->run(); } diff --git a/app/Server/Connections/ConnectionManager.php b/app/Server/Connections/ConnectionManager.php index 7f5de1d..4a47fff 100644 --- a/app/Server/Connections/ConnectionManager.php +++ b/app/Server/Connections/ConnectionManager.php @@ -9,12 +9,12 @@ class ConnectionManager { /** @var array */ protected $connections = []; - protected $host; + protected $hostname; protected $port; - public function __construct($host, $port) + public function __construct($hostname, $port) { - $this->host = $host; + $this->hostname = $hostname; $this->port = $port; } @@ -50,7 +50,7 @@ class ConnectionManager public function host() { - return $this->host === '127.0.0.1' ? 'localhost' : $this->host; + return $this->hostname; } public function port() diff --git a/app/Server/Factory.php b/app/Server/Factory.php index 76ebe51..a626206 100644 --- a/app/Server/Factory.php +++ b/app/Server/Factory.php @@ -12,6 +12,9 @@ class Factory /** @var string */ protected $host = '127.0.0.1'; + /** @var string */ + protected $hostname = 'localhost'; + /** @var int */ protected $port = 8080; @@ -44,11 +47,18 @@ class Factory return $this; } + public function setHostname(string $hostname) + { + $this->hostname = $hostname; + + return $this; + } + public function createServer() { $socket = new Server("{$this->host}:{$this->port}", $this->loop); - $connectionManager = new ConnectionManager($this->host, $this->port); + $connectionManager = new ConnectionManager($this->hostname, $this->port); $app = new Shaft($connectionManager);