|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\HttpClient; |
13 | 13 |
|
| 14 | +use FriendsOfPHP\WellKnownImplementations\WellKnownPsr17Factory; |
| 15 | +use FriendsOfPHP\WellKnownImplementations\WellKnownPsr7Request; |
| 16 | +use FriendsOfPHP\WellKnownImplementations\WellKnownPsr7Uri; |
14 | 17 | use GuzzleHttp\Promise\Promise as GuzzlePromise; |
15 | 18 | use GuzzleHttp\Promise\RejectedPromise; |
16 | 19 | use GuzzleHttp\Promise\Utils; |
@@ -81,12 +84,12 @@ public function __construct(HttpClientInterface $client = null, ResponseFactoryI |
81 | 84 | $this->promisePool = class_exists(Utils::class) ? new \SplObjectStorage() : null; |
82 | 85 |
|
83 | 86 | if (null === $responseFactory || null === $streamFactory) { |
84 | | - if (!class_exists(Psr17Factory::class) && !class_exists(Psr17FactoryDiscovery::class)) { |
| 87 | + if (!class_exists(Psr17Factory::class) && !class_exists(WellKnownPsr17Factory::class) && !class_exists(Psr17FactoryDiscovery::class)) { |
85 | 88 | throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".'); |
86 | 89 | } |
87 | 90 |
|
88 | 91 | try { |
89 | | - $psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null; |
| 92 | + $psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : (class_exists(WellKnownPsr17Factory::class, false) ? new WellKnownPsr17Factory() : null); |
90 | 93 | $responseFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory(); |
91 | 94 | $streamFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory(); |
92 | 95 | } catch (NotFoundException $e) { |
@@ -167,6 +170,8 @@ public function createRequest($method, $uri, array $headers = [], $body = null, |
167 | 170 | $request = $this->responseFactory->createRequest($method, $uri); |
168 | 171 | } elseif (class_exists(Request::class)) { |
169 | 172 | $request = new Request($method, $uri); |
| 173 | + } elseif (class_exists(WellKnownPsr7Request::class)) { |
| 174 | + $request = new WellKnownPsr7Request($method, $uri); |
170 | 175 | } elseif (class_exists(Psr17FactoryDiscovery::class)) { |
171 | 176 | $request = Psr17FactoryDiscovery::findRequestFactory()->createRequest($method, $uri); |
172 | 177 | } else { |
@@ -244,6 +249,10 @@ public function createUri($uri = ''): UriInterface |
244 | 249 | return new Uri($uri); |
245 | 250 | } |
246 | 251 |
|
| 252 | + if (class_exists(WellKnownPsr7Uri::class)) { |
| 253 | + return new WellKnownPsr7Uri($uri); |
| 254 | + } |
| 255 | + |
247 | 256 | if (class_exists(Psr17FactoryDiscovery::class)) { |
248 | 257 | return Psr17FactoryDiscovery::findUrlFactory()->createUri($uri); |
249 | 258 | } |
|
0 commit comments