diff --git a/src/MTProto.php b/src/MTProto.php index 4a24cada6..747183684 100644 --- a/src/MTProto.php +++ b/src/MTProto.php @@ -1163,6 +1163,7 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter $this->settings = new Settings; } else { if ($this->v !== API::RELEASE || $this->settings->getSchema()->needsUpgrade()) { + $this->setupLogger(); $this->logger->logger("Generic settings have changed!", Logger::WARNING); $this->upgradeMadelineProto(); } @@ -1207,6 +1208,7 @@ final class MTProto implements TLCallback, LoggerGetter, SettingsGetter || $this->settings->getSchema()->hasChanged() || $this->settings->getSchema()->needsUpgrade() || $this->v !== API::RELEASE)) { + $this->setupLogger(); $this->logger->logger("Generic settings have changed!", Logger::WARNING); if ($this->v !== API::RELEASE || $this->settings->getSchema()->needsUpgrade()) { $this->upgradeMadelineProto(); diff --git a/tools/DocsBuilder/Methods.php b/tools/DocsBuilder/Methods.php index 30f355f71..d0235dd1e 100644 --- a/tools/DocsBuilder/Methods.php +++ b/tools/DocsBuilder/Methods.php @@ -28,7 +28,6 @@ use danog\MadelineProto\StrTools; use danog\MadelineProto\Tools; use danog\PhpDoc\PhpDoc; use danog\PhpDoc\PhpDoc\MethodDoc; -use phpDocumentor\Reflection\DocBlockFactory; use ReflectionClass; use ReflectionMethod; @@ -276,7 +275,6 @@ trait Methods /** @psalm-suppress UndefinedClass */ $phpdoc = PhpDoc::fromNamespace(\danog\MadelineProto::class); $phpdoc->resolveAliases(); - $builder = DocBlockFactory::createInstance(); foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { $name = $method->getName(); if (\in_array(strtolower($name), ['update2fa', 'getdialogids', 'getdialogs', 'getfulldialogs', 'getpwrchat', 'getfullinfo', 'getinfo', 'getid', 'getself', '__magic_construct', '__construct', '__destruct', '__sleep', '__wakeup'], true)) { @@ -287,8 +285,7 @@ trait Methods continue; } if ($doc) { - $doc = $builder->create($doc); - $doc = explode("\n", $doc->getSummary())[0]; + $doc = getSummary($doc); } if (!$doc) { throw new AssertionError($name); diff --git a/tools/build_docs.php b/tools/build_docs.php index 2fd92df0b..7a4f333c6 100755 --- a/tools/build_docs.php +++ b/tools/build_docs.php @@ -25,7 +25,12 @@ use danog\MadelineProto\TL\TL; use danog\MadelineProto\Tools; use danog\PhpDoc\PhpDoc; use danog\PhpDoc\PhpDoc\MethodDoc; -use phpDocumentor\Reflection\DocBlockFactory; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode; +use PHPStan\PhpDocParser\Lexer\Lexer; +use PHPStan\PhpDocParser\Parser\ConstExprParser; +use PHPStan\PhpDocParser\Parser\PhpDocParser; +use PHPStan\PhpDocParser\Parser\TokenIterator; +use PHPStan\PhpDocParser\Parser\TypeParser; use function Amp\File\read; @@ -133,10 +138,28 @@ foreach ($files as $file) { } ksort($orderedfiles); +/** @internal */ +function getSummary(string $phpdoc): string +{ + $lexer = new Lexer(); + $constExprParser = new ConstExprParser(); + $typeParser = new TypeParser($constExprParser); + $parser = new PhpDocParser( + $typeParser, + $constExprParser, + textBetweenTagsBelongsToDescription: true + ); + foreach ($parser->parse(new TokenIterator($lexer->tokenize($phpdoc)))->children as $t) { + if ($t instanceof PhpDocTextNode) { + return explode("\n", $t->text)[0]; + } + } + return ''; +} + /** @internal */ function printTypes(array $types, string $type): string { - $b = DocBlockFactory::createInstance(); $phpdoc = PhpDoc::fromNamespace(); $data = ''; foreach ($types as $class) { @@ -148,7 +171,7 @@ function printTypes(array $types, string $type): string if (!$refl->getDocComment()) { throw new AssertionError("No documentation for $class!"); } - $f = $b->create($refl->getDocComment())->getSummary(); + $f = getSummary($refl->getDocComment()); if ($refl->hasMethod('__construct')) { $c = $refl->getMethod('__construct'); if ($c->getParameters() && $type === 'attributefilters') {