@@ -12,10 +12,10 @@ |
||
| 12 | 12 | |
| 13 | 13 | namespace chillerlan\SimpleCache\Drivers; |
| 14 | 14 | |
| 15 | -class APCUDriver extends CacheDriverAbstract{ |
|
| 15 | +class APCUDriver extends CacheDriverAbstract { |
|
| 16 | 16 | |
| 17 | 17 | /** @inheritdoc */ |
| 18 | - public function get(string $key, $default = null){ |
|
| 18 | + public function get(string $key, $default = null) { |
|
| 19 | 19 | $value = apcu_fetch($key); |
| 20 | 20 | |
| 21 | 21 | return $value ?: $default; |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | namespace chillerlan\SimpleCache\Drivers; |
| 14 | 14 | |
| 15 | -class MemoryCacheDriver extends CacheDriverAbstract{ |
|
| 15 | +class MemoryCacheDriver extends CacheDriverAbstract { |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @var array |
@@ -20,11 +20,11 @@ discard block |
||
| 20 | 20 | protected $cache = []; |
| 21 | 21 | |
| 22 | 22 | /** @inheritdoc */ |
| 23 | - public function get(string $key, $default = null){ |
|
| 23 | + public function get(string $key, $default = null) { |
|
| 24 | 24 | |
| 25 | - if(isset($this->cache[$key])){ |
|
| 25 | + if (isset($this->cache[$key])) { |
|
| 26 | 26 | |
| 27 | - if($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > time()){ |
|
| 27 | + if ($this->cache[$key]['ttl'] === null || $this->cache[$key]['ttl'] > time()) { |
|
| 28 | 28 | return $this->cache[$key]['content']; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | |
| 13 | 13 | namespace chillerlan\SimpleCache; |
| 14 | 14 | |
| 15 | -trait CacheOptionsTrait{ |
|
| 15 | +trait CacheOptionsTrait { |
|
| 16 | 16 | |
| 17 | 17 | protected $filestorage = ''; |
| 18 | 18 | protected $cachekey = '_session_cache'; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | use chillerlan\Traits\ImmutableSettingsInterface; |
| 17 | 17 | use stdClass; |
| 18 | 18 | |
| 19 | -class FileCacheDriver extends CacheDriverAbstract{ |
|
| 19 | +class FileCacheDriver extends CacheDriverAbstract { |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * @var string |
@@ -30,19 +30,19 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @throws \chillerlan\SimpleCache\CacheException |
| 32 | 32 | */ |
| 33 | - public function __construct(ImmutableSettingsInterface $options = null){ |
|
| 33 | + public function __construct(ImmutableSettingsInterface $options = null) { |
|
| 34 | 34 | parent::__construct($options); |
| 35 | 35 | |
| 36 | 36 | $this->cachedir = $this->options->filestorage; |
| 37 | 37 | |
| 38 | - if(!is_dir($this->cachedir)){ |
|
| 38 | + if (!is_dir($this->cachedir)) { |
|
| 39 | 39 | $msg = 'invalid cachedir "'.$this->cachedir.'"'; |
| 40 | 40 | |
| 41 | 41 | $this->logger->error($msg); |
| 42 | 42 | throw new CacheException($msg); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if(!is_writable($this->cachedir)){ |
|
| 45 | + if (!is_writable($this->cachedir)) { |
|
| 46 | 46 | $msg = 'cachedir is read-only. permissions?'; |
| 47 | 47 | |
| 48 | 48 | $this->logger->error($msg); |
@@ -52,16 +52,16 @@ discard block |
||
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | /** @inheritdoc */ |
| 55 | - public function get(string $key, $default = null){ |
|
| 55 | + public function get(string $key, $default = null) { |
|
| 56 | 56 | $filename = $this->filename($key); |
| 57 | 57 | |
| 58 | - if(is_file($filename)){ |
|
| 58 | + if (is_file($filename)) { |
|
| 59 | 59 | $content = file_get_contents($filename); |
| 60 | 60 | |
| 61 | - if(!empty($content)){ |
|
| 61 | + if (!empty($content)) { |
|
| 62 | 62 | $data = unserialize($content); |
| 63 | 63 | |
| 64 | - if($data->ttl === null || $data->ttl > time()){ |
|
| 64 | + if ($data->ttl === null || $data->ttl > time()) { |
|
| 65 | 65 | return $data->content; |
| 66 | 66 | } |
| 67 | 67 | |
@@ -80,13 +80,13 @@ discard block |
||
| 80 | 80 | $data->ttl = null; |
| 81 | 81 | $data->content = $value; |
| 82 | 82 | |
| 83 | - if($ttl !== null){ |
|
| 83 | + if ($ttl !== null) { |
|
| 84 | 84 | $data->ttl = time() + $ttl; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | file_put_contents($filename, serialize($data)); |
| 88 | 88 | |
| 89 | - if(is_file($filename)){ |
|
| 89 | + if (is_file($filename)) { |
|
| 90 | 90 | return true; |
| 91 | 91 | } |
| 92 | 92 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | public function delete(string $key):bool{ |
| 98 | 98 | $filename = $this->filename($key); |
| 99 | 99 | |
| 100 | - if(is_file($filename)){ |
|
| 100 | + if (is_file($filename)) { |
|
| 101 | 101 | return unlink($filename); |
| 102 | 102 | } |
| 103 | 103 | |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | public function clear():bool{ |
| 109 | 109 | $dir = scandir($this->cachedir); |
| 110 | 110 | |
| 111 | - if(is_array($dir) && !empty($dir)){ |
|
| 111 | + if (is_array($dir) && !empty($dir)) { |
|
| 112 | 112 | $return = []; |
| 113 | 113 | |
| 114 | - foreach($dir as $file){ |
|
| 114 | + foreach ($dir as $file) { |
|
| 115 | 115 | $path = $this->cachedir.DIRECTORY_SEPARATOR.$file; |
| 116 | 116 | |
| 117 | - if(is_file($path) && strlen($file) === 64){ |
|
| 117 | + if (is_file($path) && strlen($file) === 64) { |
|
| 118 | 118 | $return[] = unlink($path); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | use chillerlan\Traits\ImmutableSettingsInterface; |
| 16 | 16 | use Redis; |
| 17 | 17 | |
| 18 | -class RedisDriver extends CacheDriverAbstract{ |
|
| 18 | +class RedisDriver extends CacheDriverAbstract { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @var \Redis |
@@ -28,14 +28,14 @@ discard block |
||
| 28 | 28 | * @param \Redis $redis |
| 29 | 29 | * @param \chillerlan\Traits\ImmutableSettingsInterface|null $options |
| 30 | 30 | */ |
| 31 | - public function __construct(Redis $redis, ImmutableSettingsInterface $options = null){ |
|
| 31 | + public function __construct(Redis $redis, ImmutableSettingsInterface $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(string $key, $default = null){ |
|
| 38 | + public function get(string $key, $default = null) { |
|
| 39 | 39 | $value = $this->redis->get($key); |
| 40 | 40 | |
| 41 | 41 | return $value ? $value : $default; |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | /** @inheritdoc */ |
| 45 | 45 | public function set(string $key, $value, int $ttl = null):bool{ |
| 46 | 46 | |
| 47 | - if($ttl === null){ |
|
| 47 | + if ($ttl === null) { |
|
| 48 | 48 | return $this->redis->set($key, $value); |
| 49 | 49 | } |
| 50 | 50 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | $return = []; |
| 70 | 70 | |
| 71 | - foreach($keys as $key){ |
|
| 71 | + foreach ($keys as $key) { |
|
| 72 | 72 | $return[$key] = $values[$key] !== false ? $values[$key] : $default; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -78,13 +78,13 @@ discard block |
||
| 78 | 78 | /** @inheritdoc */ |
| 79 | 79 | public function setMultiple(array $values, int $ttl = null):bool{ |
| 80 | 80 | |
| 81 | - if($ttl === null){ |
|
| 81 | + if ($ttl === null) { |
|
| 82 | 82 | return $this->redis->msetnx($values); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | $return = []; |
| 86 | 86 | |
| 87 | - foreach($values as $key => $value){ |
|
| 87 | + foreach ($values as $key => $value) { |
|
| 88 | 88 | $return[] = $this->set($key, $value, $ttl); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @param \chillerlan\Traits\ImmutableSettingsInterface|null $options |
| 31 | 31 | */ |
| 32 | - public function __construct(ImmutableSettingsInterface $options = null){ |
|
| 32 | + public function __construct(ImmutableSettingsInterface $options = null) { |
|
| 33 | 33 | $this->options = $options ?? new CacheOptions; |
| 34 | 34 | $this->logger = new NullLogger; // logger will be set from the Cache instance |
| 35 | 35 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | public function getMultiple(array $keys, $default = null):array{ |
| 44 | 44 | $data = []; |
| 45 | 45 | |
| 46 | - foreach($keys as $key){ |
|
| 46 | + foreach ($keys as $key) { |
|
| 47 | 47 | $data[$key] = $this->get($key, $default); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | public function setMultiple(array $values, int $ttl = null):bool{ |
| 55 | 55 | $return = []; |
| 56 | 56 | |
| 57 | - foreach($values as $key => $value){ |
|
| 57 | + foreach ($values as $key => $value) { |
|
| 58 | 58 | $return[] = $this->set($key, $value, $ttl); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | public function deleteMultiple(array $keys):bool{ |
| 66 | 66 | $return = []; |
| 67 | 67 | |
| 68 | - foreach($keys as $key){ |
|
| 68 | + foreach ($keys as $key) { |
|
| 69 | 69 | $return[] = $this->delete($key); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | protected function checkReturn(array $booleans):bool{ |
| 81 | 81 | |
| 82 | - foreach($booleans as $bool){ |
|
| 82 | + foreach ($booleans as $bool) { |
|
| 83 | 83 | |
| 84 | - if(!(bool)$bool){ |
|
| 84 | + if (!(bool)$bool) { |
|
| 85 | 85 | return false; // @codeCoverageIgnore |
| 86 | 86 | } |
| 87 | 87 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | use chillerlan\SimpleCache\CacheException; |
| 16 | 16 | use chillerlan\Traits\ImmutableSettingsInterface; |
| 17 | 17 | |
| 18 | -class SessionCacheDriver extends CacheDriverAbstract{ |
|
| 18 | +class SessionCacheDriver extends CacheDriverAbstract { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @var string |
@@ -29,12 +29,12 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @throws \chillerlan\SimpleCache\CacheException |
| 31 | 31 | */ |
| 32 | - public function __construct(ImmutableSettingsInterface $options = null){ |
|
| 32 | + public function __construct(ImmutableSettingsInterface $options = null) { |
|
| 33 | 33 | parent::__construct($options); |
| 34 | 34 | |
| 35 | 35 | $this->key = $this->options->cachekey; |
| 36 | 36 | |
| 37 | - if(!is_string($this->key) || empty($this->key)){ |
|
| 37 | + if (!is_string($this->key) || empty($this->key)) { |
|
| 38 | 38 | $msg = 'invalid session cache key'; |
| 39 | 39 | |
| 40 | 40 | $this->logger->error($msg); |
@@ -46,11 +46,11 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** @inheritdoc */ |
| 49 | - public function get(string $key, $default = null){ |
|
| 49 | + public function get(string $key, $default = null) { |
|
| 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 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | use chillerlan\Traits\ImmutableSettingsInterface; |
| 17 | 17 | use Memcached; |
| 18 | 18 | |
| 19 | -class MemcachedDriver extends CacheDriverAbstract{ |
|
| 19 | +class MemcachedDriver extends CacheDriverAbstract { |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * @var \Memcached |
@@ -31,12 +31,12 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @throws \chillerlan\SimpleCache\CacheException |
| 33 | 33 | */ |
| 34 | - public function __construct(Memcached $memcached, ImmutableSettingsInterface $options = null){ |
|
| 34 | + public function __construct(Memcached $memcached, ImmutableSettingsInterface $options = null) { |
|
| 35 | 35 | parent::__construct($options); |
| 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,7 +46,7 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** @inheritdoc */ |
| 49 | - public function get(string $key, $default = null){ |
|
| 49 | + public function get(string $key, $default = null) { |
|
| 50 | 50 | $value = $this->memcached->get($key); |
| 51 | 51 | |
| 52 | 52 | return $value ?: $default; |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $values = $this->memcached->getMulti($keys); |
| 73 | 73 | $return = []; |
| 74 | 74 | |
| 75 | - foreach($keys as $key){ |
|
| 75 | + foreach ($keys as $key) { |
|
| 76 | 76 | $return[$key] = $values[$key] ?? $default; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | /** |
| 16 | 16 | * @method setLogger(\Psr\Log\LoggerInterface $logger) |
| 17 | 17 | */ |
| 18 | -interface CacheDriverInterface{ |
|
| 18 | +interface CacheDriverInterface { |
|
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * @param string $key |