From 3a328566805214291358c010221296047eb5d803 Mon Sep 17 00:00:00 2001 From: Ahrim Fakhriy Date: Fri, 19 Feb 2021 23:45:09 +0800 Subject: [PATCH 1/2] Add support for options to serve such as host/port --- src/Commands/ServeCommand.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Commands/ServeCommand.php b/src/Commands/ServeCommand.php index 84ae111..136fa01 100644 --- a/src/Commands/ServeCommand.php +++ b/src/Commands/ServeCommand.php @@ -8,7 +8,11 @@ class ServeCommand extends Command { - protected $signature = 'serve'; + protected $signature = 'serve + {--host= : The host address to serve the application on} + {--port= : The port to serve the application on} + {--tries= : The max number of ports to attempt to serve from} + {--no-reload : Do not reload the development server on .env file changes}'; protected $description = 'Serve the application on the PHP development server'; @@ -18,7 +22,7 @@ public function handle() $artisanPath = base_path('artisan'); $processes = [ - $httpProcess = new Process([$phpBinaryPath, $artisanPath, 'serve:http']), + $httpProcess = new Process([$phpBinaryPath, $artisanPath, 'serve:http', ...$this->serveOptions()]), $socketProcess = new Process([$phpBinaryPath, $artisanPath, 'serve:websockets']), ]; @@ -46,4 +50,12 @@ public function handle() sleep(1); } } + + public function serveOptions() + { + return collect($this->options()) + ->filter(fn($option) => $option) + ->map(fn($value, $key) => is_bool($value) ? "--{$key}" : "--{$key}={$value}") + ->values(); + } } From 66ced1252d1dcd05462489c17df083fc15d8ba48 Mon Sep 17 00:00:00 2001 From: Ahrim Fakhriy Date: Fri, 19 Feb 2021 23:50:44 +0800 Subject: [PATCH 2/2] Changed fn usage to function --- src/Commands/ServeCommand.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Commands/ServeCommand.php b/src/Commands/ServeCommand.php index 136fa01..5cc5369 100644 --- a/src/Commands/ServeCommand.php +++ b/src/Commands/ServeCommand.php @@ -54,8 +54,15 @@ public function handle() public function serveOptions() { return collect($this->options()) - ->filter(fn($option) => $option) - ->map(fn($value, $key) => is_bool($value) ? "--{$key}" : "--{$key}={$value}") - ->values(); + ->filter(function($option) { + return $option; + + })->map(function($value, $key) { + if(is_bool($value)) + return "--{$key}"; + + return "--{$key}={$value}"; + + })->values(); } -} +} \ No newline at end of file