-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathServeCommand.php
More file actions
67 lines (55 loc) · 2.1 KB
/
Copy pathServeCommand.php
File metadata and controls
67 lines (55 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace BangNokia\ServeLiveReload\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;
class ServeCommand extends Command
{
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';
public function handle()
{
$phpBinaryPath = (new PhpExecutableFinder())->find(false);
$artisanPath = base_path('artisan');
$processes = [
$httpProcess = new Process([$phpBinaryPath, $artisanPath, 'serve:http'] + $this->serveOptions()),
$socketProcess = new Process([$phpBinaryPath, $artisanPath, 'serve:websockets']),
];
while (count($processes)) {
/* @var \Symfony\Component\Process\Process $process */
foreach ($processes as $i => $process) {
if (!$process->isStarted()) {
$process->setTimeout(null);
$process->start();
continue;
}
if ($info = trim($process->getIncrementalOutput())) {
$this->info($info);
}
if ($error = trim($process->getIncrementalErrorOutput())) {
$this->line($error);
}
if (!$process->isRunning()) {
unset($processes[$i]);
}
}
sleep(1);
}
}
public function serveOptions()
{
return collect($this->options())
->filter(function ($option) {
return $option;
})->map(function ($value, $key) {
if (is_bool($value)) {
return "--{$key}";
}
return "--{$key}={$value}";
})->values()->toArray();
}
}