@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | use Memcached; |
19 | 19 | use Psr\Log\LoggerInterface; |
20 | 20 | |
21 | -class MemcachedCache extends CacheDriverAbstract{ |
|
21 | +class MemcachedCache extends CacheDriverAbstract { |
|
22 | 22 | |
23 | 23 | protected Memcached $memcached; |
24 | 24 | |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @throws \chillerlan\SimpleCache\CacheException |
33 | 33 | */ |
34 | - public function __construct(Memcached $memcached, SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
34 | + public function __construct(Memcached $memcached, SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
35 | 35 | parent::__construct($options, $logger); |
36 | 36 | |
37 | 37 | $this->memcached = $memcached; |
38 | 38 | |
39 | - if(empty($this->memcached->getServerList())){ |
|
39 | + if (empty($this->memcached->getServerList())) { |
|
40 | 40 | $msg = 'no memcache server available'; |
41 | 41 | |
42 | 42 | $this->logger->error($msg); |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** @inheritdoc */ |
49 | - public function get($key, $default = null){ |
|
49 | + public function get($key, $default = null) { |
|
50 | 50 | $value = $this->memcached->get($this->checkKey($key)); |
51 | 51 | |
52 | - if($value !== false){ |
|
52 | + if ($value !== false) { |
|
53 | 53 | return $value; |
54 | 54 | } |
55 | 55 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $values = $this->memcached->getMulti($keys); |
81 | 81 | $return = []; |
82 | 82 | |
83 | - foreach($keys as $key){ |
|
83 | + foreach ($keys as $key) { |
|
84 | 84 | $return[$key] = $values[$key] ?? $default; |
85 | 85 | } |
86 | 86 |
@@ -14,13 +14,13 @@ |
||
14 | 14 | |
15 | 15 | namespace chillerlan\SimpleCache; |
16 | 16 | |
17 | -class APCUCache extends CacheDriverAbstract{ |
|
17 | +class APCUCache extends CacheDriverAbstract { |
|
18 | 18 | |
19 | 19 | /** @inheritdoc */ |
20 | - public function get($key, $default = null){ |
|
20 | + public function get($key, $default = null) { |
|
21 | 21 | $value = \apcu_fetch($this->checkKey($key)); |
22 | 22 | |
23 | - if($value !== false){ |
|
23 | + if ($value !== false) { |
|
24 | 24 | return $value; |
25 | 25 | } |
26 | 26 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * CacheDriverAbstract constructor. |
32 | 32 | */ |
33 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
33 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
34 | 34 | $this->options = $options ?? new CacheOptions; |
35 | 35 | $this->logger = $logger ?? new NullLogger; |
36 | 36 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | public function getMultiple($keys, $default = null):array{ |
45 | 45 | $data = []; |
46 | 46 | |
47 | - foreach($this->getData($keys) as $key){ |
|
47 | + foreach ($this->getData($keys) as $key) { |
|
48 | 48 | $data[$key] = $this->get($key, $default); |
49 | 49 | } |
50 | 50 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function setMultiple($values, $ttl = null):bool{ |
56 | 56 | $return = []; |
57 | 57 | |
58 | - foreach($this->getData($values) as $key => $value){ |
|
58 | + foreach ($this->getData($values) as $key => $value) { |
|
59 | 59 | $return[] = $this->set($key, $value, $ttl); |
60 | 60 | } |
61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | public function deleteMultiple($keys):bool{ |
67 | 67 | $return = []; |
68 | 68 | |
69 | - foreach($this->getData($keys) as $key){ |
|
69 | + foreach ($this->getData($keys) as $key) { |
|
70 | 70 | $return[] = $this->delete($key); |
71 | 71 | } |
72 | 72 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function checkKey($key):string{ |
83 | 83 | |
84 | - if(!\is_string($key) || empty($key)){ |
|
84 | + if (!\is_string($key) || empty($key)) { |
|
85 | 85 | $msg = 'invalid cache key: "'.$key.'"'; |
86 | 86 | $this->logger->error($msg); |
87 | 87 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | protected function checkKeyArray(array $keys):void{ |
100 | 100 | |
101 | - foreach($keys as $key){ |
|
101 | + foreach ($keys as $key) { |
|
102 | 102 | $this->checkKey($key); |
103 | 103 | } |
104 | 104 | |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | */ |
113 | 113 | protected function getData($data):array{ |
114 | 114 | |
115 | - if(\is_array($data)){ |
|
115 | + if (\is_array($data)) { |
|
116 | 116 | return $data; |
117 | 117 | } |
118 | - elseif($data instanceof Traversable){ |
|
118 | + elseif ($data instanceof Traversable) { |
|
119 | 119 | return \iterator_to_array($data); // @codeCoverageIgnore |
120 | 120 | } |
121 | 121 | |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | * @return int|null |
132 | 132 | * @throws \Psr\SimpleCache\InvalidArgumentException |
133 | 133 | */ |
134 | - protected function getTTL($ttl):?int{ |
|
134 | + protected function getTTL($ttl): ?int{ |
|
135 | 135 | |
136 | - if($ttl instanceof DateInterval){ |
|
136 | + if ($ttl instanceof DateInterval) { |
|
137 | 137 | return (new DateTime)->add($ttl)->getTimeStamp() - \time(); |
138 | 138 | } |
139 | - else if((\is_int($ttl) && $ttl > 0) || $ttl === null){ |
|
139 | + else if ((\is_int($ttl) && $ttl > 0) || $ttl === null) { |
|
140 | 140 | return $ttl; |
141 | 141 | } |
142 | 142 | |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | */ |
154 | 154 | protected function checkReturn(array $booleans):bool{ |
155 | 155 | |
156 | - foreach($booleans as $bool){ |
|
156 | + foreach ($booleans as $bool) { |
|
157 | 157 | |
158 | - if(!(bool)$bool){ |
|
158 | + if (!(bool)$bool) { |
|
159 | 159 | return false; // @codeCoverageIgnore |
160 | 160 | } |
161 | 161 |
@@ -114,8 +114,7 @@ discard block |
||
114 | 114 | |
115 | 115 | if(\is_array($data)){ |
116 | 116 | return $data; |
117 | - } |
|
118 | - elseif($data instanceof Traversable){ |
|
117 | + } elseif($data instanceof Traversable){ |
|
119 | 118 | return \iterator_to_array($data); // @codeCoverageIgnore |
120 | 119 | } |
121 | 120 | |
@@ -135,8 +134,7 @@ discard block |
||
135 | 134 | |
136 | 135 | if($ttl instanceof DateInterval){ |
137 | 136 | return (new DateTime)->add($ttl)->getTimeStamp() - \time(); |
138 | - } |
|
139 | - else if((\is_int($ttl) && $ttl > 0) || $ttl === null){ |
|
137 | + } else if((\is_int($ttl) && $ttl > 0) || $ttl === null){ |
|
140 | 138 | return $ttl; |
141 | 139 | } |
142 | 140 |
@@ -12,17 +12,17 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class MemoryCache extends CacheDriverAbstract{ |
|
15 | +class MemoryCache extends CacheDriverAbstract { |
|
16 | 16 | |
17 | 17 | protected array $cache = []; |
18 | 18 | |
19 | 19 | /** @inheritdoc */ |
20 | - public function get($key, $default = null){ |
|
20 | + public function get($key, $default = null) { |
|
21 | 21 | $key = $this->checkKey($key); |
22 | 22 | |
23 | - if(isset($this->cache[$key])){ |
|
23 | + if (isset($this->cache[$key])) { |
|
24 | 24 | |
25 | - if($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > \time()){ |
|
25 | + if ($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > \time()) { |
|
26 | 26 | return $this->cache[$key]['content']; |
27 | 27 | } |
28 | 28 |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -trait CacheOptionsTrait{ |
|
15 | +trait CacheOptionsTrait { |
|
16 | 16 | |
17 | 17 | protected string $cacheFilestorage = ''; |
18 | 18 | protected string $cacheSessionkey = '_session_cache'; |
@@ -18,24 +18,24 @@ discard block |
||
18 | 18 | use Psr\Log\LoggerInterface; |
19 | 19 | use Redis; |
20 | 20 | |
21 | -class RedisCache extends CacheDriverAbstract{ |
|
21 | +class RedisCache extends CacheDriverAbstract { |
|
22 | 22 | |
23 | 23 | protected Redis $redis; |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * RedisCache constructor. |
27 | 27 | */ |
28 | - public function __construct(Redis $redis, SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
28 | + public function __construct(Redis $redis, SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
29 | 29 | parent::__construct($options, $logger); |
30 | 30 | |
31 | 31 | $this->redis = $redis; |
32 | 32 | } |
33 | 33 | |
34 | 34 | /** @inheritdoc */ |
35 | - public function get($key, $default = null){ |
|
35 | + public function get($key, $default = null) { |
|
36 | 36 | $value = $this->redis->get($this->checkKey($key)); |
37 | 37 | |
38 | - if($value !== false){ |
|
38 | + if ($value !== false) { |
|
39 | 39 | return $value; |
40 | 40 | } |
41 | 41 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $key = $this->checkKey($key); |
48 | 48 | $ttl = $this->getTTL($ttl); |
49 | 49 | |
50 | - if($ttl === null){ |
|
50 | + if ($ttl === null) { |
|
51 | 51 | return $this->redis->set($key, $value); |
52 | 52 | } |
53 | 53 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $values = \array_combine($keys, $this->redis->mget($keys)); |
75 | 75 | $return = []; |
76 | 76 | |
77 | - foreach($keys as $key){ |
|
77 | + foreach ($keys as $key) { |
|
78 | 78 | /** @phan-suppress-next-line PhanTypeArraySuspiciousNullable */ |
79 | 79 | $return[$key] = $values[$key] !== false ? $values[$key] : $default; |
80 | 80 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $values = $this->getData($values); |
88 | 88 | $ttl = $this->getTTL($ttl); |
89 | 89 | |
90 | - if($ttl === null){ |
|
90 | + if ($ttl === null) { |
|
91 | 91 | $this->checkKeyArray(\array_keys($values)); |
92 | 92 | |
93 | 93 | return $this->redis->msetnx($values); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | $return = []; |
97 | 97 | |
98 | - foreach($values as $key => $value){ |
|
98 | + foreach ($values as $key => $value) { |
|
99 | 99 | $return[] = $this->set($key, $value, $ttl); |
100 | 100 | } |
101 | 101 |
@@ -15,19 +15,19 @@ discard block |
||
15 | 15 | use chillerlan\Settings\SettingsContainerInterface; |
16 | 16 | use Psr\Log\LoggerInterface; |
17 | 17 | |
18 | -class SessionCache extends CacheDriverAbstract{ |
|
18 | +class SessionCache extends CacheDriverAbstract { |
|
19 | 19 | |
20 | 20 | protected string $key; |
21 | 21 | |
22 | 22 | /** |
23 | 23 | * SessionCache constructor. |
24 | 24 | */ |
25 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
25 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
26 | 26 | parent::__construct($options, $logger); |
27 | 27 | |
28 | 28 | $this->key = $this->options->cacheSessionkey; |
29 | 29 | |
30 | - if(!is_string($this->key) || empty($this->key)){ |
|
30 | + if (!is_string($this->key) || empty($this->key)) { |
|
31 | 31 | $msg = 'invalid session cache key'; |
32 | 32 | |
33 | 33 | $this->logger->error($msg); |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | } |
40 | 40 | |
41 | 41 | /** @inheritdoc */ |
42 | - public function get($key, $default = null){ |
|
42 | + public function get($key, $default = null) { |
|
43 | 43 | $key = $this->checkKey($key); |
44 | 44 | |
45 | - if(isset($_SESSION[$this->key][$key])){ |
|
45 | + if (isset($_SESSION[$this->key][$key])) { |
|
46 | 46 | |
47 | - if($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > \time()){ |
|
47 | + if ($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > \time()) { |
|
48 | 48 | return $_SESSION[$this->key][$key]['content']; |
49 | 49 | } |
50 | 50 |
@@ -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 |