@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | use FilesystemIterator, RecursiveDirectoryIterator, RecursiveIteratorIterator, stdClass; |
| 17 | 17 | use Psr\Log\LoggerInterface; |
| 18 | 18 | |
| 19 | -class FileCache extends CacheDriverAbstract{ |
|
| 19 | +class FileCache extends CacheDriverAbstract { |
|
| 20 | 20 | |
| 21 | 21 | protected string $cachedir; |
| 22 | 22 | |
@@ -28,19 +28,19 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @throws \chillerlan\SimpleCache\CacheException |
| 30 | 30 | */ |
| 31 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
| 31 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
| 32 | 32 | parent::__construct($options, $logger); |
| 33 | 33 | |
| 34 | 34 | $this->cachedir = \rtrim($this->options->cacheFilestorage, '/\\').\DIRECTORY_SEPARATOR; |
| 35 | 35 | |
| 36 | - if(!\is_dir($this->cachedir)){ |
|
| 36 | + if (!\is_dir($this->cachedir)) { |
|
| 37 | 37 | $msg = 'invalid cachedir "'.$this->cachedir.'"'; |
| 38 | 38 | |
| 39 | 39 | $this->logger->error($msg); |
| 40 | 40 | throw new CacheException($msg); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if(!\is_writable($this->cachedir)){ |
|
| 43 | + if (!\is_writable($this->cachedir)) { |
|
| 44 | 44 | $msg = 'cachedir is read-only. permissions?'; |
| 45 | 45 | |
| 46 | 46 | $this->logger->error($msg); |
@@ -50,16 +50,16 @@ discard block |
||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** @inheritdoc */ |
| 53 | - public function get($key, $default = null){ |
|
| 53 | + public function get($key, $default = null) { |
|
| 54 | 54 | $filename = $this->getFilepath($this->checkKey($key)); |
| 55 | 55 | |
| 56 | - if(\is_file($filename)){ |
|
| 56 | + if (\is_file($filename)) { |
|
| 57 | 57 | $content = \file_get_contents($filename); |
| 58 | 58 | |
| 59 | - if(!empty($content)){ |
|
| 59 | + if (!empty($content)) { |
|
| 60 | 60 | $data = \unserialize($content); |
| 61 | 61 | |
| 62 | - if($data->ttl === null || $data->ttl > \time()){ |
|
| 62 | + if ($data->ttl === null || $data->ttl > \time()) { |
|
| 63 | 63 | return $data->content; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $file = $this->getFilepath($this->checkKey($key)); |
| 79 | 79 | $dir = \dirname($file); |
| 80 | 80 | |
| 81 | - if(!\is_dir($dir)){ |
|
| 81 | + if (!\is_dir($dir)) { |
|
| 82 | 82 | \mkdir($dir, 0755, true); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -86,13 +86,13 @@ discard block |
||
| 86 | 86 | $data->ttl = null; |
| 87 | 87 | $data->content = $value; |
| 88 | 88 | |
| 89 | - if($ttl !== null){ |
|
| 89 | + if ($ttl !== null) { |
|
| 90 | 90 | $data->ttl = \time() + $ttl; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | \file_put_contents($file, \serialize($data)); |
| 94 | 94 | |
| 95 | - if(\is_file($file)){ |
|
| 95 | + if (\is_file($file)) { |
|
| 96 | 96 | return true; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | public function delete($key):bool{ |
| 104 | 104 | $filename = $this->getFilepath($this->checkKey($key)); |
| 105 | 105 | |
| 106 | - if(\is_file($filename)){ |
|
| 106 | + if (\is_file($filename)) { |
|
| 107 | 107 | return \unlink($filename); |
| 108 | 108 | } |
| 109 | 109 | |
@@ -112,13 +112,13 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | /** @inheritdoc */ |
| 114 | 114 | public function clear():bool{ |
| 115 | - $iterator = new RecursiveDirectoryIterator($this->cachedir, FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS); |
|
| 115 | + $iterator = new RecursiveDirectoryIterator($this->cachedir, FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS); |
|
| 116 | 116 | $return = []; |
| 117 | 117 | |
| 118 | - foreach(new RecursiveIteratorIterator($iterator) as $path){ |
|
| 118 | + foreach (new RecursiveIteratorIterator($iterator) as $path) { |
|
| 119 | 119 | |
| 120 | 120 | // skip files in the parent directory - cache files are only under /a/ab/[hash] |
| 121 | - if(\strpos(\str_replace($this->cachedir, '', $path), \DIRECTORY_SEPARATOR) === false){ |
|
| 121 | + if (\strpos(\str_replace($this->cachedir, '', $path), \DIRECTORY_SEPARATOR) === false) { |
|
| 122 | 122 | continue; |
| 123 | 123 | } |
| 124 | 124 | |