Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2bdfb41

Browse files
Add autowiring for HTTPlug
1 parent d31b716 commit 2bdfb41

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 8 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,11 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
18811881
$container->removeAlias(ClientInterface::class);
18821882
}
18831883

1884+
if (!interface_exists(HttpClient::class)) {
1885+
$container->removeDefinition('plug.http_client');
1886+
$container->removeAlias(HttpClient::class);
1887+
}
1888+
18841889
foreach ($config['scoped_clients'] as $name => $scopeConfig) {
18851890
if ('http_client' === $name) {
18861891
throw new InvalidArgumentException(sprintf('Invalid scope name: "%s" is reserved.', $name));
@@ -1901,9 +1906,8 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
19011906
$container->registerAliasForArgument($name, HttpClientInterface::class);
19021907

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

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

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,12 @@
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="plug.http_client" 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>
31+
<service id="Http\Client\HttpClient" alias="plug.http_client" />
2532
</services>
2633
</container>

0 commit comments

Comments
 (0)