@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | 'timeout_ms' => 'CURLOPT_TIMEOUT_MS', // milliseconds, libcurl version > 7.36.0 , |
36 | 36 | ); |
37 | 37 | public $curlHandle; |
38 | - protected $options = array( |
|
39 | - 'CURLOPT_MAXREDIRS' => 10, |
|
40 | - 'header' => true, |
|
41 | - 'method' => self::GET, |
|
42 | - 'transfer' => true, |
|
43 | - 'follow_location' => true, |
|
44 | - 'timeout' => 0); |
|
45 | - protected $endCallback; |
|
38 | + protected $options = array( |
|
39 | + 'CURLOPT_MAXREDIRS' => 10, |
|
40 | + 'header' => true, |
|
41 | + 'method' => self::GET, |
|
42 | + 'transfer' => true, |
|
43 | + 'follow_location' => true, |
|
44 | + 'timeout' => 0); |
|
45 | + protected $endCallback; |
|
46 | 46 | protected $withURIQuery; |
47 | 47 | protected static $logger; |
48 | 48 | protected $uri; |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | |
114 | 114 | public function addOptions(array $options = array()) { |
115 | 115 | $this->options = $options+$this->options; |
116 | - $this->uri = $this->options['url']; |
|
117 | - return $this; |
|
116 | + $this->uri = $this->options['url']; |
|
117 | + return $this; |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /* no body */ |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @return Response |
152 | 152 | */ |
153 | 153 | public function send() { |
154 | - $this->applyOptions(); |
|
154 | + $this->applyOptions(); |
|
155 | 155 | $response = $this->makeResponse(); |
156 | 156 | if ($this->endCallback) { |
157 | 157 | $func = $this->endCallback; |
@@ -168,21 +168,21 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | protected function prepare() { |
171 | - if (empty($this->options['url'])) { |
|
172 | - throw new InvalidArgumentException('url can not empty'); |
|
173 | - } |
|
174 | - |
|
175 | - if (isset($this->options['data'])) { |
|
176 | - $this->options['data'] = is_array($this->options['data'])?http_build_query($this->options['data']):$this->options['data'];//for better compatibility |
|
177 | - } |
|
178 | - if (isset($this->withURIQuery)) { |
|
179 | - $this->options['url'] .= strpos($this->options['url'], '?') === FALSE?'?':'&'; |
|
180 | - $this->options['url'] .= $this->withURIQuery; |
|
181 | - } |
|
182 | - if (isset($this->options['callback'])) { |
|
183 | - $this->onEnd($this->options['callback']); |
|
184 | - unset($this->options['callback']); |
|
185 | - } |
|
171 | + if (empty($this->options['url'])) { |
|
172 | + throw new InvalidArgumentException('url can not empty'); |
|
173 | + } |
|
174 | + |
|
175 | + if (isset($this->options['data'])) { |
|
176 | + $this->options['data'] = is_array($this->options['data'])?http_build_query($this->options['data']):$this->options['data'];//for better compatibility |
|
177 | + } |
|
178 | + if (isset($this->withURIQuery)) { |
|
179 | + $this->options['url'] .= strpos($this->options['url'], '?') === FALSE?'?':'&'; |
|
180 | + $this->options['url'] .= $this->withURIQuery; |
|
181 | + } |
|
182 | + if (isset($this->options['callback'])) { |
|
183 | + $this->onEnd($this->options['callback']); |
|
184 | + unset($this->options['callback']); |
|
185 | + } |
|
186 | 186 | //swap ip and host |
187 | 187 | if (!empty($this->options['ip'])) { |
188 | 188 | $matches = array(); |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | |
220 | 220 | $cURLOptions = self::filterAndRaw($this->options); |
221 | 221 | |
222 | - curl_setopt_array($this->curlHandle, $cURLOptions); |
|
222 | + curl_setopt_array($this->curlHandle, $cURLOptions); |
|
223 | 223 | |
224 | 224 | return $this; |
225 | 225 | } |
@@ -228,11 +228,11 @@ discard block |
||
228 | 228 | $opts = array(); |
229 | 229 | foreach ($options as $key => $val) { |
230 | 230 | $alias = self::optionAlias($key); |
231 | - $options[$alias] = $val; |
|
232 | - if ($alias) {$opts[constant($alias)] = $val; |
|
233 | - } |
|
234 | - unset($options[$key]); |
|
235 | - } |
|
231 | + $options[$alias] = $val; |
|
232 | + if ($alias) {$opts[constant($alias)] = $val; |
|
233 | + } |
|
234 | + unset($options[$key]); |
|
235 | + } |
|
236 | 236 | return $opts; |
237 | 237 | } |
238 | 238 | |
@@ -254,26 +254,26 @@ discard block |
||
254 | 254 | $info = curl_getinfo($this->curlHandle); |
255 | 255 | $errno = curl_errno($this->curlHandle); |
256 | 256 | $error = curl_error($this->curlHandle); |
257 | - $response = Response::create($this, $body, $info, $errno, $error); |
|
258 | - self::log($response); |
|
257 | + $response = Response::create($this, $body, $info, $errno, $error); |
|
258 | + self::log($response); |
|
259 | 259 | return $response; |
260 | 260 | } |
261 | 261 | |
262 | - private static function log(Response $response) |
|
263 | - { |
|
264 | - if (is_null(self::$logger)) { |
|
265 | - return; |
|
266 | - } |
|
267 | - if($response->hasErrors()){ |
|
268 | - self::$logger->error($response->request->getURI() . "\t" . $response->error, array( |
|
269 | - 'response' => print_r($response,1), |
|
270 | - )); |
|
271 | - } |
|
272 | - |
|
273 | - } |
|
274 | - |
|
275 | - public static function setLogger($logger) |
|
276 | - { |
|
277 | - self::$logger = $logger; |
|
278 | - } |
|
262 | + private static function log(Response $response) |
|
263 | + { |
|
264 | + if (is_null(self::$logger)) { |
|
265 | + return; |
|
266 | + } |
|
267 | + if($response->hasErrors()){ |
|
268 | + self::$logger->error($response->request->getURI() . "\t" . $response->error, array( |
|
269 | + 'response' => print_r($response,1), |
|
270 | + )); |
|
271 | + } |
|
272 | + |
|
273 | + } |
|
274 | + |
|
275 | + public static function setLogger($logger) |
|
276 | + { |
|
277 | + self::$logger = $logger; |
|
278 | + } |
|
279 | 279 | } |