| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\Contract\Core; |
| 4: | |
| 5: | /** |
| 6: | * @api |
| 7: | */ |
| 8: | interface Hierarchical |
| 9: | { |
| 10: | /** |
| 11: | * Get the parent of the object |
| 12: | * |
| 13: | * @return static|null |
| 14: | */ |
| 15: | public function getParent(); |
| 16: | |
| 17: | /** |
| 18: | * Get the children of the object |
| 19: | * |
| 20: | * @return static[] |
| 21: | */ |
| 22: | public function getChildren(): array; |
| 23: | |
| 24: | /** |
| 25: | * Set or unset the parent of the object |
| 26: | * |
| 27: | * - `$child->setParent($parent)` is equivalent to |
| 28: | * `$parent->addChild($child)` |
| 29: | * - `$child->setParent(null)` is equivalent to |
| 30: | * `$parent->removeChild($child)` |
| 31: | * |
| 32: | * @param static|null $parent |
| 33: | * @return $this |
| 34: | */ |
| 35: | public function setParent($parent); |
| 36: | |
| 37: | /** |
| 38: | * Add a child to the object |
| 39: | * |
| 40: | * `$parent->addChild($child)` is equivalent to |
| 41: | * `$child->setParent($parent)`. |
| 42: | * |
| 43: | * @param static $child |
| 44: | * @return $this |
| 45: | */ |
| 46: | public function addChild($child); |
| 47: | |
| 48: | /** |
| 49: | * Remove a child from the object |
| 50: | * |
| 51: | * `$parent->removeChild($child)` is equivalent to |
| 52: | * `$child->setParent(null)`. |
| 53: | * |
| 54: | * @param static $child |
| 55: | * @return $this |
| 56: | */ |
| 57: | public function removeChild($child); |
| 58: | |
| 59: | /** |
| 60: | * Get the length of the path to the object's root node |
| 61: | */ |
| 62: | public function getDepth(): int; |
| 63: | |
| 64: | /** |
| 65: | * Get the number of objects descended from the object |
| 66: | */ |
| 67: | public function countDescendants(): int; |
| 68: | } |
| 69: |