1 | <?php |
||
12 | class TreeBuilder |
||
13 | { |
||
14 | /** |
||
15 | * Transforms array in form [1,2 => [3]] to [1=>[], 2=>[3=>[]]]. |
||
16 | */ |
||
17 | const NORMALIZE_CONFIG = 1; |
||
18 | |||
19 | /** |
||
20 | * Allows absent nodes in config. |
||
21 | */ |
||
22 | const ALLOW_ABSENT_ITEMS = 2; |
||
23 | |||
24 | const RESET_CHILDREN = 4; |
||
25 | |||
26 | private $defaultFlags; |
||
27 | |||
28 | public function __construct($defaultFlags = 0) |
||
32 | |||
33 | /** |
||
34 | * Builds tree from plain nodes based on configuration. |
||
35 | * |
||
36 | * @param array $config multidimensional array that represents tree structure |
||
37 | * @param NodeInterface[] $plainItems nodes that must be organized to tree |
||
38 | * @param int $flags specifies tree building options, default: TreeBuilder::NORMALIZE_CONFIG; see TreeBuilder constants |
||
39 | * |
||
40 | * @return NodeInterface[] items organized to tree structure; array keys are not preserved |
||
41 | */ |
||
42 | public function build(array $config, array $plainItems, $flags = self::NORMALIZE_CONFIG) |
||
87 | |||
88 | /** |
||
89 | * Transforms array in form [1,2 => [3]] to [1=>[], 2=>[3=>[]]]. |
||
90 | * |
||
91 | * @param array $config |
||
92 | * |
||
93 | * @return array |
||
94 | */ |
||
95 | protected function normalizeConfig(array $config) |
||
108 | } |
||
109 |