示例#1
0
 public function make(string $name, UrlInterface $url, ResponseInterface $response) : HttpResource
 {
     $headers = $response->headers();
     if ($response->statusCode()->value() !== StatusCode::codes()->get('OK') || !$headers->has('Content-Type') || (string) $headers->get('Content-Type')->values()->current() !== 'application/json') {
         throw new InvalidArgumentException();
     }
     $data = json_decode((string) $response->body(), true);
     $data['url'] = (string) $url;
     return $this->denormalizer->denormalize($data, HttpResource::class, null, ['name' => $name]);
 }