Upgrade to 3.8.0

This commit is contained in:
Bastian Allgeier
2022-10-06 10:11:54 +02:00
parent a9ed4e45ca
commit 7d168aae58
332 changed files with 26337 additions and 21977 deletions

View File

@@ -20,10 +20,8 @@ class FileCache extends Cache
{
/**
* Full root including prefix
*
* @var string
*/
protected $root;
protected string $root;
/**
* Sets all parameters which are needed for the file cache
@@ -44,6 +42,7 @@ class FileCache extends Cache
// build the full root including prefix
$this->root = $this->options['root'];
if (empty($this->options['prefix']) === false) {
$this->root .= '/' . $this->options['prefix'];
}
@@ -52,10 +51,17 @@ class FileCache extends Cache
Dir::make($this->root, true);
}
/**
* Returns whether the cache is ready to
* store values
*/
public function enabled(): bool
{
return is_writable($this->root) === true;
}
/**
* Returns the full root including prefix
*
* @return string
*/
public function root(): string
{
@@ -64,9 +70,6 @@ class FileCache extends Cache
/**
* Returns the full path to a file for a given key
*
* @param string $key
* @return string
*/
protected function file(string $key): string
{
@@ -108,9 +111,9 @@ class FileCache extends Cache
if (isset($this->options['extension'])) {
return $file . '.' . $this->options['extension'];
} else {
return $file;
}
return $file;
}
/**
@@ -121,11 +124,6 @@ class FileCache extends Cache
* // put an item in the cache for 15 minutes
* $cache->set('value', 'my value', 15);
* </code>
*
* @param string $key
* @param mixed $value
* @param int $minutes
* @return bool
*/
public function set(string $key, $value, int $minutes = 0): bool
{
@@ -137,11 +135,8 @@ class FileCache extends Cache
/**
* Internal method to retrieve the raw cache value;
* needs to return a Value object or null if not found
*
* @param string $key
* @return \Kirby\Cache\Value|null
*/
public function retrieve(string $key)
public function retrieve(string $key): Value|null
{
$file = $this->file($key);
$value = F::read($file);
@@ -153,11 +148,8 @@ class FileCache extends Cache
* Checks when the cache has been created;
* returns the creation timestamp on success
* and false if the item does not exist
*
* @param string $key
* @return mixed
*/
public function created(string $key)
public function created(string $key): int|false
{
// use the modification timestamp
// as indicator when the cache has been created/overwritten
@@ -165,15 +157,12 @@ class FileCache extends Cache
// get the file for this cache key
$file = $this->file($key);
return file_exists($file) ? filemtime($this->file($key)) : false;
return file_exists($file) ? filemtime($file) : false;
}
/**
* Removes an item from the cache and returns
* whether the operation was successful
*
* @param string $key
* @return bool
*/
public function remove(string $key): bool
{
@@ -190,9 +179,6 @@ class FileCache extends Cache
/**
* Removes empty directories safely by checking each directory
* up to the root directory
*
* @param string $dir
* @return void
*/
protected function removeEmptyDirectories(string $dir): void
{
@@ -202,7 +188,13 @@ class FileCache extends Cache
// checks all directory segments until reaching the root directory
while (Str::startsWith($dir, $this->root()) === true && $dir !== $this->root()) {
$files = array_diff(scandir($dir) ?? [], ['.', '..']);
$files = scandir($dir);
if ($files === false) {
$files = []; // @codeCoverageIgnore
}
$files = array_diff($files, ['.', '..']);
if (empty($files) === true && Dir::remove($dir) === true) {
// continue with the next level up
@@ -212,7 +204,7 @@ class FileCache extends Cache
break;
}
}
} catch (Exception $e) { // @codeCoverageIgnore
} catch (Exception) { // @codeCoverageIgnore
// silently stops the process
}
}
@@ -220,12 +212,13 @@ class FileCache extends Cache
/**
* Flushes the entire cache and returns
* whether the operation was successful
*
* @return bool
*/
public function flush(): bool
{
if (Dir::remove($this->root) === true && Dir::make($this->root) === true) {
if (
Dir::remove($this->root) === true &&
Dir::make($this->root) === true
) {
return true;
}