|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Atreyu; |
|
4
|
|
|
|
|
5
|
|
|
use phpDocumentor\Reflection\DocBlock; |
|
6
|
|
|
use phpDocumentor\Reflection\DocBlock\Context; |
|
7
|
|
|
|
|
8
|
|
|
class StandardReflector extends BaseReflector implements Reflector |
|
9
|
|
|
{ |
|
10
|
|
|
public function getClass($class) |
|
11
|
|
|
{ |
|
12
|
|
|
return new ExtendedReflectionClass($class); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function getCtor($class) |
|
16
|
|
|
{ |
|
17
|
|
|
$reflectionClass = new ExtendedReflectionClass($class); |
|
18
|
|
|
|
|
19
|
|
|
return $reflectionClass->getConstructor(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function getCtorParams($class) |
|
23
|
|
|
{ |
|
24
|
|
|
return ($reflectedCtor = $this->getCtor($class)) |
|
25
|
|
|
? $reflectedCtor->getParameters() |
|
26
|
|
|
: null; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getParamTypeHint(\ReflectionFunctionAbstract $function, \ReflectionParameter $param, array $arguments = []) |
|
30
|
|
|
{ |
|
31
|
|
|
if ($reflectionClass = $param->getClass()) { |
|
32
|
|
|
$typeHint = $reflectionClass->getName(); |
|
33
|
|
|
} elseif (($function instanceof \ReflectionMethod) |
|
34
|
|
|
&& ($docBlockParams = $this->getDocBlock($function)->getTagsByName('param')) |
|
35
|
|
|
&& !empty($docBlockParams) |
|
36
|
|
|
) { |
|
37
|
|
|
$typeHint = $this->getParamDocBlockHint($docBlockParams, $param, $arguments); |
|
38
|
|
|
} else { |
|
39
|
|
|
$typeHint = null; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
return $typeHint; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function getFunction($functionName) |
|
46
|
|
|
{ |
|
47
|
|
|
return new \ReflectionFunction($functionName); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getMethod($classNameOrInstance, $methodName) |
|
51
|
|
|
{ |
|
52
|
|
|
$className = is_string($classNameOrInstance) |
|
53
|
|
|
? $classNameOrInstance |
|
54
|
|
|
: get_class($classNameOrInstance); |
|
55
|
|
|
|
|
56
|
|
|
return new \ReflectionMethod($className, $methodName); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getDocBlock(\ReflectionMethod $method) |
|
60
|
|
|
{ |
|
61
|
|
|
$class = $this->getClass($method->class); |
|
62
|
|
|
|
|
63
|
|
|
return new DocBlock( |
|
64
|
|
|
$method->getDocComment(), |
|
65
|
|
|
new Context( |
|
66
|
|
|
$class->getNamespaceName(), |
|
67
|
|
|
$class->getUseStatements() |
|
68
|
|
|
) |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|