@@ -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 |
@@ -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 |
@@ -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 | |
@@ -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 | } |
@@ -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'; |
@@ -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 | } |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | * @param $method |
| 52 | 52 | * @return bool |
| 53 | 53 | */ |
| 54 | - public static function hasBody($method){ |
|
| 54 | + public static function hasBody($method) { |
|
| 55 | 55 | return in_array($method, array(self::POST, self::PUT, self::PATCH, self::OPTIONS)); |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | 58 | \ 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 |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | class Request extends Http |
| 17 | 17 | { |
| 18 | -<<<<<<< HEAD |
|
| 18 | +<< << <<< HEAD |
|
| 19 | 19 | const MAX_REDIRECTS_DEFAULT = 10; |
| 20 | 20 | ======= |
| 21 | 21 | /** |
@@ -683,9 +683,4 @@ discard block |
||
| 683 | 683 | { |
| 684 | 684 | if ($response->hasErrors()) { |
| 685 | 685 | self::$logger->error($response->request->getURI() . "\t" . $response->error, array( |
| 686 | - 'response' => print_r($response, 1), |
|
| 687 | - )); |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - } |
|
| 691 | -} |
|
| 686 | + 'response' => print_r($response |
|
| 692 | 687 | \ No newline at end of file |