Skip to content

autowire PSR-18 ClientInterface, deprecate httplug Client autowire service #427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

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

# unreleased

- Deprecated `Http\Client\HttpClient` in favor of `Psr\Http\Client\ClientInterface` (#425).
- Added alias to autowire `Psr\Http\Client\ClientInterface` service (#425).

# 1.27.1 - 2023-03-03

- Added `: void` to `Collector::reset` to avoid PHP warning.
Expand Down
7 changes: 7 additions & 0 deletions src/DependencyInjection/HttplugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpKernel\Kernel;
use Twig\Environment as TwigEnvironment;

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

$loader->load('services.xml');
// TODO: Move this back into services.xml when we drop support for Symfony 4, or completely remove the service in the next major version.
if (Kernel::MAJOR_VERSION >= 5) {
$loader->load('services_legacy.xml');
} else {
$loader->load('services_legacy_sf4.xml');
}
$loader->load('plugins.xml');
if (\class_exists(MockClient::class)) {
$loader->load('mock-client.xml');
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<service id="httplug.client.default" class="Http\Client\HttpClient">
<factory class="Http\Discovery\HttpClientDiscovery" method="find" />
</service>
<service id="Http\Client\HttpClient" alias="httplug.client" public="false" />
<service id="Psr\Http\Client\ClientInterface" alias="httplug.client" public="false" />

<!-- Discovery for PSR-18 -->
<service id="httplug.psr18_client.default" class="Psr\Http\Client\ClientInterface">
Expand Down
11 changes: 11 additions & 0 deletions src/Resources/config/services_legacy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Http\Client\HttpClient" alias="httplug.client" public="false">
<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>
</service>
</services>
</container>
11 changes: 11 additions & 0 deletions src/Resources/config/services_legacy_sf4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="Http\Client\HttpClient" alias="httplug.client" public="false">
<deprecated>The "%alias_id%" service is deprecated in favor of using PSR-7 Psr\Http\Client\ClientInterface</deprecated>
</service>
</services>
</container>