ILIAS  release_7 Revision v7.30-3-g800a261c036
AbstractParentItem.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
21
26abstract class AbstractParentItem extends AbstractBaseItem implements isParent
27{
31 protected $children = [];
32
36 public function getChildren() : array
37 {
38 return $this->children;
39 }
40
44 public function withChildren(array $children) : isParent
45 {
46 $clone = clone($this);
47 $clone->children = $children;
48
49 return $clone;
50 }
51
55 public function appendChild(isItem $child) : isParent
56 {
57 $this->children[] = $child;
58
59 return $this;
60 }
61
65 public function hasChildren() : bool
66 {
67 return (count($this->children) > 0);
68 }
69
73 public function removeChild(isItem $child_to_remove) : isParent
74 {
75 $this->children = array_filter($this->children, static function (isItem $item) use ($child_to_remove) : bool {
76 return $item !== $child_to_remove;
77 });
78
79 return $this;
80 }
81}
An exception for terminatinating execution or to throw for unit testing.