Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function canMatch($pattern)
 {
     if (!is_string($pattern)) {
         return false;
     }
     return $this->parser->hasValidSyntax($pattern) && $this->parser->parse($pattern)->is('string');
 }
Exemplo n.º 2
0
 public function test_expanders_that_takes_other_expanders_as_arguments()
 {
     $pattern = "@type@.expander(expander(\"test\"), expander(1))";
     $expanders = $this->parser->getAST($pattern)->getExpanders();
     $firstExpander = new Expander("expander");
     $firstExpander->addArgument("test");
     $secondExpander = new Expander("expander");
     $secondExpander->addArgument(1);
     $this->assertEquals($expanders[0]->getArguments(), array($firstExpander, $secondExpander));
 }
Exemplo n.º 3
0
 /**
  * @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;
 }
Exemplo n.º 4
0
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * @expectedException \Coduo\PHPMatcher\Exception\PatternException
  * @expectedExceptionMessage [Syntax Error] line 0, col 25: Error: Expected "string, number, boolean or null argument", got "not"
  */
 public function test_not_argument_after_comma()
 {
     $this->parser->getAST("@type@.expander('string',not_argument");
 }