@@ -12,4 +12,4 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class CacheException extends \Exception implements \Psr\SimpleCache\CacheException{} |
|
15 | +class CacheException extends \Exception implements \Psr\SimpleCache\CacheException {} |
@@ -12,4 +12,4 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class InvalidArgumentException extends CacheException implements \Psr\SimpleCache\InvalidArgumentException{} |
|
15 | +class InvalidArgumentException extends CacheException implements \Psr\SimpleCache\InvalidArgumentException {} |
@@ -12,9 +12,9 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -trait CacheOptionsTrait{ |
|
15 | +trait CacheOptionsTrait { |
|
16 | 16 | |
17 | 17 | protected $cacheFilestorage = ''; |
18 | - protected $cacheSessionkey = '_session_cache'; |
|
18 | + protected $cacheSessionkey = '_session_cache'; |
|
19 | 19 | |
20 | 20 | } |
@@ -18,6 +18,6 @@ |
||
18 | 18 | * @property string $cacheFilestorage |
19 | 19 | * @property string $cacheSessionkey |
20 | 20 | */ |
21 | -class CacheOptions extends SettingsContainerAbstract{ |
|
21 | +class CacheOptions extends SettingsContainerAbstract { |
|
22 | 22 | use CacheOptionsTrait; |
23 | 23 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use chillerlan\Settings\SettingsContainerInterface; |
16 | 16 | |
17 | -class SessionCache extends CacheDriverAbstract{ |
|
17 | +class SessionCache extends CacheDriverAbstract { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @var string |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @throws \chillerlan\SimpleCache\CacheException |
30 | 30 | */ |
31 | - public function __construct(SettingsContainerInterface $options = null){ |
|
31 | + public function __construct(SettingsContainerInterface $options = null) { |
|
32 | 32 | parent::__construct($options); |
33 | 33 | |
34 | 34 | $this->key = $this->options->cacheSessionkey; |
35 | 35 | |
36 | - if(!is_string($this->key) || empty($this->key)){ |
|
36 | + if (!is_string($this->key) || empty($this->key)) { |
|
37 | 37 | $msg = 'invalid session cache key'; |
38 | 38 | |
39 | 39 | $this->logger->error($msg); |
@@ -45,12 +45,12 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | /** @inheritdoc */ |
48 | - public function get($key, $default = null){ |
|
48 | + public function get($key, $default = null) { |
|
49 | 49 | $key = $this->checkKey($key); |
50 | 50 | |
51 | - if(isset($_SESSION[$this->key][$key])){ |
|
51 | + if (isset($_SESSION[$this->key][$key])) { |
|
52 | 52 | |
53 | - if($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()){ |
|
53 | + if ($_SESSION[$this->key][$key]['ttl'] === null || $_SESSION[$this->key][$key]['ttl'] > time()) { |
|
54 | 54 | return $_SESSION[$this->key][$key]['content']; |
55 | 55 | } |
56 | 56 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\Settings\SettingsContainerInterface; |
16 | 16 | use FilesystemIterator, RecursiveDirectoryIterator, RecursiveIteratorIterator, stdClass; |
17 | 17 | |
18 | -class FileCache extends CacheDriverAbstract{ |
|
18 | +class FileCache extends CacheDriverAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var string |
@@ -29,19 +29,19 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @throws \chillerlan\SimpleCache\CacheException |
31 | 31 | */ |
32 | - public function __construct(SettingsContainerInterface $options = null){ |
|
32 | + public function __construct(SettingsContainerInterface $options = null) { |
|
33 | 33 | parent::__construct($options); |
34 | 34 | |
35 | 35 | $this->cachedir = rtrim($this->options->cacheFilestorage, '/\\').DIRECTORY_SEPARATOR; |
36 | 36 | |
37 | - if(!is_dir($this->cachedir)){ |
|
37 | + if (!is_dir($this->cachedir)) { |
|
38 | 38 | $msg = 'invalid cachedir "'.$this->cachedir.'"'; |
39 | 39 | |
40 | 40 | $this->logger->error($msg); |
41 | 41 | throw new CacheException($msg); |
42 | 42 | } |
43 | 43 | |
44 | - if(!is_writable($this->cachedir)){ |
|
44 | + if (!is_writable($this->cachedir)) { |
|
45 | 45 | $msg = 'cachedir is read-only. permissions?'; |
46 | 46 | |
47 | 47 | $this->logger->error($msg); |
@@ -51,16 +51,16 @@ discard block |
||
51 | 51 | } |
52 | 52 | |
53 | 53 | /** @inheritdoc */ |
54 | - public function get($key, $default = null){ |
|
54 | + public function get($key, $default = null) { |
|
55 | 55 | $filename = $this->getFilepath($this->checkKey($key)); |
56 | 56 | |
57 | - if(is_file($filename)){ |
|
57 | + if (is_file($filename)) { |
|
58 | 58 | $content = file_get_contents($filename); |
59 | 59 | |
60 | - if(!empty($content)){ |
|
60 | + if (!empty($content)) { |
|
61 | 61 | $data = unserialize($content); |
62 | 62 | |
63 | - if($data->ttl === null || $data->ttl > time()){ |
|
63 | + if ($data->ttl === null || $data->ttl > time()) { |
|
64 | 64 | return $data->content; |
65 | 65 | } |
66 | 66 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $file = $this->getFilepath($this->checkKey($key)); |
80 | 80 | $dir = dirname($file); |
81 | 81 | |
82 | - if(!is_dir($dir)){ |
|
82 | + if (!is_dir($dir)) { |
|
83 | 83 | mkdir($dir, 0755, true); |
84 | 84 | } |
85 | 85 | |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | $data->ttl = null; |
88 | 88 | $data->content = $value; |
89 | 89 | |
90 | - if($ttl !== null){ |
|
90 | + if ($ttl !== null) { |
|
91 | 91 | $data->ttl = time() + $ttl; |
92 | 92 | } |
93 | 93 | |
94 | 94 | file_put_contents($file, serialize($data)); |
95 | 95 | |
96 | - if(is_file($file)){ |
|
96 | + if (is_file($file)) { |
|
97 | 97 | return true; |
98 | 98 | } |
99 | 99 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | public function delete($key):bool{ |
105 | 105 | $filename = $this->getFilepath($this->checkKey($key)); |
106 | 106 | |
107 | - if(is_file($filename)){ |
|
107 | + if (is_file($filename)) { |
|
108 | 108 | return unlink($filename); |
109 | 109 | } |
110 | 110 | |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | |
114 | 114 | /** @inheritdoc */ |
115 | 115 | public function clear():bool{ |
116 | - $iterator = new RecursiveDirectoryIterator($this->cachedir, FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS); |
|
116 | + $iterator = new RecursiveDirectoryIterator($this->cachedir, FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS); |
|
117 | 117 | $return = []; |
118 | 118 | |
119 | - foreach(new RecursiveIteratorIterator($iterator) as $path){ |
|
119 | + foreach (new RecursiveIteratorIterator($iterator) as $path) { |
|
120 | 120 | |
121 | 121 | // skip files in the parent directory - cache files are only under /a/ab/[hash] |
122 | - if(strpos(str_replace($this->cachedir, '', $path), DIRECTORY_SEPARATOR) === false){ |
|
122 | + if (strpos(str_replace($this->cachedir, '', $path), DIRECTORY_SEPARATOR) === false) { |
|
123 | 123 | continue; |
124 | 124 | } |
125 | 125 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class MemoryCache extends CacheDriverAbstract{ |
|
15 | +class MemoryCache extends CacheDriverAbstract { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * @var array |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | protected $cache = []; |
21 | 21 | |
22 | 22 | /** @inheritdoc */ |
23 | - public function get($key, $default = null){ |
|
23 | + public function get($key, $default = null) { |
|
24 | 24 | $key = $this->checkKey($key); |
25 | 25 | |
26 | - if(isset($this->cache[$key])){ |
|
26 | + if (isset($this->cache[$key])) { |
|
27 | 27 | |
28 | - if($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > time()){ |
|
28 | + if ($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > time()) { |
|
29 | 29 | return $this->cache[$key]['content']; |
30 | 30 | } |
31 | 31 |
@@ -12,13 +12,13 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\SimpleCache; |
14 | 14 | |
15 | -class APCUCache extends CacheDriverAbstract{ |
|
15 | +class APCUCache extends CacheDriverAbstract { |
|
16 | 16 | |
17 | 17 | /** @inheritdoc */ |
18 | - public function get($key, $default = null){ |
|
18 | + public function get($key, $default = null) { |
|
19 | 19 | $value = apcu_fetch($this->checkKey($key)); |
20 | 20 | |
21 | - if($value !== false){ |
|
21 | + if ($value !== false) { |
|
22 | 22 | return $value; |
23 | 23 | } |
24 | 24 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\Settings\SettingsContainerInterface; |
16 | 16 | use Redis; |
17 | 17 | |
18 | -class RedisCache extends CacheDriverAbstract{ |
|
18 | +class RedisCache extends CacheDriverAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var \Redis |
@@ -28,17 +28,17 @@ discard block |
||
28 | 28 | * @param \Redis $redis |
29 | 29 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
30 | 30 | */ |
31 | - public function __construct(Redis $redis, SettingsContainerInterface $options = null){ |
|
31 | + public function __construct(Redis $redis, SettingsContainerInterface $options = null) { |
|
32 | 32 | parent::__construct($options); |
33 | 33 | |
34 | 34 | $this->redis = $redis; |
35 | 35 | } |
36 | 36 | |
37 | 37 | /** @inheritdoc */ |
38 | - public function get($key, $default = null){ |
|
38 | + public function get($key, $default = null) { |
|
39 | 39 | $value = $this->redis->get($this->checkKey($key)); |
40 | 40 | |
41 | - if($value !== false){ |
|
41 | + if ($value !== false) { |
|
42 | 42 | return $value; |
43 | 43 | } |
44 | 44 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $key = $this->checkKey($key); |
51 | 51 | $ttl = $this->getTTL($ttl); |
52 | 52 | |
53 | - if($ttl === null){ |
|
53 | + if ($ttl === null) { |
|
54 | 54 | return $this->redis->set($key, $value); |
55 | 55 | } |
56 | 56 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $return = []; |
80 | 80 | |
81 | - foreach($keys as $key){ |
|
81 | + foreach ($keys as $key) { |
|
82 | 82 | $return[$key] = $values[$key] !== false ? $values[$key] : $default; |
83 | 83 | } |
84 | 84 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $values = $this->getData($values); |
91 | 91 | $ttl = $this->getTTL($ttl); |
92 | 92 | |
93 | - if($ttl === null){ |
|
93 | + if ($ttl === null) { |
|
94 | 94 | $this->checkKeyArray(array_keys($values)); |
95 | 95 | |
96 | 96 | return $this->redis->msetnx($values); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | $return = []; |
100 | 100 | |
101 | - foreach($values as $key => $value){ |
|
101 | + foreach ($values as $key => $value) { |
|
102 | 102 | $return[] = $this->set($key, $value, $ttl); |
103 | 103 | } |
104 | 104 |