diff options
| author | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2024-05-15 19:10:49 +0000 |
|---|---|---|
| committer | Jan-Hendrik Willms <tleilax+studip@gmail.com> | 2024-05-15 19:10:49 +0000 |
| commit | 7fbf01fafcbc022831e9717a892a084b3c6e6e59 (patch) | |
| tree | 7520a5af1ba8bffc5664544fd3c76cdff4c33de4 /lib | |
| parent | eb4f3bba75580ee1bd04e2b6677028ff28e6a1af (diff) | |
update psr/cache to 3.0.0 and adjust everything necessary, fixes #4152
Closes #4152
Merge request studip/studip!2992
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/classes/cache/Cache.class.php | 21 | ||||
| -rw-r--r-- | lib/classes/cache/DbCache.class.php | 7 | ||||
| -rw-r--r-- | lib/classes/cache/FileCache.class.php | 7 | ||||
| -rw-r--r-- | lib/classes/cache/Item.class.php | 13 | ||||
| -rw-r--r-- | lib/classes/cache/MemcachedCache.class.php | 6 | ||||
| -rw-r--r-- | lib/classes/cache/MemoryCache.class.php | 12 | ||||
| -rw-r--r-- | lib/classes/cache/Proxy.class.php | 21 | ||||
| -rw-r--r-- | lib/classes/cache/RedisCache.class.php | 6 | ||||
| -rw-r--r-- | lib/classes/cache/Wrapper.class.php | 6 |
9 files changed, 54 insertions, 45 deletions
diff --git a/lib/classes/cache/Cache.class.php b/lib/classes/cache/Cache.class.php index 366945d..be703cf 100644 --- a/lib/classes/cache/Cache.class.php +++ b/lib/classes/cache/Cache.class.php @@ -72,12 +72,12 @@ abstract class Cache implements CacheItemPoolInterface /** * @see CacheItemPoolInterface::getItem */ - abstract public function getItem($key); + abstract public function getItem(string $key): CacheItemInterface; /** * @see CacheItemPoolInterface::hasItem */ - abstract public function hasItem($key); + abstract public function hasItem(string $key): bool; /** * @var array An array of deferred items that shall be saved only @@ -149,7 +149,7 @@ abstract class Cache implements CacheItemPoolInterface /** * @see CacheItemPoolInterface::getItems */ - public function getItems(array $keys = []) + public function getItems(array $keys = []): iterable { $items = []; foreach ($keys as $key) { @@ -164,45 +164,50 @@ abstract class Cache implements CacheItemPoolInterface /** * @see CacheItemPoolInterface::clear */ - public function clear() + public function clear(): bool { $this->deferred_items = []; $this->flush(); + return true; } /** * @see CacheItemPoolInterface::deleteItem */ - public function deleteItem($key) + public function deleteItem($key): bool { $this->expire($key); + return true; } /** * @see CacheItemPoolInterface::deleteItems */ - public function deleteItems(array $keys) + public function deleteItems(array $keys): bool { foreach ($keys as $key) { $this->expire($key); } + return true; } /** * @see CacheItemPoolInterface::saveDeferred */ - public function saveDeferred(CacheItemInterface $item) + public function saveDeferred(CacheItemInterface $item): bool { $this->deferred_items[] = $item; + return true; } /** * @see CacheItemPoolInterface::commit */ - public function commit() + public function commit(): bool { foreach ($this->deferred_items as $item) { $this->save($item); } + return true; } } diff --git a/lib/classes/cache/DbCache.class.php b/lib/classes/cache/DbCache.class.php index 3361af0..c7abef2 100644 --- a/lib/classes/cache/DbCache.class.php +++ b/lib/classes/cache/DbCache.class.php @@ -3,6 +3,7 @@ namespace Studip\Cache; use DBManager; +use Psr\Cache\CacheItemInterface; /** * StudipCache implementation using database table @@ -88,7 +89,7 @@ class DbCache extends Cache /** * @inheritDoc */ - public function getItem($key) + public function getItem(string $key): CacheItemInterface { $query = "SELECT `content`, `expires` FROM `cache` @@ -114,7 +115,7 @@ class DbCache extends Cache /** * @inheritDoc */ - public function hasItem($key) + public function hasItem(string $key): bool { $query = "SELECT 1 FROM `cache` @@ -126,7 +127,7 @@ class DbCache extends Cache /** * @inheritDoc */ - public function save(\Psr\Cache\CacheItemInterface $item) + public function save(CacheItemInterface $item): bool { $expiration = $this->getExpiration($item); if ($expiration < 1) { diff --git a/lib/classes/cache/FileCache.class.php b/lib/classes/cache/FileCache.class.php index e94395a..d760f08 100644 --- a/lib/classes/cache/FileCache.class.php +++ b/lib/classes/cache/FileCache.class.php @@ -4,6 +4,7 @@ namespace Studip\Cache; use Config; use Exception; +use Psr\Cache\CacheItemInterface; /** * Cache implementation using files @@ -223,7 +224,7 @@ class FileCache extends Cache /** * @inheritDoc */ - public function getItem($key) + public function getItem(string $key): CacheItemInterface { $real_key = $this->getCacheKey($key); @@ -251,7 +252,7 @@ class FileCache extends Cache /** * @inheritDoc */ - public function hasItem($key) + public function hasItem(string $key): bool { $real_key = $this->getCacheKey($key); $file_data = $this->check($real_key); @@ -261,7 +262,7 @@ class FileCache extends Cache /** * @inheritDoc */ - public function save(\Psr\Cache\CacheItemInterface $item) + public function save(CacheItemInterface $item): bool { $expiration = $this->getExpiration($item); if ($expiration < 1) { diff --git a/lib/classes/cache/Item.class.php b/lib/classes/cache/Item.class.php index 1a09f1d..4e83d4d 100644 --- a/lib/classes/cache/Item.class.php +++ b/lib/classes/cache/Item.class.php @@ -71,7 +71,7 @@ class Item implements CacheItemInterface /** * @inheritDoc */ - public function getKey() + public function getKey(): string { return $this->key; } @@ -79,7 +79,7 @@ class Item implements CacheItemInterface /** * @inheritDoc */ - public function get() + public function get(): mixed { return $this->value; } @@ -87,7 +87,7 @@ class Item implements CacheItemInterface /** * @inheritDoc */ - public function isHit() + public function isHit(): bool { return $this->cache_hit; } @@ -95,15 +95,16 @@ class Item implements CacheItemInterface /** * @inheritDoc */ - public function set($value) + public function set($value): static { $this->value = $value; + return $this; } /** * @inheritDoc */ - public function expiresAt($expiration) + public function expiresAt($expiration): static { $this->expiration = $expiration; return $this; @@ -112,7 +113,7 @@ class Item implements CacheItemInterface /** * @inheritDoc */ - public function expiresAfter($time) + public function expiresAfter($time): static { $this->expiration = new DateTime(); if ($time instanceof DateInterval) { diff --git a/lib/classes/cache/MemcachedCache.class.php b/lib/classes/cache/MemcachedCache.class.php index 5d9033b..1c4b685 100644 --- a/lib/classes/cache/MemcachedCache.class.php +++ b/lib/classes/cache/MemcachedCache.class.php @@ -114,7 +114,7 @@ class MemcachedCache extends Cache /** * @inheritDoc */ - public function getItem($key) + public function getItem(string $key): CacheItemInterface { $item = new Item($key); $value = $this->memcache->get($this->getCacheKey($key)); @@ -129,7 +129,7 @@ class MemcachedCache extends Cache /** * @inheritDoc */ - public function hasItem($key) + public function hasItem(string $key): bool { return $this->memcache->checkKey($this->getCacheKey($key)); } @@ -137,7 +137,7 @@ class MemcachedCache extends Cache /** * @inheritDoc */ - public function save(CacheItemInterface $item) + public function save(CacheItemInterface $item): bool { $expiration = $this->getExpiration($item); if ($expiration < 1) { diff --git a/lib/classes/cache/MemoryCache.class.php b/lib/classes/cache/MemoryCache.class.php index 93f6bbd..7c00753 100644 --- a/lib/classes/cache/MemoryCache.class.php +++ b/lib/classes/cache/MemoryCache.class.php @@ -19,11 +19,11 @@ class MemoryCache extends Cache /** * Expires just a single key. * - * @param string the key + * @param string $arg the key */ - public function expire($key) + public function expire($arg) { - unset($this->memory_cache[$key]); + unset($this->memory_cache[$arg]); } /** @@ -52,7 +52,7 @@ class MemoryCache extends Cache /** * @inheritDoc */ - public function getItem($key) + public function getItem(string $key): CacheItemInterface { $item = new Item($key); if (!isset($this->memory_cache[$key])) { @@ -75,7 +75,7 @@ class MemoryCache extends Cache /** * @inheritDoc */ - public function hasItem($key) + public function hasItem(string $key): bool { return isset($this->memory_cache[$key]) && $this->memory_cache[$key]['expires'] < time(); @@ -84,7 +84,7 @@ class MemoryCache extends Cache /** * @inheritDoc */ - public function save(CacheItemInterface $item) + public function save(CacheItemInterface $item): bool { $expiration = $this->getExpiration($item); diff --git a/lib/classes/cache/Proxy.class.php b/lib/classes/cache/Proxy.class.php index 6791fb7..fef034d 100644 --- a/lib/classes/cache/Proxy.class.php +++ b/lib/classes/cache/Proxy.class.php @@ -2,6 +2,7 @@ namespace Studip\Cache; +use Psr\Cache\CacheItemInterface; use StudipCacheOperation; /** @@ -39,20 +40,20 @@ class Proxy extends Cache /** * Expires just a single key. * - * @param string $key The item's key + * @param string $arg The item's key */ - public function expire($key) + public function expire($arg) { if (in_array('expire', $this->proxy_these)) { try { - $operation = new StudipCacheOperation([$key, 'expire']); + $operation = new StudipCacheOperation([$arg, 'expire']); $operation->parameters = serialize([]); $operation->store(); - } catch (\Exception $e) { + } catch (\Exception) { } } - return $this->actual_cache->expire($key); + return $this->actual_cache->expire($arg); } /** @@ -65,7 +66,7 @@ class Proxy extends Cache $operation = new StudipCacheOperation(['', 'flush']); $operation->parameters = serialize([]); $operation->store(); - } catch (\Exception $e) { + } catch (\Exception) { } } @@ -90,7 +91,7 @@ class Proxy extends Cache /** * @inheritDoc */ - public function getItem($key) + public function getItem(string $key): CacheItemInterface { return $this->actual_cache->getItem($key); } @@ -98,7 +99,7 @@ class Proxy extends Cache /** * @inheritDoc */ - public function hasItem($key) + public function hasItem(string $key): bool { return $this->actual_cache->hasItem($key); } @@ -106,14 +107,14 @@ class Proxy extends Cache /** * @inheritDoc */ - public function save(\Psr\Cache\CacheItemInterface $item) + public function save(CacheItemInterface $item): bool { if (in_array('save', $this->proxy_these)) { try { $operation = new StudipCacheOperation([$item->getKey(), 'save']); $operation->parameters = serialize([$item]); $operation->store(); - } catch (\Exception $e) { + } catch (\Exception) { } } diff --git a/lib/classes/cache/RedisCache.class.php b/lib/classes/cache/RedisCache.class.php index 9ea8711..a78f751 100644 --- a/lib/classes/cache/RedisCache.class.php +++ b/lib/classes/cache/RedisCache.class.php @@ -156,7 +156,7 @@ class RedisCache extends Cache /** * @inheritDoc */ - public function getItem($key) + public function getItem(string $key): CacheItemInterface { $item = new Item($key); $real_key = $this->getCacheKey($key); @@ -175,7 +175,7 @@ class RedisCache extends Cache /** * @inheritDoc */ - public function hasItem($key) + public function hasItem(string $key): bool { $real_key = $this->getCacheKey($key); return $this->redis->get($real_key) !== null; @@ -184,7 +184,7 @@ class RedisCache extends Cache /** * @inheritDoc */ - public function save(CacheItemInterface $item) + public function save(CacheItemInterface $item): bool { $expiration = $this->getExpiration($item); if ($expiration < 1) { diff --git a/lib/classes/cache/Wrapper.class.php b/lib/classes/cache/Wrapper.class.php index 7448932..4e6342c 100644 --- a/lib/classes/cache/Wrapper.class.php +++ b/lib/classes/cache/Wrapper.class.php @@ -59,7 +59,7 @@ class Wrapper extends Cache /** * @inheritDoc */ - public function getItem($key) + public function getItem(string $key): CacheItemInterface { $cached = $this->memory_cache->getItem($key); if ($cached->isHit()) { @@ -76,7 +76,7 @@ class Wrapper extends Cache /** * @inheritDoc */ - public function hasItem($key) + public function hasItem(string $key): bool { return $this->actual_cache->hasItem($key); } @@ -84,7 +84,7 @@ class Wrapper extends Cache /** * @inheritDoc */ - public function save(CacheItemInterface $item) + public function save(CacheItemInterface $item): bool { if ($this->actual_cache->save($item)) { return $this->memory_cache->save($item); |
