1 | <?php |
||
32 | final class CurlHttpClient implements ClientInterface, HttpClientInterface |
||
|
|||
33 | { |
||
34 | /** |
||
35 | * @var null|Uri |
||
36 | */ |
||
37 | private $url; |
||
38 | |||
39 | /** |
||
40 | * @var null|HttpClientAuthentication |
||
41 | */ |
||
42 | private $auth; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | private $options = [ |
||
48 | CURLOPT_RETURNTRANSFER => true, |
||
49 | CURLOPT_HEADER => true |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * @var resource |
||
54 | */ |
||
55 | private $handler; |
||
56 | |||
57 | /** |
||
58 | * Creates a CURL HTTP Client |
||
59 | * |
||
60 | * @param Uri|null $url |
||
61 | * @param HttpClientAuthentication|null $auth |
||
62 | * @param array $options |
||
63 | */ |
||
64 | public function __construct(Uri $url = null, HttpClientAuthentication $auth = null, array $options = []) |
||
74 | |||
75 | /** |
||
76 | * Send out an HTTP requests returning a promise |
||
77 | * |
||
78 | * @param RequestInterface $request |
||
79 | * |
||
80 | * @return PromiseInterface |
||
81 | * @deprecated please use CurlHttpClient::sendRequest() instead |
||
82 | */ |
||
83 | public function send(RequestInterface $request) |
||
95 | |||
96 | /** |
||
97 | * @inheritDoc |
||
98 | */ |
||
99 | public function sendRequest(RequestInterface $request): ResponseInterface |
||
121 | |||
122 | /** |
||
123 | * Call the HTTP server returning the response |
||
124 | * |
||
125 | * @param RequestInterface $request |
||
126 | * |
||
127 | * @return Response |
||
128 | * |
||
129 | * @throws RuntimeException If any error occur while preparing and connecting to the server |
||
130 | * @throws ClientErrorException for responses with status codes between 400 and 499 |
||
131 | * @throws ServerErrorException for responses with status codes grater or equal to 500 |
||
132 | */ |
||
133 | private function call(RequestInterface $request) |
||
152 | |||
153 | /** |
||
154 | * Prepares the cURL handler options |
||
155 | * |
||
156 | * @param RequestInterface $request |
||
157 | */ |
||
158 | private function prepare(RequestInterface $request) |
||
173 | |||
174 | /** |
||
175 | * Sets the URL for cURL to use |
||
176 | * |
||
177 | * @param RequestInterface $request |
||
178 | */ |
||
179 | private function setUrl(RequestInterface $request) |
||
195 | |||
196 | /** |
||
197 | * Sets the headers from the request |
||
198 | * |
||
199 | * @param RequestInterface $request |
||
200 | */ |
||
201 | private function setHeaders(RequestInterface $request) |
||
209 | |||
210 | /** |
||
211 | * Resets the cURL handler |
||
212 | * |
||
213 | * @param resource $ch |
||
214 | */ |
||
215 | private function reset(&$ch) |
||
219 | |||
220 | /** |
||
221 | * Creates a response from cURL execution result |
||
222 | * |
||
223 | * @param string $result |
||
224 | * |
||
225 | * @return Response |
||
226 | */ |
||
227 | private function createResponse($result) |
||
233 | |||
234 | /** |
||
235 | * Splits the cURL execution result into header and body |
||
236 | * |
||
237 | * @param $result |
||
238 | * |
||
239 | * @return array |
||
240 | */ |
||
241 | private function splitHeaderFromBody($result) |
||
250 | |||
251 | /** |
||
252 | * Parses the HTTP message headers from header part |
||
253 | * |
||
254 | * @param string $header |
||
255 | * |
||
256 | * @return array |
||
257 | */ |
||
258 | private function parseHeaders($header) |
||
272 | |||
273 | /** |
||
274 | * Checks provided response is an HTTP client error (4xx) |
||
275 | * |
||
276 | * @param ResponseInterface $response |
||
277 | * @param RequestInterface $request |
||
278 | * |
||
279 | * @throws ClientErrorException for responses with status codes between 400 and 499 |
||
280 | */ |
||
281 | private function checkClientError(ResponseInterface $response, RequestInterface $request) |
||
287 | |||
288 | /** |
||
289 | * Checks provided response is an HTTP server error (5xx) |
||
290 | * |
||
291 | * @param ResponseInterface $response |
||
292 | * @param RequestInterface $request |
||
293 | * |
||
294 | * @throws ServerErrorException for responses with status codes grater or equal to 500 |
||
295 | */ |
||
296 | private function checkServerError(ResponseInterface $response, RequestInterface $request) |
||
302 | |||
303 | /** |
||
304 | * Close the cURL handler on destruct |
||
305 | */ |
||
306 | public function __destruct() |
||
312 | } |
||
313 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.