Skip to content

Commit f93fbab

Browse files
authored
Register client alias to support Symfony 5.3 Target attribute (#393)
When you are using Symfony 5.3 and you have multiple clients defined, you can use the `Target` attribute to select the client that you want. Example: ```php final class MyService { public function __construct( #[Target('my_client_alias')] HttpClient $client ) {} } ``` It will now automatically inject `httplug.client.my_client_alias`. For more information: https://symfony.com/blog/new-in-symfony-5-3-service-autowiring-with-attributes
1 parent eb9e1a3 commit f93fbab

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
# UNRELEASED
6+
7+
- Added support for [Target attribute](https://symfony.com/blog/new-in-symfony-5-3-service-autowiring-with-attributes)
8+
available in Symfony 5.3
9+
510
# 1.20.1 - 2021-02-12
611

712
- Added `kernel.reset` tag to the Collector.

src/DependencyInjection/HttplugExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ private function configureClient(ContainerBuilder $container, $clientName, array
381381
{
382382
$serviceId = 'httplug.client.'.$clientName;
383383

384+
if (method_exists($container, 'registerAliasForArgument')) {
385+
$container->registerAliasForArgument($serviceId, HttpClient::class, $clientName);
386+
}
387+
384388
$plugins = [];
385389
foreach ($arguments['plugins'] as $plugin) {
386390
$pluginName = key($plugin);

0 commit comments

Comments
 (0)