本文整理汇总了PHP中Prado::serialize方法的典型用法代码示例。如果您正苦于以下问题:PHP Prado::serialize方法的具体用法?PHP Prado::serialize怎么用?PHP Prado::serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Prado
的用法示例。
在下文中一共展示了Prado::serialize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
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);
}
}
示例2: serialize
/**
* @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);
}
示例3: initApplication
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);
}
示例4: addValue
/**
* 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;
}
示例5: addValue
/**
* 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;
}
}
}