-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
ServeCommand.php
61 lines (48 loc) · 1.6 KB
/
ServeCommand.php
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
<?php
declare(strict_types=1);
namespace Hyde\Console\Commands;
use Hyde\Hyde;
use Hyde\Facades\Config;
use Illuminate\Support\Facades\Process;
use LaravelZero\Framework\Commands\Command;
use function sprintf;
/**
* Start the realtime compiler server.
*
* @see https://github.com/hydephp/realtime-compiler
*/
class ServeCommand extends Command
{
/** @var string */
protected $signature = 'serve {--host= : <comment>[default: "localhost"]</comment>}} {--port= : <comment>[default: 8080]</comment>}';
/** @var string */
protected $description = 'Start the realtime compiler server.';
public function handle(): int
{
$this->line('<info>Starting the HydeRC server...</info> Press Ctrl+C to stop');
$this->runServerProcess(sprintf('php -S %s:%d %s',
$this->getHostSelection(),
$this->getPortSelection(),
$this->getExecutablePath()
));
return Command::SUCCESS;
}
protected function getPortSelection(): int
{
return (int) ($this->option('port') ?: Config::getInt('hyde.server.port', 8080));
}
protected function getHostSelection(): string
{
return (string) $this->option('host') ?: Config::getString('hyde.server.host', 'localhost');
}
protected function getExecutablePath(): string
{
return Hyde::path('vendor/hyde/realtime-compiler/bin/server.php');
}
protected function runServerProcess(string $command): void
{
Process::forever()->run($command, function (string $type, string $line): void {
$this->output->write($line);
});
}
}