| 1 |
<?php |
| 2 |
|
| 3 |
declare (strict_types=1); |
| 4 |
namespace WCPOS\Vendor\Sentry\HttpClient; |
| 5 |
|
| 6 |
final class Response |
| 7 |
{ |
| 8 |
/** |
| 9 |
* @var int The HTTP status code |
| 10 |
*/ |
| 11 |
private $statusCode; |
| 12 |
/** |
| 13 |
* @var string[] |
| 14 |
*/ |
| 15 |
private $headerNames = []; |
| 16 |
/** |
| 17 |
* @var string[][] |
| 18 |
*/ |
| 19 |
private $headers; |
| 20 |
/** |
| 21 |
* @var string The cURL error and error message |
| 22 |
*/ |
| 23 |
private $error; |
| 24 |
/** |
| 25 |
* @param string[][] $headers |
| 26 |
*/ |
| 27 |
public function __construct(int $statusCode, array $headers, string $error) |
| 28 |
{ |
| 29 |
$this->statusCode = $statusCode; |
| 30 |
$this->headers = $headers; |
| 31 |
$this->error = $error; |
| 32 |
foreach ($headers as $name => $value) { |
| 33 |
$this->headerNames[\strtolower($name)] = $name; |
| 34 |
} |
| 35 |
} |
| 36 |
public function getStatusCode() : int |
| 37 |
{ |
| 38 |
return $this->statusCode; |
| 39 |
} |
| 40 |
public function isSuccess() : bool |
| 41 |
{ |
| 42 |
return $this->statusCode >= 200 && $this->statusCode <= 299; |
| 43 |
} |
| 44 |
public function hasHeader(string $name) : bool |
| 45 |
{ |
| 46 |
return isset($this->headerNames[\strtolower($name)]); |
| 47 |
} |
| 48 |
/** |
| 49 |
* @return string[] |
| 50 |
*/ |
| 51 |
public function getHeader(string $header) : array |
| 52 |
{ |
| 53 |
if (!$this->hasHeader($header)) { |
| 54 |
return []; |
| 55 |
} |
| 56 |
$header = $this->headerNames[\strtolower($header)]; |
| 57 |
return $this->headers[$header]; |
| 58 |
} |
| 59 |
public function getHeaderLine(string $name) : string |
| 60 |
{ |
| 61 |
$value = $this->getHeader($name); |
| 62 |
if (empty($value)) { |
| 63 |
return ''; |
| 64 |
} |
| 65 |
return \implode(',', $value); |
| 66 |
} |
| 67 |
public function getError() : string |
| 68 |
{ |
| 69 |
return $this->error; |
| 70 |
} |
| 71 |
public function hasError() : bool |
| 72 |
{ |
| 73 |
return $this->error !== ''; |
| 74 |
} |
| 75 |
} |
| 76 |
|