|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Ray\Di; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Annotations\Reader; |
|
8
|
|
|
use Ray\Di\Di\Qualifier; |
|
9
|
|
|
|
|
10
|
|
|
final class InjectionPoint implements InjectionPointInterface, \Serializable |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var \ReflectionParameter |
|
14
|
|
|
*/ |
|
15
|
|
|
private $parameter; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var Reader |
|
19
|
|
|
*/ |
|
20
|
|
|
private $reader; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
private $pClass; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
private $pFunction; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var string |
|
34
|
|
|
*/ |
|
35
|
|
|
private $pName; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct(\ReflectionParameter $parameter, Reader $reader) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->parameter = $parameter; |
|
40
|
|
|
$this->pFunction = $parameter->getDeclaringFunction()->name; |
|
41
|
|
|
$class = $parameter->getDeclaringClass(); |
|
42
|
|
|
$this->pClass = $class instanceof \ReflectionClass ? $class->name : ''; |
|
43
|
|
|
$this->pName = $parameter->name; |
|
44
|
|
|
$this->reader = $reader; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getParameter() : \ReflectionParameter |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->parameter ?? new \ReflectionParameter([$this->pClass, $this->pFunction], $this->pName); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getMethod() : \ReflectionMethod |
|
59
|
|
|
{ |
|
60
|
|
|
$class = $this->parameter->getDeclaringClass(); |
|
61
|
|
|
if (! $class instanceof \ReflectionClass) { |
|
62
|
|
|
throw new \LogicException($this->parameter->getName()); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
$method = $this->parameter->getDeclaringFunction()->getShortName(); |
|
65
|
|
|
|
|
66
|
|
|
return new \ReflectionMethod($class->name, $method); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* {@inheritdoc} |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getClass() : \ReflectionClass |
|
73
|
|
|
{ |
|
74
|
|
|
$class = $this->parameter->getDeclaringClass(); |
|
75
|
|
|
if ($class instanceof \ReflectionClass) { |
|
76
|
|
|
return $class; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
throw new \LogicException($this->parameter->getName()); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* {@inheritdoc} |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getQualifiers() : array |
|
86
|
|
|
{ |
|
87
|
|
|
$qualifiers = []; |
|
88
|
|
|
$annotations = $this->reader->getMethodAnnotations($this->getMethod()); |
|
89
|
|
|
foreach ($annotations as $annotation) { |
|
90
|
|
|
$qualifier = $this->reader->getClassAnnotation( |
|
91
|
|
|
new \ReflectionClass($annotation), |
|
92
|
|
|
Qualifier::class |
|
93
|
|
|
); |
|
94
|
|
|
if ($qualifier instanceof Qualifier) { |
|
95
|
|
|
$qualifiers[] = $annotation; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return $qualifiers; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function serialize() : string |
|
103
|
|
|
{ |
|
104
|
|
|
return serialize([$this->reader, $this->pClass, $this->pFunction, $this->pName]); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function unserialize($serialized) |
|
108
|
|
|
{ |
|
109
|
|
|
[$this->reader, $this->pClass, $this->pFunction, $this->pName] = unserialize($serialized); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|