type = $type; } /** * @return array */ abstract protected function getContent(): array; /** * @return string */ public function serialize(): string { $data = [$this->type]; $content = $this->getContent(); if (!empty($content)) $data[] = $content; return json_encode($data); } }