Пример #1
0
 public function testTags()
 {
     $comment = new \vc\Data\Comment();
     $this->assertSame(array(), $comment->getTags());
     $tag1 = new \vc\Data\Tag("note", "details");
     $this->assertSame($comment, $comment->addTag($tag1));
     $this->assertSame(array($tag1), $comment->getTags());
     $tag2 = new \vc\Data\Tag("note", "details");
     $this->assertSame($comment, $comment->addTag($tag2));
     $this->assertSame(array($tag1, $tag2), $comment->getTags());
 }
Пример #2
0
 /**
  * Parses a comment string into an object
  *
  * @param String $content The text to parse
  * @return \vc\Data\Comment
  */
 public function parse($content)
 {
     $content = trim($content, " */\t\r\n");
     $content = str_replace(array("\r\n", "\n", "\r"), "\n", $content);
     // Clean up the leading white space and astericks on each line
     $content = preg_replace('/^[ \\t\\*]+/m', '', $content);
     // Match any tags and separate them from the text
     if (preg_match_all('/^@(\\w+)/m', $content, $tags, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
         $offset = reset($tags);
         $text = trim(substr($content, 0, $offset[0][1]));
     } else {
         $text = $content;
     }
     $comment = new \vc\Data\Comment($text);
     // Build and add each tag to this comment
     foreach ($tags as $key => $tag) {
         $comment->addTag(self::buildTag($content, $tag, isset($tags[$key + 1]) ? $tags[$key + 1] : NULL));
     }
     return $comment;
 }