Files
jsonedit/src/Tree/ArrayNode.php
T

37 lines
674 B
PHP
Raw Normal View History

2024-10-01 18:46:03 +02:00
<?php
namespace NoccyLabs\JsonEdit\Tree;
2024-10-01 18:46:03 +02:00
class ArrayNode extends Node implements CollapsibleNode
{
use CollapsibleNodeTrait;
public function __construct(public array $items)
{
}
public function append(Node $value)
{
$this->items[] = $value;
}
public function removeIndex(int $index)
{
unset($this->items[$index]);
$this->items = array_values($this->items);
}
public function __clone()
{
$items = array_map(fn($v) => clone $v, $this->items);
return new ArrayNode($items);
}
2024-10-01 21:40:13 +02:00
public function jsonSerialize(): mixed
{
return array_values($this->items);
}
2024-10-01 18:46:03 +02:00
}