|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use K911\Swoole\Bridge\Symfony\Bundle\Command\ServerProfileCommand; |
| 6 | +use K911\Swoole\Bridge\Symfony\Bundle\Command\ServerReloadCommand; |
| 7 | +use K911\Swoole\Bridge\Symfony\Bundle\Command\ServerRunCommand; |
| 8 | +use K911\Swoole\Bridge\Symfony\Bundle\Command\ServerStartCommand; |
| 9 | +use K911\Swoole\Bridge\Symfony\Bundle\Command\ServerStatusCommand; |
| 10 | +use K911\Swoole\Bridge\Symfony\Bundle\Command\ServerStopCommand; |
| 11 | +use K911\Swoole\Metrics\MetricsProvider; |
| 12 | +use K911\Swoole\Server\Api\ApiServerClientFactory; |
| 13 | +use K911\Swoole\Server\Config\Sockets; |
| 14 | +use K911\Swoole\Server\Configurator\CallableChainConfigurator; |
| 15 | +use K911\Swoole\Server\Configurator\CallableChainConfiguratorFactory; |
| 16 | +use K911\Swoole\Server\HttpServer; |
| 17 | +use K911\Swoole\Server\HttpServerConfiguration; |
| 18 | +use K911\Swoole\Server\Runtime\BootableInterface; |
| 19 | +use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; |
| 20 | + |
| 21 | +use function Symfony\Component\DependencyInjection\Loader\Configurator\service; |
| 22 | + |
| 23 | +return static function (ContainerConfigurator $containerConfigurator): void { |
| 24 | + $services = $containerConfigurator->services(); |
| 25 | + |
| 26 | + $services->defaults(); |
| 27 | + |
| 28 | + $services->set(ServerStatusCommand::class) |
| 29 | + ->arg('$sockets', service(Sockets::class)) |
| 30 | + ->arg('$apiServerClientFactory', service(ApiServerClientFactory::class)) |
| 31 | + ->arg('$metricsProvider', service(MetricsProvider::class)) |
| 32 | + ->arg('$parameterBag', service('parameter_bag')) |
| 33 | + ->tag('console.command', [ |
| 34 | + 'command' => 'swoole:server:status', |
| 35 | + ]) |
| 36 | + ; |
| 37 | + |
| 38 | + $services->set(ServerStopCommand::class) |
| 39 | + ->arg('$server', service(HttpServer::class)) |
| 40 | + ->arg('$serverConfiguration', service(HttpServerConfiguration::class)) |
| 41 | + ->arg('$parameterBag', service('parameter_bag')) |
| 42 | + ->tag('console.command', [ |
| 43 | + 'command' => 'swoole:server:stop', |
| 44 | + ]) |
| 45 | + ; |
| 46 | + |
| 47 | + $services->set(ServerReloadCommand::class) |
| 48 | + ->arg('$server', service(HttpServer::class)) |
| 49 | + ->arg('$serverConfiguration', service(HttpServerConfiguration::class)) |
| 50 | + ->arg('$parameterBag', service('parameter_bag')) |
| 51 | + ->tag('console.command', [ |
| 52 | + 'command' => 'swoole:server:reload', |
| 53 | + ]) |
| 54 | + ; |
| 55 | + |
| 56 | + $services->set('swoole_bundle.server.http_server.configurator.for_server_start_command', CallableChainConfigurator::class) |
| 57 | + ->factory([ |
| 58 | + service(CallableChainConfiguratorFactory::class), |
| 59 | + 'make', |
| 60 | + ]) |
| 61 | + ->args([ |
| 62 | + service('swoole_bundle.server.http_server.configurator_collection'), |
| 63 | + service('swoole_bundle.server.http_server.configurator.with_request_handler'), |
| 64 | + ]) |
| 65 | + ; |
| 66 | + |
| 67 | + $services->set(ServerStartCommand::class) |
| 68 | + ->arg('$server', service(HttpServer::class)) |
| 69 | + ->arg('$serverConfiguration', service(HttpServerConfiguration::class)) |
| 70 | + ->arg('$serverConfigurator', service('swoole_bundle.server.http_server.configurator.for_server_start_command')) |
| 71 | + ->arg('$parameterBag', service('parameter_bag')) |
| 72 | + ->arg('$bootManager', service(BootableInterface::class)) |
| 73 | + ->tag('console.command', [ |
| 74 | + 'command' => 'swoole:server:start', |
| 75 | + ]) |
| 76 | + ; |
| 77 | + |
| 78 | + $services->set('swoole_bundle.server.http_server.configurator.for_server_run_command', CallableChainConfigurator::class) |
| 79 | + ->factory([ |
| 80 | + service(CallableChainConfiguratorFactory::class), |
| 81 | + 'make', |
| 82 | + ]) |
| 83 | + ->args([ |
| 84 | + service('swoole_bundle.server.http_server.configurator_collection'), |
| 85 | + service('swoole_bundle.server.http_server.configurator.with_request_handler'), |
| 86 | + service('swoole_bundle.server.http_server.configurator.default_handler'), |
| 87 | + ]) |
| 88 | + ; |
| 89 | + |
| 90 | + $services->set(ServerRunCommand::class) |
| 91 | + ->arg('$server', service(HttpServer::class)) |
| 92 | + ->arg('$serverConfiguration', service(HttpServerConfiguration::class)) |
| 93 | + ->arg('$serverConfigurator', service('swoole_bundle.server.http_server.configurator.for_server_run_command')) |
| 94 | + ->arg('$parameterBag', service('parameter_bag')) |
| 95 | + ->arg('$bootManager', service(BootableInterface::class)) |
| 96 | + ->tag('console.command', [ |
| 97 | + 'command' => 'swoole:server:run', |
| 98 | + ]) |
| 99 | + ; |
| 100 | + |
| 101 | + $services->set('swoole_bundle.server.http_server.configurator.for_server_profile_command', CallableChainConfigurator::class) |
| 102 | + ->factory([ |
| 103 | + service(CallableChainConfiguratorFactory::class), |
| 104 | + 'make', |
| 105 | + ]) |
| 106 | + ->args([ |
| 107 | + service('swoole_bundle.server.http_server.configurator_collection'), |
| 108 | + service('swoole_bundle.server.http_server.configurator.with_limited_request_handler'), |
| 109 | + service('swoole_bundle.server.http_server.configurator.default_handler'), |
| 110 | + ]) |
| 111 | + ; |
| 112 | + |
| 113 | + $services->set(ServerProfileCommand::class) |
| 114 | + ->arg('$server', service(HttpServer::class)) |
| 115 | + ->arg('$serverConfiguration', service(HttpServerConfiguration::class)) |
| 116 | + ->arg('$serverConfigurator', service('swoole_bundle.server.http_server.configurator.for_server_profile_command')) |
| 117 | + ->arg('$parameterBag', service('parameter_bag')) |
| 118 | + ->arg('$bootManager', service(BootableInterface::class)) |
| 119 | + ->tag('console.command', [ |
| 120 | + 'command' => 'swoole:server:profile', |
| 121 | + ]) |
| 122 | + ; |
| 123 | +}; |
0 commit comments