1 | <?php |
||
12 | final class Response |
||
13 | { |
||
14 | /** |
||
15 | * @var integer |
||
16 | */ |
||
17 | private $httpCode; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | private $headers; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $body; |
||
28 | |||
29 | /** |
||
30 | * Create a new instance of Response |
||
31 | * |
||
32 | * @param int $httpCode The http status of the response. |
||
33 | * @param array $headers An array where each header key has an array of values |
||
34 | * @param array $body The response from the API |
||
35 | * |
||
36 | * @throws InvalidArgumentException Throw if $httpCode is not an integer between 100 and 600 |
||
37 | */ |
||
38 | public function __construct(int $httpCode = 300, array $headers = [], array $body = []) |
||
48 | |||
49 | /** |
||
50 | * Returns the HTTP status code of the response. |
||
51 | * |
||
52 | * @return integer |
||
53 | */ |
||
54 | public function getHttpCode() : int |
||
58 | |||
59 | /** |
||
60 | * Returns an array representing the response from the API. |
||
61 | * |
||
62 | * @return array |
||
63 | */ |
||
64 | public function getResponse() : array |
||
68 | |||
69 | /** |
||
70 | * Returns the parsed response headers from the API. |
||
71 | * |
||
72 | * @return array Array where each header key has an array of values. |
||
73 | */ |
||
74 | public function getResponseHeaders() : array |
||
78 | |||
79 | public static function fromPsr7Response(ResponseInterface $response) |
||
87 | |||
88 | private function decodeBody(string $json) : array |
||
100 | |||
101 | private static function ensureJson() |
||
112 | } |
||
113 |