Use 0 for unlimited expiry

This commit is contained in:
Lars Strojny 2018-02-10 12:14:07 +01:00
parent 05a045268f
commit b4259a6bf3
1 changed files with 5 additions and 7 deletions

View File

@ -36,9 +36,9 @@ trait FilesystemTrait
continue;
}
if ($time >= (int) $expiresAt = fgets($h)) {
if (($expiresAt = (int) fgets($h)) && $time >= $expiresAt) {
fclose($h);
$pruned = isset($expiresAt[0]) && @unlink($file) && !file_exists($file) && $pruned;
$pruned = @unlink($file) && !file_exists($file) && $pruned;
} else {
fclose($h);
}
@ -60,11 +60,9 @@ trait FilesystemTrait
if (!file_exists($file) || !$h = @fopen($file, 'rb')) {
continue;
}
if ($now >= (int) $expiresAt = fgets($h)) {
if (($expiresAt = (int) fgets($h)) && $now >= $expiresAt) {
fclose($h);
if (isset($expiresAt[0])) {
@unlink($file);
}
@unlink($file);
} else {
$i = rawurldecode(rtrim(fgets($h)));
$value = stream_get_contents($h);
@ -94,7 +92,7 @@ trait FilesystemTrait
protected function doSave(array $values, $lifetime)
{
$ok = true;
$expiresAt = time() + ($lifetime ?: 31557600); // 31557600s = 1 year
$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;