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\AttributeDriver; |
9
|
|
|
use Doctrine\ORM\Mapping\Driver\AttributeReader; |
10
|
|
|
use Doctrine\Persistence\Mapping\Driver\AnnotationDriver; |
11
|
|
|
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; |
12
|
|
|
use GraphQL\Doctrine\Exception; |
13
|
|
|
use ReflectionClass; |
14
|
|
|
use ReflectionMethod; |
15
|
|
|
use ReflectionProperty; |
16
|
|
|
|
17
|
9 |
|
final class MappingDriverChainAdapter implements Reader |
18
|
|
|
{ |
19
|
|
|
public function __construct(private readonly MappingDriverChain $chainDriver) |
20
|
|
|
{ |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
9 |
|
* Find the reader for the class. |
25
|
|
|
*/ |
26
|
9 |
|
private function findReader(ReflectionClass $class): Reader |
27
|
9 |
|
{ |
28
|
1 |
|
$className = $class->getName(); |
29
|
1 |
|
foreach ($this->chainDriver->getDrivers() as $namespace => $driver) { |
30
|
1 |
|
if (mb_stripos($className, $namespace) === 0) { |
31
|
|
|
if ($driver instanceof AttributeDriver) { |
32
|
|
|
/** |
33
|
|
|
* doctrine lies about the return value of getReader here. |
34
|
|
|
* |
35
|
8 |
|
* @var AttributeReader $attributeReader |
36
|
7 |
|
*/ |
37
|
|
|
$attributeReader = $driver->getReader(); |
|
|
|
|
38
|
|
|
|
39
|
1 |
|
return new AttributeReaderAdapter($attributeReader); |
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
if ($driver instanceof AnnotationDriver) { |
43
|
|
|
return $driver->getReader(); |
44
|
1 |
|
} |
45
|
1 |
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
$defaultDriver = $this->chainDriver->getDefaultDriver(); |
49
|
|
|
if ($defaultDriver instanceof AttributeDriver) { |
50
|
1 |
|
/** |
51
|
1 |
|
* doctrine lies about the return value of getReader here. |
52
|
|
|
* |
53
|
|
|
* @var AttributeReader $attributeReader |
54
|
2 |
|
*/ |
55
|
|
|
$attributeReader = $defaultDriver->getReader(); |
|
|
|
|
56
|
2 |
|
|
57
|
2 |
|
return new AttributeReaderAdapter($attributeReader); |
58
|
|
|
} |
59
|
|
|
|
60
|
3 |
|
if ($defaultDriver instanceof AnnotationDriver) { |
61
|
|
|
return $defaultDriver->getReader(); |
62
|
3 |
|
} |
63
|
2 |
|
|
64
|
|
|
throw new Exception('graphql-doctrine requires ' . $className . ' entity to be configured with a `' . AnnotationDriver::class . '`.'); |
65
|
|
|
} |
66
|
1 |
|
|
67
|
|
|
public function getClassAnnotations(ReflectionClass $class) |
68
|
1 |
|
{ |
69
|
1 |
|
return $this->findReader($class) |
70
|
|
|
->getClassAnnotations($class); |
71
|
|
|
} |
72
|
1 |
|
|
73
|
|
|
public function getClassAnnotation(ReflectionClass $class, $annotationName) |
74
|
1 |
|
{ |
75
|
1 |
|
return $this->findReader($class) |
76
|
|
|
->getClassAnnotation($class, $annotationName); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getMethodAnnotations(ReflectionMethod $method) |
80
|
|
|
{ |
81
|
|
|
return $this->findReader($method->getDeclaringClass()) |
82
|
|
|
->getMethodAnnotations($method); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getMethodAnnotation(ReflectionMethod $method, $annotationName) |
86
|
|
|
{ |
87
|
|
|
return $this->findReader($method->getDeclaringClass()) |
88
|
|
|
->getMethodAnnotation($method, $annotationName); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getPropertyAnnotations(ReflectionProperty $property) |
92
|
|
|
{ |
93
|
|
|
return $this->findReader($property->getDeclaringClass()) |
94
|
|
|
->getPropertyAnnotations($property); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function getPropertyAnnotation(ReflectionProperty $property, $annotationName) |
98
|
|
|
{ |
99
|
|
|
return $this->findReader($property->getDeclaringClass()) |
100
|
|
|
->getPropertyAnnotation($property, $annotationName); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.