/**
  * @inheritdoc
  */
 public function init()
 {
     Instance::ensure($this->menuManager, MenuManager::className());
     if ($this->cache) {
         /** @var Cache $cache */
         $this->cache = Instance::ensure($this->cache, Cache::className());
         $cacheKey = __CLASS__;
         if ((list($createUrlRules, $parseUrlRules) = $this->cache->get($cacheKey)) === false) {
             $this->buildRules();
             $this->cache->set($cacheKey, [$this->_createUrlRules, $this->_parseUrlRules], $this->cacheDuration, $this->cacheDependency);
         } else {
             $this->_createUrlRules = $createUrlRules;
             $this->_parseUrlRules = $parseUrlRules;
         }
     } else {
         $this->buildRules();
     }
 }
Example #2
0
 /**
  * @inheritdoc
  */
 public function bootstrap($app)
 {
     $app->set($this->id, $this);
     $this->_moduleConfigDependency = new ExpressionDependency(['expression' => '\\Yii::$app->getModulesHash()']);
     DbState::bootstrap();
     Yii::$container->set('gromver\\models\\fields\\EditorField', ['controller' => 'grom/media/manager', 'editorOptions' => ['filebrowserBrowseUrl' => ['/grom/menu/backend/item/ckeditor-select'], 'extraPlugins' => 'codesnippet']]);
     Yii::$container->set('gromver\\models\\fields\\MediaField', ['controller' => 'grom/media/manager']);
     Yii::$container->set('gromver\\modulequery\\ModuleQuery', ['cache' => $app->cache, 'cacheDependency' => $this->_moduleConfigDependency]);
     Yii::$container->set('gromver\\platform\\basic\\components\\MenuMap', ['cache' => $app->cache, 'cacheDependency' => DbState::dependency(MenuItem::tableName())]);
     Yii::$container->set('gromver\\platform\\basic\\components\\MenuUrlRule', ['cache' => $app->cache, 'cacheDependency' => $this->_moduleConfigDependency]);
     Yii::$container->set('gromver\\platform\\basic\\modules\\main\\widgets\\Desktop', ['cache' => $app->cache, 'cacheDependency' => $this->_moduleConfigDependency]);
     /** @var MenuManager $manager */
     $rules['auth'] = 'grom/auth/default/login';
     $rules['admin'] = 'grom/backend/default/index';
     if (is_array($this->blockedUrlRules) && count($this->blockedUrlRules)) {
         foreach ($this->blockedUrlRules as $rule) {
             $rules[$rule] = 'grom/default/page-not-found';
             //блокируем доступ напрямую
         }
     }
     $app->urlManager->addRules($rules, false);
     //вставляем в начало списка
     $app->set('menuManager', \Yii::createObject(MenuManager::className()));
     // пропускаем \gromver\models\fields\events\ListItemsEvent событие, через ModuleEvent - не факт, что нужно, но почему бы и нет
     Event::on('\\gromver\\models\\fields\\ListField', 'fetchItems', function ($event) {
         /** @var $event \gromver\models\fields\events\ListItemsEvent */
         ModuleEvent::trigger(self::EVENT_FETCH_LIST_ITEMS, new ListItemsModuleEvent(['sender' => $event]));
     });
     ModuleQuery::instance()->implement('\\gromver\\platform\\common\\interfaces\\BootstrapInterface')->invoke('bootstrap', [$app]);
 }