1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GraphQL\Doctrine\Factory\MetadataReader; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Annotations\Reader; |
8
|
|
|
use Doctrine\ORM\Mapping\Driver\AttributeReader; |
9
|
|
|
use Doctrine\ORM\Mapping\Driver\RepeatableAttributeCollection; |
10
|
|
|
use ReflectionClass; |
11
|
|
|
use ReflectionMethod; |
12
|
|
|
use ReflectionProperty; |
13
|
|
|
|
14
|
|
|
final class AttributeReaderAdapter implements Reader |
15
|
|
|
{ |
16
|
|
|
private AttributeReader $attributeReader; |
17
|
|
|
|
18
|
|
|
public function __construct(AttributeReader $attributeReader) |
19
|
|
|
{ |
20
|
|
|
$this->attributeReader = $attributeReader; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function getClassAnnotations(ReflectionClass $class) |
24
|
|
|
{ |
25
|
|
|
return $this->attributeReader->getClassAnnotations($class); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getClassAnnotation(ReflectionClass $class, $annotationName) |
29
|
|
|
{ |
30
|
|
|
$result = $this->attributeReader->getClassAnnotation($class, $annotationName); |
31
|
|
|
if ($result instanceof RepeatableAttributeCollection) { |
32
|
|
|
$result = $result[0]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
assert($result instanceof $annotationName); |
36
|
|
|
|
37
|
|
|
return $result; |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getMethodAnnotations(ReflectionMethod $method) |
41
|
|
|
{ |
42
|
|
|
return $this->attributeReader->getMethodAnnotations($method); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getMethodAnnotation(ReflectionMethod $method, $annotationName) |
46
|
|
|
{ |
47
|
|
|
$result = $this->attributeReader->getMethodAnnotation($method, $annotationName); |
48
|
|
|
if ($result instanceof RepeatableAttributeCollection) { |
49
|
|
|
$result = $result[0]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
assert($result instanceof $annotationName); |
53
|
|
|
|
54
|
|
|
return $result; |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getPropertyAnnotations(ReflectionProperty $property) |
58
|
|
|
{ |
59
|
|
|
return $this->attributeReader->getPropertyAnnotations($property); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName) |
63
|
|
|
{ |
64
|
|
|
$result = $this->attributeReader->getPropertyAnnotation($property, $annotationName); |
65
|
|
|
if ($result instanceof RepeatableAttributeCollection) { |
66
|
|
|
$result = $result[0]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
assert($result instanceof $annotationName); |
70
|
|
|
|
71
|
|
|
return $result; |
|
|
|
|
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|