| 1 | <?php |
||
| 5 | class ObjectNode 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 (isset($this->children[$node->getName()])) { |
||
| 40 | throw new \InvalidArgumentException(sprintf('There is already a child with name: %s', $node->getName())); |
||
| 41 | } |
||
| 42 | |||
| 43 | $this->children[$node->getName()] = $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 (isset($this->children[$node->getName()])) { |
||
| 55 | unset($this->children[$node->getName()]); |
||
| 56 | } |
||
| 57 | |||
| 58 | return $this; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return \stdClass |
||
| 63 | */ |
||
| 64 | public function serialize() |
||
| 76 | } |
||
| 77 |