From aeb5d14b0d17f6ab464bed9ba546fab28bb5efd3 Mon Sep 17 00:00:00 2001 From: hatsu Date: Tue, 21 Jul 2026 15:29:06 +0500 Subject: [PATCH] feat: add support psr/simple-cache v3 for laravel 12 --- composer.json | 2 +- src/Helpers/ArrayFileCache.php | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index f96f143..7f4be9b 100755 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", "spiral/attributes": "^2.8|^3.0", "tochka-developers/jsonrpc-annotations": "^1.1", - "psr/simple-cache": "^1.0|^2.0" + "psr/simple-cache": "^1.0|^2.0|^3.0" }, "require-dev": { "roave/security-advisories": "dev-latest", diff --git a/src/Helpers/ArrayFileCache.php b/src/Helpers/ArrayFileCache.php index 3d35d7b..9c18f47 100644 --- a/src/Helpers/ArrayFileCache.php +++ b/src/Helpers/ArrayFileCache.php @@ -35,38 +35,38 @@ protected function loadAllData(): void } } - protected function saveAllData(): void + protected function saveAllData(): bool { if (!is_dir($this->cachePath) && !mkdir($this->cachePath) && !is_dir($this->cachePath)) { throw new \RuntimeException(sprintf('Directory "%s" was not created', $this->cachePath)); } - file_put_contents($this->getCacheFilePath(), 'data, true) . ';' . PHP_EOL); + return (bool) file_put_contents($this->getCacheFilePath(), 'data, true) . ';' . PHP_EOL); } - public function get($key, $default = null) + public function get($key, $default = null): mixed { $this->loadAllData(); return array_key_exists($key, $this->data) ? $this->data[$key] : $default; } - public function set($key, $value, $ttl = null) + public function set($key, $value, $ttl = null): bool { $this->loadAllData(); $this->data[$key] = $value; - $this->saveAllData(); + return $this->saveAllData(); } - public function delete($key) + public function delete($key): bool { $this->loadAllData(); unset($this->data[$key]); - $this->saveAllData(); + return $this->saveAllData(); } public function getMultiple($keys, $default = null): array @@ -81,16 +81,16 @@ public function getMultiple($keys, $default = null): array return $result; } - public function setMultiple($values, $ttl = null) + public function setMultiple($values, $ttl = null): bool { $this->loadAllData(); - $this->data = array_merge($this->data, $values); + $this->data = array_merge($this->data, (array) $values); - $this->saveAllData(); + return $this->saveAllData(); } - public function deleteMultiple($keys) + public function deleteMultiple($keys): bool { $this->loadAllData(); @@ -98,10 +98,10 @@ public function deleteMultiple($keys) unset($this->data[$key]); } - $this->saveAllData(); + return $this->saveAllData(); } - public function clear(): void + public function clear(): bool { $this->data = []; @@ -109,6 +109,8 @@ public function clear(): void if (file_exists($filePath)) { unlink($filePath); } + + return true; } public function has($key): bool