@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @param array $options |
| 47 | 47 | * @return $this |
| 48 | 48 | */ |
| 49 | - public function setDefaults(array $options = array()){ |
|
| 49 | + public function setDefaults(array $options = array()) { |
|
| 50 | 50 | $this->defaultOptions = $options; |
| 51 | 51 | return $this; |
| 52 | 52 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | 'method' => $method, |
| 69 | 69 | 'url' => $uri, |
| 70 | 70 | 'data' => $payload, |
| 71 | - ) + $options; |
|
| 71 | + )+$options; |
|
| 72 | 72 | $this->addOptions(array($options)); |
| 73 | 73 | return $this; |
| 74 | 74 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | public function addOptions(array $URLOptions) |
| 82 | 82 | { |
| 83 | 83 | foreach ($URLOptions as $options) { |
| 84 | - $options = $options + $this->defaultOptions; |
|
| 84 | + $options = $options+$this->defaultOptions; |
|
| 85 | 85 | $request = Request::create()->addOptions($options)->applyOptions(); |
| 86 | 86 | if (isset($options['callback'])) { |
| 87 | 87 | $request->onEnd($options['callback']); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | public function sendAll() |
| 112 | 112 | { |
| 113 | - $sleepTime = 1000;//microsecond, prevent CPU 100% |
|
| 113 | + $sleepTime = 1000; //microsecond, prevent CPU 100% |
|
| 114 | 114 | do { |
| 115 | 115 | curl_multi_exec(self::$multiHandler, $active); |
| 116 | 116 | // bug in PHP 5.3.18+ where curl_multi_select can return -1 |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | usleep($sleepTime); |
| 120 | 120 | } |
| 121 | 121 | usleep($sleepTime); |
| 122 | - } while ($active); |
|
| 122 | + }while ($active); |
|
| 123 | 123 | $return = array(); |
| 124 | 124 | foreach (self::$requestPool as $request) { |
| 125 | 125 | $return[] = $request->send(true); |
@@ -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 | } |
@@ -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 |
@@ -97,10 +97,10 @@ |
||
| 97 | 97 | public function unserializeBody() |
| 98 | 98 | { |
| 99 | 99 | if (isset($this->request->expectsMime)) { |
| 100 | - if (Mime::getFullMime($this->request->expectsMime) !== $this->contentType) throw new UnexpectedResponseException('expected mime can not be matched, real mime:'. $this->contentType. ', expected mime:'. Mime::getFullMime($this->request->expectsMime)); |
|
| 100 | + if (Mime::getFullMime($this->request->expectsMime) !== $this->contentType) throw new UnexpectedResponseException('expected mime can not be matched, real mime:'.$this->contentType.', expected mime:'.Mime::getFullMime($this->request->expectsMime)); |
|
| 101 | 101 | $clz = "\MultiHttp\\Handler\\".ucfirst($this->request->expectsMime); |
| 102 | 102 | $inst = new $clz; |
| 103 | - if (!($inst instanceof Handler\IHandler)) throw new InvalidOperationException($clz . ' is not implement of IHandler'); |
|
| 103 | + if (!($inst instanceof Handler\IHandler)) throw new InvalidOperationException($clz.' is not implement of IHandler'); |
|
| 104 | 104 | $this->body = $inst->decode($this->body); |
| 105 | 105 | } |
| 106 | 106 | } |
@@ -73,10 +73,11 @@ discard block |
||
| 73 | 73 | $headers = explode(PHP_EOL, $headers); |
| 74 | 74 | array_shift($headers); // HTTP HEADER |
| 75 | 75 | foreach ($headers as $h) { |
| 76 | - if (false !== strpos($h, ':')) |
|
| 77 | - list($k, $v) = explode(':', $h, 2); |
|
| 78 | - else |
|
| 79 | - list($k, $v) = array($h, ''); |
|
| 76 | + if (false !== strpos($h, ':')) { |
|
| 77 | + list($k, $v) = explode(':', $h, 2); |
|
| 78 | + } else { |
|
| 79 | + list($k, $v) = array($h, ''); |
|
| 80 | + } |
|
| 80 | 81 | |
| 81 | 82 | $this->header[trim($k)] = trim($v); |
| 82 | 83 | } |
@@ -97,10 +98,14 @@ discard block |
||
| 97 | 98 | public function unserializeBody() |
| 98 | 99 | { |
| 99 | 100 | if (isset($this->request->expectsMime)) { |
| 100 | - if (Mime::getFullMime($this->request->expectsMime) !== $this->contentType) throw new UnexpectedResponseException('expected mime can not be matched, real mime:'. $this->contentType. ', expected mime:'. Mime::getFullMime($this->request->expectsMime)); |
|
| 101 | + if (Mime::getFullMime($this->request->expectsMime) !== $this->contentType) { |
|
| 102 | + throw new UnexpectedResponseException('expected mime can not be matched, real mime:'. $this->contentType. ', expected mime:'. Mime::getFullMime($this->request->expectsMime)); |
|
| 103 | + } |
|
| 101 | 104 | $clz = "\MultiHttp\\Handler\\".ucfirst($this->request->expectsMime); |
| 102 | 105 | $inst = new $clz; |
| 103 | - if (!($inst instanceof Handler\IHandler)) throw new InvalidOperationException($clz . ' is not implement of IHandler'); |
|
| 106 | + if (!($inst instanceof Handler\IHandler)) { |
|
| 107 | + throw new InvalidOperationException($clz . ' is not implement of IHandler'); |
|
| 108 | + } |
|
| 104 | 109 | $this->body = $inst->decode($this->body); |
| 105 | 110 | } |
| 106 | 111 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | protected static $curlAlias = array( |
| 29 | 29 | 'url' => 'CURLOPT_URL', |
| 30 | 30 | 'uri' => 'CURLOPT_URL', |
| 31 | - 'debug' => 'CURLOPT_VERBOSE',//for debug verbose |
|
| 31 | + 'debug' => 'CURLOPT_VERBOSE', //for debug verbose |
|
| 32 | 32 | 'method' => 'CURLOPT_CUSTOMREQUEST', |
| 33 | 33 | 'data' => 'CURLOPT_POSTFIELDS', // array or string , file begin with '@' |
| 34 | 34 | 'ua' => 'CURLOPT_USERAGENT', |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | 'timeout_ms' => 'CURLOPT_TIMEOUT_MS', // milliseconds, libcurl version > 7.36.0 , |
| 47 | 47 | 'expects_mime' => null, //expected mime |
| 48 | 48 | 'send_mime' => null, //send mime |
| 49 | - 'ip' => null,//specify ip to send request |
|
| 50 | - 'callback' => null,//callback on end |
|
| 49 | + 'ip' => null, //specify ip to send request |
|
| 50 | + 'callback' => null, //callback on end |
|
| 51 | 51 | |
| 52 | 52 | ); |
| 53 | 53 | protected static $loggerHandler; |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | $options = array( |
| 79 | 79 | 'CURLOPT_MAXREDIRS' => 10, |
| 80 | - 'CURLOPT_SSL_VERIFYPEER' => false,//for https |
|
| 81 | - 'CURLOPT_SSL_VERIFYHOST' => 0,//for https |
|
| 82 | - 'CURLOPT_IPRESOLVE' => CURL_IPRESOLVE_V4,//ipv4 first |
|
| 83 | - 'CURLOPT_SAFE_UPLOAD' => false,// compatible with PHP 5.6.0 |
|
| 80 | + 'CURLOPT_SSL_VERIFYPEER' => false, //for https |
|
| 81 | + 'CURLOPT_SSL_VERIFYHOST' => 0, //for https |
|
| 82 | + 'CURLOPT_IPRESOLVE' => CURL_IPRESOLVE_V4, //ipv4 first |
|
| 83 | + 'CURLOPT_SAFE_UPLOAD' => false, // compatible with PHP 5.6.0 |
|
| 84 | 84 | 'CURLOPT_USERAGENT' => 'Mozilla/5.0 (compatible;)', |
| 85 | 85 | 'header' => true, |
| 86 | 86 | 'method' => self::GET, |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | 'follow_location' => true, |
| 90 | 90 | 'timeout' => 0, |
| 91 | 91 | // 'ip' => null, //host, in string, .e.g: 172.16.1.1:888 |
| 92 | - 'retry_times' => 1,//redo task when failed |
|
| 93 | - 'retry_duration' => 0,//in seconds |
|
| 94 | - 'send_mime' => 'form',//in seconds |
|
| 92 | + 'retry_times' => 1, //redo task when failed |
|
| 93 | + 'retry_duration' => 0, //in seconds |
|
| 94 | + 'send_mime' => 'form', //in seconds |
|
| 95 | 95 | ); |
| 96 | 96 | |
| 97 | 97 | |
@@ -155,15 +155,15 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | private static function combineUrl($parsedComponents) |
| 157 | 157 | { |
| 158 | - $scheme = isset($parsedComponents['scheme']) ? $parsedComponents['scheme'] . '://' : ''; |
|
| 158 | + $scheme = isset($parsedComponents['scheme']) ? $parsedComponents['scheme'].'://' : ''; |
|
| 159 | 159 | $host = isset($parsedComponents['host']) ? $parsedComponents['host'] : ''; |
| 160 | - $port = isset($parsedComponents['port']) ? ':' . $parsedComponents['port'] : ''; |
|
| 160 | + $port = isset($parsedComponents['port']) ? ':'.$parsedComponents['port'] : ''; |
|
| 161 | 161 | $user = isset($parsedComponents['user']) ? $parsedComponents['user'] : ''; |
| 162 | - $pass = isset($parsedComponents['pass']) ? ':' . $parsedComponents['pass'] : ''; |
|
| 162 | + $pass = isset($parsedComponents['pass']) ? ':'.$parsedComponents['pass'] : ''; |
|
| 163 | 163 | $pass = ($user || $pass) ? "$pass@" : ''; |
| 164 | 164 | $path = isset($parsedComponents['path']) ? $parsedComponents['path'] : ''; |
| 165 | - $query = isset($parsedComponents['query']) ? '?' . $parsedComponents['query'] : ''; |
|
| 166 | - $fragment = isset($parsedComponents['fragment']) ? '#' . $parsedComponents['fragment'] : ''; |
|
| 165 | + $query = isset($parsedComponents['query']) ? '?'.$parsedComponents['query'] : ''; |
|
| 166 | + $fragment = isset($parsedComponents['fragment']) ? '#'.$parsedComponents['fragment'] : ''; |
|
| 167 | 167 | return "$scheme$user$pass$host$port$path$query$fragment"; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | public function addHeader($headerName, $value) |
| 199 | 199 | { |
| 200 | - $this->options['headers'][] = $headerName . ': ' . $value; |
|
| 200 | + $this->options['headers'][] = $headerName.': '.$value; |
|
| 201 | 201 | return $this; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | public function getIni($field = null) |
| 248 | 248 | { |
| 249 | - if(!$field) return $this->options; |
|
| 249 | + if (!$field) return $this->options; |
|
| 250 | 250 | $full = self::fullOption($field); |
| 251 | 251 | return isset($this->options[$full]) ? $this->options[$full] : false; |
| 252 | 252 | } |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | */ |
| 329 | 329 | protected function ini($method, $url, $data, array $options = array()) |
| 330 | 330 | { |
| 331 | - $options = array('url' => $url, 'method' => $method, 'data' => $data) + $options; |
|
| 331 | + $options = array('url' => $url, 'method' => $method, 'data' => $data)+$options; |
|
| 332 | 332 | $this->addOptions($options); |
| 333 | 333 | |
| 334 | 334 | return $this; |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | */ |
| 341 | 341 | public function addOptions(array $options = array()) |
| 342 | 342 | { |
| 343 | - $this->options = $options + $this->options; |
|
| 343 | + $this->options = $options+$this->options; |
|
| 344 | 344 | $this->uri = $this->options['url']; |
| 345 | 345 | return $this; |
| 346 | 346 | } |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | $response = $this->makeResponse($isMultiCurl); |
| 443 | 443 | $response->parse(); |
| 444 | 444 | } catch (\Exception $e) { |
| 445 | - if(!isset($response)) $response = Response::create($this, null, null, null, null); |
|
| 445 | + if (!isset($response)) $response = Response::create($this, null, null, null, null); |
|
| 446 | 446 | $response->error = $e->getMessage(); |
| 447 | 447 | $response->errorCode = 999; |
| 448 | 448 | } |
@@ -487,11 +487,11 @@ discard block |
||
| 487 | 487 | $this->retryDuration = abs($this->options['retry_duration']); |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - if(isset($this->options['expects_mime'])){ |
|
| 490 | + if (isset($this->options['expects_mime'])) { |
|
| 491 | 491 | $this->expectsMime = $this->options['expects_mime']; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | - if(isset($this->options['send_mime'])){ |
|
| 494 | + if (isset($this->options['send_mime'])) { |
|
| 495 | 495 | $this->sendMime = $this->options['send_mime']; |
| 496 | 496 | } |
| 497 | 497 | |
@@ -506,11 +506,11 @@ discard block |
||
| 506 | 506 | $this->serializeBody(); |
| 507 | 507 | |
| 508 | 508 | //try fix url |
| 509 | - if (strpos($this->options['url'], '://') === FALSE) $this->options['url'] = 'http://' . $this->options['url']; |
|
| 509 | + if (strpos($this->options['url'], '://') === FALSE) $this->options['url'] = 'http://'.$this->options['url']; |
|
| 510 | 510 | $components = parse_url($this->options['url']); |
| 511 | - if(FALSE === $components) throw new InvalidArgumentException('formatting url occurs error: '. $this->options['url']); |
|
| 512 | - if($this->withURIQuery){ |
|
| 513 | - if(isset($components['query'])) $components['query'] .= '&'. trim($this->withURIQuery); |
|
| 511 | + if (FALSE === $components) throw new InvalidArgumentException('formatting url occurs error: '.$this->options['url']); |
|
| 512 | + if ($this->withURIQuery) { |
|
| 513 | + if (isset($components['query'])) $components['query'] .= '&'.trim($this->withURIQuery); |
|
| 514 | 514 | else $components['query'] = trim($this->withURIQuery); |
| 515 | 515 | } |
| 516 | 516 | $this->options['url'] = self::combineUrl($components); |
@@ -524,11 +524,11 @@ discard block |
||
| 524 | 524 | preg_match('/\/\/([^\/]+)/', $this->options['url'], $matches); |
| 525 | 525 | $host = $matches[1]; |
| 526 | 526 | if (empty($this->options['headers']) || !is_array($this->options['headers'])) { |
| 527 | - $this->options['headers'] = array('Host: ' . $host); |
|
| 527 | + $this->options['headers'] = array('Host: '.$host); |
|
| 528 | 528 | } else { |
| 529 | - $this->options['headers'][] = 'Host: ' . $host; |
|
| 529 | + $this->options['headers'][] = 'Host: '.$host; |
|
| 530 | 530 | } |
| 531 | - $this->options['url'] = str_replace("//{$host}", '//' . $this->options['ip'], $this->options['url']); |
|
| 531 | + $this->options['url'] = str_replace("//{$host}", '//'.$this->options['ip'], $this->options['url']); |
|
| 532 | 532 | unset($host); |
| 533 | 533 | } |
| 534 | 534 | //process version |
@@ -546,14 +546,14 @@ discard block |
||
| 546 | 546 | //convert secs to milliseconds |
| 547 | 547 | if (defined('CURLOPT_TIMEOUT_MS')) { |
| 548 | 548 | if (!isset($this->options['timeout_ms'])) { |
| 549 | - $this->options['timeout_ms'] = intval($this->options['timeout'] * 1000); |
|
| 549 | + $this->options['timeout_ms'] = intval($this->options['timeout']*1000); |
|
| 550 | 550 | } else { |
| 551 | 551 | $this->options['timeout_ms'] = intval($this->options['timeout_ms']); |
| 552 | 552 | } |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | $cURLOptions = self::filterAndRaw($this->options); |
| 556 | - if(isset($this->body))$cURLOptions[CURLOPT_POSTFIELDS] = $this->body;//use serialized body not raw data |
|
| 556 | + if (isset($this->body))$cURLOptions[CURLOPT_POSTFIELDS] = $this->body; //use serialized body not raw data |
|
| 557 | 557 | curl_setopt_array($this->curlHandle, $cURLOptions); |
| 558 | 558 | |
| 559 | 559 | return $this; |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | $this->options[CURLOPT_POST] = true; |
| 567 | 567 | $clz = '\\MultiHttp\\Handler\\'.ucfirst($this->sendMime); |
| 568 | 568 | $inst = new $clz; |
| 569 | - if (!($inst instanceof Handler\IHandler)) throw new InvalidOperationException($clz . ' is not implement of IHandler'); |
|
| 569 | + if (!($inst instanceof Handler\IHandler)) throw new InvalidOperationException($clz.' is not implement of IHandler'); |
|
| 570 | 570 | $this->body = $inst->encode($this->options['data']); |
| 571 | 571 | } |
| 572 | 572 | } |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | public function onEnd(callable $callback) |
| 579 | 579 | { |
| 580 | 580 | if (!is_callable($callback)) { |
| 581 | - throw new InvalidArgumentException('callback not is callable :' . print_r($callback, 1)); |
|
| 581 | + throw new InvalidArgumentException('callback not is callable :'.print_r($callback, 1)); |
|
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | $this->endCallback = $callback; |
@@ -246,7 +246,9 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | public function getIni($field = null) |
| 248 | 248 | { |
| 249 | - if(!$field) return $this->options; |
|
| 249 | + if(!$field) { |
|
| 250 | + return $this->options; |
|
| 251 | + } |
|
| 250 | 252 | $full = self::fullOption($field); |
| 251 | 253 | return isset($this->options[$full]) ? $this->options[$full] : false; |
| 252 | 254 | } |
@@ -437,12 +439,15 @@ discard block |
||
| 437 | 439 | public function send($isMultiCurl = false) |
| 438 | 440 | { |
| 439 | 441 | try { |
| 440 | - if (!$this->hasInitialized) |
|
| 441 | - $this->applyOptions(); |
|
| 442 | + if (!$this->hasInitialized) { |
|
| 443 | + $this->applyOptions(); |
|
| 444 | + } |
|
| 442 | 445 | $response = $this->makeResponse($isMultiCurl); |
| 443 | 446 | $response->parse(); |
| 444 | 447 | } catch (\Exception $e) { |
| 445 | - if(!isset($response)) $response = Response::create($this, null, null, null, null); |
|
| 448 | + if(!isset($response)) { |
|
| 449 | + $response = Response::create($this, null, null, null, null); |
|
| 450 | + } |
|
| 446 | 451 | $response->error = $e->getMessage(); |
| 447 | 452 | $response->errorCode = 999; |
| 448 | 453 | } |
@@ -506,12 +511,19 @@ discard block |
||
| 506 | 511 | $this->serializeBody(); |
| 507 | 512 | |
| 508 | 513 | //try fix url |
| 509 | - if (strpos($this->options['url'], '://') === FALSE) $this->options['url'] = 'http://' . $this->options['url']; |
|
| 514 | + if (strpos($this->options['url'], '://') === FALSE) { |
|
| 515 | + $this->options['url'] = 'http://' . $this->options['url']; |
|
| 516 | + } |
|
| 510 | 517 | $components = parse_url($this->options['url']); |
| 511 | - if(FALSE === $components) throw new InvalidArgumentException('formatting url occurs error: '. $this->options['url']); |
|
| 518 | + if(FALSE === $components) { |
|
| 519 | + throw new InvalidArgumentException('formatting url occurs error: '. $this->options['url']); |
|
| 520 | + } |
|
| 512 | 521 | if($this->withURIQuery){ |
| 513 | - if(isset($components['query'])) $components['query'] .= '&'. trim($this->withURIQuery); |
|
| 514 | - else $components['query'] = trim($this->withURIQuery); |
|
| 522 | + if(isset($components['query'])) { |
|
| 523 | + $components['query'] .= '&'. trim($this->withURIQuery); |
|
| 524 | + } else { |
|
| 525 | + $components['query'] = trim($this->withURIQuery); |
|
| 526 | + } |
|
| 515 | 527 | } |
| 516 | 528 | $this->options['url'] = self::combineUrl($components); |
| 517 | 529 | |
@@ -553,7 +565,10 @@ discard block |
||
| 553 | 565 | } |
| 554 | 566 | |
| 555 | 567 | $cURLOptions = self::filterAndRaw($this->options); |
| 556 | - if(isset($this->body))$cURLOptions[CURLOPT_POSTFIELDS] = $this->body;//use serialized body not raw data |
|
| 568 | + if(isset($this->body)) { |
|
| 569 | + $cURLOptions[CURLOPT_POSTFIELDS] = $this->body; |
|
| 570 | + } |
|
| 571 | + //use serialized body not raw data |
|
| 557 | 572 | curl_setopt_array($this->curlHandle, $cURLOptions); |
| 558 | 573 | |
| 559 | 574 | return $this; |
@@ -566,7 +581,9 @@ discard block |
||
| 566 | 581 | $this->options[CURLOPT_POST] = true; |
| 567 | 582 | $clz = '\\MultiHttp\\Handler\\'.ucfirst($this->sendMime); |
| 568 | 583 | $inst = new $clz; |
| 569 | - if (!($inst instanceof Handler\IHandler)) throw new InvalidOperationException($clz . ' is not implement of IHandler'); |
|
| 584 | + if (!($inst instanceof Handler\IHandler)) { |
|
| 585 | + throw new InvalidOperationException($clz . ' is not implement of IHandler'); |
|
| 586 | + } |
|
| 570 | 587 | $this->body = $inst->encode($this->options['data']); |
| 571 | 588 | } |
| 572 | 589 | } |
@@ -34,15 +34,15 @@ |
||
| 34 | 34 | public function decode($body) |
| 35 | 35 | { |
| 36 | 36 | $parsed = json_decode($body, true); |
| 37 | - if(json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '. self::jsonLastErrorMsg() . ', raw body: ' .$body ); |
|
| 37 | + if (json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '.self::jsonLastErrorMsg().', raw body: '.$body); |
|
| 38 | 38 | return $parsed; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * @return string |
| 43 | 43 | */ |
| 44 | - private static function jsonLastErrorMsg(){ |
|
| 45 | - if(function_exists('json_last_error_msg')) return json_last_error_msg(); |
|
| 44 | + private static function jsonLastErrorMsg() { |
|
| 45 | + if (function_exists('json_last_error_msg')) return json_last_error_msg(); |
|
| 46 | 46 | switch (json_last_error()) { |
| 47 | 47 | case JSON_ERROR_NONE: |
| 48 | 48 | return ' - No errors'; |
@@ -34,7 +34,9 @@ discard block |
||
| 34 | 34 | public function decode($body) |
| 35 | 35 | { |
| 36 | 36 | $parsed = json_decode($body, true); |
| 37 | - if(json_last_error() !== JSON_ERROR_NONE)throw new UnexpectedResponseException('parsing json occurs error: '. self::jsonLastErrorMsg() . ', raw body: ' .$body ); |
|
| 37 | + if(json_last_error() !== JSON_ERROR_NONE) { |
|
| 38 | + throw new UnexpectedResponseException('parsing json occurs error: '. self::jsonLastErrorMsg() . ', raw body: ' .$body ); |
|
| 39 | + } |
|
| 38 | 40 | return $parsed; |
| 39 | 41 | } |
| 40 | 42 | |
@@ -42,7 +44,9 @@ discard block |
||
| 42 | 44 | * @return string |
| 43 | 45 | */ |
| 44 | 46 | private static function jsonLastErrorMsg(){ |
| 45 | - if(function_exists('json_last_error_msg')) return json_last_error_msg(); |
|
| 47 | + if(function_exists('json_last_error_msg')) { |
|
| 48 | + return json_last_error_msg(); |
|
| 49 | + } |
|
| 46 | 50 | switch (json_last_error()) { |
| 47 | 51 | case JSON_ERROR_NONE: |
| 48 | 52 | return ' - No errors'; |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | public function decode($body) |
| 34 | 34 | { |
| 35 | - if(is_string($body)){ |
|
| 35 | + if (is_string($body)) { |
|
| 36 | 36 | parse_str($body, $body); |
| 37 | 37 | } |
| 38 | 38 | return $body; |