예제 #1
0
 public static function assets($collectionName)
 {
     static::$instance or static::$instance = static::$di->getShared('view');
     $view = static::$instance;
     $useCache = $view->config['options']['assets_options']['cache_assets'];
     if (!$view->assets) {
         $view->assets = static::$di->getShared('assets');
         $useCache and static::$cachedAssets = Cache::get('assets');
     }
     $type = substr($collectionName, strrpos($collectionName, '-') + 1);
     $view->isAdmin() and $collectionName = 'admin-' . $collectionName;
     if ($useCache && isset(static::$cachedAssets[$collectionName])) {
         return static::$cachedAssets[$collectionName];
     }
     $view->loadAssets($view->config['assets']);
     $view->loadAssets($view->config['admin']['assets'], true);
     ob_start();
     try {
         switch ($type) {
             case 'js':
                 $view->assets->outputJs($collectionName);
                 break;
             case 'css':
                 $view->assets->outputCss($collectionName);
                 break;
         }
     } catch (Exception $e) {
         Log::exception($e);
     }
     // @codeCoverageIgnoreEnd
     $assets = ob_get_clean();
     static::$cachedAssets[$collectionName] = $assets;
     $useCache and Cache::set('assets', static::$cachedAssets);
     return $assets;
 }
예제 #2
0
 public function testSetAndRemoveCache()
 {
     $cacheKey = 'test.set.cache';
     $value = 'Some stub';
     Cache::set($cacheKey, $value);
     $this->assertEquals($value, Cache::get($cacheKey), 'Unable to set cache');
     Cache::delete($cacheKey);
     $this->assertNull(Cache::get($cacheKey), 'Unable to delete cache');
 }
예제 #3
0
 public function getBrowserCache($pageId = null, $type = null)
 {
     $pageId or $pageId = $this->request->getURI();
     $cacheKey = md5($pageId);
     switch ($type) {
         case static::BROWSER_CACHE_ETAG:
             return Cache::get('fpc-etag-' . $cacheKey);
         case static::BROWSER_CACHE_CONTENT:
             return Cache::get('fpc-content-' . $cacheKey);
     }
     return ['etag' => Cache::get('fpc-etag-' . $cacheKey), 'content' => Cache::get('fpc-content-' . $cacheKey)];
 }
예제 #4
0
 public static function all()
 {
     $environment = PhwoolconConfig::environment();
     if (null === ($config = Cache::get($key = 'db_configs_' . $environment))) {
         $db = Db::connection();
         $db->tableExists('config') or static::createConfigTable();
         $config = [];
         /* @var static $row */
         foreach (static::find() as $row) {
             $value = json_decode($row->getData('value'), true);
             $config[$row->getData('key')] = $value;
         }
         Cache::set($key, $config, Cache::TTL_ONE_MONTH);
     }
     return $config;
 }
예제 #5
0
파일: SsoSite.php 프로젝트: phwoolcon/auth
 public static function getSitesData()
 {
     if (null === static::$_sites && null === (static::$_sites = Cache::get($cacheKey = 'sso.sites'))) {
         /* @var static $site */
         $data = [];
         foreach (static::find() as $site) {
             if (!($url = $site->getData('site_url')) || !($host = parse_url($url, PHP_URL_HOST))) {
                 continue;
             }
             $site->setData('host', $host);
             $data[$host] = $site->getData();
         }
         static::$_sites = $data;
         Cache::set($cacheKey, $data);
     }
     return static::$_sites;
 }
예제 #6
0
 /**
  * Reads meta-data from files
  *
  * @param string $key
  * @return mixed
  */
 public function read($key)
 {
     $this->_cachedData or $this->_cachedData = Cache::get('model-metadata');
     return isset($this->_cachedData[$key]) ? $this->_cachedData[$key] : null;
 }
예제 #7
0
 public function getPendingConfirmationData()
 {
     return ($key = Session::get('pending-confirm')) ? Cache::get('reg-pc-' . $key) : null;
 }
예제 #8
0
 public function loadLocale($locale, $force = false)
 {
     if (isset($this->locale[$locale]) && !$force) {
         return $this;
     }
     $useCache = $this->options['cache_locale'];
     $cacheKey = 'locale.' . $locale;
     if ($useCache && !$force && ($cached = Cache::get($cacheKey))) {
         $this->locale[$locale] = $cached;
         return $this;
     }
     $packages = [];
     $combined = [];
     foreach (glob($this->localePath . '/' . $this->currentLocale . '/*.php') as $file) {
         $package = pathinfo($file, PATHINFO_FILENAME);
         $combined = array_merge($combined, $packages[$package] = (array) (include $file));
     }
     $this->locale[$locale] = compact('combined', 'packages');
     $useCache and Cache::set($cacheKey, $this->locale[$locale]);
     return $this;
 }