@@ -13,5 +13,5 @@ |
||
13 | 13 | |
14 | 14 | |
15 | 15 | class InvalidOperationException extends \LogicException{ |
16 | - protected $code = 2; |
|
16 | + protected $code = 2; |
|
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -12,6 +12,6 @@ |
||
12 | 12 | namespace MultiHttp\Exception; |
13 | 13 | |
14 | 14 | |
15 | -class InvalidOperationException extends \LogicException{ |
|
15 | +class InvalidOperationException extends \LogicException { |
|
16 | 16 | protected $code = 2; |
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -13,5 +13,5 @@ |
||
13 | 13 | |
14 | 14 | |
15 | 15 | class UnexpectedResponseException extends \UnexpectedValueException { |
16 | - protected $code = 3; |
|
16 | + protected $code = 3; |
|
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -13,5 +13,5 @@ |
||
13 | 13 | |
14 | 14 | |
15 | 15 | class InvalidArgumentException extends \LogicException{ |
16 | - protected $code = 1; |
|
16 | + protected $code = 1; |
|
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -12,6 +12,6 @@ |
||
12 | 12 | namespace MultiHttp\Exception; |
13 | 13 | |
14 | 14 | |
15 | -class InvalidArgumentException extends \LogicException{ |
|
15 | +class InvalidArgumentException extends \LogicException { |
|
16 | 16 | protected $code = 1; |
17 | 17 | } |
18 | 18 | \ No newline at end of file |
@@ -54,10 +54,11 @@ |
||
54 | 54 | $headers = explode(PHP_EOL, $headers); |
55 | 55 | array_shift($headers); // HTTP HEADER |
56 | 56 | foreach($headers as $h) { |
57 | - if(false !== strpos($h, ':')) |
|
58 | - list($k, $v) = explode(':', $h, 2); |
|
59 | - else |
|
60 | - list($k, $v) = array($h,''); |
|
57 | + if(false !== strpos($h, ':')) { |
|
58 | + list($k, $v) = explode(':', $h, 2); |
|
59 | + } else { |
|
60 | + list($k, $v) = array($h,''); |
|
61 | + } |
|
61 | 62 | |
62 | 63 | $this->header[trim($k)] = trim($v); |
63 | 64 | } |
@@ -15,81 +15,81 @@ |
||
15 | 15 | |
16 | 16 | class Response |
17 | 17 | { |
18 | - public |
|
19 | - $code, |
|
20 | - $errorCode, |
|
21 | - $error, |
|
22 | - $header, |
|
23 | - $body, |
|
24 | - /** |
|
25 | - * @var Request |
|
26 | - */ |
|
27 | - $request, |
|
28 | - $contentType, |
|
29 | - $charset, |
|
30 | - $duration, |
|
31 | - $info; |
|
32 | - protected function __construct() |
|
33 | - { |
|
34 | - } |
|
18 | + public |
|
19 | + $code, |
|
20 | + $errorCode, |
|
21 | + $error, |
|
22 | + $header, |
|
23 | + $body, |
|
24 | + /** |
|
25 | + * @var Request |
|
26 | + */ |
|
27 | + $request, |
|
28 | + $contentType, |
|
29 | + $charset, |
|
30 | + $duration, |
|
31 | + $info; |
|
32 | + protected function __construct() |
|
33 | + { |
|
34 | + } |
|
35 | 35 | |
36 | - public static function create(Request $request, $body, $info, $errorCode, $error){ |
|
37 | - $self = new self; |
|
38 | - $self->request = $request; |
|
39 | - $self->body = $body; |
|
40 | - $self->info = $info; |
|
41 | - $self->errorCode = $errorCode; |
|
42 | - $self->error = $error; |
|
43 | - $self->parse(); |
|
44 | - $self->check(); |
|
45 | - return $self; |
|
46 | - } |
|
47 | - public function check(){ |
|
36 | + public static function create(Request $request, $body, $info, $errorCode, $error){ |
|
37 | + $self = new self; |
|
38 | + $self->request = $request; |
|
39 | + $self->body = $body; |
|
40 | + $self->info = $info; |
|
41 | + $self->errorCode = $errorCode; |
|
42 | + $self->error = $error; |
|
43 | + $self->parse(); |
|
44 | + $self->check(); |
|
45 | + return $self; |
|
46 | + } |
|
47 | + public function check(){ |
|
48 | 48 | |
49 | - } |
|
50 | - public function parse(){ |
|
51 | - //has header |
|
52 | - if($this->request->getIni('header')){ |
|
53 | - $headers = rtrim(substr($this->body, 0, $this->info['header_size'])); |
|
54 | - $this->body = substr($this->body, $this->info['header_size']); |
|
55 | - $headers = explode(PHP_EOL, $headers); |
|
56 | - array_shift($headers); // HTTP HEADER |
|
57 | - foreach($headers as $h) { |
|
58 | - if(false !== strpos($h, ':')) |
|
59 | - list($k, $v) = explode(':', $h, 2); |
|
60 | - else |
|
61 | - list($k, $v) = array($h,''); |
|
49 | + } |
|
50 | + public function parse(){ |
|
51 | + //has header |
|
52 | + if($this->request->getIni('header')){ |
|
53 | + $headers = rtrim(substr($this->body, 0, $this->info['header_size'])); |
|
54 | + $this->body = substr($this->body, $this->info['header_size']); |
|
55 | + $headers = explode(PHP_EOL, $headers); |
|
56 | + array_shift($headers); // HTTP HEADER |
|
57 | + foreach($headers as $h) { |
|
58 | + if(false !== strpos($h, ':')) |
|
59 | + list($k, $v) = explode(':', $h, 2); |
|
60 | + else |
|
61 | + list($k, $v) = array($h,''); |
|
62 | 62 | |
63 | - $this->header[trim($k)] = trim($v); |
|
64 | - } |
|
65 | - } |
|
66 | - $this->code = $this->info['http_code']; |
|
67 | - $this->duration = $this->info['total_time']; |
|
68 | - $this->contentType = $this->info['content_type']; |
|
69 | - $content_type = isset($this->info['content_type']) ? $this->info['content_type'] : ''; |
|
70 | - $content_type = explode(';', $content_type); |
|
71 | - $this->contentType = $content_type[0]; |
|
72 | - if (count($content_type) == 2 && strpos($content_type[1], '=') !== false) { |
|
73 | - list( , $this->charset) = explode('=', $content_type[1]); |
|
74 | - } |
|
75 | - } |
|
63 | + $this->header[trim($k)] = trim($v); |
|
64 | + } |
|
65 | + } |
|
66 | + $this->code = $this->info['http_code']; |
|
67 | + $this->duration = $this->info['total_time']; |
|
68 | + $this->contentType = $this->info['content_type']; |
|
69 | + $content_type = isset($this->info['content_type']) ? $this->info['content_type'] : ''; |
|
70 | + $content_type = explode(';', $content_type); |
|
71 | + $this->contentType = $content_type[0]; |
|
72 | + if (count($content_type) == 2 && strpos($content_type[1], '=') !== false) { |
|
73 | + list( , $this->charset) = explode('=', $content_type[1]); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Status Code Definitions |
|
79 | - * |
|
80 | - * Informational 1xx |
|
81 | - * Successful 2xx |
|
82 | - * Redirection 3xx |
|
83 | - * Client Error 4xx |
|
84 | - * Server Error 5xx |
|
85 | - * |
|
86 | - * http://pretty-rfc.herokuapp.com/RFC2616#status.codes |
|
87 | - * |
|
88 | - * @return bool Did we receive a 4xx or 5xx? |
|
89 | - */ |
|
90 | - public function hasErrors() |
|
91 | - { |
|
92 | - return $this->code == 0 || $this->code >= 400; |
|
93 | - } |
|
77 | + /** |
|
78 | + * Status Code Definitions |
|
79 | + * |
|
80 | + * Informational 1xx |
|
81 | + * Successful 2xx |
|
82 | + * Redirection 3xx |
|
83 | + * Client Error 4xx |
|
84 | + * Server Error 5xx |
|
85 | + * |
|
86 | + * http://pretty-rfc.herokuapp.com/RFC2616#status.codes |
|
87 | + * |
|
88 | + * @return bool Did we receive a 4xx or 5xx? |
|
89 | + */ |
|
90 | + public function hasErrors() |
|
91 | + { |
|
92 | + return $this->code == 0 || $this->code >= 400; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | } |
96 | 96 | \ No newline at end of file |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | { |
34 | 34 | } |
35 | 35 | |
36 | - public static function create(Request $request, $body, $info, $errorCode, $error){ |
|
36 | + public static function create(Request $request, $body, $info, $errorCode, $error) { |
|
37 | 37 | $self = new self; |
38 | 38 | $self->request = $request; |
39 | 39 | $self->body = $body; |
@@ -44,21 +44,21 @@ discard block |
||
44 | 44 | $self->check(); |
45 | 45 | return $self; |
46 | 46 | } |
47 | - public function check(){ |
|
47 | + public function check() { |
|
48 | 48 | |
49 | 49 | } |
50 | - public function parse(){ |
|
50 | + public function parse() { |
|
51 | 51 | //has header |
52 | - if($this->request->getIni('header')){ |
|
52 | + if ($this->request->getIni('header')) { |
|
53 | 53 | $headers = rtrim(substr($this->body, 0, $this->info['header_size'])); |
54 | 54 | $this->body = substr($this->body, $this->info['header_size']); |
55 | 55 | $headers = explode(PHP_EOL, $headers); |
56 | 56 | array_shift($headers); // HTTP HEADER |
57 | - foreach($headers as $h) { |
|
58 | - if(false !== strpos($h, ':')) |
|
57 | + foreach ($headers as $h) { |
|
58 | + if (false !== strpos($h, ':')) |
|
59 | 59 | list($k, $v) = explode(':', $h, 2); |
60 | 60 | else |
61 | - list($k, $v) = array($h,''); |
|
61 | + list($k, $v) = array($h, ''); |
|
62 | 62 | |
63 | 63 | $this->header[trim($k)] = trim($v); |
64 | 64 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $content_type = explode(';', $content_type); |
71 | 71 | $this->contentType = $content_type[0]; |
72 | 72 | if (count($content_type) == 2 && strpos($content_type[1], '=') !== false) { |
73 | - list( , $this->charset) = explode('=', $content_type[1]); |
|
73 | + list(, $this->charset) = explode('=', $content_type[1]); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | return $this; |
188 | 188 | } |
189 | 189 | /** |
190 | - * @param $field alias or field name |
|
190 | + * @param string $field alias or field name |
|
191 | 191 | * @return bool|mixed |
192 | 192 | */ |
193 | 193 | public function getIni($field) |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | |
199 | 199 | /** |
200 | 200 | * @param $key |
201 | - * @return mixed |
|
201 | + * @return string |
|
202 | 202 | */ |
203 | 203 | protected static function optionAlias($key) |
204 | 204 | { |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | protected static $curlAlias = array( |
20 | 20 | 'url' => 'CURLOPT_URL', |
21 | 21 | 'uri' => 'CURLOPT_URL', |
22 | - 'debug' => 'CURLOPT_VERBOSE',//for debug verbose |
|
22 | + 'debug' => 'CURLOPT_VERBOSE', //for debug verbose |
|
23 | 23 | 'method' => 'CURLOPT_CUSTOMREQUEST', |
24 | 24 | 'data' => 'CURLOPT_POSTFIELDS', // array or string , file begin with '@' |
25 | 25 | 'ua' => 'CURLOPT_USERAGENT', |
@@ -232,9 +232,9 @@ discard block |
||
232 | 232 | |
233 | 233 | /* no body */ |
234 | 234 | |
235 | - protected function ini($method, $url, $data , array $options = array()) |
|
235 | + protected function ini($method, $url, $data, array $options = array()) |
|
236 | 236 | { |
237 | - $options = array('url' => $url, 'method' => $method, 'data' => $data) + $options; |
|
237 | + $options = array('url' => $url, 'method' => $method, 'data' => $data)+$options; |
|
238 | 238 | $this->addOptions($options); |
239 | 239 | |
240 | 240 | return $this; |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | public function addOptions(array $options = array()) |
244 | 244 | { |
245 | - $this->options = $options + $this->options; |
|
245 | + $this->options = $options+$this->options; |
|
246 | 246 | $this->uri = $this->options['url']; |
247 | 247 | return $this; |
248 | 248 | } |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | } |
314 | 314 | |
315 | 315 | if (isset($this->options['data'])) { |
316 | - $this->options['data'] = is_array($this->options['data']) ? http_build_query($this->options['data']) : $this->options['data'];//for better compatibility |
|
316 | + $this->options['data'] = is_array($this->options['data']) ? http_build_query($this->options['data']) : $this->options['data']; //for better compatibility |
|
317 | 317 | } |
318 | 318 | if (isset($this->withURIQuery)) { |
319 | 319 | $this->options['url'] .= strpos($this->options['url'], '?') === FALSE ? '?' : '&'; |
@@ -329,11 +329,11 @@ discard block |
||
329 | 329 | preg_match('/\/\/([^\/]+)/', $this->options['url'], $matches); |
330 | 330 | $host = $matches[1]; |
331 | 331 | if (empty($this->options['headers']) || !is_array($this->options['headers'])) { |
332 | - $this->options['headers'] = array('Host: ' . $host); |
|
332 | + $this->options['headers'] = array('Host: '.$host); |
|
333 | 333 | } else { |
334 | - $this->options['headers'][] = 'Host: ' . $host; |
|
334 | + $this->options['headers'][] = 'Host: '.$host; |
|
335 | 335 | } |
336 | - $this->options['url'] = preg_replace('/\/\/([^\/]+)/', '//' . $this->options['ip'], $this->options['url']); |
|
336 | + $this->options['url'] = preg_replace('/\/\/([^\/]+)/', '//'.$this->options['ip'], $this->options['url']); |
|
337 | 337 | unset($this->options['ip']); |
338 | 338 | unset($host); |
339 | 339 | } |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | //convert secs to milliseconds |
353 | 353 | if (defined('CURLOPT_TIMEOUT_MS')) { |
354 | 354 | if (!isset($this->options['timeout_ms'])) { |
355 | - $this->options['timeout_ms'] = intval($this->options['timeout'] * 1000); |
|
355 | + $this->options['timeout_ms'] = intval($this->options['timeout']*1000); |
|
356 | 356 | } else { |
357 | 357 | $this->options['timeout_ms'] = intval($this->options['timeout_ms']); |
358 | 358 | } |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | public function onEnd(callable $callback) |
370 | 370 | { |
371 | 371 | if (!is_callable($callback)) { |
372 | - throw new InvalidArgumentException('callback not is callable :' . print_r($callback, 1)); |
|
372 | + throw new InvalidArgumentException('callback not is callable :'.print_r($callback, 1)); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | $this->endCallback = $callback; |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | private static function log(Response $response) |
408 | 408 | { |
409 | 409 | if ($response->hasErrors()) { |
410 | - self::$logger->error($response->request->getURI() . "\t" . $response->error, array( |
|
410 | + self::$logger->error($response->request->getURI()."\t".$response->error, array( |
|
411 | 411 | 'response' => print_r($response, 1), |
412 | 412 | )); |
413 | 413 | } |
@@ -152,7 +152,9 @@ discard block |
||
152 | 152 | } |
153 | 153 | public function mime($mime) |
154 | 154 | { |
155 | - if (empty($mime)) return $this; |
|
155 | + if (empty($mime)) { |
|
156 | + return $this; |
|
157 | + } |
|
156 | 158 | $this->content_type = $this->expected_type = Mime::getFullMime($mime); |
157 | 159 | if ($this->isUpload()) { |
158 | 160 | $this->neverSerializePayload(); |
@@ -182,7 +184,9 @@ discard block |
||
182 | 184 | } |
183 | 185 | public function expects($mime) |
184 | 186 | { |
185 | - if (empty($mime)) return $this; |
|
187 | + if (empty($mime)) { |
|
188 | + return $this; |
|
189 | + } |
|
186 | 190 | $this->expected_type = Mime::getFullMime($mime); |
187 | 191 | return $this; |
188 | 192 | } |
@@ -287,8 +291,9 @@ discard block |
||
287 | 291 | */ |
288 | 292 | public function send() |
289 | 293 | { |
290 | - if (!$this->hasInitialized) |
|
291 | - $this->applyOptions(); |
|
294 | + if (!$this->hasInitialized) { |
|
295 | + $this->applyOptions(); |
|
296 | + } |
|
292 | 297 | $response = $this->makeResponse(); |
293 | 298 | if ($this->endCallback) { |
294 | 299 | $func = $this->endCallback; |
@@ -15,401 +15,401 @@ |
||
15 | 15 | |
16 | 16 | class Request extends Http |
17 | 17 | { |
18 | - const MAX_REDIRECTS_DEFAULT = 10; |
|
19 | - protected static $curlAlias = array( |
|
20 | - 'url' => 'CURLOPT_URL', |
|
21 | - 'uri' => 'CURLOPT_URL', |
|
22 | - 'debug' => 'CURLOPT_VERBOSE',//for debug verbose |
|
23 | - 'method' => 'CURLOPT_CUSTOMREQUEST', |
|
24 | - 'data' => 'CURLOPT_POSTFIELDS', // array or string , file begin with '@' |
|
25 | - 'ua' => 'CURLOPT_USERAGENT', |
|
26 | - 'timeout' => 'CURLOPT_TIMEOUT', // (secs) 0 means indefinitely |
|
27 | - 'connect_timeout' => 'CURLOPT_CONNECTTIMEOUT', |
|
28 | - 'referer' => 'CURLOPT_REFERER', |
|
29 | - 'binary' => 'CURLOPT_BINARYTRANSFER', |
|
30 | - 'port' => 'CURLOPT_PORT', |
|
31 | - 'header' => 'CURLOPT_HEADER', // TRUE:include header |
|
32 | - 'headers' => 'CURLOPT_HTTPHEADER', // array |
|
33 | - 'download' => 'CURLOPT_FILE', // writing file stream (using fopen()), default is STDOUT |
|
34 | - 'upload' => 'CURLOPT_INFILE', // reading file stream |
|
35 | - 'transfer' => 'CURLOPT_RETURNTRANSFER', // TRUE:return string; FALSE:output directly (curl_exec) |
|
36 | - 'follow_location' => 'CURLOPT_FOLLOWLOCATION', |
|
37 | - 'timeout_ms' => 'CURLOPT_TIMEOUT_MS', // milliseconds, libcurl version > 7.36.0 , |
|
38 | - ); |
|
39 | - protected static $logger; |
|
40 | - public $curlHandle; |
|
41 | - public |
|
42 | - $uri, |
|
43 | - $timeout, |
|
44 | - $maxRedirects, |
|
45 | - $followRedirects; |
|
46 | - public $cert; |
|
47 | - public $key; |
|
48 | - public $passphrase; |
|
49 | - public $encoding; |
|
50 | - public $payload; |
|
51 | - protected $options = array( |
|
52 | - 'CURLOPT_MAXREDIRS' => 10, |
|
53 | - 'header' => true, |
|
54 | - 'method' => self::GET, |
|
55 | - 'transfer' => true, |
|
56 | - 'follow_location' => true, |
|
57 | - 'timeout' => 0); |
|
58 | - protected $endCallback; |
|
59 | - protected $withURIQuery; |
|
60 | - protected $hasInitialized = false; |
|
61 | - |
|
62 | - protected function __construct() |
|
63 | - { |
|
64 | - |
|
65 | - } |
|
66 | - |
|
67 | - public static function create() |
|
68 | - { |
|
69 | - return new self; |
|
70 | - } |
|
71 | - |
|
72 | - public static function setLogger($logger) |
|
73 | - { |
|
74 | - self::$logger = $logger; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Specify timeout |
|
79 | - * @param float|int $timeout seconds to timeout the HTTP call |
|
80 | - * @return Request |
|
81 | - */ |
|
82 | - public function timeout($timeout) |
|
83 | - { |
|
84 | - $this->timeout = $timeout; |
|
85 | - return $this; |
|
86 | - } |
|
87 | - |
|
88 | - public function noFollow() |
|
89 | - { |
|
90 | - return $this->follow(0); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * If the response is a 301 or 302 redirect, automatically |
|
95 | - * send off another request to that location |
|
96 | - * @param int $follow follow or not to follow or maximal number of redirects |
|
97 | - * @return Request |
|
98 | - */ |
|
99 | - public function follow(int $follow) |
|
100 | - { |
|
101 | - $this->maxRedirects = abs($follow); |
|
102 | - $this->followRedirects = $follow > 0; |
|
103 | - return $this; |
|
104 | - } |
|
105 | - |
|
106 | - public function endCallback() |
|
107 | - { |
|
108 | - return $this->endCallback; |
|
109 | - } |
|
110 | - |
|
111 | - public function hasEndCallback() |
|
112 | - { |
|
113 | - return isset($this->endCallback); |
|
114 | - } |
|
115 | - |
|
116 | - public function uri($uri) |
|
117 | - { |
|
118 | - $this->uri = $uri; |
|
119 | - return $this; |
|
120 | - } |
|
121 | - |
|
122 | - public function hasCert() |
|
123 | - { |
|
124 | - return isset($this->cert) && isset($this->key); |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Use Client Side Cert Authentication |
|
129 | - * @param string $key file path to client key |
|
130 | - * @param string $cert file path to client cert |
|
131 | - * @param string $passphrase for client key |
|
132 | - * @param string $encoding default PEM |
|
133 | - * @return Request |
|
134 | - */ |
|
135 | - public function cert($cert, $key, $passphrase = null, $encoding = 'PEM') |
|
136 | - { |
|
137 | - $this->cert = $cert; |
|
138 | - $this->key = $key; |
|
139 | - $this->passphrase = $passphrase; |
|
140 | - $this->encoding = $encoding; |
|
141 | - return $this; |
|
142 | - } |
|
143 | - |
|
144 | - public function body($payload, $mimeType = null) |
|
145 | - { |
|
146 | - $this->mime($mimeType); |
|
147 | - $this->payload = $payload; |
|
148 | - // Iserntentially don't call _serializePayload yet. Wait until |
|
149 | - // we actually send off the request to convert payload to string. |
|
150 | - // At that time, the `serialized_payload` is set accordingly. |
|
151 | - return $this; |
|
152 | - } |
|
153 | - public function mime($mime) |
|
154 | - { |
|
155 | - if (empty($mime)) return $this; |
|
156 | - $this->content_type = $this->expected_type = Mime::getFullMime($mime); |
|
157 | - if ($this->isUpload()) { |
|
158 | - $this->neverSerializePayload(); |
|
159 | - } |
|
160 | - return $this; |
|
161 | - } |
|
162 | - public function addHeader($header_name, $value) |
|
163 | - { |
|
164 | - $this->headers[$header_name] = $value; |
|
165 | - return $this; |
|
166 | - } |
|
167 | - |
|
168 | - public function addHeaders(array $headers) |
|
169 | - { |
|
170 | - foreach ($headers as $header => $value) { |
|
171 | - $this->addHeader($header, $value); |
|
172 | - } |
|
173 | - return $this; |
|
174 | - } |
|
175 | - public function expectsType($mime) |
|
176 | - { |
|
177 | - return $this->expects($mime); |
|
178 | - } |
|
179 | - public function sendType($mime) |
|
180 | - { |
|
181 | - return $this->contentType = $mime; |
|
182 | - } |
|
183 | - public function expects($mime) |
|
184 | - { |
|
185 | - if (empty($mime)) return $this; |
|
186 | - $this->expected_type = Mime::getFullMime($mime); |
|
187 | - return $this; |
|
188 | - } |
|
189 | - /** |
|
190 | - * @param $field alias or field name |
|
191 | - * @return bool|mixed |
|
192 | - */ |
|
193 | - public function getIni($field) |
|
194 | - { |
|
195 | - $alias = self::optionAlias($field); |
|
196 | - return isset($this->options[$alias]) ? $this->options[$alias] : false; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param $key |
|
201 | - * @return mixed |
|
202 | - */ |
|
203 | - protected static function optionAlias($key) |
|
204 | - { |
|
205 | - $alias = false; |
|
206 | - if (isset(self::$curlAlias[$key])) { |
|
207 | - $alias = self::$curlAlias[$key]; |
|
208 | - } elseif ((substr($key, 0, strlen('CURLOPT_')) == 'CURLOPT_') && defined($key)) { |
|
209 | - $alias = $key; |
|
210 | - } |
|
211 | - return $alias; |
|
212 | - } |
|
213 | - |
|
214 | - public function addQuery($data) |
|
215 | - { |
|
216 | - if (!empty($data)) { |
|
217 | - if (is_array($data)) { |
|
218 | - $this->withURIQuery = http_build_query($data); |
|
219 | - } else if (is_string($data)) { |
|
220 | - $this->withURIQuery = $data; |
|
221 | - } else { |
|
222 | - throw new InvalidArgumentException('data must be array or string'); |
|
223 | - } |
|
224 | - } |
|
225 | - return $this; |
|
226 | - } |
|
227 | - |
|
228 | - public function post($uri, $payload = null, array $options = array()) |
|
229 | - { |
|
230 | - return $this->ini(Http::POST, $uri, $payload, $options); |
|
231 | - } |
|
232 | - |
|
233 | - /* no body */ |
|
234 | - |
|
235 | - protected function ini($method, $url, $data , array $options = array()) |
|
236 | - { |
|
237 | - $options = array('url' => $url, 'method' => $method, 'data' => $data) + $options; |
|
238 | - $this->addOptions($options); |
|
239 | - |
|
240 | - return $this; |
|
241 | - } |
|
242 | - |
|
243 | - public function addOptions(array $options = array()) |
|
244 | - { |
|
245 | - $this->options = $options + $this->options; |
|
246 | - $this->uri = $this->options['url']; |
|
247 | - return $this; |
|
248 | - } |
|
249 | - |
|
250 | - function put($uri, $payload = null, array $options = array()) |
|
251 | - { |
|
252 | - return $this->ini(Http::PUT, $uri, $payload, $options); |
|
253 | - } |
|
254 | - |
|
255 | - function patch($uri, $payload = null, array $options = array()) |
|
256 | - { |
|
257 | - return $this->ini(Http::PATCH, $uri, $payload, $options); |
|
258 | - } |
|
259 | - |
|
260 | - public function get($uri, array $options = array()) |
|
261 | - { |
|
262 | - return $this->ini(Http::GET, $uri, array(), $options); |
|
263 | - } |
|
264 | - |
|
265 | - function options($uri, array $options = array()) |
|
266 | - { |
|
267 | - return $this->ini(Http::OPTIONS, $uri, array(), $options); |
|
268 | - } |
|
269 | - |
|
270 | - function head($uri, array $options = array()) |
|
271 | - { |
|
272 | - return $this->ini(Http::HEAD, $uri, array('CURLOPT_NOBODY' => true), $options); |
|
273 | - } |
|
274 | - |
|
275 | - function delete($uri, array $options = array()) |
|
276 | - { |
|
277 | - return $this->ini(Http::DELETE, $uri, array(), $options); |
|
278 | - } |
|
279 | - |
|
280 | - function trace($uri, array $options = array()) |
|
281 | - { |
|
282 | - return $this->ini(Http::TRACE, $uri, array(), $options); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * @return Response |
|
287 | - */ |
|
288 | - public function send() |
|
289 | - { |
|
290 | - if (!$this->hasInitialized) |
|
291 | - $this->applyOptions(); |
|
292 | - $response = $this->makeResponse(); |
|
293 | - if ($this->endCallback) { |
|
294 | - $func = $this->endCallback; |
|
295 | - $func($response); |
|
296 | - } |
|
297 | - return $response; |
|
298 | - } |
|
299 | - |
|
300 | - public function applyOptions() |
|
301 | - { |
|
302 | - $curl = curl_init(); |
|
303 | - $this->curlHandle = $curl; |
|
304 | - $this->prepare(); |
|
305 | - $this->hasInitialized = true; |
|
306 | - return $this; |
|
307 | - } |
|
308 | - |
|
309 | - protected function prepare() |
|
310 | - { |
|
311 | - if (empty($this->options['url'])) { |
|
312 | - throw new InvalidArgumentException('url can not empty'); |
|
313 | - } |
|
314 | - |
|
315 | - if (isset($this->options['data'])) { |
|
316 | - $this->options['data'] = is_array($this->options['data']) ? http_build_query($this->options['data']) : $this->options['data'];//for better compatibility |
|
317 | - } |
|
318 | - if (isset($this->withURIQuery)) { |
|
319 | - $this->options['url'] .= strpos($this->options['url'], '?') === FALSE ? '?' : '&'; |
|
320 | - $this->options['url'] .= $this->withURIQuery; |
|
321 | - } |
|
322 | - if (isset($this->options['callback'])) { |
|
323 | - $this->onEnd($this->options['callback']); |
|
324 | - unset($this->options['callback']); |
|
325 | - } |
|
326 | - //swap ip and host |
|
327 | - if (!empty($this->options['ip'])) { |
|
328 | - $matches = array(); |
|
329 | - preg_match('/\/\/([^\/]+)/', $this->options['url'], $matches); |
|
330 | - $host = $matches[1]; |
|
331 | - if (empty($this->options['headers']) || !is_array($this->options['headers'])) { |
|
332 | - $this->options['headers'] = array('Host: ' . $host); |
|
333 | - } else { |
|
334 | - $this->options['headers'][] = 'Host: ' . $host; |
|
335 | - } |
|
336 | - $this->options['url'] = preg_replace('/\/\/([^\/]+)/', '//' . $this->options['ip'], $this->options['url']); |
|
337 | - unset($this->options['ip']); |
|
338 | - unset($host); |
|
339 | - } |
|
340 | - //process version |
|
341 | - if (!empty($this->options['http_version'])) { |
|
342 | - $version = $this->options['http_version']; |
|
343 | - if ($version == '1.0') { |
|
344 | - $this->options['CURLOPT_HTTP_VERSION'] = CURLOPT_HTTP_VERSION_1_0; |
|
345 | - } elseif ($version == '1.1') { |
|
346 | - $this->options['CURLOPT_HTTP_VERSION'] = CURLOPT_HTTP_VERSION_1_1; |
|
347 | - } |
|
348 | - |
|
349 | - unset($version); |
|
350 | - } |
|
351 | - |
|
352 | - //convert secs to milliseconds |
|
353 | - if (defined('CURLOPT_TIMEOUT_MS')) { |
|
354 | - if (!isset($this->options['timeout_ms'])) { |
|
355 | - $this->options['timeout_ms'] = intval($this->options['timeout'] * 1000); |
|
356 | - } else { |
|
357 | - $this->options['timeout_ms'] = intval($this->options['timeout_ms']); |
|
358 | - } |
|
359 | - } |
|
360 | - |
|
361 | - $cURLOptions = self::filterAndRaw($this->options); |
|
362 | - |
|
363 | - curl_setopt_array($this->curlHandle, $cURLOptions); |
|
364 | - |
|
365 | - return $this; |
|
366 | - } |
|
367 | - |
|
368 | - public function onEnd(callable $callback) |
|
369 | - { |
|
370 | - if (!is_callable($callback)) { |
|
371 | - throw new InvalidArgumentException('callback not is callable :' . print_r($callback, 1)); |
|
372 | - } |
|
373 | - |
|
374 | - $this->endCallback = $callback; |
|
375 | - return $this; |
|
376 | - } |
|
377 | - |
|
378 | - protected static function filterAndRaw(array &$options) |
|
379 | - { |
|
380 | - $opts = array(); |
|
381 | - foreach ($options as $key => $val) { |
|
382 | - $alias = self::optionAlias($key); |
|
383 | - $options[$alias] = $val; |
|
384 | - if ($alias) { |
|
385 | - $opts[constant($alias)] = $val; |
|
386 | - } |
|
387 | - unset($options[$key]); |
|
388 | - } |
|
389 | - return $opts; |
|
390 | - } |
|
391 | - |
|
392 | - public function makeResponse($isMultiCurl = false) |
|
393 | - { |
|
394 | - $body = $isMultiCurl ? curl_multi_getcontent($this->curlHandle) : curl_exec($this->curlHandle); |
|
395 | - $info = curl_getinfo($this->curlHandle); |
|
396 | - $errno = curl_errno($this->curlHandle); |
|
397 | - $error = curl_error($this->curlHandle); |
|
398 | - $response = Response::create($this, $body, $info, $errno, $error); |
|
399 | - if (!is_null(self::$logger)) { |
|
400 | - self::log($response); |
|
401 | - } |
|
402 | - |
|
403 | - return $response; |
|
404 | - } |
|
405 | - |
|
406 | - private static function log(Response $response) |
|
407 | - { |
|
408 | - if ($response->hasErrors()) { |
|
409 | - self::$logger->error($response->request->getURI() . "\t" . $response->error, array( |
|
410 | - 'response' => print_r($response, 1), |
|
411 | - )); |
|
412 | - } |
|
413 | - |
|
414 | - } |
|
18 | + const MAX_REDIRECTS_DEFAULT = 10; |
|
19 | + protected static $curlAlias = array( |
|
20 | + 'url' => 'CURLOPT_URL', |
|
21 | + 'uri' => 'CURLOPT_URL', |
|
22 | + 'debug' => 'CURLOPT_VERBOSE',//for debug verbose |
|
23 | + 'method' => 'CURLOPT_CUSTOMREQUEST', |
|
24 | + 'data' => 'CURLOPT_POSTFIELDS', // array or string , file begin with '@' |
|
25 | + 'ua' => 'CURLOPT_USERAGENT', |
|
26 | + 'timeout' => 'CURLOPT_TIMEOUT', // (secs) 0 means indefinitely |
|
27 | + 'connect_timeout' => 'CURLOPT_CONNECTTIMEOUT', |
|
28 | + 'referer' => 'CURLOPT_REFERER', |
|
29 | + 'binary' => 'CURLOPT_BINARYTRANSFER', |
|
30 | + 'port' => 'CURLOPT_PORT', |
|
31 | + 'header' => 'CURLOPT_HEADER', // TRUE:include header |
|
32 | + 'headers' => 'CURLOPT_HTTPHEADER', // array |
|
33 | + 'download' => 'CURLOPT_FILE', // writing file stream (using fopen()), default is STDOUT |
|
34 | + 'upload' => 'CURLOPT_INFILE', // reading file stream |
|
35 | + 'transfer' => 'CURLOPT_RETURNTRANSFER', // TRUE:return string; FALSE:output directly (curl_exec) |
|
36 | + 'follow_location' => 'CURLOPT_FOLLOWLOCATION', |
|
37 | + 'timeout_ms' => 'CURLOPT_TIMEOUT_MS', // milliseconds, libcurl version > 7.36.0 , |
|
38 | + ); |
|
39 | + protected static $logger; |
|
40 | + public $curlHandle; |
|
41 | + public |
|
42 | + $uri, |
|
43 | + $timeout, |
|
44 | + $maxRedirects, |
|
45 | + $followRedirects; |
|
46 | + public $cert; |
|
47 | + public $key; |
|
48 | + public $passphrase; |
|
49 | + public $encoding; |
|
50 | + public $payload; |
|
51 | + protected $options = array( |
|
52 | + 'CURLOPT_MAXREDIRS' => 10, |
|
53 | + 'header' => true, |
|
54 | + 'method' => self::GET, |
|
55 | + 'transfer' => true, |
|
56 | + 'follow_location' => true, |
|
57 | + 'timeout' => 0); |
|
58 | + protected $endCallback; |
|
59 | + protected $withURIQuery; |
|
60 | + protected $hasInitialized = false; |
|
61 | + |
|
62 | + protected function __construct() |
|
63 | + { |
|
64 | + |
|
65 | + } |
|
66 | + |
|
67 | + public static function create() |
|
68 | + { |
|
69 | + return new self; |
|
70 | + } |
|
71 | + |
|
72 | + public static function setLogger($logger) |
|
73 | + { |
|
74 | + self::$logger = $logger; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Specify timeout |
|
79 | + * @param float|int $timeout seconds to timeout the HTTP call |
|
80 | + * @return Request |
|
81 | + */ |
|
82 | + public function timeout($timeout) |
|
83 | + { |
|
84 | + $this->timeout = $timeout; |
|
85 | + return $this; |
|
86 | + } |
|
87 | + |
|
88 | + public function noFollow() |
|
89 | + { |
|
90 | + return $this->follow(0); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * If the response is a 301 or 302 redirect, automatically |
|
95 | + * send off another request to that location |
|
96 | + * @param int $follow follow or not to follow or maximal number of redirects |
|
97 | + * @return Request |
|
98 | + */ |
|
99 | + public function follow(int $follow) |
|
100 | + { |
|
101 | + $this->maxRedirects = abs($follow); |
|
102 | + $this->followRedirects = $follow > 0; |
|
103 | + return $this; |
|
104 | + } |
|
105 | + |
|
106 | + public function endCallback() |
|
107 | + { |
|
108 | + return $this->endCallback; |
|
109 | + } |
|
110 | + |
|
111 | + public function hasEndCallback() |
|
112 | + { |
|
113 | + return isset($this->endCallback); |
|
114 | + } |
|
115 | + |
|
116 | + public function uri($uri) |
|
117 | + { |
|
118 | + $this->uri = $uri; |
|
119 | + return $this; |
|
120 | + } |
|
121 | + |
|
122 | + public function hasCert() |
|
123 | + { |
|
124 | + return isset($this->cert) && isset($this->key); |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Use Client Side Cert Authentication |
|
129 | + * @param string $key file path to client key |
|
130 | + * @param string $cert file path to client cert |
|
131 | + * @param string $passphrase for client key |
|
132 | + * @param string $encoding default PEM |
|
133 | + * @return Request |
|
134 | + */ |
|
135 | + public function cert($cert, $key, $passphrase = null, $encoding = 'PEM') |
|
136 | + { |
|
137 | + $this->cert = $cert; |
|
138 | + $this->key = $key; |
|
139 | + $this->passphrase = $passphrase; |
|
140 | + $this->encoding = $encoding; |
|
141 | + return $this; |
|
142 | + } |
|
143 | + |
|
144 | + public function body($payload, $mimeType = null) |
|
145 | + { |
|
146 | + $this->mime($mimeType); |
|
147 | + $this->payload = $payload; |
|
148 | + // Iserntentially don't call _serializePayload yet. Wait until |
|
149 | + // we actually send off the request to convert payload to string. |
|
150 | + // At that time, the `serialized_payload` is set accordingly. |
|
151 | + return $this; |
|
152 | + } |
|
153 | + public function mime($mime) |
|
154 | + { |
|
155 | + if (empty($mime)) return $this; |
|
156 | + $this->content_type = $this->expected_type = Mime::getFullMime($mime); |
|
157 | + if ($this->isUpload()) { |
|
158 | + $this->neverSerializePayload(); |
|
159 | + } |
|
160 | + return $this; |
|
161 | + } |
|
162 | + public function addHeader($header_name, $value) |
|
163 | + { |
|
164 | + $this->headers[$header_name] = $value; |
|
165 | + return $this; |
|
166 | + } |
|
167 | + |
|
168 | + public function addHeaders(array $headers) |
|
169 | + { |
|
170 | + foreach ($headers as $header => $value) { |
|
171 | + $this->addHeader($header, $value); |
|
172 | + } |
|
173 | + return $this; |
|
174 | + } |
|
175 | + public function expectsType($mime) |
|
176 | + { |
|
177 | + return $this->expects($mime); |
|
178 | + } |
|
179 | + public function sendType($mime) |
|
180 | + { |
|
181 | + return $this->contentType = $mime; |
|
182 | + } |
|
183 | + public function expects($mime) |
|
184 | + { |
|
185 | + if (empty($mime)) return $this; |
|
186 | + $this->expected_type = Mime::getFullMime($mime); |
|
187 | + return $this; |
|
188 | + } |
|
189 | + /** |
|
190 | + * @param $field alias or field name |
|
191 | + * @return bool|mixed |
|
192 | + */ |
|
193 | + public function getIni($field) |
|
194 | + { |
|
195 | + $alias = self::optionAlias($field); |
|
196 | + return isset($this->options[$alias]) ? $this->options[$alias] : false; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param $key |
|
201 | + * @return mixed |
|
202 | + */ |
|
203 | + protected static function optionAlias($key) |
|
204 | + { |
|
205 | + $alias = false; |
|
206 | + if (isset(self::$curlAlias[$key])) { |
|
207 | + $alias = self::$curlAlias[$key]; |
|
208 | + } elseif ((substr($key, 0, strlen('CURLOPT_')) == 'CURLOPT_') && defined($key)) { |
|
209 | + $alias = $key; |
|
210 | + } |
|
211 | + return $alias; |
|
212 | + } |
|
213 | + |
|
214 | + public function addQuery($data) |
|
215 | + { |
|
216 | + if (!empty($data)) { |
|
217 | + if (is_array($data)) { |
|
218 | + $this->withURIQuery = http_build_query($data); |
|
219 | + } else if (is_string($data)) { |
|
220 | + $this->withURIQuery = $data; |
|
221 | + } else { |
|
222 | + throw new InvalidArgumentException('data must be array or string'); |
|
223 | + } |
|
224 | + } |
|
225 | + return $this; |
|
226 | + } |
|
227 | + |
|
228 | + public function post($uri, $payload = null, array $options = array()) |
|
229 | + { |
|
230 | + return $this->ini(Http::POST, $uri, $payload, $options); |
|
231 | + } |
|
232 | + |
|
233 | + /* no body */ |
|
234 | + |
|
235 | + protected function ini($method, $url, $data , array $options = array()) |
|
236 | + { |
|
237 | + $options = array('url' => $url, 'method' => $method, 'data' => $data) + $options; |
|
238 | + $this->addOptions($options); |
|
239 | + |
|
240 | + return $this; |
|
241 | + } |
|
242 | + |
|
243 | + public function addOptions(array $options = array()) |
|
244 | + { |
|
245 | + $this->options = $options + $this->options; |
|
246 | + $this->uri = $this->options['url']; |
|
247 | + return $this; |
|
248 | + } |
|
249 | + |
|
250 | + function put($uri, $payload = null, array $options = array()) |
|
251 | + { |
|
252 | + return $this->ini(Http::PUT, $uri, $payload, $options); |
|
253 | + } |
|
254 | + |
|
255 | + function patch($uri, $payload = null, array $options = array()) |
|
256 | + { |
|
257 | + return $this->ini(Http::PATCH, $uri, $payload, $options); |
|
258 | + } |
|
259 | + |
|
260 | + public function get($uri, array $options = array()) |
|
261 | + { |
|
262 | + return $this->ini(Http::GET, $uri, array(), $options); |
|
263 | + } |
|
264 | + |
|
265 | + function options($uri, array $options = array()) |
|
266 | + { |
|
267 | + return $this->ini(Http::OPTIONS, $uri, array(), $options); |
|
268 | + } |
|
269 | + |
|
270 | + function head($uri, array $options = array()) |
|
271 | + { |
|
272 | + return $this->ini(Http::HEAD, $uri, array('CURLOPT_NOBODY' => true), $options); |
|
273 | + } |
|
274 | + |
|
275 | + function delete($uri, array $options = array()) |
|
276 | + { |
|
277 | + return $this->ini(Http::DELETE, $uri, array(), $options); |
|
278 | + } |
|
279 | + |
|
280 | + function trace($uri, array $options = array()) |
|
281 | + { |
|
282 | + return $this->ini(Http::TRACE, $uri, array(), $options); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * @return Response |
|
287 | + */ |
|
288 | + public function send() |
|
289 | + { |
|
290 | + if (!$this->hasInitialized) |
|
291 | + $this->applyOptions(); |
|
292 | + $response = $this->makeResponse(); |
|
293 | + if ($this->endCallback) { |
|
294 | + $func = $this->endCallback; |
|
295 | + $func($response); |
|
296 | + } |
|
297 | + return $response; |
|
298 | + } |
|
299 | + |
|
300 | + public function applyOptions() |
|
301 | + { |
|
302 | + $curl = curl_init(); |
|
303 | + $this->curlHandle = $curl; |
|
304 | + $this->prepare(); |
|
305 | + $this->hasInitialized = true; |
|
306 | + return $this; |
|
307 | + } |
|
308 | + |
|
309 | + protected function prepare() |
|
310 | + { |
|
311 | + if (empty($this->options['url'])) { |
|
312 | + throw new InvalidArgumentException('url can not empty'); |
|
313 | + } |
|
314 | + |
|
315 | + if (isset($this->options['data'])) { |
|
316 | + $this->options['data'] = is_array($this->options['data']) ? http_build_query($this->options['data']) : $this->options['data'];//for better compatibility |
|
317 | + } |
|
318 | + if (isset($this->withURIQuery)) { |
|
319 | + $this->options['url'] .= strpos($this->options['url'], '?') === FALSE ? '?' : '&'; |
|
320 | + $this->options['url'] .= $this->withURIQuery; |
|
321 | + } |
|
322 | + if (isset($this->options['callback'])) { |
|
323 | + $this->onEnd($this->options['callback']); |
|
324 | + unset($this->options['callback']); |
|
325 | + } |
|
326 | + //swap ip and host |
|
327 | + if (!empty($this->options['ip'])) { |
|
328 | + $matches = array(); |
|
329 | + preg_match('/\/\/([^\/]+)/', $this->options['url'], $matches); |
|
330 | + $host = $matches[1]; |
|
331 | + if (empty($this->options['headers']) || !is_array($this->options['headers'])) { |
|
332 | + $this->options['headers'] = array('Host: ' . $host); |
|
333 | + } else { |
|
334 | + $this->options['headers'][] = 'Host: ' . $host; |
|
335 | + } |
|
336 | + $this->options['url'] = preg_replace('/\/\/([^\/]+)/', '//' . $this->options['ip'], $this->options['url']); |
|
337 | + unset($this->options['ip']); |
|
338 | + unset($host); |
|
339 | + } |
|
340 | + //process version |
|
341 | + if (!empty($this->options['http_version'])) { |
|
342 | + $version = $this->options['http_version']; |
|
343 | + if ($version == '1.0') { |
|
344 | + $this->options['CURLOPT_HTTP_VERSION'] = CURLOPT_HTTP_VERSION_1_0; |
|
345 | + } elseif ($version == '1.1') { |
|
346 | + $this->options['CURLOPT_HTTP_VERSION'] = CURLOPT_HTTP_VERSION_1_1; |
|
347 | + } |
|
348 | + |
|
349 | + unset($version); |
|
350 | + } |
|
351 | + |
|
352 | + //convert secs to milliseconds |
|
353 | + if (defined('CURLOPT_TIMEOUT_MS')) { |
|
354 | + if (!isset($this->options['timeout_ms'])) { |
|
355 | + $this->options['timeout_ms'] = intval($this->options['timeout'] * 1000); |
|
356 | + } else { |
|
357 | + $this->options['timeout_ms'] = intval($this->options['timeout_ms']); |
|
358 | + } |
|
359 | + } |
|
360 | + |
|
361 | + $cURLOptions = self::filterAndRaw($this->options); |
|
362 | + |
|
363 | + curl_setopt_array($this->curlHandle, $cURLOptions); |
|
364 | + |
|
365 | + return $this; |
|
366 | + } |
|
367 | + |
|
368 | + public function onEnd(callable $callback) |
|
369 | + { |
|
370 | + if (!is_callable($callback)) { |
|
371 | + throw new InvalidArgumentException('callback not is callable :' . print_r($callback, 1)); |
|
372 | + } |
|
373 | + |
|
374 | + $this->endCallback = $callback; |
|
375 | + return $this; |
|
376 | + } |
|
377 | + |
|
378 | + protected static function filterAndRaw(array &$options) |
|
379 | + { |
|
380 | + $opts = array(); |
|
381 | + foreach ($options as $key => $val) { |
|
382 | + $alias = self::optionAlias($key); |
|
383 | + $options[$alias] = $val; |
|
384 | + if ($alias) { |
|
385 | + $opts[constant($alias)] = $val; |
|
386 | + } |
|
387 | + unset($options[$key]); |
|
388 | + } |
|
389 | + return $opts; |
|
390 | + } |
|
391 | + |
|
392 | + public function makeResponse($isMultiCurl = false) |
|
393 | + { |
|
394 | + $body = $isMultiCurl ? curl_multi_getcontent($this->curlHandle) : curl_exec($this->curlHandle); |
|
395 | + $info = curl_getinfo($this->curlHandle); |
|
396 | + $errno = curl_errno($this->curlHandle); |
|
397 | + $error = curl_error($this->curlHandle); |
|
398 | + $response = Response::create($this, $body, $info, $errno, $error); |
|
399 | + if (!is_null(self::$logger)) { |
|
400 | + self::log($response); |
|
401 | + } |
|
402 | + |
|
403 | + return $response; |
|
404 | + } |
|
405 | + |
|
406 | + private static function log(Response $response) |
|
407 | + { |
|
408 | + if ($response->hasErrors()) { |
|
409 | + self::$logger->error($response->request->getURI() . "\t" . $response->error, array( |
|
410 | + 'response' => print_r($response, 1), |
|
411 | + )); |
|
412 | + } |
|
413 | + |
|
414 | + } |
|
415 | 415 | } |
@@ -9,53 +9,53 @@ |
||
9 | 9 | */ |
10 | 10 | class Mime |
11 | 11 | { |
12 | - const JSON = 'application/json'; |
|
13 | - const XML = 'application/xml'; |
|
14 | - const XHTML = 'application/html+xml'; |
|
15 | - const FORM = 'application/x-www-form-urlencoded'; |
|
16 | - const UPLOAD = 'multipart/form-data'; |
|
17 | - const PLAIN = 'text/plain'; |
|
18 | - const JS = 'text/javascript'; |
|
19 | - const HTML = 'text/html'; |
|
20 | - const YAML = 'application/x-yaml'; |
|
21 | - const CSV = 'text/csv'; |
|
12 | + const JSON = 'application/json'; |
|
13 | + const XML = 'application/xml'; |
|
14 | + const XHTML = 'application/html+xml'; |
|
15 | + const FORM = 'application/x-www-form-urlencoded'; |
|
16 | + const UPLOAD = 'multipart/form-data'; |
|
17 | + const PLAIN = 'text/plain'; |
|
18 | + const JS = 'text/javascript'; |
|
19 | + const HTML = 'text/html'; |
|
20 | + const YAML = 'application/x-yaml'; |
|
21 | + const CSV = 'text/csv'; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Map short name for a mime type |
|
25 | - * to a full proper mime type |
|
26 | - */ |
|
27 | - public static $mimes = array( |
|
28 | - 'json' => self::JSON, |
|
29 | - 'xml' => self::XML, |
|
30 | - 'form' => self::FORM, |
|
31 | - 'plain' => self::PLAIN, |
|
32 | - 'text' => self::PLAIN, |
|
33 | - 'upload' => self::UPLOAD, |
|
34 | - 'html' => self::HTML, |
|
35 | - 'xhtml' => self::XHTML, |
|
36 | - 'js' => self::JS, |
|
37 | - 'javascript'=> self::JS, |
|
38 | - 'yaml' => self::YAML, |
|
39 | - 'csv' => self::CSV, |
|
40 | - ); |
|
23 | + /** |
|
24 | + * Map short name for a mime type |
|
25 | + * to a full proper mime type |
|
26 | + */ |
|
27 | + public static $mimes = array( |
|
28 | + 'json' => self::JSON, |
|
29 | + 'xml' => self::XML, |
|
30 | + 'form' => self::FORM, |
|
31 | + 'plain' => self::PLAIN, |
|
32 | + 'text' => self::PLAIN, |
|
33 | + 'upload' => self::UPLOAD, |
|
34 | + 'html' => self::HTML, |
|
35 | + 'xhtml' => self::XHTML, |
|
36 | + 'js' => self::JS, |
|
37 | + 'javascript'=> self::JS, |
|
38 | + 'yaml' => self::YAML, |
|
39 | + 'csv' => self::CSV, |
|
40 | + ); |
|
41 | 41 | |
42 | - /** |
|
43 | - * Get the full Mime Type name from a "short name". |
|
44 | - * Returns the short if no mapping was found. |
|
45 | - * @param string $short_name common name for mime type (e.g. json) |
|
46 | - * @return string full mime type (e.g. application/json) |
|
47 | - */ |
|
48 | - public static function getFullMime($short_name) |
|
49 | - { |
|
50 | - return array_key_exists($short_name, self::$mimes) ? self::$mimes[$short_name] : $short_name; |
|
51 | - } |
|
42 | + /** |
|
43 | + * Get the full Mime Type name from a "short name". |
|
44 | + * Returns the short if no mapping was found. |
|
45 | + * @param string $short_name common name for mime type (e.g. json) |
|
46 | + * @return string full mime type (e.g. application/json) |
|
47 | + */ |
|
48 | + public static function getFullMime($short_name) |
|
49 | + { |
|
50 | + return array_key_exists($short_name, self::$mimes) ? self::$mimes[$short_name] : $short_name; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @param string $short_name |
|
55 | - * @return bool |
|
56 | - */ |
|
57 | - public static function supportsMimeType($short_name) |
|
58 | - { |
|
59 | - return array_key_exists($short_name, self::$mimes); |
|
60 | - } |
|
53 | + /** |
|
54 | + * @param string $short_name |
|
55 | + * @return bool |
|
56 | + */ |
|
57 | + public static function supportsMimeType($short_name) |
|
58 | + { |
|
59 | + return array_key_exists($short_name, self::$mimes); |
|
60 | + } |
|
61 | 61 | } |
@@ -12,26 +12,26 @@ |
||
12 | 12 | namespace MultiHttp; |
13 | 13 | |
14 | 14 | trait RequestTrait { |
15 | - protected $expectContentType = null; |
|
16 | - public function expectsJson(){ |
|
17 | - $this->expectContentType = Mime::JSON; |
|
18 | - } |
|
19 | - public function expectsXml(){ |
|
20 | - $this->expectContentType = Mime::XML; |
|
21 | - } |
|
15 | + protected $expectContentType = null; |
|
16 | + public function expectsJson(){ |
|
17 | + $this->expectContentType = Mime::JSON; |
|
18 | + } |
|
19 | + public function expectsXml(){ |
|
20 | + $this->expectContentType = Mime::XML; |
|
21 | + } |
|
22 | 22 | |
23 | - protected function json(){ |
|
23 | + protected function json(){ |
|
24 | 24 | |
25 | - } |
|
26 | - protected function unJson(){ |
|
25 | + } |
|
26 | + protected function unJson(){ |
|
27 | 27 | |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - protected function xml(){ |
|
30 | + protected function xml(){ |
|
31 | 31 | |
32 | - } |
|
33 | - protected function unXml(){ |
|
32 | + } |
|
33 | + protected function unXml(){ |
|
34 | 34 | |
35 | - } |
|
35 | + } |
|
36 | 36 | } |
37 | 37 |
@@ -13,24 +13,24 @@ |
||
13 | 13 | |
14 | 14 | trait RequestTrait { |
15 | 15 | protected $expectContentType = null; |
16 | - public function expectsJson(){ |
|
16 | + public function expectsJson() { |
|
17 | 17 | $this->expectContentType = Mime::JSON; |
18 | 18 | } |
19 | - public function expectsXml(){ |
|
19 | + public function expectsXml() { |
|
20 | 20 | $this->expectContentType = Mime::XML; |
21 | 21 | } |
22 | 22 | |
23 | - protected function json(){ |
|
23 | + protected function json() { |
|
24 | 24 | |
25 | 25 | } |
26 | - protected function unJson(){ |
|
26 | + protected function unJson() { |
|
27 | 27 | |
28 | 28 | } |
29 | 29 | |
30 | - protected function xml(){ |
|
30 | + protected function xml() { |
|
31 | 31 | |
32 | 32 | } |
33 | - protected function unXml(){ |
|
33 | + protected function unXml() { |
|
34 | 34 | |
35 | 35 | } |
36 | 36 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | 'method' => $method, |
44 | 44 | 'url' => $uri, |
45 | 45 | 'data' => $payload, |
46 | - ) + $options; |
|
46 | + )+$options; |
|
47 | 47 | $this->addOptions(array($options)); |
48 | 48 | return $this; |
49 | 49 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function execute() |
82 | 82 | { |
83 | - $sleepTime = 1000;//microsecond, prevent CPU 100% |
|
83 | + $sleepTime = 1000; //microsecond, prevent CPU 100% |
|
84 | 84 | do { |
85 | 85 | curl_multi_exec(self::$multiHandler, $active); |
86 | 86 | // bug in PHP 5.3.18+ where curl_multi_select can return -1 |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | usleep($sleepTime); |
90 | 90 | } |
91 | 91 | usleep($sleepTime); |
92 | - } while ($active); |
|
92 | + }while ($active); |
|
93 | 93 | $return = array(); |
94 | 94 | foreach (self::$requestPool as $request) { |
95 | 95 | $response = $request->makeResponse(true); |
@@ -15,95 +15,95 @@ |
||
15 | 15 | */ |
16 | 16 | class MultiRequest |
17 | 17 | { |
18 | - protected static $requestPool = array(); |
|
19 | - protected static $multiHandler; |
|
20 | - private static $instance; |
|
18 | + protected static $requestPool = array(); |
|
19 | + protected static $multiHandler; |
|
20 | + private static $instance; |
|
21 | 21 | |
22 | - protected function __construct() |
|
23 | - { |
|
24 | - } |
|
22 | + protected function __construct() |
|
23 | + { |
|
24 | + } |
|
25 | 25 | |
26 | - public static function create() |
|
27 | - { |
|
28 | - if (!(self::$instance instanceof self)) { |
|
29 | - self::$instance = new self; |
|
30 | - } |
|
31 | - self::prepare(); |
|
32 | - return self::$instance; |
|
33 | - } |
|
26 | + public static function create() |
|
27 | + { |
|
28 | + if (!(self::$instance instanceof self)) { |
|
29 | + self::$instance = new self; |
|
30 | + } |
|
31 | + self::prepare(); |
|
32 | + return self::$instance; |
|
33 | + } |
|
34 | 34 | |
35 | - protected static function prepare() |
|
36 | - { |
|
37 | - self::$multiHandler = curl_multi_init(); |
|
38 | - } |
|
35 | + protected static function prepare() |
|
36 | + { |
|
37 | + self::$multiHandler = curl_multi_init(); |
|
38 | + } |
|
39 | 39 | |
40 | - public function add($method, $uri, $payload, array $options = array()) |
|
41 | - { |
|
42 | - $options = array( |
|
43 | - 'method' => $method, |
|
44 | - 'url' => $uri, |
|
45 | - 'data' => $payload, |
|
46 | - ) + $options; |
|
47 | - $this->addOptions(array($options)); |
|
48 | - return $this; |
|
49 | - } |
|
40 | + public function add($method, $uri, $payload, array $options = array()) |
|
41 | + { |
|
42 | + $options = array( |
|
43 | + 'method' => $method, |
|
44 | + 'url' => $uri, |
|
45 | + 'data' => $payload, |
|
46 | + ) + $options; |
|
47 | + $this->addOptions(array($options)); |
|
48 | + return $this; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param array $URLOptions |
|
53 | - * example: array(array('url'=>'http://localhost:9999/','timeout'=>1, 'method'=>'POST', 'data'=>'aa=bb&c=d')) |
|
54 | - * @return $this |
|
55 | - */ |
|
56 | - public function addOptions(array $URLOptions) |
|
57 | - { |
|
58 | - foreach ($URLOptions as $options) { |
|
59 | - $request = Request::create()->addOptions($options)->applyOptions(); |
|
60 | - if (isset($options['callback'])) { |
|
61 | - $request->onEnd($options['callback']); |
|
62 | - } |
|
63 | - $this->import($request); |
|
64 | - } |
|
65 | - return $this; |
|
66 | - } |
|
51 | + /** |
|
52 | + * @param array $URLOptions |
|
53 | + * example: array(array('url'=>'http://localhost:9999/','timeout'=>1, 'method'=>'POST', 'data'=>'aa=bb&c=d')) |
|
54 | + * @return $this |
|
55 | + */ |
|
56 | + public function addOptions(array $URLOptions) |
|
57 | + { |
|
58 | + foreach ($URLOptions as $options) { |
|
59 | + $request = Request::create()->addOptions($options)->applyOptions(); |
|
60 | + if (isset($options['callback'])) { |
|
61 | + $request->onEnd($options['callback']); |
|
62 | + } |
|
63 | + $this->import($request); |
|
64 | + } |
|
65 | + return $this; |
|
66 | + } |
|
67 | 67 | |
68 | - public function import(Request $request) |
|
69 | - { |
|
70 | - if (!is_resource($request->curlHandle)) { |
|
71 | - throw new InvalidArgumentException('Request curl handle is not initialized'); |
|
72 | - } |
|
73 | - curl_multi_add_handle(self::$multiHandler, $request->curlHandle); |
|
74 | - self::$requestPool[] = $request; |
|
75 | - return $this; |
|
76 | - } |
|
68 | + public function import(Request $request) |
|
69 | + { |
|
70 | + if (!is_resource($request->curlHandle)) { |
|
71 | + throw new InvalidArgumentException('Request curl handle is not initialized'); |
|
72 | + } |
|
73 | + curl_multi_add_handle(self::$multiHandler, $request->curlHandle); |
|
74 | + self::$requestPool[] = $request; |
|
75 | + return $this; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * @return array(Response) |
|
80 | - */ |
|
81 | - public function execute() |
|
82 | - { |
|
83 | - $sleepTime = 1000;//microsecond, prevent CPU 100% |
|
84 | - do { |
|
85 | - curl_multi_exec(self::$multiHandler, $active); |
|
86 | - // bug in PHP 5.3.18+ where curl_multi_select can return -1 |
|
87 | - // https://bugs.php.net/bug.php?id=63411 |
|
88 | - if (curl_multi_select(self::$multiHandler) == -1) { |
|
89 | - usleep($sleepTime); |
|
90 | - } |
|
91 | - usleep($sleepTime); |
|
92 | - } while ($active); |
|
93 | - $return = array(); |
|
94 | - foreach (self::$requestPool as $request) { |
|
95 | - $response = $request->makeResponse(true); |
|
96 | - $func = $response->request->endCallback(); |
|
97 | - if (isset($func)) { |
|
98 | - $func($response); |
|
99 | - } |
|
100 | - $return[] = $response; |
|
101 | - curl_multi_remove_handle(self::$multiHandler, $request->curlHandle); |
|
102 | - curl_close($request->curlHandle); |
|
103 | - } |
|
104 | - curl_multi_close(self::$multiHandler); |
|
105 | - self::$requestPool = array(); |
|
106 | - return $return; |
|
107 | - } |
|
78 | + /** |
|
79 | + * @return array(Response) |
|
80 | + */ |
|
81 | + public function execute() |
|
82 | + { |
|
83 | + $sleepTime = 1000;//microsecond, prevent CPU 100% |
|
84 | + do { |
|
85 | + curl_multi_exec(self::$multiHandler, $active); |
|
86 | + // bug in PHP 5.3.18+ where curl_multi_select can return -1 |
|
87 | + // https://bugs.php.net/bug.php?id=63411 |
|
88 | + if (curl_multi_select(self::$multiHandler) == -1) { |
|
89 | + usleep($sleepTime); |
|
90 | + } |
|
91 | + usleep($sleepTime); |
|
92 | + } while ($active); |
|
93 | + $return = array(); |
|
94 | + foreach (self::$requestPool as $request) { |
|
95 | + $response = $request->makeResponse(true); |
|
96 | + $func = $response->request->endCallback(); |
|
97 | + if (isset($func)) { |
|
98 | + $func($response); |
|
99 | + } |
|
100 | + $return[] = $response; |
|
101 | + curl_multi_remove_handle(self::$multiHandler, $request->curlHandle); |
|
102 | + curl_close($request->curlHandle); |
|
103 | + } |
|
104 | + curl_multi_close(self::$multiHandler); |
|
105 | + self::$requestPool = array(); |
|
106 | + return $return; |
|
107 | + } |
|
108 | 108 | |
109 | 109 | } |
@@ -19,70 +19,70 @@ |
||
19 | 19 | */ |
20 | 20 | trait JsonTrait |
21 | 21 | { |
22 | - /** |
|
23 | - * @return Request |
|
24 | - */ |
|
25 | - public function expectsJson() |
|
26 | - { |
|
27 | - return $this->expectsMime('json'); |
|
28 | - } |
|
22 | + /** |
|
23 | + * @return Request |
|
24 | + */ |
|
25 | + public function expectsJson() |
|
26 | + { |
|
27 | + return $this->expectsMime('json'); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * @return Request |
|
32 | - */ |
|
33 | - public function sendJson() |
|
34 | - { |
|
35 | - return $this->sendMime('json'); |
|
36 | - } |
|
30 | + /** |
|
31 | + * @return Request |
|
32 | + */ |
|
33 | + public function sendJson() |
|
34 | + { |
|
35 | + return $this->sendMime('json'); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param $body |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function json($body) |
|
43 | - { |
|
44 | - return json_encode($body, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
|
45 | - } |
|
38 | + /** |
|
39 | + * @param $body |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function json($body) |
|
43 | + { |
|
44 | + return json_encode($body, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @param $body |
|
49 | - * @return mixed |
|
50 | - */ |
|
51 | - public function unJson($body) |
|
52 | - { |
|
53 | - $parsed = json_decode($body, true); |
|
54 | - if(json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '. self::jsonLastErrorMsg() . ', raw body: ' .$body ); |
|
55 | - return $parsed; |
|
56 | - } |
|
47 | + /** |
|
48 | + * @param $body |
|
49 | + * @return mixed |
|
50 | + */ |
|
51 | + public function unJson($body) |
|
52 | + { |
|
53 | + $parsed = json_decode($body, true); |
|
54 | + if(json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '. self::jsonLastErrorMsg() . ', raw body: ' .$body ); |
|
55 | + return $parsed; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - private static function jsonLastErrorMsg(){ |
|
62 | - if(function_exists('json_last_error_msg')) return json_last_error_msg(); |
|
63 | - switch (json_last_error()) { |
|
64 | - case JSON_ERROR_NONE: |
|
65 | - return ' - No errors'; |
|
66 | - break; |
|
67 | - case JSON_ERROR_DEPTH: |
|
68 | - return ' - Maximum stack depth exceeded'; |
|
69 | - break; |
|
70 | - case JSON_ERROR_STATE_MISMATCH: |
|
71 | - return ' - Underflow or the modes mismatch'; |
|
72 | - break; |
|
73 | - case JSON_ERROR_CTRL_CHAR: |
|
74 | - return ' - Unexpected control character found'; |
|
75 | - break; |
|
76 | - case JSON_ERROR_SYNTAX: |
|
77 | - return ' - Syntax error, malformed JSON'; |
|
78 | - break; |
|
79 | - case JSON_ERROR_UTF8: |
|
80 | - return ' - Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
81 | - break; |
|
82 | - default: |
|
83 | - return ' - Unknown error'; |
|
84 | - break; |
|
85 | - } |
|
86 | - } |
|
58 | + /** |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + private static function jsonLastErrorMsg(){ |
|
62 | + if(function_exists('json_last_error_msg')) return json_last_error_msg(); |
|
63 | + switch (json_last_error()) { |
|
64 | + case JSON_ERROR_NONE: |
|
65 | + return ' - No errors'; |
|
66 | + break; |
|
67 | + case JSON_ERROR_DEPTH: |
|
68 | + return ' - Maximum stack depth exceeded'; |
|
69 | + break; |
|
70 | + case JSON_ERROR_STATE_MISMATCH: |
|
71 | + return ' - Underflow or the modes mismatch'; |
|
72 | + break; |
|
73 | + case JSON_ERROR_CTRL_CHAR: |
|
74 | + return ' - Unexpected control character found'; |
|
75 | + break; |
|
76 | + case JSON_ERROR_SYNTAX: |
|
77 | + return ' - Syntax error, malformed JSON'; |
|
78 | + break; |
|
79 | + case JSON_ERROR_UTF8: |
|
80 | + return ' - Malformed UTF-8 characters, possibly incorrectly encoded'; |
|
81 | + break; |
|
82 | + default: |
|
83 | + return ' - Unknown error'; |
|
84 | + break; |
|
85 | + } |
|
86 | + } |
|
87 | 87 | } |
88 | 88 |
@@ -51,15 +51,15 @@ |
||
51 | 51 | public function unJson($body) |
52 | 52 | { |
53 | 53 | $parsed = json_decode($body, true); |
54 | - if(json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '. self::jsonLastErrorMsg() . ', raw body: ' .$body ); |
|
54 | + if (json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '.self::jsonLastErrorMsg().', raw body: '.$body); |
|
55 | 55 | return $parsed; |
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * @return string |
60 | 60 | */ |
61 | - private static function jsonLastErrorMsg(){ |
|
62 | - if(function_exists('json_last_error_msg')) return json_last_error_msg(); |
|
61 | + private static function jsonLastErrorMsg() { |
|
62 | + if (function_exists('json_last_error_msg')) return json_last_error_msg(); |
|
63 | 63 | switch (json_last_error()) { |
64 | 64 | case JSON_ERROR_NONE: |
65 | 65 | return ' - No errors'; |
@@ -51,7 +51,9 @@ discard block |
||
51 | 51 | public function unJson($body) |
52 | 52 | { |
53 | 53 | $parsed = json_decode($body, true); |
54 | - if(json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '. self::jsonLastErrorMsg() . ', raw body: ' .$body ); |
|
54 | + if(json_last_error() !== JSON_ERROR_NONE) { |
|
55 | + throw new UnexpectedResponseException('parsing json occurs error: '. self::jsonLastErrorMsg() . ', raw body: ' .$body ); |
|
56 | + } |
|
55 | 57 | return $parsed; |
56 | 58 | } |
57 | 59 | |
@@ -59,7 +61,9 @@ discard block |
||
59 | 61 | * @return string |
60 | 62 | */ |
61 | 63 | private static function jsonLastErrorMsg(){ |
62 | - if(function_exists('json_last_error_msg')) return json_last_error_msg(); |
|
64 | + if(function_exists('json_last_error_msg')) { |
|
65 | + return json_last_error_msg(); |
|
66 | + } |
|
63 | 67 | switch (json_last_error()) { |
64 | 68 | case JSON_ERROR_NONE: |
65 | 69 | return ' - No errors'; |