1 | <?php |
||
8 | class Response |
||
9 | { |
||
10 | /** @var ResponseInterface */ |
||
11 | protected $response; |
||
12 | |||
13 | /** @var bool */ |
||
14 | protected $throwErrors; |
||
15 | |||
16 | /** |
||
17 | * @param ResponseInterface $response |
||
18 | * @param bool $throwErrors |
||
19 | * |
||
20 | * @return Response |
||
21 | */ |
||
22 | public static function createFromResponse(ResponseInterface $response, $throwErrors = false) |
||
23 | { |
||
24 | return new self($response, $throwErrors); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @param ResponseInterface $response |
||
29 | * @param bool $throwErrors |
||
30 | */ |
||
31 | public function __construct(ResponseInterface $response, $throwErrors = false) |
||
32 | { |
||
33 | $this->response = $response; |
||
34 | $this->throwErrors = $throwErrors; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @return int |
||
39 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
40 | */ |
||
41 | public function status(): int |
||
42 | { |
||
43 | return $this->response->getStatusCode(); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @return bool |
||
48 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
49 | */ |
||
50 | public function isSuccess(): bool |
||
51 | { |
||
52 | return $this->status() >= 200 && $this->status() < 300; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return bool |
||
57 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
58 | */ |
||
59 | public function isOk(): bool |
||
60 | { |
||
61 | return $this->isSuccess(); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @return bool |
||
66 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
67 | */ |
||
68 | public function isRedirect(): bool |
||
69 | { |
||
70 | return $this->status() >= 300 && $this->status() < 400; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return bool |
||
75 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
76 | */ |
||
77 | public function isClientError(): bool |
||
78 | { |
||
79 | return $this->status() >= 400 && $this->status() < 500; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @return bool |
||
84 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
85 | */ |
||
86 | public function isServerError(): bool |
||
87 | { |
||
88 | return $this->status() >= 500; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @return ResponseInterface |
||
93 | */ |
||
94 | public function response() |
||
95 | { |
||
96 | return $this->response; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @return string |
||
101 | * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface |
||
102 | * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface |
||
103 | * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface |
||
104 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
105 | */ |
||
106 | public function body(): string |
||
107 | { |
||
108 | return $this->response->getContent($this->throwErrors); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @return string |
||
113 | * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface |
||
114 | * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface |
||
115 | * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface |
||
116 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
117 | */ |
||
118 | public function asString(): string |
||
119 | { |
||
120 | return $this->body(); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @return mixed |
||
125 | * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface |
||
126 | * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface |
||
127 | * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface |
||
128 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
129 | */ |
||
130 | public function asObject() |
||
134 | |||
135 | /** |
||
136 | * @return \Illuminate\Support\Collection<mixed> |
||
|
|||
137 | * |
||
138 | * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface |
||
139 | * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface |
||
140 | * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface |
||
141 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
142 | */ |
||
143 | public function asCollection(): Collection |
||
147 | |||
148 | /** |
||
149 | * @return mixed |
||
150 | * |
||
151 | * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface |
||
152 | * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface |
||
153 | * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface |
||
154 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
155 | */ |
||
156 | public function asArray() |
||
160 | |||
161 | /** |
||
162 | * @return resource |
||
163 | */ |
||
164 | public function toStream() |
||
165 | { |
||
166 | if (method_exists($this->response, 'toStream')) { |
||
167 | return $this->response->toStream($this->throwErrors); |
||
168 | } |
||
169 | |||
170 | throw new \BadMethodCallException('method toStream does not exists'); |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * @return bool |
||
175 | * |
||
176 | * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface |
||
177 | * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface |
||
178 | * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface |
||
179 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
180 | */ |
||
181 | public function isJson(): bool |
||
185 | |||
186 | /** |
||
187 | * @param string $header |
||
188 | * |
||
189 | * @return mixed|string |
||
190 | * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface |
||
191 | * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface |
||
192 | * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface |
||
193 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
194 | */ |
||
195 | public function header(string $header) |
||
203 | |||
204 | /** |
||
205 | * @param array<mixed> $headers |
||
206 | * |
||
207 | * @return array<String> |
||
208 | */ |
||
209 | protected function normalizeHeaders(array $headers) |
||
215 | |||
216 | /** |
||
217 | * @return array<String> |
||
218 | * |
||
219 | * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface |
||
220 | * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface |
||
221 | * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface |
||
222 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
223 | */ |
||
224 | public function headers(): array |
||
228 | |||
229 | /** |
||
230 | * @return string |
||
231 | */ |
||
232 | public function requestUrl(): string |
||
236 | |||
237 | /** |
||
238 | * @return float |
||
239 | */ |
||
240 | public function executionTime(): float |
||
244 | |||
245 | /** |
||
246 | * @return array|mixed|null |
||
247 | */ |
||
248 | public function customData() |
||
252 | |||
253 | /** |
||
254 | * @return array|mixed|null |
||
255 | */ |
||
256 | public function info() |
||
260 | |||
261 | /** |
||
262 | * @return mixed|string |
||
263 | * |
||
264 | * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface |
||
265 | * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface |
||
266 | * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface |
||
267 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
268 | */ |
||
269 | public function contentType() |
||
273 | |||
274 | /** |
||
275 | * @return mixed|string |
||
276 | * |
||
277 | * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface |
||
278 | * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface |
||
279 | * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface |
||
280 | * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface |
||
281 | */ |
||
282 | public function userAgent() |
||
286 | } |
||
287 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.