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 Trait. |
24
|
|
|
*/ |
25
|
|
|
// @codingStandardsIgnoreStart |
26
|
|
|
final class Trait_ 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; |
38
|
|
|
|
39
|
|
|
/** @var Property[] $properties */ |
40
|
|
|
private $properties = []; |
41
|
|
|
|
42
|
|
|
/** @var Method[] $methods */ |
43
|
|
|
private $methods = []; |
44
|
|
|
|
45
|
|
|
/** @var Fqsen[] $usedTraits References to traits consumed by this trait */ |
46
|
|
|
private $usedTraits = []; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var Location |
50
|
|
|
*/ |
51
|
|
|
private $location; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Initializes the all properties |
55
|
|
|
* |
56
|
|
|
* @param DocBlock|null $docBlock |
57
|
|
|
*/ |
58
|
2 |
|
public function __construct(Fqsen $fqsen, DocBlock $docBlock = null, Location $location = null) |
59
|
|
|
{ |
60
|
2 |
|
if ($location === null) { |
61
|
2 |
|
$location = new Location(-1); |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
|
$this->fqsen = $fqsen; |
65
|
2 |
|
$this->docBlock = $docBlock; |
66
|
2 |
|
$this->location = $location; |
67
|
2 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Returns the methods of this Trait. |
71
|
|
|
* |
72
|
|
|
* @return Method[] |
73
|
|
|
*/ |
74
|
1 |
|
public function getMethods(): array |
75
|
|
|
{ |
76
|
1 |
|
return $this->methods; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Add a method to this Trait |
81
|
|
|
*/ |
82
|
1 |
|
public function addMethod(Method $method): void |
83
|
|
|
{ |
84
|
1 |
|
$this->methods[(string) $method->getFqsen()] = $method; |
85
|
1 |
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Returns the properties of this trait. |
89
|
|
|
* |
90
|
|
|
* @return Property[] |
91
|
|
|
*/ |
92
|
1 |
|
public function getProperties(): array |
93
|
|
|
{ |
94
|
1 |
|
return $this->properties; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Add a property to this Trait. |
99
|
|
|
*/ |
100
|
1 |
|
public function addProperty(Property $property): void |
101
|
|
|
{ |
102
|
1 |
|
$this->properties[(string) $property->getFqsen()] = $property; |
103
|
1 |
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Returns the Fqsen of the element. |
107
|
|
|
*/ |
108
|
1 |
|
public function getFqsen(): Fqsen |
109
|
|
|
{ |
110
|
1 |
|
return $this->fqsen; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Returns the name of the element. |
115
|
|
|
*/ |
116
|
1 |
|
public function getName(): string |
117
|
|
|
{ |
118
|
1 |
|
return $this->fqsen->getName(); |
119
|
|
|
} |
120
|
|
|
|
121
|
1 |
|
public function getDocBlock(): ?DocBlock |
122
|
|
|
{ |
123
|
1 |
|
return $this->docBlock; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Returns fqsen of all traits used by this trait. |
128
|
|
|
* |
129
|
|
|
* @return Fqsen[] |
130
|
|
|
*/ |
131
|
1 |
|
public function getUsedTraits(): array |
132
|
|
|
{ |
133
|
1 |
|
return $this->usedTraits; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Add reference to trait used by this trait. |
138
|
|
|
*/ |
139
|
1 |
|
public function addUsedTrait(Fqsen $fqsen): void |
140
|
|
|
{ |
141
|
1 |
|
$this->usedTraits[(string) $fqsen] = $fqsen; |
142
|
1 |
|
} |
143
|
|
|
|
144
|
|
|
public function getLocation(): Location |
145
|
|
|
{ |
146
|
|
|
return $this->location; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|