Skip to content

Commit c7a8687

Browse files
committed
Enable scoped http clients to be used with HttplugClient
1 parent cb39a7f commit c7a8687

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Composer\InstalledVersions;
1515
use Doctrine\Common\Annotations\Reader;
16+
use Http\Client\HttpAsyncClient;
1617
use Http\Client\HttpClient;
1718
use phpDocumentor\Reflection\DocBlockFactoryInterface;
1819
use phpDocumentor\Reflection\Types\ContextFactory;
@@ -2354,8 +2355,9 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
23542355
$container->removeAlias(ClientInterface::class);
23552356
}
23562357

2357-
if (!ContainerBuilder::willBeAvailable('php-http/httplug', HttpClient::class, ['symfony/framework-bundle', 'symfony/http-client'])) {
2358-
$container->removeDefinition(HttpClient::class);
2358+
if (!$hasHttplug = ContainerBuilder::willBeAvailable('php-http/httplug', HttpAsyncClient::class, ['symfony/framework-bundle', 'symfony/http-client'])) {
2359+
$container->removeDefinition(HttpAsyncClient::class);
2360+
$container->removeAlias(HttpClient::class);
23592361
}
23602362

23612363
if ($this->readConfigEnabled('http_client.retry_failed', $container, $retryOptions)) {
@@ -2425,6 +2427,13 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
24252427

24262428
$container->registerAliasForArgument('psr18.'.$name, ClientInterface::class, $name);
24272429
}
2430+
2431+
if ($hasHttplug) {
2432+
$container->setDefinition('httplug.'.$name, new ChildDefinition(HttpAsyncClient::class))
2433+
->replaceArgument(0, new Reference($name));
2434+
2435+
$container->registerAliasForArgument('httplug.'.$name, ClientInterface::class, $name);
2436+
}
24282437
}
24292438

24302439
if ($responseFactoryId = $config['mock_response_factory'] ?? null) {

src/Symfony/Bundle/FrameworkBundle/Resources/config/http_client.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
1313

14+
use Http\Client\HttpAsyncClient;
1415
use Psr\Http\Client\ClientInterface;
1516
use Psr\Http\Message\ResponseFactoryInterface;
1617
use Psr\Http\Message\StreamFactoryInterface;
@@ -49,13 +50,15 @@
4950

5051
->alias(ClientInterface::class, 'psr18.http_client')
5152

52-
->set(\Http\Client\HttpClient::class, HttplugClient::class)
53+
->set(HttpAsyncClient::class, HttplugClient::class)
5354
->args([
5455
service('http_client'),
5556
service(ResponseFactoryInterface::class)->ignoreOnInvalid(),
5657
service(StreamFactoryInterface::class)->ignoreOnInvalid(),
5758
])
5859

60+
->alias(\Http\Client\HttpClient::class, HttpAsyncClient::class)
61+
5962
->set('http_client.abstract_retry_strategy', GenericRetryStrategy::class)
6063
->abstract()
6164
->args([

0 commit comments

Comments
 (0)