Upgrade to 3.5.5
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Kirby\Cache;
|
||||
|
||||
use Kirby\Exception\Exception;
|
||||
use Kirby\Toolkit\Dir;
|
||||
use Kirby\Toolkit\F;
|
||||
use Kirby\Toolkit\Str;
|
||||
@@ -77,19 +78,19 @@ class FileCache extends Cache
|
||||
// forward slashes don't need special treatment
|
||||
case '/':
|
||||
break;
|
||||
|
||||
|
||||
// backslashes get their own marker in the path
|
||||
// to differentiate the cache key from one with forward slashes
|
||||
case '\\':
|
||||
$keyParts[] = '_backslash';
|
||||
break;
|
||||
|
||||
|
||||
// empty part means two slashes in a row;
|
||||
// special marker like for backslashes
|
||||
case '':
|
||||
$keyParts[] = '_empty';
|
||||
break;
|
||||
|
||||
|
||||
// an actual path segment
|
||||
default:
|
||||
// check if the segment only contains safe characters;
|
||||
@@ -178,10 +179,41 @@ class FileCache extends Cache
|
||||
{
|
||||
$file = $this->file($key);
|
||||
|
||||
if (is_file($file) === true) {
|
||||
return F::remove($file);
|
||||
} else {
|
||||
return false;
|
||||
if (is_file($file) === true && F::remove($file) === true) {
|
||||
$this->removeEmptyDirectories(dirname($file));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes empty directories safely by checking each directory
|
||||
* up to the root directory
|
||||
*
|
||||
* @param string $dir
|
||||
* @return void
|
||||
*/
|
||||
protected function removeEmptyDirectories(string $dir): void
|
||||
{
|
||||
try {
|
||||
// ensure the path doesn't end with a slash for the next comparison
|
||||
$dir = rtrim($dir, '/\/');
|
||||
|
||||
// checks all directory segments until reaching the root directory
|
||||
while (Str::startsWith($dir, $this->root()) === true && $dir !== $this->root()) {
|
||||
$files = array_diff(scandir($dir) ?? [], ['.', '..']);
|
||||
|
||||
if (empty($files) === true && Dir::remove($dir) === true) {
|
||||
// continue with the next level up
|
||||
$dir = dirname($dir);
|
||||
} else {
|
||||
// no need to continue with the next level up as `$dir` was not deleted
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) { // @codeCoverageIgnore
|
||||
// silently stops the process
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ class Value
|
||||
|
||||
/**
|
||||
* the number of minutes until the value expires
|
||||
* @todo Rename this property to $expiry to reflect
|
||||
* both minutes and absolute timestamps
|
||||
* @var int
|
||||
*/
|
||||
protected $minutes;
|
||||
@@ -40,7 +42,8 @@ class Value
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param int $minutes the number of minutes until the value expires
|
||||
* @param int $created the unix timestamp when the value has been created
|
||||
* or an absolute UNIX timestamp
|
||||
* @param int $created the UNIX timestamp when the value has been created
|
||||
*/
|
||||
public function __construct($value, int $minutes = 0, int $created = null)
|
||||
{
|
||||
@@ -72,6 +75,11 @@ class Value
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->minutes > 1000000000) {
|
||||
// absolute timestamp
|
||||
return $this->minutes;
|
||||
}
|
||||
|
||||
return $this->created + ($this->minutes * 60);
|
||||
}
|
||||
|
||||
@@ -79,7 +87,7 @@ class Value
|
||||
* Creates a value object from an array
|
||||
*
|
||||
* @param array $array
|
||||
* @return self
|
||||
* @return static
|
||||
*/
|
||||
public static function fromArray(array $array)
|
||||
{
|
||||
@@ -91,7 +99,7 @@ class Value
|
||||
* returns null on error
|
||||
*
|
||||
* @param string $json
|
||||
* @return self|null
|
||||
* @return static|null
|
||||
*/
|
||||
public static function fromJson(string $json)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user