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]); }
/** * @return void */ public function send(ResponseInterface $response) { header(sprintf('HTTP/%s %s %s', $response->protocolVersion(), $response->statusCode(), $response->reasonPhrase())); if (!$response->headers()->has('date')) { header((string) new Date(new DateValue(new \DateTime()))); } foreach ($response->headers() as $header) { header((string) $header, false); } echo (string) $response->body(); if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); } }