Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 public function testAdd()
 {
     $comment = new Comment('');
     $this->assertFalse($comment->has('tag'));
     $comment->add('tag', 'value');
     $this->assertTrue($comment->has('tag'));
     $this->assertEquals('value', $comment->get('tag'));
 }