mirror of
https://github.com/danog/AsyncOrm.git
synced 2024-11-30 04:39:45 +01:00
Cleanup
This commit is contained in:
parent
6c4c2d44c8
commit
b222c6f67d
@ -45,21 +45,35 @@ abstract class DbArray implements Countable, ArrayAccess, Traversable, IteratorA
|
||||
return $this->get($key) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TKey $offset
|
||||
* @return TValue
|
||||
*/
|
||||
final public function offsetGet(mixed $offset): mixed
|
||||
{
|
||||
return $this->get($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TKey $offset
|
||||
*/
|
||||
final public function offsetExists(mixed $offset): bool
|
||||
{
|
||||
return $this->isset($offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TKey $offset
|
||||
* @param TValue $value
|
||||
*/
|
||||
final public function offsetSet(mixed $offset, mixed $value): void
|
||||
{
|
||||
$this->set($offset, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TKey $offset
|
||||
*/
|
||||
final public function offsetUnset(mixed $offset): void
|
||||
{
|
||||
$this->unset($offset);
|
||||
|
@ -32,7 +32,7 @@ use function Amp\Future\await;
|
||||
* @template TKey as array-key
|
||||
* @template TValue
|
||||
*
|
||||
* @consistent-constructor
|
||||
* @psalm-consistent-constructor
|
||||
*
|
||||
* @extends DbArray<TKey, TValue>
|
||||
*
|
||||
@ -40,8 +40,13 @@ use function Amp\Future\await;
|
||||
*/
|
||||
abstract class DriverArray extends DbArray
|
||||
{
|
||||
protected function __construct(protected readonly FieldConfig $config, protected readonly Serializer $serializer)
|
||||
{
|
||||
/**
|
||||
* @param Serializer<TValue> $serializer
|
||||
*/
|
||||
protected function __construct(
|
||||
protected readonly FieldConfig $config,
|
||||
protected readonly Serializer $serializer
|
||||
) {
|
||||
}
|
||||
|
||||
public static function getInstance(FieldConfig $config, DbArray|null $previous): DbArray
|
||||
|
@ -33,6 +33,9 @@ use danog\AsyncOrm\Serializer;
|
||||
*/
|
||||
abstract class SqlArray extends DriverArray
|
||||
{
|
||||
/**
|
||||
* @param Serializer<TValue> $serializer
|
||||
*/
|
||||
protected function __construct(
|
||||
FieldConfig $config,
|
||||
Serializer $serializer,
|
||||
|
@ -51,6 +51,9 @@ final class MysqlArray extends SqlArray
|
||||
// We're forced to use quoting (just like PDO does internally when using prepares) because native MySQL prepares are extremely slow.
|
||||
protected PDO $pdo;
|
||||
|
||||
/**
|
||||
* @param Serializer<TValue> $serializer
|
||||
*/
|
||||
public function __construct(FieldConfig $config, Serializer $serializer)
|
||||
{
|
||||
$settings = $config->settings;
|
||||
|
@ -22,6 +22,7 @@ use danog\AsyncOrm\DbArray;
|
||||
use danog\AsyncOrm\Driver\MemoryArray;
|
||||
use danog\AsyncOrm\FieldConfig;
|
||||
use danog\AsyncOrm\Internal\Containers\ObjectContainer;
|
||||
use danog\AsyncOrm\Settings\DriverSettings;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
@ -56,6 +57,7 @@ final class ObjectArray extends DbArray
|
||||
$previous->cache->flushCache();
|
||||
return $previous->cache->inner;
|
||||
}
|
||||
\assert($config->settings instanceof DriverSettings);
|
||||
$previous->cache->startCacheCleanupLoop($config->settings->cacheTtl);
|
||||
return $previous;
|
||||
}
|
||||
|
@ -43,6 +43,9 @@ class PostgresArray extends SqlArray
|
||||
private static array $connections = [];
|
||||
|
||||
private static ?LocalKeyedMutex $mutex = null;
|
||||
/**
|
||||
* @param Serializer<TValue> $serializer
|
||||
*/
|
||||
public function __construct(FieldConfig $config, Serializer $serializer)
|
||||
{
|
||||
self::$mutex ??= new LocalKeyedMutex;
|
||||
|
@ -49,6 +49,9 @@ final class RedisArray extends DriverArray
|
||||
|
||||
private readonly RedisClient $db;
|
||||
|
||||
/**
|
||||
* @param Serializer<TValue> $serializer
|
||||
*/
|
||||
public function __construct(FieldConfig $config, Serializer $serializer)
|
||||
{
|
||||
if ($serializer instanceof Passthrough && $config->valueType === ValueType::INT) {
|
||||
@ -118,6 +121,7 @@ final class RedisArray extends DriverArray
|
||||
$value = $this->db->get($this->rKey($key));
|
||||
|
||||
if ($value !== null) {
|
||||
/** @var TValue */
|
||||
$value = $this->serializer->deserialize($value);
|
||||
}
|
||||
|
||||
|
@ -20,9 +20,17 @@ namespace danog\AsyncOrm;
|
||||
|
||||
/**
|
||||
* Serializer interface.
|
||||
*
|
||||
* @template TValue
|
||||
*/
|
||||
interface Serializer
|
||||
{
|
||||
/**
|
||||
* @param TValue $value
|
||||
*/
|
||||
public function serialize(mixed $value): mixed;
|
||||
/**
|
||||
* @return TValue
|
||||
*/
|
||||
public function deserialize(mixed $value): mixed;
|
||||
}
|
||||
|
@ -21,9 +21,17 @@ namespace danog\AsyncOrm\Serializer;
|
||||
use Amp\Postgres\PostgresByteA;
|
||||
use danog\AsyncOrm\Serializer;
|
||||
|
||||
/** @internal BYTEA serializer */
|
||||
/**
|
||||
* @internal BYTEA serializer
|
||||
*
|
||||
* @template TValue
|
||||
* @implements Serializer<TValue>
|
||||
*/
|
||||
final class ByteaSerializer implements Serializer
|
||||
{
|
||||
/**
|
||||
* @param Serializer<TValue> $inner
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly Serializer $inner
|
||||
) {
|
||||
|
@ -24,6 +24,9 @@ use danog\AsyncOrm\Serializer;
|
||||
* Igbinary serializer.
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @template TValue
|
||||
* @implements Serializer<TValue>
|
||||
*/
|
||||
final class Igbinary implements Serializer
|
||||
{
|
||||
@ -34,6 +37,7 @@ final class Igbinary implements Serializer
|
||||
public function deserialize(mixed $value): mixed
|
||||
{
|
||||
\assert(\is_string($value));
|
||||
/** @var TValue */
|
||||
return \igbinary_unserialize($value);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ use danog\AsyncOrm\Serializer;
|
||||
* Integer casting serializer.
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @implements Serializer<int>
|
||||
*/
|
||||
final class IntString implements Serializer
|
||||
{
|
||||
|
@ -24,6 +24,9 @@ use danog\AsyncOrm\Serializer;
|
||||
* JSON serializer.
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @template TValue
|
||||
* @implements Serializer<TValue>
|
||||
*/
|
||||
final class Json implements Serializer
|
||||
{
|
||||
@ -34,6 +37,7 @@ final class Json implements Serializer
|
||||
public function deserialize(mixed $value): mixed
|
||||
{
|
||||
\assert(\is_string($value));
|
||||
/** @var TValue */
|
||||
return \json_decode($value, true, flags: JSON_THROW_ON_ERROR);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ use danog\AsyncOrm\Serializer;
|
||||
* Native serializer.
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @template TValue
|
||||
* @implements Serializer<TValue>
|
||||
*/
|
||||
final class Native implements Serializer
|
||||
{
|
||||
@ -34,6 +37,7 @@ final class Native implements Serializer
|
||||
public function deserialize(mixed $value): mixed
|
||||
{
|
||||
\assert(\is_string($value));
|
||||
/** @var TValue */
|
||||
return \unserialize($value);
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,21 @@ use danog\AsyncOrm\Serializer;
|
||||
* Passthrough serializer.
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @template TValue
|
||||
* @implements Serializer<TValue>
|
||||
*/
|
||||
final class Passthrough implements Serializer
|
||||
{
|
||||
/**
|
||||
* @param TValue $value
|
||||
* @return TValue
|
||||
*/
|
||||
public function serialize(mixed $value): mixed
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
/** @param TValue $value */
|
||||
public function deserialize(mixed $value): mixed
|
||||
{
|
||||
return $value;
|
||||
|
Loading…
Reference in New Issue
Block a user