Bugfixes and more conversions to PHP 7

This commit is contained in:
djmaze 2020-03-10 18:45:00 +01:00
parent 2cada68f41
commit 3a7ec4ecb0
100 changed files with 238 additions and 992 deletions

View file

@ -17,30 +17,11 @@ namespace MailSo\Cache;
*/
interface DriverInterface
{
/**
* @param string $sKey
* @param string $sValue
*/
public function Set($sKey, $sValue) : bool;
public function Set(string $sKey, string $sValue) : bool;
/**
* @param string $sKey
*
* @return string
*/
public function Get($sKey);
public function Get(string $sKey) : string;
/**
* @param string $sKey
*
* @return void
*/
public function Delete($sKey);
public function Delete(string $sKey) : void;
/**
* @param int $iTimeToClearInHours = 24
*
* @return bool
*/
public function GC($iTimeToClearInHours = 24);
public function GC(int $iTimeToClearInHours = 24) : bool;
}

View file

@ -23,12 +23,7 @@ class APC implements \MailSo\Cache\DriverInterface
*/
private $sKeyPrefix;
/**
* @access private
*
* @param string $sKeyPrefix = ''
*/
private function __construct($sKeyPrefix = '')
private function __construct(string $sKeyPrefix = '')
{
$this->sKeyPrefix = $sKeyPrefix;
if (!empty($this->sKeyPrefix))
@ -38,52 +33,28 @@ class APC implements \MailSo\Cache\DriverInterface
}
}
/**
* @param string $sKeyPrefix = ''
*
* @return \MailSo\Cache\Drivers\APC
*/
public static function NewInstance($sKeyPrefix = '')
public static function NewInstance(string $sKeyPrefix = '') : self
{
return new self($sKeyPrefix);
}
/**
* @param string $sKey
* @param string $sValue
*/
public function Set($sKey, $sValue) : bool
public function Set(string $sKey, string $sValue) : bool
{
return \apc_store($this->generateCachedKey($sKey), (string) $sValue);
}
/**
* @param string $sKey
*
* @return string
*/
public function Get($sKey)
public function Get(string $sKey) : string
{
$sValue = \apc_fetch($this->generateCachedKey($sKey));
return \is_string($sValue) ? $sValue : '';
}
/**
* @param string $sKey
*
* @return void
*/
public function Delete($sKey)
public function Delete(string $sKey) : void
{
\apc_delete($this->generateCachedKey($sKey));
}
/**
* @param int $iTimeToClearInHours = 24
*
* @return bool
*/
public function GC($iTimeToClearInHours = 24)
public function GC(int $iTimeToClearInHours = 24) : bool
{
if (0 === $iTimeToClearInHours)
{
@ -93,12 +64,7 @@ class APC implements \MailSo\Cache\DriverInterface
return false;
}
/**
* @param string $sKey
*
* @return string
*/
private function generateCachedKey($sKey)
private function generateCachedKey(string $sKey) : string
{
return $this->sKeyPrefix.\sha1($sKey);
}

View file

@ -28,13 +28,7 @@ class File implements \MailSo\Cache\DriverInterface
*/
private $sKeyPrefix;
/**
* @access private
*
* @param string $sCacheFolder
* @param string $sKeyPrefix = ''
*/
private function __construct($sCacheFolder, $sKeyPrefix = '')
private function __construct(string $sCacheFolder, string $sKeyPrefix = '')
{
$this->sCacheFolder = $sCacheFolder;
$this->sCacheFolder = rtrim(trim($this->sCacheFolder), '\\/').'/';
@ -51,33 +45,18 @@ class File implements \MailSo\Cache\DriverInterface
}
}
/**
* @param string $sCacheFolder
* @param string $sKeyPrefix = ''
*
* @return \MailSo\Cache\Drivers\File
*/
public static function NewInstance($sCacheFolder, $sKeyPrefix = '')
public static function NewInstance(string $sCacheFolder, string $sKeyPrefix = '') : self
{
return new self($sCacheFolder, $sKeyPrefix);
}
/**
* @param string $sKey
* @param string $sValue
*/
public function Set($sKey, $sValue) : bool
public function Set(string $sKey, string $sValue) : bool
{
$sPath = $this->generateCachedFileName($sKey, true);
return '' === $sPath ? false : false !== \file_put_contents($sPath, $sValue);
}
/**
* @param string $sKey
*
* @return string
*/
public function Get($sKey)
public function Get(string $sKey) : string
{
$sValue = '';
$sPath = $this->generateCachedFileName($sKey);
@ -89,12 +68,7 @@ class File implements \MailSo\Cache\DriverInterface
return \is_string($sValue) ? $sValue : '';
}
/**
* @param string $sKey
*
* @return void
*/
public function Delete($sKey)
public function Delete(string $sKey) : void
{
$sPath = $this->generateCachedFileName($sKey);
if ('' !== $sPath && \file_exists($sPath))
@ -103,12 +77,7 @@ class File implements \MailSo\Cache\DriverInterface
}
}
/**
* @param int $iTimeToClearInHours = 24
*
* @return bool
*/
public function GC($iTimeToClearInHours = 24)
public function GC(int $iTimeToClearInHours = 24) : bool
{
if (0 < $iTimeToClearInHours)
{
@ -119,13 +88,7 @@ class File implements \MailSo\Cache\DriverInterface
return false;
}
/**
* @param string $sKey
* @param bool $bMkDir = false
*
* @return string
*/
private function generateCachedFileName($sKey, $bMkDir = false)
private function generateCachedFileName(string $sKey, bool $bMkDir = false) : string
{
$sFilePath = '';
if (3 < \strlen($sKey))

View file

@ -43,13 +43,7 @@ class Memcache implements \MailSo\Cache\DriverInterface
*/
private $sKeyPrefix;
/**
* @param string $sHost = '127.0.0.1'
* @param int $iPost = 11211
* @param int $iExpire = 43200
* @param string $sKeyPrefix = ''
*/
private function __construct($sHost = '127.0.0.1', $iPost = 11211, $iExpire = 43200, $sKeyPrefix = '')
private function __construct(string $sHost = '127.0.0.1', int $iPost = 11211, int $iExpire = 43200, string $sKeyPrefix = '')
{
$this->sHost = $sHost;
$this->iPost = $iPost;
@ -69,45 +63,23 @@ class Memcache implements \MailSo\Cache\DriverInterface
}
}
/**
* @param string $sHost = '127.0.0.1'
* @param int $iPost = 11211
* @param int $iExpire = 43200
* @param string $sKeyPrefix = ''
*
* @return \MailSo\Cache\Drivers\APC
*/
public static function NewInstance($sHost = '127.0.0.1', $iPost = 11211, $iExpire = 43200, $sKeyPrefix = '')
public static function NewInstance(string $sHost = '127.0.0.1', int $iPost = 11211, int $iExpire = 43200, string $sKeyPrefix = '') : self
{
return new self($sHost, $iPost, $iExpire, $sKeyPrefix);
}
/**
* @param string $sKey
* @param string $sValue
*/
public function Set($sKey, $sValue) : bool
public function Set(string $sKey, string $sValue) : bool
{
return $this->oMem ? $this->oMem->set($this->generateCachedKey($sKey), $sValue, 0, $this->iExpire) : false;
}
/**
* @param string $sKey
*
* @return string
*/
public function Get($sKey)
public function Get(string $sKey) : string
{
$sValue = $this->oMem ? $this->oMem->get($this->generateCachedKey($sKey)) : '';
return \is_string($sValue) ? $sValue : '';
}
/**
* @param string $sKey
*
* @return void
*/
public function Delete($sKey)
public function Delete(string $sKey) : void
{
if ($this->oMem)
{
@ -115,12 +87,7 @@ class Memcache implements \MailSo\Cache\DriverInterface
}
}
/**
* @param int $iTimeToClearInHours = 24
*
* @return bool
*/
public function GC($iTimeToClearInHours = 24)
public function GC(int $iTimeToClearInHours = 24) : bool
{
if (0 === $iTimeToClearInHours && $this->oMem)
{
@ -130,12 +97,7 @@ class Memcache implements \MailSo\Cache\DriverInterface
return false;
}
/**
* @param string $sKey
*
* @return string
*/
private function generateCachedKey($sKey)
private function generateCachedKey(string $sKey) : string
{
return $this->sKeyPrefix.\sha1($sKey);
}

View file

@ -43,13 +43,7 @@ class Redis implements \MailSo\Cache\DriverInterface
*/
private $sKeyPrefix;
/**
* @param string $sHost = '127.0.0.1'
* @param int $iPost = 6379
* @param int $iExpire = 43200
* @param string $sKeyPrefix = ''
*/
private function __construct($sHost = '127.0.0.1', $iPost = 6379, $iExpire = 43200, $sKeyPrefix = '')
private function __construct(string $sHost = '127.0.0.1', int $iPost = 6379, int $iExpire = 43200, string $sKeyPrefix = '')
{
$this->sHost = $sHost;
$this->iPost = $iPost;
@ -85,45 +79,23 @@ class Redis implements \MailSo\Cache\DriverInterface
}
}
/**
* @param string $sHost = '127.0.0.1'
* @param int $iPost = 11211
* @param int $iExpire = 43200
* @param string $sKeyPrefix = ''
*
* @return \MailSo\Cache\Drivers\APC
*/
public static function NewInstance($sHost = '127.0.0.1', $iPost = 6379, $iExpire = 43200, $sKeyPrefix = '')
public static function NewInstance(string $sHost = '127.0.0.1', int $iPost = 6379, int $iExpire = 43200, string $sKeyPrefix = '') : self
{
return new self($sHost, $iPost, $iExpire, $sKeyPrefix);
}
/**
* @param string $sKey
* @param string $sValue
*/
public function Set($sKey, $sValue) : bool
public function Set(string $sKey, string $sValue) : bool
{
return $this->oRedis ? $this->oRedis->setex($this->generateCachedKey($sKey), $this->iExpire, $sValue) : false;
}
/**
* @param string $sKey
*
* @return string
*/
public function Get($sKey)
public function Get(string $sKey) : string
{
$sValue = $this->oRedis ? $this->oRedis->get($this->generateCachedKey($sKey)) : '';
return \is_string($sValue) ? $sValue : '';
}
/**
* @param string $sKey
*
* @return void
*/
public function Delete($sKey)
public function Delete(string $sKey) : void
{
if ($this->oRedis)
{
@ -131,12 +103,7 @@ class Redis implements \MailSo\Cache\DriverInterface
}
}
/**
* @param int $iTimeToClearInHours = 24
*
* @return bool
*/
public function GC($iTimeToClearInHours = 24)
public function GC(int $iTimeToClearInHours = 24) : bool
{
if (0 === $iTimeToClearInHours && $this->oRedis)
{
@ -146,12 +113,7 @@ class Redis implements \MailSo\Cache\DriverInterface
return false;
}
/**
* @param string $sKey
*
* @return string
*/
private function generateCachedKey($sKey)
private function generateCachedKey(string $sKey) : string
{
return $this->sKeyPrefix.\sha1($sKey);
}