diff --git a/composer.json b/composer.json index 5098a0895..16abba811 100644 --- a/composer.json +++ b/composer.json @@ -44,12 +44,12 @@ "amphp/websocket-client": "^1.0" }, "require-dev": { + "phpdocumentor/reflection-docblock": "^5.2", "vlucas/phpdotenv": "^3", - "phpdocumentor/reflection-docblock": "^4.3", "ennexa/amp-update-cache": "dev-master", "phpunit/phpunit": "^8", "amphp/php-cs-fixer-config": "dev-master", - "haydenpierce/class-finder": "^0.4", + "haydenpierce/class-finder": "^0.4.2", "amphp/http-server": "dev-master", "amphp/http": "^1.6", "ext-ctype": "*", diff --git a/src/danog/MadelineProto/API.php b/src/danog/MadelineProto/API.php index 8834b48e9..298c24c6a 100644 --- a/src/danog/MadelineProto/API.php +++ b/src/danog/MadelineProto/API.php @@ -179,7 +179,7 @@ class API extends InternalDoc /** * Connect to MadelineProto. * - * @param Settings|SettingsEmpty $settings Settings + * @param SettingsAbstract $settings Settings * @param bool $forceFull Whether to force full initialization * * @return \Generator diff --git a/src/danog/MadelineProto/APIWrapper.php b/src/danog/MadelineProto/APIWrapper.php index 5712a9c6f..0c78a5613 100644 --- a/src/danog/MadelineProto/APIWrapper.php +++ b/src/danog/MadelineProto/APIWrapper.php @@ -210,4 +210,14 @@ final class APIWrapper return true; })()); } + + /** + * Get session path. + * + * @return SessionPaths + */ + public function getSession(): SessionPaths + { + return $this->session; + } } diff --git a/src/danog/MadelineProto/Db/DbPropertiesFactory.php b/src/danog/MadelineProto/Db/DbPropertiesFactory.php index f77a76af1..a7e39c064 100644 --- a/src/danog/MadelineProto/Db/DbPropertiesFactory.php +++ b/src/danog/MadelineProto/Db/DbPropertiesFactory.php @@ -9,7 +9,10 @@ use danog\MadelineProto\Settings\Database\Postgres; use danog\MadelineProto\Settings\Database\Redis; use danog\MadelineProto\Settings\DatabaseAbstract; -class DbPropertiesFactory +/** + * This factory class initializes the correct database backend for MadelineProto. + */ +abstract class DbPropertiesFactory { /** * Indicates a simple K-V array stored in a database backend. @@ -24,6 +27,8 @@ class DbPropertiesFactory * * @return Promise * + * @internal + * * @uses \danog\MadelineProto\Db\MemoryArray * @uses \danog\MadelineProto\Db\MysqlArray * @uses \danog\MadelineProto\Db\PostgresArray diff --git a/src/danog/MadelineProto/Db/DbPropertiesTrait.php b/src/danog/MadelineProto/Db/DbPropertiesTrait.php index 5cb902ec6..119fabfda 100644 --- a/src/danog/MadelineProto/Db/DbPropertiesTrait.php +++ b/src/danog/MadelineProto/Db/DbPropertiesTrait.php @@ -4,6 +4,15 @@ namespace danog\MadelineProto\Db; use danog\MadelineProto\MTProto; +/** + * Include this trait and call DbPropertiesTrait::initDb to use MadelineProto's database backend for properties. + * + * 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 + */ trait DbPropertiesTrait { /** diff --git a/src/danog/MadelineProto/Db/Driver/Mysql.php b/src/danog/MadelineProto/Db/Driver/Mysql.php index c15856ba4..a2709e3c2 100644 --- a/src/danog/MadelineProto/Db/Driver/Mysql.php +++ b/src/danog/MadelineProto/Db/Driver/Mysql.php @@ -9,6 +9,9 @@ use danog\MadelineProto\Settings\Database\Mysql as DatabaseMysql; use function Amp\Mysql\Pool; +/** + * MySQL driver wrapper. + */ class Mysql { /** @var Pool[] */ diff --git a/src/danog/MadelineProto/Db/Driver/Postgres.php b/src/danog/MadelineProto/Db/Driver/Postgres.php index b32f7bd34..c3ff30282 100644 --- a/src/danog/MadelineProto/Db/Driver/Postgres.php +++ b/src/danog/MadelineProto/Db/Driver/Postgres.php @@ -9,6 +9,9 @@ use danog\MadelineProto\Settings\Database\Postgres as DatabasePostgres; use function Amp\Postgres\Pool; +/** + * Postgres driver wrapper. + */ class Postgres { /** @var Pool[] */ diff --git a/src/danog/MadelineProto/Db/Driver/Redis.php b/src/danog/MadelineProto/Db/Driver/Redis.php index a7970ad32..cc71260d8 100644 --- a/src/danog/MadelineProto/Db/Driver/Redis.php +++ b/src/danog/MadelineProto/Db/Driver/Redis.php @@ -7,6 +7,9 @@ use Amp\Redis\Redis as RedisRedis; use Amp\Redis\RemoteExecutorFactory; use danog\MadelineProto\Settings\Database\Redis as DatabaseRedis; +/** + * Redis driver wrapper. + */ class Redis { /** @var RedisRedis[] */ diff --git a/src/danog/MadelineProto/Db/MemoryArray.php b/src/danog/MadelineProto/Db/MemoryArray.php index 4b96a90b6..d2e8229e1 100644 --- a/src/danog/MadelineProto/Db/MemoryArray.php +++ b/src/danog/MadelineProto/Db/MemoryArray.php @@ -10,6 +10,9 @@ use danog\MadelineProto\Settings\Database\Memory; use function Amp\call; +/** + * Memory database backend. + */ class MemoryArray extends \ArrayIterator implements DbArray { protected function __construct($array = [], $flags = 0) diff --git a/src/danog/MadelineProto/Db/MysqlArray.php b/src/danog/MadelineProto/Db/MysqlArray.php index f729e8228..e6ca2f7c9 100644 --- a/src/danog/MadelineProto/Db/MysqlArray.php +++ b/src/danog/MadelineProto/Db/MysqlArray.php @@ -13,6 +13,9 @@ use danog\MadelineProto\Settings\Database\Mysql as DatabaseMysql; use function Amp\call; +/** + * MySQL database backend. + */ class MysqlArray extends SqlArray { protected string $table; diff --git a/src/danog/MadelineProto/Db/NullCache/MysqlArray.php b/src/danog/MadelineProto/Db/NullCache/MysqlArray.php index 798d72fca..9e22e614a 100644 --- a/src/danog/MadelineProto/Db/NullCache/MysqlArray.php +++ b/src/danog/MadelineProto/Db/NullCache/MysqlArray.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Db\NullCache; use danog\MadelineProto\Db\MysqlArray as DbMysqlArray; +/** + * MySQL database backend, no caching. + */ class MysqlArray extends DbMysqlArray { use NullCacheTrait; diff --git a/src/danog/MadelineProto/Db/NullCache/NullCacheTrait.php b/src/danog/MadelineProto/Db/NullCache/NullCacheTrait.php index 6ccbfd410..8c4e5460a 100644 --- a/src/danog/MadelineProto/Db/NullCache/NullCacheTrait.php +++ b/src/danog/MadelineProto/Db/NullCache/NullCacheTrait.php @@ -2,6 +2,11 @@ namespace danog\MadelineProto\Db\NullCache; +/** + * Trait that disables database caching. + * + * @internal + */ trait NullCacheTrait { /** diff --git a/src/danog/MadelineProto/Db/NullCache/PostgresArray.php b/src/danog/MadelineProto/Db/NullCache/PostgresArray.php index 3d5510640..9e49ca644 100644 --- a/src/danog/MadelineProto/Db/NullCache/PostgresArray.php +++ b/src/danog/MadelineProto/Db/NullCache/PostgresArray.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Db\NullCache; use danog\MadelineProto\Db\PostgresArray as DbPostgresArray; +/** + * Postgres database backend, no caching. + */ class PostgresArray extends DbPostgresArray { use NullCacheTrait; diff --git a/src/danog/MadelineProto/Db/NullCache/RedisArray.php b/src/danog/MadelineProto/Db/NullCache/RedisArray.php index 895f9b27e..c9591f5c5 100644 --- a/src/danog/MadelineProto/Db/NullCache/RedisArray.php +++ b/src/danog/MadelineProto/Db/NullCache/RedisArray.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Db\NullCache; use danog\MadelineProto\Db\RedisArray as DbRedisArray; +/** + * Redis database backend, no caching. + */ class RedisArray extends DbRedisArray { use NullCacheTrait; diff --git a/src/danog/MadelineProto/Db/PostgresArray.php b/src/danog/MadelineProto/Db/PostgresArray.php index 0dbf2e55c..10f6ded90 100644 --- a/src/danog/MadelineProto/Db/PostgresArray.php +++ b/src/danog/MadelineProto/Db/PostgresArray.php @@ -13,6 +13,9 @@ use danog\MadelineProto\Settings\Database\Postgres as DatabasePostgres; use function Amp\call; +/** + * Postgres database backend. + */ class PostgresArray extends SqlArray { protected string $table; diff --git a/src/danog/MadelineProto/Db/RedisArray.php b/src/danog/MadelineProto/Db/RedisArray.php index 04f096413..498c313f3 100644 --- a/src/danog/MadelineProto/Db/RedisArray.php +++ b/src/danog/MadelineProto/Db/RedisArray.php @@ -13,6 +13,9 @@ use Generator; use function Amp\call; +/** + * Redis database backend. + */ class RedisArray extends SqlArray { protected DatabaseRedis $dbSettings; diff --git a/src/danog/MadelineProto/Db/SqlArray.php b/src/danog/MadelineProto/Db/SqlArray.php index 1e10dba84..01705e39c 100644 --- a/src/danog/MadelineProto/Db/SqlArray.php +++ b/src/danog/MadelineProto/Db/SqlArray.php @@ -7,6 +7,9 @@ use danog\MadelineProto\Settings\Database\DatabaseAbstract; use function Amp\call; +/** + * Generic SQL database backend. + */ abstract class SqlArray extends DriverArray { protected string $table; diff --git a/src/danog/MadelineProto/Exception.php b/src/danog/MadelineProto/Exception.php index 7e2e91819..0bc0449d5 100644 --- a/src/danog/MadelineProto/Exception.php +++ b/src/danog/MadelineProto/Exception.php @@ -19,6 +19,9 @@ namespace danog\MadelineProto; +/** + * Basic exception. + */ class Exception extends \Exception { use TL\PrettyException; diff --git a/src/danog/MadelineProto/InternalDoc.php b/src/danog/MadelineProto/InternalDoc.php index 4d4088076..501cf2c7a 100644 --- a/src/danog/MadelineProto/InternalDoc.php +++ b/src/danog/MadelineProto/InternalDoc.php @@ -6061,13 +6061,6 @@ class InternalDoc extends APIFactory { $this->__call(__FUNCTION__, [$hook_url, $pem_path]); } - /** - * Set API wrapper needed for triggering serialization functions. - */ - public function setWrapper(\danog\MadelineProto\APIWrapper $wrapper) - { - $this->__call(__FUNCTION__, [$wrapper]); - } /** * Setup logger. * diff --git a/src/danog/MadelineProto/Lua.php b/src/danog/MadelineProto/Lua.php index 0f434dbdb..bf793c02f 100644 --- a/src/danog/MadelineProto/Lua.php +++ b/src/danog/MadelineProto/Lua.php @@ -19,13 +19,15 @@ namespace danog\MadelineProto; +/** + * Lua interface. + */ class Lua { - use \danog\Serializable; public API $MadelineProto; protected $Lua; - protected $script; - public function __magic_construct($script, $MadelineProto) + protected string $script; + public function __construct(string $script, API $MadelineProto) { if (!\file_exists($script)) { throw new Exception(\danog\MadelineProto\Lang::$current_lang['script_not_exist']); diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 5f7ff7e0e..78dc420e7 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -601,11 +601,22 @@ class MTProto extends AsyncConstruct implements TLCallback } /** * Set API wrapper needed for triggering serialization functions. + * + * @internal */ public function setWrapper(APIWrapper $wrapper): void { $this->wrapper = $wrapper; } + /** + * Get API wrapper. + * + * @internal + */ + public function getWrapper(): APIWrapper + { + return $this->wrapper; + } /** * Sleep function. * diff --git a/src/danog/MadelineProto/PTSException.php b/src/danog/MadelineProto/PTSException.php index acbafaf17..691c2caf8 100644 --- a/src/danog/MadelineProto/PTSException.php +++ b/src/danog/MadelineProto/PTSException.php @@ -19,6 +19,9 @@ namespace danog\MadelineProto; +/** + * Internal error indicating a problem with Telegram's servers. + */ class PTSException extends \Exception { use TL\PrettyException; diff --git a/src/danog/MadelineProto/PhpDocBuilder.php b/src/danog/MadelineProto/PhpDocBuilder.php new file mode 100644 index 000000000..37148f5ae --- /dev/null +++ b/src/danog/MadelineProto/PhpDocBuilder.php @@ -0,0 +1,177 @@ +. + * + * @author Daniil Gentili + * @copyright 2016-2020 Daniil Gentili + * @license https://opensource.org/licenses/AGPL-3.0 AGPLv3 + * + * @link https://docs.madelineproto.xyz MadelineProto documentation + */ + +namespace danog\MadelineProto; + +use danog\MadelineProto\Async\AsyncConstruct; +use danog\MadelineProto\Db\DbPropertiesTrait; +use danog\MadelineProto\Files\Server; +use danog\MadelineProto\MTProtoTools\Crypt; +use danog\MadelineProto\MTProtoTools\GarbageCollector; +use danog\MadelineProto\MTProtoTools\MinDatabase; +use danog\MadelineProto\MTProtoTools\PasswordCalculator; +use danog\MadelineProto\MTProtoTools\ReferenceDatabase; +use danog\MadelineProto\MTProtoTools\UpdatesState; +use danog\MadelineProto\TL\TL; +use danog\MadelineProto\TL\TLConstructors; +use danog\MadelineProto\TL\TLMethods; +use danog\MadelineProto\TON\ADNLConnection; +use danog\MadelineProto\TON\APIFactory as TAPIFactory; +use danog\MadelineProto\TON\InternalDoc as TInternalDoc; +use danog\MadelineProto\TON\Lite; +use HaydenPierce\ClassFinder\ClassFinder; +use phpDocumentor\Reflection\DocBlock\Tags\Author; +use phpDocumentor\Reflection\DocBlock\Tags\Deprecated; +use phpDocumentor\Reflection\DocBlock\Tags\Generic; +use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag; +use phpDocumentor\Reflection\DocBlock\Tags\Property; +use phpDocumentor\Reflection\DocBlock\Tags\See; +use phpDocumentor\Reflection\DocBlockFactory; +use ReflectionClass; +use ReflectionClassConstant; + +class PhpDocBuilder +{ + private DocBlockFactory $factory; + public function __construct() + { + $this->factory = DocBlockFactory::createInstance(); + } + public function run() + { + $classes = ClassFinder::getClassesInNamespace('danog\\MadelineProto', ClassFinder::RECURSIVE_MODE); + foreach ($classes as $class) { + if (\in_array($class, [ + AnnotationsBuilder::class, + APIFactory::class, + APIWrapper::class, + AbstractAPIFactory::class, + Bug74586Exception::class, + Connection::class, + ContextConnector::class, + DataCenter::class, + DataCenterConnection::class, + DoHConnector::class, + DocsBuilder::class, + InternalDoc::class, + Lang::class, + LightState::class, + Magic::class, + PhpDocBuilder::class, + RSA::class, + Serialization::class, + SessionPaths::class, + SettingsEmpty::class, + SettingsAbstract::class, + Snitch::class, + AsyncConstruct::class, + Server::class, // Remove when done + VoIP::class, + + Crypt::class, + NothingInTheSocketException::class, + + GarbageCollector::class, + MinDatabase::class, + PasswordCalculator::class, + ReferenceDatabase::class, + UpdatesState::class, + + TL::class, + TLConstructors::class, + TLMethods::class, + + ADNLConnection::class, + TAPIFactory::class, + TInternalDoc::class, + Lite::class, + ]) || str_starts_with($class, 'danog\\MadelineProto\\Ipc') + || str_starts_with($class, 'danog\\MadelineProto\\Loop\\Update') + || str_starts_with($class, 'danog\\MadelineProto\\Loop\\Connection') + || str_starts_with($class, 'danog\\MadelineProto\\MTProto\\') + || str_starts_with($class, 'danog\\MadelineProto\\MTProtoSession\\') + || str_starts_with($class, 'danog\\MadelineProto\\Db\\NullCache')) { + continue; + } + $class = new ReflectionClass($class); + if ($class->isTrait()) { + continue; + } + $this->generate($class); + } + $this->generate(new ReflectionClass(DbPropertiesTrait::class)); + } + + private function generate(ReflectionClass $class): void + { + $name = $class->getName(); + $doc = $class->getDocComment(); + if (!$doc) { + throw new Exception("$name has no PHPDOC!"); + } + $doc = $this->factory->create($doc); + $title = $doc->getSummary(); + $description = $doc->getDescription(); + $tags = $doc->getTags(); + + $seeAlso = []; + $properties = []; + + $author = new Author("Daniil Gentili", "daniil@daniil.it"); + foreach ($tags as $tag) { + if ($tag instanceof Author) { + $author = $tag; + } + if ($tag instanceof Deprecated) { + return; + } + if ($tag instanceof Generic && $tag->getName() === 'internal') { + return; + } + if ($tag instanceof See) { + $seeAlso[$tag->getReference()->__toString()] = $tag->render(); + } + if ($tag instanceof Property) { + $properties[$tag->getVariableName()] = [ + $tag->getType(), + $tag->getDescription() + ]; + } + if ($tag instanceof InvalidTag && $tag->getName() === 'property') { + [$type, $description] = \explode(" $", $tag->render(), 2); + $description .= ' '; + [$varName, $description] = \explode(" ", $description, 2); + $properties[$varName] = [ + \str_replace('@property ', '', $type), + $description ?? '' + ]; + } + } + + $constants = []; + foreach ($class->getConstants() as $key => $value) { + $refl = new ReflectionClassConstant($name, $key); + $doc = $this->factory->create($refl->getDocComment() ?? ''); + $constants[$key] = [ + $value, + $description, + $doc->getDescription() + ]; + } + } +} diff --git a/src/danog/MadelineProto/PsrLogger.php b/src/danog/MadelineProto/PsrLogger.php index 5cf6c94a4..31607c637 100644 --- a/src/danog/MadelineProto/PsrLogger.php +++ b/src/danog/MadelineProto/PsrLogger.php @@ -5,6 +5,9 @@ namespace danog\MadelineProto; use Psr\Log\AbstractLogger; use Psr\Log\LogLevel; +/** + * PSR-3 wrapper for MadelineProto's Logger. + */ class PsrLogger extends AbstractLogger { private const LEVEL_MAP = [ diff --git a/src/danog/MadelineProto/RPCErrorException.php b/src/danog/MadelineProto/RPCErrorException.php index 36cdde5a0..a850a5a02 100644 --- a/src/danog/MadelineProto/RPCErrorException.php +++ b/src/danog/MadelineProto/RPCErrorException.php @@ -19,6 +19,9 @@ namespace danog\MadelineProto; +/** + * Indicates an error returned by Telegram's API. + */ class RPCErrorException extends \Exception { use TL\PrettyException; diff --git a/src/danog/MadelineProto/ResponseException.php b/src/danog/MadelineProto/ResponseException.php index d9ba28755..a9d6dfa55 100644 --- a/src/danog/MadelineProto/ResponseException.php +++ b/src/danog/MadelineProto/ResponseException.php @@ -19,6 +19,9 @@ namespace danog\MadelineProto; +/** + * Indicates an error thrown when an unexpected response is received from telegram's servers. + */ class ResponseException extends \Exception { } diff --git a/src/danog/MadelineProto/SecurityException.php b/src/danog/MadelineProto/SecurityException.php index eae3f0c97..98c3583f4 100644 --- a/src/danog/MadelineProto/SecurityException.php +++ b/src/danog/MadelineProto/SecurityException.php @@ -19,6 +19,9 @@ namespace danog\MadelineProto; +/** + * Indicates a security error. + */ class SecurityException extends \Exception { } diff --git a/src/danog/MadelineProto/Settings.php b/src/danog/MadelineProto/Settings.php index ad255471f..612c11534 100644 --- a/src/danog/MadelineProto/Settings.php +++ b/src/danog/MadelineProto/Settings.php @@ -21,6 +21,9 @@ use danog\MadelineProto\Settings\Serialization; use danog\MadelineProto\Settings\Templates; use danog\MadelineProto\Settings\TLSchema; +/** + * Settings class used for configuring MadelineProto. + */ class Settings extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/AppInfo.php b/src/danog/MadelineProto/Settings/AppInfo.php index 21982351c..d5fe6b16e 100644 --- a/src/danog/MadelineProto/Settings/AppInfo.php +++ b/src/danog/MadelineProto/Settings/AppInfo.php @@ -8,6 +8,9 @@ use danog\MadelineProto\Magic; use danog\MadelineProto\MTProto; use danog\MadelineProto\SettingsAbstract; +/** + * App information. + */ class AppInfo extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/Auth.php b/src/danog/MadelineProto/Settings/Auth.php index 3511f552b..53f877123 100644 --- a/src/danog/MadelineProto/Settings/Auth.php +++ b/src/danog/MadelineProto/Settings/Auth.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Settings; use danog\MadelineProto\SettingsAbstract; +/** + * Cryptography settings. + */ class Auth extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/Connection.php b/src/danog/MadelineProto/Settings/Connection.php index f0d167227..d3c555e8a 100644 --- a/src/danog/MadelineProto/Settings/Connection.php +++ b/src/danog/MadelineProto/Settings/Connection.php @@ -21,6 +21,9 @@ use danog\MadelineProto\Stream\Transport\DefaultStream; use danog\MadelineProto\Stream\Transport\WssStream; use danog\MadelineProto\Stream\Transport\WsStream; +/** + * Connection settings. + */ class Connection extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/Database/Memory.php b/src/danog/MadelineProto/Settings/Database/Memory.php index 8b99a6ad7..20f1e8476 100644 --- a/src/danog/MadelineProto/Settings/Database/Memory.php +++ b/src/danog/MadelineProto/Settings/Database/Memory.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Settings\Database; use danog\MadelineProto\Settings\DatabaseAbstract; +/** + * Memory backend settings. + */ class Memory extends DatabaseAbstract { /** diff --git a/src/danog/MadelineProto/Settings/Database/Mysql.php b/src/danog/MadelineProto/Settings/Database/Mysql.php index a1a1fdc63..10e106c66 100644 --- a/src/danog/MadelineProto/Settings/Database/Mysql.php +++ b/src/danog/MadelineProto/Settings/Database/Mysql.php @@ -2,6 +2,9 @@ namespace danog\MadelineProto\Settings\Database; +/** + * MySQL backend settings. + */ class Mysql extends SqlAbstract { public function mergeArray(array $settings): void diff --git a/src/danog/MadelineProto/Settings/Database/Postgres.php b/src/danog/MadelineProto/Settings/Database/Postgres.php index 7b797faff..e9155ad0f 100644 --- a/src/danog/MadelineProto/Settings/Database/Postgres.php +++ b/src/danog/MadelineProto/Settings/Database/Postgres.php @@ -2,6 +2,9 @@ namespace danog\MadelineProto\Settings\Database; +/** + * Postgres backend settings. + */ class Postgres extends SqlAbstract { public function mergeArray(array $settings): void diff --git a/src/danog/MadelineProto/Settings/Database/Redis.php b/src/danog/MadelineProto/Settings/Database/Redis.php index 3e08b1ab1..a38ec1360 100644 --- a/src/danog/MadelineProto/Settings/Database/Redis.php +++ b/src/danog/MadelineProto/Settings/Database/Redis.php @@ -2,6 +2,9 @@ namespace danog\MadelineProto\Settings\Database; +/** + * Redis backend settings. + */ class Redis extends DatabaseAbstract { /** diff --git a/src/danog/MadelineProto/Settings/Database/SqlAbstract.php b/src/danog/MadelineProto/Settings/Database/SqlAbstract.php index 0fc43e1d6..768f5ba7b 100644 --- a/src/danog/MadelineProto/Settings/Database/SqlAbstract.php +++ b/src/danog/MadelineProto/Settings/Database/SqlAbstract.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Settings\Database; use danog\MadelineProto\Settings\Database; +/** + * Generic db backend settings. + */ abstract class SqlAbstract extends DatabaseAbstract { /** diff --git a/src/danog/MadelineProto/Settings/Files.php b/src/danog/MadelineProto/Settings/Files.php index da884d1d6..fe6469b2d 100644 --- a/src/danog/MadelineProto/Settings/Files.php +++ b/src/danog/MadelineProto/Settings/Files.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Settings; use danog\MadelineProto\SettingsAbstract; +/** + * File management settings. + */ class Files extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/Ipc.php b/src/danog/MadelineProto/Settings/Ipc.php index 8500133f9..3868f5d67 100644 --- a/src/danog/MadelineProto/Settings/Ipc.php +++ b/src/danog/MadelineProto/Settings/Ipc.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Settings; use danog\MadelineProto\SettingsAbstract; +/** + * IPC server settings. + */ class Ipc extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/Logger.php b/src/danog/MadelineProto/Settings/Logger.php index 25623d940..e010dea13 100644 --- a/src/danog/MadelineProto/Settings/Logger.php +++ b/src/danog/MadelineProto/Settings/Logger.php @@ -7,6 +7,9 @@ use danog\MadelineProto\Magic; use danog\MadelineProto\SettingsAbstract; use danog\MadelineProto\Tools; +/** + * Logger settings. + */ class Logger extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/Peer.php b/src/danog/MadelineProto/Settings/Peer.php index 33ece8724..3f5bc86ae 100644 --- a/src/danog/MadelineProto/Settings/Peer.php +++ b/src/danog/MadelineProto/Settings/Peer.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Settings; use danog\MadelineProto\SettingsAbstract; +/** + * Peer database settings. + */ class Peer extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/Pwr.php b/src/danog/MadelineProto/Settings/Pwr.php index 185f57665..939914422 100644 --- a/src/danog/MadelineProto/Settings/Pwr.php +++ b/src/danog/MadelineProto/Settings/Pwr.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Settings; use danog\MadelineProto\SettingsAbstract; +/** + * PWRTelegram settings. + */ class Pwr extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/RPC.php b/src/danog/MadelineProto/Settings/RPC.php index b862933d5..8c25dbe8d 100644 --- a/src/danog/MadelineProto/Settings/RPC.php +++ b/src/danog/MadelineProto/Settings/RPC.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Settings; use danog\MadelineProto\SettingsAbstract; +/** + * RPC settings. + */ class RPC extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/SecretChats.php b/src/danog/MadelineProto/Settings/SecretChats.php index 6b5451f50..2b490bb96 100644 --- a/src/danog/MadelineProto/Settings/SecretChats.php +++ b/src/danog/MadelineProto/Settings/SecretChats.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Settings; use danog\MadelineProto\SettingsAbstract; +/** + * Secret chat settings. + */ class SecretChats extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/Serialization.php b/src/danog/MadelineProto/Settings/Serialization.php index 8da90224f..dc05768bf 100644 --- a/src/danog/MadelineProto/Settings/Serialization.php +++ b/src/danog/MadelineProto/Settings/Serialization.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Settings; use danog\MadelineProto\SettingsAbstract; +/** + * Serialization settings. + */ class Serialization extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/Settings/TLSchema.php b/src/danog/MadelineProto/Settings/TLSchema.php index 53958df35..ff6b498e5 100644 --- a/src/danog/MadelineProto/Settings/TLSchema.php +++ b/src/danog/MadelineProto/Settings/TLSchema.php @@ -4,6 +4,9 @@ namespace danog\MadelineProto\Settings; use danog\MadelineProto\SettingsAbstract; +/** + * TL schema settings. + */ class TLSchema extends SettingsAbstract { /** diff --git a/src/danog/MadelineProto/SettingsAbstract.php b/src/danog/MadelineProto/SettingsAbstract.php index 71ac60d28..83e488eed 100644 --- a/src/danog/MadelineProto/SettingsAbstract.php +++ b/src/danog/MadelineProto/SettingsAbstract.php @@ -18,6 +18,8 @@ abstract class SettingsAbstract * * @param array $settings Settings array * + * @internal + * * @return void */ public function mergeArray(array $settings): void @@ -29,6 +31,8 @@ abstract class SettingsAbstract * * @param self $other * + * @internal + * * @return void */ public function merge(self $other): void @@ -84,6 +88,8 @@ abstract class SettingsAbstract /** * Apply changes. * + * @internal + * * @return static */ public function applyChanges(): self diff --git a/src/danog/MadelineProto/Shutdown.php b/src/danog/MadelineProto/Shutdown.php index ab5b56e0d..2fed44b5b 100644 --- a/src/danog/MadelineProto/Shutdown.php +++ b/src/danog/MadelineProto/Shutdown.php @@ -19,8 +19,8 @@ namespace danog\MadelineProto; -/* - * Controls script shutdown +/** + * Class that controls script shutdown. */ class Shutdown { diff --git a/src/danog/MadelineProto/TL/Conversion/Exception.php b/src/danog/MadelineProto/TL/Conversion/Exception.php index 956d2ae30..71cb9e5c2 100644 --- a/src/danog/MadelineProto/TL/Conversion/Exception.php +++ b/src/danog/MadelineProto/TL/Conversion/Exception.php @@ -19,6 +19,9 @@ namespace danog\MadelineProto\TL\Conversion; +/** + * TL conversion exception. + */ class Exception extends \Exception { use \danog\MadelineProto\TL\PrettyException; diff --git a/src/danog/MadelineProto/TL/Exception.php b/src/danog/MadelineProto/TL/Exception.php index 174975e31..d6de2f74f 100644 --- a/src/danog/MadelineProto/TL/Exception.php +++ b/src/danog/MadelineProto/TL/Exception.php @@ -19,6 +19,9 @@ namespace danog\MadelineProto\TL; +/** + * TL deserialization exception. + */ class Exception extends \Exception { use PrettyException; diff --git a/src/danog/MadelineProto/TL/Types/Button.php b/src/danog/MadelineProto/TL/Types/Button.php index ecf2a46e9..ba8fcf631 100644 --- a/src/danog/MadelineProto/TL/Types/Button.php +++ b/src/danog/MadelineProto/TL/Types/Button.php @@ -19,9 +19,13 @@ namespace danog\MadelineProto\TL\Types; +use danog\MadelineProto\API; use danog\MadelineProto\MTProto; use danog\MadelineProto\Tools; +/** + * Clickable button. + */ class Button implements \JsonSerializable, \ArrayAccess { /** @@ -31,9 +35,15 @@ class Button implements \JsonSerializable, \ArrayAccess */ private array $button; /** - * MTProto instance. + * Session name. */ - private MTProto $API; + private string $session; + /** + * MTProto instance. + * + * @var MTProto|API + */ + private $API; /** * Message ID. */ @@ -62,6 +72,7 @@ class Button implements \JsonSerializable, \ArrayAccess : $message['peer_id']; $this->id = $message['id']; $this->API = $API; + $this->session = $API->getWrapper()->getSession()->getLegacySessionPath(); } /** * Sleep function. @@ -70,7 +81,7 @@ class Button implements \JsonSerializable, \ArrayAccess */ public function __sleep(): array { - return ['button', 'peer', 'id', 'API']; + return ['button', 'peer', 'id', 'session']; } /** * Click on button. @@ -81,7 +92,11 @@ class Button implements \JsonSerializable, \ArrayAccess */ public function click(bool $donotwait = true) { - $async = isset($this->API->wrapper) ? $this->API->wrapper->isAsync() : true; + if (!isset($this->API)) { + $this->API = new API($this->session); + } else { + $async = isset($this->API->wrapper) ? $this->API->wrapper->isAsync() : true; + } $method = $donotwait ? 'methodCallAsyncWrite' : 'methodCallAsyncRead'; switch ($this->button['_']) { default: diff --git a/src/danog/MadelineProto/TL/Types/Bytes.php b/src/danog/MadelineProto/TL/Types/Bytes.php index edf6f4a52..3d3f6ee9b 100644 --- a/src/danog/MadelineProto/TL/Types/Bytes.php +++ b/src/danog/MadelineProto/TL/Types/Bytes.php @@ -19,6 +19,9 @@ namespace danog\MadelineProto\TL\Types; +/** + * Bytes wrapper. + */ class Bytes implements \JsonSerializable, \ArrayAccess { /**