1 | <?php |
||
13 | abstract class InnerNode extends ArrayNode |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * An array of all the children. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $children = []; |
||
22 | |||
23 | /** |
||
24 | * Sets the encoding class to this node and propagates it |
||
25 | * to all its children. |
||
26 | * |
||
27 | * @param Encode $encode |
||
28 | * @return void |
||
29 | */ |
||
30 | public function propagateEncoding(Encode $encode) |
||
41 | |||
42 | /** |
||
43 | * Checks if this node has children. |
||
44 | * |
||
45 | * @return bool |
||
46 | */ |
||
47 | public function hasChildren() |
||
51 | |||
52 | /** |
||
53 | * Returns the child by id. |
||
54 | * |
||
55 | * @param int $id |
||
56 | * @return AbstractNode |
||
57 | * @throws ChildNotFoundException |
||
58 | */ |
||
59 | public function getChild($id) |
||
67 | |||
68 | /** |
||
69 | * Returns a new array of child nodes |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | public function getChildren() |
||
88 | |||
89 | /** |
||
90 | * Counts children |
||
91 | * |
||
92 | * @return int |
||
93 | */ |
||
94 | public function countChildren() |
||
98 | |||
99 | /** |
||
100 | * Adds a child node to this node and returns the id of the child for this |
||
101 | * parent. |
||
102 | * |
||
103 | * @param AbstractNode $child |
||
104 | * @return bool |
||
105 | * @throws CircularException |
||
106 | */ |
||
107 | public function addChild(AbstractNode $child) |
||
146 | |||
147 | /** |
||
148 | * Removes the child by id. |
||
149 | * |
||
150 | * @param int $id |
||
151 | * @return $this |
||
152 | */ |
||
153 | public function removeChild($id) |
||
177 | |||
178 | /** |
||
179 | * Check if has next Child |
||
180 | * |
||
181 | * @param $id childId |
||
182 | * @return mixed |
||
183 | */ |
||
184 | public function hasNextChild($id) |
||
189 | |||
190 | /** |
||
191 | * Attempts to get the next child. |
||
192 | * |
||
193 | * @param int $id |
||
194 | * @return AbstractNode |
||
195 | * @uses $this->getChild() |
||
196 | * @throws ChildNotFoundException |
||
197 | */ |
||
198 | public function nextChild($id) |
||
205 | |||
206 | /** |
||
207 | * Attempts to get the previous child. |
||
208 | * |
||
209 | * @param int $id |
||
210 | * @return AbstractNode |
||
211 | * @uses $this->getChild() |
||
212 | * @throws ChildNotFoundException |
||
213 | */ |
||
214 | public function previousChild($id) |
||
221 | |||
222 | /** |
||
223 | * Checks if the given node id is a child of the |
||
224 | * current node. |
||
225 | * |
||
226 | * @param int $id |
||
227 | * @return bool |
||
228 | */ |
||
229 | public function isChild($id) |
||
239 | |||
240 | /** |
||
241 | * Removes the child with id $childId and replace it with the new child |
||
242 | * $newChild. |
||
243 | * |
||
244 | * @param int $childId |
||
245 | * @param AbstractNode $newChild |
||
246 | * @throws ChildNotFoundException |
||
247 | */ |
||
248 | public function replaceChild($childId, AbstractNode $newChild) |
||
258 | |||
259 | /** |
||
260 | * Shortcut to return the first child. |
||
261 | * |
||
262 | * @return AbstractNode |
||
263 | * @uses $this->getChild() |
||
264 | */ |
||
265 | public function firstChild() |
||
272 | |||
273 | /** |
||
274 | * Attempts to get the last child. |
||
275 | * |
||
276 | * @return AbstractNode |
||
277 | */ |
||
278 | public function lastChild() |
||
285 | |||
286 | /** |
||
287 | * Checks if the given node id is a descendant of the |
||
288 | * current node. |
||
289 | * |
||
290 | * @param int $id |
||
291 | * @return bool |
||
292 | */ |
||
293 | public function isDescendant($id) |
||
312 | |||
313 | /** |
||
314 | * Sets the parent node. |
||
315 | * |
||
316 | * @param InnerNode $parent |
||
317 | * @return $this |
||
318 | * @throws CircularException |
||
319 | */ |
||
320 | public function setParent(InnerNode $parent) |
||
329 | } |