1 | <?php |
||
5 | class Response |
||
6 | { |
||
7 | /** |
||
8 | * HTTP Status code |
||
9 | * |
||
10 | * @int |
||
11 | */ |
||
12 | protected $status; |
||
13 | |||
14 | /** |
||
15 | * Headers. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $headers; |
||
20 | |||
21 | /** |
||
22 | * Contents. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $body; |
||
27 | |||
28 | /** |
||
29 | * Assign dependencies. |
||
30 | * |
||
31 | * @param int $status |
||
32 | * @param array $headers |
||
33 | * @param string $body |
||
34 | */ |
||
35 | 26 | public function __construct($status = 200, array $headers = [], $body = null) |
|
41 | |||
42 | /** |
||
43 | * Extracts the relevant content from the response. |
||
44 | * |
||
45 | * @return array|mixed |
||
46 | */ |
||
47 | 4 | public function result() |
|
48 | { |
||
49 | 4 | $body = $this->body; |
|
50 | 4 | $content = json_decode($body, true); |
|
51 | |||
52 | 4 | if (JSON_ERROR_NONE !== json_last_error()) { |
|
53 | 2 | return $body; |
|
54 | } |
||
55 | |||
56 | 2 | return $content['result']; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Get query limit headers. |
||
61 | * |
||
62 | * @param array $limits |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | 2 | public function limits(array $limits = []) |
|
80 | |||
81 | /** |
||
82 | * Get body. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | 4 | public function getBody() |
|
90 | |||
91 | /** |
||
92 | * Get HTTP status code. |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | 4 | public function getStatus() |
|
100 | |||
101 | /** |
||
102 | * Get response headers. |
||
103 | * |
||
104 | * @return array |
||
105 | */ |
||
106 | 2 | public function getHeaders() |
|
110 | |||
111 | /** |
||
112 | * Get a response header by key. |
||
113 | * |
||
114 | * @param string $key |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | 6 | public function getHeader($key) |
|
124 | } |
||
125 |