Skip to content

Commit 4042d53

Browse files
committed
minor #37321 [HttpClient] Move configuration to PHP (IonBazan)
This PR was squashed before being merged into the 5.2-dev branch. Discussion ---------- [HttpClient] Move configuration to PHP | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Part of #37186 | License | MIT | Doc PR | - Commits ------- 955ab04d96 [HttpClient] Move configuration to PHP
2 parents 69d3552 + 4d0d708 commit 4042d53

File tree

5 files changed

+81
-49
lines changed

5 files changed

+81
-49
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public function load(array $configs, ContainerBuilder $container)
352352
}
353353

354354
if ($this->httpClientConfigEnabled = $this->isConfigEnabled($container, $config['http_client'])) {
355-
$this->registerHttpClientConfiguration($config['http_client'], $container, $loader, $config['profiler']);
355+
$this->registerHttpClientConfiguration($config['http_client'], $container, $phpLoader, $config['profiler']);
356356
}
357357

358358
if ($this->mailerConfigEnabled = $this->isConfigEnabled($container, $config['mailer'])) {
@@ -604,7 +604,7 @@ private function registerProfilerConfiguration(array $config, ContainerBuilder $
604604
}
605605

606606
if ($this->httpClientConfigEnabled) {
607-
$loader->load('http_client_debug.xml');
607+
$phpLoader->load('http_client_debug.php');
608608
}
609609

610610
$container->setParameter('profiler_listener.only_exceptions', $config['only_exceptions']);
@@ -1904,9 +1904,9 @@ private function registerCacheConfiguration(array $config, ContainerBuilder $con
19041904
}
19051905
}
19061906

1907-
private function registerHttpClientConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader, array $profilerConfig)
1907+
private function registerHttpClientConfiguration(array $config, ContainerBuilder $container, PhpFileLoader $loader, array $profilerConfig)
19081908
{
1909-
$loader->load('http_client.xml');
1909+
$loader->load('http_client.php');
19101910

19111911
$container->getDefinition('http_client')->setArguments([$config['default_options'] ?? [], $config['max_host_connections'] ?? 6]);
19121912

Resources/config/http_client.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Psr\Http\Client\ClientInterface;
15+
use Psr\Http\Message\ResponseFactoryInterface;
16+
use Psr\Http\Message\StreamFactoryInterface;
17+
use Symfony\Component\HttpClient\HttpClient;
18+
use Symfony\Component\HttpClient\HttplugClient;
19+
use Symfony\Component\HttpClient\Psr18Client;
20+
use Symfony\Contracts\HttpClient\HttpClientInterface;
21+
22+
return static function (ContainerConfigurator $container) {
23+
$container->services()
24+
->set('http_client', HttpClientInterface::class)
25+
->factory([HttpClient::class, 'create'])
26+
->args([
27+
[], // default options
28+
abstract_arg('max host connections'),
29+
])
30+
->call('setLogger', [service('logger')->ignoreOnInvalid()])
31+
->tag('monolog.logger', ['channel' => 'http_client'])
32+
->tag('http_client.client')
33+
34+
->alias(HttpClientInterface::class, 'http_client')
35+
36+
->set('psr18.http_client', Psr18Client::class)
37+
->args([
38+
service('http_client'),
39+
service(ResponseFactoryInterface::class)->ignoreOnInvalid(),
40+
service(StreamFactoryInterface::class)->ignoreOnInvalid(),
41+
])
42+
43+
->alias(ClientInterface::class, 'psr18.http_client')
44+
45+
->set(\Http\Client\HttpClient::class, HttplugClient::class)
46+
->args([
47+
service('http_client'),
48+
service(ResponseFactoryInterface::class)->ignoreOnInvalid(),
49+
service(StreamFactoryInterface::class)->ignoreOnInvalid(),
50+
])
51+
;
52+
};

Resources/config/http_client.xml

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
13+
14+
use Symfony\Component\HttpClient\DataCollector\HttpClientDataCollector;
15+
16+
return static function (ContainerConfigurator $container) {
17+
$container->services()
18+
->set('data_collector.http_client', HttpClientDataCollector::class)
19+
->tag('data_collector', [
20+
'template' => '@WebProfiler/Collector/http_client.html.twig',
21+
'id' => 'http_client',
22+
'priority' => 250,
23+
])
24+
;
25+
};

Resources/config/http_client_debug.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)