https://github.com/koriym/koriym.paramreader
An attribute/annotation reader for parameters
https://github.com/koriym/koriym.paramreader
annotation attribute php8
Last synced: 10 months ago
JSON representation
An attribute/annotation reader for parameters
- Host: GitHub
- URL: https://github.com/koriym/koriym.paramreader
- Owner: koriym
- License: mit
- Created: 2022-03-07T11:39:21.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-13T18:18:43.000Z (almost 2 years ago)
- Last Synced: 2025-03-27T10:21:23.215Z (11 months ago)
- Topics: annotation, attribute, php8
- Language: PHP
- Homepage: https://packagist.org/packages/koriym/param-reader
- Size: 74.2 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# Koriym.ParamReader
This is a meta data reader to get attributes or annotations from method parameters.
Although [doctine/annotation](https://github.com/doctrine/annotations) 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
```php
$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.
```php
class Consumer
{
private $name;
public function __construct(#[User, Foo] string $name) {
$this->name = $name;
}
}
```
```php
class Consumer
{
/**
* @User
* @Foo
*/
private $name;
public function __construct(string $name) {
$this->name = $name;
}
}
```
## Related
* [koriym/attributes](https://github.com/koriym/Koriym.Attributes)