koriym/attributes
Composer 安装命令:
composer require koriym/attributes
包简介
An annotation/attribute reader
关键字:
README 文档
README
A koriym/attributes dual reader implements doctrine/annotation Reader interface
in order to read both doctrine/annotation and PHP 8 attributes.
Doctrine annotations are different by design than PHP core one. Not all attributes can be read by this reader (ex. parameters), and not all doctrine/annotations can be read by this reader either. (ex. nested annotations)
However, This reader help you to code forward compatible that supports both PHP 7.x annotations and 8.x attributes in certain senario.
Installation
composer require koriym/attributes
Usage
Create the reader instance.
use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\Reader; use Koriym\Attributes\DualReader; use Koriym\Attributes\AttributeReader; $reader = new DualReader( new AnnotationReader(), new AttributeReader() ); assert($reader instanceof Reader);
The reader can read both annotations and attributes.
Compatible Annotation
Existing doctrine annotations can be changed into annotations that work for both doctrine annotation and PHP8 attributes.
Add #[Attribute] attribute.
use Attribute;
/** @Annotation */
+#[Attribute]
final class Foo
{
}
Then add constructor when annotation has properties.
Following example works with both PHP8 attribute and doctrine/annotations.
use Attribute; +use Doctrine\Common\Annotations\NamedArgumentConstructor; /** * @Annotation * @Target("METHOD") +* @NamedArgumentConstructor */ +#[Attribute(Attribute::TARGET_METHOD)] final class Foo { public string $bar; public int $baz; + public function __construct(string $bar = '', int $baz = 0) + { + $this->bar = $bar; + $this->baz = $baz; + } }
See more about annotation compatible attribute at Constructors with Named Parameters
koriym/attributes 适用场景与选型建议
koriym/attributes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.63M 次下载、GitHub Stars 达 43, 最近一次更新时间为 2020 年 12 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「annotation」 「attribute」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 koriym/attributes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 koriym/attributes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 koriym/attributes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Symfony bundle to add arbitrary metadata to classes and their constants by annotation
Powerful class discovery system for Laravel with attribute-based scanning, directory traversal, and monorepo support
Show attribute codes in product edit form
hyperf 注解日志
Annotated files scanner - looks for methods annotated with provided annotations, outputs an array of either filepaths or directories.
统计信息
- 总下载量: 3.63M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 44
- 点击次数: 15
- 依赖项目数: 12
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2020-12-17