ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
AbstractParentItem.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 abstract class AbstractParentItem extends AbstractBaseItem implements isParent
28 {
32  protected array $children = [];
33 
37  public function getChildren(): array
38  {
39  return $this->children;
40  }
41 
45  public function withChildren(array $children): isParent
46  {
47  $clone = clone($this);
48  $clone->children = $children;
49 
50  return $clone;
51  }
52 
56  public function appendChild(isItem $child): isParent
57  {
58  $this->children[] = $child;
59 
60  return $this;
61  }
62 
66  public function hasChildren(): bool
67  {
68  return ($this->children !== []);
69  }
70 
74  public function removeChild(isItem $child_to_remove): isParent
75  {
76  $this->children = array_filter($this->children, static fn(isItem $item): bool => $item !== $child_to_remove);
77 
78  return $this;
79  }
80 }