Skip to content

Commit 79501e9

Browse files
authored
Use ClientInterface instead of HttpClient interface when registering aliases (#394)
* Register client alias for `Psr\Http\Client\ClientInterface` * Deprecate client alias registration on HttpClient interface
1 parent cac3c43 commit 79501e9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/DependencyInjection/HttplugExtension.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Http\Message\Authentication\QueryParam;
2222
use Http\Message\Authentication\Wsse;
2323
use Http\Mock\Client as MockClient;
24+
use Psr\Http\Client\ClientInterface;
2425
use Psr\Http\Message\UriInterface;
2526
use Symfony\Component\Config\FileLocator;
2627
use Symfony\Component\DependencyInjection\Alias;
@@ -382,7 +383,14 @@ private function configureClient(ContainerBuilder $container, $clientName, array
382383
$serviceId = 'httplug.client.'.$clientName;
383384

384385
if (method_exists($container, 'registerAliasForArgument')) {
385-
$container->registerAliasForArgument($serviceId, HttpClient::class, $clientName);
386+
$alias = $container->registerAliasForArgument($serviceId, HttpClient::class, $clientName);
387+
388+
$interfaces = class_implements(HttpClient::class) ?? [];
389+
if (isset($interfaces[ClientInterface::class])) {
390+
$alias->setDeprecated('php-http/httplug-bundle', '1.22', 'The "%alias_id%" alias is deprecated, use "Psr\Http\Client\ClientInterface" instead.');
391+
392+
$container->registerAliasForArgument($serviceId, ClientInterface::class, $clientName);
393+
}
386394
}
387395

388396
$plugins = [];

0 commit comments

Comments
 (0)