Example #1
0
File: Menu.php Project: h4kuna/menu
 /**
  * 
  * @param string $index
  * @return array
  */
 public function findByIndex($index)
 {
     try {
         return $this->menuList->getNodeByIndex($index);
     } catch (MenuException $e) {
         return NULL;
     }
 }
Example #2
0
 /**
  * 
  * @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);
 }