@@ -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,56 +360,56 @@ 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 ||$this->curlErrorCode==7) |
|
| 373 | - && $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 || $this->curlErrorCode == 7) |
|
| 373 | + && $i++ < $this->retryCount) { |
|
| 374 | 374 | continue; |
| 375 | 375 | } |
| 376 | 376 | break; |
| 377 | 377 | } |
| 378 | - $this->curlErrorMessage = curl_error($this->curl); |
|
| 378 | + $this->curlErrorMessage=curl_error($this->curl); |
|
| 379 | 379 | } else { |
| 380 | - $this->rawResponse = curl_multi_getcontent($ch); |
|
| 381 | - $this->curlErrorMessage = curl_error($ch); |
|
| 380 | + $this->rawResponse=curl_multi_getcontent($ch); |
|
| 381 | + $this->curlErrorMessage=curl_error($ch); |
|
| 382 | 382 | } |
| 383 | - $this->curlError = !($this->curlErrorCode === 0); |
|
| 383 | + $this->curlError=!($this->curlErrorCode === 0); |
|
| 384 | 384 | // Include additional error code information in error message when possible. |
| 385 | 385 | if ($this->curlError && function_exists('curl_strerror')) { |
| 386 | - $this->curlErrorMessage = |
|
| 387 | - curl_strerror($this->curlErrorCode) . ( |
|
| 388 | - empty($this->curlErrorMessage) ? '' : ': ' . $this->curlErrorMessage |
|
| 386 | + $this->curlErrorMessage= |
|
| 387 | + curl_strerror($this->curlErrorCode).( |
|
| 388 | + empty($this->curlErrorMessage) ? '' : ': '.$this->curlErrorMessage |
|
| 389 | 389 | ); |
| 390 | 390 | print_r($this->rawResponse); |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - $this->httpStatusCode = $this->getInfo(CURLINFO_HTTP_CODE); |
|
| 394 | - $this->httpError = in_array(floor($this->httpStatusCode / 100), array(4, 5)); |
|
| 395 | - $this->error = $this->curlError || $this->httpError; |
|
| 396 | - $this->errorCode = $this->error ? ($this->curlError ? $this->curlErrorCode : $this->httpStatusCode) : 0; |
|
| 393 | + $this->httpStatusCode=$this->getInfo(CURLINFO_HTTP_CODE); |
|
| 394 | + $this->httpError=in_array(floor($this->httpStatusCode / 100), array(4, 5)); |
|
| 395 | + $this->error=$this->curlError || $this->httpError; |
|
| 396 | + $this->errorCode=$this->error ? ($this->curlError ? $this->curlErrorCode : $this->httpStatusCode) : 0; |
|
| 397 | 397 | |
| 398 | 398 | // NOTE: CURLINFO_HEADER_OUT set to true is required for requestHeaders |
| 399 | 399 | // to not be empty (e.g. $curl->setOpt(CURLINFO_HEADER_OUT, true);). |
| 400 | 400 | if ($this->getOpt(CURLINFO_HEADER_OUT) === true) { |
| 401 | - $this->requestHeaders = $this->parseRequestHeaders($this->getInfo(CURLINFO_HEADER_OUT)); |
|
| 401 | + $this->requestHeaders=$this->parseRequestHeaders($this->getInfo(CURLINFO_HEADER_OUT)); |
|
| 402 | 402 | } |
| 403 | - $this->responseHeaders = $this->parseResponseHeaders($this->rawResponseHeaders); |
|
| 404 | - $this->response = $this->parseResponse($this->responseHeaders, $this->rawResponse); |
|
| 403 | + $this->responseHeaders=$this->parseResponseHeaders($this->rawResponseHeaders); |
|
| 404 | + $this->response=$this->parseResponse($this->responseHeaders, $this->rawResponse); |
|
| 405 | 405 | |
| 406 | - $this->httpErrorMessage = ''; |
|
| 406 | + $this->httpErrorMessage=''; |
|
| 407 | 407 | if ($this->error) { |
| 408 | 408 | if (isset($this->responseHeaders['Status-Line'])) { |
| 409 | - $this->httpErrorMessage = $this->responseHeaders['Status-Line']; |
|
| 409 | + $this->httpErrorMessage=$this->responseHeaders['Status-Line']; |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | - $this->errorMessage = $this->curlError ? $this->curlErrorMessage : $this->httpErrorMessage; |
|
| 412 | + $this->errorMessage=$this->curlError ? $this->curlErrorMessage : $this->httpErrorMessage; |
|
| 413 | 413 | |
| 414 | 414 | if (!$this->error) { |
| 415 | 415 | $this->call($this->successFunction); |
@@ -436,11 +436,11 @@ discard block |
||
| 436 | 436 | * |
| 437 | 437 | * @return mixed Returns the value provided by exec. |
| 438 | 438 | */ |
| 439 | - public function get($url, $data = array()) |
|
| 439 | + public function get($url, $data=array()) |
|
| 440 | 440 | { |
| 441 | 441 | if (is_array($url)) { |
| 442 | - $data = $url; |
|
| 443 | - $url = $this->baseUrl; |
|
| 442 | + $data=$url; |
|
| 443 | + $url=$this->baseUrl; |
|
| 444 | 444 | } |
| 445 | 445 | $this->setUrl($url, $data); |
| 446 | 446 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'GET'); |
@@ -456,13 +456,13 @@ discard block |
||
| 456 | 456 | * |
| 457 | 457 | * @return mixed |
| 458 | 458 | */ |
| 459 | - public function getInfo($opt = null) |
|
| 459 | + public function getInfo($opt=null) |
|
| 460 | 460 | { |
| 461 | - $args = array(); |
|
| 462 | - $args[] = $this->curl; |
|
| 461 | + $args=array(); |
|
| 462 | + $args[]=$this->curl; |
|
| 463 | 463 | |
| 464 | 464 | if (func_num_args()) { |
| 465 | - $args[] = $opt; |
|
| 465 | + $args[]=$opt; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | return call_user_func_array('curl_getinfo', $args); |
@@ -490,11 +490,11 @@ discard block |
||
| 490 | 490 | * |
| 491 | 491 | * @return string |
| 492 | 492 | */ |
| 493 | - public function head($url, $data = array()) |
|
| 493 | + public function head($url, $data=array()) |
|
| 494 | 494 | { |
| 495 | 495 | if (is_array($url)) { |
| 496 | - $data = $url; |
|
| 497 | - $url = $this->baseUrl; |
|
| 496 | + $data=$url; |
|
| 497 | + $url=$this->baseUrl; |
|
| 498 | 498 | } |
| 499 | 499 | $this->setUrl($url, $data); |
| 500 | 500 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'HEAD'); |
@@ -514,9 +514,9 @@ discard block |
||
| 514 | 514 | public function headerCallback($ch, $header) |
| 515 | 515 | { |
| 516 | 516 | if (preg_match('/^Set-Cookie:\s*([^=]+)=([^;]+)/mi', $header, $cookie) === 1) { |
| 517 | - $this->responseCookies[$cookie[1]] = trim($cookie[2], " \n\r\t\0\x0B"); |
|
| 517 | + $this->responseCookies[$cookie[1]]=trim($cookie[2], " \n\r\t\0\x0B"); |
|
| 518 | 518 | } |
| 519 | - $this->rawResponseHeaders .= $header; |
|
| 519 | + $this->rawResponseHeaders.=$header; |
|
| 520 | 520 | return strlen($header); |
| 521 | 521 | } |
| 522 | 522 | |
@@ -529,11 +529,11 @@ discard block |
||
| 529 | 529 | * |
| 530 | 530 | * @return string |
| 531 | 531 | */ |
| 532 | - public function options($url, $data = array()) |
|
| 532 | + public function options($url, $data=array()) |
|
| 533 | 533 | { |
| 534 | 534 | if (is_array($url)) { |
| 535 | - $data = $url; |
|
| 536 | - $url = $this->baseUrl; |
|
| 535 | + $data=$url; |
|
| 536 | + $url=$this->baseUrl; |
|
| 537 | 537 | } |
| 538 | 538 | $this->setUrl($url, $data); |
| 539 | 539 | $this->removeHeader('Content-Length'); |
@@ -550,11 +550,11 @@ discard block |
||
| 550 | 550 | * |
| 551 | 551 | * @return string |
| 552 | 552 | */ |
| 553 | - public function patch($url, $data = array()) |
|
| 553 | + public function patch($url, $data=array()) |
|
| 554 | 554 | { |
| 555 | 555 | if (is_array($url)) { |
| 556 | - $data = $url; |
|
| 557 | - $url = $this->baseUrl; |
|
| 556 | + $data=$url; |
|
| 557 | + $url=$this->baseUrl; |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | 560 | if (is_array($data) && empty($data)) { |
@@ -592,12 +592,12 @@ discard block |
||
| 592 | 592 | * [2] https://github.com/php/php-src/pull/531 |
| 593 | 593 | * [3] http://php.net/ChangeLog-5.php#5.5.11 |
| 594 | 594 | */ |
| 595 | - public function post($url, $data = array(), $follow_303_with_post = false) |
|
| 595 | + public function post($url, $data=array(), $follow_303_with_post=false) |
|
| 596 | 596 | { |
| 597 | 597 | if (is_array($url)) { |
| 598 | - $follow_303_with_post = (bool)$data; |
|
| 599 | - $data = $url; |
|
| 600 | - $url = $this->baseUrl; |
|
| 598 | + $follow_303_with_post=(bool) $data; |
|
| 599 | + $data=$url; |
|
| 600 | + $url=$this->baseUrl; |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | $this->setUrl($url); |
@@ -634,15 +634,15 @@ discard block |
||
| 634 | 634 | * |
| 635 | 635 | * @return string |
| 636 | 636 | */ |
| 637 | - public function put($url, $data = array()) |
|
| 637 | + public function put($url, $data=array()) |
|
| 638 | 638 | { |
| 639 | 639 | if (is_array($url)) { |
| 640 | - $data = $url; |
|
| 641 | - $url = $this->baseUrl; |
|
| 640 | + $data=$url; |
|
| 641 | + $url=$this->baseUrl; |
|
| 642 | 642 | } |
| 643 | 643 | $this->setUrl($url); |
| 644 | 644 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'PUT'); |
| 645 | - $put_data = $this->buildPostData($data); |
|
| 645 | + $put_data=$this->buildPostData($data); |
|
| 646 | 646 | if (empty($this->options[CURLOPT_INFILE]) && empty($this->options[CURLOPT_INFILESIZE])) { |
| 647 | 647 | if (is_string($put_data)) { |
| 648 | 648 | $this->setHeader('Content-Length', strlen($put_data)); |
@@ -663,15 +663,15 @@ discard block |
||
| 663 | 663 | * |
| 664 | 664 | * @return string |
| 665 | 665 | */ |
| 666 | - public function search($url, $data = array()) |
|
| 666 | + public function search($url, $data=array()) |
|
| 667 | 667 | { |
| 668 | 668 | if (is_array($url)) { |
| 669 | - $data = $url; |
|
| 670 | - $url = $this->baseUrl; |
|
| 669 | + $data=$url; |
|
| 670 | + $url=$this->baseUrl; |
|
| 671 | 671 | } |
| 672 | 672 | $this->setUrl($url); |
| 673 | 673 | $this->setOpt(CURLOPT_CUSTOMREQUEST, 'SEARCH'); |
| 674 | - $put_data = $this->buildPostData($data); |
|
| 674 | + $put_data=$this->buildPostData($data); |
|
| 675 | 675 | if (empty($this->options[CURLOPT_INFILE]) && empty($this->options[CURLOPT_INFILESIZE])) { |
| 676 | 676 | if (is_string($put_data)) { |
| 677 | 677 | $this->setHeader('Content-Length', strlen($put_data)); |
@@ -690,10 +690,10 @@ discard block |
||
| 690 | 690 | * @param $username |
| 691 | 691 | * @param $password |
| 692 | 692 | */ |
| 693 | - public function setBasicAuthentication($username, $password = '') |
|
| 693 | + public function setBasicAuthentication($username, $password='') |
|
| 694 | 694 | { |
| 695 | 695 | $this->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_BASIC); |
| 696 | - $this->setOpt(CURLOPT_USERPWD, $username . ':' . $password); |
|
| 696 | + $this->setOpt(CURLOPT_USERPWD, $username.':'.$password); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | /** |
@@ -703,10 +703,10 @@ discard block |
||
| 703 | 703 | * @param $username |
| 704 | 704 | * @param $password |
| 705 | 705 | */ |
| 706 | - public function setDigestAuthentication($username, $password = '') |
|
| 706 | + public function setDigestAuthentication($username, $password='') |
|
| 707 | 707 | { |
| 708 | 708 | $this->setOpt(CURLOPT_HTTPAUTH, CURLAUTH_DIGEST); |
| 709 | - $this->setOpt(CURLOPT_USERPWD, $username . ':' . $password); |
|
| 709 | + $this->setOpt(CURLOPT_USERPWD, $username.':'.$password); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -718,27 +718,27 @@ discard block |
||
| 718 | 718 | */ |
| 719 | 719 | public function setCookie($key, $value) |
| 720 | 720 | { |
| 721 | - $name_chars = array(); |
|
| 721 | + $name_chars=array(); |
|
| 722 | 722 | foreach (str_split($key) as $name_char) { |
| 723 | 723 | if (!isset($this->rfc2616[$name_char])) { |
| 724 | - $name_chars[] = rawurlencode($name_char); |
|
| 724 | + $name_chars[]=rawurlencode($name_char); |
|
| 725 | 725 | } else { |
| 726 | - $name_chars[] = $name_char; |
|
| 726 | + $name_chars[]=$name_char; |
|
| 727 | 727 | } |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | - $value_chars = array(); |
|
| 730 | + $value_chars=array(); |
|
| 731 | 731 | foreach (str_split($value) as $value_char) { |
| 732 | 732 | if (!isset($this->rfc6265[$value_char])) { |
| 733 | - $value_chars[] = rawurlencode($value_char); |
|
| 733 | + $value_chars[]=rawurlencode($value_char); |
|
| 734 | 734 | } else { |
| 735 | - $value_chars[] = $value_char; |
|
| 735 | + $value_chars[]=$value_char; |
|
| 736 | 736 | } |
| 737 | 737 | } |
| 738 | 738 | |
| 739 | - $this->cookies[implode('', $name_chars)] = implode('', $value_chars); |
|
| 740 | - $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function ($k, $v) { |
|
| 741 | - return $k . '=' . $v; |
|
| 739 | + $this->cookies[implode('', $name_chars)]=implode('', $value_chars); |
|
| 740 | + $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function($k, $v) { |
|
| 741 | + return $k.'='.$v; |
|
| 742 | 742 | }, array_keys($this->cookies), array_values($this->cookies)))); |
| 743 | 743 | } |
| 744 | 744 | |
@@ -751,29 +751,29 @@ discard block |
||
| 751 | 751 | public function setCookies($cookies) |
| 752 | 752 | { |
| 753 | 753 | foreach ($cookies as $key => $value) { |
| 754 | - $name_chars = array(); |
|
| 754 | + $name_chars=array(); |
|
| 755 | 755 | foreach (str_split($key) as $name_char) { |
| 756 | 756 | if (!isset($this->rfc2616[$name_char])) { |
| 757 | - $name_chars[] = rawurlencode($name_char); |
|
| 757 | + $name_chars[]=rawurlencode($name_char); |
|
| 758 | 758 | } else { |
| 759 | - $name_chars[] = $name_char; |
|
| 759 | + $name_chars[]=$name_char; |
|
| 760 | 760 | } |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | - $value_chars = array(); |
|
| 763 | + $value_chars=array(); |
|
| 764 | 764 | foreach (str_split($value) as $value_char) { |
| 765 | 765 | if (!isset($this->rfc6265[$value_char])) { |
| 766 | - $value_chars[] = rawurlencode($value_char); |
|
| 766 | + $value_chars[]=rawurlencode($value_char); |
|
| 767 | 767 | } else { |
| 768 | - $value_chars[] = $value_char; |
|
| 768 | + $value_chars[]=$value_char; |
|
| 769 | 769 | } |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | - $this->cookies[implode('', $name_chars)] = implode('', $value_chars); |
|
| 772 | + $this->cookies[implode('', $name_chars)]=implode('', $value_chars); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | - $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function ($k, $v) { |
|
| 776 | - return $k . '=' . $v; |
|
| 775 | + $this->setOpt(CURLOPT_COOKIE, implode('; ', array_map(function($k, $v) { |
|
| 776 | + return $k.'='.$v; |
|
| 777 | 777 | }, array_keys($this->cookies), array_values($this->cookies)))); |
| 778 | 778 | } |
| 779 | 779 | |
@@ -813,14 +813,14 @@ discard block |
||
| 813 | 813 | { |
| 814 | 814 | // Make compatible with PHP version both before and after 5.5.0. PHP 5.5.0 added the cURL resource as the first |
| 815 | 815 | // argument to the CURLOPT_PROGRESSFUNCTION callback. |
| 816 | - $gte_v550 = version_compare(PHP_VERSION, '5.5.0') >= 0; |
|
| 816 | + $gte_v550=version_compare(PHP_VERSION, '5.5.0') >= 0; |
|
| 817 | 817 | if ($gte_v550) { |
| 818 | - $callback = function ($resource, $download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 818 | + $callback=function($resource, $download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 819 | 819 | // Abort the transfer when $downloaded bytes exceeds maximum $bytes by returning a non-zero value. |
| 820 | 820 | return $downloaded > $bytes ? 1 : 0; |
| 821 | 821 | }; |
| 822 | 822 | } else { |
| 823 | - $callback = function ($download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 823 | + $callback=function($download_size, $downloaded, $upload_size, $uploaded) use ($bytes) { |
|
| 824 | 824 | return $downloaded > $bytes ? 1 : 0; |
| 825 | 825 | }; |
| 826 | 826 | } |
@@ -899,20 +899,20 @@ discard block |
||
| 899 | 899 | */ |
| 900 | 900 | public function setDefaultJsonDecoder() |
| 901 | 901 | { |
| 902 | - $args = func_get_args(); |
|
| 903 | - $this->jsonDecoder = function ($response) use ($args) { |
|
| 902 | + $args=func_get_args(); |
|
| 903 | + $this->jsonDecoder=function($response) use ($args) { |
|
| 904 | 904 | array_unshift($args, $response); |
| 905 | 905 | |
| 906 | 906 | // Call json_decode() without the $options parameter in PHP |
| 907 | 907 | // versions less than 5.4.0 as the $options parameter was added in |
| 908 | 908 | // PHP version 5.4.0. |
| 909 | 909 | if (version_compare(PHP_VERSION, '5.4.0', '<')) { |
| 910 | - $args = array_slice($args, 0, 3); |
|
| 910 | + $args=array_slice($args, 0, 3); |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | - $json_obj = call_user_func_array('json_decode', $args); |
|
| 913 | + $json_obj=call_user_func_array('json_decode', $args); |
|
| 914 | 914 | if (!($json_obj === null)) { |
| 915 | - $response = $json_obj; |
|
| 915 | + $response=$json_obj; |
|
| 916 | 916 | } |
| 917 | 917 | return $response; |
| 918 | 918 | }; |
@@ -925,10 +925,10 @@ discard block |
||
| 925 | 925 | */ |
| 926 | 926 | public function setDefaultXmlDecoder() |
| 927 | 927 | { |
| 928 | - $this->xmlDecoder = function ($response) { |
|
| 929 | - $xml_obj = @simplexml_load_string($response); |
|
| 928 | + $this->xmlDecoder=function($response) { |
|
| 929 | + $xml_obj=@simplexml_load_string($response); |
|
| 930 | 930 | if (!($xml_obj === false)) { |
| 931 | - $response = $xml_obj; |
|
| 931 | + $response=$xml_obj; |
|
| 932 | 932 | } |
| 933 | 933 | return $response; |
| 934 | 934 | }; |
@@ -940,15 +940,15 @@ discard block |
||
| 940 | 940 | * @access public |
| 941 | 941 | * @param $decoder string|callable |
| 942 | 942 | */ |
| 943 | - public function setDefaultDecoder($decoder = 'json') |
|
| 943 | + public function setDefaultDecoder($decoder='json') |
|
| 944 | 944 | { |
| 945 | 945 | if (is_callable($decoder)) { |
| 946 | - $this->defaultDecoder = $decoder; |
|
| 946 | + $this->defaultDecoder=$decoder; |
|
| 947 | 947 | } else { |
| 948 | 948 | if ($decoder === 'json') { |
| 949 | - $this->defaultDecoder = $this->jsonDecoder; |
|
| 949 | + $this->defaultDecoder=$this->jsonDecoder; |
|
| 950 | 950 | } elseif ($decoder === 'xml') { |
| 951 | - $this->defaultDecoder = $this->xmlDecoder; |
|
| 951 | + $this->defaultDecoder=$this->xmlDecoder; |
|
| 952 | 952 | } |
| 953 | 953 | } |
| 954 | 954 | } |
@@ -970,10 +970,10 @@ discard block |
||
| 970 | 970 | */ |
| 971 | 971 | public function setDefaultUserAgent() |
| 972 | 972 | { |
| 973 | - $user_agent = 'puck client' . self::VERSION . ' mini'; |
|
| 974 | - $user_agent .= ' PHP/' . PHP_VERSION; |
|
| 975 | - $curl_version = curl_version(); |
|
| 976 | - $user_agent .= ' curl/' . $curl_version['version']; |
|
| 973 | + $user_agent='puck client'.self::VERSION.' mini'; |
|
| 974 | + $user_agent.=' PHP/'.PHP_VERSION; |
|
| 975 | + $curl_version=curl_version(); |
|
| 976 | + $user_agent.=' curl/'.$curl_version['version']; |
|
| 977 | 977 | $this->setUserAgent($user_agent); |
| 978 | 978 | } |
| 979 | 979 | |
@@ -988,10 +988,10 @@ discard block |
||
| 988 | 988 | */ |
| 989 | 989 | public function setHeader($key, $value) |
| 990 | 990 | { |
| 991 | - $this->headers[$key] = $value; |
|
| 992 | - $headers = array(); |
|
| 991 | + $this->headers[$key]=$value; |
|
| 992 | + $headers=array(); |
|
| 993 | 993 | foreach ($this->headers as $key => $value) { |
| 994 | - $headers[] = $key . ': ' . $value; |
|
| 994 | + $headers[]=$key.': '.$value; |
|
| 995 | 995 | } |
| 996 | 996 | $this->setOpt(CURLOPT_HTTPHEADER, $headers); |
| 997 | 997 | } |
@@ -1007,12 +1007,12 @@ discard block |
||
| 1007 | 1007 | public function setHeaders($headers) |
| 1008 | 1008 | { |
| 1009 | 1009 | foreach ($headers as $key => $value) { |
| 1010 | - $this->headers[$key] = $value; |
|
| 1010 | + $this->headers[$key]=$value; |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | - $headers = array(); |
|
| 1013 | + $headers=array(); |
|
| 1014 | 1014 | foreach ($this->headers as $key => $value) { |
| 1015 | - $headers[] = $key . ': ' . $value; |
|
| 1015 | + $headers[]=$key.': '.$value; |
|
| 1016 | 1016 | } |
| 1017 | 1017 | $this->setOpt(CURLOPT_HTTPHEADER, $headers); |
| 1018 | 1018 | } |
@@ -1026,7 +1026,7 @@ discard block |
||
| 1026 | 1026 | public function setJsonDecoder($function) |
| 1027 | 1027 | { |
| 1028 | 1028 | if (is_callable($function)) { |
| 1029 | - $this->jsonDecoder = $function; |
|
| 1029 | + $this->jsonDecoder=$function; |
|
| 1030 | 1030 | } |
| 1031 | 1031 | } |
| 1032 | 1032 | |
@@ -1039,7 +1039,7 @@ discard block |
||
| 1039 | 1039 | public function setXmlDecoder($function) |
| 1040 | 1040 | { |
| 1041 | 1041 | if (is_callable($function)) { |
| 1042 | - $this->xmlDecoder = $function; |
|
| 1042 | + $this->xmlDecoder=$function; |
|
| 1043 | 1043 | } |
| 1044 | 1044 | } |
| 1045 | 1045 | |
@@ -1054,17 +1054,17 @@ discard block |
||
| 1054 | 1054 | */ |
| 1055 | 1055 | public function setOpt($option, $value) |
| 1056 | 1056 | { |
| 1057 | - $required_options = array( |
|
| 1057 | + $required_options=array( |
|
| 1058 | 1058 | CURLOPT_RETURNTRANSFER => 'CURLOPT_RETURNTRANSFER', |
| 1059 | 1059 | ); |
| 1060 | 1060 | |
| 1061 | 1061 | if (in_array($option, array_keys($required_options), true) && !($value === true)) { |
| 1062 | - trigger_error($required_options[$option] . ' is a required option', E_USER_WARNING); |
|
| 1062 | + trigger_error($required_options[$option].' is a required option', E_USER_WARNING); |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | - $success = curl_setopt($this->curl, $option, $value); |
|
| 1065 | + $success=curl_setopt($this->curl, $option, $value); |
|
| 1066 | 1066 | if ($success) { |
| 1067 | - $this->options[$option] = $value; |
|
| 1067 | + $this->options[$option]=$value; |
|
| 1068 | 1068 | } |
| 1069 | 1069 | return $success; |
| 1070 | 1070 | } |
@@ -1129,10 +1129,10 @@ discard block |
||
| 1129 | 1129 | * @param $url |
| 1130 | 1130 | * @param $data |
| 1131 | 1131 | */ |
| 1132 | - public function setUrl($url, $data = array()) |
|
| 1132 | + public function setUrl($url, $data=array()) |
|
| 1133 | 1133 | { |
| 1134 | - $this->baseUrl = $url; |
|
| 1135 | - $this->url = $this->buildURL($url, $data); |
|
| 1134 | + $this->baseUrl=$url; |
|
| 1135 | + $this->url=$this->buildURL($url, $data); |
|
| 1136 | 1136 | $this->setOpt(CURLOPT_URL, $this->url); |
| 1137 | 1137 | } |
| 1138 | 1138 | |
@@ -1155,7 +1155,7 @@ discard block |
||
| 1155 | 1155 | */ |
| 1156 | 1156 | public function success($callback) |
| 1157 | 1157 | { |
| 1158 | - $this->successFunction = $callback; |
|
| 1158 | + $this->successFunction=$callback; |
|
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | /** |
@@ -1169,9 +1169,9 @@ discard block |
||
| 1169 | 1169 | public function unsetHeader($key) |
| 1170 | 1170 | { |
| 1171 | 1171 | unset($this->headers[$key]); |
| 1172 | - $headers = array(); |
|
| 1172 | + $headers=array(); |
|
| 1173 | 1173 | foreach ($this->headers as $key => $value) { |
| 1174 | - $headers[] = $key . ': ' . $value; |
|
| 1174 | + $headers[]=$key.': '.$value; |
|
| 1175 | 1175 | } |
| 1176 | 1176 | $this->setOpt(CURLOPT_HTTPHEADER, $headers); |
| 1177 | 1177 | } |
@@ -1197,7 +1197,7 @@ discard block |
||
| 1197 | 1197 | * @param bool $on |
| 1198 | 1198 | * @param resource $output |
| 1199 | 1199 | */ |
| 1200 | - public function verbose($on = true, $output = STDERR) |
|
| 1200 | + public function verbose($on=true, $output=STDERR) |
|
| 1201 | 1201 | { |
| 1202 | 1202 | // Turn off CURLINFO_HEADER_OUT for verbose to work. This has the side |
| 1203 | 1203 | // effect of causing Curl::requestHeaders to be empty. |
@@ -1220,9 +1220,9 @@ discard block |
||
| 1220 | 1220 | |
| 1221 | 1221 | public function __get($name) |
| 1222 | 1222 | { |
| 1223 | - $return = null; |
|
| 1224 | - if (in_array($name, self::$deferredProperties) && is_callable(array($this, $getter = '__get_' . $name))) { |
|
| 1225 | - $return = $this->$name = $this->$getter(); |
|
| 1223 | + $return=null; |
|
| 1224 | + if (in_array($name, self::$deferredProperties) && is_callable(array($this, $getter='__get_'.$name))) { |
|
| 1225 | + $return=$this->$name=$this->$getter(); |
|
| 1226 | 1226 | } |
| 1227 | 1227 | return $return; |
| 1228 | 1228 | } |
@@ -1276,9 +1276,9 @@ discard block |
||
| 1276 | 1276 | * |
| 1277 | 1277 | * @return string |
| 1278 | 1278 | */ |
| 1279 | - private function buildURL($url, $data = array()) |
|
| 1279 | + private function buildURL($url, $data=array()) |
|
| 1280 | 1280 | { |
| 1281 | - return $url . (empty($data) ? '' : '?' . http_build_query($data, '', '&')); |
|
| 1281 | + return $url.(empty($data) ? '' : '?'.http_build_query($data, '', '&')); |
|
| 1282 | 1282 | } |
| 1283 | 1283 | |
| 1284 | 1284 | /** |
@@ -1291,19 +1291,19 @@ discard block |
||
| 1291 | 1291 | */ |
| 1292 | 1292 | private function parseHeaders($raw_headers) |
| 1293 | 1293 | { |
| 1294 | - $raw_headers = preg_split('/\r\n/', $raw_headers, null, PREG_SPLIT_NO_EMPTY); |
|
| 1295 | - $http_headers = []; |
|
| 1294 | + $raw_headers=preg_split('/\r\n/', $raw_headers, null, PREG_SPLIT_NO_EMPTY); |
|
| 1295 | + $http_headers=[]; |
|
| 1296 | 1296 | |
| 1297 | - $raw_headers_count = count($raw_headers); |
|
| 1298 | - for ($i = 1; $i < $raw_headers_count; $i++) { |
|
| 1299 | - list($key, $value) = explode(':', $raw_headers[$i], 2); |
|
| 1300 | - $key = trim($key); |
|
| 1301 | - $value = trim($value); |
|
| 1297 | + $raw_headers_count=count($raw_headers); |
|
| 1298 | + for ($i=1; $i < $raw_headers_count; $i++) { |
|
| 1299 | + list($key, $value)=explode(':', $raw_headers[$i], 2); |
|
| 1300 | + $key=trim($key); |
|
| 1301 | + $value=trim($value); |
|
| 1302 | 1302 | // Use isset() as array_key_exists() and ArrayAccess are not compatible. |
| 1303 | 1303 | if (isset($http_headers[$key])) { |
| 1304 | - $http_headers[$key] .= ',' . $value; |
|
| 1304 | + $http_headers[$key].=','.$value; |
|
| 1305 | 1305 | } else { |
| 1306 | - $http_headers[$key] = $value; |
|
| 1306 | + $http_headers[$key]=$value; |
|
| 1307 | 1307 | } |
| 1308 | 1308 | } |
| 1309 | 1309 | |
@@ -1320,11 +1320,11 @@ discard block |
||
| 1320 | 1320 | */ |
| 1321 | 1321 | private function parseRequestHeaders($raw_headers) |
| 1322 | 1322 | { |
| 1323 | - $request_headers = []; |
|
| 1324 | - list($first_line, $headers) = $this->parseHeaders($raw_headers); |
|
| 1325 | - $request_headers['Request-Line'] = $first_line; |
|
| 1323 | + $request_headers=[]; |
|
| 1324 | + list($first_line, $headers)=$this->parseHeaders($raw_headers); |
|
| 1325 | + $request_headers['Request-Line']=$first_line; |
|
| 1326 | 1326 | foreach ($headers as $key => $value) { |
| 1327 | - $request_headers[$key] = $value; |
|
| 1327 | + $request_headers[$key]=$value; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | return $request_headers; |
| 1330 | 1330 | } |
@@ -1343,22 +1343,22 @@ discard block |
||
| 1343 | 1343 | */ |
| 1344 | 1344 | private function parseResponse($response_headers, $raw_response) |
| 1345 | 1345 | { |
| 1346 | - $response = $raw_response; |
|
| 1346 | + $response=$raw_response; |
|
| 1347 | 1347 | if (isset($response_headers['Content-Type'])) { |
| 1348 | 1348 | if (preg_match($this->jsonPattern, $response_headers['Content-Type'])) { |
| 1349 | - $json_decoder = $this->jsonDecoder; |
|
| 1349 | + $json_decoder=$this->jsonDecoder; |
|
| 1350 | 1350 | if (is_callable($json_decoder)) { |
| 1351 | - $response = $json_decoder($response); |
|
| 1351 | + $response=$json_decoder($response); |
|
| 1352 | 1352 | } |
| 1353 | 1353 | } elseif (preg_match($this->xmlPattern, $response_headers['Content-Type'])) { |
| 1354 | - $xml_decoder = $this->xmlDecoder; |
|
| 1354 | + $xml_decoder=$this->xmlDecoder; |
|
| 1355 | 1355 | if (is_callable($xml_decoder)) { |
| 1356 | - $response = $xml_decoder($response); |
|
| 1356 | + $response=$xml_decoder($response); |
|
| 1357 | 1357 | } |
| 1358 | 1358 | } else { |
| 1359 | - $decoder = $this->defaultDecoder; |
|
| 1359 | + $decoder=$this->defaultDecoder; |
|
| 1360 | 1360 | if (is_callable($decoder)) { |
| 1361 | - $response = $decoder($response); |
|
| 1361 | + $response=$decoder($response); |
|
| 1362 | 1362 | } |
| 1363 | 1363 | } |
| 1364 | 1364 | } |
@@ -1376,20 +1376,20 @@ discard block |
||
| 1376 | 1376 | */ |
| 1377 | 1377 | private function parseResponseHeaders($raw_response_headers) |
| 1378 | 1378 | { |
| 1379 | - $response_header_array = explode("\r\n\r\n", $raw_response_headers); |
|
| 1380 | - $response_header = ''; |
|
| 1381 | - for ($i = count($response_header_array) - 1; $i >= 0; $i--) { |
|
| 1379 | + $response_header_array=explode("\r\n\r\n", $raw_response_headers); |
|
| 1380 | + $response_header=''; |
|
| 1381 | + for ($i=count($response_header_array) - 1; $i >= 0; $i--) { |
|
| 1382 | 1382 | if (stripos($response_header_array[$i], 'HTTP/') === 0) { |
| 1383 | - $response_header = $response_header_array[$i]; |
|
| 1383 | + $response_header=$response_header_array[$i]; |
|
| 1384 | 1384 | break; |
| 1385 | 1385 | } |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | - $response_headers = []; |
|
| 1389 | - list($first_line, $headers) = $this->parseHeaders($response_header); |
|
| 1390 | - $response_headers['Status-Line'] = $first_line; |
|
| 1388 | + $response_headers=[]; |
|
| 1389 | + list($first_line, $headers)=$this->parseHeaders($response_header); |
|
| 1390 | + $response_headers['Status-Line']=$first_line; |
|
| 1391 | 1391 | foreach ($headers as $key => $value) { |
| 1392 | - $response_headers[$key] = $value; |
|
| 1392 | + $response_headers[$key]=$value; |
|
| 1393 | 1393 | } |
| 1394 | 1394 | return $response_headers; |
| 1395 | 1395 | } |