mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 01:38:41 +00:00
bug fixes
This commit is contained in:
parent
9d6e431c3b
commit
d209c16831
|
|
@ -209,7 +209,7 @@ class Account implements \JsonSerializable, ArrayableInterface
|
|||
/**
|
||||
* User has group.
|
||||
*
|
||||
* @param int $group Group id
|
||||
* @param int $id Group id
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
|
|||
|
|
@ -104,11 +104,11 @@ abstract class StatusAbstract
|
|||
}
|
||||
|
||||
if (!\is_file($destRoutePath)) {
|
||||
throw new PathException($destRoutePath);
|
||||
throw new PathException($destRoutePath); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if (!\is_writable($destRoutePath)) {
|
||||
throw new PermissionException($destRoutePath);
|
||||
throw new PermissionException($destRoutePath); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
|
|
|
|||
|
|
@ -28,6 +28,14 @@ use phpOMS\DataStorage\Cache\Exception\InvalidConnectionConfigException;
|
|||
*/
|
||||
final class MemCached extends ConnectionAbstract
|
||||
{
|
||||
/**
|
||||
* Delimiter for cache meta data
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private const DELIM = '$';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -90,7 +98,7 @@ final class MemCached extends ConnectionAbstract
|
|||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
$this->con->set($key, $value, \max($expire, 0));
|
||||
$this->con->set((string) $key, $value, \max($expire, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -106,7 +114,7 @@ final class MemCached extends ConnectionAbstract
|
|||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
return $this->con->add($key, $value, \max($expire, 0));
|
||||
return $this->con->add((string) $key, $value, \max($expire, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -118,7 +126,7 @@ final class MemCached extends ConnectionAbstract
|
|||
return null;
|
||||
}
|
||||
|
||||
$result = $this->con->get($key);
|
||||
$result = $this->con->get((string) $key);
|
||||
|
||||
if ($this->con->getResultCode() !== \Memcached::RES_SUCCESS) {
|
||||
return null;
|
||||
|
|
@ -136,7 +144,7 @@ final class MemCached extends ConnectionAbstract
|
|||
return false;
|
||||
}
|
||||
|
||||
return $this->con->delete($key);
|
||||
return $this->con->delete((string) $key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -148,7 +156,7 @@ final class MemCached extends ConnectionAbstract
|
|||
return false;
|
||||
}
|
||||
|
||||
return $this->con->get($key) !== false;
|
||||
return $this->con->get((string) $key) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -156,7 +164,7 @@ final class MemCached extends ConnectionAbstract
|
|||
*/
|
||||
public function increment(int | string $key, int $value = 1) : bool
|
||||
{
|
||||
$this->con->increment($key, $value);
|
||||
$this->con->increment((string) $key, $value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -166,7 +174,7 @@ final class MemCached extends ConnectionAbstract
|
|||
*/
|
||||
public function decrement(int | string $key, int $value = 1) : bool
|
||||
{
|
||||
$this->con->decrement($key, $value);
|
||||
$this->con->decrement((string) $key, $value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -176,9 +184,9 @@ final class MemCached extends ConnectionAbstract
|
|||
*/
|
||||
public function rename(int | string $old, int | string $new, int $expire = -1) : void
|
||||
{
|
||||
$value = $this->get($old);
|
||||
$this->set($new, $value, $expire);
|
||||
$this->delete($old);
|
||||
$value = $this->get((string) $old);
|
||||
$this->set((string) $new, $value, $expire);
|
||||
$this->delete((string) $old);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -209,6 +217,61 @@ final class MemCached extends ConnectionAbstract
|
|||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse cached value
|
||||
*
|
||||
* @param int $type Cached value type
|
||||
* @param string $raw Cached value
|
||||
* @param int $expireEnd Value end position
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function reverseValue(int $type, string $raw, int $expireEnd) : mixed
|
||||
{
|
||||
switch ($type) {
|
||||
case CacheValueType::_INT:
|
||||
return (int) \substr($raw, $expireEnd + 1);
|
||||
case CacheValueType::_FLOAT:
|
||||
return (float) \substr($raw, $expireEnd + 1);
|
||||
case CacheValueType::_BOOL:
|
||||
return (bool) \substr($raw, $expireEnd + 1);
|
||||
case CacheValueType::_STRING:
|
||||
return \substr($raw, $expireEnd + 1);
|
||||
case CacheValueType::_ARRAY:
|
||||
$array = \substr($raw, $expireEnd + 1);
|
||||
return \json_decode($array === false ? '[]' : $array, true);
|
||||
case CacheValueType::_NULL:
|
||||
return null;
|
||||
case CacheValueType::_JSONSERIALIZABLE:
|
||||
$namespaceStart = (int) \strpos($raw, self::DELIM, $expireEnd);
|
||||
$namespaceEnd = (int) \strpos($raw, self::DELIM, $namespaceStart + 1);
|
||||
$namespace = \substr($raw, $namespaceStart + 1, $namespaceEnd - $namespaceStart - 1);
|
||||
|
||||
if ($namespace === false) {
|
||||
return null; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return new $namespace();
|
||||
case CacheValueType::_SERIALIZABLE:
|
||||
$namespaceStart = (int) \strpos($raw, self::DELIM, $expireEnd);
|
||||
$namespaceEnd = (int) \strpos($raw, self::DELIM, $namespaceStart + 1);
|
||||
$namespace = \substr($raw, $namespaceStart + 1, $namespaceEnd - $namespaceStart - 1);
|
||||
|
||||
if ($namespace === false) {
|
||||
return null; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$obj = new $namespace();
|
||||
$obj->unserialize(\substr($raw, $namespaceEnd + 1));
|
||||
|
||||
return $obj;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
@ -234,7 +297,7 @@ final class MemCached extends ConnectionAbstract
|
|||
public function updateExpire(int | string $key, int $expire = -1) : bool
|
||||
{
|
||||
if ($expire > 0) {
|
||||
$this->con->touch($key, $expire);
|
||||
$this->con->touch((string) $key, $expire);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -271,7 +334,7 @@ final class MemCached extends ConnectionAbstract
|
|||
return false;
|
||||
}
|
||||
|
||||
return $this->con->replace($key, $value, \max($expire, 0));
|
||||
return $this->con->replace((string) $key, $value, \max($expire, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -111,12 +111,12 @@ final class RedisCache extends ConnectionAbstract
|
|||
}
|
||||
|
||||
if ($expire > 0) {
|
||||
$this->con->setEx($key, $expire, $this->build($value));
|
||||
$this->con->setEx((string) $key, $expire, $this->build($value));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->con->set($key, $this->build($value));
|
||||
$this->con->set((string) $key, $this->build($value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -129,10 +129,10 @@ final class RedisCache extends ConnectionAbstract
|
|||
}
|
||||
|
||||
if ($expire > 0) {
|
||||
return $this->con->setNx($key, $this->build($value), $expire);
|
||||
return $this->con->setNx((string) $key, $this->build($value), $expire);
|
||||
}
|
||||
|
||||
return $this->con->setNx($key, $this->build($value));
|
||||
return $this->con->setNx((string) $key, $this->build($value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -140,11 +140,11 @@ final class RedisCache extends ConnectionAbstract
|
|||
*/
|
||||
public function get(int | string $key, int $expire = -1) : mixed
|
||||
{
|
||||
if ($this->status !== CacheStatus::OK || $this->con->exists($key) < 1) {
|
||||
if ($this->status !== CacheStatus::OK || $this->con->exists((string) $key) < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = $this->con->get($key);
|
||||
$result = $this->con->get((string) $key);
|
||||
|
||||
if (\is_string($result)) {
|
||||
$type = (int) $result[0];
|
||||
|
|
@ -164,7 +164,7 @@ final class RedisCache extends ConnectionAbstract
|
|||
return false;
|
||||
}
|
||||
|
||||
return $this->con->del($key) > 0;
|
||||
return $this->con->del((string) $key) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -176,7 +176,7 @@ final class RedisCache extends ConnectionAbstract
|
|||
return false;
|
||||
}
|
||||
|
||||
return $this->con->exists($key);
|
||||
return $this->con->exists((string) $key) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -184,7 +184,7 @@ final class RedisCache extends ConnectionAbstract
|
|||
*/
|
||||
public function increment(int | string $key, int $value = 1) : bool
|
||||
{
|
||||
$this->con->incrBy($key, $value);
|
||||
$this->con->incrBy((string) $key, $value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -194,7 +194,7 @@ final class RedisCache extends ConnectionAbstract
|
|||
*/
|
||||
public function decrement(int | string $key, int $value = 1) : bool
|
||||
{
|
||||
$this->con->decrBy($key, $value);
|
||||
$this->con->decrBy((string) $key, $value);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -204,10 +204,10 @@ final class RedisCache extends ConnectionAbstract
|
|||
*/
|
||||
public function rename(int | string $old, int | string $new, int $expire = -1) : void
|
||||
{
|
||||
$this->con->rename($old, $new);
|
||||
$this->con->rename((string) $old, (string) $new);
|
||||
|
||||
if ($expire > 0) {
|
||||
$this->con->expire($new, $expire);
|
||||
$this->con->expire((string) $new, $expire);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ final class RedisCache extends ConnectionAbstract
|
|||
|
||||
foreach ($keys as $key) {
|
||||
if (\preg_match('/' . $pattern . '/', $key) === 1) {
|
||||
$result = $this->con->get($key);
|
||||
$result = $this->con->get((string) $key);
|
||||
if (\is_string($result)) {
|
||||
$type = (int) $result[0];
|
||||
$start = (int) \strpos($result, self::DELIM);
|
||||
|
|
@ -264,7 +264,7 @@ final class RedisCache extends ConnectionAbstract
|
|||
public function updateExpire(int | string $key, int $expire = -1) : bool
|
||||
{
|
||||
if ($expire > 0) {
|
||||
$this->con->expire($key, $expire);
|
||||
$this->con->expire((string) $key, $expire);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -301,8 +301,8 @@ final class RedisCache extends ConnectionAbstract
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($this->con->exists($key) > 0) {
|
||||
$this->set($key, $value, $expire);
|
||||
if ($this->con->exists((string) $key) > 0) {
|
||||
$this->set((string) $key, $value, $expire);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ abstract class ModuleAbstract
|
|||
public static function getLocalization(string $language, string $destination) : array
|
||||
{
|
||||
$lang = [];
|
||||
if (\is_file($oldPath = static::PATH . '/Theme/' . $destination . '/Lang/' . $language . '.lang.php')) {
|
||||
if (\is_file($oldPath = \rtrim(static::PATH, '/') . '/Theme/' . $destination . '/Lang/' . $language . '.lang.php')) {
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
return include $oldPath;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,11 +114,11 @@ abstract class StatusAbstract
|
|||
}
|
||||
|
||||
if (!\is_file($destRoutePath)) {
|
||||
throw new PathException($destRoutePath);
|
||||
throw new PathException($destRoutePath); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if (!\is_writable($destRoutePath)) {
|
||||
throw new PermissionException($destRoutePath);
|
||||
throw new PermissionException($destRoutePath); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
|
|
@ -246,11 +246,11 @@ abstract class StatusAbstract
|
|||
}
|
||||
|
||||
if (!\is_file($destRoutePath)) {
|
||||
throw new PathException($destRoutePath);
|
||||
throw new PathException($destRoutePath); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
if (!\is_writable($destRoutePath)) {
|
||||
throw new PermissionException($destRoutePath);
|
||||
throw new PermissionException($destRoutePath); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/** @noinspection PhpIncludeInspection */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user