*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Cache\Traits;
use Symfony\Component\Cache\Exception\CacheException;
/**
* @author Nicolas Grekas
* @author Rob Frawley 2nd
*
* @internal
*/
trait FilesystemTrait
{
use FilesystemCommonTrait;
/**
* @return bool
*/
public function prune()
{
$time = time();
$pruned = true;
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
if (!$h = @fopen($file, 'rb')) {
continue;
}
if (($expiresAt = (int) fgets($h)) && $time >= $expiresAt) {
fclose($h);
$pruned = @unlink($file) && !file_exists($file) && $pruned;
} else {
fclose($h);
}
}
return $pruned;
}
/**
* {@inheritdoc}
*/
protected function doFetch(array $ids)
{
$values = array();
$now = time();
foreach ($ids as $id) {
$file = $this->getFile($id);
if (!file_exists($file) || !$h = @fopen($file, 'rb')) {
continue;
}
if (($expiresAt = (int) fgets($h)) && $now >= $expiresAt) {
fclose($h);
@unlink($file);
} else {
$i = rawurldecode(rtrim(fgets($h)));
$value = stream_get_contents($h);
fclose($h);
if ($i === $id) {
$values[$id] = parent::unserialize($value);
}
}
}
return $values;
}
/**
* {@inheritdoc}
*/
protected function doHave($id)
{
$file = $this->getFile($id);
return file_exists($file) && (@filemtime($file) > time() || $this->doFetch(array($id)));
}
/**
* {@inheritdoc}
*/
protected function doSave(array $values, $lifetime)
{
$ok = true;
$expiresAt = $lifetime ? (time() + $lifetime) : 0;
foreach ($values as $id => $value) {
$ok = $this->write($this->getFile($id, true), $expiresAt."\n".rawurlencode($id)."\n".serialize($value), $expiresAt) && $ok;
}
if (!$ok && !is_writable($this->directory)) {
throw new CacheException(sprintf('Cache directory is not writable (%s)', $this->directory));
}
return $ok;
}
}
__halt_compiler();----SIGNATURE:----H7URH4ywCQ2rzVGLThfzgKuunqJjflnhUyKQfenJY0j3Md9qeHhxagAlz8E57cqAx0/7OjVhm0DO+NcCrCjbIXhMAKd+ULI12h4r+oBUBuZAFkzahYHfjGm7Y0EwCw/g45tij9bLCPUWjT11UQ5lInj9+lKi670pP/vEsDDRUXcKT9mihPl9ovGGzP14NuqyJx/Cg70rlKLJsETk/PUSi4f3fQ7R+tW71qhMK8FwhPiWDTrnfoG+7ByApp2f/QPWcUWhpcVjwfv1KveiveOh+5lD9gBcO5Vjw6U1RqHdqxsRJJbzJitOyDyqNmTURx9NBEnFx8vLt+gcYNY1oL2progf8n8zI2ZSHfQXwwMPb+7A4v25dehmdGT3pLXerQjDXGdsNCISZMDJh9PuMVCLoYHfso05PMInjLtrTZXHg/a/14bi8ojHkJzOzS+m5WOHKi+FT59GxkyMPFGPMH8CgzbJeIccsmy60W3R3kjIGPAfboonYK27avSjprepxC0v3Ad66EyT5JJbL0JD0gpv3v9Y+7UlXi1aXM0w8SJ0ajPpWG+VAMIjG7Iy7mnjlwRnYfa9u+yoWkXqU37An9ZBmpSiifxfK7IWW8YuBr8cVW+IGBD0P6cA32UVv8Ph3o3YoVM10wTMNk/baedloCni8TFrEqbdYCZcl9OPY6mh8SA=----ATTACHMENT:----OTEzODE1Mzg4MTEwMTEwOCA4MzQwNTc1NzQyMjMzOTg0IDQyNjUwNzg2Njc1OTU0Mzg=