1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) Paulus Gandung Prakosa ([email protected]) |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace DependencyInjection\Internal; |
8
|
|
|
|
9
|
|
|
class ReflectionClassFactory implements ReflectionFactoryInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var \ReflectionClass |
13
|
|
|
*/ |
14
|
|
|
private $reflection; |
15
|
|
|
|
16
|
|
|
public function __construct($instance) |
17
|
|
|
{ |
18
|
|
|
if (!is_string($instance) && !class_exists($instance)) { |
19
|
|
|
throw Exception\ReflectionExceptionFactory::invalidArgument( |
20
|
|
|
sprintf("Parameter 1 of %s must be a string and exist class name.", __METHOD__) |
21
|
|
|
); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$this->reflection = new \ReflectionClass($instance); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public static function create($instance) |
28
|
|
|
{ |
29
|
|
|
return new static($instance); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getConstant($name) |
33
|
|
|
{ |
34
|
|
|
return $this->reflection->getConstant($name); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getConstants() |
38
|
|
|
{ |
39
|
|
|
return $this->reflection->getConstants(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getConstructor() |
43
|
|
|
{ |
44
|
|
|
return $this->reflection->getConstructor(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getDefaultProperties() |
48
|
|
|
{ |
49
|
|
|
return $this->reflection->getDefaultProperties(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getDocComment() |
53
|
|
|
{ |
54
|
|
|
return $this->reflection->getDocComment(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function getEndLine() |
58
|
|
|
{ |
59
|
|
|
return $this->reflection->getEndLine(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getExtension() |
63
|
|
|
{ |
64
|
|
|
return $this->reflection->getExtension(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getExtensionName() |
68
|
|
|
{ |
69
|
|
|
return $this->reflection->getExtensionName(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getFileName() |
73
|
|
|
{ |
74
|
|
|
return $this->reflection->getFileName(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function getInterfaceNames() |
78
|
|
|
{ |
79
|
|
|
return $this->reflection->getInterfaceNames(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getInterfaces() |
83
|
|
|
{ |
84
|
|
|
return $this->reflection->getInterfaces(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function getMethod($name) |
88
|
|
|
{ |
89
|
|
|
return $this->reflection->getMethod($name); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getMethods() |
93
|
|
|
{ |
94
|
|
|
return $this->reflection->getMethods(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function getModifiers() |
98
|
|
|
{ |
99
|
|
|
return $this->reflection->getModifiers(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getName() |
103
|
|
|
{ |
104
|
|
|
return $this->reflection->getName(); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getNamespaceName() |
108
|
|
|
{ |
109
|
|
|
return $this->reflection->getNamespaceName(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getParentClass() |
113
|
|
|
{ |
114
|
|
|
return $this->reflection->getParentClass(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function getProperties($filter = null) |
118
|
|
|
{ |
119
|
|
|
return (!is_int($filter) |
120
|
|
|
? $this->reflection->getProperties() |
121
|
|
|
: $this->reflection->getProperties($filter)); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function getProperty($name) |
125
|
|
|
{ |
126
|
|
|
return $this->reflection->getProperty($name); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function getShortName() |
130
|
|
|
{ |
131
|
|
|
return $this->reflection->getShortName(); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function getStartLine() |
135
|
|
|
{ |
136
|
|
|
return $this->reflection->getStartLine(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function getStaticProperties() |
140
|
|
|
{ |
141
|
|
|
return $this->reflection->getStaticProperties(); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function getStaticPropertyValue($name, &$def_value = null) |
145
|
|
|
{ |
146
|
|
|
return (!isset($def_value) |
147
|
|
|
? $this->reflection->getStaticPropertyValue($name) |
148
|
|
|
: $this->reflection->getStaticPropertyValue($name, $def_value)); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function getTraitAliases() |
152
|
|
|
{ |
153
|
|
|
return $this->reflection->getTraitAliases(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function getTraitNames() |
157
|
|
|
{ |
158
|
|
|
return $this->reflection->getTraitNames(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function getTraits() |
162
|
|
|
{ |
163
|
|
|
return $this->reflection->getTraits(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
View Code Duplication |
public function hasConstant($name) |
|
|
|
|
167
|
|
|
{ |
168
|
|
|
if (!is_string($name)) { |
169
|
|
|
throw Exception\ReflectionExceptionFactory::invalidArgument( |
170
|
|
|
sprintf("Parameter 1 of %s must be a string.", __METHOD__) |
171
|
|
|
); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return $this->reflection->hasConstant($name); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
View Code Duplication |
public function hasMethod($name) |
|
|
|
|
178
|
|
|
{ |
179
|
|
|
if (!is_string($name)) { |
180
|
|
|
throw Exception\ReflectionExceptionFactory::invalidArgument( |
181
|
|
|
sprintf("Parameter 1 of %s must be a string.", __METHOD__) |
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
return $this->reflection->hasMethod($name); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
View Code Duplication |
public function hasProperty($name) |
|
|
|
|
189
|
|
|
{ |
190
|
|
|
if (!is_string($name)) { |
191
|
|
|
throw Exception\ReflectionExceptionFactory::invalidArgument( |
192
|
|
|
sprintf("Parameter 1 of %s must be a string.", __METHOD__) |
193
|
|
|
); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
return $this->reflection->hasProperty($name); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
View Code Duplication |
public function implementsInterface($interface) |
|
|
|
|
200
|
|
|
{ |
201
|
|
|
if (!is_string($interface)) { |
202
|
|
|
throw Exception\ReflectionExceptionFactory::invalidArgument( |
203
|
|
|
sprintf("Parameter 1 of %s must be a string.", __METHOD__) |
204
|
|
|
); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
return $this->reflection->implementsInterface($interface); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function inNamespace() |
211
|
|
|
{ |
212
|
|
|
return $this->reflection->inNamespace(); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public function isAbstract() |
216
|
|
|
{ |
217
|
|
|
return $this->reflection->isAbstract(); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function isCloneable() |
221
|
|
|
{ |
222
|
|
|
return $this->reflection->isCloneable(); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
public function isFinal() |
226
|
|
|
{ |
227
|
|
|
return $this->reflection->isFinal(); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
public function isInstance($object) |
231
|
|
|
{ |
232
|
|
|
if (!is_object($object)) { |
233
|
|
|
throw Exception\ReflectionExceptionFactory::invalidArgument( |
234
|
|
|
sprintf("Parameter 1 of %s must be an object.", __METHOD__) |
235
|
|
|
); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
return $this->reflection->isInstance($object); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
public function isInstantiable() |
242
|
|
|
{ |
243
|
|
|
return $this->reflection->isInstantiable(); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
public function isInterface() |
247
|
|
|
{ |
248
|
|
|
return $this->reflection->isInterface(); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
public function isInternal() |
252
|
|
|
{ |
253
|
|
|
return $this->reflection->isInternal(); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
public function isIterateable() |
257
|
|
|
{ |
258
|
|
|
return $this->reflection->isIterateable(); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
View Code Duplication |
public function isSubclassOf($class) |
|
|
|
|
262
|
|
|
{ |
263
|
|
|
if (!is_string($class)) { |
264
|
|
|
throw Exception\ReflectionExceptionFactory::invalidArgument( |
265
|
|
|
sprintf("Parameter 1 of %s must be a string.", __METHOD__) |
266
|
|
|
); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
return $this->reflection->isSubclassOf($class); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
public function isTrait() |
273
|
|
|
{ |
274
|
|
|
return $this->reflection->isTrait(); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
public function isUserDefined() |
278
|
|
|
{ |
279
|
|
|
return $this->reflection->isUserDefined(); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
public function newInstance() |
283
|
|
|
{ |
284
|
|
|
return call_user_func_array([$this->reflection, 'newInstance'], func_get_args()); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
public function newInstanceArgs($args) |
288
|
|
|
{ |
289
|
|
|
if (!is_array($args)) { |
290
|
|
|
throw Exception\ReflectionExceptionFactory::invalidArgument( |
291
|
|
|
sprintf("Parameter 1 of %s must be an array.", __METHOD__) |
292
|
|
|
); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
return $this->reflection->newInstanceArgs($args); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function newInstanceWithoutConstructor() |
299
|
|
|
{ |
300
|
|
|
return $this->reflection->newInstanceWithoutConstructor(); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
public function setStaticPropertyValue($name, $value) |
304
|
|
|
{ |
305
|
|
|
if (!is_string($name)) { |
306
|
|
|
throw Exception\ReflectionExceptionFactory::invalidArgument( |
307
|
|
|
sprintf("Parameter 1 of %s must be a string.", __METHOD__) |
308
|
|
|
); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
if (!isset($value)) { |
312
|
|
|
throw Exception\ReflectionExceptionFactory::invalidArgument( |
313
|
|
|
sprintf("Parameter 2 of %s must be set.", __METHOD__) |
314
|
|
|
); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
$this->reflection->setStaticPropertyValue($name, $value); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
public function __toString() |
321
|
|
|
{ |
322
|
|
|
return call_user_func([$this->reflection, '__toString']); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
public function getReflector() |
326
|
|
|
{ |
327
|
|
|
return $this->reflection; |
328
|
|
|
} |
329
|
|
|
} |
330
|
|
|
|