示例#1
0
 /**
  * @param string $syntax
  * @param array  $data
  * @throws NoMatcherFoundException
  * @return array
  */
 public function getMatcherForSyntax($syntax, array $data = array())
 {
     ArgumentChecker::check($syntax, 'string');
     $rawSyntax = $this->getRawSyntax($syntax);
     $endsWith = ' on error ?';
     if ($this->endsWith($rawSyntax, $endsWith)) {
         $rawSyntax = substr($rawSyntax, 0, strlen($rawSyntax) - strlen($endsWith));
     }
     foreach ($this->modules as $module) {
         $reflectionClass = new ReflectionClass($module);
         foreach ($reflectionClass->getMethods() as $method) {
             $doc = $method->getDocComment();
             foreach (explode("\n", $doc) as $line) {
                 $pos = strpos($line, '@syntax');
                 if ($pos !== false) {
                     $s = new Syntax(trim(substr($line, $pos + 7)), $method->getDeclaringClass()->getName() . '::' . $method->getName());
                     if ($s->getRawSyntax() == $rawSyntax) {
                         $class = $s->getClass();
                         $r = array('matcher' => new $class(), 'originalSyntax' => $s->getSyntax());
                         if ($this->endsWith($this->getRawSyntax($syntax), $endsWith)) {
                             $r['on_error'] = $data[count($data) - 1];
                         }
                         return $r;
                     }
                 }
             }
         }
     }
     throw new NoMatcherFoundException(array($syntax));
 }