|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* This file is part of phpDocumentor. |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @copyright 2010-2018 Mike van Riel<[email protected]> |
|
11
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
|
12
|
|
|
* @link http://phpdoc.org |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace phpDocumentor\Reflection\Php; |
|
16
|
|
|
|
|
17
|
|
|
use phpDocumentor\Reflection\DocBlock; |
|
18
|
|
|
use phpDocumentor\Reflection\Element; |
|
19
|
|
|
use phpDocumentor\Reflection\Fqsen; |
|
20
|
|
|
use phpDocumentor\Reflection\Location; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Descriptor representing a Class. |
|
24
|
|
|
*/ |
|
25
|
|
|
// @codingStandardsIgnoreStart |
|
26
|
|
|
final class Class_ implements Element |
|
27
|
|
|
// @codingStandardsIgnoreEnd |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var Fqsen Full Qualified Structural Element Name |
|
31
|
|
|
*/ |
|
32
|
|
|
private $fqsen; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var DocBlock|null |
|
36
|
|
|
*/ |
|
37
|
|
|
private $docBlock = null; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var boolean Whether this is an abstract class. |
|
41
|
|
|
*/ |
|
42
|
|
|
private $abstract = false; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var boolean Whether this class is marked as final and can't be subclassed. |
|
46
|
|
|
*/ |
|
47
|
|
|
private $final = false; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var null|Fqsen The class this class is extending. |
|
51
|
|
|
*/ |
|
52
|
|
|
private $parent = null; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var Fqsen[] References to interfaces that are implemented by this class. |
|
56
|
|
|
*/ |
|
57
|
|
|
private $implements = []; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var Constant[] References to constants defined in this class. |
|
61
|
|
|
*/ |
|
62
|
|
|
private $constants = []; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @var Property[] References to properties defined in this class. |
|
66
|
|
|
*/ |
|
67
|
|
|
private $properties = []; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var Method[] References to methods defined in this class. |
|
71
|
|
|
*/ |
|
72
|
|
|
private $methods = []; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @var Fqsen[] References to traits consumed by this class |
|
76
|
|
|
*/ |
|
77
|
|
|
private $usedTraits = []; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @var Location |
|
81
|
|
|
*/ |
|
82
|
|
|
private $location; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Initializes a number of properties with the given values. Others are initialized by definition. |
|
86
|
|
|
*/ |
|
87
|
3 |
|
public function __construct( |
|
88
|
|
|
Fqsen $fqsen, |
|
89
|
|
|
?DocBlock $docBlock = null, |
|
90
|
|
|
?Fqsen $parent = null, |
|
91
|
|
|
bool $abstract = false, |
|
92
|
|
|
bool $final = false, |
|
93
|
|
|
?Location $location = null |
|
94
|
|
|
) { |
|
95
|
3 |
|
if ($location === null) { |
|
96
|
3 |
|
$location = new Location(-1); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
3 |
|
$this->fqsen = $fqsen; |
|
100
|
3 |
|
$this->parent = $parent; |
|
101
|
3 |
|
$this->docBlock = $docBlock; |
|
102
|
3 |
|
$this->abstract = $abstract; |
|
103
|
3 |
|
$this->final = $final; |
|
104
|
3 |
|
$this->location = $location; |
|
105
|
3 |
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Returns true when this class is final. Otherwise returns false. |
|
109
|
|
|
*/ |
|
110
|
1 |
|
public function isFinal(): bool |
|
111
|
|
|
{ |
|
112
|
1 |
|
return $this->final; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Returns true when this class is abstract. Otherwise returns false. |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function isAbstract(): bool |
|
119
|
|
|
{ |
|
120
|
1 |
|
return $this->abstract; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Returns the superclass this class is extending if available. |
|
125
|
|
|
*/ |
|
126
|
1 |
|
public function getParent(): ?Fqsen |
|
127
|
|
|
{ |
|
128
|
1 |
|
return $this->parent; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Returns the interfaces this class is implementing. |
|
133
|
|
|
* |
|
134
|
|
|
* @return Fqsen[] |
|
135
|
|
|
*/ |
|
136
|
1 |
|
public function getInterfaces(): array |
|
137
|
|
|
{ |
|
138
|
1 |
|
return $this->implements; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Add a interface Fqsen this class is implementing. |
|
143
|
|
|
*/ |
|
144
|
1 |
|
public function addInterface(Fqsen $interface): void |
|
145
|
|
|
{ |
|
146
|
1 |
|
$this->implements[(string) $interface] = $interface; |
|
147
|
1 |
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Returns the constants of this class. |
|
151
|
|
|
* |
|
152
|
|
|
* @return Constant[] |
|
153
|
|
|
*/ |
|
154
|
1 |
|
public function getConstants(): array |
|
155
|
|
|
{ |
|
156
|
1 |
|
return $this->constants; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Add Constant to this class. |
|
161
|
|
|
*/ |
|
162
|
1 |
|
public function addConstant(Constant $constant): void |
|
163
|
|
|
{ |
|
164
|
1 |
|
$this->constants[(string) $constant->getFqsen()] = $constant; |
|
165
|
1 |
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Returns the methods of this class. |
|
169
|
|
|
* |
|
170
|
|
|
* @return Method[] |
|
171
|
|
|
*/ |
|
172
|
1 |
|
public function getMethods(): array |
|
173
|
|
|
{ |
|
174
|
1 |
|
return $this->methods; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Add a method to this class. |
|
179
|
|
|
*/ |
|
180
|
1 |
|
public function addMethod(Method $method): void |
|
181
|
|
|
{ |
|
182
|
1 |
|
$this->methods[(string) $method->getFqsen()] = $method; |
|
183
|
1 |
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Returns the properties of this class. |
|
187
|
|
|
* |
|
188
|
|
|
* @return Property[] |
|
189
|
|
|
*/ |
|
190
|
1 |
|
public function getProperties(): array |
|
191
|
|
|
{ |
|
192
|
1 |
|
return $this->properties; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Add a property to this class. |
|
197
|
|
|
*/ |
|
198
|
1 |
|
public function addProperty(Property $property): void |
|
199
|
|
|
{ |
|
200
|
1 |
|
$this->properties[(string) $property->getFqsen()] = $property; |
|
201
|
1 |
|
} |
|
202
|
|
|
|
|
203
|
|
|
/** |
|
204
|
|
|
* Returns the traits used by this class. |
|
205
|
|
|
* |
|
206
|
|
|
* @return Fqsen[] |
|
207
|
|
|
*/ |
|
208
|
1 |
|
public function getUsedTraits(): array |
|
209
|
|
|
{ |
|
210
|
1 |
|
return $this->usedTraits; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Add trait fqsen used by this class. |
|
215
|
|
|
*/ |
|
216
|
1 |
|
public function addUsedTrait(Fqsen $fqsen): void |
|
217
|
|
|
{ |
|
218
|
1 |
|
$this->usedTraits[(string) $fqsen] = $fqsen; |
|
219
|
1 |
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Returns the Fqsen of the element. |
|
223
|
|
|
*/ |
|
224
|
|
|
public function getFqsen(): Fqsen |
|
225
|
|
|
{ |
|
226
|
|
|
return $this->fqsen; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* Returns the name of the element. |
|
231
|
|
|
*/ |
|
232
|
|
|
public function getName(): string |
|
233
|
|
|
{ |
|
234
|
|
|
return $this->fqsen->getName(); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
public function getDocBlock(): ?DocBlock |
|
238
|
|
|
{ |
|
239
|
|
|
return $this->docBlock; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
public function getLocation(): Location |
|
243
|
|
|
{ |
|
244
|
|
|
return $this->location; |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
|