diff --git a/src/MTProto.php b/src/MTProto.php index 747183684..52595fb4d 100644 --- a/src/MTProto.php +++ b/src/MTProto.php @@ -36,6 +36,7 @@ use Amp\Sync\LocalMutex; use AssertionError; use danog\AsyncOrm\Annotations\OrmMappedArray; use danog\AsyncOrm\DbArray; +use danog\AsyncOrm\DbArrayBuilder; use danog\AsyncOrm\DbAutoProperties; use danog\AsyncOrm\Driver\MemoryArray; use danog\AsyncOrm\KeyType; @@ -422,7 +423,12 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter $db []= async($this->event_handler_instance->internalSaveDbProperties(...)); } await($db); - return $this->getDbPrefix().'session'; + return new DbArrayBuilder( + $this->getDbPrefix().'session', + $this->getDbSettings(), + KeyType::STRING, + ValueType::SCALAR + ); } /** diff --git a/src/MTProtoTools/ReferenceDatabase.php b/src/MTProtoTools/ReferenceDatabase.php index c3583cc6e..7887ced8d 100644 --- a/src/MTProtoTools/ReferenceDatabase.php +++ b/src/MTProtoTools/ReferenceDatabase.php @@ -107,6 +107,7 @@ final class ReferenceDatabase implements TLCallback } public function init(): void { + var_dump($this->db); $this->initDbProperties($this->API->getDbSettings(), $this->API->getDbPrefix()); if ($this->v === 0) { $this->db->clear(); diff --git a/src/Serialization.php b/src/Serialization.php index fce877cb7..5a4da4395 100644 --- a/src/Serialization.php +++ b/src/Serialization.php @@ -220,29 +220,35 @@ abstract class Serialization } else { $unserialized = null; } - if ($unserialized instanceof DriverArray || \is_string($unserialized) || !$exists) { + if ($unserialized instanceof DriverArray || $unserialized instanceof DbArrayBuilder || !$exists) { if ($settings instanceof Settings) { $settings = $settings->getDb(); } + $tableName = null; + $array = null; if ($settings instanceof DriverDatabaseAbstract && $prefix = $settings->getEphemeralFilesystemPrefix() ) { $tableName = "{$prefix}_MTProto_session"; } elseif ($unserialized instanceof DriverArray) { - $tableName = ((array) $unserialized)["\0*\0table"]; + $unserialized = (array) $unserialized; + $tableName = $unserialized["\0*\0table"]; + $settings = $unserialized["\0*\0dbSettings"]; } else { - $tableName = $unserialized; + \assert($unserialized instanceof DbArrayBuilder); + $array = $unserialized->build(); } - $unserialized = null; if ($tableName !== null && $settings instanceof DriverDatabaseAbstract) { Logger::log('Extracting session from database...'); - $unserialized = (new DbArrayBuilder( + $array = (new DbArrayBuilder( $tableName, $settings->getOrmSettings(), KeyType::STRING, ValueType::SCALAR, - ))->build()->get('data'); + ))->build(); } + \assert($array !== null); + $unserialized = $array->get('data'); if (!$unserialized && $exists) { throw new Exception('Could not extract session from database!'); } diff --git a/src/polyfill.php b/src/polyfill.php index 078743e98..ddb12ec5a 100644 --- a/src/polyfill.php +++ b/src/polyfill.php @@ -5,6 +5,8 @@ if (class_exists('\\danog\\MadelineProto\\Db\\NullCache\\MysqlArray')) { } use danog\AsyncOrm\Driver\MemoryArray; +use danog\AsyncOrm\Internal\Containers\CacheContainer; +use danog\AsyncOrm\Internal\Driver\CachedArray; use danog\AsyncOrm\Internal\Driver\MysqlArray; use danog\AsyncOrm\Internal\Driver\PostgresArray; use danog\AsyncOrm\Internal\Driver\RedisArray; @@ -18,6 +20,8 @@ class_alias(PostgresArray::class, '\\danog\\MadelineProto\\Db\\PostgresArray'); class_alias(PostgresArray::class, '\\danog\\MadelineProto\\Db\\PostgresArrayBytea'); class_alias(RedisArray::class, '\\danog\\MadelineProto\\Db\\RedisArray'); class_alias(MemoryArray::class, '\\danog\\MadelineProto\\Db\\MemoryArray'); +class_alias(CachedArray::class, '\\danog\\MadelineProto\\Db\\CachedArray'); +class_alias(CacheContainer::class, '\\danog\\MadelineProto\\Db\\CacheContainer'); if ((PHP_MINOR_VERSION === 2 && PHP_VERSION_ID < 80204) || PHP_MAJOR_VERSION < 8 diff --git a/tools/phpdoc.php b/tools/phpdoc.php index 455702b6b..10f4a4d00 100644 --- a/tools/phpdoc.php +++ b/tools/phpdoc.php @@ -10,7 +10,6 @@ use danog\MadelineProto\Bug74586Exception; use danog\MadelineProto\Connection; use danog\MadelineProto\DataCenter; use danog\MadelineProto\DataCenterConnection; -use danog\MadelineProto\Db\DbPropertiesTrait; use danog\MadelineProto\Doc\MethodDoc; use danog\MadelineProto\Doc\NamespaceDoc; use danog\MadelineProto\DocsBuilder; @@ -110,9 +109,6 @@ $filter = static function (string $class) use ($ignore): bool { || str_starts_with($class, 'danog\\MadelineProto\\Db\\NullCache')) { return false; } - if ($class === DbPropertiesTrait::class) { - return true; - } $class = new ReflectionClass($class); return !$class->isTrait(); };