|
57 | 57 | */
|
58 | 58 | final class HttplugClient implements HttplugInterface, HttpAsyncClient, RequestFactory, StreamFactory, UriFactory
|
59 | 59 | {
|
60 |
| - private $client; |
61 |
| - private $responseFactory; |
62 |
| - private $streamFactory; |
63 |
| - private $promisePool; |
64 |
| - private $waitLoop; |
| 60 | + private HttpClientInterface $client; |
| 61 | + private ResponseFactoryInterface $responseFactory; |
| 62 | + private StreamFactoryInterface $streamFactory; |
| 63 | + private ?\SplObjectStorage $promisePool; |
| 64 | + private HttplugWaitLoop $waitLoop; |
65 | 65 |
|
66 | 66 | public function __construct(HttpClientInterface $client = null, ResponseFactoryInterface $responseFactory = null, StreamFactoryInterface $streamFactory = null)
|
67 | 67 | {
|
68 | 68 | $this->client = $client ?? HttpClient::create();
|
69 |
| - $this->responseFactory = $responseFactory; |
70 |
| - $this->streamFactory = $streamFactory ?? ($responseFactory instanceof StreamFactoryInterface ? $responseFactory : null); |
| 69 | + $streamFactory ??= $responseFactory instanceof StreamFactoryInterface ? $responseFactory : null; |
71 | 70 | $this->promisePool = \function_exists('GuzzleHttp\Promise\queue') ? new \SplObjectStorage() : null;
|
72 | 71 |
|
73 |
| - if (null === $this->responseFactory || null === $this->streamFactory) { |
| 72 | + if (null === $responseFactory || null === $streamFactory) { |
74 | 73 | if (!class_exists(Psr17Factory::class) && !class_exists(Psr17FactoryDiscovery::class)) {
|
75 | 74 | 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".');
|
76 | 75 | }
|
77 | 76 |
|
78 | 77 | try {
|
79 | 78 | $psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
|
80 |
| - $this->responseFactory = $this->responseFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory(); |
81 |
| - $this->streamFactory = $this->streamFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory(); |
| 79 | + $responseFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory(); |
| 80 | + $streamFactory ??= $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory(); |
82 | 81 | } catch (NotFoundException $e) {
|
83 | 82 | throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been found. Try running "composer require nyholm/psr7".', 0, $e);
|
84 | 83 | }
|
85 | 84 | }
|
86 | 85 |
|
| 86 | + $this->responseFactory = $responseFactory; |
| 87 | + $this->streamFactory = $streamFactory; |
87 | 88 | $this->waitLoop = new HttplugWaitLoop($this->client, $this->promisePool, $this->responseFactory, $this->streamFactory);
|
88 | 89 | }
|
89 | 90 |
|
|
0 commit comments