1 | <?php |
||
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 | 15 | public function __construct( |
|
77 | |||
78 | /** |
||
79 | * @return string |
||
80 | */ |
||
81 | 1 | public function getSummary() |
|
85 | |||
86 | /** |
||
87 | * @return DocBlock\Description |
||
88 | */ |
||
89 | 1 | public function getDescription() |
|
93 | |||
94 | /** |
||
95 | * Returns the current context. |
||
96 | * |
||
97 | * @return Types\Context |
||
98 | */ |
||
99 | 1 | public function getContext() |
|
103 | |||
104 | /** |
||
105 | * Returns the current location. |
||
106 | * |
||
107 | * @return Location |
||
108 | */ |
||
109 | 1 | public function getLocation() |
|
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() |
|
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() |
|
151 | |||
152 | /** |
||
153 | * Returns the tags for this DocBlock. |
||
154 | * |
||
155 | * @return Tag[] |
||
156 | */ |
||
157 | 1 | public function getTags() |
|
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 | 2 | public function getTagsByName($name) |
|
171 | { |
||
172 | 2 | Assert::string($name); |
|
173 | |||
174 | 1 | $result = array(); |
|
175 | |||
176 | /** @var Tag $tag */ |
||
177 | 1 | foreach ($this->getTags() as $tag) { |
|
178 | 1 | if ($tag->getName() != $name) { |
|
179 | 1 | continue; |
|
180 | } |
||
181 | |||
182 | 1 | $result[] = $tag; |
|
183 | } |
||
184 | |||
185 | 1 | 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 | 2 | public function hasTag($name) |
|
196 | { |
||
197 | 2 | Assert::string($name); |
|
198 | |||
199 | /** @var Tag $tag */ |
||
200 | 1 | foreach ($this->getTags() as $tag) { |
|
201 | 1 | 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 | 3 | private function addTag(Tag $tag) |
|
220 | } |
||
221 |