Skip to content

Commit 63a217d

Browse files
committed
chore(di): disabled autowiring and autoconfiguration in all services, according to best practices
1 parent 4c0b625 commit 63a217d

File tree

6 files changed

+204
-85
lines changed

6 files changed

+204
-85
lines changed

src/Bridge/Symfony/Bundle/Command/ServerStartCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ protected function startServer(HttpServerConfiguration $serverConfiguration, Htt
5858
private function closeSymfonyStyle(SymfonyStyle $io): void
5959
{
6060
$output = get_object_property($io, 'output', OutputStyle::class);
61+
6162
if ($output instanceof ConsoleOutput) {
6263
$this->closeConsoleOutput($output);
6364
} elseif ($output instanceof StreamOutput) {

src/Bridge/Symfony/Bundle/DependencyInjection/SwooleExtension.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use K911\Swoole\Bridge\Symfony\HttpFoundation\AccessLogOnKernelTerminate;
1515
use K911\Swoole\Bridge\Symfony\HttpFoundation\CloudFrontRequestFactory;
1616
use K911\Swoole\Bridge\Symfony\HttpFoundation\RequestFactoryInterface;
17+
use K911\Swoole\Bridge\Symfony\HttpFoundation\ResponseProcessorInterface;
1718
use K911\Swoole\Bridge\Symfony\HttpFoundation\TrustAllProxiesRequestHandler;
1819
use K911\Swoole\Bridge\Symfony\HttpKernel\ContextReleasingHttpKernelRequestHandler;
1920
use K911\Swoole\Bridge\Symfony\HttpKernel\CoroutineKernelPool;
@@ -317,9 +318,11 @@ private function configureHttpServerHMR(array $hmr, ContainerBuilder $container)
317318
;
318319
}
319320

320-
$container->autowire(HMRWorkerStartHandler::class)
321+
$container->register(HMRWorkerStartHandler::class)
321322
->setPublic(false)
322-
->setAutoconfigured(true)
323+
->setAutoconfigured(false)
324+
->setArgument('$hmr', new Reference(HotModuleReloaderInterface::class))
325+
->setArgument('$swoole', new Reference(Swoole::class))
323326
->setArgument('$decorated', new Reference(HMRWorkerStartHandler::class.'.inner'))
324327
->setDecoratedService(WorkerStartHandlerInterface::class)
325328
;
@@ -344,8 +347,8 @@ private function configureHttpServerServices(array $config, ContainerBuilder $co
344347
if ($config['cloudfront_proto_header_handler']) {
345348
$container->register(CloudFrontRequestFactory::class)
346349
->addArgument(new Reference(CloudFrontRequestFactory::class.'.inner'))
347-
->setAutowired(true)
348-
->setAutoconfigured(true)
350+
->setAutowired(false)
351+
->setAutoconfigured(false)
349352
->setPublic(false)
350353
->setDecoratedService(RequestFactoryInterface::class, null, -10)
351354
;
@@ -497,21 +500,28 @@ private function configureSymfonyExceptionHandler(ContainerBuilder $container):
497500
->setPublic(false)
498501
;
499502
$container->register(ExceptionHandlerFactory::class)
503+
->setArgument('$kernel', new Reference('http_kernel')) // @todo check if this is ok with coroutines enabled
500504
->setArgument('$throwableHandler', new Reference('swoole_bundle.error_handler.symfony_kernel_throwable_handler'))
501-
->setAutowired(true)
502-
->setAutoconfigured(true)
505+
->setAutowired(false)
506+
->setAutoconfigured(false)
503507
->setPublic(false)
504508
;
505509
$container->register(ErrorResponder::class)
506510
->setArgument('$errorHandler', new Reference('swoole_bundle.error_handler.symfony_error_handler'))
507-
->setAutowired(true)
508-
->setAutoconfigured(true)
511+
->setAutowired(false)
512+
->setAutoconfigured(false)
509513
->setPublic(false)
514+
->setArgument('$errorHandler', new Reference('swoole_bundle.error_handler.symfony_error_handler'))
515+
->setArgument('$handlerFactory', new Reference(ExceptionHandlerFactory::class))
510516
;
511517
$container->register(SymfonyExceptionHandler::class)
512-
->setAutowired(true)
513-
->setAutoconfigured(true)
518+
->setAutowired(false)
519+
->setAutoconfigured(false)
514520
->setPublic(false)
521+
->setArgument('$kernel', new Reference('http_kernel')) // @todo check if this is ok with coroutines enabled
522+
->setArgument('$requestFactory', new Reference(RequestFactoryInterface::class))
523+
->setArgument('$responseProcessor', new Reference(ResponseProcessorInterface::class))
524+
->setArgument('$errorResponder', new Reference(ErrorResponder::class))
515525
;
516526
}
517527

Lines changed: 76 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,77 @@
11
services:
2-
_defaults:
3-
autowire: true
4-
autoconfigure: true
5-
public: false
6-
7-
'K911\Swoole\Bridge\Symfony\Bundle\Command\ServerStatusCommand':
8-
arguments:
9-
$metricsProvider: '@K911\Swoole\Metrics\MetricsProvider'
10-
tags: [ { name: console.command, command: 'swoole:server:status' } ]
11-
12-
'K911\Swoole\Bridge\Symfony\Bundle\Command\ServerStopCommand':
13-
tags: [ { name: console.command, command: 'swoole:server:stop' } ]
14-
15-
'K911\Swoole\Bridge\Symfony\Bundle\Command\ServerReloadCommand':
16-
tags: [ { name: console.command, command: 'swoole:server:reload' } ]
17-
18-
'swoole_bundle.server.http_server.configurator.for_server_start_command':
19-
class: K911\Swoole\Server\Configurator\CallableChainConfigurator
20-
factory: ['@K911\Swoole\Server\Configurator\CallableChainConfiguratorFactory', 'make']
21-
arguments:
22-
- '@swoole_bundle.server.http_server.configurator_collection'
23-
- '@swoole_bundle.server.http_server.configurator.with_request_handler'
24-
autoconfigure: false
25-
26-
'K911\Swoole\Bridge\Symfony\Bundle\Command\ServerStartCommand':
27-
tags: [ { name: console.command, command: 'swoole:server:start' } ]
28-
arguments:
29-
$serverConfigurator: '@swoole_bundle.server.http_server.configurator.for_server_start_command'
30-
31-
'swoole_bundle.server.http_server.configurator.for_server_run_command':
32-
class: K911\Swoole\Server\Configurator\CallableChainConfigurator
33-
factory: ['@K911\Swoole\Server\Configurator\CallableChainConfiguratorFactory', 'make']
34-
arguments:
35-
- '@swoole_bundle.server.http_server.configurator_collection'
36-
- '@swoole_bundle.server.http_server.configurator.with_request_handler'
37-
- '@swoole_bundle.server.http_server.configurator.with_sigint_handler'
38-
autoconfigure: false
39-
40-
'K911\Swoole\Bridge\Symfony\Bundle\Command\ServerRunCommand':
41-
tags: [ { name: console.command, command: 'swoole:server:run' } ]
42-
arguments:
43-
$serverConfigurator: '@swoole_bundle.server.http_server.configurator.for_server_run_command'
44-
45-
'swoole_bundle.server.http_server.configurator.for_server_profile_command':
46-
class: K911\Swoole\Server\Configurator\CallableChainConfigurator
47-
factory: ['@K911\Swoole\Server\Configurator\CallableChainConfiguratorFactory', 'make']
48-
arguments:
49-
- '@swoole_bundle.server.http_server.configurator_collection'
50-
- '@swoole_bundle.server.http_server.configurator.with_limited_request_handler'
51-
- '@swoole_bundle.server.http_server.configurator.with_sigint_handler'
52-
autoconfigure: false
53-
54-
'K911\Swoole\Bridge\Symfony\Bundle\Command\ServerProfileCommand':
55-
tags: [ { name: console.command, command: 'swoole:server:profile' } ]
56-
arguments:
57-
$serverConfigurator: '@swoole_bundle.server.http_server.configurator.for_server_profile_command'
2+
_defaults:
3+
autowire: false
4+
autoconfigure: false
5+
public: false
6+
7+
K911\Swoole\Bridge\Symfony\Bundle\Command\ServerStatusCommand:
8+
arguments:
9+
$sockets: '@K911\Swoole\Server\Config\Sockets'
10+
$apiServerClientFactory: '@K911\Swoole\Server\Api\ApiServerClientFactory'
11+
$metricsProvider: '@K911\Swoole\Metrics\MetricsProvider'
12+
$parameterBag: '@parameter_bag'
13+
tags: [ { name: console.command, command: 'swoole:server:status' } ]
14+
15+
K911\Swoole\Bridge\Symfony\Bundle\Command\ServerStopCommand:
16+
arguments:
17+
$server: '@K911\Swoole\Server\HttpServer'
18+
$serverConfiguration: '@K911\Swoole\Server\HttpServerConfiguration'
19+
$parameterBag: '@parameter_bag'
20+
tags: [ { name: console.command, command: 'swoole:server:stop' } ]
21+
22+
K911\Swoole\Bridge\Symfony\Bundle\Command\ServerReloadCommand:
23+
arguments:
24+
$server: '@K911\Swoole\Server\HttpServer'
25+
$serverConfiguration: '@K911\Swoole\Server\HttpServerConfiguration'
26+
$parameterBag: '@parameter_bag'
27+
tags: [ { name: console.command, command: 'swoole:server:reload' } ]
28+
29+
swoole_bundle.server.http_server.configurator.for_server_start_command:
30+
class: K911\Swoole\Server\Configurator\CallableChainConfigurator
31+
factory: ['@K911\Swoole\Server\Configurator\CallableChainConfiguratorFactory', 'make']
32+
arguments:
33+
- '@swoole_bundle.server.http_server.configurator_collection'
34+
- '@swoole_bundle.server.http_server.configurator.with_request_handler'
35+
36+
K911\Swoole\Bridge\Symfony\Bundle\Command\ServerStartCommand:
37+
arguments:
38+
$server: '@K911\Swoole\Server\HttpServer'
39+
$serverConfiguration: '@K911\Swoole\Server\HttpServerConfiguration'
40+
$serverConfigurator: '@swoole_bundle.server.http_server.configurator.for_server_start_command'
41+
$parameterBag: '@parameter_bag'
42+
$bootManager: '@K911\Swoole\Server\Runtime\BootableInterface'
43+
tags: [ { name: console.command, command: 'swoole:server:start' } ]
44+
45+
swoole_bundle.server.http_server.configurator.for_server_run_command:
46+
class: K911\Swoole\Server\Configurator\CallableChainConfigurator
47+
factory: ['@K911\Swoole\Server\Configurator\CallableChainConfiguratorFactory', 'make']
48+
arguments:
49+
- '@swoole_bundle.server.http_server.configurator_collection'
50+
- '@swoole_bundle.server.http_server.configurator.with_request_handler'
51+
- '@swoole_bundle.server.http_server.configurator.default_handler'
52+
53+
K911\Swoole\Bridge\Symfony\Bundle\Command\ServerRunCommand:
54+
arguments:
55+
$server: '@K911\Swoole\Server\HttpServer'
56+
$serverConfiguration: '@K911\Swoole\Server\HttpServerConfiguration'
57+
$serverConfigurator: '@swoole_bundle.server.http_server.configurator.for_server_run_command'
58+
$parameterBag: '@parameter_bag'
59+
$bootManager: '@K911\Swoole\Server\Runtime\BootableInterface'
60+
tags: [ { name: console.command, command: 'swoole:server:run' } ]
61+
62+
swoole_bundle.server.http_server.configurator.for_server_profile_command:
63+
class: K911\Swoole\Server\Configurator\CallableChainConfigurator
64+
factory: ['@K911\Swoole\Server\Configurator\CallableChainConfiguratorFactory', 'make']
65+
arguments:
66+
- '@swoole_bundle.server.http_server.configurator_collection'
67+
- '@swoole_bundle.server.http_server.configurator.with_limited_request_handler'
68+
- '@swoole_bundle.server.http_server.configurator.default_handler'
69+
70+
K911\Swoole\Bridge\Symfony\Bundle\Command\ServerProfileCommand:
71+
arguments:
72+
$server: '@K911\Swoole\Server\HttpServer'
73+
$serverConfiguration: '@K911\Swoole\Server\HttpServerConfiguration'
74+
$serverConfigurator: '@swoole_bundle.server.http_server.configurator.for_server_profile_command'
75+
$parameterBag: '@parameter_bag'
76+
$bootManager: '@K911\Swoole\Server\Runtime\BootableInterface'
77+
tags: [ { name: console.command, command: 'swoole:server:profile' } ]

0 commit comments

Comments
 (0)