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 static
34: */
35: public function setParent($parent);
36:
37: /**
38: * Add a child to the object
39: *
40: * Equivalent to `$child->setParent($parent)`.
41: *
42: * @param static $child
43: * @return static
44: */
45: public function addChild($child);
46:
47: /**
48: * Remove a child from the object
49: *
50: * Equivalent to `$child->setParent(null)`.
51: *
52: * @param static $child
53: * @return static
54: */
55: public function removeChild($child);
56:
57: /**
58: * Get the length of the path to the object's root node
59: */
60: public function getDepth(): int;
61:
62: /**
63: * Get the number of objects descended from the object
64: */
65: public function countDescendants(): int;
66: }
67: