This repository has been archived by the owner on Sep 23, 2022. It is now read-only.
/
NodeInterface.php
119 lines (99 loc) · 2.9 KB
/
NodeInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace Knp\Component\Tree\MaterializedPath;
use Doctrine\Common\Collections\Collection;
/**
* Tree\Node defines a set of needed mathods
* to work with materialized path tree nodes
*
* @author Florian Klein <florian.klein@free.fr>
*/
interface NodeInterface
{
/**
* @return string the id that will represent the node in the path
**/
function getId();
/**
* @return string the materialized path,
* eg the representation of path from all ancestors
**/
function getPath();
/**
* @return string the materialized path from the parent, eg: the representation of path from all parent ancestors
**/
function getParentPath();
/**
* Set parent path.
*
* @param path the value to set.
*/
function setParentPath($path);
/**
* @return NodeInterface the parent node
**/
function getParent();
/**
* @param string $path the materialized path, eg: the the materialized path to its parent
*
* @return NodeInterface $this Fluent interface
**/
function setPath($path);
/**
* Used to build the hierarchical tree.
* This method will do:
* - modify the parent of this node
* - Add the this node to the children of the new parent
* - Remove the this node from the children of the old parent
* - Modify the materialized path of this node and all its children, recursively
*
* @param NodeInterface $node The node to use as a parent
*
* @return NodeInterface $this Fluent interface
**/
function setChildOf(NodeInterface $node);
/**
* @param Collection the children collection
*
* @return NodeInterface $this Fluent interface
**/
function setNodeChildren(Collection $children);
/**
* @param NodeInterface the node to append to the children collection
*
* @return NodeInterface $this Fluent interface
**/
function addChild(NodeInterface $node);
/**
* @return Collection the children collection
**/
function getNodeChildren();
/**
* Tells if this node is a child of another node
* @param NodeInterface $node the node to compare with
*
* @return boolean true if this node is a direct child of $node
**/
function isChildOf(NodeInterface $node);
/**
* @param integer|mixed the value used to sort nodes in current level
*
* @return NodeInterface $this Fluent interface
**/
function setSort($sort);
/**
*
* @return integer|mixed the value used to sort nodes in current level
**/
function getSort();
/**
*
* @return integer the level of this node, eg: the depth compared to root node
**/
function getLevel();
/**
* Builds a hierarchical tree from a flat collection of NodeInterface elements
*
* @return void
**/
function buildTree(\Traversable $nodes);
}