123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- declare(strict_types=1);
- namespace catcher\library\client;
- use GuzzleHttp\Promise\Promise;
- class Response implements \ArrayAccess
- {
-
- protected $response;
- public function __construct($response)
- {
- $this->response = $response;
- }
-
- public function body()
- {
- return $this->response->getBody();
- }
-
- public function contents()
- {
- return $this->body()->getContents();
- }
-
- public function json():array
- {
- return \json_decode($this->contents(), true);
- }
-
- public function status():int
- {
- return $this->response->getStatusCode();
- }
-
- public function ok():bool
- {
- return $this->status() == 200;
- }
-
- public function successful():bool
- {
- return $this->status() >= 200 && $this->status() < 300;
- }
-
- public function failed():bool
- {
- return $this->status() >= 400;
- }
-
- public function headers(): array
- {
- return $this->response->getHeaders();
- }
-
- public function then(callable $response, callable $exception)
- {
- return $this->response->then($response, $exception);
- }
-
- public function __call($name, $arguments)
- {
-
- return $this->response->{$name}(...$arguments);
- }
-
- public function offsetExists($offset)
- {
-
- return isset($this->json()[$offset]);
- }
-
- public function offsetGet($offset)
- {
-
- return $this->json()[$offset];
- }
-
- public function offsetSet($offset, $value)
- {
-
- }
- public function offsetUnset($offset)
- {
-
- }
- }
|