1
|
|
|
<?php |
2
|
|
|
namespace mxdiModule\Service; |
3
|
|
|
|
4
|
|
|
use mxdiModule\Annotation\Inject; |
5
|
|
|
use mxdiModule\Annotation\InjectParams; |
6
|
|
|
|
7
|
|
|
class ChangeSet |
8
|
|
|
{ |
9
|
|
|
/** @var string */ |
10
|
|
|
protected $fqcn; |
11
|
|
|
|
12
|
|
|
/** @var InjectParams|null */ |
13
|
|
|
protected $constructorInjections; |
14
|
|
|
|
15
|
|
|
/** @var bool */ |
16
|
|
|
protected $hasSimpleConstructor; |
17
|
|
|
|
18
|
|
|
/** @var InjectParams[] */ |
19
|
|
|
protected $methodsInjections; |
20
|
|
|
|
21
|
|
|
/** @var Inject[] */ |
22
|
|
|
protected $propertiesInjections; |
23
|
|
|
|
24
|
|
|
/** @var bool[] */ |
25
|
|
|
protected $propertyVisibility; |
26
|
|
|
|
27
|
|
|
/** @var bool[] */ |
28
|
|
|
protected $methodVisibility; |
29
|
|
|
|
30
|
|
|
/** @var bool */ |
31
|
|
|
protected $isAnnotated = false; |
32
|
|
|
|
33
|
8 |
|
public function __construct(ExtractorInterface $extractor, $fqcn) |
34
|
|
|
{ |
35
|
8 |
|
if (!class_exists($fqcn)) { |
36
|
4 |
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
4 |
|
$this->fqcn = $fqcn; |
40
|
4 |
|
$this->setConstructorInjections($extractor, $fqcn); |
41
|
4 |
|
$this->setMethodsInjections($extractor, $fqcn); |
42
|
4 |
|
$this->setPropertiesInjections($extractor, $fqcn); |
43
|
|
|
|
44
|
4 |
|
$this->isAnnotated = |
45
|
4 |
|
$this->constructorInjections || |
46
|
1 |
|
count($this->methodsInjections) || |
47
|
1 |
|
count($this->propertiesInjections); |
48
|
4 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getFqcn() |
54
|
|
|
{ |
55
|
|
|
return $this->fqcn; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return InjectParams|null |
60
|
|
|
*/ |
61
|
2 |
|
public function getConstructorInjections() |
62
|
|
|
{ |
63
|
2 |
|
return $this->constructorInjections; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return boolean |
68
|
|
|
*/ |
69
|
2 |
|
public function hasSimpleConstructor() |
70
|
|
|
{ |
71
|
2 |
|
return $this->hasSimpleConstructor; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return InjectParams|null |
76
|
|
|
*/ |
77
|
1 |
|
public function getMethodsInjections() |
78
|
|
|
{ |
79
|
1 |
|
return $this->methodsInjections; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return array|\mxdiModule\Annotation\Inject[] |
84
|
|
|
*/ |
85
|
1 |
|
public function getPropertiesInjections() |
86
|
|
|
{ |
87
|
1 |
|
return $this->propertiesInjections; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $name |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
1 |
|
public function isPropertyPublic($name) |
95
|
|
|
{ |
96
|
1 |
|
return $this->propertyVisibility[$name]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string $name |
101
|
|
|
* @return bool |
102
|
|
|
*/ |
103
|
1 |
|
public function isMethodPublic($name) |
104
|
|
|
{ |
105
|
1 |
|
return $this->methodVisibility[$name]; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return boolean |
110
|
|
|
*/ |
111
|
5 |
|
public function isAnnotated() |
112
|
|
|
{ |
113
|
5 |
|
return $this->isAnnotated; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @param ExtractorInterface $extractor |
118
|
|
|
* @param string $fqcn |
119
|
|
|
*/ |
120
|
4 |
|
protected function setConstructorInjections(ExtractorInterface $extractor, $fqcn) |
121
|
|
|
{ |
122
|
4 |
|
$this->constructorInjections = $extractor->getConstructorInjections($fqcn); |
123
|
4 |
|
$this->hasSimpleConstructor = null === $this->constructorInjections; |
124
|
4 |
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param ExtractorInterface $extractor |
128
|
|
|
* @param string $fqcn |
129
|
|
|
*/ |
130
|
4 |
|
protected function setMethodsInjections(ExtractorInterface $extractor, $fqcn) |
131
|
|
|
{ |
132
|
4 |
|
$this->methodsInjections = (array)$extractor->getMethodsInjections($fqcn); |
133
|
|
|
|
134
|
4 |
|
foreach ($this->methodsInjections as $methodName => $injection) { |
135
|
1 |
|
$reflection = new \ReflectionMethod($fqcn, $methodName); |
136
|
1 |
|
$this->methodVisibility[$methodName] = $reflection->isPublic(); |
137
|
4 |
|
} |
138
|
4 |
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param ExtractorInterface $extractor |
142
|
|
|
* @param string $fqcn |
143
|
|
|
*/ |
144
|
4 |
|
protected function setPropertiesInjections(ExtractorInterface $extractor, $fqcn) |
145
|
|
|
{ |
146
|
4 |
|
$this->propertiesInjections = (array)$extractor->getPropertiesInjections($fqcn); |
147
|
|
|
|
148
|
4 |
|
foreach ($this->propertiesInjections as $propertyName => $injection) { |
149
|
1 |
|
$reflection = new \ReflectionProperty($fqcn, $propertyName); |
150
|
1 |
|
$this->propertyVisibility[$propertyName] = $reflection->isPublic(); |
151
|
4 |
|
} |
152
|
4 |
|
} |
153
|
|
|
} |
154
|
|
|
|