public function testClassAnnotationInterface() { $comment = new Comment(''); $comment->addAnnotation('someclass', 'whatever'); $comment->addAnnotation('someclass', 'also whatever'); $this->assertFalse($comment->hasAnnotationType('whatever')); $this->assertTrue($comment->hasAnnotationType('someclass')); $this->assertEquals(['whatever', 'also whatever'], $comment->getAnnotationType('someclass')); }
/** * Parses a documentation comment. * * @param string $commentString * @param $target * * @return Comment */ public function parse($commentString, $target) { // Extract the description part of the comment block $commentString = $this->stripCommentDecoration($commentString); $parts = preg_split('/^\\s*(?=@[a-zA-Z]+)/m', $commentString, 2); $comment = new Comment(trim($parts[0])); if (!isset($parts[1])) { return $comment; } $trimmed = trim($parts[1]); if (empty($trimmed)) { return $comment; } $pattern = '/(\'(?:\\\\.|[^\'\\\\])*\'|"(?:\\\\.|[^"\\\\])*"|[@(),={}]|\\s+|(?<![:])[:](?![:]))/'; $flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY; $this->parts = preg_split($pattern, $parts[1], -1, $flags); $this->position = -1; while (isset($this->parts[++$this->position])) { if ($this->parts[$this->position] === '@') { list($name, $parameters, $isClass) = $this->parseTag(); if ($isClass) { $className = $this->getFullyQualifiedName($name); $this->saveState(); $comment->addAnnotation($className, $this->container->readClass($className, $parameters, $target)); $this->restoreState(); } else { $comment->add($name, $parameters); } } } return $comment; }