phpDocumentor\Reflection\DocBlock\Tag::createInstance PHP Method

createInstance() final public static method

Factory method responsible for instantiating the correct sub type.
final public static createInstance ( string $tag_line, DocBlock $docblock = null, phpDocumentor\Reflection\DocBlock\Location $location = null ) : static
$tag_line string The text for this tag, including description.
$docblock phpDocumentor\Reflection\DocBlock The DocBlock which this tag belongs to.
$location phpDocumentor\Reflection\DocBlock\Location Location of the tag.
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);
    }

Usage Example

 /**
  * Generate docblock.
  *
  * @param string $class
  * @param array $properties
  * @param array $methods
  * @return mixed
  */
 public function docblock($class, $properties, $methods)
 {
     $phpdoc = new DocBlock('');
     $phpdoc->setText($class);
     foreach ($properties as $property) {
         $tag = Tag::createInstance("@{$property['type']} {$property['return']} {$property['name']}", $phpdoc);
         $phpdoc->appendTag($tag);
     }
     foreach ($methods as $method) {
         $tag = Tag::createInstance("@method {$method['type']} {$method['return']} {$method['name']}({$method['arguments']})", $phpdoc);
         $phpdoc->appendTag($tag);
     }
     $serializer = new DocBlockSerializer();
     $docComment = $serializer->getDocComment($phpdoc);
     return $docComment;
 }
All Usage Examples Of phpDocumentor\Reflection\DocBlock\Tag::createInstance