|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Antidot\React; |
| 6 | + |
| 7 | +use Drift\Server\Console\RunServerCommand; |
| 8 | +use Psr\Container\ContainerInterface; |
| 9 | +use Symfony\Component\Console\Input\InputArgument; |
| 10 | + |
| 11 | +class RunServerCommandFactory |
| 12 | +{ |
| 13 | + public function __invoke(ContainerInterface $container): RunServerCommand |
| 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 RunServerCommand(dirname('./'), 'server:run'); |
| 21 | + $command->setDescription('Run Drift HTTP Server'); |
| 22 | + $definition = $command->getDefinition(); |
| 23 | + |
| 24 | + $path = new InputArgument('path', InputArgument::OPTIONAL, $definition->getArgument('path')->getDescription()); |
| 25 | + $path->setDefault(sprintf('%s:%s', $config['host'], $config['port'])); |
| 26 | + $definition->setArguments([$path]); |
| 27 | + |
| 28 | + $adapter = $definition->getOption('adapter'); |
| 29 | + $adapter->setDefault(DriftKernelAdapter::class); |
| 30 | + $staticFolder = $definition->getOption('static-folder'); |
| 31 | + $staticFolder->setDefault($config['static_folder']); |
| 32 | + $workers = $definition->getOption('workers'); |
| 33 | + $workers->setDefault($config['workers']); |
| 34 | + $concurrentRequests = $definition->getOption('concurrent-requests'); |
| 35 | + $concurrentRequests->setDefault($config['max_concurrency']); |
| 36 | + $bufferSize = $definition->getOption('request-body-buffer'); |
| 37 | + $bufferSize->setDefault($config['buffer_size']); |
| 38 | + |
| 39 | + return $command; |
| 40 | + } |
| 41 | +} |
0 commit comments