コード例 #1
0
ファイル: MenuManager.php プロジェクト: hd-deman/elcodi
 /**
  * Load menu hidration given the code.
  *
  * If the menu is already loaded in local variable, return it.
  * Otherwise, if is saved into cache, load it and save it locally
  * Otherwise, generate the data, save it into cache and save it locally
  *
  * @param string $menuCode Menu code
  *
  * @return array|null Result
  */
 public function loadMenuByCode($menuCode)
 {
     $key = $this->buildKey($this->key, $menuCode);
     if (isset($this->menus[$key])) {
         return $this->menus[$key];
     }
     $menuHidrated = $this->encoder->decode($this->cache->fetch($key));
     if (empty($menuHidrated)) {
         $menu = $this->menuRepository->findOneBy(['code' => $menuCode, 'enabled' => true]);
         if (!$menu instanceof MenuInterface) {
             return null;
         }
         $menuHidrated = $this->loadSubnodes($menu);
         $this->cache->save($key, $this->encoder->encode($menuHidrated));
     }
     $this->menus[$key] = $menuHidrated;
     return $menuHidrated;
 }
コード例 #2
0
ファイル: MenuManager.php プロジェクト: VictorMateo/elcodi
 /**
  * Build menu.
  *
  * @param string $menuCode Menu code
  *
  * @return MenuInterface Menu
  *
  * @throws Exception
  */
 private function buildMenuFromRepository($menuCode)
 {
     $menu = $this->menuRepository->findOneBy(['code' => $menuCode, 'enabled' => true]);
     if (!$menu instanceof MenuInterface) {
         throw new Exception(sprintf('Menu "%s" not found', $menuCode));
     }
     $this->menuObjectManager->detach($menu);
     return $menu;
 }