public function init() { parent::init(); $this->_initOptions(); if ($this->cache) { /** @var Cache $cache */ $this->cache = Instance::ensure($this->cache, Cache::className()); $cacheKey = [__CLASS__, $this->items]; if (($this->items = $this->cache->get($cacheKey)) === false) { $this->items = ModuleEvent::trigger(self::EVENT_FETCH_ITEMS, new MenuItemsEvent(['items' => $this->items]), 'items'); $this->cache->set($cacheKey, $this->items, $this->cacheDuration, $this->cacheDependency); } } else { $this->items = ModuleEvent::trigger(self::EVENT_FETCH_ITEMS, new MenuItemsEvent(['items' => $this->items]), 'items'); } }
public function run() { if ($this->cache) { /** @var Cache $cache */ $this->cache = Instance::ensure($this->cache, Cache::className()); $cacheKey = [__CLASS__, $this->items]; if (($this->items = $this->cache->get($cacheKey)) === false) { $this->items = ModuleEvent::trigger(self::EVENT_FETCH_ITEMS, new MenuItemsEvent(['items' => $this->items]), 'items'); $this->cache->set($cacheKey, $this->items, $this->cacheDuration, $this->cacheDependency); } } else { $this->items = ModuleEvent::trigger(self::EVENT_FETCH_ITEMS, new MenuItemsEvent(['items' => $this->items]), 'items'); } $this->items += $this->customItems; parent::run(); // TODO: Change the autogenerated stub }
/** * Собирает правила маршрутизации со всех маршрутизаторов модулей * @throws InvalidConfigException */ protected function buildRules() { //нам нужно собрать все роутеры от модулей и вытащить из них инструкции по маршрутизации $routers = ModuleEvent::trigger(self::EVENT_FETCH_MODULE_ROUTERS, new \app\components\events\FetchRoutersEvent(['routers' => [], 'sender' => $this]), 'routers'); // вытаскиваем инструкции из всех роутеров foreach ($routers as $routerClass) { $router = $this->getRouter($routerClass); foreach ($router->createUrlRules() as $rule) { @$rule['class'] or $rule['class'] = MenuRouterUrlRuleCreate::className(); $rule['router'] = $router->className(); $this->_createUrlRules[] = Yii::createObject($rule); } foreach ($router->parseUrlRules() as $rule) { @$rule['class'] or $rule['class'] = MenuRouterUrlRuleParse::className(); $rule['router'] = $router->className(); $this->_parseUrlRules[] = Yii::createObject($rule); } } }
/** * @return array */ public function getMenuItemLayouts() { return ModuleEvent::trigger(self::EVENT_MENU_ITEM_LAYOUTS, new MenuItemLayoutsModuleEvent(['items' => $this->_menuItemLayouts]), 'items'); }