本文整理汇总了PHP中Str::match方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::match方法的具体用法?PHP Str::match怎么用?PHP Str::match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Str
的用法示例。
在下文中一共展示了Str::match方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
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: fromString
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: buildCondition
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: fromString
/**
* 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: referer_match
/**
* Проверяет адрес страницы которая привела пользователя на текущую страницу с шаблоном по "звездочке"
*
* @param string $pattern - путь с маской
* @return boolean
*/
public static function referer_match($pattern)
{
return Str::match($pattern, static::referer());
}