public function matches($string, &$annotations) { $annotations = array(); $annotationMatcher = new AnnotationMatcher(); while (true) { if (preg_match('~(?P<leadingSpace>\\s)?(?=@)~', $string, $matches, PREG_OFFSET_CAPTURE)) { $offset = $matches[0][1]; if (isset($matches['leadingSpace'])) { $offset++; } $string = substr($string, $offset); } else { // no more annotations break; } if (($length = $annotationMatcher->matches($string, $data)) !== false) { $string = substr($string, $length); list($name, $params) = $data; $annotations[$name][] = $params; } else { // Move on ! $string = substr($string, 1); } } }
public function matches($string, &$annotations) { $annotations = array(); $annotation_matcher = new AnnotationMatcher(); while (true) { if (preg_match('/\\s(?=@)/', $string, $matches, PREG_OFFSET_CAPTURE)) { $offset = $matches[0][1] + 1; $string = substr($string, $offset); } else { return; // no more annotations } if (($length = $annotation_matcher->matches($string, $data)) !== false) { $string = substr($string, $length); list($name, $params) = $data; $annotations[$name][] = $params; } } }
public function testAnnotationMatcherShouldMatchAlsoBrackets() { $matcher = new AnnotationMatcher(); $this->assertEqual($matcher->matches('@Annotation()', $value), 13); $this->assertEqual($value, array('Annotation', array())); }