1 | <?php |
||
5 | class ArrayNode implements NodeInterface |
||
6 | { |
||
7 | /** |
||
8 | * @var string |
||
9 | */ |
||
10 | protected $name; |
||
11 | |||
12 | /** |
||
13 | * @var NodeInterface[]|array |
||
14 | */ |
||
15 | protected $children = []; |
||
16 | |||
17 | /** |
||
18 | * @param string $name |
||
19 | */ |
||
20 | public function __construct($name) |
||
24 | |||
25 | /** |
||
26 | * @return string |
||
27 | */ |
||
28 | public function getName() |
||
32 | |||
33 | /** |
||
34 | * @param NodeInterface $node |
||
35 | * @return $this |
||
36 | */ |
||
37 | public function add(NodeInterface $node) |
||
38 | { |
||
39 | if (false !== $index = array_search($node, $this->children, true)) { |
||
40 | throw new \InvalidArgumentException(sprintf('Child already added index: %d', $index)); |
||
41 | } |
||
42 | |||
43 | $this->children[] = $node; |
||
44 | |||
45 | return $this; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param NodeInterface $node |
||
50 | * @return $this |
||
51 | */ |
||
52 | public function remove(NodeInterface $node) |
||
53 | { |
||
54 | if (false !== $index = array_search($node, $this->children, true)) { |
||
55 | unset($this->children[$index]); |
||
56 | } |
||
57 | |||
58 | return $this; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @return array |
||
63 | */ |
||
64 | public function serialize() |
||
76 | } |
||
77 |