*/ public array $children = []; /** * Create OutlineNode from JSON array * * @param array $data JSON data * @return self */ public static function fromArray(array $data): self { $node = new self(); $node->title = $data['title']; $node->level = $data['level']; $node->page_index = $data['page_index'] ?? null; if (isset($data['destination']) && $data['destination'] !== null) { $node->destination = Destination::fromArray($data['destination']); } foreach ($data['children'] ?? [] as $item) { $node->children[] = self::fromArray($item); } return $node; } /** * Convert to JSON array * * @return array */ public function toArray(): array { $data = [ 'title' => $this->title, 'level' => $this->level, 'children' => array_map(fn($c) => $c->toArray(), $this->children), ]; if ($this->page_index !== null) { $data['page_index'] = $this->page_index; } if ($this->destination !== null) { $data['destination'] = $this->destination->toArray(); } return $data; } }