1 | <?php |
||
19 | class Tree implements TreeInterface |
||
20 | { |
||
21 | /** |
||
22 | * the tree |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $tree; |
||
27 | |||
28 | /** |
||
29 | * construct a tree with/without default data |
||
30 | * |
||
31 | * @param array $data |
||
32 | */ |
||
33 | public function __construct(array $data = []) |
||
37 | |||
38 | /** |
||
39 | * {@inheritDoc} |
||
40 | */ |
||
41 | public function &get(string $node) |
||
50 | |||
51 | /** |
||
52 | * {@inheritDoc} |
||
53 | */ |
||
54 | public function has(string $node): bool |
||
62 | |||
63 | /** |
||
64 | * {@inheritDoc} |
||
65 | */ |
||
66 | public function add(string $node, $data): TreeInterface |
||
85 | |||
86 | /** |
||
87 | * {@inheritDoc} |
||
88 | */ |
||
89 | public function delete(string $node): TreeInterface |
||
100 | |||
101 | /** |
||
102 | * Get the parent node |
||
103 | * |
||
104 | * @param string $node |
||
105 | * @return array |
||
106 | */ |
||
107 | protected function &parentNode(string $node): array |
||
114 | |||
115 | /** |
||
116 | * Get short name |
||
117 | * |
||
118 | * @param string $node |
||
119 | * @return string |
||
120 | */ |
||
121 | protected function getName(string $node): string |
||
126 | |||
127 | /** |
||
128 | * Fix data, convert 'flat.name' to array node name |
||
129 | * |
||
130 | * @param array $data |
||
131 | * @return array |
||
132 | */ |
||
133 | protected function fixData(array $data): array |
||
150 | |||
151 | /** |
||
152 | * Search a node in the $data, create on the fly |
||
153 | * |
||
154 | * @param string $path |
||
155 | * @param array &$data |
||
156 | * @param bool $create |
||
157 | * @return mixed null for not found |
||
158 | */ |
||
159 | protected function &searchNode(string $path, array &$data, bool $create = FALSE) |
||
170 | |||
171 | /** |
||
172 | * get or create the next/child node, return NULL if not found |
||
173 | * |
||
174 | * @param string $key |
||
175 | * @param mixed &$data |
||
176 | * @param bool $create create the node if not exist |
||
177 | * @return mixed |
||
178 | */ |
||
179 | protected function &childNode(string $key, &$data, bool $create) |
||
192 | } |