page = new PageDetails($data["page"]); if (isset($data['file'])) { $this->file = new FileDetails($data["file"]); } if (isset($data["parent"])) { $this->parent = [ "author" => [ "name" => $data["parent"]["author"]["name"], "email" => $data["parent"]["author"]["email"], ], "id" => $data["parent"]["id"] ]; } } public function toArray() { $array = [ "page" => $this->page->toArray(), ]; if ($this->file) { $array["file"] = $this->file; } if ($this->parent) { $array["parent"] = $this->parent; } return $array; } }