1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Overblog\GraphQLBundle\Config\Parser\Annotation; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Annotations\AnnotationException; |
8
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
9
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
10
|
|
|
use ReflectionClass; |
11
|
|
|
use ReflectionMethod; |
12
|
|
|
use ReflectionProperty; |
13
|
|
|
use RuntimeException; |
14
|
|
|
use function class_exists; |
15
|
|
|
|
16
|
|
|
class GraphClass extends ReflectionClass |
17
|
|
|
{ |
18
|
|
|
private static ?AnnotationReader $annotationReader = null; |
19
|
|
|
|
20
|
|
|
protected array $annotations = []; |
21
|
|
|
|
22
|
|
|
protected array $propertiesExtended = []; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param mixed $className |
26
|
|
|
*/ |
27
|
25 |
|
public function __construct($className) |
28
|
|
|
{ |
29
|
25 |
|
parent::__construct($className); |
30
|
|
|
|
31
|
25 |
|
$annotationReader = self::getAnnotationReader(); |
32
|
25 |
|
$this->annotations = $annotationReader->getClassAnnotations($this); |
33
|
|
|
|
34
|
25 |
|
$reflection = $this; |
35
|
|
|
do { |
36
|
25 |
|
foreach ($reflection->getProperties() as $property) { |
37
|
24 |
|
if (isset($this->propertiesExtended[$property->getName()])) { |
38
|
24 |
|
continue; |
39
|
|
|
} |
40
|
24 |
|
$this->propertiesExtended[$property->getName()] = $property; |
41
|
|
|
} |
42
|
25 |
|
} while ($reflection = $reflection->getParentClass()); |
43
|
25 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @return ReflectionProperty[] |
47
|
|
|
*/ |
48
|
25 |
|
public function getPropertiesExtended() |
49
|
|
|
{ |
50
|
25 |
|
return $this->propertiesExtended; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param ReflectionMethod|ReflectionProperty|null $from |
55
|
|
|
* |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
25 |
|
public function getAnnotations(object $from = null) |
59
|
|
|
{ |
60
|
25 |
|
if (!$from) { |
61
|
25 |
|
return $this->annotations; |
62
|
|
|
} |
63
|
|
|
|
64
|
24 |
|
if ($from instanceof ReflectionMethod) { |
65
|
24 |
|
return self::getAnnotationReader()->getMethodAnnotations($from); |
66
|
|
|
} |
67
|
|
|
|
68
|
24 |
|
if ($from instanceof ReflectionProperty) { |
69
|
24 |
|
return self::getAnnotationReader()->getPropertyAnnotations($from); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** @phpstan-ignore-next-line */ |
73
|
|
|
throw new AnnotationException(sprintf('Unable to retrieve annotations from object of class "%s".', get_class($from))); |
74
|
|
|
} |
75
|
|
|
|
76
|
25 |
|
private static function getAnnotationReader(): AnnotationReader |
77
|
|
|
{ |
78
|
25 |
|
if (null === self::$annotationReader) { |
79
|
1 |
|
if (!class_exists(AnnotationReader::class) || |
80
|
1 |
|
!class_exists(AnnotationRegistry::class)) { |
81
|
|
|
throw new RuntimeException('In order to use graphql annotation, you need to require doctrine annotations'); |
82
|
|
|
} |
83
|
|
|
|
84
|
1 |
|
AnnotationRegistry::registerLoader('class_exists'); |
|
|
|
|
85
|
1 |
|
self::$annotationReader = new AnnotationReader(); |
86
|
|
|
} |
87
|
|
|
|
88
|
25 |
|
return self::$annotationReader; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
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.