| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace LaravelUi5\OData\Service\Discovery; |
| 6: | |
| 7: | use LaravelUi5\OData\Edm\Contracts\Annotation\AnnotationInterface; |
| 8: | use LaravelUi5\OData\Edm\Contracts\Annotation\TypedAnnotationInterface; |
| 9: | use ReflectionAttribute; |
| 10: | use ReflectionClass; |
| 11: | use ReflectionParameter; |
| 12: | use ReflectionProperty; |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | final readonly class AttributeReader |
| 34: | { |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | public function readClass(ReflectionClass $reflection): array |
| 42: | { |
| 43: | return $this->extract( |
| 44: | $reflection->getAttributes(TypedAnnotationInterface::class, ReflectionAttribute::IS_INSTANCEOF), |
| 45: | ); |
| 46: | } |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | public function readProperty(ReflectionProperty $reflection): array |
| 55: | { |
| 56: | return $this->extract( |
| 57: | $reflection->getAttributes(TypedAnnotationInterface::class, ReflectionAttribute::IS_INSTANCEOF), |
| 58: | ); |
| 59: | } |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | public function readParameter(ReflectionParameter $reflection): array |
| 68: | { |
| 69: | return $this->extract( |
| 70: | $reflection->getAttributes(TypedAnnotationInterface::class, ReflectionAttribute::IS_INSTANCEOF), |
| 71: | ); |
| 72: | } |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: | private function extract(array $attributes): array |
| 79: | { |
| 80: | return array_values(array_map( |
| 81: | static fn(ReflectionAttribute $a): AnnotationInterface => $a->newInstance()->toAnnotation(), |
| 82: | $attributes, |
| 83: | )); |
| 84: | } |
| 85: | } |
| 86: | |