@@ -15,7 +15,7 @@ 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 | /** |
21 | 21 | * @var string |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @throws \chillerlan\SimpleCache\CacheException |
32 | 32 | */ |
33 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
33 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
34 | 34 | parent::__construct($options, $logger); |
35 | 35 | |
36 | 36 | $this->key = $this->options->cacheSessionkey; |
37 | 37 | |
38 | - if(!is_string($this->key) || empty($this->key)){ |
|
38 | + if (!is_string($this->key) || empty($this->key)) { |
|
39 | 39 | $msg = 'invalid session cache key'; |
40 | 40 | |
41 | 41 | $this->logger->error($msg); |
@@ -47,12 +47,12 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | /** @inheritdoc */ |
50 | - public function get($key, $default = null){ |
|
50 | + public function get($key, $default = null) { |
|
51 | 51 | $key = $this->checkKey($key); |
52 | 52 | |
53 | - if(isset($_SESSION[$this->key][$key])){ |
|
53 | + if (isset($_SESSION[$this->key][$key])) { |
|
54 | 54 | |
55 | - if($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()){ |
|
55 | + if ($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()) { |
|
56 | 56 | return $_SESSION[$this->key][$key]['content']; |
57 | 57 | } |
58 | 58 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use Memcached; |
17 | 17 | use Psr\Log\LoggerInterface; |
18 | 18 | |
19 | -class MemcachedCache extends CacheDriverAbstract{ |
|
19 | +class MemcachedCache extends CacheDriverAbstract { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @var \Memcached |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @throws \chillerlan\SimpleCache\CacheException |
34 | 34 | */ |
35 | - public function __construct(Memcached $memcached, SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
35 | + public function __construct(Memcached $memcached, SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
36 | 36 | parent::__construct($options, $logger); |
37 | 37 | |
38 | 38 | $this->memcached = $memcached; |
39 | 39 | |
40 | - if(empty($this->memcached->getServerList())){ |
|
40 | + if (empty($this->memcached->getServerList())) { |
|
41 | 41 | $msg = 'no memcache server available'; |
42 | 42 | |
43 | 43 | $this->logger->error($msg); |
@@ -47,10 +47,10 @@ discard block |
||
47 | 47 | } |
48 | 48 | |
49 | 49 | /** @inheritdoc */ |
50 | - public function get($key, $default = null){ |
|
50 | + public function get($key, $default = null) { |
|
51 | 51 | $value = $this->memcached->get($this->checkKey($key)); |
52 | 52 | |
53 | - if($value !== false){ |
|
53 | + if ($value !== false) { |
|
54 | 54 | return $value; |
55 | 55 | } |
56 | 56 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $values = $this->memcached->getMulti($keys); |
82 | 82 | $return = []; |
83 | 83 | |
84 | - foreach($keys as $key){ |
|
84 | + foreach ($keys as $key) { |
|
85 | 85 | $return[$key] = $values[$key] ?? $default; |
86 | 86 | } |
87 | 87 |
@@ -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 | /** |
22 | 22 | * @var string |
@@ -31,19 +31,19 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @throws \chillerlan\SimpleCache\CacheException |
33 | 33 | */ |
34 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
34 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
35 | 35 | parent::__construct($options, $logger); |
36 | 36 | |
37 | 37 | $this->cachedir = rtrim($this->options->cacheFilestorage, '/\\').DIRECTORY_SEPARATOR; |
38 | 38 | |
39 | - if(!is_dir($this->cachedir)){ |
|
39 | + if (!is_dir($this->cachedir)) { |
|
40 | 40 | $msg = 'invalid cachedir "'.$this->cachedir.'"'; |
41 | 41 | |
42 | 42 | $this->logger->error($msg); |
43 | 43 | throw new CacheException($msg); |
44 | 44 | } |
45 | 45 | |
46 | - if(!is_writable($this->cachedir)){ |
|
46 | + if (!is_writable($this->cachedir)) { |
|
47 | 47 | $msg = 'cachedir is read-only. permissions?'; |
48 | 48 | |
49 | 49 | $this->logger->error($msg); |
@@ -53,16 +53,16 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | /** @inheritdoc */ |
56 | - public function get($key, $default = null){ |
|
56 | + public function get($key, $default = null) { |
|
57 | 57 | $filename = $this->getFilepath($this->checkKey($key)); |
58 | 58 | |
59 | - if(is_file($filename)){ |
|
59 | + if (is_file($filename)) { |
|
60 | 60 | $content = file_get_contents($filename); |
61 | 61 | |
62 | - if(!empty($content)){ |
|
62 | + if (!empty($content)) { |
|
63 | 63 | $data = unserialize($content); |
64 | 64 | |
65 | - if($data->ttl === null || $data->ttl > time()){ |
|
65 | + if ($data->ttl === null || $data->ttl > time()) { |
|
66 | 66 | return $data->content; |
67 | 67 | } |
68 | 68 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $file = $this->getFilepath($this->checkKey($key)); |
82 | 82 | $dir = dirname($file); |
83 | 83 | |
84 | - if(!is_dir($dir)){ |
|
84 | + if (!is_dir($dir)) { |
|
85 | 85 | mkdir($dir, 0755, true); |
86 | 86 | } |
87 | 87 | |
@@ -89,13 +89,13 @@ discard block |
||
89 | 89 | $data->ttl = null; |
90 | 90 | $data->content = $value; |
91 | 91 | |
92 | - if($ttl !== null){ |
|
92 | + if ($ttl !== null) { |
|
93 | 93 | $data->ttl = time() + $ttl; |
94 | 94 | } |
95 | 95 | |
96 | 96 | file_put_contents($file, serialize($data)); |
97 | 97 | |
98 | - if(is_file($file)){ |
|
98 | + if (is_file($file)) { |
|
99 | 99 | return true; |
100 | 100 | } |
101 | 101 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | public function delete($key):bool{ |
107 | 107 | $filename = $this->getFilepath($this->checkKey($key)); |
108 | 108 | |
109 | - if(is_file($filename)){ |
|
109 | + if (is_file($filename)) { |
|
110 | 110 | return unlink($filename); |
111 | 111 | } |
112 | 112 | |
@@ -115,13 +115,13 @@ discard block |
||
115 | 115 | |
116 | 116 | /** @inheritdoc */ |
117 | 117 | public function clear():bool{ |
118 | - $iterator = new RecursiveDirectoryIterator($this->cachedir, FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS); |
|
118 | + $iterator = new RecursiveDirectoryIterator($this->cachedir, FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS); |
|
119 | 119 | $return = []; |
120 | 120 | |
121 | - foreach(new RecursiveIteratorIterator($iterator) as $path){ |
|
121 | + foreach (new RecursiveIteratorIterator($iterator) as $path) { |
|
122 | 122 | |
123 | 123 | // skip files in the parent directory - cache files are only under /a/ab/[hash] |
124 | - if(strpos(str_replace($this->cachedir, '', $path), DIRECTORY_SEPARATOR) === false){ |
|
124 | + if (strpos(str_replace($this->cachedir, '', $path), DIRECTORY_SEPARATOR) === false) { |
|
125 | 125 | continue; |
126 | 126 | } |
127 | 127 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use Psr\Log\LoggerInterface; |
17 | 17 | use Redis; |
18 | 18 | |
19 | -class RedisCache extends CacheDriverAbstract{ |
|
19 | +class RedisCache extends CacheDriverAbstract { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @var \Redis |
@@ -30,17 +30,17 @@ discard block |
||
30 | 30 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
31 | 31 | * @param \Psr\Log\LoggerInterface|null $logger |
32 | 32 | */ |
33 | - public function __construct(Redis $redis, SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
33 | + public function __construct(Redis $redis, SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
34 | 34 | parent::__construct($options, $logger); |
35 | 35 | |
36 | 36 | $this->redis = $redis; |
37 | 37 | } |
38 | 38 | |
39 | 39 | /** @inheritdoc */ |
40 | - public function get($key, $default = null){ |
|
40 | + public function get($key, $default = null) { |
|
41 | 41 | $value = $this->redis->get($this->checkKey($key)); |
42 | 42 | |
43 | - if($value !== false){ |
|
43 | + if ($value !== false) { |
|
44 | 44 | return $value; |
45 | 45 | } |
46 | 46 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | $key = $this->checkKey($key); |
53 | 53 | $ttl = $this->getTTL($ttl); |
54 | 54 | |
55 | - if($ttl === null){ |
|
55 | + if ($ttl === null) { |
|
56 | 56 | return $this->redis->set($key, $value); |
57 | 57 | } |
58 | 58 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | $return = []; |
82 | 82 | |
83 | - foreach($keys as $key){ |
|
83 | + foreach ($keys as $key) { |
|
84 | 84 | $return[$key] = $values[$key] !== false ? $values[$key] : $default; |
85 | 85 | } |
86 | 86 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $values = $this->getData($values); |
93 | 93 | $ttl = $this->getTTL($ttl); |
94 | 94 | |
95 | - if($ttl === null){ |
|
95 | + if ($ttl === null) { |
|
96 | 96 | $this->checkKeyArray(array_keys($values)); |
97 | 97 | |
98 | 98 | return $this->redis->msetnx($values); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | |
101 | 101 | $return = []; |
102 | 102 | |
103 | - foreach($values as $key => $value){ |
|
103 | + foreach ($values as $key => $value) { |
|
104 | 104 | $return[] = $this->set($key, $value, $ttl); |
105 | 105 | } |
106 | 106 |