diff --git a/Handlers/FileSystemHandler.php b/Handlers/FileSystemHandler.php index 63d7f5c..9149c46 100755 --- a/Handlers/FileSystemHandler.php +++ b/Handlers/FileSystemHandler.php @@ -8,8 +8,12 @@ class FileSystemHandler extends CachePoolAbstract { - private $cacheDirectory; + private string $cacheDirectory; + /** + * Init the File system handler + * @param string $cacheDirectory + */ public function __construct(string $cacheDirectory) { $this->cacheDirectory = rtrim($cacheDirectory, "/"); @@ -27,7 +31,7 @@ protected function setItem(CacheItemInterface $item): void if (is_file($path)) { if (!is_readable($path)) { - throw new CacheException("The cache file ({$path}) is not readable!", 1); + throw new CacheException("The cache file ($path) is not readable!", 1); } $data = file_get_contents($path); @@ -45,7 +49,7 @@ protected function setItem(CacheItemInterface $item): void public function getAllKeys(): array { $new = array(); - $files = glob("{$this->cacheDirectory}/*.cache"); + $files = glob("$this->cacheDirectory/*.cache"); foreach ($files as $file) { $file = basename($file); $exp = explode(".", $file); @@ -61,7 +65,7 @@ public function getAllKeys(): array */ protected function setClear(): bool { - $files = glob("{$this->cacheDirectory}/*.cache"); + $files = glob("$this->cacheDirectory/*.cache"); foreach ($files as $file) { if (is_file($file) && is_writable($file)) { unlink($file); @@ -95,7 +99,7 @@ protected function setDelete($key): bool protected function setSave(CacheItemInterface $item): bool { if (!is_dir($this->cacheDirectory)) { - throw new CacheException("The cache directory is not a directory: {$this->cacheDirectory}", 1); + throw new CacheException("The cache directory is not a directory: $this->cacheDirectory", 1); } if (!is_writeable($this->cacheDirectory)) { throw new CacheException("The cache filesystem directory is not writable!", 1); @@ -118,6 +122,6 @@ protected function setSave(CacheItemInterface $item): bool */ protected function getCacheFilePath(string $key): string { - return "{$this->cacheDirectory}/{$key}.cache"; + return "$this->cacheDirectory/$key.cache"; } } diff --git a/Handlers/MemcachedHandler.php b/Handlers/MemcachedHandler.php index 16a9ed5..a5fb20a 100755 --- a/Handlers/MemcachedHandler.php +++ b/Handlers/MemcachedHandler.php @@ -5,6 +5,7 @@ use MaplePHP\Cache\Interfaces\CacheItemInterface; use MaplePHP\Cache\Exceptions\CacheException; use MaplePHP\Cache\CachePoolAbstract; +use MaplePHP\DTO\Format\Arr; use Memcached; class MemcachedHandler extends CachePoolAbstract @@ -17,6 +18,12 @@ class MemcachedHandler extends CachePoolAbstract private $servers = array(); private $stats; + /** + * Init the memcache handler + * @param string|array $host + * @param int|null $port + * @param int $weight + */ public function __construct(string|array $host, ?int $port = null, int $weight = 0) { @@ -24,7 +31,6 @@ public function __construct(string|array $host, ?int $port = null, int $weight = throw new CacheException("The PHP package \"Memcached\" is missing!", 1); } - $this->handler = new Memcached(); if (is_string($host)) { $this->servers[] = [$host, $port, $weight]; @@ -36,7 +42,7 @@ public function __construct(string|array $host, ?int $port = null, int $weight = /** * Get all set keys - * e.g. Some key may have already expired and wont be removed before @mem->get("KEY_NAME") has been called! + * e.g. Some key may have already expired and won't be removed before @mem->get("KEY_NAME") has been called! * @return array */ public function getAllKeys(): array diff --git a/Interfaces/CacheItemPoolInterface.php b/Interfaces/CacheItemPoolInterface.php index 06086eb..2b01c40 100755 --- a/Interfaces/CacheItemPoolInterface.php +++ b/Interfaces/CacheItemPoolInterface.php @@ -139,6 +139,7 @@ public function commit(): bool; /** * Get all keys + * * @return array */ public function getAllKeys(): array;