Skip to content

Commit 94833d0

Browse files
authored
Revert "Revert "Do not override HttpClient DI"" (#1240)
This reverts commit b3d80e39707f220fade8c297af3fc500ae5d7ee9.
1 parent 8599a09 commit 94833d0

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/DependencyInjection/AsyncAwsExtension.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use AsyncAws\Core\Credentials\ChainProvider;
99
use AsyncAws\Core\Credentials\CredentialProvider;
1010
use AsyncAws\Core\Credentials\SymfonyCacheProvider;
11+
use AsyncAws\Core\HttpClient\AwsHttpClientFactory;
1112
use AsyncAws\Symfony\Bundle\Secrets\CachedEnvVarLoader;
1213
use AsyncAws\Symfony\Bundle\Secrets\SsmVault;
1314
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
@@ -17,6 +18,7 @@
1718
use Symfony\Component\DependencyInjection\Reference;
1819
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1920
use Symfony\Contracts\Cache\CacheInterface;
21+
use Symfony\Contracts\HttpClient\HttpClientInterface;
2022

2123
class AsyncAwsExtension extends Extension
2224
{
@@ -94,7 +96,16 @@ private function addServiceDefinition(ContainerBuilder $container, string $name,
9496
$httpClient = $config['http_client'] ? new Reference($config['http_client']) : null;
9597
} else {
9698
// Use default Symfony http_client unless explicitly set to null.
97-
$httpClient = new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE);
99+
if (class_exists(AwsHttpClientFactory::class)) {
100+
$httpClient = new Definition(HttpClientInterface::class);
101+
$httpClient->setFactory([AwsHttpClientFactory::class, 'createRetryableClient'])
102+
->setArguments([
103+
new Reference('http_clients', ContainerInterface::NULL_ON_INVALID_REFERENCE),
104+
$logger,
105+
]);
106+
} else {
107+
$httpClient = new Reference('http_client', ContainerInterface::NULL_ON_INVALID_REFERENCE);
108+
}
98109
}
99110

100111
// If no credential provider is specified, lets configured a credentials provider with cache.
@@ -126,10 +137,12 @@ private function addServiceDefinition(ContainerBuilder $container, string $name,
126137
}
127138

128139
$definition = new Definition($clientClass);
129-
$definition->addArgument($config['config']);
130-
$definition->addArgument($credentialServiceId ? new Reference($credentialServiceId) : null);
131-
$definition->addArgument($httpClient);
132-
$definition->addArgument($logger);
140+
$definition->setArguments([
141+
$config['config'],
142+
$credentialServiceId ? new Reference($credentialServiceId) : null,
143+
$httpClient,
144+
$logger,
145+
]);
133146
$definition->addTag('monolog.logger', ['channel' => 'async_aws']);
134147
$container->setDefinition(sprintf('async_aws.client.%s', $name), $definition);
135148
}

0 commit comments

Comments
 (0)