@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | use chillerlan\SimpleCache\SimpleCacheException; |
| 16 | 16 | use stdClass; |
| 17 | 17 | |
| 18 | -class FileCacheDriver extends CacheDriverAbstract{ |
|
| 18 | +class FileCacheDriver extends CacheDriverAbstract { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @var string |
@@ -29,30 +29,30 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @throws \chillerlan\SimpleCache\SimpleCacheException |
| 31 | 31 | */ |
| 32 | - public function __construct(string $cachedir){ |
|
| 32 | + public function __construct(string $cachedir) { |
|
| 33 | 33 | $this->cachedir = $cachedir; |
| 34 | 34 | |
| 35 | - if(!is_dir($cachedir)){ |
|
| 35 | + if (!is_dir($cachedir)) { |
|
| 36 | 36 | throw new SimpleCacheException('invalid cachedir "'.$cachedir.'"'); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if(!is_writable($cachedir)){ |
|
| 39 | + if (!is_writable($cachedir)) { |
|
| 40 | 40 | throw new SimpleCacheException('cachedir is read-only. permissions?'); // @codeCoverageIgnore |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** @inheritdoc */ |
| 46 | - public function get(string $key, $default = null){ |
|
| 46 | + public function get(string $key, $default = null) { |
|
| 47 | 47 | $filename = $this->filename($key); |
| 48 | 48 | |
| 49 | - if(is_file($filename)){ |
|
| 49 | + if (is_file($filename)) { |
|
| 50 | 50 | $content = file_get_contents($filename); |
| 51 | 51 | |
| 52 | - if(!empty($content)){ |
|
| 52 | + if (!empty($content)) { |
|
| 53 | 53 | $data = unserialize($content); |
| 54 | 54 | |
| 55 | - if(is_null($data->ttl) || $data->ttl > time()){ |
|
| 55 | + if (is_null($data->ttl) || $data->ttl > time()) { |
|
| 56 | 56 | return $data->content; |
| 57 | 57 | } |
| 58 | 58 | |
@@ -71,13 +71,13 @@ discard block |
||
| 71 | 71 | $data->ttl = null; |
| 72 | 72 | $data->content = $value; |
| 73 | 73 | |
| 74 | - if($ttl !== null){ |
|
| 74 | + if ($ttl !== null) { |
|
| 75 | 75 | $data->ttl = time() + $ttl; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | file_put_contents($filename, serialize($data)); |
| 79 | 79 | |
| 80 | - if(is_file($filename)){ |
|
| 80 | + if (is_file($filename)) { |
|
| 81 | 81 | return true; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | public function delete(string $key):bool{ |
| 89 | 89 | $filename = $this->filename($key); |
| 90 | 90 | |
| 91 | - if(is_file($filename)){ |
|
| 91 | + if (is_file($filename)) { |
|
| 92 | 92 | return unlink($filename); |
| 93 | 93 | } |
| 94 | 94 | |
@@ -99,13 +99,13 @@ discard block |
||
| 99 | 99 | public function clear():bool{ |
| 100 | 100 | $dir = scandir($this->cachedir); |
| 101 | 101 | |
| 102 | - if(is_array($dir) && !empty($dir)){ |
|
| 102 | + if (is_array($dir) && !empty($dir)) { |
|
| 103 | 103 | $return = []; |
| 104 | 104 | |
| 105 | - foreach($dir as $file){ |
|
| 105 | + foreach ($dir as $file) { |
|
| 106 | 106 | $path = $this->cachedir.DIRECTORY_SEPARATOR.$file; |
| 107 | 107 | |
| 108 | - if(is_file($path) && strlen($file) === 64){ |
|
| 108 | + if (is_file($path) && strlen($file) === 64) { |
|
| 109 | 109 | $return[] = unlink($path); |
| 110 | 110 | } |
| 111 | 111 | |