|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BrainExe\Core\Console; |
|
4
|
|
|
|
|
5
|
|
|
use BrainExe\Core\Annotations\Inject; |
|
6
|
|
|
use Symfony\Component\Console\Command\Command; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
11
|
|
|
use Symfony\Component\Process\ProcessBuilder; |
|
12
|
|
|
use BrainExe\Core\Annotations\Command as CommandAnnotation; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @todo matze |
|
|
|
|
|
|
16
|
|
|
* @CommandAnnotation |
|
17
|
|
|
*/ |
|
18
|
|
|
class ServerRunCommand extends Command |
|
19
|
|
|
{ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
private $serverAddress; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var ProcessBuilder |
|
28
|
|
|
*/ |
|
29
|
|
|
private $processBuilder; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @Inject({ |
|
33
|
|
|
* "processBuilder" = "@ProcessBuilder", |
|
34
|
|
|
* "address" = "%server.host%" |
|
35
|
|
|
* }) |
|
36
|
|
|
* @param ProcessBuilder $processBuilder |
|
37
|
|
|
* @param string $address |
|
38
|
|
|
*/ |
|
39
|
2 |
|
public function __construct(ProcessBuilder $processBuilder, string $address) |
|
40
|
|
|
{ |
|
41
|
2 |
|
$this->serverAddress = $address; |
|
42
|
2 |
|
$this->processBuilder = $processBuilder; |
|
43
|
|
|
|
|
44
|
2 |
|
parent::__construct(null); |
|
45
|
2 |
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
2 |
|
protected function configure() |
|
51
|
|
|
{ |
|
52
|
|
|
$this |
|
53
|
2 |
|
->addArgument('address', InputArgument::OPTIONAL, 'host:port') |
|
54
|
2 |
|
->addOption('quiet', 'q', InputOption::VALUE_NONE) |
|
55
|
2 |
|
->setName('server:run') |
|
56
|
2 |
|
->setDescription('Runs PHP built-in web server'); |
|
57
|
2 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
1 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
63
|
|
|
{ |
|
64
|
1 |
|
$address = $input->getArgument('address') ?: $this->serverAddress; |
|
65
|
|
|
|
|
66
|
1 |
|
$output->writeln(sprintf("Server running on <info>%s</info>\n", $address)); |
|
67
|
|
|
|
|
68
|
1 |
|
$process = $this->processBuilder |
|
69
|
1 |
|
->setArguments([PHP_BINARY, '-S', $address]) |
|
70
|
1 |
|
->setWorkingDirectory(ROOT . 'web/') |
|
71
|
1 |
|
->setTimeout(null) |
|
72
|
1 |
|
->getProcess(); |
|
73
|
|
|
|
|
74
|
1 |
|
$process->run(function ($type, $buffer) use ($output, $input) { |
|
75
|
|
|
unset($type); |
|
76
|
|
|
if (!$input->getOption('quiet')) { |
|
77
|
|
|
$output->write($buffer); |
|
78
|
|
|
} |
|
79
|
1 |
|
}); |
|
80
|
1 |
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
This check looks
TODOcomments that have been left in the code.``TODO``s show that something is left unfinished and should be attended to.