/** * @param ApiCallData $data * * @return ApiResponseInterface * * @throws \Exception */ public static function create(ApiCallData $data) { $type = $data->getResponseType(); if (!class_exists($type)) { throw new \Exception("Type Class '" . $type . "', could not be loaded"); } $interfaces = class_implements($type); if ($type == '\\Exception' || $type === '\\Packaged\\Api\\Exceptions\\ApiException' || in_array('\\Packaged\\Api\\Exceptions\\ApiException', $interfaces) || array_key_exists('Exception', class_parents($type))) { $code = $data->getStatusCode(); if (!is_numeric($code)) { $code = 500; } $exception = new $type($data->getStatusMessage(), $code); $rawData = $data->getRawResult(); if (is_object($rawData)) { Objects::hydrate($exception, $rawData); } throw $exception; } else { if (in_array('Packaged\\Api\\Interfaces\\ApiResponseInterface', $interfaces)) { $class = new $type(); /** * @var $class \Packaged\Api\Interfaces\ApiResponseInterface */ $class->setApiCallData($data); return $class; } else { throw new ApiException("An invalid message type was used '" . $type . "'"); } } }
/** * @param ApiCallData $callData * * @return ApiResponseInterface|static */ public function setApiCallData(ApiCallData $callData) { $this->_apiCallData = $callData; $data = $callData->getRawResult(); $this->hydrate($data); }