@@ -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 |
@@ -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 | } |
@@ -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'; |
@@ -14,12 +14,12 @@ |
||
14 | 14 | |
15 | 15 | class Helper |
16 | 16 | { |
17 | - public static function retry($maxTimes = 2, callable $task, $sleep = 0){ |
|
18 | - $tryTimes = 0; |
|
19 | - while(++$tryTimes <= $maxTimes){ |
|
20 | - if($task()) break; |
|
21 | - else usleep(abs($sleep) * 1000000); |
|
22 | - } |
|
23 | - return $tryTimes; |
|
24 | - } |
|
17 | + public static function retry($maxTimes = 2, callable $task, $sleep = 0){ |
|
18 | + $tryTimes = 0; |
|
19 | + while(++$tryTimes <= $maxTimes){ |
|
20 | + if($task()) break; |
|
21 | + else usleep(abs($sleep) * 1000000); |
|
22 | + } |
|
23 | + return $tryTimes; |
|
24 | + } |
|
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -14,11 +14,11 @@ |
||
14 | 14 | |
15 | 15 | class Helper |
16 | 16 | { |
17 | - public static function retry($maxTimes = 2, callable $task, $sleep = 0){ |
|
17 | + public static function retry($maxTimes = 2, callable $task, $sleep = 0) { |
|
18 | 18 | $tryTimes = 0; |
19 | - while(++$tryTimes <= $maxTimes){ |
|
20 | - if($task()) break; |
|
21 | - else usleep(abs($sleep) * 1000000); |
|
19 | + while (++$tryTimes <= $maxTimes) { |
|
20 | + if ($task()) break; |
|
21 | + else usleep(abs($sleep)*1000000); |
|
22 | 22 | } |
23 | 23 | return $tryTimes; |
24 | 24 | } |
@@ -17,8 +17,11 @@ |
||
17 | 17 | public static function retry($maxTimes = 2, callable $task, $sleep = 0){ |
18 | 18 | $tryTimes = 0; |
19 | 19 | while(++$tryTimes <= $maxTimes){ |
20 | - if($task()) break; |
|
21 | - else usleep(abs($sleep) * 1000000); |
|
20 | + if($task()) { |
|
21 | + break; |
|
22 | + } else { |
|
23 | + usleep(abs($sleep) * 1000000); |
|
24 | + } |
|
22 | 25 | } |
23 | 26 | return $tryTimes; |
24 | 27 | } |
@@ -121,7 +121,4 @@ |
||
121 | 121 | curl_multi_close(self::$multiHandler); |
122 | 122 | self::$requestPool = array(); |
123 | 123 | self::$multiHandler = null; |
124 | - return $return; |
|
125 | - } |
|
126 | - |
|
127 | -} |
|
124 | + return $return |
|
128 | 125 | \ No newline at end of file |
@@ -121,7 +121,4 @@ |
||
121 | 121 | curl_multi_close(self::$multiHandler); |
122 | 122 | self::$requestPool = array(); |
123 | 123 | self::$multiHandler = null; |
124 | - return $return; |
|
125 | - } |
|
126 | - |
|
127 | -} |
|
124 | + return $return |
|
128 | 125 | \ No newline at end of file |
@@ -121,7 +121,4 @@ |
||
121 | 121 | curl_multi_close(self::$multiHandler); |
122 | 122 | self::$requestPool = array(); |
123 | 123 | self::$multiHandler = null; |
124 | - return $return; |
|
125 | - } |
|
126 | - |
|
127 | -} |
|
124 | + return $return |
|
128 | 125 | \ No newline at end of file |
@@ -121,7 +121,4 @@ |
||
121 | 121 | curl_multi_close(self::$multiHandler); |
122 | 122 | self::$requestPool = array(); |
123 | 123 | self::$multiHandler = null; |
124 | - return $return; |
|
125 | - } |
|
126 | - |
|
127 | -} |
|
124 | + return $return |
|
128 | 125 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class MultiRequest |
17 | 17 | { |
18 | -<<<<<<< HEAD |
|
18 | +<< << <<< HEAD |
|
19 | 19 | ======= |
20 | 20 | /** |
21 | 21 | * @var [Response] |
@@ -121,7 +121,4 @@ discard block |
||
121 | 121 | curl_multi_close(self::$multiHandler); |
122 | 122 | self::$requestPool = array(); |
123 | 123 | self::$multiHandler = null; |
124 | - return $return; |
|
125 | - } |
|
126 | - |
|
127 | -} |
|
124 | + return $return |
|
128 | 125 | \ No newline at end of file |
@@ -121,7 +121,4 @@ |
||
121 | 121 | curl_multi_close(self::$multiHandler); |
122 | 122 | self::$requestPool = array(); |
123 | 123 | self::$multiHandler = null; |
124 | - return $return; |
|
125 | - } |
|
126 | - |
|
127 | -} |
|
124 | + return $return |
|
128 | 125 | \ No newline at end of file |
@@ -121,7 +121,4 @@ |
||
121 | 121 | curl_multi_close(self::$multiHandler); |
122 | 122 | self::$requestPool = array(); |
123 | 123 | self::$multiHandler = null; |
124 | - return $return; |
|
125 | - } |
|
126 | - |
|
127 | -} |
|
124 | + return $return |
|
128 | 125 | \ No newline at end of file |