public function addPage($page) { if (is_array($page)) { $page = Page::fromArray($page); } if (!$page instanceof Page) { throw new ErrorException('Page must be instance of App\\Navigation\\Page or an array'); } $hash = $page->getHashCode(); if (isset($this[$hash])) { return $this; } $this->dirtyIndex = true; $page->setParent($this); $this[$hash] = $page; return $this; }