1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2015 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Reflection; |
14
|
|
|
|
15
|
|
|
use phpDocumentor\Reflection\DocBlock\Tag; |
16
|
|
|
use Webmozart\Assert\Assert; |
17
|
|
|
|
18
|
|
|
final class DocBlock |
19
|
|
|
{ |
20
|
|
|
/** @var string The opening line for this docblock. */ |
21
|
|
|
private $summary = ''; |
22
|
|
|
|
23
|
|
|
/** @var DocBlock\Description The actual description for this docblock. */ |
24
|
|
|
private $description = null; |
25
|
|
|
|
26
|
|
|
/** @var Tag[] An array containing all the tags in this docblock; except inline. */ |
27
|
|
|
private $tags = array(); |
28
|
|
|
|
29
|
|
|
/** @var Types\Context Information about the context of this DocBlock. */ |
30
|
|
|
private $context = null; |
31
|
|
|
|
32
|
|
|
/** @var Location Information about the location of this DocBlock. */ |
33
|
|
|
private $location = null; |
34
|
|
|
|
35
|
|
|
/** @var bool Is this DocBlock (the start of) a template? */ |
36
|
|
|
private $isTemplateStart = false; |
37
|
|
|
|
38
|
|
|
/** @var bool Does this DocBlock signify the end of a DocBlock template? */ |
39
|
|
|
private $isTemplateEnd = false; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $summary |
43
|
|
|
* @param DocBlock\Description $description |
44
|
|
|
* @param DocBlock\Tag[] $tags |
45
|
|
|
* @param Types\Context $context The context in which the DocBlock occurs. |
46
|
|
|
* @param Location $location The location within the file that this DocBlock occurs in. |
47
|
|
|
* @param bool $isTemplateStart |
48
|
|
|
* @param bool $isTemplateEnd |
49
|
|
|
*/ |
50
|
13 |
|
public function __construct( |
51
|
2 |
|
$summary = '', |
52
|
4 |
|
DocBlock\Description $description = null, |
53
|
5 |
|
array $tags = [], |
54
|
9 |
|
Types\Context $context = null, |
55
|
10 |
|
Location $location = null, |
56
|
11 |
|
$isTemplateStart = false, |
57
|
13 |
|
$isTemplateEnd = false |
58
|
|
|
) |
59
|
|
|
{ |
|
|
|
|
60
|
1 |
|
Assert::string($summary); |
61
|
1 |
|
Assert::boolean($isTemplateStart); |
62
|
1 |
|
Assert::boolean($isTemplateEnd); |
63
|
1 |
|
Assert::allIsInstanceOf($tags, Tag::class); |
64
|
|
|
|
65
|
11 |
|
$this->summary = $summary; |
66
|
1 |
|
$this->description = $description ?: new DocBlock\Description(''); |
67
|
|
|
foreach ($tags as $tag) { |
68
|
|
|
$this->addTag($tag); |
69
|
8 |
|
} |
70
|
|
|
|
71
|
11 |
|
$this->context = $context; |
72
|
11 |
|
$this->location = $location; |
73
|
|
|
|
74
|
11 |
|
$this->isTemplateEnd = $isTemplateEnd; |
75
|
11 |
|
$this->isTemplateStart = $isTemplateStart; |
76
|
2 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
1 |
|
public function getSummary() |
82
|
|
|
{ |
83
|
1 |
|
return $this->summary; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return DocBlock\Description |
88
|
|
|
*/ |
89
|
1 |
|
public function getDescription() |
90
|
|
|
{ |
91
|
1 |
|
return $this->description; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Returns the current context. |
96
|
|
|
* |
97
|
|
|
* @return Types\Context |
98
|
|
|
*/ |
99
|
1 |
|
public function getContext() |
100
|
|
|
{ |
101
|
1 |
|
return $this->context; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Returns the current location. |
106
|
|
|
* |
107
|
|
|
* @return Location |
108
|
|
|
*/ |
109
|
1 |
|
public function getLocation() |
110
|
|
|
{ |
111
|
1 |
|
return $this->location; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Returns whether this DocBlock is the start of a Template section. |
116
|
|
|
* |
117
|
|
|
* A Docblock may serve as template for a series of subsequent DocBlocks. This is indicated by a special marker |
118
|
|
|
* (`#@+`) that is appended directly after the opening `/**` of a DocBlock. |
119
|
|
|
* |
120
|
|
|
* An example of such an opening is: |
121
|
|
|
* |
122
|
|
|
* ``` |
123
|
|
|
* /**#@+ |
124
|
|
|
* * My DocBlock |
125
|
|
|
* * / |
126
|
|
|
* ``` |
127
|
|
|
* |
128
|
|
|
* The description and tags (not the summary!) are copied onto all subsequent DocBlocks and also applied to all |
129
|
|
|
* elements that follow until another DocBlock is found that contains the closing marker (`#@-`). |
130
|
|
|
* |
131
|
|
|
* @see self::isTemplateEnd() for the check whether a closing marker was provided. |
132
|
|
|
* |
133
|
|
|
* @return boolean |
134
|
|
|
*/ |
135
|
1 |
|
public function isTemplateStart() |
136
|
|
|
{ |
137
|
1 |
|
return $this->isTemplateStart; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Returns whether this DocBlock is the end of a Template section. |
142
|
|
|
* |
143
|
|
|
* @see self::isTemplateStart() for a more complete description of the Docblock Template functionality. |
144
|
|
|
* |
145
|
|
|
* @return boolean |
146
|
|
|
*/ |
147
|
1 |
|
public function isTemplateEnd() |
148
|
|
|
{ |
149
|
1 |
|
return $this->isTemplateEnd; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Returns the tags for this DocBlock. |
154
|
|
|
* |
155
|
|
|
* @return Tag[] |
156
|
|
|
*/ |
157
|
1 |
|
public function getTags() |
158
|
|
|
{ |
159
|
1 |
|
return $this->tags; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Returns an array of tags matching the given name. If no tags are found |
164
|
|
|
* an empty array is returned. |
165
|
|
|
* |
166
|
|
|
* @param string $name String to search by. |
167
|
|
|
* |
168
|
|
|
* @return Tag[] |
169
|
|
|
*/ |
170
|
1 |
|
public function getTagsByName($name) |
171
|
|
|
{ |
172
|
1 |
|
Assert::string($name); |
173
|
|
|
|
174
|
|
|
$result = array(); |
175
|
|
|
|
176
|
|
|
/** @var Tag $tag */ |
177
|
|
|
foreach ($this->getTags() as $tag) { |
178
|
|
|
if ($tag->getName() != $name) { |
179
|
|
|
continue; |
180
|
|
|
} |
181
|
|
|
|
182
|
1 |
|
$result[] = $tag; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
return $result; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Checks if a tag of a certain type is present in this DocBlock. |
190
|
|
|
* |
191
|
|
|
* @param string $name Tag name to check for. |
192
|
|
|
* |
193
|
|
|
* @return bool |
194
|
|
|
*/ |
195
|
1 |
|
public function hasTag($name) |
196
|
|
|
{ |
197
|
1 |
|
Assert::string($name); |
198
|
|
|
|
199
|
|
|
/** @var Tag $tag */ |
200
|
|
|
foreach ($this->getTags() as $tag) { |
201
|
|
|
if ($tag->getName() == $name) { |
202
|
1 |
|
return true; |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
|
|
206
|
1 |
|
return false; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* Adds a tag to this DocBlock. |
211
|
|
|
* |
212
|
|
|
* @param Tag $tag The tag to add. |
213
|
|
|
* |
214
|
|
|
* @return void |
215
|
|
|
*/ |
216
|
1 |
|
private function addTag(Tag $tag) |
217
|
|
|
{ |
218
|
1 |
|
$this->tags[] = $tag; |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|