/** * {@inheritDoc} */ public function canMatch($pattern) { if (!is_string($pattern)) { return false; } return $this->parser->hasValidSyntax($pattern) && $this->parser->parse($pattern)->is('string'); }
/** * @param $value * @param $pattern * @return bool * @throws \Coduo\PHPMatcher\Exception\UnknownExpanderException */ private function allExpandersMatch($value, $pattern) { $typePattern = $this->parser->parse($pattern); if (!$typePattern->matchExpanders($value)) { $this->error = $typePattern->getError(); return false; } return true; }
/** * Reaplce each type pattern (@string@.startsWith("lorem")) with placeholder, in order * to use preg_quote without destroying pattern & expanders. * * before replacement: "/users/@integer@.greaterThan(200)/active" * after replacement: "/users/__PLACEHOLDER0__/active" * * @param string $patternRegex * @return TypePattern[]|array */ private function replaceTypePatternsWithPlaceholders(&$patternRegex) { $patternsReplacedWithRegex = array(); preg_match_all(self::PATTERN_REGEXP, $patternRegex, $matches); foreach ($matches[0] as $index => $typePatternString) { $typePattern = $this->parser->parse($typePatternString); $patternsReplacedWithRegex[] = $typePattern; $patternRegex = str_replace($typePatternString, sprintf(self::PATTERN_REGEXP_PLACEHOLDER_TEMPLATE, $index), $patternRegex); } return $patternsReplacedWithRegex; }