Beispiel #1
0
 public function load()
 {
     if (($cache = $this->getApplication()->getCache()) !== null && ($value = $cache->get(self::CACHE_NAME)) !== false) {
         return Prado::unserialize($value);
     } else {
         if (($content = @file_get_contents($this->getStateFilePath())) !== false) {
             return Prado::unserialize($content);
         } else {
             return null;
         }
     }
 }
 /**
  * @param TPage
  * @param string serialized data
  * @return mixed unserialized state data, null if data is corrupted
  */
 public static function unserialize($page, $data)
 {
     $str = base64_decode($data);
     if ($str === '') {
         return null;
     }
     if ($str !== false) {
         $sm = $page->getApplication()->getSecurityManager();
         if ($page->getEnableStateEncryption()) {
             $str = $sm->decrypt($str);
         }
         if ($page->getEnableStateCompression() && extension_loaded('zlib')) {
             $str = @gzuncompress($str);
         }
         if ($page->getEnableStateValidation()) {
             if (($str = $sm->validateData($str)) !== false) {
                 return Prado::unserialize($str);
             }
         } else {
             return Prado::unserialize($str);
         }
     }
     return null;
 }
 protected function initApplication()
 {
     if ($this->_configFile !== null) {
         if ($this->_cacheFile === null || @filemtime($this->_cacheFile) < filemtime($this->_configFile)) {
             $config = new TApplicationConfiguration();
             $config->loadFromFile($this->_configFile);
             if ($this->_cacheFile !== null) {
                 file_put_contents($this->_cacheFile, Prado::serialize($config), LOCK_EX);
             }
         } else {
             $config = Prado::unserialize(file_get_contents($this->_cacheFile));
         }
         $this->applyConfiguration($config, false);
     }
     if (($serviceID = $this->getRequest()->resolveRequest(array_keys($this->_services))) === null) {
         $serviceID = $this->getPageServiceID();
     }
     $this->startService($serviceID);
 }
 /**
  * Retrieves a value from cache with a specified key.
  * This is the implementation of the method declared in the parent class.
  * @param string a unique key identifying the cached value
  * @return string the value stored in cache, false if the value is not in the cache or expired.
  */
 protected function getValue($key)
 {
     $sql = 'SELECT value FROM ' . self::CACHE_TABLE . ' WHERE key=\'' . $key . '\' AND (expire=0 OR expire>' . time() . ') LIMIT 1';
     if (($ret = $this->_db->query($sql)) != false && ($row = $ret->fetch(SQLITE_ASSOC)) !== false) {
         return Prado::unserialize($row['value']);
     } else {
         return false;
     }
 }
Beispiel #5
0
 /**
  * Retrieves a value from cache with a specified key.
  * This is the implementation of the method declared in the parent class.
  * @param string a unique key identifying the cached value
  * @return string the value stored in cache, false if the value is not in the cache or expired.
  */
 protected function getValue($key)
 {
     if (!$this->_cacheInitialized) {
         $this->initializeCache();
     }
     try {
         $sql = 'SELECT value FROM ' . $this->_cacheTable . ' WHERE itemkey=\'' . $key . '\' AND (expire=0 OR expire>' . time() . ') ORDER BY expire DESC';
         $command = $this->getDbConnection()->createCommand($sql);
         return Prado::unserialize($command->queryScalar());
     } catch (Exception $e) {
         $this->initializeCache(true);
         return Prado::unserialize($command->queryScalar());
     }
 }