Beispiel #1
0
 public function parse($comment)
 {
     // remove comment characters and normalize
     $comment = preg_replace(array('#^/\\*\\*\\s*#', '#\\s*\\*/$#', '#^\\s*\\*#m'), '', trim($comment));
     $comment = "\n" . preg_replace('/(\\r\\n|\\r)/', "\n", $comment);
     $this->position = 'desc';
     $this->comment = $comment;
     $this->lineno = 1;
     $this->cursor = 0;
     $doc = new DocBlockNode();
     while ($this->cursor < strlen($this->comment)) {
         switch ($this->position) {
             case 'desc':
                 list($short, $long) = $this->parseDesc();
                 $doc->setShortDesc($short);
                 $doc->setLongDesc($long);
                 break;
             case 'tag':
                 try {
                     list($type, $values) = $this->parseTag();
                     $doc->addTag($type, $values);
                 } catch (\LogicException $e) {
                     $doc->addError($e->getMessage());
                 }
                 break;
         }
         if (preg_match('/\\s*$/As', $this->comment, $match, null, $this->cursor)) {
             $this->cursor = strlen($this->comment);
         }
     }
     return $doc;
 }
 private function createDocblock(array $elements)
 {
     $docblock = new DocBlockNode();
     foreach ($elements as $key => $value) {
         switch ($key) {
             case 'tags':
                 foreach ($value as $tag => $value) {
                     if (!is_array($value)) {
                         $value = array($value);
                     }
                     foreach ($value as $v) {
                         $docblock->addTag($tag, $v);
                     }
                 }
                 break;
             default:
                 $method = 'set' . $key;
                 $docblock->{$method}($value);
         }
     }
     return $docblock;
 }
Beispiel #3
0
 public function parse($comment, ParserContext $context)
 {
     $docBlock = null;
     $errorMessage = '';
     try {
         $docBlockContext = new DocBlock\Context($context->getNamespace(), $context->getAliases() ?: array());
         $docBlock = new DocBlock((string) $comment, $docBlockContext);
     } catch (\Exception $e) {
         $errorMessage = $e->getMessage();
     }
     $result = new DocBlockNode();
     if ($errorMessage) {
         $result->addError($errorMessage);
         return $result;
     }
     $result->setShortDesc($docBlock->getShortDescription());
     $result->setLongDesc((string) $docBlock->getLongDescription());
     foreach ($docBlock->getTags() as $tag) {
         $result->addTag($tag->getName(), $this->parseTag($tag));
     }
     return $result;
 }