loot/phpdoc-reader

该包可以解析phpdoc注释

v1.1 2021-02-19 16:24 UTC

This package is auto-updated.

Last update: 2024-09-20 00:38:32 UTC


README

用法

$class = \App\Models\User::class;
$method = 'getChild';
$comment = (new \ReflectionMethod($class, $method))->getDocComment();
$res = new Loot\PhpDocReader\PhpDocReader($comment);

var_dump($res->getAnnotationsByName('@param'));

或者

$comment = '
/**
 * @param int $var Description
 */';
$res = new Loot\PhpDocReader\PhpDocReader($comment);

var_dump($res->getAnnotation('@param')->getDescription());

类 PhpDocReader

方法 getAnnotation

根据名称获取第一个注释。

$res = new Loot\PhpDocReader\PhpDocReader('
/**
  * @return int
  */');

var_dump($res->getAnnotation('@return')->getType());

方法 getAnnotationsByName

根据名称获取所有注释。

$res = new Loot\PhpDocReader\PhpDocReader('
/**
  * @param int $int
  * @param string $string
  */');

var_dump($res->getAnnotationsByName('@param'));

方法 getAnnotations

获取第一个注释。

$res = new Loot\PhpDocReader\PhpDocReader('
/**
  * @param int $int
  * @param string $string
  */');

var_dump($res->getAnnotations());

类 PhpDocLine

方法 getName()

返回注释的名称。

方法 getType()

返回注释的类型。

方法 getDescription()

返回注释的描述。

方法 getVariable()

返回注释中的变量。