public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface { $start = $this->clock->now(); if (!$this->isHtml($attributes)) { return $attributes; } $document = $this->reader->read($response->body()); try { $metas = (new Elements('meta'))((new Head())($document)); } catch (ElementNotFoundException $e) { return $attributes; } $meta = $metas->filter(function (ElementInterface $meta) : bool { return $meta->attributes()->contains('name') && $meta->attributes()->get('name')->value() === 'apple-itunes-app' && $meta->attributes()->contains('content'); }); if ($meta->size() !== 1) { return $attributes; } $content = $meta->current()->attributes()->get('content')->value(); $content = new Str($content); if (!$content->match(self::PATTERN)) { return $attributes; } $matches = $content->getMatches(self::PATTERN); return $attributes->put(self::key(), new Attribute(self::key(), (string) $matches['uri'], $this->clock->now()->elapsedSince($start)->milliseconds())); }
public static function fromString(string $type, Types $types) : TypeInterface { $type = new Str($type); if (!$type->match(self::PATTERN)) { throw new InvalidArgumentException(); } return new self($types->build((string) $type->getMatches(self::PATTERN)->get('inner'))); }
public function make(Str $name, Str $value) : HeaderInterface { if ((string) $name->toLower() !== 'content-type') { throw new InvalidArgumentException(); } $matches = $value->getMatches('~(?<type>[\\w*]+)/(?<subType>[\\w*]+)(?<params>(; ?\\w+=\\"?[\\w\\-.]+\\"?)+)?~'); return new ContentType(new ContentTypeValue((string) $matches->get('type'), (string) $matches->get('subType'), $this->buildParams($matches->hasKey('params') ? $matches->get('params') : new Str('')))); }