*/ public array $beads = []; /** * Create Thread from JSON array * * @param array $data JSON data * @return self */ public static function fromArray(array $data): self { $thread = new self(); $thread->title = $data['title'] ?? null; $thread->author = $data['author'] ?? null; $thread->subject = $data['subject'] ?? null; $thread->keywords = $data['keywords'] ?? null; foreach ($data['beads'] ?? [] as $item) { $thread->beads[] = Bead::fromArray($item); } return $thread; } /** * Convert to JSON array * * @return array */ public function toArray(): array { $data = [ 'beads' => array_map(fn($b) => $b->toArray(), $this->beads), ]; if ($this->title !== null) { $data['title'] = $this->title; } if ($this->author !== null) { $data['author'] = $this->author; } if ($this->subject !== null) { $data['subject'] = $this->subject; } if ($this->keywords !== null) { $data['keywords'] = $this->keywords; } return $data; } }