biurad / annotations
一个轻量级、易于使用的库,用于轻松管理所有PHP属性/注解
v1.1.0
2022-10-08 09:42 UTC
Requires
- php: ^7.2 || ^8.0
- symfony/polyfill-php80: ^1.22
Requires (Dev)
- doctrine/annotations: ^1.11
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^8.5 || ^9.5
- spiral/attributes: ^2.8
- squizlabs/php_codesniffer: ^3.6
- vimeo/psalm: ^4.7
Suggests
- doctrine/annotations: ^1.8 for Doctrine metadata driver support
- spiral/attributes: For loading doctrine and/or PHP 8 attributes for PHP 7
README
Poakium 注解
一个轻量级的 PHP 库,提供简单、快速、易于使用的 Doctrine 注解 和 属性 支持,适用于您的 PHP 项目。这有助于提高代码组织性,降低错误风险,并使代码的维护和更新更容易。从 PHP 7.2 到 7.4 项目需要安装 spiral/attributes
。
📦 安装
本项目需要 PHP 7.2 或更高版本。推荐使用 Composer 进行安装。只需运行
$ composer require biurad/annotations
📍 快速入门
此库作为管理器使用,允许您在一个地方使用所有的注解/属性。使用 resource()
方法添加您想从中获取注解/属性的所有资源。然后添加您的监听器,它们将对您的注解/属性实现进行监听。当您想使用特定监听器的返回结果时,请使用 load()
方法。(注意:监听器可以命名)。
以下是如何使用此库的示例
use Biurad\Annotations\AnnotationLoader; use Spiral\Attributes\AnnotationReader; use Spiral\Attributes\AttributeReader; use Spiral\Attributes\Composite\MergeReader; // The doctrine annotation reader requires doctrine/annotations library $doctrine = new AnnotationReader(); // With spiral/attributes library, we can use PHP 8 attributes in PHP 7.2 + $attribute = new AttributeReader(); // Create a new annotation loader from readers ... $annotation = new AnnotationLoader(new MergeReader([$doctrine, $attribute])); $annotation->listener(...); // Add your implemented Annotation listeners $annotation->resource(...); // Add a class/function string, class file, or directory $listeners = $annotation->load(); // Compile once, then load cached ... // To use a collector you implemented into your instance of `Biurad\Annotations\ListenerInterface` foreach ($listeners as $collector) { // You can fetch the required $collector from here. }
注意:如果您正在使用 PHP 8 并且只想使用属性,请避免使用
spiral/attributes
包以获得最佳性能,这也是为什么此库没有附带spiral/attributes
包的原因。
📓 文档
有关如何使用此库的详细文档可在 docs.biurad.com 找到。还建议浏览 tests 目录中的单元测试。
🙌 赞助者
如果这个库被用于您的项目,或者您有兴趣支持我们,请考虑 捐赠 以支持未来的开发。
👥 致谢与感谢
- Divine Niiquaye Ibok 是此库的作者。
- 所有贡献者 都为此项目做出了贡献。
📄 许可证
Poakium 注解完全免费,并按照 BSD 3 许可证 发布。