_menuBuilder = $menuBuilder; $this->_director = $menuDirector; $this->_configCacheType = $configCacheType; $this->_eventManager = $eventManager; $this->_logger = $logger; $this->_menuFactory = $menuFactory; $this->_configReader = $configReader; $this->_scopeConfig = $scopeConfig; $this->_appState = $appState; } /** * Build menu model from config * * @return \Magento\Backend\Model\Menu * @throws \Exception|\InvalidArgumentException * @throws \Exception * @throws \BadMethodCallException|\Exception * @throws \Exception|\OutOfRangeException */ public function getMenu() { try { $this->_initMenu(); return $this->_menu; } catch (\InvalidArgumentException $e) { $this->_logger->critical($e); throw $e; } catch (\BadMethodCallException $e) { $this->_logger->critical($e); throw $e; } catch (\OutOfRangeException $e) { $this->_logger->critical($e); throw $e; } catch (\Exception $e) { throw $e; } } /** * Initialize menu object * * @return void */ protected function _initMenu() { if (!$this->_menu) { $this->_menu = $this->_menuFactory->create(); $cache = $this->_configCacheType->load(self::CACHE_MENU_OBJECT); if ($cache) { $this->_menu->unserialize($cache); return; } $this->_director->direct( $this->_configReader->read($this->_appState->getAreaCode()), $this->_menuBuilder, $this->_logger ); $this->_menu = $this->_menuBuilder->getResult($this->_menu); $this->_configCacheType->save($this->_menu->serialize(), self::CACHE_MENU_OBJECT); } } }