koriym / param-reader
An annotation/attribute reader for method parameter
Installs: 592 950
Dependents: 3
Suggesters: 1
Security: 0
Stars: 1
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
- doctrine/annotations: ^1.13 || ^2.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.4
- phpunit/phpunit: ^8.5.24
Suggests
- koriym/attributes: doctrine/annotation Reader interface in order to read both doctrine/annotation and PHP 8 attributes.
This package is auto-updated.
Last update: 2024-12-13 19:58:38 UTC
README
This is a meta data reader to get attributes or annotations from method parameters.
Although doctine/annotation cannot annotate method parameters, this reader treats annotations of properties with the same names as method parameters as method parameter metadata.
This is especially useful when you want to prepare metadata for injection.
Installation
composer require koriym/param-reader
Getting Started
$reader = new PramReader(); $user = $reader->getParametrAnnotation(new ReflectionParameter([Consumer::class, '__construct'], 'name'), User::class); assert($user instanceof User); $users = $reader->getParametrAnnotations(new ReflectionParameter([Consumer::class, '__construct'], 'name')); assert($users[0] instanceof User); assert($users[1] instanceof Foo);
The following two codes provide the same meta information.
class Consumer { private $name; public function __construct(#[User, Foo] string $name) { $this->name = $name; } }
class Consumer { /** * @User * @Foo */ private $name; public function __construct(string $name) { $this->name = $name; } }