anhoder / annotations-collector
This package is abandoned and no longer maintained.
The author suggests using the yarfox/attributes-collector package instead.
PHP8 Attribute Collector.
1.1.2
2022-07-23 12:02 UTC
Requires
- php: >=8.0
- php-parallel-lint/php-console-color: ^1.0
- yarfox/container: ^1.0.0
Requires (Dev)
- phpunit/phpunit: ^9.5
README
PHP8 attribute collector.
Required
- php>=8
Install
composer require yarfox/attributes-collector
Usage
- Install
- Add php file
AttributeConfig.php
to 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();