1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Antidot\React; |
6
|
|
|
|
7
|
|
|
use Drift\Server\Console\WatchServerCommand; |
8
|
|
|
use Psr\Container\ContainerInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
|
11
|
|
|
class WatchServerCommandFactory |
12
|
|
|
{ |
13
|
|
|
public function __invoke(ContainerInterface $container): WatchServerCommand |
14
|
|
|
{ |
15
|
|
|
/** @var array<string, array> $globalConfig */ |
16
|
|
|
$globalConfig = $container->get('config'); |
17
|
|
|
/** @var array<string, string|int> $config */ |
18
|
|
|
$config = $globalConfig['server']; |
19
|
|
|
|
20
|
|
|
$command = new WatchServerCommand(dirname('./'), [ |
21
|
|
|
'bin/console', |
22
|
|
|
'server:run', |
23
|
|
|
sprintf('--adapter=%s', DriftKernelAdapter::class), |
24
|
|
|
'--debug', |
25
|
|
|
], 'server:watch'); |
26
|
|
|
$definition = $command->getDefinition(); |
27
|
|
|
$command->setDescription('Watch Drift HTTP Server for development purposes'); |
28
|
|
|
|
29
|
|
|
$path = new InputArgument('path', InputArgument::OPTIONAL, $definition->getArgument('path')->getDescription()); |
30
|
|
|
$path->setDefault(sprintf('%s:%s', $config['host'], $config['port'])); |
31
|
|
|
$definition->setArguments([$path]); |
32
|
|
|
|
33
|
|
|
$staticFolder = $definition->getOption('static-folder'); |
34
|
|
|
$staticFolder->setDefault($config['static_folder']); |
35
|
|
|
$concurrentRequests = $definition->getOption('concurrent-requests'); |
36
|
|
|
$concurrentRequests->setDefault($config['max_concurrency']); |
37
|
|
|
$bufferSize = $definition->getOption('request-body-buffer'); |
38
|
|
|
$bufferSize->setDefault($config['buffer_size']); |
39
|
|
|
|
40
|
|
|
return $command; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|