yarfox/attributes-collector
Composer 安装命令:
composer require yarfox/attributes-collector
包简介
PHP8 Attribute Collector.
README 文档
README
PHP8 attribute collector.
Required
- php>=8
Install
composer require yarfox/attributes-collector
Usage
- Install
- Add php file
AttributeConfig.phpto your project.
class AttributeConfig implements ConfigInterface { #[ArrayShape(['scanDirs' => 'array'])] public static function getAttributeConfigs(): array { return [ 'scanDirs' => [ __NAMESPACE__ => __DIR__, ], ]; } }
- Add attribute and attribute handler.
// Attribute #[Attribute(Attribute::TARGET_CLASS)] class ClassAttribute { public const TEST = 'test'; private string $test; public function __construct(#[ExpectedValues(valuesFromClass: ClassAttribute::class)] string $test) { $this->test = $test; } public function getTest(): string { return $this->test; } } // AttributeHandler #[AttributeHandler(ClassAttribute::class)] class ClassAttributeHandler extends AbstractHandler { public function handle(): void { /** * @var $attribute ClassAttribute */ var_dump($this); $attribute = $this->attribute; var_dump($attribute->getTest()); } }
- Use Attribute
#[ClassAttribute(ClassAttribute::TEST)] class ClassAttributeTest { }
- Start scan.
AttributeKeeper::bootloader(); AttributeKeeper::collect();
Example
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-18