/** * @param null|array $data * * @return Resource */ protected function createResource($data) { if (null === $data) { return null; } return Resource::create($this->client, $data); }
/** * @param HttpResponse $response * @param HttpClientInterface $client * * @return Resource * * @throws \RuntimeException */ public static function parse(HttpResponse $response, HttpClientInterface $client) { if (substr($response->getHeader('Content-Type'), 0, 20) !== 'application/hal+json') { throw new \RuntimeException('Invalid content type'); } $data = @json_decode($response->getBody(), true); if ($data === null) { throw new \RuntimeException('Invalid JSON format'); } return Resource::create($client, $data); }