1 | <?php declare(strict_types = 1); |
||
13 | class TreeNode extends AbstractIterable |
||
14 | { |
||
15 | /** string Internal collection name for iteration and counting */ |
||
16 | protected const COLLECTION_NAME = 'children'; |
||
17 | |||
18 | /** @var TreeNode[] Collection of tree node children */ |
||
19 | public $children = []; |
||
20 | |||
21 | /** @var string Tree node identifier */ |
||
22 | public $identifier; |
||
23 | |||
24 | /** @var self Pointer to parent node */ |
||
25 | public $parent; |
||
26 | |||
27 | /** @var string Tree node value */ |
||
28 | public $value; |
||
29 | |||
30 | /** @var string Tree node full value */ |
||
31 | public $fullValue; |
||
32 | |||
33 | /** |
||
34 | * TreeNode constructor. |
||
35 | * |
||
36 | * @param string $value Node value |
||
37 | * @param string $identifier Node identifier |
||
38 | * @param TreeNode $parent Pointer to parent node |
||
39 | */ |
||
40 | 1 | public function __construct(string $value = '', string $identifier = '', TreeNode $parent = null) |
|
49 | |||
50 | /** |
||
51 | * Convert tree node to associative array. |
||
52 | * |
||
53 | * @return array Tree structure as hashed array |
||
54 | */ |
||
55 | 1 | public function toArray(): array |
|
74 | |||
75 | /** |
||
76 | * Append new node instance and return it. |
||
77 | * |
||
78 | * @param string $value Node value |
||
79 | * @param string $identifier Node identifier |
||
80 | * |
||
81 | * @return TreeNode New created node instance |
||
82 | */ |
||
83 | 1 | public function append(string $value, string $identifier): TreeNode |
|
87 | } |
||
88 |