public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface { $start = $this->clock->now(); if (!$response->headers()->has('Content-Type') || !($header = $response->headers()->get('Content-Type')) instanceof ContentType || !$header->values()->current()->parameters()->contains('charset')) { return $attributes; } return $attributes->put(self::key(), new Attribute(self::key(), $header->values()->current()->parameters()->get('charset')->value(), $this->clock->now()->elapsedSince($start)->milliseconds())); }
public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface { $start = $this->clock->now(); if (!$response->headers()->has('Content-Type') || !$response->headers()->get('Content-Type') instanceof ContentType) { return $attributes; } return $attributes->put(self::key(), new Attribute(self::key(), MediaType::fromString((string) $response->headers()->get('Content-Type')->values()->current()), $this->clock->now()->elapsedSince($start)->milliseconds())); }
public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface { $start = $this->clock->now(); if (!$response->headers()->has('Content-Language') || !$response->headers()->get('Content-Language') instanceof ContentLanguage) { return $attributes; } return $attributes->put(self::key(), new Attribute(self::key(), $response->headers()->get('Content-Language')->values()->reduce(new Set('string'), function (Set $carry, ContentLanguageValue $language) : Set { return $carry->add((string) $language); }), $this->clock->now()->elapsedSince($start)->milliseconds())); }
public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface { $start = $this->clock->now(); if (!$response->headers()->has('Link') || !$response->headers()->get('Link') instanceof Link) { return $attributes; } $links = $response->headers()->get('Link')->values()->filter(function (LinkValue $value) : bool { return $value->relationship() === 'canonical'; }); if ($links->size() !== 1) { return $attributes; } return $attributes->put(self::key(), new Attribute(self::key(), $this->resolver->resolve($request, $attributes, $links->current()->url()), $this->clock->now()->elapsedSince($start)->milliseconds())); }
public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface { $start = $this->clock->now(); if (!$response->headers()->has('Cache-Control')) { return $attributes; } $directives = $response->headers()->get('Cache-Control')->values()->filter(function (HeaderValueInterface $value) : bool { return $value instanceof SharedMaxAge; }); if ($directives->size() !== 1) { return $attributes; } return $attributes->put(self::key(), new Attribute(self::key(), $this->clock->now()->goForward(new Second($directives->current()->age())), $this->clock->now()->elapsedSince($start)->milliseconds())); }
/** * @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(); } }
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]); }
public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface { $start = $this->clock->now(); if (!$response->headers()->has('Link') || !$response->headers()->get('Link') instanceof Link) { return $attributes; } $alternates = $response->headers()->get('Link')->values()->reduce(new Map(UrlInterface::class, 'string'), function (Map $links, LinkValue $header) : Map { if ($header->relationship() !== 'alternate' || !$header->parameters()->contains('hreflang')) { return $links; } return $links->put($header->url(), $header->parameters()->get('hreflang')->value()); })->groupBy(function (UrlInterface $url, string $language) : string { return $language; })->map(function (string $language, SequenceInterface $links) use($request, $attributes) : SequenceInterface { return $links->map(function (Pair $link) use($request, $attributes) : UrlInterface { return $this->resolver->resolve($request, $attributes, $link->key()); }); })->reduce(new Map('string', AttributeInterface::class), function (Map $languages, string $language, SequenceInterface $links) use($start) : Map { return $languages->put($language, new Alternate($language, $links->reduce(new Set(UrlInterface::class), function (Set $links, UrlInterface $link) : Set { return $links->add($link); }), $this->clock->now()->elapsedSince($start)->milliseconds())); }); return $attributes->put(self::key(), new Alternates($alternates)); }