1: <?php declare(strict_types=1);
2:
3: namespace Salient\Contract\Core;
4:
5: /**
6: * @api
7: */
8: interface HierarchyInterface
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)` has the same effect as
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: * Equivalent to `$child->setParent($parent)`.
41: *
42: * @param static $child
43: * @return $this
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 $this
54: */
55: public function removeChild($child);
56:
57: /**
58: * Get the object's distance from the top of the hierarchy it belongs to
59: *
60: * Returns `0` if the object has no parent, `1` if its parent has no parent,
61: * and so on.
62: */
63: public function getDepth(): int;
64:
65: /**
66: * Get the number of objects descended from the object
67: */
68: public function getDescendantCount(): int;
69: }
70: