Skip to content

Improve quality #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Handlers/FileSystemHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, "/");
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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";
}
}
10 changes: 8 additions & 2 deletions Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,14 +18,19 @@ 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)
{

if (!class_exists("Memcached")) {
throw new CacheException("The PHP package \"Memcached\" is missing!", 1);
}


$this->handler = new Memcached();
if (is_string($host)) {
$this->servers[] = [$host, $port, $weight];
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions Interfaces/CacheItemPoolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function commit(): bool;

/**
* Get all keys
*
* @return array
*/
public function getAllKeys(): array;
Expand Down