1 | <?php |
||
28 | class Tree extends ObjectAbstract |
||
29 | { |
||
30 | /** |
||
31 | * node splitter |
||
32 | * |
||
33 | * @var string |
||
34 | * @access protected |
||
35 | */ |
||
36 | protected $splitter = '.'; |
||
37 | |||
38 | /** |
||
39 | * the result tree |
||
40 | * |
||
41 | * @var array |
||
42 | * @access protected |
||
43 | */ |
||
44 | protected $tree; |
||
45 | |||
46 | /** |
||
47 | * construct a tree |
||
48 | * |
||
49 | * @param array $data |
||
50 | * @param string $splitter |
||
51 | * @access public |
||
52 | * @api |
||
53 | */ |
||
54 | public function __construct(array $data = [], /*# string */ $splitter = '.') |
||
59 | |||
60 | /** |
||
61 | * return the whole tree |
||
62 | * |
||
63 | * @return array |
||
64 | * @access public |
||
65 | * @api |
||
66 | */ |
||
67 | public function getTree()/*# : array */ |
||
71 | |||
72 | /** |
||
73 | * Get one node, NULL if not found |
||
74 | * |
||
75 | * @param string $nodeName |
||
76 | * @return mixed |
||
77 | * @access public |
||
78 | * @api |
||
79 | */ |
||
80 | public function &getNode(/*# string */ $nodeName) |
||
89 | |||
90 | /** |
||
91 | * Has node in tree or not |
||
92 | * |
||
93 | * @param string $nodeName |
||
94 | * @return bool |
||
95 | * @access public |
||
96 | * @api |
||
97 | */ |
||
98 | public function hasNode(/*# string */ $nodeName)/*# : bool */ |
||
106 | |||
107 | /** |
||
108 | * Add one node |
||
109 | * |
||
110 | * @param string $nodeName |
||
111 | * @param mixed $data |
||
112 | * @return $this |
||
113 | * @access public |
||
114 | * @api |
||
115 | */ |
||
116 | public function addNode(/*# string */ $nodeName, $data) |
||
122 | |||
123 | /** |
||
124 | * Delete one node if exists |
||
125 | * |
||
126 | * @param string $nodeName |
||
127 | * @return $this |
||
128 | * @access public |
||
129 | * @since 2.0.5 |
||
130 | * @api |
||
131 | */ |
||
132 | public function deleteNode(/*# string */ $nodeName) |
||
147 | |||
148 | /** |
||
149 | * Fix array, convert flat name to tree node name |
||
150 | * |
||
151 | * @param array $data |
||
152 | * @return array |
||
153 | * @access protected |
||
154 | */ |
||
155 | protected function fixTree(array $data)/*# : array */ |
||
164 | |||
165 | /** |
||
166 | * Search a node in the $data |
||
167 | * |
||
168 | * @param string $key |
||
169 | * @param array &$data |
||
170 | * @param bool $create |
||
171 | * @access protected |
||
172 | */ |
||
173 | protected function &searchNode( |
||
192 | } |
||
193 |