1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74:
<?php
/**
* Erply Books API PHP client
*
* @author Rene Korss <rene@koren.ee>
* @copyright Copyright (c) 2020 Rene Korss (https://koren.ee)
* @license MIT
*/
namespace Koren\ErplyBooks\Response;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
abstract class Response implements ResponseInterface
{
/**
* Response
* @var \GuzzleHttp\Psr7\Response
*/
protected $response = null;
/**
* Body
* @var object
*/
protected $body = null;
/**
* Error(s)
* @var mixed
*/
protected $error = null;
/**
* Constructor
*
* @param \GuzzleHttp\Psr7\Response $response Response object
*/
public function __construct(GuzzleResponse $response)
{
$this->response = $response;
$this->body = json_decode($this->response->getBody());
if (isset($this->body->exception)) {
$this->error = $this->body;
}
}
/**
* Get error
*
* @return mixed Null, if no error, object otherwise
*/
public function getError()
{
return $this->error;
}
/**
* Magic method so we can still call original response methods
*
* @ignore
* @codeCoverageIgnore
*/
public function __call($name, $arguments)
{
if (method_exists($this->response, $name)) {
return call_user_func_array([$this->response, $name], $arguments);
}
return false;
}
}