danineto/annotations

注释是一种为源代码添加元数据信息的机制。

v0.0.1 2019-06-27 16:44 UTC

This package is auto-updated.

Last update: 2024-09-29 05:21:56 UTC


README

此库为PHP类实现自定义注释提供了能力。

它扩展了Doctrine/Annotations的所有功能。

需求

此库使用PHP 7.2+。

安装

建议您通过Composer安装此库。

要这样做,运行Composer命令安装最新稳定版本

composer require danineto/annotations

如果不使用Composer,您还必须包含此库:Doctrine/Annotations

通过注释获取方法

通过注释获取方法允许您检索实现了特定注释和特定参数的类方法。

使用AsMethod注释的示例

use Danineto\Annotations\AsMethod;
use Danineto\Annotations\Common\AnnotationReader;

$class = new class
{
    /**
     * @AsMethod(name="getExample")
     */
    function method()
    {
        return true;
    }
};

$reader = new AnnotationReader()
$methods = $reader->getMethodByAnnotation($class, AsMethod::class, [
    'name' => 'getExample'
]);

var_dump($methods);

参数

通过注释获取方法参数包括

  • class 包含注释的类对象
  • annotation 要搜索的注释
  • parameters 注释的参数值

许可证

注释库是开源软件,受MIT许可证许可。