1
1
<?php
2
+
2
3
namespace Http \Client \Curl ;
3
4
4
5
use Http \Client \Exception ;
13
14
use Psr \Http \Message \ResponseInterface ;
14
15
15
16
/**
16
- * PSR-7 compatible cURL based HTTP client
17
+ * PSR-7 compatible cURL based HTTP client.
17
18
*
18
19
* @license http://opensource.org/licenses/MIT MIT
19
- *
20
20
* @author Михаил Красильников <m.krasilnikov@yandex.ru>
21
21
* @author Blake Williams <github@shabbyrobe.org>
22
22
*
23
23
* @api
24
+ *
24
25
* @since 1.0
25
26
*/
26
27
class Client implements HttpClient, HttpAsyncClient
27
28
{
28
29
/**
29
- * cURL options
30
+ * cURL options.
30
31
*
31
32
* @var array
32
33
*/
33
34
private $ options ;
34
35
35
36
/**
36
- * PSR-7 message factory
37
+ * PSR-7 message factory.
37
38
*
38
39
* @var MessageFactory
39
40
*/
40
41
private $ messageFactory ;
41
42
42
43
/**
43
- * PSR-7 stream factory
44
+ * PSR-7 stream factory.
44
45
*
45
46
* @var StreamFactory
46
47
*/
47
48
private $ streamFactory ;
48
49
49
50
/**
50
- * cURL synchronous requests handle
51
+ * cURL synchronous requests handle.
51
52
*
52
53
* @var resource|null
53
54
*/
54
55
private $ handle = null ;
55
56
56
57
/**
57
- * Simultaneous requests runner
58
+ * Simultaneous requests runner.
58
59
*
59
60
* @var MultiRunner|null
60
61
*/
61
62
private $ multiRunner = null ;
62
63
63
64
/**
64
- * Create new client
65
+ * Create new client.
65
66
*
66
67
* @param MessageFactory|null $messageFactory HTTP Message factory
67
68
* @param StreamFactory|null $streamFactory HTTP Stream factory
68
69
* @param array $options cURL options (see http://php.net/curl_setopt)
69
70
*
70
- * @throws \Http\Discovery\Exception\NotFoundException If factory discovery failed.
71
+ * @throws \Http\Discovery\Exception\NotFoundException If factory discovery failed
71
72
*
72
73
* @since 1.0
73
74
*/
@@ -82,7 +83,7 @@ public function __construct(
82
83
}
83
84
84
85
/**
85
- * Release resources if still active
86
+ * Release resources if still active.
86
87
*/
87
88
public function __destruct ()
88
89
{
@@ -98,13 +99,13 @@ public function __destruct()
98
99
*
99
100
* @return ResponseInterface
100
101
*
101
- * @throws \Http\Client\Exception\NetworkException In case of network problems.
102
- * @throws \Http\Client\Exception\RequestException On invalid request.
103
- * @throws \InvalidArgumentException For invalid header names or values.
104
- * @throws \RuntimeException If creating the body stream fails.
102
+ * @throws \Http\Client\Exception\NetworkException In case of network problems
103
+ * @throws \Http\Client\Exception\RequestException On invalid request
104
+ * @throws \InvalidArgumentException For invalid header names or values
105
+ * @throws \RuntimeException If creating the body stream fails
105
106
*
106
- * @since 1.6 \UnexpectedValueException replaced with RequestException.
107
- * @since 1.6 Throw NetworkException on network errors.
107
+ * @since 1.6 \UnexpectedValueException replaced with RequestException
108
+ * @since 1.6 Throw NetworkException on network errors
108
109
* @since 1.0
109
110
*/
110
111
public function sendRequest (RequestInterface $ request )
@@ -149,11 +150,11 @@ public function sendRequest(RequestInterface $request)
149
150
*
150
151
* @return Promise
151
152
*
152
- * @throws \Http\Client\Exception\RequestException On invalid request.
153
- * @throws \InvalidArgumentException For invalid header names or values.
154
- * @throws \RuntimeException If creating the body stream fails.
153
+ * @throws \Http\Client\Exception\RequestException On invalid request
154
+ * @throws \InvalidArgumentException For invalid header names or values
155
+ * @throws \RuntimeException If creating the body stream fails
155
156
*
156
- * @since 1.6 \UnexpectedValueException replaced with RequestException.
157
+ * @since 1.6 \UnexpectedValueException replaced with RequestException
157
158
* @since 1.0
158
159
*/
159
160
public function sendAsyncRequest (RequestInterface $ request )
@@ -175,14 +176,14 @@ public function sendAsyncRequest(RequestInterface $request)
175
176
}
176
177
177
178
/**
178
- * Generates cURL options
179
+ * Generates cURL options.
179
180
*
180
181
* @param RequestInterface $request
181
182
* @param ResponseBuilder $responseBuilder
182
183
*
183
- * @throws \Http\Client\Exception\RequestException On invalid request.
184
- * @throws \InvalidArgumentException For invalid header names or values.
185
- * @throws \RuntimeException if can not read body
184
+ * @throws \Http\Client\Exception\RequestException On invalid request
185
+ * @throws \InvalidArgumentException For invalid header names or values
186
+ * @throws \RuntimeException if can not read body
186
187
*
187
188
* @return array
188
189
*/
@@ -231,7 +232,7 @@ private function createCurlOptions(RequestInterface $request, ResponseBuilder $r
231
232
}
232
233
233
234
/**
234
- * Return cURL constant for specified HTTP version
235
+ * Return cURL constant for specified HTTP version.
235
236
*
236
237
* @param string $requestVersion
237
238
*
@@ -311,7 +312,7 @@ private function addRequestBodyOptions(RequestInterface $request, array $options
311
312
}
312
313
313
314
/**
314
- * Create headers array for CURLOPT_HTTPHEADER
315
+ * Create headers array for CURLOPT_HTTPHEADER.
315
316
*
316
317
* @param RequestInterface $request
317
318
* @param array $options cURL options
@@ -338,7 +339,7 @@ private function createHeaders(RequestInterface $request, array $options)
338
339
}
339
340
}
340
341
foreach ($ values as $ value ) {
341
- $ curlHeaders [] = $ name . ': ' . $ value ;
342
+ $ curlHeaders [] = $ name. ': ' . $ value ;
342
343
}
343
344
}
344
345
/*
@@ -351,11 +352,11 @@ private function createHeaders(RequestInterface $request, array $options)
351
352
}
352
353
353
354
/**
354
- * Create new ResponseBuilder instance
355
+ * Create new ResponseBuilder instance.
355
356
*
356
357
* @return ResponseBuilder
357
358
*
358
- * @throws \RuntimeException If creating the stream from $body fails.
359
+ * @throws \RuntimeException If creating the stream from $body fails
359
360
*/
360
361
private function createResponseBuilder ()
361
362
{
0 commit comments