Esempio n. 1
0
 public function save($state)
 {
     $content = Prado::serialize($state);
     $saveFile = true;
     if (($cache = $this->getApplication()->getCache()) !== null) {
         if ($cache->get(self::CACHE_NAME) === $content) {
             $saveFile = false;
         } else {
             $cache->set(self::CACHE_NAME, $content);
         }
     }
     if ($saveFile) {
         $fileName = $this->getStateFilePath();
         file_put_contents($fileName, $content, LOCK_EX);
     }
 }
Esempio n. 2
0
 /**
  * @param TPage
  * @param mixed state data
  * @return string serialized data
  */
 public static function serialize($page, $data)
 {
     $sm = $page->getApplication()->getSecurityManager();
     if ($page->getEnableStateValidation()) {
         $str = $sm->hashData(Prado::serialize($data));
     } else {
         $str = Prado::serialize($data);
     }
     if ($page->getEnableStateCompression() && extension_loaded('zlib')) {
         $str = gzcompress($str);
     }
     if ($page->getEnableStateEncryption()) {
         $str = $sm->encrypt($str);
     }
     return base64_encode($str);
 }
 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);
 }
Esempio n. 4
0
 /**
  * Stores a value identified by a key into cache if the cache does not contain this key.
  * This is the implementation of the method declared in the parent class.
  *
  * @param string the key identifying the value to be cached
  * @param string the value to be cached
  * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
  * @return boolean true if the value is successfully stored into cache, false otherwise
  */
 protected function addValue($key, $value, $expire)
 {
     $expire = $expire <= 0 ? 0 : time() + $expire;
     $sql = 'INSERT INTO ' . self::CACHE_TABLE . ' VALUES(\'' . $key . '\',\'' . sqlite_escape_string(Prado::serialize($value)) . '\',' . $expire . ')';
     return @$this->_db->query($sql) !== false;
 }
Esempio n. 5
0
 /**
  * Stores a value identified by a key into cache if the cache does not contain this key.
  * This is the implementation of the method declared in the parent class.
  *
  * @param string the key identifying the value to be cached
  * @param string the value to be cached
  * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
  * @return boolean true if the value is successfully stored into cache, false otherwise
  */
 protected function addValue($key, $value, $expire)
 {
     if (!$this->_cacheInitialized) {
         $this->initializeCache();
     }
     $expire = $expire <= 0 ? 0 : time() + $expire;
     $sql = "INSERT INTO {$this->_cacheTable} (itemkey,value,expire) VALUES(:key,:value,{$expire})";
     try {
         $command = $this->getDbConnection()->createCommand($sql);
         $command->bindValue(':key', $key, PDO::PARAM_STR);
         $command->bindValue(':value', Prado::serialize($value), PDO::PARAM_LOB);
         $command->execute();
         return true;
     } catch (Exception $e) {
         try {
             $this->initializeCache(true);
             $command->execute();
             return true;
         } catch (Exception $e) {
             return false;
         }
     }
 }