mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-06-29 14:24:17 +02:00
[core] Apply common indentation
All files are now using tabs for indentation
This commit is contained in:
@ -2,93 +2,88 @@
|
||||
/**
|
||||
* Cache with file system
|
||||
*/
|
||||
class FileCache extends CacheAbstract{
|
||||
protected $cacheDirCreated; // boolean to avoid always chck dir cache existance
|
||||
class FileCache extends CacheAbstract {
|
||||
protected $cacheDirCreated; // boolean to avoid always chck dir cache existance
|
||||
|
||||
public function loadData(){
|
||||
$this->isPrepareCache();
|
||||
public function loadData(){
|
||||
$this->isPrepareCache();
|
||||
$datas = unserialize(file_get_contents($this->getCacheFile()));
|
||||
return $datas;
|
||||
}
|
||||
|
||||
$datas = unserialize(file_get_contents($this->getCacheFile()));
|
||||
public function saveData($datas){
|
||||
$this->isPrepareCache();
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
||||
public function saveData($datas){
|
||||
$this->isPrepareCache();
|
||||
|
||||
//Re-encode datas to UTF-8
|
||||
//$datas = Cache::utf8_encode_deep($datas);
|
||||
|
||||
$writeStream = file_put_contents($this->getCacheFile(), serialize($datas));
|
||||
//Re-encode datas to UTF-8
|
||||
//$datas = Cache::utf8_encode_deep($datas);
|
||||
$writeStream = file_put_contents($this->getCacheFile(), serialize($datas));
|
||||
|
||||
if(!$writeStream) {
|
||||
|
||||
throw new \Exception("Cannot write the cache... Do you have the right permissions ?");
|
||||
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTime(){
|
||||
$this->isPrepareCache();
|
||||
public function getTime(){
|
||||
$this->isPrepareCache();
|
||||
|
||||
$cacheFile = $this->getCacheFile();
|
||||
if( file_exists($cacheFile) ){
|
||||
return filemtime($cacheFile);
|
||||
}
|
||||
$cacheFile = $this->getCacheFile();
|
||||
if(file_exists($cacheFile)){
|
||||
return filemtime($cacheFile);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache is prepared ?
|
||||
* Note : Cache name is based on request information, then cache must be prepare before use
|
||||
* @return \Exception|true
|
||||
*/
|
||||
protected function isPrepareCache(){
|
||||
if( is_null($this->param) ){
|
||||
throw new \Exception('Please feed "prepare" method before try to load');
|
||||
}
|
||||
/**
|
||||
* Cache is prepared ?
|
||||
* Note : Cache name is based on request information, then cache must be prepare before use
|
||||
* @return \Exception|true
|
||||
*/
|
||||
protected function isPrepareCache(){
|
||||
if(is_null($this->param)){
|
||||
throw new \Exception('Please feed "prepare" method before try to load');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return cache path (and create if not exist)
|
||||
* @return string Cache path
|
||||
*/
|
||||
protected function getCachePath(){
|
||||
$cacheDir = __DIR__ . '/../cache/'; // FIXME : configuration ?
|
||||
/**
|
||||
* Return cache path (and create if not exist)
|
||||
* @return string Cache path
|
||||
*/
|
||||
protected function getCachePath(){
|
||||
$cacheDir = __DIR__ . '/../cache/'; // FIXME : configuration ?
|
||||
|
||||
// FIXME : implement recursive dir creation
|
||||
if( is_null($this->cacheDirCreated) && !is_dir($cacheDir) ){
|
||||
$this->cacheDirCreated = true;
|
||||
// FIXME : implement recursive dir creation
|
||||
if(is_null($this->cacheDirCreated) && !is_dir($cacheDir)){
|
||||
$this->cacheDirCreated = true;
|
||||
|
||||
mkdir($cacheDir,0705);
|
||||
chmod($cacheDir,0705);
|
||||
}
|
||||
mkdir($cacheDir,0705);
|
||||
chmod($cacheDir,0705);
|
||||
}
|
||||
|
||||
return $cacheDir;
|
||||
}
|
||||
return $cacheDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file name use for cache store
|
||||
* @return string Path to the file cache
|
||||
*/
|
||||
protected function getCacheFile(){
|
||||
return $this->getCachePath() . $this->getCacheName();
|
||||
}
|
||||
/**
|
||||
* Get the file name use for cache store
|
||||
* @return string Path to the file cache
|
||||
*/
|
||||
protected function getCacheFile(){
|
||||
return $this->getCachePath() . $this->getCacheName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines file name for store the cache
|
||||
* return string
|
||||
*/
|
||||
protected function getCacheName(){
|
||||
$this->isPrepareCache();
|
||||
/**
|
||||
* Determines file name for store the cache
|
||||
* return string
|
||||
*/
|
||||
protected function getCacheName(){
|
||||
$this->isPrepareCache();
|
||||
|
||||
$stringToEncode = $_SERVER['REQUEST_URI'] . http_build_query($this->param);
|
||||
$stringToEncode = preg_replace('/(\?|&)format=[^&]*/i', '$1', $stringToEncode);
|
||||
return hash('sha1', $stringToEncode) . '.cache';
|
||||
}
|
||||
$stringToEncode = $_SERVER['REQUEST_URI'] . http_build_query($this->param);
|
||||
$stringToEncode = preg_replace('/(\?|&)format=[^&]*/i', '$1', $stringToEncode);
|
||||
return hash('sha1', $stringToEncode) . '.cache';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user