Skip to content

Commit 8be4a75

Browse files
committed
feature #32104 Add autowiring for HTTPlug (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- Add autowiring for HTTPlug | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- f76e77d58f Add autowiring for HTTPlug
2 parents 86b68fb + 201e89b commit 8be4a75

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

DependencyInjection/FrameworkExtension.php

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

1414
use Doctrine\Common\Annotations\AnnotationRegistry;
1515
use Doctrine\Common\Annotations\Reader;
16+
use Http\Client\HttpClient;
1617
use Psr\Cache\CacheItemPoolInterface;
1718
use Psr\Container\ContainerInterface as PsrContainerInterface;
1819
use Psr\Http\Client\ClientInterface;
@@ -60,7 +61,6 @@
6061
use Symfony\Component\Form\FormTypeExtensionInterface;
6162
use Symfony\Component\Form\FormTypeGuesserInterface;
6263
use Symfony\Component\Form\FormTypeInterface;
63-
use Symfony\Component\HttpClient\Psr18Client;
6464
use Symfony\Component\HttpClient\ScopingHttpClient;
6565
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
6666
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
@@ -1881,6 +1881,10 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
18811881
$container->removeAlias(ClientInterface::class);
18821882
}
18831883

1884+
if (!interface_exists(HttpClient::class)) {
1885+
$container->removeDefinition(HttpClient::class);
1886+
}
1887+
18841888
foreach ($config['scoped_clients'] as $name => $scopeConfig) {
18851889
if ('http_client' === $name) {
18861890
throw new InvalidArgumentException(sprintf('Invalid scope name: "%s" is reserved.', $name));
@@ -1901,9 +1905,8 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
19011905
$container->registerAliasForArgument($name, HttpClientInterface::class);
19021906

19031907
if ($hasPsr18) {
1904-
$container->register('psr18.'.$name, Psr18Client::class)
1905-
->setAutowired(true)
1906-
->setArguments([new Reference($name)]);
1908+
$container->setDefinition('psr18.'.$name, new ChildDefinition('psr18.http_client'))
1909+
->replaceArgument(0, new Reference($name));
19071910

19081911
$container->registerAliasForArgument('psr18.'.$name, ClientInterface::class, $name);
19091912
}

Resources/config/http_client.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,11 @@
2222
<argument type="service" id="Psr\Http\Message\StreamFactoryInterface" on-invalid="ignore" />
2323
</service>
2424
<service id="Psr\Http\Client\ClientInterface" alias="psr18.http_client" />
25+
26+
<service id="Http\Client\HttpClient" class="Symfony\Component\HttpClient\HttplugClient">
27+
<argument type="service" id="http_client" />
28+
<argument type="service" id="Http\Message\ResponseFactory" on-invalid="ignore" />
29+
<argument type="service" id="Http\Message\StreamFactory" on-invalid="ignore" />
30+
</service>
2531
</services>
2632
</container>

0 commit comments

Comments
 (0)