1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of cloak. |
5
|
|
|
* |
6
|
|
|
* (c) Noritaka Horio <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace cloak\reflection; |
13
|
|
|
|
14
|
|
|
use cloak\reflection\collection\ReflectionCollection; |
15
|
|
|
use cloak\result\LineResultSelectable; |
16
|
|
|
use cloak\value\LineRange; |
17
|
|
|
use cloak\result\type\ClassResult; |
18
|
|
|
use cloak\result\type\TraitResult; |
19
|
|
|
use Zend\Code\Reflection\ClassReflection as ZendClassReflection; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class ClassReflection |
24
|
|
|
* @package cloak\reflection |
25
|
|
|
*/ |
26
|
|
|
class ClassReflection implements Reflection, ResultConvertible |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var \Zend\Code\Reflection\ClassReflection |
31
|
|
|
*/ |
32
|
|
|
private $reflection; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $className |
37
|
|
|
*/ |
38
|
|
|
public function __construct($className) |
39
|
|
|
{ |
40
|
|
|
$this->reflection = new ZendClassReflection($className); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
|
|
public function getIdentityName() |
47
|
|
|
{ |
48
|
|
|
$template = '%s\\%s'; |
49
|
|
|
$assembleContent = sprintf( |
50
|
|
|
$template, |
51
|
|
|
$this->getNamespaceName(), |
52
|
|
|
$this->getName() |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
return $assembleContent; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
|
|
public function getName() |
62
|
|
|
{ |
63
|
|
|
return $this->reflection->name; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getNamespaceName() |
70
|
|
|
{ |
71
|
|
|
return $this->reflection->getNamespaceName(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
|
|
public function isTrait() |
78
|
|
|
{ |
79
|
|
|
return $this->reflection->isTrait(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
public function isClass() |
86
|
|
|
{ |
87
|
|
|
return $this->isTrait() === false; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* {@inheritdoc} |
92
|
|
|
*/ |
93
|
|
|
public function getLineRange() |
94
|
|
|
{ |
95
|
|
|
$startLine = $this->reflection->getStartLine(); |
96
|
|
|
$endLine = $this->reflection->getEndLine(); |
97
|
|
|
|
98
|
|
|
return new LineRange($startLine, $endLine); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return ReflectionCollection |
103
|
|
|
*/ |
104
|
|
|
public function getMethods() |
105
|
|
|
{ |
106
|
|
|
$className = $this->reflection->name; |
107
|
|
|
$selector = MethodSelector::fromClassName($className); |
108
|
|
|
|
109
|
|
|
$result = $selector->excludeNative() |
110
|
|
|
->excludeInherited() |
111
|
|
|
->excludeTraitMethods() |
112
|
|
|
->toCollection(); |
113
|
|
|
|
114
|
|
|
return $result; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* {@inheritdoc} |
119
|
|
|
*/ |
120
|
|
|
public function convertToResult(LineResultSelectable $selector) |
121
|
|
|
{ |
122
|
|
|
if ($this->isClass()) { |
123
|
|
|
$result = new ClassResult($this, $selector); |
124
|
|
|
} else { |
125
|
|
|
$result = new TraitResult($this, $selector); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $result; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function __toString() |
135
|
|
|
{ |
136
|
|
|
return $this->getIdentityName(); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
} |
140
|
|
|
|