1
0
Fork 0

Standardize return valuse of the cache class

pull/1282/head
Jordi Boggiano 2012-11-10 22:17:46 +01:00
parent fb3a43b2f0
commit 79bf55e505
1 changed files with 17 additions and 2 deletions

View File

@ -53,14 +53,19 @@ class Cache
if ($this->enabled && file_exists($this->root . $file)) { if ($this->enabled && file_exists($this->root . $file)) {
return file_get_contents($this->root . $file); return file_get_contents($this->root . $file);
} }
return false;
} }
public function write($file, $contents) public function write($file, $contents)
{ {
if ($this->enabled) { if ($this->enabled) {
$file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file); $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
file_put_contents($this->root . $file, $contents);
return file_put_contents($this->root . $file, $contents);
} }
return false;
} }
public function copyFrom($file, $source) public function copyFrom($file, $source)
@ -68,8 +73,11 @@ class Cache
if ($this->enabled) { if ($this->enabled) {
$file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file); $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
$this->filesystem->ensureDirectoryExists(dirname($this->root . $file)); $this->filesystem->ensureDirectoryExists(dirname($this->root . $file));
copy($source, $this->root . $file);
return copy($source, $this->root . $file);
} }
return false;
} }
public function copyTo($file, $target) public function copyTo($file, $target)
@ -77,8 +85,11 @@ class Cache
$file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file); $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
if ($this->enabled && file_exists($this->root . $file)) { if ($this->enabled && file_exists($this->root . $file)) {
touch($this->root . $file); touch($this->root . $file);
return copy($this->root . $file, $target); return copy($this->root . $file, $target);
} }
return false;
} }
public function gc($expire) public function gc($expire)
@ -92,6 +103,8 @@ class Cache
if ($this->enabled && file_exists($this->root . $file)) { if ($this->enabled && file_exists($this->root . $file)) {
return sha1_file($this->root . $file); return sha1_file($this->root . $file);
} }
return false;
} }
public function sha256($file) public function sha256($file)
@ -100,5 +113,7 @@ class Cache
if ($this->enabled && file_exists($this->root . $file)) { if ($this->enabled && file_exists($this->root . $file)) {
return hash_file('sha256', $this->root . $file); return hash_file('sha256', $this->root . $file);
} }
return false;
} }
} }