phpdocumentor/reflection-docblock's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
The phpdocumentor/reflection-docblock is a DocBlock parser for PHP that is 100% compatible with the PHPDoc standard. It enables a library to support annotations via DocBlocks and to retrieve information embedded in a DocBlock. The tool is part of the phpDocumentor suite of tools which are widely used in PHP development for their ability to generate high-quality documentation for PHP code.
To use phpdocumentor/reflection-docblock, start by installing it using composer with the command
composer require phpdocumentor/reflection-docblock.
Then create a DocBlockFactory instance with the
createInstance factory method:
$factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
After that, invoke the
create method of the factory to parse the DocBlock:
$docComment = <<<DOCCOMMENT /** * This is an example of a summary. * * This is a Description. A Summary and Description are separated by either * two subsequent newlines (thus a whiteline in between as can be seen in this * example), or when the Summary ends with a dot (`.`) and some form of * whitespace. */ DOCCOMMENT; $docblock = $factory->create($docComment);
Finally, you can interrogate the methods of the object yielded by
create, which is an instance of
$summary = $docblock->getSummary(); $description = $docblock->getDescription(); $description = (string) $docblock->getDescription(); $description = $docblock->getDescription()->render();
For the documentation of phpdocumentor/reflection-docblock, check out the
/examples folder in the project repository at GitHub. It contains several scripts that demonstrate usage of the library. You'll find detailed examples that shed more light on how to use the parsed elements to write and read PHPDocs effectively.