Пример #1
0
 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()));
 }
Пример #2
0
 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')));
 }
Пример #3
0
 private function buildCondition(ComparatorInterface $specification) : SequenceInterface
 {
     $property = new Str($specification->property());
     switch (true) {
         case $this->meta->properties()->contains($specification->property()):
             return $this->buildPropertyCondition($specification);
         case $property->match('/[a-zA-Z]+(\\.[a-zA-Z]+)+/'):
             return $this->buildSubPropertyCondition($specification);
     }
 }
Пример #4
0
 /**
  * Build an object out of a string
  *
  * @param string $string
  *
  * @return self
  */
 public static function fromString(string $string) : self
 {
     $string = new Str($string);
     $pattern = sprintf('~%s/[\\w\\-.]+(\\+\\w+)?([;,] [\\w\\-.]+=[\\w\\-.]+)?~', self::topLevels()->join('|'));
     if (!$string->match($pattern)) {
         throw new InvalidMediaTypeStringException();
     }
     $splits = $string->pregSplit('~[;,] ~');
     $matches = $splits->get(0)->getMatches(sprintf('~^(?<topLevel>%s)/(?<subType>[\\w\\-.]+)(\\+(?<suffix>\\w+))?$~', self::topLevels()->join('|')));
     $topLevel = $matches->get('topLevel');
     $subType = $matches->get('subType');
     $suffix = $matches->hasKey('suffix') ? $matches->get('suffix') : '';
     $params = new Map('string', ParameterInterface::class);
     $splits->shift()->each(function (int $idx, Str $param) use(&$params) {
         $matches = $param->getMatches('~^(?<key>[\\w\\-.]+)=(?<value>[\\w\\-.]+)$~');
         $params = $params->put((string) $matches->get('key'), new Parameter((string) $matches->get('key'), (string) $matches->get('value')));
     });
     return new self((string) $topLevel, (string) $subType, (string) $suffix, $params);
 }
Пример #5
0
 /**
  * Проверяет адрес страницы которая привела пользователя на текущую страницу с шаблоном по "звездочке"
  *
  * @param string $pattern - путь с маской
  * @return boolean
  */
 public static function referer_match($pattern)
 {
     return Str::match($pattern, static::referer());
 }