@@ -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 | } |
@@ -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 | } |
@@ -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); |
@@ -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'; |