From 20d6a907cf22c23383bf99cb7ead42600bc8f1ad Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Mon, 5 Jul 2021 14:02:34 +0200 Subject: [PATCH] Register client alias to support Symfony 5.3 Target attribute 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 --- CHANGELOG.md | 5 +++++ src/DependencyInjection/HttplugExtension.php | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 633df58e..f9e58c57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release. +# UNRELEASED + +- Added support for [Target attribute](https://symfony.com/blog/new-in-symfony-5-3-service-autowiring-with-attributes) + available in Symfony 5.3 + # 1.20.1 - 2021-02-12 - Added `kernel.reset` tag to the Collector. diff --git a/src/DependencyInjection/HttplugExtension.php b/src/DependencyInjection/HttplugExtension.php index 5fd60376..ffc30356 100644 --- a/src/DependencyInjection/HttplugExtension.php +++ b/src/DependencyInjection/HttplugExtension.php @@ -381,6 +381,10 @@ private function configureClient(ContainerBuilder $container, $clientName, array { $serviceId = 'httplug.client.'.$clientName; + if (method_exists($container, 'registerAliasForArgument')) { + $container->registerAliasForArgument($serviceId, HttpClient::class, $clientName); + } + $plugins = []; foreach ($arguments['plugins'] as $plugin) { $pluginName = key($plugin);