Skip to content

Commit 7192c33

Browse files
committed
[HttpClient] Handle Amp HTTP client v5 incompatibility gracefully
1 parent d84aec5 commit 7192c33

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Symfony/Component/HttpClient/AmpHttpClient.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Amp\Http\Client\PooledHttpClient;
1818
use Amp\Http\Client\Request;
1919
use Amp\Http\Tunnel\Http1TunnelConnector;
20+
use Amp\Promise;
2021
use Psr\Log\LoggerAwareInterface;
2122
use Psr\Log\LoggerAwareTrait;
2223
use Symfony\Component\HttpClient\Exception\TransportException;
@@ -29,7 +30,11 @@
2930
use Symfony\Contracts\Service\ResetInterface;
3031

3132
if (!interface_exists(DelegateHttpClient::class)) {
32-
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\AmpHttpClient" as the "amphp/http-client" package is not installed. Try running "composer require amphp/http-client".');
33+
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\AmpHttpClient" as the "amphp/http-client" package is not installed. Try running "composer require amphp/http-client:^4.2.1".');
34+
}
35+
36+
if (!interface_exists(Promise::class)) {
37+
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\AmpHttpClient" as the installed "amphp/http-client" is not compatible with this version of "symfony/http-client". Try downgrading "amphp/http-client" to "^4.2.1".');
3338
}
3439

3540
/**

src/Symfony/Component/HttpClient/HttpClient.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpClient;
1313

1414
use Amp\Http\Client\Connection\ConnectionLimitingPool;
15+
use Amp\Promise;
1516
use Symfony\Contracts\HttpClient\HttpClientInterface;
1617

1718
/**
@@ -30,7 +31,7 @@ final class HttpClient
3031
*/
3132
public static function create(array $defaultOptions = [], int $maxHostConnections = 6, int $maxPendingPushes = 50): HttpClientInterface
3233
{
33-
if ($amp = class_exists(ConnectionLimitingPool::class)) {
34+
if ($amp = class_exists(ConnectionLimitingPool::class) && interface_exists(Promise::class)) {
3435
if (!\extension_loaded('curl')) {
3536
return new AmpHttpClient($defaultOptions, null, $maxHostConnections, $maxPendingPushes);
3637
}
@@ -61,7 +62,7 @@ public static function create(array $defaultOptions = [], int $maxHostConnection
6162
return new AmpHttpClient($defaultOptions, null, $maxHostConnections, $maxPendingPushes);
6263
}
6364

64-
@trigger_error((\extension_loaded('curl') ? 'Upgrade' : 'Install').' the curl extension or run "composer require amphp/http-client" to perform async HTTP operations, including full HTTP/2 support', \E_USER_NOTICE);
65+
@trigger_error((\extension_loaded('curl') ? 'Upgrade' : 'Install').' the curl extension or run "composer require amphp/http-client:^4.2.1" to perform async HTTP operations, including full HTTP/2 support', \E_USER_NOTICE);
6566

6667
return new NativeHttpClient($defaultOptions, $maxHostConnections);
6768
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy