|
24 | 24 | namespace Facebook; |
25 | 25 |
|
26 | 26 | use Facebook\Exception\SDKException; |
27 | | -use Http\Client\HttpClient; |
28 | | -use Http\Discovery\HttpClientDiscovery; |
29 | 27 | use Http\Discovery\Psr17FactoryDiscovery; |
| 28 | +use Http\Discovery\Psr18ClientDiscovery; |
| 29 | +use Psr\Http\Client\ClientInterface; |
30 | 30 |
|
31 | 31 | class Client |
32 | 32 | { |
@@ -83,31 +83,31 @@ class Client |
83 | 83 | /** |
84 | 84 | * Instantiates a new Client object. |
85 | 85 | * |
86 | | - * @param null|HttpClient $httpClient |
| 86 | + * @param null|ClientInterface $httpClient |
87 | 87 | * @param bool $enableBeta |
88 | 88 | */ |
89 | | - public function __construct(HttpClient $httpClient = null, $enableBeta = false) |
| 89 | + public function __construct(ClientInterface $httpClient = null, $enableBeta = false) |
90 | 90 | { |
91 | | - $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); |
| 91 | + $this->httpClient = $httpClient ?: Psr18ClientDiscovery::find(); |
92 | 92 | $this->enableBetaMode = $enableBeta; |
93 | 93 | } |
94 | 94 |
|
95 | 95 | /** |
96 | 96 | * Sets the HTTP client handler. |
97 | 97 | * |
98 | | - * @param HttpClient $httpClient |
| 98 | + * @param ClientInterface $httpClient |
99 | 99 | */ |
100 | | - public function setHttpClient(HttpClient $httpClient) |
| 100 | + public function setClientInterface(ClientInterface $httpClient) |
101 | 101 | { |
102 | 102 | $this->httpClient = $httpClient; |
103 | 103 | } |
104 | 104 |
|
105 | 105 | /** |
106 | 106 | * Returns the HTTP client handler. |
107 | 107 | * |
108 | | - * @return HttpClient |
| 108 | + * @return ClientInterface |
109 | 109 | */ |
110 | | - public function getHttpClient() |
| 110 | + public function getClientInterface() |
111 | 111 | { |
112 | 112 | return $this->httpClient; |
113 | 113 | } |
@@ -186,11 +186,17 @@ public function sendRequest(Request $request) |
186 | 186 | $request->validateAccessToken(); |
187 | 187 | } |
188 | 188 |
|
189 | | - list($url, $method, $headers, $body) = $this->prepareRequestMessage($request); |
| 189 | + [$url, $method, $headers, $body] = $this->prepareRequestMessage($request); |
190 | 190 |
|
191 | | - $psr7Response = $this->httpClient->sendRequest( |
192 | | - Psr17FactoryDiscovery::findRequestFactory()->createRequest($method, $url, $headers, $body) |
193 | | - ); |
| 191 | + $psrRequest = Psr17FactoryDiscovery::findRequestFactory()->createRequest($method, $url, $headers, $body) |
| 192 | + ->withBody(Psr17FactoryDiscovery::findStreamFactory()->createStream($body)); |
| 193 | + |
| 194 | + foreach ($headers as $headerKey => $headerValue) { |
| 195 | + $psrRequest->withHeader($headerKey, $headerValue); |
| 196 | + } |
| 197 | + |
| 198 | + |
| 199 | + $psr7Response = $this->httpClient->sendRequest($psrRequest); |
194 | 200 |
|
195 | 201 | static::$requestCount++; |
196 | 202 |
|
|
0 commit comments