예제 #1
0
 /**
  * Factory method responsible for instantiating the correct sub type.
  *
  * @param string   $tag_line The text for this tag, including description.
  * @param DocBlock $docblock The DocBlock which this tag belongs to.
  * @param Location $location Location of the tag.
  *
  * @throws \InvalidArgumentException if an invalid tag line was presented.
  *
  * @return static A new tag object.
  */
 public static final function createInstance($tag_line, DocBlock $docblock = null, Location $location = null)
 {
     if (!preg_match('/^@(' . self::REGEX_TAGNAME . ')(?:\\s*([^\\s].*)|$)?/us', $tag_line, $matches)) {
         throw new \InvalidArgumentException('Invalid tag_line detected: ' . $tag_line);
     }
     $handler = __CLASS__;
     if (isset(self::$tagHandlerMappings[$matches[1]])) {
         $handler = self::$tagHandlerMappings[$matches[1]];
     } elseif (isset($docblock)) {
         $tagName = (string) new Type\Collection(array($matches[1]), $docblock->getContext());
         if (isset(self::$tagHandlerMappings[$tagName])) {
             $handler = self::$tagHandlerMappings[$tagName];
         }
     }
     return new $handler($matches[1], isset($matches[2]) ? $matches[2] : '', $docblock, $location);
 }
예제 #2
0
 /**
  * Generate a DocBlock comment.
  *
  * @param DocBlock The DocBlock to serialize.
  * 
  * @return string The serialized doc block.
  */
 public function getDocComment(DocBlock $docblock)
 {
     $indent = str_repeat($this->indentString, $this->indent);
     $firstIndent = $this->isFirstLineIndented ? $indent : '';
     $text = $docblock->getText();
     if ($this->lineLength) {
         //3 === strlen(' * ')
         $wrapLength = $this->lineLength - strlen($indent) - 3;
         $text = wordwrap($text, $wrapLength);
     }
     $text = str_replace("\n", "\n{$indent} * ", $text);
     $comment = "{$firstIndent}/**\n{$indent} * {$text}\n{$indent} *\n";
     /** @var Tag $tag */
     foreach ($docblock->getTags() as $tag) {
         $tagText = (string) $tag;
         if ($this->lineLength) {
             $tagText = wordwrap($tagText, $wrapLength);
         }
         $tagText = str_replace("\n", "\n{$indent} * ", $tagText);
         $comment .= "{$indent} * {$tagText}\n";
     }
     $comment .= $indent . ' */';
     return $comment;
 }
 /**
  * @param $route
  *
  * @return bool
  */
 private function isRouteVisibleForDocumentation($route)
 {
     list($class, $method) = explode('@', $route);
     $reflection = new ReflectionClass($class);
     $comment = $reflection->getMethod($method)->getDocComment();
     if ($comment) {
         $phpdoc = new DocBlock($comment);
         return collect($phpdoc->getTags())->filter(function ($tag) use($route) {
             return $tag->getName() === 'hideFromAPIDocumentation';
         })->isEmpty();
     }
     return true;
 }
 /**
  * @param  string  $route
  *
  * @return string
  */
 protected function getRouteGroup($route)
 {
     list($class, $method) = explode('@', $route);
     $reflection = new ReflectionClass($class);
     $comment = $reflection->getDocComment();
     if ($comment) {
         $phpdoc = new DocBlock($comment);
         foreach ($phpdoc->getTags() as $tag) {
             if ($tag->getName() === 'resource') {
                 return $tag->getContent();
             }
         }
     }
     return 'general';
 }
예제 #5
0
    /**
     * @depends testConstructWithTagsOnly
     * @covers \phpDocumentor\Reflection\DocBlock::getTagsByName
     * 
     * @return void
     */
    public function testGetTagsByNameMultipleMatch()
    {
        $fixture = <<<DOCBLOCK
/**
 * @param string
 * @param int
 * @return void
 */
DOCBLOCK;
        $object = new DocBlock($fixture);
        $this->assertEmpty($object->getTagsByName('category'));
        $this->assertCount(1, $object->getTagsByName('return'));
        $this->assertCount(2, $object->getTagsByName('param'));
    }