@@ -9,53 +9,53 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | class Curl { |
| 11 | 11 | |
| 12 | - const VERSION = '7.2.0'; |
|
| 13 | - const DEFAULT_TIMEOUT = 20; |
|
| 12 | + const VERSION='7.2.0'; |
|
| 13 | + const DEFAULT_TIMEOUT=20; |
|
| 14 | 14 | |
| 15 | - public $retryCount = 3; |
|
| 15 | + public $retryCount=3; |
|
| 16 | 16 | |
| 17 | 17 | public $curl; |
| 18 | - public $id = null; |
|
| 19 | - |
|
| 20 | - public $error = false; |
|
| 21 | - public $errorCode = 0; |
|
| 22 | - public $errorMessage = null; |
|
| 23 | - |
|
| 24 | - public $curlError = false; |
|
| 25 | - public $curlErrorCode = 0; |
|
| 26 | - public $curlErrorMessage = null; |
|
| 27 | - |
|
| 28 | - public $httpError = false; |
|
| 29 | - public $httpStatusCode = 0; |
|
| 30 | - public $httpErrorMessage = null; |
|
| 31 | - |
|
| 32 | - public $baseUrl = null; |
|
| 33 | - public $url = null; |
|
| 34 | - public $requestHeaders = null; |
|
| 35 | - public $responseHeaders = null; |
|
| 36 | - public $rawResponseHeaders = ''; |
|
| 37 | - public $responseCookies = array(); |
|
| 38 | - public $response = null; |
|
| 39 | - public $rawResponse = null; |
|
| 40 | - |
|
| 41 | - public $beforeSendFunction = null; |
|
| 42 | - public $downloadCompleteFunction = null; |
|
| 43 | - public $successFunction = null; |
|
| 44 | - public $errorFunction = null; |
|
| 45 | - public $completeFunction = null; |
|
| 46 | - public $fileHandle = null; |
|
| 47 | - |
|
| 48 | - private $cookies = array(); |
|
| 49 | - private $headers = array(); |
|
| 50 | - private $options = array(); |
|
| 51 | - |
|
| 52 | - private $jsonDecoder = null; |
|
| 53 | - private $jsonPattern = '/^(?:application|text)\/(?:[a-z]+(?:[\.-][0-9a-z]+){0,}[\+\.]|x-)?json(?:-[a-z]+)?/i'; |
|
| 54 | - private $xmlDecoder = null; |
|
| 55 | - private $xmlPattern = '~^(?:text/|application/(?:atom\+|rss\+)?)xml~i'; |
|
| 56 | - private $defaultDecoder = null; |
|
| 57 | - |
|
| 58 | - public static $RFC2616 = array( |
|
| 18 | + public $id=null; |
|
| 19 | + |
|
| 20 | + public $error=false; |
|
| 21 | + public $errorCode=0; |
|
| 22 | + public $errorMessage=null; |
|
| 23 | + |
|
| 24 | + public $curlError=false; |
|
| 25 | + public $curlErrorCode=0; |
|
| 26 | + public $curlErrorMessage=null; |
|
| 27 | + |
|
| 28 | + public $httpError=false; |
|
| 29 | + public $httpStatusCode=0; |
|
| 30 | + public $httpErrorMessage=null; |
|
| 31 | + |
|
| 32 | + public $baseUrl=null; |
|
| 33 | + public $url=null; |
|
| 34 | + public $requestHeaders=null; |
|
| 35 | + public $responseHeaders=null; |
|
| 36 | + public $rawResponseHeaders=''; |
|
| 37 | + public $responseCookies=array(); |
|
| 38 | + public $response=null; |
|
| 39 | + public $rawResponse=null; |
|
| 40 | + |
|
| 41 | + public $beforeSendFunction=null; |
|
| 42 | + public $downloadCompleteFunction=null; |
|
| 43 | + public $successFunction=null; |
|
| 44 | + public $errorFunction=null; |
|
| 45 | + public $completeFunction=null; |
|
| 46 | + public $fileHandle=null; |
|
| 47 | + |
|
| 48 | + private $cookies=array(); |
|
| 49 | + private $headers=array(); |
|
| 50 | + private $options=array(); |
|
| 51 | + |
|
| 52 | + private $jsonDecoder=null; |
|
| 53 | + private $jsonPattern='/^(?:application|text)\/(?:[a-z]+(?:[\.-][0-9a-z]+){0,}[\+\.]|x-)?json(?:-[a-z]+)?/i'; |
|
| 54 | + private $xmlDecoder=null; |
|
| 55 | + private $xmlPattern='~^(?:text/|application/(?:atom\+|rss\+)?)xml~i'; |
|
| 56 | + private $defaultDecoder=null; |
|
| 57 | + |
|
| 58 | + public static $RFC2616=array( |
|
| 59 | 59 | // RFC2616: "any CHAR except CTLs or separators". |
| 60 | 60 | // CHAR = <any US-ASCII character (octets 0 - 127)> |
| 61 | 61 | // CTL = <any US-ASCII control character |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | 'Y', 'Z', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', |
| 73 | 73 | 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '|', '~', |
| 74 | 74 | ); |
| 75 | - public static $RFC6265 = array( |
|
| 75 | + public static $RFC6265=array( |
|
| 76 | 76 | // RFC6265: "US-ASCII characters excluding CTLs, whitespace DQUOTE, comma, semicolon, and backslash". |
| 77 | 77 | // %x21 |
| 78 | 78 | '!', |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', |
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | - private static $deferredProperties = array( |
|
| 91 | + private static $deferredProperties=array( |
|
| 92 | 92 | 'effectiveUrl', |
| 93 | 93 | 'rfc2616', |
| 94 | 94 | 'rfc6265', |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | * @param $base_url |
| 103 | 103 | * @throws \ErrorException |
| 104 | 104 | */ |
| 105 | - public function __construct($base_url = null) |
|
| 105 | + public function __construct($base_url=null) |
|
| 106 | 106 | { |
| 107 | 107 | if (!extension_loaded('curl')) { |
| 108 | 108 | throw new \ErrorException('cURL library is not loaded'); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $this->curl = curl_init(); |
|
| 112 | - $this->id = uniqid('', true); |
|
| 111 | + $this->curl=curl_init(); |
|
| 112 | + $this->id=uniqid('', true); |
|
| 113 | 113 | $this->setDefaultUserAgent(); |
| 114 | 114 | $this->setDefaultJsonDecoder(); |
| 115 | 115 | $this->setDefaultXmlDecoder(); |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $this->setOpt(CURLINFO_HEADER_OUT, true); |
| 118 | 118 | $this->setOpt(CURLOPT_HEADERFUNCTION, array($this, 'headerCallback')); |
| 119 | 119 | $this->setOpt(CURLOPT_RETURNTRANSFER, true); |
| 120 | - $this->headers = []; |
|
| 120 | + $this->headers=[]; |
|
| 121 | 121 | $this->setUrl($base_url); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | public function beforeSend($callback) |
| 131 | 131 | { |
| 132 | - $this->beforeSendFunction = $callback; |
|
| 132 | + $this->beforeSendFunction=$callback; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -142,21 +142,21 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public function buildPostData($data) |
| 144 | 144 | { |
| 145 | - $binary_data = false; |
|
| 145 | + $binary_data=false; |
|
| 146 | 146 | if (is_array($data)) { |
| 147 | 147 | // Return JSON-encoded string when the request's content-type is JSON. |
| 148 | 148 | if (isset($this->headers['Content-Type']) && |
| 149 | 149 | preg_match($this->jsonPattern, $this->headers['Content-Type'])) { |
| 150 | - $json_str = json_encode($data); |
|
| 150 | + $json_str=json_encode($data); |
|
| 151 | 151 | if (!($json_str === false)) { |
| 152 | - $data = $json_str; |
|
| 152 | + $data=$json_str; |
|
| 153 | 153 | } |
| 154 | 154 | } else { |
| 155 | 155 | // Manually build a single-dimensional array from a multi-dimensional array as using curl_setopt($ch, |
| 156 | 156 | // CURLOPT_POSTFIELDS, $data) doesn't correctly handle multi-dimensional arrays when files are |
| 157 | 157 | // referenced. |
| 158 | 158 | if (Arr::isMultidim($data)) { |
| 159 | - $data = Arr::flatten($data); |
|
| 159 | + $data=Arr::flatten($data); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // Modify array values to ensure any referenced files are properly handled depending on the support of |
@@ -165,19 +165,19 @@ discard block |
||
| 165 | 165 | // non-file values prefixed with the @ character. |
| 166 | 166 | foreach ($data as $key => $value) { |
| 167 | 167 | if (is_string($value) && strpos($value, '@') === 0 && is_file(substr($value, 1))) { |
| 168 | - $binary_data = true; |
|
| 168 | + $binary_data=true; |
|
| 169 | 169 | if (class_exists('CURLFile')) { |
| 170 | - $data[$key] = new \CURLFile(substr($value, 1)); |
|
| 170 | + $data[$key]=new \CURLFile(substr($value, 1)); |
|
| 171 | 171 | } |
| 172 | 172 | } elseif ($value instanceof \CURLFile) { |
| 173 | - $binary_data = true; |
|
| 173 | + $binary_data=true; |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | if (!$binary_data && (is_array($data) || is_object($data))) { |
| 180 | - $data = http_build_query($data, '', '&'); |
|
| 180 | + $data=http_build_query($data, '', '&'); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | return $data; |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | public function call() |
| 192 | 192 | { |
| 193 | - $args = func_get_args(); |
|
| 194 | - $function = array_shift($args); |
|
| 193 | + $args=func_get_args(); |
|
| 194 | + $function=array_shift($args); |
|
| 195 | 195 | if (is_callable($function)) { |
| 196 | 196 | array_unshift($args, $this); |
| 197 | 197 | call_user_func_array($function, $args); |
@@ -208,10 +208,10 @@ discard block |
||
| 208 | 208 | if (is_resource($this->curl)) { |
| 209 | 209 | curl_close($this->curl); |
| 210 | 210 | } |
| 211 | - $this->options = null; |
|
| 212 | - $this->jsonDecoder = null; |
|
| 213 | - $this->xmlDecoder = null; |
|
| 214 | - $this->defaultDecoder = null; |
|
| 211 | + $this->options=null; |
|
| 212 | + $this->jsonDecoder=null; |
|
| 213 | + $this->xmlDecoder=null; |
|
| 214 | + $this->defaultDecoder=null; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | */ |
| 223 | 223 | public function complete($callback) |
| 224 | 224 | { |
| 225 | - $this->completeFunction = $callback; |
|
| 225 | + $this->completeFunction=$callback; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -247,12 +247,12 @@ discard block |
||
| 247 | 247 | * |
| 248 | 248 | * @return string |
| 249 | 249 | */ |
| 250 | - public function delete($url, $query_parameters = array(), $data = array()) |
|
| 250 | + public function delete($url, $query_parameters=array(), $data=array()) |
|
| 251 | 251 | { |
| 252 | 252 | if (is_array($url)) { |
| 253 | - $data = $query_parameters; |
|
| 254 | - $query_parameters = $url; |
|
| 255 | - $url = $this->baseUrl; |
|
| 253 | + $data=$query_parameters; |
|
| 254 | + $query_parameters=$url; |
|
| 255 | + $url=$this->baseUrl; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | $this->setUrl($url, $query_parameters); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | if (!$this->error && $this->downloadCompleteFunction) { |
| 273 | 273 | rewind($fh); |
| 274 | 274 | $this->call($this->downloadCompleteFunction, $fh); |
| 275 | - $this->downloadCompleteFunction = null; |
|
| 275 | + $this->downloadCompleteFunction=null; |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | if (is_resource($fh)) { |
@@ -308,29 +308,29 @@ discard block |
||
| 308 | 308 | public function download($url, $mixed_filename) |
| 309 | 309 | { |
| 310 | 310 | if (is_callable($mixed_filename)) { |
| 311 | - $this->downloadCompleteFunction = $mixed_filename; |
|
| 312 | - $this->fileHandle = tmpfile(); |
|
| 311 | + $this->downloadCompleteFunction=$mixed_filename; |
|
| 312 | + $this->fileHandle=tmpfile(); |
|
| 313 | 313 | } else { |
| 314 | - $filename = $mixed_filename; |
|
| 314 | + $filename=$mixed_filename; |
|
| 315 | 315 | |
| 316 | 316 | // Use a temporary file when downloading. Not using a temporary file can cause an error when an existing |
| 317 | 317 | // file has already fully completed downloading and a new download is started with the same destination save |
| 318 | 318 | // path. The download request will include header "Range: bytes=$filesize-" which is syntactically valid, |
| 319 | 319 | // but unsatisfiable. |
| 320 | - $download_filename = $filename . '.pccdownload'; |
|
| 320 | + $download_filename=$filename.'.pccdownload'; |
|
| 321 | 321 | |
| 322 | - $mode = 'wb'; |
|
| 322 | + $mode='wb'; |
|
| 323 | 323 | // Attempt to resume download only when a temporary download file exists and is not empty. |
| 324 | - if (file_exists($download_filename) && $filesize = filesize($download_filename)) { |
|
| 325 | - $mode = 'ab'; |
|
| 326 | - $first_byte_position = $filesize; |
|
| 327 | - $range = $first_byte_position . '-'; |
|
| 324 | + if (file_exists($download_filename) && $filesize=filesize($download_filename)) { |
|
| 325 | + $mode='ab'; |
|
| 326 | + $first_byte_position=$filesize; |
|
| 327 | + $range=$first_byte_position.'-'; |
|
| 328 | 328 | $this->setOpt(CURLOPT_RANGE, $range); |
| 329 | 329 | } |
| 330 | - $this->fileHandle = fopen($download_filename, $mode); |
|
| 330 | + $this->fileHandle=fopen($download_filename, $mode); |
|
| 331 | 331 | |
| 332 | 332 | // Move the downloaded temporary file to the destination save path. |
| 333 | - $this->downloadCompleteFunction = function ($fh) use ($download_filename, $filename) { |
|
| 333 | + $this->downloadCompleteFunction=function($fh) use ($download_filename, $filename) { |
|
| 334 | 334 | rename($download_filename, $filename); |
| 335 | 335 | }; |
| 336 | 336 | } |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | $this->setOpt(CURLOPT_FILE, $this->fileHandle); |
| 339 | 339 | $this->get($url); |
| 340 | 340 | |
| 341 | - return ! $this->error; |
|
| 341 | + return !$this->error; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | */ |
| 350 | 350 | public function error($callback) |
| 351 | 351 | { |
| 352 | - $this->errorFunction = $callback; |
|
| 352 | + $this->errorFunction=$callback; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -360,55 +360,55 @@ discard block |
||
| 360 | 360 | * |
| 361 | 361 | * @return mixed Returns the value provided by parseResponse. |
| 362 | 362 | */ |
| 363 | - public function exec($ch = null) |
|
| 363 | + public function exec($ch=null) |
|
| 364 | 364 | { |
| 365 | 365 | if ($ch === null) { |
| 366 | - $this->responseCookies = array(); |
|
| 366 | + $this->responseCookies=array(); |
|
| 367 | 367 | $this->call($this->beforeSendFunction); |
| 368 | 368 | $i=0; |
| 369 | - while(1){ |
|
| 370 | - $this->rawResponse = curl_exec($this->curl); |
|
| 371 | - $this->curlErrorCode = curl_errno($this->curl); |
|
| 372 | - if($this->curlErrorCode==28 && $i++ < $this->retryCount){ |
|
| 369 | + while (1) { |
|
| 370 | + $this->rawResponse=curl_exec($this->curl); |
|
| 371 | + $this->curlErrorCode=curl_errno($this->curl); |
|
| 372 | + if ($this->curlErrorCode == 28 && $i++ < $this->retryCount) { |
|
| 373 | 373 | continue; |
| 374 | 374 | } |
| 375 | 375 | break; |
| 376 | 376 | } |
| 377 | - $this->curlErrorMessage = curl_error($this->curl); |
|
| 377 | + $this->curlErrorMessage=curl_error($this->curl); |
|
| 378 | 378 | } else { |
| 379 | - $this->rawResponse = curl_multi_getcontent($ch); |
|
| 380 | - $this->curlErrorMessage = curl_error($ch); |
|
| 379 | + $this->rawResponse=curl_multi_getcontent($ch); |
|
| 380 | + $this->curlErrorMessage=curl_error($ch); |
|
| 381 | 381 | } |
| 382 | - $this->curlError = !($this->curlErrorCode === 0); |
|
| 382 | + $this->curlError=!($this->curlErrorCode === 0); |
|
| 383 | 383 | // Include additional error code information in error message when possible. |
| 384 | 384 | if ($this->curlError && function_exists('curl_strerror')) { |
| 385 | - $this->curlErrorMessage = |
|
| 386 | - curl_strerror($this->curlErrorCode) . ( |
|
| 387 | - empty($this->curlErrorMessage) ? '' : ': ' . $this->curlErrorMessage |
|
| 385 | + $this->curlErrorMessage= |
|
| 386 | + curl_strerror($this->curlErrorCode).( |
|
| 387 | + empty($this->curlErrorMessage) ? '' : ': '.$this->curlErrorMessage |
|
| 388 | 388 | ); |
| 389 | 389 | print_r($this->rawResponse); |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - $this->httpStatusCode = $this->getInfo(CURLINFO_HTTP_CODE); |
|
| 393 | - $this->httpError = in_array(floor($this->httpStatusCode / 100), array(4, 5)); |
|
| 394 | - $this->error = $this->curlError || $this->httpError; |
|
| 395 | - $this->errorCode = $this->error ? ($this->curlError ? $this->curlErrorCode : $this->httpStatusCode) : 0; |
|
| 392 | + $this->httpStatusCode=$this->getInfo(CURLINFO_HTTP_CODE); |
|
| 393 | + $this->httpError=in_array(floor($this->httpStatusCode / 100), array(4, 5)); |
|
| 394 | + $this->error=$this->curlError || $this->httpError; |
|
| 395 | + $this->errorCode=$this->error ? ($this->curlError ? $this->curlErrorCode : $this->httpStatusCode) : 0; |
|
| 396 | 396 | |
| 397 | 397 | // NOTE: CURLINFO_HEADER_OUT set to true is required for requestHeaders |
| 398 | 398 | // to not be empty (e.g. $curl->setOpt(CURLINFO_HEADER_OUT, true);). |
| 399 | 399 | if ($this->getOpt(CURLINFO_HEADER_OUT) === true) { |
| 400 | - $this->requestHeaders = $this->parseRequestHeaders($this->getInfo(CURLINFO_HEADER_OUT)); |
|
| 400 | + $this->requestHeaders=$this->parseRequestHeaders($this->getInfo(CURLINFO_HEADER_OUT)); |
|
| 401 | 401 | } |
| 402 | - $this->responseHeaders = $this->parseResponseHeaders($this->rawResponseHeaders); |
|
| 403 | - $this->response = $this->parseResponse($this->responseHeaders, $this->rawResponse); |
|
| 402 | + $this->responseHeaders=$this->parseResponseHeaders($this->rawResponseHeaders); |
|
| 403 | + $this->response=$this->parseResponse($this->responseHeaders, $this->rawResponse); |
|
| 404 | 404 | |
| 405 | - $this->httpErrorMessage = ''; |
|
| 405 | + $this->httpErrorMessage=''; |
|
| 406 | 406 | if ($this->error) { |
| 407 | 407 | if (isset($this->responseHeaders['Status-Line'])) { |
| 408 | - $this->httpErrorMessage = $this->responseHeaders['Status-Line']; |
|
| 408 | + $this->httpErrorMessage=$this->responseHeaders['Status-Line']; |
|
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | - $this->errorMessage = $this->curlError ? $this->curlErrorMessage : $this->httpErrorMessage; |
|
| 411 | + $this->errorMessage=$this->curlError ? $this->curlErrorMessage : $this->httpErrorMessage; |
|
| 412 | 412 | |
| 413 | 413 | if (!$this->error) { |
| 414 | 414 | $this->call($this->successFunction); |
@@ -435,11 +435,11 @@ discard block |
||
| 435 | 435 | * |
| 436 | 436 | * @return mixed Returns the value provided by exec. |
| 437 | 437 | */ |
| 438 | - public function get($url, $data = array()) |
|
| 438 | + public function get($url, $data=array()) |
|
| 439 | 439 | { |
| 440 | 440 | if (is_array($url)) { |
| 441 | - $data = $url; |
|
| 442 | - $url = $this->baseUrl; |
|
| 441 | + $data=$url; |
|
| 442 | + $url=$this->baseUrl; |
|
| 443 | 443 | } |
| 444 | 444 | $this->setUrl($url, $data); |
| 445 | 445 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET'); |
@@ -455,13 +455,13 @@ discard block |
||
| 455 | 455 | * |
| 456 | 456 | * @return mixed |
| 457 | 457 | */ |
| 458 | - public function getInfo($opt = null) |
|
| 458 | + public function getInfo($opt=null) |
|
| 459 | 459 | { |
| 460 | - $args = array(); |
|
| 461 | - $args[] = $this->curl; |
|
| 460 | + $args=array(); |
|
| 461 | + $args[]=$this->curl; |
|
| 462 | 462 | |
| 463 | 463 | if (func_num_args()) { |
| 464 | - $args[] = $opt; |
|
| 464 | + $args[]=$opt; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | return call_user_func_array('curl_getinfo', $args); |
@@ -489,11 +489,11 @@ discard block |
||
| 489 | 489 | * |
| 490 | 490 | * @return string |
| 491 | 491 | */ |
| 492 | - public function head($url, $data = array()) |
|
| 492 | + public function head($url, $data=array()) |
|
| 493 | 493 | { |
| 494 | 494 | if (is_array($url)) { |
| 495 | - $data = $url; |
|
| 496 | - $url = $this->baseUrl; |
|
| 495 | + $data=$url; |
|
| 496 | + $url=$this->baseUrl; |
|
| 497 | 497 | } |
| 498 | 498 | $this->setUrl($url, $data); |
| 499 | 499 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'HEAD'); |
@@ -513,9 +513,9 @@ discard block |
||
| 513 | 513 | public function headerCallback($ch, $header) |
| 514 | 514 | { |
| 515 | 515 | if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) === 1) { |
| 516 | - $this->responseCookies[$cookie[1]] = trim($cookie[2], " \n\r\t\0\x0B"); |
|
| 516 | + $this->responseCookies[$cookie[1]]=trim($cookie[2], " \n\r\t\0\x0B"); |
|
| 517 | 517 | } |
| 518 | - $this->rawResponseHeaders .= $header; |
|
| 518 | + $this->rawResponseHeaders.=$header; |
|
| 519 | 519 | return strlen($header); |
| 520 | 520 | } |
| 521 | 521 | |
@@ -528,11 +528,11 @@ discard block |
||
| 528 | 528 | * |
| 529 | 529 | * @return string |
| 530 | 530 | */ |
| 531 | - public function options($url, $data = array()) |
|
| 531 | + public function options($url, $data=array()) |
|
| 532 | 532 | { |
| 533 | 533 | if (is_array($url)) { |
| 534 | - $data = $url; |
|
| 535 | - $url = $this->baseUrl; |
|
| 534 | + $data=$url; |
|
| 535 | + $url=$this->baseUrl; |
|
| 536 | 536 | } |
| 537 | 537 | $this->setUrl($url, $data); |
| 538 | 538 | $this->removeHeader('Content-Length'); |
@@ -549,11 +549,11 @@ discard block |
||
| 549 | 549 | * |
| 550 | 550 | * @return string |
| 551 | 551 | */ |
| 552 | - public function patch($url, $data = array()) |
|
| 552 | + public function patch($url, $data=array()) |
|
| 553 | 553 | { |
| 554 | 554 | if (is_array($url)) { |
| 555 | - $data = $url; |
|
| 556 | - $url = $this->baseUrl; |
|
| 555 | + $data=$url; |
|
| 556 | + $url=$this->baseUrl; |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | if (is_array($data) && empty($data)) { |
@@ -591,12 +591,12 @@ discard block |
||
| 591 | 591 | * [2] https://github.com/php/php-src/pull/531 |
| 592 | 592 | * [3] http://php.net/ChangeLog-5.php#5.5.11 |
| 593 | 593 | */ |
| 594 | - public function post($url, $data = array(), $follow_303_with_post = false) |
|
| 594 | + public function post($url, $data=array(), $follow_303_with_post=false) |
|
| 595 | 595 | { |
| 596 | 596 | if (is_array($url)) { |
| 597 | - $follow_303_with_post = (bool)$data; |
|
| 598 | - $data = $url; |
|
| 599 | - $url = $this->baseUrl; |
|
| 597 | + $follow_303_with_post=(bool) $data; |
|
| 598 | + $data=$url; |
|
| 599 | + $url=$this->baseUrl; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | $this->setUrl($url); |
@@ -633,15 +633,15 @@ discard block |
||
| 633 | 633 | * |
| 634 | 634 | * @return string |
| 635 | 635 | */ |
| 636 | - public function put($url, $data = array()) |
|
| 636 | + public function put($url, $data=array()) |
|
| 637 | 637 | { |
| 638 | 638 | if (is_array($url)) { |
| 639 | - $data = $url; |
|
| 640 | - $url = $this->baseUrl; |
|
| 639 | + $data=$url; |
|
| 640 | + $url=$this->baseUrl; |
|
| 641 | 641 | } |
| 642 | 642 | $this->setUrl($url); |
| 643 | 643 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT'); |
| 644 | - $put_data = $this->buildPostData($data); |
|
| 644 | + $put_data=$this->buildPostData($data); |
|
| 645 | 645 | if (empty($this->options[CURLOPT_INFILE]) && empty($this->options[CURLOPT_INFILESIZE])) { |
| 646 | 646 | if (is_string($put_data)) { |
| 647 | 647 | $this->setHeader('Content-Length', strlen($put_data)); |
@@ -662,15 +662,15 @@ discard block |
||
| 662 | 662 | * |
| 663 | 663 | * @return string |
| 664 | 664 | */ |
| 665 | - public function search($url, $data = array()) |
|
| 665 | + public function search($url, $data=array()) |
|
| 666 | 666 | { |
| 667 | 667 | if (is_array($url)) { |
| 668 | - $data = $url; |
|
| 669 | - $url = $this->baseUrl; |
|
| 668 | + $data=$url; |
|
| 669 | + $url=$this->baseUrl; |
|
| 670 | 670 | } |
| 671 | 671 | $this->setUrl($url); |
| 672 | 672 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'SEARCH'); |
| 673 | - $put_data = $this->buildPostData($data); |
|
| 673 | + $put_data=$this->buildPostData($data); |
|
| 674 | 674 | if (empty($this->options[CURLOPT_INFILE]) && empty($this->options[CURLOPT_INFILESIZE])) { |
| 675 | 675 | if (is_string($put_data)) { |
| 676 | 676 | $this->setHeader('Content-Length', strlen($put_data)); |
@@ -689,10 +689,10 @@ discard block |
||
| 689 | 689 | * @param $username |
| 690 | 690 | * @param $password |
| 691 | 691 | */ |
| 692 | - public function setBasicAuthentication($username, $password = '') |
|
| 692 | + public function setBasicAuthentication($username, $password='') |
|
| 693 | 693 | { |
| 694 | 694 | $this->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
| 695 | - $this->setOpt(CURLOPT_USERPWD, $username . ':' . $password); |
|
| 695 | + $this->setOpt(CURLOPT_USERPWD, $username.':'.$password); |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
@@ -702,10 +702,10 @@ discard block |
||
| 702 | 702 | * @param $username |
| 703 | 703 | * @param $password |
| 704 | 704 | */ |
| 705 | - public function setDigestAuthentication($username, $password = '') |
|
| 705 | + public function setDigestAuthentication($username, $password='') |
|
| 706 | 706 | { |
| 707 | 707 | $this->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); |
| 708 | - $this->setOpt(CURLOPT_USERPWD, $username . ':' . $password); |
|
| 708 | + $this->setOpt(CURLOPT_USERPWD, $username.':'.$password); |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -717,27 +717,27 @@ discard block |
||
| 717 | 717 | */ |
| 718 | 718 | public function setCookie($key, $value) |
| 719 | 719 | { |
| 720 | - $name_chars = array(); |
|
| 720 | + $name_chars=array(); |
|
| 721 | 721 | foreach (str_split($key) as $name_char) { |
| 722 | 722 | if (!isset($this->rfc2616[$name_char])) { |
| 723 | - $name_chars[] = rawurlencode($name_char); |
|
| 723 | + $name_chars[]=rawurlencode($name_char); |
|
| 724 | 724 | } else { |
| 725 | - $name_chars[] = $name_char; |
|
| 725 | + $name_chars[]=$name_char; |
|
| 726 | 726 | } |
| 727 | 727 | } |
| 728 | 728 | |
| 729 | - $value_chars = array(); |
|
| 729 | + $value_chars=array(); |
|
| 730 | 730 | foreach (str_split($value) as $value_char) { |
| 731 | 731 | if (!isset($this->rfc6265[$value_char])) { |
| 732 | - $value_chars[] = rawurlencode($value_char); |
|
| 732 | + $value_chars[]=rawurlencode($value_char); |
|
| 733 | 733 | } else { |
| 734 | - $value_chars[] = $value_char; |
|
| 734 | + $value_chars[]=$value_char; |
|
| 735 | 735 | } |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | - $this->cookies[implode('', $name_chars)] = implode('', $value_chars); |
|
| 739 | - $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function ($k, $v) { |
|
| 740 | - return $k . '=' . $v; |
|
| 738 | + $this->cookies[implode('', $name_chars)]=implode('', $value_chars); |
|
| 739 | + $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function($k, $v) { |
|
| 740 | + return $k.'='.$v; |
|
| 741 | 741 | }, array_keys($this->cookies), array_values($this->cookies)))); |
| 742 | 742 | } |
| 743 | 743 | |
@@ -750,29 +750,29 @@ discard block |
||
| 750 | 750 | public function setCookies($cookies) |
| 751 | 751 | { |
| 752 | 752 | foreach ($cookies as $key => $value) { |
| 753 | - $name_chars = array(); |
|
| 753 | + $name_chars=array(); |
|
| 754 | 754 | foreach (str_split($key) as $name_char) { |
| 755 | 755 | if (!isset($this->rfc2616[$name_char])) { |
| 756 | - $name_chars[] = rawurlencode($name_char); |
|
| 756 | + $name_chars[]=rawurlencode($name_char); |
|
| 757 | 757 | } else { |
| 758 | - $name_chars[] = $name_char; |
|
| 758 | + $name_chars[]=$name_char; |
|
| 759 | 759 | } |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - $value_chars = array(); |
|
| 762 | + $value_chars=array(); |
|
| 763 | 763 | foreach (str_split($value) as $value_char) { |
| 764 | 764 | if (!isset($this->rfc6265[$value_char])) { |
| 765 | - $value_chars[] = rawurlencode($value_char); |
|
| 765 | + $value_chars[]=rawurlencode($value_char); |
|
| 766 | 766 | } else { |
| 767 | - $value_chars[] = $value_char; |
|
| 767 | + $value_chars[]=$value_char; |
|
| 768 | 768 | } |
| 769 | 769 | } |
| 770 | 770 | |
| 771 | - $this->cookies[implode('', $name_chars)] = implode('', $value_chars); |
|
| 771 | + $this->cookies[implode('', $name_chars)]=implode('', $value_chars); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | - $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function ($k, $v) { |
|
| 775 | - return $k . '=' . $v; |
|
| 774 | + $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function($k, $v) { |
|
| 775 | + return $k.'='.$v; |
|
| 776 | 776 | }, array_keys($this->cookies), array_values($this->cookies)))); |
| 777 | 777 | } |
| 778 | 778 | |
@@ -812,14 +812,14 @@ discard block |
||
| 812 | 812 | { |
| 813 | 813 | // Make compatible with PHP version both before and after 5.5.0. PHP 5.5.0 added the cURL resource as the first |
| 814 | 814 | // argument to the CURLOPT_PROGRESSFUNCTION callback. |
| 815 | - $gte_v550 = version_compare(PHP_VERSION, '5.5.0') >= 0; |
|
| 815 | + $gte_v550=version_compare(PHP_VERSION, '5.5.0') >= 0; |
|
| 816 | 816 | if ($gte_v550) { |
| 817 | - $callback = function ($resource, $download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 817 | + $callback=function($resource, $download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 818 | 818 | // Abort the transfer when $downloaded bytes exceeds maximum $bytes by returning a non-zero value. |
| 819 | 819 | return $downloaded > $bytes ? 1 : 0; |
| 820 | 820 | }; |
| 821 | 821 | } else { |
| 822 | - $callback = function ($download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 822 | + $callback=function($download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 823 | 823 | return $downloaded > $bytes ? 1 : 0; |
| 824 | 824 | }; |
| 825 | 825 | } |
@@ -898,20 +898,20 @@ discard block |
||
| 898 | 898 | */ |
| 899 | 899 | public function setDefaultJsonDecoder() |
| 900 | 900 | { |
| 901 | - $args = func_get_args(); |
|
| 902 | - $this->jsonDecoder = function ($response) use ($args) { |
|
| 901 | + $args=func_get_args(); |
|
| 902 | + $this->jsonDecoder=function($response) use ($args) { |
|
| 903 | 903 | array_unshift($args, $response); |
| 904 | 904 | |
| 905 | 905 | // Call json_decode() without the $options parameter in PHP |
| 906 | 906 | // versions less than 5.4.0 as the $options parameter was added in |
| 907 | 907 | // PHP version 5.4.0. |
| 908 | 908 | if (version_compare(PHP_VERSION, '5.4.0', '<')) { |
| 909 | - $args = array_slice($args, 0, 3); |
|
| 909 | + $args=array_slice($args, 0, 3); |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | - $json_obj = call_user_func_array('json_decode', $args); |
|
| 912 | + $json_obj=call_user_func_array('json_decode', $args); |
|
| 913 | 913 | if (!($json_obj === null)) { |
| 914 | - $response = $json_obj; |
|
| 914 | + $response=$json_obj; |
|
| 915 | 915 | } |
| 916 | 916 | return $response; |
| 917 | 917 | }; |
@@ -924,10 +924,10 @@ discard block |
||
| 924 | 924 | */ |
| 925 | 925 | public function setDefaultXmlDecoder() |
| 926 | 926 | { |
| 927 | - $this->xmlDecoder = function ($response) { |
|
| 928 | - $xml_obj = @simplexml_load_string($response); |
|
| 927 | + $this->xmlDecoder=function($response) { |
|
| 928 | + $xml_obj=@simplexml_load_string($response); |
|
| 929 | 929 | if (!($xml_obj === false)) { |
| 930 | - $response = $xml_obj; |
|
| 930 | + $response=$xml_obj; |
|
| 931 | 931 | } |
| 932 | 932 | return $response; |
| 933 | 933 | }; |
@@ -939,15 +939,15 @@ discard block |
||
| 939 | 939 | * @access public |
| 940 | 940 | * @param $decoder string|callable |
| 941 | 941 | */ |
| 942 | - public function setDefaultDecoder($decoder = 'json') |
|
| 942 | + public function setDefaultDecoder($decoder='json') |
|
| 943 | 943 | { |
| 944 | 944 | if (is_callable($decoder)) { |
| 945 | - $this->defaultDecoder = $decoder; |
|
| 945 | + $this->defaultDecoder=$decoder; |
|
| 946 | 946 | } else { |
| 947 | 947 | if ($decoder === 'json') { |
| 948 | - $this->defaultDecoder = $this->jsonDecoder; |
|
| 948 | + $this->defaultDecoder=$this->jsonDecoder; |
|
| 949 | 949 | } elseif ($decoder === 'xml') { |
| 950 | - $this->defaultDecoder = $this->xmlDecoder; |
|
| 950 | + $this->defaultDecoder=$this->xmlDecoder; |
|
| 951 | 951 | } |
| 952 | 952 | } |
| 953 | 953 | } |
@@ -969,10 +969,10 @@ discard block |
||
| 969 | 969 | */ |
| 970 | 970 | public function setDefaultUserAgent() |
| 971 | 971 | { |
| 972 | - $user_agent = 'puck client' . self::VERSION . ' mini'; |
|
| 973 | - $user_agent .= ' PHP/' . PHP_VERSION; |
|
| 974 | - $curl_version = curl_version(); |
|
| 975 | - $user_agent .= ' curl/' . $curl_version['version']; |
|
| 972 | + $user_agent='puck client'.self::VERSION.' mini'; |
|
| 973 | + $user_agent.=' PHP/'.PHP_VERSION; |
|
| 974 | + $curl_version=curl_version(); |
|
| 975 | + $user_agent.=' curl/'.$curl_version['version']; |
|
| 976 | 976 | $this->setUserAgent($user_agent); |
| 977 | 977 | } |
| 978 | 978 | |
@@ -987,10 +987,10 @@ discard block |
||
| 987 | 987 | */ |
| 988 | 988 | public function setHeader($key, $value) |
| 989 | 989 | { |
| 990 | - $this->headers[$key] = $value; |
|
| 991 | - $headers = array(); |
|
| 990 | + $this->headers[$key]=$value; |
|
| 991 | + $headers=array(); |
|
| 992 | 992 | foreach ($this->headers as $key => $value) { |
| 993 | - $headers[] = $key . ': ' . $value; |
|
| 993 | + $headers[]=$key.': '.$value; |
|
| 994 | 994 | } |
| 995 | 995 | $this->setOpt(CURLOPT_HTTPHEADER, $headers); |
| 996 | 996 | } |
@@ -1006,12 +1006,12 @@ discard block |
||
| 1006 | 1006 | public function setHeaders($headers) |
| 1007 | 1007 | { |
| 1008 | 1008 | foreach ($headers as $key => $value) { |
| 1009 | - $this->headers[$key] = $value; |
|
| 1009 | + $this->headers[$key]=$value; |
|
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | - $headers = array(); |
|
| 1012 | + $headers=array(); |
|
| 1013 | 1013 | foreach ($this->headers as $key => $value) { |
| 1014 | - $headers[] = $key . ': ' . $value; |
|
| 1014 | + $headers[]=$key.': '.$value; |
|
| 1015 | 1015 | } |
| 1016 | 1016 | $this->setOpt(CURLOPT_HTTPHEADER, $headers); |
| 1017 | 1017 | } |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | public function setJsonDecoder($function) |
| 1026 | 1026 | { |
| 1027 | 1027 | if (is_callable($function)) { |
| 1028 | - $this->jsonDecoder = $function; |
|
| 1028 | + $this->jsonDecoder=$function; |
|
| 1029 | 1029 | } |
| 1030 | 1030 | } |
| 1031 | 1031 | |
@@ -1038,7 +1038,7 @@ discard block |
||
| 1038 | 1038 | public function setXmlDecoder($function) |
| 1039 | 1039 | { |
| 1040 | 1040 | if (is_callable($function)) { |
| 1041 | - $this->xmlDecoder = $function; |
|
| 1041 | + $this->xmlDecoder=$function; |
|
| 1042 | 1042 | } |
| 1043 | 1043 | } |
| 1044 | 1044 | |
@@ -1053,17 +1053,17 @@ discard block |
||
| 1053 | 1053 | */ |
| 1054 | 1054 | public function setOpt($option, $value) |
| 1055 | 1055 | { |
| 1056 | - $required_options = array( |
|
| 1056 | + $required_options=array( |
|
| 1057 | 1057 | CURLOPT_RETURNTRANSFER => 'CURLOPT_RETURNTRANSFER', |
| 1058 | 1058 | ); |
| 1059 | 1059 | |
| 1060 | 1060 | if (in_array($option, array_keys($required_options), true) && !($value === true)) { |
| 1061 | - trigger_error($required_options[$option] . ' is a required option', E_USER_WARNING); |
|
| 1061 | + trigger_error($required_options[$option].' is a required option', E_USER_WARNING); |
|
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | - $success = curl_setopt($this->curl, $option, $value); |
|
| 1064 | + $success=curl_setopt($this->curl, $option, $value); |
|
| 1065 | 1065 | if ($success) { |
| 1066 | - $this->options[$option] = $value; |
|
| 1066 | + $this->options[$option]=$value; |
|
| 1067 | 1067 | } |
| 1068 | 1068 | return $success; |
| 1069 | 1069 | } |
@@ -1128,10 +1128,10 @@ discard block |
||
| 1128 | 1128 | * @param $url |
| 1129 | 1129 | * @param $data |
| 1130 | 1130 | */ |
| 1131 | - public function setUrl($url, $data = array()) |
|
| 1131 | + public function setUrl($url, $data=array()) |
|
| 1132 | 1132 | { |
| 1133 | - $this->baseUrl = $url; |
|
| 1134 | - $this->url = $this->buildURL($url, $data); |
|
| 1133 | + $this->baseUrl=$url; |
|
| 1134 | + $this->url=$this->buildURL($url, $data); |
|
| 1135 | 1135 | $this->setOpt(CURLOPT_URL, $this->url); |
| 1136 | 1136 | } |
| 1137 | 1137 | |
@@ -1154,7 +1154,7 @@ discard block |
||
| 1154 | 1154 | */ |
| 1155 | 1155 | public function success($callback) |
| 1156 | 1156 | { |
| 1157 | - $this->successFunction = $callback; |
|
| 1157 | + $this->successFunction=$callback; |
|
| 1158 | 1158 | } |
| 1159 | 1159 | |
| 1160 | 1160 | /** |
@@ -1168,9 +1168,9 @@ discard block |
||
| 1168 | 1168 | public function unsetHeader($key) |
| 1169 | 1169 | { |
| 1170 | 1170 | unset($this->headers[$key]); |
| 1171 | - $headers = array(); |
|
| 1171 | + $headers=array(); |
|
| 1172 | 1172 | foreach ($this->headers as $key => $value) { |
| 1173 | - $headers[] = $key . ': ' . $value; |
|
| 1173 | + $headers[]=$key.': '.$value; |
|
| 1174 | 1174 | } |
| 1175 | 1175 | $this->setOpt(CURLOPT_HTTPHEADER, $headers); |
| 1176 | 1176 | } |
@@ -1196,7 +1196,7 @@ discard block |
||
| 1196 | 1196 | * @param bool $on |
| 1197 | 1197 | * @param resource $output |
| 1198 | 1198 | */ |
| 1199 | - public function verbose($on = true, $output = STDERR) |
|
| 1199 | + public function verbose($on=true, $output=STDERR) |
|
| 1200 | 1200 | { |
| 1201 | 1201 | // Turn off CURLINFO_HEADER_OUT for verbose to work. This has the side |
| 1202 | 1202 | // effect of causing Curl::requestHeaders to be empty. |
@@ -1219,9 +1219,9 @@ discard block |
||
| 1219 | 1219 | |
| 1220 | 1220 | public function __get($name) |
| 1221 | 1221 | { |
| 1222 | - $return = null; |
|
| 1223 | - if (in_array($name, self::$deferredProperties) && is_callable(array($this, $getter = '__get_' . $name))) { |
|
| 1224 | - $return = $this->$name = $this->$getter(); |
|
| 1222 | + $return=null; |
|
| 1223 | + if (in_array($name, self::$deferredProperties) && is_callable(array($this, $getter='__get_'.$name))) { |
|
| 1224 | + $return=$this->$name=$this->$getter(); |
|
| 1225 | 1225 | } |
| 1226 | 1226 | return $return; |
| 1227 | 1227 | } |
@@ -1275,9 +1275,9 @@ discard block |
||
| 1275 | 1275 | * |
| 1276 | 1276 | * @return string |
| 1277 | 1277 | */ |
| 1278 | - private function buildURL($url, $data = array()) |
|
| 1278 | + private function buildURL($url, $data=array()) |
|
| 1279 | 1279 | { |
| 1280 | - return $url . (empty($data) ? '' : '?' . http_build_query($data, '', '&')); |
|
| 1280 | + return $url.(empty($data) ? '' : '?'.http_build_query($data, '', '&')); |
|
| 1281 | 1281 | } |
| 1282 | 1282 | |
| 1283 | 1283 | /** |
@@ -1290,19 +1290,19 @@ discard block |
||
| 1290 | 1290 | */ |
| 1291 | 1291 | private function parseHeaders($raw_headers) |
| 1292 | 1292 | { |
| 1293 | - $raw_headers = preg_split('/\r\n/', $raw_headers, null, PREG_SPLIT_NO_EMPTY); |
|
| 1294 | - $http_headers = []; |
|
| 1293 | + $raw_headers=preg_split('/\r\n/', $raw_headers, null, PREG_SPLIT_NO_EMPTY); |
|
| 1294 | + $http_headers=[]; |
|
| 1295 | 1295 | |
| 1296 | - $raw_headers_count = count($raw_headers); |
|
| 1297 | - for ($i = 1; $i < $raw_headers_count; $i++) { |
|
| 1298 | - list($key, $value) = explode(':', $raw_headers[$i], 2); |
|
| 1299 | - $key = trim($key); |
|
| 1300 | - $value = trim($value); |
|
| 1296 | + $raw_headers_count=count($raw_headers); |
|
| 1297 | + for ($i=1; $i < $raw_headers_count; $i++) { |
|
| 1298 | + list($key, $value)=explode(':', $raw_headers[$i], 2); |
|
| 1299 | + $key=trim($key); |
|
| 1300 | + $value=trim($value); |
|
| 1301 | 1301 | // Use isset() as array_key_exists() and ArrayAccess are not compatible. |
| 1302 | 1302 | if (isset($http_headers[$key])) { |
| 1303 | - $http_headers[$key] .= ',' . $value; |
|
| 1303 | + $http_headers[$key].=','.$value; |
|
| 1304 | 1304 | } else { |
| 1305 | - $http_headers[$key] = $value; |
|
| 1305 | + $http_headers[$key]=$value; |
|
| 1306 | 1306 | } |
| 1307 | 1307 | } |
| 1308 | 1308 | |
@@ -1319,11 +1319,11 @@ discard block |
||
| 1319 | 1319 | */ |
| 1320 | 1320 | private function parseRequestHeaders($raw_headers) |
| 1321 | 1321 | { |
| 1322 | - $request_headers = []; |
|
| 1323 | - list($first_line, $headers) = $this->parseHeaders($raw_headers); |
|
| 1324 | - $request_headers['Request-Line'] = $first_line; |
|
| 1322 | + $request_headers=[]; |
|
| 1323 | + list($first_line, $headers)=$this->parseHeaders($raw_headers); |
|
| 1324 | + $request_headers['Request-Line']=$first_line; |
|
| 1325 | 1325 | foreach ($headers as $key => $value) { |
| 1326 | - $request_headers[$key] = $value; |
|
| 1326 | + $request_headers[$key]=$value; |
|
| 1327 | 1327 | } |
| 1328 | 1328 | return $request_headers; |
| 1329 | 1329 | } |
@@ -1342,22 +1342,22 @@ discard block |
||
| 1342 | 1342 | */ |
| 1343 | 1343 | private function parseResponse($response_headers, $raw_response) |
| 1344 | 1344 | { |
| 1345 | - $response = $raw_response; |
|
| 1345 | + $response=$raw_response; |
|
| 1346 | 1346 | if (isset($response_headers['Content-Type'])) { |
| 1347 | 1347 | if (preg_match($this->jsonPattern, $response_headers['Content-Type'])) { |
| 1348 | - $json_decoder = $this->jsonDecoder; |
|
| 1348 | + $json_decoder=$this->jsonDecoder; |
|
| 1349 | 1349 | if (is_callable($json_decoder)) { |
| 1350 | - $response = $json_decoder($response); |
|
| 1350 | + $response=$json_decoder($response); |
|
| 1351 | 1351 | } |
| 1352 | 1352 | } elseif (preg_match($this->xmlPattern, $response_headers['Content-Type'])) { |
| 1353 | - $xml_decoder = $this->xmlDecoder; |
|
| 1353 | + $xml_decoder=$this->xmlDecoder; |
|
| 1354 | 1354 | if (is_callable($xml_decoder)) { |
| 1355 | - $response = $xml_decoder($response); |
|
| 1355 | + $response=$xml_decoder($response); |
|
| 1356 | 1356 | } |
| 1357 | 1357 | } else { |
| 1358 | - $decoder = $this->defaultDecoder; |
|
| 1358 | + $decoder=$this->defaultDecoder; |
|
| 1359 | 1359 | if (is_callable($decoder)) { |
| 1360 | - $response = $decoder($response); |
|
| 1360 | + $response=$decoder($response); |
|
| 1361 | 1361 | } |
| 1362 | 1362 | } |
| 1363 | 1363 | } |
@@ -1375,20 +1375,20 @@ discard block |
||
| 1375 | 1375 | */ |
| 1376 | 1376 | private function parseResponseHeaders($raw_response_headers) |
| 1377 | 1377 | { |
| 1378 | - $response_header_array = explode("\r\n\r\n", $raw_response_headers); |
|
| 1379 | - $response_header = ''; |
|
| 1380 | - for ($i = count($response_header_array) - 1; $i >= 0; $i--) { |
|
| 1378 | + $response_header_array=explode("\r\n\r\n", $raw_response_headers); |
|
| 1379 | + $response_header=''; |
|
| 1380 | + for ($i=count($response_header_array) - 1; $i >= 0; $i--) { |
|
| 1381 | 1381 | if (stripos($response_header_array[$i], 'HTTP/') === 0) { |
| 1382 | - $response_header = $response_header_array[$i]; |
|
| 1382 | + $response_header=$response_header_array[$i]; |
|
| 1383 | 1383 | break; |
| 1384 | 1384 | } |
| 1385 | 1385 | } |
| 1386 | 1386 | |
| 1387 | - $response_headers = []; |
|
| 1388 | - list($first_line, $headers) = $this->parseHeaders($response_header); |
|
| 1389 | - $response_headers['Status-Line'] = $first_line; |
|
| 1387 | + $response_headers=[]; |
|
| 1388 | + list($first_line, $headers)=$this->parseHeaders($response_header); |
|
| 1389 | + $response_headers['Status-Line']=$first_line; |
|
| 1390 | 1390 | foreach ($headers as $key => $value) { |
| 1391 | - $response_headers[$key] = $value; |
|
| 1391 | + $response_headers[$key]=$value; |
|
| 1392 | 1392 | } |
| 1393 | 1393 | return $response_headers; |
| 1394 | 1394 | } |