phpdocumentor / reflection-docblock
With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
Installs: 597 096 052
Dependents: 1 067
Suggesters: 23
Security: 0
Stars: 9 343
Watchers: 20
Forks: 121
Open Issues: 11
Requires
- php: ^7.4 || ^8.0
- ext-filter: *
- doctrine/deprecations: ^1.1
- phpdocumentor/reflection-common: ^2.2
- phpdocumentor/type-resolver: ^1.7
- phpstan/phpdoc-parser: ^1.7|^2.0
- webmozart/assert: ^1.9.1
Requires (Dev)
- mockery/mockery: ~1.3.5 || ~1.6.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.8
- phpstan/phpstan-mockery: ^1.1
- phpstan/phpstan-webmozart-assert: ^1.2
- phpunit/phpunit: ^9.5
- psalm/phar: ^5.26
- 5.x-dev
- 5.6.0
- 5.5.1
- 5.5.0
- 5.4.1
- 5.4.0
- 5.3.0
- 5.2.2
- 5.2.1
- 5.2.0
- 5.1.0
- 5.0.0
- 5.0.0-beta
- 5.0.0-alpha9
- 5.0.0-alpha8
- 5.0.0-alpha7
- 5.0.0-alpha6
- 5.0.0-alpha5
- 5.0.0-alpha4
- 5.0.0-alpha3
- 5.0.0-alpha2
- 5.0.0-alpha1
- 4.3.4
- 4.3.3
- 4.3.2
- 4.3.1
- 4.3.0
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.1
- 4.0.0
- 3.3.2
- 3.3.0
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 2.0.0a3
- 2.0.0a2
- 2.0.0a1
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 1.0.0-beta7
- 1.0.0-beta6
- 1.0.0-beta5
- 1.0.0-beta4
- 1.0.0-beta3
- 1.0.0-beta2
- 1.0.0-beta1
- dev-dependabot/composer/phpstan/phpdoc-parser-2.0.0
- dev-dependabot/composer/phpdocumentor/type-resolver-1.10.0
- dev-dependabot/composer/phpstan/phpstan-1.12.8
- dev-hack/phpstan-parser
- dev-feature/method_params
- dev-release/4.x
- dev-danrot-long-method-annotation
- dev-release/2.x
- dev-release/3.x
- dev-_before-history-rewrite
This package is auto-updated.
Last update: 2024-11-13 10:22:53 UTC
README
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 = <<<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);
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.