Skip to content

Commit d12ecaf

Browse files
authored
Merge pull request #427 from php-http/425-client-interface
autowire PSR-18 ClientInterface, deprecate httplug Client autowire service
2 parents 1b23561 + d4e9b9c commit d12ecaf

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
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+
- Deprecated `Http\Client\HttpClient` in favor of `Psr\Http\Client\ClientInterface` (#425).
8+
- Added alias to autowire `Psr\Http\Client\ClientInterface` service (#425).
9+
510
# 1.27.1 - 2023-03-03
611

712
- Added `: void` to `Collector::reset` to avoid PHP warning.

src/DependencyInjection/HttplugExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
3333
use Symfony\Component\DependencyInjection\Reference;
3434
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
35+
use Symfony\Component\HttpKernel\Kernel;
3536
use Twig\Environment as TwigEnvironment;
3637

3738
/**
@@ -60,6 +61,12 @@ public function load(array $configs, ContainerBuilder $container)
6061
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
6162

6263
$loader->load('services.xml');
64+
// TODO: Move this back into services.xml when we drop support for Symfony 4, or completely remove the service in the next major version.
65+
if (Kernel::MAJOR_VERSION >= 5) {
66+
$loader->load('services_legacy.xml');
67+
} else {
68+
$loader->load('services_legacy_sf4.xml');
69+
}
6370
$loader->load('plugins.xml');
6471
if (\class_exists(MockClient::class)) {
6572
$loader->load('mock-client.xml');

src/Resources/config/services.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<service id="httplug.client.default" class="Http\Client\HttpClient">
4848
<factory class="Http\Discovery\HttpClientDiscovery" method="find" />
4949
</service>
50-
<service id="Http\Client\HttpClient" alias="httplug.client" public="false" />
50+
<service id="Psr\Http\Client\ClientInterface" alias="httplug.client" public="false" />
5151

5252
<!-- Discovery for PSR-18 -->
5353
<service id="httplug.psr18_client.default" class="Psr\Http\Client\ClientInterface">
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service id="Http\Client\HttpClient" alias="httplug.client" public="false">
8+
<deprecated package="php-http/httplug-bundle" version="1.28">The "%alias_id%" service is deprecated in favor of using PSR-7 Psr\Http\Client\ClientInterface</deprecated>
9+
</service>
10+
</services>
11+
</container>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
6+
<services>
7+
<service id="Http\Client\HttpClient" alias="httplug.client" public="false">
8+
<deprecated>The "%alias_id%" service is deprecated in favor of using PSR-7 Psr\Http\Client\ClientInterface</deprecated>
9+
</service>
10+
</services>
11+
</container>

0 commit comments

Comments
 (0)