phpdocumentor / reflection-docblock
此组件允许库通过 DocBlocks 提供注释支持或检索嵌入在 DocBlock 中的信息。
5.4.1
2024-05-21 05:55 UTC
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
- webmozart/assert: ^1.9.1
Requires (Dev)
- mockery/mockery: ~1.3.5
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.8
- phpstan/phpstan-mockery: ^1.1
- phpstan/phpstan-webmozart-assert: ^1.2
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^5.13
- 5.x-dev
- 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-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-09-14 20:09:34 UTC
README
ReflectionDocBlock
简介
phpDocumentor 的 ReflectionDocBlock 组件提供了一种与 PHPDoc 标准 100% 兼容的 DocBlock 解析器。
此组件允许库通过 DocBlocks 提供注释支持或检索嵌入在 DocBlock 中的信息。
安装
composer require phpdocumentor/reflection-docblock
用法
要解析 DocBlock,需要一个 DocBlockFactory,可以使用其 createInstance
工厂方法进行实例化,如下所示
$factory = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
然后我们可以使用工厂的 create
方法来解释 DocBlock。请注意,也可以提供一个具有 getDocComment()
方法的类,例如 ReflectionClass
类型的对象,如果存在,创建方法将读取该对象。
$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);
create
方法将产生一个类型为 \phpDocumentor\Reflection\DocBlock
的对象,可以查询其方法
// 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();
有关更多示例,最好查看
/examples
文件夹中的脚本。