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

Skip to content

Commit 67d8daa

Browse files
feature #49691 [FrameworkBundle] Add scoped httplug clients and deprecate httplugs use like psr18 client (simonberger)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [FrameworkBundle] Add scoped httplug clients and deprecate httplugs use like psr18 client | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | yes | Tickets | Fix #49644 | License | MIT | Doc PR | symfony/symfony-docs#18064 This MR does 2 closely related things to try to fully integrate the HttplugClient with the unique features it brings and on the other hand deprecate its use like a psr18 client which it is in a pending deprecation state since a long time. - Added a new services `httplug.http_client` and alias `Http\Client\HttpAsyncClient` to inject the the `HttplugClient`. - Make the available service `Http\Client\HttpClient` a deprecated alias of it - Create httplug.<scoped_client_id> services for all scoped clients like it is done with the psr18 ClientInterface Commits ------- 20ab567 [FrameworkBundle] Add scoped httplug clients and deprecate httplugs use like psr18 client
2 parents 9aa6e08 + 20ab567 commit 67d8daa

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

UPGRADE-6.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ FrameworkBundle
5656
---------------
5757

5858
* Deprecate the `notifier.logger_notification_listener` service, use the `notifier.notification_logger_listener` service instead
59+
* Deprecate the `Http\Client\HttpClient` service, use `Psr\Http\Client\ClientInterface` instead
5960

6061
HttpFoundation
6162
--------------

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ CHANGELOG
1818
* Add `framework.http_cache.skip_response_headers` option
1919
* Display warmers duration on debug verbosity for `cache:clear` command
2020
* Add `AbstractController::sendEarlyHints()` to send HTTP Early Hints
21+
* Add autowiring aliases for `Http\Client\HttpAsyncClient`
22+
* Deprecate the `Http\Client\HttpClient` service, use `Psr\Http\Client\ClientInterface` instead
2123

2224
6.2
2325
---

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

Lines changed: 12 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;
@@ -2369,8 +2370,10 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
23692370
$container->removeAlias(ClientInterface::class);
23702371
}
23712372

2372-
if (!ContainerBuilder::willBeAvailable('php-http/httplug', HttpClient::class, ['symfony/framework-bundle', 'symfony/http-client'])) {
2373-
$container->removeDefinition(HttpClient::class);
2373+
if (!$hasHttplug = ContainerBuilder::willBeAvailable('php-http/httplug', HttpAsyncClient::class, ['symfony/framework-bundle', 'symfony/http-client'])) {
2374+
$container->removeDefinition('httplug.http_client');
2375+
$container->removeAlias(HttpAsyncClient::class);
2376+
$container->removeAlias(HttpClient::class);
23742377
}
23752378

23762379
if ($this->readConfigEnabled('http_client.retry_failed', $container, $retryOptions)) {
@@ -2440,6 +2443,13 @@ private function registerHttpClientConfiguration(array $config, ContainerBuilder
24402443

24412444
$container->registerAliasForArgument('psr18.'.$name, ClientInterface::class, $name);
24422445
}
2446+
2447+
if ($hasHttplug) {
2448+
$container->setDefinition('httplug.'.$name, new ChildDefinition('httplug.http_client'))
2449+
->replaceArgument(0, new Reference($name));
2450+
2451+
$container->registerAliasForArgument('httplug.'.$name, HttpAsyncClient::class, $name);
2452+
}
24432453
}
24442454

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

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

Lines changed: 6 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,17 @@
4950

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

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

60+
->alias(HttpAsyncClient::class, 'httplug.http_client')
61+
->alias(\Http\Client\HttpClient::class, 'httplug.http_client')
62+
->deprecate('symfony/framework-bundle', '6.3', 'The "%alias_id%" service is deprecated, use "'.ClientInterface::class.'" instead.')
63+
5964
->set('http_client.abstract_retry_strategy', GenericRetryStrategy::class)
6065
->abstract()
6166
->args([

0 commit comments

Comments
 (0)