Files

36 lines
648 B
PHP
Raw Permalink 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);
}
2024-10-07 00:30:09 +02:00
public function __clone(): void
2024-10-01 18:46:03 +02:00
{
2024-10-07 00:30:09 +02:00
$this->items = array_map(fn($v) => clone $v, $this->items);
2024-10-01 18:46:03 +02:00
}
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
}