/** * * @param string $index * @return array */ public function findByIndex($index) { try { return $this->menuList->getNodeByIndex($index); } catch (MenuException $e) { return NULL; } }
/** * * @param array|\Travesable $data * @return Menu * @throws MenuException */ static function createFromSql($data) { $menuList = new MenuList(); array_walk($data, function ($value) use($menuList) { $item = new Node\ItemSql($value); if ($item->getParentId()) { $item->setParent($menuList->getNodeByIndex($item->getParentId())); } else { $menuList->addItem($item); } $menuList->addIndex($item); }); return new Menu($menuList); }