PHP hacktoberfest docblocks
Need help with ReflectionDocBlock?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.
phpDocumentor
8.3K Stars 88 Forks MIT License 559 Commits 14 Opened issues

Services available

Need anything else?

License: MIT Qa workflow Coveralls Coverage Scrutinizer Code Coverage Scrutinizer Code Quality Stable Version Unstable Version

ReflectionDocBlock

Introduction

The ReflectionDocBlock component of phpDocumentor provides a DocBlock parser that is 100% compatible with the PHPDoc standard.

With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.

Installation

composer require phpdocumentor/reflection-docblock

Usage

In order to parse the DocBlock one needs a DocBlockFactory that can be instantiated using its

createInstance
factory method like this:
$factory  = \phpDocumentor\Reflection\DocBlockFactory::createInstance();

Then we can use the

create
method of the factory to interpret the DocBlock. Please note that it is also possible to provide a class that has the
getDocComment()
method, such as an object of type
ReflectionClass
, the create method will read that if it exists.
$docComment = <<create($docComment);

The

create
method will yield an object of type
\phpDocumentor\Reflection\DocBlock
whose methods can be queried:
// Contains the summary for this DocBlock
$summary = $docblock->getSummary();

// Contains \phpDocumentor\Reflection\DocBlock\Description object $description = $docblock->getDescription();

// You can either cast it to string $description = (string) $docblock->getDescription();

// Or use the render method to get a string representation of the Description. $description = $docblock->getDescription()->render();

For more examples it would be best to review the scripts in the

/examples
folder.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.