1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace FondBot\Toolbelt\Commands; |
6
|
|
|
|
7
|
|
|
use FondBot\Toolbelt\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Process\PhpExecutableFinder; |
10
|
|
|
use Symfony\Component\Process\ProcessUtils; |
11
|
|
|
|
12
|
|
|
class ServerRun extends Command |
13
|
|
|
{ |
14
|
|
|
protected function configure(): void |
15
|
|
|
{ |
16
|
|
|
$this |
17
|
|
|
->setName('serve') |
18
|
|
|
->setDescription('Run server') |
19
|
|
|
->addOption('host', null, InputArgument::OPTIONAL, 'The host address to serve the application on.', '127.0.0.1') |
20
|
|
|
->addOption('port', null, InputArgument::OPTIONAL, 'The port to serve the application on.', '8000'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get the port for the command. |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
protected function port() |
29
|
|
|
{ |
30
|
|
|
return $this->input->getOption('port'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the host for the command. |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
protected function host() |
39
|
|
|
{ |
40
|
|
|
return $this->input->getOption('host'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the full server command. |
45
|
|
|
* |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
protected function serverCommand() : string |
49
|
|
|
{ |
50
|
|
|
return sprintf('%s -S %s:%s %s/public/index.php', |
51
|
|
|
ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false)), |
|
|
|
|
52
|
|
|
$this->host(), |
53
|
|
|
$this->port(), |
54
|
|
|
ProcessUtils::escapeArgument(path()) |
|
|
|
|
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function handle(): void |
59
|
|
|
{ |
60
|
|
|
chdir(path()); |
61
|
|
|
$this->line("<info>Fondbot development server started:</info> <http://{$this->host()}:{$this->port()}>"); |
62
|
|
|
passthru($this->serverCommand()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|