From 26b900cf61d356d5b3ab77d9261aabe4a44a3ff6 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 2 May 2023 18:42:46 +0200 Subject: [PATCH] Misc improvements --- README.md | 16 +++--- composer.json | 2 +- docs | 2 +- examples/bot.php | 2 +- src/Db/DbPropertiesFactory.php | 22 ++++---- src/Db/DbPropertiesTrait.php | 5 +- src/Db/DriverArray.php | 54 +++++++++---------- src/Db/MemoryArray.php | 2 +- src/Db/MysqlArray.php | 1 - src/Db/PostgresArray.php | 27 ++++++---- src/Db/RedisArray.php | 6 +-- src/Db/SqlArray.php | 6 +-- src/MTProto.php | 15 +++--- src/MTProtoTools/MinDatabase.php | 3 +- src/MTProtoTools/ReferenceDatabase.php | 3 +- src/Magic.php | 6 +++ src/Serialization.php | 10 ++-- src/SessionPaths.php | 18 +++++-- ...bstract.php => DriverDatabaseAbstract.php} | 8 ++- src/Settings/Database/Redis.php | 2 +- src/Settings/Database/SerializerType.php | 2 +- src/Settings/Database/SqlAbstract.php | 2 +- 22 files changed, 113 insertions(+), 101 deletions(-) rename src/Settings/Database/{PersistentDatabaseAbstract.php => DriverDatabaseAbstract.php} (92%) diff --git a/README.md b/README.md index 8b078298b..1649fd5ee 100644 --- a/README.md +++ b/README.md @@ -200,15 +200,15 @@ Want to add your own open-source project to this list? [Click here!](https://doc * [Queues](https://docs.madelineproto.xyz/docs/USING_METHODS.html#queues) * [Multiple method calls](https://docs.madelineproto.xyz/docs/USING_METHODS.html#multiple-method-calls) * [FULL API Documentation with descriptions](https://docs.madelineproto.xyz/API_docs/methods/) - * [Logout](https://docs.madelineproto.xyz/logout.html) * [Login](https://docs.madelineproto.xyz/docs/LOGIN.html) - * [Change 2FA password](https://docs.madelineproto.xyz/update2fa.html) - * [Get all chats, broadcast a message to all chats](https://docs.madelineproto.xyz/docs/DIALOGS.html) - * [Get the full participant list of a channel/group/supergroup](https://docs.madelineproto.xyz/getPwrChat.html) - * [Get full info about a user/chat/supergroup/channel](https://docs.madelineproto.xyz/getFullInfo.html) - * [Get info about a user/chat/supergroup/channel](https://docs.madelineproto.xyz/getInfo.html) - * [Get info about the currently logged-in user](https://docs.madelineproto.xyz/getSelf.html) - * [Upload or download files up to 2 GB](https://docs.madelineproto.xyz/docs/FILES.html) + * [Change 2FA password: update2FA](https://docs.madelineproto.xyz/update2fa.html) + * [Get all chats, broadcast a message to all chats: getDialogIds, getDialogs, getFullDialogs](https://docs.madelineproto.xyz/docs/DIALOGS.html) + * [Get the full participant list of a channel/group/supergroup: getPwrChat](https://docs.madelineproto.xyz/getPwrChat.html) + * [Get full info about a user/chat/supergroup/channel: getFullInfo](https://docs.madelineproto.xyz/getFullInfo.html) + * [Get info about a user/chat/supergroup/channel: getInfo](https://docs.madelineproto.xyz/getInfo.html) + * [Get the ID of a user/chat/supergroup/channel/update: getID](https://docs.madelineproto.xyz/getId.html) + * [Get info about the currently logged-in user: getSelf](https://docs.madelineproto.xyz/getSelf.html) + * [Upload or download files up to 2 GB: uploadFrom*, downloadTo*](https://docs.madelineproto.xyz/docs/FILES.html) * [Make a phone call and play a song](https://docs.madelineproto.xyz/docs/CALLS.html) * [Create a secret chat bot](https://docs.madelineproto.xyz/docs/SECRET_CHATS.html) * Abort a pending 2FA password reset, see here for more info ยป: account.declinePasswordReset diff --git a/composer.json b/composer.json index 8c892f15f..039662b39 100644 --- a/composer.json +++ b/composer.json @@ -119,7 +119,7 @@ "test-php56": "tests/test-conversion.sh 5", "cs": "PHP_CS_FIXER_IGNORE_ENV=1 php -d pcre.jit=0 vendor/bin/php-cs-fixer fix -v --diff --dry-run", "cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php -d pcre.jit=0 vendor/bin/php-cs-fixer fix -v --diff", - "psalm": "psalm", + "psalm": "psalm.phar", "docs": "php tools/build_docs.php", "docs-fix": "tools/fix_docs.sh", "test": "@php -dzend.assertions=1 -dassert.exception=1 ./vendor/bin/phpunit --coverage-text --config tests/phpunit.xml", diff --git a/docs b/docs index a6959a7fe..0689f6a3d 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit a6959a7fe20409d539ea8fafeafe780681f943b6 +Subproject commit 0689f6a3df370f6626672149a01aa937415e91d8 diff --git a/examples/bot.php b/examples/bot.php index 1ab0cc2a0..3c78c5263 100755 --- a/examples/bot.php +++ b/examples/bot.php @@ -57,7 +57,7 @@ class MyEventHandler extends EventHandler * @see https://docs.madelineproto.xyz/docs/DATABASE.html */ protected static array $dbProperties = [ - 'dataStoredOnDb' => 'array', + 'dataStoredOnDb' => [], ]; /** diff --git a/src/Db/DbPropertiesFactory.php b/src/Db/DbPropertiesFactory.php index 9d7bc9caf..e27c48615 100644 --- a/src/Db/DbPropertiesFactory.php +++ b/src/Db/DbPropertiesFactory.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace danog\MadelineProto\Db; +use danog\MadelineProto\Settings\Database\DriverDatabaseAbstract; use danog\MadelineProto\Settings\Database\Memory; use danog\MadelineProto\Settings\Database\Mysql; -use danog\MadelineProto\Settings\Database\PersistentDatabaseAbstract; use danog\MadelineProto\Settings\Database\Postgres; use danog\MadelineProto\Settings\Database\Redis; use danog\MadelineProto\Settings\Database\SerializerType; @@ -14,12 +14,13 @@ use danog\MadelineProto\Settings\DatabaseAbstract; use InvalidArgumentException; /** + * @psalm-type TOrmConfig=array{serializer?: SerializerType, enableCache?: bool, cacheTtl?: int} * This factory class initializes the correct database backend for MadelineProto. */ abstract class DbPropertiesFactory { /** - * @param SerializerType | array{serializer?: SerializerType, enableCache?: bool, cacheTtl?: int} $config + * @param TOrmConfig|'array' $config * @return DbType * @internal * @uses \danog\MadelineProto\Db\MemoryArray @@ -27,25 +28,22 @@ abstract class DbPropertiesFactory * @uses \danog\MadelineProto\Db\PostgresArray * @uses \danog\MadelineProto\Db\RedisArray */ - public static function get(DatabaseAbstract $dbSettings, string $table, SerializerType|array $config, ?DbType $value = null) + public static function get(DatabaseAbstract $dbSettings, string $table, string|array $config, ?DbType $value = null) { + if ($config === 'array') { + $config = []; + } $dbSettingsCopy = clone $dbSettings; $class = __NAMESPACE__; - if ($dbSettingsCopy instanceof PersistentDatabaseAbstract) { - if ($config instanceof SerializerType) { - $config = [ - 'serializer' => $config - ]; - } - - $config = array_merge([ + if ($dbSettingsCopy instanceof DriverDatabaseAbstract) { + $config = \array_merge([ 'serializer' => $dbSettings->getSerializer(), 'enableCache' => true, 'cacheTtl' => $dbSettings->getCacheTtl(), ], $config); - $class = $dbSettings instanceof PersistentDatabaseAbstract && (!($config['enableCache'] ?? true) || !$config['cacheTtl']) + $class = $dbSettings instanceof DriverDatabaseAbstract && (!($config['enableCache'] ?? true) || !$config['cacheTtl']) ? __NAMESPACE__ . '\\NullCache' : __NAMESPACE__; diff --git a/src/Db/DbPropertiesTrait.php b/src/Db/DbPropertiesTrait.php index 127782e1b..1b0b3a590 100644 --- a/src/Db/DbPropertiesTrait.php +++ b/src/Db/DbPropertiesTrait.php @@ -15,8 +15,9 @@ use function Amp\Future\await; * * You will have to define a `$dbProperties` static array property, with a list of properties you want to store to a database. * - * @see DbPropertiesFactory For a list of allowed property types - * @property array $dbProperties + * @psalm-import-type TOrmConfig from DbPropertiesFactory + * + * @property array $dbProperties */ trait DbPropertiesTrait { diff --git a/src/Db/DriverArray.php b/src/Db/DriverArray.php index f6685732c..49abd3dae 100644 --- a/src/Db/DriverArray.php +++ b/src/Db/DriverArray.php @@ -5,9 +5,10 @@ declare(strict_types=1); namespace danog\MadelineProto\Db; use danog\MadelineProto\Logger; -use danog\MadelineProto\Settings\Database\PersistentDatabaseAbstract; +use danog\MadelineProto\Settings\Database\DriverDatabaseAbstract; use danog\MadelineProto\Settings\Database\Memory; use danog\MadelineProto\Settings\Database\SerializerType; +use danog\MadelineProto\Settings\DatabaseAbstract; use danog\MadelineProto\SettingsAbstract; use IteratorAggregate; use ReflectionClass; @@ -29,7 +30,11 @@ use function Amp\Future\await; abstract class DriverArray implements DbArray, IteratorAggregate { protected string $table; - protected PersistentDatabaseAbstract $dbSettings; + /** @var callable(mixed): mixed */ + protected $serializer; + /** @var callable(string): mixed */ + protected $deserializer; + protected DriverDatabaseAbstract $dbSettings; use ArrayCacheTrait; @@ -77,7 +82,7 @@ abstract class DriverArray implements DbArray, IteratorAggregate return $this->offsetGet($key) !== null; } - public static function getInstance(string $table, DbType|array|null $previous, $settings): static + public static function getInstance(string $table, DbType|array|null $previous, DatabaseAbstract $settings): static { /** @var MysqlArray|PostgresArray|RedisArray */ $instance = new static(); @@ -85,6 +90,7 @@ abstract class DriverArray implements DbArray, IteratorAggregate $instance->dbSettings = $settings; $instance->setCacheTtl($settings->getCacheTtl()); + $instance->setSerializer($settings->getSerializer()); $instance->startCacheCleanupLoop(); @@ -102,6 +108,22 @@ abstract class DriverArray implements DbArray, IteratorAggregate return $instance; } + protected function setSerializer(SerializerType $serializer): void + { + $this->serializer = match ($serializer) { + SerializerType::SERIALIZE => \serialize(...), + SerializerType::IGBINARY => \igbinary_serialize(...), + SerializerType::JSON => fn ($value) => \json_encode($value, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES), + SerializerType::STRING => strval(...), + }; + $this->deserializer = match ($serializer) { + SerializerType::SERIALIZE => \unserialize(...), + SerializerType::IGBINARY => \igbinary_unserialize(...), + SerializerType::JSON => fn ($value) => \json_decode($value, true, 256, JSON_THROW_ON_ERROR), + SerializerType::STRING => fn ($v) => $v, + }; + } + /** * Rename table of old database, if the new one is not a temporary table name. * @@ -215,30 +237,4 @@ abstract class DriverArray implements DbArray, IteratorAggregate } return \str_replace('NullCache\\', '', $instance::class); } - - /** - * Serialize retrieved value. - */ - protected function serialize(mixed $value): string - { - return match ($this->dbSettings->getSerializer()) { - SerializerType::SERIALIZE => \serialize($value), - SerializerType::IGBINARY => \igbinary_serialize($value), - SerializerType::JSON => json_encode($value, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES), - SerializerType::STRING => (string)$value, - }; - } - - /** - * Deserialize retrieved value. - */ - protected function unserialize(string $value): mixed - { - return match ($this->dbSettings->getSerializer()) { - SerializerType::SERIALIZE => \unserialize($value), - SerializerType::IGBINARY => \igbinary_unserialize($value), - SerializerType::JSON => json_decode($value, true, 256, JSON_THROW_ON_ERROR), - SerializerType::STRING => $value, - }; - } } diff --git a/src/Db/MemoryArray.php b/src/Db/MemoryArray.php index 0d005626c..c85d5a6f0 100644 --- a/src/Db/MemoryArray.php +++ b/src/Db/MemoryArray.php @@ -28,7 +28,7 @@ final class MemoryArray extends ArrayIterator implements DbArray /** * @param Memory $settings */ - public static function getInstance(string $table, $previous, Memory $settings): static + public static function getInstance(string $table, DbType|array|null $previous, $settings): static { if ($previous instanceof MemoryArray) { return $previous; diff --git a/src/Db/MysqlArray.php b/src/Db/MysqlArray.php index 028a7e8f0..19669a87a 100644 --- a/src/Db/MysqlArray.php +++ b/src/Db/MysqlArray.php @@ -22,7 +22,6 @@ use PDO; */ class MysqlArray extends SqlArray { - // Legacy protected array $settings; diff --git a/src/Db/PostgresArray.php b/src/Db/PostgresArray.php index 96e6ce6a2..438a4fad8 100644 --- a/src/Db/PostgresArray.php +++ b/src/Db/PostgresArray.php @@ -4,12 +4,13 @@ declare(strict_types=1); namespace danog\MadelineProto\Db; +use Amp\Postgres\ByteA; use Amp\Postgres\PostgresConfig; use danog\MadelineProto\Db\Driver\Postgres; use danog\MadelineProto\Exception; use danog\MadelineProto\Logger; -use danog\MadelineProto\Settings\Database\PersistentDatabaseAbstract; use danog\MadelineProto\Settings\Database\Postgres as DatabasePostgres; +use danog\MadelineProto\Settings\Database\SerializerType; use PDO; /** @@ -22,7 +23,6 @@ use PDO; */ class PostgresArray extends SqlArray { - // Legacy protected array $settings; @@ -90,16 +90,21 @@ class PostgresArray extends SqlArray } } - protected function unserialize(string $value): mixed + protected function setSerializer(SerializerType $serializer): void { - return parent::unserialize(\hex2bin($value)); + $this->serializer = match ($serializer) { + SerializerType::SERIALIZE => fn ($v) => new ByteA(\serialize($v)), + SerializerType::IGBINARY => fn ($v) => new ByteA(\igbinary_serialize($v)), + SerializerType::JSON => fn ($value) => \json_encode($value, JSON_THROW_ON_ERROR|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES), + SerializerType::STRING => strval(...), + }; + $this->deserializer = match ($serializer) { + SerializerType::SERIALIZE => \unserialize(...), + SerializerType::IGBINARY => \igbinary_unserialize(...), + SerializerType::JSON => fn ($value) => \json_decode($value, true, 256, JSON_THROW_ON_ERROR), + SerializerType::STRING => fn ($v) => $v, + }; } - - protected function serialize(mixed $value): string - { - return \bin2hex(parent::serialize($value)); - } - /** * Create table for property. */ @@ -111,7 +116,7 @@ class PostgresArray extends SqlArray CREATE TABLE IF NOT EXISTS \"{$this->table}\" ( \"key\" VARCHAR(255) PRIMARY KEY NOT NULL, - \"value\" TEXT NOT NULL + \"value\" BYTEA NOT NULL ); "); } diff --git a/src/Db/RedisArray.php b/src/Db/RedisArray.php index f19cc6931..c4b102c14 100644 --- a/src/Db/RedisArray.php +++ b/src/Db/RedisArray.php @@ -85,7 +85,7 @@ class RedisArray extends DriverArray $this->setCache($index, $value); - $this->db->set($this->rKey($index), $this->serialize($value)); + $this->db->set($this->rKey($index), ($this->serializer)($value)); $this->setCache($index, $value); } @@ -98,7 +98,7 @@ class RedisArray extends DriverArray $value = $this->db->get($this->rKey($offset)); - if ($value !== null && $value = $this->unserialize($value)) { + if ($value !== null && $value = ($this->deserializer)($value)) { $this->setCache($offset, $value); } @@ -123,7 +123,7 @@ class RedisArray extends DriverArray $len = \strlen($this->rKey('')); foreach ($request as $key) { - yield \substr($key, $len) => \unserialize($this->db->get($key)); + yield \substr($key, $len) => ($this->deserializer)($this->db->get($key)); } } diff --git a/src/Db/SqlArray.php b/src/Db/SqlArray.php index 91b391434..5ffa62809 100644 --- a/src/Db/SqlArray.php +++ b/src/Db/SqlArray.php @@ -66,7 +66,7 @@ abstract class SqlArray extends DriverArray public function getIterator(): \Traversable { foreach ($this->execute($this->queries[self::SQL_ITERATE]) as ['key' => $key, 'value' => $value]) { - yield $key => $this->unserialize($value); + yield $key => ($this->deserializer)($value); } } @@ -86,7 +86,7 @@ abstract class SqlArray extends DriverArray return null; } - $value = $this->unserialize($row['value']); + $value = ($this->deserializer)($row['value']); $this->setCache($key, $value); return $value; @@ -105,7 +105,7 @@ abstract class SqlArray extends DriverArray $this->queries[self::SQL_SET], [ 'index' => $key, - 'value' => $this->serialize($value), + 'value' => ($this->serializer)($value), ], ); $this->setCache($key, $value); diff --git a/src/MTProto.php b/src/MTProto.php index e68689266..fabfdf60b 100644 --- a/src/MTProto.php +++ b/src/MTProto.php @@ -48,6 +48,7 @@ use danog\MadelineProto\MTProtoTools\UpdatesState; use danog\MadelineProto\SecretChats\MessageHandler; use danog\MadelineProto\SecretChats\ResponseHandler; use danog\MadelineProto\SecretChats\SeqNoHandler; +use danog\MadelineProto\Settings\Database\SerializerType; use danog\MadelineProto\Settings\TLSchema; use danog\MadelineProto\TL\Conversion\BotAPI; use danog\MadelineProto\TL\Conversion\BotAPIFiles; @@ -501,14 +502,12 @@ final class MTProto implements TLCallback, LoggerGetter * @see DbPropertiesFactory */ protected static array $dbProperties = [ - 'chats' => [], - 'full_chats' => [], - 'sponsoredMessages' => [], - 'channelParticipants' => [], - 'usernames' => [], - 'session' => [ - 'config' => ['enableCache' => false], - ], + 'chats' => ['serializer' => SerializerType::SERIALIZE], + 'full_chats' => ['serializer' => SerializerType::SERIALIZE], + 'sponsoredMessages' => ['serializer' => SerializerType::SERIALIZE], + 'channelParticipants' => ['serializer' => SerializerType::SERIALIZE], + 'usernames' => ['serializer' => SerializerType::SERIALIZE], + 'session' => ['serializer' => SerializerType::SERIALIZE, 'enableCache' => false], ]; /** diff --git a/src/MTProtoTools/MinDatabase.php b/src/MTProtoTools/MinDatabase.php index cea40e39d..bbc2b237f 100644 --- a/src/MTProtoTools/MinDatabase.php +++ b/src/MTProtoTools/MinDatabase.php @@ -25,6 +25,7 @@ use danog\MadelineProto\Db\DbPropertiesTrait; use danog\MadelineProto\Exception; use danog\MadelineProto\Logger; use danog\MadelineProto\MTProto; +use danog\MadelineProto\Settings\Database\SerializerType; use danog\MadelineProto\TL\TLCallback; use Revolt\EventLoop; @@ -68,7 +69,7 @@ final class MinDatabase implements TLCallback * @see DbPropertiesFactory */ protected static array $dbProperties = [ - 'db' => [], + 'db' => ['serializer' => SerializerType::SERIALIZE], ]; public function __construct(MTProto $API) diff --git a/src/MTProtoTools/ReferenceDatabase.php b/src/MTProtoTools/ReferenceDatabase.php index 0cc27a9e3..ac6ababbd 100644 --- a/src/MTProtoTools/ReferenceDatabase.php +++ b/src/MTProtoTools/ReferenceDatabase.php @@ -26,6 +26,7 @@ use danog\MadelineProto\Exception; use danog\MadelineProto\Logger; use danog\MadelineProto\MTProto; use danog\MadelineProto\MTProto\OutgoingMessage; +use danog\MadelineProto\Settings\Database\SerializerType; use danog\MadelineProto\TL\TLCallback; use danog\MadelineProto\Tools; use Webmozart\Assert\Assert; @@ -87,7 +88,7 @@ final class ReferenceDatabase implements TLCallback * @see DbPropertiesFactory */ protected static array $dbProperties = [ - 'db' => [], + 'db' => ['serializer' => SerializerType::SERIALIZE], ]; public function __construct(private MTProto $API) diff --git a/src/Magic.php b/src/Magic.php index d72e52b8f..78998b285 100644 --- a/src/Magic.php +++ b/src/Magic.php @@ -82,6 +82,11 @@ final class Magic * */ public static bool $can_getcwd = false; + /** + * Whether we can use igbinary. + * + */ + public static bool $can_use_igbinary = false; /** * Whether we've processed forks. * @@ -224,6 +229,7 @@ final class Magic Shutdown::init(); \set_error_handler(Exception::exceptionErrorHandler(...)); \set_exception_handler(Exception::exceptionHandler(...)); + self::$can_use_igbinary = \function_exists('igbinary_serialize'); self::$isIpcWorker = \defined('MADELINE_WORKER_TYPE') ? MADELINE_WORKER_TYPE === 'madeline-ipc' : false; // Important, obtain root relative to caller script $backtrace = \debug_backtrace(0); diff --git a/src/Serialization.php b/src/Serialization.php index 574a2451f..bc651c8eb 100644 --- a/src/Serialization.php +++ b/src/Serialization.php @@ -51,11 +51,9 @@ abstract class Serialization /** * Header for session files. */ - const PHP_HEADER = ' SerializerType::SERIALIZE], $unserialized, ); } else { diff --git a/src/SessionPaths.php b/src/SessionPaths.php index 64878173a..8cbb3feda 100644 --- a/src/SessionPaths.php +++ b/src/SessionPaths.php @@ -124,10 +124,11 @@ final class SessionPaths Logger::log("Got exclusive lock of $path.lock..."); $object = Serialization::PHP_HEADER - .\chr(Serialization::VERSION) + .\chr(Serialization::VERSION_SERIALIZATION_AWARE) .\chr(PHP_MAJOR_VERSION) .\chr(PHP_MINOR_VERSION) - .\serialize($object); + .\chr(Magic::$can_use_igbinary ? 1 : 0) + .(Magic::$can_use_igbinary ? \igbinary_serialize($object) : \serialize($object)); write( "$path.temp.php", @@ -170,7 +171,7 @@ final class SessionPaths $file->seek($headerLen++); $v = \ord($file->read(null, 1)); - if ($v === Serialization::VERSION) { + if ($v >= Serialization::VERSION_OLD) { $php = $file->read(null, 2); $major = \ord($php[0]); $minor = \ord($php[1]); @@ -179,7 +180,16 @@ final class SessionPaths } $headerLen += 2; } - $unserialized = \unserialize($file->read(null, $size - $headerLen) ?? ''); + $igbinary = false; + if ($v >= Serialization::VERSION_SERIALIZATION_AWARE) { + $igbinary = (bool) \ord($file->read(null, 1)); + if ($igbinary && !Magic::$can_use_igbinary) { + throw Exception::extension('igbinary'); + } + $headerLen++; + } + $unserialized = $file->read(null, $size - $headerLen) ?? ''; + $unserialized = $igbinary ? \igbinary_unserialize($unserialized) : \unserialize($unserialized); $file->close(); } finally { $unlock(); diff --git a/src/Settings/Database/PersistentDatabaseAbstract.php b/src/Settings/Database/DriverDatabaseAbstract.php similarity index 92% rename from src/Settings/Database/PersistentDatabaseAbstract.php rename to src/Settings/Database/DriverDatabaseAbstract.php index ee847df2a..a441c4344 100644 --- a/src/Settings/Database/PersistentDatabaseAbstract.php +++ b/src/Settings/Database/DriverDatabaseAbstract.php @@ -4,12 +4,12 @@ declare(strict_types=1); namespace danog\MadelineProto\Settings\Database; -use danog\MadelineProto\Settings\DatabaseAbstract as SettingsDatabaseAbstract; +use danog\MadelineProto\Settings\DatabaseAbstract; /** * Base class for database backends. */ -abstract class PersistentDatabaseAbstract extends SettingsDatabaseAbstract +abstract class DriverDatabaseAbstract extends DatabaseAbstract { /** * For how long to keep records in memory after last read, for cached backends. @@ -21,7 +21,7 @@ abstract class PersistentDatabaseAbstract extends SettingsDatabaseAbstract protected string $password = ''; /** - * Which serializer strategy use by default + * Which serializer strategy to use by default. */ protected SerializerType $serializer = SerializerType::SERIALIZE; @@ -31,7 +31,6 @@ abstract class PersistentDatabaseAbstract extends SettingsDatabaseAbstract 'database', 'password', 'cache_ttl', - 'serializer', ]) as $object => $array) { if (isset($settings[$array])) { $this->{$object}($settings[$array]); @@ -111,7 +110,6 @@ abstract class PersistentDatabaseAbstract extends SettingsDatabaseAbstract */ abstract public function setUri(string $uri): self; - public function getSerializer(): SerializerType { return $this->serializer; diff --git a/src/Settings/Database/Redis.php b/src/Settings/Database/Redis.php index 2e5e31d96..4eff4be06 100644 --- a/src/Settings/Database/Redis.php +++ b/src/Settings/Database/Redis.php @@ -7,7 +7,7 @@ namespace danog\MadelineProto\Settings\Database; /** * Redis backend settings. */ -final class Redis extends PersistentDatabaseAbstract +final class Redis extends DriverDatabaseAbstract { /** * Database number. diff --git a/src/Settings/Database/SerializerType.php b/src/Settings/Database/SerializerType.php index e422397df..26cf9d67f 100644 --- a/src/Settings/Database/SerializerType.php +++ b/src/Settings/Database/SerializerType.php @@ -1,4 +1,4 @@ -