예제 #1
0
 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (!empty($this->cache)) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }
예제 #2
0
 public function beforeAction($action)
 {
     if (!$this->enabled) {
         return true;
     }
     $this->cache = Instance::ensure($this->cache, Cache::className());
     $this->cache->cachePath = Yii::getAlias($this->cachePath) . '/' . $action->getUniqueId();
     if (is_array($this->dependency)) {
         $this->dependency = Yii::createObject($this->dependency);
     }
     $properties = [];
     foreach (['cache', 'duration', 'dependency', 'variations'] as $name) {
         $properties[$name] = $this->{$name};
     }
     $id = $this->varyByRoute ? $action->getUniqueId() : __CLASS__;
     $response = Yii::$app->getResponse();
     ob_start();
     ob_implicit_flush(false);
     if ($this->view->beginCache($id, $properties)) {
         $response->on(Response::EVENT_AFTER_SEND, [$this, 'cacheResponse']);
         return true;
     } else {
         $data = $this->cache->get($this->calculateCacheKey());
         if (is_array($data)) {
             $this->restoreResponse($response, $data);
         }
         $response->content = ob_get_clean();
         return false;
     }
 }
예제 #3
0
 public function init()
 {
     if (null !== $this->cache) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
     parent::init();
 }
예제 #4
0
 /**
  * Initialize the component
  */
 public function init()
 {
     parent::init();
     if ($this->cache !== null) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
     $this->model = new $this->modelClass();
 }
예제 #5
0
 /**
  * Singleton construct.
  */
 protected function __construct()
 {
     try {
         $this->cache = Instance::ensure($this->cache, DefaultCache::className());
     } catch (Exception $e) {
         $this->cache = new DummyCache();
     }
 }
 public function actionFlushCache($component = 'cache')
 {
     /** @var Cache $cache */
     $cache = Instance::ensure($component, Cache::className());
     $cache->flush();
     Yii::$app->session->setFlash(Alert::TYPE_SUCCESS, Yii::t('gromver.platform', 'Cache flushed.'));
     return $this->redirect(['index']);
 }
예제 #7
0
 /**
  * Initializes the DbMessageSource component.
  * This method will initialize the [[db]] property to make sure it refers to a valid DB connection.
  * Configured [[cache]] component would also be initialized.
  * @throws InvalidConfigException if [[db]] is invalid or [[cache]] is invalid.
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     if ($this->enableCaching) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }
 /**
  * 初始化组件
  */
 public function init()
 {
     parent::init();
     if ($this->cache !== null) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     } else {
         throw new InvalidConfigException("Cache must be turned on");
     }
     self::$wechat = $this;
 }
 /**
  * 初始化组件,检查参数
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if ($this->cache !== null) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
     if ($this->cache !== null && !$this->cache instanceof Cache) {
         throw new InvalidConfigException("cache must be extends \\yii\\caching\\Cache");
     }
 }
예제 #10
0
 /**
  * Initializes the FragmentCache object.
  */
 public function init()
 {
     parent::init();
     $this->cache = $this->enabled ? Instance::ensure($this->cache, Cache::className()) : null;
     if ($this->getCachedContent() === false) {
         $this->getView()->cacheStack[] = $this;
         ob_start();
         ob_implicit_flush(false);
     }
 }
예제 #11
0
 /**
  * Initialization of cache component.
  * @throws InvalidConfigException if cacheComponent is incorrect.
  */
 protected function initCacheComponent()
 {
     if ($this->cacheComponent === null || is_array($this->cacheComponent)) {
         $this->cacheComponent = Yii::createObject(array_merge(['class' => FileCache::className(), 'cachePath' => rtrim($this->compiledPath, '\\/') . '/cache', 'fileMode' => $this->fileMode, 'dirMode' => $this->mkDirMode], $this->cacheComponent ?: []));
     } elseif (is_string($this->cacheComponent)) {
         $this->cacheComponent = Yii::$app->get($this->cacheComponent);
     }
     if ($this->cacheComponent !== false && !$this->cacheComponent instanceof Cache) {
         throw new InvalidConfigException('Incorrect value of ' . __CLASS__ . '::$cacheComponent param. Calculated value of this param must be an instance of ' . Cache::className() . '.');
     }
 }
예제 #12
0
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     if (empty($this->db)) {
         throw new InvalidConfigException('UserConfig::db must be set.');
     }
     $this->db = Instance::ensure($this->db, Connection::className());
     if ($this->cache !== null) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }
예제 #13
0
 /**
  * Initialize
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->db = Instance::ensure($this->db, Connection::className());
     $this->authManager = Instance::ensure($this->authManager, BaseManager::className());
     $this->user = Instance::ensure($this->user, User::className());
     if (empty($this->cache)) {
         $this->cache = $this->createCacheComponent();
     } else {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
 }
예제 #14
0
 /**
  * Initializes the application component.
  */
 public function init()
 {
     parent::init();
     $this->cache = Instance::ensure($this->cache, Cache::className());
     if ($this->clientId === null) {
         throw new InvalidConfigException('RestfulClient::clientId must be set.');
     }
     if ($this->clientSecret === null) {
         throw new InvalidConfigException('RestfulClient::clientSecret must be set.');
     }
     if ($this->baseUrl === null) {
         throw new InvalidConfigException('RestfulClient::baseUrl must be set.');
     }
 }
예제 #15
0
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     if ($this->cache) {
         /** @var Cache $cache */
         $this->cache = Instance::ensure($this->cache, Cache::className());
         $cacheKey = __CLASS__;
         if (($this->_paramsInfo = $this->cache->get($cacheKey)) === false) {
             $this->_paramsInfo = $this->fetchParamsInfo();
             $this->cache->set($cacheKey, $this->_paramsInfo, $this->cacheDuration, $this->cacheDependency);
         }
     } else {
         $this->_paramsInfo = $this->fetchParamsInfo();
     }
 }
예제 #16
0
 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');
     }
 }
예제 #17
0
파일: Menu.php 프로젝트: oakcms/oakcms
 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
 }
예제 #18
0
 public function init()
 {
     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]);
         } else {
             $this->_createUrlRules = $createUrlRules;
             $this->_parseUrlRules = $parseUrlRules;
         }
     } else {
         $this->buildRules();
     }
 }
예제 #19
0
 public function init()
 {
     if ($this->cache) {
         /** @var Cache $cache */
         $this->cache = Instance::ensure($this->cache, Cache::className());
         $cacheKey = __CLASS__;
         if ((list($paths, $routes, $links) = $this->cache->get($cacheKey)) === false) {
             $this->createMap();
             $this->cache->set($cacheKey, [$this->_paths, $this->_routes, $this->_links], $this->cacheDuration, $this->cacheDependency);
         } else {
             $this->_paths = $paths;
             $this->_routes = $routes;
             $this->_links = $links;
         }
     } else {
         $this->createMap();
     }
 }
예제 #20
0
 public function init()
 {
     if (!$this->language) {
         throw new InvalidConfigException(get_called_class() . '::language must be set.');
     }
     if ($this->cache) {
         /** @var Cache $cache */
         $this->cache = Instance::ensure($this->cache, Cache::className());
         $cacheKey = [__CLASS__, $this->language];
         if ((list($paths, $routes, $links) = $this->cache->get($cacheKey)) === false) {
             $this->createMap();
             $this->cache->set($cacheKey, [$this->_paths, $this->_routes, $this->_links], $this->cacheDuration, $this->cacheDependency);
         } else {
             $this->_paths = $paths;
             $this->_routes = $routes;
             $this->_links = $links;
         }
     } else {
         $this->createMap();
     }
 }
예제 #21
0
 /**
  * Renders the menu.
  */
 public function run()
 {
     if ($this->route === null && Yii::$app->controller !== null) {
         $this->route = Yii::$app->controller->getRoute();
     }
     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 DesktopEvent(['items' => $this->items]), 'items');
             $this->cache->set($cacheKey, $this->items, $this->cacheDuration, $this->cacheDependency);
         }
     } else {
         $this->items = ModuleEvent::trigger(self::EVENT_FETCH_ITEMS, new DesktopEvent(['items' => $this->items]), 'items');
     }
     $this->normalizeItems();
     $options = $this->options;
     $tag = ArrayHelper::remove($options, 'tag', 'div');
     echo Html::tag($tag, $this->renderItems($this->columns), $options);
 }
예제 #22
0
 /**
  * Checks if given class is a Cache class.
  * @param string $className class name.
  * @return boolean
  */
 private function isCacheClass($className)
 {
     return is_subclass_of($className, Cache::className());
 }
예제 #23
0
 /**
  * Base initiation of queue service
  */
 public function init()
 {
     $this->cache = Instance::ensure($this->cache, Cache::className());
 }
예제 #24
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $components = ['cache' => ['value' => $this->cache, 'type' => Cache::className()], 'configManager' => ['value' => $this->configManager, 'type' => ConfigManager::className()]];
     foreach ($components as $key => $val) {
         if (is_string($this->{$key})) {
             $this->{$key} = Instance::ensure($this->{$key}, $val['type']);
         } elseif (is_array($this->{$key})) {
             $this->{$key} = Yii::createObject($this->{$key});
         }
         if (!$this->{$key} instanceof $val['type']) {
             throw new InvalidConfigException("Property `{${$key}}` must be specified.");
         }
     }
     if (empty($this->messageCategory)) {
         throw new InvalidConfigException('Property `$messageCategory` must be specified.');
     }
     $this->registerTranslations();
 }
예제 #25
0
 /**
  * Init component
  * @throws InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->_db = Instance::ensure($this->_dbCacheDependency = $this->_db, Connection::className());
     $this->_cache = Instance::ensure($this->_cache, Cache::className());
 }
예제 #26
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->provider === null) {
         throw new InvalidConfigException('The "provider" property must be set.');
     }
     if ($this->serviceUrl === null) {
         throw new InvalidConfigException('The "serviceUrl" property must be set.');
     }
     if ($this->wsdlUrl === null) {
         throw new InvalidConfigException('The "wsdlUrl" property must be set.');
     }
     if ($this->enableCaching) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
     }
     if (YII_DEBUG) {
         ini_set('soap.wsdl_cache_enabled', 0);
     }
 }
예제 #27
0
 /**
  * Initialises component.
  * If cache is not set in configuration [[DummyCache]] is used instead.
  */
 public function init()
 {
     try {
         $this->cache = Instance::ensure($this->cache, DefaultCache::className());
     } catch (Exception $e) {
         $this->cache = new DummyCache();
     }
 }
 /**
  * @return null|Cache
  * @throws \yii\base\InvalidConfigException
  */
 protected function ensureCache()
 {
     return $this->cache ? Instance::ensure($this->cache, Cache::className()) : null;
 }
예제 #29
0
파일: PageCache.php 프로젝트: kilyanov/yii2
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * You may override this method to do last-minute preparation for the action.
  * @param Action $action the action to be executed.
  * @return bool whether the action should continue to be executed.
  */
 public function beforeAction($action)
 {
     if (!$this->enabled) {
         return true;
     }
     $this->cache = Instance::ensure($this->cache, Cache::className());
     if (is_array($this->dependency)) {
         $this->dependency = Yii::createObject($this->dependency);
     }
     $response = Yii::$app->getResponse();
     $data = $this->cache->get($this->calculateCacheKey());
     if (!is_array($data) || !isset($data['cacheVersion']) || $data['cacheVersion'] !== 1) {
         $this->view->cacheStack[] = $this;
         ob_start();
         ob_implicit_flush(false);
         $response->on(Response::EVENT_AFTER_SEND, [$this, 'cacheResponse']);
         Yii::trace('Valid page content is not found in the cache.', __METHOD__);
         return true;
     } else {
         $this->restoreResponse($response, $data);
         Yii::trace('Valid page content is found in the cache.', __METHOD__);
         return false;
     }
 }
예제 #30
-1
파일: I18N.php 프로젝트: athl64/yii2-i18n
 /**
  * @throws InvalidConfigException
  */
 public function init()
 {
     if (!$this->languages) {
         throw new InvalidConfigException('You should configure i18n component [language]');
     }
     if ($this->languages instanceof \Closure) {
         $this->languages = $this->languages->__invoke();
     }
     $cacheConfig = [];
     if ($this->enableCaching) {
         $this->cache = Instance::ensure($this->cache, Cache::className());
         $cacheConfig = ['cache' => $this->cache, 'cachingDuration' => $this->cachingDuration, 'enableCaching' => true];
     }
     $translationConfig = ['class' => DbMessageSource::className(), 'db' => $this->db, 'sourceMessageTable' => $this->sourceMessageTable, 'messageTable' => $this->messageTable, 'on missingTranslation' => $this->missingTranslationHandler];
     $translationConfig = ArrayHelper::merge($translationConfig, $cacheConfig);
     if (!isset($this->translations['*'])) {
         $this->translations['*'] = $translationConfig;
     }
     if (!isset($this->translations['app']) && !isset($this->translations['app*'])) {
         $this->translations['app'] = $translationConfig;
     }
     parent::init();
 }