podlove / comment-introspection
PHP库,提供了解析类和方法注释的工具集。
dev-master
2014-01-04 16:27 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is auto-updated.
Last update: 2024-08-27 03:56:40 UTC
README
PHP库,提供了解析类和方法注释的工具集。
用法
use Podlove\Comment\Comment; class ExampleClass { /** * A Title * * A multiline * description. * * @tag1 * @tag2 tag2 description */ public function foo() { return "bar"; } } $reflectionClass = new ReflectionClass("ExampleClass"); $methods = $reflectionClass->getMethods(); $parsedMethods = array_map(function($method) { $c = new Comment($method->getDocComment()); $c->parse(); return [ 'methodname' => $method->name, 'title' => $c->getTitle(), 'description' => $c->getDescription(), 'tags' => $c->getTags() /** * You can also access specific tags like so: * $c->getTag('tag1') or * $c->getTags('param') if you use one tag multiple times */ ]; }, $methods); print_r($parsedMethods); /* => Array ( [0] => Array ( [methodname] => foo [title] => A Title [description] => A multiline description. [tags] => Array ( [0] => Array ( [name] => tag2 [description] => tag2 description [line] => 6 ) [1] => Array ( [name] => tag1 [description] => [line] => 5 ) ) ) ) */