1
0
Fork 0

Add debug output to cache class

pull/1922/head
Jordi Boggiano 2013-05-17 10:22:47 +02:00
parent 978ba292a6
commit 950fc7e66e
1 changed files with 18 additions and 0 deletions

View File

@ -63,6 +63,9 @@ 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)) {
if ($this->io->isDebug()) {
$this->io->write('Reading '.$this->root . $file.' from cache');
}
return file_get_contents($this->root . $file); return file_get_contents($this->root . $file);
} }
@ -74,30 +77,45 @@ class Cache
if ($this->enabled) { if ($this->enabled) {
$file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file); $file = preg_replace('{[^'.$this->whitelist.']}i', '-', $file);
if ($this->io->isDebug()) {
$this->io->write('Writing '.$this->root . $file.' into cache');
}
return file_put_contents($this->root . $file, $contents); return file_put_contents($this->root . $file, $contents);
} }
return false; return false;
} }
/**
* Copy a file into the cache
*/
public function copyFrom($file, $source) public function copyFrom($file, $source)
{ {
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));
if ($this->io->isDebug()) {
$this->io->write('Writing '.$this->root . $file.' into cache');
}
return copy($source, $this->root . $file); return copy($source, $this->root . $file);
} }
return false; return false;
} }
/**
* Copy a file out of the cache
*/
public function copyTo($file, $target) public function copyTo($file, $target)
{ {
$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);
if ($this->io->isDebug()) {
$this->io->write('Reading '.$this->root . $file.' from cache');
}
return copy($this->root . $file, $target); return copy($this->root . $file, $target);
} }