8000 better import · symfony/symfony@953f3c6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 953f3c6

Browse files
committed
better import
1 parent 668e09b commit 953f3c6

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/Symfony/Component/HttpClient/Httplug/CorePromise.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Psr\Http\Message\RequestInterface;
1919
use Psr\Http\Message\ResponseFactoryInterface;
2020
use Psr\Http\Message\StreamFactoryInterface;
21+
use Psr\Http\Message\ResponseInterface as Psr7ResponseInterface;
2122
use Symfony\Component\HttpClient\Response\ResponseTrait;
2223
use Symfony\Component\HttpClient\Response\StreamWrapper;
2324
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
@@ -114,12 +115,13 @@ public function wait()
114115
{
115116
try {
116117
$headers = $this->response->getHeaders(false);
118+
$body = isset(class_uses($this->response)[ResponseTrait::class]) ? $this->response->toStream(false) : StreamWrapper::createResource($this->response, $this->client);
117119
} catch (TransportExceptionInterface $e) {
118120
$this->reject($e);
119121

120122
return;
121123
}
122-
$this->fulfill($headers);
124+
$this->fulfill($headers, $body);
123125
}
124126

125127
/**
@@ -177,7 +179,7 @@ public function getException()
177179
return $this->exception;
178180
}
179181

180-
private function fulfill(array $headers)
182+
private function fulfill(array $headers, $contentResource)
181183
{
182184
$this->state = Promise::FULFILLED;
183185
try {
@@ -189,8 +191,7 @@ private function fulfill(array $headers)
189191
}
190192
}
191193

192-
$body = isset(class_uses($this->response)[ResponseTrait::class]) ? $this->response->toStream(false) : StreamWrapper::createResource($this->response, $this->client);
193-
$body = $this->streamFactory->createStreamFromResource($body);
194+
$body = $this->streamFactory->createStreamFromResource($contentResource);
194195

195196
if ($body->isSeekable()) {
196197
$body->seek(0);
@@ -209,7 +210,7 @@ private function fulfill(array $headers)
209210
$psrResponse = \call_user_func($callback, $psrResponse);
210211
}
211212

212-
if ($psrResponse instanceof \Psr\Http\Message\ResponseInterface) {
213+
if ($psrResponse instanceof Psr7ResponseInterface) {
213214
$this->psrResponse = $psrResponse;
214215
}
215216
}

src/Symfony/Component/HttpClient/HttplugClient.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Http\Client\Exception\NetworkException;
1515
use Http\Client\Exception\RequestException;
1616
use Http\Client\HttpAsyncClient;
17-
use Http\Client\HttpClient;
17+
use Http\Client\HttpClient as HttplugClientInterface;
1818
use Http\Message\RequestFactory;
1919
use Http\Message\StreamFactory;
2020
use Http\Message\UriFactory;
@@ -39,10 +39,6 @@
3939
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\HttplugClient" as the "php-http/httplug" package is not installed. Try running "composer require php-http/httplug".');
4040
}
4141

42-
if (!interface_exists(ClientInterface::class)) {
43-
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\HttplugClient" as the "psr/http-client" package is not installed. Try running "composer require psr/http-client".');
44-
}
45-
4642
if (!interface_exists(RequestFactory::class)) {
4743
throw new \LogicException('You cannot use "Symfony\Component\HttpClient\HttplugClient" as the "php-http/message-factory" package is not installed. Try running "composer require nyholm/psr7".');
4844
}
@@ -56,15 +52,15 @@
5652
*
5753
* @author Nicolas Grekas <p@tchwork.com>
5854
*/
59-
final class HttplugClient implements HttpClient, HttpAsyncClient, RequestFactory, StreamFactory, UriFactory
55+
final class HttplugClient implements HttplugClientInterface, HttpAsyncClient, RequestFactory, StreamFactory, UriFactory
6056
{
6157
private $client;
6258
private $responseFactory;
6359
private $streamFactory;
6460

6561
public function __construct(HttpClientInterface $client = null, ResponseFactoryInterface $responseFactory = null, StreamFactoryInterface $streamFactory = null)
6662
{
67-
$this->client = $client ?? \Symfony\Component\HttpClient\HttpClient::create();
63+
$this->client = $client ?? HttpClient::create();
6864
$this->responseFactory = $responseFactory;
6965
$this->streamFactory = $streamFactory ?? ($responseFactory instanceof StreamFactoryInterface ? $responseFactory : null);
7066

0 commit comments

Comments
 (0)
0